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.
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.
69 * Switch to disassemble 16-bit code.
71 static BOOL db_disasm_16 = FALSE;
74 * Flag to indicate whether we need to display instruction,
75 * or whether we just need to know the address of the next
78 static BOOL db_display = FALSE;
96 #define E 1 /* general effective address */
97 #define Eind 2 /* indirect address (jump, call) */
98 #define Ew 3 /* address, word size */
99 #define Eb 4 /* address, byte size */
100 #define R 5 /* register, in 'reg' field */
101 #define Rw 6 /* word register, in 'reg' field */
102 #define Ri 7 /* register in instruction */
103 #define S 8 /* segment reg, in 'reg' field */
104 #define Si 9 /* segment reg, in instruction */
105 #define A 10 /* accumulator */
106 #define BX 11 /* (bx) */
107 #define CL 12 /* cl, for shifts */
108 #define DX 13 /* dx, for IO */
109 #define SI 14 /* si */
110 #define DI 15 /* di */
111 #define CR 16 /* control register */
112 #define DR 17 /* debug register */
113 #define TR 18 /* test register */
114 #define I 19 /* immediate, unsigned */
115 #define Is 20 /* immediate, signed */
116 #define Ib 21 /* byte immediate, unsigned */
117 #define Ibs 22 /* byte immediate, signed */
118 #define Iw 23 /* word immediate, unsigned */
119 #define Il 24 /* long immediate */
120 #define O 25 /* direct address */
121 #define Db 26 /* byte displacement from EIP */
122 #define Dl 27 /* long displacement from EIP */
123 #define o1 28 /* constant 1 */
124 #define o3 29 /* constant 3 */
125 #define OS 30 /* immediate offset/segment */
126 #define ST 31 /* FP stack top */
127 #define STI 32 /* FP stack */
128 #define X 33 /* extended FP op */
129 #define XA 34 /* for 'fstcw %ax' */
132 const char *i_name; /* name */
133 short i_has_modrm; /* has regmodrm byte */
134 short i_size; /* operand size */
135 int i_mode; /* addressing modes */
136 const char *i_extra; /* pointer to extra opcode table */
140 #define op2(x,y) ((x)|((y)<<8))
141 #define op3(x,y,z) ((x)|((y)<<8)|((z)<<16))
144 const char *f_name; /* name for memory instruction */
145 int f_size; /* size for memory instruction */
146 int f_rrmode; /* mode for rr instruction */
147 const char *f_rrname; /* name for rr instruction
148 (or pointer to table) */
151 static const char * const db_Grp6[] = {
162 static const char * const db_Grp7[] = {
173 static const char * const db_Grp8[] = {
184 static const struct inst db_inst_0f0x[] = {
185 /*00*/ { "", TRUE, NONE, op1(Ew), (char *)db_Grp6 },
186 /*01*/ { "", TRUE, NONE, op1(Ew), (char *)db_Grp7 },
187 /*02*/ { "lar", TRUE, LONG, op2(E,R), 0 },
188 /*03*/ { "lsl", TRUE, LONG, op2(E,R), 0 },
189 /*04*/ { "", FALSE, NONE, 0, 0 },
190 /*05*/ { "", FALSE, NONE, 0, 0 },
191 /*06*/ { "clts", FALSE, NONE, 0, 0 },
192 /*07*/ { "", FALSE, NONE, 0, 0 },
194 /*08*/ { "invd", FALSE, NONE, 0, 0 },
195 /*09*/ { "wbinvd",FALSE, NONE, 0, 0 },
196 /*0a*/ { "", FALSE, NONE, 0, 0 },
197 /*0b*/ { "", FALSE, NONE, 0, 0 },
198 /*0c*/ { "", FALSE, NONE, 0, 0 },
199 /*0d*/ { "", FALSE, NONE, 0, 0 },
200 /*0e*/ { "", FALSE, NONE, 0, 0 },
201 /*0f*/ { "", FALSE, NONE, 0, 0 },
204 static const struct inst db_inst_0f2x[] = {
205 /*20*/ { "mov", TRUE, LONG, op2(CR,E), 0 }, /* use E for reg */
206 /*21*/ { "mov", TRUE, LONG, op2(DR,E), 0 }, /* since mod == 11 */
207 /*22*/ { "mov", TRUE, LONG, op2(E,CR), 0 },
208 /*23*/ { "mov", TRUE, LONG, op2(E,DR), 0 },
209 /*24*/ { "mov", TRUE, LONG, op2(TR,E), 0 },
210 /*25*/ { "", FALSE, NONE, 0, 0 },
211 /*26*/ { "mov", TRUE, LONG, op2(E,TR), 0 },
212 /*27*/ { "", FALSE, NONE, 0, 0 },
214 /*28*/ { "", FALSE, NONE, 0, 0 },
215 /*29*/ { "", FALSE, NONE, 0, 0 },
216 /*2a*/ { "", FALSE, NONE, 0, 0 },
217 /*2b*/ { "", FALSE, NONE, 0, 0 },
218 /*2c*/ { "", FALSE, NONE, 0, 0 },
219 /*2d*/ { "", FALSE, NONE, 0, 0 },
220 /*2e*/ { "", FALSE, NONE, 0, 0 },
221 /*2f*/ { "", FALSE, NONE, 0, 0 },
224 static const struct inst db_inst_0f8x[] = {
225 /*80*/ { "jo", FALSE, NONE, op1(Dl), 0 },
226 /*81*/ { "jno", FALSE, NONE, op1(Dl), 0 },
227 /*82*/ { "jb", FALSE, NONE, op1(Dl), 0 },
228 /*83*/ { "jnb", FALSE, NONE, op1(Dl), 0 },
229 /*84*/ { "jz", FALSE, NONE, op1(Dl), 0 },
230 /*85*/ { "jnz", FALSE, NONE, op1(Dl), 0 },
231 /*86*/ { "jbe", FALSE, NONE, op1(Dl), 0 },
232 /*87*/ { "jnbe", FALSE, NONE, op1(Dl), 0 },
234 /*88*/ { "js", FALSE, NONE, op1(Dl), 0 },
235 /*89*/ { "jns", FALSE, NONE, op1(Dl), 0 },
236 /*8a*/ { "jp", FALSE, NONE, op1(Dl), 0 },
237 /*8b*/ { "jnp", FALSE, NONE, op1(Dl), 0 },
238 /*8c*/ { "jl", FALSE, NONE, op1(Dl), 0 },
239 /*8d*/ { "jnl", FALSE, NONE, op1(Dl), 0 },
240 /*8e*/ { "jle", FALSE, NONE, op1(Dl), 0 },
241 /*8f*/ { "jnle", FALSE, NONE, op1(Dl), 0 },
244 static const struct inst db_inst_0f9x[] = {
245 /*90*/ { "seto", TRUE, NONE, op1(Eb), 0 },
246 /*91*/ { "setno", TRUE, NONE, op1(Eb), 0 },
247 /*92*/ { "setb", TRUE, NONE, op1(Eb), 0 },
248 /*93*/ { "setnb", TRUE, NONE, op1(Eb), 0 },
249 /*94*/ { "setz", TRUE, NONE, op1(Eb), 0 },
250 /*95*/ { "setnz", TRUE, NONE, op1(Eb), 0 },
251 /*96*/ { "setbe", TRUE, NONE, op1(Eb), 0 },
252 /*97*/ { "setnbe",TRUE, NONE, op1(Eb), 0 },
254 /*98*/ { "sets", TRUE, NONE, op1(Eb), 0 },
255 /*99*/ { "setns", TRUE, NONE, op1(Eb), 0 },
256 /*9a*/ { "setp", TRUE, NONE, op1(Eb), 0 },
257 /*9b*/ { "setnp", TRUE, NONE, op1(Eb), 0 },
258 /*9c*/ { "setl", TRUE, NONE, op1(Eb), 0 },
259 /*9d*/ { "setnl", TRUE, NONE, op1(Eb), 0 },
260 /*9e*/ { "setle", TRUE, NONE, op1(Eb), 0 },
261 /*9f*/ { "setnle",TRUE, NONE, op1(Eb), 0 },
264 static const struct inst db_inst_0fax[] = {
265 /*a0*/ { "push", FALSE, NONE, op1(Si), 0 },
266 /*a1*/ { "pop", FALSE, NONE, op1(Si), 0 },
267 /*a2*/ { "cpuid", FALSE, NONE, 0, 0 },
268 /*a3*/ { "bt", TRUE, LONG, op2(E,R), 0 },
269 /*a4*/ { "shld", TRUE, LONG, op3(Ib,E,R), 0 },
270 /*a5*/ { "shld", TRUE, LONG, op3(CL,E,R), 0 },
271 /*a6*/ { "", FALSE, NONE, 0, 0 },
272 /*a7*/ { "", FALSE, NONE, 0, 0 },
274 /*a8*/ { "push", FALSE, NONE, op1(Si), 0 },
275 /*a9*/ { "pop", FALSE, NONE, op1(Si), 0 },
276 /*aa*/ { "", FALSE, NONE, 0, 0 },
277 /*ab*/ { "bts", TRUE, LONG, op2(E,R), 0 },
278 /*ac*/ { "shrd", TRUE, LONG, op3(Ib,E,R), 0 },
279 /*ad*/ { "shrd", TRUE, LONG, op3(CL,E,R), 0 },
280 /*a6*/ { "", FALSE, NONE, 0, 0 },
281 /*a7*/ { "imul", TRUE, LONG, op2(E,R), 0 },
284 static const struct inst db_inst_0fbx[] = {
285 /*b0*/ { "cmpxchg",TRUE, BYTE, op2(E, R), 0 },
286 /*b1*/ { "cmpxchg",TRUE, LONG, op2(E, R), 0 },
287 /*b2*/ { "lss", TRUE, LONG, op2(E, R), 0 },
288 /*b3*/ { "bts", TRUE, LONG, op2(R, E), 0 },
289 /*b4*/ { "lfs", TRUE, LONG, op2(E, R), 0 },
290 /*b5*/ { "lgs", TRUE, LONG, op2(E, R), 0 },
291 /*b6*/ { "movzb", TRUE, LONG, op2(E, R), 0 },
292 /*b7*/ { "movzw", TRUE, LONG, op2(E, R), 0 },
294 /*b8*/ { "", FALSE, NONE, 0, 0 },
295 /*b9*/ { "", FALSE, NONE, 0, 0 },
296 /*ba*/ { "", TRUE, LONG, op2(Ib, E), (char *)db_Grp8 },
297 /*bb*/ { "btc", TRUE, LONG, op2(R, E), 0 },
298 /*bc*/ { "bsf", TRUE, LONG, op2(E, R), 0 },
299 /*bd*/ { "bsr", TRUE, LONG, op2(E, R), 0 },
300 /*be*/ { "movsb", TRUE, LONG, op2(E, R), 0 },
301 /*bf*/ { "movsw", TRUE, LONG, op2(E, R), 0 },
304 static const struct inst db_inst_0fcx[] = {
305 /*c0*/ { "xadd", TRUE, BYTE, op2(R, E), 0 },
306 /*c1*/ { "xadd", TRUE, LONG, op2(R, E), 0 },
307 /*c2*/ { "", FALSE, NONE, 0, 0 },
308 /*c3*/ { "", FALSE, NONE, 0, 0 },
309 /*c4*/ { "", FALSE, NONE, 0, 0 },
310 /*c5*/ { "", FALSE, NONE, 0, 0 },
311 /*c6*/ { "", FALSE, NONE, 0, 0 },
312 /*c7*/ { "", FALSE, NONE, 0, 0 },
313 /*c8*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
314 /*c9*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
315 /*ca*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
316 /*cb*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
317 /*cc*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
318 /*cd*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
319 /*ce*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
320 /*cf*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
323 static const struct inst db_inst_0fdx[] = {
324 /*c0*/ { "cmpxchg",TRUE, BYTE, op2(R, E), 0 },
325 /*c1*/ { "cmpxchg",TRUE, LONG, op2(R, E), 0 },
326 /*c2*/ { "", FALSE, NONE, 0, 0 },
327 /*c3*/ { "", FALSE, NONE, 0, 0 },
328 /*c4*/ { "", FALSE, NONE, 0, 0 },
329 /*c5*/ { "", FALSE, NONE, 0, 0 },
330 /*c6*/ { "", FALSE, NONE, 0, 0 },
331 /*c7*/ { "", FALSE, NONE, 0, 0 },
332 /*c8*/ { "", FALSE, NONE, 0, 0 },
333 /*c9*/ { "", FALSE, NONE, 0, 0 },
334 /*ca*/ { "", FALSE, NONE, 0, 0 },
335 /*cb*/ { "", FALSE, NONE, 0, 0 },
336 /*cc*/ { "", FALSE, NONE, 0, 0 },
337 /*cd*/ { "", FALSE, NONE, 0, 0 },
338 /*ce*/ { "", FALSE, NONE, 0, 0 },
339 /*cf*/ { "", FALSE, NONE, 0, 0 },
342 static const struct inst * const db_inst_0f[] = {
361 static const char * const db_Esc92[] = {
362 "fnop", "", "", "", "", "", "", ""
364 static const char * const db_Esc93[] = {
365 "", "", "", "", "", "", "", ""
367 static const char * const db_Esc94[] = {
368 "fchs", "fabs", "", "", "ftst", "fxam", "", ""
370 static const char * const db_Esc95[] = {
371 "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
373 static const char * const db_Esc96[] = {
374 "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
377 static const char * const db_Esc97[] = {
378 "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
381 static const char * const db_Esca4[] = {
382 "", "fucompp","", "", "", "", "", ""
385 static const char * const db_Escb4[] = {
386 "", "", "fnclex","fninit","", "", "", ""
389 static const char * const db_Esce3[] = {
390 "", "fcompp","", "", "", "", "", ""
393 static const char * const db_Escf4[] = {
394 "fnstsw","", "", "", "", "", "", ""
397 static const struct finst db_Esc8[] = {
398 /*0*/ { "fadd", SNGL, op2(STI,ST), 0 },
399 /*1*/ { "fmul", SNGL, op2(STI,ST), 0 },
400 /*2*/ { "fcom", SNGL, op2(STI,ST), 0 },
401 /*3*/ { "fcomp", SNGL, op2(STI,ST), 0 },
402 /*4*/ { "fsub", SNGL, op2(STI,ST), 0 },
403 /*5*/ { "fsubr", SNGL, op2(STI,ST), 0 },
404 /*6*/ { "fdiv", SNGL, op2(STI,ST), 0 },
405 /*7*/ { "fdivr", SNGL, op2(STI,ST), 0 },
408 static const struct finst db_Esc9[] = {
409 /*0*/ { "fld", SNGL, op1(STI), 0 },
410 /*1*/ { "", NONE, op1(STI), "fxch" },
411 /*2*/ { "fst", SNGL, op1(X), (char *)db_Esc92 },
412 /*3*/ { "fstp", SNGL, op1(X), (char *)db_Esc93 },
413 /*4*/ { "fldenv", NONE, op1(X), (char *)db_Esc94 },
414 /*5*/ { "fldcw", NONE, op1(X), (char *)db_Esc95 },
415 /*6*/ { "fnstenv",NONE, op1(X), (char *)db_Esc96 },
416 /*7*/ { "fnstcw", NONE, op1(X), (char *)db_Esc97 },
419 static const struct finst db_Esca[] = {
420 /*0*/ { "fiadd", WORD, 0, 0 },
421 /*1*/ { "fimul", WORD, 0, 0 },
422 /*2*/ { "ficom", WORD, 0, 0 },
423 /*3*/ { "ficomp", WORD, 0, 0 },
424 /*4*/ { "fisub", WORD, op1(X), (char *)db_Esca4 },
425 /*5*/ { "fisubr", WORD, 0, 0 },
426 /*6*/ { "fidiv", WORD, 0, 0 },
427 /*7*/ { "fidivr", WORD, 0, 0 }
430 static const struct finst db_Escb[] = {
431 /*0*/ { "fild", WORD, 0, 0 },
432 /*1*/ { "", NONE, 0, 0 },
433 /*2*/ { "fist", WORD, 0, 0 },
434 /*3*/ { "fistp", WORD, 0, 0 },
435 /*4*/ { "", WORD, op1(X), (char *)db_Escb4 },
436 /*5*/ { "fld", EXTR, 0, 0 },
437 /*6*/ { "", WORD, 0, 0 },
438 /*7*/ { "fstp", EXTR, 0, 0 },
441 static const struct finst db_Escc[] = {
442 /*0*/ { "fadd", DBLR, op2(ST,STI), 0 },
443 /*1*/ { "fmul", DBLR, op2(ST,STI), 0 },
444 /*2*/ { "fcom", DBLR, op2(ST,STI), 0 },
445 /*3*/ { "fcomp", DBLR, op2(ST,STI), 0 },
446 /*4*/ { "fsub", DBLR, op2(ST,STI), "fsubr" },
447 /*5*/ { "fsubr", DBLR, op2(ST,STI), "fsub" },
448 /*6*/ { "fdiv", DBLR, op2(ST,STI), "fdivr" },
449 /*7*/ { "fdivr", DBLR, op2(ST,STI), "fdiv" },
452 static const struct finst db_Escd[] = {
453 /*0*/ { "fld", DBLR, op1(STI), "ffree" },
454 /*1*/ { "", NONE, 0, 0 },
455 /*2*/ { "fst", DBLR, op1(STI), 0 },
456 /*3*/ { "fstp", DBLR, op1(STI), 0 },
457 /*4*/ { "frstor", NONE, op1(STI), "fucom" },
458 /*5*/ { "", NONE, op1(STI), "fucomp" },
459 /*6*/ { "fnsave", NONE, 0, 0 },
460 /*7*/ { "fnstsw", NONE, 0, 0 },
463 static const struct finst db_Esce[] = {
464 /*0*/ { "fiadd", LONG, op2(ST,STI), "faddp" },
465 /*1*/ { "fimul", LONG, op2(ST,STI), "fmulp" },
466 /*2*/ { "ficom", LONG, 0, 0 },
467 /*3*/ { "ficomp", LONG, op1(X), (char *)db_Esce3 },
468 /*4*/ { "fisub", LONG, op2(ST,STI), "fsubrp" },
469 /*5*/ { "fisubr", LONG, op2(ST,STI), "fsubp" },
470 /*6*/ { "fidiv", LONG, op2(ST,STI), "fdivrp" },
471 /*7*/ { "fidivr", LONG, op2(ST,STI), "fdivp" },
474 static const struct finst db_Escf[] = {
475 /*0*/ { "fild", LONG, 0, 0 },
476 /*1*/ { "", LONG, 0, 0 },
477 /*2*/ { "fist", LONG, 0, 0 },
478 /*3*/ { "fistp", LONG, 0, 0 },
479 /*4*/ { "fbld", NONE, op1(XA), (char *)db_Escf4 },
480 /*5*/ { "fld", QUAD, 0, 0 },
481 /*6*/ { "fbstp", NONE, 0, 0 },
482 /*7*/ { "fstp", QUAD, 0, 0 },
485 static const struct finst * const db_Esc_inst[] = {
486 db_Esc8, db_Esc9, db_Esca, db_Escb,
487 db_Escc, db_Escd, db_Esce, db_Escf
490 static const char * const db_Grp1[] = {
501 static const char * const db_Grp2[] = {
512 static const struct inst db_Grp3[] = {
513 { "test", TRUE, NONE, op2(I,E), 0 },
514 { "test", TRUE, NONE, op2(I,E), 0 },
515 { "not", TRUE, NONE, op1(E), 0 },
516 { "neg", TRUE, NONE, op1(E), 0 },
517 { "mul", TRUE, NONE, op2(E,A), 0 },
518 { "imul", TRUE, NONE, op2(E,A), 0 },
519 { "div", TRUE, NONE, op2(E,A), 0 },
520 { "idiv", TRUE, NONE, op2(E,A), 0 },
523 static const struct inst db_Grp4[] = {
524 { "inc", TRUE, BYTE, op1(E), 0 },
525 { "dec", TRUE, BYTE, op1(E), 0 },
526 { "", TRUE, NONE, 0, 0 },
527 { "", TRUE, NONE, 0, 0 },
528 { "", TRUE, NONE, 0, 0 },
529 { "", TRUE, NONE, 0, 0 },
530 { "", TRUE, NONE, 0, 0 },
531 { "", TRUE, NONE, 0, 0 }
534 static const struct inst db_Grp5[] = {
535 { "inc", TRUE, LONG, op1(E), 0 },
536 { "dec", TRUE, LONG, op1(E), 0 },
537 { "call", TRUE, NONE, op1(Eind),0 },
538 { "lcall", TRUE, NONE, op1(Eind),0 },
539 { "jmp", TRUE, NONE, op1(Eind),0 },
540 { "ljmp", TRUE, NONE, op1(Eind),0 },
541 { "push", TRUE, LONG, op1(E), 0 },
542 { "", TRUE, NONE, 0, 0 }
545 static const struct inst db_inst_table[256] = {
546 /*00*/ { "add", TRUE, BYTE, op2(R, E), 0 },
547 /*01*/ { "add", TRUE, LONG, op2(R, E), 0 },
548 /*02*/ { "add", TRUE, BYTE, op2(E, R), 0 },
549 /*03*/ { "add", TRUE, LONG, op2(E, R), 0 },
550 /*04*/ { "add", FALSE, BYTE, op2(Is, A), 0 },
551 /*05*/ { "add", FALSE, LONG, op2(Is, A), 0 },
552 /*06*/ { "push", FALSE, NONE, op1(Si), 0 },
553 /*07*/ { "pop", FALSE, NONE, op1(Si), 0 },
555 /*08*/ { "or", TRUE, BYTE, op2(R, E), 0 },
556 /*09*/ { "or", TRUE, LONG, op2(R, E), 0 },
557 /*0a*/ { "or", TRUE, BYTE, op2(E, R), 0 },
558 /*0b*/ { "or", TRUE, LONG, op2(E, R), 0 },
559 /*0c*/ { "or", FALSE, BYTE, op2(I, A), 0 },
560 /*0d*/ { "or", FALSE, LONG, op2(I, A), 0 },
561 /*0e*/ { "push", FALSE, NONE, op1(Si), 0 },
562 /*0f*/ { "", FALSE, NONE, 0, 0 },
564 /*10*/ { "adc", TRUE, BYTE, op2(R, E), 0 },
565 /*11*/ { "adc", TRUE, LONG, op2(R, E), 0 },
566 /*12*/ { "adc", TRUE, BYTE, op2(E, R), 0 },
567 /*13*/ { "adc", TRUE, LONG, op2(E, R), 0 },
568 /*14*/ { "adc", FALSE, BYTE, op2(Is, A), 0 },
569 /*15*/ { "adc", FALSE, LONG, op2(Is, A), 0 },
570 /*16*/ { "push", FALSE, NONE, op1(Si), 0 },
571 /*17*/ { "pop", FALSE, NONE, op1(Si), 0 },
573 /*18*/ { "sbb", TRUE, BYTE, op2(R, E), 0 },
574 /*19*/ { "sbb", TRUE, LONG, op2(R, E), 0 },
575 /*1a*/ { "sbb", TRUE, BYTE, op2(E, R), 0 },
576 /*1b*/ { "sbb", TRUE, LONG, op2(E, R), 0 },
577 /*1c*/ { "sbb", FALSE, BYTE, op2(Is, A), 0 },
578 /*1d*/ { "sbb", FALSE, LONG, op2(Is, A), 0 },
579 /*1e*/ { "push", FALSE, NONE, op1(Si), 0 },
580 /*1f*/ { "pop", FALSE, NONE, op1(Si), 0 },
582 /*20*/ { "and", TRUE, BYTE, op2(R, E), 0 },
583 /*21*/ { "and", TRUE, LONG, op2(R, E), 0 },
584 /*22*/ { "and", TRUE, BYTE, op2(E, R), 0 },
585 /*23*/ { "and", TRUE, LONG, op2(E, R), 0 },
586 /*24*/ { "and", FALSE, BYTE, op2(I, A), 0 },
587 /*25*/ { "and", FALSE, LONG, op2(I, A), 0 },
588 /*26*/ { "", FALSE, NONE, 0, 0 },
589 /*27*/ { "aaa", FALSE, NONE, 0, 0 },
591 /*28*/ { "sub", TRUE, BYTE, op2(R, E), 0 },
592 /*29*/ { "sub", TRUE, LONG, op2(R, E), 0 },
593 /*2a*/ { "sub", TRUE, BYTE, op2(E, R), 0 },
594 /*2b*/ { "sub", TRUE, LONG, op2(E, R), 0 },
595 /*2c*/ { "sub", FALSE, BYTE, op2(Is, A), 0 },
596 /*2d*/ { "sub", FALSE, LONG, op2(Is, A), 0 },
597 /*2e*/ { "", FALSE, NONE, 0, 0 },
598 /*2f*/ { "das", FALSE, NONE, 0, 0 },
600 /*30*/ { "xor", TRUE, BYTE, op2(R, E), 0 },
601 /*31*/ { "xor", TRUE, LONG, op2(R, E), 0 },
602 /*32*/ { "xor", TRUE, BYTE, op2(E, R), 0 },
603 /*33*/ { "xor", TRUE, LONG, op2(E, R), 0 },
604 /*34*/ { "xor", FALSE, BYTE, op2(I, A), 0 },
605 /*35*/ { "xor", FALSE, LONG, op2(I, A), 0 },
606 /*36*/ { "", FALSE, NONE, 0, 0 },
607 /*37*/ { "daa", FALSE, NONE, 0, 0 },
609 /*38*/ { "cmp", TRUE, BYTE, op2(R, E), 0 },
610 /*39*/ { "cmp", TRUE, LONG, op2(R, E), 0 },
611 /*3a*/ { "cmp", TRUE, BYTE, op2(E, R), 0 },
612 /*3b*/ { "cmp", TRUE, LONG, op2(E, R), 0 },
613 /*3c*/ { "cmp", FALSE, BYTE, op2(Is, A), 0 },
614 /*3d*/ { "cmp", FALSE, LONG, op2(Is, A), 0 },
615 /*3e*/ { "", FALSE, NONE, 0, 0 },
616 /*3f*/ { "aas", FALSE, NONE, 0, 0 },
618 /*40*/ { "inc", FALSE, LONG, op1(Ri), 0 },
619 /*41*/ { "inc", FALSE, LONG, op1(Ri), 0 },
620 /*42*/ { "inc", FALSE, LONG, op1(Ri), 0 },
621 /*43*/ { "inc", FALSE, LONG, op1(Ri), 0 },
622 /*44*/ { "inc", FALSE, LONG, op1(Ri), 0 },
623 /*45*/ { "inc", FALSE, LONG, op1(Ri), 0 },
624 /*46*/ { "inc", FALSE, LONG, op1(Ri), 0 },
625 /*47*/ { "inc", FALSE, LONG, op1(Ri), 0 },
627 /*48*/ { "dec", FALSE, LONG, op1(Ri), 0 },
628 /*49*/ { "dec", FALSE, LONG, op1(Ri), 0 },
629 /*4a*/ { "dec", FALSE, LONG, op1(Ri), 0 },
630 /*4b*/ { "dec", FALSE, LONG, op1(Ri), 0 },
631 /*4c*/ { "dec", FALSE, LONG, op1(Ri), 0 },
632 /*4d*/ { "dec", FALSE, LONG, op1(Ri), 0 },
633 /*4e*/ { "dec", FALSE, LONG, op1(Ri), 0 },
634 /*4f*/ { "dec", FALSE, LONG, op1(Ri), 0 },
636 /*50*/ { "push", FALSE, LONG, op1(Ri), 0 },
637 /*51*/ { "push", FALSE, LONG, op1(Ri), 0 },
638 /*52*/ { "push", FALSE, LONG, op1(Ri), 0 },
639 /*53*/ { "push", FALSE, LONG, op1(Ri), 0 },
640 /*54*/ { "push", FALSE, LONG, op1(Ri), 0 },
641 /*55*/ { "push", FALSE, LONG, op1(Ri), 0 },
642 /*56*/ { "push", FALSE, LONG, op1(Ri), 0 },
643 /*57*/ { "push", FALSE, LONG, op1(Ri), 0 },
645 /*58*/ { "pop", FALSE, LONG, op1(Ri), 0 },
646 /*59*/ { "pop", FALSE, LONG, op1(Ri), 0 },
647 /*5a*/ { "pop", FALSE, LONG, op1(Ri), 0 },
648 /*5b*/ { "pop", FALSE, LONG, op1(Ri), 0 },
649 /*5c*/ { "pop", FALSE, LONG, op1(Ri), 0 },
650 /*5d*/ { "pop", FALSE, LONG, op1(Ri), 0 },
651 /*5e*/ { "pop", FALSE, LONG, op1(Ri), 0 },
652 /*5f*/ { "pop", FALSE, LONG, op1(Ri), 0 },
654 /*60*/ { "pusha", FALSE, LONG, 0, 0 },
655 /*61*/ { "popa", FALSE, LONG, 0, 0 },
656 /*62*/ { "bound", TRUE, LONG, op2(E, R), 0 },
657 /*63*/ { "arpl", TRUE, NONE, op2(Ew,Rw), 0 },
659 /*64*/ { "", FALSE, NONE, 0, 0 },
660 /*65*/ { "", FALSE, NONE, 0, 0 },
661 /*66*/ { "", FALSE, NONE, 0, 0 },
662 /*67*/ { "", FALSE, NONE, 0, 0 },
664 /*68*/ { "push", FALSE, LONG, op1(I), 0 },
665 /*69*/ { "imul", TRUE, LONG, op3(I,E,R), 0 },
666 /*6a*/ { "push", FALSE, LONG, op1(Ib), 0 },
667 /*6b*/ { "imul", TRUE, LONG, op3(Ibs,E,R),0 },
668 /*6c*/ { "ins", FALSE, BYTE, op2(DX, DI), 0 },
669 /*6d*/ { "ins", FALSE, LONG, op2(DX, DI), 0 },
670 /*6e*/ { "outs", FALSE, BYTE, op2(SI, DX), 0 },
671 /*6f*/ { "outs", FALSE, LONG, op2(SI, DX), 0 },
673 /*70*/ { "jo", FALSE, NONE, op1(Db), 0 },
674 /*71*/ { "jno", FALSE, NONE, op1(Db), 0 },
675 /*72*/ { "jb", FALSE, NONE, op1(Db), 0 },
676 /*73*/ { "jnb", FALSE, NONE, op1(Db), 0 },
677 /*74*/ { "jz", FALSE, NONE, op1(Db), 0 },
678 /*75*/ { "jnz", FALSE, NONE, op1(Db), 0 },
679 /*76*/ { "jbe", FALSE, NONE, op1(Db), 0 },
680 /*77*/ { "jnbe", FALSE, NONE, op1(Db), 0 },
682 /*78*/ { "js", FALSE, NONE, op1(Db), 0 },
683 /*79*/ { "jns", FALSE, NONE, op1(Db), 0 },
684 /*7a*/ { "jp", FALSE, NONE, op1(Db), 0 },
685 /*7b*/ { "jnp", FALSE, NONE, op1(Db), 0 },
686 /*7c*/ { "jl", FALSE, NONE, op1(Db), 0 },
687 /*7d*/ { "jnl", FALSE, NONE, op1(Db), 0 },
688 /*7e*/ { "jle", FALSE, NONE, op1(Db), 0 },
689 /*7f*/ { "jnle", FALSE, NONE, op1(Db), 0 },
691 /*80*/ { "", TRUE, BYTE, op2(I, E), (char *)db_Grp1 },
692 /*81*/ { "", TRUE, LONG, op2(I, E), (char *)db_Grp1 },
693 /*82*/ { "", TRUE, BYTE, op2(Is,E), (char *)db_Grp1 },
694 /*83*/ { "", TRUE, LONG, op2(Ibs,E), (char *)db_Grp1 },
695 /*84*/ { "test", TRUE, BYTE, op2(R, E), 0 },
696 /*85*/ { "test", TRUE, LONG, op2(R, E), 0 },
697 /*86*/ { "xchg", TRUE, BYTE, op2(R, E), 0 },
698 /*87*/ { "xchg", TRUE, LONG, op2(R, E), 0 },
700 /*88*/ { "mov", TRUE, BYTE, op2(R, E), 0 },
701 /*89*/ { "mov", TRUE, LONG, op2(R, E), 0 },
702 /*8a*/ { "mov", TRUE, BYTE, op2(E, R), 0 },
703 /*8b*/ { "mov", TRUE, LONG, op2(E, R), 0 },
704 /*8c*/ { "mov", TRUE, NONE, op2(S, Ew), 0 },
705 /*8d*/ { "lea", TRUE, LONG, op2(E, R), 0 },
706 /*8e*/ { "mov", TRUE, NONE, op2(Ew, S), 0 },
707 /*8f*/ { "pop", TRUE, LONG, op1(E), 0 },
709 /*90*/ { "nop", FALSE, NONE, 0, 0 },
710 /*91*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
711 /*92*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
712 /*93*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
713 /*94*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
714 /*95*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
715 /*96*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
716 /*97*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
718 /*98*/ { "cbw", FALSE, SDEP, 0, "cwde" }, /* cbw/cwde */
719 /*99*/ { "cwd", FALSE, SDEP, 0, "cdq" }, /* cwd/cdq */
720 /*9a*/ { "lcall", FALSE, NONE, op1(OS), 0 },
721 /*9b*/ { "wait", FALSE, NONE, 0, 0 },
722 /*9c*/ { "pushf", FALSE, LONG, 0, 0 },
723 /*9d*/ { "popf", FALSE, LONG, 0, 0 },
724 /*9e*/ { "sahf", FALSE, NONE, 0, 0 },
725 /*9f*/ { "lahf", FALSE, NONE, 0, 0 },
727 /*a0*/ { "mov", FALSE, BYTE, op2(O, A), 0 },
728 /*a1*/ { "mov", FALSE, LONG, op2(O, A), 0 },
729 /*a2*/ { "mov", FALSE, BYTE, op2(A, O), 0 },
730 /*a3*/ { "mov", FALSE, LONG, op2(A, O), 0 },
731 /*a4*/ { "movs", FALSE, BYTE, op2(SI,DI), 0 },
732 /*a5*/ { "movs", FALSE, LONG, op2(SI,DI), 0 },
733 /*a6*/ { "cmps", FALSE, BYTE, op2(SI,DI), 0 },
734 /*a7*/ { "cmps", FALSE, LONG, op2(SI,DI), 0 },
736 /*a8*/ { "test", FALSE, BYTE, op2(I, A), 0 },
737 /*a9*/ { "test", FALSE, LONG, op2(I, A), 0 },
738 /*aa*/ { "stos", FALSE, BYTE, op1(DI), 0 },
739 /*ab*/ { "stos", FALSE, LONG, op1(DI), 0 },
740 /*ac*/ { "lods", FALSE, BYTE, op1(SI), 0 },
741 /*ad*/ { "lods", FALSE, LONG, op1(SI), 0 },
742 /*ae*/ { "scas", FALSE, BYTE, op1(DI), 0 },
743 /*af*/ { "scas", FALSE, LONG, op1(DI), 0 },
745 /*b0*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
746 /*b1*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
747 /*b2*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
748 /*b3*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
749 /*b4*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
750 /*b5*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
751 /*b6*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
752 /*b7*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
754 /*b8*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
755 /*b9*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
756 /*ba*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
757 /*bb*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
758 /*bc*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
759 /*bd*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
760 /*be*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
761 /*bf*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
763 /*c0*/ { "", TRUE, BYTE, op2(Ib, E), (char *)db_Grp2 },
764 /*c1*/ { "", TRUE, LONG, op2(Ib, E), (char *)db_Grp2 },
765 /*c2*/ { "ret", FALSE, NONE, op1(Iw), 0 },
766 /*c3*/ { "ret", FALSE, NONE, 0, 0 },
767 /*c4*/ { "les", TRUE, LONG, op2(E, R), 0 },
768 /*c5*/ { "lds", TRUE, LONG, op2(E, R), 0 },
769 /*c6*/ { "mov", TRUE, BYTE, op2(I, E), 0 },
770 /*c7*/ { "mov", TRUE, LONG, op2(I, E), 0 },
772 /*c8*/ { "enter", FALSE, NONE, op2(Ib, Iw), 0 },
773 /*c9*/ { "leave", FALSE, NONE, 0, 0 },
774 /*ca*/ { "lret", FALSE, NONE, op1(Iw), 0 },
775 /*cb*/ { "lret", FALSE, NONE, 0, 0 },
776 /*cc*/ { "int", FALSE, NONE, op1(o3), 0 },
777 /*cd*/ { "int", FALSE, NONE, op1(Ib), 0 },
778 /*ce*/ { "into", FALSE, NONE, 0, 0 },
779 /*cf*/ { "iret", FALSE, NONE, 0, 0 },
781 /*d0*/ { "", TRUE, BYTE, op2(o1, E), (char *)db_Grp2 },
782 /*d1*/ { "", TRUE, LONG, op2(o1, E), (char *)db_Grp2 },
783 /*d2*/ { "", TRUE, BYTE, op2(CL, E), (char *)db_Grp2 },
784 /*d3*/ { "", TRUE, LONG, op2(CL, E), (char *)db_Grp2 },
785 /*d4*/ { "aam", TRUE, NONE, 0, 0 },
786 /*d5*/ { "aad", TRUE, NONE, 0, 0 },
787 /*d6*/ { "", FALSE, NONE, 0, 0 },
788 /*d7*/ { "xlat", FALSE, BYTE, op1(BX), 0 },
790 /*d8*/ { "", TRUE, NONE, 0, (char *)db_Esc8 },
791 /*d9*/ { "", TRUE, NONE, 0, (char *)db_Esc9 },
792 /*da*/ { "", TRUE, NONE, 0, (char *)db_Esca },
793 /*db*/ { "", TRUE, NONE, 0, (char *)db_Escb },
794 /*dc*/ { "", TRUE, NONE, 0, (char *)db_Escc },
795 /*dd*/ { "", TRUE, NONE, 0, (char *)db_Escd },
796 /*de*/ { "", TRUE, NONE, 0, (char *)db_Esce },
797 /*df*/ { "", TRUE, NONE, 0, (char *)db_Escf },
799 /*e0*/ { "loopne",FALSE, NONE, op1(Db), 0 },
800 /*e1*/ { "loope", FALSE, NONE, op1(Db), 0 },
801 /*e2*/ { "loop", FALSE, NONE, op1(Db), 0 },
802 /*e3*/ { "jcxz", FALSE, SDEP, op1(Db), "jecxz" },
803 /*e4*/ { "in", FALSE, BYTE, op2(Ib, A), 0 },
804 /*e5*/ { "in", FALSE, LONG, op2(Ib, A) , 0 },
805 /*e6*/ { "out", FALSE, BYTE, op2(A, Ib), 0 },
806 /*e7*/ { "out", FALSE, LONG, op2(A, Ib) , 0 },
808 /*e8*/ { "call", FALSE, NONE, op1(Dl), 0 },
809 /*e9*/ { "jmp", FALSE, NONE, op1(Dl), 0 },
810 /*ea*/ { "ljmp", FALSE, NONE, op1(OS), 0 },
811 /*eb*/ { "jmp", FALSE, NONE, op1(Db), 0 },
812 /*ec*/ { "in", FALSE, BYTE, op2(DX, A), 0 },
813 /*ed*/ { "in", FALSE, LONG, op2(DX, A) , 0 },
814 /*ee*/ { "out", FALSE, BYTE, op2(A, DX), 0 },
815 /*ef*/ { "out", FALSE, LONG, op2(A, DX) , 0 },
817 /*f0*/ { "", FALSE, NONE, 0, 0 },
818 /*f1*/ { "", FALSE, NONE, 0, 0 },
819 /*f2*/ { "", FALSE, NONE, 0, 0 },
820 /*f3*/ { "", FALSE, NONE, 0, 0 },
821 /*f4*/ { "hlt", FALSE, NONE, 0, 0 },
822 /*f5*/ { "cmc", FALSE, NONE, 0, 0 },
823 /*f6*/ { "", TRUE, BYTE, 0, (char *)db_Grp3 },
824 /*f7*/ { "", TRUE, LONG, 0, (char *)db_Grp3 },
826 /*f8*/ { "clc", FALSE, NONE, 0, 0 },
827 /*f9*/ { "stc", FALSE, NONE, 0, 0 },
828 /*fa*/ { "cli", FALSE, NONE, 0, 0 },
829 /*fb*/ { "sti", FALSE, NONE, 0, 0 },
830 /*fc*/ { "cld", FALSE, NONE, 0, 0 },
831 /*fd*/ { "std", FALSE, NONE, 0, 0 },
832 /*fe*/ { "", TRUE, NONE, 0, (char *)db_Grp4 },
833 /*ff*/ { "", TRUE, NONE, 0, (char *)db_Grp5 },
836 static const struct inst db_bad_inst =
837 { "???", FALSE, NONE, 0, 0 }
840 #define f_mod(byte) ((byte)>>6)
841 #define f_reg(byte) (((byte)>>3)&0x7)
842 #define f_rm(byte) ((byte)&0x7)
844 #define sib_ss(byte) ((byte)>>6)
845 #define sib_index(byte) (((byte)>>3)&0x7)
846 #define sib_base(byte) ((byte)&0x7)
849 int is_reg; /* if reg, reg number is in 'disp' */
856 static const char * const db_index_reg_16[8] = {
867 static const char * const db_reg[3][8] = {
868 { "%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh" },
869 { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di" },
870 { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi" }
873 static const char * const db_seg_reg[8] = {
874 "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
878 * lengths for size attributes
880 static const int db_lengths[] = {
890 static unsigned int db_get_task_value( const DBG_ADDR *addr,
891 int size, int is_signed )
894 unsigned char *p = DBG_ADDR_TO_LIN( addr );
899 if (is_signed) result = (unsigned int) *(int *)p;
900 else result = *(unsigned int *)p;
903 if (is_signed) result = (unsigned int) *(short int *)p;
904 else result = *(unsigned short int *)p;
907 if (is_signed) result = (unsigned int) *(char *)p;
908 else result = *(unsigned char *)p;
911 fprintf(stderr, "Illegal size specified\n");
918 #define get_value_inc(result, addr, size, is_signed) \
919 result = db_get_task_value((addr), (size), (is_signed)); \
920 if (!db_disasm_16) (addr)->off += (size); \
921 else (addr)->off = ((addr)->off + (size)) & 0xffff;
924 * Read address at location and return updated location.
926 void db_read_address( DBG_ADDR *addr, int short_addr, int regmodrm,
927 struct i_addr *addrp )
929 int mod, rm, sib, index, disp;
931 mod = f_mod(regmodrm);
935 addrp->is_reg = TRUE;
939 addrp->is_reg = FALSE;
948 get_value_inc(disp, addr, 2, TRUE);
954 addrp->base = db_index_reg_16[rm];
958 get_value_inc(disp, addr, 1, TRUE);
960 addrp->base = db_index_reg_16[rm];
963 get_value_inc(disp, addr, 2, TRUE);
965 addrp->base = db_index_reg_16[rm];
970 if (mod != 3 && rm == 4) {
971 get_value_inc(sib, addr, 1, FALSE);
973 index = sib_index(sib);
975 addrp->index = db_reg[LONG][index];
976 addrp->ss = sib_ss(sib);
982 get_value_inc(addrp->disp, addr, 4, FALSE);
987 addrp->base = db_reg[LONG][rm];
992 get_value_inc(disp, addr, 1, TRUE);
994 addrp->base = db_reg[LONG][rm];
998 get_value_inc(disp, addr, 4, FALSE);
1000 addrp->base = db_reg[LONG][rm];
1006 static void db_task_printsym(unsigned int addr, int size)
1010 address.type = NULL;
1014 DEBUG_PrintAddress( &address, db_disasm_16 ? 16 : 32, TRUE );
1017 void db_print_address(char *seg, int size, struct i_addr *addrp, int byref)
1019 if (addrp->is_reg) {
1020 fprintf(stderr,"%s", db_reg[size][addrp->disp]);
1025 fprintf(stderr,"%s:", seg);
1028 if (addrp->base != 0 || addrp->index != 0) {
1029 fprintf(stderr,"0x%x", addrp->disp);
1030 fprintf(stderr,"(");
1032 fprintf(stderr,"%s", addrp->base);
1034 fprintf(stderr,",%s,%d", addrp->index, 1<<addrp->ss);
1035 fprintf(stderr,")");
1039 /* try to get destination of indirect call
1040 does not work for segmented adresses */
1041 if (!seg && byref) {
1042 DBG_ADDR dbg_addr = {NULL, 0, 0};
1044 dbg_addr.off = addrp->disp;
1045 fprintf(stderr,"0x%x -> ", addrp->disp);
1046 if (DEBUG_IsBadReadPtr( &dbg_addr, sizeof(LPDWORD))) {
1047 fprintf(stderr, "(invalid source)");
1049 dbg_addr.off = *(LPDWORD)(addrp->disp);
1050 if (DEBUG_IsBadReadPtr( &dbg_addr, sizeof(DWORD)))
1051 fprintf(stderr, "(invalid destination)");
1053 db_task_printsym(dbg_addr.off, 0);
1057 db_task_printsym(addrp->disp, size);
1062 * Disassemble floating-point ("escape") instruction
1063 * and return updated location.
1065 void db_disasm_esc( DBG_ADDR *addr, int inst, int short_addr,
1066 int size, char *seg )
1069 const struct finst *fp;
1071 struct i_addr address;
1074 get_value_inc(regmodrm, addr, 1, FALSE);
1080 fp = &db_Esc_inst[inst - 0xd8][f_reg(regmodrm)];
1081 mod = f_mod(regmodrm);
1084 * Normal address modes.
1086 db_read_address( addr, short_addr, regmodrm, &address);
1087 fprintf(stderr,fp->f_name);
1088 switch(fp->f_size) {
1090 fprintf(stderr,"s");
1093 fprintf(stderr,"l");
1096 fprintf(stderr,"t");
1099 fprintf(stderr,"s");
1102 fprintf(stderr,"l");
1105 fprintf(stderr,"q");
1110 fprintf(stderr,"\t");
1111 db_print_address(seg, BYTE, &address, 0);
1115 * 'reg-reg' - special formats
1117 switch (fp->f_rrmode) {
1119 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1120 fprintf(stderr,"%s\t%%st,%%st(%d)",name,f_rm(regmodrm));
1123 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1124 fprintf(stderr,"%s\t%%st(%d),%%st",name, f_rm(regmodrm));
1127 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1128 fprintf(stderr,"%s\t%%st(%d)",name, f_rm(regmodrm));
1131 fprintf(stderr,"%s", ((char **)fp->f_rrname)[f_rm(regmodrm)]);
1134 fprintf(stderr,"%s\t%%ax",
1135 ((char **)fp->f_rrname)[f_rm(regmodrm)]);
1138 fprintf(stderr,"<bad instruction>");
1145 /***********************************************************************
1148 * Disassemble instruction at 'addr'. addr is changed to point to the
1149 * start of the next instruction.
1151 void DEBUG_Disasm( DBG_ADDR *addr, int display )
1157 const struct inst *ip;
1167 struct i_addr address;
1170 * Set this so we get can supress the printout if we need to.
1172 db_display = display;
1173 db_disasm_16 = IS_SELECTOR_V86(addr->seg) || !IS_SELECTOR_32BIT(addr->seg);
1175 get_value_inc( inst, addr, 1, FALSE );
1193 case 0x66: /* data16 */
1200 short_addr = !short_addr;
1222 fprintf(stderr,"lock ");
1226 fprintf(stderr,"repne ");
1230 fprintf(stderr,"repe "); /* XXX repe VS rep */
1237 get_value_inc(inst, addr, 1, FALSE);
1241 if (inst >= 0xd8 && inst <= 0xdf)
1243 db_disasm_esc( addr, inst, short_addr, size, seg);
1248 get_value_inc(inst, addr, 1, FALSE);
1249 ip = db_inst_0f[inst>>4];
1258 ip = &db_inst_table[inst];
1260 if (ip->i_has_modrm) {
1261 get_value_inc(regmodrm, addr, 1, FALSE);
1262 db_read_address( addr, short_addr, regmodrm, &address);
1265 i_name = ip->i_name;
1266 i_size = ip->i_size;
1267 i_mode = ip->i_mode;
1269 if (ip->i_extra == (char *)db_Grp1 ||
1270 ip->i_extra == (char *)db_Grp2 ||
1271 ip->i_extra == (char *)db_Grp6 ||
1272 ip->i_extra == (char *)db_Grp7 ||
1273 ip->i_extra == (char *)db_Grp8) {
1274 i_name = ((char **)ip->i_extra)[f_reg(regmodrm)];
1276 else if (ip->i_extra == (char *)db_Grp3) {
1277 ip = (struct inst *)ip->i_extra;
1278 ip = &ip[f_reg(regmodrm)];
1279 i_name = ip->i_name;
1280 i_mode = ip->i_mode;
1282 else if (ip->i_extra == (char *)db_Grp4 ||
1283 ip->i_extra == (char *)db_Grp5) {
1284 ip = (struct inst *)ip->i_extra;
1285 ip = &ip[f_reg(regmodrm)];
1286 i_name = ip->i_name;
1287 i_mode = ip->i_mode;
1288 i_size = ip->i_size;
1291 if (i_size == SDEP) {
1295 fprintf(stderr,i_name);
1297 fprintf(stderr,ip->i_extra);
1303 fprintf(stderr,i_name);
1305 if (i_size != NONE) {
1306 if (i_size == BYTE) {
1309 fprintf(stderr,"b");
1313 else if (i_size == WORD) {
1316 fprintf(stderr,"w");
1320 else if (size == WORD)
1324 fprintf(stderr,"w");
1331 fprintf(stderr,"l");
1338 fprintf(stderr,"\t");
1342 i_mode >>= 8, first = FALSE)
1344 if (!first && db_display)
1345 fprintf(stderr,",");
1347 switch (i_mode & 0xFF) {
1352 db_print_address(seg, size, &address, 0);
1359 fprintf(stderr,"*");
1360 db_print_address(seg, size, &address, 1);
1367 db_print_address(seg, WORD, &address, 0);
1374 db_print_address(seg, BYTE, &address, 0);
1381 fprintf(stderr,"%s", db_reg[size][f_reg(regmodrm)]);
1388 fprintf(stderr,"%s", db_reg[WORD][f_reg(regmodrm)]);
1395 fprintf(stderr,"%s", db_reg[size][f_rm(inst)]);
1402 fprintf(stderr,"%s", db_seg_reg[f_reg(regmodrm)]);
1409 fprintf(stderr,"%s", db_seg_reg[f_reg(inst)]);
1416 fprintf(stderr,"%s", db_reg[size][0]); /* acc */
1424 fprintf(stderr,"%s:", seg);
1425 fprintf(stderr,"(%s)", short_addr ? "%bx" : "%ebx");
1432 fprintf(stderr,"%%cl");
1439 fprintf(stderr,"%%dx");
1447 fprintf(stderr,"%s:", seg);
1448 fprintf(stderr,"(%s)", short_addr ? "%si" : "%esi");
1455 fprintf(stderr,"%%es:(%s)", short_addr ? "%di" : "%edi");
1462 fprintf(stderr,"%%cr%d", f_reg(regmodrm));
1469 fprintf(stderr,"%%dr%d", f_reg(regmodrm));
1476 fprintf(stderr,"%%tr%d", f_reg(regmodrm));
1481 len = db_lengths[size];
1482 get_value_inc(imm, addr, len, FALSE);/* unsigned */
1485 fprintf(stderr,"$0x%x", imm);
1490 len = db_lengths[size];
1491 get_value_inc(imm, addr, len, TRUE); /* signed */
1494 fprintf(stderr,"$%d", imm);
1499 get_value_inc(imm, addr, 1, FALSE); /* unsigned */
1502 fprintf(stderr,"$0x%x", imm);
1507 get_value_inc(imm, addr, 1, TRUE); /* signed */
1510 fprintf(stderr,"$%d", imm);
1515 get_value_inc(imm, addr, 2, FALSE); /* unsigned */
1518 fprintf(stderr,"$0x%x", imm);
1523 get_value_inc(imm, addr, 4, FALSE);
1526 fprintf(stderr,"$0x%x", imm);
1532 get_value_inc(displ, addr, 2, TRUE);
1535 get_value_inc(displ, addr, 4, TRUE);
1543 fprintf(stderr,"%s:0x%x",seg, displ);
1545 db_task_printsym(displ, short_addr ? WORD : LONG);
1549 get_value_inc(displ, addr, 1, TRUE);
1556 /* offset only affects low 16 bits */
1557 displ = (addr->off & 0xffff0000)
1558 | ((addr->off + displ) & 0xffff);
1560 else displ += addr->off;
1561 db_task_printsym(displ, size);
1566 get_value_inc(displ, addr, 2, TRUE);
1567 /* offset only affects low 16 bits */
1568 displ = (addr->off & 0xffff0000)
1569 | ((addr->off + displ) & 0xffff);
1572 get_value_inc(displ, addr, 4, TRUE);
1579 db_task_printsym( displ, size );
1585 fprintf(stderr,"$1");
1592 fprintf(stderr,"$3");
1599 get_value_inc( address.off, addr, /* offset */
1600 short_addr ? 2 : 4, FALSE );
1601 get_value_inc( address.seg, addr, /* segment */
1605 DEBUG_PrintAddress( &address, short_addr ? 16 : 32,