~ubuntu-branches/ubuntu/saucy/bochs/saucy-proposed

« back to all changes in this revision

Viewing changes to cpu/instr.h

  • Committer: Bazaar Package Importer
  • Author(s): David Futcher
  • Date: 2009-04-30 07:46:11 UTC
  • mfrom: (1.1.11 upstream) (4.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090430074611-6dih80a5mk2uvxhk
Tags: 2.3.7+20090416-1ubuntu1
* Merge from debian unstable (LP: #370427), remaining changes:
  - debian/patches/12_no-ssp.patch: Build bios with -fno-stack-protector
  - Add Replaces/Conflicts for bochsbios-qemu (<< 2.3.6-2)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/////////////////////////////////////////////////////////////////////////
2
 
// $Id: instr.h,v 1.11 2008/04/14 21:48:35 sshwarts Exp $
 
2
// $Id: instr.h,v 1.20 2009/01/16 18:18:58 sshwarts Exp $
3
3
/////////////////////////////////////////////////////////////////////////
4
4
//
5
5
//   Copyright (c) 2008 Stanislav Shwartsman
17
17
//
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
21
21
//
22
22
/////////////////////////////////////////////////////////////////////////
23
23
 
28
28
 
29
29
// <TAG-TYPE-EXECUTEPTR-START>
30
30
#if BX_USE_CPU_SMF
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 *);
33
33
#else
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);
36
36
#endif
37
37
// <TAG-TYPE-EXECUTEPTR-END>
38
38
 
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
 
50
  Bit16u ia_opcode;
 
51
#endif
48
52
 
49
53
  struct {
50
 
    //  7...2 (unused)
51
 
    //  1...1 stop trace (used with trace cache)
52
 
    //  0...0 opcode extension: 0-none, 1-0x0f used
 
54
    //  7...1 (unused)
 
55
    //  0...0 stop trace (used with trace cache)
53
56
    Bit8u metaInfo4;
54
57
 
55
58
    //  7...0 b1 - opcode byte
115
118
#endif
116
119
  };
117
120
 
118
 
  BX_CPP_INLINE unsigned modC0()
 
121
  BX_CPP_INLINE unsigned modC0() const
119
122
  {
120
123
    // This is a cheaper way to test for modRM instructions where
121
124
    // the mod field is 0xc0.  FetchDecode flags this condition since
131
134
    // by REX.B on x86-64) to be used with IxIxForm or IqForm.
132
135
    metaData[BX_INSTR_METADATA_RM] = opreg;
133
136
  }
