Added the TEXT() and MAKELRESULT() definitions.
[wine/multimedia.git] / debugger / db_disasm.c
blobcde7c29009a7ac48179834abf7fc415aebe100e2
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 "windows.h"
67 #include "debugger.h"
70 * Switch to disassemble 16-bit code.
72 static BOOL32 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
77 * instruction.
79 static BOOL32 db_display = FALSE;
82 * Size attributes
84 #define BYTE 0
85 #define WORD 1
86 #define LONG 2
87 #define QUAD 3
88 #define SNGL 4
89 #define DBLR 5
90 #define EXTR 6
91 #define SDEP 7
92 #define NONE 8
95 * Addressing modes
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' */
132 struct inst {
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 */
140 #define op1(x) (x)
141 #define op2(x,y) ((x)|((y)<<8))
142 #define op3(x,y,z) ((x)|((y)<<8)|((z)<<16))
144 struct finst {
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[] = {
153 "sldt",
154 "str",
155 "lldt",
156 "ltr",
157 "verr",
158 "verw",
163 static const char * const db_Grp7[] = {
164 "sgdt",
165 "sidt",
166 "lgdt",
167 "lidt",
168 "smsw",
170 "lmsw",
171 "invlpg"
174 static const char * const db_Grp8[] = {
179 "bt",
180 "bts",
181 "btr",
182 "btc"
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_0f8x[] = {
226 /*80*/ { "jo", FALSE, NONE, op1(Dl), 0 },
227 /*81*/ { "jno", FALSE, NONE, op1(Dl), 0 },
228 /*82*/ { "jb", FALSE, NONE, op1(Dl), 0 },
229 /*83*/ { "jnb", FALSE, NONE, op1(Dl), 0 },
230 /*84*/ { "jz", FALSE, NONE, op1(Dl), 0 },
231 /*85*/ { "jnz", FALSE, NONE, op1(Dl), 0 },
232 /*86*/ { "jbe", FALSE, NONE, op1(Dl), 0 },
233 /*87*/ { "jnbe", FALSE, NONE, op1(Dl), 0 },
235 /*88*/ { "js", FALSE, NONE, op1(Dl), 0 },
236 /*89*/ { "jns", FALSE, NONE, op1(Dl), 0 },
237 /*8a*/ { "jp", FALSE, NONE, op1(Dl), 0 },
238 /*8b*/ { "jnp", FALSE, NONE, op1(Dl), 0 },
239 /*8c*/ { "jl", FALSE, NONE, op1(Dl), 0 },
240 /*8d*/ { "jnl", FALSE, NONE, op1(Dl), 0 },
241 /*8e*/ { "jle", FALSE, NONE, op1(Dl), 0 },
242 /*8f*/ { "jnle", FALSE, NONE, op1(Dl), 0 },
245 static const struct inst db_inst_0f9x[] = {
246 /*90*/ { "seto", TRUE, NONE, op1(Eb), 0 },
247 /*91*/ { "setno", TRUE, NONE, op1(Eb), 0 },
248 /*92*/ { "setb", TRUE, NONE, op1(Eb), 0 },
249 /*93*/ { "setnb", TRUE, NONE, op1(Eb), 0 },
250 /*94*/ { "setz", TRUE, NONE, op1(Eb), 0 },
251 /*95*/ { "setnz", TRUE, NONE, op1(Eb), 0 },
252 /*96*/ { "setbe", TRUE, NONE, op1(Eb), 0 },
253 /*97*/ { "setnbe",TRUE, NONE, op1(Eb), 0 },
255 /*98*/ { "sets", TRUE, NONE, op1(Eb), 0 },
256 /*99*/ { "setns", TRUE, NONE, op1(Eb), 0 },
257 /*9a*/ { "setp", TRUE, NONE, op1(Eb), 0 },
258 /*9b*/ { "setnp", TRUE, NONE, op1(Eb), 0 },
259 /*9c*/ { "setl", TRUE, NONE, op1(Eb), 0 },
260 /*9d*/ { "setnl", TRUE, NONE, op1(Eb), 0 },
261 /*9e*/ { "setle", TRUE, NONE, op1(Eb), 0 },
262 /*9f*/ { "setnle",TRUE, NONE, op1(Eb), 0 },
265 static const struct inst db_inst_0fax[] = {
266 /*a0*/ { "push", FALSE, NONE, op1(Si), 0 },
267 /*a1*/ { "pop", FALSE, NONE, op1(Si), 0 },
268 /*a2*/ { "cpuid", FALSE, NONE, 0, 0 },
269 /*a3*/ { "bt", TRUE, LONG, op2(E,R), 0 },
270 /*a4*/ { "shld", TRUE, LONG, op3(Ib,E,R), 0 },
271 /*a5*/ { "shld", TRUE, LONG, op3(CL,E,R), 0 },
272 /*a6*/ { "", FALSE, NONE, 0, 0 },
273 /*a7*/ { "", FALSE, NONE, 0, 0 },
275 /*a8*/ { "push", FALSE, NONE, op1(Si), 0 },
276 /*a9*/ { "pop", FALSE, NONE, op1(Si), 0 },
277 /*aa*/ { "", FALSE, NONE, 0, 0 },
278 /*ab*/ { "bts", TRUE, LONG, op2(E,R), 0 },
279 /*ac*/ { "shrd", TRUE, LONG, op3(Ib,E,R), 0 },
280 /*ad*/ { "shrd", TRUE, LONG, op3(CL,E,R), 0 },
281 /*a6*/ { "", FALSE, NONE, 0, 0 },
282 /*a7*/ { "imul", TRUE, LONG, op2(E,R), 0 },
285 static const struct inst db_inst_0fbx[] = {
286 /*b0*/ { "cmpxchg",TRUE, BYTE, op2(E, R), 0 },
287 /*b1*/ { "cmpxchg",TRUE, LONG, op2(E, R), 0 },
288 /*b2*/ { "lss", TRUE, LONG, op2(E, R), 0 },
289 /*b3*/ { "bts", TRUE, LONG, op2(R, E), 0 },
290 /*b4*/ { "lfs", TRUE, LONG, op2(E, R), 0 },
291 /*b5*/ { "lgs", TRUE, LONG, op2(E, R), 0 },
292 /*b6*/ { "movzb", TRUE, LONG, op2(E, R), 0 },
293 /*b7*/ { "movzw", TRUE, LONG, op2(E, R), 0 },
295 /*b8*/ { "", FALSE, NONE, 0, 0 },
296 /*b9*/ { "", FALSE, NONE, 0, 0 },
297 /*ba*/ { "", TRUE, LONG, op2(Is, E), (char *)db_Grp8 },
298 /*bb*/ { "btc", TRUE, LONG, op2(R, E), 0 },
299 /*bc*/ { "bsf", TRUE, LONG, op2(E, R), 0 },
300 /*bd*/ { "bsr", TRUE, LONG, op2(E, R), 0 },
301 /*be*/ { "movsb", TRUE, LONG, op2(E, R), 0 },
302 /*bf*/ { "movsw", TRUE, LONG, op2(E, R), 0 },
305 static const struct inst db_inst_0fcx[] = {
306 /*c0*/ { "xadd", TRUE, BYTE, op2(R, E), 0 },
307 /*c1*/ { "xadd", TRUE, LONG, op2(R, E), 0 },
308 /*c2*/ { "", FALSE, NONE, 0, 0 },
309 /*c3*/ { "", FALSE, NONE, 0, 0 },
310 /*c4*/ { "", FALSE, NONE, 0, 0 },
311 /*c5*/ { "", FALSE, NONE, 0, 0 },
312 /*c6*/ { "", FALSE, NONE, 0, 0 },
313 /*c7*/ { "", FALSE, NONE, 0, 0 },
314 /*c8*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
315 /*c9*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
316 /*ca*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
317 /*cb*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
318 /*cc*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
319 /*cd*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
320 /*ce*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
321 /*cf*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
324 static const struct inst db_inst_0fdx[] = {
325 /*c0*/ { "cmpxchg",TRUE, BYTE, op2(R, E), 0 },
326 /*c1*/ { "cmpxchg",TRUE, LONG, op2(R, E), 0 },
327 /*c2*/ { "", FALSE, NONE, 0, 0 },
328 /*c3*/ { "", FALSE, NONE, 0, 0 },
329 /*c4*/ { "", FALSE, NONE, 0, 0 },
330 /*c5*/ { "", FALSE, NONE, 0, 0 },
331 /*c6*/ { "", FALSE, NONE, 0, 0 },
332 /*c7*/ { "", FALSE, NONE, 0, 0 },
333 /*c8*/ { "", FALSE, NONE, 0, 0 },
334 /*c9*/ { "", FALSE, NONE, 0, 0 },
335 /*ca*/ { "", FALSE, NONE, 0, 0 },
336 /*cb*/ { "", FALSE, NONE, 0, 0 },
337 /*cc*/ { "", FALSE, NONE, 0, 0 },
338 /*cd*/ { "", FALSE, NONE, 0, 0 },
339 /*ce*/ { "", FALSE, NONE, 0, 0 },
340 /*cf*/ { "", FALSE, NONE, 0, 0 },
343 static const struct inst * const db_inst_0f[] = {
344 db_inst_0f0x,
346 db_inst_0f2x,
352 db_inst_0f8x,
353 db_inst_0f9x,
354 db_inst_0fax,
355 db_inst_0fbx,
356 db_inst_0fcx,
357 db_inst_0fdx,
362 static const char * const db_Esc92[] = {
363 "fnop", "", "", "", "", "", "", ""
365 static const char * const db_Esc93[] = {
366 "", "", "", "", "", "", "", ""
368 static const char * const db_Esc94[] = {
369 "fchs", "fabs", "", "", "ftst", "fxam", "", ""
371 static const char * const db_Esc95[] = {
372 "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
374 static const char * const db_Esc96[] = {
375 "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
376 "fincstp"
378 static const char * const db_Esc97[] = {
379 "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
382 static const char * const db_Esca4[] = {
383 "", "fucompp","", "", "", "", "", ""
386 static const char * const db_Escb4[] = {
387 "", "", "fnclex","fninit","", "", "", ""
390 static const char * const db_Esce3[] = {
391 "", "fcompp","", "", "", "", "", ""
394 static const char * const db_Escf4[] = {
395 "fnstsw","", "", "", "", "", "", ""
398 static const struct finst db_Esc8[] = {
399 /*0*/ { "fadd", SNGL, op2(STI,ST), 0 },
400 /*1*/ { "fmul", SNGL, op2(STI,ST), 0 },
401 /*2*/ { "fcom", SNGL, op2(STI,ST), 0 },
402 /*3*/ { "fcomp", SNGL, op2(STI,ST), 0 },
403 /*4*/ { "fsub", SNGL, op2(STI,ST), 0 },
404 /*5*/ { "fsubr", SNGL, op2(STI,ST), 0 },
405 /*6*/ { "fdiv", SNGL, op2(STI,ST), 0 },
406 /*7*/ { "fdivr", SNGL, op2(STI,ST), 0 },
409 static const struct finst db_Esc9[] = {
410 /*0*/ { "fld", SNGL, op1(STI), 0 },
411 /*1*/ { "", NONE, op1(STI), "fxch" },
412 /*2*/ { "fst", SNGL, op1(X), (char *)db_Esc92 },
413 /*3*/ { "fstp", SNGL, op1(X), (char *)db_Esc93 },
414 /*4*/ { "fldenv", NONE, op1(X), (char *)db_Esc94 },
415 /*5*/ { "fldcw", NONE, op1(X), (char *)db_Esc95 },
416 /*6*/ { "fnstenv",NONE, op1(X), (char *)db_Esc96 },
417 /*7*/ { "fnstcw", NONE, op1(X), (char *)db_Esc97 },
420 static const struct finst db_Esca[] = {
421 /*0*/ { "fiadd", WORD, 0, 0 },
422 /*1*/ { "fimul", WORD, 0, 0 },
423 /*2*/ { "ficom", WORD, 0, 0 },
424 /*3*/ { "ficomp", WORD, 0, 0 },
425 /*4*/ { "fisub", WORD, op1(X), (char *)db_Esca4 },
426 /*5*/ { "fisubr", WORD, 0, 0 },
427 /*6*/ { "fidiv", WORD, 0, 0 },
428 /*7*/ { "fidivr", WORD, 0, 0 }
431 static const struct finst db_Escb[] = {
432 /*0*/ { "fild", WORD, 0, 0 },
433 /*1*/ { "", NONE, 0, 0 },
434 /*2*/ { "fist", WORD, 0, 0 },
435 /*3*/ { "fistp", WORD, 0, 0 },
436 /*4*/ { "", WORD, op1(X), (char *)db_Escb4 },
437 /*5*/ { "fld", EXTR, 0, 0 },
438 /*6*/ { "", WORD, 0, 0 },
439 /*7*/ { "fstp", EXTR, 0, 0 },
442 static const struct finst db_Escc[] = {
443 /*0*/ { "fadd", DBLR, op2(ST,STI), 0 },
444 /*1*/ { "fmul", DBLR, op2(ST,STI), 0 },
445 /*2*/ { "fcom", DBLR, op2(ST,STI), 0 },
446 /*3*/ { "fcomp", DBLR, op2(ST,STI), 0 },
447 /*4*/ { "fsub", DBLR, op2(ST,STI), "fsubr" },
448 /*5*/ { "fsubr", DBLR, op2(ST,STI), "fsub" },
449 /*6*/ { "fdiv", DBLR, op2(ST,STI), "fdivr" },
450 /*7*/ { "fdivr", DBLR, op2(ST,STI), "fdiv" },
453 static const struct finst db_Escd[] = {
454 /*0*/ { "fld", DBLR, op1(STI), "ffree" },
455 /*1*/ { "", NONE, 0, 0 },
456 /*2*/ { "fst", DBLR, op1(STI), 0 },
457 /*3*/ { "fstp", DBLR, op1(STI), 0 },
458 /*4*/ { "frstor", NONE, op1(STI), "fucom" },
459 /*5*/ { "", NONE, op1(STI), "fucomp" },
460 /*6*/ { "fnsave", NONE, 0, 0 },
461 /*7*/ { "fnstsw", NONE, 0, 0 },
464 static const struct finst db_Esce[] = {
465 /*0*/ { "fiadd", LONG, op2(ST,STI), "faddp" },
466 /*1*/ { "fimul", LONG, op2(ST,STI), "fmulp" },
467 /*2*/ { "ficom", LONG, 0, 0 },
468 /*3*/ { "ficomp", LONG, op1(X), (char *)db_Esce3 },
469 /*4*/ { "fisub", LONG, op2(ST,STI), "fsubrp" },
470 /*5*/ { "fisubr", LONG, op2(ST,STI), "fsubp" },
471 /*6*/ { "fidiv", LONG, op2(ST,STI), "fdivrp" },
472 /*7*/ { "fidivr", LONG, op2(ST,STI), "fdivp" },
475 static const struct finst db_Escf[] = {
476 /*0*/ { "fild", LONG, 0, 0 },
477 /*1*/ { "", LONG, 0, 0 },
478 /*2*/ { "fist", LONG, 0, 0 },
479 /*3*/ { "fistp", LONG, 0, 0 },
480 /*4*/ { "fbld", NONE, op1(XA), (char *)db_Escf4 },
481 /*5*/ { "fld", QUAD, 0, 0 },
482 /*6*/ { "fbstp", NONE, 0, 0 },
483 /*7*/ { "fstp", QUAD, 0, 0 },
486 static const struct finst * const db_Esc_inst[] = {
487 db_Esc8, db_Esc9, db_Esca, db_Escb,
488 db_Escc, db_Escd, db_Esce, db_Escf
491 static const char * const db_Grp1[] = {
492 "add",
493 "or",
494 "adc",
495 "sbb",
496 "and",
497 "sub",
498 "xor",
499 "cmp"
502 static const char * const db_Grp2[] = {
503 "rol",
504 "ror",
505 "rcl",
506 "rcr",
507 "shl",
508 "shr",
509 "shl",
510 "sar"
513 static const struct inst db_Grp3[] = {
514 { "test", TRUE, NONE, op2(I,E), 0 },
515 { "test", TRUE, NONE, op2(I,E), 0 },
516 { "not", TRUE, NONE, op1(E), 0 },
517 { "neg", TRUE, NONE, op1(E), 0 },
518 { "mul", TRUE, NONE, op2(E,A), 0 },
519 { "imul", TRUE, NONE, op2(E,A), 0 },
520 { "div", TRUE, NONE, op2(E,A), 0 },
521 { "idiv", TRUE, NONE, op2(E,A), 0 },
524 static const struct inst db_Grp4[] = {
525 { "inc", TRUE, BYTE, op1(E), 0 },
526 { "dec", TRUE, BYTE, op1(E), 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 },
532 { "", TRUE, NONE, 0, 0 }
535 static const struct inst db_Grp5[] = {
536 { "inc", TRUE, LONG, op1(E), 0 },
537 { "dec", TRUE, LONG, op1(E), 0 },
538 { "call", TRUE, NONE, op1(Eind),0 },
539 { "lcall", TRUE, NONE, op1(Eind),0 },
540 { "jmp", TRUE, NONE, op1(Eind),0 },
541 { "ljmp", TRUE, NONE, op1(Eind),0 },
542 { "push", TRUE, LONG, op1(E), 0 },
543 { "", TRUE, NONE, 0, 0 }
546 static const struct inst db_inst_table[256] = {
547 /*00*/ { "add", TRUE, BYTE, op2(R, E), 0 },
548 /*01*/ { "add", TRUE, LONG, op2(R, E), 0 },
549 /*02*/ { "add", TRUE, BYTE, op2(E, R), 0 },
550 /*03*/ { "add", TRUE, LONG, op2(E, R), 0 },
551 /*04*/ { "add", FALSE, BYTE, op2(Is, A), 0 },
552 /*05*/ { "add", FALSE, LONG, op2(Is, A), 0 },
553 /*06*/ { "push", FALSE, NONE, op1(Si), 0 },
554 /*07*/ { "pop", FALSE, NONE, op1(Si), 0 },
556 /*08*/ { "or", TRUE, BYTE, op2(R, E), 0 },
557 /*09*/ { "or", TRUE, LONG, op2(R, E), 0 },
558 /*0a*/ { "or", TRUE, BYTE, op2(E, R), 0 },
559 /*0b*/ { "or", TRUE, LONG, op2(E, R), 0 },
560 /*0c*/ { "or", FALSE, BYTE, op2(I, A), 0 },
561 /*0d*/ { "or", FALSE, LONG, op2(I, A), 0 },
562 /*0e*/ { "push", FALSE, NONE, op1(Si), 0 },
563 /*0f*/ { "", FALSE, NONE, 0, 0 },
565 /*10*/ { "adc", TRUE, BYTE, op2(R, E), 0 },
566 /*11*/ { "adc", TRUE, LONG, op2(R, E), 0 },
567 /*12*/ { "adc", TRUE, BYTE, op2(E, R), 0 },
568 /*13*/ { "adc", TRUE, LONG, op2(E, R), 0 },
569 /*14*/ { "adc", FALSE, BYTE, op2(Is, A), 0 },
570 /*15*/ { "adc", FALSE, LONG, op2(Is, A), 0 },
571 /*16*/ { "push", FALSE, NONE, op1(Si), 0 },
572 /*17*/ { "pop", FALSE, NONE, op1(Si), 0 },
574 /*18*/ { "sbb", TRUE, BYTE, op2(R, E), 0 },
575 /*19*/ { "sbb", TRUE, LONG, op2(R, E), 0 },
576 /*1a*/ { "sbb", TRUE, BYTE, op2(E, R), 0 },
577 /*1b*/ { "sbb", TRUE, LONG, op2(E, R), 0 },
578 /*1c*/ { "sbb", FALSE, BYTE, op2(Is, A), 0 },
579 /*1d*/ { "sbb", FALSE, LONG, op2(Is, A), 0 },
580 /*1e*/ { "push", FALSE, NONE, op1(Si), 0 },
581 /*1f*/ { "pop", FALSE, NONE, op1(Si), 0 },
583 /*20*/ { "and", TRUE, BYTE, op2(R, E), 0 },
584 /*21*/ { "and", TRUE, LONG, op2(R, E), 0 },
585 /*22*/ { "and", TRUE, BYTE, op2(E, R), 0 },
586 /*23*/ { "and", TRUE, LONG, op2(E, R), 0 },
587 /*24*/ { "and", FALSE, BYTE, op2(I, A), 0 },
588 /*25*/ { "and", FALSE, LONG, op2(I, A), 0 },
589 /*26*/ { "", FALSE, NONE, 0, 0 },
590 /*27*/ { "aaa", FALSE, NONE, 0, 0 },
592 /*28*/ { "sub", TRUE, BYTE, op2(R, E), 0 },
593 /*29*/ { "sub", TRUE, LONG, op2(R, E), 0 },
594 /*2a*/ { "sub", TRUE, BYTE, op2(E, R), 0 },
595 /*2b*/ { "sub", TRUE, LONG, op2(E, R), 0 },
596 /*2c*/ { "sub", FALSE, BYTE, op2(Is, A), 0 },
597 /*2d*/ { "sub", FALSE, LONG, op2(Is, A), 0 },
598 /*2e*/ { "", FALSE, NONE, 0, 0 },
599 /*2f*/ { "das", FALSE, NONE, 0, 0 },
601 /*30*/ { "xor", TRUE, BYTE, op2(R, E), 0 },
602 /*31*/ { "xor", TRUE, LONG, op2(R, E), 0 },
603 /*32*/ { "xor", TRUE, BYTE, op2(E, R), 0 },
604 /*33*/ { "xor", TRUE, LONG, op2(E, R), 0 },
605 /*34*/ { "xor", FALSE, BYTE, op2(I, A), 0 },
606 /*35*/ { "xor", FALSE, LONG, op2(I, A), 0 },
607 /*36*/ { "", FALSE, NONE, 0, 0 },
608 /*37*/ { "daa", FALSE, NONE, 0, 0 },
610 /*38*/ { "cmp", TRUE, BYTE, op2(R, E), 0 },
611 /*39*/ { "cmp", TRUE, LONG, op2(R, E), 0 },
612 /*3a*/ { "cmp", TRUE, BYTE, op2(E, R), 0 },
613 /*3b*/ { "cmp", TRUE, LONG, op2(E, R), 0 },
614 /*3c*/ { "cmp", FALSE, BYTE, op2(Is, A), 0 },
615 /*3d*/ { "cmp", FALSE, LONG, op2(Is, A), 0 },
616 /*3e*/ { "", FALSE, NONE, 0, 0 },
617 /*3f*/ { "aas", FALSE, NONE, 0, 0 },
619 /*40*/ { "inc", FALSE, LONG, op1(Ri), 0 },
620 /*41*/ { "inc", FALSE, LONG, op1(Ri), 0 },
621 /*42*/ { "inc", FALSE, LONG, op1(Ri), 0 },
622 /*43*/ { "inc", FALSE, LONG, op1(Ri), 0 },
623 /*44*/ { "inc", FALSE, LONG, op1(Ri), 0 },
624 /*45*/ { "inc", FALSE, LONG, op1(Ri), 0 },
625 /*46*/ { "inc", FALSE, LONG, op1(Ri), 0 },
626 /*47*/ { "inc", FALSE, LONG, op1(Ri), 0 },
628 /*48*/ { "dec", FALSE, LONG, op1(Ri), 0 },
629 /*49*/ { "dec", FALSE, LONG, op1(Ri), 0 },
630 /*4a*/ { "dec", FALSE, LONG, op1(Ri), 0 },
631 /*4b*/ { "dec", FALSE, LONG, op1(Ri), 0 },
632 /*4c*/ { "dec", FALSE, LONG, op1(Ri), 0 },
633 /*4d*/ { "dec", FALSE, LONG, op1(Ri), 0 },
634 /*4e*/ { "dec", FALSE, LONG, op1(Ri), 0 },
635 /*4f*/ { "dec", FALSE, LONG, op1(Ri), 0 },
637 /*50*/ { "push", FALSE, LONG, op1(Ri), 0 },
638 /*51*/ { "push", FALSE, LONG, op1(Ri), 0 },
639 /*52*/ { "push", FALSE, LONG, op1(Ri), 0 },
640 /*53*/ { "push", FALSE, LONG, op1(Ri), 0 },
641 /*54*/ { "push", FALSE, LONG, op1(Ri), 0 },
642 /*55*/ { "push", FALSE, LONG, op1(Ri), 0 },
643 /*56*/ { "push", FALSE, LONG, op1(Ri), 0 },
644 /*57*/ { "push", FALSE, LONG, op1(Ri), 0 },
646 /*58*/ { "pop", FALSE, LONG, op1(Ri), 0 },
647 /*59*/ { "pop", FALSE, LONG, op1(Ri), 0 },
648 /*5a*/ { "pop", FALSE, LONG, op1(Ri), 0 },
649 /*5b*/ { "pop", FALSE, LONG, op1(Ri), 0 },
650 /*5c*/ { "pop", FALSE, LONG, op1(Ri), 0 },
651 /*5d*/ { "pop", FALSE, LONG, op1(Ri), 0 },
652 /*5e*/ { "pop", FALSE, LONG, op1(Ri), 0 },
653 /*5f*/ { "pop", FALSE, LONG, op1(Ri), 0 },
655 /*60*/ { "pusha", FALSE, LONG, 0, 0 },
656 /*61*/ { "popa", FALSE, LONG, 0, 0 },
657 /*62*/ { "bound", TRUE, LONG, op2(E, R), 0 },
658 /*63*/ { "arpl", TRUE, NONE, op2(Ew,Rw), 0 },
660 /*64*/ { "", FALSE, NONE, 0, 0 },
661 /*65*/ { "", FALSE, NONE, 0, 0 },
662 /*66*/ { "", FALSE, NONE, 0, 0 },
663 /*67*/ { "", FALSE, NONE, 0, 0 },
665 /*68*/ { "push", FALSE, LONG, op1(I), 0 },
666 /*69*/ { "imul", TRUE, LONG, op3(I,E,R), 0 },
667 /*6a*/ { "push", FALSE, LONG, op1(Ib), 0 },
668 /*6b*/ { "imul", TRUE, LONG, op3(Ibs,E,R),0 },
669 /*6c*/ { "ins", FALSE, BYTE, op2(DX, DI), 0 },
670 /*6d*/ { "ins", FALSE, LONG, op2(DX, DI), 0 },
671 /*6e*/ { "outs", FALSE, BYTE, op2(SI, DX), 0 },
672 /*6f*/ { "outs", FALSE, LONG, op2(SI, DX), 0 },
674 /*70*/ { "jo", FALSE, NONE, op1(Db), 0 },
675 /*71*/ { "jno", FALSE, NONE, op1(Db), 0 },
676 /*72*/ { "jb", FALSE, NONE, op1(Db), 0 },
677 /*73*/ { "jnb", FALSE, NONE, op1(Db), 0 },
678 /*74*/ { "jz", FALSE, NONE, op1(Db), 0 },
679 /*75*/ { "jnz", FALSE, NONE, op1(Db), 0 },
680 /*76*/ { "jbe", FALSE, NONE, op1(Db), 0 },
681 /*77*/ { "jnbe", FALSE, NONE, op1(Db), 0 },
683 /*78*/ { "js", FALSE, NONE, op1(Db), 0 },
684 /*79*/ { "jns", FALSE, NONE, op1(Db), 0 },
685 /*7a*/ { "jp", FALSE, NONE, op1(Db), 0 },
686 /*7b*/ { "jnp", FALSE, NONE, op1(Db), 0 },
687 /*7c*/ { "jl", FALSE, NONE, op1(Db), 0 },
688 /*7d*/ { "jnl", FALSE, NONE, op1(Db), 0 },
689 /*7e*/ { "jle", FALSE, NONE, op1(Db), 0 },
690 /*7f*/ { "jnle", FALSE, NONE, op1(Db), 0 },
692 /*80*/ { "", TRUE, BYTE, op2(I, E), (char *)db_Grp1 },
693 /*81*/ { "", TRUE, LONG, op2(I, E), (char *)db_Grp1 },
694 /*82*/ { "", TRUE, BYTE, op2(Is,E), (char *)db_Grp1 },
695 /*83*/ { "", TRUE, LONG, op2(Ibs,E), (char *)db_Grp1 },
696 /*84*/ { "test", TRUE, BYTE, op2(R, E), 0 },
697 /*85*/ { "test", TRUE, LONG, op2(R, E), 0 },
698 /*86*/ { "xchg", TRUE, BYTE, op2(R, E), 0 },
699 /*87*/ { "xchg", TRUE, LONG, op2(R, E), 0 },
701 /*88*/ { "mov", TRUE, BYTE, op2(R, E), 0 },
702 /*89*/ { "mov", TRUE, LONG, op2(R, E), 0 },
703 /*8a*/ { "mov", TRUE, BYTE, op2(E, R), 0 },
704 /*8b*/ { "mov", TRUE, LONG, op2(E, R), 0 },
705 /*8c*/ { "mov", TRUE, NONE, op2(S, Ew), 0 },
706 /*8d*/ { "lea", TRUE, LONG, op2(E, R), 0 },
707 /*8e*/ { "mov", TRUE, NONE, op2(Ew, S), 0 },
708 /*8f*/ { "pop", TRUE, LONG, op1(E), 0 },
710 /*90*/ { "nop", FALSE, NONE, 0, 0 },
711 /*91*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
712 /*92*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
713 /*93*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
714 /*94*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
715 /*95*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
716 /*96*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
717 /*97*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
719 /*98*/ { "cbw", FALSE, SDEP, 0, "cwde" }, /* cbw/cwde */
720 /*99*/ { "cwd", FALSE, SDEP, 0, "cdq" }, /* cwd/cdq */
721 /*9a*/ { "lcall", FALSE, NONE, op1(OS), 0 },
722 /*9b*/ { "wait", FALSE, NONE, 0, 0 },
723 /*9c*/ { "pushf", FALSE, LONG, 0, 0 },
724 /*9d*/ { "popf", FALSE, LONG, 0, 0 },
725 /*9e*/ { "sahf", FALSE, NONE, 0, 0 },
726 /*9f*/ { "lahf", FALSE, NONE, 0, 0 },
728 /*a0*/ { "mov", FALSE, BYTE, op2(O, A), 0 },
729 /*a1*/ { "mov", FALSE, LONG, op2(O, A), 0 },
730 /*a2*/ { "mov", FALSE, BYTE, op2(A, O), 0 },
731 /*a3*/ { "mov", FALSE, LONG, op2(A, O), 0 },
732 /*a4*/ { "movs", FALSE, BYTE, op2(SI,DI), 0 },
733 /*a5*/ { "movs", FALSE, LONG, op2(SI,DI), 0 },
734 /*a6*/ { "cmps", FALSE, BYTE, op2(SI,DI), 0 },
735 /*a7*/ { "cmps", FALSE, LONG, op2(SI,DI), 0 },
737 /*a8*/ { "test", FALSE, BYTE, op2(I, A), 0 },
738 /*a9*/ { "test", FALSE, LONG, op2(I, A), 0 },
739 /*aa*/ { "stos", FALSE, BYTE, op1(DI), 0 },
740 /*ab*/ { "stos", FALSE, LONG, op1(DI), 0 },
741 /*ac*/ { "lods", FALSE, BYTE, op1(SI), 0 },
742 /*ad*/ { "lods", FALSE, LONG, op1(SI), 0 },
743 /*ae*/ { "scas", FALSE, BYTE, op1(DI), 0 },
744 /*af*/ { "scas", FALSE, LONG, op1(DI), 0 },
746 /*b0*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
747 /*b1*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
748 /*b2*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
749 /*b3*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
750 /*b4*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
751 /*b5*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
752 /*b6*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
753 /*b7*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
755 /*b8*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
756 /*b9*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
757 /*ba*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
758 /*bb*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
759 /*bc*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
760 /*bd*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
761 /*be*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
762 /*bf*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
764 /*c0*/ { "", TRUE, BYTE, op2(Ib, E), (char *)db_Grp2 },
765 /*c1*/ { "", TRUE, LONG, op2(Ib, E), (char *)db_Grp2 },
766 /*c2*/ { "ret", FALSE, NONE, op1(Iw), 0 },
767 /*c3*/ { "ret", FALSE, NONE, 0, 0 },
768 /*c4*/ { "les", TRUE, LONG, op2(E, R), 0 },
769 /*c5*/ { "lds", TRUE, LONG, op2(E, R), 0 },
770 /*c6*/ { "mov", TRUE, BYTE, op2(I, E), 0 },
771 /*c7*/ { "mov", TRUE, LONG, op2(I, E), 0 },
773 /*c8*/ { "enter", FALSE, NONE, op2(Ib, Iw), 0 },
774 /*c9*/ { "leave", FALSE, NONE, 0, 0 },
775 /*ca*/ { "lret", FALSE, NONE, op1(Iw), 0 },
776 /*cb*/ { "lret", FALSE, NONE, 0, 0 },
777 /*cc*/ { "int", FALSE, NONE, op1(o3), 0 },
778 /*cd*/ { "int", FALSE, NONE, op1(Ib), 0 },
779 /*ce*/ { "into", FALSE, NONE, 0, 0 },
780 /*cf*/ { "iret", FALSE, NONE, 0, 0 },
782 /*d0*/ { "", TRUE, BYTE, op2(o1, E), (char *)db_Grp2 },
783 /*d1*/ { "", TRUE, LONG, op2(o1, E), (char *)db_Grp2 },
784 /*d2*/ { "", TRUE, BYTE, op2(CL, E), (char *)db_Grp2 },
785 /*d3*/ { "", TRUE, LONG, op2(CL, E), (char *)db_Grp2 },
786 /*d4*/ { "aam", TRUE, NONE, 0, 0 },
787 /*d5*/ { "aad", TRUE, NONE, 0, 0 },
788 /*d6*/ { "", FALSE, NONE, 0, 0 },
789 /*d7*/ { "xlat", FALSE, BYTE, op1(BX), 0 },
791 /*d8*/ { "", TRUE, NONE, 0, (char *)db_Esc8 },
792 /*d9*/ { "", TRUE, NONE, 0, (char *)db_Esc9 },
793 /*da*/ { "", TRUE, NONE, 0, (char *)db_Esca },
794 /*db*/ { "", TRUE, NONE, 0, (char *)db_Escb },
795 /*dc*/ { "", TRUE, NONE, 0, (char *)db_Escc },
796 /*dd*/ { "", TRUE, NONE, 0, (char *)db_Escd },
797 /*de*/ { "", TRUE, NONE, 0, (char *)db_Esce },
798 /*df*/ { "", TRUE, NONE, 0, (char *)db_Escf },
800 /*e0*/ { "loopne",FALSE, NONE, op1(Db), 0 },
801 /*e1*/ { "loope", FALSE, NONE, op1(Db), 0 },
802 /*e2*/ { "loop", FALSE, NONE, op1(Db), 0 },
803 /*e3*/ { "jcxz", FALSE, SDEP, op1(Db), "jecxz" },
804 /*e4*/ { "in", FALSE, BYTE, op2(Ib, A), 0 },
805 /*e5*/ { "in", FALSE, LONG, op2(Ib, A) , 0 },
806 /*e6*/ { "out", FALSE, BYTE, op2(A, Ib), 0 },
807 /*e7*/ { "out", FALSE, LONG, op2(A, Ib) , 0 },
809 /*e8*/ { "call", FALSE, NONE, op1(Dl), 0 },
810 /*e9*/ { "jmp", FALSE, NONE, op1(Dl), 0 },
811 /*ea*/ { "ljmp", FALSE, NONE, op1(OS), 0 },
812 /*eb*/ { "jmp", FALSE, NONE, op1(Db), 0 },
813 /*ec*/ { "in", FALSE, BYTE, op2(DX, A), 0 },
814 /*ed*/ { "in", FALSE, LONG, op2(DX, A) , 0 },
815 /*ee*/ { "out", FALSE, BYTE, op2(A, DX), 0 },
816 /*ef*/ { "out", FALSE, LONG, op2(A, DX) , 0 },
818 /*f0*/ { "", FALSE, NONE, 0, 0 },
819 /*f1*/ { "", FALSE, NONE, 0, 0 },
820 /*f2*/ { "", FALSE, NONE, 0, 0 },
821 /*f3*/ { "", FALSE, NONE, 0, 0 },
822 /*f4*/ { "hlt", FALSE, NONE, 0, 0 },
823 /*f5*/ { "cmc", FALSE, NONE, 0, 0 },
824 /*f6*/ { "", TRUE, BYTE, 0, (char *)db_Grp3 },
825 /*f7*/ { "", TRUE, LONG, 0, (char *)db_Grp3 },
827 /*f8*/ { "clc", FALSE, NONE, 0, 0 },
828 /*f9*/ { "stc", FALSE, NONE, 0, 0 },
829 /*fa*/ { "cli", FALSE, NONE, 0, 0 },
830 /*fb*/ { "sti", FALSE, NONE, 0, 0 },
831 /*fc*/ { "cld", FALSE, NONE, 0, 0 },
832 /*fd*/ { "std", FALSE, NONE, 0, 0 },
833 /*fe*/ { "", TRUE, NONE, 0, (char *)db_Grp4 },
834 /*ff*/ { "", TRUE, NONE, 0, (char *)db_Grp5 },
837 static const struct inst db_bad_inst =
838 { "???", FALSE, NONE, 0, 0 }
841 #define f_mod(byte) ((byte)>>6)
842 #define f_reg(byte) (((byte)>>3)&0x7)
843 #define f_rm(byte) ((byte)&0x7)
845 #define sib_ss(byte) ((byte)>>6)
846 #define sib_index(byte) (((byte)>>3)&0x7)
847 #define sib_base(byte) ((byte)&0x7)
849 struct i_addr {
850 int is_reg; /* if reg, reg number is in 'disp' */
851 int disp;
852 const char * base;
853 const char * index;
854 int ss;
857 static const char * const db_index_reg_16[8] = {
858 "%bx,%si",
859 "%bx,%di",
860 "%bp,%si",
861 "%bp,%di",
862 "%si",
863 "%di",
864 "%bp",
865 "%bx"
868 static const char * const db_reg[3][8] = {
869 { "%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh" },
870 { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di" },
871 { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi" }
874 static const char * const db_seg_reg[8] = {
875 "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
879 * lengths for size attributes
881 static const int db_lengths[] = {
882 1, /* BYTE */
883 2, /* WORD */
884 4, /* LONG */
885 8, /* QUAD */
886 4, /* SNGL */
887 8, /* DBLR */
888 10, /* EXTR */
891 static unsigned int db_get_task_value( const DBG_ADDR *addr,
892 int size, int is_signed )
894 unsigned int result;
895 unsigned char *p = DBG_ADDR_TO_LIN( addr );
897 switch(size)
899 case 4:
900 if (is_signed) result = (unsigned int) *(int *)p;
901 else result = *(unsigned int *)p;
902 break;
903 case 2:
904 if (is_signed) result = (unsigned int) *(short int *)p;
905 else result = *(unsigned short int *)p;
906 break;
907 case 1:
908 if (is_signed) result = (unsigned int) *(char *)p;
909 else result = *(unsigned char *)p;
910 break;
911 default:
912 fprintf(stderr, "Illegal size specified\n");
913 result = 0;
914 break;
916 return result;
919 #define get_value_inc(result, addr, size, is_signed) \
920 result = db_get_task_value((addr), (size), (is_signed)); \
921 if (!db_disasm_16) (addr)->off += (size); \
922 else (addr)->off = ((addr)->off + (size)) & 0xffff;
925 * Read address at location and return updated location.
927 void db_read_address( DBG_ADDR *addr, int short_addr, int regmodrm,
928 struct i_addr *addrp )
930 int mod, rm, sib, index, disp;
932 mod = f_mod(regmodrm);
933 rm = f_rm(regmodrm);
935 if (mod == 3) {
936 addrp->is_reg = TRUE;
937 addrp->disp = rm;
938 return;
940 addrp->is_reg = FALSE;
941 addrp->index = 0;
943 if (short_addr) {
944 addrp->index = 0;
945 addrp->ss = 0;
946 switch (mod) {
947 case 0:
948 if (rm == 6) {
949 get_value_inc(disp, addr, 2, TRUE);
950 addrp->disp = disp;
951 addrp->base = 0;
953 else {
954 addrp->disp = 0;
955 addrp->base = db_index_reg_16[rm];
957 break;
958 case 1:
959 get_value_inc(disp, addr, 1, TRUE);
960 addrp->disp = disp;
961 addrp->base = db_index_reg_16[rm];
962 break;
963 case 2:
964 get_value_inc(disp, addr, 2, TRUE);
965 addrp->disp = disp;
966 addrp->base = db_index_reg_16[rm];
967 break;
970 else {
971 if (mod != 3 && rm == 4) {
972 get_value_inc(sib, addr, 1, FALSE);
973 rm = sib_base(sib);
974 index = sib_index(sib);
975 if (index != 4)
976 addrp->index = db_reg[LONG][index];
977 addrp->ss = sib_ss(sib);
980 switch (mod) {
981 case 0:
982 if (rm == 5) {
983 get_value_inc(addrp->disp, addr, 4, FALSE);
984 addrp->base = 0;
986 else {
987 addrp->disp = 0;
988 addrp->base = db_reg[LONG][rm];
990 break;
992 case 1:
993 get_value_inc(disp, addr, 1, TRUE);
994 addrp->disp = disp;
995 addrp->base = db_reg[LONG][rm];
996 break;
998 case 2:
999 get_value_inc(disp, addr, 4, FALSE);
1000 addrp->disp = disp;
1001 addrp->base = db_reg[LONG][rm];
1002 break;
1007 static void db_task_printsym(unsigned int addr, int size)
1009 switch(size)
1011 case BYTE:
1012 case WORD:
1013 fprintf(stderr, "0x%4.4x", addr & 0xffff );
1014 break;
1015 case LONG:
1017 DBG_ADDR address = { NULL, 0, addr };
1018 DEBUG_PrintAddress( &address, db_disasm_16 ? 16 : 32, TRUE );
1020 break;
1024 void
1025 db_print_address(seg, size, addrp)
1026 char * seg;
1027 int size;
1028 struct i_addr *addrp;
1030 if (addrp->is_reg) {
1031 fprintf(stderr,"%s", db_reg[size][addrp->disp]);
1032 return;
1035 if (seg) {
1036 fprintf(stderr,"%s:", seg);
1039 if (addrp->base != 0 || addrp->index != 0) {
1040 fprintf(stderr,"0x%x", addrp->disp);
1041 fprintf(stderr,"(");
1042 if (addrp->base)
1043 fprintf(stderr,"%s", addrp->base);
1044 if (addrp->index)
1045 fprintf(stderr,",%s,%d", addrp->index, 1<<addrp->ss);
1046 fprintf(stderr,")");
1047 } else
1048 db_task_printsym(addrp->disp, size);
1052 * Disassemble floating-point ("escape") instruction
1053 * and return updated location.
1055 void db_disasm_esc( DBG_ADDR *addr, int inst, int short_addr,
1056 int size, char *seg )
1058 int regmodrm;
1059 const struct finst *fp;
1060 int mod;
1061 struct i_addr address;
1062 const char * name;
1064 get_value_inc(regmodrm, addr, 1, FALSE);
1065 if( !db_display )
1067 return;
1070 fp = &db_Esc_inst[inst - 0xd8][f_reg(regmodrm)];
1071 mod = f_mod(regmodrm);
1072 if (mod != 3) {
1074 * Normal address modes.
1076 db_read_address( addr, short_addr, regmodrm, &address);
1077 fprintf(stderr,fp->f_name);
1078 switch(fp->f_size) {
1079 case SNGL:
1080 fprintf(stderr,"s");
1081 break;
1082 case DBLR:
1083 fprintf(stderr,"l");
1084 break;
1085 case EXTR:
1086 fprintf(stderr,"t");
1087 break;
1088 case WORD:
1089 fprintf(stderr,"s");
1090 break;
1091 case LONG:
1092 fprintf(stderr,"l");
1093 break;
1094 case QUAD:
1095 fprintf(stderr,"q");
1096 break;
1097 default:
1098 break;
1100 fprintf(stderr,"\t");
1101 db_print_address(seg, BYTE, &address);
1103 else {
1105 * 'reg-reg' - special formats
1107 switch (fp->f_rrmode) {
1108 case op2(ST,STI):
1109 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1110 fprintf(stderr,"%s\t%%st,%%st(%d)",name,f_rm(regmodrm));
1111 break;
1112 case op2(STI,ST):
1113 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1114 fprintf(stderr,"%s\t%%st(%d),%%st",name, f_rm(regmodrm));
1115 break;
1116 case op1(STI):
1117 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1118 fprintf(stderr,"%s\t%%st(%d)",name, f_rm(regmodrm));
1119 break;
1120 case op1(X):
1121 fprintf(stderr,"%s", ((char **)fp->f_rrname)[f_rm(regmodrm)]);
1122 break;
1123 case op1(XA):
1124 fprintf(stderr,"%s\t%%ax",
1125 ((char **)fp->f_rrname)[f_rm(regmodrm)]);
1126 break;
1127 default:
1128 fprintf(stderr,"<bad instruction>");
1129 break;
1135 /***********************************************************************
1136 * DEBUG_Disasm
1138 * Disassemble instruction at 'addr'. addr is changed to point to the
1139 * start of the next instruction.
1141 void DEBUG_Disasm( DBG_ADDR *addr, int display )
1143 int inst;
1144 int size;
1145 int short_addr;
1146 char * seg;
1147 const struct inst *ip;
1148 const char *i_name;
1149 int i_size;
1150 int i_mode;
1151 int regmodrm = 0;
1152 BOOL32 first;
1153 int displ;
1154 int prefix;
1155 int imm;
1156 int len;
1157 struct i_addr address;
1160 * Set this so we get can supress the printout if we need to.
1162 db_display = display;
1163 db_disasm_16 = IS_SELECTOR_V86(addr->seg) || !IS_SELECTOR_32BIT(addr->seg);
1165 get_value_inc( inst, addr, 1, FALSE );
1167 if (db_disasm_16) {
1168 short_addr = TRUE;
1169 size = WORD;
1171 else {
1172 short_addr = FALSE;
1173 size = LONG;
1175 seg = 0;
1178 * Get prefixes
1180 prefix = TRUE;
1181 do {
1182 switch (inst) {
1183 case 0x66: /* data16 */
1184 if (size == LONG)
1185 size = WORD;
1186 else
1187 size = LONG;
1188 break;
1189 case 0x67:
1190 short_addr = !short_addr;
1191 break;
1192 case 0x26:
1193 seg = "%es";
1194 break;
1195 case 0x36:
1196 seg = "%ss";
1197 break;
1198 case 0x2e:
1199 seg = "%cs";
1200 break;
1201 case 0x3e:
1202 seg = "%ds";
1203 break;
1204 case 0x64:
1205 seg = "%fs";
1206 break;
1207 case 0x65:
1208 seg = "%gs";
1209 break;
1210 case 0xf0:
1211 if( db_display )
1212 fprintf(stderr,"lock ");
1213 break;
1214 case 0xf2:
1215 if( db_display )
1216 fprintf(stderr,"repne ");
1217 break;
1218 case 0xf3:
1219 if( db_display )
1220 fprintf(stderr,"repe "); /* XXX repe VS rep */
1221 break;
1222 default:
1223 prefix = FALSE;
1224 break;
1226 if (prefix) {
1227 get_value_inc(inst, addr, 1, FALSE);
1229 } while (prefix);
1231 if (inst >= 0xd8 && inst <= 0xdf)
1233 db_disasm_esc( addr, inst, short_addr, size, seg);
1234 return;
1237 if (inst == 0x0f) {
1238 get_value_inc(inst, addr, 1, FALSE);
1239 ip = db_inst_0f[inst>>4];
1240 if (ip == 0) {
1241 ip = &db_bad_inst;
1243 else {
1244 ip = &ip[inst&0xf];
1247 else
1248 ip = &db_inst_table[inst];
1250 if (ip->i_has_modrm) {
1251 get_value_inc(regmodrm, addr, 1, FALSE);
1252 db_read_address( addr, short_addr, regmodrm, &address);
1255 i_name = ip->i_name;
1256 i_size = ip->i_size;
1257 i_mode = ip->i_mode;
1259 if (ip->i_extra == (char *)db_Grp1 ||
1260 ip->i_extra == (char *)db_Grp2 ||
1261 ip->i_extra == (char *)db_Grp6 ||
1262 ip->i_extra == (char *)db_Grp7 ||
1263 ip->i_extra == (char *)db_Grp8) {
1264 i_name = ((char **)ip->i_extra)[f_reg(regmodrm)];
1266 else if (ip->i_extra == (char *)db_Grp3) {
1267 ip = (struct inst *)ip->i_extra;
1268 ip = &ip[f_reg(regmodrm)];
1269 i_name = ip->i_name;
1270 i_mode = ip->i_mode;
1272 else if (ip->i_extra == (char *)db_Grp4 ||
1273 ip->i_extra == (char *)db_Grp5) {
1274 ip = (struct inst *)ip->i_extra;
1275 ip = &ip[f_reg(regmodrm)];
1276 i_name = ip->i_name;
1277 i_mode = ip->i_mode;
1278 i_size = ip->i_size;
1281 if (i_size == SDEP) {
1282 if( db_display )
1284 if (size == WORD)
1285 fprintf(stderr,i_name);
1286 else
1287 fprintf(stderr,ip->i_extra);
1290 else {
1291 if( db_display )
1293 fprintf(stderr,i_name);
1295 if (i_size != NONE) {
1296 if (i_size == BYTE) {
1297 if( db_display )
1299 fprintf(stderr,"b");
1301 size = BYTE;
1303 else if (i_size == WORD) {
1304 if( db_display )
1306 fprintf(stderr,"w");
1308 size = WORD;
1310 else if (size == WORD)
1312 if( db_display )
1314 fprintf(stderr,"w");
1317 else
1319 if( db_display )
1321 fprintf(stderr,"l");
1326 if( db_display )
1328 fprintf(stderr,"\t");
1330 for (first = TRUE;
1331 i_mode != 0;
1332 i_mode >>= 8, first = FALSE)
1334 if (!first && db_display)
1335 fprintf(stderr,",");
1337 switch (i_mode & 0xFF) {
1339 case E:
1340 if( db_display )
1342 db_print_address(seg, size, &address);
1344 break;
1346 case Eind:
1347 if( db_display )
1349 fprintf(stderr,"*");
1350 db_print_address(seg, size, &address);
1352 break;
1354 case Ew:
1355 if( db_display )
1357 db_print_address(seg, WORD, &address);
1359 break;
1361 case Eb:
1362 if( db_display )
1364 db_print_address(seg, BYTE, &address);
1366 break;
1368 case R:
1369 if( db_display )
1371 fprintf(stderr,"%s", db_reg[size][f_reg(regmodrm)]);
1373 break;
1375 case Rw:
1376 if( db_display )
1378 fprintf(stderr,"%s", db_reg[WORD][f_reg(regmodrm)]);
1380 break;
1382 case Ri:
1383 if( db_display )
1385 fprintf(stderr,"%s", db_reg[size][f_rm(inst)]);
1387 break;
1389 case S:
1390 if( db_display )
1392 fprintf(stderr,"%s", db_seg_reg[f_reg(regmodrm)]);
1394 break;
1396 case Si:
1397 if( db_display )
1399 fprintf(stderr,"%s", db_seg_reg[f_reg(inst)]);
1401 break;
1403 case A:
1404 if( db_display )
1406 fprintf(stderr,"%s", db_reg[size][0]); /* acc */
1408 break;
1410 case BX:
1411 if( db_display )
1413 if (seg)
1414 fprintf(stderr,"%s:", seg);
1415 fprintf(stderr,"(%s)", short_addr ? "%bx" : "%ebx");
1417 break;
1419 case CL:
1420 if( db_display )
1422 fprintf(stderr,"%%cl");
1424 break;
1426 case DX:
1427 if( db_display )
1429 fprintf(stderr,"%%dx");
1431 break;
1433 case SI:
1434 if( db_display )
1436 if (seg)
1437 fprintf(stderr,"%s:", seg);
1438 fprintf(stderr,"(%s)", short_addr ? "%si" : "%esi");
1440 break;
1442 case DI:
1443 if( db_display )
1445 fprintf(stderr,"%%es:(%s)", short_addr ? "%di" : "%edi");
1447 break;
1449 case CR:
1450 if( db_display )
1452 fprintf(stderr,"%%cr%d", f_reg(regmodrm));
1454 break;
1456 case DR:
1457 if( db_display )
1459 fprintf(stderr,"%%dr%d", f_reg(regmodrm));
1461 break;
1463 case TR:
1464 if( db_display )
1466 fprintf(stderr,"%%tr%d", f_reg(regmodrm));
1468 break;
1470 case I:
1471 len = db_lengths[size];
1472 get_value_inc(imm, addr, len, FALSE);/* unsigned */
1473 if( db_display )
1475 fprintf(stderr,"$0x%x", imm);
1477 break;
1479 case Is:
1480 len = db_lengths[size];
1481 get_value_inc(imm, addr, len, TRUE); /* signed */
1482 if( db_display )
1484 fprintf(stderr,"$%d", imm);
1486 break;
1488 case Ib:
1489 get_value_inc(imm, addr, 1, FALSE); /* unsigned */
1490 if( db_display )
1492 fprintf(stderr,"$0x%x", imm);
1494 break;
1496 case Ibs:
1497 get_value_inc(imm, addr, 1, TRUE); /* signed */
1498 if( db_display )
1500 fprintf(stderr,"$%d", imm);
1502 break;
1504 case Iw:
1505 get_value_inc(imm, addr, 2, FALSE); /* unsigned */
1506 if( db_display )
1508 fprintf(stderr,"$0x%x", imm);
1510 break;
1512 case Il:
1513 get_value_inc(imm, addr, 4, FALSE);
1514 if( db_display )
1516 fprintf(stderr,"$0x%x", imm);
1518 break;
1520 case O:
1521 if (short_addr) {
1522 get_value_inc(displ, addr, 2, TRUE);
1524 else {
1525 get_value_inc(displ, addr, 4, TRUE);
1527 if( !db_display )
1529 break;
1532 if (seg)
1533 fprintf(stderr,"%s:0x%x",seg, displ);
1534 else
1535 db_task_printsym(displ, short_addr ? WORD : LONG);
1536 break;
1538 case Db:
1539 get_value_inc(displ, addr, 1, TRUE);
1540 if( !db_display )
1542 break;
1545 if (short_addr) {
1546 /* offset only affects low 16 bits */
1547 displ = (addr->off & 0xffff0000)
1548 | ((addr->off + displ) & 0xffff);
1550 else displ += addr->off;
1551 db_task_printsym(displ, short_addr ? WORD : LONG);
1552 break;
1554 case Dl:
1555 if (short_addr) {
1556 get_value_inc(displ, addr, 2, TRUE);
1557 /* offset only affects low 16 bits */
1558 displ = (addr->off & 0xffff0000)
1559 | ((addr->off + displ) & 0xffff);
1561 else {
1562 get_value_inc(displ, addr, 4, TRUE);
1563 displ += addr->off;
1565 if( !db_display )
1567 break;
1569 db_task_printsym( displ, short_addr ? WORD : LONG);
1570 break;
1572 case o1:
1573 if( db_display )
1575 fprintf(stderr,"$1");
1577 break;
1579 case o3:
1580 if( db_display )
1582 fprintf(stderr,"$3");
1584 break;
1586 case OS:
1588 DBG_ADDR address;
1589 get_value_inc( address.off, addr, /* offset */
1590 short_addr ? 2 : 4, FALSE );
1591 get_value_inc( address.seg, addr, /* segment */
1592 2, FALSE );
1593 if( db_display )
1595 DEBUG_PrintAddress( &address, short_addr ? 16 : 32,
1596 TRUE );
1600 break;