2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
28 * $Log: db_disasm.c,v $
29 * Revision 2.6 92/01/03 20:05:00 dbg
30 * Add a switch to disassemble 16-bit code.
31 * Fix spelling of 'lods' opcodes.
34 * Revision 2.5 91/10/09 16:05:58 af
35 * Supported disassemble of non current task by passing task parameter.
38 * Revision 2.4 91/05/14 16:05:04 mrt
39 * Correcting copyright
41 * Revision 2.3 91/02/05 17:11:03 mrt
42 * Changed to new Mach copyright
43 * [91/02/01 17:31:03 mrt]
45 * Revision 2.2 90/08/27 21:55:56 dbg
46 * Fix register operand for move to/from control/test/debug
47 * register instructions. Add i486 instructions.
50 * Import db_sym.h. Print instruction displacements in
51 * current radix (signed). Change calling sequence of
62 * Instruction disassembler.
70 * Switch to disassemble 16-bit code.
72 static BOOL32 db_disasm_16
= FALSE
;
90 #define E 1 /* general effective address */
91 #define Eind 2 /* indirect address (jump, call) */
92 #define Ew 3 /* address, word size */
93 #define Eb 4 /* address, byte size */
94 #define R 5 /* register, in 'reg' field */
95 #define Rw 6 /* word register, in 'reg' field */
96 #define Ri 7 /* register in instruction */
97 #define S 8 /* segment reg, in 'reg' field */
98 #define Si 9 /* segment reg, in instruction */
99 #define A 10 /* accumulator */
100 #define BX 11 /* (bx) */
101 #define CL 12 /* cl, for shifts */
102 #define DX 13 /* dx, for IO */
103 #define SI 14 /* si */
104 #define DI 15 /* di */
105 #define CR 16 /* control register */
106 #define DR 17 /* debug register */
107 #define TR 18 /* test register */
108 #define I 19 /* immediate, unsigned */
109 #define Is 20 /* immediate, signed */
110 #define Ib 21 /* byte immediate, unsigned */
111 #define Ibs 22 /* byte immediate, signed */
112 #define Iw 23 /* word immediate, unsigned */
113 #define Il 24 /* long immediate */
114 #define O 25 /* direct address */
115 #define Db 26 /* byte displacement from EIP */
116 #define Dl 27 /* long displacement from EIP */
117 #define o1 28 /* constant 1 */
118 #define o3 29 /* constant 3 */
119 #define OS 30 /* immediate offset/segment */
120 #define ST 31 /* FP stack top */
121 #define STI 32 /* FP stack */
122 #define X 33 /* extended FP op */
123 #define XA 34 /* for 'fstcw %ax' */
126 const char *i_name
; /* name */
127 short i_has_modrm
; /* has regmodrm byte */
128 short i_size
; /* operand size */
129 int i_mode
; /* addressing modes */
130 const char *i_extra
; /* pointer to extra opcode table */
134 #define op2(x,y) ((x)|((y)<<8))
135 #define op3(x,y,z) ((x)|((y)<<8)|((z)<<16))
138 const char *f_name
; /* name for memory instruction */
139 int f_size
; /* size for memory instruction */
140 int f_rrmode
; /* mode for rr instruction */
141 const char *f_rrname
; /* name for rr instruction
142 (or pointer to table) */
145 static const char * const db_Grp6
[] = {
156 static const char * const db_Grp7
[] = {
167 static const char * const db_Grp8
[] = {
178 static const struct inst db_inst_0f0x
[] = {
179 /*00*/ { "", TRUE
, NONE
, op1(Ew
), (char *)db_Grp6
},
180 /*01*/ { "", TRUE
, NONE
, op1(Ew
), (char *)db_Grp7
},
181 /*02*/ { "lar", TRUE
, LONG
, op2(E
,R
), 0 },
182 /*03*/ { "lsl", TRUE
, LONG
, op2(E
,R
), 0 },
183 /*04*/ { "", FALSE
, NONE
, 0, 0 },
184 /*05*/ { "", FALSE
, NONE
, 0, 0 },
185 /*06*/ { "clts", FALSE
, NONE
, 0, 0 },
186 /*07*/ { "", FALSE
, NONE
, 0, 0 },
188 /*08*/ { "invd", FALSE
, NONE
, 0, 0 },
189 /*09*/ { "wbinvd",FALSE
, NONE
, 0, 0 },
190 /*0a*/ { "", FALSE
, NONE
, 0, 0 },
191 /*0b*/ { "", FALSE
, NONE
, 0, 0 },
192 /*0c*/ { "", FALSE
, NONE
, 0, 0 },
193 /*0d*/ { "", FALSE
, NONE
, 0, 0 },
194 /*0e*/ { "", FALSE
, NONE
, 0, 0 },
195 /*0f*/ { "", FALSE
, NONE
, 0, 0 },
198 static const struct inst db_inst_0f2x
[] = {
199 /*20*/ { "mov", TRUE
, LONG
, op2(CR
,E
), 0 }, /* use E for reg */
200 /*21*/ { "mov", TRUE
, LONG
, op2(DR
,E
), 0 }, /* since mod == 11 */
201 /*22*/ { "mov", TRUE
, LONG
, op2(E
,CR
), 0 },
202 /*23*/ { "mov", TRUE
, LONG
, op2(E
,DR
), 0 },
203 /*24*/ { "mov", TRUE
, LONG
, op2(TR
,E
), 0 },
204 /*25*/ { "", FALSE
, NONE
, 0, 0 },
205 /*26*/ { "mov", TRUE
, LONG
, op2(E
,TR
), 0 },
206 /*27*/ { "", FALSE
, NONE
, 0, 0 },
208 /*28*/ { "", FALSE
, NONE
, 0, 0 },
209 /*29*/ { "", FALSE
, NONE
, 0, 0 },
210 /*2a*/ { "", FALSE
, NONE
, 0, 0 },
211 /*2b*/ { "", FALSE
, NONE
, 0, 0 },
212 /*2c*/ { "", FALSE
, NONE
, 0, 0 },
213 /*2d*/ { "", FALSE
, NONE
, 0, 0 },
214 /*2e*/ { "", FALSE
, NONE
, 0, 0 },
215 /*2f*/ { "", FALSE
, NONE
, 0, 0 },
218 static const struct inst db_inst_0f8x
[] = {
219 /*80*/ { "jo", FALSE
, NONE
, op1(Dl
), 0 },
220 /*81*/ { "jno", FALSE
, NONE
, op1(Dl
), 0 },
221 /*82*/ { "jb", FALSE
, NONE
, op1(Dl
), 0 },
222 /*83*/ { "jnb", FALSE
, NONE
, op1(Dl
), 0 },
223 /*84*/ { "jz", FALSE
, NONE
, op1(Dl
), 0 },
224 /*85*/ { "jnz", FALSE
, NONE
, op1(Dl
), 0 },
225 /*86*/ { "jbe", FALSE
, NONE
, op1(Dl
), 0 },
226 /*87*/ { "jnbe", FALSE
, NONE
, op1(Dl
), 0 },
228 /*88*/ { "js", FALSE
, NONE
, op1(Dl
), 0 },
229 /*89*/ { "jns", FALSE
, NONE
, op1(Dl
), 0 },
230 /*8a*/ { "jp", FALSE
, NONE
, op1(Dl
), 0 },
231 /*8b*/ { "jnp", FALSE
, NONE
, op1(Dl
), 0 },
232 /*8c*/ { "jl", FALSE
, NONE
, op1(Dl
), 0 },
233 /*8d*/ { "jnl", FALSE
, NONE
, op1(Dl
), 0 },
234 /*8e*/ { "jle", FALSE
, NONE
, op1(Dl
), 0 },
235 /*8f*/ { "jnle", FALSE
, NONE
, op1(Dl
), 0 },
238 static const struct inst db_inst_0f9x
[] = {
239 /*90*/ { "seto", TRUE
, NONE
, op1(Eb
), 0 },
240 /*91*/ { "setno", TRUE
, NONE
, op1(Eb
), 0 },
241 /*92*/ { "setb", TRUE
, NONE
, op1(Eb
), 0 },
242 /*93*/ { "setnb", TRUE
, NONE
, op1(Eb
), 0 },
243 /*94*/ { "setz", TRUE
, NONE
, op1(Eb
), 0 },
244 /*95*/ { "setnz", TRUE
, NONE
, op1(Eb
), 0 },
245 /*96*/ { "setbe", TRUE
, NONE
, op1(Eb
), 0 },
246 /*97*/ { "setnbe",TRUE
, NONE
, op1(Eb
), 0 },
248 /*98*/ { "sets", TRUE
, NONE
, op1(Eb
), 0 },
249 /*99*/ { "setns", TRUE
, NONE
, op1(Eb
), 0 },
250 /*9a*/ { "setp", TRUE
, NONE
, op1(Eb
), 0 },
251 /*9b*/ { "setnp", TRUE
, NONE
, op1(Eb
), 0 },
252 /*9c*/ { "setl", TRUE
, NONE
, op1(Eb
), 0 },
253 /*9d*/ { "setnl", TRUE
, NONE
, op1(Eb
), 0 },
254 /*9e*/ { "setle", TRUE
, NONE
, op1(Eb
), 0 },
255 /*9f*/ { "setnle",TRUE
, NONE
, op1(Eb
), 0 },
258 static const struct inst db_inst_0fax
[] = {
259 /*a0*/ { "push", FALSE
, NONE
, op1(Si
), 0 },
260 /*a1*/ { "pop", FALSE
, NONE
, op1(Si
), 0 },
261 /*a2*/ { "", FALSE
, NONE
, 0, 0 },
262 /*a3*/ { "bt", TRUE
, LONG
, op2(E
,R
), 0 },
263 /*a4*/ { "shld", TRUE
, LONG
, op3(Ib
,E
,R
), 0 },
264 /*a5*/ { "shld", TRUE
, LONG
, op3(CL
,E
,R
), 0 },
265 /*a6*/ { "", FALSE
, NONE
, 0, 0 },
266 /*a7*/ { "", FALSE
, NONE
, 0, 0 },
268 /*a8*/ { "push", FALSE
, NONE
, op1(Si
), 0 },
269 /*a9*/ { "pop", FALSE
, NONE
, op1(Si
), 0 },
270 /*aa*/ { "", FALSE
, NONE
, 0, 0 },
271 /*ab*/ { "bts", TRUE
, LONG
, op2(E
,R
), 0 },
272 /*ac*/ { "shrd", TRUE
, LONG
, op3(Ib
,E
,R
), 0 },
273 /*ad*/ { "shrd", TRUE
, LONG
, op3(CL
,E
,R
), 0 },
274 /*a6*/ { "", FALSE
, NONE
, 0, 0 },
275 /*a7*/ { "imul", TRUE
, LONG
, op2(E
,R
), 0 },
278 static const struct inst db_inst_0fbx
[] = {
279 /*b0*/ { "", FALSE
, NONE
, 0, 0 },
280 /*b1*/ { "", FALSE
, NONE
, 0, 0 },
281 /*b2*/ { "lss", TRUE
, LONG
, op2(E
, R
), 0 },
282 /*b3*/ { "bts", TRUE
, LONG
, op2(R
, E
), 0 },
283 /*b4*/ { "lfs", TRUE
, LONG
, op2(E
, R
), 0 },
284 /*b5*/ { "lgs", TRUE
, LONG
, op2(E
, R
), 0 },
285 /*b6*/ { "movzb", TRUE
, LONG
, op2(E
, R
), 0 },
286 /*b7*/ { "movzw", TRUE
, LONG
, op2(E
, R
), 0 },
288 /*b8*/ { "", FALSE
, NONE
, 0, 0 },
289 /*b9*/ { "", FALSE
, NONE
, 0, 0 },
290 /*ba*/ { "", TRUE
, LONG
, op2(Is
, E
), (char *)db_Grp8
},
291 /*bb*/ { "btc", TRUE
, LONG
, op2(R
, E
), 0 },
292 /*bc*/ { "bsf", TRUE
, LONG
, op2(E
, R
), 0 },
293 /*bd*/ { "bsr", TRUE
, LONG
, op2(E
, R
), 0 },
294 /*be*/ { "movsb", TRUE
, LONG
, op2(E
, R
), 0 },
295 /*bf*/ { "movsw", TRUE
, LONG
, op2(E
, R
), 0 },
298 static const struct inst db_inst_0fcx
[] = {
299 /*c0*/ { "xadd", TRUE
, BYTE
, op2(R
, E
), 0 },
300 /*c1*/ { "xadd", TRUE
, LONG
, op2(R
, E
), 0 },
301 /*c2*/ { "", FALSE
, NONE
, 0, 0 },
302 /*c3*/ { "", FALSE
, NONE
, 0, 0 },
303 /*c4*/ { "", FALSE
, NONE
, 0, 0 },
304 /*c5*/ { "", FALSE
, NONE
, 0, 0 },
305 /*c6*/ { "", FALSE
, NONE
, 0, 0 },
306 /*c7*/ { "", FALSE
, NONE
, 0, 0 },
307 /*c8*/ { "bswap", FALSE
, LONG
, op1(Ri
), 0 },
308 /*c9*/ { "bswap", FALSE
, LONG
, op1(Ri
), 0 },
309 /*ca*/ { "bswap", FALSE
, LONG
, op1(Ri
), 0 },
310 /*cb*/ { "bswap", FALSE
, LONG
, op1(Ri
), 0 },
311 /*cc*/ { "bswap", FALSE
, LONG
, op1(Ri
), 0 },
312 /*cd*/ { "bswap", FALSE
, LONG
, op1(Ri
), 0 },
313 /*ce*/ { "bswap", FALSE
, LONG
, op1(Ri
), 0 },
314 /*cf*/ { "bswap", FALSE
, LONG
, op1(Ri
), 0 },
317 static const struct inst db_inst_0fdx
[] = {
318 /*c0*/ { "cmpxchg",TRUE
, BYTE
, op2(R
, E
), 0 },
319 /*c1*/ { "cmpxchg",TRUE
, LONG
, op2(R
, E
), 0 },
320 /*c2*/ { "", FALSE
, NONE
, 0, 0 },
321 /*c3*/ { "", FALSE
, NONE
, 0, 0 },
322 /*c4*/ { "", FALSE
, NONE
, 0, 0 },
323 /*c5*/ { "", FALSE
, NONE
, 0, 0 },
324 /*c6*/ { "", FALSE
, NONE
, 0, 0 },
325 /*c7*/ { "", FALSE
, NONE
, 0, 0 },
326 /*c8*/ { "", FALSE
, NONE
, 0, 0 },
327 /*c9*/ { "", FALSE
, NONE
, 0, 0 },
328 /*ca*/ { "", FALSE
, NONE
, 0, 0 },
329 /*cb*/ { "", FALSE
, NONE
, 0, 0 },
330 /*cc*/ { "", FALSE
, NONE
, 0, 0 },
331 /*cd*/ { "", FALSE
, NONE
, 0, 0 },
332 /*ce*/ { "", FALSE
, NONE
, 0, 0 },
333 /*cf*/ { "", FALSE
, NONE
, 0, 0 },
336 static const struct inst
* const db_inst_0f
[] = {
355 static const char * const db_Esc92
[] = {
356 "fnop", "", "", "", "", "", "", ""
358 static const char * const db_Esc93
[] = {
359 "", "", "", "", "", "", "", ""
361 static const char * const db_Esc94
[] = {
362 "fchs", "fabs", "", "", "ftst", "fxam", "", ""
364 static const char * const db_Esc95
[] = {
365 "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
367 static const char * const db_Esc96
[] = {
368 "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
371 static const char * const db_Esc97
[] = {
372 "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
375 static const char * const db_Esca4
[] = {
376 "", "fucompp","", "", "", "", "", ""
379 static const char * const db_Escb4
[] = {
380 "", "", "fnclex","fninit","", "", "", ""
383 static const char * const db_Esce3
[] = {
384 "", "fcompp","", "", "", "", "", ""
387 static const char * const db_Escf4
[] = {
388 "fnstsw","", "", "", "", "", "", ""
391 static const struct finst db_Esc8
[] = {
392 /*0*/ { "fadd", SNGL
, op2(STI
,ST
), 0 },
393 /*1*/ { "fmul", SNGL
, op2(STI
,ST
), 0 },
394 /*2*/ { "fcom", SNGL
, op2(STI
,ST
), 0 },
395 /*3*/ { "fcomp", SNGL
, op2(STI
,ST
), 0 },
396 /*4*/ { "fsub", SNGL
, op2(STI
,ST
), 0 },
397 /*5*/ { "fsubr", SNGL
, op2(STI
,ST
), 0 },
398 /*6*/ { "fdiv", SNGL
, op2(STI
,ST
), 0 },
399 /*7*/ { "fdivr", SNGL
, op2(STI
,ST
), 0 },
402 static const struct finst db_Esc9
[] = {
403 /*0*/ { "fld", SNGL
, op1(STI
), 0 },
404 /*1*/ { "", NONE
, op1(STI
), "fxch" },
405 /*2*/ { "fst", SNGL
, op1(X
), (char *)db_Esc92
},
406 /*3*/ { "fstp", SNGL
, op1(X
), (char *)db_Esc93
},
407 /*4*/ { "fldenv", NONE
, op1(X
), (char *)db_Esc94
},
408 /*5*/ { "fldcw", NONE
, op1(X
), (char *)db_Esc95
},
409 /*6*/ { "fnstenv",NONE
, op1(X
), (char *)db_Esc96
},
410 /*7*/ { "fnstcw", NONE
, op1(X
), (char *)db_Esc97
},
413 static const struct finst db_Esca
[] = {
414 /*0*/ { "fiadd", WORD
, 0, 0 },
415 /*1*/ { "fimul", WORD
, 0, 0 },
416 /*2*/ { "ficom", WORD
, 0, 0 },
417 /*3*/ { "ficomp", WORD
, 0, 0 },
418 /*4*/ { "fisub", WORD
, op1(X
), (char *)db_Esca4
},
419 /*5*/ { "fisubr", WORD
, 0, 0 },
420 /*6*/ { "fidiv", WORD
, 0, 0 },
421 /*7*/ { "fidivr", WORD
, 0, 0 }
424 static const struct finst db_Escb
[] = {
425 /*0*/ { "fild", WORD
, 0, 0 },
426 /*1*/ { "", NONE
, 0, 0 },
427 /*2*/ { "fist", WORD
, 0, 0 },
428 /*3*/ { "fistp", WORD
, 0, 0 },
429 /*4*/ { "", WORD
, op1(X
), (char *)db_Escb4
},
430 /*5*/ { "fld", EXTR
, 0, 0 },
431 /*6*/ { "", WORD
, 0, 0 },
432 /*7*/ { "fstp", EXTR
, 0, 0 },
435 static const struct finst db_Escc
[] = {
436 /*0*/ { "fadd", DBLR
, op2(ST
,STI
), 0 },
437 /*1*/ { "fmul", DBLR
, op2(ST
,STI
), 0 },
438 /*2*/ { "fcom", DBLR
, op2(ST
,STI
), 0 },
439 /*3*/ { "fcomp", DBLR
, op2(ST
,STI
), 0 },
440 /*4*/ { "fsub", DBLR
, op2(ST
,STI
), "fsubr" },
441 /*5*/ { "fsubr", DBLR
, op2(ST
,STI
), "fsub" },
442 /*6*/ { "fdiv", DBLR
, op2(ST
,STI
), "fdivr" },
443 /*7*/ { "fdivr", DBLR
, op2(ST
,STI
), "fdiv" },
446 static const struct finst db_Escd
[] = {
447 /*0*/ { "fld", DBLR
, op1(STI
), "ffree" },
448 /*1*/ { "", NONE
, 0, 0 },
449 /*2*/ { "fst", DBLR
, op1(STI
), 0 },
450 /*3*/ { "fstp", DBLR
, op1(STI
), 0 },
451 /*4*/ { "frstor", NONE
, op1(STI
), "fucom" },
452 /*5*/ { "", NONE
, op1(STI
), "fucomp" },
453 /*6*/ { "fnsave", NONE
, 0, 0 },
454 /*7*/ { "fnstsw", NONE
, 0, 0 },
457 static const struct finst db_Esce
[] = {
458 /*0*/ { "fiadd", LONG
, op2(ST
,STI
), "faddp" },
459 /*1*/ { "fimul", LONG
, op2(ST
,STI
), "fmulp" },
460 /*2*/ { "ficom", LONG
, 0, 0 },
461 /*3*/ { "ficomp", LONG
, op1(X
), (char *)db_Esce3
},
462 /*4*/ { "fisub", LONG
, op2(ST
,STI
), "fsubrp" },
463 /*5*/ { "fisubr", LONG
, op2(ST
,STI
), "fsubp" },
464 /*6*/ { "fidiv", LONG
, op2(ST
,STI
), "fdivrp" },
465 /*7*/ { "fidivr", LONG
, op2(ST
,STI
), "fdivp" },
468 static const struct finst db_Escf
[] = {
469 /*0*/ { "fild", LONG
, 0, 0 },
470 /*1*/ { "", LONG
, 0, 0 },
471 /*2*/ { "fist", LONG
, 0, 0 },
472 /*3*/ { "fistp", LONG
, 0, 0 },
473 /*4*/ { "fbld", NONE
, op1(XA
), (char *)db_Escf4
},
474 /*5*/ { "fld", QUAD
, 0, 0 },
475 /*6*/ { "fbstp", NONE
, 0, 0 },
476 /*7*/ { "fstp", QUAD
, 0, 0 },
479 static const struct finst
* const db_Esc_inst
[] = {
480 db_Esc8
, db_Esc9
, db_Esca
, db_Escb
,
481 db_Escc
, db_Escd
, db_Esce
, db_Escf
484 static const char * const db_Grp1
[] = {
495 static const char * const db_Grp2
[] = {
506 static const struct inst db_Grp3
[] = {
507 { "test", TRUE
, NONE
, op2(I
,E
), 0 },
508 { "test", TRUE
, NONE
, op2(I
,E
), 0 },
509 { "not", TRUE
, NONE
, op1(E
), 0 },
510 { "neg", TRUE
, NONE
, op1(E
), 0 },
511 { "mul", TRUE
, NONE
, op2(E
,A
), 0 },
512 { "imul", TRUE
, NONE
, op2(E
,A
), 0 },
513 { "div", TRUE
, NONE
, op2(E
,A
), 0 },
514 { "idiv", TRUE
, NONE
, op2(E
,A
), 0 },
517 static const struct inst db_Grp4
[] = {
518 { "inc", TRUE
, BYTE
, op1(E
), 0 },
519 { "dec", TRUE
, BYTE
, op1(E
), 0 },
520 { "", TRUE
, NONE
, 0, 0 },
521 { "", TRUE
, NONE
, 0, 0 },
522 { "", TRUE
, NONE
, 0, 0 },
523 { "", TRUE
, NONE
, 0, 0 },
524 { "", TRUE
, NONE
, 0, 0 },
525 { "", TRUE
, NONE
, 0, 0 }
528 static const struct inst db_Grp5
[] = {
529 { "inc", TRUE
, LONG
, op1(E
), 0 },
530 { "dec", TRUE
, LONG
, op1(E
), 0 },
531 { "call", TRUE
, NONE
, op1(Eind
),0 },
532 { "lcall", TRUE
, NONE
, op1(Eind
),0 },
533 { "jmp", TRUE
, NONE
, op1(Eind
),0 },
534 { "ljmp", TRUE
, NONE
, op1(Eind
),0 },
535 { "push", TRUE
, LONG
, op1(E
), 0 },
536 { "", TRUE
, NONE
, 0, 0 }
539 static const struct inst db_inst_table
[256] = {
540 /*00*/ { "add", TRUE
, BYTE
, op2(R
, E
), 0 },
541 /*01*/ { "add", TRUE
, LONG
, op2(R
, E
), 0 },
542 /*02*/ { "add", TRUE
, BYTE
, op2(E
, R
), 0 },
543 /*03*/ { "add", TRUE
, LONG
, op2(E
, R
), 0 },
544 /*04*/ { "add", FALSE
, BYTE
, op2(Is
, A
), 0 },
545 /*05*/ { "add", FALSE
, LONG
, op2(Is
, A
), 0 },
546 /*06*/ { "push", FALSE
, NONE
, op1(Si
), 0 },
547 /*07*/ { "pop", FALSE
, NONE
, op1(Si
), 0 },
549 /*08*/ { "or", TRUE
, BYTE
, op2(R
, E
), 0 },
550 /*09*/ { "or", TRUE
, LONG
, op2(R
, E
), 0 },
551 /*0a*/ { "or", TRUE
, BYTE
, op2(E
, R
), 0 },
552 /*0b*/ { "or", TRUE
, LONG
, op2(E
, R
), 0 },
553 /*0c*/ { "or", FALSE
, BYTE
, op2(I
, A
), 0 },
554 /*0d*/ { "or", FALSE
, LONG
, op2(I
, A
), 0 },
555 /*0e*/ { "push", FALSE
, NONE
, op1(Si
), 0 },
556 /*0f*/ { "", FALSE
, NONE
, 0, 0 },
558 /*10*/ { "adc", TRUE
, BYTE
, op2(R
, E
), 0 },
559 /*11*/ { "adc", TRUE
, LONG
, op2(R
, E
), 0 },
560 /*12*/ { "adc", TRUE
, BYTE
, op2(E
, R
), 0 },
561 /*13*/ { "adc", TRUE
, LONG
, op2(E
, R
), 0 },
562 /*14*/ { "adc", FALSE
, BYTE
, op2(Is
, A
), 0 },
563 /*15*/ { "adc", FALSE
, LONG
, op2(Is
, A
), 0 },
564 /*16*/ { "push", FALSE
, NONE
, op1(Si
), 0 },
565 /*17*/ { "pop", FALSE
, NONE
, op1(Si
), 0 },
567 /*18*/ { "sbb", TRUE
, BYTE
, op2(R
, E
), 0 },
568 /*19*/ { "sbb", TRUE
, LONG
, op2(R
, E
), 0 },
569 /*1a*/ { "sbb", TRUE
, BYTE
, op2(E
, R
), 0 },
570 /*1b*/ { "sbb", TRUE
, LONG
, op2(E
, R
), 0 },
571 /*1c*/ { "sbb", FALSE
, BYTE
, op2(Is
, A
), 0 },
572 /*1d*/ { "sbb", FALSE
, LONG
, op2(Is
, A
), 0 },
573 /*1e*/ { "push", FALSE
, NONE
, op1(Si
), 0 },
574 /*1f*/ { "pop", FALSE
, NONE
, op1(Si
), 0 },
576 /*20*/ { "and", TRUE
, BYTE
, op2(R
, E
), 0 },
577 /*21*/ { "and", TRUE
, LONG
, op2(R
, E
), 0 },
578 /*22*/ { "and", TRUE
, BYTE
, op2(E
, R
), 0 },
579 /*23*/ { "and", TRUE
, LONG
, op2(E
, R
), 0 },
580 /*24*/ { "and", FALSE
, BYTE
, op2(I
, A
), 0 },
581 /*25*/ { "and", FALSE
, LONG
, op2(I
, A
), 0 },
582 /*26*/ { "", FALSE
, NONE
, 0, 0 },
583 /*27*/ { "aaa", FALSE
, NONE
, 0, 0 },
585 /*28*/ { "sub", TRUE
, BYTE
, op2(R
, E
), 0 },
586 /*29*/ { "sub", TRUE
, LONG
, op2(R
, E
), 0 },
587 /*2a*/ { "sub", TRUE
, BYTE
, op2(E
, R
), 0 },
588 /*2b*/ { "sub", TRUE
, LONG
, op2(E
, R
), 0 },
589 /*2c*/ { "sub", FALSE
, BYTE
, op2(Is
, A
), 0 },
590 /*2d*/ { "sub", FALSE
, LONG
, op2(Is
, A
), 0 },
591 /*2e*/ { "", FALSE
, NONE
, 0, 0 },
592 /*2f*/ { "das", FALSE
, NONE
, 0, 0 },
594 /*30*/ { "xor", TRUE
, BYTE
, op2(R
, E
), 0 },
595 /*31*/ { "xor", TRUE
, LONG
, op2(R
, E
), 0 },
596 /*32*/ { "xor", TRUE
, BYTE
, op2(E
, R
), 0 },
597 /*33*/ { "xor", TRUE
, LONG
, op2(E
, R
), 0 },
598 /*34*/ { "xor", FALSE
, BYTE
, op2(I
, A
), 0 },
599 /*35*/ { "xor", FALSE
, LONG
, op2(I
, A
), 0 },
600 /*36*/ { "", FALSE
, NONE
, 0, 0 },
601 /*37*/ { "daa", FALSE
, NONE
, 0, 0 },
603 /*38*/ { "cmp", TRUE
, BYTE
, op2(R
, E
), 0 },
604 /*39*/ { "cmp", TRUE
, LONG
, op2(R
, E
), 0 },
605 /*3a*/ { "cmp", TRUE
, BYTE
, op2(E
, R
), 0 },
606 /*3b*/ { "cmp", TRUE
, LONG
, op2(E
, R
), 0 },
607 /*3c*/ { "cmp", FALSE
, BYTE
, op2(Is
, A
), 0 },
608 /*3d*/ { "cmp", FALSE
, LONG
, op2(Is
, A
), 0 },
609 /*3e*/ { "", FALSE
, NONE
, 0, 0 },
610 /*3f*/ { "aas", FALSE
, NONE
, 0, 0 },
612 /*40*/ { "inc", FALSE
, LONG
, op1(Ri
), 0 },
613 /*41*/ { "inc", FALSE
, LONG
, op1(Ri
), 0 },
614 /*42*/ { "inc", FALSE
, LONG
, op1(Ri
), 0 },
615 /*43*/ { "inc", FALSE
, LONG
, op1(Ri
), 0 },
616 /*44*/ { "inc", FALSE
, LONG
, op1(Ri
), 0 },
617 /*45*/ { "inc", FALSE
, LONG
, op1(Ri
), 0 },
618 /*46*/ { "inc", FALSE
, LONG
, op1(Ri
), 0 },
619 /*47*/ { "inc", FALSE
, LONG
, op1(Ri
), 0 },
621 /*48*/ { "dec", FALSE
, LONG
, op1(Ri
), 0 },
622 /*49*/ { "dec", FALSE
, LONG
, op1(Ri
), 0 },
623 /*4a*/ { "dec", FALSE
, LONG
, op1(Ri
), 0 },
624 /*4b*/ { "dec", FALSE
, LONG
, op1(Ri
), 0 },
625 /*4c*/ { "dec", FALSE
, LONG
, op1(Ri
), 0 },
626 /*4d*/ { "dec", FALSE
, LONG
, op1(Ri
), 0 },
627 /*4e*/ { "dec", FALSE
, LONG
, op1(Ri
), 0 },
628 /*4f*/ { "dec", FALSE
, LONG
, op1(Ri
), 0 },
630 /*50*/ { "push", FALSE
, LONG
, op1(Ri
), 0 },
631 /*51*/ { "push", FALSE
, LONG
, op1(Ri
), 0 },
632 /*52*/ { "push", FALSE
, LONG
, op1(Ri
), 0 },
633 /*53*/ { "push", FALSE
, LONG
, op1(Ri
), 0 },
634 /*54*/ { "push", FALSE
, LONG
, op1(Ri
), 0 },
635 /*55*/ { "push", FALSE
, LONG
, op1(Ri
), 0 },
636 /*56*/ { "push", FALSE
, LONG
, op1(Ri
), 0 },
637 /*57*/ { "push", FALSE
, LONG
, op1(Ri
), 0 },
639 /*58*/ { "pop", FALSE
, LONG
, op1(Ri
), 0 },
640 /*59*/ { "pop", FALSE
, LONG
, op1(Ri
), 0 },
641 /*5a*/ { "pop", FALSE
, LONG
, op1(Ri
), 0 },
642 /*5b*/ { "pop", FALSE
, LONG
, op1(Ri
), 0 },
643 /*5c*/ { "pop", FALSE
, LONG
, op1(Ri
), 0 },
644 /*5d*/ { "pop", FALSE
, LONG
, op1(Ri
), 0 },
645 /*5e*/ { "pop", FALSE
, LONG
, op1(Ri
), 0 },
646 /*5f*/ { "pop", FALSE
, LONG
, op1(Ri
), 0 },
648 /*60*/ { "pusha", FALSE
, LONG
, 0, 0 },
649 /*61*/ { "popa", FALSE
, LONG
, 0, 0 },
650 /*62*/ { "bound", TRUE
, LONG
, op2(E
, R
), 0 },
651 /*63*/ { "arpl", TRUE
, NONE
, op2(Ew
,Rw
), 0 },
653 /*64*/ { "", FALSE
, NONE
, 0, 0 },
654 /*65*/ { "", FALSE
, NONE
, 0, 0 },
655 /*66*/ { "", FALSE
, NONE
, 0, 0 },
656 /*67*/ { "", FALSE
, NONE
, 0, 0 },
658 /*68*/ { "push", FALSE
, LONG
, op1(I
), 0 },
659 /*69*/ { "imul", TRUE
, LONG
, op3(I
,E
,R
), 0 },
660 /*6a*/ { "push", FALSE
, LONG
, op1(Ib
), 0 },
661 /*6b*/ { "imul", TRUE
, LONG
, op3(Ibs
,E
,R
),0 },
662 /*6c*/ { "ins", FALSE
, BYTE
, op2(DX
, DI
), 0 },
663 /*6d*/ { "ins", FALSE
, LONG
, op2(DX
, DI
), 0 },
664 /*6e*/ { "outs", FALSE
, BYTE
, op2(SI
, DX
), 0 },
665 /*6f*/ { "outs", FALSE
, LONG
, op2(SI
, DX
), 0 },
667 /*70*/ { "jo", FALSE
, NONE
, op1(Db
), 0 },
668 /*71*/ { "jno", FALSE
, NONE
, op1(Db
), 0 },
669 /*72*/ { "jb", FALSE
, NONE
, op1(Db
), 0 },
670 /*73*/ { "jnb", FALSE
, NONE
, op1(Db
), 0 },
671 /*74*/ { "jz", FALSE
, NONE
, op1(Db
), 0 },
672 /*75*/ { "jnz", FALSE
, NONE
, op1(Db
), 0 },
673 /*76*/ { "jbe", FALSE
, NONE
, op1(Db
), 0 },
674 /*77*/ { "jnbe", FALSE
, NONE
, op1(Db
), 0 },
676 /*78*/ { "js", FALSE
, NONE
, op1(Db
), 0 },
677 /*79*/ { "jns", FALSE
, NONE
, op1(Db
), 0 },
678 /*7a*/ { "jp", FALSE
, NONE
, op1(Db
), 0 },
679 /*7b*/ { "jnp", FALSE
, NONE
, op1(Db
), 0 },
680 /*7c*/ { "jl", FALSE
, NONE
, op1(Db
), 0 },
681 /*7d*/ { "jnl", FALSE
, NONE
, op1(Db
), 0 },
682 /*7e*/ { "jle", FALSE
, NONE
, op1(Db
), 0 },
683 /*7f*/ { "jnle", FALSE
, NONE
, op1(Db
), 0 },
685 /*80*/ { "", TRUE
, BYTE
, op2(I
, E
), (char *)db_Grp1
},
686 /*81*/ { "", TRUE
, LONG
, op2(I
, E
), (char *)db_Grp1
},
687 /*82*/ { "", TRUE
, BYTE
, op2(Is
,E
), (char *)db_Grp1
},
688 /*83*/ { "", TRUE
, LONG
, op2(Ibs
,E
), (char *)db_Grp1
},
689 /*84*/ { "test", TRUE
, BYTE
, op2(R
, E
), 0 },
690 /*85*/ { "test", TRUE
, LONG
, op2(R
, E
), 0 },
691 /*86*/ { "xchg", TRUE
, BYTE
, op2(R
, E
), 0 },
692 /*87*/ { "xchg", TRUE
, LONG
, op2(R
, E
), 0 },
694 /*88*/ { "mov", TRUE
, BYTE
, op2(R
, E
), 0 },
695 /*89*/ { "mov", TRUE
, LONG
, op2(R
, E
), 0 },
696 /*8a*/ { "mov", TRUE
, BYTE
, op2(E
, R
), 0 },
697 /*8b*/ { "mov", TRUE
, LONG
, op2(E
, R
), 0 },
698 /*8c*/ { "mov", TRUE
, NONE
, op2(S
, Ew
), 0 },
699 /*8d*/ { "lea", TRUE
, LONG
, op2(E
, R
), 0 },
700 /*8e*/ { "mov", TRUE
, NONE
, op2(Ew
, S
), 0 },
701 /*8f*/ { "pop", TRUE
, LONG
, op1(E
), 0 },
703 /*90*/ { "nop", FALSE
, NONE
, 0, 0 },
704 /*91*/ { "xchg", FALSE
, LONG
, op2(A
, Ri
), 0 },
705 /*92*/ { "xchg", FALSE
, LONG
, op2(A
, Ri
), 0 },
706 /*93*/ { "xchg", FALSE
, LONG
, op2(A
, Ri
), 0 },
707 /*94*/ { "xchg", FALSE
, LONG
, op2(A
, Ri
), 0 },
708 /*95*/ { "xchg", FALSE
, LONG
, op2(A
, Ri
), 0 },
709 /*96*/ { "xchg", FALSE
, LONG
, op2(A
, Ri
), 0 },
710 /*97*/ { "xchg", FALSE
, LONG
, op2(A
, Ri
), 0 },
712 /*98*/ { "cbw", FALSE
, SDEP
, 0, "cwde" }, /* cbw/cwde */
713 /*99*/ { "cwd", FALSE
, SDEP
, 0, "cdq" }, /* cwd/cdq */
714 /*9a*/ { "lcall", FALSE
, NONE
, op1(OS
), 0 },
715 /*9b*/ { "wait", FALSE
, NONE
, 0, 0 },
716 /*9c*/ { "pushf", FALSE
, LONG
, 0, 0 },
717 /*9d*/ { "popf", FALSE
, LONG
, 0, 0 },
718 /*9e*/ { "sahf", FALSE
, NONE
, 0, 0 },
719 /*9f*/ { "lahf", FALSE
, NONE
, 0, 0 },
721 /*a0*/ { "mov", FALSE
, BYTE
, op2(O
, A
), 0 },
722 /*a1*/ { "mov", FALSE
, LONG
, op2(O
, A
), 0 },
723 /*a2*/ { "mov", FALSE
, BYTE
, op2(A
, O
), 0 },
724 /*a3*/ { "mov", FALSE
, LONG
, op2(A
, O
), 0 },
725 /*a4*/ { "movs", FALSE
, BYTE
, op2(SI
,DI
), 0 },
726 /*a5*/ { "movs", FALSE
, LONG
, op2(SI
,DI
), 0 },
727 /*a6*/ { "cmps", FALSE
, BYTE
, op2(SI
,DI
), 0 },
728 /*a7*/ { "cmps", FALSE
, LONG
, op2(SI
,DI
), 0 },
730 /*a8*/ { "test", FALSE
, BYTE
, op2(I
, A
), 0 },
731 /*a9*/ { "test", FALSE
, LONG
, op2(I
, A
), 0 },
732 /*aa*/ { "stos", FALSE
, BYTE
, op1(DI
), 0 },
733 /*ab*/ { "stos", FALSE
, LONG
, op1(DI
), 0 },
734 /*ac*/ { "lods", FALSE
, BYTE
, op1(SI
), 0 },
735 /*ad*/ { "lods", FALSE
, LONG
, op1(SI
), 0 },
736 /*ae*/ { "scas", FALSE
, BYTE
, op1(DI
), 0 },
737 /*af*/ { "scas", FALSE
, LONG
, op1(DI
), 0 },
739 /*b0*/ { "mov", FALSE
, BYTE
, op2(I
, Ri
), 0 },
740 /*b1*/ { "mov", FALSE
, BYTE
, op2(I
, Ri
), 0 },
741 /*b2*/ { "mov", FALSE
, BYTE
, op2(I
, Ri
), 0 },
742 /*b3*/ { "mov", FALSE
, BYTE
, op2(I
, Ri
), 0 },
743 /*b4*/ { "mov", FALSE
, BYTE
, op2(I
, Ri
), 0 },
744 /*b5*/ { "mov", FALSE
, BYTE
, op2(I
, Ri
), 0 },
745 /*b6*/ { "mov", FALSE
, BYTE
, op2(I
, Ri
), 0 },
746 /*b7*/ { "mov", FALSE
, BYTE
, op2(I
, Ri
), 0 },
748 /*b8*/ { "mov", FALSE
, LONG
, op2(I
, Ri
), 0 },
749 /*b9*/ { "mov", FALSE
, LONG
, op2(I
, Ri
), 0 },
750 /*ba*/ { "mov", FALSE
, LONG
, op2(I
, Ri
), 0 },
751 /*bb*/ { "mov", FALSE
, LONG
, op2(I
, Ri
), 0 },
752 /*bc*/ { "mov", FALSE
, LONG
, op2(I
, Ri
), 0 },
753 /*bd*/ { "mov", FALSE
, LONG
, op2(I
, Ri
), 0 },
754 /*be*/ { "mov", FALSE
, LONG
, op2(I
, Ri
), 0 },
755 /*bf*/ { "mov", FALSE
, LONG
, op2(I
, Ri
), 0 },
757 /*c0*/ { "", TRUE
, BYTE
, op2(Ib
, E
), (char *)db_Grp2
},
758 /*c1*/ { "", TRUE
, LONG
, op2(Ib
, E
), (char *)db_Grp2
},
759 /*c2*/ { "ret", FALSE
, NONE
, op1(Iw
), 0 },
760 /*c3*/ { "ret", FALSE
, NONE
, 0, 0 },
761 /*c4*/ { "les", TRUE
, LONG
, op2(E
, R
), 0 },
762 /*c5*/ { "lds", TRUE
, LONG
, op2(E
, R
), 0 },
763 /*c6*/ { "mov", TRUE
, BYTE
, op2(I
, E
), 0 },
764 /*c7*/ { "mov", TRUE
, LONG
, op2(I
, E
), 0 },
766 /*c8*/ { "enter", FALSE
, NONE
, op2(Ib
, Iw
), 0 },
767 /*c9*/ { "leave", FALSE
, NONE
, 0, 0 },
768 /*ca*/ { "lret", FALSE
, NONE
, op1(Iw
), 0 },
769 /*cb*/ { "lret", FALSE
, NONE
, 0, 0 },
770 /*cc*/ { "int", FALSE
, NONE
, op1(o3
), 0 },
771 /*cd*/ { "int", FALSE
, NONE
, op1(Ib
), 0 },
772 /*ce*/ { "into", FALSE
, NONE
, 0, 0 },
773 /*cf*/ { "iret", FALSE
, NONE
, 0, 0 },
775 /*d0*/ { "", TRUE
, BYTE
, op2(o1
, E
), (char *)db_Grp2
},
776 /*d1*/ { "", TRUE
, LONG
, op2(o1
, E
), (char *)db_Grp2
},
777 /*d2*/ { "", TRUE
, BYTE
, op2(CL
, E
), (char *)db_Grp2
},
778 /*d3*/ { "", TRUE
, LONG
, op2(CL
, E
), (char *)db_Grp2
},
779 /*d4*/ { "aam", TRUE
, NONE
, 0, 0 },
780 /*d5*/ { "aad", TRUE
, NONE
, 0, 0 },
781 /*d6*/ { "", FALSE
, NONE
, 0, 0 },
782 /*d7*/ { "xlat", FALSE
, BYTE
, op1(BX
), 0 },
784 /*d8*/ { "", TRUE
, NONE
, 0, (char *)db_Esc8
},
785 /*d9*/ { "", TRUE
, NONE
, 0, (char *)db_Esc9
},
786 /*da*/ { "", TRUE
, NONE
, 0, (char *)db_Esca
},
787 /*db*/ { "", TRUE
, NONE
, 0, (char *)db_Escb
},
788 /*dc*/ { "", TRUE
, NONE
, 0, (char *)db_Escc
},
789 /*dd*/ { "", TRUE
, NONE
, 0, (char *)db_Escd
},
790 /*de*/ { "", TRUE
, NONE
, 0, (char *)db_Esce
},
791 /*df*/ { "", TRUE
, NONE
, 0, (char *)db_Escf
},
793 /*e0*/ { "loopne",FALSE
, NONE
, op1(Db
), 0 },
794 /*e1*/ { "loope", FALSE
, NONE
, op1(Db
), 0 },
795 /*e2*/ { "loop", FALSE
, NONE
, op1(Db
), 0 },
796 /*e3*/ { "jcxz", FALSE
, SDEP
, op1(Db
), "jecxz" },
797 /*e4*/ { "in", FALSE
, BYTE
, op2(Ib
, A
), 0 },
798 /*e5*/ { "in", FALSE
, LONG
, op2(Ib
, A
) , 0 },
799 /*e6*/ { "out", FALSE
, BYTE
, op2(A
, Ib
), 0 },
800 /*e7*/ { "out", FALSE
, LONG
, op2(A
, Ib
) , 0 },
802 /*e8*/ { "call", FALSE
, NONE
, op1(Dl
), 0 },
803 /*e9*/ { "jmp", FALSE
, NONE
, op1(Dl
), 0 },
804 /*ea*/ { "ljmp", FALSE
, NONE
, op1(OS
), 0 },
805 /*eb*/ { "jmp", FALSE
, NONE
, op1(Db
), 0 },
806 /*ec*/ { "in", FALSE
, BYTE
, op2(DX
, A
), 0 },
807 /*ed*/ { "in", FALSE
, LONG
, op2(DX
, A
) , 0 },
808 /*ee*/ { "out", FALSE
, BYTE
, op2(A
, DX
), 0 },
809 /*ef*/ { "out", FALSE
, LONG
, op2(A
, DX
) , 0 },
811 /*f0*/ { "", FALSE
, NONE
, 0, 0 },
812 /*f1*/ { "", FALSE
, NONE
, 0, 0 },
813 /*f2*/ { "", FALSE
, NONE
, 0, 0 },
814 /*f3*/ { "", FALSE
, NONE
, 0, 0 },
815 /*f4*/ { "hlt", FALSE
, NONE
, 0, 0 },
816 /*f5*/ { "cmc", FALSE
, NONE
, 0, 0 },
817 /*f6*/ { "", TRUE
, BYTE
, 0, (char *)db_Grp3
},
818 /*f7*/ { "", TRUE
, LONG
, 0, (char *)db_Grp3
},
820 /*f8*/ { "clc", FALSE
, NONE
, 0, 0 },
821 /*f9*/ { "stc", FALSE
, NONE
, 0, 0 },
822 /*fa*/ { "cli", FALSE
, NONE
, 0, 0 },
823 /*fb*/ { "sti", FALSE
, NONE
, 0, 0 },
824 /*fc*/ { "cld", FALSE
, NONE
, 0, 0 },
825 /*fd*/ { "std", FALSE
, NONE
, 0, 0 },
826 /*fe*/ { "", TRUE
, NONE
, 0, (char *)db_Grp4
},
827 /*ff*/ { "", TRUE
, NONE
, 0, (char *)db_Grp5
},
830 static const struct inst db_bad_inst
=
831 { "???", FALSE
, NONE
, 0, 0 }
834 #define f_mod(byte) ((byte)>>6)
835 #define f_reg(byte) (((byte)>>3)&0x7)
836 #define f_rm(byte) ((byte)&0x7)
838 #define sib_ss(byte) ((byte)>>6)
839 #define sib_index(byte) (((byte)>>3)&0x7)
840 #define sib_base(byte) ((byte)&0x7)
843 int is_reg
; /* if reg, reg number is in 'disp' */
850 static const char * const db_index_reg_16
[8] = {
861 static const char * const db_reg
[3][8] = {
862 { "%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh" },
863 { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di" },
864 { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi" }
867 static const char * const db_seg_reg
[8] = {
868 "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
872 * lengths for size attributes
874 static const int db_lengths
[] = {
884 static unsigned int db_get_task_value( const DBG_ADDR
*addr
,
885 int size
, int is_signed
)
888 unsigned char *p
= DBG_ADDR_TO_LIN( addr
);
893 if (is_signed
) result
= (unsigned int) *(int *)p
;
894 else result
= *(unsigned int *)p
;
897 if (is_signed
) result
= (unsigned int) *(short int *)p
;
898 else result
= *(unsigned short int *)p
;
901 if (is_signed
) result
= (unsigned int) *(char *)p
;
902 else result
= *(unsigned char *)p
;
905 fprintf(stderr
, "Illegal size specified\n");
912 #define get_value_inc(result, addr, size, is_signed) \
913 result = db_get_task_value((addr), (size), (is_signed)); \
914 if (!db_disasm_16) (addr)->off += (size); \
915 else (addr)->off = ((addr)->off + (size)) & 0xffff;
918 * Read address at location and return updated location.
920 void db_read_address( DBG_ADDR
*addr
, int short_addr
, int regmodrm
,
921 struct i_addr
*addrp
)
923 int mod
, rm
, sib
, index
, disp
;
925 mod
= f_mod(regmodrm
);
929 addrp
->is_reg
= TRUE
;
933 addrp
->is_reg
= FALSE
;
942 get_value_inc(disp
, addr
, 2, TRUE
);
948 addrp
->base
= db_index_reg_16
[rm
];
952 get_value_inc(disp
, addr
, 1, TRUE
);
954 addrp
->base
= db_index_reg_16
[rm
];
957 get_value_inc(disp
, addr
, 2, TRUE
);
959 addrp
->base
= db_index_reg_16
[rm
];
964 if (mod
!= 3 && rm
== 4) {
965 get_value_inc(sib
, addr
, 1, FALSE
);
967 index
= sib_index(sib
);
969 addrp
->index
= db_reg
[LONG
][index
];
970 addrp
->ss
= sib_ss(sib
);
976 get_value_inc(addrp
->disp
, addr
, 4, FALSE
);
981 addrp
->base
= db_reg
[LONG
][rm
];
986 get_value_inc(disp
, addr
, 1, TRUE
);
988 addrp
->base
= db_reg
[LONG
][rm
];
992 get_value_inc(disp
, addr
, 4, FALSE
);
994 addrp
->base
= db_reg
[LONG
][rm
];
1000 static void db_task_printsym(unsigned int addr
, int size
)
1005 fprintf(stderr
, "0x%2.2x", addr
& 0xff );
1008 fprintf(stderr
, "0x%4.4x", addr
& 0xffff );
1012 DBG_ADDR address
= { 0, addr
};
1013 DEBUG_PrintAddress( &address
, db_disasm_16
? 16 : 32, TRUE
);
1020 db_print_address(seg
, size
, addrp
)
1023 struct i_addr
*addrp
;
1025 if (addrp
->is_reg
) {
1026 fprintf(stderr
,"%s", db_reg
[size
][addrp
->disp
]);
1031 fprintf(stderr
,"%s:", seg
);
1034 if (addrp
->base
!= 0 || addrp
->index
!= 0) {
1035 fprintf(stderr
,"0x%x", addrp
->disp
);
1036 fprintf(stderr
,"(");
1038 fprintf(stderr
,"%s", addrp
->base
);
1040 fprintf(stderr
,",%s,%d", addrp
->index
, 1<<addrp
->ss
);
1041 fprintf(stderr
,")");
1043 db_task_printsym(addrp
->disp
, size
);
1047 * Disassemble floating-point ("escape") instruction
1048 * and return updated location.
1050 void db_disasm_esc( DBG_ADDR
*addr
, int inst
, int short_addr
,
1051 int size
, char *seg
)
1054 const struct finst
*fp
;
1056 struct i_addr address
;
1059 get_value_inc(regmodrm
, addr
, 1, FALSE
);
1060 fp
= &db_Esc_inst
[inst
- 0xd8][f_reg(regmodrm
)];
1061 mod
= f_mod(regmodrm
);
1064 * Normal address modes.
1066 db_read_address( addr
, short_addr
, regmodrm
, &address
);
1067 fprintf(stderr
,fp
->f_name
);
1068 switch(fp
->f_size
) {
1070 fprintf(stderr
,"s");
1073 fprintf(stderr
,"l");
1076 fprintf(stderr
,"t");
1079 fprintf(stderr
,"s");
1082 fprintf(stderr
,"l");
1085 fprintf(stderr
,"q");
1090 fprintf(stderr
,"\t");
1091 db_print_address(seg
, BYTE
, &address
);
1095 * 'reg-reg' - special formats
1097 switch (fp
->f_rrmode
) {
1099 name
= (fp
->f_rrname
) ? fp
->f_rrname
: fp
->f_name
;
1100 fprintf(stderr
,"%s\t%%st,%%st(%d)",name
,f_rm(regmodrm
));
1103 name
= (fp
->f_rrname
) ? fp
->f_rrname
: fp
->f_name
;
1104 fprintf(stderr
,"%s\t%%st(%d),%%st",name
, f_rm(regmodrm
));
1107 name
= (fp
->f_rrname
) ? fp
->f_rrname
: fp
->f_name
;
1108 fprintf(stderr
,"%s\t%%st(%d)",name
, f_rm(regmodrm
));
1111 fprintf(stderr
,"%s", ((char **)fp
->f_rrname
)[f_rm(regmodrm
)]);
1114 fprintf(stderr
,"%s\t%%ax",
1115 ((char **)fp
->f_rrname
)[f_rm(regmodrm
)]);
1118 fprintf(stderr
,"<bad instruction>");
1125 /***********************************************************************
1128 * Disassemble instruction at 'addr'. addr is changed to point to the
1129 * start of the next instruction.
1131 void DEBUG_Disasm( DBG_ADDR
*addr
)
1137 const struct inst
*ip
;
1147 struct i_addr address
;
1149 if (!addr
->seg
) db_disasm_16
= FALSE
;
1150 else db_disasm_16
= !(GET_SEL_FLAGS(addr
->seg
) & LDT_FLAGS_32BIT
);
1152 get_value_inc( inst
, addr
, 1, FALSE
);
1170 case 0x66: /* data16 */
1177 short_addr
= !short_addr
;
1198 fprintf(stderr
,"lock ");
1201 fprintf(stderr
,"repne ");
1204 fprintf(stderr
,"repe "); /* XXX repe VS rep */
1211 get_value_inc(inst
, addr
, 1, FALSE
);
1215 if (inst
>= 0xd8 && inst
<= 0xdf)
1217 db_disasm_esc( addr
, inst
, short_addr
, size
, seg
);
1222 get_value_inc(inst
, addr
, 1, FALSE
);
1223 ip
= db_inst_0f
[inst
>>4];
1232 ip
= &db_inst_table
[inst
];
1234 if (ip
->i_has_modrm
) {
1235 get_value_inc(regmodrm
, addr
, 1, FALSE
);
1236 db_read_address( addr
, short_addr
, regmodrm
, &address
);
1239 i_name
= ip
->i_name
;
1240 i_size
= ip
->i_size
;
1241 i_mode
= ip
->i_mode
;
1243 if (ip
->i_extra
== (char *)db_Grp1
||
1244 ip
->i_extra
== (char *)db_Grp2
||
1245 ip
->i_extra
== (char *)db_Grp6
||
1246 ip
->i_extra
== (char *)db_Grp7
||
1247 ip
->i_extra
== (char *)db_Grp8
) {
1248 i_name
= ((char **)ip
->i_extra
)[f_reg(regmodrm
)];
1250 else if (ip
->i_extra
== (char *)db_Grp3
) {
1251 ip
= (struct inst
*)ip
->i_extra
;
1252 ip
= &ip
[f_reg(regmodrm
)];
1253 i_name
= ip
->i_name
;
1254 i_mode
= ip
->i_mode
;
1256 else if (ip
->i_extra
== (char *)db_Grp4
||
1257 ip
->i_extra
== (char *)db_Grp5
) {
1258 ip
= (struct inst
*)ip
->i_extra
;
1259 ip
= &ip
[f_reg(regmodrm
)];
1260 i_name
= ip
->i_name
;
1261 i_mode
= ip
->i_mode
;
1262 i_size
= ip
->i_size
;
1265 if (i_size
== SDEP
) {
1267 fprintf(stderr
,i_name
);
1269 fprintf(stderr
,ip
->i_extra
);
1272 fprintf(stderr
,i_name
);
1273 if (i_size
!= NONE
) {
1274 if (i_size
== BYTE
) {
1275 fprintf(stderr
,"b");
1278 else if (i_size
== WORD
) {
1279 fprintf(stderr
,"w");
1282 else if (size
== WORD
)
1283 fprintf(stderr
,"w");
1285 fprintf(stderr
,"l");
1288 fprintf(stderr
,"\t");
1291 i_mode
>>= 8, first
= FALSE
)
1294 fprintf(stderr
,",");
1296 switch (i_mode
& 0xFF) {
1299 db_print_address(seg
, size
, &address
);
1303 fprintf(stderr
,"*");
1304 db_print_address(seg
, size
, &address
);
1308 db_print_address(seg
, WORD
, &address
);
1312 db_print_address(seg
, BYTE
, &address
);
1316 fprintf(stderr
,"%s", db_reg
[size
][f_reg(regmodrm
)]);
1320 fprintf(stderr
,"%s", db_reg
[WORD
][f_reg(regmodrm
)]);
1324 fprintf(stderr
,"%s", db_reg
[size
][f_rm(inst
)]);
1328 fprintf(stderr
,"%s", db_seg_reg
[f_reg(regmodrm
)]);
1332 fprintf(stderr
,"%s", db_seg_reg
[f_reg(inst
)]);
1336 fprintf(stderr
,"%s", db_reg
[size
][0]); /* acc */
1341 fprintf(stderr
,"%s:", seg
);
1342 fprintf(stderr
,"(%s)", short_addr
? "%bx" : "%ebx");
1346 fprintf(stderr
,"%%cl");
1350 fprintf(stderr
,"%%dx");
1355 fprintf(stderr
,"%s:", seg
);
1356 fprintf(stderr
,"(%s)", short_addr
? "%si" : "%esi");
1360 fprintf(stderr
,"%%es:(%s)", short_addr
? "%di" : "%edi");
1364 fprintf(stderr
,"%%cr%d", f_reg(regmodrm
));
1368 fprintf(stderr
,"%%dr%d", f_reg(regmodrm
));
1372 fprintf(stderr
,"%%tr%d", f_reg(regmodrm
));
1376 len
= db_lengths
[size
];
1377 get_value_inc(imm
, addr
, len
, FALSE
);/* unsigned */
1378 fprintf(stderr
,"$0x%x", imm
);
1382 len
= db_lengths
[size
];
1383 get_value_inc(imm
, addr
, len
, TRUE
); /* signed */
1384 fprintf(stderr
,"$%d", imm
);
1388 get_value_inc(imm
, addr
, 1, FALSE
); /* unsigned */
1389 fprintf(stderr
,"$0x%x", imm
);
1393 get_value_inc(imm
, addr
, 1, TRUE
); /* signed */
1394 fprintf(stderr
,"$%d", imm
);
1398 get_value_inc(imm
, addr
, 2, FALSE
); /* unsigned */
1399 fprintf(stderr
,"$0x%x", imm
);
1403 get_value_inc(imm
, addr
, 4, FALSE
);
1404 fprintf(stderr
,"$0x%x", imm
);
1409 get_value_inc(displ
, addr
, 2, TRUE
);
1412 get_value_inc(displ
, addr
, 4, TRUE
);
1415 fprintf(stderr
,"%s:%d",seg
, displ
);
1417 db_task_printsym(displ
, short_addr
? WORD
: LONG
);
1421 get_value_inc(displ
, addr
, 1, TRUE
);
1423 /* offset only affects low 16 bits */
1424 displ
= (addr
->off
& 0xffff0000)
1425 | ((addr
->off
+ displ
) & 0xffff);
1427 else displ
+= addr
->off
;
1428 db_task_printsym(displ
, short_addr
? WORD
: LONG
);
1433 get_value_inc(displ
, addr
, 2, TRUE
);
1434 /* offset only affects low 16 bits */
1435 displ
= (addr
->off
& 0xffff0000)
1436 | ((addr
->off
+ displ
) & 0xffff);
1439 get_value_inc(displ
, addr
, 4, TRUE
);
1442 db_task_printsym( displ
, short_addr
? WORD
: LONG
);
1446 fprintf(stderr
,"$1");
1450 fprintf(stderr
,"$3");
1456 get_value_inc( address
.off
, addr
, /* offset */
1457 short_addr
? 2 : 4, FALSE
);
1458 get_value_inc( address
.seg
, addr
, /* segment */
1460 DEBUG_PrintAddress( &address
, short_addr
? 16 : 32,