Implemented TOOLBAR_MouseLeave to handle WM_MOUSELEAVE messages.
[wine/multimedia.git] / debugger / db_disasm.c
blob1a2e9e89269b7b2f0e03b5b6fe3762a1c9c73de8
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"
68 #ifdef __i386__
71 * Switch to disassemble 16-bit code.
73 static BOOL db_disasm_16 = FALSE;
76 * Flag to indicate whether we need to display instruction,
77 * or whether we just need to know the address of the next
78 * instruction.
80 static BOOL db_display = FALSE;
83 * Size attributes
85 #define BYTE 0
86 #define WORD 1
87 #define LONG 2
88 #define QUAD 3
89 #define SNGL 4
90 #define DBLR 5
91 #define EXTR 6
92 #define SDEP 7
93 #define NONE 8
96 * Addressing modes
98 #define E 1 /* general effective address */
99 #define Eind 2 /* indirect address (jump, call) */
100 #define Ew 3 /* address, word size */
101 #define Eb 4 /* address, byte size */
102 #define R 5 /* register, in 'reg' field */
103 #define Rw 6 /* word register, in 'reg' field */
104 #define Ri 7 /* register in instruction */
105 #define S 8 /* segment reg, in 'reg' field */
106 #define Si 9 /* segment reg, in instruction */
107 #define A 10 /* accumulator */
108 #define BX 11 /* (bx) */
109 #define CL 12 /* cl, for shifts */
110 #define DX 13 /* dx, for IO */
111 #define SI 14 /* si */
112 #define DI 15 /* di */
113 #define CR 16 /* control register */
114 #define DR 17 /* debug register */
115 #define TR 18 /* test register */
116 #define I 19 /* immediate, unsigned */
117 #define Is 20 /* immediate, signed */
118 #define Ib 21 /* byte immediate, unsigned */
119 #define Ibs 22 /* byte immediate, signed */
120 #define Iw 23 /* word immediate, unsigned */
121 #define Il 24 /* long immediate */
122 #define O 25 /* direct address */
123 #define Db 26 /* byte displacement from EIP */
124 #define Dl 27 /* long displacement from EIP */
125 #define o1 28 /* constant 1 */
126 #define o3 29 /* constant 3 */
127 #define OS 30 /* immediate offset/segment */
128 #define ST 31 /* FP stack top */
129 #define STI 32 /* FP stack */
130 #define X 33 /* extended FP op */
131 #define XA 34 /* for 'fstcw %ax' */
133 struct inst {
134 const char *i_name; /* name */
135 short i_has_modrm; /* has regmodrm byte */
136 short i_size; /* operand size */
137 int i_mode; /* addressing modes */
138 const char *i_extra; /* pointer to extra opcode table */
141 #define op1(x) (x)
142 #define op2(x,y) ((x)|((y)<<8))
143 #define op3(x,y,z) ((x)|((y)<<8)|((z)<<16))
145 struct finst {
146 const char *f_name; /* name for memory instruction */
147 int f_size; /* size for memory instruction */
148 int f_rrmode; /* mode for rr instruction */
149 const char *f_rrname; /* name for rr instruction
150 (or pointer to table) */
153 static const char * const db_Grp6[] = {
154 "sldt",
155 "str",
156 "lldt",
157 "ltr",
158 "verr",
159 "verw",
164 static const char * const db_Grp7[] = {
165 "sgdt",
166 "sidt",
167 "lgdt",
168 "lidt",
169 "smsw",
171 "lmsw",
172 "invlpg"
175 static const char * const db_Grp8[] = {
180 "bt",
181 "bts",
182 "btr",
183 "btc"
186 static const struct inst db_inst_0f0x[] = {
187 /*00*/ { "", TRUE, NONE, op1(Ew), (char *)db_Grp6 },
188 /*01*/ { "", TRUE, NONE, op1(Ew), (char *)db_Grp7 },
189 /*02*/ { "lar", TRUE, LONG, op2(E,R), 0 },
190 /*03*/ { "lsl", TRUE, LONG, op2(E,R), 0 },
191 /*04*/ { "", FALSE, NONE, 0, 0 },
192 /*05*/ { "", FALSE, NONE, 0, 0 },
193 /*06*/ { "clts", FALSE, NONE, 0, 0 },
194 /*07*/ { "", FALSE, NONE, 0, 0 },
196 /*08*/ { "invd", FALSE, NONE, 0, 0 },
197 /*09*/ { "wbinvd",FALSE, NONE, 0, 0 },
198 /*0a*/ { "", FALSE, NONE, 0, 0 },
199 /*0b*/ { "", FALSE, NONE, 0, 0 },
200 /*0c*/ { "", FALSE, NONE, 0, 0 },
201 /*0d*/ { "", FALSE, NONE, 0, 0 },
202 /*0e*/ { "", FALSE, NONE, 0, 0 },
203 /*0f*/ { "", FALSE, NONE, 0, 0 },
206 static const struct inst db_inst_0f2x[] = {
207 /*20*/ { "mov", TRUE, LONG, op2(CR,E), 0 }, /* use E for reg */
208 /*21*/ { "mov", TRUE, LONG, op2(DR,E), 0 }, /* since mod == 11 */
209 /*22*/ { "mov", TRUE, LONG, op2(E,CR), 0 },
210 /*23*/ { "mov", TRUE, LONG, op2(E,DR), 0 },
211 /*24*/ { "mov", TRUE, LONG, op2(TR,E), 0 },
212 /*25*/ { "", FALSE, NONE, 0, 0 },
213 /*26*/ { "mov", TRUE, LONG, op2(E,TR), 0 },
214 /*27*/ { "", FALSE, NONE, 0, 0 },
216 /*28*/ { "", FALSE, NONE, 0, 0 },
217 /*29*/ { "", FALSE, NONE, 0, 0 },
218 /*2a*/ { "", FALSE, NONE, 0, 0 },
219 /*2b*/ { "", FALSE, NONE, 0, 0 },
220 /*2c*/ { "", FALSE, NONE, 0, 0 },
221 /*2d*/ { "", FALSE, NONE, 0, 0 },
222 /*2e*/ { "", FALSE, NONE, 0, 0 },
223 /*2f*/ { "", FALSE, NONE, 0, 0 },
226 static const struct inst db_inst_0f8x[] = {
227 /*80*/ { "jo", FALSE, NONE, op1(Dl), 0 },
228 /*81*/ { "jno", FALSE, NONE, op1(Dl), 0 },
229 /*82*/ { "jb", FALSE, NONE, op1(Dl), 0 },
230 /*83*/ { "jnb", FALSE, NONE, op1(Dl), 0 },
231 /*84*/ { "jz", FALSE, NONE, op1(Dl), 0 },
232 /*85*/ { "jnz", FALSE, NONE, op1(Dl), 0 },
233 /*86*/ { "jbe", FALSE, NONE, op1(Dl), 0 },
234 /*87*/ { "jnbe", FALSE, NONE, op1(Dl), 0 },
236 /*88*/ { "js", FALSE, NONE, op1(Dl), 0 },
237 /*89*/ { "jns", FALSE, NONE, op1(Dl), 0 },
238 /*8a*/ { "jp", FALSE, NONE, op1(Dl), 0 },
239 /*8b*/ { "jnp", FALSE, NONE, op1(Dl), 0 },
240 /*8c*/ { "jl", FALSE, NONE, op1(Dl), 0 },
241 /*8d*/ { "jnl", FALSE, NONE, op1(Dl), 0 },
242 /*8e*/ { "jle", FALSE, NONE, op1(Dl), 0 },
243 /*8f*/ { "jnle", FALSE, NONE, op1(Dl), 0 },
246 static const struct inst db_inst_0f9x[] = {
247 /*90*/ { "seto", TRUE, NONE, op1(Eb), 0 },
248 /*91*/ { "setno", TRUE, NONE, op1(Eb), 0 },
249 /*92*/ { "setb", TRUE, NONE, op1(Eb), 0 },
250 /*93*/ { "setnb", TRUE, NONE, op1(Eb), 0 },
251 /*94*/ { "setz", TRUE, NONE, op1(Eb), 0 },
252 /*95*/ { "setnz", TRUE, NONE, op1(Eb), 0 },
253 /*96*/ { "setbe", TRUE, NONE, op1(Eb), 0 },
254 /*97*/ { "setnbe",TRUE, NONE, op1(Eb), 0 },
256 /*98*/ { "sets", TRUE, NONE, op1(Eb), 0 },
257 /*99*/ { "setns", TRUE, NONE, op1(Eb), 0 },
258 /*9a*/ { "setp", TRUE, NONE, op1(Eb), 0 },
259 /*9b*/ { "setnp", TRUE, NONE, op1(Eb), 0 },
260 /*9c*/ { "setl", TRUE, NONE, op1(Eb), 0 },
261 /*9d*/ { "setnl", TRUE, NONE, op1(Eb), 0 },
262 /*9e*/ { "setle", TRUE, NONE, op1(Eb), 0 },
263 /*9f*/ { "setnle",TRUE, NONE, op1(Eb), 0 },
266 static const struct inst db_inst_0fax[] = {
267 /*a0*/ { "push", FALSE, NONE, op1(Si), 0 },
268 /*a1*/ { "pop", FALSE, NONE, op1(Si), 0 },
269 /*a2*/ { "cpuid", FALSE, NONE, 0, 0 },
270 /*a3*/ { "bt", TRUE, LONG, op2(E,R), 0 },
271 /*a4*/ { "shld", TRUE, LONG, op3(Ib,E,R), 0 },
272 /*a5*/ { "shld", TRUE, LONG, op3(CL,E,R), 0 },
273 /*a6*/ { "", FALSE, NONE, 0, 0 },
274 /*a7*/ { "", FALSE, NONE, 0, 0 },
276 /*a8*/ { "push", FALSE, NONE, op1(Si), 0 },
277 /*a9*/ { "pop", FALSE, NONE, op1(Si), 0 },
278 /*aa*/ { "", FALSE, NONE, 0, 0 },
279 /*ab*/ { "bts", TRUE, LONG, op2(E,R), 0 },
280 /*ac*/ { "shrd", TRUE, LONG, op3(Ib,E,R), 0 },
281 /*ad*/ { "shrd", TRUE, LONG, op3(CL,E,R), 0 },
282 /*a6*/ { "", FALSE, NONE, 0, 0 },
283 /*a7*/ { "imul", TRUE, LONG, op2(E,R), 0 },
286 static const struct inst db_inst_0fbx[] = {
287 /*b0*/ { "cmpxchg",TRUE, BYTE, op2(E, R), 0 },
288 /*b1*/ { "cmpxchg",TRUE, LONG, op2(E, R), 0 },
289 /*b2*/ { "lss", TRUE, LONG, op2(E, R), 0 },
290 /*b3*/ { "bts", TRUE, LONG, op2(R, E), 0 },
291 /*b4*/ { "lfs", TRUE, LONG, op2(E, R), 0 },
292 /*b5*/ { "lgs", TRUE, LONG, op2(E, R), 0 },
293 /*b6*/ { "movzb", TRUE, LONG, op2(E, R), 0 },
294 /*b7*/ { "movzw", TRUE, LONG, op2(E, R), 0 },
296 /*b8*/ { "", FALSE, NONE, 0, 0 },
297 /*b9*/ { "", FALSE, NONE, 0, 0 },
298 /*ba*/ { "", TRUE, LONG, op2(Ib, E), (char *)db_Grp8 },
299 /*bb*/ { "btc", TRUE, LONG, op2(R, E), 0 },
300 /*bc*/ { "bsf", TRUE, LONG, op2(E, R), 0 },
301 /*bd*/ { "bsr", TRUE, LONG, op2(E, R), 0 },
302 /*be*/ { "movsb", TRUE, LONG, op2(E, R), 0 },
303 /*bf*/ { "movsw", TRUE, LONG, op2(E, R), 0 },
306 static const struct inst db_inst_0fcx[] = {
307 /*c0*/ { "xadd", TRUE, BYTE, op2(R, E), 0 },
308 /*c1*/ { "xadd", TRUE, LONG, op2(R, E), 0 },
309 /*c2*/ { "", FALSE, NONE, 0, 0 },
310 /*c3*/ { "", FALSE, NONE, 0, 0 },
311 /*c4*/ { "", FALSE, NONE, 0, 0 },
312 /*c5*/ { "", FALSE, NONE, 0, 0 },
313 /*c6*/ { "", FALSE, NONE, 0, 0 },
314 /*c7*/ { "", FALSE, NONE, 0, 0 },
315 /*c8*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
316 /*c9*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
317 /*ca*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
318 /*cb*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
319 /*cc*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
320 /*cd*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
321 /*ce*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
322 /*cf*/ { "bswap", FALSE, LONG, op1(Ri), 0 },
325 static const struct inst db_inst_0fdx[] = {
326 /*c0*/ { "cmpxchg",TRUE, BYTE, op2(R, E), 0 },
327 /*c1*/ { "cmpxchg",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*/ { "", FALSE, NONE, 0, 0 },
335 /*c9*/ { "", FALSE, NONE, 0, 0 },
336 /*ca*/ { "", FALSE, NONE, 0, 0 },
337 /*cb*/ { "", FALSE, NONE, 0, 0 },
338 /*cc*/ { "", FALSE, NONE, 0, 0 },
339 /*cd*/ { "", FALSE, NONE, 0, 0 },
340 /*ce*/ { "", FALSE, NONE, 0, 0 },
341 /*cf*/ { "", FALSE, NONE, 0, 0 },
344 static const struct inst * const db_inst_0f[] = {
345 db_inst_0f0x,
347 db_inst_0f2x,
353 db_inst_0f8x,
354 db_inst_0f9x,
355 db_inst_0fax,
356 db_inst_0fbx,
357 db_inst_0fcx,
358 db_inst_0fdx,
363 static const char * const db_Esc92[] = {
364 "fnop", "", "", "", "", "", "", ""
366 static const char * const db_Esc93[] = {
367 "", "", "", "", "", "", "", ""
369 static const char * const db_Esc94[] = {
370 "fchs", "fabs", "", "", "ftst", "fxam", "", ""
372 static const char * const db_Esc95[] = {
373 "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
375 static const char * const db_Esc96[] = {
376 "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
377 "fincstp"
379 static const char * const db_Esc97[] = {
380 "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
383 static const char * const db_Esca4[] = {
384 "", "fucompp","", "", "", "", "", ""
387 static const char * const db_Escb4[] = {
388 "", "", "fnclex","fninit","", "", "", ""
391 static const char * const db_Esce3[] = {
392 "", "fcompp","", "", "", "", "", ""
395 static const char * const db_Escf4[] = {
396 "fnstsw","", "", "", "", "", "", ""
399 static const struct finst db_Esc8[] = {
400 /*0*/ { "fadd", SNGL, op2(STI,ST), 0 },
401 /*1*/ { "fmul", SNGL, op2(STI,ST), 0 },
402 /*2*/ { "fcom", SNGL, op2(STI,ST), 0 },
403 /*3*/ { "fcomp", SNGL, op2(STI,ST), 0 },
404 /*4*/ { "fsub", SNGL, op2(STI,ST), 0 },
405 /*5*/ { "fsubr", SNGL, op2(STI,ST), 0 },
406 /*6*/ { "fdiv", SNGL, op2(STI,ST), 0 },
407 /*7*/ { "fdivr", SNGL, op2(STI,ST), 0 },
410 static const struct finst db_Esc9[] = {
411 /*0*/ { "fld", SNGL, op1(STI), 0 },
412 /*1*/ { "", NONE, op1(STI), "fxch" },
413 /*2*/ { "fst", SNGL, op1(X), (char *)db_Esc92 },
414 /*3*/ { "fstp", SNGL, op1(X), (char *)db_Esc93 },
415 /*4*/ { "fldenv", NONE, op1(X), (char *)db_Esc94 },
416 /*5*/ { "fldcw", NONE, op1(X), (char *)db_Esc95 },
417 /*6*/ { "fnstenv",NONE, op1(X), (char *)db_Esc96 },
418 /*7*/ { "fnstcw", NONE, op1(X), (char *)db_Esc97 },
421 static const struct finst db_Esca[] = {
422 /*0*/ { "fiadd", WORD, 0, 0 },
423 /*1*/ { "fimul", WORD, 0, 0 },
424 /*2*/ { "ficom", WORD, 0, 0 },
425 /*3*/ { "ficomp", WORD, 0, 0 },
426 /*4*/ { "fisub", WORD, op1(X), (char *)db_Esca4 },
427 /*5*/ { "fisubr", WORD, 0, 0 },
428 /*6*/ { "fidiv", WORD, 0, 0 },
429 /*7*/ { "fidivr", WORD, 0, 0 }
432 static const struct finst db_Escb[] = {
433 /*0*/ { "fild", WORD, 0, 0 },
434 /*1*/ { "", NONE, 0, 0 },
435 /*2*/ { "fist", WORD, 0, 0 },
436 /*3*/ { "fistp", WORD, 0, 0 },
437 /*4*/ { "", WORD, op1(X), (char *)db_Escb4 },
438 /*5*/ { "fld", EXTR, 0, 0 },
439 /*6*/ { "", WORD, 0, 0 },
440 /*7*/ { "fstp", EXTR, 0, 0 },
443 static const struct finst db_Escc[] = {
444 /*0*/ { "fadd", DBLR, op2(ST,STI), 0 },
445 /*1*/ { "fmul", DBLR, op2(ST,STI), 0 },
446 /*2*/ { "fcom", DBLR, op2(ST,STI), 0 },
447 /*3*/ { "fcomp", DBLR, op2(ST,STI), 0 },
448 /*4*/ { "fsub", DBLR, op2(ST,STI), "fsubr" },
449 /*5*/ { "fsubr", DBLR, op2(ST,STI), "fsub" },
450 /*6*/ { "fdiv", DBLR, op2(ST,STI), "fdivr" },
451 /*7*/ { "fdivr", DBLR, op2(ST,STI), "fdiv" },
454 static const struct finst db_Escd[] = {
455 /*0*/ { "fld", DBLR, op1(STI), "ffree" },
456 /*1*/ { "", NONE, 0, 0 },
457 /*2*/ { "fst", DBLR, op1(STI), 0 },
458 /*3*/ { "fstp", DBLR, op1(STI), 0 },
459 /*4*/ { "frstor", NONE, op1(STI), "fucom" },
460 /*5*/ { "", NONE, op1(STI), "fucomp" },
461 /*6*/ { "fnsave", NONE, 0, 0 },
462 /*7*/ { "fnstsw", NONE, 0, 0 },
465 static const struct finst db_Esce[] = {
466 /*0*/ { "fiadd", LONG, op2(ST,STI), "faddp" },
467 /*1*/ { "fimul", LONG, op2(ST,STI), "fmulp" },
468 /*2*/ { "ficom", LONG, 0, 0 },
469 /*3*/ { "ficomp", LONG, op1(X), (char *)db_Esce3 },
470 /*4*/ { "fisub", LONG, op2(ST,STI), "fsubrp" },
471 /*5*/ { "fisubr", LONG, op2(ST,STI), "fsubp" },
472 /*6*/ { "fidiv", LONG, op2(ST,STI), "fdivrp" },
473 /*7*/ { "fidivr", LONG, op2(ST,STI), "fdivp" },
476 static const struct finst db_Escf[] = {
477 /*0*/ { "fild", LONG, 0, 0 },
478 /*1*/ { "", LONG, 0, 0 },
479 /*2*/ { "fist", LONG, 0, 0 },
480 /*3*/ { "fistp", LONG, 0, 0 },
481 /*4*/ { "fbld", NONE, op1(XA), (char *)db_Escf4 },
482 /*5*/ { "fld", QUAD, 0, 0 },
483 /*6*/ { "fbstp", NONE, 0, 0 },
484 /*7*/ { "fstp", QUAD, 0, 0 },
487 static const struct finst * const db_Esc_inst[] = {
488 db_Esc8, db_Esc9, db_Esca, db_Escb,
489 db_Escc, db_Escd, db_Esce, db_Escf
492 static const char * const db_Grp1[] = {
493 "add",
494 "or",
495 "adc",
496 "sbb",
497 "and",
498 "sub",
499 "xor",
500 "cmp"
503 static const char * const db_Grp2[] = {
504 "rol",
505 "ror",
506 "rcl",
507 "rcr",
508 "shl",
509 "shr",
510 "shl",
511 "sar"
514 static const struct inst db_Grp3[] = {
515 { "test", TRUE, NONE, op2(I,E), 0 },
516 { "test", TRUE, NONE, op2(I,E), 0 },
517 { "not", TRUE, NONE, op1(E), 0 },
518 { "neg", TRUE, NONE, op1(E), 0 },
519 { "mul", TRUE, NONE, op2(E,A), 0 },
520 { "imul", TRUE, NONE, op2(E,A), 0 },
521 { "div", TRUE, NONE, op2(E,A), 0 },
522 { "idiv", TRUE, NONE, op2(E,A), 0 },
525 static const struct inst db_Grp4[] = {
526 { "inc", TRUE, BYTE, op1(E), 0 },
527 { "dec", TRUE, BYTE, op1(E), 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 },
533 { "", TRUE, NONE, 0, 0 }
536 static const struct inst db_Grp5[] = {
537 { "inc", TRUE, LONG, op1(E), 0 },
538 { "dec", TRUE, LONG, op1(E), 0 },
539 { "call", TRUE, NONE, op1(Eind),0 },
540 { "lcall", TRUE, NONE, op1(Eind),0 },
541 { "jmp", TRUE, NONE, op1(Eind),0 },
542 { "ljmp", TRUE, NONE, op1(Eind),0 },
543 { "push", TRUE, LONG, op1(E), 0 },
544 { "", TRUE, NONE, 0, 0 }
547 static const struct inst db_inst_table[256] = {
548 /*00*/ { "add", TRUE, BYTE, op2(R, E), 0 },
549 /*01*/ { "add", TRUE, LONG, op2(R, E), 0 },
550 /*02*/ { "add", TRUE, BYTE, op2(E, R), 0 },
551 /*03*/ { "add", TRUE, LONG, op2(E, R), 0 },
552 /*04*/ { "add", FALSE, BYTE, op2(Is, A), 0 },
553 /*05*/ { "add", FALSE, LONG, op2(Is, A), 0 },
554 /*06*/ { "push", FALSE, NONE, op1(Si), 0 },
555 /*07*/ { "pop", FALSE, NONE, op1(Si), 0 },
557 /*08*/ { "or", TRUE, BYTE, op2(R, E), 0 },
558 /*09*/ { "or", TRUE, LONG, op2(R, E), 0 },
559 /*0a*/ { "or", TRUE, BYTE, op2(E, R), 0 },
560 /*0b*/ { "or", TRUE, LONG, op2(E, R), 0 },
561 /*0c*/ { "or", FALSE, BYTE, op2(I, A), 0 },
562 /*0d*/ { "or", FALSE, LONG, op2(I, A), 0 },
563 /*0e*/ { "push", FALSE, NONE, op1(Si), 0 },
564 /*0f*/ { "", FALSE, NONE, 0, 0 },
566 /*10*/ { "adc", TRUE, BYTE, op2(R, E), 0 },
567 /*11*/ { "adc", TRUE, LONG, op2(R, E), 0 },
568 /*12*/ { "adc", TRUE, BYTE, op2(E, R), 0 },
569 /*13*/ { "adc", TRUE, LONG, op2(E, R), 0 },
570 /*14*/ { "adc", FALSE, BYTE, op2(Is, A), 0 },
571 /*15*/ { "adc", FALSE, LONG, op2(Is, A), 0 },
572 /*16*/ { "push", FALSE, NONE, op1(Si), 0 },
573 /*17*/ { "pop", FALSE, NONE, op1(Si), 0 },
575 /*18*/ { "sbb", TRUE, BYTE, op2(R, E), 0 },
576 /*19*/ { "sbb", TRUE, LONG, op2(R, E), 0 },
577 /*1a*/ { "sbb", TRUE, BYTE, op2(E, R), 0 },
578 /*1b*/ { "sbb", TRUE, LONG, op2(E, R), 0 },
579 /*1c*/ { "sbb", FALSE, BYTE, op2(Is, A), 0 },
580 /*1d*/ { "sbb", FALSE, LONG, op2(Is, A), 0 },
581 /*1e*/ { "push", FALSE, NONE, op1(Si), 0 },
582 /*1f*/ { "pop", FALSE, NONE, op1(Si), 0 },
584 /*20*/ { "and", TRUE, BYTE, op2(R, E), 0 },
585 /*21*/ { "and", TRUE, LONG, op2(R, E), 0 },
586 /*22*/ { "and", TRUE, BYTE, op2(E, R), 0 },
587 /*23*/ { "and", TRUE, LONG, op2(E, R), 0 },
588 /*24*/ { "and", FALSE, BYTE, op2(I, A), 0 },
589 /*25*/ { "and", FALSE, LONG, op2(I, A), 0 },
590 /*26*/ { "", FALSE, NONE, 0, 0 },
591 /*27*/ { "aaa", FALSE, NONE, 0, 0 },
593 /*28*/ { "sub", TRUE, BYTE, op2(R, E), 0 },
594 /*29*/ { "sub", TRUE, LONG, op2(R, E), 0 },
595 /*2a*/ { "sub", TRUE, BYTE, op2(E, R), 0 },
596 /*2b*/ { "sub", TRUE, LONG, op2(E, R), 0 },
597 /*2c*/ { "sub", FALSE, BYTE, op2(Is, A), 0 },
598 /*2d*/ { "sub", FALSE, LONG, op2(Is, A), 0 },
599 /*2e*/ { "", FALSE, NONE, 0, 0 },
600 /*2f*/ { "das", FALSE, NONE, 0, 0 },
602 /*30*/ { "xor", TRUE, BYTE, op2(R, E), 0 },
603 /*31*/ { "xor", TRUE, LONG, op2(R, E), 0 },
604 /*32*/ { "xor", TRUE, BYTE, op2(E, R), 0 },
605 /*33*/ { "xor", TRUE, LONG, op2(E, R), 0 },
606 /*34*/ { "xor", FALSE, BYTE, op2(I, A), 0 },
607 /*35*/ { "xor", FALSE, LONG, op2(I, A), 0 },
608 /*36*/ { "", FALSE, NONE, 0, 0 },
609 /*37*/ { "daa", FALSE, NONE, 0, 0 },
611 /*38*/ { "cmp", TRUE, BYTE, op2(R, E), 0 },
612 /*39*/ { "cmp", TRUE, LONG, op2(R, E), 0 },
613 /*3a*/ { "cmp", TRUE, BYTE, op2(E, R), 0 },
614 /*3b*/ { "cmp", TRUE, LONG, op2(E, R), 0 },
615 /*3c*/ { "cmp", FALSE, BYTE, op2(Is, A), 0 },
616 /*3d*/ { "cmp", FALSE, LONG, op2(Is, A), 0 },
617 /*3e*/ { "", FALSE, NONE, 0, 0 },
618 /*3f*/ { "aas", FALSE, NONE, 0, 0 },
620 /*40*/ { "inc", FALSE, LONG, op1(Ri), 0 },
621 /*41*/ { "inc", FALSE, LONG, op1(Ri), 0 },
622 /*42*/ { "inc", FALSE, LONG, op1(Ri), 0 },
623 /*43*/ { "inc", FALSE, LONG, op1(Ri), 0 },
624 /*44*/ { "inc", FALSE, LONG, op1(Ri), 0 },
625 /*45*/ { "inc", FALSE, LONG, op1(Ri), 0 },
626 /*46*/ { "inc", FALSE, LONG, op1(Ri), 0 },
627 /*47*/ { "inc", FALSE, LONG, op1(Ri), 0 },
629 /*48*/ { "dec", FALSE, LONG, op1(Ri), 0 },
630 /*49*/ { "dec", FALSE, LONG, op1(Ri), 0 },
631 /*4a*/ { "dec", FALSE, LONG, op1(Ri), 0 },
632 /*4b*/ { "dec", FALSE, LONG, op1(Ri), 0 },
633 /*4c*/ { "dec", FALSE, LONG, op1(Ri), 0 },
634 /*4d*/ { "dec", FALSE, LONG, op1(Ri), 0 },
635 /*4e*/ { "dec", FALSE, LONG, op1(Ri), 0 },
636 /*4f*/ { "dec", FALSE, LONG, op1(Ri), 0 },
638 /*50*/ { "push", FALSE, LONG, op1(Ri), 0 },
639 /*51*/ { "push", FALSE, LONG, op1(Ri), 0 },
640 /*52*/ { "push", FALSE, LONG, op1(Ri), 0 },
641 /*53*/ { "push", FALSE, LONG, op1(Ri), 0 },
642 /*54*/ { "push", FALSE, LONG, op1(Ri), 0 },
643 /*55*/ { "push", FALSE, LONG, op1(Ri), 0 },
644 /*56*/ { "push", FALSE, LONG, op1(Ri), 0 },
645 /*57*/ { "push", FALSE, LONG, op1(Ri), 0 },
647 /*58*/ { "pop", FALSE, LONG, op1(Ri), 0 },
648 /*59*/ { "pop", FALSE, LONG, op1(Ri), 0 },
649 /*5a*/ { "pop", FALSE, LONG, op1(Ri), 0 },
650 /*5b*/ { "pop", FALSE, LONG, op1(Ri), 0 },
651 /*5c*/ { "pop", FALSE, LONG, op1(Ri), 0 },
652 /*5d*/ { "pop", FALSE, LONG, op1(Ri), 0 },
653 /*5e*/ { "pop", FALSE, LONG, op1(Ri), 0 },
654 /*5f*/ { "pop", FALSE, LONG, op1(Ri), 0 },
656 /*60*/ { "pusha", FALSE, LONG, 0, 0 },
657 /*61*/ { "popa", FALSE, LONG, 0, 0 },
658 /*62*/ { "bound", TRUE, LONG, op2(E, R), 0 },
659 /*63*/ { "arpl", TRUE, NONE, op2(Ew,Rw), 0 },
661 /*64*/ { "", FALSE, NONE, 0, 0 },
662 /*65*/ { "", FALSE, NONE, 0, 0 },
663 /*66*/ { "", FALSE, NONE, 0, 0 },
664 /*67*/ { "", FALSE, NONE, 0, 0 },
666 /*68*/ { "push", FALSE, LONG, op1(I), 0 },
667 /*69*/ { "imul", TRUE, LONG, op3(I,E,R), 0 },
668 /*6a*/ { "push", FALSE, LONG, op1(Ib), 0 },
669 /*6b*/ { "imul", TRUE, LONG, op3(Ibs,E,R),0 },
670 /*6c*/ { "ins", FALSE, BYTE, op2(DX, DI), 0 },
671 /*6d*/ { "ins", FALSE, LONG, op2(DX, DI), 0 },
672 /*6e*/ { "outs", FALSE, BYTE, op2(SI, DX), 0 },
673 /*6f*/ { "outs", FALSE, LONG, op2(SI, DX), 0 },
675 /*70*/ { "jo", FALSE, NONE, op1(Db), 0 },
676 /*71*/ { "jno", FALSE, NONE, op1(Db), 0 },
677 /*72*/ { "jb", FALSE, NONE, op1(Db), 0 },
678 /*73*/ { "jnb", FALSE, NONE, op1(Db), 0 },
679 /*74*/ { "jz", FALSE, NONE, op1(Db), 0 },
680 /*75*/ { "jnz", FALSE, NONE, op1(Db), 0 },
681 /*76*/ { "jbe", FALSE, NONE, op1(Db), 0 },
682 /*77*/ { "jnbe", FALSE, NONE, op1(Db), 0 },
684 /*78*/ { "js", FALSE, NONE, op1(Db), 0 },
685 /*79*/ { "jns", FALSE, NONE, op1(Db), 0 },
686 /*7a*/ { "jp", FALSE, NONE, op1(Db), 0 },
687 /*7b*/ { "jnp", FALSE, NONE, op1(Db), 0 },
688 /*7c*/ { "jl", FALSE, NONE, op1(Db), 0 },
689 /*7d*/ { "jnl", FALSE, NONE, op1(Db), 0 },
690 /*7e*/ { "jle", FALSE, NONE, op1(Db), 0 },
691 /*7f*/ { "jnle", FALSE, NONE, op1(Db), 0 },
693 /*80*/ { "", TRUE, BYTE, op2(I, E), (char *)db_Grp1 },
694 /*81*/ { "", TRUE, LONG, op2(I, E), (char *)db_Grp1 },
695 /*82*/ { "", TRUE, BYTE, op2(Is,E), (char *)db_Grp1 },
696 /*83*/ { "", TRUE, LONG, op2(Ibs,E), (char *)db_Grp1 },
697 /*84*/ { "test", TRUE, BYTE, op2(R, E), 0 },
698 /*85*/ { "test", TRUE, LONG, op2(R, E), 0 },
699 /*86*/ { "xchg", TRUE, BYTE, op2(R, E), 0 },
700 /*87*/ { "xchg", TRUE, LONG, op2(R, E), 0 },
702 /*88*/ { "mov", TRUE, BYTE, op2(R, E), 0 },
703 /*89*/ { "mov", TRUE, LONG, op2(R, E), 0 },
704 /*8a*/ { "mov", TRUE, BYTE, op2(E, R), 0 },
705 /*8b*/ { "mov", TRUE, LONG, op2(E, R), 0 },
706 /*8c*/ { "mov", TRUE, NONE, op2(S, Ew), 0 },
707 /*8d*/ { "lea", TRUE, LONG, op2(E, R), 0 },
708 /*8e*/ { "mov", TRUE, NONE, op2(Ew, S), 0 },
709 /*8f*/ { "pop", TRUE, LONG, op1(E), 0 },
711 /*90*/ { "nop", FALSE, NONE, 0, 0 },
712 /*91*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
713 /*92*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
714 /*93*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
715 /*94*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
716 /*95*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
717 /*96*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
718 /*97*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
720 /*98*/ { "cbw", FALSE, SDEP, 0, "cwde" }, /* cbw/cwde */
721 /*99*/ { "cwd", FALSE, SDEP, 0, "cdq" }, /* cwd/cdq */
722 /*9a*/ { "lcall", FALSE, NONE, op1(OS), 0 },
723 /*9b*/ { "wait", FALSE, NONE, 0, 0 },
724 /*9c*/ { "pushf", FALSE, LONG, 0, 0 },
725 /*9d*/ { "popf", FALSE, LONG, 0, 0 },
726 /*9e*/ { "sahf", FALSE, NONE, 0, 0 },
727 /*9f*/ { "lahf", FALSE, NONE, 0, 0 },
729 /*a0*/ { "mov", FALSE, BYTE, op2(O, A), 0 },
730 /*a1*/ { "mov", FALSE, LONG, op2(O, A), 0 },
731 /*a2*/ { "mov", FALSE, BYTE, op2(A, O), 0 },
732 /*a3*/ { "mov", FALSE, LONG, op2(A, O), 0 },
733 /*a4*/ { "movs", FALSE, BYTE, op2(SI,DI), 0 },
734 /*a5*/ { "movs", FALSE, LONG, op2(SI,DI), 0 },
735 /*a6*/ { "cmps", FALSE, BYTE, op2(SI,DI), 0 },
736 /*a7*/ { "cmps", FALSE, LONG, op2(SI,DI), 0 },
738 /*a8*/ { "test", FALSE, BYTE, op2(I, A), 0 },
739 /*a9*/ { "test", FALSE, LONG, op2(I, A), 0 },
740 /*aa*/ { "stos", FALSE, BYTE, op1(DI), 0 },
741 /*ab*/ { "stos", FALSE, LONG, op1(DI), 0 },
742 /*ac*/ { "lods", FALSE, BYTE, op1(SI), 0 },
743 /*ad*/ { "lods", FALSE, LONG, op1(SI), 0 },
744 /*ae*/ { "scas", FALSE, BYTE, op1(DI), 0 },
745 /*af*/ { "scas", FALSE, LONG, op1(DI), 0 },
747 /*b0*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
748 /*b1*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
749 /*b2*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
750 /*b3*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
751 /*b4*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
752 /*b5*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
753 /*b6*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
754 /*b7*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
756 /*b8*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
757 /*b9*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
758 /*ba*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
759 /*bb*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
760 /*bc*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
761 /*bd*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
762 /*be*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
763 /*bf*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
765 /*c0*/ { "", TRUE, BYTE, op2(Ib, E), (char *)db_Grp2 },
766 /*c1*/ { "", TRUE, LONG, op2(Ib, E), (char *)db_Grp2 },
767 /*c2*/ { "ret", FALSE, NONE, op1(Iw), 0 },
768 /*c3*/ { "ret", FALSE, NONE, 0, 0 },
769 /*c4*/ { "les", TRUE, LONG, op2(E, R), 0 },
770 /*c5*/ { "lds", TRUE, LONG, op2(E, R), 0 },
771 /*c6*/ { "mov", TRUE, BYTE, op2(I, E), 0 },
772 /*c7*/ { "mov", TRUE, LONG, op2(I, E), 0 },
774 /*c8*/ { "enter", FALSE, NONE, op2(Iw, Ib), 0 },
775 /*c9*/ { "leave", FALSE, NONE, 0, 0 },
776 /*ca*/ { "lret", FALSE, NONE, op1(Iw), 0 },
777 /*cb*/ { "lret", FALSE, NONE, 0, 0 },
778 /*cc*/ { "int", FALSE, NONE, op1(o3), 0 },
779 /*cd*/ { "int", FALSE, NONE, op1(Ib), 0 },
780 /*ce*/ { "into", FALSE, NONE, 0, 0 },
781 /*cf*/ { "iret", FALSE, NONE, 0, 0 },
783 /*d0*/ { "", TRUE, BYTE, op2(o1, E), (char *)db_Grp2 },
784 /*d1*/ { "", TRUE, LONG, op2(o1, E), (char *)db_Grp2 },
785 /*d2*/ { "", TRUE, BYTE, op2(CL, E), (char *)db_Grp2 },
786 /*d3*/ { "", TRUE, LONG, op2(CL, E), (char *)db_Grp2 },
787 /*d4*/ { "aam", TRUE, NONE, 0, 0 },
788 /*d5*/ { "aad", TRUE, NONE, 0, 0 },
789 /*d6*/ { "", FALSE, NONE, 0, 0 },
790 /*d7*/ { "xlat", FALSE, BYTE, op1(BX), 0 },
792 /*d8*/ { "", TRUE, NONE, 0, (char *)db_Esc8 },
793 /*d9*/ { "", TRUE, NONE, 0, (char *)db_Esc9 },
794 /*da*/ { "", TRUE, NONE, 0, (char *)db_Esca },
795 /*db*/ { "", TRUE, NONE, 0, (char *)db_Escb },
796 /*dc*/ { "", TRUE, NONE, 0, (char *)db_Escc },
797 /*dd*/ { "", TRUE, NONE, 0, (char *)db_Escd },
798 /*de*/ { "", TRUE, NONE, 0, (char *)db_Esce },
799 /*df*/ { "", TRUE, NONE, 0, (char *)db_Escf },
801 /*e0*/ { "loopne",FALSE, NONE, op1(Db), 0 },
802 /*e1*/ { "loope", FALSE, NONE, op1(Db), 0 },
803 /*e2*/ { "loop", FALSE, NONE, op1(Db), 0 },
804 /*e3*/ { "jcxz", FALSE, SDEP, op1(Db), "jecxz" },
805 /*e4*/ { "in", FALSE, BYTE, op2(Ib, A), 0 },
806 /*e5*/ { "in", FALSE, LONG, op2(Ib, A) , 0 },
807 /*e6*/ { "out", FALSE, BYTE, op2(A, Ib), 0 },
808 /*e7*/ { "out", FALSE, LONG, op2(A, Ib) , 0 },
810 /*e8*/ { "call", FALSE, NONE, op1(Dl), 0 },
811 /*e9*/ { "jmp", FALSE, NONE, op1(Dl), 0 },
812 /*ea*/ { "ljmp", FALSE, NONE, op1(OS), 0 },
813 /*eb*/ { "jmp", FALSE, NONE, op1(Db), 0 },
814 /*ec*/ { "in", FALSE, BYTE, op2(DX, A), 0 },
815 /*ed*/ { "in", FALSE, LONG, op2(DX, A) , 0 },
816 /*ee*/ { "out", FALSE, BYTE, op2(A, DX), 0 },
817 /*ef*/ { "out", FALSE, LONG, op2(A, DX) , 0 },
819 /*f0*/ { "", FALSE, NONE, 0, 0 },
820 /*f1*/ { "", FALSE, NONE, 0, 0 },
821 /*f2*/ { "", FALSE, NONE, 0, 0 },
822 /*f3*/ { "", FALSE, NONE, 0, 0 },
823 /*f4*/ { "hlt", FALSE, NONE, 0, 0 },
824 /*f5*/ { "cmc", FALSE, NONE, 0, 0 },
825 /*f6*/ { "", TRUE, BYTE, 0, (char *)db_Grp3 },
826 /*f7*/ { "", TRUE, LONG, 0, (char *)db_Grp3 },
828 /*f8*/ { "clc", FALSE, NONE, 0, 0 },
829 /*f9*/ { "stc", FALSE, NONE, 0, 0 },
830 /*fa*/ { "cli", FALSE, NONE, 0, 0 },
831 /*fb*/ { "sti", FALSE, NONE, 0, 0 },
832 /*fc*/ { "cld", FALSE, NONE, 0, 0 },
833 /*fd*/ { "std", FALSE, NONE, 0, 0 },
834 /*fe*/ { "", TRUE, NONE, 0, (char *)db_Grp4 },
835 /*ff*/ { "", TRUE, NONE, 0, (char *)db_Grp5 },
838 static const struct inst db_bad_inst =
839 { "???", FALSE, NONE, 0, 0 }
842 #define f_mod(byte) ((byte)>>6)
843 #define f_reg(byte) (((byte)>>3)&0x7)
844 #define f_rm(byte) ((byte)&0x7)
846 #define sib_ss(byte) ((byte)>>6)
847 #define sib_index(byte) (((byte)>>3)&0x7)
848 #define sib_base(byte) ((byte)&0x7)
850 struct i_addr {
851 int is_reg; /* if reg, reg number is in 'disp' */
852 int disp;
853 const char * base;
854 const char * index;
855 int ss;
858 static const char * const db_index_reg_16[8] = {
859 "%bx,%si",
860 "%bx,%di",
861 "%bp,%si",
862 "%bp,%di",
863 "%si",
864 "%di",
865 "%bp",
866 "%bx"
869 static const char * const db_reg[3][8] = {
870 { "%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh" },
871 { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di" },
872 { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi" }
875 static const char * const db_seg_reg[8] = {
876 "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
880 * lengths for size attributes
882 static const int db_lengths[] = {
883 1, /* BYTE */
884 2, /* WORD */
885 4, /* LONG */
886 8, /* QUAD */
887 4, /* SNGL */
888 8, /* DBLR */
889 10, /* EXTR */
892 static unsigned int db_get_task_value( const DBG_ADDR *addr,
893 int size, int is_signed )
895 unsigned int result = 0;
896 char buffer[4];
898 if (size != 1 && size != 2 && size != 4) {
899 DEBUG_Printf(DBG_CHN_MESG, "Illegal size specified\n");
900 } else {
901 DEBUG_READ_MEM((void*)DEBUG_ToLinear( addr ), buffer, size);
903 switch(size)
905 case 4:
906 if (is_signed) result = (unsigned int) *(int *)buffer;
907 else result = *(unsigned int *)buffer;
908 break;
909 case 2:
910 if (is_signed) result = (unsigned int) *(short int *)buffer;
911 else result = *(unsigned short int *)buffer;
912 break;
913 case 1:
914 if (is_signed) result = (unsigned int) *(char *)buffer;
915 else result = *(unsigned char *)buffer;
916 break;
919 return result;
922 #define get_value_inc(result, addr, size, is_signed) \
923 result = db_get_task_value((addr), (size), (is_signed)); \
924 if (!db_disasm_16) (addr)->off += (size); \
925 else (addr)->off = ((addr)->off + (size)) & 0xffff;
928 * Read address at location and return updated location.
930 void db_read_address( DBG_ADDR *addr, int short_addr, int regmodrm,
931 struct i_addr *addrp )
933 int mod, rm, sib, index, disp;
935 mod = f_mod(regmodrm);
936 rm = f_rm(regmodrm);
938 if (mod == 3) {
939 addrp->is_reg = TRUE;
940 addrp->disp = rm;
941 return;
943 addrp->is_reg = FALSE;
944 addrp->index = 0;
946 if (short_addr) {
947 addrp->index = 0;
948 addrp->ss = 0;
949 switch (mod) {
950 case 0:
951 if (rm == 6) {
952 get_value_inc(disp, addr, 2, TRUE);
953 addrp->disp = disp;
954 addrp->base = 0;
956 else {
957 addrp->disp = 0;
958 addrp->base = db_index_reg_16[rm];
960 break;
961 case 1:
962 get_value_inc(disp, addr, 1, TRUE);
963 addrp->disp = disp;
964 addrp->base = db_index_reg_16[rm];
965 break;
966 case 2:
967 get_value_inc(disp, addr, 2, TRUE);
968 addrp->disp = disp;
969 addrp->base = db_index_reg_16[rm];
970 break;
973 else {
974 if (mod != 3 && rm == 4) {
975 get_value_inc(sib, addr, 1, FALSE);
976 rm = sib_base(sib);
977 index = sib_index(sib);
978 if (index != 4)
979 addrp->index = db_reg[LONG][index];
980 addrp->ss = sib_ss(sib);
983 switch (mod) {
984 case 0:
985 if (rm == 5) {
986 get_value_inc(addrp->disp, addr, 4, FALSE);
987 addrp->base = 0;
989 else {
990 addrp->disp = 0;
991 addrp->base = db_reg[LONG][rm];
993 break;
995 case 1:
996 get_value_inc(disp, addr, 1, TRUE);
997 addrp->disp = disp;
998 addrp->base = db_reg[LONG][rm];
999 break;
1001 case 2:
1002 get_value_inc(disp, addr, 4, FALSE);
1003 addrp->disp = disp;
1004 addrp->base = db_reg[LONG][rm];
1005 break;
1010 static void db_task_printsym(unsigned int addr, int size)
1012 DBG_ADDR address;
1014 address.seg = 0;
1015 address.off = addr;
1017 DEBUG_PrintAddress( &address, db_disasm_16 ? 16 : 32, TRUE );
1020 void db_print_address(char *seg, int size, struct i_addr *addrp, int byref)
1022 if (addrp->is_reg) {
1023 DEBUG_Printf(DBG_CHN_MESG,"%s", db_reg[size][addrp->disp]);
1024 return;
1027 if (seg) {
1028 DEBUG_Printf(DBG_CHN_MESG,"%s:", seg);
1031 if (addrp->base != 0 || addrp->index != 0) {
1032 DEBUG_Printf(DBG_CHN_MESG,"0x%x(", addrp->disp);
1033 if (addrp->base)
1034 DEBUG_Printf(DBG_CHN_MESG,"%s", addrp->base);
1035 if (addrp->index)
1036 DEBUG_Printf(DBG_CHN_MESG,",%s,%d", addrp->index, 1<<addrp->ss);
1037 DEBUG_Printf(DBG_CHN_MESG,")");
1039 else {
1041 /* try to get destination of indirect call
1042 does not work for segmented adresses */
1043 if (!seg && byref) {
1044 void* a1;
1045 void* a2;
1047 DEBUG_Printf(DBG_CHN_MESG,"0x%x -> ", addrp->disp);
1048 if (!DEBUG_READ_MEM((void*)addrp->disp, &a1, sizeof(a1))) {
1049 DEBUG_Printf(DBG_CHN_MESG, "(invalid source)");
1050 } else if (!DEBUG_READ_MEM(a1, &a2, sizeof(a2))) {
1051 DEBUG_Printf(DBG_CHN_MESG, "(invalid destination)");
1052 } else {
1053 db_task_printsym((unsigned long)a1, 0);
1056 else
1057 db_task_printsym(addrp->disp, size);
1062 * Disassemble floating-point ("escape") instruction
1063 * and return updated location.
1065 void db_disasm_esc( DBG_ADDR *addr, int inst, int short_addr,
1066 int size, char *seg )
1068 int regmodrm;
1069 const struct finst *fp;
1070 int mod;
1071 struct i_addr address;
1072 const char * name;
1074 get_value_inc(regmodrm, addr, 1, FALSE);
1075 if( !db_display )
1077 return;
1080 fp = &db_Esc_inst[inst - 0xd8][f_reg(regmodrm)];
1081 mod = f_mod(regmodrm);
1082 if (mod != 3) {
1084 * Normal address modes.
1086 db_read_address( addr, short_addr, regmodrm, &address);
1087 DEBUG_Printf(DBG_CHN_MESG,fp->f_name);
1088 switch(fp->f_size) {
1089 case SNGL:
1090 DEBUG_Printf(DBG_CHN_MESG,"s");
1091 break;
1092 case DBLR:
1093 DEBUG_Printf(DBG_CHN_MESG,"l");
1094 break;
1095 case EXTR:
1096 DEBUG_Printf(DBG_CHN_MESG,"t");
1097 break;
1098 case WORD:
1099 DEBUG_Printf(DBG_CHN_MESG,"s");
1100 break;
1101 case LONG:
1102 DEBUG_Printf(DBG_CHN_MESG,"l");
1103 break;
1104 case QUAD:
1105 DEBUG_Printf(DBG_CHN_MESG,"q");
1106 break;
1107 default:
1108 break;
1110 DEBUG_Printf(DBG_CHN_MESG,"\t");
1111 db_print_address(seg, BYTE, &address, 0);
1113 else {
1115 * 'reg-reg' - special formats
1117 switch (fp->f_rrmode) {
1118 case op2(ST,STI):
1119 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1120 DEBUG_Printf(DBG_CHN_MESG,"%s\t%%st,%%st(%d)",name,f_rm(regmodrm));
1121 break;
1122 case op2(STI,ST):
1123 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1124 DEBUG_Printf(DBG_CHN_MESG,"%s\t%%st(%d),%%st",name, f_rm(regmodrm));
1125 break;
1126 case op1(STI):
1127 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1128 DEBUG_Printf(DBG_CHN_MESG,"%s\t%%st(%d)",name, f_rm(regmodrm));
1129 break;
1130 case op1(X):
1131 DEBUG_Printf(DBG_CHN_MESG,"%s", ((char **)fp->f_rrname)[f_rm(regmodrm)]);
1132 break;
1133 case op1(XA):
1134 DEBUG_Printf(DBG_CHN_MESG,"%s\t%%ax",
1135 ((char **)fp->f_rrname)[f_rm(regmodrm)]);
1136 break;
1137 default:
1138 DEBUG_Printf(DBG_CHN_MESG,"<bad instruction>");
1139 break;
1145 /***********************************************************************
1146 * DEBUG_Disasm
1148 * Disassemble instruction at 'addr'. addr is changed to point to the
1149 * start of the next instruction.
1151 void DEBUG_Disasm( DBG_ADDR *addr, int display )
1153 int inst;
1154 int size;
1155 int short_addr;
1156 char * seg;
1157 const struct inst *ip;
1158 const char *i_name;
1159 int i_size;
1160 int i_mode;
1161 int regmodrm = 0;
1162 BOOL first;
1163 int displ;
1164 int prefix;
1165 int imm;
1166 int len;
1167 struct i_addr address;
1170 * Set this so we get can supress the printout if we need to.
1172 db_display = display;
1173 switch (DEBUG_GetSelectorType(addr->seg)) {
1174 case 16: db_disasm_16 = 1; break;
1175 case 32: db_disasm_16 = 0; break;
1176 default: DEBUG_Printf(DBG_CHN_MESG, "Bad selector %ld\n", addr->seg); return;
1179 get_value_inc( inst, addr, 1, FALSE );
1181 if (db_disasm_16) {
1182 short_addr = TRUE;
1183 size = WORD;
1185 else {
1186 short_addr = FALSE;
1187 size = LONG;
1189 seg = 0;
1192 * Get prefixes
1194 prefix = TRUE;
1195 do {
1196 switch (inst) {
1197 case 0x66: /* data16 */
1198 if (size == LONG)
1199 size = WORD;
1200 else
1201 size = LONG;
1202 break;
1203 case 0x67:
1204 short_addr = !short_addr;
1205 break;
1206 case 0x26:
1207 seg = "%es";
1208 break;
1209 case 0x36:
1210 seg = "%ss";
1211 break;
1212 case 0x2e:
1213 seg = "%cs";
1214 break;
1215 case 0x3e:
1216 seg = "%ds";
1217 break;
1218 case 0x64:
1219 seg = "%fs";
1220 break;
1221 case 0x65:
1222 seg = "%gs";
1223 break;
1224 case 0xf0:
1225 if( db_display )
1226 DEBUG_Printf(DBG_CHN_MESG,"lock ");
1227 break;
1228 case 0xf2:
1229 if( db_display )
1230 DEBUG_Printf(DBG_CHN_MESG,"repne ");
1231 break;
1232 case 0xf3:
1233 if( db_display )
1234 DEBUG_Printf(DBG_CHN_MESG,"repe "); /* XXX repe VS rep */
1235 break;
1236 default:
1237 prefix = FALSE;
1238 break;
1240 if (prefix) {
1241 get_value_inc(inst, addr, 1, FALSE);
1243 } while (prefix);
1245 if (inst >= 0xd8 && inst <= 0xdf)
1247 db_disasm_esc( addr, inst, short_addr, size, seg);
1248 return;
1251 if (inst == 0x0f) {
1252 get_value_inc(inst, addr, 1, FALSE);
1253 ip = db_inst_0f[inst>>4];
1254 if (ip == 0) {
1255 ip = &db_bad_inst;
1257 else {
1258 ip = &ip[inst&0xf];
1261 else
1262 ip = &db_inst_table[inst];
1264 if (ip->i_has_modrm) {
1265 get_value_inc(regmodrm, addr, 1, FALSE);
1266 db_read_address( addr, short_addr, regmodrm, &address);
1269 i_name = ip->i_name;
1270 i_size = ip->i_size;
1271 i_mode = ip->i_mode;
1273 if (ip->i_extra == (char *)db_Grp1 ||
1274 ip->i_extra == (char *)db_Grp2 ||
1275 ip->i_extra == (char *)db_Grp6 ||
1276 ip->i_extra == (char *)db_Grp7 ||
1277 ip->i_extra == (char *)db_Grp8) {
1278 i_name = ((char **)ip->i_extra)[f_reg(regmodrm)];
1280 else if (ip->i_extra == (char *)db_Grp3) {
1281 ip = (struct inst *)ip->i_extra;
1282 ip = &ip[f_reg(regmodrm)];
1283 i_name = ip->i_name;
1284 i_mode = ip->i_mode;
1286 else if (ip->i_extra == (char *)db_Grp4 ||
1287 ip->i_extra == (char *)db_Grp5) {
1288 ip = (struct inst *)ip->i_extra;
1289 ip = &ip[f_reg(regmodrm)];
1290 i_name = ip->i_name;
1291 i_mode = ip->i_mode;
1292 i_size = ip->i_size;
1295 if (i_size == SDEP) {
1296 if( db_display )
1298 if (size == WORD)
1299 DEBUG_Printf(DBG_CHN_MESG,i_name);
1300 else
1301 DEBUG_Printf(DBG_CHN_MESG,ip->i_extra);
1304 else {
1305 if( db_display )
1307 DEBUG_Printf(DBG_CHN_MESG,i_name);
1309 if (i_size != NONE) {
1310 if (i_size == BYTE) {
1311 if( db_display )
1313 DEBUG_Printf(DBG_CHN_MESG,"b");
1315 size = BYTE;
1317 else if (i_size == WORD) {
1318 if( db_display )
1320 DEBUG_Printf(DBG_CHN_MESG,"w");
1322 size = WORD;
1324 else if (size == WORD)
1326 if( db_display )
1328 DEBUG_Printf(DBG_CHN_MESG,"w");
1331 else
1333 if( db_display )
1335 DEBUG_Printf(DBG_CHN_MESG,"l");
1340 if( db_display )
1342 DEBUG_Printf(DBG_CHN_MESG,"\t");
1344 for (first = TRUE;
1345 i_mode != 0;
1346 i_mode >>= 8, first = FALSE)
1348 if (!first && db_display)
1349 DEBUG_Printf(DBG_CHN_MESG,",");
1351 switch (i_mode & 0xFF) {
1353 case E:
1354 if( db_display )
1356 db_print_address(seg, size, &address, 0);
1358 break;
1360 case Eind:
1361 if( db_display )
1363 DEBUG_Printf(DBG_CHN_MESG,"*");
1364 db_print_address(seg, size, &address, 1);
1366 break;
1368 case Ew:
1369 if( db_display )
1371 db_print_address(seg, WORD, &address, 0);
1373 break;
1375 case Eb:
1376 if( db_display )
1378 db_print_address(seg, BYTE, &address, 0);
1380 break;
1382 case R:
1383 if( db_display )
1385 DEBUG_Printf(DBG_CHN_MESG,"%s", db_reg[size][f_reg(regmodrm)]);
1387 break;
1389 case Rw:
1390 if( db_display )
1392 DEBUG_Printf(DBG_CHN_MESG,"%s", db_reg[WORD][f_reg(regmodrm)]);
1394 break;
1396 case Ri:
1397 if( db_display )
1399 DEBUG_Printf(DBG_CHN_MESG,"%s", db_reg[size][f_rm(inst)]);
1401 break;
1403 case S:
1404 if( db_display )
1406 DEBUG_Printf(DBG_CHN_MESG,"%s", db_seg_reg[f_reg(regmodrm)]);
1408 break;
1410 case Si:
1411 if( db_display )
1413 DEBUG_Printf(DBG_CHN_MESG,"%s", db_seg_reg[f_reg(inst)]);
1415 break;
1417 case A:
1418 if( db_display )
1420 DEBUG_Printf(DBG_CHN_MESG,"%s", db_reg[size][0]); /* acc */
1422 break;
1424 case BX:
1425 if( db_display )
1427 if (seg)
1428 DEBUG_Printf(DBG_CHN_MESG,"%s:", seg);
1429 DEBUG_Printf(DBG_CHN_MESG,"(%s)", short_addr ? "%bx" : "%ebx");
1431 break;
1433 case CL:
1434 if( db_display )
1436 DEBUG_Printf(DBG_CHN_MESG,"%%cl");
1438 break;
1440 case DX:
1441 if( db_display )
1443 DEBUG_Printf(DBG_CHN_MESG,"%%dx");
1445 break;
1447 case SI:
1448 if( db_display )
1450 if (seg)
1451 DEBUG_Printf(DBG_CHN_MESG,"%s:", seg);
1452 DEBUG_Printf(DBG_CHN_MESG,"(%s)", short_addr ? "%si" : "%esi");
1454 break;
1456 case DI:
1457 if( db_display )
1459 DEBUG_Printf(DBG_CHN_MESG,"%%es:(%s)", short_addr ? "%di" : "%edi");
1461 break;
1463 case CR:
1464 if( db_display )
1466 DEBUG_Printf(DBG_CHN_MESG,"%%cr%d", f_reg(regmodrm));
1468 break;
1470 case DR:
1471 if( db_display )
1473 DEBUG_Printf(DBG_CHN_MESG,"%%dr%d", f_reg(regmodrm));
1475 break;
1477 case TR:
1478 if( db_display )
1480 DEBUG_Printf(DBG_CHN_MESG,"%%tr%d", f_reg(regmodrm));
1482 break;
1484 case I:
1485 len = db_lengths[size];
1486 get_value_inc(imm, addr, len, FALSE);/* unsigned */
1487 if( db_display )
1489 DEBUG_Printf(DBG_CHN_MESG,"$0x%x", imm);
1491 break;
1493 case Is:
1494 len = db_lengths[size];
1495 get_value_inc(imm, addr, len, TRUE); /* signed */
1496 if( db_display )
1498 DEBUG_Printf(DBG_CHN_MESG,"$%d", imm);
1500 break;
1502 case Ib:
1503 get_value_inc(imm, addr, 1, FALSE); /* unsigned */
1504 if( db_display )
1506 DEBUG_Printf(DBG_CHN_MESG,"$0x%x", imm);
1508 break;
1510 case Ibs:
1511 get_value_inc(imm, addr, 1, TRUE); /* signed */
1512 if( db_display )
1514 DEBUG_Printf(DBG_CHN_MESG,"$%d", imm);
1516 break;
1518 case Iw:
1519 get_value_inc(imm, addr, 2, FALSE); /* unsigned */
1520 if( db_display )
1522 DEBUG_Printf(DBG_CHN_MESG,"$0x%x", imm);
1524 break;
1526 case Il:
1527 get_value_inc(imm, addr, 4, FALSE);
1528 if( db_display )
1530 DEBUG_Printf(DBG_CHN_MESG,"$0x%x", imm);
1532 break;
1534 case O:
1535 if (short_addr) {
1536 get_value_inc(displ, addr, 2, TRUE);
1538 else {
1539 get_value_inc(displ, addr, 4, TRUE);
1541 if( !db_display )
1543 break;
1546 if (seg)
1547 DEBUG_Printf(DBG_CHN_MESG,"%s:0x%x",seg, displ);
1548 else
1549 db_task_printsym(displ, short_addr ? WORD : LONG);
1550 break;
1552 case Db:
1553 get_value_inc(displ, addr, 1, TRUE);
1554 if( !db_display )
1556 break;
1559 if (size == WORD) {
1560 /* offset only affects low 16 bits */
1561 displ = (addr->off & 0xffff0000)
1562 | ((addr->off + displ) & 0xffff);
1564 else displ += addr->off;
1565 db_task_printsym(displ, size);
1566 break;
1568 case Dl:
1569 if (size == WORD) {
1570 get_value_inc(displ, addr, 2, TRUE);
1571 /* offset only affects low 16 bits */
1572 displ = (addr->off & 0xffff0000)
1573 | ((addr->off + displ) & 0xffff);
1575 else {
1576 get_value_inc(displ, addr, 4, TRUE);
1577 displ += addr->off;
1579 if( !db_display )
1581 break;
1583 db_task_printsym( displ, size );
1584 break;
1586 case o1:
1587 if( db_display )
1589 DEBUG_Printf(DBG_CHN_MESG,"$1");
1591 break;
1593 case o3:
1594 if( db_display )
1596 DEBUG_Printf(DBG_CHN_MESG,"$3");
1598 break;
1600 case OS:
1602 DBG_ADDR address;
1603 get_value_inc( address.off, addr, /* offset */
1604 short_addr ? 2 : 4, FALSE );
1605 get_value_inc( address.seg, addr, /* segment */
1606 2, FALSE );
1607 if( db_display )
1609 DEBUG_PrintAddress( &address, short_addr ? 16 : 32,
1610 TRUE );
1614 break;
1619 #else /* __i386__ */
1621 void DEBUG_Disasm( DBG_ADDR *addr, int display )
1625 #endif /* __i386__ */