src/Emu/Utility/OpEmulationState.h

説明を見る。
00001 // 
00002 // Copyright (c) 2005-2008 Kenichi Watanabe.
00003 // Copyright (c) 2005-2008 Yasuhiro Watari.
00004 // Copyright (c) 2005-2008 Hironori Ichibayashi.
00005 // Copyright (c) 2008-2009 Kazuo Horio.
00006 // Copyright (c) 2009-2013 Naruki Kurata.
00007 // Copyright (c) 2005-2013 Ryota Shioya.
00008 // Copyright (c) 2005-2013 Masahiro Goshima.
00009 // 
00010 // This software is provided 'as-is', without any express or implied
00011 // warranty. In no event will the authors be held liable for any damages
00012 // arising from the use of this software.
00013 // 
00014 // Permission is granted to anyone to use this software for any purpose,
00015 // including commercial applications, and to alter it and redistribute it
00016 // freely, subject to the following restrictions:
00017 // 
00018 // 1. The origin of this software must not be misrepresented; you must not
00019 // claim that you wrote the original software. If you use this software
00020 // in a product, an acknowledgment in the product documentation would be
00021 // appreciated but is not required.
00022 // 
00023 // 2. Altered source versions must be plainly marked as such, and must not be
00024 // misrepresented as being the original software.
00025 // 
00026 // 3. This notice may not be removed or altered from any source
00027 // distribution.
00028 // 
00029 // 
00030 
00031 
00032 #ifndef __EMULATORUTILITY_OPEMULATIONSTATE_H__
00033 #define __EMULATORUTILITY_OPEMULATIONSTATE_H__
00034 
00035 #include "Interface/OpStateIF.h"
00036 
00037 #include "Interface/OpInfo.h"
00038 #include "Emu/Utility/CommonOpInfo.h"
00039 
00040 namespace Onikiri {
00041     namespace EmulatorUtility {
00042 
00043         class ProcessState;
00044 
00045         class OpEmulationState {
00046         private:
00047             OpStateIF* m_opState;
00048             OpInfo* m_opInfo;
00049             EmulatorUtility::ProcessState* m_processState;
00050 
00051             // VA[LeN`
00052             static const int MaxSrcCount = 8;   // SrcReg + Imm
00053             static const int MaxDstCount = 3;
00054 
00055             // El src 
00056             // E\[XWX^[WX^ src  0 
00057             // EfXeBl[VWX^[WX^CfXeBl[VWX^ dst  OpState f
00058             boost::array<u64, MaxSrcCount> m_src;
00059             boost::array<u64, MaxDstCount> m_dst;
00060 
00061             u64 m_PC;
00062             u64 m_takenPC;
00063             bool m_taken;
00064             int m_pid;
00065             int m_tid;
00066 
00067 
00068         private:
00069             template<typename TOpInfo, typename TRegObtainer>
00070             void InitOperands(TRegObtainer obtainer)
00071             {
00072                 TOpInfo* opInfo = static_cast<TOpInfo*>(m_opInfo);
00073                 {
00074                     int immNum = opInfo->GetImmNum();
00075                     for (int i = 0; i < immNum; i ++) {
00076                         m_src[ opInfo->GetImmOpMap(i) ] = opInfo->GetImm(i);
00077                     }
00078                 }
00079 
00080                 {
00081                     int srcRegNum = opInfo->GetSrcRegNum();
00082                     for (int i = 0; i < srcRegNum; i ++) {
00083                         m_src[ opInfo->GetSrcRegOpMap(i) ] = obtainer(i);
00084                     }
00085                 }
00086             }
00087         public:
00088             // WX^lOpState
00089             struct RegFromOpState : public std::unary_function<int, u64>
00090             {
00091                 RegFromOpState(Onikiri::OpStateIF* opState) : m_opState(opState) {}
00092 
00093                 u64 operator()(int index) {
00094                     return m_opState->GetSrc(index);
00095                 }
00096                 Onikiri::OpStateIF* m_opState;
00097             };
00098 
00099             // WX^lregArray
00100             template<typename TOpInfo>
00101             struct RegFromRegArray : public std::unary_function<int, u64>
00102             {
00103                 RegFromRegArray(TOpInfo* opInfo, u64* regArray) : m_opInfo(opInfo), m_regArray(regArray)  {}
00104 
00105                 u64 operator()(int index) {
00106                     return m_regArray[ m_opInfo->GetSrcReg(index) ];
00107                 }
00108                 TOpInfo* m_opInfo;
00109                 u64* m_regArray;
00110             };
00111 
00112             // opInfo]opStatel
00113             template<typename TOpInfo>
00114             OpEmulationState(Onikiri::OpStateIF* opState, TOpInfo* opInfo, EmulatorUtility::ProcessState* processState)
00115                 : m_opState(opState), m_opInfo(opInfo), m_processState(processState)
00116             {
00117                 Addr addr = m_opState->GetTakenPC();
00118                 m_takenPC = addr.address;
00119                 m_taken = false;
00120                 m_pid = addr.pid;
00121                 m_tid = addr.tid;
00122 
00123                 m_PC = m_opState->GetPC().address;
00124 
00125                 InitOperands<TOpInfo, RegFromOpState>( RegFromOpState(opState) );
00126             }
00127 
00128             // G~[Vp
00129             // WX^l regArray 
00130             template<typename TOpInfo>
00131             OpEmulationState(Onikiri::OpStateIF* opState, TOpInfo* opInfo, EmulatorUtility::ProcessState* processState, PC pc, u64 takenAddr, u64* regArray)
00132                 : m_opState(opState), m_opInfo(opInfo), m_processState(processState)
00133             {
00134                 m_takenPC = pc.address+4;
00135                 m_taken = false;
00136                 m_pid = pc.pid;
00137                 m_tid = pc.tid;
00138 
00139                 m_PC = pc.address;
00140 
00141                 InitOperands<TOpInfo, RegFromRegArray<TOpInfo> >( RegFromRegArray<TOpInfo>(opInfo, regArray) );
00142             }
00143 
00144             // OpState f
00145             template<typename TOpInfo>
00146             void ApplyEmulationState()
00147             {
00148                 TOpInfo* opInfo = static_cast<TOpInfo*>(m_opInfo);
00149                 m_opState->SetTaken(m_taken);
00150                 m_opState->SetTakenPC( Addr(m_pid, m_tid, m_takenPC) );
00151 
00152                 // opInfo] dst 
00153                 int dstRegNum = opInfo->GetDstRegNum();
00154                 for (int i = 0; i < dstRegNum; i ++) {
00155                     m_opState->SetDst( i, m_dst[ opInfo->GetDstRegOpMap(i) ]);
00156                 }
00157             }
00158 
00159             // G~[Vp
00160             // regArray f
00161             template<typename TOpInfo>
00162             void ApplyEmulationStateToRegArray(u64* regArray)
00163             {
00164                 TOpInfo* opInfo = static_cast<TOpInfo*>(m_opInfo);
00165 
00166                 // opInfo] dst 
00167                 int dstRegNum = opInfo->GetDstRegNum();
00168                 for (int i = 0; i < dstRegNum; i ++) {
00169                     regArray[ opInfo->GetDstReg(i) ] = m_dst[ opInfo->GetDstRegOpMap(i) ];
00170                 }
00171             }
00172 
00173             void SetDst(int index, u64 value)
00174             {
00175                 m_dst[index] = value;
00176             }
00177             u64 GetSrc(int index)
00178             {
00179                 return m_src[index];
00180             }
00181             u64 GetDst(int index)
00182             {
00183                 return m_dst[index];
00184             }
00185 
00186             //// Accessors for results
00187             void SetTaken(bool t)
00188             {
00189                 m_taken = t;
00190             }
00191             bool GetTaken() const
00192             {
00193                 return m_taken;
00194             }
00195 
00196             Onikiri::u64 GetPC() const
00197             {
00198                 return m_PC;
00199             }
00200 
00201             void SetTakenPC(Onikiri::u64 pc)
00202             {
00203                 m_takenPC = pc;
00204             }
00205 
00206             Onikiri::u64 GetTakenPC() const
00207             {
00208                 return m_takenPC;
00209             }
00210 
00211             int GetPID() const
00212             {
00213                 return m_pid;
00214             }
00215 
00216             int GetTID() const
00217             {
00218                 return m_tid;
00219             }
00220 
00221             OpStateIF* GetOpState()
00222             {
00223                 return m_opState;
00224             }
00225             OpInfo* GetOpInfo()
00226             {
00227                 return m_opInfo;
00228             }
00229             EmulatorUtility::ProcessState* GetProcessState()
00230             {
00231                 return m_processState;
00232             }
00233         };
00234 
00235     } // namespace EmulatorUtility
00236 } // namespace Onikiri
00237 
00238 #endif

Onikiri2に対してTue Jun 18 14:34:20 2013に生成されました。  doxygen 1.4.7