Added missing string.h include.
[wine.git] / debugger / db_disasm.c
blob0345b039d8c7a7445a019f09ea1b7138cf4cdcc8
1 /*
2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
4 * All Rights Reserved.
5 *
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.
27 * HISTORY
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.
32 * [91/10/30 dbg]
34 * Revision 2.5 91/10/09 16:05:58 af
35 * Supported disassemble of non current task by passing task parameter.
36 * [91/08/29 tak]
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.
48 * [90/08/27 dbg]
50 * Import db_sym.h. Print instruction displacements in
51 * current radix (signed). Change calling sequence of
52 * db_disasm.
53 * [90/08/21 dbg]
54 * Fix includes.
55 * [90/08/08 dbg]
56 * Created.
57 * [90/07/25 dbg]
62 * Instruction disassembler.
65 #include <stdio.h>
66 #include "debugger.h"
69 * Switch to disassemble 16-bit code.
71 static BOOL32 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
76 * instruction.
78 static BOOL32 db_display = FALSE;
81 * Size attributes
83 #define BYTE 0
84 #define WORD 1
85 #define LONG 2
86 #define QUAD 3
87 #define SNGL 4
88 #define DBLR 5
89 #define EXTR 6
90 #define SDEP 7
91 #define NONE 8
94 * Addressing modes
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' */
131 struct inst {
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 */
139 #define op1(x) (x)
140 #define op2(x,y) ((x)|((y)<<8))
141 #define op3(x,y,z) ((x)|((y)<<8)|((z)<<16))
143 struct finst {
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[] = {
152 "sldt",
153 "str",
154 "lldt",
155 "ltr",
156 "verr",
157 "verw",
162 static const char * const db_Grp7[] = {
163 "sgdt",
164 "sidt",
165 "lgdt",
166 "lidt",
167 "smsw",
169 "lmsw",
170 "invlpg"
173 static const char * const db_Grp8[] = {
178 "bt",
179 "bts",
180 "btr",
181 "btc"
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(Is, 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[] = {
343 db_inst_0f0x,
345 db_inst_0f2x,
351 db_inst_0f8x,
352 db_inst_0f9x,
353 db_inst_0fax,
354 db_inst_0fbx,
355 db_inst_0fcx,
356 db_inst_0fdx,
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",
375 "fincstp"
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[] = {
491 "add",
492 "or",
493 "adc",
494 "sbb",
495 "and",
496 "sub",
497 "xor",
498 "cmp"
501 static const char * const db_Grp2[] = {
502 "rol",
503 "ror",
504 "rcl",
505 "rcr",
506 "shl",
507 "shr",
508 "shl",
509 "sar"
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)
848 struct i_addr {
849 int is_reg; /* if reg, reg number is in 'disp' */
850 int disp;
851 const char * base;
852 const char * index;
853 int ss;
856 static const char * const db_index_reg_16[8] = {
857 "%bx,%si",
858 "%bx,%di",
859 "%bp,%si",
860 "%bp,%di",
861 "%si",
862 "%di",
863 "%bp",
864 "%bx"
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[] = {
881 1, /* BYTE */
882 2, /* WORD */
883 4, /* LONG */
884 8, /* QUAD */
885 4, /* SNGL */
886 8, /* DBLR */
887 10, /* EXTR */
890 static unsigned int db_get_task_value( const DBG_ADDR *addr,
891 int size, int is_signed )
893 unsigned int result;
894 unsigned char *p = DBG_ADDR_TO_LIN( addr );
896 switch(size)
898 case 4:
899 if (is_signed) result = (unsigned int) *(int *)p;
900 else result = *(unsigned int *)p;
901 break;
902 case 2:
903 if (is_signed) result = (unsigned int) *(short int *)p;
904 else result = *(unsigned short int *)p;
905 break;
906 case 1:
907 if (is_signed) result = (unsigned int) *(char *)p;
908 else result = *(unsigned char *)p;
909 break;
910 default:
911 fprintf(stderr, "Illegal size specified\n");
912 result = 0;
913 break;
915 return result;
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);
932 rm = f_rm(regmodrm);
934 if (mod == 3) {
935 addrp->is_reg = TRUE;
936 addrp->disp = rm;
937 return;
939 addrp->is_reg = FALSE;
940 addrp->index = 0;
942 if (short_addr) {
943 addrp->index = 0;
944 addrp->ss = 0;
945 switch (mod) {
946 case 0:
947 if (rm == 6) {
948 get_value_inc(disp, addr, 2, TRUE);
949 addrp->disp = disp;
950 addrp->base = 0;
952 else {
953 addrp->disp = 0;
954 addrp->base = db_index_reg_16[rm];
956 break;
957 case 1:
958 get_value_inc(disp, addr, 1, TRUE);
959 addrp->disp = disp;
960 addrp->base = db_index_reg_16[rm];
961 break;
962 case 2:
963 get_value_inc(disp, addr, 2, TRUE);
964 addrp->disp = disp;
965 addrp->base = db_index_reg_16[rm];
966 break;
969 else {
970 if (mod != 3 && rm == 4) {
971 get_value_inc(sib, addr, 1, FALSE);
972 rm = sib_base(sib);
973 index = sib_index(sib);
974 if (index != 4)
975 addrp->index = db_reg[LONG][index];
976 addrp->ss = sib_ss(sib);
979 switch (mod) {
980 case 0:
981 if (rm == 5) {
982 get_value_inc(addrp->disp, addr, 4, FALSE);
983 addrp->base = 0;
985 else {
986 addrp->disp = 0;
987 addrp->base = db_reg[LONG][rm];
989 break;
991 case 1:
992 get_value_inc(disp, addr, 1, TRUE);
993 addrp->disp = disp;
994 addrp->base = db_reg[LONG][rm];
995 break;
997 case 2:
998 get_value_inc(disp, addr, 4, FALSE);
999 addrp->disp = disp;
1000 addrp->base = db_reg[LONG][rm];
1001 break;
1006 static void db_task_printsym(unsigned int addr, int size)
1008 DBG_ADDR address = { NULL, 0, addr };
1009 DEBUG_PrintAddress( &address, db_disasm_16 ? 16 : 32, TRUE );
1012 void
1013 db_print_address(seg, size, addrp, byref)
1014 char * seg;
1015 int size;
1016 struct i_addr *addrp;
1017 int byref;
1019 if (addrp->is_reg) {
1020 fprintf(stderr,"%s", db_reg[size][addrp->disp]);
1021 return;
1024 if (seg) {
1025 fprintf(stderr,"%s:", seg);
1028 if (addrp->base != 0 || addrp->index != 0) {
1029 fprintf(stderr,"0x%x", addrp->disp);
1030 fprintf(stderr,"(");
1031 if (addrp->base)
1032 fprintf(stderr,"%s", addrp->base);
1033 if (addrp->index)
1034 fprintf(stderr,",%s,%d", addrp->index, 1<<addrp->ss);
1035 fprintf(stderr,")");
1037 else {
1039 /* try to get destination of indirect call)
1040 works not for segmented adresses */
1041 if (!seg && byref) {
1042 DBG_ADDR dbg_addr = {0,0,*(LPDWORD)(addrp->disp)};
1043 fprintf(stderr,"0x%x -> ", addrp->disp);
1044 if ( DEBUG_IsBadReadPtr( &dbg_addr, sizeof(DWORD)))
1045 fprintf(stderr, "(invalid destination)");
1046 else
1047 db_task_printsym(dbg_addr.off, 0);
1049 else
1050 db_task_printsym(addrp->disp, size);
1055 * Disassemble floating-point ("escape") instruction
1056 * and return updated location.
1058 void db_disasm_esc( DBG_ADDR *addr, int inst, int short_addr,
1059 int size, char *seg )
1061 int regmodrm;
1062 const struct finst *fp;
1063 int mod;
1064 struct i_addr address;
1065 const char * name;
1067 get_value_inc(regmodrm, addr, 1, FALSE);
1068 if( !db_display )
1070 return;
1073 fp = &db_Esc_inst[inst - 0xd8][f_reg(regmodrm)];
1074 mod = f_mod(regmodrm);
1075 if (mod != 3) {
1077 * Normal address modes.
1079 db_read_address( addr, short_addr, regmodrm, &address);
1080 fprintf(stderr,fp->f_name);
1081 switch(fp->f_size) {
1082 case SNGL:
1083 fprintf(stderr,"s");
1084 break;
1085 case DBLR:
1086 fprintf(stderr,"l");
1087 break;
1088 case EXTR:
1089 fprintf(stderr,"t");
1090 break;
1091 case WORD:
1092 fprintf(stderr,"s");
1093 break;
1094 case LONG:
1095 fprintf(stderr,"l");
1096 break;
1097 case QUAD:
1098 fprintf(stderr,"q");
1099 break;
1100 default:
1101 break;
1103 fprintf(stderr,"\t");
1104 db_print_address(seg, BYTE, &address, 0);
1106 else {
1108 * 'reg-reg' - special formats
1110 switch (fp->f_rrmode) {
1111 case op2(ST,STI):
1112 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1113 fprintf(stderr,"%s\t%%st,%%st(%d)",name,f_rm(regmodrm));
1114 break;
1115 case op2(STI,ST):
1116 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1117 fprintf(stderr,"%s\t%%st(%d),%%st",name, f_rm(regmodrm));
1118 break;
1119 case op1(STI):
1120 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1121 fprintf(stderr,"%s\t%%st(%d)",name, f_rm(regmodrm));
1122 break;
1123 case op1(X):
1124 fprintf(stderr,"%s", ((char **)fp->f_rrname)[f_rm(regmodrm)]);
1125 break;
1126 case op1(XA):
1127 fprintf(stderr,"%s\t%%ax",
1128 ((char **)fp->f_rrname)[f_rm(regmodrm)]);
1129 break;
1130 default:
1131 fprintf(stderr,"<bad instruction>");
1132 break;
1138 /***********************************************************************
1139 * DEBUG_Disasm
1141 * Disassemble instruction at 'addr'. addr is changed to point to the
1142 * start of the next instruction.
1144 void DEBUG_Disasm( DBG_ADDR *addr, int display )
1146 int inst;
1147 int size;
1148 int short_addr;
1149 char * seg;
1150 const struct inst *ip;
1151 const char *i_name;
1152 int i_size;
1153 int i_mode;
1154 int regmodrm = 0;
1155 BOOL32 first;
1156 int displ;
1157 int prefix;
1158 int imm;
1159 int len;
1160 struct i_addr address;
1163 * Set this so we get can supress the printout if we need to.
1165 db_display = display;
1166 db_disasm_16 = IS_SELECTOR_V86(addr->seg) || !IS_SELECTOR_32BIT(addr->seg);
1168 get_value_inc( inst, addr, 1, FALSE );
1170 if (db_disasm_16) {
1171 short_addr = TRUE;
1172 size = WORD;
1174 else {
1175 short_addr = FALSE;
1176 size = LONG;
1178 seg = 0;
1181 * Get prefixes
1183 prefix = TRUE;
1184 do {
1185 switch (inst) {
1186 case 0x66: /* data16 */
1187 if (size == LONG)
1188 size = WORD;
1189 else
1190 size = LONG;
1191 break;
1192 case 0x67:
1193 short_addr = !short_addr;
1194 break;
1195 case 0x26:
1196 seg = "%es";
1197 break;
1198 case 0x36:
1199 seg = "%ss";
1200 break;
1201 case 0x2e:
1202 seg = "%cs";
1203 break;
1204 case 0x3e:
1205 seg = "%ds";
1206 break;
1207 case 0x64:
1208 seg = "%fs";
1209 break;
1210 case 0x65:
1211 seg = "%gs";
1212 break;
1213 case 0xf0:
1214 if( db_display )
1215 fprintf(stderr,"lock ");
1216 break;
1217 case 0xf2:
1218 if( db_display )
1219 fprintf(stderr,"repne ");
1220 break;
1221 case 0xf3:
1222 if( db_display )
1223 fprintf(stderr,"repe "); /* XXX repe VS rep */
1224 break;
1225 default:
1226 prefix = FALSE;
1227 break;
1229 if (prefix) {
1230 get_value_inc(inst, addr, 1, FALSE);
1232 } while (prefix);
1234 if (inst >= 0xd8 && inst <= 0xdf)
1236 db_disasm_esc( addr, inst, short_addr, size, seg);
1237 return;
1240 if (inst == 0x0f) {
1241 get_value_inc(inst, addr, 1, FALSE);
1242 ip = db_inst_0f[inst>>4];
1243 if (ip == 0) {
1244 ip = &db_bad_inst;
1246 else {
1247 ip = &ip[inst&0xf];
1250 else
1251 ip = &db_inst_table[inst];
1253 if (ip->i_has_modrm) {
1254 get_value_inc(regmodrm, addr, 1, FALSE);
1255 db_read_address( addr, short_addr, regmodrm, &address);
1258 i_name = ip->i_name;
1259 i_size = ip->i_size;
1260 i_mode = ip->i_mode;
1262 if (ip->i_extra == (char *)db_Grp1 ||
1263 ip->i_extra == (char *)db_Grp2 ||
1264 ip->i_extra == (char *)db_Grp6 ||
1265 ip->i_extra == (char *)db_Grp7 ||
1266 ip->i_extra == (char *)db_Grp8) {
1267 i_name = ((char **)ip->i_extra)[f_reg(regmodrm)];
1269 else if (ip->i_extra == (char *)db_Grp3) {
1270 ip = (struct inst *)ip->i_extra;
1271 ip = &ip[f_reg(regmodrm)];
1272 i_name = ip->i_name;
1273 i_mode = ip->i_mode;
1275 else if (ip->i_extra == (char *)db_Grp4 ||
1276 ip->i_extra == (char *)db_Grp5) {
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;
1281 i_size = ip->i_size;
1284 if (i_size == SDEP) {
1285 if( db_display )
1287 if (size == WORD)
1288 fprintf(stderr,i_name);
1289 else
1290 fprintf(stderr,ip->i_extra);
1293 else {
1294 if( db_display )
1296 fprintf(stderr,i_name);
1298 if (i_size != NONE) {
1299 if (i_size == BYTE) {
1300 if( db_display )
1302 fprintf(stderr,"b");
1304 size = BYTE;
1306 else if (i_size == WORD) {
1307 if( db_display )
1309 fprintf(stderr,"w");
1311 size = WORD;
1313 else if (size == WORD)
1315 if( db_display )
1317 fprintf(stderr,"w");
1320 else
1322 if( db_display )
1324 fprintf(stderr,"l");
1329 if( db_display )
1331 fprintf(stderr,"\t");
1333 for (first = TRUE;
1334 i_mode != 0;
1335 i_mode >>= 8, first = FALSE)
1337 if (!first && db_display)
1338 fprintf(stderr,",");
1340 switch (i_mode & 0xFF) {
1342 case E:
1343 if( db_display )
1345 db_print_address(seg, size, &address, 0);
1347 break;
1349 case Eind:
1350 if( db_display )
1352 fprintf(stderr,"*");
1353 db_print_address(seg, size, &address, 1);
1355 break;
1357 case Ew:
1358 if( db_display )
1360 db_print_address(seg, WORD, &address, 0);
1362 break;
1364 case Eb:
1365 if( db_display )
1367 db_print_address(seg, BYTE, &address, 0);
1369 break;
1371 case R:
1372 if( db_display )
1374 fprintf(stderr,"%s", db_reg[size][f_reg(regmodrm)]);
1376 break;
1378 case Rw:
1379 if( db_display )
1381 fprintf(stderr,"%s", db_reg[WORD][f_reg(regmodrm)]);
1383 break;
1385 case Ri:
1386 if( db_display )
1388 fprintf(stderr,"%s", db_reg[size][f_rm(inst)]);
1390 break;
1392 case S:
1393 if( db_display )
1395 fprintf(stderr,"%s", db_seg_reg[f_reg(regmodrm)]);
1397 break;
1399 case Si:
1400 if( db_display )
1402 fprintf(stderr,"%s", db_seg_reg[f_reg(inst)]);
1404 break;
1406 case A:
1407 if( db_display )
1409 fprintf(stderr,"%s", db_reg[size][0]); /* acc */
1411 break;
1413 case BX:
1414 if( db_display )
1416 if (seg)
1417 fprintf(stderr,"%s:", seg);
1418 fprintf(stderr,"(%s)", short_addr ? "%bx" : "%ebx");
1420 break;
1422 case CL:
1423 if( db_display )
1425 fprintf(stderr,"%%cl");
1427 break;
1429 case DX:
1430 if( db_display )
1432 fprintf(stderr,"%%dx");
1434 break;
1436 case SI:
1437 if( db_display )
1439 if (seg)
1440 fprintf(stderr,"%s:", seg);
1441 fprintf(stderr,"(%s)", short_addr ? "%si" : "%esi");
1443 break;
1445 case DI:
1446 if( db_display )
1448 fprintf(stderr,"%%es:(%s)", short_addr ? "%di" : "%edi");
1450 break;
1452 case CR:
1453 if( db_display )
1455 fprintf(stderr,"%%cr%d", f_reg(regmodrm));
1457 break;
1459 case DR:
1460 if( db_display )
1462 fprintf(stderr,"%%dr%d", f_reg(regmodrm));
1464 break;
1466 case TR:
1467 if( db_display )
1469 fprintf(stderr,"%%tr%d", f_reg(regmodrm));
1471 break;
1473 case I:
1474 len = db_lengths[size];
1475 get_value_inc(imm, addr, len, FALSE);/* unsigned */
1476 if( db_display )
1478 fprintf(stderr,"$0x%x", imm);
1480 break;
1482 case Is:
1483 len = db_lengths[size];
1484 get_value_inc(imm, addr, len, TRUE); /* signed */
1485 if( db_display )
1487 fprintf(stderr,"$%d", imm);
1489 break;
1491 case Ib:
1492 get_value_inc(imm, addr, 1, FALSE); /* unsigned */
1493 if( db_display )
1495 fprintf(stderr,"$0x%x", imm);
1497 break;
1499 case Ibs:
1500 get_value_inc(imm, addr, 1, TRUE); /* signed */
1501 if( db_display )
1503 fprintf(stderr,"$%d", imm);
1505 break;
1507 case Iw:
1508 get_value_inc(imm, addr, 2, FALSE); /* unsigned */
1509 if( db_display )
1511 fprintf(stderr,"$0x%x", imm);
1513 break;
1515 case Il:
1516 get_value_inc(imm, addr, 4, FALSE);
1517 if( db_display )
1519 fprintf(stderr,"$0x%x", imm);
1521 break;
1523 case O:
1524 if (short_addr) {
1525 get_value_inc(displ, addr, 2, TRUE);
1527 else {
1528 get_value_inc(displ, addr, 4, TRUE);
1530 if( !db_display )
1532 break;
1535 if (seg)
1536 fprintf(stderr,"%s:0x%x",seg, displ);
1537 else
1538 db_task_printsym(displ, short_addr ? WORD : LONG);
1539 break;
1541 case Db:
1542 get_value_inc(displ, addr, 1, TRUE);
1543 if( !db_display )
1545 break;
1548 if (short_addr) {
1549 /* offset only affects low 16 bits */
1550 displ = (addr->off & 0xffff0000)
1551 | ((addr->off + displ) & 0xffff);
1553 else displ += addr->off;
1554 db_task_printsym(displ, short_addr ? WORD : LONG);
1555 break;
1557 case Dl:
1558 if (short_addr) {
1559 get_value_inc(displ, addr, 2, TRUE);
1560 /* offset only affects low 16 bits */
1561 displ = (addr->off & 0xffff0000)
1562 | ((addr->off + displ) & 0xffff);
1564 else {
1565 get_value_inc(displ, addr, 4, TRUE);
1566 displ += addr->off;
1568 if( !db_display )
1570 break;
1572 db_task_printsym( displ, short_addr ? WORD : LONG);
1573 break;
1575 case o1:
1576 if( db_display )
1578 fprintf(stderr,"$1");
1580 break;
1582 case o3:
1583 if( db_display )
1585 fprintf(stderr,"$3");
1587 break;
1589 case OS:
1591 DBG_ADDR address;
1592 get_value_inc( address.off, addr, /* offset */
1593 short_addr ? 2 : 4, FALSE );
1594 get_value_inc( address.seg, addr, /* segment */
1595 2, FALSE );
1596 if( db_display )
1598 DEBUG_PrintAddress( &address, short_addr ? 16 : 32,
1599 TRUE );
1603 break;