db_disasm.c revision 181606
1139731Simp/*- 24Srgrimes * Mach Operating System 34Srgrimes * Copyright (c) 1991,1990 Carnegie Mellon University 44Srgrimes * All Rights Reserved. 58876Srgrimes * 64Srgrimes * Permission to use, copy, modify and distribute this software and its 74Srgrimes * documentation is hereby granted, provided that both the copyright 84Srgrimes * notice and this permission notice appear in all copies of the 94Srgrimes * software, derivative works or modified versions, and any portions 104Srgrimes * thereof, and that both notices appear in supporting documentation. 118876Srgrimes * 128876Srgrimes * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS 134Srgrimes * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 144Srgrimes * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 158876Srgrimes * 164Srgrimes * Carnegie Mellon requests users of this software to return to 178876Srgrimes * 184Srgrimes * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 194Srgrimes * School of Computer Science 204Srgrimes * Carnegie Mellon University 214Srgrimes * Pittsburgh PA 15213-3890 228876Srgrimes * 234Srgrimes * any improvements or extensions that they make and grant Carnegie the 244Srgrimes * rights to redistribute these changes. 254Srgrimes */ 264Srgrimes 27118031Sobrien#include <sys/cdefs.h> 28118031Sobrien__FBSDID("$FreeBSD: head/sys/amd64/amd64/db_disasm.c 181606 2008-08-11 20:19:42Z jhb $"); 29118031Sobrien 304Srgrimes/* 314Srgrimes * Instruction disassembler. 324Srgrimes */ 332056Swollman#include <sys/param.h> 3424494Sbde 352056Swollman#include <ddb/ddb.h> 364Srgrimes#include <ddb/db_access.h> 374Srgrimes#include <ddb/db_sym.h> 384Srgrimes 394Srgrimes/* 404Srgrimes * Size attributes 414Srgrimes */ 424Srgrimes#define BYTE 0 434Srgrimes#define WORD 1 444Srgrimes#define LONG 2 454Srgrimes#define QUAD 3 464Srgrimes#define SNGL 4 474Srgrimes#define DBLR 5 484Srgrimes#define EXTR 6 494Srgrimes#define SDEP 7 504Srgrimes#define NONE 8 514Srgrimes 524Srgrimes/* 53144353Speter * REX prefix and bits 54144353Speter */ 55144353Speter#define REX_B 1 56144353Speter#define REX_X 2 57144353Speter#define REX_R 4 58144353Speter#define REX_W 8 59144353Speter#define REX 0x40 60144353Speter 61144353Speter/* 624Srgrimes * Addressing modes 634Srgrimes */ 644Srgrimes#define E 1 /* general effective address */ 654Srgrimes#define Eind 2 /* indirect address (jump, call) */ 664Srgrimes#define Ew 3 /* address, word size */ 674Srgrimes#define Eb 4 /* address, byte size */ 684Srgrimes#define R 5 /* register, in 'reg' field */ 694Srgrimes#define Rw 6 /* word register, in 'reg' field */ 704Srgrimes#define Ri 7 /* register in instruction */ 714Srgrimes#define S 8 /* segment reg, in 'reg' field */ 724Srgrimes#define Si 9 /* segment reg, in instruction */ 734Srgrimes#define A 10 /* accumulator */ 744Srgrimes#define BX 11 /* (bx) */ 754Srgrimes#define CL 12 /* cl, for shifts */ 764Srgrimes#define DX 13 /* dx, for IO */ 774Srgrimes#define SI 14 /* si */ 784Srgrimes#define DI 15 /* di */ 794Srgrimes#define CR 16 /* control register */ 804Srgrimes#define DR 17 /* debug register */ 814Srgrimes#define TR 18 /* test register */ 824Srgrimes#define I 19 /* immediate, unsigned */ 834Srgrimes#define Is 20 /* immediate, signed */ 844Srgrimes#define Ib 21 /* byte immediate, unsigned */ 854Srgrimes#define Ibs 22 /* byte immediate, signed */ 864Srgrimes#define Iw 23 /* word immediate, unsigned */ 87164263Sjhb#define Ilq 24 /* long/quad immediate, unsigned */ 884Srgrimes#define O 25 /* direct address */ 894Srgrimes#define Db 26 /* byte displacement from EIP */ 904Srgrimes#define Dl 27 /* long displacement from EIP */ 914Srgrimes#define o1 28 /* constant 1 */ 924Srgrimes#define o3 29 /* constant 3 */ 934Srgrimes#define OS 30 /* immediate offset/segment */ 944Srgrimes#define ST 31 /* FP stack top */ 954Srgrimes#define STI 32 /* FP stack */ 964Srgrimes#define X 33 /* extended FP op */ 974Srgrimes#define XA 34 /* for 'fstcw %ax' */ 98144354Speter#define El 35 /* address, long/quad size */ 9921277Sbde#define Ril 36 /* long register in instruction */ 10021277Sbde#define Iba 37 /* byte immediate, don't print if 0xa */ 101144354Speter#define EL 38 /* address, explicitly long size */ 1024Srgrimes 10311940Sbdestruct inst { 10414887Swollman const char * i_name; /* name */ 1054Srgrimes short i_has_modrm; /* has regmodrm byte */ 1064Srgrimes short i_size; /* operand size */ 1074Srgrimes int i_mode; /* addressing modes */ 10817109Sbde const void * i_extra; /* pointer to extra opcode table */ 1094Srgrimes}; 1104Srgrimes 1114Srgrimes#define op1(x) (x) 1124Srgrimes#define op2(x,y) ((x)|((y)<<8)) 1134Srgrimes#define op3(x,y,z) ((x)|((y)<<8)|((z)<<16)) 1144Srgrimes 11511940Sbdestruct finst { 11614887Swollman const char * f_name; /* name for memory instruction */ 1174Srgrimes int f_size; /* size for memory instruction */ 1184Srgrimes int f_rrmode; /* mode for rr instruction */ 11917109Sbde const void * f_rrname; /* name for rr instruction 1204Srgrimes (or pointer to table) */ 1214Srgrimes}; 1224Srgrimes 12314887Swollmanstatic const char * const db_Grp6[] = { 1244Srgrimes "sldt", 1254Srgrimes "str", 1264Srgrimes "lldt", 1274Srgrimes "ltr", 1284Srgrimes "verr", 1294Srgrimes "verw", 1304Srgrimes "", 1314Srgrimes "" 1324Srgrimes}; 1334Srgrimes 13414887Swollmanstatic const char * const db_Grp7[] = { 1354Srgrimes "sgdt", 1364Srgrimes "sidt", 1374Srgrimes "lgdt", 1384Srgrimes "lidt", 1394Srgrimes "smsw", 1404Srgrimes "", 1414Srgrimes "lmsw", 1424Srgrimes "invlpg" 1434Srgrimes}; 1444Srgrimes 14514887Swollmanstatic const char * const db_Grp8[] = { 1464Srgrimes "", 1474Srgrimes "", 1484Srgrimes "", 1494Srgrimes "", 1504Srgrimes "bt", 1514Srgrimes "bts", 1524Srgrimes "btr", 1534Srgrimes "btc" 1544Srgrimes}; 1554Srgrimes 15621277Sbdestatic const char * const db_Grp9[] = { 15721277Sbde "", 15821277Sbde "cmpxchg8b", 15921277Sbde "", 16021277Sbde "", 16121277Sbde "", 16221277Sbde "", 16321277Sbde "", 16421277Sbde "" 16521277Sbde}; 16621277Sbde 167181606Sjhbstatic const char * const db_Grp15[] = { 168181606Sjhb "fxsave", 169181606Sjhb "fxrstor", 170181606Sjhb "ldmxcsr", 171181606Sjhb "stmxcsr", 172181606Sjhb "", 173181606Sjhb "", 174181606Sjhb "", 175181606Sjhb "clflush" 176181606Sjhb}; 177181606Sjhb 178181606Sjhbstatic const char * const db_Grp15b[] = { 179181606Sjhb "", 180181606Sjhb "", 181181606Sjhb "", 182181606Sjhb "", 183181606Sjhb "", 184181606Sjhb "lfence", 185181606Sjhb "mfence", 186181606Sjhb "sfence" 187181606Sjhb}; 188181606Sjhb 18914887Swollmanstatic const struct inst db_inst_0f0x[] = { 19017109Sbde/*00*/ { "", TRUE, NONE, op1(Ew), db_Grp6 }, 19117109Sbde/*01*/ { "", TRUE, NONE, op1(Ew), db_Grp7 }, 1924Srgrimes/*02*/ { "lar", TRUE, LONG, op2(E,R), 0 }, 1934Srgrimes/*03*/ { "lsl", TRUE, LONG, op2(E,R), 0 }, 1944Srgrimes/*04*/ { "", FALSE, NONE, 0, 0 }, 195181606Sjhb/*05*/ { "syscall",FALSE,NONE, 0, 0 }, 1964Srgrimes/*06*/ { "clts", FALSE, NONE, 0, 0 }, 197181606Sjhb/*07*/ { "sysret",FALSE, NONE, 0, 0 }, 1984Srgrimes 1994Srgrimes/*08*/ { "invd", FALSE, NONE, 0, 0 }, 2004Srgrimes/*09*/ { "wbinvd",FALSE, NONE, 0, 0 }, 2014Srgrimes/*0a*/ { "", FALSE, NONE, 0, 0 }, 2024Srgrimes/*0b*/ { "", FALSE, NONE, 0, 0 }, 2034Srgrimes/*0c*/ { "", FALSE, NONE, 0, 0 }, 2044Srgrimes/*0d*/ { "", FALSE, NONE, 0, 0 }, 2054Srgrimes/*0e*/ { "", FALSE, NONE, 0, 0 }, 2064Srgrimes/*0f*/ { "", FALSE, NONE, 0, 0 }, 2074Srgrimes}; 2084Srgrimes 20917109Sbdestatic const struct inst db_inst_0f2x[] = { 21021277Sbde/*20*/ { "mov", TRUE, LONG, op2(CR,El), 0 }, 21121277Sbde/*21*/ { "mov", TRUE, LONG, op2(DR,El), 0 }, 21221277Sbde/*22*/ { "mov", TRUE, LONG, op2(El,CR), 0 }, 21321277Sbde/*23*/ { "mov", TRUE, LONG, op2(El,DR), 0 }, 21421277Sbde/*24*/ { "mov", TRUE, LONG, op2(TR,El), 0 }, 2154Srgrimes/*25*/ { "", FALSE, NONE, 0, 0 }, 21621277Sbde/*26*/ { "mov", TRUE, LONG, op2(El,TR), 0 }, 2174Srgrimes/*27*/ { "", FALSE, NONE, 0, 0 }, 2184Srgrimes 2194Srgrimes/*28*/ { "", FALSE, NONE, 0, 0 }, 2204Srgrimes/*29*/ { "", FALSE, NONE, 0, 0 }, 2214Srgrimes/*2a*/ { "", FALSE, NONE, 0, 0 }, 2224Srgrimes/*2b*/ { "", FALSE, NONE, 0, 0 }, 2234Srgrimes/*2c*/ { "", FALSE, NONE, 0, 0 }, 2244Srgrimes/*2d*/ { "", FALSE, NONE, 0, 0 }, 2254Srgrimes/*2e*/ { "", FALSE, NONE, 0, 0 }, 2264Srgrimes/*2f*/ { "", FALSE, NONE, 0, 0 }, 2274Srgrimes}; 2284Srgrimes 22914887Swollmanstatic const struct inst db_inst_0f3x[] = { 23014887Swollman/*30*/ { "wrmsr", FALSE, NONE, 0, 0 }, 23114887Swollman/*31*/ { "rdtsc", FALSE, NONE, 0, 0 }, 23214887Swollman/*32*/ { "rdmsr", FALSE, NONE, 0, 0 }, 23314887Swollman/*33*/ { "rdpmc", FALSE, NONE, 0, 0 }, 234181606Sjhb/*34*/ { "sysenter",FALSE,NONE, 0, 0 }, 235181606Sjhb/*35*/ { "sysexit",FALSE,NONE, 0, 0 }, 23614887Swollman/*36*/ { "", FALSE, NONE, 0, 0 }, 237181606Sjhb/*37*/ { "getsec",FALSE, NONE, 0, 0 }, 23814887Swollman 23914887Swollman/*38*/ { "", FALSE, NONE, 0, 0 }, 24014887Swollman/*39*/ { "", FALSE, NONE, 0, 0 }, 24114887Swollman/*3a*/ { "", FALSE, NONE, 0, 0 }, 24214887Swollman/*3b*/ { "", FALSE, NONE, 0, 0 }, 24314887Swollman/*3c*/ { "", FALSE, NONE, 0, 0 }, 24414887Swollman/*3d*/ { "", FALSE, NONE, 0, 0 }, 24514887Swollman/*3e*/ { "", FALSE, NONE, 0, 0 }, 24614887Swollman/*3f*/ { "", FALSE, NONE, 0, 0 }, 24714887Swollman}; 24814887Swollman 249144354Speterstatic const struct inst db_inst_0f4x[] = { 250144354Speter/*40*/ { "cmovo", TRUE, NONE, op2(E, R), 0 }, 251144354Speter/*41*/ { "cmovno", TRUE, NONE, op2(E, R), 0 }, 252144354Speter/*42*/ { "cmovb", TRUE, NONE, op2(E, R), 0 }, 253144354Speter/*43*/ { "cmovnb", TRUE, NONE, op2(E, R), 0 }, 254144354Speter/*44*/ { "cmovz", TRUE, NONE, op2(E, R), 0 }, 255144354Speter/*45*/ { "cmovnz", TRUE, NONE, op2(E, R), 0 }, 256144354Speter/*46*/ { "cmovbe", TRUE, NONE, op2(E, R), 0 }, 257144354Speter/*47*/ { "cmovnbe",TRUE, NONE, op2(E, R), 0 }, 258144354Speter 259144354Speter/*48*/ { "cmovs", TRUE, NONE, op2(E, R), 0 }, 260144354Speter/*49*/ { "cmovns", TRUE, NONE, op2(E, R), 0 }, 261144354Speter/*4a*/ { "cmovp", TRUE, NONE, op2(E, R), 0 }, 262144354Speter/*4b*/ { "cmovnp", TRUE, NONE, op2(E, R), 0 }, 263144354Speter/*4c*/ { "cmovl", TRUE, NONE, op2(E, R), 0 }, 264144354Speter/*4d*/ { "cmovnl", TRUE, NONE, op2(E, R), 0 }, 265144354Speter/*4e*/ { "cmovle", TRUE, NONE, op2(E, R), 0 }, 266144354Speter/*4f*/ { "cmovnle",TRUE, NONE, op2(E, R), 0 }, 267144354Speter}; 268144354Speter 26917109Sbdestatic const struct inst db_inst_0f8x[] = { 2704Srgrimes/*80*/ { "jo", FALSE, NONE, op1(Dl), 0 }, 2714Srgrimes/*81*/ { "jno", FALSE, NONE, op1(Dl), 0 }, 2724Srgrimes/*82*/ { "jb", FALSE, NONE, op1(Dl), 0 }, 2734Srgrimes/*83*/ { "jnb", FALSE, NONE, op1(Dl), 0 }, 2744Srgrimes/*84*/ { "jz", FALSE, NONE, op1(Dl), 0 }, 2754Srgrimes/*85*/ { "jnz", FALSE, NONE, op1(Dl), 0 }, 2764Srgrimes/*86*/ { "jbe", FALSE, NONE, op1(Dl), 0 }, 2774Srgrimes/*87*/ { "jnbe", FALSE, NONE, op1(Dl), 0 }, 2784Srgrimes 2794Srgrimes/*88*/ { "js", FALSE, NONE, op1(Dl), 0 }, 2804Srgrimes/*89*/ { "jns", FALSE, NONE, op1(Dl), 0 }, 2814Srgrimes/*8a*/ { "jp", FALSE, NONE, op1(Dl), 0 }, 2824Srgrimes/*8b*/ { "jnp", FALSE, NONE, op1(Dl), 0 }, 2834Srgrimes/*8c*/ { "jl", FALSE, NONE, op1(Dl), 0 }, 2844Srgrimes/*8d*/ { "jnl", FALSE, NONE, op1(Dl), 0 }, 2854Srgrimes/*8e*/ { "jle", FALSE, NONE, op1(Dl), 0 }, 2864Srgrimes/*8f*/ { "jnle", FALSE, NONE, op1(Dl), 0 }, 2874Srgrimes}; 2884Srgrimes 28917109Sbdestatic const struct inst db_inst_0f9x[] = { 2904Srgrimes/*90*/ { "seto", TRUE, NONE, op1(Eb), 0 }, 2914Srgrimes/*91*/ { "setno", TRUE, NONE, op1(Eb), 0 }, 2924Srgrimes/*92*/ { "setb", TRUE, NONE, op1(Eb), 0 }, 2934Srgrimes/*93*/ { "setnb", TRUE, NONE, op1(Eb), 0 }, 2944Srgrimes/*94*/ { "setz", TRUE, NONE, op1(Eb), 0 }, 2954Srgrimes/*95*/ { "setnz", TRUE, NONE, op1(Eb), 0 }, 2964Srgrimes/*96*/ { "setbe", TRUE, NONE, op1(Eb), 0 }, 2974Srgrimes/*97*/ { "setnbe",TRUE, NONE, op1(Eb), 0 }, 2984Srgrimes 2994Srgrimes/*98*/ { "sets", TRUE, NONE, op1(Eb), 0 }, 3004Srgrimes/*99*/ { "setns", TRUE, NONE, op1(Eb), 0 }, 3014Srgrimes/*9a*/ { "setp", TRUE, NONE, op1(Eb), 0 }, 3024Srgrimes/*9b*/ { "setnp", TRUE, NONE, op1(Eb), 0 }, 3034Srgrimes/*9c*/ { "setl", TRUE, NONE, op1(Eb), 0 }, 3044Srgrimes/*9d*/ { "setnl", TRUE, NONE, op1(Eb), 0 }, 3054Srgrimes/*9e*/ { "setle", TRUE, NONE, op1(Eb), 0 }, 3064Srgrimes/*9f*/ { "setnle",TRUE, NONE, op1(Eb), 0 }, 3074Srgrimes}; 3084Srgrimes 30917109Sbdestatic const struct inst db_inst_0fax[] = { 3104Srgrimes/*a0*/ { "push", FALSE, NONE, op1(Si), 0 }, 3114Srgrimes/*a1*/ { "pop", FALSE, NONE, op1(Si), 0 }, 31221277Sbde/*a2*/ { "cpuid", FALSE, NONE, 0, 0 }, 31321277Sbde/*a3*/ { "bt", TRUE, LONG, op2(R,E), 0 }, 31417109Sbde/*a4*/ { "shld", TRUE, LONG, op3(Ib,R,E), 0 }, 31517109Sbde/*a5*/ { "shld", TRUE, LONG, op3(CL,R,E), 0 }, 3164Srgrimes/*a6*/ { "", FALSE, NONE, 0, 0 }, 3174Srgrimes/*a7*/ { "", FALSE, NONE, 0, 0 }, 3184Srgrimes 3194Srgrimes/*a8*/ { "push", FALSE, NONE, op1(Si), 0 }, 3204Srgrimes/*a9*/ { "pop", FALSE, NONE, op1(Si), 0 }, 32121277Sbde/*aa*/ { "rsm", FALSE, NONE, 0, 0 }, 32221277Sbde/*ab*/ { "bts", TRUE, LONG, op2(R,E), 0 }, 32317109Sbde/*ac*/ { "shrd", TRUE, LONG, op3(Ib,R,E), 0 }, 32417109Sbde/*ad*/ { "shrd", TRUE, LONG, op3(CL,R,E), 0 }, 325181606Sjhb/*ae*/ { "", TRUE, LONG, op1(E), db_Grp15 }, 326181606Sjhb/*af*/ { "imul", TRUE, LONG, op2(E,R), 0 }, 3274Srgrimes}; 3284Srgrimes 32917109Sbdestatic const struct inst db_inst_0fbx[] = { 33021277Sbde/*b0*/ { "cmpxchg",TRUE, BYTE, op2(R, E), 0 }, 33121277Sbde/*b0*/ { "cmpxchg",TRUE, LONG, op2(R, E), 0 }, 3324Srgrimes/*b2*/ { "lss", TRUE, LONG, op2(E, R), 0 }, 33321277Sbde/*b3*/ { "btr", TRUE, LONG, op2(R, E), 0 }, 3344Srgrimes/*b4*/ { "lfs", TRUE, LONG, op2(E, R), 0 }, 3354Srgrimes/*b5*/ { "lgs", TRUE, LONG, op2(E, R), 0 }, 33621277Sbde/*b6*/ { "movzb", TRUE, LONG, op2(Eb, R), 0 }, 33721277Sbde/*b7*/ { "movzw", TRUE, LONG, op2(Ew, R), 0 }, 3384Srgrimes 3394Srgrimes/*b8*/ { "", FALSE, NONE, 0, 0 }, 3404Srgrimes/*b9*/ { "", FALSE, NONE, 0, 0 }, 34117109Sbde/*ba*/ { "", TRUE, LONG, op2(Ib, E), db_Grp8 }, 3424Srgrimes/*bb*/ { "btc", TRUE, LONG, op2(R, E), 0 }, 3434Srgrimes/*bc*/ { "bsf", TRUE, LONG, op2(E, R), 0 }, 3444Srgrimes/*bd*/ { "bsr", TRUE, LONG, op2(E, R), 0 }, 34521277Sbde/*be*/ { "movsb", TRUE, LONG, op2(Eb, R), 0 }, 34621277Sbde/*bf*/ { "movsw", TRUE, LONG, op2(Ew, R), 0 }, 3474Srgrimes}; 3484Srgrimes 34917109Sbdestatic const struct inst db_inst_0fcx[] = { 3504Srgrimes/*c0*/ { "xadd", TRUE, BYTE, op2(R, E), 0 }, 3514Srgrimes/*c1*/ { "xadd", TRUE, LONG, op2(R, E), 0 }, 3524Srgrimes/*c2*/ { "", FALSE, NONE, 0, 0 }, 3534Srgrimes/*c3*/ { "", FALSE, NONE, 0, 0 }, 3544Srgrimes/*c4*/ { "", FALSE, NONE, 0, 0 }, 3554Srgrimes/*c5*/ { "", FALSE, NONE, 0, 0 }, 3564Srgrimes/*c6*/ { "", FALSE, NONE, 0, 0 }, 35721277Sbde/*c7*/ { "", TRUE, NONE, op1(E), db_Grp9 }, 35821277Sbde/*c8*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 35921277Sbde/*c9*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 36021277Sbde/*ca*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 36121277Sbde/*cb*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 36221277Sbde/*cc*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 36321277Sbde/*cd*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 36421277Sbde/*ce*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 36521277Sbde/*cf*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 3664Srgrimes}; 3674Srgrimes 36814887Swollmanstatic const struct inst * const db_inst_0f[] = { 3694Srgrimes db_inst_0f0x, 3704Srgrimes 0, 3714Srgrimes db_inst_0f2x, 37214887Swollman db_inst_0f3x, 373144354Speter db_inst_0f4x, 3744Srgrimes 0, 3754Srgrimes 0, 3764Srgrimes 0, 3774Srgrimes db_inst_0f8x, 3784Srgrimes db_inst_0f9x, 3794Srgrimes db_inst_0fax, 3804Srgrimes db_inst_0fbx, 3814Srgrimes db_inst_0fcx, 3824Srgrimes 0, 38321277Sbde 0, 3844Srgrimes 0 3854Srgrimes}; 3864Srgrimes 38714887Swollmanstatic const char * const db_Esc92[] = { 3884Srgrimes "fnop", "", "", "", "", "", "", "" 3894Srgrimes}; 39014887Swollmanstatic const char * const db_Esc94[] = { 3914Srgrimes "fchs", "fabs", "", "", "ftst", "fxam", "", "" 3924Srgrimes}; 39317109Sbdestatic const char * const db_Esc95[] = { 3944Srgrimes "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz","" 3954Srgrimes}; 39617109Sbdestatic const char * const db_Esc96[] = { 3974Srgrimes "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp", 3984Srgrimes "fincstp" 3994Srgrimes}; 40014887Swollmanstatic const char * const db_Esc97[] = { 4014Srgrimes "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos" 4024Srgrimes}; 4034Srgrimes 40421277Sbdestatic const char * const db_Esca5[] = { 4054Srgrimes "", "fucompp","", "", "", "", "", "" 4064Srgrimes}; 4074Srgrimes 40817109Sbdestatic const char * const db_Escb4[] = { 40921277Sbde "fneni","fndisi", "fnclex","fninit","fsetpm", "", "", "" 4104Srgrimes}; 4114Srgrimes 41214887Swollmanstatic const char * const db_Esce3[] = { 4134Srgrimes "", "fcompp","", "", "", "", "", "" 4144Srgrimes}; 4154Srgrimes 41617109Sbdestatic const char * const db_Escf4[] = { 4174Srgrimes "fnstsw","", "", "", "", "", "", "" 4184Srgrimes}; 4194Srgrimes 42014887Swollmanstatic const struct finst db_Esc8[] = { 4214Srgrimes/*0*/ { "fadd", SNGL, op2(STI,ST), 0 }, 4224Srgrimes/*1*/ { "fmul", SNGL, op2(STI,ST), 0 }, 4234Srgrimes/*2*/ { "fcom", SNGL, op2(STI,ST), 0 }, 4244Srgrimes/*3*/ { "fcomp", SNGL, op2(STI,ST), 0 }, 4254Srgrimes/*4*/ { "fsub", SNGL, op2(STI,ST), 0 }, 4264Srgrimes/*5*/ { "fsubr", SNGL, op2(STI,ST), 0 }, 4274Srgrimes/*6*/ { "fdiv", SNGL, op2(STI,ST), 0 }, 4284Srgrimes/*7*/ { "fdivr", SNGL, op2(STI,ST), 0 }, 4294Srgrimes}; 4304Srgrimes 43114887Swollmanstatic const struct finst db_Esc9[] = { 4324Srgrimes/*0*/ { "fld", SNGL, op1(STI), 0 }, 4334Srgrimes/*1*/ { "", NONE, op1(STI), "fxch" }, 43417109Sbde/*2*/ { "fst", SNGL, op1(X), db_Esc92 }, 43521277Sbde/*3*/ { "fstp", SNGL, 0, 0 }, 43617109Sbde/*4*/ { "fldenv", NONE, op1(X), db_Esc94 }, 43717109Sbde/*5*/ { "fldcw", NONE, op1(X), db_Esc95 }, 43817109Sbde/*6*/ { "fnstenv",NONE, op1(X), db_Esc96 }, 43917109Sbde/*7*/ { "fnstcw", NONE, op1(X), db_Esc97 }, 4404Srgrimes}; 4414Srgrimes 44214887Swollmanstatic const struct finst db_Esca[] = { 44321277Sbde/*0*/ { "fiadd", LONG, 0, 0 }, 44421277Sbde/*1*/ { "fimul", LONG, 0, 0 }, 44521277Sbde/*2*/ { "ficom", LONG, 0, 0 }, 44621277Sbde/*3*/ { "ficomp", LONG, 0, 0 }, 44721277Sbde/*4*/ { "fisub", LONG, 0, 0 }, 44821277Sbde/*5*/ { "fisubr", LONG, op1(X), db_Esca5 }, 44921277Sbde/*6*/ { "fidiv", LONG, 0, 0 }, 45021277Sbde/*7*/ { "fidivr", LONG, 0, 0 } 4514Srgrimes}; 4524Srgrimes 45314887Swollmanstatic const struct finst db_Escb[] = { 45421277Sbde/*0*/ { "fild", LONG, 0, 0 }, 4554Srgrimes/*1*/ { "", NONE, 0, 0 }, 45621277Sbde/*2*/ { "fist", LONG, 0, 0 }, 45721277Sbde/*3*/ { "fistp", LONG, 0, 0 }, 45817109Sbde/*4*/ { "", WORD, op1(X), db_Escb4 }, 4594Srgrimes/*5*/ { "fld", EXTR, 0, 0 }, 4604Srgrimes/*6*/ { "", WORD, 0, 0 }, 4614Srgrimes/*7*/ { "fstp", EXTR, 0, 0 }, 4624Srgrimes}; 4634Srgrimes 46414887Swollmanstatic const struct finst db_Escc[] = { 4654Srgrimes/*0*/ { "fadd", DBLR, op2(ST,STI), 0 }, 4664Srgrimes/*1*/ { "fmul", DBLR, op2(ST,STI), 0 }, 46721277Sbde/*2*/ { "fcom", DBLR, 0, 0 }, 46821277Sbde/*3*/ { "fcomp", DBLR, 0, 0 }, 4694Srgrimes/*4*/ { "fsub", DBLR, op2(ST,STI), "fsubr" }, 4704Srgrimes/*5*/ { "fsubr", DBLR, op2(ST,STI), "fsub" }, 4714Srgrimes/*6*/ { "fdiv", DBLR, op2(ST,STI), "fdivr" }, 4724Srgrimes/*7*/ { "fdivr", DBLR, op2(ST,STI), "fdiv" }, 4734Srgrimes}; 4744Srgrimes 47514887Swollmanstatic const struct finst db_Escd[] = { 4764Srgrimes/*0*/ { "fld", DBLR, op1(STI), "ffree" }, 4774Srgrimes/*1*/ { "", NONE, 0, 0 }, 4784Srgrimes/*2*/ { "fst", DBLR, op1(STI), 0 }, 4794Srgrimes/*3*/ { "fstp", DBLR, op1(STI), 0 }, 4804Srgrimes/*4*/ { "frstor", NONE, op1(STI), "fucom" }, 4814Srgrimes/*5*/ { "", NONE, op1(STI), "fucomp" }, 4824Srgrimes/*6*/ { "fnsave", NONE, 0, 0 }, 4834Srgrimes/*7*/ { "fnstsw", NONE, 0, 0 }, 4844Srgrimes}; 4854Srgrimes 48614887Swollmanstatic const struct finst db_Esce[] = { 48721277Sbde/*0*/ { "fiadd", WORD, op2(ST,STI), "faddp" }, 48821277Sbde/*1*/ { "fimul", WORD, op2(ST,STI), "fmulp" }, 48921277Sbde/*2*/ { "ficom", WORD, 0, 0 }, 49021277Sbde/*3*/ { "ficomp", WORD, op1(X), db_Esce3 }, 49121277Sbde/*4*/ { "fisub", WORD, op2(ST,STI), "fsubrp" }, 49221277Sbde/*5*/ { "fisubr", WORD, op2(ST,STI), "fsubp" }, 49321277Sbde/*6*/ { "fidiv", WORD, op2(ST,STI), "fdivrp" }, 49421277Sbde/*7*/ { "fidivr", WORD, op2(ST,STI), "fdivp" }, 4954Srgrimes}; 4964Srgrimes 49714887Swollmanstatic const struct finst db_Escf[] = { 49821277Sbde/*0*/ { "fild", WORD, 0, 0 }, 49921277Sbde/*1*/ { "", NONE, 0, 0 }, 50021277Sbde/*2*/ { "fist", WORD, 0, 0 }, 50121277Sbde/*3*/ { "fistp", WORD, 0, 0 }, 50217109Sbde/*4*/ { "fbld", NONE, op1(XA), db_Escf4 }, 50321277Sbde/*5*/ { "fild", QUAD, 0, 0 }, 5044Srgrimes/*6*/ { "fbstp", NONE, 0, 0 }, 50521277Sbde/*7*/ { "fistp", QUAD, 0, 0 }, 5064Srgrimes}; 5074Srgrimes 50817109Sbdestatic const struct finst * const db_Esc_inst[] = { 5094Srgrimes db_Esc8, db_Esc9, db_Esca, db_Escb, 5104Srgrimes db_Escc, db_Escd, db_Esce, db_Escf 5114Srgrimes}; 5124Srgrimes 51314887Swollmanstatic const char * const db_Grp1[] = { 5144Srgrimes "add", 5154Srgrimes "or", 5164Srgrimes "adc", 5174Srgrimes "sbb", 5184Srgrimes "and", 5194Srgrimes "sub", 5204Srgrimes "xor", 5214Srgrimes "cmp" 5224Srgrimes}; 5234Srgrimes 52414887Swollmanstatic const char * const db_Grp2[] = { 5254Srgrimes "rol", 5264Srgrimes "ror", 5274Srgrimes "rcl", 5284Srgrimes "rcr", 5294Srgrimes "shl", 5304Srgrimes "shr", 5314Srgrimes "shl", 5324Srgrimes "sar" 5334Srgrimes}; 5344Srgrimes 53514887Swollmanstatic const struct inst db_Grp3[] = { 5364Srgrimes { "test", TRUE, NONE, op2(I,E), 0 }, 5374Srgrimes { "test", TRUE, NONE, op2(I,E), 0 }, 5384Srgrimes { "not", TRUE, NONE, op1(E), 0 }, 5394Srgrimes { "neg", TRUE, NONE, op1(E), 0 }, 5404Srgrimes { "mul", TRUE, NONE, op2(E,A), 0 }, 5414Srgrimes { "imul", TRUE, NONE, op2(E,A), 0 }, 5424Srgrimes { "div", TRUE, NONE, op2(E,A), 0 }, 5434Srgrimes { "idiv", TRUE, NONE, op2(E,A), 0 }, 5444Srgrimes}; 5454Srgrimes 54617109Sbdestatic const struct inst db_Grp4[] = { 5474Srgrimes { "inc", TRUE, BYTE, op1(E), 0 }, 5484Srgrimes { "dec", TRUE, BYTE, op1(E), 0 }, 5494Srgrimes { "", TRUE, NONE, 0, 0 }, 5504Srgrimes { "", TRUE, NONE, 0, 0 }, 5514Srgrimes { "", TRUE, NONE, 0, 0 }, 5524Srgrimes { "", TRUE, NONE, 0, 0 }, 5534Srgrimes { "", TRUE, NONE, 0, 0 }, 5544Srgrimes { "", TRUE, NONE, 0, 0 } 5554Srgrimes}; 5564Srgrimes 55717109Sbdestatic const struct inst db_Grp5[] = { 5584Srgrimes { "inc", TRUE, LONG, op1(E), 0 }, 5594Srgrimes { "dec", TRUE, LONG, op1(E), 0 }, 56021277Sbde { "call", TRUE, LONG, op1(Eind),0 }, 56121277Sbde { "lcall", TRUE, LONG, op1(Eind),0 }, 56221277Sbde { "jmp", TRUE, LONG, op1(Eind),0 }, 56321277Sbde { "ljmp", TRUE, LONG, op1(Eind),0 }, 5644Srgrimes { "push", TRUE, LONG, op1(E), 0 }, 5654Srgrimes { "", TRUE, NONE, 0, 0 } 5664Srgrimes}; 5674Srgrimes 56814887Swollmanstatic const struct inst db_inst_table[256] = { 5694Srgrimes/*00*/ { "add", TRUE, BYTE, op2(R, E), 0 }, 5704Srgrimes/*01*/ { "add", TRUE, LONG, op2(R, E), 0 }, 5714Srgrimes/*02*/ { "add", TRUE, BYTE, op2(E, R), 0 }, 5724Srgrimes/*03*/ { "add", TRUE, LONG, op2(E, R), 0 }, 57321277Sbde/*04*/ { "add", FALSE, BYTE, op2(I, A), 0 }, 5744Srgrimes/*05*/ { "add", FALSE, LONG, op2(Is, A), 0 }, 5754Srgrimes/*06*/ { "push", FALSE, NONE, op1(Si), 0 }, 5764Srgrimes/*07*/ { "pop", FALSE, NONE, op1(Si), 0 }, 5774Srgrimes 5784Srgrimes/*08*/ { "or", TRUE, BYTE, op2(R, E), 0 }, 5794Srgrimes/*09*/ { "or", TRUE, LONG, op2(R, E), 0 }, 5804Srgrimes/*0a*/ { "or", TRUE, BYTE, op2(E, R), 0 }, 5814Srgrimes/*0b*/ { "or", TRUE, LONG, op2(E, R), 0 }, 5824Srgrimes/*0c*/ { "or", FALSE, BYTE, op2(I, A), 0 }, 5834Srgrimes/*0d*/ { "or", FALSE, LONG, op2(I, A), 0 }, 5844Srgrimes/*0e*/ { "push", FALSE, NONE, op1(Si), 0 }, 5854Srgrimes/*0f*/ { "", FALSE, NONE, 0, 0 }, 5864Srgrimes 5874Srgrimes/*10*/ { "adc", TRUE, BYTE, op2(R, E), 0 }, 5884Srgrimes/*11*/ { "adc", TRUE, LONG, op2(R, E), 0 }, 5894Srgrimes/*12*/ { "adc", TRUE, BYTE, op2(E, R), 0 }, 5904Srgrimes/*13*/ { "adc", TRUE, LONG, op2(E, R), 0 }, 59121277Sbde/*14*/ { "adc", FALSE, BYTE, op2(I, A), 0 }, 5924Srgrimes/*15*/ { "adc", FALSE, LONG, op2(Is, A), 0 }, 5934Srgrimes/*16*/ { "push", FALSE, NONE, op1(Si), 0 }, 5944Srgrimes/*17*/ { "pop", FALSE, NONE, op1(Si), 0 }, 5954Srgrimes 5964Srgrimes/*18*/ { "sbb", TRUE, BYTE, op2(R, E), 0 }, 5974Srgrimes/*19*/ { "sbb", TRUE, LONG, op2(R, E), 0 }, 5984Srgrimes/*1a*/ { "sbb", TRUE, BYTE, op2(E, R), 0 }, 5994Srgrimes/*1b*/ { "sbb", TRUE, LONG, op2(E, R), 0 }, 60021277Sbde/*1c*/ { "sbb", FALSE, BYTE, op2(I, A), 0 }, 6014Srgrimes/*1d*/ { "sbb", FALSE, LONG, op2(Is, A), 0 }, 6024Srgrimes/*1e*/ { "push", FALSE, NONE, op1(Si), 0 }, 6034Srgrimes/*1f*/ { "pop", FALSE, NONE, op1(Si), 0 }, 6044Srgrimes 6054Srgrimes/*20*/ { "and", TRUE, BYTE, op2(R, E), 0 }, 6064Srgrimes/*21*/ { "and", TRUE, LONG, op2(R, E), 0 }, 6074Srgrimes/*22*/ { "and", TRUE, BYTE, op2(E, R), 0 }, 6084Srgrimes/*23*/ { "and", TRUE, LONG, op2(E, R), 0 }, 6094Srgrimes/*24*/ { "and", FALSE, BYTE, op2(I, A), 0 }, 6104Srgrimes/*25*/ { "and", FALSE, LONG, op2(I, A), 0 }, 6114Srgrimes/*26*/ { "", FALSE, NONE, 0, 0 }, 61221277Sbde/*27*/ { "daa", FALSE, NONE, 0, 0 }, 6134Srgrimes 6144Srgrimes/*28*/ { "sub", TRUE, BYTE, op2(R, E), 0 }, 6154Srgrimes/*29*/ { "sub", TRUE, LONG, op2(R, E), 0 }, 6164Srgrimes/*2a*/ { "sub", TRUE, BYTE, op2(E, R), 0 }, 6174Srgrimes/*2b*/ { "sub", TRUE, LONG, op2(E, R), 0 }, 61821277Sbde/*2c*/ { "sub", FALSE, BYTE, op2(I, A), 0 }, 6194Srgrimes/*2d*/ { "sub", FALSE, LONG, op2(Is, A), 0 }, 6204Srgrimes/*2e*/ { "", FALSE, NONE, 0, 0 }, 6214Srgrimes/*2f*/ { "das", FALSE, NONE, 0, 0 }, 6224Srgrimes 6234Srgrimes/*30*/ { "xor", TRUE, BYTE, op2(R, E), 0 }, 6244Srgrimes/*31*/ { "xor", TRUE, LONG, op2(R, E), 0 }, 6254Srgrimes/*32*/ { "xor", TRUE, BYTE, op2(E, R), 0 }, 6264Srgrimes/*33*/ { "xor", TRUE, LONG, op2(E, R), 0 }, 6274Srgrimes/*34*/ { "xor", FALSE, BYTE, op2(I, A), 0 }, 6284Srgrimes/*35*/ { "xor", FALSE, LONG, op2(I, A), 0 }, 6294Srgrimes/*36*/ { "", FALSE, NONE, 0, 0 }, 63021277Sbde/*37*/ { "aaa", FALSE, NONE, 0, 0 }, 6314Srgrimes 6324Srgrimes/*38*/ { "cmp", TRUE, BYTE, op2(R, E), 0 }, 6334Srgrimes/*39*/ { "cmp", TRUE, LONG, op2(R, E), 0 }, 6344Srgrimes/*3a*/ { "cmp", TRUE, BYTE, op2(E, R), 0 }, 6354Srgrimes/*3b*/ { "cmp", TRUE, LONG, op2(E, R), 0 }, 63621277Sbde/*3c*/ { "cmp", FALSE, BYTE, op2(I, A), 0 }, 6374Srgrimes/*3d*/ { "cmp", FALSE, LONG, op2(Is, A), 0 }, 6384Srgrimes/*3e*/ { "", FALSE, NONE, 0, 0 }, 6394Srgrimes/*3f*/ { "aas", FALSE, NONE, 0, 0 }, 6404Srgrimes 641144353Speter/*40*/ { "rex", FALSE, NONE, 0, 0 }, 642144353Speter/*41*/ { "rex.b", FALSE, NONE, 0, 0 }, 643144353Speter/*42*/ { "rex.x", FALSE, NONE, 0, 0 }, 644144353Speter/*43*/ { "rex.xb", FALSE, NONE, 0, 0 }, 645144353Speter/*44*/ { "rex.r", FALSE, NONE, 0, 0 }, 646144353Speter/*45*/ { "rex.rb", FALSE, NONE, 0, 0 }, 647144353Speter/*46*/ { "rex.rx", FALSE, NONE, 0, 0 }, 648144353Speter/*47*/ { "rex.rxb", FALSE, NONE, 0, 0 }, 6494Srgrimes 650144353Speter/*48*/ { "rex.w", FALSE, NONE, 0, 0 }, 651144353Speter/*49*/ { "rex.wb", FALSE, NONE, 0, 0 }, 652144353Speter/*4a*/ { "rex.wx", FALSE, NONE, 0, 0 }, 653144353Speter/*4b*/ { "rex.wxb", FALSE, NONE, 0, 0 }, 654144353Speter/*4c*/ { "rex.wr", FALSE, NONE, 0, 0 }, 655144353Speter/*4d*/ { "rex.wrb", FALSE, NONE, 0, 0 }, 656144353Speter/*4e*/ { "rex.wrx", FALSE, NONE, 0, 0 }, 657144353Speter/*4f*/ { "rex.wrxb", FALSE, NONE, 0, 0 }, 6584Srgrimes 6594Srgrimes/*50*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6604Srgrimes/*51*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6614Srgrimes/*52*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6624Srgrimes/*53*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6634Srgrimes/*54*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6644Srgrimes/*55*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6654Srgrimes/*56*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6664Srgrimes/*57*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6674Srgrimes 6684Srgrimes/*58*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6694Srgrimes/*59*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6704Srgrimes/*5a*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6714Srgrimes/*5b*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6724Srgrimes/*5c*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6734Srgrimes/*5d*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6744Srgrimes/*5e*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6754Srgrimes/*5f*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6764Srgrimes 6774Srgrimes/*60*/ { "pusha", FALSE, LONG, 0, 0 }, 6784Srgrimes/*61*/ { "popa", FALSE, LONG, 0, 0 }, 6794Srgrimes/*62*/ { "bound", TRUE, LONG, op2(E, R), 0 }, 680144354Speter/*63*/ { "movslq", TRUE, NONE, op2(EL,R), 0 }, 6814Srgrimes 6824Srgrimes/*64*/ { "", FALSE, NONE, 0, 0 }, 6834Srgrimes/*65*/ { "", FALSE, NONE, 0, 0 }, 6844Srgrimes/*66*/ { "", FALSE, NONE, 0, 0 }, 6854Srgrimes/*67*/ { "", FALSE, NONE, 0, 0 }, 6864Srgrimes 6874Srgrimes/*68*/ { "push", FALSE, LONG, op1(I), 0 }, 6884Srgrimes/*69*/ { "imul", TRUE, LONG, op3(I,E,R), 0 }, 68921277Sbde/*6a*/ { "push", FALSE, LONG, op1(Ibs), 0 }, 6904Srgrimes/*6b*/ { "imul", TRUE, LONG, op3(Ibs,E,R),0 }, 6914Srgrimes/*6c*/ { "ins", FALSE, BYTE, op2(DX, DI), 0 }, 6924Srgrimes/*6d*/ { "ins", FALSE, LONG, op2(DX, DI), 0 }, 6934Srgrimes/*6e*/ { "outs", FALSE, BYTE, op2(SI, DX), 0 }, 6944Srgrimes/*6f*/ { "outs", FALSE, LONG, op2(SI, DX), 0 }, 6954Srgrimes 6964Srgrimes/*70*/ { "jo", FALSE, NONE, op1(Db), 0 }, 6974Srgrimes/*71*/ { "jno", FALSE, NONE, op1(Db), 0 }, 6984Srgrimes/*72*/ { "jb", FALSE, NONE, op1(Db), 0 }, 6994Srgrimes/*73*/ { "jnb", FALSE, NONE, op1(Db), 0 }, 7004Srgrimes/*74*/ { "jz", FALSE, NONE, op1(Db), 0 }, 7014Srgrimes/*75*/ { "jnz", FALSE, NONE, op1(Db), 0 }, 7024Srgrimes/*76*/ { "jbe", FALSE, NONE, op1(Db), 0 }, 7034Srgrimes/*77*/ { "jnbe", FALSE, NONE, op1(Db), 0 }, 7044Srgrimes 7054Srgrimes/*78*/ { "js", FALSE, NONE, op1(Db), 0 }, 7064Srgrimes/*79*/ { "jns", FALSE, NONE, op1(Db), 0 }, 7074Srgrimes/*7a*/ { "jp", FALSE, NONE, op1(Db), 0 }, 7084Srgrimes/*7b*/ { "jnp", FALSE, NONE, op1(Db), 0 }, 7094Srgrimes/*7c*/ { "jl", FALSE, NONE, op1(Db), 0 }, 7104Srgrimes/*7d*/ { "jnl", FALSE, NONE, op1(Db), 0 }, 7114Srgrimes/*7e*/ { "jle", FALSE, NONE, op1(Db), 0 }, 7124Srgrimes/*7f*/ { "jnle", FALSE, NONE, op1(Db), 0 }, 7134Srgrimes 71417109Sbde/*80*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 }, 71517109Sbde/*81*/ { "", TRUE, LONG, op2(I, E), db_Grp1 }, 71621277Sbde/*82*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 }, 71717109Sbde/*83*/ { "", TRUE, LONG, op2(Ibs,E), db_Grp1 }, 7184Srgrimes/*84*/ { "test", TRUE, BYTE, op2(R, E), 0 }, 7194Srgrimes/*85*/ { "test", TRUE, LONG, op2(R, E), 0 }, 7204Srgrimes/*86*/ { "xchg", TRUE, BYTE, op2(R, E), 0 }, 7214Srgrimes/*87*/ { "xchg", TRUE, LONG, op2(R, E), 0 }, 7224Srgrimes 7234Srgrimes/*88*/ { "mov", TRUE, BYTE, op2(R, E), 0 }, 7244Srgrimes/*89*/ { "mov", TRUE, LONG, op2(R, E), 0 }, 7254Srgrimes/*8a*/ { "mov", TRUE, BYTE, op2(E, R), 0 }, 7264Srgrimes/*8b*/ { "mov", TRUE, LONG, op2(E, R), 0 }, 7274Srgrimes/*8c*/ { "mov", TRUE, NONE, op2(S, Ew), 0 }, 7284Srgrimes/*8d*/ { "lea", TRUE, LONG, op2(E, R), 0 }, 7294Srgrimes/*8e*/ { "mov", TRUE, NONE, op2(Ew, S), 0 }, 7304Srgrimes/*8f*/ { "pop", TRUE, LONG, op1(E), 0 }, 7314Srgrimes 7324Srgrimes/*90*/ { "nop", FALSE, NONE, 0, 0 }, 7334Srgrimes/*91*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7344Srgrimes/*92*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7354Srgrimes/*93*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7364Srgrimes/*94*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7374Srgrimes/*95*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7384Srgrimes/*96*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7394Srgrimes/*97*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7404Srgrimes 7414Srgrimes/*98*/ { "cbw", FALSE, SDEP, 0, "cwde" }, /* cbw/cwde */ 7424Srgrimes/*99*/ { "cwd", FALSE, SDEP, 0, "cdq" }, /* cwd/cdq */ 7434Srgrimes/*9a*/ { "lcall", FALSE, NONE, op1(OS), 0 }, 7444Srgrimes/*9b*/ { "wait", FALSE, NONE, 0, 0 }, 7454Srgrimes/*9c*/ { "pushf", FALSE, LONG, 0, 0 }, 7464Srgrimes/*9d*/ { "popf", FALSE, LONG, 0, 0 }, 7474Srgrimes/*9e*/ { "sahf", FALSE, NONE, 0, 0 }, 7484Srgrimes/*9f*/ { "lahf", FALSE, NONE, 0, 0 }, 7494Srgrimes 7504Srgrimes/*a0*/ { "mov", FALSE, BYTE, op2(O, A), 0 }, 7514Srgrimes/*a1*/ { "mov", FALSE, LONG, op2(O, A), 0 }, 7524Srgrimes/*a2*/ { "mov", FALSE, BYTE, op2(A, O), 0 }, 7534Srgrimes/*a3*/ { "mov", FALSE, LONG, op2(A, O), 0 }, 7544Srgrimes/*a4*/ { "movs", FALSE, BYTE, op2(SI,DI), 0 }, 7554Srgrimes/*a5*/ { "movs", FALSE, LONG, op2(SI,DI), 0 }, 7564Srgrimes/*a6*/ { "cmps", FALSE, BYTE, op2(SI,DI), 0 }, 7574Srgrimes/*a7*/ { "cmps", FALSE, LONG, op2(SI,DI), 0 }, 7584Srgrimes 7594Srgrimes/*a8*/ { "test", FALSE, BYTE, op2(I, A), 0 }, 7604Srgrimes/*a9*/ { "test", FALSE, LONG, op2(I, A), 0 }, 7614Srgrimes/*aa*/ { "stos", FALSE, BYTE, op1(DI), 0 }, 7624Srgrimes/*ab*/ { "stos", FALSE, LONG, op1(DI), 0 }, 763118Srgrimes/*ac*/ { "lods", FALSE, BYTE, op1(SI), 0 }, 764118Srgrimes/*ad*/ { "lods", FALSE, LONG, op1(SI), 0 }, 7654Srgrimes/*ae*/ { "scas", FALSE, BYTE, op1(SI), 0 }, 7664Srgrimes/*af*/ { "scas", FALSE, LONG, op1(SI), 0 }, 7674Srgrimes 7684Srgrimes/*b0*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7694Srgrimes/*b1*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7704Srgrimes/*b2*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7714Srgrimes/*b3*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7724Srgrimes/*b4*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7734Srgrimes/*b5*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7744Srgrimes/*b6*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7754Srgrimes/*b7*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7764Srgrimes 777164263Sjhb/*b8*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 }, 778164263Sjhb/*b9*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 }, 779164263Sjhb/*ba*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 }, 780164263Sjhb/*bb*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 }, 781164263Sjhb/*bc*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 }, 782164263Sjhb/*bd*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 }, 783164263Sjhb/*be*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 }, 784164263Sjhb/*bf*/ { "mov", FALSE, LONG, op2(Ilq, Ri), 0 }, 7854Srgrimes 78617109Sbde/*c0*/ { "", TRUE, BYTE, op2(Ib, E), db_Grp2 }, 78717109Sbde/*c1*/ { "", TRUE, LONG, op2(Ib, E), db_Grp2 }, 7884Srgrimes/*c2*/ { "ret", FALSE, NONE, op1(Iw), 0 }, 7894Srgrimes/*c3*/ { "ret", FALSE, NONE, 0, 0 }, 7904Srgrimes/*c4*/ { "les", TRUE, LONG, op2(E, R), 0 }, 7914Srgrimes/*c5*/ { "lds", TRUE, LONG, op2(E, R), 0 }, 7924Srgrimes/*c6*/ { "mov", TRUE, BYTE, op2(I, E), 0 }, 7934Srgrimes/*c7*/ { "mov", TRUE, LONG, op2(I, E), 0 }, 7944Srgrimes 79521277Sbde/*c8*/ { "enter", FALSE, NONE, op2(Iw, Ib), 0 }, 7964Srgrimes/*c9*/ { "leave", FALSE, NONE, 0, 0 }, 7974Srgrimes/*ca*/ { "lret", FALSE, NONE, op1(Iw), 0 }, 7984Srgrimes/*cb*/ { "lret", FALSE, NONE, 0, 0 }, 7994Srgrimes/*cc*/ { "int", FALSE, NONE, op1(o3), 0 }, 8004Srgrimes/*cd*/ { "int", FALSE, NONE, op1(Ib), 0 }, 8014Srgrimes/*ce*/ { "into", FALSE, NONE, 0, 0 }, 8024Srgrimes/*cf*/ { "iret", FALSE, NONE, 0, 0 }, 8034Srgrimes 80417109Sbde/*d0*/ { "", TRUE, BYTE, op2(o1, E), db_Grp2 }, 80517109Sbde/*d1*/ { "", TRUE, LONG, op2(o1, E), db_Grp2 }, 80617109Sbde/*d2*/ { "", TRUE, BYTE, op2(CL, E), db_Grp2 }, 80717109Sbde/*d3*/ { "", TRUE, LONG, op2(CL, E), db_Grp2 }, 80821277Sbde/*d4*/ { "aam", FALSE, NONE, op1(Iba), 0 }, 80921277Sbde/*d5*/ { "aad", FALSE, NONE, op1(Iba), 0 }, 81021277Sbde/*d6*/ { ".byte\t0xd6", FALSE, NONE, 0, 0 }, 8114Srgrimes/*d7*/ { "xlat", FALSE, BYTE, op1(BX), 0 }, 8124Srgrimes 81317109Sbde/*d8*/ { "", TRUE, NONE, 0, db_Esc8 }, 81417109Sbde/*d9*/ { "", TRUE, NONE, 0, db_Esc9 }, 81517109Sbde/*da*/ { "", TRUE, NONE, 0, db_Esca }, 81617109Sbde/*db*/ { "", TRUE, NONE, 0, db_Escb }, 81717109Sbde/*dc*/ { "", TRUE, NONE, 0, db_Escc }, 81817109Sbde/*dd*/ { "", TRUE, NONE, 0, db_Escd }, 81917109Sbde/*de*/ { "", TRUE, NONE, 0, db_Esce }, 82017109Sbde/*df*/ { "", TRUE, NONE, 0, db_Escf }, 8214Srgrimes 8224Srgrimes/*e0*/ { "loopne",FALSE, NONE, op1(Db), 0 }, 8234Srgrimes/*e1*/ { "loope", FALSE, NONE, op1(Db), 0 }, 8244Srgrimes/*e2*/ { "loop", FALSE, NONE, op1(Db), 0 }, 8254Srgrimes/*e3*/ { "jcxz", FALSE, SDEP, op1(Db), "jecxz" }, 8264Srgrimes/*e4*/ { "in", FALSE, BYTE, op2(Ib, A), 0 }, 8274Srgrimes/*e5*/ { "in", FALSE, LONG, op2(Ib, A) , 0 }, 8284Srgrimes/*e6*/ { "out", FALSE, BYTE, op2(A, Ib), 0 }, 8294Srgrimes/*e7*/ { "out", FALSE, LONG, op2(A, Ib) , 0 }, 8304Srgrimes 8314Srgrimes/*e8*/ { "call", FALSE, NONE, op1(Dl), 0 }, 8324Srgrimes/*e9*/ { "jmp", FALSE, NONE, op1(Dl), 0 }, 8334Srgrimes/*ea*/ { "ljmp", FALSE, NONE, op1(OS), 0 }, 8344Srgrimes/*eb*/ { "jmp", FALSE, NONE, op1(Db), 0 }, 8354Srgrimes/*ec*/ { "in", FALSE, BYTE, op2(DX, A), 0 }, 8364Srgrimes/*ed*/ { "in", FALSE, LONG, op2(DX, A) , 0 }, 8374Srgrimes/*ee*/ { "out", FALSE, BYTE, op2(A, DX), 0 }, 8384Srgrimes/*ef*/ { "out", FALSE, LONG, op2(A, DX) , 0 }, 8394Srgrimes 8404Srgrimes/*f0*/ { "", FALSE, NONE, 0, 0 }, 84121277Sbde/*f1*/ { ".byte\t0xf1", FALSE, NONE, 0, 0 }, 8424Srgrimes/*f2*/ { "", FALSE, NONE, 0, 0 }, 8434Srgrimes/*f3*/ { "", FALSE, NONE, 0, 0 }, 8444Srgrimes/*f4*/ { "hlt", FALSE, NONE, 0, 0 }, 8454Srgrimes/*f5*/ { "cmc", FALSE, NONE, 0, 0 }, 84617109Sbde/*f6*/ { "", TRUE, BYTE, 0, db_Grp3 }, 84717109Sbde/*f7*/ { "", TRUE, LONG, 0, db_Grp3 }, 8484Srgrimes 8494Srgrimes/*f8*/ { "clc", FALSE, NONE, 0, 0 }, 8504Srgrimes/*f9*/ { "stc", FALSE, NONE, 0, 0 }, 8514Srgrimes/*fa*/ { "cli", FALSE, NONE, 0, 0 }, 8524Srgrimes/*fb*/ { "sti", FALSE, NONE, 0, 0 }, 8534Srgrimes/*fc*/ { "cld", FALSE, NONE, 0, 0 }, 8544Srgrimes/*fd*/ { "std", FALSE, NONE, 0, 0 }, 85517109Sbde/*fe*/ { "", TRUE, NONE, 0, db_Grp4 }, 85617109Sbde/*ff*/ { "", TRUE, NONE, 0, db_Grp5 }, 8574Srgrimes}; 8584Srgrimes 85917109Sbdestatic const struct inst db_bad_inst = 8604Srgrimes { "???", FALSE, NONE, 0, 0 } 8614Srgrimes; 8624Srgrimes 863144353Speter#define f_mod(rex, byte) ((byte)>>6) 864144353Speter#define f_reg(rex, byte) ((((byte)>>3)&0x7) | (rex & REX_R ? 0x8 : 0x0)) 865144353Speter#define f_rm(rex, byte) (((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0)) 8664Srgrimes 867144353Speter#define sib_ss(rex, byte) ((byte)>>6) 868144353Speter#define sib_index(rex, byte) ((((byte)>>3)&0x7) | (rex & REX_X ? 0x8 : 0x0)) 869144353Speter#define sib_base(rex, byte) (((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0)) 8704Srgrimes 87111940Sbdestruct i_addr { 8724Srgrimes int is_reg; /* if reg, reg number is in 'disp' */ 8734Srgrimes int disp; 87414887Swollman const char * base; 87514887Swollman const char * index; 8764Srgrimes int ss; 8774Srgrimes}; 8784Srgrimes 879144353Speterstatic const char * const db_reg[2][4][16] = { 880144353Speter 881144353Speter {{"%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh", 882144353Speter "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" }, 883144353Speter { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di", 884144353Speter "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" }, 885144353Speter { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi", 886144353Speter "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" }, 887144353Speter { "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi", 888144353Speter "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }}, 889144353Speter 890144353Speter {{"%al", "%cl", "%dl", "%bl", "%spl", "%bpl", "%sil", "%dil", 891144353Speter "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" }, 892144353Speter { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di", 893144353Speter "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" }, 894144353Speter { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi", 895144353Speter "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" }, 896144353Speter { "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi", 897144353Speter "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }} 8984Srgrimes}; 8994Srgrimes 90017109Sbdestatic const char * const db_seg_reg[8] = { 9014Srgrimes "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", "" 9024Srgrimes}; 9034Srgrimes 9044Srgrimes/* 9054Srgrimes * lengths for size attributes 9064Srgrimes */ 90714887Swollmanstatic const int db_lengths[] = { 9084Srgrimes 1, /* BYTE */ 9094Srgrimes 2, /* WORD */ 9104Srgrimes 4, /* LONG */ 9114Srgrimes 8, /* QUAD */ 9124Srgrimes 4, /* SNGL */ 9134Srgrimes 8, /* DBLR */ 9144Srgrimes 10, /* EXTR */ 9154Srgrimes}; 9164Srgrimes 9174Srgrimes#define get_value_inc(result, loc, size, is_signed) \ 9184Srgrimes result = db_get_value((loc), (size), (is_signed)); \ 9194Srgrimes (loc) += (size); 9204Srgrimes 92111940Sbdestatic db_addr_t 922144353Speter db_disasm_esc(db_addr_t loc, int inst, int rex, int short_addr, 92393017Sbde int size, const char *seg); 924144353Speterstatic void db_print_address(const char *seg, int size, int rex, 92593017Sbde struct i_addr *addrp); 92611940Sbdestatic db_addr_t 927144353Speter db_read_address(db_addr_t loc, int short_addr, int rex, int regmodrm, 92893017Sbde struct i_addr *addrp); 92911940Sbde 9304Srgrimes/* 9314Srgrimes * Read address at location and return updated location. 9324Srgrimes */ 93311921Sphkstatic db_addr_t 934144353Speterdb_read_address(loc, short_addr, rex, regmodrm, addrp) 9354Srgrimes db_addr_t loc; 9364Srgrimes int short_addr; 937144353Speter int rex; 9384Srgrimes int regmodrm; 93917109Sbde struct i_addr * addrp; /* out */ 9404Srgrimes{ 941164263Sjhb int mod, rm, sib, index, disp, size, have_sib; 9424Srgrimes 943144353Speter mod = f_mod(rex, regmodrm); 944144353Speter rm = f_rm(rex, regmodrm); 9454Srgrimes 9464Srgrimes if (mod == 3) { 9474Srgrimes addrp->is_reg = TRUE; 9484Srgrimes addrp->disp = rm; 9494Srgrimes return (loc); 9504Srgrimes } 9514Srgrimes addrp->is_reg = FALSE; 9524Srgrimes addrp->index = 0; 9534Srgrimes 954164263Sjhb if (short_addr) 955164263Sjhb size = LONG; 956164263Sjhb else 957164263Sjhb size = QUAD; 9584Srgrimes 959164263Sjhb if ((rm & 0x7) == 4) { 960164263Sjhb get_value_inc(sib, loc, 1, FALSE); 961164263Sjhb rm = sib_base(rex, sib); 962164263Sjhb index = sib_index(rex, sib); 963164263Sjhb if (index != 4) 964164263Sjhb addrp->index = db_reg[1][size][index]; 965164263Sjhb addrp->ss = sib_ss(rex, sib); 966164263Sjhb have_sib = 1; 967164263Sjhb } else 968164263Sjhb have_sib = 0; 969164263Sjhb 970164263Sjhb switch (mod) { 971164263Sjhb case 0: 972164263Sjhb if (rm == 5) { 973164263Sjhb get_value_inc(addrp->disp, loc, 4, FALSE); 974164263Sjhb if (have_sib) 9754Srgrimes addrp->base = 0; 976164263Sjhb else if (short_addr) 977164263Sjhb addrp->base = "%eip"; 978164263Sjhb else 979164263Sjhb addrp->base = "%rip"; 980164263Sjhb } else { 981164263Sjhb addrp->disp = 0; 982164263Sjhb addrp->base = db_reg[1][size][rm]; 983164263Sjhb } 984164263Sjhb break; 9854Srgrimes 986164263Sjhb case 1: 987164263Sjhb get_value_inc(disp, loc, 1, TRUE); 988164263Sjhb addrp->disp = disp; 989164263Sjhb addrp->base = db_reg[1][size][rm]; 990164263Sjhb break; 9914Srgrimes 992164263Sjhb case 2: 993164263Sjhb get_value_inc(disp, loc, 4, FALSE); 994164263Sjhb addrp->disp = disp; 995164263Sjhb addrp->base = db_reg[1][size][rm]; 996164263Sjhb break; 9974Srgrimes } 9984Srgrimes return (loc); 9994Srgrimes} 10004Srgrimes 100111921Sphkstatic void 1002144353Speterdb_print_address(seg, size, rex, addrp) 100317109Sbde const char * seg; 10044Srgrimes int size; 1005144353Speter int rex; 100617109Sbde struct i_addr * addrp; 10074Srgrimes{ 10084Srgrimes if (addrp->is_reg) { 1009144354Speter db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][addrp->disp]); 10104Srgrimes return; 10114Srgrimes } 10124Srgrimes 10134Srgrimes if (seg) { 10144Srgrimes db_printf("%s:", seg); 10154Srgrimes } 10164Srgrimes 1017164263Sjhb if (addrp->disp != 0 || (addrp->base == 0 && addrp->index == 0)) 1018164263Sjhb db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY); 10194Srgrimes if (addrp->base != 0 || addrp->index != 0) { 10204Srgrimes db_printf("("); 10214Srgrimes if (addrp->base) 10224Srgrimes db_printf("%s", addrp->base); 10234Srgrimes if (addrp->index) 10244Srgrimes db_printf(",%s,%d", addrp->index, 1<<addrp->ss); 10254Srgrimes db_printf(")"); 10264Srgrimes } 10274Srgrimes} 10284Srgrimes 10294Srgrimes/* 10304Srgrimes * Disassemble floating-point ("escape") instruction 10314Srgrimes * and return updated location. 10324Srgrimes */ 103311921Sphkstatic db_addr_t 1034144353Speterdb_disasm_esc(loc, inst, rex, short_addr, size, seg) 10354Srgrimes db_addr_t loc; 10364Srgrimes int inst; 1037144353Speter int rex; 10384Srgrimes int short_addr; 10394Srgrimes int size; 104017109Sbde const char * seg; 10414Srgrimes{ 10424Srgrimes int regmodrm; 104317109Sbde const struct finst * fp; 10444Srgrimes int mod; 10454Srgrimes struct i_addr address; 104617109Sbde const char * name; 10474Srgrimes 10484Srgrimes get_value_inc(regmodrm, loc, 1, FALSE); 1049144353Speter fp = &db_Esc_inst[inst - 0xd8][f_reg(rex, regmodrm)]; 1050144353Speter mod = f_mod(rex, regmodrm); 10514Srgrimes if (mod != 3) { 105221277Sbde if (*fp->f_name == '\0') { 105321277Sbde db_printf("<bad instruction>"); 105421277Sbde return (loc); 105521277Sbde } 10564Srgrimes /* 10574Srgrimes * Normal address modes. 10584Srgrimes */ 1059144353Speter loc = db_read_address(loc, short_addr, rex, regmodrm, &address); 106079885Skris db_printf("%s", fp->f_name); 10614Srgrimes switch(fp->f_size) { 10624Srgrimes case SNGL: 10634Srgrimes db_printf("s"); 10644Srgrimes break; 10654Srgrimes case DBLR: 10664Srgrimes db_printf("l"); 10674Srgrimes break; 10684Srgrimes case EXTR: 10694Srgrimes db_printf("t"); 10704Srgrimes break; 10714Srgrimes case WORD: 10724Srgrimes db_printf("s"); 10734Srgrimes break; 10744Srgrimes case LONG: 10754Srgrimes db_printf("l"); 10764Srgrimes break; 10774Srgrimes case QUAD: 10784Srgrimes db_printf("q"); 10794Srgrimes break; 10804Srgrimes default: 10814Srgrimes break; 10824Srgrimes } 10834Srgrimes db_printf("\t"); 1084144353Speter db_print_address(seg, BYTE, rex, &address); 10854Srgrimes } 10864Srgrimes else { 10874Srgrimes /* 10884Srgrimes * 'reg-reg' - special formats 10894Srgrimes */ 10904Srgrimes switch (fp->f_rrmode) { 10914Srgrimes case op2(ST,STI): 10924Srgrimes name = (fp->f_rrname) ? fp->f_rrname : fp->f_name; 1093144353Speter db_printf("%s\t%%st,%%st(%d)",name,f_rm(rex, regmodrm)); 10944Srgrimes break; 10954Srgrimes case op2(STI,ST): 10964Srgrimes name = (fp->f_rrname) ? fp->f_rrname : fp->f_name; 1097144353Speter db_printf("%s\t%%st(%d),%%st",name, f_rm(rex, regmodrm)); 10984Srgrimes break; 10994Srgrimes case op1(STI): 11004Srgrimes name = (fp->f_rrname) ? fp->f_rrname : fp->f_name; 1101144353Speter db_printf("%s\t%%st(%d)",name, f_rm(rex, regmodrm)); 11024Srgrimes break; 11034Srgrimes case op1(X): 1104144353Speter name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)]; 110521277Sbde if (*name == '\0') 110621277Sbde goto bad; 110721277Sbde db_printf("%s", name); 11084Srgrimes break; 11094Srgrimes case op1(XA): 1110144353Speter name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)]; 111121277Sbde if (*name == '\0') 111221277Sbde goto bad; 111321277Sbde db_printf("%s\t%%ax", name); 11144Srgrimes break; 11154Srgrimes default: 111621277Sbde bad: 11174Srgrimes db_printf("<bad instruction>"); 11184Srgrimes break; 11194Srgrimes } 11204Srgrimes } 11214Srgrimes 11224Srgrimes return (loc); 11234Srgrimes} 11244Srgrimes 11254Srgrimes/* 11264Srgrimes * Disassemble instruction at 'loc'. 'altfmt' specifies an 11274Srgrimes * (optional) alternate format. Return address of start of 11284Srgrimes * next instruction. 11294Srgrimes */ 11304Srgrimesdb_addr_t 11314Srgrimesdb_disasm(loc, altfmt) 11324Srgrimes db_addr_t loc; 11334Srgrimes boolean_t altfmt; 11344Srgrimes{ 11354Srgrimes int inst; 11364Srgrimes int size; 11374Srgrimes int short_addr; 113817109Sbde const char * seg; 113914887Swollman const struct inst * ip; 114014887Swollman const char * i_name; 11414Srgrimes int i_size; 11424Srgrimes int i_mode; 1143144353Speter int rex = 0; 1144798Swollman int regmodrm = 0; 11454Srgrimes boolean_t first; 11464Srgrimes int displ; 11474Srgrimes int prefix; 1148181606Sjhb int rep; 11494Srgrimes int imm; 11504Srgrimes int imm2; 1151164263Sjhb long imm64; 11524Srgrimes int len; 11534Srgrimes struct i_addr address; 11544Srgrimes 11554Srgrimes get_value_inc(inst, loc, 1, FALSE); 11564Srgrimes short_addr = FALSE; 11574Srgrimes size = LONG; 11584Srgrimes seg = 0; 11594Srgrimes 11604Srgrimes /* 11614Srgrimes * Get prefixes 11624Srgrimes */ 1163181606Sjhb rep = FALSE; 11644Srgrimes prefix = TRUE; 11654Srgrimes do { 11664Srgrimes switch (inst) { 11674Srgrimes case 0x66: /* data16 */ 11684Srgrimes size = WORD; 11694Srgrimes break; 11704Srgrimes case 0x67: 11714Srgrimes short_addr = TRUE; 11724Srgrimes break; 11734Srgrimes case 0x26: 11744Srgrimes seg = "%es"; 11754Srgrimes break; 11764Srgrimes case 0x36: 11774Srgrimes seg = "%ss"; 11784Srgrimes break; 11794Srgrimes case 0x2e: 11804Srgrimes seg = "%cs"; 11814Srgrimes break; 11824Srgrimes case 0x3e: 11834Srgrimes seg = "%ds"; 11844Srgrimes break; 11854Srgrimes case 0x64: 11864Srgrimes seg = "%fs"; 11874Srgrimes break; 11884Srgrimes case 0x65: 11894Srgrimes seg = "%gs"; 11904Srgrimes break; 11914Srgrimes case 0xf0: 11924Srgrimes db_printf("lock "); 11934Srgrimes break; 11944Srgrimes case 0xf2: 11954Srgrimes db_printf("repne "); 11964Srgrimes break; 11974Srgrimes case 0xf3: 1198181606Sjhb rep = TRUE; 11994Srgrimes break; 12004Srgrimes default: 12014Srgrimes prefix = FALSE; 12024Srgrimes break; 12034Srgrimes } 1204144353Speter if (inst >= 0x40 && inst < 0x50) { 1205144353Speter rex = inst; 1206144353Speter prefix = TRUE; 1207144353Speter } 12084Srgrimes if (prefix) { 12094Srgrimes get_value_inc(inst, loc, 1, FALSE); 12104Srgrimes } 1211181606Sjhb if (rep == TRUE) { 1212181606Sjhb if (inst == 0x90) { 1213181606Sjhb db_printf("pause\n"); 1214181606Sjhb return (loc); 1215181606Sjhb } 1216181606Sjhb db_printf("repe "); /* XXX repe VS rep */ 1217181606Sjhb rep = FALSE; 1218181606Sjhb } 12194Srgrimes } while (prefix); 12204Srgrimes 12214Srgrimes if (inst >= 0xd8 && inst <= 0xdf) { 1222144353Speter loc = db_disasm_esc(loc, inst, rex, short_addr, size, seg); 12234Srgrimes db_printf("\n"); 12244Srgrimes return (loc); 12254Srgrimes } 12264Srgrimes 12274Srgrimes if (inst == 0x0f) { 12284Srgrimes get_value_inc(inst, loc, 1, FALSE); 12294Srgrimes ip = db_inst_0f[inst>>4]; 12304Srgrimes if (ip == 0) { 12314Srgrimes ip = &db_bad_inst; 12324Srgrimes } 12334Srgrimes else { 12344Srgrimes ip = &ip[inst&0xf]; 12354Srgrimes } 12364Srgrimes } 12374Srgrimes else 12384Srgrimes ip = &db_inst_table[inst]; 12394Srgrimes 12404Srgrimes if (ip->i_has_modrm) { 12414Srgrimes get_value_inc(regmodrm, loc, 1, FALSE); 1242144353Speter loc = db_read_address(loc, short_addr, rex, regmodrm, &address); 12434Srgrimes } 12444Srgrimes 12454Srgrimes i_name = ip->i_name; 12464Srgrimes i_size = ip->i_size; 12474Srgrimes i_mode = ip->i_mode; 12484Srgrimes 124917109Sbde if (ip->i_extra == db_Grp1 || ip->i_extra == db_Grp2 || 125017109Sbde ip->i_extra == db_Grp6 || ip->i_extra == db_Grp7 || 1251181606Sjhb ip->i_extra == db_Grp8 || ip->i_extra == db_Grp9 || 1252181606Sjhb ip->i_extra == db_Grp15) { 1253144353Speter i_name = ((const char * const *)ip->i_extra)[f_reg(rex, regmodrm)]; 12544Srgrimes } 125517109Sbde else if (ip->i_extra == db_Grp3) { 125617109Sbde ip = ip->i_extra; 1257144353Speter ip = &ip[f_reg(rex, regmodrm)]; 12584Srgrimes i_name = ip->i_name; 12594Srgrimes i_mode = ip->i_mode; 12604Srgrimes } 126117109Sbde else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) { 126217109Sbde ip = ip->i_extra; 1263144353Speter ip = &ip[f_reg(rex, regmodrm)]; 12644Srgrimes i_name = ip->i_name; 12654Srgrimes i_mode = ip->i_mode; 12664Srgrimes i_size = ip->i_size; 12674Srgrimes } 12684Srgrimes 1269181606Sjhb /* Special cases that don't fit well in the tables. */ 1270181606Sjhb if (ip->i_extra == db_Grp7 && f_mod(rex, regmodrm) == 3) { 1271181606Sjhb switch (regmodrm) { 1272181606Sjhb case 0xc8: 1273181606Sjhb i_name = "monitor"; 1274181606Sjhb i_size = NONE; 1275181606Sjhb i_mode = 0; 1276181606Sjhb break; 1277181606Sjhb case 0xc9: 1278181606Sjhb i_name = "mwait"; 1279181606Sjhb i_size = NONE; 1280181606Sjhb i_mode = 0; 1281181606Sjhb break; 1282181606Sjhb case 0xf8: 1283181606Sjhb i_name = "swapgs"; 1284181606Sjhb i_size = NONE; 1285181606Sjhb i_mode = 0; 1286181606Sjhb break; 1287181606Sjhb } 1288181606Sjhb } 1289181606Sjhb if (ip->i_extra == db_Grp15 && f_mod(rex, regmodrm) == 3) { 1290181606Sjhb i_name = db_Grp15b[f_reg(rex, regmodrm)]; 1291181606Sjhb i_size = NONE; 1292181606Sjhb i_mode = 0; 1293181606Sjhb } 1294181606Sjhb 12954Srgrimes if (i_size == SDEP) { 12964Srgrimes if (size == WORD) 129779885Skris db_printf("%s", i_name); 12984Srgrimes else 129979885Skris db_printf("%s", (const char *)ip->i_extra); 13004Srgrimes } 13014Srgrimes else { 130279885Skris db_printf("%s", i_name); 1303144354Speter if ((inst >= 0x50 && inst <= 0x5f) || inst == 0x68 || inst == 0x6a) { 1304144354Speter i_size = NONE; 1305144354Speter db_printf("q"); 1306144354Speter } 13074Srgrimes if (i_size != NONE) { 13084Srgrimes if (i_size == BYTE) { 13094Srgrimes db_printf("b"); 13104Srgrimes size = BYTE; 13114Srgrimes } 13124Srgrimes else if (i_size == WORD) { 13134Srgrimes db_printf("w"); 13144Srgrimes size = WORD; 13154Srgrimes } 13164Srgrimes else if (size == WORD) 13174Srgrimes db_printf("w"); 1318144353Speter else { 1319144353Speter if (rex & REX_W) 1320144353Speter db_printf("q"); 1321144353Speter else 1322144353Speter db_printf("l"); 1323144353Speter } 13244Srgrimes } 13254Srgrimes } 13264Srgrimes db_printf("\t"); 13274Srgrimes for (first = TRUE; 13284Srgrimes i_mode != 0; 13294Srgrimes i_mode >>= 8, first = FALSE) 13304Srgrimes { 13314Srgrimes if (!first) 13324Srgrimes db_printf(","); 13334Srgrimes 13344Srgrimes switch (i_mode & 0xFF) { 13354Srgrimes 13364Srgrimes case E: 1337144353Speter db_print_address(seg, size, rex, &address); 13384Srgrimes break; 13394Srgrimes 13404Srgrimes case Eind: 13414Srgrimes db_printf("*"); 1342144353Speter db_print_address(seg, size, rex, &address); 13434Srgrimes break; 13444Srgrimes 134521277Sbde case El: 1346144353Speter db_print_address(seg, (rex & REX_W) ? QUAD : LONG, rex, &address); 134721277Sbde break; 134821277Sbde 1349144354Speter case EL: 1350144354Speter db_print_address(seg, LONG, 0, &address); 1351144354Speter break; 1352144354Speter 13534Srgrimes case Ew: 1354144353Speter db_print_address(seg, WORD, rex, &address); 13554Srgrimes break; 13564Srgrimes 13574Srgrimes case Eb: 1358144353Speter db_print_address(seg, BYTE, rex, &address); 13594Srgrimes break; 13604Srgrimes 13614Srgrimes case R: 1362144354Speter db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][f_reg(rex, regmodrm)]); 13634Srgrimes break; 13644Srgrimes 13654Srgrimes case Rw: 1366144353Speter db_printf("%s", db_reg[rex != 0 ? 1 : 0][WORD][f_reg(rex, regmodrm)]); 13674Srgrimes break; 13684Srgrimes 13694Srgrimes case Ri: 1370144354Speter db_printf("%s", db_reg[0][QUAD][f_rm(rex, inst)]); 13714Srgrimes break; 13724Srgrimes 137321277Sbde case Ril: 1374144353Speter db_printf("%s", db_reg[rex != 0 ? 1 : 0][(rex & REX_R) ? QUAD : LONG][f_rm(rex, inst)]); 137521277Sbde break; 137621277Sbde 13774Srgrimes case S: 1378144353Speter db_printf("%s", db_seg_reg[f_reg(rex, regmodrm)]); 13794Srgrimes break; 13804Srgrimes 13814Srgrimes case Si: 1382144353Speter db_printf("%s", db_seg_reg[f_reg(rex, inst)]); 13834Srgrimes break; 13844Srgrimes 13854Srgrimes case A: 1386144353Speter db_printf("%s", db_reg[rex != 0 ? 1 : 0][size][0]); /* acc */ 13874Srgrimes break; 13884Srgrimes 13894Srgrimes case BX: 13904Srgrimes if (seg) 13914Srgrimes db_printf("%s:", seg); 13924Srgrimes db_printf("(%s)", short_addr ? "%bx" : "%ebx"); 13934Srgrimes break; 13944Srgrimes 13954Srgrimes case CL: 13964Srgrimes db_printf("%%cl"); 13974Srgrimes break; 13984Srgrimes 13994Srgrimes case DX: 14004Srgrimes db_printf("%%dx"); 14014Srgrimes break; 14024Srgrimes 14034Srgrimes case SI: 14044Srgrimes if (seg) 14054Srgrimes db_printf("%s:", seg); 1406144353Speter db_printf("(%s)", short_addr ? "%si" : "%rsi"); 14074Srgrimes break; 14084Srgrimes 14094Srgrimes case DI: 1410144353Speter db_printf("%%es:(%s)", short_addr ? "%di" : "%rdi"); 14114Srgrimes break; 14124Srgrimes 14134Srgrimes case CR: 1414144353Speter db_printf("%%cr%d", f_reg(rex, regmodrm)); 14154Srgrimes break; 14164Srgrimes 14174Srgrimes case DR: 1418144353Speter db_printf("%%dr%d", f_reg(rex, regmodrm)); 14194Srgrimes break; 14204Srgrimes 14214Srgrimes case TR: 1422144353Speter db_printf("%%tr%d", f_reg(rex, regmodrm)); 14234Srgrimes break; 14244Srgrimes 14254Srgrimes case I: 1426144354Speter len = db_lengths[size]; 142721277Sbde get_value_inc(imm, loc, len, FALSE); 142837506Sbde db_printf("$%#r", imm); 14294Srgrimes break; 14304Srgrimes 14314Srgrimes case Is: 1432144353Speter len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size]; 143321277Sbde get_value_inc(imm, loc, len, FALSE); 143437506Sbde db_printf("$%+#r", imm); 14354Srgrimes break; 14364Srgrimes 14374Srgrimes case Ib: 143821277Sbde get_value_inc(imm, loc, 1, FALSE); 143937506Sbde db_printf("$%#r", imm); 14404Srgrimes break; 14414Srgrimes 144221277Sbde case Iba: 144321277Sbde get_value_inc(imm, loc, 1, FALSE); 144421277Sbde if (imm != 0x0a) 144537506Sbde db_printf("$%#r", imm); 144621277Sbde break; 144721277Sbde 14484Srgrimes case Ibs: 144921277Sbde get_value_inc(imm, loc, 1, TRUE); 145021277Sbde if (size == WORD) 145121277Sbde imm &= 0xFFFF; 145237506Sbde db_printf("$%+#r", imm); 14534Srgrimes break; 14544Srgrimes 14554Srgrimes case Iw: 145621277Sbde get_value_inc(imm, loc, 2, FALSE); 145737506Sbde db_printf("$%#r", imm); 14584Srgrimes break; 14594Srgrimes 1460164263Sjhb case Ilq: 1461164263Sjhb len = db_lengths[rex & REX_W ? QUAD : LONG]; 1462164263Sjhb get_value_inc(imm64, loc, len, FALSE); 1463164263Sjhb db_printf("$%#lr", imm64); 1464164263Sjhb break; 1465164263Sjhb 14664Srgrimes case O: 146721277Sbde len = (short_addr ? 2 : 4); 146821277Sbde get_value_inc(displ, loc, len, FALSE); 14694Srgrimes if (seg) 147037506Sbde db_printf("%s:%+#r",seg, displ); 14714Srgrimes else 14724Srgrimes db_printsym((db_addr_t)displ, DB_STGY_ANY); 14734Srgrimes break; 14744Srgrimes 14754Srgrimes case Db: 14764Srgrimes get_value_inc(displ, loc, 1, TRUE); 147721277Sbde displ += loc; 147821277Sbde if (size == WORD) 147921277Sbde displ &= 0xFFFF; 148021277Sbde db_printsym((db_addr_t)displ, DB_STGY_XTRN); 14814Srgrimes break; 14824Srgrimes 14834Srgrimes case Dl: 1484144353Speter len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size]; 148521277Sbde get_value_inc(displ, loc, len, FALSE); 148621277Sbde displ += loc; 148721277Sbde if (size == WORD) 148821277Sbde displ &= 0xFFFF; 148921277Sbde db_printsym((db_addr_t)displ, DB_STGY_XTRN); 14904Srgrimes break; 14914Srgrimes 14924Srgrimes case o1: 14934Srgrimes db_printf("$1"); 14944Srgrimes break; 14954Srgrimes 14964Srgrimes case o3: 14974Srgrimes db_printf("$3"); 14984Srgrimes break; 14994Srgrimes 15004Srgrimes case OS: 150121277Sbde len = db_lengths[size]; 150221277Sbde get_value_inc(imm, loc, len, FALSE); /* offset */ 15034Srgrimes get_value_inc(imm2, loc, 2, FALSE); /* segment */ 150437506Sbde db_printf("$%#r,%#r", imm2, imm); 15054Srgrimes break; 15064Srgrimes } 15074Srgrimes } 15084Srgrimes db_printf("\n"); 15094Srgrimes return (loc); 15104Srgrimes} 1511