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_0f1x[] = {
254 /*10*/ { "", FALSE, NONE, 0, 0 },
255 /*11*/ { "", FALSE, NONE, 0, 0 },
256 /*12*/ { "", FALSE, NONE, 0, 0 },
257 /*13*/ { "", FALSE, NONE, 0, 0 },
258 /*14*/ { "", FALSE, NONE, 0, 0 },
259 /*15*/ { "", FALSE, NONE, 0, 0 },
260 /*16*/ { "", FALSE, NONE, 0, 0 },
261 /*17*/ { "", FALSE, NONE, 0, 0 },
263 /*18*/ { "", FALSE, NONE, 0, 0 },
264 /*19*/ { "", FALSE, NONE, 0, 0 },
265 /*1a*/ { "", FALSE, NONE, 0, 0 },
266 /*1b*/ { "", FALSE, NONE, 0, 0 },
267 /*1c*/ { "", FALSE, NONE, 0, 0 },
268 /*1d*/ { "", FALSE, NONE, 0, 0 },
269 /*1e*/ { "", FALSE, NONE, 0, 0 },
270 /*1f*/ { "nopl", TRUE, SDEP, 0, "nopw" },
273 static const struct inst db_inst_0f2x[] = {
274 /*20*/ { "mov", TRUE, LONG, op2(CR,El), 0 },
275 /*21*/ { "mov", TRUE, LONG, op2(DR,El), 0 },
276 /*22*/ { "mov", TRUE, LONG, op2(El,CR), 0 },
277 /*23*/ { "mov", TRUE, LONG, op2(El,DR), 0 },
278 /*24*/ { "mov", TRUE, LONG, op2(TR,El), 0 },
279 /*25*/ { "", FALSE, NONE, 0, 0 },
280 /*26*/ { "mov", TRUE, LONG, op2(El,TR), 0 },
281 /*27*/ { "", FALSE, NONE, 0, 0 },
283 /*28*/ { "", FALSE, NONE, 0, 0 },
284 /*29*/ { "", FALSE, NONE, 0, 0 },
285 /*2a*/ { "", FALSE, NONE, 0, 0 },
286 /*2b*/ { "", FALSE, NONE, 0, 0 },
287 /*2c*/ { "", FALSE, NONE, 0, 0 },
288 /*2d*/ { "", FALSE, NONE, 0, 0 },
289 /*2e*/ { "", FALSE, NONE, 0, 0 },
290 /*2f*/ { "", FALSE, NONE, 0, 0 },
293 static const struct inst db_inst_0f3x[] = {
294 /*30*/ { "wrmsr", FALSE, NONE, 0, 0 },
295 /*31*/ { "rdtsc", FALSE, NONE, 0, 0 },
296 /*32*/ { "rdmsr", FALSE, NONE, 0, 0 },
297 /*33*/ { "rdpmc", FALSE, NONE, 0, 0 },
298 /*34*/ { "sysenter",FALSE,NONE, 0, 0 },
299 /*35*/ { "sysexit",FALSE,NONE, 0, 0 },
300 /*36*/ { "", FALSE, NONE, 0, 0 },
301 /*37*/ { "getsec",FALSE, NONE, 0, 0 },
303 /*38*/ { "", FALSE, ESC, 0, db_inst_0f38 },
304 /*39*/ { "", FALSE, NONE, 0, 0 },
305 /*3a*/ { "", FALSE, NONE, 0, 0 },
306 /*3b*/ { "", FALSE, NONE, 0, 0 },
307 /*3c*/ { "", FALSE, NONE, 0, 0 },
308 /*3d*/ { "", FALSE, NONE, 0, 0 },
309 /*3e*/ { "", FALSE, NONE, 0, 0 },
310 /*3f*/ { "", FALSE, NONE, 0, 0 },
313 static const struct inst db_inst_0f4x[] = {
314 /*40*/ { "cmovo", TRUE, NONE, op2(E, R), 0 },
315 /*41*/ { "cmovno", TRUE, NONE, op2(E, R), 0 },
316 /*42*/ { "cmovb", TRUE, NONE, op2(E, R), 0 },
317 /*43*/ { "cmovnb", TRUE, NONE, op2(E, R), 0 },
318 /*44*/ { "cmovz", TRUE, NONE, op2(E, R), 0 },
319 /*45*/ { "cmovnz", TRUE, NONE, op2(E, R), 0 },
320 /*46*/ { "cmovbe", TRUE, NONE, op2(E, R), 0 },
321 /*47*/ { "cmovnbe",TRUE, NONE, op2(E, R), 0 },
323 /*48*/ { "cmovs", TRUE, NONE, op2(E, R), 0 },
324 /*49*/ { "cmovns", TRUE, NONE, op2(E, R), 0 },
325 /*4a*/ { "cmovp", TRUE, NONE, op2(E, R), 0 },
326 /*4b*/ { "cmovnp", TRUE, NONE, op2(E, R), 0 },
327 /*4c*/ { "cmovl", TRUE, NONE, op2(E, R), 0 },
328 /*4d*/ { "cmovnl", TRUE, NONE, op2(E, R), 0 },
329 /*4e*/ { "cmovle", TRUE, NONE, op2(E, R), 0 },
330 /*4f*/ { "cmovnle",TRUE, NONE, op2(E, R), 0 },
333 static const struct inst db_inst_0f7x[] = {
334 /*70*/ { "", FALSE, NONE, 0, 0 },
335 /*71*/ { "", FALSE, NONE, 0, 0 },
336 /*72*/ { "", FALSE, NONE, 0, 0 },
337 /*73*/ { "", FALSE, NONE, 0, 0 },
338 /*74*/ { "", FALSE, NONE, 0, 0 },
339 /*75*/ { "", FALSE, NONE, 0, 0 },
340 /*76*/ { "", FALSE, NONE, 0, 0 },
341 /*77*/ { "", FALSE, NONE, 0, 0 },
343 /*78*/ { "vmread", TRUE, NONE, op2(Rq, E), 0 },
344 /*79*/ { "vmwrite",TRUE, NONE, op2(E, Rq), 0 },
345 /*7a*/ { "", FALSE, NONE, 0, 0 },
346 /*7b*/ { "", FALSE, NONE, 0, 0 },
347 /*7c*/ { "", FALSE, NONE, 0, 0 },
348 /*7d*/ { "", FALSE, NONE, 0, 0 },
349 /*7e*/ { "", FALSE, NONE, 0, 0 },
350 /*7f*/ { "", FALSE, NONE, 0, 0 },
353 static const struct inst db_inst_0f8x[] = {
354 /*80*/ { "jo", FALSE, NONE, op1(Dl), 0 },
355 /*81*/ { "jno", FALSE, NONE, op1(Dl), 0 },
356 /*82*/ { "jb", FALSE, NONE, op1(Dl), 0 },
357 /*83*/ { "jnb", FALSE, NONE, op1(Dl), 0 },
358 /*84*/ { "jz", FALSE, NONE, op1(Dl), 0 },
359 /*85*/ { "jnz", FALSE, NONE, op1(Dl), 0 },
360 /*86*/ { "jbe", FALSE, NONE, op1(Dl), 0 },
361 /*87*/ { "jnbe", FALSE, NONE, op1(Dl), 0 },
363 /*88*/ { "js", FALSE, NONE, op1(Dl), 0 },
364 /*89*/ { "jns", FALSE, NONE, op1(Dl), 0 },
365 /*8a*/ { "jp", FALSE, NONE, op1(Dl), 0 },
366 /*8b*/ { "jnp", FALSE, NONE, op1(Dl), 0 },
367 /*8c*/ { "jl", FALSE, NONE, op1(Dl), 0 },
368 /*8d*/ { "jnl", FALSE, NONE, op1(Dl), 0 },
369 /*8e*/ { "jle", FALSE, NONE, op1(Dl), 0 },
370 /*8f*/ { "jnle", FALSE, NONE, op1(Dl), 0 },
373 static const struct inst db_inst_0f9x[] = {
374 /*90*/ { "seto", TRUE, NONE, op1(Eb), 0 },
375 /*91*/ { "setno", TRUE, NONE, op1(Eb), 0 },
376 /*92*/ { "setb", TRUE, NONE, op1(Eb), 0 },
377 /*93*/ { "setnb", TRUE, NONE, op1(Eb), 0 },
378 /*94*/ { "setz", TRUE, NONE, op1(Eb), 0 },
379 /*95*/ { "setnz", TRUE, NONE, op1(Eb), 0 },
380 /*96*/ { "setbe", TRUE, NONE, op1(Eb), 0 },
381 /*97*/ { "setnbe",TRUE, NONE, op1(Eb), 0 },
383 /*98*/ { "sets", TRUE, NONE, op1(Eb), 0 },
384 /*99*/ { "setns", TRUE, NONE, op1(Eb), 0 },
385 /*9a*/ { "setp", TRUE, NONE, op1(Eb), 0 },
386 /*9b*/ { "setnp", TRUE, NONE, op1(Eb), 0 },
387 /*9c*/ { "setl", TRUE, NONE, op1(Eb), 0 },
388 /*9d*/ { "setnl", TRUE, NONE, op1(Eb), 0 },
389 /*9e*/ { "setle", TRUE, NONE, op1(Eb), 0 },
390 /*9f*/ { "setnle",TRUE, NONE, op1(Eb), 0 },
393 static const struct inst db_inst_0fax[] = {
394 /*a0*/ { "push", FALSE, NONE, op1(Si), 0 },
395 /*a1*/ { "pop", FALSE, NONE, op1(Si), 0 },
396 /*a2*/ { "cpuid", FALSE, NONE, 0, 0 },
397 /*a3*/ { "bt", TRUE, LONG, op2(R,E), 0 },
398 /*a4*/ { "shld", TRUE, LONG, op3(Ib,R,E), 0 },
399 /*a5*/ { "shld", TRUE, LONG, op3(CL,R,E), 0 },
400 /*a6*/ { "", FALSE, NONE, 0, 0 },
401 /*a7*/ { "", FALSE, NONE, 0, 0 },
403 /*a8*/ { "push", FALSE, NONE, op1(Si), 0 },
404 /*a9*/ { "pop", FALSE, NONE, op1(Si), 0 },
405 /*aa*/ { "rsm", FALSE, NONE, 0, 0 },
406 /*ab*/ { "bts", TRUE, LONG, op2(R,E), 0 },
407 /*ac*/ { "shrd", TRUE, LONG, op3(Ib,R,E), 0 },
408 /*ad*/ { "shrd", TRUE, LONG, op3(CL,R,E), 0 },
409 /*ae*/ { "", TRUE, LONG, op1(E), db_Grp15 },
410 /*af*/ { "imul", TRUE, LONG, op2(E,R), 0 },
413 static const struct inst db_inst_0fbx[] = {
414 /*b0*/ { "cmpxchg",TRUE, BYTE, op2(R, E), 0 },
415 /*b0*/ { "cmpxchg",TRUE, LONG, op2(R, E), 0 },
416 /*b2*/ { "lss", TRUE, LONG, op2(E, R), 0 },
417 /*b3*/ { "btr", TRUE, LONG, op2(R, E), 0 },
418 /*b4*/ { "lfs", TRUE, LONG, op2(E, R), 0 },
419 /*b5*/ { "lgs", TRUE, LONG, op2(E, R), 0 },
420 /*b6*/ { "movzb", TRUE, LONG, op2(Eb, R), 0 },
421 /*b7*/ { "movzw", TRUE, LONG, op2(Ew, R), 0 },
423 /*b8*/ { "", FALSE, NONE, 0, 0 },
424 /*b9*/ { "", FALSE, NONE, 0, 0 },
425 /*ba*/ { "", TRUE, LONG, op2(Ib, E), db_Grp8 },
426 /*bb*/ { "btc", TRUE, LONG, op2(R, E), 0 },
427 /*bc*/ { "bsf", TRUE, LONG, op2(E, R), 0 },
428 /*bd*/ { "bsr", TRUE, LONG, op2(E, R), 0 },
429 /*be*/ { "movsb", TRUE, LONG, op2(Eb, R), 0 },
430 /*bf*/ { "movsw", TRUE, LONG, op2(Ew, R), 0 },
433 static const struct inst db_inst_0fcx[] = {
434 /*c0*/ { "xadd", TRUE, BYTE, op2(R, E), 0 },
435 /*c1*/ { "xadd", TRUE, LONG, op2(R, E), 0 },
436 /*c2*/ { "", FALSE, NONE, 0, 0 },
437 /*c3*/ { "", FALSE, NONE, 0, 0 },
438 /*c4*/ { "", FALSE, NONE, 0, 0 },
439 /*c5*/ { "", FALSE, NONE, 0, 0 },
440 /*c6*/ { "", FALSE, NONE, 0, 0 },
441 /*c7*/ { "", TRUE, NONE, op1(E), db_Grp9 },
442 /*c8*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
443 /*c9*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
444 /*ca*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
445 /*cb*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
446 /*cc*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
447 /*cd*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
448 /*ce*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
449 /*cf*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
452 static const struct inst * const db_inst_0f[] = {
471 static const char * const db_Esc92[] = {
472 "fnop", "", "", "", "", "", "", ""
474 static const char * const db_Esc94[] = {
475 "fchs", "fabs", "", "", "ftst", "fxam", "", ""
477 static const char * const db_Esc95[] = {
478 "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
480 static const char * const db_Esc96[] = {
481 "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
484 static const char * const db_Esc97[] = {
485 "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
488 static const char * const db_Esca5[] = {
489 "", "fucompp","", "", "", "", "", ""
492 static const char * const db_Escb4[] = {
493 "fneni","fndisi", "fnclex","fninit","fsetpm", "", "", ""
496 static const char * const db_Esce3[] = {
497 "", "fcompp","", "", "", "", "", ""
500 static const char * const db_Escf4[] = {
501 "fnstsw","", "", "", "", "", "", ""
504 static const struct finst db_Esc8[] = {
505 /*0*/ { "fadd", SNGL, op2(STI,ST), 0 },
506 /*1*/ { "fmul", SNGL, op2(STI,ST), 0 },
507 /*2*/ { "fcom", SNGL, op2(STI,ST), 0 },
508 /*3*/ { "fcomp", SNGL, op2(STI,ST), 0 },
509 /*4*/ { "fsub", SNGL, op2(STI,ST), 0 },
510 /*5*/ { "fsubr", SNGL, op2(STI,ST), 0 },
511 /*6*/ { "fdiv", SNGL, op2(STI,ST), 0 },
512 /*7*/ { "fdivr", SNGL, op2(STI,ST), 0 },
515 static const struct finst db_Esc9[] = {
516 /*0*/ { "fld", SNGL, op1(STI), 0 },
517 /*1*/ { "", NONE, op1(STI), "fxch" },
518 /*2*/ { "fst", SNGL, op1(X), db_Esc92 },
519 /*3*/ { "fstp", SNGL, 0, 0 },
520 /*4*/ { "fldenv", NONE, op1(X), db_Esc94 },
521 /*5*/ { "fldcw", NONE, op1(X), db_Esc95 },
522 /*6*/ { "fnstenv",NONE, op1(X), db_Esc96 },
523 /*7*/ { "fnstcw", NONE, op1(X), db_Esc97 },
526 static const struct finst db_Esca[] = {
527 /*0*/ { "fiadd", LONG, 0, 0 },
528 /*1*/ { "fimul", LONG, 0, 0 },
529 /*2*/ { "ficom", LONG, 0, 0 },
530 /*3*/ { "ficomp", LONG, 0, 0 },
531 /*4*/ { "fisub", LONG, 0, 0 },
532 /*5*/ { "fisubr", LONG, op1(X), db_Esca5 },
533 /*6*/ { "fidiv", LONG, 0, 0 },
534 /*7*/ { "fidivr", LONG, 0, 0 }
537 static const struct finst db_Escb[] = {
538 /*0*/ { "fild", LONG, 0, 0 },
539 /*1*/ { "", NONE, 0, 0 },
540 /*2*/ { "fist", LONG, 0, 0 },
541 /*3*/ { "fistp", LONG, 0, 0 },
542 /*4*/ { "", WORD, op1(X), db_Escb4 },
543 /*5*/ { "fld", EXTR, 0, 0 },
544 /*6*/ { "", WORD, 0, 0 },
545 /*7*/ { "fstp", EXTR, 0, 0 },
548 static const struct finst db_Escc[] = {
549 /*0*/ { "fadd", DBLR, op2(ST,STI), 0 },
550 /*1*/ { "fmul", DBLR, op2(ST,STI), 0 },
551 /*2*/ { "fcom", DBLR, 0, 0 },
552 /*3*/ { "fcomp", DBLR, 0, 0 },
553 /*4*/ { "fsub", DBLR, op2(ST,STI), "fsubr" },
554 /*5*/ { "fsubr", DBLR, op2(ST,STI), "fsub" },
555 /*6*/ { "fdiv", DBLR, op2(ST,STI), "fdivr" },
556 /*7*/ { "fdivr", DBLR, op2(ST,STI), "fdiv" },
559 static const struct finst db_Escd[] = {
560 /*0*/ { "fld", DBLR, op1(STI), "ffree" },
561 /*1*/ { "", NONE, 0, 0 },
562 /*2*/ { "fst", DBLR, op1(STI), 0 },
563 /*3*/ { "fstp", DBLR, op1(STI), 0 },
564 /*4*/ { "frstor", NONE, op1(STI), "fucom" },
565 /*5*/ { "", NONE, op1(STI), "fucomp" },
566 /*6*/ { "fnsave", NONE, 0, 0 },
567 /*7*/ { "fnstsw", NONE, 0, 0 },
570 static const struct finst db_Esce[] = {
571 /*0*/ { "fiadd", WORD, op2(ST,STI), "faddp" },
572 /*1*/ { "fimul", WORD, op2(ST,STI), "fmulp" },
573 /*2*/ { "ficom", WORD, 0, 0 },
574 /*3*/ { "ficomp", WORD, op1(X), db_Esce3 },
575 /*4*/ { "fisub", WORD, op2(ST,STI), "fsubrp" },
576 /*5*/ { "fisubr", WORD, op2(ST,STI), "fsubp" },
577 /*6*/ { "fidiv", WORD, op2(ST,STI), "fdivrp" },
578 /*7*/ { "fidivr", WORD, op2(ST,STI), "fdivp" },
581 static const struct finst db_Escf[] = {
582 /*0*/ { "fild", WORD, 0, 0 },
583 /*1*/ { "", NONE, 0, 0 },
584 /*2*/ { "fist", WORD, 0, 0 },
585 /*3*/ { "fistp", WORD, 0, 0 },
586 /*4*/ { "fbld", NONE, op1(XA), db_Escf4 },
587 /*5*/ { "fild", QUAD, 0, 0 },
588 /*6*/ { "fbstp", NONE, 0, 0 },
589 /*7*/ { "fistp", QUAD, 0, 0 },
592 static const struct finst * const db_Esc_inst[] = {
593 db_Esc8, db_Esc9, db_Esca, db_Escb,
594 db_Escc, db_Escd, db_Esce, db_Escf
597 static const char * const db_Grp1[] = {
608 static const char * const db_Grp2[] = {
619 static const struct inst db_Grp3[] = {
620 { "test", TRUE, NONE, op2(I,E), 0 },
621 { "test", TRUE, NONE, op2(I,E), 0 },
622 { "not", TRUE, NONE, op1(E), 0 },
623 { "neg", TRUE, NONE, op1(E), 0 },
624 { "mul", TRUE, NONE, op2(E,A), 0 },
625 { "imul", TRUE, NONE, op2(E,A), 0 },
626 { "div", TRUE, NONE, op2(E,A), 0 },
627 { "idiv", TRUE, NONE, op2(E,A), 0 },
630 static const struct inst db_Grp4[] = {
631 { "inc", TRUE, BYTE, op1(E), 0 },
632 { "dec", TRUE, BYTE, op1(E), 0 },
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 }
641 static const struct inst db_Grp5[] = {
642 { "inc", TRUE, LONG, op1(E), 0 },
643 { "dec", TRUE, LONG, op1(E), 0 },
644 { "call", TRUE, LONG, op1(Eind),0 },
645 { "lcall", TRUE, LONG, op1(Eind),0 },
646 { "jmp", TRUE, LONG, op1(Eind),0 },
647 { "ljmp", TRUE, LONG, op1(Eind),0 },
648 { "push", TRUE, LONG, op1(E), 0 },
649 { "", TRUE, NONE, 0, 0 }
652 static const struct inst db_Grp9b[] = {
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 },
659 { "rdrand",TRUE, LONG, op1(Rv), 0 },
660 { "rdseed",TRUE, LONG, op1(Rv), 0 }
663 static const struct inst db_inst_table[256] = {
664 /*00*/ { "add", TRUE, BYTE, op2(R, E), 0 },
665 /*01*/ { "add", TRUE, LONG, op2(R, E), 0 },
666 /*02*/ { "add", TRUE, BYTE, op2(E, R), 0 },
667 /*03*/ { "add", TRUE, LONG, op2(E, R), 0 },
668 /*04*/ { "add", FALSE, BYTE, op2(I, A), 0 },
669 /*05*/ { "add", FALSE, LONG, op2(Is, A), 0 },
670 /*06*/ { "push", FALSE, NONE, op1(Si), 0 },
671 /*07*/ { "pop", FALSE, NONE, op1(Si), 0 },
673 /*08*/ { "or", TRUE, BYTE, op2(R, E), 0 },
674 /*09*/ { "or", TRUE, LONG, op2(R, E), 0 },
675 /*0a*/ { "or", TRUE, BYTE, op2(E, R), 0 },
676 /*0b*/ { "or", TRUE, LONG, op2(E, R), 0 },
677 /*0c*/ { "or", FALSE, BYTE, op2(I, A), 0 },
678 /*0d*/ { "or", FALSE, LONG, op2(I, A), 0 },
679 /*0e*/ { "push", FALSE, NONE, op1(Si), 0 },
680 /*0f*/ { "", FALSE, ESC, 0, db_inst_0f },
682 /*10*/ { "adc", TRUE, BYTE, op2(R, E), 0 },
683 /*11*/ { "adc", TRUE, LONG, op2(R, E), 0 },
684 /*12*/ { "adc", TRUE, BYTE, op2(E, R), 0 },
685 /*13*/ { "adc", TRUE, LONG, op2(E, R), 0 },
686 /*14*/ { "adc", FALSE, BYTE, op2(I, A), 0 },
687 /*15*/ { "adc", FALSE, LONG, op2(Is, A), 0 },
688 /*16*/ { "push", FALSE, NONE, op1(Si), 0 },
689 /*17*/ { "pop", FALSE, NONE, op1(Si), 0 },
691 /*18*/ { "sbb", TRUE, BYTE, op2(R, E), 0 },
692 /*19*/ { "sbb", TRUE, LONG, op2(R, E), 0 },
693 /*1a*/ { "sbb", TRUE, BYTE, op2(E, R), 0 },
694 /*1b*/ { "sbb", TRUE, LONG, op2(E, R), 0 },
695 /*1c*/ { "sbb", FALSE, BYTE, op2(I, A), 0 },
696 /*1d*/ { "sbb", FALSE, LONG, op2(Is, A), 0 },
697 /*1e*/ { "push", FALSE, NONE, op1(Si), 0 },
698 /*1f*/ { "pop", FALSE, NONE, op1(Si), 0 },
700 /*20*/ { "and", TRUE, BYTE, op2(R, E), 0 },
701 /*21*/ { "and", TRUE, LONG, op2(R, E), 0 },
702 /*22*/ { "and", TRUE, BYTE, op2(E, R), 0 },
703 /*23*/ { "and", TRUE, LONG, op2(E, R), 0 },
704 /*24*/ { "and", FALSE, BYTE, op2(I, A), 0 },
705 /*25*/ { "and", FALSE, LONG, op2(I, A), 0 },
706 /*26*/ { "", FALSE, NONE, 0, 0 },
707 /*27*/ { "daa", FALSE, NONE, 0, 0 },
709 /*28*/ { "sub", TRUE, BYTE, op2(R, E), 0 },
710 /*29*/ { "sub", TRUE, LONG, op2(R, E), 0 },
711 /*2a*/ { "sub", TRUE, BYTE, op2(E, R), 0 },
712 /*2b*/ { "sub", TRUE, LONG, op2(E, R), 0 },
713 /*2c*/ { "sub", FALSE, BYTE, op2(I, A), 0 },
714 /*2d*/ { "sub", FALSE, LONG, op2(Is, A), 0 },
715 /*2e*/ { "", FALSE, NONE, 0, 0 },
716 /*2f*/ { "das", FALSE, NONE, 0, 0 },
718 /*30*/ { "xor", TRUE, BYTE, op2(R, E), 0 },
719 /*31*/ { "xor", TRUE, LONG, op2(R, E), 0 },
720 /*32*/ { "xor", TRUE, BYTE, op2(E, R), 0 },
721 /*33*/ { "xor", TRUE, LONG, op2(E, R), 0 },
722 /*34*/ { "xor", FALSE, BYTE, op2(I, A), 0 },
723 /*35*/ { "xor", FALSE, LONG, op2(I, A), 0 },
724 /*36*/ { "", FALSE, NONE, 0, 0 },
725 /*37*/ { "aaa", FALSE, NONE, 0, 0 },
727 /*38*/ { "cmp", TRUE, BYTE, op2(R, E), 0 },
728 /*39*/ { "cmp", TRUE, LONG, op2(R, E), 0 },
729 /*3a*/ { "cmp", TRUE, BYTE, op2(E, R), 0 },
730 /*3b*/ { "cmp", TRUE, LONG, op2(E, R), 0 },
731 /*3c*/ { "cmp", FALSE, BYTE, op2(I, A), 0 },
732 /*3d*/ { "cmp", FALSE, LONG, op2(Is, A), 0 },
733 /*3e*/ { "", FALSE, NONE, 0, 0 },
734 /*3f*/ { "aas", FALSE, NONE, 0, 0 },
736 /*40*/ { "rex", FALSE, NONE, 0, 0 },
737 /*41*/ { "rex.b", FALSE, NONE, 0, 0 },
738 /*42*/ { "rex.x", FALSE, NONE, 0, 0 },
739 /*43*/ { "rex.xb", FALSE, NONE, 0, 0 },
740 /*44*/ { "rex.r", FALSE, NONE, 0, 0 },
741 /*45*/ { "rex.rb", FALSE, NONE, 0, 0 },
742 /*46*/ { "rex.rx", FALSE, NONE, 0, 0 },
743 /*47*/ { "rex.rxb", FALSE, NONE, 0, 0 },
745 /*48*/ { "rex.w", FALSE, NONE, 0, 0 },
746 /*49*/ { "rex.wb", FALSE, NONE, 0, 0 },
747 /*4a*/ { "rex.wx", FALSE, NONE, 0, 0 },
748 /*4b*/ { "rex.wxb", FALSE, NONE, 0, 0 },
749 /*4c*/ { "rex.wr", FALSE, NONE, 0, 0 },
750 /*4d*/ { "rex.wrb", FALSE, NONE, 0, 0 },
751 /*4e*/ { "rex.wrx", FALSE, NONE, 0, 0 },
752 /*4f*/ { "rex.wrxb", FALSE, NONE, 0, 0 },
754 /*50*/ { "push", FALSE, LONG, op1(Ri), 0 },
755 /*51*/ { "push", FALSE, LONG, op1(Ri), 0 },
756 /*52*/ { "push", FALSE, LONG, op1(Ri), 0 },
757 /*53*/ { "push", FALSE, LONG, op1(Ri), 0 },
758 /*54*/ { "push", FALSE, LONG, op1(Ri), 0 },
759 /*55*/ { "push", FALSE, LONG, op1(Ri), 0 },
760 /*56*/ { "push", FALSE, LONG, op1(Ri), 0 },
761 /*57*/ { "push", FALSE, LONG, op1(Ri), 0 },
763 /*58*/ { "pop", FALSE, LONG, op1(Ri), 0 },
764 /*59*/ { "pop", FALSE, LONG, op1(Ri), 0 },
765 /*5a*/ { "pop", FALSE, LONG, op1(Ri), 0 },
766 /*5b*/ { "pop", FALSE, LONG, op1(Ri), 0 },
767 /*5c*/ { "pop", FALSE, LONG, op1(Ri), 0 },
768 /*5d*/ { "pop", FALSE, LONG, op1(Ri), 0 },
769 /*5e*/ { "pop", FALSE, LONG, op1(Ri), 0 },
770 /*5f*/ { "pop", FALSE, LONG, op1(Ri), 0 },
772 /*60*/ { "pusha", FALSE, LONG, 0, 0 },
773 /*61*/ { "popa", FALSE, LONG, 0, 0 },
774 /*62*/ { "bound", TRUE, LONG, op2(E, R), 0 },
775 /*63*/ { "movslq", TRUE, NONE, op2(EL,R), 0 },
777 /*64*/ { "", FALSE, NONE, 0, 0 },
778 /*65*/ { "", FALSE, NONE, 0, 0 },
779 /*66*/ { "", FALSE, NONE, 0, 0 },
780 /*67*/ { "", FALSE, NONE, 0, 0 },
782 /*68*/ { "push", FALSE, LONG, op1(I), 0 },
783 /*69*/ { "imul", TRUE, LONG, op3(I,E,R), 0 },
784 /*6a*/ { "push", FALSE, LONG, op1(Ibs), 0 },
785 /*6b*/ { "imul", TRUE, LONG, op3(Ibs,E,R),0 },
786 /*6c*/ { "ins", FALSE, BYTE, op2(DX, DI), 0 },
787 /*6d*/ { "ins", FALSE, LONG, op2(DX, DI), 0 },
788 /*6e*/ { "outs", FALSE, BYTE, op2(SI, DX), 0 },
789 /*6f*/ { "outs", FALSE, LONG, op2(SI, DX), 0 },
791 /*70*/ { "jo", FALSE, NONE, op1(Db), 0 },
792 /*71*/ { "jno", FALSE, NONE, op1(Db), 0 },
793 /*72*/ { "jb", FALSE, NONE, op1(Db), 0 },
794 /*73*/ { "jnb", FALSE, NONE, op1(Db), 0 },
795 /*74*/ { "jz", FALSE, NONE, op1(Db), 0 },
796 /*75*/ { "jnz", FALSE, NONE, op1(Db), 0 },
797 /*76*/ { "jbe", FALSE, NONE, op1(Db), 0 },
798 /*77*/ { "jnbe", FALSE, NONE, op1(Db), 0 },
800 /*78*/ { "js", FALSE, NONE, op1(Db), 0 },
801 /*79*/ { "jns", FALSE, NONE, op1(Db), 0 },
802 /*7a*/ { "jp", FALSE, NONE, op1(Db), 0 },
803 /*7b*/ { "jnp", FALSE, NONE, op1(Db), 0 },
804 /*7c*/ { "jl", FALSE, NONE, op1(Db), 0 },
805 /*7d*/ { "jnl", FALSE, NONE, op1(Db), 0 },
806 /*7e*/ { "jle", FALSE, NONE, op1(Db), 0 },
807 /*7f*/ { "jnle", FALSE, NONE, op1(Db), 0 },
809 /*80*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 },
810 /*81*/ { "", TRUE, LONG, op2(I, E), db_Grp1 },
811 /*82*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 },
812 /*83*/ { "", TRUE, LONG, op2(Ibs,E), db_Grp1 },
813 /*84*/ { "test", TRUE, BYTE, op2(R, E), 0 },
814 /*85*/ { "test", TRUE, LONG, op2(R, E), 0 },
815 /*86*/ { "xchg", TRUE, BYTE, op2(R, E), 0 },
816 /*87*/ { "xchg", TRUE, LONG, op2(R, E), 0 },
818 /*88*/ { "mov", TRUE, BYTE, op2(R, E), 0 },
819 /*89*/ { "mov", TRUE, LONG, op2(R, E), 0 },
820 /*8a*/ { "mov", TRUE, BYTE, op2(E, R), 0 },
821 /*8b*/ { "mov", TRUE, LONG, op2(E, R), 0 },
822 /*8c*/ { "mov", TRUE, NONE, op2(S, Ew), 0 },
823 /*8d*/ { "lea", TRUE, LONG, op2(E, R), 0 },
824 /*8e*/ { "mov", TRUE, NONE, op2(Ew, S), 0 },
825 /*8f*/ { "pop", TRUE, LONG, op1(E), 0 },
827 /*90*/ { "nop", FALSE, NONE, 0, 0 },
828 /*91*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
829 /*92*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
830 /*93*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
831 /*94*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
832 /*95*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
833 /*96*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
834 /*97*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
836 /*98*/ { "cwde", FALSE, SDEP, 0, "cbw" },
837 /*99*/ { "cdq", FALSE, SDEP, 0, "cwd" },
838 /*9a*/ { "lcall", FALSE, NONE, op1(OS), 0 },
839 /*9b*/ { "wait", FALSE, NONE, 0, 0 },
840 /*9c*/ { "pushf", FALSE, LONG, 0, 0 },
841 /*9d*/ { "popf", FALSE, LONG, 0, 0 },
842 /*9e*/ { "sahf", FALSE, NONE, 0, 0 },
843 /*9f*/ { "lahf", FALSE, NONE, 0, 0 },
845 /*a0*/ { "mov", FALSE, BYTE, op2(O, A), 0 },
846 /*a1*/ { "mov", FALSE, LONG, op2(O, A), 0 },
847 /*a2*/ { "mov", FALSE, BYTE, op2(A, O), 0 },
848 /*a3*/ { "mov", FALSE, LONG, op2(A, O), 0 },
849 /*a4*/ { "movs", FALSE, BYTE, op2(SI,DI), 0 },
850 /*a5*/ { "movs", FALSE, LONG, op2(SI,DI), 0 },
851 /*a6*/ { "cmps", FALSE, BYTE, op2(SI,DI), 0 },
852 /*a7*/ { "cmps", FALSE, LONG, op2(SI,DI), 0 },
854 /*a8*/ { "test", FALSE, BYTE, op2(I, A), 0 },
855 /*a9*/ { "test", FALSE, LONG, op2(I, A), 0 },
856 /*aa*/ { "stos", FALSE, BYTE, op1(DI), 0 },
857 /*ab*/ { "stos", FALSE, LONG, op1(DI), 0 },
858 /*ac*/ { "lods", FALSE, BYTE, op1(SI), 0 },
859 /*ad*/ { "lods", FALSE, LONG, op1(SI), 0 },
860 /*ae*/ { "scas", FALSE, BYTE, op1(SI), 0 },
861 /*af*/ { "scas", FALSE, LONG, op1(SI), 0 },
863 /*b0*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
864 /*b1*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
865 /*b2*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
866 /*b3*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
867 /*b4*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
868 /*b5*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
869 /*b6*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
870 /*b7*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
872 /*b8*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
873 /*b9*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
874 /*ba*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
875 /*bb*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
876 /*bc*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
877 /*bd*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
878 /*be*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
879 /*bf*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 },
881 /*c0*/ { "", TRUE, BYTE, op2(Ib, E), db_Grp2 },
882 /*c1*/ { "", TRUE, LONG, op2(Ib, E), db_Grp2 },
883 /*c2*/ { "ret", FALSE, NONE, op1(Iw), 0 },
884 /*c3*/ { "ret", FALSE, NONE, 0, 0 },
885 /*c4*/ { "les", TRUE, LONG, op2(E, R), 0 },
886 /*c5*/ { "lds", TRUE, LONG, op2(E, R), 0 },
887 /*c6*/ { "mov", TRUE, BYTE, op2(I, E), 0 },
888 /*c7*/ { "mov", TRUE, LONG, op2(I, E), 0 },
890 /*c8*/ { "enter", FALSE, NONE, op2(Iw, Ib), 0 },
891 /*c9*/ { "leave", FALSE, NONE, 0, 0 },
892 /*ca*/ { "lret", FALSE, NONE, op1(Iw), 0 },
893 /*cb*/ { "lret", FALSE, NONE, 0, 0 },
894 /*cc*/ { "int", FALSE, NONE, op1(o3), 0 },
895 /*cd*/ { "int", FALSE, NONE, op1(Ib), 0 },
896 /*ce*/ { "into", FALSE, NONE, 0, 0 },
897 /*cf*/ { "iret", FALSE, NONE, 0, 0 },
899 /*d0*/ { "", TRUE, BYTE, op2(o1, E), db_Grp2 },
900 /*d1*/ { "", TRUE, LONG, op2(o1, E), db_Grp2 },
901 /*d2*/ { "", TRUE, BYTE, op2(CL, E), db_Grp2 },
902 /*d3*/ { "", TRUE, LONG, op2(CL, E), db_Grp2 },
903 /*d4*/ { "aam", FALSE, NONE, op1(Iba), 0 },
904 /*d5*/ { "aad", FALSE, NONE, op1(Iba), 0 },
905 /*d6*/ { ".byte\t0xd6", FALSE, NONE, 0, 0 },
906 /*d7*/ { "xlat", FALSE, BYTE, op1(BX), 0 },
908 /*d8*/ { "", TRUE, NONE, 0, db_Esc8 },
909 /*d9*/ { "", TRUE, NONE, 0, db_Esc9 },
910 /*da*/ { "", TRUE, NONE, 0, db_Esca },
911 /*db*/ { "", TRUE, NONE, 0, db_Escb },
912 /*dc*/ { "", TRUE, NONE, 0, db_Escc },
913 /*dd*/ { "", TRUE, NONE, 0, db_Escd },
914 /*de*/ { "", TRUE, NONE, 0, db_Esce },
915 /*df*/ { "", TRUE, NONE, 0, db_Escf },
917 /*e0*/ { "loopne",FALSE, NONE, op1(Db), 0 },
918 /*e1*/ { "loope", FALSE, NONE, op1(Db), 0 },
919 /*e2*/ { "loop", FALSE, NONE, op1(Db), 0 },
920 /*e3*/ { "jrcxz", FALSE, ADEP, op1(Db), "jecxz" },
921 /*e4*/ { "in", FALSE, BYTE, op2(Ib, A), 0 },
922 /*e5*/ { "in", FALSE, LONG, op2(Ib, A) , 0 },
923 /*e6*/ { "out", FALSE, BYTE, op2(A, Ib), 0 },
924 /*e7*/ { "out", FALSE, LONG, op2(A, Ib) , 0 },
926 /*e8*/ { "call", FALSE, NONE, op1(Dl), 0 },
927 /*e9*/ { "jmp", FALSE, NONE, op1(Dl), 0 },
928 /*ea*/ { "ljmp", FALSE, NONE, op1(OS), 0 },
929 /*eb*/ { "jmp", FALSE, NONE, op1(Db), 0 },
930 /*ec*/ { "in", FALSE, BYTE, op2(DX, A), 0 },
931 /*ed*/ { "in", FALSE, LONG, op2(DX, A) , 0 },
932 /*ee*/ { "out", FALSE, BYTE, op2(A, DX), 0 },
933 /*ef*/ { "out", FALSE, LONG, op2(A, DX) , 0 },
935 /*f0*/ { "", FALSE, NONE, 0, 0 },
936 /*f1*/ { ".byte\t0xf1", FALSE, NONE, 0, 0 },
937 /*f2*/ { "", FALSE, NONE, 0, 0 },
938 /*f3*/ { "", FALSE, NONE, 0, 0 },
939 /*f4*/ { "hlt", FALSE, NONE, 0, 0 },
940 /*f5*/ { "cmc", FALSE, NONE, 0, 0 },
941 /*f6*/ { "", TRUE, BYTE, 0, db_Grp3 },
942 /*f7*/ { "", TRUE, LONG, 0, db_Grp3 },
944 /*f8*/ { "clc", FALSE, NONE, 0, 0 },
945 /*f9*/ { "stc", FALSE, NONE, 0, 0 },
946 /*fa*/ { "cli", FALSE, NONE, 0, 0 },
947 /*fb*/ { "sti", FALSE, NONE, 0, 0 },
948 /*fc*/ { "cld", FALSE, NONE, 0, 0 },
949 /*fd*/ { "std", FALSE, NONE, 0, 0 },
950 /*fe*/ { "", TRUE, NONE, 0, db_Grp4 },
951 /*ff*/ { "", TRUE, NONE, 0, db_Grp5 },
954 static const struct inst db_bad_inst =
955 { "???", FALSE, NONE, 0, 0 }
958 #define f_mod(rex, byte) ((byte)>>6)
959 #define f_reg(rex, byte) ((((byte)>>3)&0x7) | (rex & REX_R ? 0x8 : 0x0))
960 #define f_rm(rex, byte) (((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0))
962 #define sib_ss(rex, byte) ((byte)>>6)
963 #define sib_index(rex, byte) ((((byte)>>3)&0x7) | (rex & REX_X ? 0x8 : 0x0))
964 #define sib_base(rex, byte) (((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0))
967 int is_reg; /* if reg, reg number is in 'disp' */
974 static const char * const db_reg[2][4][16] = {
976 {{"%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh",
977 "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" },
978 { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di",
979 "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" },
980 { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
981 "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" },
982 { "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
983 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }},
985 {{"%al", "%cl", "%dl", "%bl", "%spl", "%bpl", "%sil", "%dil",
986 "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" },
987 { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di",
988 "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" },
989 { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
990 "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" },
991 { "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
992 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }}
995 static const char * const db_seg_reg[8] = {
996 "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
1000 * lengths for size attributes
1002 static const int db_lengths[] = {
1012 #define get_value_inc(result, loc, size, is_signed) \
1013 result = db_get_value((loc), (size), (is_signed)); \
1017 db_disasm_esc(db_addr_t loc, int inst, int rex, int short_addr,
1018 int size, const char *seg);
1019 static void db_print_address(const char *seg, int size, int rex,
1020 struct i_addr *addrp);
1022 db_read_address(db_addr_t loc, int short_addr, int rex, int regmodrm,
1023 struct i_addr *addrp);
1026 * Read address at location and return updated location.
1029 db_read_address(loc, short_addr, rex, regmodrm, addrp)
1034 struct i_addr * addrp; /* out */
1036 int mod, rm, sib, index, disp, size, have_sib;
1038 mod = f_mod(rex, regmodrm);
1039 rm = f_rm(rex, regmodrm);
1042 addrp->is_reg = TRUE;
1046 addrp->is_reg = FALSE;
1054 if ((rm & 0x7) == 4) {
1055 get_value_inc(sib, loc, 1, FALSE);
1056 rm = sib_base(rex, sib);
1057 index = sib_index(rex, sib);
1059 addrp->index = db_reg[1][size][index];
1060 addrp->ss = sib_ss(rex, sib);
1068 get_value_inc(addrp->disp, loc, 4, FALSE);
1071 else if (short_addr)
1072 addrp->base = "%eip";
1074 addrp->base = "%rip";
1077 addrp->base = db_reg[1][size][rm];
1082 get_value_inc(disp, loc, 1, TRUE);
1084 addrp->base = db_reg[1][size][rm];
1088 get_value_inc(disp, loc, 4, FALSE);
1090 addrp->base = db_reg[1][size][rm];
1097 db_print_address(seg, size, rex, addrp)
1101 struct i_addr * addrp;
1103 if (addrp->is_reg) {
1104 db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][addrp->disp]);
1109 db_printf("%s:", seg);
1112 if (addrp->disp != 0 || (addrp->base == 0 && addrp->index == 0))
1113 db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY);
1114 if (addrp->base != 0 || addrp->index != 0) {
1117 db_printf("%s", addrp->base);
1119 db_printf(",%s,%d", addrp->index, 1<<addrp->ss);
1125 * Disassemble floating-point ("escape") instruction
1126 * and return updated location.
1129 db_disasm_esc(loc, inst, rex, short_addr, size, seg)
1138 const struct finst * fp;
1140 struct i_addr address;
1143 get_value_inc(regmodrm, loc, 1, FALSE);
1144 fp = &db_Esc_inst[inst - 0xd8][f_reg(rex, regmodrm)];
1145 mod = f_mod(rex, regmodrm);
1147 if (*fp->f_name == '\0') {
1148 db_printf("<bad instruction>");
1152 * Normal address modes.
1154 loc = db_read_address(loc, short_addr, rex, regmodrm, &address);
1155 db_printf("%s", fp->f_name);
1156 switch(fp->f_size) {
1179 db_print_address(seg, BYTE, rex, &address);
1183 * 'reg-reg' - special formats
1185 switch (fp->f_rrmode) {
1187 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1188 db_printf("%s\t%%st,%%st(%d)",name,f_rm(rex, regmodrm));
1191 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1192 db_printf("%s\t%%st(%d),%%st",name, f_rm(rex, regmodrm));
1195 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1196 db_printf("%s\t%%st(%d)",name, f_rm(rex, regmodrm));
1199 name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)];
1202 db_printf("%s", name);
1205 name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)];
1208 db_printf("%s\t%%ax", name);
1212 db_printf("<bad instruction>");
1221 * Disassemble instruction at 'loc'. 'altfmt' specifies an
1222 * (optional) alternate format. Return address of start of
1226 db_disasm(db_addr_t loc, bool altfmt)
1232 const struct inst * ip;
1233 const char * i_name;
1246 struct i_addr address;
1248 get_value_inc(inst, loc, 1, FALSE);
1260 case 0x66: /* data16 */
1288 db_printf("repne ");
1297 if (inst >= 0x40 && inst < 0x50) {
1302 get_value_inc(inst, loc, 1, FALSE);
1306 if (inst >= 0xd8 && inst <= 0xdf) {
1307 loc = db_disasm_esc(loc, inst, rex, short_addr, size, seg);
1312 ip = &db_inst_table[inst];
1313 while (ip->i_size == ESC) {
1314 get_value_inc(inst, loc, 1, FALSE);
1315 ip = ((const struct inst * const *)ip->i_extra)[inst>>4];
1324 if (ip->i_has_modrm) {
1325 get_value_inc(regmodrm, loc, 1, FALSE);
1326 loc = db_read_address(loc, short_addr, rex, regmodrm, &address);
1329 i_name = ip->i_name;
1330 i_size = ip->i_size;
1331 i_mode = ip->i_mode;
1333 if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) == 3) {
1334 ip = &db_Grp9b[f_reg(rex, regmodrm)];
1335 i_name = ip->i_name;
1336 i_size = ip->i_size;
1337 i_mode = ip->i_mode;
1339 else if (ip->i_extra == db_Grp1 || ip->i_extra == db_Grp2 ||
1340 ip->i_extra == db_Grp6 || ip->i_extra == db_Grp7 ||
1341 ip->i_extra == db_Grp8 || ip->i_extra == db_Grp9 ||
1342 ip->i_extra == db_Grp15) {
1343 i_name = ((const char * const *)ip->i_extra)[f_reg(rex, regmodrm)];
1345 else if (ip->i_extra == db_Grp3) {
1347 ip = &ip[f_reg(rex, regmodrm)];
1348 i_name = ip->i_name;
1349 i_mode = ip->i_mode;
1351 else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) {
1353 ip = &ip[f_reg(rex, regmodrm)];
1354 i_name = ip->i_name;
1355 i_mode = ip->i_mode;
1356 i_size = ip->i_size;
1359 /* Special cases that don't fit well in the tables. */
1360 if (ip->i_extra == db_Grp7 && f_mod(rex, regmodrm) == 3) {
1368 i_name = "vmlaunch";
1373 i_name = "vmresume";
1464 if (ip->i_extra == db_Grp15 && f_mod(rex, regmodrm) == 3) {
1465 i_name = db_Grp15b[f_reg(rex, regmodrm)];
1470 /* Handle instructions identified by mandatory prefixes. */
1477 } else if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) != 3 &&
1478 f_reg(rex, regmodrm) == 0x6) {
1484 if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) != 3 &&
1485 f_reg(rex, regmodrm) == 0x6) {
1490 if (strcmp(i_name, "cwde") == 0)
1492 else if (strcmp(i_name, "cmpxchg8b") == 0)
1493 i_name = "cmpxchg16b";
1497 db_printf("repe "); /* XXX repe VS rep */
1499 if (i_size == SDEP) {
1501 db_printf("%s", i_name);
1503 db_printf("%s", (const char *)ip->i_extra);
1504 } else if (i_size == ADEP) {
1505 if (short_addr == FALSE)
1506 db_printf("%s", i_name);
1508 db_printf("%s", (const char *)ip->i_extra);
1511 db_printf("%s", i_name);
1512 if ((inst >= 0x50 && inst <= 0x5f) || inst == 0x68 || inst == 0x6a) {
1516 if (i_size != NONE) {
1517 if (i_size == BYTE) {
1521 else if (i_size == WORD) {
1525 else if (size == WORD)
1538 i_mode >>= 8, first = FALSE)
1543 switch (i_mode & 0xFF) {
1546 db_print_address(seg, size, rex, &address);
1551 db_print_address(seg, size, rex, &address);
1555 db_print_address(seg, (rex & REX_W) ? QUAD : LONG, rex, &address);
1559 db_print_address(seg, LONG, 0, &address);
1563 db_print_address(seg, WORD, rex, &address);
1567 db_print_address(seg, BYTE, rex, &address);
1571 db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][f_reg(rex, regmodrm)]);
1575 db_printf("%s", db_reg[rex != 0 ? 1 : 0][WORD][f_reg(rex, regmodrm)]);
1579 db_printf("%s", db_reg[rex != 0 ? 1 : 0][QUAD][f_reg(rex, regmodrm)]);
1583 db_printf("%s", db_reg[0][QUAD][f_rm(rex, inst)]);
1587 db_printf("%s", db_reg[rex != 0 ? 1 : 0][(rex & REX_R) ? QUAD : LONG][f_rm(rex, inst)]);
1591 db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][f_rm(rex, regmodrm)]);
1595 db_printf("%s", db_seg_reg[f_reg(rex, regmodrm)]);
1599 db_printf("%s", db_seg_reg[f_reg(rex, inst)]);
1603 db_printf("%s", db_reg[rex != 0 ? 1 : 0][size][0]); /* acc */
1608 db_printf("%s:", seg);
1609 db_printf("(%s)", short_addr ? "%bx" : "%ebx");
1622 db_printf("%s:", seg);
1623 db_printf("(%s)", short_addr ? "%si" : "%rsi");
1627 db_printf("%%es:(%s)", short_addr ? "%di" : "%rdi");
1631 db_printf("%%cr%d", f_reg(rex, regmodrm));
1635 db_printf("%%dr%d", f_reg(rex, regmodrm));
1639 db_printf("%%tr%d", f_reg(rex, regmodrm));
1643 len = db_lengths[size];
1644 get_value_inc(imm, loc, len, FALSE);
1645 db_printf("$%#r", imm);
1649 len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
1650 get_value_inc(imm, loc, len, FALSE);
1651 db_printf("$%+#r", imm);
1655 get_value_inc(imm, loc, 1, FALSE);
1656 db_printf("$%#r", imm);
1660 get_value_inc(imm, loc, 1, FALSE);
1662 db_printf("$%#r", imm);
1666 get_value_inc(imm, loc, 1, TRUE);
1669 db_printf("$%+#r", imm);
1673 get_value_inc(imm, loc, 2, FALSE);
1674 db_printf("$%#r", imm);
1678 len = db_lengths[rex & REX_W ? QUAD : LONG];
1679 get_value_inc(imm64, loc, len, FALSE);
1680 db_printf("$%#lr", imm64);
1684 len = (short_addr ? 2 : 4);
1685 get_value_inc(displ, loc, len, FALSE);
1687 db_printf("%s:%+#r",seg, displ);
1689 db_printsym((db_addr_t)displ, DB_STGY_ANY);
1693 get_value_inc(displ, loc, 1, TRUE);
1697 db_printsym((db_addr_t)displ, DB_STGY_XTRN);
1701 len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
1702 get_value_inc(displ, loc, len, FALSE);
1706 db_printsym((db_addr_t)displ, DB_STGY_XTRN);
1718 len = db_lengths[size];
1719 get_value_inc(imm, loc, len, FALSE); /* offset */
1720 get_value_inc(imm2, loc, 2, FALSE); /* segment */
1721 db_printf("$%#r,%#r", imm2, imm);