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 * const db_inst_0f38[] = {
167 static const char * const db_Grp6[] = {
178 static const char * const db_Grp7[] = {
189 static const char * const db_Grp8[] = {
200 static const char * const db_Grp9[] = {
211 static const char * const db_Grp15[] = {
222 static const char * const db_Grp15b[] = {
233 static const struct inst db_inst_0f0x[] = {
234 /*00*/ { "", TRUE, NONE, op1(Ew), db_Grp6 },
235 /*01*/ { "", TRUE, NONE, op1(Ew), db_Grp7 },
236 /*02*/ { "lar", TRUE, LONG, op2(E,R), 0 },
237 /*03*/ { "lsl", TRUE, LONG, op2(E,R), 0 },
238 /*04*/ { "", FALSE, NONE, 0, 0 },
239 /*05*/ { "syscall",FALSE,NONE, 0, 0 },
240 /*06*/ { "clts", FALSE, NONE, 0, 0 },
241 /*07*/ { "sysret",FALSE, NONE, 0, 0 },
243 /*08*/ { "invd", FALSE, NONE, 0, 0 },
244 /*09*/ { "wbinvd",FALSE, NONE, 0, 0 },
245 /*0a*/ { "", FALSE, NONE, 0, 0 },
246 /*0b*/ { "", FALSE, NONE, 0, 0 },
247 /*0c*/ { "", FALSE, NONE, 0, 0 },
248 /*0d*/ { "", FALSE, NONE, 0, 0 },
249 /*0e*/ { "", FALSE, NONE, 0, 0 },
250 /*0f*/ { "", FALSE, NONE, 0, 0 },
253 static const struct inst db_inst_0f2x[] = {
254 /*20*/ { "mov", TRUE, LONG, op2(CR,El), 0 },
255 /*21*/ { "mov", TRUE, LONG, op2(DR,El), 0 },
256 /*22*/ { "mov", TRUE, LONG, op2(El,CR), 0 },
257 /*23*/ { "mov", TRUE, LONG, op2(El,DR), 0 },
258 /*24*/ { "mov", TRUE, LONG, op2(TR,El), 0 },
259 /*25*/ { "", FALSE, NONE, 0, 0 },
260 /*26*/ { "mov", TRUE, LONG, op2(El,TR), 0 },
261 /*27*/ { "", FALSE, NONE, 0, 0 },
263 /*28*/ { "", FALSE, NONE, 0, 0 },
264 /*29*/ { "", FALSE, NONE, 0, 0 },
265 /*2a*/ { "", FALSE, NONE, 0, 0 },
266 /*2b*/ { "", FALSE, NONE, 0, 0 },
267 /*2c*/ { "", FALSE, NONE, 0, 0 },
268 /*2d*/ { "", FALSE, NONE, 0, 0 },
269 /*2e*/ { "", FALSE, NONE, 0, 0 },
270 /*2f*/ { "", FALSE, NONE, 0, 0 },
273 static const struct inst db_inst_0f3x[] = {
274 /*30*/ { "wrmsr", FALSE, NONE, 0, 0 },
275 /*31*/ { "rdtsc", FALSE, NONE, 0, 0 },
276 /*32*/ { "rdmsr", FALSE, NONE, 0, 0 },
277 /*33*/ { "rdpmc", FALSE, NONE, 0, 0 },
278 /*34*/ { "sysenter",FALSE,NONE, 0, 0 },
279 /*35*/ { "sysexit",FALSE,NONE, 0, 0 },
280 /*36*/ { "", FALSE, NONE, 0, 0 },
281 /*37*/ { "getsec",FALSE, NONE, 0, 0 },
283 /*38*/ { "", FALSE, ESC, 0, db_inst_0f38 },
284 /*39*/ { "", FALSE, NONE, 0, 0 },
285 /*3a*/ { "", FALSE, NONE, 0, 0 },
286 /*3b*/ { "", FALSE, NONE, 0, 0 },
287 /*3c*/ { "", FALSE, NONE, 0, 0 },
288 /*3d*/ { "", FALSE, NONE, 0, 0 },
289 /*3e*/ { "", FALSE, NONE, 0, 0 },
290 /*3f*/ { "", FALSE, NONE, 0, 0 },
293 static const struct inst db_inst_0f4x[] = {
294 /*40*/ { "cmovo", TRUE, NONE, op2(E, R), 0 },
295 /*41*/ { "cmovno", TRUE, NONE, op2(E, R), 0 },
296 /*42*/ { "cmovb", TRUE, NONE, op2(E, R), 0 },
297 /*43*/ { "cmovnb", TRUE, NONE, op2(E, R), 0 },
298 /*44*/ { "cmovz", TRUE, NONE, op2(E, R), 0 },
299 /*45*/ { "cmovnz", TRUE, NONE, op2(E, R), 0 },
300 /*46*/ { "cmovbe", TRUE, NONE, op2(E, R), 0 },
301 /*47*/ { "cmovnbe",TRUE, NONE, op2(E, R), 0 },
303 /*48*/ { "cmovs", TRUE, NONE, op2(E, R), 0 },
304 /*49*/ { "cmovns", TRUE, NONE, op2(E, R), 0 },
305 /*4a*/ { "cmovp", TRUE, NONE, op2(E, R), 0 },
306 /*4b*/ { "cmovnp", TRUE, NONE, op2(E, R), 0 },
307 /*4c*/ { "cmovl", TRUE, NONE, op2(E, R), 0 },
308 /*4d*/ { "cmovnl", TRUE, NONE, op2(E, R), 0 },
309 /*4e*/ { "cmovle", TRUE, NONE, op2(E, R), 0 },
310 /*4f*/ { "cmovnle",TRUE, NONE, op2(E, R), 0 },
313 static const struct inst db_inst_0f7x[] = {
314 /*70*/ { "", FALSE, NONE, 0, 0 },
315 /*71*/ { "", FALSE, NONE, 0, 0 },
316 /*72*/ { "", FALSE, NONE, 0, 0 },
317 /*73*/ { "", FALSE, NONE, 0, 0 },
318 /*74*/ { "", FALSE, NONE, 0, 0 },
319 /*75*/ { "", FALSE, NONE, 0, 0 },
320 /*76*/ { "", FALSE, NONE, 0, 0 },
321 /*77*/ { "", FALSE, NONE, 0, 0 },
323 /*78*/ { "vmread", TRUE, NONE, op2(Rq, E), 0 },
324 /*79*/ { "vmwrite",TRUE, NONE, op2(E, Rq), 0 },
325 /*7a*/ { "", FALSE, NONE, 0, 0 },
326 /*7b*/ { "", FALSE, NONE, 0, 0 },
327 /*7c*/ { "", FALSE, NONE, 0, 0 },
328 /*7d*/ { "", FALSE, NONE, 0, 0 },
329 /*7e*/ { "", FALSE, NONE, 0, 0 },
330 /*7f*/ { "", FALSE, NONE, 0, 0 },
333 static const struct inst db_inst_0f8x[] = {
334 /*80*/ { "jo", FALSE, NONE, op1(Dl), 0 },
335 /*81*/ { "jno", FALSE, NONE, op1(Dl), 0 },
336 /*82*/ { "jb", FALSE, NONE, op1(Dl), 0 },
337 /*83*/ { "jnb", FALSE, NONE, op1(Dl), 0 },
338 /*84*/ { "jz", FALSE, NONE, op1(Dl), 0 },
339 /*85*/ { "jnz", FALSE, NONE, op1(Dl), 0 },
340 /*86*/ { "jbe", FALSE, NONE, op1(Dl), 0 },
341 /*87*/ { "jnbe", FALSE, NONE, op1(Dl), 0 },
343 /*88*/ { "js", FALSE, NONE, op1(Dl), 0 },
344 /*89*/ { "jns", FALSE, NONE, op1(Dl), 0 },
345 /*8a*/ { "jp", FALSE, NONE, op1(Dl), 0 },
346 /*8b*/ { "jnp", FALSE, NONE, op1(Dl), 0 },
347 /*8c*/ { "jl", FALSE, NONE, op1(Dl), 0 },
348 /*8d*/ { "jnl", FALSE, NONE, op1(Dl), 0 },
349 /*8e*/ { "jle", FALSE, NONE, op1(Dl), 0 },
350 /*8f*/ { "jnle", FALSE, NONE, op1(Dl), 0 },
353 static const struct inst db_inst_0f9x[] = {
354 /*90*/ { "seto", TRUE, NONE, op1(Eb), 0 },
355 /*91*/ { "setno", TRUE, NONE, op1(Eb), 0 },
356 /*92*/ { "setb", TRUE, NONE, op1(Eb), 0 },
357 /*93*/ { "setnb", TRUE, NONE, op1(Eb), 0 },
358 /*94*/ { "setz", TRUE, NONE, op1(Eb), 0 },
359 /*95*/ { "setnz", TRUE, NONE, op1(Eb), 0 },
360 /*96*/ { "setbe", TRUE, NONE, op1(Eb), 0 },
361 /*97*/ { "setnbe",TRUE, NONE, op1(Eb), 0 },
363 /*98*/ { "sets", TRUE, NONE, op1(Eb), 0 },
364 /*99*/ { "setns", TRUE, NONE, op1(Eb), 0 },
365 /*9a*/ { "setp", TRUE, NONE, op1(Eb), 0 },
366 /*9b*/ { "setnp", TRUE, NONE, op1(Eb), 0 },
367 /*9c*/ { "setl", TRUE, NONE, op1(Eb), 0 },
368 /*9d*/ { "setnl", TRUE, NONE, op1(Eb), 0 },
369 /*9e*/ { "setle", TRUE, NONE, op1(Eb), 0 },
370 /*9f*/ { "setnle",TRUE, NONE, op1(Eb), 0 },
373 static const struct inst db_inst_0fax[] = {
374 /*a0*/ { "push", FALSE, NONE, op1(Si), 0 },
375 /*a1*/ { "pop", FALSE, NONE, op1(Si), 0 },
376 /*a2*/ { "cpuid", FALSE, NONE, 0, 0 },
377 /*a3*/ { "bt", TRUE, LONG, op2(R,E), 0 },
378 /*a4*/ { "shld", TRUE, LONG, op3(Ib,R,E), 0 },
379 /*a5*/ { "shld", TRUE, LONG, op3(CL,R,E), 0 },
380 /*a6*/ { "", FALSE, NONE, 0, 0 },
381 /*a7*/ { "", FALSE, NONE, 0, 0 },
383 /*a8*/ { "push", FALSE, NONE, op1(Si), 0 },
384 /*a9*/ { "pop", FALSE, NONE, op1(Si), 0 },
385 /*aa*/ { "rsm", FALSE, NONE, 0, 0 },
386 /*ab*/ { "bts", TRUE, LONG, op2(R,E), 0 },
387 /*ac*/ { "shrd", TRUE, LONG, op3(Ib,R,E), 0 },
388 /*ad*/ { "shrd", TRUE, LONG, op3(CL,R,E), 0 },
389 /*ae*/ { "", TRUE, LONG, op1(E), db_Grp15 },
390 /*af*/ { "imul", TRUE, LONG, op2(E,R), 0 },
393 static const struct inst db_inst_0fbx[] = {
394 /*b0*/ { "cmpxchg",TRUE, BYTE, op2(R, E), 0 },
395 /*b0*/ { "cmpxchg",TRUE, LONG, op2(R, E), 0 },
396 /*b2*/ { "lss", TRUE, LONG, op2(E, R), 0 },
397 /*b3*/ { "btr", TRUE, LONG, op2(R, E), 0 },
398 /*b4*/ { "lfs", TRUE, LONG, op2(E, R), 0 },
399 /*b5*/ { "lgs", TRUE, LONG, op2(E, R), 0 },
400 /*b6*/ { "movzb", TRUE, LONG, op2(Eb, R), 0 },
401 /*b7*/ { "movzw", TRUE, LONG, op2(Ew, R), 0 },
403 /*b8*/ { "", FALSE, NONE, 0, 0 },
404 /*b9*/ { "", FALSE, NONE, 0, 0 },
405 /*ba*/ { "", TRUE, LONG, op2(Ib, E), db_Grp8 },
406 /*bb*/ { "btc", TRUE, LONG, op2(R, E), 0 },
407 /*bc*/ { "bsf", TRUE, LONG, op2(E, R), 0 },
408 /*bd*/ { "bsr", TRUE, LONG, op2(E, R), 0 },
409 /*be*/ { "movsb", TRUE, LONG, op2(Eb, R), 0 },
410 /*bf*/ { "movsw", TRUE, LONG, op2(Ew, R), 0 },
413 static const struct inst db_inst_0fcx[] = {
414 /*c0*/ { "xadd", TRUE, BYTE, op2(R, E), 0 },
415 /*c1*/ { "xadd", TRUE, LONG, op2(R, E), 0 },
416 /*c2*/ { "", FALSE, NONE, 0, 0 },
417 /*c3*/ { "", FALSE, NONE, 0, 0 },
418 /*c4*/ { "", FALSE, NONE, 0, 0 },
419 /*c5*/ { "", FALSE, NONE, 0, 0 },
420 /*c6*/ { "", FALSE, NONE, 0, 0 },
421 /*c7*/ { "", TRUE, NONE, op1(E), db_Grp9 },
422 /*c8*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
423 /*c9*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
424 /*ca*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
425 /*cb*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
426 /*cc*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
427 /*cd*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
428 /*ce*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
429 /*cf*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
432 static const struct inst * const db_inst_0f[] = {
451 static const char * const db_Esc92[] = {
452 "fnop", "", "", "", "", "", "", ""
454 static const char * const db_Esc94[] = {
455 "fchs", "fabs", "", "", "ftst", "fxam", "", ""
457 static const char * const db_Esc95[] = {
458 "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
460 static const char * const db_Esc96[] = {
461 "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
464 static const char * const db_Esc97[] = {
465 "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
468 static const char * const db_Esca5[] = {
469 "", "fucompp","", "", "", "", "", ""
472 static const char * const db_Escb4[] = {
473 "fneni","fndisi", "fnclex","fninit","fsetpm", "", "", ""
476 static const char * const db_Esce3[] = {
477 "", "fcompp","", "", "", "", "", ""
480 static const char * const db_Escf4[] = {
481 "fnstsw","", "", "", "", "", "", ""
484 static const struct finst db_Esc8[] = {
485 /*0*/ { "fadd", SNGL, op2(STI,ST), 0 },
486 /*1*/ { "fmul", SNGL, op2(STI,ST), 0 },
487 /*2*/ { "fcom", SNGL, op2(STI,ST), 0 },
488 /*3*/ { "fcomp", SNGL, op2(STI,ST), 0 },
489 /*4*/ { "fsub", SNGL, op2(STI,ST), 0 },
490 /*5*/ { "fsubr", SNGL, op2(STI,ST), 0 },
491 /*6*/ { "fdiv", SNGL, op2(STI,ST), 0 },
492 /*7*/ { "fdivr", SNGL, op2(STI,ST), 0 },
495 static const struct finst db_Esc9[] = {
496 /*0*/ { "fld", SNGL, op1(STI), 0 },
497 /*1*/ { "", NONE, op1(STI), "fxch" },
498 /*2*/ { "fst", SNGL, op1(X), db_Esc92 },
499 /*3*/ { "fstp", SNGL, 0, 0 },
500 /*4*/ { "fldenv", NONE, op1(X), db_Esc94 },
501 /*5*/ { "fldcw", NONE, op1(X), db_Esc95 },
502 /*6*/ { "fnstenv",NONE, op1(X), db_Esc96 },
503 /*7*/ { "fnstcw", NONE, op1(X), db_Esc97 },
506 static const struct finst db_Esca[] = {
507 /*0*/ { "fiadd", LONG, 0, 0 },
508 /*1*/ { "fimul", LONG, 0, 0 },
509 /*2*/ { "ficom", LONG, 0, 0 },
510 /*3*/ { "ficomp", LONG, 0, 0 },
511 /*4*/ { "fisub", LONG, 0, 0 },
512 /*5*/ { "fisubr", LONG, op1(X), db_Esca5 },
513 /*6*/ { "fidiv", LONG, 0, 0 },
514 /*7*/ { "fidivr", LONG, 0, 0 }
517 static const struct finst db_Escb[] = {
518 /*0*/ { "fild", LONG, 0, 0 },
519 /*1*/ { "", NONE, 0, 0 },
520 /*2*/ { "fist", LONG, 0, 0 },
521 /*3*/ { "fistp", LONG, 0, 0 },
522 /*4*/ { "", WORD, op1(X), db_Escb4 },
523 /*5*/ { "fld", EXTR, 0, 0 },
524 /*6*/ { "", WORD, 0, 0 },
525 /*7*/ { "fstp", EXTR, 0, 0 },
528 static const struct finst db_Escc[] = {
529 /*0*/ { "fadd", DBLR, op2(ST,STI), 0 },
530 /*1*/ { "fmul", DBLR, op2(ST,STI), 0 },
531 /*2*/ { "fcom", DBLR, 0, 0 },
532 /*3*/ { "fcomp", DBLR, 0, 0 },
533 /*4*/ { "fsub", DBLR, op2(ST,STI), "fsubr" },
534 /*5*/ { "fsubr", DBLR, op2(ST,STI), "fsub" },
535 /*6*/ { "fdiv", DBLR, op2(ST,STI), "fdivr" },
536 /*7*/ { "fdivr", DBLR, op2(ST,STI), "fdiv" },
539 static const struct finst db_Escd[] = {
540 /*0*/ { "fld", DBLR, op1(STI), "ffree" },
541 /*1*/ { "", NONE, 0, 0 },
542 /*2*/ { "fst", DBLR, op1(STI), 0 },
543 /*3*/ { "fstp", DBLR, op1(STI), 0 },
544 /*4*/ { "frstor", NONE, op1(STI), "fucom" },
545 /*5*/ { "", NONE, op1(STI), "fucomp" },
546 /*6*/ { "fnsave", NONE, 0, 0 },
547 /*7*/ { "fnstsw", NONE, 0, 0 },
550 static const struct finst db_Esce[] = {
551 /*0*/ { "fiadd", WORD, op2(ST,STI), "faddp" },
552 /*1*/ { "fimul", WORD, op2(ST,STI), "fmulp" },
553 /*2*/ { "ficom", WORD, 0, 0 },
554 /*3*/ { "ficomp", WORD, op1(X), db_Esce3 },
555 /*4*/ { "fisub", WORD, op2(ST,STI), "fsubrp" },
556 /*5*/ { "fisubr", WORD, op2(ST,STI), "fsubp" },
557 /*6*/ { "fidiv", WORD, op2(ST,STI), "fdivrp" },
558 /*7*/ { "fidivr", WORD, op2(ST,STI), "fdivp" },
561 static const struct finst db_Escf[] = {
562 /*0*/ { "fild", WORD, 0, 0 },
563 /*1*/ { "", NONE, 0, 0 },
564 /*2*/ { "fist", WORD, 0, 0 },
565 /*3*/ { "fistp", WORD, 0, 0 },
566 /*4*/ { "fbld", NONE, op1(XA), db_Escf4 },
567 /*5*/ { "fild", QUAD, 0, 0 },
568 /*6*/ { "fbstp", NONE, 0, 0 },
569 /*7*/ { "fistp", QUAD, 0, 0 },
572 static const struct finst * const db_Esc_inst[] = {
573 db_Esc8, db_Esc9, db_Esca, db_Escb,
574 db_Escc, db_Escd, db_Esce, db_Escf
577 static const char * const db_Grp1[] = {
588 static const char * const db_Grp2[] = {
599 static const struct inst db_Grp3[] = {
600 { "test", TRUE, NONE, op2(I,E), 0 },
601 { "test", TRUE, NONE, op2(I,E), 0 },
602 { "not", TRUE, NONE, op1(E), 0 },
603 { "neg", TRUE, NONE, op1(E), 0 },
604 { "mul", TRUE, NONE, op2(E,A), 0 },
605 { "imul", TRUE, NONE, op2(E,A), 0 },
606 { "div", TRUE, NONE, op2(E,A), 0 },
607 { "idiv", TRUE, NONE, op2(E,A), 0 },
610 static const struct inst db_Grp4[] = {
611 { "inc", TRUE, BYTE, op1(E), 0 },
612 { "dec", TRUE, BYTE, op1(E), 0 },
613 { "", TRUE, NONE, 0, 0 },
614 { "", TRUE, NONE, 0, 0 },
615 { "", TRUE, NONE, 0, 0 },
616 { "", TRUE, NONE, 0, 0 },
617 { "", TRUE, NONE, 0, 0 },
618 { "", TRUE, NONE, 0, 0 }
621 static const struct inst db_Grp5[] = {
622 { "inc", TRUE, LONG, op1(E), 0 },
623 { "dec", TRUE, LONG, op1(E), 0 },
624 { "call", TRUE, LONG, op1(Eind),0 },
625 { "lcall", TRUE, LONG, op1(Eind),0 },
626 { "jmp", TRUE, LONG, op1(Eind),0 },
627 { "ljmp", TRUE, LONG, op1(Eind),0 },
628 { "push", TRUE, LONG, op1(E), 0 },
629 { "", TRUE, NONE, 0, 0 }
632 static const struct inst db_Grp9b[] = {
633 { "", TRUE, NONE, 0, 0 },
634 { "", TRUE, NONE, 0, 0 },
635 { "", TRUE, NONE, 0, 0 },
636 { "", TRUE, NONE, 0, 0 },
637 { "", TRUE, NONE, 0, 0 },
638 { "", TRUE, NONE, 0, 0 },
639 { "rdrand",TRUE, LONG, op1(Rv), 0 },
640 { "rdseed",TRUE, LONG, op1(Rv), 0 }
643 static const struct inst db_inst_table[256] = {
644 /*00*/ { "add", TRUE, BYTE, op2(R, E), 0 },
645 /*01*/ { "add", TRUE, LONG, op2(R, E), 0 },
646 /*02*/ { "add", TRUE, BYTE, op2(E, R), 0 },
647 /*03*/ { "add", TRUE, LONG, op2(E, R), 0 },
648 /*04*/ { "add", FALSE, BYTE, op2(I, A), 0 },
649 /*05*/ { "add", FALSE, LONG, op2(Is, A), 0 },
650 /*06*/ { "push", FALSE, NONE, op1(Si), 0 },
651 /*07*/ { "pop", FALSE, NONE, op1(Si), 0 },
653 /*08*/ { "or", TRUE, BYTE, op2(R, E), 0 },
654 /*09*/ { "or", TRUE, LONG, op2(R, E), 0 },
655 /*0a*/ { "or", TRUE, BYTE, op2(E, R), 0 },
656 /*0b*/ { "or", TRUE, LONG, op2(E, R), 0 },
657 /*0c*/ { "or", FALSE, BYTE, op2(I, A), 0 },
658 /*0d*/ { "or", FALSE, LONG, op2(I, A), 0 },
659 /*0e*/ { "push", FALSE, NONE, op1(Si), 0 },
660 /*0f*/ { "", FALSE, ESC, 0, db_inst_0f },
662 /*10*/ { "adc", TRUE, BYTE, op2(R, E), 0 },
663 /*11*/ { "adc", TRUE, LONG, op2(R, E), 0 },
664 /*12*/ { "adc", TRUE, BYTE, op2(E, R), 0 },
665 /*13*/ { "adc", TRUE, LONG, op2(E, R), 0 },
666 /*14*/ { "adc", FALSE, BYTE, op2(I, A), 0 },
667 /*15*/ { "adc", FALSE, LONG, op2(Is, A), 0 },
668 /*16*/ { "push", FALSE, NONE, op1(Si), 0 },
669 /*17*/ { "pop", FALSE, NONE, op1(Si), 0 },
671 /*18*/ { "sbb", TRUE, BYTE, op2(R, E), 0 },
672 /*19*/ { "sbb", TRUE, LONG, op2(R, E), 0 },
673 /*1a*/ { "sbb", TRUE, BYTE, op2(E, R), 0 },
674 /*1b*/ { "sbb", TRUE, LONG, op2(E, R), 0 },
675 /*1c*/ { "sbb", FALSE, BYTE, op2(I, A), 0 },
676 /*1d*/ { "sbb", FALSE, LONG, op2(Is, A), 0 },
677 /*1e*/ { "push", FALSE, NONE, op1(Si), 0 },
678 /*1f*/ { "pop", FALSE, NONE, op1(Si), 0 },
680 /*20*/ { "and", TRUE, BYTE, op2(R, E), 0 },
681 /*21*/ { "and", TRUE, LONG, op2(R, E), 0 },
682 /*22*/ { "and", TRUE, BYTE, op2(E, R), 0 },
683 /*23*/ { "and", TRUE, LONG, op2(E, R), 0 },
684 /*24*/ { "and", FALSE, BYTE, op2(I, A), 0 },
685 /*25*/ { "and", FALSE, LONG, op2(I, A), 0 },
686 /*26*/ { "", FALSE, NONE, 0, 0 },
687 /*27*/ { "daa", FALSE, NONE, 0, 0 },
689 /*28*/ { "sub", TRUE, BYTE, op2(R, E), 0 },
690 /*29*/ { "sub", TRUE, LONG, op2(R, E), 0 },
691 /*2a*/ { "sub", TRUE, BYTE, op2(E, R), 0 },
692 /*2b*/ { "sub", TRUE, LONG, op2(E, R), 0 },
693 /*2c*/ { "sub", FALSE, BYTE, op2(I, A), 0 },
694 /*2d*/ { "sub", FALSE, LONG, op2(Is, A), 0 },
695 /*2e*/ { "", FALSE, NONE, 0, 0 },
696 /*2f*/ { "das", FALSE, NONE, 0, 0 },
698 /*30*/ { "xor", TRUE, BYTE, op2(R, E), 0 },
699 /*31*/ { "xor", TRUE, LONG, op2(R, E), 0 },
700 /*32*/ { "xor", TRUE, BYTE, op2(E, R), 0 },
701 /*33*/ { "xor", TRUE, LONG, op2(E, R), 0 },
702 /*34*/ { "xor", FALSE, BYTE, op2(I, A), 0 },
703 /*35*/ { "xor", FALSE, LONG, op2(I, A), 0 },
704 /*36*/ { "", FALSE, NONE, 0, 0 },
705 /*37*/ { "aaa", FALSE, NONE, 0, 0 },
707 /*38*/ { "cmp", TRUE, BYTE, op2(R, E), 0 },
708 /*39*/ { "cmp", TRUE, LONG, op2(R, E), 0 },
709 /*3a*/ { "cmp", TRUE, BYTE, op2(E, R), 0 },
710 /*3b*/ { "cmp", TRUE, LONG, op2(E, R), 0 },
711 /*3c*/ { "cmp", FALSE, BYTE, op2(I, A), 0 },
712 /*3d*/ { "cmp", FALSE, LONG, op2(Is, A), 0 },
713 /*3e*/ { "", FALSE, NONE, 0, 0 },
714 /*3f*/ { "aas", FALSE, NONE, 0, 0 },
716 /*40*/ { "rex", FALSE, NONE, 0, 0 },
717 /*41*/ { "rex.b", FALSE, NONE, 0, 0 },
718 /*42*/ { "rex.x", FALSE, NONE, 0, 0 },
719 /*43*/ { "rex.xb", FALSE, NONE, 0, 0 },
720 /*44*/ { "rex.r", FALSE, NONE, 0, 0 },
721 /*45*/ { "rex.rb", FALSE, NONE, 0, 0 },
722 /*46*/ { "rex.rx", FALSE, NONE, 0, 0 },
723 /*47*/ { "rex.rxb", FALSE, NONE, 0, 0 },
725 /*48*/ { "rex.w", FALSE, NONE, 0, 0 },
726 /*49*/ { "rex.wb", FALSE, NONE, 0, 0 },
727 /*4a*/ { "rex.wx", FALSE, NONE, 0, 0 },
728 /*4b*/ { "rex.wxb", FALSE, NONE, 0, 0 },
729 /*4c*/ { "rex.wr", FALSE, NONE, 0, 0 },
730 /*4d*/ { "rex.wrb", FALSE, NONE, 0, 0 },
731 /*4e*/ { "rex.wrx", FALSE, NONE, 0, 0 },
732 /*4f*/ { "rex.wrxb", FALSE, NONE, 0, 0 },
734 /*50*/ { "push", FALSE, LONG, op1(Ri), 0 },
735 /*51*/ { "push", FALSE, LONG, op1(Ri), 0 },
736 /*52*/ { "push", FALSE, LONG, op1(Ri), 0 },
737 /*53*/ { "push", FALSE, LONG, op1(Ri), 0 },
738 /*54*/ { "push", FALSE, LONG, op1(Ri), 0 },
739 /*55*/ { "push", FALSE, LONG, op1(Ri), 0 },
740 /*56*/ { "push", FALSE, LONG, op1(Ri), 0 },
741 /*57*/ { "push", FALSE, LONG, op1(Ri), 0 },
743 /*58*/ { "pop", FALSE, LONG, op1(Ri), 0 },
744 /*59*/ { "pop", FALSE, LONG, op1(Ri), 0 },
745 /*5a*/ { "pop", FALSE, LONG, op1(Ri), 0 },
746 /*5b*/ { "pop", FALSE, LONG, op1(Ri), 0 },
747 /*5c*/ { "pop", FALSE, LONG, op1(Ri), 0 },
748 /*5d*/ { "pop", FALSE, LONG, op1(Ri), 0 },
749 /*5e*/ { "pop", FALSE, LONG, op1(Ri), 0 },
750 /*5f*/ { "pop", FALSE, LONG, op1(Ri), 0 },
752 /*60*/ { "pusha", FALSE, LONG, 0, 0 },
753 /*61*/ { "popa", FALSE, LONG, 0, 0 },
754 /*62*/ { "bound", TRUE, LONG, op2(E, R), 0 },
755 /*63*/ { "movslq", TRUE, NONE, op2(EL,R), 0 },
757 /*64*/ { "", FALSE, NONE, 0, 0 },
758 /*65*/ { "", FALSE, NONE, 0, 0 },
759 /*66*/ { "", FALSE, NONE, 0, 0 },
760 /*67*/ { "", FALSE, NONE, 0, 0 },
762 /*68*/ { "push", FALSE, LONG, op1(I), 0 },
763 /*69*/ { "imul", TRUE, LONG, op3(I,E,R), 0 },
764 /*6a*/ { "push", FALSE, LONG, op1(Ibs), 0 },
765 /*6b*/ { "imul", TRUE, LONG, op3(Ibs,E,R),0 },
766 /*6c*/ { "ins", FALSE, BYTE, op2(DX, DI), 0 },
767 /*6d*/ { "ins", FALSE, LONG, op2(DX, DI), 0 },
768 /*6e*/ { "outs", FALSE, BYTE, op2(SI, DX), 0 },
769 /*6f*/ { "outs", FALSE, LONG, op2(SI, DX), 0 },
771 /*70*/ { "jo", FALSE, NONE, op1(Db), 0 },
772 /*71*/ { "jno", FALSE, NONE, op1(Db), 0 },
773 /*72*/ { "jb", FALSE, NONE, op1(Db), 0 },
774 /*73*/ { "jnb", FALSE, NONE, op1(Db), 0 },
775 /*74*/ { "jz", FALSE, NONE, op1(Db), 0 },
776 /*75*/ { "jnz", FALSE, NONE, op1(Db), 0 },
777 /*76*/ { "jbe", FALSE, NONE, op1(Db), 0 },
778 /*77*/ { "jnbe", FALSE, NONE, op1(Db), 0 },
780 /*78*/ { "js", FALSE, NONE, op1(Db), 0 },
781 /*79*/ { "jns", FALSE, NONE, op1(Db), 0 },
782 /*7a*/ { "jp", FALSE, NONE, op1(Db), 0 },
783 /*7b*/ { "jnp", FALSE, NONE, op1(Db), 0 },
784 /*7c*/ { "jl", FALSE, NONE, op1(Db), 0 },
785 /*7d*/ { "jnl", FALSE, NONE, op1(Db), 0 },
786 /*7e*/ { "jle", FALSE, NONE, op1(Db), 0 },
787 /*7f*/ { "jnle", FALSE, NONE, op1(Db), 0 },
789 /*80*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 },
790 /*81*/ { "", TRUE, LONG, op2(I, E), db_Grp1 },
791 /*82*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 },
792 /*83*/ { "", TRUE, LONG, op2(Ibs,E), db_Grp1 },
793 /*84*/ { "test", TRUE, BYTE, op2(R, E), 0 },
794 /*85*/ { "test", TRUE, LONG, op2(R, E), 0 },
795 /*86*/ { "xchg", TRUE, BYTE, op2(R, E), 0 },
796 /*87*/ { "xchg", TRUE, LONG, op2(R, E), 0 },
798 /*88*/ { "mov", TRUE, BYTE, op2(R, E), 0 },
799 /*89*/ { "mov", TRUE, LONG, op2(R, E), 0 },
800 /*8a*/ { "mov", TRUE, BYTE, op2(E, R), 0 },
801 /*8b*/ { "mov", TRUE, LONG, op2(E, R), 0 },
802 /*8c*/ { "mov", TRUE, NONE, op2(S, Ew), 0 },
803 /*8d*/ { "lea", TRUE, LONG, op2(E, R), 0 },
804 /*8e*/ { "mov", TRUE, NONE, op2(Ew, S), 0 },
805 /*8f*/ { "pop", TRUE, LONG, op1(E), 0 },
807 /*90*/ { "nop", FALSE, NONE, 0, 0 },
808 /*91*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
809 /*92*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
810 /*93*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
811 /*94*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
812 /*95*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
813 /*96*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
814 /*97*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
816 /*98*/ { "cwde", FALSE, SDEP, 0, "cbw" },
817 /*99*/ { "cdq", FALSE, SDEP, 0, "cwd" },
818 /*9a*/ { "lcall", FALSE, NONE, op1(OS), 0 },
819 /*9b*/ { "wait", FALSE, NONE, 0, 0 },
820 /*9c*/ { "pushf", FALSE, LONG, 0, 0 },
821 /*9d*/ { "popf", FALSE, LONG, 0, 0 },
822 /*9e*/ { "sahf", FALSE, NONE, 0, 0 },
823 /*9f*/ { "lahf", FALSE, NONE, 0, 0 },
825 /*a0*/ { "mov", FALSE, BYTE, op2(O, A), 0 },
826 /*a1*/ { "mov", FALSE, LONG, op2(O, A), 0 },
827 /*a2*/ { "mov", FALSE, BYTE, op2(A, O), 0 },
828 /*a3*/ { "mov", FALSE, LONG, op2(A, O), 0 },
829 /*a4*/ { "movs", FALSE, BYTE, op2(SI,DI), 0 },
830 /*a5*/ { "movs", FALSE, LONG, op2(SI,DI), 0 },
831 /*a6*/ { "cmps", FALSE, BYTE, op2(SI,DI), 0 },
832 /*a7*/ { "cmps", FALSE, LONG, op2(SI,DI), 0 },
834 /*a8*/ { "test", FALSE, BYTE, op2(I, A), 0 },
835 /*a9*/ { "test", FALSE, LONG, op2(I, A), 0 },
836 /*aa*/ { "stos", FALSE, BYTE, op1(DI), 0 },
837 /*ab*/ { "stos", FALSE, LONG, op1(DI), 0 },
838 /*ac*/ { "lods", FALSE, BYTE, op1(SI), 0 },
839 /*ad*/ { "lods", FALSE, LONG, op1(SI), 0 },
840 /*ae*/ { "scas", FALSE, BYTE, op1(SI), 0 },
841 /*af*/ { "scas", FALSE, LONG, op1(SI), 0 },
843 /*b0*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
844 /*b1*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
845 /*b2*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
846 /*b3*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
847 /*b4*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
848 /*b5*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
849 /*b6*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
850 /*b7*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
852 /*b8*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
853 /*b9*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
854 /*ba*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
855 /*bb*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
856 /*bc*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
857 /*bd*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
858 /*be*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
859 /*bf*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
861 /*c0*/ { "", TRUE, BYTE, op2(Ib, E), db_Grp2 },
862 /*c1*/ { "", TRUE, LONG, op2(Ib, E), db_Grp2 },
863 /*c2*/ { "ret", FALSE, NONE, op1(Iw), 0 },
864 /*c3*/ { "ret", FALSE, NONE, 0, 0 },
865 /*c4*/ { "les", TRUE, LONG, op2(E, R), 0 },
866 /*c5*/ { "lds", TRUE, LONG, op2(E, R), 0 },
867 /*c6*/ { "mov", TRUE, BYTE, op2(I, E), 0 },
868 /*c7*/ { "mov", TRUE, LONG, op2(I, E), 0 },
870 /*c8*/ { "enter", FALSE, NONE, op2(Iw, Ib), 0 },
871 /*c9*/ { "leave", FALSE, NONE, 0, 0 },
872 /*ca*/ { "lret", FALSE, NONE, op1(Iw), 0 },
873 /*cb*/ { "lret", FALSE, NONE, 0, 0 },
874 /*cc*/ { "int", FALSE, NONE, op1(o3), 0 },
875 /*cd*/ { "int", FALSE, NONE, op1(Ib), 0 },
876 /*ce*/ { "into", FALSE, NONE, 0, 0 },
877 /*cf*/ { "iret", FALSE, NONE, 0, 0 },
879 /*d0*/ { "", TRUE, BYTE, op2(o1, E), db_Grp2 },
880 /*d1*/ { "", TRUE, LONG, op2(o1, E), db_Grp2 },
881 /*d2*/ { "", TRUE, BYTE, op2(CL, E), db_Grp2 },
882 /*d3*/ { "", TRUE, LONG, op2(CL, E), db_Grp2 },
883 /*d4*/ { "aam", FALSE, NONE, op1(Iba), 0 },
884 /*d5*/ { "aad", FALSE, NONE, op1(Iba), 0 },
885 /*d6*/ { ".byte\t0xd6", FALSE, NONE, 0, 0 },
886 /*d7*/ { "xlat", FALSE, BYTE, op1(BX), 0 },
888 /*d8*/ { "", TRUE, NONE, 0, db_Esc8 },
889 /*d9*/ { "", TRUE, NONE, 0, db_Esc9 },
890 /*da*/ { "", TRUE, NONE, 0, db_Esca },
891 /*db*/ { "", TRUE, NONE, 0, db_Escb },
892 /*dc*/ { "", TRUE, NONE, 0, db_Escc },
893 /*dd*/ { "", TRUE, NONE, 0, db_Escd },
894 /*de*/ { "", TRUE, NONE, 0, db_Esce },
895 /*df*/ { "", TRUE, NONE, 0, db_Escf },
897 /*e0*/ { "loopne",FALSE, NONE, op1(Db), 0 },
898 /*e1*/ { "loope", FALSE, NONE, op1(Db), 0 },
899 /*e2*/ { "loop", FALSE, NONE, op1(Db), 0 },
900 /*e3*/ { "jrcxz", FALSE, ADEP, op1(Db), "jecxz" },
901 /*e4*/ { "in", FALSE, BYTE, op2(Ib, A), 0 },
902 /*e5*/ { "in", FALSE, LONG, op2(Ib, A) , 0 },
903 /*e6*/ { "out", FALSE, BYTE, op2(A, Ib), 0 },
904 /*e7*/ { "out", FALSE, LONG, op2(A, Ib) , 0 },
906 /*e8*/ { "call", FALSE, NONE, op1(Dl), 0 },
907 /*e9*/ { "jmp", FALSE, NONE, op1(Dl), 0 },
908 /*ea*/ { "ljmp", FALSE, NONE, op1(OS), 0 },
909 /*eb*/ { "jmp", FALSE, NONE, op1(Db), 0 },
910 /*ec*/ { "in", FALSE, BYTE, op2(DX, A), 0 },
911 /*ed*/ { "in", FALSE, LONG, op2(DX, A) , 0 },
912 /*ee*/ { "out", FALSE, BYTE, op2(A, DX), 0 },
913 /*ef*/ { "out", FALSE, LONG, op2(A, DX) , 0 },
915 /*f0*/ { "", FALSE, NONE, 0, 0 },
916 /*f1*/ { ".byte\t0xf1", FALSE, NONE, 0, 0 },
917 /*f2*/ { "", FALSE, NONE, 0, 0 },
918 /*f3*/ { "", FALSE, NONE, 0, 0 },
919 /*f4*/ { "hlt", FALSE, NONE, 0, 0 },
920 /*f5*/ { "cmc", FALSE, NONE, 0, 0 },
921 /*f6*/ { "", TRUE, BYTE, 0, db_Grp3 },
922 /*f7*/ { "", TRUE, LONG, 0, db_Grp3 },
924 /*f8*/ { "clc", FALSE, NONE, 0, 0 },
925 /*f9*/ { "stc", FALSE, NONE, 0, 0 },
926 /*fa*/ { "cli", FALSE, NONE, 0, 0 },
927 /*fb*/ { "sti", FALSE, NONE, 0, 0 },
928 /*fc*/ { "cld", FALSE, NONE, 0, 0 },
929 /*fd*/ { "std", FALSE, NONE, 0, 0 },
930 /*fe*/ { "", TRUE, NONE, 0, db_Grp4 },
931 /*ff*/ { "", TRUE, NONE, 0, db_Grp5 },
934 static const struct inst db_bad_inst =
935 { "???", FALSE, NONE, 0, 0 }
938 #define f_mod(rex, byte) ((byte)>>6)
939 #define f_reg(rex, byte) ((((byte)>>3)&0x7) | (rex & REX_R ? 0x8 : 0x0))
940 #define f_rm(rex, byte) (((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0))
942 #define sib_ss(rex, byte) ((byte)>>6)
943 #define sib_index(rex, byte) ((((byte)>>3)&0x7) | (rex & REX_X ? 0x8 : 0x0))
944 #define sib_base(rex, byte) (((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0))
947 int is_reg; /* if reg, reg number is in 'disp' */
954 static const char * const db_reg[2][4][16] = {
956 {{"%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh",
957 "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" },
958 { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di",
959 "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" },
960 { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
961 "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" },
962 { "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
963 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }},
965 {{"%al", "%cl", "%dl", "%bl", "%spl", "%bpl", "%sil", "%dil",
966 "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" },
967 { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di",
968 "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" },
969 { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
970 "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" },
971 { "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
972 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }}
975 static const char * const db_seg_reg[8] = {
976 "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
980 * lengths for size attributes
982 static const int db_lengths[] = {
992 #define get_value_inc(result, loc, size, is_signed) \
993 result = db_get_value((loc), (size), (is_signed)); \
997 db_disasm_esc(db_addr_t loc, int inst, int rex, int short_addr,
998 int size, const char *seg);
999 static void db_print_address(const char *seg, int size, int rex,
1000 struct i_addr *addrp);
1002 db_read_address(db_addr_t loc, int short_addr, int rex, int regmodrm,
1003 struct i_addr *addrp);
1006 * Read address at location and return updated location.
1009 db_read_address(loc, short_addr, rex, regmodrm, addrp)
1014 struct i_addr * addrp; /* out */
1016 int mod, rm, sib, index, disp, size, have_sib;
1018 mod = f_mod(rex, regmodrm);
1019 rm = f_rm(rex, regmodrm);
1022 addrp->is_reg = TRUE;
1026 addrp->is_reg = FALSE;
1034 if ((rm & 0x7) == 4) {
1035 get_value_inc(sib, loc, 1, FALSE);
1036 rm = sib_base(rex, sib);
1037 index = sib_index(rex, sib);
1039 addrp->index = db_reg[1][size][index];
1040 addrp->ss = sib_ss(rex, sib);
1048 get_value_inc(addrp->disp, loc, 4, FALSE);
1051 else if (short_addr)
1052 addrp->base = "%eip";
1054 addrp->base = "%rip";
1057 addrp->base = db_reg[1][size][rm];
1062 get_value_inc(disp, loc, 1, TRUE);
1064 addrp->base = db_reg[1][size][rm];
1068 get_value_inc(disp, loc, 4, FALSE);
1070 addrp->base = db_reg[1][size][rm];
1077 db_print_address(seg, size, rex, addrp)
1081 struct i_addr * addrp;
1083 if (addrp->is_reg) {
1084 db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][addrp->disp]);
1089 db_printf("%s:", seg);
1092 if (addrp->disp != 0 || (addrp->base == 0 && addrp->index == 0))
1093 db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY);
1094 if (addrp->base != 0 || addrp->index != 0) {
1097 db_printf("%s", addrp->base);
1099 db_printf(",%s,%d", addrp->index, 1<<addrp->ss);
1105 * Disassemble floating-point ("escape") instruction
1106 * and return updated location.
1109 db_disasm_esc(loc, inst, rex, short_addr, size, seg)
1118 const struct finst * fp;
1120 struct i_addr address;
1123 get_value_inc(regmodrm, loc, 1, FALSE);
1124 fp = &db_Esc_inst[inst - 0xd8][f_reg(rex, regmodrm)];
1125 mod = f_mod(rex, regmodrm);
1127 if (*fp->f_name == '\0') {
1128 db_printf("<bad instruction>");
1132 * Normal address modes.
1134 loc = db_read_address(loc, short_addr, rex, regmodrm, &address);
1135 db_printf("%s", fp->f_name);
1136 switch(fp->f_size) {
1159 db_print_address(seg, BYTE, rex, &address);
1163 * 'reg-reg' - special formats
1165 switch (fp->f_rrmode) {
1167 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1168 db_printf("%s\t%%st,%%st(%d)",name,f_rm(rex, regmodrm));
1171 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1172 db_printf("%s\t%%st(%d),%%st",name, f_rm(rex, regmodrm));
1175 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1176 db_printf("%s\t%%st(%d)",name, f_rm(rex, regmodrm));
1179 name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)];
1182 db_printf("%s", name);
1185 name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)];
1188 db_printf("%s\t%%ax", name);
1192 db_printf("<bad instruction>");
1201 * Disassemble instruction at 'loc'. 'altfmt' specifies an
1202 * (optional) alternate format. Return address of start of
1206 db_disasm(loc, altfmt)
1214 const struct inst * ip;
1215 const char * i_name;
1228 struct i_addr address;
1230 get_value_inc(inst, loc, 1, FALSE);
1242 case 0x66: /* data16 */
1270 db_printf("repne ");
1279 if (inst >= 0x40 && inst < 0x50) {
1284 get_value_inc(inst, loc, 1, FALSE);
1288 if (inst >= 0xd8 && inst <= 0xdf) {
1289 loc = db_disasm_esc(loc, inst, rex, short_addr, size, seg);
1294 ip = &db_inst_table[inst];
1295 while (ip->i_size == ESC) {
1296 get_value_inc(inst, loc, 1, FALSE);
1297 ip = ((const struct inst * const *)ip->i_extra)[inst>>4];
1306 if (ip->i_has_modrm) {
1307 get_value_inc(regmodrm, loc, 1, FALSE);
1308 loc = db_read_address(loc, short_addr, rex, regmodrm, &address);
1311 i_name = ip->i_name;
1312 i_size = ip->i_size;
1313 i_mode = ip->i_mode;
1315 if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) == 3) {
1316 ip = &db_Grp9b[f_reg(rex, regmodrm)];
1317 i_name = ip->i_name;
1318 i_size = ip->i_size;
1319 i_mode = ip->i_mode;
1321 else if (ip->i_extra == db_Grp1 || ip->i_extra == db_Grp2 ||
1322 ip->i_extra == db_Grp6 || ip->i_extra == db_Grp7 ||
1323 ip->i_extra == db_Grp8 || ip->i_extra == db_Grp9 ||
1324 ip->i_extra == db_Grp15) {
1325 i_name = ((const char * const *)ip->i_extra)[f_reg(rex, regmodrm)];
1327 else if (ip->i_extra == db_Grp3) {
1329 ip = &ip[f_reg(rex, regmodrm)];
1330 i_name = ip->i_name;
1331 i_mode = ip->i_mode;
1333 else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) {
1335 ip = &ip[f_reg(rex, regmodrm)];
1336 i_name = ip->i_name;
1337 i_mode = ip->i_mode;
1338 i_size = ip->i_size;
1341 /* Special cases that don't fit well in the tables. */
1342 if (ip->i_extra == db_Grp7 && f_mod(rex, regmodrm) == 3) {
1350 i_name = "vmlaunch";
1355 i_name = "vmresume";
1446 if (ip->i_extra == db_Grp15 && f_mod(rex, regmodrm) == 3) {
1447 i_name = db_Grp15b[f_reg(rex, regmodrm)];
1452 /* Handle instructions identified by mandatory prefixes. */
1459 } else if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) != 3 &&
1460 f_reg(rex, regmodrm) == 0x6) {
1466 if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) != 3 &&
1467 f_reg(rex, regmodrm) == 0x6) {
1472 if (strcmp(i_name, "cwde") == 0)
1474 else if (strcmp(i_name, "cmpxchg8b") == 0)
1475 i_name = "cmpxchg16b";
1479 db_printf("repe "); /* XXX repe VS rep */
1481 if (i_size == SDEP) {
1483 db_printf("%s", i_name);
1485 db_printf("%s", (const char *)ip->i_extra);
1486 } else if (i_size == ADEP) {
1487 if (short_addr == FALSE)
1488 db_printf("%s", i_name);
1490 db_printf("%s", (const char *)ip->i_extra);
1493 db_printf("%s", i_name);
1494 if ((inst >= 0x50 && inst <= 0x5f) || inst == 0x68 || inst == 0x6a) {
1498 if (i_size != NONE) {
1499 if (i_size == BYTE) {
1503 else if (i_size == WORD) {
1507 else if (size == WORD)
1520 i_mode >>= 8, first = FALSE)
1525 switch (i_mode & 0xFF) {
1528 db_print_address(seg, size, rex, &address);
1533 db_print_address(seg, size, rex, &address);
1537 db_print_address(seg, (rex & REX_W) ? QUAD : LONG, rex, &address);
1541 db_print_address(seg, LONG, 0, &address);
1545 db_print_address(seg, WORD, rex, &address);
1549 db_print_address(seg, BYTE, rex, &address);
1553 db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][f_reg(rex, regmodrm)]);
1557 db_printf("%s", db_reg[rex != 0 ? 1 : 0][WORD][f_reg(rex, regmodrm)]);
1561 db_printf("%s", db_reg[rex != 0 ? 1 : 0][QUAD][f_reg(rex, regmodrm)]);
1565 db_printf("%s", db_reg[0][QUAD][f_rm(rex, inst)]);
1569 db_printf("%s", db_reg[rex != 0 ? 1 : 0][(rex & REX_R) ? QUAD : LONG][f_rm(rex, inst)]);
1573 db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][f_rm(rex, regmodrm)]);
1577 db_printf("%s", db_seg_reg[f_reg(rex, regmodrm)]);
1581 db_printf("%s", db_seg_reg[f_reg(rex, inst)]);
1585 db_printf("%s", db_reg[rex != 0 ? 1 : 0][size][0]); /* acc */
1590 db_printf("%s:", seg);
1591 db_printf("(%s)", short_addr ? "%bx" : "%ebx");
1604 db_printf("%s:", seg);
1605 db_printf("(%s)", short_addr ? "%si" : "%rsi");
1609 db_printf("%%es:(%s)", short_addr ? "%di" : "%rdi");
1613 db_printf("%%cr%d", f_reg(rex, regmodrm));
1617 db_printf("%%dr%d", f_reg(rex, regmodrm));
1621 db_printf("%%tr%d", f_reg(rex, regmodrm));
1625 len = db_lengths[size];
1626 get_value_inc(imm, loc, len, FALSE);
1627 db_printf("$%#r", imm);
1631 len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
1632 get_value_inc(imm, loc, len, FALSE);
1633 db_printf("$%+#r", imm);
1637 get_value_inc(imm, loc, 1, FALSE);
1638 db_printf("$%#r", imm);
1642 get_value_inc(imm, loc, 1, FALSE);
1644 db_printf("$%#r", imm);
1648 get_value_inc(imm, loc, 1, TRUE);
1651 db_printf("$%+#r", imm);
1655 get_value_inc(imm, loc, 2, FALSE);
1656 db_printf("$%#r", imm);
1660 len = db_lengths[rex & REX_W ? QUAD : LONG];
1661 get_value_inc(imm64, loc, len, FALSE);
1662 db_printf("$%#lr", imm64);
1666 len = (short_addr ? 2 : 4);
1667 get_value_inc(displ, loc, len, FALSE);
1669 db_printf("%s:%+#r",seg, displ);
1671 db_printsym((db_addr_t)displ, DB_STGY_ANY);
1675 get_value_inc(displ, loc, 1, TRUE);
1679 db_printsym((db_addr_t)displ, DB_STGY_XTRN);
1683 len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
1684 get_value_inc(displ, loc, len, FALSE);
1688 db_printsym((db_addr_t)displ, DB_STGY_XTRN);
1700 len = db_lengths[size];
1701 get_value_inc(imm, loc, len, FALSE); /* offset */
1702 get_value_inc(imm2, loc, 2, FALSE); /* segment */
1703 db_printf("$%#r,%#r", imm2, imm);