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.
70 * Switch to disassemble 16-bit code.
72 static BOOL db_disasm_16 = FALSE;
75 * Flag to indicate whether we need to display instruction,
76 * or whether we just need to know the address of the next
79 static BOOL db_display = FALSE;
97 #define E 1 /* general effective address */
98 #define Eind 2 /* indirect address (jump, call) */
99 #define Ew 3 /* address, word size */
100 #define Eb 4 /* address, byte size */
101 #define R 5 /* register, in 'reg' field */
102 #define Rw 6 /* word register, in 'reg' field */
103 #define Ri 7 /* register in instruction */
104 #define S 8 /* segment reg, in 'reg' field */
105 #define Si 9 /* segment reg, in instruction */
106 #define A 10 /* accumulator */
107 #define BX 11 /* (bx) */
108 #define CL 12 /* cl, for shifts */
109 #define DX 13 /* dx, for IO */
110 #define SI 14 /* si */
111 #define DI 15 /* di */
112 #define CR 16 /* control register */
113 #define DR 17 /* debug register */
114 #define TR 18 /* test register */
115 #define I 19 /* immediate, unsigned */
116 #define Is 20 /* immediate, signed */
117 #define Ib 21 /* byte immediate, unsigned */
118 #define Ibs 22 /* byte immediate, signed */
119 #define Iw 23 /* word immediate, unsigned */
120 #define Il 24 /* long immediate */
121 #define O 25 /* direct address */
122 #define Db 26 /* byte displacement from EIP */
123 #define Dl 27 /* long displacement from EIP */
124 #define o1 28 /* constant 1 */
125 #define o3 29 /* constant 3 */
126 #define OS 30 /* immediate offset/segment */
127 #define ST 31 /* FP stack top */
128 #define STI 32 /* FP stack */
129 #define X 33 /* extended FP op */
130 #define XA 34 /* for 'fstcw %ax' */
133 const char *i_name; /* name */
134 short i_has_modrm; /* has regmodrm byte */
135 short i_size; /* operand size */
136 int i_mode; /* addressing modes */
137 const char *i_extra; /* pointer to extra opcode table */
141 #define op2(x,y) ((x)|((y)<<8))
142 #define op3(x,y,z) ((x)|((y)<<8)|((z)<<16))
145 const char *f_name; /* name for memory instruction */
146 int f_size; /* size for memory instruction */
147 int f_rrmode; /* mode for rr instruction */
148 const char *f_rrname; /* name for rr instruction
149 (or pointer to table) */
152 static const char * const db_Grp6[] = {
163 static const char * const db_Grp7[] = {
174 static const char * const db_Grp8[] = {
185 static const struct inst db_inst_0f0x[] = {
186 /*00*/ { "", TRUE, NONE, op1(Ew), (char *)db_Grp6 },
187 /*01*/ { "", TRUE, NONE, op1(Ew), (char *)db_Grp7 },
188 /*02*/ { "lar", TRUE, LONG, op2(E,R), 0 },
189 /*03*/ { "lsl", TRUE, LONG, op2(E,R), 0 },
190 /*04*/ { "", FALSE, NONE, 0, 0 },
191 /*05*/ { "", FALSE, NONE, 0, 0 },
192 /*06*/ { "clts", FALSE, NONE, 0, 0 },
193 /*07*/ { "", FALSE, NONE, 0, 0 },
195 /*08*/ { "invd", FALSE, NONE, 0, 0 },
196 /*09*/ { "wbinvd",FALSE, NONE, 0, 0 },
197 /*0a*/ { "", FALSE, NONE, 0, 0 },
198 /*0b*/ { "", FALSE, NONE, 0, 0 },
199 /*0c*/ { "", FALSE, NONE, 0, 0 },
200 /*0d*/ { "", FALSE, NONE, 0, 0 },
201 /*0e*/ { "", FALSE, NONE, 0, 0 },
202 /*0f*/ { "", FALSE, NONE, 0, 0 },
205 static const struct inst db_inst_0f2x[] = {
206 /*20*/ { "mov", TRUE, LONG, op2(CR,E), 0 }, /* use E for reg */
207 /*21*/ { "mov", TRUE, LONG, op2(DR,E), 0 }, /* since mod == 11 */
208 /*22*/ { "mov", TRUE, LONG, op2(E,CR), 0 },
209 /*23*/ { "mov", TRUE, LONG, op2(E,DR), 0 },
210 /*24*/ { "mov", TRUE, LONG, op2(TR,E), 0 },
211 /*25*/ { "", FALSE, NONE, 0, 0 },
212 /*26*/ { "mov", TRUE, LONG, op2(E,TR), 0 },
213 /*27*/ { "", FALSE, NONE, 0, 0 },
215 /*28*/ { "", FALSE, NONE, 0, 0 },
216 /*29*/ { "", FALSE, NONE, 0, 0 },
217 /*2a*/ { "", FALSE, NONE, 0, 0 },
218 /*2b*/ { "", FALSE, NONE, 0, 0 },
219 /*2c*/ { "", FALSE, NONE, 0, 0 },
220 /*2d*/ { "", FALSE, NONE, 0, 0 },
221 /*2e*/ { "", FALSE, NONE, 0, 0 },
222 /*2f*/ { "", FALSE, NONE, 0, 0 },
225 static const struct inst db_inst_0f4x[] = {
226 /*40*/ { "cmovo", TRUE, NONE, op2(E, R), 0 },
227 /*41*/ { "cmovno", TRUE, NONE, op2(E, R), 0 },
228 /*42*/ { "cmovnae",TRUE, NONE, op2(E, R), 0 },
229 /*43*/ { "cmovnb", TRUE, NONE, op2(E, R), 0 },
230 /*44*/ { "cmove", TRUE, NONE, op2(E, R), 0 },
231 /*45*/ { "cmovne", TRUE, NONE, op2(E, R), 0 },
232 /*46*/ { "cmovna", TRUE, NONE, op2(E, R), 0 },
233 /*47*/ { "cmova", TRUE, NONE, op2(E, R), 0 },
235 /*48*/ { "cmovs", TRUE, NONE, op2(E, R), 0 },
236 /*49*/ { "cmovns", TRUE, NONE, op2(E, R), 0 },
237 /*4a*/ { "cmovpe", TRUE, NONE, op2(E, R), 0 },
238 /*4b*/ { "cmovpo", TRUE, NONE, op2(E, R), 0 },
239 /*4c*/ { "cmovl", TRUE, NONE, op2(E, R), 0 },
240 /*4d*/ { "cmovge", TRUE, NONE, op2(E, R), 0 },
241 /*4e*/ { "cmovle", TRUE, NONE, op2(E, R), 0 },
242 /*4f*/ { "cmovnle",TRUE, NONE, op2(E, R), 0 },
245 static const struct inst db_inst_0f8x[] = {
246 /*80*/ { "jo", FALSE, NONE, op1(Dl), 0 },
247 /*81*/ { "jno", FALSE, NONE, op1(Dl), 0 },
248 /*82*/ { "jb", FALSE, NONE, op1(Dl), 0 },
249 /*83*/ { "jnb", FALSE, NONE, op1(Dl), 0 },
250 /*84*/ { "jz", FALSE, NONE, op1(Dl), 0 },
251 /*85*/ { "jnz", FALSE, NONE, op1(Dl), 0 },
252 /*86*/ { "jbe", FALSE, NONE, op1(Dl), 0 },
253 /*87*/ { "jnbe", FALSE, NONE, op1(Dl), 0 },
255 /*88*/ { "js", FALSE, NONE, op1(Dl), 0 },
256 /*89*/ { "jns", FALSE, NONE, op1(Dl), 0 },
257 /*8a*/ { "jp", FALSE, NONE, op1(Dl), 0 },
258 /*8b*/ { "jnp", FALSE, NONE, op1(Dl), 0 },
259 /*8c*/ { "jl", FALSE, NONE, op1(Dl), 0 },
260 /*8d*/ { "jnl", FALSE, NONE, op1(Dl), 0 },
261 /*8e*/ { "jle", FALSE, NONE, op1(Dl), 0 },
262 /*8f*/ { "jnle", FALSE, NONE, op1(Dl), 0 },
265 static const struct inst db_inst_0f9x[] = {
266 /*90*/ { "seto", TRUE, NONE, op1(Eb), 0 },
267 /*91*/ { "setno", TRUE, NONE, op1(Eb), 0 },
268 /*92*/ { "setb", TRUE, NONE, op1(Eb), 0 },
269 /*93*/ { "setnb", TRUE, NONE, op1(Eb), 0 },
270 /*94*/ { "setz", TRUE, NONE, op1(Eb), 0 },
271 /*95*/ { "setnz", TRUE, NONE, op1(Eb), 0 },
272 /*96*/ { "setbe", TRUE, NONE, op1(Eb), 0 },
273 /*97*/ { "setnbe",TRUE, NONE, op1(Eb), 0 },
275 /*98*/ { "sets", TRUE, NONE, op1(Eb), 0 },
276 /*99*/ { "setns", TRUE, NONE, op1(Eb), 0 },
277 /*9a*/ { "setp", TRUE, NONE, op1(Eb), 0 },
278 /*9b*/ { "setnp", TRUE, NONE, op1(Eb), 0 },
279 /*9c*/ { "setl", TRUE, NONE, op1(Eb), 0 },
280 /*9d*/ { "setnl", TRUE, NONE, op1(Eb), 0 },
281 /*9e*/ { "setle", TRUE, NONE, op1(Eb), 0 },
282 /*9f*/ { "setnle",TRUE, NONE, op1(Eb), 0 },
285 static const struct inst db_inst_0fax[] = {
286 /*a0*/ { "push", FALSE, NONE, op1(Si), 0 },
287 /*a1*/ { "pop", FALSE, NONE, op1(Si), 0 },
288 /*a2*/ { "cpuid", FALSE, NONE, 0, 0 },
289 /*a3*/ { "bt", TRUE, LONG, op2(E,R), 0 },
290 /*a4*/ { "shld", TRUE, LONG, op3(Ib,E,R), 0 },
291 /*a5*/ { "shld", TRUE, LONG, op3(CL,E,R), 0 },
292 /*a6*/ { "", FALSE, NONE, 0, 0 },
293 /*a7*/ { "", FALSE, NONE, 0, 0 },
295 /*a8*/ { "push", FALSE, NONE, op1(Si), 0 },
296 /*a9*/ { "pop", FALSE, NONE, op1(Si), 0 },
297 /*aa*/ { "", FALSE, NONE, 0, 0 },
298 /*ab*/ { "bts", TRUE, LONG, op2(E,R), 0 },
299 /*ac*/ { "shrd", TRUE, LONG, op3(Ib,E,R), 0 },
300 /*ad*/ { "shrd", TRUE, LONG, op3(CL,E,R), 0 },
301 /*a6*/ { "", FALSE, NONE, 0, 0 },
302 /*a7*/ { "imul", TRUE, LONG, op2(E,R), 0 },
305 static const struct inst db_inst_0fbx[] = {
306 /*b0*/ { "cmpxchg",TRUE, BYTE, op2(E, R), 0 },
307 /*b1*/ { "cmpxchg",TRUE, LONG, op2(E, R), 0 },
308 /*b2*/ { "lss", TRUE, LONG, op2(E, R), 0 },
309 /*b3*/ { "bts", TRUE, LONG, op2(R, E), 0 },
310 /*b4*/ { "lfs", TRUE, LONG, op2(E, R), 0 },
311 /*b5*/ { "lgs", TRUE, LONG, op2(E, R), 0 },
312 /*b6*/ { "movzb", TRUE, LONG, op2(E, R), 0 },
313 /*b7*/ { "movzw", TRUE, LONG, op2(E, R), 0 },
315 /*b8*/ { "", FALSE, NONE, 0, 0 },
316 /*b9*/ { "", FALSE, NONE, 0, 0 },
317 /*ba*/ { "", TRUE, LONG, op2(Ib, E), (char *)db_Grp8 },
318 /*bb*/ { "btc", TRUE, LONG, op2(R, E), 0 },
319 /*bc*/ { "bsf", TRUE, LONG, op2(E, R), 0 },
320 /*bd*/ { "bsr", TRUE, LONG, op2(E, R), 0 },
321 /*be*/ { "movsb", TRUE, LONG, op2(E, R), 0 },
322 /*bf*/ { "movsw", TRUE, LONG, op2(E, R), 0 },
325 static const struct inst db_inst_0fcx[] = {
326 /*c0*/ { "xadd", TRUE, BYTE, op2(R, E), 0 },
327 /*c1*/ { "xadd", TRUE, LONG, op2(R, E), 0 },
328 /*c2*/ { "", FALSE, NONE, 0, 0 },
329 /*c3*/ { "", FALSE, NONE, 0, 0 },
330 /*c4*/ { "", FALSE, NONE, 0, 0 },
331 /*c5*/ { "", FALSE, NONE, 0, 0 },
332 /*c6*/ { "", FALSE, NONE, 0, 0 },
333 /*c7*/ { "", FALSE, NONE, 0, 0 },
334 /*c8*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
335 /*c9*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
336 /*ca*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
337 /*cb*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
338 /*cc*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
339 /*cd*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
340 /*ce*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
341 /*cf*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
344 static const struct inst db_inst_0fdx[] = {
345 /*c0*/ { "cmpxchg",TRUE, BYTE, op2(R, E), 0 },
346 /*c1*/ { "cmpxchg",TRUE, LONG, op2(R, E), 0 },
347 /*c2*/ { "", FALSE, NONE, 0, 0 },
348 /*c3*/ { "", FALSE, NONE, 0, 0 },
349 /*c4*/ { "", FALSE, NONE, 0, 0 },
350 /*c5*/ { "", FALSE, NONE, 0, 0 },
351 /*c6*/ { "", FALSE, NONE, 0, 0 },
352 /*c7*/ { "", FALSE, NONE, 0, 0 },
353 /*c8*/ { "", FALSE, NONE, 0, 0 },
354 /*c9*/ { "", FALSE, NONE, 0, 0 },
355 /*ca*/ { "", FALSE, NONE, 0, 0 },
356 /*cb*/ { "", FALSE, NONE, 0, 0 },
357 /*cc*/ { "", FALSE, NONE, 0, 0 },
358 /*cd*/ { "", FALSE, NONE, 0, 0 },
359 /*ce*/ { "", FALSE, NONE, 0, 0 },
360 /*cf*/ { "", FALSE, NONE, 0, 0 },
363 static const struct inst * const db_inst_0f[] = {
382 static const char * const db_Esc92[] = {
383 "fnop", "", "", "", "", "", "", ""
385 static const char * const db_Esc93[] = {
386 "", "", "", "", "", "", "", ""
388 static const char * const db_Esc94[] = {
389 "fchs", "fabs", "", "", "ftst", "fxam", "", ""
391 static const char * const db_Esc95[] = {
392 "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
394 static const char * const db_Esc96[] = {
395 "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
398 static const char * const db_Esc97[] = {
399 "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
402 static const char * const db_Esca4[] = {
403 "", "fucompp","", "", "", "", "", ""
406 static const char * const db_Escb4[] = {
407 "", "", "fnclex","fninit","", "", "", ""
410 static const char * const db_Esce3[] = {
411 "", "fcompp","", "", "", "", "", ""
414 static const char * const db_Escf4[] = {
415 "fnstsw","", "", "", "", "", "", ""
418 static const struct finst db_Esc8[] = {
419 /*0*/ { "fadd", SNGL, op2(STI,ST), 0 },
420 /*1*/ { "fmul", SNGL, op2(STI,ST), 0 },
421 /*2*/ { "fcom", SNGL, op2(STI,ST), 0 },
422 /*3*/ { "fcomp", SNGL, op2(STI,ST), 0 },
423 /*4*/ { "fsub", SNGL, op2(STI,ST), 0 },
424 /*5*/ { "fsubr", SNGL, op2(STI,ST), 0 },
425 /*6*/ { "fdiv", SNGL, op2(STI,ST), 0 },
426 /*7*/ { "fdivr", SNGL, op2(STI,ST), 0 },
429 static const struct finst db_Esc9[] = {
430 /*0*/ { "fld", SNGL, op1(STI), 0 },
431 /*1*/ { "", NONE, op1(STI), "fxch" },
432 /*2*/ { "fst", SNGL, op1(X), (char *)db_Esc92 },
433 /*3*/ { "fstp", SNGL, op1(X), (char *)db_Esc93 },
434 /*4*/ { "fldenv", NONE, op1(X), (char *)db_Esc94 },
435 /*5*/ { "fldcw", NONE, op1(X), (char *)db_Esc95 },
436 /*6*/ { "fnstenv",NONE, op1(X), (char *)db_Esc96 },
437 /*7*/ { "fnstcw", NONE, op1(X), (char *)db_Esc97 },
440 static const struct finst db_Esca[] = {
441 /*0*/ { "fiadd", WORD, 0, 0 },
442 /*1*/ { "fimul", WORD, 0, 0 },
443 /*2*/ { "ficom", WORD, 0, 0 },
444 /*3*/ { "ficomp", WORD, 0, 0 },
445 /*4*/ { "fisub", WORD, op1(X), (char *)db_Esca4 },
446 /*5*/ { "fisubr", WORD, 0, 0 },
447 /*6*/ { "fidiv", WORD, 0, 0 },
448 /*7*/ { "fidivr", WORD, 0, 0 }
451 static const struct finst db_Escb[] = {
452 /*0*/ { "fild", WORD, 0, 0 },
453 /*1*/ { "", NONE, 0, 0 },
454 /*2*/ { "fist", WORD, 0, 0 },
455 /*3*/ { "fistp", WORD, 0, 0 },
456 /*4*/ { "", WORD, op1(X), (char *)db_Escb4 },
457 /*5*/ { "fld", EXTR, 0, 0 },
458 /*6*/ { "", WORD, 0, 0 },
459 /*7*/ { "fstp", EXTR, 0, 0 },
462 static const struct finst db_Escc[] = {
463 /*0*/ { "fadd", DBLR, op2(ST,STI), 0 },
464 /*1*/ { "fmul", DBLR, op2(ST,STI), 0 },
465 /*2*/ { "fcom", DBLR, op2(ST,STI), 0 },
466 /*3*/ { "fcomp", DBLR, op2(ST,STI), 0 },
467 /*4*/ { "fsub", DBLR, op2(ST,STI), "fsubr" },
468 /*5*/ { "fsubr", DBLR, op2(ST,STI), "fsub" },
469 /*6*/ { "fdiv", DBLR, op2(ST,STI), "fdivr" },
470 /*7*/ { "fdivr", DBLR, op2(ST,STI), "fdiv" },
473 static const struct finst db_Escd[] = {
474 /*0*/ { "fld", DBLR, op1(STI), "ffree" },
475 /*1*/ { "", NONE, 0, 0 },
476 /*2*/ { "fst", DBLR, op1(STI), 0 },
477 /*3*/ { "fstp", DBLR, op1(STI), 0 },
478 /*4*/ { "frstor", NONE, op1(STI), "fucom" },
479 /*5*/ { "", NONE, op1(STI), "fucomp" },
480 /*6*/ { "fnsave", NONE, 0, 0 },
481 /*7*/ { "fnstsw", NONE, 0, 0 },
484 static const struct finst db_Esce[] = {
485 /*0*/ { "fiadd", LONG, op2(ST,STI), "faddp" },
486 /*1*/ { "fimul", LONG, op2(ST,STI), "fmulp" },
487 /*2*/ { "ficom", LONG, 0, 0 },
488 /*3*/ { "ficomp", LONG, op1(X), (char *)db_Esce3 },
489 /*4*/ { "fisub", LONG, op2(ST,STI), "fsubrp" },
490 /*5*/ { "fisubr", LONG, op2(ST,STI), "fsubp" },
491 /*6*/ { "fidiv", LONG, op2(ST,STI), "fdivrp" },
492 /*7*/ { "fidivr", LONG, op2(ST,STI), "fdivp" },
495 static const struct finst db_Escf[] = {
496 /*0*/ { "fild", LONG, 0, 0 },
497 /*1*/ { "", LONG, 0, 0 },
498 /*2*/ { "fist", LONG, 0, 0 },
499 /*3*/ { "fistp", LONG, 0, 0 },
500 /*4*/ { "fbld", NONE, op1(XA), (char *)db_Escf4 },
501 /*5*/ { "fld", QUAD, 0, 0 },
502 /*6*/ { "fbstp", NONE, 0, 0 },
503 /*7*/ { "fstp", QUAD, 0, 0 },
506 static const struct finst * const db_Esc_inst[] = {
507 db_Esc8, db_Esc9, db_Esca, db_Escb,
508 db_Escc, db_Escd, db_Esce, db_Escf
511 static const char * const db_Grp1[] = {
522 static const char * const db_Grp2[] = {
533 static const struct inst db_Grp3[] = {
534 { "test", TRUE, NONE, op2(I,E), 0 },
535 { "test", TRUE, NONE, op2(I,E), 0 },
536 { "not", TRUE, NONE, op1(E), 0 },
537 { "neg", TRUE, NONE, op1(E), 0 },
538 { "mul", TRUE, NONE, op2(E,A), 0 },
539 { "imul", TRUE, NONE, op2(E,A), 0 },
540 { "div", TRUE, NONE, op2(E,A), 0 },
541 { "idiv", TRUE, NONE, op2(E,A), 0 },
544 static const struct inst db_Grp4[] = {
545 { "inc", TRUE, BYTE, op1(E), 0 },
546 { "dec", TRUE, BYTE, op1(E), 0 },
547 { "", TRUE, NONE, 0, 0 },
548 { "", TRUE, NONE, 0, 0 },
549 { "", TRUE, NONE, 0, 0 },
550 { "", TRUE, NONE, 0, 0 },
551 { "", TRUE, NONE, 0, 0 },
552 { "", TRUE, NONE, 0, 0 }
555 static const struct inst db_Grp5[] = {
556 { "inc", TRUE, LONG, op1(E), 0 },
557 { "dec", TRUE, LONG, op1(E), 0 },
558 { "call", TRUE, NONE, op1(Eind),0 },
559 { "lcall", TRUE, NONE, op1(Eind),0 },
560 { "jmp", TRUE, NONE, op1(Eind),0 },
561 { "ljmp", TRUE, NONE, op1(Eind),0 },
562 { "push", TRUE, LONG, op1(E), 0 },
563 { "", TRUE, NONE, 0, 0 }
566 static const struct inst db_inst_table[256] = {
567 /*00*/ { "add", TRUE, BYTE, op2(R, E), 0 },
568 /*01*/ { "add", TRUE, LONG, op2(R, E), 0 },
569 /*02*/ { "add", TRUE, BYTE, op2(E, R), 0 },
570 /*03*/ { "add", TRUE, LONG, op2(E, R), 0 },
571 /*04*/ { "add", FALSE, BYTE, op2(Is, A), 0 },
572 /*05*/ { "add", FALSE, LONG, op2(Is, A), 0 },
573 /*06*/ { "push", FALSE, NONE, op1(Si), 0 },
574 /*07*/ { "pop", FALSE, NONE, op1(Si), 0 },
576 /*08*/ { "or", TRUE, BYTE, op2(R, E), 0 },
577 /*09*/ { "or", TRUE, LONG, op2(R, E), 0 },
578 /*0a*/ { "or", TRUE, BYTE, op2(E, R), 0 },
579 /*0b*/ { "or", TRUE, LONG, op2(E, R), 0 },
580 /*0c*/ { "or", FALSE, BYTE, op2(I, A), 0 },
581 /*0d*/ { "or", FALSE, LONG, op2(I, A), 0 },
582 /*0e*/ { "push", FALSE, NONE, op1(Si), 0 },
583 /*0f*/ { "", FALSE, NONE, 0, 0 },
585 /*10*/ { "adc", TRUE, BYTE, op2(R, E), 0 },
586 /*11*/ { "adc", TRUE, LONG, op2(R, E), 0 },
587 /*12*/ { "adc", TRUE, BYTE, op2(E, R), 0 },
588 /*13*/ { "adc", TRUE, LONG, op2(E, R), 0 },
589 /*14*/ { "adc", FALSE, BYTE, op2(Is, A), 0 },
590 /*15*/ { "adc", FALSE, LONG, op2(Is, A), 0 },
591 /*16*/ { "push", FALSE, NONE, op1(Si), 0 },
592 /*17*/ { "pop", FALSE, NONE, op1(Si), 0 },
594 /*18*/ { "sbb", TRUE, BYTE, op2(R, E), 0 },
595 /*19*/ { "sbb", TRUE, LONG, op2(R, E), 0 },
596 /*1a*/ { "sbb", TRUE, BYTE, op2(E, R), 0 },
597 /*1b*/ { "sbb", TRUE, LONG, op2(E, R), 0 },
598 /*1c*/ { "sbb", FALSE, BYTE, op2(Is, A), 0 },
599 /*1d*/ { "sbb", FALSE, LONG, op2(Is, A), 0 },
600 /*1e*/ { "push", FALSE, NONE, op1(Si), 0 },
601 /*1f*/ { "pop", FALSE, NONE, op1(Si), 0 },
603 /*20*/ { "and", TRUE, BYTE, op2(R, E), 0 },
604 /*21*/ { "and", TRUE, LONG, op2(R, E), 0 },
605 /*22*/ { "and", TRUE, BYTE, op2(E, R), 0 },
606 /*23*/ { "and", TRUE, LONG, op2(E, R), 0 },
607 /*24*/ { "and", FALSE, BYTE, op2(I, A), 0 },
608 /*25*/ { "and", FALSE, LONG, op2(I, A), 0 },
609 /*26*/ { "", FALSE, NONE, 0, 0 },
610 /*27*/ { "aaa", FALSE, NONE, 0, 0 },
612 /*28*/ { "sub", TRUE, BYTE, op2(R, E), 0 },
613 /*29*/ { "sub", TRUE, LONG, op2(R, E), 0 },
614 /*2a*/ { "sub", TRUE, BYTE, op2(E, R), 0 },
615 /*2b*/ { "sub", TRUE, LONG, op2(E, R), 0 },
616 /*2c*/ { "sub", FALSE, BYTE, op2(Is, A), 0 },
617 /*2d*/ { "sub", FALSE, LONG, op2(Is, A), 0 },
618 /*2e*/ { "", FALSE, NONE, 0, 0 },
619 /*2f*/ { "das", FALSE, NONE, 0, 0 },
621 /*30*/ { "xor", TRUE, BYTE, op2(R, E), 0 },
622 /*31*/ { "xor", TRUE, LONG, op2(R, E), 0 },
623 /*32*/ { "xor", TRUE, BYTE, op2(E, R), 0 },
624 /*33*/ { "xor", TRUE, LONG, op2(E, R), 0 },
625 /*34*/ { "xor", FALSE, BYTE, op2(I, A), 0 },
626 /*35*/ { "xor", FALSE, LONG, op2(I, A), 0 },
627 /*36*/ { "", FALSE, NONE, 0, 0 },
628 /*37*/ { "daa", FALSE, NONE, 0, 0 },
630 /*38*/ { "cmp", TRUE, BYTE, op2(R, E), 0 },
631 /*39*/ { "cmp", TRUE, LONG, op2(R, E), 0 },
632 /*3a*/ { "cmp", TRUE, BYTE, op2(E, R), 0 },
633 /*3b*/ { "cmp", TRUE, LONG, op2(E, R), 0 },
634 /*3c*/ { "cmp", FALSE, BYTE, op2(Is, A), 0 },
635 /*3d*/ { "cmp", FALSE, LONG, op2(Is, A), 0 },
636 /*3e*/ { "", FALSE, NONE, 0, 0 },
637 /*3f*/ { "aas", FALSE, NONE, 0, 0 },
639 /*40*/ { "inc", FALSE, LONG, op1(Ri), 0 },
640 /*41*/ { "inc", FALSE, LONG, op1(Ri), 0 },
641 /*42*/ { "inc", FALSE, LONG, op1(Ri), 0 },
642 /*43*/ { "inc", FALSE, LONG, op1(Ri), 0 },
643 /*44*/ { "inc", FALSE, LONG, op1(Ri), 0 },
644 /*45*/ { "inc", FALSE, LONG, op1(Ri), 0 },
645 /*46*/ { "inc", FALSE, LONG, op1(Ri), 0 },
646 /*47*/ { "inc", FALSE, LONG, op1(Ri), 0 },
648 /*48*/ { "dec", FALSE, LONG, op1(Ri), 0 },
649 /*49*/ { "dec", FALSE, LONG, op1(Ri), 0 },
650 /*4a*/ { "dec", FALSE, LONG, op1(Ri), 0 },
651 /*4b*/ { "dec", FALSE, LONG, op1(Ri), 0 },
652 /*4c*/ { "dec", FALSE, LONG, op1(Ri), 0 },
653 /*4d*/ { "dec", FALSE, LONG, op1(Ri), 0 },
654 /*4e*/ { "dec", FALSE, LONG, op1(Ri), 0 },
655 /*4f*/ { "dec", FALSE, LONG, op1(Ri), 0 },
657 /*50*/ { "push", FALSE, LONG, op1(Ri), 0 },
658 /*51*/ { "push", FALSE, LONG, op1(Ri), 0 },
659 /*52*/ { "push", FALSE, LONG, op1(Ri), 0 },
660 /*53*/ { "push", FALSE, LONG, op1(Ri), 0 },
661 /*54*/ { "push", FALSE, LONG, op1(Ri), 0 },
662 /*55*/ { "push", FALSE, LONG, op1(Ri), 0 },
663 /*56*/ { "push", FALSE, LONG, op1(Ri), 0 },
664 /*57*/ { "push", FALSE, LONG, op1(Ri), 0 },
666 /*58*/ { "pop", FALSE, LONG, op1(Ri), 0 },
667 /*59*/ { "pop", FALSE, LONG, op1(Ri), 0 },
668 /*5a*/ { "pop", FALSE, LONG, op1(Ri), 0 },
669 /*5b*/ { "pop", FALSE, LONG, op1(Ri), 0 },
670 /*5c*/ { "pop", FALSE, LONG, op1(Ri), 0 },
671 /*5d*/ { "pop", FALSE, LONG, op1(Ri), 0 },
672 /*5e*/ { "pop", FALSE, LONG, op1(Ri), 0 },
673 /*5f*/ { "pop", FALSE, LONG, op1(Ri), 0 },
675 /*60*/ { "pusha", FALSE, LONG, 0, 0 },
676 /*61*/ { "popa", FALSE, LONG, 0, 0 },
677 /*62*/ { "bound", TRUE, LONG, op2(E, R), 0 },
678 /*63*/ { "arpl", TRUE, NONE, op2(Ew,Rw), 0 },
680 /*64*/ { "", FALSE, NONE, 0, 0 },
681 /*65*/ { "", FALSE, NONE, 0, 0 },
682 /*66*/ { "", FALSE, NONE, 0, 0 },
683 /*67*/ { "", FALSE, NONE, 0, 0 },
685 /*68*/ { "push", FALSE, LONG, op1(I), 0 },
686 /*69*/ { "imul", TRUE, LONG, op3(I,E,R), 0 },
687 /*6a*/ { "push", FALSE, LONG, op1(Ib), 0 },
688 /*6b*/ { "imul", TRUE, LONG, op3(Ibs,E,R),0 },
689 /*6c*/ { "ins", FALSE, BYTE, op2(DX, DI), 0 },
690 /*6d*/ { "ins", FALSE, LONG, op2(DX, DI), 0 },
691 /*6e*/ { "outs", FALSE, BYTE, op2(SI, DX), 0 },
692 /*6f*/ { "outs", FALSE, LONG, op2(SI, DX), 0 },
694 /*70*/ { "jo", FALSE, NONE, op1(Db), 0 },
695 /*71*/ { "jno", FALSE, NONE, op1(Db), 0 },
696 /*72*/ { "jb", FALSE, NONE, op1(Db), 0 },
697 /*73*/ { "jnb", FALSE, NONE, op1(Db), 0 },
698 /*74*/ { "jz", FALSE, NONE, op1(Db), 0 },
699 /*75*/ { "jnz", FALSE, NONE, op1(Db), 0 },
700 /*76*/ { "jbe", FALSE, NONE, op1(Db), 0 },
701 /*77*/ { "jnbe", FALSE, NONE, op1(Db), 0 },
703 /*78*/ { "js", FALSE, NONE, op1(Db), 0 },
704 /*79*/ { "jns", FALSE, NONE, op1(Db), 0 },
705 /*7a*/ { "jp", FALSE, NONE, op1(Db), 0 },
706 /*7b*/ { "jnp", FALSE, NONE, op1(Db), 0 },
707 /*7c*/ { "jl", FALSE, NONE, op1(Db), 0 },
708 /*7d*/ { "jnl", FALSE, NONE, op1(Db), 0 },
709 /*7e*/ { "jle", FALSE, NONE, op1(Db), 0 },
710 /*7f*/ { "jnle", FALSE, NONE, op1(Db), 0 },
712 /*80*/ { "", TRUE, BYTE, op2(I, E), (char *)db_Grp1 },
713 /*81*/ { "", TRUE, LONG, op2(I, E), (char *)db_Grp1 },
714 /*82*/ { "", TRUE, BYTE, op2(Is,E), (char *)db_Grp1 },
715 /*83*/ { "", TRUE, LONG, op2(Ibs,E), (char *)db_Grp1 },
716 /*84*/ { "test", TRUE, BYTE, op2(R, E), 0 },
717 /*85*/ { "test", TRUE, LONG, op2(R, E), 0 },
718 /*86*/ { "xchg", TRUE, BYTE, op2(R, E), 0 },
719 /*87*/ { "xchg", TRUE, LONG, op2(R, E), 0 },
721 /*88*/ { "mov", TRUE, BYTE, op2(R, E), 0 },
722 /*89*/ { "mov", TRUE, LONG, op2(R, E), 0 },
723 /*8a*/ { "mov", TRUE, BYTE, op2(E, R), 0 },
724 /*8b*/ { "mov", TRUE, LONG, op2(E, R), 0 },
725 /*8c*/ { "mov", TRUE, NONE, op2(S, Ew), 0 },
726 /*8d*/ { "lea", TRUE, LONG, op2(E, R), 0 },
727 /*8e*/ { "mov", TRUE, NONE, op2(Ew, S), 0 },
728 /*8f*/ { "pop", TRUE, LONG, op1(E), 0 },
730 /*90*/ { "nop", FALSE, NONE, 0, 0 },
731 /*91*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
732 /*92*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
733 /*93*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
734 /*94*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
735 /*95*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
736 /*96*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
737 /*97*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
739 /*98*/ { "cbw", FALSE, SDEP, 0, "cwde" }, /* cbw/cwde */
740 /*99*/ { "cwd", FALSE, SDEP, 0, "cdq" }, /* cwd/cdq */
741 /*9a*/ { "lcall", FALSE, NONE, op1(OS), 0 },
742 /*9b*/ { "wait", FALSE, NONE, 0, 0 },
743 /*9c*/ { "pushf", FALSE, LONG, 0, 0 },
744 /*9d*/ { "popf", FALSE, LONG, 0, 0 },
745 /*9e*/ { "sahf", FALSE, NONE, 0, 0 },
746 /*9f*/ { "lahf", FALSE, NONE, 0, 0 },
748 /*a0*/ { "mov", FALSE, BYTE, op2(O, A), 0 },
749 /*a1*/ { "mov", FALSE, LONG, op2(O, A), 0 },
750 /*a2*/ { "mov", FALSE, BYTE, op2(A, O), 0 },
751 /*a3*/ { "mov", FALSE, LONG, op2(A, O), 0 },
752 /*a4*/ { "movs", FALSE, BYTE, op2(SI,DI), 0 },
753 /*a5*/ { "movs", FALSE, LONG, op2(SI,DI), 0 },
754 /*a6*/ { "cmps", FALSE, BYTE, op2(SI,DI), 0 },
755 /*a7*/ { "cmps", FALSE, LONG, op2(SI,DI), 0 },
757 /*a8*/ { "test", FALSE, BYTE, op2(I, A), 0 },
758 /*a9*/ { "test", FALSE, LONG, op2(I, A), 0 },
759 /*aa*/ { "stos", FALSE, BYTE, op1(DI), 0 },
760 /*ab*/ { "stos", FALSE, LONG, op1(DI), 0 },
761 /*ac*/ { "lods", FALSE, BYTE, op1(SI), 0 },
762 /*ad*/ { "lods", FALSE, LONG, op1(SI), 0 },
763 /*ae*/ { "scas", FALSE, BYTE, op1(DI), 0 },
764 /*af*/ { "scas", FALSE, LONG, op1(DI), 0 },
766 /*b0*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
767 /*b1*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
768 /*b2*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
769 /*b3*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
770 /*b4*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
771 /*b5*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
772 /*b6*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
773 /*b7*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
775 /*b8*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
776 /*b9*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
777 /*ba*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
778 /*bb*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
779 /*bc*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
780 /*bd*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
781 /*be*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
782 /*bf*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
784 /*c0*/ { "", TRUE, BYTE, op2(Ib, E), (char *)db_Grp2 },
785 /*c1*/ { "", TRUE, LONG, op2(Ib, E), (char *)db_Grp2 },
786 /*c2*/ { "ret", FALSE, NONE, op1(Iw), 0 },
787 /*c3*/ { "ret", FALSE, NONE, 0, 0 },
788 /*c4*/ { "les", TRUE, LONG, op2(E, R), 0 },
789 /*c5*/ { "lds", TRUE, LONG, op2(E, R), 0 },
790 /*c6*/ { "mov", TRUE, BYTE, op2(I, E), 0 },
791 /*c7*/ { "mov", TRUE, LONG, op2(I, E), 0 },
793 /*c8*/ { "enter", FALSE, NONE, op2(Iw, Ib), 0 },
794 /*c9*/ { "leave", FALSE, NONE, 0, 0 },
795 /*ca*/ { "lret", FALSE, NONE, op1(Iw), 0 },
796 /*cb*/ { "lret", FALSE, NONE, 0, 0 },
797 /*cc*/ { "int", FALSE, NONE, op1(o3), 0 },
798 /*cd*/ { "int", FALSE, NONE, op1(Ib), 0 },
799 /*ce*/ { "into", FALSE, NONE, 0, 0 },
800 /*cf*/ { "iret", FALSE, NONE, 0, 0 },
802 /*d0*/ { "", TRUE, BYTE, op2(o1, E), (char *)db_Grp2 },
803 /*d1*/ { "", TRUE, LONG, op2(o1, E), (char *)db_Grp2 },
804 /*d2*/ { "", TRUE, BYTE, op2(CL, E), (char *)db_Grp2 },
805 /*d3*/ { "", TRUE, LONG, op2(CL, E), (char *)db_Grp2 },
806 /*d4*/ { "aam", TRUE, NONE, 0, 0 },
807 /*d5*/ { "aad", TRUE, NONE, 0, 0 },
808 /*d6*/ { "", FALSE, NONE, 0, 0 },
809 /*d7*/ { "xlat", FALSE, BYTE, op1(BX), 0 },
811 /*d8*/ { "", TRUE, NONE, 0, (char *)db_Esc8 },
812 /*d9*/ { "", TRUE, NONE, 0, (char *)db_Esc9 },
813 /*da*/ { "", TRUE, NONE, 0, (char *)db_Esca },
814 /*db*/ { "", TRUE, NONE, 0, (char *)db_Escb },
815 /*dc*/ { "", TRUE, NONE, 0, (char *)db_Escc },
816 /*dd*/ { "", TRUE, NONE, 0, (char *)db_Escd },
817 /*de*/ { "", TRUE, NONE, 0, (char *)db_Esce },
818 /*df*/ { "", TRUE, NONE, 0, (char *)db_Escf },
820 /*e0*/ { "loopne",FALSE, NONE, op1(Db), 0 },
821 /*e1*/ { "loope", FALSE, NONE, op1(Db), 0 },
822 /*e2*/ { "loop", FALSE, NONE, op1(Db), 0 },
823 /*e3*/ { "jcxz", FALSE, SDEP, op1(Db), "jecxz" },
824 /*e4*/ { "in", FALSE, BYTE, op2(Ib, A), 0 },
825 /*e5*/ { "in", FALSE, LONG, op2(Ib, A) , 0 },
826 /*e6*/ { "out", FALSE, BYTE, op2(A, Ib), 0 },
827 /*e7*/ { "out", FALSE, LONG, op2(A, Ib) , 0 },
829 /*e8*/ { "call", FALSE, NONE, op1(Dl), 0 },
830 /*e9*/ { "jmp", FALSE, NONE, op1(Dl), 0 },
831 /*ea*/ { "ljmp", FALSE, NONE, op1(OS), 0 },
832 /*eb*/ { "jmp", FALSE, NONE, op1(Db), 0 },
833 /*ec*/ { "in", FALSE, BYTE, op2(DX, A), 0 },
834 /*ed*/ { "in", FALSE, LONG, op2(DX, A) , 0 },
835 /*ee*/ { "out", FALSE, BYTE, op2(A, DX), 0 },
836 /*ef*/ { "out", FALSE, LONG, op2(A, DX) , 0 },
838 /*f0*/ { "", FALSE, NONE, 0, 0 },
839 /*f1*/ { "", FALSE, NONE, 0, 0 },
840 /*f2*/ { "", FALSE, NONE, 0, 0 },
841 /*f3*/ { "", FALSE, NONE, 0, 0 },
842 /*f4*/ { "hlt", FALSE, NONE, 0, 0 },
843 /*f5*/ { "cmc", FALSE, NONE, 0, 0 },
844 /*f6*/ { "", TRUE, BYTE, 0, (char *)db_Grp3 },
845 /*f7*/ { "", TRUE, LONG, 0, (char *)db_Grp3 },
847 /*f8*/ { "clc", FALSE, NONE, 0, 0 },
848 /*f9*/ { "stc", FALSE, NONE, 0, 0 },
849 /*fa*/ { "cli", FALSE, NONE, 0, 0 },
850 /*fb*/ { "sti", FALSE, NONE, 0, 0 },
851 /*fc*/ { "cld", FALSE, NONE, 0, 0 },
852 /*fd*/ { "std", FALSE, NONE, 0, 0 },
853 /*fe*/ { "", TRUE, NONE, 0, (char *)db_Grp4 },
854 /*ff*/ { "", TRUE, NONE, 0, (char *)db_Grp5 },
857 static const struct inst db_bad_inst =
858 { "???", FALSE, NONE, 0, 0 }
861 #define f_mod(byte) ((byte)>>6)
862 #define f_reg(byte) (((byte)>>3)&0x7)
863 #define f_rm(byte) ((byte)&0x7)
865 #define sib_ss(byte) ((byte)>>6)
866 #define sib_index(byte) (((byte)>>3)&0x7)
867 #define sib_base(byte) ((byte)&0x7)
870 int is_reg; /* if reg, reg number is in 'disp' */
877 static const char * const db_index_reg_16[8] = {
888 static const char * const db_reg[3][8] = {
889 { "%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh" },
890 { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di" },
891 { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi" }
894 static const char * const db_seg_reg[8] = {
895 "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
899 * lengths for size attributes
901 static const int db_lengths[] = {
911 static unsigned int db_get_task_value( const DBG_ADDR *addr,
912 int size, int is_signed )
914 unsigned int result = 0;
917 if (size != 1 && size != 2 && size != 4) {
918 DEBUG_Printf(DBG_CHN_MESG, "Illegal size specified\n");
920 DEBUG_READ_MEM((void*)DEBUG_ToLinear( addr ), buffer, size);
925 if (is_signed) result = (unsigned int) *(int *)buffer;
926 else result = *(unsigned int *)buffer;
929 if (is_signed) result = (unsigned int) *(short int *)buffer;
930 else result = *(unsigned short int *)buffer;
933 if (is_signed) result = (unsigned int) *(char *)buffer;
934 else result = *(unsigned char *)buffer;
941 #define get_value_inc(result, addr, size, is_signed) \
942 result = db_get_task_value((addr), (size), (is_signed)); \
943 if (!db_disasm_16) (addr)->off += (size); \
944 else (addr)->off = ((addr)->off + (size)) & 0xffff;
947 * Read address at location and return updated location.
949 void db_read_address( DBG_ADDR *addr, int short_addr, int regmodrm,
950 struct i_addr *addrp )
952 int mod, rm, sib, index, disp;
954 mod = f_mod(regmodrm);
958 addrp->is_reg = TRUE;
962 addrp->is_reg = FALSE;
971 get_value_inc(disp, addr, 2, TRUE);
977 addrp->base = db_index_reg_16[rm];
981 get_value_inc(disp, addr, 1, TRUE);
983 addrp->base = db_index_reg_16[rm];
986 get_value_inc(disp, addr, 2, TRUE);
988 addrp->base = db_index_reg_16[rm];
993 if (mod != 3 && rm == 4) {
994 get_value_inc(sib, addr, 1, FALSE);
996 index = sib_index(sib);
998 addrp->index = db_reg[LONG][index];
999 addrp->ss = sib_ss(sib);
1005 get_value_inc(addrp->disp, addr, 4, FALSE);
1010 addrp->base = db_reg[LONG][rm];
1015 get_value_inc(disp, addr, 1, TRUE);
1017 addrp->base = db_reg[LONG][rm];
1021 get_value_inc(disp, addr, 4, FALSE);
1023 addrp->base = db_reg[LONG][rm];
1029 static void db_task_printsym(unsigned int addr, int size)
1036 DEBUG_PrintAddress( &address, db_disasm_16 ? MODE_16 : MODE_32, TRUE );
1039 void db_print_address(char *seg, int size, struct i_addr *addrp, int byref)
1041 if (addrp->is_reg) {
1042 DEBUG_Printf(DBG_CHN_MESG,"%s", db_reg[size][addrp->disp]);
1047 DEBUG_Printf(DBG_CHN_MESG,"%s:", seg);
1050 if (addrp->base != 0 || addrp->index != 0) {
1051 DEBUG_Printf(DBG_CHN_MESG,"0x%x(", addrp->disp);
1053 DEBUG_Printf(DBG_CHN_MESG,"%s", addrp->base);
1055 DEBUG_Printf(DBG_CHN_MESG,",%s,%d", addrp->index, 1<<addrp->ss);
1056 DEBUG_Printf(DBG_CHN_MESG,")");
1060 /* try to get destination of indirect call
1061 does not work for segmented adresses */
1062 if (!seg && byref) {
1066 DEBUG_Printf(DBG_CHN_MESG,"0x%x -> ", addrp->disp);
1067 if (!DEBUG_READ_MEM((void*)addrp->disp, &a1, sizeof(a1))) {
1068 DEBUG_Printf(DBG_CHN_MESG, "(invalid source)");
1069 } else if (!DEBUG_READ_MEM(a1, &a2, sizeof(a2))) {
1070 DEBUG_Printf(DBG_CHN_MESG, "(invalid destination)");
1072 db_task_printsym((unsigned long)a1, 0);
1076 db_task_printsym(addrp->disp, size);
1081 * Disassemble floating-point ("escape") instruction
1082 * and return updated location.
1084 void db_disasm_esc( DBG_ADDR *addr, int inst, int short_addr,
1085 int size, char *seg )
1088 const struct finst *fp;
1090 struct i_addr address;
1093 get_value_inc(regmodrm, addr, 1, FALSE);
1099 fp = &db_Esc_inst[inst - 0xd8][f_reg(regmodrm)];
1100 mod = f_mod(regmodrm);
1103 * Normal address modes.
1105 db_read_address( addr, short_addr, regmodrm, &address);
1106 DEBUG_Printf(DBG_CHN_MESG,fp->f_name);
1107 switch(fp->f_size) {
1109 DEBUG_Printf(DBG_CHN_MESG,"s");
1112 DEBUG_Printf(DBG_CHN_MESG,"l");
1115 DEBUG_Printf(DBG_CHN_MESG,"t");
1118 DEBUG_Printf(DBG_CHN_MESG,"s");
1121 DEBUG_Printf(DBG_CHN_MESG,"l");
1124 DEBUG_Printf(DBG_CHN_MESG,"q");
1129 DEBUG_Printf(DBG_CHN_MESG,"\t");
1130 db_print_address(seg, BYTE, &address, 0);
1134 * 'reg-reg' - special formats
1136 switch (fp->f_rrmode) {
1138 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1139 DEBUG_Printf(DBG_CHN_MESG,"%s\t%%st,%%st(%d)",name,f_rm(regmodrm));
1142 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1143 DEBUG_Printf(DBG_CHN_MESG,"%s\t%%st(%d),%%st",name, f_rm(regmodrm));
1146 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1147 DEBUG_Printf(DBG_CHN_MESG,"%s\t%%st(%d)",name, f_rm(regmodrm));
1150 DEBUG_Printf(DBG_CHN_MESG,"%s", ((char **)fp->f_rrname)[f_rm(regmodrm)]);
1153 DEBUG_Printf(DBG_CHN_MESG,"%s\t%%ax",
1154 ((char **)fp->f_rrname)[f_rm(regmodrm)]);
1157 DEBUG_Printf(DBG_CHN_MESG,"<bad instruction>");
1164 /***********************************************************************
1167 * Disassemble instruction at 'addr'. addr is changed to point to the
1168 * start of the next instruction.
1170 void DEBUG_Disasm( DBG_ADDR *addr, int display )
1176 const struct inst *ip;
1186 struct i_addr address;
1189 * Set this so we get can supress the printout if we need to.
1191 db_display = display;
1192 switch (DEBUG_GetSelectorType(addr->seg))
1195 case MODE_16: db_disasm_16 = 1; break;
1196 case MODE_32: db_disasm_16 = 0; break;
1197 default: DEBUG_Printf(DBG_CHN_MESG, "Bad selector %lx\n", addr->seg); return;
1200 get_value_inc( inst, addr, 1, FALSE );
1218 case 0x66: /* data16 */
1225 short_addr = !short_addr;
1247 DEBUG_Printf(DBG_CHN_MESG,"lock ");
1251 DEBUG_Printf(DBG_CHN_MESG,"repne ");
1255 DEBUG_Printf(DBG_CHN_MESG,"repe "); /* XXX repe VS rep */
1262 get_value_inc(inst, addr, 1, FALSE);
1266 if (inst >= 0xd8 && inst <= 0xdf)
1268 db_disasm_esc( addr, inst, short_addr, size, seg);
1273 get_value_inc(inst, addr, 1, FALSE);
1274 ip = db_inst_0f[inst>>4];
1283 ip = &db_inst_table[inst];
1285 if (ip->i_has_modrm) {
1286 get_value_inc(regmodrm, addr, 1, FALSE);
1287 db_read_address( addr, short_addr, regmodrm, &address);
1290 i_name = ip->i_name;
1291 i_size = ip->i_size;
1292 i_mode = ip->i_mode;
1294 if (ip->i_extra == (char *)db_Grp1 ||
1295 ip->i_extra == (char *)db_Grp2 ||
1296 ip->i_extra == (char *)db_Grp6 ||
1297 ip->i_extra == (char *)db_Grp7 ||
1298 ip->i_extra == (char *)db_Grp8) {
1299 i_name = ((char **)ip->i_extra)[f_reg(regmodrm)];
1301 else if (ip->i_extra == (char *)db_Grp3) {
1302 ip = (struct inst *)ip->i_extra;
1303 ip = &ip[f_reg(regmodrm)];
1304 i_name = ip->i_name;
1305 i_mode = ip->i_mode;
1307 else if (ip->i_extra == (char *)db_Grp4 ||
1308 ip->i_extra == (char *)db_Grp5) {
1309 ip = (struct inst *)ip->i_extra;
1310 ip = &ip[f_reg(regmodrm)];
1311 i_name = ip->i_name;
1312 i_mode = ip->i_mode;
1313 i_size = ip->i_size;
1316 if (i_size == SDEP) {
1320 DEBUG_Printf(DBG_CHN_MESG,i_name);
1322 DEBUG_Printf(DBG_CHN_MESG,ip->i_extra);
1328 DEBUG_Printf(DBG_CHN_MESG,i_name);
1330 if (i_size != NONE) {
1331 if (i_size == BYTE) {
1334 DEBUG_Printf(DBG_CHN_MESG,"b");
1338 else if (i_size == WORD) {
1341 DEBUG_Printf(DBG_CHN_MESG,"w");
1345 else if (size == WORD)
1349 DEBUG_Printf(DBG_CHN_MESG,"w");
1356 DEBUG_Printf(DBG_CHN_MESG,"l");
1363 DEBUG_Printf(DBG_CHN_MESG,"\t");
1367 i_mode >>= 8, first = FALSE)
1369 if (!first && db_display)
1370 DEBUG_Printf(DBG_CHN_MESG,",");
1372 switch (i_mode & 0xFF) {
1377 db_print_address(seg, size, &address, 0);
1384 DEBUG_Printf(DBG_CHN_MESG,"*");
1385 db_print_address(seg, size, &address, 1);
1392 db_print_address(seg, WORD, &address, 0);
1399 db_print_address(seg, BYTE, &address, 0);
1406 DEBUG_Printf(DBG_CHN_MESG,"%s", db_reg[size][f_reg(regmodrm)]);
1413 DEBUG_Printf(DBG_CHN_MESG,"%s", db_reg[WORD][f_reg(regmodrm)]);
1420 DEBUG_Printf(DBG_CHN_MESG,"%s", db_reg[size][f_rm(inst)]);
1427 DEBUG_Printf(DBG_CHN_MESG,"%s", db_seg_reg[f_reg(regmodrm)]);
1434 DEBUG_Printf(DBG_CHN_MESG,"%s", db_seg_reg[f_reg(inst)]);
1441 DEBUG_Printf(DBG_CHN_MESG,"%s", db_reg[size][0]); /* acc */
1449 DEBUG_Printf(DBG_CHN_MESG,"%s:", seg);
1450 DEBUG_Printf(DBG_CHN_MESG,"(%s)", short_addr ? "%bx" : "%ebx");
1457 DEBUG_Printf(DBG_CHN_MESG,"%%cl");
1464 DEBUG_Printf(DBG_CHN_MESG,"%%dx");
1472 DEBUG_Printf(DBG_CHN_MESG,"%s:", seg);
1473 DEBUG_Printf(DBG_CHN_MESG,"(%s)", short_addr ? "%si" : "%esi");
1480 DEBUG_Printf(DBG_CHN_MESG,"%%es:(%s)", short_addr ? "%di" : "%edi");
1487 DEBUG_Printf(DBG_CHN_MESG,"%%cr%d", f_reg(regmodrm));
1494 DEBUG_Printf(DBG_CHN_MESG,"%%dr%d", f_reg(regmodrm));
1501 DEBUG_Printf(DBG_CHN_MESG,"%%tr%d", f_reg(regmodrm));
1506 len = db_lengths[size];
1507 get_value_inc(imm, addr, len, FALSE);/* unsigned */
1510 DEBUG_Printf(DBG_CHN_MESG,"$0x%x", imm);
1515 len = db_lengths[size];
1516 get_value_inc(imm, addr, len, TRUE); /* signed */
1519 DEBUG_Printf(DBG_CHN_MESG,"$%d", imm);
1524 get_value_inc(imm, addr, 1, FALSE); /* unsigned */
1527 DEBUG_Printf(DBG_CHN_MESG,"$0x%x", imm);
1532 get_value_inc(imm, addr, 1, TRUE); /* signed */
1535 DEBUG_Printf(DBG_CHN_MESG,"$%d", imm);
1540 get_value_inc(imm, addr, 2, FALSE); /* unsigned */
1543 DEBUG_Printf(DBG_CHN_MESG,"$0x%x", imm);
1548 get_value_inc(imm, addr, 4, FALSE);
1551 DEBUG_Printf(DBG_CHN_MESG,"$0x%x", imm);
1557 get_value_inc(displ, addr, 2, TRUE);
1560 get_value_inc(displ, addr, 4, TRUE);
1568 DEBUG_Printf(DBG_CHN_MESG,"%s:0x%x",seg, displ);
1570 db_task_printsym(displ, short_addr ? WORD : LONG);
1574 get_value_inc(displ, addr, 1, TRUE);
1581 /* offset only affects low 16 bits */
1582 displ = (addr->off & 0xffff0000)
1583 | ((addr->off + displ) & 0xffff);
1585 else displ += addr->off;
1586 db_task_printsym(displ, size);
1591 get_value_inc(displ, addr, 2, TRUE);
1592 /* offset only affects low 16 bits */
1593 displ = (addr->off & 0xffff0000)
1594 | ((addr->off + displ) & 0xffff);
1597 get_value_inc(displ, addr, 4, TRUE);
1604 db_task_printsym( displ, size );
1610 DEBUG_Printf(DBG_CHN_MESG,"$1");
1617 DEBUG_Printf(DBG_CHN_MESG,"$3");
1624 get_value_inc( address.off, addr, /* offset */
1625 short_addr ? 2 : 4, FALSE );
1626 get_value_inc( address.seg, addr, /* segment */
1630 DEBUG_PrintAddress( &address, short_addr ? MODE_16 : MODE_32, TRUE );
1639 #else /* __i386__ */
1641 void DEBUG_Disasm( DBG_ADDR *addr, int display )
1645 #endif /* __i386__ */