db_disasm.c revision 144353
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 144353 2005-03-30 22:52:27Z peter $"); 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 */ 874Srgrimes#define O 25 /* direct address */ 884Srgrimes#define Db 26 /* byte displacement from EIP */ 894Srgrimes#define Dl 27 /* long displacement from EIP */ 904Srgrimes#define o1 28 /* constant 1 */ 914Srgrimes#define o3 29 /* constant 3 */ 924Srgrimes#define OS 30 /* immediate offset/segment */ 934Srgrimes#define ST 31 /* FP stack top */ 944Srgrimes#define STI 32 /* FP stack */ 954Srgrimes#define X 33 /* extended FP op */ 964Srgrimes#define XA 34 /* for 'fstcw %ax' */ 9721277Sbde#define El 35 /* address, long size */ 9821277Sbde#define Ril 36 /* long register in instruction */ 9921277Sbde#define Iba 37 /* byte immediate, don't print if 0xa */ 1004Srgrimes 10111940Sbdestruct inst { 10214887Swollman const char * i_name; /* name */ 1034Srgrimes short i_has_modrm; /* has regmodrm byte */ 1044Srgrimes short i_size; /* operand size */ 1054Srgrimes int i_mode; /* addressing modes */ 10617109Sbde const void * i_extra; /* pointer to extra opcode table */ 1074Srgrimes}; 1084Srgrimes 1094Srgrimes#define op1(x) (x) 1104Srgrimes#define op2(x,y) ((x)|((y)<<8)) 1114Srgrimes#define op3(x,y,z) ((x)|((y)<<8)|((z)<<16)) 1124Srgrimes 11311940Sbdestruct finst { 11414887Swollman const char * f_name; /* name for memory instruction */ 1154Srgrimes int f_size; /* size for memory instruction */ 1164Srgrimes int f_rrmode; /* mode for rr instruction */ 11717109Sbde const void * f_rrname; /* name for rr instruction 1184Srgrimes (or pointer to table) */ 1194Srgrimes}; 1204Srgrimes 12114887Swollmanstatic const char * const db_Grp6[] = { 1224Srgrimes "sldt", 1234Srgrimes "str", 1244Srgrimes "lldt", 1254Srgrimes "ltr", 1264Srgrimes "verr", 1274Srgrimes "verw", 1284Srgrimes "", 1294Srgrimes "" 1304Srgrimes}; 1314Srgrimes 13214887Swollmanstatic const char * const db_Grp7[] = { 1334Srgrimes "sgdt", 1344Srgrimes "sidt", 1354Srgrimes "lgdt", 1364Srgrimes "lidt", 1374Srgrimes "smsw", 1384Srgrimes "", 1394Srgrimes "lmsw", 1404Srgrimes "invlpg" 1414Srgrimes}; 1424Srgrimes 14314887Swollmanstatic const char * const db_Grp8[] = { 1444Srgrimes "", 1454Srgrimes "", 1464Srgrimes "", 1474Srgrimes "", 1484Srgrimes "bt", 1494Srgrimes "bts", 1504Srgrimes "btr", 1514Srgrimes "btc" 1524Srgrimes}; 1534Srgrimes 15421277Sbdestatic const char * const db_Grp9[] = { 15521277Sbde "", 15621277Sbde "cmpxchg8b", 15721277Sbde "", 15821277Sbde "", 15921277Sbde "", 16021277Sbde "", 16121277Sbde "", 16221277Sbde "" 16321277Sbde}; 16421277Sbde 16514887Swollmanstatic const struct inst db_inst_0f0x[] = { 16617109Sbde/*00*/ { "", TRUE, NONE, op1(Ew), db_Grp6 }, 16717109Sbde/*01*/ { "", TRUE, NONE, op1(Ew), db_Grp7 }, 1684Srgrimes/*02*/ { "lar", TRUE, LONG, op2(E,R), 0 }, 1694Srgrimes/*03*/ { "lsl", TRUE, LONG, op2(E,R), 0 }, 1704Srgrimes/*04*/ { "", FALSE, NONE, 0, 0 }, 1714Srgrimes/*05*/ { "", FALSE, NONE, 0, 0 }, 1724Srgrimes/*06*/ { "clts", FALSE, NONE, 0, 0 }, 1734Srgrimes/*07*/ { "", FALSE, NONE, 0, 0 }, 1744Srgrimes 1754Srgrimes/*08*/ { "invd", FALSE, NONE, 0, 0 }, 1764Srgrimes/*09*/ { "wbinvd",FALSE, NONE, 0, 0 }, 1774Srgrimes/*0a*/ { "", FALSE, NONE, 0, 0 }, 1784Srgrimes/*0b*/ { "", FALSE, NONE, 0, 0 }, 1794Srgrimes/*0c*/ { "", FALSE, NONE, 0, 0 }, 1804Srgrimes/*0d*/ { "", FALSE, NONE, 0, 0 }, 1814Srgrimes/*0e*/ { "", FALSE, NONE, 0, 0 }, 1824Srgrimes/*0f*/ { "", FALSE, NONE, 0, 0 }, 1834Srgrimes}; 1844Srgrimes 18517109Sbdestatic const struct inst db_inst_0f2x[] = { 18621277Sbde/*20*/ { "mov", TRUE, LONG, op2(CR,El), 0 }, 18721277Sbde/*21*/ { "mov", TRUE, LONG, op2(DR,El), 0 }, 18821277Sbde/*22*/ { "mov", TRUE, LONG, op2(El,CR), 0 }, 18921277Sbde/*23*/ { "mov", TRUE, LONG, op2(El,DR), 0 }, 19021277Sbde/*24*/ { "mov", TRUE, LONG, op2(TR,El), 0 }, 1914Srgrimes/*25*/ { "", FALSE, NONE, 0, 0 }, 19221277Sbde/*26*/ { "mov", TRUE, LONG, op2(El,TR), 0 }, 1934Srgrimes/*27*/ { "", FALSE, NONE, 0, 0 }, 1944Srgrimes 1954Srgrimes/*28*/ { "", FALSE, NONE, 0, 0 }, 1964Srgrimes/*29*/ { "", FALSE, NONE, 0, 0 }, 1974Srgrimes/*2a*/ { "", FALSE, NONE, 0, 0 }, 1984Srgrimes/*2b*/ { "", FALSE, NONE, 0, 0 }, 1994Srgrimes/*2c*/ { "", FALSE, NONE, 0, 0 }, 2004Srgrimes/*2d*/ { "", FALSE, NONE, 0, 0 }, 2014Srgrimes/*2e*/ { "", FALSE, NONE, 0, 0 }, 2024Srgrimes/*2f*/ { "", FALSE, NONE, 0, 0 }, 2034Srgrimes}; 2044Srgrimes 20514887Swollmanstatic const struct inst db_inst_0f3x[] = { 20614887Swollman/*30*/ { "wrmsr", FALSE, NONE, 0, 0 }, 20714887Swollman/*31*/ { "rdtsc", FALSE, NONE, 0, 0 }, 20814887Swollman/*32*/ { "rdmsr", FALSE, NONE, 0, 0 }, 20914887Swollman/*33*/ { "rdpmc", FALSE, NONE, 0, 0 }, 21014887Swollman/*34*/ { "", FALSE, NONE, 0, 0 }, 21114887Swollman/*35*/ { "", FALSE, NONE, 0, 0 }, 21214887Swollman/*36*/ { "", FALSE, NONE, 0, 0 }, 21314887Swollman/*37*/ { "", FALSE, NONE, 0, 0 }, 21414887Swollman 21514887Swollman/*38*/ { "", FALSE, NONE, 0, 0 }, 21614887Swollman/*39*/ { "", FALSE, NONE, 0, 0 }, 21714887Swollman/*3a*/ { "", FALSE, NONE, 0, 0 }, 21814887Swollman/*3b*/ { "", FALSE, NONE, 0, 0 }, 21914887Swollman/*3c*/ { "", FALSE, NONE, 0, 0 }, 22014887Swollman/*3d*/ { "", FALSE, NONE, 0, 0 }, 22114887Swollman/*3e*/ { "", FALSE, NONE, 0, 0 }, 22214887Swollman/*3f*/ { "", FALSE, NONE, 0, 0 }, 22314887Swollman}; 22414887Swollman 22517109Sbdestatic const struct inst db_inst_0f8x[] = { 2264Srgrimes/*80*/ { "jo", FALSE, NONE, op1(Dl), 0 }, 2274Srgrimes/*81*/ { "jno", FALSE, NONE, op1(Dl), 0 }, 2284Srgrimes/*82*/ { "jb", FALSE, NONE, op1(Dl), 0 }, 2294Srgrimes/*83*/ { "jnb", FALSE, NONE, op1(Dl), 0 }, 2304Srgrimes/*84*/ { "jz", FALSE, NONE, op1(Dl), 0 }, 2314Srgrimes/*85*/ { "jnz", FALSE, NONE, op1(Dl), 0 }, 2324Srgrimes/*86*/ { "jbe", FALSE, NONE, op1(Dl), 0 }, 2334Srgrimes/*87*/ { "jnbe", FALSE, NONE, op1(Dl), 0 }, 2344Srgrimes 2354Srgrimes/*88*/ { "js", FALSE, NONE, op1(Dl), 0 }, 2364Srgrimes/*89*/ { "jns", FALSE, NONE, op1(Dl), 0 }, 2374Srgrimes/*8a*/ { "jp", FALSE, NONE, op1(Dl), 0 }, 2384Srgrimes/*8b*/ { "jnp", FALSE, NONE, op1(Dl), 0 }, 2394Srgrimes/*8c*/ { "jl", FALSE, NONE, op1(Dl), 0 }, 2404Srgrimes/*8d*/ { "jnl", FALSE, NONE, op1(Dl), 0 }, 2414Srgrimes/*8e*/ { "jle", FALSE, NONE, op1(Dl), 0 }, 2424Srgrimes/*8f*/ { "jnle", FALSE, NONE, op1(Dl), 0 }, 2434Srgrimes}; 2444Srgrimes 24517109Sbdestatic const struct inst db_inst_0f9x[] = { 2464Srgrimes/*90*/ { "seto", TRUE, NONE, op1(Eb), 0 }, 2474Srgrimes/*91*/ { "setno", TRUE, NONE, op1(Eb), 0 }, 2484Srgrimes/*92*/ { "setb", TRUE, NONE, op1(Eb), 0 }, 2494Srgrimes/*93*/ { "setnb", TRUE, NONE, op1(Eb), 0 }, 2504Srgrimes/*94*/ { "setz", TRUE, NONE, op1(Eb), 0 }, 2514Srgrimes/*95*/ { "setnz", TRUE, NONE, op1(Eb), 0 }, 2524Srgrimes/*96*/ { "setbe", TRUE, NONE, op1(Eb), 0 }, 2534Srgrimes/*97*/ { "setnbe",TRUE, NONE, op1(Eb), 0 }, 2544Srgrimes 2554Srgrimes/*98*/ { "sets", TRUE, NONE, op1(Eb), 0 }, 2564Srgrimes/*99*/ { "setns", TRUE, NONE, op1(Eb), 0 }, 2574Srgrimes/*9a*/ { "setp", TRUE, NONE, op1(Eb), 0 }, 2584Srgrimes/*9b*/ { "setnp", TRUE, NONE, op1(Eb), 0 }, 2594Srgrimes/*9c*/ { "setl", TRUE, NONE, op1(Eb), 0 }, 2604Srgrimes/*9d*/ { "setnl", TRUE, NONE, op1(Eb), 0 }, 2614Srgrimes/*9e*/ { "setle", TRUE, NONE, op1(Eb), 0 }, 2624Srgrimes/*9f*/ { "setnle",TRUE, NONE, op1(Eb), 0 }, 2634Srgrimes}; 2644Srgrimes 26517109Sbdestatic const struct inst db_inst_0fax[] = { 2664Srgrimes/*a0*/ { "push", FALSE, NONE, op1(Si), 0 }, 2674Srgrimes/*a1*/ { "pop", FALSE, NONE, op1(Si), 0 }, 26821277Sbde/*a2*/ { "cpuid", FALSE, NONE, 0, 0 }, 26921277Sbde/*a3*/ { "bt", TRUE, LONG, op2(R,E), 0 }, 27017109Sbde/*a4*/ { "shld", TRUE, LONG, op3(Ib,R,E), 0 }, 27117109Sbde/*a5*/ { "shld", TRUE, LONG, op3(CL,R,E), 0 }, 2724Srgrimes/*a6*/ { "", FALSE, NONE, 0, 0 }, 2734Srgrimes/*a7*/ { "", FALSE, NONE, 0, 0 }, 2744Srgrimes 2754Srgrimes/*a8*/ { "push", FALSE, NONE, op1(Si), 0 }, 2764Srgrimes/*a9*/ { "pop", FALSE, NONE, op1(Si), 0 }, 27721277Sbde/*aa*/ { "rsm", FALSE, NONE, 0, 0 }, 27821277Sbde/*ab*/ { "bts", TRUE, LONG, op2(R,E), 0 }, 27917109Sbde/*ac*/ { "shrd", TRUE, LONG, op3(Ib,R,E), 0 }, 28017109Sbde/*ad*/ { "shrd", TRUE, LONG, op3(CL,R,E), 0 }, 2814Srgrimes/*a6*/ { "", FALSE, NONE, 0, 0 }, 2824Srgrimes/*a7*/ { "imul", TRUE, LONG, op2(E,R), 0 }, 2834Srgrimes}; 2844Srgrimes 28517109Sbdestatic const struct inst db_inst_0fbx[] = { 28621277Sbde/*b0*/ { "cmpxchg",TRUE, BYTE, op2(R, E), 0 }, 28721277Sbde/*b0*/ { "cmpxchg",TRUE, LONG, op2(R, E), 0 }, 2884Srgrimes/*b2*/ { "lss", TRUE, LONG, op2(E, R), 0 }, 28921277Sbde/*b3*/ { "btr", TRUE, LONG, op2(R, E), 0 }, 2904Srgrimes/*b4*/ { "lfs", TRUE, LONG, op2(E, R), 0 }, 2914Srgrimes/*b5*/ { "lgs", TRUE, LONG, op2(E, R), 0 }, 29221277Sbde/*b6*/ { "movzb", TRUE, LONG, op2(Eb, R), 0 }, 29321277Sbde/*b7*/ { "movzw", TRUE, LONG, op2(Ew, R), 0 }, 2944Srgrimes 2954Srgrimes/*b8*/ { "", FALSE, NONE, 0, 0 }, 2964Srgrimes/*b9*/ { "", FALSE, NONE, 0, 0 }, 29717109Sbde/*ba*/ { "", TRUE, LONG, op2(Ib, E), db_Grp8 }, 2984Srgrimes/*bb*/ { "btc", TRUE, LONG, op2(R, E), 0 }, 2994Srgrimes/*bc*/ { "bsf", TRUE, LONG, op2(E, R), 0 }, 3004Srgrimes/*bd*/ { "bsr", TRUE, LONG, op2(E, R), 0 }, 30121277Sbde/*be*/ { "movsb", TRUE, LONG, op2(Eb, R), 0 }, 30221277Sbde/*bf*/ { "movsw", TRUE, LONG, op2(Ew, R), 0 }, 3034Srgrimes}; 3044Srgrimes 30517109Sbdestatic const struct inst db_inst_0fcx[] = { 3064Srgrimes/*c0*/ { "xadd", TRUE, BYTE, op2(R, E), 0 }, 3074Srgrimes/*c1*/ { "xadd", TRUE, LONG, op2(R, E), 0 }, 3084Srgrimes/*c2*/ { "", FALSE, NONE, 0, 0 }, 3094Srgrimes/*c3*/ { "", FALSE, NONE, 0, 0 }, 3104Srgrimes/*c4*/ { "", FALSE, NONE, 0, 0 }, 3114Srgrimes/*c5*/ { "", FALSE, NONE, 0, 0 }, 3124Srgrimes/*c6*/ { "", FALSE, NONE, 0, 0 }, 31321277Sbde/*c7*/ { "", TRUE, NONE, op1(E), db_Grp9 }, 31421277Sbde/*c8*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 31521277Sbde/*c9*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 31621277Sbde/*ca*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 31721277Sbde/*cb*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 31821277Sbde/*cc*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 31921277Sbde/*cd*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 32021277Sbde/*ce*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 32121277Sbde/*cf*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 3224Srgrimes}; 3234Srgrimes 32414887Swollmanstatic const struct inst * const db_inst_0f[] = { 3254Srgrimes db_inst_0f0x, 3264Srgrimes 0, 3274Srgrimes db_inst_0f2x, 32814887Swollman db_inst_0f3x, 3294Srgrimes 0, 3304Srgrimes 0, 3314Srgrimes 0, 3324Srgrimes 0, 3334Srgrimes db_inst_0f8x, 3344Srgrimes db_inst_0f9x, 3354Srgrimes db_inst_0fax, 3364Srgrimes db_inst_0fbx, 3374Srgrimes db_inst_0fcx, 3384Srgrimes 0, 33921277Sbde 0, 3404Srgrimes 0 3414Srgrimes}; 3424Srgrimes 34314887Swollmanstatic const char * const db_Esc92[] = { 3444Srgrimes "fnop", "", "", "", "", "", "", "" 3454Srgrimes}; 34614887Swollmanstatic const char * const db_Esc94[] = { 3474Srgrimes "fchs", "fabs", "", "", "ftst", "fxam", "", "" 3484Srgrimes}; 34917109Sbdestatic const char * const db_Esc95[] = { 3504Srgrimes "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz","" 3514Srgrimes}; 35217109Sbdestatic const char * const db_Esc96[] = { 3534Srgrimes "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp", 3544Srgrimes "fincstp" 3554Srgrimes}; 35614887Swollmanstatic const char * const db_Esc97[] = { 3574Srgrimes "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos" 3584Srgrimes}; 3594Srgrimes 36021277Sbdestatic const char * const db_Esca5[] = { 3614Srgrimes "", "fucompp","", "", "", "", "", "" 3624Srgrimes}; 3634Srgrimes 36417109Sbdestatic const char * const db_Escb4[] = { 36521277Sbde "fneni","fndisi", "fnclex","fninit","fsetpm", "", "", "" 3664Srgrimes}; 3674Srgrimes 36814887Swollmanstatic const char * const db_Esce3[] = { 3694Srgrimes "", "fcompp","", "", "", "", "", "" 3704Srgrimes}; 3714Srgrimes 37217109Sbdestatic const char * const db_Escf4[] = { 3734Srgrimes "fnstsw","", "", "", "", "", "", "" 3744Srgrimes}; 3754Srgrimes 37614887Swollmanstatic const struct finst db_Esc8[] = { 3774Srgrimes/*0*/ { "fadd", SNGL, op2(STI,ST), 0 }, 3784Srgrimes/*1*/ { "fmul", SNGL, op2(STI,ST), 0 }, 3794Srgrimes/*2*/ { "fcom", SNGL, op2(STI,ST), 0 }, 3804Srgrimes/*3*/ { "fcomp", SNGL, op2(STI,ST), 0 }, 3814Srgrimes/*4*/ { "fsub", SNGL, op2(STI,ST), 0 }, 3824Srgrimes/*5*/ { "fsubr", SNGL, op2(STI,ST), 0 }, 3834Srgrimes/*6*/ { "fdiv", SNGL, op2(STI,ST), 0 }, 3844Srgrimes/*7*/ { "fdivr", SNGL, op2(STI,ST), 0 }, 3854Srgrimes}; 3864Srgrimes 38714887Swollmanstatic const struct finst db_Esc9[] = { 3884Srgrimes/*0*/ { "fld", SNGL, op1(STI), 0 }, 3894Srgrimes/*1*/ { "", NONE, op1(STI), "fxch" }, 39017109Sbde/*2*/ { "fst", SNGL, op1(X), db_Esc92 }, 39121277Sbde/*3*/ { "fstp", SNGL, 0, 0 }, 39217109Sbde/*4*/ { "fldenv", NONE, op1(X), db_Esc94 }, 39317109Sbde/*5*/ { "fldcw", NONE, op1(X), db_Esc95 }, 39417109Sbde/*6*/ { "fnstenv",NONE, op1(X), db_Esc96 }, 39517109Sbde/*7*/ { "fnstcw", NONE, op1(X), db_Esc97 }, 3964Srgrimes}; 3974Srgrimes 39814887Swollmanstatic const struct finst db_Esca[] = { 39921277Sbde/*0*/ { "fiadd", LONG, 0, 0 }, 40021277Sbde/*1*/ { "fimul", LONG, 0, 0 }, 40121277Sbde/*2*/ { "ficom", LONG, 0, 0 }, 40221277Sbde/*3*/ { "ficomp", LONG, 0, 0 }, 40321277Sbde/*4*/ { "fisub", LONG, 0, 0 }, 40421277Sbde/*5*/ { "fisubr", LONG, op1(X), db_Esca5 }, 40521277Sbde/*6*/ { "fidiv", LONG, 0, 0 }, 40621277Sbde/*7*/ { "fidivr", LONG, 0, 0 } 4074Srgrimes}; 4084Srgrimes 40914887Swollmanstatic const struct finst db_Escb[] = { 41021277Sbde/*0*/ { "fild", LONG, 0, 0 }, 4114Srgrimes/*1*/ { "", NONE, 0, 0 }, 41221277Sbde/*2*/ { "fist", LONG, 0, 0 }, 41321277Sbde/*3*/ { "fistp", LONG, 0, 0 }, 41417109Sbde/*4*/ { "", WORD, op1(X), db_Escb4 }, 4154Srgrimes/*5*/ { "fld", EXTR, 0, 0 }, 4164Srgrimes/*6*/ { "", WORD, 0, 0 }, 4174Srgrimes/*7*/ { "fstp", EXTR, 0, 0 }, 4184Srgrimes}; 4194Srgrimes 42014887Swollmanstatic const struct finst db_Escc[] = { 4214Srgrimes/*0*/ { "fadd", DBLR, op2(ST,STI), 0 }, 4224Srgrimes/*1*/ { "fmul", DBLR, op2(ST,STI), 0 }, 42321277Sbde/*2*/ { "fcom", DBLR, 0, 0 }, 42421277Sbde/*3*/ { "fcomp", DBLR, 0, 0 }, 4254Srgrimes/*4*/ { "fsub", DBLR, op2(ST,STI), "fsubr" }, 4264Srgrimes/*5*/ { "fsubr", DBLR, op2(ST,STI), "fsub" }, 4274Srgrimes/*6*/ { "fdiv", DBLR, op2(ST,STI), "fdivr" }, 4284Srgrimes/*7*/ { "fdivr", DBLR, op2(ST,STI), "fdiv" }, 4294Srgrimes}; 4304Srgrimes 43114887Swollmanstatic const struct finst db_Escd[] = { 4324Srgrimes/*0*/ { "fld", DBLR, op1(STI), "ffree" }, 4334Srgrimes/*1*/ { "", NONE, 0, 0 }, 4344Srgrimes/*2*/ { "fst", DBLR, op1(STI), 0 }, 4354Srgrimes/*3*/ { "fstp", DBLR, op1(STI), 0 }, 4364Srgrimes/*4*/ { "frstor", NONE, op1(STI), "fucom" }, 4374Srgrimes/*5*/ { "", NONE, op1(STI), "fucomp" }, 4384Srgrimes/*6*/ { "fnsave", NONE, 0, 0 }, 4394Srgrimes/*7*/ { "fnstsw", NONE, 0, 0 }, 4404Srgrimes}; 4414Srgrimes 44214887Swollmanstatic const struct finst db_Esce[] = { 44321277Sbde/*0*/ { "fiadd", WORD, op2(ST,STI), "faddp" }, 44421277Sbde/*1*/ { "fimul", WORD, op2(ST,STI), "fmulp" }, 44521277Sbde/*2*/ { "ficom", WORD, 0, 0 }, 44621277Sbde/*3*/ { "ficomp", WORD, op1(X), db_Esce3 }, 44721277Sbde/*4*/ { "fisub", WORD, op2(ST,STI), "fsubrp" }, 44821277Sbde/*5*/ { "fisubr", WORD, op2(ST,STI), "fsubp" }, 44921277Sbde/*6*/ { "fidiv", WORD, op2(ST,STI), "fdivrp" }, 45021277Sbde/*7*/ { "fidivr", WORD, op2(ST,STI), "fdivp" }, 4514Srgrimes}; 4524Srgrimes 45314887Swollmanstatic const struct finst db_Escf[] = { 45421277Sbde/*0*/ { "fild", WORD, 0, 0 }, 45521277Sbde/*1*/ { "", NONE, 0, 0 }, 45621277Sbde/*2*/ { "fist", WORD, 0, 0 }, 45721277Sbde/*3*/ { "fistp", WORD, 0, 0 }, 45817109Sbde/*4*/ { "fbld", NONE, op1(XA), db_Escf4 }, 45921277Sbde/*5*/ { "fild", QUAD, 0, 0 }, 4604Srgrimes/*6*/ { "fbstp", NONE, 0, 0 }, 46121277Sbde/*7*/ { "fistp", QUAD, 0, 0 }, 4624Srgrimes}; 4634Srgrimes 46417109Sbdestatic const struct finst * const db_Esc_inst[] = { 4654Srgrimes db_Esc8, db_Esc9, db_Esca, db_Escb, 4664Srgrimes db_Escc, db_Escd, db_Esce, db_Escf 4674Srgrimes}; 4684Srgrimes 46914887Swollmanstatic const char * const db_Grp1[] = { 4704Srgrimes "add", 4714Srgrimes "or", 4724Srgrimes "adc", 4734Srgrimes "sbb", 4744Srgrimes "and", 4754Srgrimes "sub", 4764Srgrimes "xor", 4774Srgrimes "cmp" 4784Srgrimes}; 4794Srgrimes 48014887Swollmanstatic const char * const db_Grp2[] = { 4814Srgrimes "rol", 4824Srgrimes "ror", 4834Srgrimes "rcl", 4844Srgrimes "rcr", 4854Srgrimes "shl", 4864Srgrimes "shr", 4874Srgrimes "shl", 4884Srgrimes "sar" 4894Srgrimes}; 4904Srgrimes 49114887Swollmanstatic const struct inst db_Grp3[] = { 4924Srgrimes { "test", TRUE, NONE, op2(I,E), 0 }, 4934Srgrimes { "test", TRUE, NONE, op2(I,E), 0 }, 4944Srgrimes { "not", TRUE, NONE, op1(E), 0 }, 4954Srgrimes { "neg", TRUE, NONE, op1(E), 0 }, 4964Srgrimes { "mul", TRUE, NONE, op2(E,A), 0 }, 4974Srgrimes { "imul", TRUE, NONE, op2(E,A), 0 }, 4984Srgrimes { "div", TRUE, NONE, op2(E,A), 0 }, 4994Srgrimes { "idiv", TRUE, NONE, op2(E,A), 0 }, 5004Srgrimes}; 5014Srgrimes 50217109Sbdestatic const struct inst db_Grp4[] = { 5034Srgrimes { "inc", TRUE, BYTE, op1(E), 0 }, 5044Srgrimes { "dec", TRUE, BYTE, op1(E), 0 }, 5054Srgrimes { "", TRUE, NONE, 0, 0 }, 5064Srgrimes { "", TRUE, NONE, 0, 0 }, 5074Srgrimes { "", TRUE, NONE, 0, 0 }, 5084Srgrimes { "", TRUE, NONE, 0, 0 }, 5094Srgrimes { "", TRUE, NONE, 0, 0 }, 5104Srgrimes { "", TRUE, NONE, 0, 0 } 5114Srgrimes}; 5124Srgrimes 51317109Sbdestatic const struct inst db_Grp5[] = { 5144Srgrimes { "inc", TRUE, LONG, op1(E), 0 }, 5154Srgrimes { "dec", TRUE, LONG, op1(E), 0 }, 51621277Sbde { "call", TRUE, LONG, op1(Eind),0 }, 51721277Sbde { "lcall", TRUE, LONG, op1(Eind),0 }, 51821277Sbde { "jmp", TRUE, LONG, op1(Eind),0 }, 51921277Sbde { "ljmp", TRUE, LONG, op1(Eind),0 }, 5204Srgrimes { "push", TRUE, LONG, op1(E), 0 }, 5214Srgrimes { "", TRUE, NONE, 0, 0 } 5224Srgrimes}; 5234Srgrimes 52414887Swollmanstatic const struct inst db_inst_table[256] = { 5254Srgrimes/*00*/ { "add", TRUE, BYTE, op2(R, E), 0 }, 5264Srgrimes/*01*/ { "add", TRUE, LONG, op2(R, E), 0 }, 5274Srgrimes/*02*/ { "add", TRUE, BYTE, op2(E, R), 0 }, 5284Srgrimes/*03*/ { "add", TRUE, LONG, op2(E, R), 0 }, 52921277Sbde/*04*/ { "add", FALSE, BYTE, op2(I, A), 0 }, 5304Srgrimes/*05*/ { "add", FALSE, LONG, op2(Is, A), 0 }, 5314Srgrimes/*06*/ { "push", FALSE, NONE, op1(Si), 0 }, 5324Srgrimes/*07*/ { "pop", FALSE, NONE, op1(Si), 0 }, 5334Srgrimes 5344Srgrimes/*08*/ { "or", TRUE, BYTE, op2(R, E), 0 }, 5354Srgrimes/*09*/ { "or", TRUE, LONG, op2(R, E), 0 }, 5364Srgrimes/*0a*/ { "or", TRUE, BYTE, op2(E, R), 0 }, 5374Srgrimes/*0b*/ { "or", TRUE, LONG, op2(E, R), 0 }, 5384Srgrimes/*0c*/ { "or", FALSE, BYTE, op2(I, A), 0 }, 5394Srgrimes/*0d*/ { "or", FALSE, LONG, op2(I, A), 0 }, 5404Srgrimes/*0e*/ { "push", FALSE, NONE, op1(Si), 0 }, 5414Srgrimes/*0f*/ { "", FALSE, NONE, 0, 0 }, 5424Srgrimes 5434Srgrimes/*10*/ { "adc", TRUE, BYTE, op2(R, E), 0 }, 5444Srgrimes/*11*/ { "adc", TRUE, LONG, op2(R, E), 0 }, 5454Srgrimes/*12*/ { "adc", TRUE, BYTE, op2(E, R), 0 }, 5464Srgrimes/*13*/ { "adc", TRUE, LONG, op2(E, R), 0 }, 54721277Sbde/*14*/ { "adc", FALSE, BYTE, op2(I, A), 0 }, 5484Srgrimes/*15*/ { "adc", FALSE, LONG, op2(Is, A), 0 }, 5494Srgrimes/*16*/ { "push", FALSE, NONE, op1(Si), 0 }, 5504Srgrimes/*17*/ { "pop", FALSE, NONE, op1(Si), 0 }, 5514Srgrimes 5524Srgrimes/*18*/ { "sbb", TRUE, BYTE, op2(R, E), 0 }, 5534Srgrimes/*19*/ { "sbb", TRUE, LONG, op2(R, E), 0 }, 5544Srgrimes/*1a*/ { "sbb", TRUE, BYTE, op2(E, R), 0 }, 5554Srgrimes/*1b*/ { "sbb", TRUE, LONG, op2(E, R), 0 }, 55621277Sbde/*1c*/ { "sbb", FALSE, BYTE, op2(I, A), 0 }, 5574Srgrimes/*1d*/ { "sbb", FALSE, LONG, op2(Is, A), 0 }, 5584Srgrimes/*1e*/ { "push", FALSE, NONE, op1(Si), 0 }, 5594Srgrimes/*1f*/ { "pop", FALSE, NONE, op1(Si), 0 }, 5604Srgrimes 5614Srgrimes/*20*/ { "and", TRUE, BYTE, op2(R, E), 0 }, 5624Srgrimes/*21*/ { "and", TRUE, LONG, op2(R, E), 0 }, 5634Srgrimes/*22*/ { "and", TRUE, BYTE, op2(E, R), 0 }, 5644Srgrimes/*23*/ { "and", TRUE, LONG, op2(E, R), 0 }, 5654Srgrimes/*24*/ { "and", FALSE, BYTE, op2(I, A), 0 }, 5664Srgrimes/*25*/ { "and", FALSE, LONG, op2(I, A), 0 }, 5674Srgrimes/*26*/ { "", FALSE, NONE, 0, 0 }, 56821277Sbde/*27*/ { "daa", FALSE, NONE, 0, 0 }, 5694Srgrimes 5704Srgrimes/*28*/ { "sub", TRUE, BYTE, op2(R, E), 0 }, 5714Srgrimes/*29*/ { "sub", TRUE, LONG, op2(R, E), 0 }, 5724Srgrimes/*2a*/ { "sub", TRUE, BYTE, op2(E, R), 0 }, 5734Srgrimes/*2b*/ { "sub", TRUE, LONG, op2(E, R), 0 }, 57421277Sbde/*2c*/ { "sub", FALSE, BYTE, op2(I, A), 0 }, 5754Srgrimes/*2d*/ { "sub", FALSE, LONG, op2(Is, A), 0 }, 5764Srgrimes/*2e*/ { "", FALSE, NONE, 0, 0 }, 5774Srgrimes/*2f*/ { "das", FALSE, NONE, 0, 0 }, 5784Srgrimes 5794Srgrimes/*30*/ { "xor", TRUE, BYTE, op2(R, E), 0 }, 5804Srgrimes/*31*/ { "xor", TRUE, LONG, op2(R, E), 0 }, 5814Srgrimes/*32*/ { "xor", TRUE, BYTE, op2(E, R), 0 }, 5824Srgrimes/*33*/ { "xor", TRUE, LONG, op2(E, R), 0 }, 5834Srgrimes/*34*/ { "xor", FALSE, BYTE, op2(I, A), 0 }, 5844Srgrimes/*35*/ { "xor", FALSE, LONG, op2(I, A), 0 }, 5854Srgrimes/*36*/ { "", FALSE, NONE, 0, 0 }, 58621277Sbde/*37*/ { "aaa", FALSE, NONE, 0, 0 }, 5874Srgrimes 5884Srgrimes/*38*/ { "cmp", TRUE, BYTE, op2(R, E), 0 }, 5894Srgrimes/*39*/ { "cmp", TRUE, LONG, op2(R, E), 0 }, 5904Srgrimes/*3a*/ { "cmp", TRUE, BYTE, op2(E, R), 0 }, 5914Srgrimes/*3b*/ { "cmp", TRUE, LONG, op2(E, R), 0 }, 59221277Sbde/*3c*/ { "cmp", FALSE, BYTE, op2(I, A), 0 }, 5934Srgrimes/*3d*/ { "cmp", FALSE, LONG, op2(Is, A), 0 }, 5944Srgrimes/*3e*/ { "", FALSE, NONE, 0, 0 }, 5954Srgrimes/*3f*/ { "aas", FALSE, NONE, 0, 0 }, 5964Srgrimes 597144353Speter/*40*/ { "rex", FALSE, NONE, 0, 0 }, 598144353Speter/*41*/ { "rex.b", FALSE, NONE, 0, 0 }, 599144353Speter/*42*/ { "rex.x", FALSE, NONE, 0, 0 }, 600144353Speter/*43*/ { "rex.xb", FALSE, NONE, 0, 0 }, 601144353Speter/*44*/ { "rex.r", FALSE, NONE, 0, 0 }, 602144353Speter/*45*/ { "rex.rb", FALSE, NONE, 0, 0 }, 603144353Speter/*46*/ { "rex.rx", FALSE, NONE, 0, 0 }, 604144353Speter/*47*/ { "rex.rxb", FALSE, NONE, 0, 0 }, 6054Srgrimes 606144353Speter/*48*/ { "rex.w", FALSE, NONE, 0, 0 }, 607144353Speter/*49*/ { "rex.wb", FALSE, NONE, 0, 0 }, 608144353Speter/*4a*/ { "rex.wx", FALSE, NONE, 0, 0 }, 609144353Speter/*4b*/ { "rex.wxb", FALSE, NONE, 0, 0 }, 610144353Speter/*4c*/ { "rex.wr", FALSE, NONE, 0, 0 }, 611144353Speter/*4d*/ { "rex.wrb", FALSE, NONE, 0, 0 }, 612144353Speter/*4e*/ { "rex.wrx", FALSE, NONE, 0, 0 }, 613144353Speter/*4f*/ { "rex.wrxb", FALSE, NONE, 0, 0 }, 6144Srgrimes 6154Srgrimes/*50*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6164Srgrimes/*51*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6174Srgrimes/*52*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6184Srgrimes/*53*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6194Srgrimes/*54*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6204Srgrimes/*55*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6214Srgrimes/*56*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6224Srgrimes/*57*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6234Srgrimes 6244Srgrimes/*58*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6254Srgrimes/*59*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6264Srgrimes/*5a*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6274Srgrimes/*5b*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6284Srgrimes/*5c*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6294Srgrimes/*5d*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6304Srgrimes/*5e*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6314Srgrimes/*5f*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6324Srgrimes 6334Srgrimes/*60*/ { "pusha", FALSE, LONG, 0, 0 }, 6344Srgrimes/*61*/ { "popa", FALSE, LONG, 0, 0 }, 6354Srgrimes/*62*/ { "bound", TRUE, LONG, op2(E, R), 0 }, 63621277Sbde/*63*/ { "arpl", TRUE, NONE, op2(Rw,Ew), 0 }, 6374Srgrimes 6384Srgrimes/*64*/ { "", FALSE, NONE, 0, 0 }, 6394Srgrimes/*65*/ { "", FALSE, NONE, 0, 0 }, 6404Srgrimes/*66*/ { "", FALSE, NONE, 0, 0 }, 6414Srgrimes/*67*/ { "", FALSE, NONE, 0, 0 }, 6424Srgrimes 6434Srgrimes/*68*/ { "push", FALSE, LONG, op1(I), 0 }, 6444Srgrimes/*69*/ { "imul", TRUE, LONG, op3(I,E,R), 0 }, 64521277Sbde/*6a*/ { "push", FALSE, LONG, op1(Ibs), 0 }, 6464Srgrimes/*6b*/ { "imul", TRUE, LONG, op3(Ibs,E,R),0 }, 6474Srgrimes/*6c*/ { "ins", FALSE, BYTE, op2(DX, DI), 0 }, 6484Srgrimes/*6d*/ { "ins", FALSE, LONG, op2(DX, DI), 0 }, 6494Srgrimes/*6e*/ { "outs", FALSE, BYTE, op2(SI, DX), 0 }, 6504Srgrimes/*6f*/ { "outs", FALSE, LONG, op2(SI, DX), 0 }, 6514Srgrimes 6524Srgrimes/*70*/ { "jo", FALSE, NONE, op1(Db), 0 }, 6534Srgrimes/*71*/ { "jno", FALSE, NONE, op1(Db), 0 }, 6544Srgrimes/*72*/ { "jb", FALSE, NONE, op1(Db), 0 }, 6554Srgrimes/*73*/ { "jnb", FALSE, NONE, op1(Db), 0 }, 6564Srgrimes/*74*/ { "jz", FALSE, NONE, op1(Db), 0 }, 6574Srgrimes/*75*/ { "jnz", FALSE, NONE, op1(Db), 0 }, 6584Srgrimes/*76*/ { "jbe", FALSE, NONE, op1(Db), 0 }, 6594Srgrimes/*77*/ { "jnbe", FALSE, NONE, op1(Db), 0 }, 6604Srgrimes 6614Srgrimes/*78*/ { "js", FALSE, NONE, op1(Db), 0 }, 6624Srgrimes/*79*/ { "jns", FALSE, NONE, op1(Db), 0 }, 6634Srgrimes/*7a*/ { "jp", FALSE, NONE, op1(Db), 0 }, 6644Srgrimes/*7b*/ { "jnp", FALSE, NONE, op1(Db), 0 }, 6654Srgrimes/*7c*/ { "jl", FALSE, NONE, op1(Db), 0 }, 6664Srgrimes/*7d*/ { "jnl", FALSE, NONE, op1(Db), 0 }, 6674Srgrimes/*7e*/ { "jle", FALSE, NONE, op1(Db), 0 }, 6684Srgrimes/*7f*/ { "jnle", FALSE, NONE, op1(Db), 0 }, 6694Srgrimes 67017109Sbde/*80*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 }, 67117109Sbde/*81*/ { "", TRUE, LONG, op2(I, E), db_Grp1 }, 67221277Sbde/*82*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 }, 67317109Sbde/*83*/ { "", TRUE, LONG, op2(Ibs,E), db_Grp1 }, 6744Srgrimes/*84*/ { "test", TRUE, BYTE, op2(R, E), 0 }, 6754Srgrimes/*85*/ { "test", TRUE, LONG, op2(R, E), 0 }, 6764Srgrimes/*86*/ { "xchg", TRUE, BYTE, op2(R, E), 0 }, 6774Srgrimes/*87*/ { "xchg", TRUE, LONG, op2(R, E), 0 }, 6784Srgrimes 6794Srgrimes/*88*/ { "mov", TRUE, BYTE, op2(R, E), 0 }, 6804Srgrimes/*89*/ { "mov", TRUE, LONG, op2(R, E), 0 }, 6814Srgrimes/*8a*/ { "mov", TRUE, BYTE, op2(E, R), 0 }, 6824Srgrimes/*8b*/ { "mov", TRUE, LONG, op2(E, R), 0 }, 6834Srgrimes/*8c*/ { "mov", TRUE, NONE, op2(S, Ew), 0 }, 6844Srgrimes/*8d*/ { "lea", TRUE, LONG, op2(E, R), 0 }, 6854Srgrimes/*8e*/ { "mov", TRUE, NONE, op2(Ew, S), 0 }, 6864Srgrimes/*8f*/ { "pop", TRUE, LONG, op1(E), 0 }, 6874Srgrimes 6884Srgrimes/*90*/ { "nop", FALSE, NONE, 0, 0 }, 6894Srgrimes/*91*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 6904Srgrimes/*92*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 6914Srgrimes/*93*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 6924Srgrimes/*94*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 6934Srgrimes/*95*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 6944Srgrimes/*96*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 6954Srgrimes/*97*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 6964Srgrimes 6974Srgrimes/*98*/ { "cbw", FALSE, SDEP, 0, "cwde" }, /* cbw/cwde */ 6984Srgrimes/*99*/ { "cwd", FALSE, SDEP, 0, "cdq" }, /* cwd/cdq */ 6994Srgrimes/*9a*/ { "lcall", FALSE, NONE, op1(OS), 0 }, 7004Srgrimes/*9b*/ { "wait", FALSE, NONE, 0, 0 }, 7014Srgrimes/*9c*/ { "pushf", FALSE, LONG, 0, 0 }, 7024Srgrimes/*9d*/ { "popf", FALSE, LONG, 0, 0 }, 7034Srgrimes/*9e*/ { "sahf", FALSE, NONE, 0, 0 }, 7044Srgrimes/*9f*/ { "lahf", FALSE, NONE, 0, 0 }, 7054Srgrimes 7064Srgrimes/*a0*/ { "mov", FALSE, BYTE, op2(O, A), 0 }, 7074Srgrimes/*a1*/ { "mov", FALSE, LONG, op2(O, A), 0 }, 7084Srgrimes/*a2*/ { "mov", FALSE, BYTE, op2(A, O), 0 }, 7094Srgrimes/*a3*/ { "mov", FALSE, LONG, op2(A, O), 0 }, 7104Srgrimes/*a4*/ { "movs", FALSE, BYTE, op2(SI,DI), 0 }, 7114Srgrimes/*a5*/ { "movs", FALSE, LONG, op2(SI,DI), 0 }, 7124Srgrimes/*a6*/ { "cmps", FALSE, BYTE, op2(SI,DI), 0 }, 7134Srgrimes/*a7*/ { "cmps", FALSE, LONG, op2(SI,DI), 0 }, 7144Srgrimes 7154Srgrimes/*a8*/ { "test", FALSE, BYTE, op2(I, A), 0 }, 7164Srgrimes/*a9*/ { "test", FALSE, LONG, op2(I, A), 0 }, 7174Srgrimes/*aa*/ { "stos", FALSE, BYTE, op1(DI), 0 }, 7184Srgrimes/*ab*/ { "stos", FALSE, LONG, op1(DI), 0 }, 719118Srgrimes/*ac*/ { "lods", FALSE, BYTE, op1(SI), 0 }, 720118Srgrimes/*ad*/ { "lods", FALSE, LONG, op1(SI), 0 }, 7214Srgrimes/*ae*/ { "scas", FALSE, BYTE, op1(SI), 0 }, 7224Srgrimes/*af*/ { "scas", FALSE, LONG, op1(SI), 0 }, 7234Srgrimes 7244Srgrimes/*b0*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7254Srgrimes/*b1*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7264Srgrimes/*b2*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7274Srgrimes/*b3*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7284Srgrimes/*b4*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7294Srgrimes/*b5*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7304Srgrimes/*b6*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7314Srgrimes/*b7*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7324Srgrimes 7334Srgrimes/*b8*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7344Srgrimes/*b9*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7354Srgrimes/*ba*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7364Srgrimes/*bb*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7374Srgrimes/*bc*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7384Srgrimes/*bd*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7394Srgrimes/*be*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7404Srgrimes/*bf*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7414Srgrimes 74217109Sbde/*c0*/ { "", TRUE, BYTE, op2(Ib, E), db_Grp2 }, 74317109Sbde/*c1*/ { "", TRUE, LONG, op2(Ib, E), db_Grp2 }, 7444Srgrimes/*c2*/ { "ret", FALSE, NONE, op1(Iw), 0 }, 7454Srgrimes/*c3*/ { "ret", FALSE, NONE, 0, 0 }, 7464Srgrimes/*c4*/ { "les", TRUE, LONG, op2(E, R), 0 }, 7474Srgrimes/*c5*/ { "lds", TRUE, LONG, op2(E, R), 0 }, 7484Srgrimes/*c6*/ { "mov", TRUE, BYTE, op2(I, E), 0 }, 7494Srgrimes/*c7*/ { "mov", TRUE, LONG, op2(I, E), 0 }, 7504Srgrimes 75121277Sbde/*c8*/ { "enter", FALSE, NONE, op2(Iw, Ib), 0 }, 7524Srgrimes/*c9*/ { "leave", FALSE, NONE, 0, 0 }, 7534Srgrimes/*ca*/ { "lret", FALSE, NONE, op1(Iw), 0 }, 7544Srgrimes/*cb*/ { "lret", FALSE, NONE, 0, 0 }, 7554Srgrimes/*cc*/ { "int", FALSE, NONE, op1(o3), 0 }, 7564Srgrimes/*cd*/ { "int", FALSE, NONE, op1(Ib), 0 }, 7574Srgrimes/*ce*/ { "into", FALSE, NONE, 0, 0 }, 7584Srgrimes/*cf*/ { "iret", FALSE, NONE, 0, 0 }, 7594Srgrimes 76017109Sbde/*d0*/ { "", TRUE, BYTE, op2(o1, E), db_Grp2 }, 76117109Sbde/*d1*/ { "", TRUE, LONG, op2(o1, E), db_Grp2 }, 76217109Sbde/*d2*/ { "", TRUE, BYTE, op2(CL, E), db_Grp2 }, 76317109Sbde/*d3*/ { "", TRUE, LONG, op2(CL, E), db_Grp2 }, 76421277Sbde/*d4*/ { "aam", FALSE, NONE, op1(Iba), 0 }, 76521277Sbde/*d5*/ { "aad", FALSE, NONE, op1(Iba), 0 }, 76621277Sbde/*d6*/ { ".byte\t0xd6", FALSE, NONE, 0, 0 }, 7674Srgrimes/*d7*/ { "xlat", FALSE, BYTE, op1(BX), 0 }, 7684Srgrimes 76917109Sbde/*d8*/ { "", TRUE, NONE, 0, db_Esc8 }, 77017109Sbde/*d9*/ { "", TRUE, NONE, 0, db_Esc9 }, 77117109Sbde/*da*/ { "", TRUE, NONE, 0, db_Esca }, 77217109Sbde/*db*/ { "", TRUE, NONE, 0, db_Escb }, 77317109Sbde/*dc*/ { "", TRUE, NONE, 0, db_Escc }, 77417109Sbde/*dd*/ { "", TRUE, NONE, 0, db_Escd }, 77517109Sbde/*de*/ { "", TRUE, NONE, 0, db_Esce }, 77617109Sbde/*df*/ { "", TRUE, NONE, 0, db_Escf }, 7774Srgrimes 7784Srgrimes/*e0*/ { "loopne",FALSE, NONE, op1(Db), 0 }, 7794Srgrimes/*e1*/ { "loope", FALSE, NONE, op1(Db), 0 }, 7804Srgrimes/*e2*/ { "loop", FALSE, NONE, op1(Db), 0 }, 7814Srgrimes/*e3*/ { "jcxz", FALSE, SDEP, op1(Db), "jecxz" }, 7824Srgrimes/*e4*/ { "in", FALSE, BYTE, op2(Ib, A), 0 }, 7834Srgrimes/*e5*/ { "in", FALSE, LONG, op2(Ib, A) , 0 }, 7844Srgrimes/*e6*/ { "out", FALSE, BYTE, op2(A, Ib), 0 }, 7854Srgrimes/*e7*/ { "out", FALSE, LONG, op2(A, Ib) , 0 }, 7864Srgrimes 7874Srgrimes/*e8*/ { "call", FALSE, NONE, op1(Dl), 0 }, 7884Srgrimes/*e9*/ { "jmp", FALSE, NONE, op1(Dl), 0 }, 7894Srgrimes/*ea*/ { "ljmp", FALSE, NONE, op1(OS), 0 }, 7904Srgrimes/*eb*/ { "jmp", FALSE, NONE, op1(Db), 0 }, 7914Srgrimes/*ec*/ { "in", FALSE, BYTE, op2(DX, A), 0 }, 7924Srgrimes/*ed*/ { "in", FALSE, LONG, op2(DX, A) , 0 }, 7934Srgrimes/*ee*/ { "out", FALSE, BYTE, op2(A, DX), 0 }, 7944Srgrimes/*ef*/ { "out", FALSE, LONG, op2(A, DX) , 0 }, 7954Srgrimes 7964Srgrimes/*f0*/ { "", FALSE, NONE, 0, 0 }, 79721277Sbde/*f1*/ { ".byte\t0xf1", FALSE, NONE, 0, 0 }, 7984Srgrimes/*f2*/ { "", FALSE, NONE, 0, 0 }, 7994Srgrimes/*f3*/ { "", FALSE, NONE, 0, 0 }, 8004Srgrimes/*f4*/ { "hlt", FALSE, NONE, 0, 0 }, 8014Srgrimes/*f5*/ { "cmc", FALSE, NONE, 0, 0 }, 80217109Sbde/*f6*/ { "", TRUE, BYTE, 0, db_Grp3 }, 80317109Sbde/*f7*/ { "", TRUE, LONG, 0, db_Grp3 }, 8044Srgrimes 8054Srgrimes/*f8*/ { "clc", FALSE, NONE, 0, 0 }, 8064Srgrimes/*f9*/ { "stc", FALSE, NONE, 0, 0 }, 8074Srgrimes/*fa*/ { "cli", FALSE, NONE, 0, 0 }, 8084Srgrimes/*fb*/ { "sti", FALSE, NONE, 0, 0 }, 8094Srgrimes/*fc*/ { "cld", FALSE, NONE, 0, 0 }, 8104Srgrimes/*fd*/ { "std", FALSE, NONE, 0, 0 }, 81117109Sbde/*fe*/ { "", TRUE, NONE, 0, db_Grp4 }, 81217109Sbde/*ff*/ { "", TRUE, NONE, 0, db_Grp5 }, 8134Srgrimes}; 8144Srgrimes 81517109Sbdestatic const struct inst db_bad_inst = 8164Srgrimes { "???", FALSE, NONE, 0, 0 } 8174Srgrimes; 8184Srgrimes 819144353Speter#define f_mod(rex, byte) ((byte)>>6) 820144353Speter#define f_reg(rex, byte) ((((byte)>>3)&0x7) | (rex & REX_R ? 0x8 : 0x0)) 821144353Speter#define f_rm(rex, byte) (((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0)) 8224Srgrimes 823144353Speter#define sib_ss(rex, byte) ((byte)>>6) 824144353Speter#define sib_index(rex, byte) ((((byte)>>3)&0x7) | (rex & REX_X ? 0x8 : 0x0)) 825144353Speter#define sib_base(rex, byte) (((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0)) 8264Srgrimes 82711940Sbdestruct i_addr { 8284Srgrimes int is_reg; /* if reg, reg number is in 'disp' */ 8294Srgrimes int disp; 83014887Swollman const char * base; 83114887Swollman const char * index; 8324Srgrimes int ss; 8334Srgrimes}; 8344Srgrimes 83514887Swollmanstatic const char * const db_index_reg_16[8] = { 8364Srgrimes "%bx,%si", 8374Srgrimes "%bx,%di", 8384Srgrimes "%bp,%si", 8394Srgrimes "%bp,%di", 8404Srgrimes "%si", 8414Srgrimes "%di", 8424Srgrimes "%bp", 8434Srgrimes "%bx" 8444Srgrimes}; 8454Srgrimes 846144353Speterstatic const char * const db_reg[2][4][16] = { 847144353Speter 848144353Speter {{"%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh", 849144353Speter "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" }, 850144353Speter { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di", 851144353Speter "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" }, 852144353Speter { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi", 853144353Speter "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" }, 854144353Speter { "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi", 855144353Speter "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }}, 856144353Speter 857144353Speter {{"%al", "%cl", "%dl", "%bl", "%spl", "%bpl", "%sil", "%dil", 858144353Speter "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" }, 859144353Speter { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di", 860144353Speter "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" }, 861144353Speter { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi", 862144353Speter "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" }, 863144353Speter { "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi", 864144353Speter "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }} 8654Srgrimes}; 8664Srgrimes 86717109Sbdestatic const char * const db_seg_reg[8] = { 8684Srgrimes "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", "" 8694Srgrimes}; 8704Srgrimes 8714Srgrimes/* 8724Srgrimes * lengths for size attributes 8734Srgrimes */ 87414887Swollmanstatic const int db_lengths[] = { 8754Srgrimes 1, /* BYTE */ 8764Srgrimes 2, /* WORD */ 8774Srgrimes 4, /* LONG */ 8784Srgrimes 8, /* QUAD */ 8794Srgrimes 4, /* SNGL */ 8804Srgrimes 8, /* DBLR */ 8814Srgrimes 10, /* EXTR */ 8824Srgrimes}; 8834Srgrimes 884144353Speter 8854Srgrimes#define get_value_inc(result, loc, size, is_signed) \ 8864Srgrimes result = db_get_value((loc), (size), (is_signed)); \ 8874Srgrimes (loc) += (size); 8884Srgrimes 88911940Sbdestatic db_addr_t 890144353Speter db_disasm_esc(db_addr_t loc, int inst, int rex, int short_addr, 89193017Sbde int size, const char *seg); 892144353Speterstatic void db_print_address(const char *seg, int size, int rex, 89393017Sbde struct i_addr *addrp); 89411940Sbdestatic db_addr_t 895144353Speter db_read_address(db_addr_t loc, int short_addr, int rex, int regmodrm, 89693017Sbde struct i_addr *addrp); 89711940Sbde 8984Srgrimes/* 8994Srgrimes * Read address at location and return updated location. 9004Srgrimes */ 90111921Sphkstatic db_addr_t 902144353Speterdb_read_address(loc, short_addr, rex, regmodrm, addrp) 9034Srgrimes db_addr_t loc; 9044Srgrimes int short_addr; 905144353Speter int rex; 9064Srgrimes int regmodrm; 90717109Sbde struct i_addr * addrp; /* out */ 9084Srgrimes{ 9093436Sphk int mod, rm, sib, index, disp; 9104Srgrimes 911144353Speter mod = f_mod(rex, regmodrm); 912144353Speter rm = f_rm(rex, regmodrm); 9134Srgrimes 9144Srgrimes if (mod == 3) { 9154Srgrimes addrp->is_reg = TRUE; 9164Srgrimes addrp->disp = rm; 9174Srgrimes return (loc); 9184Srgrimes } 9194Srgrimes addrp->is_reg = FALSE; 9204Srgrimes addrp->index = 0; 9214Srgrimes 9224Srgrimes if (short_addr) { 9234Srgrimes addrp->index = 0; 9244Srgrimes addrp->ss = 0; 9254Srgrimes switch (mod) { 9264Srgrimes case 0: 9274Srgrimes if (rm == 6) { 92821277Sbde get_value_inc(disp, loc, 2, FALSE); 9294Srgrimes addrp->disp = disp; 9304Srgrimes addrp->base = 0; 9314Srgrimes } 9324Srgrimes else { 9334Srgrimes addrp->disp = 0; 9344Srgrimes addrp->base = db_index_reg_16[rm]; 9354Srgrimes } 9364Srgrimes break; 9374Srgrimes case 1: 9384Srgrimes get_value_inc(disp, loc, 1, TRUE); 93921277Sbde disp &= 0xFFFF; 9404Srgrimes addrp->disp = disp; 9414Srgrimes addrp->base = db_index_reg_16[rm]; 9424Srgrimes break; 9434Srgrimes case 2: 94421277Sbde get_value_inc(disp, loc, 2, FALSE); 9454Srgrimes addrp->disp = disp; 9464Srgrimes addrp->base = db_index_reg_16[rm]; 9474Srgrimes break; 9484Srgrimes } 9494Srgrimes } 9504Srgrimes else { 9514Srgrimes if (mod != 3 && rm == 4) { 9524Srgrimes get_value_inc(sib, loc, 1, FALSE); 953144353Speter rm = sib_base(rex, sib); 954144353Speter index = sib_index(rex, sib); 9554Srgrimes if (index != 4) 956144353Speter addrp->index = db_reg[rex != 0 ? 1 : 0][(rex & REX_R) ? QUAD : LONG][index]; 957144353Speter addrp->ss = sib_ss(rex, sib); 9584Srgrimes } 9594Srgrimes 9604Srgrimes switch (mod) { 9614Srgrimes case 0: 9624Srgrimes if (rm == 5) { 9634Srgrimes get_value_inc(addrp->disp, loc, 4, FALSE); 9644Srgrimes addrp->base = 0; 9654Srgrimes } 9664Srgrimes else { 9674Srgrimes addrp->disp = 0; 968144353Speter addrp->base = db_reg[rex != 0 ? 1 : 0][(rex & REX_R) ? QUAD : LONG][rm]; 9694Srgrimes } 9704Srgrimes break; 9714Srgrimes 9724Srgrimes case 1: 9734Srgrimes get_value_inc(disp, loc, 1, TRUE); 9744Srgrimes addrp->disp = disp; 975144353Speter addrp->base = db_reg[rex != 0 ? 1 : 0][(rex & REX_R) ? QUAD : LONG][rm]; 9764Srgrimes break; 9774Srgrimes 9784Srgrimes case 2: 9794Srgrimes get_value_inc(disp, loc, 4, FALSE); 9804Srgrimes addrp->disp = disp; 981144353Speter addrp->base = db_reg[rex != 0 ? 1 : 0][(rex & REX_R) ? QUAD : LONG][rm]; 9824Srgrimes break; 9834Srgrimes } 9844Srgrimes } 9854Srgrimes return (loc); 9864Srgrimes} 9874Srgrimes 98811921Sphkstatic void 989144353Speterdb_print_address(seg, size, rex, addrp) 99017109Sbde const char * seg; 9914Srgrimes int size; 992144353Speter int rex; 99317109Sbde struct i_addr * addrp; 9944Srgrimes{ 9954Srgrimes if (addrp->is_reg) { 996144353Speter db_printf("%s", db_reg[rex != 0 ? 1 : 0][size][addrp->disp]); 9974Srgrimes return; 9984Srgrimes } 9994Srgrimes 10004Srgrimes if (seg) { 10014Srgrimes db_printf("%s:", seg); 10024Srgrimes } 10034Srgrimes 10044Srgrimes db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY); 10054Srgrimes if (addrp->base != 0 || addrp->index != 0) { 10064Srgrimes db_printf("("); 10074Srgrimes if (addrp->base) 10084Srgrimes db_printf("%s", addrp->base); 10094Srgrimes if (addrp->index) 10104Srgrimes db_printf(",%s,%d", addrp->index, 1<<addrp->ss); 10114Srgrimes db_printf(")"); 10124Srgrimes } 10134Srgrimes} 10144Srgrimes 10154Srgrimes/* 10164Srgrimes * Disassemble floating-point ("escape") instruction 10174Srgrimes * and return updated location. 10184Srgrimes */ 101911921Sphkstatic db_addr_t 1020144353Speterdb_disasm_esc(loc, inst, rex, short_addr, size, seg) 10214Srgrimes db_addr_t loc; 10224Srgrimes int inst; 1023144353Speter int rex; 10244Srgrimes int short_addr; 10254Srgrimes int size; 102617109Sbde const char * seg; 10274Srgrimes{ 10284Srgrimes int regmodrm; 102917109Sbde const struct finst * fp; 10304Srgrimes int mod; 10314Srgrimes struct i_addr address; 103217109Sbde const char * name; 10334Srgrimes 10344Srgrimes get_value_inc(regmodrm, loc, 1, FALSE); 1035144353Speter fp = &db_Esc_inst[inst - 0xd8][f_reg(rex, regmodrm)]; 1036144353Speter mod = f_mod(rex, regmodrm); 10374Srgrimes if (mod != 3) { 103821277Sbde if (*fp->f_name == '\0') { 103921277Sbde db_printf("<bad instruction>"); 104021277Sbde return (loc); 104121277Sbde } 10424Srgrimes /* 10434Srgrimes * Normal address modes. 10444Srgrimes */ 1045144353Speter loc = db_read_address(loc, short_addr, rex, regmodrm, &address); 104679885Skris db_printf("%s", fp->f_name); 10474Srgrimes switch(fp->f_size) { 10484Srgrimes case SNGL: 10494Srgrimes db_printf("s"); 10504Srgrimes break; 10514Srgrimes case DBLR: 10524Srgrimes db_printf("l"); 10534Srgrimes break; 10544Srgrimes case EXTR: 10554Srgrimes db_printf("t"); 10564Srgrimes break; 10574Srgrimes case WORD: 10584Srgrimes db_printf("s"); 10594Srgrimes break; 10604Srgrimes case LONG: 10614Srgrimes db_printf("l"); 10624Srgrimes break; 10634Srgrimes case QUAD: 10644Srgrimes db_printf("q"); 10654Srgrimes break; 10664Srgrimes default: 10674Srgrimes break; 10684Srgrimes } 10694Srgrimes db_printf("\t"); 1070144353Speter db_print_address(seg, BYTE, rex, &address); 10714Srgrimes } 10724Srgrimes else { 10734Srgrimes /* 10744Srgrimes * 'reg-reg' - special formats 10754Srgrimes */ 10764Srgrimes switch (fp->f_rrmode) { 10774Srgrimes case op2(ST,STI): 10784Srgrimes name = (fp->f_rrname) ? fp->f_rrname : fp->f_name; 1079144353Speter db_printf("%s\t%%st,%%st(%d)",name,f_rm(rex, regmodrm)); 10804Srgrimes break; 10814Srgrimes case op2(STI,ST): 10824Srgrimes name = (fp->f_rrname) ? fp->f_rrname : fp->f_name; 1083144353Speter db_printf("%s\t%%st(%d),%%st",name, f_rm(rex, regmodrm)); 10844Srgrimes break; 10854Srgrimes case op1(STI): 10864Srgrimes name = (fp->f_rrname) ? fp->f_rrname : fp->f_name; 1087144353Speter db_printf("%s\t%%st(%d)",name, f_rm(rex, regmodrm)); 10884Srgrimes break; 10894Srgrimes case op1(X): 1090144353Speter name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)]; 109121277Sbde if (*name == '\0') 109221277Sbde goto bad; 109321277Sbde db_printf("%s", name); 10944Srgrimes break; 10954Srgrimes case op1(XA): 1096144353Speter name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)]; 109721277Sbde if (*name == '\0') 109821277Sbde goto bad; 109921277Sbde db_printf("%s\t%%ax", name); 11004Srgrimes break; 11014Srgrimes default: 110221277Sbde bad: 11034Srgrimes db_printf("<bad instruction>"); 11044Srgrimes break; 11054Srgrimes } 11064Srgrimes } 11074Srgrimes 11084Srgrimes return (loc); 11094Srgrimes} 11104Srgrimes 11114Srgrimes/* 11124Srgrimes * Disassemble instruction at 'loc'. 'altfmt' specifies an 11134Srgrimes * (optional) alternate format. Return address of start of 11144Srgrimes * next instruction. 11154Srgrimes */ 11164Srgrimesdb_addr_t 11174Srgrimesdb_disasm(loc, altfmt) 11184Srgrimes db_addr_t loc; 11194Srgrimes boolean_t altfmt; 11204Srgrimes{ 11214Srgrimes int inst; 11224Srgrimes int size; 11234Srgrimes int short_addr; 112417109Sbde const char * seg; 112514887Swollman const struct inst * ip; 112614887Swollman const char * i_name; 11274Srgrimes int i_size; 11284Srgrimes int i_mode; 1129144353Speter int rex = 0; 1130798Swollman int regmodrm = 0; 11314Srgrimes boolean_t first; 11324Srgrimes int displ; 11334Srgrimes int prefix; 11344Srgrimes int imm; 11354Srgrimes int imm2; 11364Srgrimes int len; 11374Srgrimes struct i_addr address; 11384Srgrimes 11394Srgrimes get_value_inc(inst, loc, 1, FALSE); 11404Srgrimes short_addr = FALSE; 11414Srgrimes size = LONG; 11424Srgrimes seg = 0; 11434Srgrimes 11444Srgrimes /* 11454Srgrimes * Get prefixes 11464Srgrimes */ 11474Srgrimes prefix = TRUE; 11484Srgrimes do { 11494Srgrimes switch (inst) { 11504Srgrimes case 0x66: /* data16 */ 11514Srgrimes size = WORD; 11524Srgrimes break; 11534Srgrimes case 0x67: 11544Srgrimes short_addr = TRUE; 11554Srgrimes break; 11564Srgrimes case 0x26: 11574Srgrimes seg = "%es"; 11584Srgrimes break; 11594Srgrimes case 0x36: 11604Srgrimes seg = "%ss"; 11614Srgrimes break; 11624Srgrimes case 0x2e: 11634Srgrimes seg = "%cs"; 11644Srgrimes break; 11654Srgrimes case 0x3e: 11664Srgrimes seg = "%ds"; 11674Srgrimes break; 11684Srgrimes case 0x64: 11694Srgrimes seg = "%fs"; 11704Srgrimes break; 11714Srgrimes case 0x65: 11724Srgrimes seg = "%gs"; 11734Srgrimes break; 11744Srgrimes case 0xf0: 11754Srgrimes db_printf("lock "); 11764Srgrimes break; 11774Srgrimes case 0xf2: 11784Srgrimes db_printf("repne "); 11794Srgrimes break; 11804Srgrimes case 0xf3: 11814Srgrimes db_printf("repe "); /* XXX repe VS rep */ 11824Srgrimes break; 11834Srgrimes default: 11844Srgrimes prefix = FALSE; 11854Srgrimes break; 11864Srgrimes } 1187144353Speter if (inst >= 0x40 && inst < 0x50) { 1188144353Speter rex = inst; 1189144353Speter prefix = TRUE; 1190144353Speter } 11914Srgrimes if (prefix) { 11924Srgrimes get_value_inc(inst, loc, 1, FALSE); 11934Srgrimes } 11944Srgrimes } while (prefix); 11954Srgrimes 11964Srgrimes if (inst >= 0xd8 && inst <= 0xdf) { 1197144353Speter loc = db_disasm_esc(loc, inst, rex, short_addr, size, seg); 11984Srgrimes db_printf("\n"); 11994Srgrimes return (loc); 12004Srgrimes } 12014Srgrimes 12024Srgrimes if (inst == 0x0f) { 12034Srgrimes get_value_inc(inst, loc, 1, FALSE); 12044Srgrimes ip = db_inst_0f[inst>>4]; 12054Srgrimes if (ip == 0) { 12064Srgrimes ip = &db_bad_inst; 12074Srgrimes } 12084Srgrimes else { 12094Srgrimes ip = &ip[inst&0xf]; 12104Srgrimes } 12114Srgrimes } 12124Srgrimes else 12134Srgrimes ip = &db_inst_table[inst]; 12144Srgrimes 12154Srgrimes if (ip->i_has_modrm) { 12164Srgrimes get_value_inc(regmodrm, loc, 1, FALSE); 1217144353Speter loc = db_read_address(loc, short_addr, rex, regmodrm, &address); 12184Srgrimes } 12194Srgrimes 12204Srgrimes i_name = ip->i_name; 12214Srgrimes i_size = ip->i_size; 12224Srgrimes i_mode = ip->i_mode; 12234Srgrimes 122417109Sbde if (ip->i_extra == db_Grp1 || ip->i_extra == db_Grp2 || 122517109Sbde ip->i_extra == db_Grp6 || ip->i_extra == db_Grp7 || 122621277Sbde ip->i_extra == db_Grp8 || ip->i_extra == db_Grp9) { 1227144353Speter i_name = ((const char * const *)ip->i_extra)[f_reg(rex, regmodrm)]; 12284Srgrimes } 122917109Sbde else if (ip->i_extra == db_Grp3) { 123017109Sbde ip = ip->i_extra; 1231144353Speter ip = &ip[f_reg(rex, regmodrm)]; 12324Srgrimes i_name = ip->i_name; 12334Srgrimes i_mode = ip->i_mode; 12344Srgrimes } 123517109Sbde else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) { 123617109Sbde ip = ip->i_extra; 1237144353Speter ip = &ip[f_reg(rex, regmodrm)]; 12384Srgrimes i_name = ip->i_name; 12394Srgrimes i_mode = ip->i_mode; 12404Srgrimes i_size = ip->i_size; 12414Srgrimes } 12424Srgrimes 12434Srgrimes if (i_size == SDEP) { 12444Srgrimes if (size == WORD) 124579885Skris db_printf("%s", i_name); 12464Srgrimes else 124779885Skris db_printf("%s", (const char *)ip->i_extra); 12484Srgrimes } 12494Srgrimes else { 125079885Skris db_printf("%s", i_name); 12514Srgrimes if (i_size != NONE) { 12524Srgrimes if (i_size == BYTE) { 12534Srgrimes db_printf("b"); 12544Srgrimes size = BYTE; 12554Srgrimes } 12564Srgrimes else if (i_size == WORD) { 12574Srgrimes db_printf("w"); 12584Srgrimes size = WORD; 12594Srgrimes } 12604Srgrimes else if (size == WORD) 12614Srgrimes db_printf("w"); 1262144353Speter else { 1263144353Speter if (rex & REX_W) 1264144353Speter db_printf("q"); 1265144353Speter else 1266144353Speter db_printf("l"); 1267144353Speter } 12684Srgrimes } 12694Srgrimes } 12704Srgrimes db_printf("\t"); 12714Srgrimes for (first = TRUE; 12724Srgrimes i_mode != 0; 12734Srgrimes i_mode >>= 8, first = FALSE) 12744Srgrimes { 12754Srgrimes if (!first) 12764Srgrimes db_printf(","); 12774Srgrimes 12784Srgrimes switch (i_mode & 0xFF) { 12794Srgrimes 12804Srgrimes case E: 1281144353Speter db_print_address(seg, size, rex, &address); 12824Srgrimes break; 12834Srgrimes 12844Srgrimes case Eind: 12854Srgrimes db_printf("*"); 1286144353Speter db_print_address(seg, size, rex, &address); 12874Srgrimes break; 12884Srgrimes 128921277Sbde case El: 1290144353Speter db_print_address(seg, (rex & REX_W) ? QUAD : LONG, rex, &address); 129121277Sbde break; 129221277Sbde 12934Srgrimes case Ew: 1294144353Speter db_print_address(seg, WORD, rex, &address); 12954Srgrimes break; 12964Srgrimes 12974Srgrimes case Eb: 1298144353Speter db_print_address(seg, BYTE, rex, &address); 12994Srgrimes break; 13004Srgrimes 13014Srgrimes case R: 1302144353Speter db_printf("%s", db_reg[rex != 0 ? 1 : 0][size][f_reg(rex, regmodrm)]); 13034Srgrimes break; 13044Srgrimes 13054Srgrimes case Rw: 1306144353Speter db_printf("%s", db_reg[rex != 0 ? 1 : 0][WORD][f_reg(rex, regmodrm)]); 13074Srgrimes break; 13084Srgrimes 13094Srgrimes case Ri: 1310144353Speter db_printf("%s", db_reg[rex != 0 ? 1 : 0][size][f_rm(rex, inst)]); 13114Srgrimes break; 13124Srgrimes 131321277Sbde case Ril: 1314144353Speter db_printf("%s", db_reg[rex != 0 ? 1 : 0][(rex & REX_R) ? QUAD : LONG][f_rm(rex, inst)]); 131521277Sbde break; 131621277Sbde 13174Srgrimes case S: 1318144353Speter db_printf("%s", db_seg_reg[f_reg(rex, regmodrm)]); 13194Srgrimes break; 13204Srgrimes 13214Srgrimes case Si: 1322144353Speter db_printf("%s", db_seg_reg[f_reg(rex, inst)]); 13234Srgrimes break; 13244Srgrimes 13254Srgrimes case A: 1326144353Speter db_printf("%s", db_reg[rex != 0 ? 1 : 0][size][0]); /* acc */ 13274Srgrimes break; 13284Srgrimes 13294Srgrimes case BX: 13304Srgrimes if (seg) 13314Srgrimes db_printf("%s:", seg); 13324Srgrimes db_printf("(%s)", short_addr ? "%bx" : "%ebx"); 13334Srgrimes break; 13344Srgrimes 13354Srgrimes case CL: 13364Srgrimes db_printf("%%cl"); 13374Srgrimes break; 13384Srgrimes 13394Srgrimes case DX: 13404Srgrimes db_printf("%%dx"); 13414Srgrimes break; 13424Srgrimes 13434Srgrimes case SI: 13444Srgrimes if (seg) 13454Srgrimes db_printf("%s:", seg); 1346144353Speter db_printf("(%s)", short_addr ? "%si" : "%rsi"); 13474Srgrimes break; 13484Srgrimes 13494Srgrimes case DI: 1350144353Speter db_printf("%%es:(%s)", short_addr ? "%di" : "%rdi"); 13514Srgrimes break; 13524Srgrimes 13534Srgrimes case CR: 1354144353Speter db_printf("%%cr%d", f_reg(rex, regmodrm)); 13554Srgrimes break; 13564Srgrimes 13574Srgrimes case DR: 1358144353Speter db_printf("%%dr%d", f_reg(rex, regmodrm)); 13594Srgrimes break; 13604Srgrimes 13614Srgrimes case TR: 1362144353Speter db_printf("%%tr%d", f_reg(rex, regmodrm)); 13634Srgrimes break; 13644Srgrimes 13654Srgrimes case I: 1366144353Speter len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size]; 136721277Sbde get_value_inc(imm, loc, len, FALSE); 136837506Sbde db_printf("$%#r", imm); 13694Srgrimes break; 13704Srgrimes 13714Srgrimes case Is: 1372144353Speter len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size]; 137321277Sbde get_value_inc(imm, loc, len, FALSE); 137437506Sbde db_printf("$%+#r", imm); 13754Srgrimes break; 13764Srgrimes 13774Srgrimes case Ib: 137821277Sbde get_value_inc(imm, loc, 1, FALSE); 137937506Sbde db_printf("$%#r", imm); 13804Srgrimes break; 13814Srgrimes 138221277Sbde case Iba: 138321277Sbde get_value_inc(imm, loc, 1, FALSE); 138421277Sbde if (imm != 0x0a) 138537506Sbde db_printf("$%#r", imm); 138621277Sbde break; 138721277Sbde 13884Srgrimes case Ibs: 138921277Sbde get_value_inc(imm, loc, 1, TRUE); 139021277Sbde if (size == WORD) 139121277Sbde imm &= 0xFFFF; 139237506Sbde db_printf("$%+#r", imm); 13934Srgrimes break; 13944Srgrimes 13954Srgrimes case Iw: 139621277Sbde get_value_inc(imm, loc, 2, FALSE); 139737506Sbde db_printf("$%#r", imm); 13984Srgrimes break; 13994Srgrimes 14004Srgrimes case O: 140121277Sbde len = (short_addr ? 2 : 4); 140221277Sbde get_value_inc(displ, loc, len, FALSE); 14034Srgrimes if (seg) 140437506Sbde db_printf("%s:%+#r",seg, displ); 14054Srgrimes else 14064Srgrimes db_printsym((db_addr_t)displ, DB_STGY_ANY); 14074Srgrimes break; 14084Srgrimes 14094Srgrimes case Db: 14104Srgrimes get_value_inc(displ, loc, 1, TRUE); 141121277Sbde displ += loc; 141221277Sbde if (size == WORD) 141321277Sbde displ &= 0xFFFF; 141421277Sbde db_printsym((db_addr_t)displ, DB_STGY_XTRN); 14154Srgrimes break; 14164Srgrimes 14174Srgrimes case Dl: 1418144353Speter len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size]; 141921277Sbde get_value_inc(displ, loc, len, FALSE); 142021277Sbde displ += loc; 142121277Sbde if (size == WORD) 142221277Sbde displ &= 0xFFFF; 142321277Sbde db_printsym((db_addr_t)displ, DB_STGY_XTRN); 14244Srgrimes break; 14254Srgrimes 14264Srgrimes case o1: 14274Srgrimes db_printf("$1"); 14284Srgrimes break; 14294Srgrimes 14304Srgrimes case o3: 14314Srgrimes db_printf("$3"); 14324Srgrimes break; 14334Srgrimes 14344Srgrimes case OS: 143521277Sbde len = db_lengths[size]; 143621277Sbde get_value_inc(imm, loc, len, FALSE); /* offset */ 14374Srgrimes get_value_inc(imm2, loc, 2, FALSE); /* segment */ 143837506Sbde db_printf("$%#r,%#r", imm2, imm); 14394Srgrimes break; 14404Srgrimes } 14414Srgrimes } 14424Srgrimes db_printf("\n"); 14434Srgrimes return (loc); 14444Srgrimes} 1445