00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef EMU_UTILITY_COMMON_OP_INFO_H
00033 #define EMU_UTILITY_COMMON_OP_INFO_H
00034
00035 #include "Utility/RuntimeError.h"
00036 #include "Interface/OpInfo.h"
00037 #include "Interface/OpStateIF.h"
00038 #include "Interface/ExtraOpDecoderIF.h"
00039 #include "Interface/OpClass.h"
00040
00041
00042 namespace Onikiri
00043 {
00044 namespace EmulatorUtility
00045 {
00046
00047 class OpEmulationState;
00048
00049
00050 template<class TISAInfo>
00051 class CommonOpInfo : public OpInfo
00052 {
00053 public:
00054 static const int MaxSrcRegCount = TISAInfo::MaxSrcRegCount;
00055 static const int MaxDstRegCount = TISAInfo::MaxDstRegCount;
00056 static const int MaxImmCount = TISAInfo::MaxImmCount;
00057 static const int MaxSrcCount = MaxSrcRegCount + MaxImmCount;
00058 static const int MaxDstCount = MaxDstRegCount;
00059 enum OperandType { NONE, REG, IMM, ZERO };
00060 typedef void (*EmulationFunc)(OpEmulationState*);
00061
00062 explicit CommonOpInfo(OpClass opClass) :
00063 m_opClass(opClass),
00064 m_emulationFunc(0),
00065 m_srcRegNum(0),
00066 m_dstRegNum(0),
00067 m_srcOpNum(0),
00068 m_dstOpNum(0),
00069 m_immNum(0),
00070 m_microOpNum(0),
00071 m_microOpIndex(0),
00072 m_mnemonic("")
00073 {
00074 std::fill(m_srcReg.begin(), m_srcReg.end(), -1);
00075 std::fill(m_dstReg.begin(), m_dstReg.end(), -1);
00076 std::fill(m_imm.begin(), m_imm.end(), -1);
00077
00078 std::fill(m_srcRegOpMap.begin(), m_srcRegOpMap.end(), -1);
00079 std::fill(m_dstRegOpMap.begin(), m_dstRegOpMap.end(), -1);
00080 std::fill(m_immOpMap.begin(), m_immOpMap.end(), -1);
00081 }
00082 virtual ~CommonOpInfo()
00083 {
00084 }
00085
00086 int GetSrcReg(int index) { return m_srcReg[index]; }
00087 void SetSrcReg(int index, int value)
00088 {
00089 assert( index < MaxSrcRegCount );
00090 m_srcReg[index] = value;
00091 }
00092
00093 int GetDstReg(int index) { return m_dstReg[index]; }
00094 void SetDstReg(int index, int value)
00095 {
00096 assert( index < MaxDstRegCount );
00097 m_dstReg[index] = value;
00098 }
00099
00100 s64 GetImm(int index) { return m_imm[index]; }
00101 void SetImm(int index, s64 value)
00102 {
00103 assert( index < MaxImmCount );
00104 m_imm[index] = value;
00105 }
00106
00107 EmulationFunc GetEmulationFunc() const { return m_emulationFunc; }
00108 void SetEmulationFunc(EmulationFunc func) { m_emulationFunc = func; }
00109
00110
00111 void SetSrcRegOpMap(int index, int value)
00112 {
00113 assert( index < MaxSrcCount );
00114 m_srcRegOpMap[index] = value;
00115 }
00116 int GetSrcRegOpMap(int index) const { return m_srcRegOpMap[index]; }
00117
00118 void SetImmOpMap(int index, int value)
00119 {
00120 assert( index < MaxImmCount );
00121 m_immOpMap[index] = value;
00122 }
00123 int GetImmOpMap(int index) const { return m_immOpMap[index]; }
00124
00125 void SetDstRegOpMap(int index, int value)
00126 {
00127 assert( index < MaxDstCount );
00128 m_dstRegOpMap[index] = value;
00129 }
00130 int GetDstRegOpMap(int index) const { return m_dstRegOpMap[index]; }
00131
00132
00133 void SetSrcOpNum(int n) { m_srcOpNum = n; }
00134 int GetSrcOpNum() const { return m_srcOpNum; }
00135 void SetDstOpNum(int n) { m_dstOpNum = n; }
00136 int GetDstOpNum() const { return m_dstOpNum; }
00137
00138
00139 void SetImmNum(int n) { m_immNum = n; }
00140 int GetImmNum() const { return m_immNum; }
00141
00142
00143 void SetSrcRegNum(int n) { m_srcRegNum = n; }
00144 void SetDstRegNum(int n) { m_dstRegNum = n; }
00145
00146 int GetSrcRegNum() const { return m_srcRegNum; }
00147 int GetDstRegNum() const { return m_dstRegNum; }
00148
00149
00150 void SetMicroOpNum( int microOpNum ) { m_microOpNum = microOpNum; }
00151 void SetMicroOpIndex( int microOpIndex ){ m_microOpIndex = microOpIndex; }
00152
00153
00154 void SetMnemonic(const char* mnemonic) { m_mnemonic = mnemonic; }
00155
00156
00157 virtual const OpClass& GetOpClass() const
00158 {
00159 return m_opClass;
00160 }
00161 virtual int GetSrcOperand(const int index) const
00162 {
00163 assert(index < MaxSrcRegCount);
00164 return m_srcReg[index];
00165 }
00166 virtual int GetDstOperand(const int index) const
00167 {
00168 assert(index < MaxDstRegCount);
00169 return m_dstReg[index];
00170 }
00171 virtual int GetSrcNum() const
00172 {
00173 return m_srcRegNum;
00174 }
00175 virtual int GetDstNum() const
00176 {
00177 return m_dstRegNum;
00178 }
00179
00180
00181 virtual int GetMicroOpNum() const
00182 {
00183 return m_microOpNum;
00184 }
00185
00186
00187 virtual int GetMicroOpIndex() const
00188 {
00189 return m_microOpIndex;
00190 }
00191
00192 virtual const char* GetMnemonic() const
00193 {
00194 return m_mnemonic;
00195 }
00196
00197 protected:
00198 OpClass m_opClass;
00199
00200
00201 EmulationFunc m_emulationFunc;
00202
00203 boost::array<int, MaxSrcRegCount> m_srcReg;
00204
00205 boost::array<int, MaxDstRegCount> m_dstReg;
00206
00207 boost::array<s64, MaxImmCount> m_imm;
00208
00209 int m_srcRegNum;
00210
00211 int m_dstRegNum;
00212
00213
00214 int m_srcOpNum;
00215
00216 int m_dstOpNum;
00217
00218 int m_immNum;
00219
00220 int m_microOpNum;
00221 int m_microOpIndex;
00222
00223
00224 const char* m_mnemonic;
00225
00226
00227
00228 boost::array<int, MaxSrcCount> m_srcRegOpMap;
00229 boost::array<int, MaxDstCount> m_dstRegOpMap;
00230 boost::array<int, MaxImmCount> m_immOpMap;
00231 };
00232
00233 }
00234 }
00235
00236 #endif
00237