The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/amd64/amd64/db_disasm.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Mach Operating System
    3  * Copyright (c) 1991,1990 Carnegie Mellon University
    4  * All Rights Reserved.
    5  *
    6  * Permission to use, copy, modify and distribute this software and its
    7  * documentation is hereby granted, provided that both the copyright
    8  * notice and this permission notice appear in all copies of the
    9  * software, derivative works or modified versions, and any portions
   10  * thereof, and that both notices appear in supporting documentation.
   11  *
   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.
   15  *
   16  * Carnegie Mellon requests users of this software to return to
   17  *
   18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   19  *  School of Computer Science
   20  *  Carnegie Mellon University
   21  *  Pittsburgh PA 15213-3890
   22  *
   23  * any improvements or extensions that they make and grant Carnegie the
   24  * rights to redistribute these changes.
   25  */
   26 
   27 #include <sys/cdefs.h>
   28 __FBSDID("$FreeBSD: releng/11.1/sys/amd64/amd64/db_disasm.c 315221 2017-03-14 02:06:03Z pfg $");
   29 
   30 /*
   31  * Instruction disassembler.
   32  */
   33 #include <sys/param.h>
   34 #include <sys/libkern.h>
   35 
   36 #include <ddb/ddb.h>
   37 #include <ddb/db_access.h>
   38 #include <ddb/db_sym.h>
   39 
   40 /*
   41  * Size attributes
   42  */
   43 #define BYTE    0
   44 #define WORD    1
   45 #define LONG    2
   46 #define QUAD    3
   47 #define SNGL    4
   48 #define DBLR    5
   49 #define EXTR    6
   50 #define SDEP    7
   51 #define ADEP    8
   52 #define ESC     9
   53 #define NONE    10
   54 
   55 /*
   56  * REX prefix and bits
   57  */
   58 #define REX_B   1
   59 #define REX_X   2
   60 #define REX_R   4
   61 #define REX_W   8
   62 #define REX     0x40
   63 
   64 /*
   65  * Addressing modes
   66  */
   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 */
  107 
  108 struct inst {
  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 */
  114 };
  115 
  116 #define op1(x)          (x)
  117 #define op2(x,y)        ((x)|((y)<<8))
  118 #define op3(x,y,z)      ((x)|((y)<<8)|((z)<<16))
  119 
  120 struct finst {
  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) */
  126 };
  127 
  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 },
  137 
  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 },
  146 };
  147 
  148 static const struct inst * const db_inst_0f38[] = {
  149         0,
  150         0,
  151         0,
  152         0,
  153         0,
  154         0,
  155         0,
  156         0,
  157         db_inst_0f388x,
  158         0,
  159         0,
  160         0,
  161         0,
  162         0,
  163         0,
  164         0
  165 };
  166 
  167 static const char * const db_Grp6[] = {
  168         "sldt",
  169         "str",
  170         "lldt",
  171         "ltr",
  172         "verr",
  173         "verw",
  174         "",
  175         ""
  176 };
  177 
  178 static const char * const db_Grp7[] = {
  179         "sgdt",
  180         "sidt",
  181         "lgdt",
  182         "lidt",
  183         "smsw",
  184         "",
  185         "lmsw",
  186         "invlpg"
  187 };
  188 
  189 static const char * const db_Grp8[] = {
  190         "",
  191         "",
  192         "",
  193         "",
  194         "bt",
  195         "bts",
  196         "btr",
  197         "btc"
  198 };
  199 
  200 static const char * const db_Grp9[] = {
  201         "",
  202         "cmpxchg8b",
  203         "",
  204         "",
  205         "",
  206         "",
  207         "vmptrld",
  208         "vmptrst"
  209 };
  210 
  211 static const char * const db_Grp15[] = {
  212         "fxsave",
  213         "fxrstor",
  214         "ldmxcsr",
  215         "stmxcsr",
  216         "xsave",
  217         "xrstor",
  218         "xsaveopt",
  219         "clflush"
  220 };
  221 
  222 static const char * const db_Grp15b[] = {
  223         "",
  224         "",
  225         "",
  226         "",
  227         "",
  228         "lfence",
  229         "mfence",
  230         "sfence"
  231 };
  232 
  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 },
  242 
  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 },
  251 };
  252 
  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 },
  262 
  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" },
  271 };
  272 
  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 },
  282 
  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 },
  291 };
  292 
  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 },
  302 
  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 },
  311 };
  312 
  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 },
  322 
  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 },
  331 };
  332 
  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 },
  342 
  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 },
  351 };
  352 
  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 },
  362 
  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 },
  371 };
  372 
  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 },
  382 
  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 },
  391 };
  392 
  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 },
  402 
  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 },
  411 };
  412 
  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 },
  422 
  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 },
  431 };
  432 
  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 },
  450 };
  451 
  452 static const struct inst * const db_inst_0f[] = {
  453         db_inst_0f0x,
  454         db_inst_0f1x,
  455         db_inst_0f2x,
  456         db_inst_0f3x,
  457         db_inst_0f4x,
  458         0,
  459         0,
  460         db_inst_0f7x,
  461         db_inst_0f8x,
  462         db_inst_0f9x,
  463         db_inst_0fax,
  464         db_inst_0fbx,
  465         db_inst_0fcx,
  466         0,
  467         0,
  468         0
  469 };
  470 
  471 static const char * const db_Esc92[] = {
  472         "fnop", "",     "",     "",     "",     "",     "",     ""
  473 };
  474 static const char * const db_Esc94[] = {
  475         "fchs", "fabs", "",     "",     "ftst", "fxam", "",     ""
  476 };
  477 static const char * const db_Esc95[] = {
  478         "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
  479 };
  480 static const char * const db_Esc96[] = {
  481         "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
  482         "fincstp"
  483 };
  484 static const char * const db_Esc97[] = {
  485         "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
  486 };
  487 
  488 static const char * const db_Esca5[] = {
  489         "",     "fucompp","",   "",     "",     "",     "",     ""
  490 };
  491 
  492 static const char * const db_Escb4[] = {
  493         "fneni","fndisi",       "fnclex","fninit","fsetpm",     "",     "",     ""
  494 };
  495 
  496 static const char * const db_Esce3[] = {
  497         "",     "fcompp","",    "",     "",     "",     "",     ""
  498 };
  499 
  500 static const char * const db_Escf4[] = {
  501         "fnstsw","",    "",     "",     "",     "",     "",     ""
  502 };
  503 
  504 static const struct finst db_Esc8[] = {
  505 /**/   { "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 },
  513 };
  514 
  515 static const struct finst db_Esc9[] = {
  516 /**/   { "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 },
  524 };
  525 
  526 static const struct finst db_Esca[] = {
  527 /**/   { "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 }
  535 };
  536 
  537 static const struct finst db_Escb[] = {
  538 /**/   { "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 },
  546 };
  547 
  548 static const struct finst db_Escc[] = {
  549 /**/   { "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" },
  557 };
  558 
  559 static const struct finst db_Escd[] = {
  560 /**/   { "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 },
  568 };
  569 
  570 static const struct finst db_Esce[] = {
  571 /**/   { "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" },
  579 };
  580 
  581 static const struct finst db_Escf[] = {
  582 /**/   { "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 },
  590 };
  591 
  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
  595 };
  596 
  597 static const char * const db_Grp1[] = {
  598         "add",
  599         "or",
  600         "adc",
  601         "sbb",
  602         "and",
  603         "sub",
  604         "xor",
  605         "cmp"
  606 };
  607 
  608 static const char * const db_Grp2[] = {
  609         "rol",
  610         "ror",
  611         "rcl",
  612         "rcr",
  613         "shl",
  614         "shr",
  615         "shl",
  616         "sar"
  617 };
  618 
  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 },
  628 };
  629 
  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 }
  639 };
  640 
  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 }
  650 };
  651 
  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 }
  661 };
  662 
  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 },
  672 
  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 },
  681 
  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 },
  690 
  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 },
  699 
  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 },
  708 
  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 },
  717 
  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 },
  726 
  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 },
  735 
  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 },
  744 
  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 },
  753 
  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 },
  762 
  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 },
  771 
  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 },
  776 
  777 /*64*/  { "",      FALSE, NONE,  0,          0 },
  778 /*65*/  { "",      FALSE, NONE,  0,          0 },
  779 /*66*/  { "",      FALSE, NONE,  0,          0 },
  780 /*67*/  { "",      FALSE, NONE,  0,          0 },
  781 
  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 },
  790 
  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 },
  799 
  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 },
  808 
  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 },
  817 
  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 },
  826 
  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 },
  835 
  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 },
  844 
  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 },
  853 
  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 },
  862 
  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 },
  871 
  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 },
  880 
  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 },
  889 
  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 },
  898 
  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 },
  907 
  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 },
  916 
  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 },
  925 
  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 },
  934 
  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 },
  943 
  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 },
  952 };
  953 
  954 static const struct inst db_bad_inst =
  955         { "???",   FALSE, NONE,  0,           0 }
  956 ;
  957 
  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))
  961 
  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))
  965 
  966 struct i_addr {
  967         int             is_reg; /* if reg, reg number is in 'disp' */
  968         int             disp;
  969         const char *    base;
  970         const char *    index;
  971         int             ss;
  972 };
  973 
  974 static const char * const db_reg[2][4][16] = {
  975 
  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" }},
  984 
  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" }}
  993 };
  994 
  995 static const char * const db_seg_reg[8] = {
  996         "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
  997 };
  998 
  999 /*
 1000  * lengths for size attributes
 1001  */
 1002 static const int db_lengths[] = {
 1003         1,      /* BYTE */
 1004         2,      /* WORD */
 1005         4,      /* LONG */
 1006         8,      /* QUAD */
 1007         4,      /* SNGL */
 1008         8,      /* DBLR */
 1009         10,     /* EXTR */
 1010 };
 1011 
 1012 #define get_value_inc(result, loc, size, is_signed) \
 1013         result = db_get_value((loc), (size), (is_signed)); \
 1014         (loc) += (size);
 1015 
 1016 static db_addr_t
 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);
 1021 static db_addr_t
 1022                 db_read_address(db_addr_t loc, int short_addr, int rex, int regmodrm,
 1023                     struct i_addr *addrp);
 1024 
 1025 /*
 1026  * Read address at location and return updated location.
 1027  */
 1028 static db_addr_t
 1029 db_read_address(loc, short_addr, rex, regmodrm, addrp)
 1030         db_addr_t       loc;
 1031         int             short_addr;
 1032         int             rex;
 1033         int             regmodrm;
 1034         struct i_addr * addrp;          /* out */
 1035 {
 1036         int             mod, rm, sib, index, disp, size, have_sib;
 1037 
 1038         mod = f_mod(rex, regmodrm);
 1039         rm  = f_rm(rex, regmodrm);
 1040 
 1041         if (mod == 3) {
 1042             addrp->is_reg = TRUE;
 1043             addrp->disp = rm;
 1044             return (loc);
 1045         }
 1046         addrp->is_reg = FALSE;
 1047         addrp->index = NULL;
 1048 
 1049         if (short_addr)
 1050             size = LONG;
 1051         else
 1052             size = QUAD;
 1053 
 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);
 1058             if (index != 4)
 1059                 addrp->index = db_reg[1][size][index];
 1060             addrp->ss = sib_ss(rex, sib);
 1061             have_sib = 1;
 1062         } else
 1063             have_sib = 0;
 1064 
 1065         switch (mod) {
 1066             case 0:
 1067                 if (rm == 5) {
 1068                     get_value_inc(addrp->disp, loc, 4, FALSE);
 1069                     if (have_sib)
 1070                         addrp->base = NULL;
 1071                     else if (short_addr)
 1072                         addrp->base = "%eip";
 1073                     else
 1074                         addrp->base = "%rip";
 1075                 } else {
 1076                     addrp->disp = 0;
 1077                     addrp->base = db_reg[1][size][rm];
 1078                 }
 1079                 break;
 1080 
 1081             case 1:
 1082                 get_value_inc(disp, loc, 1, TRUE);
 1083                 addrp->disp = disp;
 1084                 addrp->base = db_reg[1][size][rm];
 1085                 break;
 1086 
 1087             case 2:
 1088                 get_value_inc(disp, loc, 4, FALSE);
 1089                 addrp->disp = disp;
 1090                 addrp->base = db_reg[1][size][rm];
 1091                 break;
 1092         }
 1093         return (loc);
 1094 }
 1095 
 1096 static void
 1097 db_print_address(seg, size, rex, addrp)
 1098         const char *    seg;
 1099         int             size;
 1100         int             rex;
 1101         struct i_addr * addrp;
 1102 {
 1103         if (addrp->is_reg) {
 1104             db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][addrp->disp]);
 1105             return;
 1106         }
 1107 
 1108         if (seg) {
 1109             db_printf("%s:", seg);
 1110         }
 1111 
 1112         if (addrp->disp != 0 || (addrp->base == NULL && addrp->index == NULL))
 1113                 db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY);
 1114         if (addrp->base != NULL || addrp->index != NULL) {
 1115             db_printf("(");
 1116             if (addrp->base)
 1117                 db_printf("%s", addrp->base);
 1118             if (addrp->index)
 1119                 db_printf(",%s,%d", addrp->index, 1<<addrp->ss);
 1120             db_printf(")");
 1121         }
 1122 }
 1123 
 1124 /*
 1125  * Disassemble floating-point ("escape") instruction
 1126  * and return updated location.
 1127  */
 1128 static db_addr_t
 1129 db_disasm_esc(loc, inst, rex, short_addr, size, seg)
 1130         db_addr_t       loc;
 1131         int             inst;
 1132         int             rex;
 1133         int             short_addr;
 1134         int             size;
 1135         const char *    seg;
 1136 {
 1137         int             regmodrm;
 1138         const struct finst *    fp;
 1139         int             mod;
 1140         struct i_addr   address;
 1141         const char *    name;
 1142 
 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);
 1146         if (mod != 3) {
 1147             if (*fp->f_name == '\0') {
 1148                 db_printf("<bad instruction>");
 1149                 return (loc);
 1150             }
 1151             /*
 1152              * Normal address modes.
 1153              */
 1154             loc = db_read_address(loc, short_addr, rex, regmodrm, &address);
 1155             db_printf("%s", fp->f_name);
 1156             switch(fp->f_size) {
 1157                 case SNGL:
 1158                     db_printf("s");
 1159                     break;
 1160                 case DBLR:
 1161                     db_printf("l");
 1162                     break;
 1163                 case EXTR:
 1164                     db_printf("t");
 1165                     break;
 1166                 case WORD:
 1167                     db_printf("s");
 1168                     break;
 1169                 case LONG:
 1170                     db_printf("l");
 1171                     break;
 1172                 case QUAD:
 1173                     db_printf("q");
 1174                     break;
 1175                 default:
 1176                     break;
 1177             }
 1178             db_printf("\t");
 1179             db_print_address(seg, BYTE, rex, &address);
 1180         }
 1181         else {
 1182             /*
 1183              * 'reg-reg' - special formats
 1184              */
 1185             switch (fp->f_rrmode) {
 1186                 case op2(ST,STI):
 1187                     name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
 1188                     db_printf("%s\t%%st,%%st(%d)",name,f_rm(rex, regmodrm));
 1189                     break;
 1190                 case op2(STI,ST):
 1191                     name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
 1192                     db_printf("%s\t%%st(%d),%%st",name, f_rm(rex, regmodrm));
 1193                     break;
 1194                 case op1(STI):
 1195                     name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
 1196                     db_printf("%s\t%%st(%d)",name, f_rm(rex, regmodrm));
 1197                     break;
 1198                 case op1(X):
 1199                     name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)];
 1200                     if (*name == '\0')
 1201                         goto bad;
 1202                     db_printf("%s", name);
 1203                     break;
 1204                 case op1(XA):
 1205                     name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)];
 1206                     if (*name == '\0')
 1207                         goto bad;
 1208                     db_printf("%s\t%%ax", name);
 1209                     break;
 1210                 default:
 1211                 bad:
 1212                     db_printf("<bad instruction>");
 1213                     break;
 1214             }
 1215         }
 1216 
 1217         return (loc);
 1218 }
 1219 
 1220 /*
 1221  * Disassemble instruction at 'loc'.  'altfmt' specifies an
 1222  * (optional) alternate format.  Return address of start of
 1223  * next instruction.
 1224  */
 1225 db_addr_t
 1226 db_disasm(db_addr_t loc, bool altfmt)
 1227 {
 1228         int     inst;
 1229         int     size;
 1230         int     short_addr;
 1231         const char *    seg;
 1232         const struct inst *     ip;
 1233         const char *    i_name;
 1234         int     i_size;
 1235         int     i_mode;
 1236         int     rex = 0;
 1237         int     regmodrm = 0;
 1238         boolean_t       first;
 1239         int     displ;
 1240         int     prefix;
 1241         int     rep;
 1242         int     imm;
 1243         int     imm2;
 1244         long    imm64;
 1245         int     len;
 1246         struct i_addr   address;
 1247 
 1248         get_value_inc(inst, loc, 1, FALSE);
 1249         short_addr = FALSE;
 1250         size = LONG;
 1251         seg = NULL;
 1252 
 1253         /*
 1254          * Get prefixes
 1255          */
 1256         rep = FALSE;
 1257         prefix = TRUE;
 1258         do {
 1259             switch (inst) {
 1260                 case 0x66:              /* data16 */
 1261                     size = WORD;
 1262                     break;
 1263                 case 0x67:
 1264                     short_addr = TRUE;
 1265                     break;
 1266                 case 0x26:
 1267                     seg = "%es";
 1268                     break;
 1269                 case 0x36:
 1270                     seg = "%ss";
 1271                     break;
 1272                 case 0x2e:
 1273                     seg = "%cs";
 1274                     break;
 1275                 case 0x3e:
 1276                     seg = "%ds";
 1277                     break;
 1278                 case 0x64:
 1279                     seg = "%fs";
 1280                     break;
 1281                 case 0x65:
 1282                     seg = "%gs";
 1283                     break;
 1284                 case 0xf0:
 1285                     db_printf("lock ");
 1286                     break;
 1287                 case 0xf2:
 1288                     db_printf("repne ");
 1289                     break;
 1290                 case 0xf3:
 1291                     rep = TRUE;
 1292                     break;
 1293                 default:
 1294                     prefix = FALSE;
 1295                     break;
 1296             }
 1297             if (inst >= 0x40 && inst < 0x50) {
 1298                 rex = inst;
 1299                 prefix = TRUE;
 1300             }
 1301             if (prefix) {
 1302                 get_value_inc(inst, loc, 1, FALSE);
 1303             }
 1304         } while (prefix);
 1305 
 1306         if (inst >= 0xd8 && inst <= 0xdf) {
 1307             loc = db_disasm_esc(loc, inst, rex, short_addr, size, seg);
 1308             db_printf("\n");
 1309             return (loc);
 1310         }
 1311 
 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];
 1316             if (ip == NULL) {
 1317                 ip = &db_bad_inst;
 1318             }
 1319             else {
 1320                 ip = &ip[inst&0xf];
 1321             }
 1322         }
 1323 
 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);
 1327         }
 1328 
 1329         i_name = ip->i_name;
 1330         i_size = ip->i_size;
 1331         i_mode = ip->i_mode;
 1332 
 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;
 1338         }
 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)];
 1344         }
 1345         else if (ip->i_extra == db_Grp3) {
 1346             ip = ip->i_extra;
 1347             ip = &ip[f_reg(rex, regmodrm)];
 1348             i_name = ip->i_name;
 1349             i_mode = ip->i_mode;
 1350         }
 1351         else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) {
 1352             ip = ip->i_extra;
 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;
 1357         }
 1358 
 1359         /* Special cases that don't fit well in the tables. */
 1360         if (ip->i_extra == db_Grp7 && f_mod(rex, regmodrm) == 3) {
 1361                 switch (regmodrm) {
 1362                 case 0xc1:
 1363                         i_name = "vmcall";
 1364                         i_size = NONE;
 1365                         i_mode = 0;
 1366                         break;
 1367                 case 0xc2:
 1368                         i_name = "vmlaunch";
 1369                         i_size = NONE;
 1370                         i_mode = 0;
 1371                         break;
 1372                 case 0xc3:
 1373                         i_name = "vmresume";
 1374                         i_size = NONE;
 1375                         i_mode = 0;
 1376                         break;
 1377                 case 0xc4:
 1378                         i_name = "vmxoff";
 1379                         i_size = NONE;
 1380                         i_mode = 0;
 1381                         break;
 1382                 case 0xc8:
 1383                         i_name = "monitor";
 1384                         i_size = NONE;
 1385                         i_mode = 0;                     
 1386                         break;
 1387                 case 0xc9:
 1388                         i_name = "mwait";
 1389                         i_size = NONE;
 1390                         i_mode = 0;
 1391                         break;
 1392                 case 0xca:
 1393                         i_name = "clac";
 1394                         i_size = NONE;
 1395                         i_mode = 0;
 1396                         break;
 1397                 case 0xcb:
 1398                         i_name = "stac";
 1399                         i_size = NONE;
 1400                         i_mode = 0;
 1401                         break;
 1402                 case 0xd0:
 1403                         i_name = "xgetbv";
 1404                         i_size = NONE;
 1405                         i_mode = 0;
 1406                         break;
 1407                 case 0xd1:
 1408                         i_name = "xsetbv";
 1409                         i_size = NONE;
 1410                         i_mode = 0;
 1411                         break;
 1412                 case 0xd8:
 1413                         i_name = "vmrun";
 1414                         i_size = NONE;
 1415                         i_mode = 0;
 1416                         break;
 1417                 case 0xd9:
 1418                         i_name = "vmmcall";
 1419                         i_size = NONE;
 1420                         i_mode = 0;
 1421                         break;
 1422                 case 0xda:
 1423                         i_name = "vmload";
 1424                         i_size = NONE;
 1425                         i_mode = 0;
 1426                         break;
 1427                 case 0xdb:
 1428                         i_name = "vmsave";
 1429                         i_size = NONE;
 1430                         i_mode = 0;
 1431                         break;
 1432                 case 0xdc:
 1433                         i_name = "stgi";
 1434                         i_size = NONE;
 1435                         i_mode = 0;
 1436                         break;
 1437                 case 0xdd:
 1438                         i_name = "clgi";
 1439                         i_size = NONE;
 1440                         i_mode = 0;
 1441                         break;
 1442                 case 0xde:
 1443                         i_name = "skinit";
 1444                         i_size = NONE;
 1445                         i_mode = 0;
 1446                         break;
 1447                 case 0xdf:
 1448                         i_name = "invlpga";
 1449                         i_size = NONE;
 1450                         i_mode = 0;
 1451                         break;
 1452                 case 0xf8:
 1453                         i_name = "swapgs";
 1454                         i_size = NONE;
 1455                         i_mode = 0;
 1456                         break;
 1457                 case 0xf9:
 1458                         i_name = "rdtscp";
 1459                         i_size = NONE;
 1460                         i_mode = 0;
 1461                         break;
 1462                 }
 1463         }
 1464         if (ip->i_extra == db_Grp15 && f_mod(rex, regmodrm) == 3) {
 1465                 i_name = db_Grp15b[f_reg(rex, regmodrm)];
 1466                 i_size = NONE;
 1467                 i_mode = 0;
 1468         }
 1469 
 1470         /* Handle instructions identified by mandatory prefixes. */
 1471         if (rep == TRUE) {
 1472             if (inst == 0x90) {
 1473                 i_name = "pause";
 1474                 i_size = NONE;
 1475                 i_mode = 0;
 1476                 rep = FALSE;
 1477             } else if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) != 3 &&
 1478                 f_reg(rex, regmodrm) == 0x6) {
 1479                 i_name = "vmxon";
 1480                 rep = FALSE;
 1481             }
 1482         }
 1483         if (size == WORD) {
 1484             if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) != 3 &&
 1485                 f_reg(rex, regmodrm) == 0x6) {
 1486                 i_name = "vmclear";
 1487             }
 1488         }
 1489         if (rex & REX_W) {
 1490             if (strcmp(i_name, "cwde") == 0)
 1491                 i_name = "cdqe";
 1492             else if (strcmp(i_name, "cmpxchg8b") == 0)
 1493                 i_name = "cmpxchg16b";
 1494         }
 1495 
 1496         if (rep == TRUE)
 1497             db_printf("repe "); /* XXX repe VS rep */
 1498 
 1499         if (i_size == SDEP) {
 1500             if (size == LONG)
 1501                 db_printf("%s", i_name);
 1502             else
 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);
 1507             else
 1508                 db_printf("%s", (const char *)ip->i_extra);
 1509         }
 1510         else {
 1511             db_printf("%s", i_name);
 1512             if ((inst >= 0x50 && inst <= 0x5f) || inst == 0x68 || inst == 0x6a) {
 1513                 i_size = NONE;
 1514                 db_printf("q");
 1515             }
 1516             if (i_size != NONE) {
 1517                 if (i_size == BYTE) {
 1518                     db_printf("b");
 1519                     size = BYTE;
 1520                 }
 1521                 else if (i_size == WORD) {
 1522                     db_printf("w");
 1523                     size = WORD;
 1524                 }
 1525                 else if (size == WORD)
 1526                     db_printf("w");
 1527                 else {
 1528                     if (rex & REX_W)
 1529                         db_printf("q");
 1530                     else
 1531                         db_printf("l");
 1532                 }
 1533             }
 1534         }
 1535         db_printf("\t");
 1536         for (first = TRUE;
 1537              i_mode != 0;
 1538              i_mode >>= 8, first = FALSE)
 1539         {
 1540             if (!first)
 1541                 db_printf(",");
 1542 
 1543             switch (i_mode & 0xFF) {
 1544 
 1545                 case E:
 1546                     db_print_address(seg, size, rex, &address);
 1547                     break;
 1548 
 1549                 case Eind:
 1550                     db_printf("*");
 1551                     db_print_address(seg, size, rex, &address);
 1552                     break;
 1553 
 1554                 case El:
 1555                     db_print_address(seg, (rex & REX_W) ? QUAD : LONG, rex, &address);
 1556                     break;
 1557 
 1558                 case EL:
 1559                     db_print_address(seg, LONG, 0, &address);
 1560                     break;
 1561 
 1562                 case Ew:
 1563                     db_print_address(seg, WORD, rex, &address);
 1564                     break;
 1565 
 1566                 case Eb:
 1567                     db_print_address(seg, BYTE, rex, &address);
 1568                     break;
 1569 
 1570                 case R:
 1571                     db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][f_reg(rex, regmodrm)]);
 1572                     break;
 1573 
 1574                 case Rw:
 1575                     db_printf("%s", db_reg[rex != 0 ? 1 : 0][WORD][f_reg(rex, regmodrm)]);
 1576                     break;
 1577 
 1578                 case Rq:
 1579                     db_printf("%s", db_reg[rex != 0 ? 1 : 0][QUAD][f_reg(rex, regmodrm)]);
 1580                     break;
 1581 
 1582                 case Ri:
 1583                     db_printf("%s", db_reg[0][QUAD][f_rm(rex, inst)]);
 1584                     break;
 1585 
 1586                 case Ril:
 1587                     db_printf("%s", db_reg[rex != 0 ? 1 : 0][(rex & REX_R) ? QUAD : LONG][f_rm(rex, inst)]);
 1588                     break;
 1589 
 1590                 case Rv:
 1591                     db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][f_rm(rex, regmodrm)]);
 1592                     break;
 1593 
 1594                 case S:
 1595                     db_printf("%s", db_seg_reg[f_reg(rex, regmodrm)]);
 1596                     break;
 1597 
 1598                 case Si:
 1599                     db_printf("%s", db_seg_reg[f_reg(rex, inst)]);
 1600                     break;
 1601 
 1602                 case A:
 1603                     db_printf("%s", db_reg[rex != 0 ? 1 : 0][size][0]); /* acc */
 1604                     break;
 1605 
 1606                 case BX:
 1607                     if (seg)
 1608                         db_printf("%s:", seg);
 1609                     db_printf("(%s)", short_addr ? "%bx" : "%ebx");
 1610                     break;
 1611 
 1612                 case CL:
 1613                     db_printf("%%cl");
 1614                     break;
 1615 
 1616                 case DX:
 1617                     db_printf("%%dx");
 1618                     break;
 1619 
 1620                 case SI:
 1621                     if (seg)
 1622                         db_printf("%s:", seg);
 1623                     db_printf("(%s)", short_addr ? "%si" : "%rsi");
 1624                     break;
 1625 
 1626                 case DI:
 1627                     db_printf("%%es:(%s)", short_addr ? "%di" : "%rdi");
 1628                     break;
 1629 
 1630                 case CR:
 1631                     db_printf("%%cr%d", f_reg(rex, regmodrm));
 1632                     break;
 1633 
 1634                 case DR:
 1635                     db_printf("%%dr%d", f_reg(rex, regmodrm));
 1636                     break;
 1637 
 1638                 case TR:
 1639                     db_printf("%%tr%d", f_reg(rex, regmodrm));
 1640                     break;
 1641 
 1642                 case I:
 1643                     len = db_lengths[size];
 1644                     get_value_inc(imm, loc, len, FALSE);
 1645                     db_printf("$%#r", imm);
 1646                     break;
 1647 
 1648                 case Is:
 1649                     len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
 1650                     get_value_inc(imm, loc, len, FALSE);
 1651                     db_printf("$%+#r", imm);
 1652                     break;
 1653 
 1654                 case Ib:
 1655                     get_value_inc(imm, loc, 1, FALSE);
 1656                     db_printf("$%#r", imm);
 1657                     break;
 1658 
 1659                 case Iba:
 1660                     get_value_inc(imm, loc, 1, FALSE);
 1661                     if (imm != 0x0a)
 1662                         db_printf("$%#r", imm);
 1663                     break;
 1664 
 1665                 case Ibs:
 1666                     get_value_inc(imm, loc, 1, TRUE);
 1667                     if (size == WORD)
 1668                         imm &= 0xFFFF;
 1669                     db_printf("$%+#r", imm);
 1670                     break;
 1671 
 1672                 case Iw:
 1673                     get_value_inc(imm, loc, 2, FALSE);
 1674                     db_printf("$%#r", imm);
 1675                     break;
 1676 
 1677                 case Ilq:
 1678                     len = db_lengths[rex & REX_W ? QUAD : LONG];
 1679                     get_value_inc(imm64, loc, len, FALSE);
 1680                     db_printf("$%#lr", imm64);
 1681                     break;
 1682 
 1683                 case O:
 1684                     len = (short_addr ? 2 : 4);
 1685                     get_value_inc(displ, loc, len, FALSE);
 1686                     if (seg)
 1687                         db_printf("%s:%+#r",seg, displ);
 1688                     else
 1689                         db_printsym((db_addr_t)displ, DB_STGY_ANY);
 1690                     break;
 1691 
 1692                 case Db:
 1693                     get_value_inc(displ, loc, 1, TRUE);
 1694                     displ += loc;
 1695                     if (size == WORD)
 1696                         displ &= 0xFFFF;
 1697                     db_printsym((db_addr_t)displ, DB_STGY_XTRN);
 1698                     break;
 1699 
 1700                 case Dl:
 1701                     len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
 1702                     get_value_inc(displ, loc, len, FALSE);
 1703                     displ += loc;
 1704                     if (size == WORD)
 1705                         displ &= 0xFFFF;
 1706                     db_printsym((db_addr_t)displ, DB_STGY_XTRN);
 1707                     break;
 1708 
 1709                 case o1:
 1710                     db_printf("$1");
 1711                     break;
 1712 
 1713                 case o3:
 1714                     db_printf("$3");
 1715                     break;
 1716 
 1717                 case OS:
 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);
 1722                     break;
 1723             }
 1724         }
 1725         db_printf("\n");
 1726         return (loc);
 1727 }

Cache object: 58cb50e08ca296309f667b3d415bcef8


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.