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/i386/i386/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/6.0/sys/i386/i386/db_disasm.c 139724 2005-01-05 19:10:48Z imp $");
   29 
   30 /*
   31  * Instruction disassembler.
   32  */
   33 #include <sys/param.h>
   34 
   35 #include <ddb/ddb.h>
   36 #include <ddb/db_access.h>
   37 #include <ddb/db_sym.h>
   38 
   39 /*
   40  * Size attributes
   41  */
   42 #define BYTE    0
   43 #define WORD    1
   44 #define LONG    2
   45 #define QUAD    3
   46 #define SNGL    4
   47 #define DBLR    5
   48 #define EXTR    6
   49 #define SDEP    7
   50 #define NONE    8
   51 
   52 /*
   53  * Addressing modes
   54  */
   55 #define E       1                       /* general effective address */
   56 #define Eind    2                       /* indirect address (jump, call) */
   57 #define Ew      3                       /* address, word size */
   58 #define Eb      4                       /* address, byte size */
   59 #define R       5                       /* register, in 'reg' field */
   60 #define Rw      6                       /* word register, in 'reg' field */
   61 #define Ri      7                       /* register in instruction */
   62 #define S       8                       /* segment reg, in 'reg' field */
   63 #define Si      9                       /* segment reg, in instruction */
   64 #define A       10                      /* accumulator */
   65 #define BX      11                      /* (bx) */
   66 #define CL      12                      /* cl, for shifts */
   67 #define DX      13                      /* dx, for IO */
   68 #define SI      14                      /* si */
   69 #define DI      15                      /* di */
   70 #define CR      16                      /* control register */
   71 #define DR      17                      /* debug register */
   72 #define TR      18                      /* test register */
   73 #define I       19                      /* immediate, unsigned */
   74 #define Is      20                      /* immediate, signed */
   75 #define Ib      21                      /* byte immediate, unsigned */
   76 #define Ibs     22                      /* byte immediate, signed */
   77 #define Iw      23                      /* word immediate, unsigned */
   78 #define O       25                      /* direct address */
   79 #define Db      26                      /* byte displacement from EIP */
   80 #define Dl      27                      /* long displacement from EIP */
   81 #define o1      28                      /* constant 1 */
   82 #define o3      29                      /* constant 3 */
   83 #define OS      30                      /* immediate offset/segment */
   84 #define ST      31                      /* FP stack top */
   85 #define STI     32                      /* FP stack */
   86 #define X       33                      /* extended FP op */
   87 #define XA      34                      /* for 'fstcw %ax' */
   88 #define El      35                      /* address, long size */
   89 #define Ril     36                      /* long register in instruction */
   90 #define Iba     37                      /* byte immediate, don't print if 0xa */
   91 
   92 struct inst {
   93         const char *    i_name;         /* name */
   94         short   i_has_modrm;            /* has regmodrm byte */
   95         short   i_size;                 /* operand size */
   96         int     i_mode;                 /* addressing modes */
   97         const void *    i_extra;        /* pointer to extra opcode table */
   98 };
   99 
  100 #define op1(x)          (x)
  101 #define op2(x,y)        ((x)|((y)<<8))
  102 #define op3(x,y,z)      ((x)|((y)<<8)|((z)<<16))
  103 
  104 struct finst {
  105         const char *    f_name;         /* name for memory instruction */
  106         int     f_size;                 /* size for memory instruction */
  107         int     f_rrmode;               /* mode for rr instruction */
  108         const void *    f_rrname;       /* name for rr instruction
  109                                            (or pointer to table) */
  110 };
  111 
  112 static const char * const db_Grp6[] = {
  113         "sldt",
  114         "str",
  115         "lldt",
  116         "ltr",
  117         "verr",
  118         "verw",
  119         "",
  120         ""
  121 };
  122 
  123 static const char * const db_Grp7[] = {
  124         "sgdt",
  125         "sidt",
  126         "lgdt",
  127         "lidt",
  128         "smsw",
  129         "",
  130         "lmsw",
  131         "invlpg"
  132 };
  133 
  134 static const char * const db_Grp8[] = {
  135         "",
  136         "",
  137         "",
  138         "",
  139         "bt",
  140         "bts",
  141         "btr",
  142         "btc"
  143 };
  144 
  145 static const char * const db_Grp9[] = {
  146         "",
  147         "cmpxchg8b",
  148         "",
  149         "",
  150         "",
  151         "",
  152         "",
  153         ""
  154 };
  155 
  156 static const struct inst db_inst_0f0x[] = {
  157 /*00*/  { "",      TRUE,  NONE,  op1(Ew),     db_Grp6 },
  158 /*01*/  { "",      TRUE,  NONE,  op1(Ew),     db_Grp7 },
  159 /*02*/  { "lar",   TRUE,  LONG,  op2(E,R),    0 },
  160 /*03*/  { "lsl",   TRUE,  LONG,  op2(E,R),    0 },
  161 /*04*/  { "",      FALSE, NONE,  0,           0 },
  162 /*05*/  { "",      FALSE, NONE,  0,           0 },
  163 /*06*/  { "clts",  FALSE, NONE,  0,           0 },
  164 /*07*/  { "",      FALSE, NONE,  0,           0 },
  165 
  166 /*08*/  { "invd",  FALSE, NONE,  0,           0 },
  167 /*09*/  { "wbinvd",FALSE, NONE,  0,           0 },
  168 /*0a*/  { "",      FALSE, NONE,  0,           0 },
  169 /*0b*/  { "",      FALSE, NONE,  0,           0 },
  170 /*0c*/  { "",      FALSE, NONE,  0,           0 },
  171 /*0d*/  { "",      FALSE, NONE,  0,           0 },
  172 /*0e*/  { "",      FALSE, NONE,  0,           0 },
  173 /*0f*/  { "",      FALSE, NONE,  0,           0 },
  174 };
  175 
  176 static const struct inst db_inst_0f2x[] = {
  177 /*20*/  { "mov",   TRUE,  LONG,  op2(CR,El),  0 },
  178 /*21*/  { "mov",   TRUE,  LONG,  op2(DR,El),  0 },
  179 /*22*/  { "mov",   TRUE,  LONG,  op2(El,CR),  0 },
  180 /*23*/  { "mov",   TRUE,  LONG,  op2(El,DR),  0 },
  181 /*24*/  { "mov",   TRUE,  LONG,  op2(TR,El),  0 },
  182 /*25*/  { "",      FALSE, NONE,  0,           0 },
  183 /*26*/  { "mov",   TRUE,  LONG,  op2(El,TR),  0 },
  184 /*27*/  { "",      FALSE, NONE,  0,           0 },
  185 
  186 /*28*/  { "",      FALSE, NONE,  0,           0 },
  187 /*29*/  { "",      FALSE, NONE,  0,           0 },
  188 /*2a*/  { "",      FALSE, NONE,  0,           0 },
  189 /*2b*/  { "",      FALSE, NONE,  0,           0 },
  190 /*2c*/  { "",      FALSE, NONE,  0,           0 },
  191 /*2d*/  { "",      FALSE, NONE,  0,           0 },
  192 /*2e*/  { "",      FALSE, NONE,  0,           0 },
  193 /*2f*/  { "",      FALSE, NONE,  0,           0 },
  194 };
  195 
  196 static const struct inst db_inst_0f3x[] = {
  197 /*30*/  { "wrmsr", FALSE, NONE,  0,           0 },
  198 /*31*/  { "rdtsc", FALSE, NONE,  0,           0 },
  199 /*32*/  { "rdmsr", FALSE, NONE,  0,           0 },
  200 /*33*/  { "rdpmc", FALSE, NONE,  0,           0 },
  201 /*34*/  { "",      FALSE, NONE,  0,           0 },
  202 /*35*/  { "",      FALSE, NONE,  0,           0 },
  203 /*36*/  { "",      FALSE, NONE,  0,           0 },
  204 /*37*/  { "",      FALSE, NONE,  0,           0 },
  205 
  206 /*38*/  { "",      FALSE, NONE,  0,           0 },
  207 /*39*/  { "",      FALSE, NONE,  0,           0 },
  208 /*3a*/  { "",      FALSE, NONE,  0,           0 },
  209 /*3b*/  { "",      FALSE, NONE,  0,           0 },
  210 /*3c*/  { "",      FALSE, NONE,  0,           0 },
  211 /*3d*/  { "",      FALSE, NONE,  0,           0 },
  212 /*3e*/  { "",      FALSE, NONE,  0,           0 },
  213 /*3f*/  { "",      FALSE, NONE,  0,           0 },
  214 };
  215 
  216 static const struct inst db_inst_0f8x[] = {
  217 /*80*/  { "jo",    FALSE, NONE,  op1(Dl),     0 },
  218 /*81*/  { "jno",   FALSE, NONE,  op1(Dl),     0 },
  219 /*82*/  { "jb",    FALSE, NONE,  op1(Dl),     0 },
  220 /*83*/  { "jnb",   FALSE, NONE,  op1(Dl),     0 },
  221 /*84*/  { "jz",    FALSE, NONE,  op1(Dl),     0 },
  222 /*85*/  { "jnz",   FALSE, NONE,  op1(Dl),     0 },
  223 /*86*/  { "jbe",   FALSE, NONE,  op1(Dl),     0 },
  224 /*87*/  { "jnbe",  FALSE, NONE,  op1(Dl),     0 },
  225 
  226 /*88*/  { "js",    FALSE, NONE,  op1(Dl),     0 },
  227 /*89*/  { "jns",   FALSE, NONE,  op1(Dl),     0 },
  228 /*8a*/  { "jp",    FALSE, NONE,  op1(Dl),     0 },
  229 /*8b*/  { "jnp",   FALSE, NONE,  op1(Dl),     0 },
  230 /*8c*/  { "jl",    FALSE, NONE,  op1(Dl),     0 },
  231 /*8d*/  { "jnl",   FALSE, NONE,  op1(Dl),     0 },
  232 /*8e*/  { "jle",   FALSE, NONE,  op1(Dl),     0 },
  233 /*8f*/  { "jnle",  FALSE, NONE,  op1(Dl),     0 },
  234 };
  235 
  236 static const struct inst db_inst_0f9x[] = {
  237 /*90*/  { "seto",  TRUE,  NONE,  op1(Eb),     0 },
  238 /*91*/  { "setno", TRUE,  NONE,  op1(Eb),     0 },
  239 /*92*/  { "setb",  TRUE,  NONE,  op1(Eb),     0 },
  240 /*93*/  { "setnb", TRUE,  NONE,  op1(Eb),     0 },
  241 /*94*/  { "setz",  TRUE,  NONE,  op1(Eb),     0 },
  242 /*95*/  { "setnz", TRUE,  NONE,  op1(Eb),     0 },
  243 /*96*/  { "setbe", TRUE,  NONE,  op1(Eb),     0 },
  244 /*97*/  { "setnbe",TRUE,  NONE,  op1(Eb),     0 },
  245 
  246 /*98*/  { "sets",  TRUE,  NONE,  op1(Eb),     0 },
  247 /*99*/  { "setns", TRUE,  NONE,  op1(Eb),     0 },
  248 /*9a*/  { "setp",  TRUE,  NONE,  op1(Eb),     0 },
  249 /*9b*/  { "setnp", TRUE,  NONE,  op1(Eb),     0 },
  250 /*9c*/  { "setl",  TRUE,  NONE,  op1(Eb),     0 },
  251 /*9d*/  { "setnl", TRUE,  NONE,  op1(Eb),     0 },
  252 /*9e*/  { "setle", TRUE,  NONE,  op1(Eb),     0 },
  253 /*9f*/  { "setnle",TRUE,  NONE,  op1(Eb),     0 },
  254 };
  255 
  256 static const struct inst db_inst_0fax[] = {
  257 /*a0*/  { "push",  FALSE, NONE,  op1(Si),     0 },
  258 /*a1*/  { "pop",   FALSE, NONE,  op1(Si),     0 },
  259 /*a2*/  { "cpuid", FALSE, NONE,  0,           0 },
  260 /*a3*/  { "bt",    TRUE,  LONG,  op2(R,E),    0 },
  261 /*a4*/  { "shld",  TRUE,  LONG,  op3(Ib,R,E), 0 },
  262 /*a5*/  { "shld",  TRUE,  LONG,  op3(CL,R,E), 0 },
  263 /*a6*/  { "",      FALSE, NONE,  0,           0 },
  264 /*a7*/  { "",      FALSE, NONE,  0,           0 },
  265 
  266 /*a8*/  { "push",  FALSE, NONE,  op1(Si),     0 },
  267 /*a9*/  { "pop",   FALSE, NONE,  op1(Si),     0 },
  268 /*aa*/  { "rsm",   FALSE, NONE,  0,           0 },
  269 /*ab*/  { "bts",   TRUE,  LONG,  op2(R,E),    0 },
  270 /*ac*/  { "shrd",  TRUE,  LONG,  op3(Ib,R,E), 0 },
  271 /*ad*/  { "shrd",  TRUE,  LONG,  op3(CL,R,E), 0 },
  272 /*a6*/  { "",      FALSE, NONE,  0,           0 },
  273 /*a7*/  { "imul",  TRUE,  LONG,  op2(E,R),    0 },
  274 };
  275 
  276 static const struct inst db_inst_0fbx[] = {
  277 /*b0*/  { "cmpxchg",TRUE, BYTE,  op2(R, E),   0 },
  278 /*b0*/  { "cmpxchg",TRUE, LONG,  op2(R, E),   0 },
  279 /*b2*/  { "lss",   TRUE,  LONG,  op2(E, R),   0 },
  280 /*b3*/  { "btr",   TRUE,  LONG,  op2(R, E),   0 },
  281 /*b4*/  { "lfs",   TRUE,  LONG,  op2(E, R),   0 },
  282 /*b5*/  { "lgs",   TRUE,  LONG,  op2(E, R),   0 },
  283 /*b6*/  { "movzb", TRUE,  LONG,  op2(Eb, R),  0 },
  284 /*b7*/  { "movzw", TRUE,  LONG,  op2(Ew, R),  0 },
  285 
  286 /*b8*/  { "",      FALSE, NONE,  0,           0 },
  287 /*b9*/  { "",      FALSE, NONE,  0,           0 },
  288 /*ba*/  { "",      TRUE,  LONG,  op2(Ib, E),  db_Grp8 },
  289 /*bb*/  { "btc",   TRUE,  LONG,  op2(R, E),   0 },
  290 /*bc*/  { "bsf",   TRUE,  LONG,  op2(E, R),   0 },
  291 /*bd*/  { "bsr",   TRUE,  LONG,  op2(E, R),   0 },
  292 /*be*/  { "movsb", TRUE,  LONG,  op2(Eb, R),  0 },
  293 /*bf*/  { "movsw", TRUE,  LONG,  op2(Ew, R),  0 },
  294 };
  295 
  296 static const struct inst db_inst_0fcx[] = {
  297 /*c0*/  { "xadd",  TRUE,  BYTE,  op2(R, E),   0 },
  298 /*c1*/  { "xadd",  TRUE,  LONG,  op2(R, E),   0 },
  299 /*c2*/  { "",      FALSE, NONE,  0,           0 },
  300 /*c3*/  { "",      FALSE, NONE,  0,           0 },
  301 /*c4*/  { "",      FALSE, NONE,  0,           0 },
  302 /*c5*/  { "",      FALSE, NONE,  0,           0 },
  303 /*c6*/  { "",      FALSE, NONE,  0,           0 },
  304 /*c7*/  { "",      TRUE,  NONE,  op1(E),      db_Grp9 },
  305 /*c8*/  { "bswap", FALSE, LONG,  op1(Ril),    0 },
  306 /*c9*/  { "bswap", FALSE, LONG,  op1(Ril),    0 },
  307 /*ca*/  { "bswap", FALSE, LONG,  op1(Ril),    0 },
  308 /*cb*/  { "bswap", FALSE, LONG,  op1(Ril),    0 },
  309 /*cc*/  { "bswap", FALSE, LONG,  op1(Ril),    0 },
  310 /*cd*/  { "bswap", FALSE, LONG,  op1(Ril),    0 },
  311 /*ce*/  { "bswap", FALSE, LONG,  op1(Ril),    0 },
  312 /*cf*/  { "bswap", FALSE, LONG,  op1(Ril),    0 },
  313 };
  314 
  315 static const struct inst * const db_inst_0f[] = {
  316         db_inst_0f0x,
  317         0,
  318         db_inst_0f2x,
  319         db_inst_0f3x,
  320         0,
  321         0,
  322         0,
  323         0,
  324         db_inst_0f8x,
  325         db_inst_0f9x,
  326         db_inst_0fax,
  327         db_inst_0fbx,
  328         db_inst_0fcx,
  329         0,
  330         0,
  331         0
  332 };
  333 
  334 static const char * const db_Esc92[] = {
  335         "fnop", "",     "",     "",     "",     "",     "",     ""
  336 };
  337 static const char * const db_Esc94[] = {
  338         "fchs", "fabs", "",     "",     "ftst", "fxam", "",     ""
  339 };
  340 static const char * const db_Esc95[] = {
  341         "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
  342 };
  343 static const char * const db_Esc96[] = {
  344         "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
  345         "fincstp"
  346 };
  347 static const char * const db_Esc97[] = {
  348         "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
  349 };
  350 
  351 static const char * const db_Esca5[] = {
  352         "",     "fucompp","",   "",     "",     "",     "",     ""
  353 };
  354 
  355 static const char * const db_Escb4[] = {
  356         "fneni","fndisi",       "fnclex","fninit","fsetpm",     "",     "",     ""
  357 };
  358 
  359 static const char * const db_Esce3[] = {
  360         "",     "fcompp","",    "",     "",     "",     "",     ""
  361 };
  362 
  363 static const char * const db_Escf4[] = {
  364         "fnstsw","",    "",     "",     "",     "",     "",     ""
  365 };
  366 
  367 static const struct finst db_Esc8[] = {
  368 /**/   { "fadd",   SNGL,  op2(STI,ST), 0 },
  369 /*1*/   { "fmul",   SNGL,  op2(STI,ST), 0 },
  370 /*2*/   { "fcom",   SNGL,  op2(STI,ST), 0 },
  371 /*3*/   { "fcomp",  SNGL,  op2(STI,ST), 0 },
  372 /*4*/   { "fsub",   SNGL,  op2(STI,ST), 0 },
  373 /*5*/   { "fsubr",  SNGL,  op2(STI,ST), 0 },
  374 /*6*/   { "fdiv",   SNGL,  op2(STI,ST), 0 },
  375 /*7*/   { "fdivr",  SNGL,  op2(STI,ST), 0 },
  376 };
  377 
  378 static const struct finst db_Esc9[] = {
  379 /**/   { "fld",    SNGL,  op1(STI),    0 },
  380 /*1*/   { "",       NONE,  op1(STI),    "fxch" },
  381 /*2*/   { "fst",    SNGL,  op1(X),      db_Esc92 },
  382 /*3*/   { "fstp",   SNGL,  0,           0 },
  383 /*4*/   { "fldenv", NONE,  op1(X),      db_Esc94 },
  384 /*5*/   { "fldcw",  NONE,  op1(X),      db_Esc95 },
  385 /*6*/   { "fnstenv",NONE,  op1(X),      db_Esc96 },
  386 /*7*/   { "fnstcw", NONE,  op1(X),      db_Esc97 },
  387 };
  388 
  389 static const struct finst db_Esca[] = {
  390 /**/   { "fiadd",  LONG,  0,           0 },
  391 /*1*/   { "fimul",  LONG,  0,           0 },
  392 /*2*/   { "ficom",  LONG,  0,           0 },
  393 /*3*/   { "ficomp", LONG,  0,           0 },
  394 /*4*/   { "fisub",  LONG,  0,           0 },
  395 /*5*/   { "fisubr", LONG,  op1(X),      db_Esca5 },
  396 /*6*/   { "fidiv",  LONG,  0,           0 },
  397 /*7*/   { "fidivr", LONG,  0,           0 }
  398 };
  399 
  400 static const struct finst db_Escb[] = {
  401 /**/   { "fild",   LONG,  0,           0 },
  402 /*1*/   { "",       NONE,  0,           0 },
  403 /*2*/   { "fist",   LONG,  0,           0 },
  404 /*3*/   { "fistp",  LONG,  0,           0 },
  405 /*4*/   { "",       WORD,  op1(X),      db_Escb4 },
  406 /*5*/   { "fld",    EXTR,  0,           0 },
  407 /*6*/   { "",       WORD,  0,           0 },
  408 /*7*/   { "fstp",   EXTR,  0,           0 },
  409 };
  410 
  411 static const struct finst db_Escc[] = {
  412 /**/   { "fadd",   DBLR,  op2(ST,STI), 0 },
  413 /*1*/   { "fmul",   DBLR,  op2(ST,STI), 0 },
  414 /*2*/   { "fcom",   DBLR,  0,           0 },
  415 /*3*/   { "fcomp",  DBLR,  0,           0 },
  416 /*4*/   { "fsub",   DBLR,  op2(ST,STI), "fsubr" },
  417 /*5*/   { "fsubr",  DBLR,  op2(ST,STI), "fsub" },
  418 /*6*/   { "fdiv",   DBLR,  op2(ST,STI), "fdivr" },
  419 /*7*/   { "fdivr",  DBLR,  op2(ST,STI), "fdiv" },
  420 };
  421 
  422 static const struct finst db_Escd[] = {
  423 /**/   { "fld",    DBLR,  op1(STI),    "ffree" },
  424 /*1*/   { "",       NONE,  0,           0 },
  425 /*2*/   { "fst",    DBLR,  op1(STI),    0 },
  426 /*3*/   { "fstp",   DBLR,  op1(STI),    0 },
  427 /*4*/   { "frstor", NONE,  op1(STI),    "fucom" },
  428 /*5*/   { "",       NONE,  op1(STI),    "fucomp" },
  429 /*6*/   { "fnsave", NONE,  0,           0 },
  430 /*7*/   { "fnstsw", NONE,  0,           0 },
  431 };
  432 
  433 static const struct finst db_Esce[] = {
  434 /**/   { "fiadd",  WORD,  op2(ST,STI), "faddp" },
  435 /*1*/   { "fimul",  WORD,  op2(ST,STI), "fmulp" },
  436 /*2*/   { "ficom",  WORD,  0,           0 },
  437 /*3*/   { "ficomp", WORD,  op1(X),      db_Esce3 },
  438 /*4*/   { "fisub",  WORD,  op2(ST,STI), "fsubrp" },
  439 /*5*/   { "fisubr", WORD,  op2(ST,STI), "fsubp" },
  440 /*6*/   { "fidiv",  WORD,  op2(ST,STI), "fdivrp" },
  441 /*7*/   { "fidivr", WORD,  op2(ST,STI), "fdivp" },
  442 };
  443 
  444 static const struct finst db_Escf[] = {
  445 /**/   { "fild",   WORD,  0,           0 },
  446 /*1*/   { "",       NONE,  0,           0 },
  447 /*2*/   { "fist",   WORD,  0,           0 },
  448 /*3*/   { "fistp",  WORD,  0,           0 },
  449 /*4*/   { "fbld",   NONE,  op1(XA),     db_Escf4 },
  450 /*5*/   { "fild",   QUAD,  0,           0 },
  451 /*6*/   { "fbstp",  NONE,  0,           0 },
  452 /*7*/   { "fistp",  QUAD,  0,           0 },
  453 };
  454 
  455 static const struct finst * const db_Esc_inst[] = {
  456         db_Esc8, db_Esc9, db_Esca, db_Escb,
  457         db_Escc, db_Escd, db_Esce, db_Escf
  458 };
  459 
  460 static const char * const db_Grp1[] = {
  461         "add",
  462         "or",
  463         "adc",
  464         "sbb",
  465         "and",
  466         "sub",
  467         "xor",
  468         "cmp"
  469 };
  470 
  471 static const char * const db_Grp2[] = {
  472         "rol",
  473         "ror",
  474         "rcl",
  475         "rcr",
  476         "shl",
  477         "shr",
  478         "shl",
  479         "sar"
  480 };
  481 
  482 static const struct inst db_Grp3[] = {
  483         { "test",  TRUE, NONE, op2(I,E), 0 },
  484         { "test",  TRUE, NONE, op2(I,E), 0 },
  485         { "not",   TRUE, NONE, op1(E),   0 },
  486         { "neg",   TRUE, NONE, op1(E),   0 },
  487         { "mul",   TRUE, NONE, op2(E,A), 0 },
  488         { "imul",  TRUE, NONE, op2(E,A), 0 },
  489         { "div",   TRUE, NONE, op2(E,A), 0 },
  490         { "idiv",  TRUE, NONE, op2(E,A), 0 },
  491 };
  492 
  493 static const struct inst db_Grp4[] = {
  494         { "inc",   TRUE, BYTE, op1(E),   0 },
  495         { "dec",   TRUE, BYTE, op1(E),   0 },
  496         { "",      TRUE, NONE, 0,        0 },
  497         { "",      TRUE, NONE, 0,        0 },
  498         { "",      TRUE, NONE, 0,        0 },
  499         { "",      TRUE, NONE, 0,        0 },
  500         { "",      TRUE, NONE, 0,        0 },
  501         { "",      TRUE, NONE, 0,        0 }
  502 };
  503 
  504 static const struct inst db_Grp5[] = {
  505         { "inc",   TRUE, LONG, op1(E),   0 },
  506         { "dec",   TRUE, LONG, op1(E),   0 },
  507         { "call",  TRUE, LONG, op1(Eind),0 },
  508         { "lcall", TRUE, LONG, op1(Eind),0 },
  509         { "jmp",   TRUE, LONG, op1(Eind),0 },
  510         { "ljmp",  TRUE, LONG, op1(Eind),0 },
  511         { "push",  TRUE, LONG, op1(E),   0 },
  512         { "",      TRUE, NONE, 0,        0 }
  513 };
  514 
  515 static const struct inst db_inst_table[256] = {
  516 /*00*/  { "add",   TRUE,  BYTE,  op2(R, E),  0 },
  517 /*01*/  { "add",   TRUE,  LONG,  op2(R, E),  0 },
  518 /*02*/  { "add",   TRUE,  BYTE,  op2(E, R),  0 },
  519 /*03*/  { "add",   TRUE,  LONG,  op2(E, R),  0 },
  520 /*04*/  { "add",   FALSE, BYTE,  op2(I, A),  0 },
  521 /*05*/  { "add",   FALSE, LONG,  op2(Is, A), 0 },
  522 /*06*/  { "push",  FALSE, NONE,  op1(Si),    0 },
  523 /*07*/  { "pop",   FALSE, NONE,  op1(Si),    0 },
  524 
  525 /*08*/  { "or",    TRUE,  BYTE,  op2(R, E),  0 },
  526 /*09*/  { "or",    TRUE,  LONG,  op2(R, E),  0 },
  527 /*0a*/  { "or",    TRUE,  BYTE,  op2(E, R),  0 },
  528 /*0b*/  { "or",    TRUE,  LONG,  op2(E, R),  0 },
  529 /*0c*/  { "or",    FALSE, BYTE,  op2(I, A),  0 },
  530 /*0d*/  { "or",    FALSE, LONG,  op2(I, A),  0 },
  531 /*0e*/  { "push",  FALSE, NONE,  op1(Si),    0 },
  532 /*0f*/  { "",      FALSE, NONE,  0,          0 },
  533 
  534 /*10*/  { "adc",   TRUE,  BYTE,  op2(R, E),  0 },
  535 /*11*/  { "adc",   TRUE,  LONG,  op2(R, E),  0 },
  536 /*12*/  { "adc",   TRUE,  BYTE,  op2(E, R),  0 },
  537 /*13*/  { "adc",   TRUE,  LONG,  op2(E, R),  0 },
  538 /*14*/  { "adc",   FALSE, BYTE,  op2(I, A),  0 },
  539 /*15*/  { "adc",   FALSE, LONG,  op2(Is, A), 0 },
  540 /*16*/  { "push",  FALSE, NONE,  op1(Si),    0 },
  541 /*17*/  { "pop",   FALSE, NONE,  op1(Si),    0 },
  542 
  543 /*18*/  { "sbb",   TRUE,  BYTE,  op2(R, E),  0 },
  544 /*19*/  { "sbb",   TRUE,  LONG,  op2(R, E),  0 },
  545 /*1a*/  { "sbb",   TRUE,  BYTE,  op2(E, R),  0 },
  546 /*1b*/  { "sbb",   TRUE,  LONG,  op2(E, R),  0 },
  547 /*1c*/  { "sbb",   FALSE, BYTE,  op2(I, A),  0 },
  548 /*1d*/  { "sbb",   FALSE, LONG,  op2(Is, A), 0 },
  549 /*1e*/  { "push",  FALSE, NONE,  op1(Si),    0 },
  550 /*1f*/  { "pop",   FALSE, NONE,  op1(Si),    0 },
  551 
  552 /*20*/  { "and",   TRUE,  BYTE,  op2(R, E),  0 },
  553 /*21*/  { "and",   TRUE,  LONG,  op2(R, E),  0 },
  554 /*22*/  { "and",   TRUE,  BYTE,  op2(E, R),  0 },
  555 /*23*/  { "and",   TRUE,  LONG,  op2(E, R),  0 },
  556 /*24*/  { "and",   FALSE, BYTE,  op2(I, A),  0 },
  557 /*25*/  { "and",   FALSE, LONG,  op2(I, A),  0 },
  558 /*26*/  { "",      FALSE, NONE,  0,          0 },
  559 /*27*/  { "daa",   FALSE, NONE,  0,          0 },
  560 
  561 /*28*/  { "sub",   TRUE,  BYTE,  op2(R, E),  0 },
  562 /*29*/  { "sub",   TRUE,  LONG,  op2(R, E),  0 },
  563 /*2a*/  { "sub",   TRUE,  BYTE,  op2(E, R),  0 },
  564 /*2b*/  { "sub",   TRUE,  LONG,  op2(E, R),  0 },
  565 /*2c*/  { "sub",   FALSE, BYTE,  op2(I, A),  0 },
  566 /*2d*/  { "sub",   FALSE, LONG,  op2(Is, A), 0 },
  567 /*2e*/  { "",      FALSE, NONE,  0,          0 },
  568 /*2f*/  { "das",   FALSE, NONE,  0,          0 },
  569 
  570 /*30*/  { "xor",   TRUE,  BYTE,  op2(R, E),  0 },
  571 /*31*/  { "xor",   TRUE,  LONG,  op2(R, E),  0 },
  572 /*32*/  { "xor",   TRUE,  BYTE,  op2(E, R),  0 },
  573 /*33*/  { "xor",   TRUE,  LONG,  op2(E, R),  0 },
  574 /*34*/  { "xor",   FALSE, BYTE,  op2(I, A),  0 },
  575 /*35*/  { "xor",   FALSE, LONG,  op2(I, A),  0 },
  576 /*36*/  { "",      FALSE, NONE,  0,          0 },
  577 /*37*/  { "aaa",   FALSE, NONE,  0,          0 },
  578 
  579 /*38*/  { "cmp",   TRUE,  BYTE,  op2(R, E),  0 },
  580 /*39*/  { "cmp",   TRUE,  LONG,  op2(R, E),  0 },
  581 /*3a*/  { "cmp",   TRUE,  BYTE,  op2(E, R),  0 },
  582 /*3b*/  { "cmp",   TRUE,  LONG,  op2(E, R),  0 },
  583 /*3c*/  { "cmp",   FALSE, BYTE,  op2(I, A),  0 },
  584 /*3d*/  { "cmp",   FALSE, LONG,  op2(Is, A), 0 },
  585 /*3e*/  { "",      FALSE, NONE,  0,          0 },
  586 /*3f*/  { "aas",   FALSE, NONE,  0,          0 },
  587 
  588 /*40*/  { "inc",   FALSE, LONG,  op1(Ri),    0 },
  589 /*41*/  { "inc",   FALSE, LONG,  op1(Ri),    0 },
  590 /*42*/  { "inc",   FALSE, LONG,  op1(Ri),    0 },
  591 /*43*/  { "inc",   FALSE, LONG,  op1(Ri),    0 },
  592 /*44*/  { "inc",   FALSE, LONG,  op1(Ri),    0 },
  593 /*45*/  { "inc",   FALSE, LONG,  op1(Ri),    0 },
  594 /*46*/  { "inc",   FALSE, LONG,  op1(Ri),    0 },
  595 /*47*/  { "inc",   FALSE, LONG,  op1(Ri),    0 },
  596 
  597 /*48*/  { "dec",   FALSE, LONG,  op1(Ri),    0 },
  598 /*49*/  { "dec",   FALSE, LONG,  op1(Ri),    0 },
  599 /*4a*/  { "dec",   FALSE, LONG,  op1(Ri),    0 },
  600 /*4b*/  { "dec",   FALSE, LONG,  op1(Ri),    0 },
  601 /*4c*/  { "dec",   FALSE, LONG,  op1(Ri),    0 },
  602 /*4d*/  { "dec",   FALSE, LONG,  op1(Ri),    0 },
  603 /*4e*/  { "dec",   FALSE, LONG,  op1(Ri),    0 },
  604 /*4f*/  { "dec",   FALSE, LONG,  op1(Ri),    0 },
  605 
  606 /*50*/  { "push",  FALSE, LONG,  op1(Ri),    0 },
  607 /*51*/  { "push",  FALSE, LONG,  op1(Ri),    0 },
  608 /*52*/  { "push",  FALSE, LONG,  op1(Ri),    0 },
  609 /*53*/  { "push",  FALSE, LONG,  op1(Ri),    0 },
  610 /*54*/  { "push",  FALSE, LONG,  op1(Ri),    0 },
  611 /*55*/  { "push",  FALSE, LONG,  op1(Ri),    0 },
  612 /*56*/  { "push",  FALSE, LONG,  op1(Ri),    0 },
  613 /*57*/  { "push",  FALSE, LONG,  op1(Ri),    0 },
  614 
  615 /*58*/  { "pop",   FALSE, LONG,  op1(Ri),    0 },
  616 /*59*/  { "pop",   FALSE, LONG,  op1(Ri),    0 },
  617 /*5a*/  { "pop",   FALSE, LONG,  op1(Ri),    0 },
  618 /*5b*/  { "pop",   FALSE, LONG,  op1(Ri),    0 },
  619 /*5c*/  { "pop",   FALSE, LONG,  op1(Ri),    0 },
  620 /*5d*/  { "pop",   FALSE, LONG,  op1(Ri),    0 },
  621 /*5e*/  { "pop",   FALSE, LONG,  op1(Ri),    0 },
  622 /*5f*/  { "pop",   FALSE, LONG,  op1(Ri),    0 },
  623 
  624 /*60*/  { "pusha", FALSE, LONG,  0,          0 },
  625 /*61*/  { "popa",  FALSE, LONG,  0,          0 },
  626 /*62*/  { "bound", TRUE,  LONG,  op2(E, R),  0 },
  627 /*63*/  { "arpl",  TRUE,  NONE,  op2(Rw,Ew), 0 },
  628 
  629 /*64*/  { "",      FALSE, NONE,  0,          0 },
  630 /*65*/  { "",      FALSE, NONE,  0,          0 },
  631 /*66*/  { "",      FALSE, NONE,  0,          0 },
  632 /*67*/  { "",      FALSE, NONE,  0,          0 },
  633 
  634 /*68*/  { "push",  FALSE, LONG,  op1(I),     0 },
  635 /*69*/  { "imul",  TRUE,  LONG,  op3(I,E,R), 0 },
  636 /*6a*/  { "push",  FALSE, LONG,  op1(Ibs),   0 },
  637 /*6b*/  { "imul",  TRUE,  LONG,  op3(Ibs,E,R),0 },
  638 /*6c*/  { "ins",   FALSE, BYTE,  op2(DX, DI), 0 },
  639 /*6d*/  { "ins",   FALSE, LONG,  op2(DX, DI), 0 },
  640 /*6e*/  { "outs",  FALSE, BYTE,  op2(SI, DX), 0 },
  641 /*6f*/  { "outs",  FALSE, LONG,  op2(SI, DX), 0 },
  642 
  643 /*70*/  { "jo",    FALSE, NONE,  op1(Db),     0 },
  644 /*71*/  { "jno",   FALSE, NONE,  op1(Db),     0 },
  645 /*72*/  { "jb",    FALSE, NONE,  op1(Db),     0 },
  646 /*73*/  { "jnb",   FALSE, NONE,  op1(Db),     0 },
  647 /*74*/  { "jz",    FALSE, NONE,  op1(Db),     0 },
  648 /*75*/  { "jnz",   FALSE, NONE,  op1(Db),     0 },
  649 /*76*/  { "jbe",   FALSE, NONE,  op1(Db),     0 },
  650 /*77*/  { "jnbe",  FALSE, NONE,  op1(Db),     0 },
  651 
  652 /*78*/  { "js",    FALSE, NONE,  op1(Db),     0 },
  653 /*79*/  { "jns",   FALSE, NONE,  op1(Db),     0 },
  654 /*7a*/  { "jp",    FALSE, NONE,  op1(Db),     0 },
  655 /*7b*/  { "jnp",   FALSE, NONE,  op1(Db),     0 },
  656 /*7c*/  { "jl",    FALSE, NONE,  op1(Db),     0 },
  657 /*7d*/  { "jnl",   FALSE, NONE,  op1(Db),     0 },
  658 /*7e*/  { "jle",   FALSE, NONE,  op1(Db),     0 },
  659 /*7f*/  { "jnle",  FALSE, NONE,  op1(Db),     0 },
  660 
  661 /*80*/  { "",      TRUE,  BYTE,  op2(I, E),   db_Grp1 },
  662 /*81*/  { "",      TRUE,  LONG,  op2(I, E),   db_Grp1 },
  663 /*82*/  { "",      TRUE,  BYTE,  op2(I, E),   db_Grp1 },
  664 /*83*/  { "",      TRUE,  LONG,  op2(Ibs,E),  db_Grp1 },
  665 /*84*/  { "test",  TRUE,  BYTE,  op2(R, E),   0 },
  666 /*85*/  { "test",  TRUE,  LONG,  op2(R, E),   0 },
  667 /*86*/  { "xchg",  TRUE,  BYTE,  op2(R, E),   0 },
  668 /*87*/  { "xchg",  TRUE,  LONG,  op2(R, E),   0 },
  669 
  670 /*88*/  { "mov",   TRUE,  BYTE,  op2(R, E),   0 },
  671 /*89*/  { "mov",   TRUE,  LONG,  op2(R, E),   0 },
  672 /*8a*/  { "mov",   TRUE,  BYTE,  op2(E, R),   0 },
  673 /*8b*/  { "mov",   TRUE,  LONG,  op2(E, R),   0 },
  674 /*8c*/  { "mov",   TRUE,  NONE,  op2(S, Ew),  0 },
  675 /*8d*/  { "lea",   TRUE,  LONG,  op2(E, R),   0 },
  676 /*8e*/  { "mov",   TRUE,  NONE,  op2(Ew, S),  0 },
  677 /*8f*/  { "pop",   TRUE,  LONG,  op1(E),      0 },
  678 
  679 /*90*/  { "nop",   FALSE, NONE,  0,           0 },
  680 /*91*/  { "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
  681 /*92*/  { "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
  682 /*93*/  { "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
  683 /*94*/  { "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
  684 /*95*/  { "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
  685 /*96*/  { "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
  686 /*97*/  { "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
  687 
  688 /*98*/  { "cbw",   FALSE, SDEP,  0,           "cwde" }, /* cbw/cwde */
  689 /*99*/  { "cwd",   FALSE, SDEP,  0,           "cdq"  }, /* cwd/cdq */
  690 /*9a*/  { "lcall", FALSE, NONE,  op1(OS),     0 },
  691 /*9b*/  { "wait",  FALSE, NONE,  0,           0 },
  692 /*9c*/  { "pushf", FALSE, LONG,  0,           0 },
  693 /*9d*/  { "popf",  FALSE, LONG,  0,           0 },
  694 /*9e*/  { "sahf",  FALSE, NONE,  0,           0 },
  695 /*9f*/  { "lahf",  FALSE, NONE,  0,           0 },
  696 
  697 /*a0*/  { "mov",   FALSE, BYTE,  op2(O, A),   0 },
  698 /*a1*/  { "mov",   FALSE, LONG,  op2(O, A),   0 },
  699 /*a2*/  { "mov",   FALSE, BYTE,  op2(A, O),   0 },
  700 /*a3*/  { "mov",   FALSE, LONG,  op2(A, O),   0 },
  701 /*a4*/  { "movs",  FALSE, BYTE,  op2(SI,DI),  0 },
  702 /*a5*/  { "movs",  FALSE, LONG,  op2(SI,DI),  0 },
  703 /*a6*/  { "cmps",  FALSE, BYTE,  op2(SI,DI),  0 },
  704 /*a7*/  { "cmps",  FALSE, LONG,  op2(SI,DI),  0 },
  705 
  706 /*a8*/  { "test",  FALSE, BYTE,  op2(I, A),   0 },
  707 /*a9*/  { "test",  FALSE, LONG,  op2(I, A),   0 },
  708 /*aa*/  { "stos",  FALSE, BYTE,  op1(DI),     0 },
  709 /*ab*/  { "stos",  FALSE, LONG,  op1(DI),     0 },
  710 /*ac*/  { "lods",  FALSE, BYTE,  op1(SI),     0 },
  711 /*ad*/  { "lods",  FALSE, LONG,  op1(SI),     0 },
  712 /*ae*/  { "scas",  FALSE, BYTE,  op1(SI),     0 },
  713 /*af*/  { "scas",  FALSE, LONG,  op1(SI),     0 },
  714 
  715 /*b0*/  { "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
  716 /*b1*/  { "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
  717 /*b2*/  { "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
  718 /*b3*/  { "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
  719 /*b4*/  { "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
  720 /*b5*/  { "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
  721 /*b6*/  { "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
  722 /*b7*/  { "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
  723 
  724 /*b8*/  { "mov",   FALSE, LONG,  op2(I, Ri),  0 },
  725 /*b9*/  { "mov",   FALSE, LONG,  op2(I, Ri),  0 },
  726 /*ba*/  { "mov",   FALSE, LONG,  op2(I, Ri),  0 },
  727 /*bb*/  { "mov",   FALSE, LONG,  op2(I, Ri),  0 },
  728 /*bc*/  { "mov",   FALSE, LONG,  op2(I, Ri),  0 },
  729 /*bd*/  { "mov",   FALSE, LONG,  op2(I, Ri),  0 },
  730 /*be*/  { "mov",   FALSE, LONG,  op2(I, Ri),  0 },
  731 /*bf*/  { "mov",   FALSE, LONG,  op2(I, Ri),  0 },
  732 
  733 /*c0*/  { "",      TRUE,  BYTE,  op2(Ib, E),  db_Grp2 },
  734 /*c1*/  { "",      TRUE,  LONG,  op2(Ib, E),  db_Grp2 },
  735 /*c2*/  { "ret",   FALSE, NONE,  op1(Iw),     0 },
  736 /*c3*/  { "ret",   FALSE, NONE,  0,           0 },
  737 /*c4*/  { "les",   TRUE,  LONG,  op2(E, R),   0 },
  738 /*c5*/  { "lds",   TRUE,  LONG,  op2(E, R),   0 },
  739 /*c6*/  { "mov",   TRUE,  BYTE,  op2(I, E),   0 },
  740 /*c7*/  { "mov",   TRUE,  LONG,  op2(I, E),   0 },
  741 
  742 /*c8*/  { "enter", FALSE, NONE,  op2(Iw, Ib), 0 },
  743 /*c9*/  { "leave", FALSE, NONE,  0,           0 },
  744 /*ca*/  { "lret",  FALSE, NONE,  op1(Iw),     0 },
  745 /*cb*/  { "lret",  FALSE, NONE,  0,           0 },
  746 /*cc*/  { "int",   FALSE, NONE,  op1(o3),     0 },
  747 /*cd*/  { "int",   FALSE, NONE,  op1(Ib),     0 },
  748 /*ce*/  { "into",  FALSE, NONE,  0,           0 },
  749 /*cf*/  { "iret",  FALSE, NONE,  0,           0 },
  750 
  751 /*d0*/  { "",      TRUE,  BYTE,  op2(o1, E),  db_Grp2 },
  752 /*d1*/  { "",      TRUE,  LONG,  op2(o1, E),  db_Grp2 },
  753 /*d2*/  { "",      TRUE,  BYTE,  op2(CL, E),  db_Grp2 },
  754 /*d3*/  { "",      TRUE,  LONG,  op2(CL, E),  db_Grp2 },
  755 /*d4*/  { "aam",   FALSE, NONE,  op1(Iba),    0 },
  756 /*d5*/  { "aad",   FALSE, NONE,  op1(Iba),    0 },
  757 /*d6*/  { ".byte\t0xd6", FALSE, NONE, 0,      0 },
  758 /*d7*/  { "xlat",  FALSE, BYTE,  op1(BX),     0 },
  759 
  760 /*d8*/  { "",      TRUE,  NONE,  0,           db_Esc8 },
  761 /*d9*/  { "",      TRUE,  NONE,  0,           db_Esc9 },
  762 /*da*/  { "",      TRUE,  NONE,  0,           db_Esca },
  763 /*db*/  { "",      TRUE,  NONE,  0,           db_Escb },
  764 /*dc*/  { "",      TRUE,  NONE,  0,           db_Escc },
  765 /*dd*/  { "",      TRUE,  NONE,  0,           db_Escd },
  766 /*de*/  { "",      TRUE,  NONE,  0,           db_Esce },
  767 /*df*/  { "",      TRUE,  NONE,  0,           db_Escf },
  768 
  769 /*e0*/  { "loopne",FALSE, NONE,  op1(Db),     0 },
  770 /*e1*/  { "loope", FALSE, NONE,  op1(Db),     0 },
  771 /*e2*/  { "loop",  FALSE, NONE,  op1(Db),     0 },
  772 /*e3*/  { "jcxz",  FALSE, SDEP,  op1(Db),     "jecxz" },
  773 /*e4*/  { "in",    FALSE, BYTE,  op2(Ib, A),  0 },
  774 /*e5*/  { "in",    FALSE, LONG,  op2(Ib, A) , 0 },
  775 /*e6*/  { "out",   FALSE, BYTE,  op2(A, Ib),  0 },
  776 /*e7*/  { "out",   FALSE, LONG,  op2(A, Ib) , 0 },
  777 
  778 /*e8*/  { "call",  FALSE, NONE,  op1(Dl),     0 },
  779 /*e9*/  { "jmp",   FALSE, NONE,  op1(Dl),     0 },
  780 /*ea*/  { "ljmp",  FALSE, NONE,  op1(OS),     0 },
  781 /*eb*/  { "jmp",   FALSE, NONE,  op1(Db),     0 },
  782 /*ec*/  { "in",    FALSE, BYTE,  op2(DX, A),  0 },
  783 /*ed*/  { "in",    FALSE, LONG,  op2(DX, A) , 0 },
  784 /*ee*/  { "out",   FALSE, BYTE,  op2(A, DX),  0 },
  785 /*ef*/  { "out",   FALSE, LONG,  op2(A, DX) , 0 },
  786 
  787 /*f0*/  { "",      FALSE, NONE,  0,          0 },
  788 /*f1*/  { ".byte\t0xf1", FALSE, NONE, 0,     0 },
  789 /*f2*/  { "",      FALSE, NONE,  0,          0 },
  790 /*f3*/  { "",      FALSE, NONE,  0,          0 },
  791 /*f4*/  { "hlt",   FALSE, NONE,  0,          0 },
  792 /*f5*/  { "cmc",   FALSE, NONE,  0,          0 },
  793 /*f6*/  { "",      TRUE,  BYTE,  0,          db_Grp3 },
  794 /*f7*/  { "",      TRUE,  LONG,  0,          db_Grp3 },
  795 
  796 /*f8*/  { "clc",   FALSE, NONE,  0,          0 },
  797 /*f9*/  { "stc",   FALSE, NONE,  0,          0 },
  798 /*fa*/  { "cli",   FALSE, NONE,  0,          0 },
  799 /*fb*/  { "sti",   FALSE, NONE,  0,          0 },
  800 /*fc*/  { "cld",   FALSE, NONE,  0,          0 },
  801 /*fd*/  { "std",   FALSE, NONE,  0,          0 },
  802 /*fe*/  { "",      TRUE,  NONE,  0,          db_Grp4 },
  803 /*ff*/  { "",      TRUE,  NONE,  0,          db_Grp5 },
  804 };
  805 
  806 static const struct inst db_bad_inst =
  807         { "???",   FALSE, NONE,  0,           0 }
  808 ;
  809 
  810 #define f_mod(byte)     ((byte)>>6)
  811 #define f_reg(byte)     (((byte)>>3)&0x7)
  812 #define f_rm(byte)      ((byte)&0x7)
  813 
  814 #define sib_ss(byte)    ((byte)>>6)
  815 #define sib_index(byte) (((byte)>>3)&0x7)
  816 #define sib_base(byte)  ((byte)&0x7)
  817 
  818 struct i_addr {
  819         int             is_reg; /* if reg, reg number is in 'disp' */
  820         int             disp;
  821         const char *    base;
  822         const char *    index;
  823         int             ss;
  824 };
  825 
  826 static const char * const db_index_reg_16[8] = {
  827         "%bx,%si",
  828         "%bx,%di",
  829         "%bp,%si",
  830         "%bp,%di",
  831         "%si",
  832         "%di",
  833         "%bp",
  834         "%bx"
  835 };
  836 
  837 static const char * const db_reg[3][8] = {
  838         { "%al",  "%cl",  "%dl",  "%bl",  "%ah",  "%ch",  "%dh",  "%bh" },
  839         { "%ax",  "%cx",  "%dx",  "%bx",  "%sp",  "%bp",  "%si",  "%di" },
  840         { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi" }
  841 };
  842 
  843 static const char * const db_seg_reg[8] = {
  844         "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
  845 };
  846 
  847 /*
  848  * lengths for size attributes
  849  */
  850 static const int db_lengths[] = {
  851         1,      /* BYTE */
  852         2,      /* WORD */
  853         4,      /* LONG */
  854         8,      /* QUAD */
  855         4,      /* SNGL */
  856         8,      /* DBLR */
  857         10,     /* EXTR */
  858 };
  859 
  860 #define get_value_inc(result, loc, size, is_signed) \
  861         result = db_get_value((loc), (size), (is_signed)); \
  862         (loc) += (size);
  863 
  864 static db_addr_t
  865                 db_disasm_esc(db_addr_t loc, int inst, int short_addr,
  866                     int size, const char *seg);
  867 static void     db_print_address(const char *seg, int size,
  868                     struct i_addr *addrp);
  869 static db_addr_t
  870                 db_read_address(db_addr_t loc, int short_addr, int regmodrm,
  871                     struct i_addr *addrp);
  872 
  873 /*
  874  * Read address at location and return updated location.
  875  */
  876 static db_addr_t
  877 db_read_address(loc, short_addr, regmodrm, addrp)
  878         db_addr_t       loc;
  879         int             short_addr;
  880         int             regmodrm;
  881         struct i_addr * addrp;          /* out */
  882 {
  883         int             mod, rm, sib, index, disp;
  884 
  885         mod = f_mod(regmodrm);
  886         rm  = f_rm(regmodrm);
  887 
  888         if (mod == 3) {
  889             addrp->is_reg = TRUE;
  890             addrp->disp = rm;
  891             return (loc);
  892         }
  893         addrp->is_reg = FALSE;
  894         addrp->index = 0;
  895 
  896         if (short_addr) {
  897             addrp->index = 0;
  898             addrp->ss = 0;
  899             switch (mod) {
  900                 case 0:
  901                     if (rm == 6) {
  902                         get_value_inc(disp, loc, 2, FALSE);
  903                         addrp->disp = disp;
  904                         addrp->base = 0;
  905                     }
  906                     else {
  907                         addrp->disp = 0;
  908                         addrp->base = db_index_reg_16[rm];
  909                     }
  910                     break;
  911                 case 1:
  912                     get_value_inc(disp, loc, 1, TRUE);
  913                     disp &= 0xFFFF;
  914                     addrp->disp = disp;
  915                     addrp->base = db_index_reg_16[rm];
  916                     break;
  917                 case 2:
  918                     get_value_inc(disp, loc, 2, FALSE);
  919                     addrp->disp = disp;
  920                     addrp->base = db_index_reg_16[rm];
  921                     break;
  922             }
  923         }
  924         else {
  925             if (mod != 3 && rm == 4) {
  926                 get_value_inc(sib, loc, 1, FALSE);
  927                 rm = sib_base(sib);
  928                 index = sib_index(sib);
  929                 if (index != 4)
  930                     addrp->index = db_reg[LONG][index];
  931                 addrp->ss = sib_ss(sib);
  932             }
  933 
  934             switch (mod) {
  935                 case 0:
  936                     if (rm == 5) {
  937                         get_value_inc(addrp->disp, loc, 4, FALSE);
  938                         addrp->base = 0;
  939                     }
  940                     else {
  941                         addrp->disp = 0;
  942                         addrp->base = db_reg[LONG][rm];
  943                     }
  944                     break;
  945 
  946                 case 1:
  947                     get_value_inc(disp, loc, 1, TRUE);
  948                     addrp->disp = disp;
  949                     addrp->base = db_reg[LONG][rm];
  950                     break;
  951 
  952                 case 2:
  953                     get_value_inc(disp, loc, 4, FALSE);
  954                     addrp->disp = disp;
  955                     addrp->base = db_reg[LONG][rm];
  956                     break;
  957             }
  958         }
  959         return (loc);
  960 }
  961 
  962 static void
  963 db_print_address(seg, size, addrp)
  964         const char *    seg;
  965         int             size;
  966         struct i_addr * addrp;
  967 {
  968         if (addrp->is_reg) {
  969             db_printf("%s", db_reg[size][addrp->disp]);
  970             return;
  971         }
  972 
  973         if (seg) {
  974             db_printf("%s:", seg);
  975         }
  976 
  977         db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY);
  978         if (addrp->base != 0 || addrp->index != 0) {
  979             db_printf("(");
  980             if (addrp->base)
  981                 db_printf("%s", addrp->base);
  982             if (addrp->index)
  983                 db_printf(",%s,%d", addrp->index, 1<<addrp->ss);
  984             db_printf(")");
  985         }
  986 }
  987 
  988 /*
  989  * Disassemble floating-point ("escape") instruction
  990  * and return updated location.
  991  */
  992 static db_addr_t
  993 db_disasm_esc(loc, inst, short_addr, size, seg)
  994         db_addr_t       loc;
  995         int             inst;
  996         int             short_addr;
  997         int             size;
  998         const char *    seg;
  999 {
 1000         int             regmodrm;
 1001         const struct finst *    fp;
 1002         int             mod;
 1003         struct i_addr   address;
 1004         const char *    name;
 1005 
 1006         get_value_inc(regmodrm, loc, 1, FALSE);
 1007         fp = &db_Esc_inst[inst - 0xd8][f_reg(regmodrm)];
 1008         mod = f_mod(regmodrm);
 1009         if (mod != 3) {
 1010             if (*fp->f_name == '\0') {
 1011                 db_printf("<bad instruction>");
 1012                 return (loc);
 1013             }
 1014             /*
 1015              * Normal address modes.
 1016              */
 1017             loc = db_read_address(loc, short_addr, regmodrm, &address);
 1018             db_printf("%s", fp->f_name);
 1019             switch(fp->f_size) {
 1020                 case SNGL:
 1021                     db_printf("s");
 1022                     break;
 1023                 case DBLR:
 1024                     db_printf("l");
 1025                     break;
 1026                 case EXTR:
 1027                     db_printf("t");
 1028                     break;
 1029                 case WORD:
 1030                     db_printf("s");
 1031                     break;
 1032                 case LONG:
 1033                     db_printf("l");
 1034                     break;
 1035                 case QUAD:
 1036                     db_printf("q");
 1037                     break;
 1038                 default:
 1039                     break;
 1040             }
 1041             db_printf("\t");
 1042             db_print_address(seg, BYTE, &address);
 1043         }
 1044         else {
 1045             /*
 1046              * 'reg-reg' - special formats
 1047              */
 1048             switch (fp->f_rrmode) {
 1049                 case op2(ST,STI):
 1050                     name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
 1051                     db_printf("%s\t%%st,%%st(%d)",name,f_rm(regmodrm));
 1052                     break;
 1053                 case op2(STI,ST):
 1054                     name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
 1055                     db_printf("%s\t%%st(%d),%%st",name, f_rm(regmodrm));
 1056                     break;
 1057                 case op1(STI):
 1058                     name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
 1059                     db_printf("%s\t%%st(%d)",name, f_rm(regmodrm));
 1060                     break;
 1061                 case op1(X):
 1062                     name = ((const char * const *)fp->f_rrname)[f_rm(regmodrm)];
 1063                     if (*name == '\0')
 1064                         goto bad;
 1065                     db_printf("%s", name);
 1066                     break;
 1067                 case op1(XA):
 1068                     name = ((const char * const *)fp->f_rrname)[f_rm(regmodrm)];
 1069                     if (*name == '\0')
 1070                         goto bad;
 1071                     db_printf("%s\t%%ax", name);
 1072                     break;
 1073                 default:
 1074                 bad:
 1075                     db_printf("<bad instruction>");
 1076                     break;
 1077             }
 1078         }
 1079 
 1080         return (loc);
 1081 }
 1082 
 1083 /*
 1084  * Disassemble instruction at 'loc'.  'altfmt' specifies an
 1085  * (optional) alternate format.  Return address of start of
 1086  * next instruction.
 1087  */
 1088 db_addr_t
 1089 db_disasm(loc, altfmt)
 1090         db_addr_t       loc;
 1091         boolean_t       altfmt;
 1092 {
 1093         int     inst;
 1094         int     size;
 1095         int     short_addr;
 1096         const char *    seg;
 1097         const struct inst *     ip;
 1098         const char *    i_name;
 1099         int     i_size;
 1100         int     i_mode;
 1101         int     regmodrm = 0;
 1102         boolean_t       first;
 1103         int     displ;
 1104         int     prefix;
 1105         int     imm;
 1106         int     imm2;
 1107         int     len;
 1108         struct i_addr   address;
 1109 
 1110         get_value_inc(inst, loc, 1, FALSE);
 1111         short_addr = FALSE;
 1112         size = LONG;
 1113         seg = 0;
 1114 
 1115         /*
 1116          * Get prefixes
 1117          */
 1118         prefix = TRUE;
 1119         do {
 1120             switch (inst) {
 1121                 case 0x66:              /* data16 */
 1122                     size = WORD;
 1123                     break;
 1124                 case 0x67:
 1125                     short_addr = TRUE;
 1126                     break;
 1127                 case 0x26:
 1128                     seg = "%es";
 1129                     break;
 1130                 case 0x36:
 1131                     seg = "%ss";
 1132                     break;
 1133                 case 0x2e:
 1134                     seg = "%cs";
 1135                     break;
 1136                 case 0x3e:
 1137                     seg = "%ds";
 1138                     break;
 1139                 case 0x64:
 1140                     seg = "%fs";
 1141                     break;
 1142                 case 0x65:
 1143                     seg = "%gs";
 1144                     break;
 1145                 case 0xf0:
 1146                     db_printf("lock ");
 1147                     break;
 1148                 case 0xf2:
 1149                     db_printf("repne ");
 1150                     break;
 1151                 case 0xf3:
 1152                     db_printf("repe "); /* XXX repe VS rep */
 1153                     break;
 1154                 default:
 1155                     prefix = FALSE;
 1156                     break;
 1157             }
 1158             if (prefix) {
 1159                 get_value_inc(inst, loc, 1, FALSE);
 1160             }
 1161         } while (prefix);
 1162 
 1163         if (inst >= 0xd8 && inst <= 0xdf) {
 1164             loc = db_disasm_esc(loc, inst, short_addr, size, seg);
 1165             db_printf("\n");
 1166             return (loc);
 1167         }
 1168 
 1169         if (inst == 0x0f) {
 1170             get_value_inc(inst, loc, 1, FALSE);
 1171             ip = db_inst_0f[inst>>4];
 1172             if (ip == 0) {
 1173                 ip = &db_bad_inst;
 1174             }
 1175             else {
 1176                 ip = &ip[inst&0xf];
 1177             }
 1178         }
 1179         else
 1180             ip = &db_inst_table[inst];
 1181 
 1182         if (ip->i_has_modrm) {
 1183             get_value_inc(regmodrm, loc, 1, FALSE);
 1184             loc = db_read_address(loc, short_addr, regmodrm, &address);
 1185         }
 1186 
 1187         i_name = ip->i_name;
 1188         i_size = ip->i_size;
 1189         i_mode = ip->i_mode;
 1190 
 1191         if (ip->i_extra == db_Grp1 || ip->i_extra == db_Grp2 ||
 1192             ip->i_extra == db_Grp6 || ip->i_extra == db_Grp7 ||
 1193             ip->i_extra == db_Grp8 || ip->i_extra == db_Grp9) {
 1194             i_name = ((const char * const *)ip->i_extra)[f_reg(regmodrm)];
 1195         }
 1196         else if (ip->i_extra == db_Grp3) {
 1197             ip = ip->i_extra;
 1198             ip = &ip[f_reg(regmodrm)];
 1199             i_name = ip->i_name;
 1200             i_mode = ip->i_mode;
 1201         }
 1202         else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) {
 1203             ip = ip->i_extra;
 1204             ip = &ip[f_reg(regmodrm)];
 1205             i_name = ip->i_name;
 1206             i_mode = ip->i_mode;
 1207             i_size = ip->i_size;
 1208         }
 1209 
 1210         if (i_size == SDEP) {
 1211             if (size == WORD)
 1212                 db_printf("%s", i_name);
 1213             else
 1214                 db_printf("%s", (const char *)ip->i_extra);
 1215         }
 1216         else {
 1217             db_printf("%s", i_name);
 1218             if (i_size != NONE) {
 1219                 if (i_size == BYTE) {
 1220                     db_printf("b");
 1221                     size = BYTE;
 1222                 }
 1223                 else if (i_size == WORD) {
 1224                     db_printf("w");
 1225                     size = WORD;
 1226                 }
 1227                 else if (size == WORD)
 1228                     db_printf("w");
 1229                 else
 1230                     db_printf("l");
 1231             }
 1232         }
 1233         db_printf("\t");
 1234         for (first = TRUE;
 1235              i_mode != 0;
 1236              i_mode >>= 8, first = FALSE)
 1237         {
 1238             if (!first)
 1239                 db_printf(",");
 1240 
 1241             switch (i_mode & 0xFF) {
 1242 
 1243                 case E:
 1244                     db_print_address(seg, size, &address);
 1245                     break;
 1246 
 1247                 case Eind:
 1248                     db_printf("*");
 1249                     db_print_address(seg, size, &address);
 1250                     break;
 1251 
 1252                 case El:
 1253                     db_print_address(seg, LONG, &address);
 1254                     break;
 1255 
 1256                 case Ew:
 1257                     db_print_address(seg, WORD, &address);
 1258                     break;
 1259 
 1260                 case Eb:
 1261                     db_print_address(seg, BYTE, &address);
 1262                     break;
 1263 
 1264                 case R:
 1265                     db_printf("%s", db_reg[size][f_reg(regmodrm)]);
 1266                     break;
 1267 
 1268                 case Rw:
 1269                     db_printf("%s", db_reg[WORD][f_reg(regmodrm)]);
 1270                     break;
 1271 
 1272                 case Ri:
 1273                     db_printf("%s", db_reg[size][f_rm(inst)]);
 1274                     break;
 1275 
 1276                 case Ril:
 1277                     db_printf("%s", db_reg[LONG][f_rm(inst)]);
 1278                     break;
 1279 
 1280                 case S:
 1281                     db_printf("%s", db_seg_reg[f_reg(regmodrm)]);
 1282                     break;
 1283 
 1284                 case Si:
 1285                     db_printf("%s", db_seg_reg[f_reg(inst)]);
 1286                     break;
 1287 
 1288                 case A:
 1289                     db_printf("%s", db_reg[size][0]);   /* acc */
 1290                     break;
 1291 
 1292                 case BX:
 1293                     if (seg)
 1294                         db_printf("%s:", seg);
 1295                     db_printf("(%s)", short_addr ? "%bx" : "%ebx");
 1296                     break;
 1297 
 1298                 case CL:
 1299                     db_printf("%%cl");
 1300                     break;
 1301 
 1302                 case DX:
 1303                     db_printf("%%dx");
 1304                     break;
 1305 
 1306                 case SI:
 1307                     if (seg)
 1308                         db_printf("%s:", seg);
 1309                     db_printf("(%s)", short_addr ? "%si" : "%esi");
 1310                     break;
 1311 
 1312                 case DI:
 1313                     db_printf("%%es:(%s)", short_addr ? "%di" : "%edi");
 1314                     break;
 1315 
 1316                 case CR:
 1317                     db_printf("%%cr%d", f_reg(regmodrm));
 1318                     break;
 1319 
 1320                 case DR:
 1321                     db_printf("%%dr%d", f_reg(regmodrm));
 1322                     break;
 1323 
 1324                 case TR:
 1325                     db_printf("%%tr%d", f_reg(regmodrm));
 1326                     break;
 1327 
 1328                 case I:
 1329                     len = db_lengths[size];
 1330                     get_value_inc(imm, loc, len, FALSE);
 1331                     db_printf("$%#r", imm);
 1332                     break;
 1333 
 1334                 case Is:
 1335                     len = db_lengths[size];
 1336                     get_value_inc(imm, loc, len, FALSE);
 1337                     db_printf("$%+#r", imm);
 1338                     break;
 1339 
 1340                 case Ib:
 1341                     get_value_inc(imm, loc, 1, FALSE);
 1342                     db_printf("$%#r", imm);
 1343                     break;
 1344 
 1345                 case Iba:
 1346                     get_value_inc(imm, loc, 1, FALSE);
 1347                     if (imm != 0x0a)
 1348                         db_printf("$%#r", imm);
 1349                     break;
 1350 
 1351                 case Ibs:
 1352                     get_value_inc(imm, loc, 1, TRUE);
 1353                     if (size == WORD)
 1354                         imm &= 0xFFFF;
 1355                     db_printf("$%+#r", imm);
 1356                     break;
 1357 
 1358                 case Iw:
 1359                     get_value_inc(imm, loc, 2, FALSE);
 1360                     db_printf("$%#r", imm);
 1361                     break;
 1362 
 1363                 case O:
 1364                     len = (short_addr ? 2 : 4);
 1365                     get_value_inc(displ, loc, len, FALSE);
 1366                     if (seg)
 1367                         db_printf("%s:%+#r",seg, displ);
 1368                     else
 1369                         db_printsym((db_addr_t)displ, DB_STGY_ANY);
 1370                     break;
 1371 
 1372                 case Db:
 1373                     get_value_inc(displ, loc, 1, TRUE);
 1374                     displ += loc;
 1375                     if (size == WORD)
 1376                         displ &= 0xFFFF;
 1377                     db_printsym((db_addr_t)displ, DB_STGY_XTRN);
 1378                     break;
 1379 
 1380                 case Dl:
 1381                     len = db_lengths[size];
 1382                     get_value_inc(displ, loc, len, FALSE);
 1383                     displ += loc;
 1384                     if (size == WORD)
 1385                         displ &= 0xFFFF;
 1386                     db_printsym((db_addr_t)displ, DB_STGY_XTRN);
 1387                     break;
 1388 
 1389                 case o1:
 1390                     db_printf("$1");
 1391                     break;
 1392 
 1393                 case o3:
 1394                     db_printf("$3");
 1395                     break;
 1396 
 1397                 case OS:
 1398                     len = db_lengths[size];
 1399                     get_value_inc(imm, loc, len, FALSE);        /* offset */
 1400                     get_value_inc(imm2, loc, 2, FALSE); /* segment */
 1401                     db_printf("$%#r,%#r", imm2, imm);
 1402                     break;
 1403             }
 1404         }
 1405         db_printf("\n");
 1406         return (loc);
 1407 }

Cache object: b8339fd09113ad855df3f3c71b5cbe14


[ 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.