18
18
// You should have received a copy of the GNU Lesser General Public
19
19
// License along with this library; if not, write to the Free Software
20
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
22
22
/////////////////////////////////////////////////////////////////////////
29
29
// <TAG-TYPE-EXECUTEPTR-START>
31
typedef void (*BxExecutePtr_t)(bxInstruction_c *);
32
31
typedef void (BX_CPP_AttrRegparmN(1) *BxExecutePtr_tR)(bxInstruction_c *);
32
typedef bx_address (BX_CPP_AttrRegparmN(1) *BxResolvePtr_tR)(bxInstruction_c *);
34
typedef void (BX_CPU_C::*BxExecutePtr_t)(bxInstruction_c *);
35
34
typedef void (BX_CPU_C::*BxExecutePtr_tR)(bxInstruction_c *) BX_CPP_AttrRegparmN(1);
35
typedef bx_address (BX_CPU_C::*BxResolvePtr_tR)(bxInstruction_c *) BX_CPP_AttrRegparmN(1);
37
37
// <TAG-TYPE-EXECUTEPTR-END>
43
43
// given the current state of the CPU and the instruction data,
44
44
// and a function to execute the instruction after resolving
45
45
// the memory address (if any).
46
BxExecutePtr_tR ResolveModrm;
47
46
BxExecutePtr_tR execute;
47
BxExecutePtr_tR execute2;
48
BxResolvePtr_tR ResolveModrm;
49
#if BX_INSTRUMENTATION
51
// 1...1 stop trace (used with trace cache)
52
// 0...0 opcode extension: 0-none, 1-0x0f used
55
// 0...0 stop trace (used with trace cache)
55
58
// 7...0 b1 - opcode byte
131
134
// by REX.B on x86-64) to be used with IxIxForm or IqForm.
132
135
metaData[BX_INSTR_METADATA_RM] = opreg;
134
BX_CPP_INLINE unsigned opcodeReg() {
137
BX_CPP_INLINE unsigned opcodeReg() const {
135
138
return metaData[BX_INSTR_METADATA_RM];
137
140
BX_CPP_INLINE void setModRM(unsigned modrm) {
138
141
metaData[BX_INSTR_METADATA_MODRM] = modrm;
140
BX_CPP_INLINE unsigned modrm() {
143
BX_CPP_INLINE unsigned modrm() const {
141
144
return metaData[BX_INSTR_METADATA_MODRM];
143
146
BX_CPP_INLINE void setNnn(unsigned nnn) {
144
147
metaData[BX_INSTR_METADATA_NNN] = nnn;
146
BX_CPP_INLINE unsigned nnn() {
149
BX_CPP_INLINE unsigned nnn() const {
147
150
return metaData[BX_INSTR_METADATA_NNN];
149
152
BX_CPP_INLINE void setRm(unsigned rm) {
150
153
metaData[BX_INSTR_METADATA_RM] = rm;
152
BX_CPP_INLINE unsigned rm() {
155
BX_CPP_INLINE unsigned rm() const {
153
156
return metaData[BX_INSTR_METADATA_RM];
155
158
BX_CPP_INLINE void setSibScale(unsigned scale) {
156
159
metaData[BX_INSTR_METADATA_SCALE] = scale;
158
BX_CPP_INLINE unsigned sibScale() {
161
BX_CPP_INLINE unsigned sibScale() const {
159
162
return metaData[BX_INSTR_METADATA_SCALE];
161
164
BX_CPP_INLINE void setSibIndex(unsigned index) {
162
165
metaData[BX_INSTR_METADATA_INDEX] = index;
164
BX_CPP_INLINE unsigned sibIndex() {
167
BX_CPP_INLINE unsigned sibIndex() const {
165
168
return metaData[BX_INSTR_METADATA_INDEX];
167
170
BX_CPP_INLINE void setSibBase(unsigned base) {
168
171
metaData[BX_INSTR_METADATA_BASE] = base;
170
BX_CPP_INLINE unsigned sibBase() {
173
BX_CPP_INLINE unsigned sibBase() const {
171
174
return metaData[BX_INSTR_METADATA_BASE];
173
BX_CPP_INLINE Bit32u displ32u() { return modRMForm.displ32u; }
174
BX_CPP_INLINE Bit16u displ16u() { return modRMForm.displ16u; }
175
BX_CPP_INLINE Bit32u Id() { return modRMForm.Id; }
176
BX_CPP_INLINE Bit16u Iw() { return modRMForm.Iw; }
177
BX_CPP_INLINE Bit8u Ib() { return modRMForm.Ib; }
178
BX_CPP_INLINE Bit16u Iw2() { return IxIxForm.Iw2; } // Legacy
179
BX_CPP_INLINE Bit8u Ib2() { return IxIxForm.Ib2; } // Legacy
176
BX_CPP_INLINE Bit32s displ32s() const { return (Bit32s) modRMForm.displ32u; }
177
BX_CPP_INLINE Bit16s displ16s() const { return (Bit16s) modRMForm.displ16u; }
178
BX_CPP_INLINE Bit32u Id() const { return modRMForm.Id; }
179
BX_CPP_INLINE Bit16u Iw() const { return modRMForm.Iw; }
180
BX_CPP_INLINE Bit8u Ib() const { return modRMForm.Ib; }
181
BX_CPP_INLINE Bit16u Iw2() const { return IxIxForm.Iw2; } // Legacy
182
BX_CPP_INLINE Bit8u Ib2() const { return IxIxForm.Ib2; } // Legacy
180
183
#if BX_SUPPORT_X86_64
181
BX_CPP_INLINE Bit64u Iq() { return IqForm.Iq; }
184
BX_CPP_INLINE Bit64u Iq() const { return IqForm.Iq; }
184
187
// Info in the metaInfo field.
191
194
metaInfo.metaInfo1 = (os32<<3) | (as32<<4) | (os64<<5) | (as64<<6);
192
195
metaInfo.metaInfo4 = 0;
193
metaData[BX_INSTR_METADATA_SEG] = BX_SEG_REG_NULL;
195
BX_CPP_INLINE unsigned seg(void) {
197
BX_CPP_INLINE unsigned seg(void) const {
196
198
return metaData[BX_INSTR_METADATA_SEG];
198
200
BX_CPP_INLINE void setSeg(unsigned val) {
199
201
metaData[BX_INSTR_METADATA_SEG] = val;
202
BX_CPP_INLINE unsigned os32L(void) {
204
BX_CPP_INLINE unsigned os32L(void) const {
203
205
return metaInfo.metaInfo1 & (1<<3);
205
207
BX_CPP_INLINE void setOs32B(unsigned bit) {
219
221
#if BX_SUPPORT_X86_64
220
BX_CPP_INLINE unsigned os64L(void) {
222
BX_CPP_INLINE unsigned os64L(void) const {
221
223
return metaInfo.metaInfo1 & (1<<5);
223
225
BX_CPP_INLINE void assertOs64(void) {
224
226
metaInfo.metaInfo1 |= (1<<5);
227
BX_CPP_INLINE unsigned os64L(void) { return 0; }
229
BX_CPP_INLINE unsigned os64L(void) const { return 0; }
230
232
#if BX_SUPPORT_X86_64
231
BX_CPP_INLINE unsigned as64L(void) {
233
BX_CPP_INLINE unsigned as64L(void) const {
232
234
return metaInfo.metaInfo1 & (1<<6);
234
236
BX_CPP_INLINE void setAs64B(unsigned bit) {
235
237
metaInfo.metaInfo1 = (metaInfo.metaInfo1 & ~(1<<6)) | (bit<<6);
238
BX_CPP_INLINE unsigned as64L(void) { return 0; }
240
BX_CPP_INLINE unsigned as64L(void) const { return 0; }
241
243
#if BX_SUPPORT_X86_64
242
BX_CPP_INLINE unsigned extend8bitL(void) {
244
BX_CPP_INLINE unsigned extend8bitL(void) const {
243
245
return metaInfo.metaInfo1 & (1<<7);
245
247
BX_CPP_INLINE void assertExtend8bit(void) {
250
BX_CPP_INLINE unsigned ilen(void) {
252
BX_CPP_INLINE unsigned ilen(void) const {
251
253
return metaInfo.metaInfo2;
253
255
BX_CPP_INLINE void setILen(unsigned ilen) {
254
256
metaInfo.metaInfo2 = ilen;
257
BX_CPP_INLINE unsigned repUsedL(void) {
259
BX_CPP_INLINE unsigned repUsedL(void) const {
258
260
return metaInfo.metaInfo1 & 3;
260
BX_CPP_INLINE unsigned repUsedValue(void) {
262
BX_CPP_INLINE unsigned repUsedValue(void) const {
261
263
return metaInfo.metaInfo1 & 3;
263
265
BX_CPP_INLINE void setRepUsed(unsigned value) {
264
266
metaInfo.metaInfo1 = (metaInfo.metaInfo1 & ~3) | (value);
267
BX_CPP_INLINE unsigned b1(void) {
269
BX_CPP_INLINE unsigned b1(void) const {
268
270
return metaInfo.metaInfo3;
270
272
BX_CPP_INLINE void setB1(unsigned b1) {
271
273
metaInfo.metaInfo3 = b1 & 0xff;
274
BX_CPP_INLINE void setOpcodeExtension(void) {
275
metaInfo.metaInfo4 |= 1;
277
BX_CPP_INLINE unsigned hasOpcodeExtension(void) {
278
return metaInfo.metaInfo4 & 1;
281
276
#if BX_SUPPORT_TRACE_CACHE
282
277
BX_CPP_INLINE void setStopTraceAttr(void) {
283
metaInfo.metaInfo4 |= (1<<1);
278
metaInfo.metaInfo4 |= 1;
285
BX_CPP_INLINE unsigned getStopTraceAttr(void) {
286
return metaInfo.metaInfo4 & (1<<1);
280
BX_CPP_INLINE unsigned getStopTraceAttr(void) const {
281
return metaInfo.metaInfo4 & 1;
290
285
// <TAG-CLASS-INSTRUCTION-END>
292
extern BxExecutePtr_tR BxOpcodesTable[];