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.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 * Instruction disassembler.
33 #include <sys/param.h>
34 #include <sys/libkern.h>
37 #include <ddb/db_access.h>
38 #include <ddb/db_sym.h>
67 #define E 1 /* general effective address */
68 #define Eind 2 /* indirect address (jump, call) */
69 #define Ew 3 /* address, word size */
70 #define Eb 4 /* address, byte size */
71 #define R 5 /* register, in 'reg' field */
72 #define Rw 6 /* word register, in 'reg' field */
73 #define Rq 39 /* quad register, in 'reg' field */
74 #define Rv 40 /* register in 'r/m' field */
75 #define Ri 7 /* register in instruction */
76 #define S 8 /* segment reg, in 'reg' field */
77 #define Si 9 /* segment reg, in instruction */
78 #define A 10 /* accumulator */
79 #define BX 11 /* (bx) */
80 #define CL 12 /* cl, for shifts */
81 #define DX 13 /* dx, for IO */
82 #define SI 14 /* si */
83 #define DI 15 /* di */
84 #define CR 16 /* control register */
85 #define DR 17 /* debug register */
86 #define TR 18 /* test register */
87 #define I 19 /* immediate, unsigned */
88 #define Is 20 /* immediate, signed */
89 #define Ib 21 /* byte immediate, unsigned */
90 #define Ibs 22 /* byte immediate, signed */
91 #define Iw 23 /* word immediate, unsigned */
92 #define Ilq 24 /* long/quad immediate, unsigned */
93 #define O 25 /* direct address */
94 #define Db 26 /* byte displacement from EIP */
95 #define Dl 27 /* long displacement from EIP */
96 #define o1 28 /* constant 1 */
97 #define o3 29 /* constant 3 */
98 #define OS 30 /* immediate offset/segment */
99 #define ST 31 /* FP stack top */
100 #define STI 32 /* FP stack */
101 #define X 33 /* extended FP op */
102 #define XA 34 /* for 'fstcw %ax' */
103 #define El 35 /* address, long/quad size */
104 #define Ril 36 /* long register in instruction */
105 #define Iba 37 /* byte immediate, don't print if 0xa */
106 #define EL 38 /* address, explicitly long size */
109 const char * i_name; /* name */
110 short i_has_modrm; /* has regmodrm byte */
111 short i_size; /* operand size */
112 int i_mode; /* addressing modes */
113 const void * i_extra; /* pointer to extra opcode table */
117 #define op2(x,y) ((x)|((y)<<8))
118 #define op3(x,y,z) ((x)|((y)<<8)|((z)<<16))
121 const char * f_name; /* name for memory instruction */
122 int f_size; /* size for memory instruction */
123 int f_rrmode; /* mode for rr instruction */
124 const void * f_rrname; /* name for rr instruction
125 (or pointer to table) */
128 static const struct inst db_inst_0f388x[] = {
129 /*80*/ { "", TRUE, SDEP, op2(E, Rq), "invept" },
130 /*81*/ { "", TRUE, SDEP, op2(E, Rq), "invvpid" },
131 /*82*/ { "", TRUE, SDEP, op2(E, Rq), "invpcid" },
132 /*83*/ { "", FALSE, NONE, 0, 0 },
133 /*84*/ { "", FALSE, NONE, 0, 0 },
134 /*85*/ { "", FALSE, NONE, 0, 0 },
135 /*86*/ { "", FALSE, NONE, 0, 0 },
136 /*87*/ { "", FALSE, NONE, 0, 0 },
138 /*88*/ { "", FALSE, NONE, 0, 0 },
139 /*89*/ { "", FALSE, NONE, 0, 0 },
140 /*8a*/ { "", FALSE, NONE, 0, 0 },
141 /*8b*/ { "", FALSE, NONE, 0, 0 },
142 /*8c*/ { "", FALSE, NONE, 0, 0 },
143 /*8d*/ { "", FALSE, NONE, 0, 0 },
144 /*8e*/ { "", FALSE, NONE, 0, 0 },
145 /*8f*/ { "", FALSE, NONE, 0, 0 },
148 static const struct inst db_inst_0f38fx[] = {
149 /*f0*/ { "crc32b",TRUE, NONE, op2(Eb, R), 0 },
150 /*f1*/ { "crc32", TRUE, LONG, op2(E, R), 0 },
151 /*f2*/ { "", FALSE, NONE, 0, 0 },
152 /*f3*/ { "", FALSE, NONE, 0, 0 },
153 /*f4*/ { "", FALSE, NONE, 0, 0 },
154 /*f5*/ { "", FALSE, NONE, 0, 0 },
155 /*f6*/ { "", FALSE, NONE, 0, 0 },
156 /*f7*/ { "", FALSE, NONE, 0, 0 },
158 /*f8*/ { "", FALSE, NONE, 0, 0 },
159 /*f9*/ { "", FALSE, NONE, 0, 0 },
160 /*fa*/ { "", FALSE, NONE, 0, 0 },
161 /*fb*/ { "", FALSE, NONE, 0, 0 },
162 /*fc*/ { "", FALSE, NONE, 0, 0 },
163 /*fd*/ { "", FALSE, NONE, 0, 0 },
164 /*fe*/ { "", FALSE, NONE, 0, 0 },
165 /*ff*/ { "", FALSE, NONE, 0, 0 },
168 static const struct inst * const db_inst_0f38[] = {
187 static const char * const db_Grp6[] = {
198 static const char * const db_Grp7[] = {
209 static const char * const db_Grp8[] = {
220 static const char * const db_Grp9[] = {
231 static const char * const db_Grp15[] = {
242 static const char * const db_Grp15b[] = {
253 static const struct inst db_inst_0f0x[] = {
254 /*00*/ { "", TRUE, NONE, op1(Ew), db_Grp6 },
255 /*01*/ { "", TRUE, NONE, op1(Ew), db_Grp7 },
256 /*02*/ { "lar", TRUE, LONG, op2(E,R), 0 },
257 /*03*/ { "lsl", TRUE, LONG, op2(E,R), 0 },
258 /*04*/ { "", FALSE, NONE, 0, 0 },
259 /*05*/ { "syscall",FALSE,NONE, 0, 0 },
260 /*06*/ { "clts", FALSE, NONE, 0, 0 },
261 /*07*/ { "sysret",FALSE, NONE, 0, 0 },
263 /*08*/ { "invd", FALSE, NONE, 0, 0 },
264 /*09*/ { "wbinvd",FALSE, NONE, 0, 0 },
265 /*0a*/ { "", FALSE, NONE, 0, 0 },
266 /*0b*/ { "", FALSE, NONE, 0, 0 },
267 /*0c*/ { "", FALSE, NONE, 0, 0 },
268 /*0d*/ { "", FALSE, NONE, 0, 0 },
269 /*0e*/ { "", FALSE, NONE, 0, 0 },
270 /*0f*/ { "", FALSE, NONE, 0, 0 },
273 static const struct inst db_inst_0f1x[] = {
274 /*10*/ { "", FALSE, NONE, 0, 0 },
275 /*11*/ { "", FALSE, NONE, 0, 0 },
276 /*12*/ { "", FALSE, NONE, 0, 0 },
277 /*13*/ { "", FALSE, NONE, 0, 0 },
278 /*14*/ { "", FALSE, NONE, 0, 0 },
279 /*15*/ { "", FALSE, NONE, 0, 0 },
280 /*16*/ { "", FALSE, NONE, 0, 0 },
281 /*17*/ { "", FALSE, NONE, 0, 0 },
283 /*18*/ { "", FALSE, NONE, 0, 0 },
284 /*19*/ { "", FALSE, NONE, 0, 0 },
285 /*1a*/ { "", FALSE, NONE, 0, 0 },
286 /*1b*/ { "", FALSE, NONE, 0, 0 },
287 /*1c*/ { "", FALSE, NONE, 0, 0 },
288 /*1d*/ { "", FALSE, NONE, 0, 0 },
289 /*1e*/ { "", FALSE, NONE, 0, 0 },
290 /*1f*/ { "nopl", TRUE, SDEP, 0, "nopw" },
293 static const struct inst db_inst_0f2x[] = {
294 /*20*/ { "mov", TRUE, LONG, op2(CR,El), 0 },
295 /*21*/ { "mov", TRUE, LONG, op2(DR,El), 0 },
296 /*22*/ { "mov", TRUE, LONG, op2(El,CR), 0 },
297 /*23*/ { "mov", TRUE, LONG, op2(El,DR), 0 },
298 /*24*/ { "mov", TRUE, LONG, op2(TR,El), 0 },
299 /*25*/ { "", FALSE, NONE, 0, 0 },
300 /*26*/ { "mov", TRUE, LONG, op2(El,TR), 0 },
301 /*27*/ { "", FALSE, NONE, 0, 0 },
303 /*28*/ { "", FALSE, NONE, 0, 0 },
304 /*29*/ { "", FALSE, NONE, 0, 0 },
305 /*2a*/ { "", FALSE, NONE, 0, 0 },
306 /*2b*/ { "", FALSE, NONE, 0, 0 },
307 /*2c*/ { "", FALSE, NONE, 0, 0 },
308 /*2d*/ { "", FALSE, NONE, 0, 0 },
309 /*2e*/ { "", FALSE, NONE, 0, 0 },
310 /*2f*/ { "", FALSE, NONE, 0, 0 },
313 static const struct inst db_inst_0f3x[] = {
314 /*30*/ { "wrmsr", FALSE, NONE, 0, 0 },
315 /*31*/ { "rdtsc", FALSE, NONE, 0, 0 },
316 /*32*/ { "rdmsr", FALSE, NONE, 0, 0 },
317 /*33*/ { "rdpmc", FALSE, NONE, 0, 0 },
318 /*34*/ { "sysenter",FALSE,NONE, 0, 0 },
319 /*35*/ { "sysexit",FALSE,NONE, 0, 0 },
320 /*36*/ { "", FALSE, NONE, 0, 0 },
321 /*37*/ { "getsec",FALSE, NONE, 0, 0 },
323 /*38*/ { "", FALSE, ESC, 0, db_inst_0f38 },
324 /*39*/ { "", FALSE, NONE, 0, 0 },
325 /*3a*/ { "", FALSE, NONE, 0, 0 },
326 /*3b*/ { "", FALSE, NONE, 0, 0 },
327 /*3c*/ { "", FALSE, NONE, 0, 0 },
328 /*3d*/ { "", FALSE, NONE, 0, 0 },
329 /*3e*/ { "", FALSE, NONE, 0, 0 },
330 /*3f*/ { "", FALSE, NONE, 0, 0 },
333 static const struct inst db_inst_0f4x[] = {
334 /*40*/ { "cmovo", TRUE, NONE, op2(E, R), 0 },
335 /*41*/ { "cmovno", TRUE, NONE, op2(E, R), 0 },
336 /*42*/ { "cmovb", TRUE, NONE, op2(E, R), 0 },
337 /*43*/ { "cmovnb", TRUE, NONE, op2(E, R), 0 },
338 /*44*/ { "cmovz", TRUE, NONE, op2(E, R), 0 },
339 /*45*/ { "cmovnz", TRUE, NONE, op2(E, R), 0 },
340 /*46*/ { "cmovbe", TRUE, NONE, op2(E, R), 0 },
341 /*47*/ { "cmovnbe",TRUE, NONE, op2(E, R), 0 },
343 /*48*/ { "cmovs", TRUE, NONE, op2(E, R), 0 },
344 /*49*/ { "cmovns", TRUE, NONE, op2(E, R), 0 },
345 /*4a*/ { "cmovp", TRUE, NONE, op2(E, R), 0 },
346 /*4b*/ { "cmovnp", TRUE, NONE, op2(E, R), 0 },
347 /*4c*/ { "cmovl", TRUE, NONE, op2(E, R), 0 },
348 /*4d*/ { "cmovnl", TRUE, NONE, op2(E, R), 0 },
349 /*4e*/ { "cmovle", TRUE, NONE, op2(E, R), 0 },
350 /*4f*/ { "cmovnle",TRUE, NONE, op2(E, R), 0 },
353 static const struct inst db_inst_0f7x[] = {
354 /*70*/ { "", FALSE, NONE, 0, 0 },
355 /*71*/ { "", FALSE, NONE, 0, 0 },
356 /*72*/ { "", FALSE, NONE, 0, 0 },
357 /*73*/ { "", FALSE, NONE, 0, 0 },
358 /*74*/ { "", FALSE, NONE, 0, 0 },
359 /*75*/ { "", FALSE, NONE, 0, 0 },
360 /*76*/ { "", FALSE, NONE, 0, 0 },
361 /*77*/ { "", FALSE, NONE, 0, 0 },
363 /*78*/ { "vmread", TRUE, NONE, op2(Rq, E), 0 },
364 /*79*/ { "vmwrite",TRUE, NONE, op2(E, Rq), 0 },
365 /*7a*/ { "", FALSE, NONE, 0, 0 },
366 /*7b*/ { "", FALSE, NONE, 0, 0 },
367 /*7c*/ { "", FALSE, NONE, 0, 0 },
368 /*7d*/ { "", FALSE, NONE, 0, 0 },
369 /*7e*/ { "", FALSE, NONE, 0, 0 },
370 /*7f*/ { "", FALSE, NONE, 0, 0 },
373 static const struct inst db_inst_0f8x[] = {
374 /*80*/ { "jo", FALSE, NONE, op1(Dl), 0 },
375 /*81*/ { "jno", FALSE, NONE, op1(Dl), 0 },
376 /*82*/ { "jb", FALSE, NONE, op1(Dl), 0 },
377 /*83*/ { "jnb", FALSE, NONE, op1(Dl), 0 },
378 /*84*/ { "jz", FALSE, NONE, op1(Dl), 0 },
379 /*85*/ { "jnz", FALSE, NONE, op1(Dl), 0 },
380 /*86*/ { "jbe", FALSE, NONE, op1(Dl), 0 },
381 /*87*/ { "jnbe", FALSE, NONE, op1(Dl), 0 },
383 /*88*/ { "js", FALSE, NONE, op1(Dl), 0 },
384 /*89*/ { "jns", FALSE, NONE, op1(Dl), 0 },
385 /*8a*/ { "jp", FALSE, NONE, op1(Dl), 0 },
386 /*8b*/ { "jnp", FALSE, NONE, op1(Dl), 0 },
387 /*8c*/ { "jl", FALSE, NONE, op1(Dl), 0 },
388 /*8d*/ { "jnl", FALSE, NONE, op1(Dl), 0 },
389 /*8e*/ { "jle", FALSE, NONE, op1(Dl), 0 },
390 /*8f*/ { "jnle", FALSE, NONE, op1(Dl), 0 },
393 static const struct inst db_inst_0f9x[] = {
394 /*90*/ { "seto", TRUE, NONE, op1(Eb), 0 },
395 /*91*/ { "setno", TRUE, NONE, op1(Eb), 0 },
396 /*92*/ { "setb", TRUE, NONE, op1(Eb), 0 },
397 /*93*/ { "setnb", TRUE, NONE, op1(Eb), 0 },
398 /*94*/ { "setz", TRUE, NONE, op1(Eb), 0 },
399 /*95*/ { "setnz", TRUE, NONE, op1(Eb), 0 },
400 /*96*/ { "setbe", TRUE, NONE, op1(Eb), 0 },
401 /*97*/ { "setnbe",TRUE, NONE, op1(Eb), 0 },
403 /*98*/ { "sets", TRUE, NONE, op1(Eb), 0 },
404 /*99*/ { "setns", TRUE, NONE, op1(Eb), 0 },
405 /*9a*/ { "setp", TRUE, NONE, op1(Eb), 0 },
406 /*9b*/ { "setnp", TRUE, NONE, op1(Eb), 0 },
407 /*9c*/ { "setl", TRUE, NONE, op1(Eb), 0 },
408 /*9d*/ { "setnl", TRUE, NONE, op1(Eb), 0 },
409 /*9e*/ { "setle", TRUE, NONE, op1(Eb), 0 },
410 /*9f*/ { "setnle",TRUE, NONE, op1(Eb), 0 },
413 static const struct inst db_inst_0fax[] = {
414 /*a0*/ { "push", FALSE, NONE, op1(Si), 0 },
415 /*a1*/ { "pop", FALSE, NONE, op1(Si), 0 },
416 /*a2*/ { "cpuid", FALSE, NONE, 0, 0 },
417 /*a3*/ { "bt", TRUE, LONG, op2(R,E), 0 },
418 /*a4*/ { "shld", TRUE, LONG, op3(Ib,R,E), 0 },
419 /*a5*/ { "shld", TRUE, LONG, op3(CL,R,E), 0 },
420 /*a6*/ { "", FALSE, NONE, 0, 0 },
421 /*a7*/ { "", FALSE, NONE, 0, 0 },
423 /*a8*/ { "push", FALSE, NONE, op1(Si), 0 },
424 /*a9*/ { "pop", FALSE, NONE, op1(Si), 0 },
425 /*aa*/ { "rsm", FALSE, NONE, 0, 0 },
426 /*ab*/ { "bts", TRUE, LONG, op2(R,E), 0 },
427 /*ac*/ { "shrd", TRUE, LONG, op3(Ib,R,E), 0 },
428 /*ad*/ { "shrd", TRUE, LONG, op3(CL,R,E), 0 },
429 /*ae*/ { "", TRUE, LONG, op1(E), db_Grp15 },
430 /*af*/ { "imul", TRUE, LONG, op2(E,R), 0 },
433 static const struct inst db_inst_0fbx[] = {
434 /*b0*/ { "cmpxchg",TRUE, BYTE, op2(R, E), 0 },
435 /*b0*/ { "cmpxchg",TRUE, LONG, op2(R, E), 0 },
436 /*b2*/ { "lss", TRUE, LONG, op2(E, R), 0 },
437 /*b3*/ { "btr", TRUE, LONG, op2(R, E), 0 },
438 /*b4*/ { "lfs", TRUE, LONG, op2(E, R), 0 },
439 /*b5*/ { "lgs", TRUE, LONG, op2(E, R), 0 },
440 /*b6*/ { "movzb", TRUE, LONG, op2(Eb, R), 0 },
441 /*b7*/ { "movzw", TRUE, LONG, op2(Ew, R), 0 },
443 /*b8*/ { "", FALSE, NONE, 0, 0 },
444 /*b9*/ { "", FALSE, NONE, 0, 0 },
445 /*ba*/ { "", TRUE, LONG, op2(Ib, E), db_Grp8 },
446 /*bb*/ { "btc", TRUE, LONG, op2(R, E), 0 },
447 /*bc*/ { "bsf", TRUE, LONG, op2(E, R), 0 },
448 /*bd*/ { "bsr", TRUE, LONG, op2(E, R), 0 },
449 /*be*/ { "movsb", TRUE, LONG, op2(Eb, R), 0 },
450 /*bf*/ { "movsw", TRUE, LONG, op2(Ew, R), 0 },
453 static const struct inst db_inst_0fcx[] = {
454 /*c0*/ { "xadd", TRUE, BYTE, op2(R, E), 0 },
455 /*c1*/ { "xadd", TRUE, LONG, op2(R, E), 0 },
456 /*c2*/ { "", FALSE, NONE, 0, 0 },
457 /*c3*/ { "", FALSE, NONE, 0, 0 },
458 /*c4*/ { "", FALSE, NONE, 0, 0 },
459 /*c5*/ { "", FALSE, NONE, 0, 0 },
460 /*c6*/ { "", FALSE, NONE, 0, 0 },
461 /*c7*/ { "", TRUE, NONE, op1(E), db_Grp9 },
462 /*c8*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
463 /*c9*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
464 /*ca*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
465 /*cb*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
466 /*cc*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
467 /*cd*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
468 /*ce*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
469 /*cf*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
472 static const struct inst * const db_inst_0f[] = {
491 static const char * const db_Esc92[] = {
492 "fnop", "", "", "", "", "", "", ""
494 static const char * const db_Esc94[] = {
495 "fchs", "fabs", "", "", "ftst", "fxam", "", ""
497 static const char * const db_Esc95[] = {
498 "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
500 static const char * const db_Esc96[] = {
501 "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
504 static const char * const db_Esc97[] = {
505 "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
508 static const char * const db_Esca5[] = {
509 "", "fucompp","", "", "", "", "", ""
512 static const char * const db_Escb4[] = {
513 "fneni","fndisi", "fnclex","fninit","fsetpm", "", "", ""
516 static const char * const db_Esce3[] = {
517 "", "fcompp","", "", "", "", "", ""
520 static const char * const db_Escf4[] = {
521 "fnstsw","", "", "", "", "", "", ""
524 static const struct finst db_Esc8[] = {
525 /*0*/ { "fadd", SNGL, op2(STI,ST), 0 },
526 /*1*/ { "fmul", SNGL, op2(STI,ST), 0 },
527 /*2*/ { "fcom", SNGL, op2(STI,ST), 0 },
528 /*3*/ { "fcomp", SNGL, op2(STI,ST), 0 },
529 /*4*/ { "fsub", SNGL, op2(STI,ST), 0 },
530 /*5*/ { "fsubr", SNGL, op2(STI,ST), 0 },
531 /*6*/ { "fdiv", SNGL, op2(STI,ST), 0 },
532 /*7*/ { "fdivr", SNGL, op2(STI,ST), 0 },
535 static const struct finst db_Esc9[] = {
536 /*0*/ { "fld", SNGL, op1(STI), 0 },
537 /*1*/ { "", NONE, op1(STI), "fxch" },
538 /*2*/ { "fst", SNGL, op1(X), db_Esc92 },
539 /*3*/ { "fstp", SNGL, 0, 0 },
540 /*4*/ { "fldenv", NONE, op1(X), db_Esc94 },
541 /*5*/ { "fldcw", NONE, op1(X), db_Esc95 },
542 /*6*/ { "fnstenv",NONE, op1(X), db_Esc96 },
543 /*7*/ { "fnstcw", NONE, op1(X), db_Esc97 },
546 static const struct finst db_Esca[] = {
547 /*0*/ { "fiadd", LONG, 0, 0 },
548 /*1*/ { "fimul", LONG, 0, 0 },
549 /*2*/ { "ficom", LONG, 0, 0 },
550 /*3*/ { "ficomp", LONG, 0, 0 },
551 /*4*/ { "fisub", LONG, 0, 0 },
552 /*5*/ { "fisubr", LONG, op1(X), db_Esca5 },
553 /*6*/ { "fidiv", LONG, 0, 0 },
554 /*7*/ { "fidivr", LONG, 0, 0 }
557 static const struct finst db_Escb[] = {
558 /*0*/ { "fild", LONG, 0, 0 },
559 /*1*/ { "", NONE, 0, 0 },
560 /*2*/ { "fist", LONG, 0, 0 },
561 /*3*/ { "fistp", LONG, 0, 0 },
562 /*4*/ { "", WORD, op1(X), db_Escb4 },
563 /*5*/ { "fld", EXTR, 0, 0 },
564 /*6*/ { "", WORD, 0, 0 },
565 /*7*/ { "fstp", EXTR, 0, 0 },
568 static const struct finst db_Escc[] = {
569 /*0*/ { "fadd", DBLR, op2(ST,STI), 0 },
570 /*1*/ { "fmul", DBLR, op2(ST,STI), 0 },
571 /*2*/ { "fcom", DBLR, 0, 0 },
572 /*3*/ { "fcomp", DBLR, 0, 0 },
573 /*4*/ { "fsub", DBLR, op2(ST,STI), "fsubr" },
574 /*5*/ { "fsubr", DBLR, op2(ST,STI), "fsub" },
575 /*6*/ { "fdiv", DBLR, op2(ST,STI), "fdivr" },
576 /*7*/ { "fdivr", DBLR, op2(ST,STI), "fdiv" },
579 static const struct finst db_Escd[] = {
580 /*0*/ { "fld", DBLR, op1(STI), "ffree" },
581 /*1*/ { "", NONE, 0, 0 },
582 /*2*/ { "fst", DBLR, op1(STI), 0 },
583 /*3*/ { "fstp", DBLR, op1(STI), 0 },
584 /*4*/ { "frstor", NONE, op1(STI), "fucom" },
585 /*5*/ { "", NONE, op1(STI), "fucomp" },
586 /*6*/ { "fnsave", NONE, 0, 0 },
587 /*7*/ { "fnstsw", NONE, 0, 0 },
590 static const struct finst db_Esce[] = {
591 /*0*/ { "fiadd", WORD, op2(ST,STI), "faddp" },
592 /*1*/ { "fimul", WORD, op2(ST,STI), "fmulp" },
593 /*2*/ { "ficom", WORD, 0, 0 },
594 /*3*/ { "ficomp", WORD, op1(X), db_Esce3 },
595 /*4*/ { "fisub", WORD, op2(ST,STI), "fsubrp" },
596 /*5*/ { "fisubr", WORD, op2(ST,STI), "fsubp" },
597 /*6*/ { "fidiv", WORD, op2(ST,STI), "fdivrp" },
598 /*7*/ { "fidivr", WORD, op2(ST,STI), "fdivp" },
601 static const struct finst db_Escf[] = {
602 /*0*/ { "fild", WORD, 0, 0 },
603 /*1*/ { "", NONE, 0, 0 },
604 /*2*/ { "fist", WORD, 0, 0 },
605 /*3*/ { "fistp", WORD, 0, 0 },
606 /*4*/ { "fbld", NONE, op1(XA), db_Escf4 },
607 /*5*/ { "fild", QUAD, 0, 0 },
608 /*6*/ { "fbstp", NONE, 0, 0 },
609 /*7*/ { "fistp", QUAD, 0, 0 },
612 static const struct finst * const db_Esc_inst[] = {
613 db_Esc8, db_Esc9, db_Esca, db_Escb,
614 db_Escc, db_Escd, db_Esce, db_Escf
617 static const char * const db_Grp1[] = {
628 static const char * const db_Grp2[] = {
639 static const struct inst db_Grp3[] = {
640 { "test", TRUE, NONE, op2(I,E), 0 },
641 { "test", TRUE, NONE, op2(I,E), 0 },
642 { "not", TRUE, NONE, op1(E), 0 },
643 { "neg", TRUE, NONE, op1(E), 0 },
644 { "mul", TRUE, NONE, op2(E,A), 0 },
645 { "imul", TRUE, NONE, op2(E,A), 0 },
646 { "div", TRUE, NONE, op2(E,A), 0 },
647 { "idiv", TRUE, NONE, op2(E,A), 0 },
650 static const struct inst db_Grp4[] = {
651 { "inc", TRUE, BYTE, op1(E), 0 },
652 { "dec", TRUE, BYTE, op1(E), 0 },
653 { "", TRUE, NONE, 0, 0 },
654 { "", TRUE, NONE, 0, 0 },
655 { "", TRUE, NONE, 0, 0 },
656 { "", TRUE, NONE, 0, 0 },
657 { "", TRUE, NONE, 0, 0 },
658 { "", TRUE, NONE, 0, 0 }
661 static const struct inst db_Grp5[] = {
662 { "inc", TRUE, LONG, op1(E), 0 },
663 { "dec", TRUE, LONG, op1(E), 0 },
664 { "call", TRUE, LONG, op1(Eind),0 },
665 { "lcall", TRUE, LONG, op1(Eind),0 },
666 { "jmp", TRUE, LONG, op1(Eind),0 },
667 { "ljmp", TRUE, LONG, op1(Eind),0 },
668 { "push", TRUE, LONG, op1(E), 0 },
669 { "", TRUE, NONE, 0, 0 }
672 static const struct inst db_Grp9b[] = {
673 { "", TRUE, NONE, 0, 0 },
674 { "", TRUE, NONE, 0, 0 },
675 { "", TRUE, NONE, 0, 0 },
676 { "", TRUE, NONE, 0, 0 },
677 { "", TRUE, NONE, 0, 0 },
678 { "", TRUE, NONE, 0, 0 },
679 { "rdrand",TRUE, LONG, op1(Rv), 0 },
680 { "rdseed",TRUE, LONG, op1(Rv), 0 }
683 static const struct inst db_inst_table[256] = {
684 /*00*/ { "add", TRUE, BYTE, op2(R, E), 0 },
685 /*01*/ { "add", TRUE, LONG, op2(R, E), 0 },
686 /*02*/ { "add", TRUE, BYTE, op2(E, R), 0 },
687 /*03*/ { "add", TRUE, LONG, op2(E, R), 0 },
688 /*04*/ { "add", FALSE, BYTE, op2(I, A), 0 },
689 /*05*/ { "add", FALSE, LONG, op2(Is, A), 0 },
690 /*06*/ { "push", FALSE, NONE, op1(Si), 0 },
691 /*07*/ { "pop", FALSE, NONE, op1(Si), 0 },
693 /*08*/ { "or", TRUE, BYTE, op2(R, E), 0 },
694 /*09*/ { "or", TRUE, LONG, op2(R, E), 0 },
695 /*0a*/ { "or", TRUE, BYTE, op2(E, R), 0 },
696 /*0b*/ { "or", TRUE, LONG, op2(E, R), 0 },
697 /*0c*/ { "or", FALSE, BYTE, op2(I, A), 0 },
698 /*0d*/ { "or", FALSE, LONG, op2(I, A), 0 },
699 /*0e*/ { "push", FALSE, NONE, op1(Si), 0 },
700 /*0f*/ { "", FALSE, ESC, 0, db_inst_0f },
702 /*10*/ { "adc", TRUE, BYTE, op2(R, E), 0 },
703 /*11*/ { "adc", TRUE, LONG, op2(R, E), 0 },
704 /*12*/ { "adc", TRUE, BYTE, op2(E, R), 0 },
705 /*13*/ { "adc", TRUE, LONG, op2(E, R), 0 },
706 /*14*/ { "adc", FALSE, BYTE, op2(I, A), 0 },
707 /*15*/ { "adc", FALSE, LONG, op2(Is, A), 0 },
708 /*16*/ { "push", FALSE, NONE, op1(Si), 0 },
709 /*17*/ { "pop", FALSE, NONE, op1(Si), 0 },
711 /*18*/ { "sbb", TRUE, BYTE, op2(R, E), 0 },
712 /*19*/ { "sbb", TRUE, LONG, op2(R, E), 0 },
713 /*1a*/ { "sbb", TRUE, BYTE, op2(E, R), 0 },
714 /*1b*/ { "sbb", TRUE, LONG, op2(E, R), 0 },
715 /*1c*/ { "sbb", FALSE, BYTE, op2(I, A), 0 },
716 /*1d*/ { "sbb", FALSE, LONG, op2(Is, A), 0 },
717 /*1e*/ { "push", FALSE, NONE, op1(Si), 0 },
718 /*1f*/ { "pop", FALSE, NONE, op1(Si), 0 },
720 /*20*/ { "and", TRUE, BYTE, op2(R, E), 0 },
721 /*21*/ { "and", TRUE, LONG, op2(R, E), 0 },
722 /*22*/ { "and", TRUE, BYTE, op2(E, R), 0 },
723 /*23*/ { "and", TRUE, LONG, op2(E, R), 0 },
724 /*24*/ { "and", FALSE, BYTE, op2(I, A), 0 },
725 /*25*/ { "and", FALSE, LONG, op2(I, A), 0 },
726 /*26*/ { "", FALSE, NONE, 0, 0 },
727 /*27*/ { "daa", FALSE, NONE, 0, 0 },
729 /*28*/ { "sub", TRUE, BYTE, op2(R, E), 0 },
730 /*29*/ { "sub", TRUE, LONG, op2(R, E), 0 },
731 /*2a*/ { "sub", TRUE, BYTE, op2(E, R), 0 },
732 /*2b*/ { "sub", TRUE, LONG, op2(E, R), 0 },
733 /*2c*/ { "sub", FALSE, BYTE, op2(I, A), 0 },
734 /*2d*/ { "sub", FALSE, LONG, op2(Is, A), 0 },
735 /*2e*/ { "", FALSE, NONE, 0, 0 },
736 /*2f*/ { "das", FALSE, NONE, 0, 0 },
738 /*30*/ { "xor", TRUE, BYTE, op2(R, E), 0 },
739 /*31*/ { "xor", TRUE, LONG, op2(R, E), 0 },
740 /*32*/ { "xor", TRUE, BYTE, op2(E, R), 0 },
741 /*33*/ { "xor", TRUE, LONG, op2(E, R), 0 },
742 /*34*/ { "xor", FALSE, BYTE, op2(I, A), 0 },
743 /*35*/ { "xor", FALSE, LONG, op2(I, A), 0 },
744 /*36*/ { "", FALSE, NONE, 0, 0 },
745 /*37*/ { "aaa", FALSE, NONE, 0, 0 },
747 /*38*/ { "cmp", TRUE, BYTE, op2(R, E), 0 },
748 /*39*/ { "cmp", TRUE, LONG, op2(R, E), 0 },
749 /*3a*/ { "cmp", TRUE, BYTE, op2(E, R), 0 },
750 /*3b*/ { "cmp", TRUE, LONG, op2(E, R), 0 },
751 /*3c*/ { "cmp", FALSE, BYTE, op2(I, A), 0 },
752 /*3d*/ { "cmp", FALSE, LONG, op2(Is, A), 0 },
753 /*3e*/ { "", FALSE, NONE, 0, 0 },
754 /*3f*/ { "aas", FALSE, NONE, 0, 0 },
756 /*40*/ { "rex", FALSE, NONE, 0, 0 },
757 /*41*/ { "rex.b", FALSE, NONE, 0, 0 },
758 /*42*/ { "rex.x", FALSE, NONE, 0, 0 },
759 /*43*/ { "rex.xb", FALSE, NONE, 0, 0 },
760 /*44*/ { "rex.r", FALSE, NONE, 0, 0 },
761 /*45*/ { "rex.rb", FALSE, NONE, 0, 0 },
762 /*46*/ { "rex.rx", FALSE, NONE, 0, 0 },
763 /*47*/ { "rex.rxb", FALSE, NONE, 0, 0 },
765 /*48*/ { "rex.w", FALSE, NONE, 0, 0 },
766 /*49*/ { "rex.wb", FALSE, NONE, 0, 0 },
767 /*4a*/ { "rex.wx", FALSE, NONE, 0, 0 },
768 /*4b*/ { "rex.wxb", FALSE, NONE, 0, 0 },
769 /*4c*/ { "rex.wr", FALSE, NONE, 0, 0 },
770 /*4d*/ { "rex.wrb", FALSE, NONE, 0, 0 },
771 /*4e*/ { "rex.wrx", FALSE, NONE, 0, 0 },
772 /*4f*/ { "rex.wrxb", FALSE, NONE, 0, 0 },
774 /*50*/ { "push", FALSE, LONG, op1(Ri), 0 },
775 /*51*/ { "push", FALSE, LONG, op1(Ri), 0 },
776 /*52*/ { "push", FALSE, LONG, op1(Ri), 0 },
777 /*53*/ { "push", FALSE, LONG, op1(Ri), 0 },
778 /*54*/ { "push", FALSE, LONG, op1(Ri), 0 },
779 /*55*/ { "push", FALSE, LONG, op1(Ri), 0 },
780 /*56*/ { "push", FALSE, LONG, op1(Ri), 0 },
781 /*57*/ { "push", FALSE, LONG, op1(Ri), 0 },
783 /*58*/ { "pop", FALSE, LONG, op1(Ri), 0 },
784 /*59*/ { "pop", FALSE, LONG, op1(Ri), 0 },
785 /*5a*/ { "pop", FALSE, LONG, op1(Ri), 0 },
786 /*5b*/ { "pop", FALSE, LONG, op1(Ri), 0 },
787 /*5c*/ { "pop", FALSE, LONG, op1(Ri), 0 },
788 /*5d*/ { "pop", FALSE, LONG, op1(Ri), 0 },
789 /*5e*/ { "pop", FALSE, LONG, op1(Ri), 0 },
790 /*5f*/ { "pop", FALSE, LONG, op1(Ri), 0 },
792 /*60*/ { "pusha", FALSE, LONG, 0, 0 },
793 /*61*/ { "popa", FALSE, LONG, 0, 0 },
794 /*62*/ { "bound", TRUE, LONG, op2(E, R), 0 },
795 /*63*/ { "movslq", TRUE, NONE, op2(EL,R), 0 },
797 /*64*/ { "", FALSE, NONE, 0, 0 },
798 /*65*/ { "", FALSE, NONE, 0, 0 },
799 /*66*/ { "", FALSE, NONE, 0, 0 },
800 /*67*/ { "", FALSE, NONE, 0, 0 },
802 /*68*/ { "push", FALSE, LONG, op1(I), 0 },
803 /*69*/ { "imul", TRUE, LONG, op3(I,E,R), 0 },
804 /*6a*/ { "push", FALSE, LONG, op1(Ibs), 0 },
805 /*6b*/ { "imul", TRUE, LONG, op3(Ibs,E,R),0 },
806 /*6c*/ { "ins", FALSE, BYTE, op2(DX, DI), 0 },
807 /*6d*/ { "ins", FALSE, LONG, op2(DX, DI), 0 },
808 /*6e*/ { "outs", FALSE, BYTE, op2(SI, DX), 0 },
809 /*6f*/ { "outs", FALSE, LONG, op2(SI, DX), 0 },
811 /*70*/ { "jo", FALSE, NONE, op1(Db), 0 },
812 /*71*/ { "jno", FALSE, NONE, op1(Db), 0 },
813 /*72*/ { "jb", FALSE, NONE, op1(Db), 0 },
814 /*73*/ { "jnb", FALSE, NONE, op1(Db), 0 },
815 /*74*/ { "jz", FALSE, NONE, op1(Db), 0 },
816 /*75*/ { "jnz", FALSE, NONE, op1(Db), 0 },
817 /*76*/ { "jbe", FALSE, NONE, op1(Db), 0 },
818 /*77*/ { "jnbe", FALSE, NONE, op1(Db), 0 },
820 /*78*/ { "js", FALSE, NONE, op1(Db), 0 },
821 /*79*/ { "jns", FALSE, NONE, op1(Db), 0 },
822 /*7a*/ { "jp", FALSE, NONE, op1(Db), 0 },
823 /*7b*/ { "jnp", FALSE, NONE, op1(Db), 0 },
824 /*7c*/ { "jl", FALSE, NONE, op1(Db), 0 },
825 /*7d*/ { "jnl", FALSE, NONE, op1(Db), 0 },
826 /*7e*/ { "jle", FALSE, NONE, op1(Db), 0 },
827 /*7f*/ { "jnle", FALSE, NONE, op1(Db), 0 },
829 /*80*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 },
830 /*81*/ { "", TRUE, LONG, op2(I, E), db_Grp1 },
831 /*82*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 },
832 /*83*/ { "", TRUE, LONG, op2(Ibs,E), db_Grp1 },
833 /*84*/ { "test", TRUE, BYTE, op2(R, E), 0 },
834 /*85*/ { "test", TRUE, LONG, op2(R, E), 0 },
835 /*86*/ { "xchg", TRUE, BYTE, op2(R, E), 0 },
836 /*87*/ { "xchg", TRUE, LONG, op2(R, E), 0 },
838 /*88*/ { "mov", TRUE, BYTE, op2(R, E), 0 },
839 /*89*/ { "mov", TRUE, LONG, op2(R, E), 0 },
840 /*8a*/ { "mov", TRUE, BYTE, op2(E, R), 0 },
841 /*8b*/ { "mov", TRUE, LONG, op2(E, R), 0 },
842 /*8c*/ { "mov", TRUE, NONE, op2(S, Ew), 0 },
843 /*8d*/ { "lea", TRUE, LONG, op2(E, R), 0 },
844 /*8e*/ { "mov", TRUE, NONE, op2(Ew, S), 0 },
845 /*8f*/ { "pop", TRUE, LONG, op1(E), 0 },
847 /*90*/ { "nop", FALSE, NONE, 0, 0 },
848 /*91*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
849 /*92*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
850 /*93*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
851 /*94*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
852 /*95*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
853 /*96*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
854 /*97*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
856 /*98*/ { "cwde", FALSE, SDEP, 0, "cbw" },
857 /*99*/ { "cdq", FALSE, SDEP, 0, "cwd" },
858 /*9a*/ { "lcall", FALSE, NONE, op1(OS), 0 },
859 /*9b*/ { "wait", FALSE, NONE, 0, 0 },
860 /*9c*/ { "pushf", FALSE, LONG, 0, 0 },
861 /*9d*/ { "popf", FALSE, LONG, 0, 0 },
862 /*9e*/ { "sahf", FALSE, NONE, 0, 0 },
863 /*9f*/ { "lahf", FALSE, NONE, 0, 0 },
865 /*a0*/ { "mov", FALSE, BYTE, op2(O, A), 0 },
866 /*a1*/ { "mov", FALSE, LONG, op2(O, A), 0 },
867 /*a2*/ { "mov", FALSE, BYTE, op2(A, O), 0 },
868 /*a3*/ { "mov", FALSE, LONG, op2(A, O), 0 },
869 /*a4*/ { "movs", FALSE, BYTE, op2(SI,DI), 0 },
870 /*a5*/ { "movs", FALSE, LONG, op2(SI,DI), 0 },
871 /*a6*/ { "cmps", FALSE, BYTE, op2(SI,DI), 0 },
872 /*a7*/ { "cmps", FALSE, LONG, op2(SI,DI), 0 },
874 /*a8*/ { "test", FALSE, BYTE, op2(I, A), 0 },
875 /*a9*/ { "test", FALSE, LONG, op2(I, A), 0 },
876 /*aa*/ { "stos", FALSE, BYTE, op1(DI), 0 },
877 /*ab*/ { "stos", FALSE, LONG, op1(DI), 0 },
878 /*ac*/ { "lods", FALSE, BYTE, op1(SI), 0 },
879 /*ad*/ { "lods", FALSE, LONG, op1(SI), 0 },
880 /*ae*/ { "scas", FALSE, BYTE, op1(SI), 0 },
881 /*af*/ { "scas", FALSE, LONG, op1(SI), 0 },
883 /*b0*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
884 /*b1*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
885 /*b2*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
886 /*b3*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
887 /*b4*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
888 /*b5*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
889 /*b6*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
890 /*b7*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
892 /*b8*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
893 /*b9*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
894 /*ba*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
895 /*bb*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
896 /*bc*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
897 /*bd*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
898 /*be*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
899 /*bf*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
901 /*c0*/ { "", TRUE, BYTE, op2(Ib, E), db_Grp2 },
902 /*c1*/ { "", TRUE, LONG, op2(Ib, E), db_Grp2 },
903 /*c2*/ { "ret", FALSE, NONE, op1(Iw), 0 },
904 /*c3*/ { "ret", FALSE, NONE, 0, 0 },
905 /*c4*/ { "les", TRUE, LONG, op2(E, R), 0 },
906 /*c5*/ { "lds", TRUE, LONG, op2(E, R), 0 },
907 /*c6*/ { "mov", TRUE, BYTE, op2(I, E), 0 },
908 /*c7*/ { "mov", TRUE, LONG, op2(I, E), 0 },
910 /*c8*/ { "enter", FALSE, NONE, op2(Iw, Ib), 0 },
911 /*c9*/ { "leave", FALSE, NONE, 0, 0 },
912 /*ca*/ { "lret", FALSE, NONE, op1(Iw), 0 },
913 /*cb*/ { "lret", FALSE, NONE, 0, 0 },
914 /*cc*/ { "int", FALSE, NONE, op1(o3), 0 },
915 /*cd*/ { "int", FALSE, NONE, op1(Ib), 0 },
916 /*ce*/ { "into", FALSE, NONE, 0, 0 },
917 /*cf*/ { "iret", FALSE, NONE, 0, 0 },
919 /*d0*/ { "", TRUE, BYTE, op2(o1, E), db_Grp2 },
920 /*d1*/ { "", TRUE, LONG, op2(o1, E), db_Grp2 },
921 /*d2*/ { "", TRUE, BYTE, op2(CL, E), db_Grp2 },
922 /*d3*/ { "", TRUE, LONG, op2(CL, E), db_Grp2 },
923 /*d4*/ { "aam", FALSE, NONE, op1(Iba), 0 },
924 /*d5*/ { "aad", FALSE, NONE, op1(Iba), 0 },
925 /*d6*/ { ".byte\t0xd6", FALSE, NONE, 0, 0 },
926 /*d7*/ { "xlat", FALSE, BYTE, op1(BX), 0 },
928 /*d8*/ { "", TRUE, NONE, 0, db_Esc8 },
929 /*d9*/ { "", TRUE, NONE, 0, db_Esc9 },
930 /*da*/ { "", TRUE, NONE, 0, db_Esca },
931 /*db*/ { "", TRUE, NONE, 0, db_Escb },
932 /*dc*/ { "", TRUE, NONE, 0, db_Escc },
933 /*dd*/ { "", TRUE, NONE, 0, db_Escd },
934 /*de*/ { "", TRUE, NONE, 0, db_Esce },
935 /*df*/ { "", TRUE, NONE, 0, db_Escf },
937 /*e0*/ { "loopne",FALSE, NONE, op1(Db), 0 },
938 /*e1*/ { "loope", FALSE, NONE, op1(Db), 0 },
939 /*e2*/ { "loop", FALSE, NONE, op1(Db), 0 },
940 /*e3*/ { "jrcxz", FALSE, ADEP, op1(Db), "jecxz" },
941 /*e4*/ { "in", FALSE, BYTE, op2(Ib, A), 0 },
942 /*e5*/ { "in", FALSE, LONG, op2(Ib, A) , 0 },
943 /*e6*/ { "out", FALSE, BYTE, op2(A, Ib), 0 },
944 /*e7*/ { "out", FALSE, LONG, op2(A, Ib) , 0 },
946 /*e8*/ { "call", FALSE, NONE, op1(Dl), 0 },
947 /*e9*/ { "jmp", FALSE, NONE, op1(Dl), 0 },
948 /*ea*/ { "ljmp", FALSE, NONE, op1(OS), 0 },
949 /*eb*/ { "jmp", FALSE, NONE, op1(Db), 0 },
950 /*ec*/ { "in", FALSE, BYTE, op2(DX, A), 0 },
951 /*ed*/ { "in", FALSE, LONG, op2(DX, A) , 0 },
952 /*ee*/ { "out", FALSE, BYTE, op2(A, DX), 0 },
953 /*ef*/ { "out", FALSE, LONG, op2(A, DX) , 0 },
955 /*f0*/ { "", FALSE, NONE, 0, 0 },
956 /*f1*/ { ".byte\t0xf1", FALSE, NONE, 0, 0 },
957 /*f2*/ { "", FALSE, NONE, 0, 0 },
958 /*f3*/ { "", FALSE, NONE, 0, 0 },
959 /*f4*/ { "hlt", FALSE, NONE, 0, 0 },
960 /*f5*/ { "cmc", FALSE, NONE, 0, 0 },
961 /*f6*/ { "", TRUE, BYTE, 0, db_Grp3 },
962 /*f7*/ { "", TRUE, LONG, 0, db_Grp3 },
964 /*f8*/ { "clc", FALSE, NONE, 0, 0 },
965 /*f9*/ { "stc", FALSE, NONE, 0, 0 },
966 /*fa*/ { "cli", FALSE, NONE, 0, 0 },
967 /*fb*/ { "sti", FALSE, NONE, 0, 0 },
968 /*fc*/ { "cld", FALSE, NONE, 0, 0 },
969 /*fd*/ { "std", FALSE, NONE, 0, 0 },
970 /*fe*/ { "", TRUE, NONE, 0, db_Grp4 },
971 /*ff*/ { "", TRUE, NONE, 0, db_Grp5 },
974 static const struct inst db_bad_inst =
975 { "???", FALSE, NONE, 0, 0 }
978 #define f_mod(rex, byte) ((byte)>>6)
979 #define f_reg(rex, byte) ((((byte)>>3)&0x7) | (rex & REX_R ? 0x8 : 0x0))
980 #define f_rm(rex, byte) (((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0))
982 #define sib_ss(rex, byte) ((byte)>>6)
983 #define sib_index(rex, byte) ((((byte)>>3)&0x7) | (rex & REX_X ? 0x8 : 0x0))
984 #define sib_base(rex, byte) (((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0))
987 int is_reg; /* if reg, reg number is in 'disp' */
994 static const char * const db_reg[2][4][16] = {
996 {{"%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh",
997 "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" },
998 { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di",
999 "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" },
1000 { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
1001 "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" },
1002 { "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
1003 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }},
1005 {{"%al", "%cl", "%dl", "%bl", "%spl", "%bpl", "%sil", "%dil",
1006 "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" },
1007 { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di",
1008 "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" },
1009 { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
1010 "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" },
1011 { "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
1012 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }}
1015 static const char * const db_seg_reg[8] = {
1016 "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
1020 * lengths for size attributes
1022 static const int db_lengths[] = {
1032 #define get_value_inc(result, loc, size, is_signed) \
1033 result = db_get_value((loc), (size), (is_signed)); \
1037 db_disasm_esc(db_addr_t loc, int inst, int rex, int short_addr,
1038 int size, const char *seg);
1039 static void db_print_address(const char *seg, int size, int rex,
1040 struct i_addr *addrp);
1042 db_read_address(db_addr_t loc, int short_addr, int rex, int regmodrm,
1043 struct i_addr *addrp);
1046 * Read address at location and return updated location.
1049 db_read_address(loc, short_addr, rex, regmodrm, addrp)
1054 struct i_addr * addrp; /* out */
1056 int mod, rm, sib, index, disp, size, have_sib;
1058 mod = f_mod(rex, regmodrm);
1059 rm = f_rm(rex, regmodrm);
1062 addrp->is_reg = TRUE;
1066 addrp->is_reg = FALSE;
1067 addrp->index = NULL;
1074 if ((rm & 0x7) == 4) {
1075 get_value_inc(sib, loc, 1, FALSE);
1076 rm = sib_base(rex, sib);
1077 index = sib_index(rex, sib);
1079 addrp->index = db_reg[1][size][index];
1080 addrp->ss = sib_ss(rex, sib);
1088 get_value_inc(addrp->disp, loc, 4, FALSE);
1091 else if (short_addr)
1092 addrp->base = "%eip";
1094 addrp->base = "%rip";
1097 addrp->base = db_reg[1][size][rm];
1102 get_value_inc(disp, loc, 1, TRUE);
1104 addrp->base = db_reg[1][size][rm];
1108 get_value_inc(disp, loc, 4, FALSE);
1110 addrp->base = db_reg[1][size][rm];
1117 db_print_address(seg, size, rex, addrp)
1121 struct i_addr * addrp;
1123 if (addrp->is_reg) {
1124 db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][addrp->disp]);
1129 db_printf("%s:", seg);
1132 if (addrp->disp != 0 || (addrp->base == NULL && addrp->index == NULL))
1133 db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY);
1134 if (addrp->base != NULL || addrp->index != NULL) {
1137 db_printf("%s", addrp->base);
1139 db_printf(",%s,%d", addrp->index, 1<<addrp->ss);
1145 * Disassemble floating-point ("escape") instruction
1146 * and return updated location.
1149 db_disasm_esc(loc, inst, rex, short_addr, size, seg)
1158 const struct finst * fp;
1160 struct i_addr address;
1163 get_value_inc(regmodrm, loc, 1, FALSE);
1164 fp = &db_Esc_inst[inst - 0xd8][f_reg(rex, regmodrm)];
1165 mod = f_mod(rex, regmodrm);
1167 if (*fp->f_name == '\0') {
1168 db_printf("<bad instruction>");
1172 * Normal address modes.
1174 loc = db_read_address(loc, short_addr, rex, regmodrm, &address);
1175 db_printf("%s", fp->f_name);
1176 switch(fp->f_size) {
1199 db_print_address(seg, BYTE, rex, &address);
1203 * 'reg-reg' - special formats
1205 switch (fp->f_rrmode) {
1207 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1208 db_printf("%s\t%%st,%%st(%d)",name,f_rm(rex, regmodrm));
1211 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1212 db_printf("%s\t%%st(%d),%%st",name, f_rm(rex, regmodrm));
1215 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1216 db_printf("%s\t%%st(%d)",name, f_rm(rex, regmodrm));
1219 name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)];
1222 db_printf("%s", name);
1225 name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)];
1228 db_printf("%s\t%%ax", name);
1232 db_printf("<bad instruction>");
1241 * Disassemble instruction at 'loc'. 'altfmt' specifies an
1242 * (optional) alternate format. Return address of start of
1246 db_disasm(db_addr_t loc, bool altfmt)
1252 const struct inst * ip;
1253 const char * i_name;
1266 struct i_addr address;
1268 get_value_inc(inst, loc, 1, FALSE);
1281 case 0x66: /* data16 */
1309 * XXX repne/repe are only actually valid for MOVS, CMPS,
1310 * SCAS, LODS, STOS, INS, OUTS.
1322 if (inst >= 0x40 && inst < 0x50) {
1327 get_value_inc(inst, loc, 1, FALSE);
1331 if (inst >= 0xd8 && inst <= 0xdf) {
1332 loc = db_disasm_esc(loc, inst, rex, short_addr, size, seg);
1337 ip = &db_inst_table[inst];
1338 while (ip->i_size == ESC) {
1339 get_value_inc(inst, loc, 1, FALSE);
1340 ip = ((const struct inst * const *)ip->i_extra)[inst>>4];
1349 if (ip->i_has_modrm) {
1350 get_value_inc(regmodrm, loc, 1, FALSE);
1351 loc = db_read_address(loc, short_addr, rex, regmodrm, &address);
1354 i_name = ip->i_name;
1355 i_size = ip->i_size;
1356 i_mode = ip->i_mode;
1358 if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) == 3) {
1359 ip = &db_Grp9b[f_reg(rex, regmodrm)];
1360 i_name = ip->i_name;
1361 i_size = ip->i_size;
1362 i_mode = ip->i_mode;
1364 else if (ip->i_extra == db_Grp1 || ip->i_extra == db_Grp2 ||
1365 ip->i_extra == db_Grp6 || ip->i_extra == db_Grp7 ||
1366 ip->i_extra == db_Grp8 || ip->i_extra == db_Grp9 ||
1367 ip->i_extra == db_Grp15) {
1368 i_name = ((const char * const *)ip->i_extra)[f_reg(rex, regmodrm)];
1370 else if (ip->i_extra == db_Grp3) {
1372 ip = &ip[f_reg(rex, regmodrm)];
1373 i_name = ip->i_name;
1374 i_mode = ip->i_mode;
1376 else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) {
1378 ip = &ip[f_reg(rex, regmodrm)];
1379 i_name = ip->i_name;
1380 i_mode = ip->i_mode;
1381 i_size = ip->i_size;
1384 /* Special cases that don't fit well in the tables. */
1385 if (ip->i_extra == db_Grp7 && f_mod(rex, regmodrm) == 3) {
1393 i_name = "vmlaunch";
1398 i_name = "vmresume";
1489 if (ip->i_extra == db_Grp15 && f_mod(rex, regmodrm) == 3) {
1490 i_name = db_Grp15b[f_reg(rex, regmodrm)];
1495 /* Handle instructions identified by mandatory prefixes. */
1502 } else if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) != 3 &&
1503 f_reg(rex, regmodrm) == 0x6) {
1508 /* N.B., likely highly incomplete. */
1510 if (ip == &db_inst_0f38fx[0] || ip == &db_inst_0f38fx[1])
1514 if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) != 3 &&
1515 f_reg(rex, regmodrm) == 0x6) {
1520 if (strcmp(i_name, "cwde") == 0)
1522 else if (strcmp(i_name, "cmpxchg8b") == 0)
1523 i_name = "cmpxchg16b";
1527 db_printf("repe "); /* XXX repe VS rep */
1529 db_printf("repne ");
1531 if (i_size == SDEP) {
1533 db_printf("%s", i_name);
1535 db_printf("%s", (const char *)ip->i_extra);
1536 } else if (i_size == ADEP) {
1537 if (short_addr == FALSE)
1538 db_printf("%s", i_name);
1540 db_printf("%s", (const char *)ip->i_extra);
1543 db_printf("%s", i_name);
1544 if ((inst >= 0x50 && inst <= 0x5f) || inst == 0x68 || inst == 0x6a) {
1548 if (i_size != NONE) {
1549 if (i_size == BYTE) {
1553 else if (i_size == WORD) {
1557 else if (size == WORD)
1570 i_mode >>= 8, first = FALSE)
1575 switch (i_mode & 0xFF) {
1578 db_print_address(seg, size, rex, &address);
1583 db_print_address(seg, size, rex, &address);
1587 db_print_address(seg, (rex & REX_W) ? QUAD : LONG, rex, &address);
1591 db_print_address(seg, LONG, 0, &address);
1595 db_print_address(seg, WORD, rex, &address);
1599 db_print_address(seg, BYTE, rex, &address);
1603 db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][f_reg(rex, regmodrm)]);
1607 db_printf("%s", db_reg[rex != 0 ? 1 : 0][WORD][f_reg(rex, regmodrm)]);
1611 db_printf("%s", db_reg[rex != 0 ? 1 : 0][QUAD][f_reg(rex, regmodrm)]);
1615 db_printf("%s", db_reg[0][QUAD][f_rm(rex, inst)]);
1619 db_printf("%s", db_reg[rex != 0 ? 1 : 0][(rex & REX_R) ? QUAD : LONG][f_rm(rex, inst)]);
1623 db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][f_rm(rex, regmodrm)]);
1627 db_printf("%s", db_seg_reg[f_reg(rex, regmodrm)]);
1631 db_printf("%s", db_seg_reg[f_reg(rex, inst)]);
1635 db_printf("%s", db_reg[rex != 0 ? 1 : 0][size][0]); /* acc */
1640 db_printf("%s:", seg);
1641 db_printf("(%s)", short_addr ? "%bx" : "%ebx");
1654 db_printf("%s:", seg);
1655 db_printf("(%s)", short_addr ? "%si" : "%rsi");
1659 db_printf("%%es:(%s)", short_addr ? "%di" : "%rdi");
1663 db_printf("%%cr%d", f_reg(rex, regmodrm));
1667 db_printf("%%dr%d", f_reg(rex, regmodrm));
1671 db_printf("%%tr%d", f_reg(rex, regmodrm));
1675 len = db_lengths[size];
1676 get_value_inc(imm, loc, len, FALSE);
1677 db_printf("$%#r", imm);
1681 len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
1682 get_value_inc(imm, loc, len, FALSE);
1683 db_printf("$%+#r", imm);
1687 get_value_inc(imm, loc, 1, FALSE);
1688 db_printf("$%#r", imm);
1692 get_value_inc(imm, loc, 1, FALSE);
1694 db_printf("$%#r", imm);
1698 get_value_inc(imm, loc, 1, TRUE);
1701 db_printf("$%+#r", imm);
1705 get_value_inc(imm, loc, 2, FALSE);
1706 db_printf("$%#r", imm);
1710 len = db_lengths[rex & REX_W ? QUAD : LONG];
1711 get_value_inc(imm64, loc, len, FALSE);
1712 db_printf("$%#lr", imm64);
1716 len = (short_addr ? 2 : 4);
1717 get_value_inc(displ, loc, len, FALSE);
1719 db_printf("%s:%+#r",seg, displ);
1721 db_printsym((db_addr_t)displ, DB_STGY_ANY);
1725 get_value_inc(displ, loc, 1, TRUE);
1729 db_printsym((db_addr_t)displ, DB_STGY_XTRN);
1733 len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
1734 get_value_inc(displ, loc, len, FALSE);
1738 db_printsym((db_addr_t)displ, DB_STGY_XTRN);
1750 len = db_lengths[size];
1751 get_value_inc(imm, loc, len, FALSE); /* offset */
1752 get_value_inc(imm2, loc, 2, FALSE); /* segment */
1753 db_printf("$%#r,%#r", imm2, imm);