134
 
  BX_CPP_INLINE unsigned opcodeReg() {
 
137
  BX_CPP_INLINE unsigned opcodeReg() const {
135
138
    return metaData[BX_INSTR_METADATA_RM];
136
139
  }
137
140
  BX_CPP_INLINE void setModRM(unsigned modrm) {
138
141
    metaData[BX_INSTR_METADATA_MODRM] = modrm;
139
142
  }
140
 
  BX_CPP_INLINE unsigned modrm() {
 
143
  BX_CPP_INLINE unsigned modrm() const {
141
144
    return metaData[BX_INSTR_METADATA_MODRM];
142
145
  }
143
146
  BX_CPP_INLINE void setNnn(unsigned nnn) {
144
147
    metaData[BX_INSTR_METADATA_NNN] = nnn;
145
148
  }
146
 
  BX_CPP_INLINE unsigned nnn() {
 
149
  BX_CPP_INLINE unsigned nnn() const {
147
150
    return metaData[BX_INSTR_METADATA_NNN];
148
151
  }
149
152
  BX_CPP_INLINE void setRm(unsigned rm) {
150
153
    metaData[BX_INSTR_METADATA_RM] = rm;
151
154
  }
152
 
  BX_CPP_INLINE unsigned rm() {
 
155
  BX_CPP_INLINE unsigned rm() const {
153
156
    return metaData[BX_INSTR_METADATA_RM];
154
157
  }
155
158
  BX_CPP_INLINE void setSibScale(unsigned scale) {
156
159
    metaData[BX_INSTR_METADATA_SCALE] = scale;
157
160
  }
158
 
  BX_CPP_INLINE unsigned sibScale() {
 
161
  BX_CPP_INLINE unsigned sibScale() const {
159
162
    return metaData[BX_INSTR_METADATA_SCALE];
160
163
  }
161
164
  BX_CPP_INLINE void setSibIndex(unsigned index) {
162
165
    metaData[BX_INSTR_METADATA_INDEX] = index;
163
166
  }
164
 
  BX_CPP_INLINE unsigned sibIndex() {
 
167
  BX_CPP_INLINE unsigned sibIndex() const {
165
168
    return metaData[BX_INSTR_METADATA_INDEX];
166
169
  }
167
170
  BX_CPP_INLINE void setSibBase(unsigned base) {
168
171
    metaData[BX_INSTR_METADATA_BASE] = base;
169
172
  }
170
 
  BX_CPP_INLINE unsigned sibBase() {
 
173
  BX_CPP_INLINE unsigned sibBase() const {
171
174
    return metaData[BX_INSTR_METADATA_BASE];
172
175
  }
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; }
182
185
#endif
183
186
 
184
187
  // Info in the metaInfo field.
190
193
  {
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;
194
196
  }
195
 
  BX_CPP_INLINE unsigned seg(void) {
 
197
  BX_CPP_INLINE unsigned seg(void) const {
196
198
    return metaData[BX_INSTR_METADATA_SEG];
197
199
  }
198
200
  BX_CPP_INLINE void setSeg(unsigned val) {
199
201
    metaData[BX_INSTR_METADATA_SEG] = val;
200
202
  }
201
203
 
202
 
  BX_CPP_INLINE unsigned os32L(void) {
 
204
  BX_CPP_INLINE unsigned os32L(void) const {
203
205
    return metaInfo.metaInfo1 & (1<<3);
204
206
  }
205
207
  BX_CPP_INLINE void setOs32B(unsigned bit) {
209
211
    metaInfo.metaInfo1 |= (1<<3);
210
212
  }
211
213
 
212
 
  BX_CPP_INLINE unsigned as32L(void) {
 
214
  BX_CPP_INLINE unsigned as32L(void) const {
213
215
    return metaInfo.metaInfo1 & (1<<4);
214
216
  }
215
217
  BX_CPP_INLINE void setAs32B(unsigned bit) {
217
219
  }
218
220
 
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);
222
224
  }
223
225
  BX_CPP_INLINE void assertOs64(void) {
224
226
    metaInfo.metaInfo1 |= (1<<5);
225
227
  }
226
228
#else
227
 
  BX_CPP_INLINE unsigned os64L(void) { return 0; }
 
229
  BX_CPP_INLINE unsigned os64L(void) const { return 0; }
228
230
#endif
229
231
 
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);
233
235
  }
234
236
  BX_CPP_INLINE void setAs64B(unsigned bit) {
235
237
    metaInfo.metaInfo1 = (metaInfo.metaInfo1 & ~(1<<6)) | (bit<<6);
236
238
  }
237
239
#else
238
 
  BX_CPP_INLINE unsigned as64L(void) { return 0; }
 
240
  BX_CPP_INLINE unsigned as64L(void) const { return 0; }
239
241
#endif
240
242
 
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);
244
246
  }
245
247
  BX_CPP_INLINE void assertExtend8bit(void) {
247
249
  }
248
250
#endif
249
251
 
250
 
  BX_CPP_INLINE unsigned ilen(void) {
 
252
  BX_CPP_INLINE unsigned ilen(void) const {
251
253
    return metaInfo.metaInfo2;
252
254
  }
253
255
  BX_CPP_INLINE void setILen(unsigned ilen) {
254
256
    metaInfo.metaInfo2 = ilen;
255
257
  }
256
258
 
257
 
  BX_CPP_INLINE unsigned repUsedL(void) {
 
259
  BX_CPP_INLINE unsigned repUsedL(void) const {
258
260
    return metaInfo.metaInfo1 & 3;
259
261
  }
260
 
  BX_CPP_INLINE unsigned repUsedValue(void) {
 
262
  BX_CPP_INLINE unsigned repUsedValue(void) const {
261
263
    return metaInfo.metaInfo1 & 3;
262
264
  }
263
265
  BX_CPP_INLINE void setRepUsed(unsigned value) {
264
266
    metaInfo.metaInfo1 = (metaInfo.metaInfo1 & ~3) | (value);
265
267
  }
266
268
 
267
 
  BX_CPP_INLINE unsigned b1(void) {
 
269
  BX_CPP_INLINE unsigned b1(void) const {
268
270
    return metaInfo.metaInfo3;
269
271
  }
270
272
  BX_CPP_INLINE void setB1(unsigned b1) {
271
273
    metaInfo.metaInfo3 = b1 & 0xff;
272
274
  }
273
275
 
274
 
  BX_CPP_INLINE void setOpcodeExtension(void) {
275
 
    metaInfo.metaInfo4 |= 1;
276
 
  }
277
 
  BX_CPP_INLINE unsigned hasOpcodeExtension(void) {
278
 
    return metaInfo.metaInfo4 & 1;
279
 
  }
280
 
 
281
276
#if BX_SUPPORT_TRACE_CACHE
282
277
  BX_CPP_INLINE void setStopTraceAttr(void) {
283
 
   metaInfo.metaInfo4 |= (1<<1);
 
278
   metaInfo.metaInfo4 |= 1;
284
279
  }
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;
287
282
  }
288
283
#endif
289
284
};
290
285
// <TAG-CLASS-INSTRUCTION-END>
291
286
 
292
 
extern BxExecutePtr_tR BxOpcodesTable[];
293
 
 
294
287
#endif