2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
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 the
24 * rights to redistribute these changes.
28 * Instruction disassembler.
31 /* <Wine specific wrappers> */
36 #define __attribute__(X)
39 static int db_debug = 0;
40 static int db_printf(const char* format, ...) __attribute__((format (printf,1,2)));
41 int db_printf(const char* format, ...)
47 va_start(valist, format);
48 len = dbg_printf(format, valist);
54 typedef DWORD_PTR db_addr_t;
55 typedef BOOL boolean_t;
57 static ULONG64 db_get_value(db_addr_t addr, int size, int is_signed)
62 if (size != 1 && size != 2 && size != 4 && size != 8)
64 db_printf("Illegal size specified\n");
66 else if (dbg_read_memory((void*)addr, buffer, size))
71 if (is_signed) result = (ULONG64)*(LONG64*)buffer;
72 else result = *(ULONG64*)buffer;
75 if (is_signed) result = (ULONG) *(LONG*)buffer;
76 else result = *(ULONG64*)buffer;
79 if (is_signed) result = (unsigned int) *(short int *)buffer;
80 else result = *(unsigned short int *)buffer;
83 if (is_signed) result = (unsigned int) *(char *)buffer;
84 else result = *(unsigned char *)buffer;
92 #define DB_STGY_XTRN 0
94 static void db_printsym(db_addr_t addr, unsigned unused)
100 a.Mode = AddrModeFlat;
103 print_address(&a, FALSE);
107 /* </Wine specific wrappers> */
123 * REX prefix and bits
134 #define E 1 /* general effective address */
135 #define Eind 2 /* indirect address (jump, call) */
136 #define Ew 3 /* address, word size */
137 #define Eb 4 /* address, byte size */
138 #define R 5 /* register, in 'reg' field */
139 #define Rw 6 /* word register, in 'reg' field */
140 #define Ri 7 /* register in instruction */
141 #define S 8 /* segment reg, in 'reg' field */
142 #define Si 9 /* segment reg, in instruction */
143 #define A 10 /* accumulator */
144 #define BX 11 /* (bx) */
145 #define CL 12 /* cl, for shifts */
146 #define DX 13 /* dx, for IO */
147 #define SI 14 /* si */
148 #define DI 15 /* di */
149 #define CR 16 /* control register */
150 #define DR 17 /* debug register */
151 #define TR 18 /* test register */
152 #define I 19 /* immediate, unsigned */
153 #define Is 20 /* immediate, signed */
154 #define Ib 21 /* byte immediate, unsigned */
155 #define Ibs 22 /* byte immediate, signed */
156 #define Iw 23 /* word immediate, unsigned */
157 #define Ilq 24 /* long/quad immediate, unsigned */
158 #define O 25 /* direct address */
159 #define Db 26 /* byte displacement from EIP */
160 #define Dl 27 /* long displacement from EIP */
161 #define o1 28 /* constant 1 */
162 #define o3 29 /* constant 3 */
163 #define OS 30 /* immediate offset/segment */
164 #define ST 31 /* FP stack top */
165 #define STI 32 /* FP stack */
166 #define X 33 /* extended FP op */
167 #define XA 34 /* for 'fstcw %ax' */
168 #define El 35 /* address, long/quad size */
169 #define Ril 36 /* long register in instruction */
170 #define Iba 37 /* byte immediate, don't print if 0xa */
171 #define EL 38 /* address, explicitly long size */
172 /* Wine extensions */
173 #define MX 39 /* special register (MMX reg %mm0-7) */
174 #define EMX 40 /* special register (MMX reg %mm0-7) */
175 #define XMM 41 /* special register (floating point reg %xmm0-7) */
176 #define EXMM 42 /* special register (floating point reg %xmm0-7) */
179 const char * i_name; /* name */
180 short i_has_modrm; /* has regmodrm byte */
181 short i_size; /* operand size */
182 int i_mode; /* addressing modes */
183 const void * i_extra; /* pointer to extra opcode table */
187 #define op2(x,y) ((x)|((y)<<8))
188 #define op3(x,y,z) ((x)|((y)<<8)|((z)<<16))
191 const char * f_name; /* name for memory instruction */
192 int f_size; /* size for memory instruction */
193 int f_rrmode; /* mode for rr instruction */
194 const void * f_rrname; /* name for rr instruction
195 (or pointer to table) */
198 static const char * const db_Grp6[] = {
209 static const char * const db_Grp7[] = {
220 static const char * const db_Grp8[] = {
231 static const char * const db_Grp9[] = {
242 static const char * const db_Grp15[] = {
253 static const char * const db_Grp15b[] = {
264 static const struct inst db_inst_0f0x[] = {
265 /*00*/ { "", TRUE, NONE, op1(Ew), db_Grp6 },
266 /*01*/ { "", TRUE, NONE, op1(Ew), db_Grp7 },
267 /*02*/ { "lar", TRUE, LONG, op2(E,R), 0 },
268 /*03*/ { "lsl", TRUE, LONG, op2(E,R), 0 },
269 /*04*/ { "", FALSE, NONE, 0, 0 },
270 /*05*/ { "syscall",FALSE,NONE, 0, 0 },
271 /*06*/ { "clts", FALSE, NONE, 0, 0 },
272 /*07*/ { "sysret",FALSE, NONE, 0, 0 },
274 /*08*/ { "invd", FALSE, NONE, 0, 0 },
275 /*09*/ { "wbinvd",FALSE, NONE, 0, 0 },
276 /*0a*/ { "", FALSE, NONE, 0, 0 },
277 /*0b*/ { "", FALSE, NONE, 0, 0 },
278 /*0c*/ { "", FALSE, NONE, 0, 0 },
279 /*0d*/ { "", FALSE, NONE, 0, 0 },
280 /*0e*/ { "", FALSE, NONE, 0, 0 },
281 /*0f*/ { "", FALSE, NONE, 0, 0 },
284 static const struct inst db_inst_0f2x[] = {
285 /*20*/ { "mov", TRUE, LONG, op2(CR,El), 0 },
286 /*21*/ { "mov", TRUE, LONG, op2(DR,El), 0 },
287 /*22*/ { "mov", TRUE, LONG, op2(El,CR), 0 },
288 /*23*/ { "mov", TRUE, LONG, op2(El,DR), 0 },
289 /*24*/ { "mov", TRUE, LONG, op2(TR,El), 0 },
290 /*25*/ { "", FALSE, NONE, 0, 0 },
291 /*26*/ { "mov", TRUE, LONG, op2(El,TR), 0 },
292 /*27*/ { "", FALSE, NONE, 0, 0 },
294 /*28*/ { "", FALSE, NONE, 0, 0 },
295 /*29*/ { "", FALSE, NONE, 0, 0 },
296 /*2a*/ { "", FALSE, NONE, 0, 0 },
297 /*2b*/ { "", FALSE, NONE, 0, 0 },
298 /*2c*/ { "", FALSE, NONE, 0, 0 },
299 /*2d*/ { "", FALSE, NONE, 0, 0 },
300 /*2e*/ { "", FALSE, NONE, 0, 0 },
301 /*2f*/ { "", FALSE, NONE, 0, 0 },
304 static const struct inst db_inst_0f3x[] = {
305 /*30*/ { "wrmsr", FALSE, NONE, 0, 0 },
306 /*31*/ { "rdtsc", FALSE, NONE, 0, 0 },
307 /*32*/ { "rdmsr", FALSE, NONE, 0, 0 },
308 /*33*/ { "rdpmc", FALSE, NONE, 0, 0 },
309 /*34*/ { "sysenter",FALSE,NONE, 0, 0 },
310 /*35*/ { "sysexit",FALSE,NONE, 0, 0 },
311 /*36*/ { "", FALSE, NONE, 0, 0 },
312 /*37*/ { "getsec",FALSE, NONE, 0, 0 },
314 /*38*/ { "", FALSE, NONE, 0, 0 },
315 /*39*/ { "", FALSE, NONE, 0, 0 },
316 /*3a*/ { "", FALSE, NONE, 0, 0 },
317 /*3b*/ { "", FALSE, NONE, 0, 0 },
318 /*3c*/ { "", FALSE, NONE, 0, 0 },
319 /*3d*/ { "", FALSE, NONE, 0, 0 },
320 /*3e*/ { "", FALSE, NONE, 0, 0 },
321 /*3f*/ { "", FALSE, NONE, 0, 0 },
324 static const struct inst db_inst_0f4x[] = {
325 /*40*/ { "cmovo", TRUE, NONE, op2(E, R), 0 },
326 /*41*/ { "cmovno", TRUE, NONE, op2(E, R), 0 },
327 /*42*/ { "cmovb", TRUE, NONE, op2(E, R), 0 },
328 /*43*/ { "cmovnb", TRUE, NONE, op2(E, R), 0 },
329 /*44*/ { "cmovz", TRUE, NONE, op2(E, R), 0 },
330 /*45*/ { "cmovnz", TRUE, NONE, op2(E, R), 0 },
331 /*46*/ { "cmovbe", TRUE, NONE, op2(E, R), 0 },
332 /*47*/ { "cmovnbe",TRUE, NONE, op2(E, R), 0 },
334 /*48*/ { "cmovs", TRUE, NONE, op2(E, R), 0 },
335 /*49*/ { "cmovns", TRUE, NONE, op2(E, R), 0 },
336 /*4a*/ { "cmovp", TRUE, NONE, op2(E, R), 0 },
337 /*4b*/ { "cmovnp", TRUE, NONE, op2(E, R), 0 },
338 /*4c*/ { "cmovl", TRUE, NONE, op2(E, R), 0 },
339 /*4d*/ { "cmovnl", TRUE, NONE, op2(E, R), 0 },
340 /*4e*/ { "cmovle", TRUE, NONE, op2(E, R), 0 },
341 /*4f*/ { "cmovnle",TRUE, NONE, op2(E, R), 0 },
344 static const struct inst db_inst_0f5x[] = {
345 /*50*/ { "movmskps",TRUE, NONE, op2(E, XMM), 0 },
346 /*51*/ { "sqrtps", TRUE, NONE, op2(XMM, EXMM), 0 },
347 /*52*/ { "rsqrtps", TRUE, NONE, op2(XMM, EXMM), 0 },
348 /*53*/ { "rcpps", TRUE, NONE, op2(XMM, EXMM), 0 },
349 /*54*/ { "andps", TRUE, NONE, op2(XMM, EXMM), 0 },
350 /*55*/ { "andnps", TRUE, NONE, op2(XMM, EXMM), 0 },
351 /*56*/ { "orps", TRUE, NONE, op2(XMM, EXMM), 0 },
352 /*57*/ { "xorps", TRUE, NONE, op2(XMM, EXMM), 0 },
354 /*58*/ { "addps", TRUE, NONE, op2(XMM, EXMM), 0 },
355 /*59*/ { "mulps", TRUE, NONE, op2(XMM, EXMM), 0 },
356 /*5a*/ { "(bad)", FALSE, NONE, 0, 0 },
357 /*5b*/ { "(bad)", FALSE, NONE, 0, 0 },
358 /*5c*/ { "subps", TRUE, NONE, op2(XMM, EXMM), 0 },
359 /*5d*/ { "minps", TRUE, NONE, op2(XMM, EXMM), 0 },
360 /*5e*/ { "divps", TRUE, NONE, op2(XMM, EXMM), 0 },
361 /*5f*/ { "maxps", TRUE, NONE, op2(XMM, EXMM), 0 },
364 static const struct inst db_inst_0f6x[] = {
365 /*60*/ { "punpcklbw", TRUE, NONE, op2(E, MX), 0 },
366 /*61*/ { "punpcklwd", TRUE, NONE, op2(E, MX), 0 },
367 /*62*/ { "punpckldq", TRUE, NONE, op2(E, MX), 0 },
368 /*63*/ { "packsswb", TRUE, NONE, op2(E, MX), 0 },
369 /*64*/ { "pcmpgtb", TRUE, NONE, op2(E, MX), 0 },
370 /*65*/ { "pcmpgtw", TRUE, NONE, op2(E, MX), 0 },
371 /*66*/ { "pcmpgtd", TRUE, NONE, op2(E, MX), 0 },
372 /*67*/ { "packuswb", TRUE, NONE, op2(E, MX), 0 },
374 /*68*/ { "punpckhbw", TRUE, NONE, op2(E, MX), 0 },
375 /*69*/ { "punpckhwd", TRUE, NONE, op2(E, MX), 0 },
376 /*6a*/ { "punpckhdq", TRUE, NONE, op2(E, MX), 0 },
377 /*6b*/ { "packssdw", TRUE, NONE, op2(E, MX), 0 },
378 /*6c*/ { "(bad)", TRUE, NONE, 0, 0 },
379 /*6d*/ { "(bad)", TRUE, NONE, 0, 0 },
380 /*6e*/ { "movd", TRUE, NONE, op2(E, MX), 0 },
381 /*6f*/ { "movq", TRUE, NONE, op2(E, MX), 0 },
384 static const struct inst db_inst_0f7x[] = {
385 /*70*/ { "pshufw", TRUE, NONE, op2(MX, EMX), 0 },
386 /*71*/ { "(bad)", TRUE, NONE, 0, 0 }, /* FIXME: grp 12 */
387 /*72*/ { "(bad)", TRUE, NONE, 0, 0 }, /* FIXME: grp 13 */
388 /*73*/ { "(bad)", TRUE, NONE, 0, 0 }, /* FIXME: grp 14 */
389 /*74*/ { "pcmpeqb", TRUE, NONE, op2(E, MX), 0 },
390 /*75*/ { "pcmpeqw", TRUE, NONE, op2(E, MX), 0 },
391 /*76*/ { "pcmpeqd", TRUE, NONE, op2(E, MX), 0 },
392 /*77*/ { "emms", FALSE,NONE, 0, 0 },
394 /*78*/ { "(bad)", TRUE, NONE, 0, 0 },
395 /*79*/ { "(bad)", TRUE, NONE, 0, 0 },
396 /*7a*/ { "(bad)", TRUE, NONE, 0, 0 },
397 /*7b*/ { "(bad)", TRUE, NONE, 0, 0 },
398 /*7c*/ { "(bad)", TRUE, NONE, 0, 0 },
399 /*7d*/ { "(bad)", TRUE, NONE, 0, 0 },
400 /*7e*/ { "movd", TRUE, NONE, op2(E, MX), 0 },
401 /*7f*/ { "movq", TRUE, NONE, op2(EMX, MX), 0 },
404 static const struct inst db_inst_0f8x[] = {
405 /*80*/ { "jo", FALSE, NONE, op1(Dl), 0 },
406 /*81*/ { "jno", FALSE, NONE, op1(Dl), 0 },
407 /*82*/ { "jb", FALSE, NONE, op1(Dl), 0 },
408 /*83*/ { "jnb", FALSE, NONE, op1(Dl), 0 },
409 /*84*/ { "jz", FALSE, NONE, op1(Dl), 0 },
410 /*85*/ { "jnz", FALSE, NONE, op1(Dl), 0 },
411 /*86*/ { "jbe", FALSE, NONE, op1(Dl), 0 },
412 /*87*/ { "jnbe", FALSE, NONE, op1(Dl), 0 },
414 /*88*/ { "js", FALSE, NONE, op1(Dl), 0 },
415 /*89*/ { "jns", FALSE, NONE, op1(Dl), 0 },
416 /*8a*/ { "jp", FALSE, NONE, op1(Dl), 0 },
417 /*8b*/ { "jnp", FALSE, NONE, op1(Dl), 0 },
418 /*8c*/ { "jl", FALSE, NONE, op1(Dl), 0 },
419 /*8d*/ { "jnl", FALSE, NONE, op1(Dl), 0 },
420 /*8e*/ { "jle", FALSE, NONE, op1(Dl), 0 },
421 /*8f*/ { "jnle", FALSE, NONE, op1(Dl), 0 },
424 static const struct inst db_inst_0f9x[] = {
425 /*90*/ { "seto", TRUE, NONE, op1(Eb), 0 },
426 /*91*/ { "setno", TRUE, NONE, op1(Eb), 0 },
427 /*92*/ { "setb", TRUE, NONE, op1(Eb), 0 },
428 /*93*/ { "setnb", TRUE, NONE, op1(Eb), 0 },
429 /*94*/ { "setz", TRUE, NONE, op1(Eb), 0 },
430 /*95*/ { "setnz", TRUE, NONE, op1(Eb), 0 },
431 /*96*/ { "setbe", TRUE, NONE, op1(Eb), 0 },
432 /*97*/ { "setnbe",TRUE, NONE, op1(Eb), 0 },
434 /*98*/ { "sets", TRUE, NONE, op1(Eb), 0 },
435 /*99*/ { "setns", TRUE, NONE, op1(Eb), 0 },
436 /*9a*/ { "setp", TRUE, NONE, op1(Eb), 0 },
437 /*9b*/ { "setnp", TRUE, NONE, op1(Eb), 0 },
438 /*9c*/ { "setl", TRUE, NONE, op1(Eb), 0 },
439 /*9d*/ { "setnl", TRUE, NONE, op1(Eb), 0 },
440 /*9e*/ { "setle", TRUE, NONE, op1(Eb), 0 },
441 /*9f*/ { "setnle",TRUE, NONE, op1(Eb), 0 },
444 static const struct inst db_inst_0fax[] = {
445 /*a0*/ { "push", FALSE, NONE, op1(Si), 0 },
446 /*a1*/ { "pop", FALSE, NONE, op1(Si), 0 },
447 /*a2*/ { "cpuid", FALSE, NONE, 0, 0 },
448 /*a3*/ { "bt", TRUE, LONG, op2(R,E), 0 },
449 /*a4*/ { "shld", TRUE, LONG, op3(Ib,R,E), 0 },
450 /*a5*/ { "shld", TRUE, LONG, op3(CL,R,E), 0 },
451 /*a6*/ { "", FALSE, NONE, 0, 0 },
452 /*a7*/ { "", FALSE, NONE, 0, 0 },
454 /*a8*/ { "push", FALSE, NONE, op1(Si), 0 },
455 /*a9*/ { "pop", FALSE, NONE, op1(Si), 0 },
456 /*aa*/ { "rsm", FALSE, NONE, 0, 0 },
457 /*ab*/ { "bts", TRUE, LONG, op2(R,E), 0 },
458 /*ac*/ { "shrd", TRUE, LONG, op3(Ib,R,E), 0 },
459 /*ad*/ { "shrd", TRUE, LONG, op3(CL,R,E), 0 },
460 /*ae*/ { "", TRUE, LONG, op1(E), db_Grp15 },
461 /*af*/ { "imul", TRUE, LONG, op2(E,R), 0 },
464 static const struct inst db_inst_0fbx[] = {
465 /*b0*/ { "cmpxchg",TRUE, BYTE, op2(R, E), 0 },
466 /*b0*/ { "cmpxchg",TRUE, LONG, op2(R, E), 0 },
467 /*b2*/ { "lss", TRUE, LONG, op2(E, R), 0 },
468 /*b3*/ { "btr", TRUE, LONG, op2(R, E), 0 },
469 /*b4*/ { "lfs", TRUE, LONG, op2(E, R), 0 },
470 /*b5*/ { "lgs", TRUE, LONG, op2(E, R), 0 },
471 /*b6*/ { "movzb", TRUE, LONG, op2(Eb, R), 0 },
472 /*b7*/ { "movzw", TRUE, LONG, op2(Ew, R), 0 },
474 /*b8*/ { "", FALSE, NONE, 0, 0 },
475 /*b9*/ { "", FALSE, NONE, 0, 0 },
476 /*ba*/ { "", TRUE, LONG, op2(Ib, E), db_Grp8 },
477 /*bb*/ { "btc", TRUE, LONG, op2(R, E), 0 },
478 /*bc*/ { "bsf", TRUE, LONG, op2(E, R), 0 },
479 /*bd*/ { "bsr", TRUE, LONG, op2(E, R), 0 },
480 /*be*/ { "movsb", TRUE, LONG, op2(Eb, R), 0 },
481 /*bf*/ { "movsw", TRUE, LONG, op2(Ew, R), 0 },
484 static const struct inst db_inst_0fcx[] = {
485 /*c0*/ { "xadd", TRUE, BYTE, op2(R, E), 0 },
486 /*c1*/ { "xadd", TRUE, LONG, op2(R, E), 0 },
487 /*c2*/ { "", FALSE, NONE, 0, 0 },
488 /*c3*/ { "", FALSE, NONE, 0, 0 },
489 /*c4*/ { "", FALSE, NONE, 0, 0 },
490 /*c5*/ { "", FALSE, NONE, 0, 0 },
491 /*c6*/ { "", FALSE, NONE, 0, 0 },
492 /*c7*/ { "", TRUE, NONE, op1(E), db_Grp9 },
493 /*c8*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
494 /*c9*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
495 /*ca*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
496 /*cb*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
497 /*cc*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
498 /*cd*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
499 /*ce*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
500 /*cf*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
503 static const struct inst * const db_inst_0f[] = {
522 static const char * const db_Esc92[] = {
523 "fnop", "", "", "", "", "", "", ""
525 static const char * const db_Esc94[] = {
526 "fchs", "fabs", "", "", "ftst", "fxam", "", ""
528 static const char * const db_Esc95[] = {
529 "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
531 static const char * const db_Esc96[] = {
532 "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
535 static const char * const db_Esc97[] = {
536 "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
539 static const char * const db_Esca5[] = {
540 "", "fucompp","", "", "", "", "", ""
543 static const char * const db_Escb4[] = {
544 "fneni","fndisi", "fnclex","fninit","fsetpm", "", "", ""
547 static const char * const db_Esce3[] = {
548 "", "fcompp","", "", "", "", "", ""
551 static const char * const db_Escf4[] = {
552 "fnstsw","", "", "", "", "", "", ""
555 static const struct finst db_Esc8[] = {
556 /*0*/ { "fadd", SNGL, op2(STI,ST), 0 },
557 /*1*/ { "fmul", SNGL, op2(STI,ST), 0 },
558 /*2*/ { "fcom", SNGL, op2(STI,ST), 0 },
559 /*3*/ { "fcomp", SNGL, op2(STI,ST), 0 },
560 /*4*/ { "fsub", SNGL, op2(STI,ST), 0 },
561 /*5*/ { "fsubr", SNGL, op2(STI,ST), 0 },
562 /*6*/ { "fdiv", SNGL, op2(STI,ST), 0 },
563 /*7*/ { "fdivr", SNGL, op2(STI,ST), 0 },
566 static const struct finst db_Esc9[] = {
567 /*0*/ { "fld", SNGL, op1(STI), 0 },
568 /*1*/ { "", NONE, op1(STI), "fxch" },
569 /*2*/ { "fst", SNGL, op1(X), db_Esc92 },
570 /*3*/ { "fstp", SNGL, 0, 0 },
571 /*4*/ { "fldenv", NONE, op1(X), db_Esc94 },
572 /*5*/ { "fldcw", NONE, op1(X), db_Esc95 },
573 /*6*/ { "fnstenv",NONE, op1(X), db_Esc96 },
574 /*7*/ { "fnstcw", NONE, op1(X), db_Esc97 },
577 static const struct finst db_Esca[] = {
578 /*0*/ { "fiadd", LONG, 0, 0 },
579 /*1*/ { "fimul", LONG, 0, 0 },
580 /*2*/ { "ficom", LONG, 0, 0 },
581 /*3*/ { "ficomp", LONG, 0, 0 },
582 /*4*/ { "fisub", LONG, 0, 0 },
583 /*5*/ { "fisubr", LONG, op1(X), db_Esca5 },
584 /*6*/ { "fidiv", LONG, 0, 0 },
585 /*7*/ { "fidivr", LONG, 0, 0 }
588 static const struct finst db_Escb[] = {
589 /*0*/ { "fild", LONG, 0, 0 },
590 /*1*/ { "", NONE, 0, 0 },
591 /*2*/ { "fist", LONG, 0, 0 },
592 /*3*/ { "fistp", LONG, 0, 0 },
593 /*4*/ { "", WORD, op1(X), db_Escb4 },
594 /*5*/ { "fld", EXTR, 0, 0 },
595 /*6*/ { "", WORD, 0, 0 },
596 /*7*/ { "fstp", EXTR, 0, 0 },
599 static const struct finst db_Escc[] = {
600 /*0*/ { "fadd", DBLR, op2(ST,STI), 0 },
601 /*1*/ { "fmul", DBLR, op2(ST,STI), 0 },
602 /*2*/ { "fcom", DBLR, 0, 0 },
603 /*3*/ { "fcomp", DBLR, 0, 0 },
604 /*4*/ { "fsub", DBLR, op2(ST,STI), "fsubr" },
605 /*5*/ { "fsubr", DBLR, op2(ST,STI), "fsub" },
606 /*6*/ { "fdiv", DBLR, op2(ST,STI), "fdivr" },
607 /*7*/ { "fdivr", DBLR, op2(ST,STI), "fdiv" },
610 static const struct finst db_Escd[] = {
611 /*0*/ { "fld", DBLR, op1(STI), "ffree" },
612 /*1*/ { "", NONE, 0, 0 },
613 /*2*/ { "fst", DBLR, op1(STI), 0 },
614 /*3*/ { "fstp", DBLR, op1(STI), 0 },
615 /*4*/ { "frstor", NONE, op1(STI), "fucom" },
616 /*5*/ { "", NONE, op1(STI), "fucomp" },
617 /*6*/ { "fnsave", NONE, 0, 0 },
618 /*7*/ { "fnstsw", NONE, 0, 0 },
621 static const struct finst db_Esce[] = {
622 /*0*/ { "fiadd", WORD, op2(ST,STI), "faddp" },
623 /*1*/ { "fimul", WORD, op2(ST,STI), "fmulp" },
624 /*2*/ { "ficom", WORD, 0, 0 },
625 /*3*/ { "ficomp", WORD, op1(X), db_Esce3 },
626 /*4*/ { "fisub", WORD, op2(ST,STI), "fsubrp" },
627 /*5*/ { "fisubr", WORD, op2(ST,STI), "fsubp" },
628 /*6*/ { "fidiv", WORD, op2(ST,STI), "fdivrp" },
629 /*7*/ { "fidivr", WORD, op2(ST,STI), "fdivp" },
632 static const struct finst db_Escf[] = {
633 /*0*/ { "fild", WORD, 0, 0 },
634 /*1*/ { "", NONE, 0, 0 },
635 /*2*/ { "fist", WORD, 0, 0 },
636 /*3*/ { "fistp", WORD, 0, 0 },
637 /*4*/ { "fbld", NONE, op1(XA), db_Escf4 },
638 /*5*/ { "fild", QUAD, 0, 0 },
639 /*6*/ { "fbstp", NONE, 0, 0 },
640 /*7*/ { "fistp", QUAD, 0, 0 },
643 static const struct finst * const db_Esc_inst[] = {
644 db_Esc8, db_Esc9, db_Esca, db_Escb,
645 db_Escc, db_Escd, db_Esce, db_Escf
648 static const char * const db_Grp1[] = {
659 static const char * const db_Grp2[] = {
670 static const struct inst db_Grp3[] = {
671 { "test", TRUE, NONE, op2(I,E), 0 },
672 { "test", TRUE, NONE, op2(I,E), 0 },
673 { "not", TRUE, NONE, op1(E), 0 },
674 { "neg", TRUE, NONE, op1(E), 0 },
675 { "mul", TRUE, NONE, op2(E,A), 0 },
676 { "imul", TRUE, NONE, op2(E,A), 0 },
677 { "div", TRUE, NONE, op2(E,A), 0 },
678 { "idiv", TRUE, NONE, op2(E,A), 0 },
681 static const struct inst db_Grp4[] = {
682 { "inc", TRUE, BYTE, op1(E), 0 },
683 { "dec", TRUE, BYTE, op1(E), 0 },
684 { "", TRUE, NONE, 0, 0 },
685 { "", TRUE, NONE, 0, 0 },
686 { "", TRUE, NONE, 0, 0 },
687 { "", TRUE, NONE, 0, 0 },
688 { "", TRUE, NONE, 0, 0 },
689 { "", TRUE, NONE, 0, 0 }
692 static const struct inst db_Grp5[] = {
693 { "inc", TRUE, LONG, op1(E), 0 },
694 { "dec", TRUE, LONG, op1(E), 0 },
695 { "call", TRUE, LONG, op1(Eind),0 },
696 { "lcall", TRUE, LONG, op1(Eind),0 },
697 { "jmp", TRUE, LONG, op1(Eind),0 },
698 { "ljmp", TRUE, LONG, op1(Eind),0 },
699 { "push", TRUE, LONG, op1(E), 0 },
700 { "", TRUE, NONE, 0, 0 }
703 static const struct inst db_inst_table[256] = {
704 /*00*/ { "add", TRUE, BYTE, op2(R, E), 0 },
705 /*01*/ { "add", TRUE, LONG, op2(R, E), 0 },
706 /*02*/ { "add", TRUE, BYTE, op2(E, R), 0 },
707 /*03*/ { "add", TRUE, LONG, op2(E, R), 0 },
708 /*04*/ { "add", FALSE, BYTE, op2(I, A), 0 },
709 /*05*/ { "add", FALSE, LONG, op2(Is, A), 0 },
710 /*06*/ { "push", FALSE, NONE, op1(Si), 0 },
711 /*07*/ { "pop", FALSE, NONE, op1(Si), 0 },
713 /*08*/ { "or", TRUE, BYTE, op2(R, E), 0 },
714 /*09*/ { "or", TRUE, LONG, op2(R, E), 0 },
715 /*0a*/ { "or", TRUE, BYTE, op2(E, R), 0 },
716 /*0b*/ { "or", TRUE, LONG, op2(E, R), 0 },
717 /*0c*/ { "or", FALSE, BYTE, op2(I, A), 0 },
718 /*0d*/ { "or", FALSE, LONG, op2(I, A), 0 },
719 /*0e*/ { "push", FALSE, NONE, op1(Si), 0 },
720 /*0f*/ { "", FALSE, NONE, 0, 0 },
722 /*10*/ { "adc", TRUE, BYTE, op2(R, E), 0 },
723 /*11*/ { "adc", TRUE, LONG, op2(R, E), 0 },
724 /*12*/ { "adc", TRUE, BYTE, op2(E, R), 0 },
725 /*13*/ { "adc", TRUE, LONG, op2(E, R), 0 },
726 /*14*/ { "adc", FALSE, BYTE, op2(I, A), 0 },
727 /*15*/ { "adc", FALSE, LONG, op2(Is, A), 0 },
728 /*16*/ { "push", FALSE, NONE, op1(Si), 0 },
729 /*17*/ { "pop", FALSE, NONE, op1(Si), 0 },
731 /*18*/ { "sbb", TRUE, BYTE, op2(R, E), 0 },
732 /*19*/ { "sbb", TRUE, LONG, op2(R, E), 0 },
733 /*1a*/ { "sbb", TRUE, BYTE, op2(E, R), 0 },
734 /*1b*/ { "sbb", TRUE, LONG, op2(E, R), 0 },
735 /*1c*/ { "sbb", FALSE, BYTE, op2(I, A), 0 },
736 /*1d*/ { "sbb", FALSE, LONG, op2(Is, A), 0 },
737 /*1e*/ { "push", FALSE, NONE, op1(Si), 0 },
738 /*1f*/ { "pop", FALSE, NONE, op1(Si), 0 },
740 /*20*/ { "and", TRUE, BYTE, op2(R, E), 0 },
741 /*21*/ { "and", TRUE, LONG, op2(R, E), 0 },
742 /*22*/ { "and", TRUE, BYTE, op2(E, R), 0 },
743 /*23*/ { "and", TRUE, LONG, op2(E, R), 0 },
744 /*24*/ { "and", FALSE, BYTE, op2(I, A), 0 },
745 /*25*/ { "and", FALSE, LONG, op2(I, A), 0 },
746 /*26*/ { "", FALSE, NONE, 0, 0 },
747 /*27*/ { "daa", FALSE, NONE, 0, 0 },
749 /*28*/ { "sub", TRUE, BYTE, op2(R, E), 0 },
750 /*29*/ { "sub", TRUE, LONG, op2(R, E), 0 },
751 /*2a*/ { "sub", TRUE, BYTE, op2(E, R), 0 },
752 /*2b*/ { "sub", TRUE, LONG, op2(E, R), 0 },
753 /*2c*/ { "sub", FALSE, BYTE, op2(I, A), 0 },
754 /*2d*/ { "sub", FALSE, LONG, op2(Is, A), 0 },
755 /*2e*/ { "", FALSE, NONE, 0, 0 },
756 /*2f*/ { "das", FALSE, NONE, 0, 0 },
758 /*30*/ { "xor", TRUE, BYTE, op2(R, E), 0 },
759 /*31*/ { "xor", TRUE, LONG, op2(R, E), 0 },
760 /*32*/ { "xor", TRUE, BYTE, op2(E, R), 0 },
761 /*33*/ { "xor", TRUE, LONG, op2(E, R), 0 },
762 /*34*/ { "xor", FALSE, BYTE, op2(I, A), 0 },
763 /*35*/ { "xor", FALSE, LONG, op2(I, A), 0 },
764 /*36*/ { "", FALSE, NONE, 0, 0 },
765 /*37*/ { "aaa", FALSE, NONE, 0, 0 },
767 /*38*/ { "cmp", TRUE, BYTE, op2(R, E), 0 },
768 /*39*/ { "cmp", TRUE, LONG, op2(R, E), 0 },
769 /*3a*/ { "cmp", TRUE, BYTE, op2(E, R), 0 },
770 /*3b*/ { "cmp", TRUE, LONG, op2(E, R), 0 },
771 /*3c*/ { "cmp", FALSE, BYTE, op2(I, A), 0 },
772 /*3d*/ { "cmp", FALSE, LONG, op2(Is, A), 0 },
773 /*3e*/ { "", FALSE, NONE, 0, 0 },
774 /*3f*/ { "aas", FALSE, NONE, 0, 0 },
776 /*40*/ { "rex", FALSE, NONE, 0, 0 },
777 /*41*/ { "rex.b", FALSE, NONE, 0, 0 },
778 /*42*/ { "rex.x", FALSE, NONE, 0, 0 },
779 /*43*/ { "rex.xb", FALSE, NONE, 0, 0 },
780 /*44*/ { "rex.r", FALSE, NONE, 0, 0 },
781 /*45*/ { "rex.rb", FALSE, NONE, 0, 0 },
782 /*46*/ { "rex.rx", FALSE, NONE, 0, 0 },
783 /*47*/ { "rex.rxb", FALSE, NONE, 0, 0 },
785 /*48*/ { "rex.w", FALSE, NONE, 0, 0 },
786 /*49*/ { "rex.wb", FALSE, NONE, 0, 0 },
787 /*4a*/ { "rex.wx", FALSE, NONE, 0, 0 },
788 /*4b*/ { "rex.wxb", FALSE, NONE, 0, 0 },
789 /*4c*/ { "rex.wr", FALSE, NONE, 0, 0 },
790 /*4d*/ { "rex.wrb", FALSE, NONE, 0, 0 },
791 /*4e*/ { "rex.wrx", FALSE, NONE, 0, 0 },
792 /*4f*/ { "rex.wrxb", FALSE, NONE, 0, 0 },
794 /*50*/ { "push", FALSE, LONG, op1(Ri), 0 },
795 /*51*/ { "push", FALSE, LONG, op1(Ri), 0 },
796 /*52*/ { "push", FALSE, LONG, op1(Ri), 0 },
797 /*53*/ { "push", FALSE, LONG, op1(Ri), 0 },
798 /*54*/ { "push", FALSE, LONG, op1(Ri), 0 },
799 /*55*/ { "push", FALSE, LONG, op1(Ri), 0 },
800 /*56*/ { "push", FALSE, LONG, op1(Ri), 0 },
801 /*57*/ { "push", FALSE, LONG, op1(Ri), 0 },
803 /*58*/ { "pop", FALSE, LONG, op1(Ri), 0 },
804 /*59*/ { "pop", FALSE, LONG, op1(Ri), 0 },
805 /*5a*/ { "pop", FALSE, LONG, op1(Ri), 0 },
806 /*5b*/ { "pop", FALSE, LONG, op1(Ri), 0 },
807 /*5c*/ { "pop", FALSE, LONG, op1(Ri), 0 },
808 /*5d*/ { "pop", FALSE, LONG, op1(Ri), 0 },
809 /*5e*/ { "pop", FALSE, LONG, op1(Ri), 0 },
810 /*5f*/ { "pop", FALSE, LONG, op1(Ri), 0 },
812 /*60*/ { "pusha", FALSE, LONG, 0, 0 },
813 /*61*/ { "popa", FALSE, LONG, 0, 0 },
814 /*62*/ { "bound", TRUE, LONG, op2(E, R), 0 },
815 /*63*/ { "movslq", TRUE, NONE, op2(EL,R), 0 },
817 /*64*/ { "", FALSE, NONE, 0, 0 },
818 /*65*/ { "", FALSE, NONE, 0, 0 },
819 /*66*/ { "", FALSE, NONE, 0, 0 },
820 /*67*/ { "", FALSE, NONE, 0, 0 },
822 /*68*/ { "push", FALSE, LONG, op1(I), 0 },
823 /*69*/ { "imul", TRUE, LONG, op3(I,E,R), 0 },
824 /*6a*/ { "push", FALSE, LONG, op1(Ibs), 0 },
825 /*6b*/ { "imul", TRUE, LONG, op3(Ibs,E,R),0 },
826 /*6c*/ { "ins", FALSE, BYTE, op2(DX, DI), 0 },
827 /*6d*/ { "ins", FALSE, LONG, op2(DX, DI), 0 },
828 /*6e*/ { "outs", FALSE, BYTE, op2(SI, DX), 0 },
829 /*6f*/ { "outs", FALSE, LONG, op2(SI, DX), 0 },
831 /*70*/ { "jo", FALSE, NONE, op1(Db), 0 },
832 /*71*/ { "jno", FALSE, NONE, op1(Db), 0 },
833 /*72*/ { "jb", FALSE, NONE, op1(Db), 0 },
834 /*73*/ { "jnb", FALSE, NONE, op1(Db), 0 },
835 /*74*/ { "jz", FALSE, NONE, op1(Db), 0 },
836 /*75*/ { "jnz", FALSE, NONE, op1(Db), 0 },
837 /*76*/ { "jbe", FALSE, NONE, op1(Db), 0 },
838 /*77*/ { "jnbe", FALSE, NONE, op1(Db), 0 },
840 /*78*/ { "js", FALSE, NONE, op1(Db), 0 },
841 /*79*/ { "jns", FALSE, NONE, op1(Db), 0 },
842 /*7a*/ { "jp", FALSE, NONE, op1(Db), 0 },
843 /*7b*/ { "jnp", FALSE, NONE, op1(Db), 0 },
844 /*7c*/ { "jl", FALSE, NONE, op1(Db), 0 },
845 /*7d*/ { "jnl", FALSE, NONE, op1(Db), 0 },
846 /*7e*/ { "jle", FALSE, NONE, op1(Db), 0 },
847 /*7f*/ { "jnle", FALSE, NONE, op1(Db), 0 },
849 /*80*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 },
850 /*81*/ { "", TRUE, LONG, op2(I, E), db_Grp1 },
851 /*82*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 },
852 /*83*/ { "", TRUE, LONG, op2(Ibs,E), db_Grp1 },
853 /*84*/ { "test", TRUE, BYTE, op2(R, E), 0 },
854 /*85*/ { "test", TRUE, LONG, op2(R, E), 0 },
855 /*86*/ { "xchg", TRUE, BYTE, op2(R, E), 0 },
856 /*87*/ { "xchg", TRUE, LONG, op2(R, E), 0 },
858 /*88*/ { "mov", TRUE, BYTE, op2(R, E), 0 },
859 /*89*/ { "mov", TRUE, LONG, op2(R, E), 0 },
860 /*8a*/ { "mov", TRUE, BYTE, op2(E, R), 0 },
861 /*8b*/ { "mov", TRUE, LONG, op2(E, R), 0 },
862 /*8c*/ { "mov", TRUE, NONE, op2(S, Ew), 0 },
863 /*8d*/ { "lea", TRUE, LONG, op2(E, R), 0 },
864 /*8e*/ { "mov", TRUE, NONE, op2(Ew, S), 0 },
865 /*8f*/ { "pop", TRUE, LONG, op1(E), 0 },
867 /*90*/ { "nop", FALSE, NONE, 0, 0 },
868 /*91*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
869 /*92*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
870 /*93*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
871 /*94*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
872 /*95*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
873 /*96*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
874 /*97*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
876 /*98*/ { "cbw", FALSE, SDEP, 0, "cwde" }, /* cbw/cwde */
877 /*99*/ { "cwd", FALSE, SDEP, 0, "cdq" }, /* cwd/cdq */
878 /*9a*/ { "lcall", FALSE, NONE, op1(OS), 0 },
879 /*9b*/ { "wait", FALSE, NONE, 0, 0 },
880 /*9c*/ { "pushf", FALSE, LONG, 0, 0 },
881 /*9d*/ { "popf", FALSE, LONG, 0, 0 },
882 /*9e*/ { "sahf", FALSE, NONE, 0, 0 },
883 /*9f*/ { "lahf", FALSE, NONE, 0, 0 },
885 /*a0*/ { "mov", FALSE, BYTE, op2(O, A), 0 },
886 /*a1*/ { "mov", FALSE, LONG, op2(O, A), 0 },
887 /*a2*/ { "mov", FALSE, BYTE, op2(A, O), 0 },
888 /*a3*/ { "mov", FALSE, LONG, op2(A, O), 0 },
889 /*a4*/ { "movs", FALSE, BYTE, op2(SI,DI), 0 },
890 /*a5*/ { "movs", FALSE, LONG, op2(SI,DI), 0 },
891 /*a6*/ { "cmps", FALSE, BYTE, op2(SI,DI), 0 },
892 /*a7*/ { "cmps", FALSE, LONG, op2(SI,DI), 0 },
894 /*a8*/ { "test", FALSE, BYTE, op2(I, A), 0 },
895 /*a9*/ { "test", FALSE, LONG, op2(I, A), 0 },
896 /*aa*/ { "stos", FALSE, BYTE, op1(DI), 0 },
897 /*ab*/ { "stos", FALSE, LONG, op1(DI), 0 },
898 /*ac*/ { "lods", FALSE, BYTE, op1(SI), 0 },
899 /*ad*/ { "lods", FALSE, LONG, op1(SI), 0 },
900 /*ae*/ { "scas", FALSE, BYTE, op1(SI), 0 },
901 /*af*/ { "scas", FALSE, LONG, op1(SI), 0 },
903 /*b0*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
904 /*b1*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
905 /*b2*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
906 /*b3*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
907 /*b4*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
908 /*b5*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
909 /*b6*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
910 /*b7*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
912 /*b8*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
913 /*b9*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
914 /*ba*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
915 /*bb*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
916 /*bc*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
917 /*bd*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
918 /*be*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
919 /*bf*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
921 /*c0*/ { "", TRUE, BYTE, op2(Ib, E), db_Grp2 },
922 /*c1*/ { "", TRUE, LONG, op2(Ib, E), db_Grp2 },
923 /*c2*/ { "ret", FALSE, NONE, op1(Iw), 0 },
924 /*c3*/ { "ret", FALSE, NONE, 0, 0 },
925 /*c4*/ { "les", TRUE, LONG, op2(E, R), 0 },
926 /*c5*/ { "lds", TRUE, LONG, op2(E, R), 0 },
927 /*c6*/ { "mov", TRUE, BYTE, op2(I, E), 0 },
928 /*c7*/ { "mov", TRUE, LONG, op2(I, E), 0 },
930 /*c8*/ { "enter", FALSE, NONE, op2(Iw, Ib), 0 },
931 /*c9*/ { "leave", FALSE, NONE, 0, 0 },
932 /*ca*/ { "lret", FALSE, NONE, op1(Iw), 0 },
933 /*cb*/ { "lret", FALSE, NONE, 0, 0 },
934 /*cc*/ { "int", FALSE, NONE, op1(o3), 0 },
935 /*cd*/ { "int", FALSE, NONE, op1(Ib), 0 },
936 /*ce*/ { "into", FALSE, NONE, 0, 0 },
937 /*cf*/ { "iret", FALSE, NONE, 0, 0 },
939 /*d0*/ { "", TRUE, BYTE, op2(o1, E), db_Grp2 },
940 /*d1*/ { "", TRUE, LONG, op2(o1, E), db_Grp2 },
941 /*d2*/ { "", TRUE, BYTE, op2(CL, E), db_Grp2 },
942 /*d3*/ { "", TRUE, LONG, op2(CL, E), db_Grp2 },
943 /*d4*/ { "aam", FALSE, NONE, op1(Iba), 0 },
944 /*d5*/ { "aad", FALSE, NONE, op1(Iba), 0 },
945 /*d6*/ { ".byte\t0xd6", FALSE, NONE, 0, 0 },
946 /*d7*/ { "xlat", FALSE, BYTE, op1(BX), 0 },
948 /*d8*/ { "", TRUE, NONE, 0, db_Esc8 },
949 /*d9*/ { "", TRUE, NONE, 0, db_Esc9 },
950 /*da*/ { "", TRUE, NONE, 0, db_Esca },
951 /*db*/ { "", TRUE, NONE, 0, db_Escb },
952 /*dc*/ { "", TRUE, NONE, 0, db_Escc },
953 /*dd*/ { "", TRUE, NONE, 0, db_Escd },
954 /*de*/ { "", TRUE, NONE, 0, db_Esce },
955 /*df*/ { "", TRUE, NONE, 0, db_Escf },
957 /*e0*/ { "loopne",FALSE, NONE, op1(Db), 0 },
958 /*e1*/ { "loope", FALSE, NONE, op1(Db), 0 },
959 /*e2*/ { "loop", FALSE, NONE, op1(Db), 0 },
960 /*e3*/ { "jcxz", FALSE, SDEP, op1(Db), "jecxz" },
961 /*e4*/ { "in", FALSE, BYTE, op2(Ib, A), 0 },
962 /*e5*/ { "in", FALSE, LONG, op2(Ib, A) , 0 },
963 /*e6*/ { "out", FALSE, BYTE, op2(A, Ib), 0 },
964 /*e7*/ { "out", FALSE, LONG, op2(A, Ib) , 0 },
966 /*e8*/ { "call", FALSE, NONE, op1(Dl), 0 },
967 /*e9*/ { "jmp", FALSE, NONE, op1(Dl), 0 },
968 /*ea*/ { "ljmp", FALSE, NONE, op1(OS), 0 },
969 /*eb*/ { "jmp", FALSE, NONE, op1(Db), 0 },
970 /*ec*/ { "in", FALSE, BYTE, op2(DX, A), 0 },
971 /*ed*/ { "in", FALSE, LONG, op2(DX, A) , 0 },
972 /*ee*/ { "out", FALSE, BYTE, op2(A, DX), 0 },
973 /*ef*/ { "out", FALSE, LONG, op2(A, DX) , 0 },
975 /*f0*/ { "", FALSE, NONE, 0, 0 },
976 /*f1*/ { ".byte\t0xf1", FALSE, NONE, 0, 0 },
977 /*f2*/ { "", FALSE, NONE, 0, 0 },
978 /*f3*/ { "", FALSE, NONE, 0, 0 },
979 /*f4*/ { "hlt", FALSE, NONE, 0, 0 },
980 /*f5*/ { "cmc", FALSE, NONE, 0, 0 },
981 /*f6*/ { "", TRUE, BYTE, 0, db_Grp3 },
982 /*f7*/ { "", TRUE, LONG, 0, db_Grp3 },
984 /*f8*/ { "clc", FALSE, NONE, 0, 0 },
985 /*f9*/ { "stc", FALSE, NONE, 0, 0 },
986 /*fa*/ { "cli", FALSE, NONE, 0, 0 },
987 /*fb*/ { "sti", FALSE, NONE, 0, 0 },
988 /*fc*/ { "cld", FALSE, NONE, 0, 0 },
989 /*fd*/ { "std", FALSE, NONE, 0, 0 },
990 /*fe*/ { "", TRUE, NONE, 0, db_Grp4 },
991 /*ff*/ { "", TRUE, NONE, 0, db_Grp5 },
994 static const struct inst db_bad_inst =
995 { "???", FALSE, NONE, 0, 0 }
998 #define f_mod(rex, byte) ((byte)>>6)
999 #define f_reg(rex, byte) ((((byte)>>3)&0x7) | (rex & REX_R ? 0x8 : 0x0))
1000 #define f_rm(rex, byte) (((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0))
1002 #define sib_ss(rex, byte) ((byte)>>6)
1003 #define sib_index(rex, byte) ((((byte)>>3)&0x7) | (rex & REX_X ? 0x8 : 0x0))
1004 #define sib_base(rex, byte) (((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0))
1007 int is_reg; /* if reg, reg number is in 'disp' */
1014 static const char * const db_reg[2][4][16] = {
1016 {{"%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh",
1017 "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" },
1018 { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di",
1019 "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" },
1020 { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
1021 "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" },
1022 { "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
1023 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }},
1025 {{"%al", "%cl", "%dl", "%bl", "%spl", "%bpl", "%sil", "%dil",
1026 "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" },
1027 { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di",
1028 "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" },
1029 { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
1030 "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" },
1031 { "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
1032 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }}
1035 static const char * const db_seg_reg[8] = {
1036 "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
1040 * lengths for size attributes
1042 static const int db_lengths[] = {
1052 #define get_value_inc(result, loc, size, is_signed) \
1053 result = db_get_value((loc), (size), (is_signed)); \
1057 db_disasm_esc(db_addr_t loc, int inst, int rex, int short_addr,
1058 int size, const char *seg);
1059 static void db_print_address(const char *seg, int size, int rex,
1060 struct i_addr *addrp);
1062 db_read_address(db_addr_t loc, int short_addr, int rex, int regmodrm,
1063 struct i_addr *addrp);
1066 * Read address at location and return updated location.
1069 db_read_address(loc, short_addr, rex, regmodrm, addrp)
1074 struct i_addr * addrp; /* out */
1076 int mod, rm, sib, index, disp, size, have_sib;
1078 mod = f_mod(rex, regmodrm);
1079 rm = f_rm(rex, regmodrm);
1082 addrp->is_reg = TRUE;
1086 addrp->is_reg = FALSE;
1094 if ((rm & 0x7) == 4) {
1095 get_value_inc(sib, loc, 1, FALSE);
1096 rm = sib_base(rex, sib);
1097 index = sib_index(rex, sib);
1099 addrp->index = db_reg[1][size][index];
1100 addrp->ss = sib_ss(rex, sib);
1108 get_value_inc(addrp->disp, loc, 4, FALSE);
1111 else if (short_addr)
1112 addrp->base = "%eip";
1114 addrp->base = "%rip";
1117 addrp->base = db_reg[1][size][rm];
1122 get_value_inc(disp, loc, 1, TRUE);
1124 addrp->base = db_reg[1][size][rm];
1128 get_value_inc(disp, loc, 4, FALSE);
1130 addrp->base = db_reg[1][size][rm];
1137 db_print_address(seg, size, rex, addrp)
1141 struct i_addr * addrp;
1143 if (addrp->is_reg) {
1144 db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][addrp->disp]);
1149 db_printf("%s:", seg);
1152 if (addrp->disp != 0 || (addrp->base == 0 && addrp->index == 0))
1153 db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY);
1154 if (addrp->base != 0 || addrp->index != 0) {
1157 db_printf("%s", addrp->base);
1159 db_printf(",%s,%d", addrp->index, 1<<addrp->ss);
1165 * Disassemble floating-point ("escape") instruction
1166 * and return updated location.
1169 db_disasm_esc(loc, inst, rex, short_addr, size, seg)
1178 const struct finst * fp;
1180 struct i_addr address;
1183 get_value_inc(regmodrm, loc, 1, FALSE);
1184 fp = &db_Esc_inst[inst - 0xd8][f_reg(rex, regmodrm)];
1185 mod = f_mod(rex, regmodrm);
1187 if (*fp->f_name == '\0') {
1188 db_printf("<bad instruction>");
1192 * Normal address modes.
1194 loc = db_read_address(loc, short_addr, rex, regmodrm, &address);
1195 db_printf("%s", fp->f_name);
1196 switch(fp->f_size) {
1219 db_print_address(seg, BYTE, rex, &address);
1223 * 'reg-reg' - special formats
1225 switch (fp->f_rrmode) {
1227 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1228 db_printf("%s\t%%st,%%st(%d)",name,f_rm(rex, regmodrm));
1231 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1232 db_printf("%s\t%%st(%d),%%st",name, f_rm(rex, regmodrm));
1235 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1236 db_printf("%s\t%%st(%d)",name, f_rm(rex, regmodrm));
1239 name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)];
1242 db_printf("%s", name);
1245 name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)];
1248 db_printf("%s\t%%ax", name);
1252 db_printf("<bad instruction>");
1261 * Disassemble instruction at 'loc'. 'altfmt' specifies an
1262 * (optional) alternate format. Return address of start of
1266 db_disasm(db_addr_t loc, boolean_t altfmt)
1272 const struct inst * ip;
1273 const char * i_name;
1286 struct i_addr address;
1289 get_value_inc(inst, loc, 1, FALSE);
1301 case 0x66: /* data16 */
1329 db_printf("repne ");
1338 if (inst >= 0x40 && inst < 0x50) {
1343 get_value_inc(inst, loc, 1, FALSE);
1347 db_printf("pause\n");
1350 db_printf("repe "); /* XXX repe VS rep */
1355 if (inst >= 0xd8 && inst <= 0xdf) {
1356 loc = db_disasm_esc(loc, inst, rex, short_addr, size, seg);
1362 get_value_inc(inst, loc, 1, FALSE);
1363 ip = db_inst_0f[inst>>4];
1372 ip = &db_inst_table[inst];
1374 if (ip->i_has_modrm) {
1375 get_value_inc(regmodrm, loc, 1, FALSE);
1376 loc = db_read_address(loc, short_addr, rex, regmodrm, &address);
1379 i_name = ip->i_name;
1380 i_size = ip->i_size;
1381 i_mode = ip->i_mode;
1383 if (ip->i_extra == db_Grp1 || ip->i_extra == db_Grp2 ||
1384 ip->i_extra == db_Grp6 || ip->i_extra == db_Grp7 ||
1385 ip->i_extra == db_Grp8 || ip->i_extra == db_Grp9 ||
1386 ip->i_extra == db_Grp15) {
1387 i_name = ((const char * const *)ip->i_extra)[f_reg(rex, regmodrm)];
1389 else if (ip->i_extra == db_Grp3) {
1391 ip = &ip[f_reg(rex, regmodrm)];
1392 i_name = ip->i_name;
1393 i_mode = ip->i_mode;
1395 else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) {
1397 ip = &ip[f_reg(rex, regmodrm)];
1398 i_name = ip->i_name;
1399 i_mode = ip->i_mode;
1400 i_size = ip->i_size;
1403 /* Special cases that don't fit well in the tables. */
1404 if (ip->i_extra == db_Grp7 && f_mod(rex, regmodrm) == 3) {
1423 if (ip->i_extra == db_Grp15 && f_mod(0, regmodrm) == 3) {
1424 i_name = db_Grp15b[f_reg(0, regmodrm)];
1429 if (i_size == SDEP) {
1431 db_printf("%s", i_name);
1433 db_printf("%s", (const char *)ip->i_extra);
1436 db_printf("%s", i_name);
1437 if ((inst >= 0x50 && inst <= 0x5f) || inst == 0x68 || inst == 0x6a) {
1441 if (i_size != NONE) {
1442 if (i_size == BYTE) {
1446 else if (i_size == WORD) {
1450 else if (size == WORD)
1463 i_mode >>= 8, first = FALSE)
1468 switch (i_mode & 0xFF) {
1471 db_print_address(seg, size, rex, &address);
1476 db_print_address(seg, size, rex, &address);
1480 db_print_address(seg, (rex & REX_W) ? QUAD : LONG, rex, &address);
1484 db_print_address(seg, LONG, 0, &address);
1488 db_print_address(seg, WORD, rex, &address);
1492 db_print_address(seg, BYTE, rex, &address);
1496 db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][f_reg(rex, regmodrm)]);
1500 db_printf("%s", db_reg[rex != 0 ? 1 : 0][WORD][f_reg(rex, regmodrm)]);
1504 db_printf("%s", db_reg[0][QUAD][f_rm(rex, inst)]);
1508 db_printf("%s", db_reg[rex != 0 ? 1 : 0][(rex & REX_R) ? QUAD : LONG][f_rm(rex, inst)]);
1512 db_printf("%s", db_seg_reg[f_reg(0, regmodrm)]);
1516 db_printf("%s", db_seg_reg[f_reg(0, inst)]);
1520 db_printf("%s", db_reg[rex != 0 ? 1 : 0][size][0]); /* acc */
1525 db_printf("%s:", seg);
1526 db_printf("(%s)", short_addr ? "%bx" : "%ebx");
1539 db_printf("%s:", seg);
1540 db_printf("(%s)", short_addr ? "%si" : "%rsi");
1544 db_printf("%%es:(%s)", short_addr ? "%di" : "%rdi");
1548 db_printf("%%cr%d", f_reg(rex, regmodrm));
1552 db_printf("%%dr%d", f_reg(rex, regmodrm));
1556 db_printf("%%tr%d", f_reg(rex, regmodrm));
1560 len = db_lengths[size];
1561 get_value_inc(imm, loc, len, FALSE);
1562 db_printf("$%#x", imm);
1566 len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
1567 get_value_inc(imm, loc, len, FALSE);
1568 db_printf("$%x", imm);
1572 get_value_inc(imm, loc, 1, FALSE);
1573 db_printf("$%#x", imm);
1577 get_value_inc(imm, loc, 1, FALSE);
1579 db_printf("$%#x", imm);
1583 get_value_inc(imm, loc, 1, TRUE);
1586 db_printf("$%x", imm);
1590 get_value_inc(imm, loc, 2, FALSE);
1591 db_printf("$%#x", imm);
1595 len = db_lengths[rex & REX_W ? QUAD : LONG];
1596 get_value_inc(imm64, loc, len, FALSE);
1597 db_printf("$%#lx", imm64);
1601 len = (short_addr ? 2 : 4);
1602 get_value_inc(displ, loc, len, FALSE);
1604 db_printf("%s:%x",seg, displ);
1606 db_printsym((db_addr_t)displ, DB_STGY_ANY);
1610 get_value_inc(displ, loc, 1, TRUE);
1611 addr = loc + (LONG64)displ;
1614 db_printsym(addr, DB_STGY_XTRN);
1618 len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
1619 get_value_inc(displ, loc, len, FALSE);
1620 addr = loc + (LONG64)displ;
1623 db_printsym(addr, DB_STGY_XTRN);
1635 len = db_lengths[size];
1636 get_value_inc(imm, loc, len, FALSE); /* offset */
1637 get_value_inc(imm2, loc, 2, FALSE); /* segment */
1638 db_printf("$%#x,%#x", imm2, imm);
1641 db_printf("%%mm%d", f_reg(rex, regmodrm));
1644 db_printf("%%mm%d", f_rm(rex, regmodrm));
1647 db_printf("%%xmm%d", f_reg(rex, regmodrm));
1650 db_printf("%%xmm%d", f_rm(rex, regmodrm));
1657 void be_x86_64_disasm_one_insn(ADDRESS64 *addr, int display)
1660 addr->Offset = db_disasm(addr->Offset, TRUE);