1139724Simp/*- 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 27115683Sobrien#include <sys/cdefs.h> 28115683Sobrien__FBSDID("$FreeBSD$"); 29115683Sobrien 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/* 534Srgrimes * Addressing modes 544Srgrimes */ 554Srgrimes#define E 1 /* general effective address */ 564Srgrimes#define Eind 2 /* indirect address (jump, call) */ 574Srgrimes#define Ew 3 /* address, word size */ 584Srgrimes#define Eb 4 /* address, byte size */ 594Srgrimes#define R 5 /* register, in 'reg' field */ 604Srgrimes#define Rw 6 /* word register, in 'reg' field */ 614Srgrimes#define Ri 7 /* register in instruction */ 624Srgrimes#define S 8 /* segment reg, in 'reg' field */ 634Srgrimes#define Si 9 /* segment reg, in instruction */ 644Srgrimes#define A 10 /* accumulator */ 654Srgrimes#define BX 11 /* (bx) */ 664Srgrimes#define CL 12 /* cl, for shifts */ 674Srgrimes#define DX 13 /* dx, for IO */ 684Srgrimes#define SI 14 /* si */ 694Srgrimes#define DI 15 /* di */ 704Srgrimes#define CR 16 /* control register */ 714Srgrimes#define DR 17 /* debug register */ 724Srgrimes#define TR 18 /* test register */ 734Srgrimes#define I 19 /* immediate, unsigned */ 744Srgrimes#define Is 20 /* immediate, signed */ 754Srgrimes#define Ib 21 /* byte immediate, unsigned */ 764Srgrimes#define Ibs 22 /* byte immediate, signed */ 774Srgrimes#define Iw 23 /* word immediate, unsigned */ 784Srgrimes#define O 25 /* direct address */ 794Srgrimes#define Db 26 /* byte displacement from EIP */ 804Srgrimes#define Dl 27 /* long displacement from EIP */ 814Srgrimes#define o1 28 /* constant 1 */ 824Srgrimes#define o3 29 /* constant 3 */ 834Srgrimes#define OS 30 /* immediate offset/segment */ 844Srgrimes#define ST 31 /* FP stack top */ 854Srgrimes#define STI 32 /* FP stack */ 864Srgrimes#define X 33 /* extended FP op */ 874Srgrimes#define XA 34 /* for 'fstcw %ax' */ 8821277Sbde#define El 35 /* address, long size */ 8921277Sbde#define Ril 36 /* long register in instruction */ 9021277Sbde#define Iba 37 /* byte immediate, don't print if 0xa */ 914Srgrimes 9211940Sbdestruct inst { 9314887Swollman const char * i_name; /* name */ 944Srgrimes short i_has_modrm; /* has regmodrm byte */ 954Srgrimes short i_size; /* operand size */ 964Srgrimes int i_mode; /* addressing modes */ 9717109Sbde const void * i_extra; /* pointer to extra opcode table */ 984Srgrimes}; 994Srgrimes 1004Srgrimes#define op1(x) (x) 1014Srgrimes#define op2(x,y) ((x)|((y)<<8)) 1024Srgrimes#define op3(x,y,z) ((x)|((y)<<8)|((z)<<16)) 1034Srgrimes 10411940Sbdestruct finst { 10514887Swollman const char * f_name; /* name for memory instruction */ 1064Srgrimes int f_size; /* size for memory instruction */ 1074Srgrimes int f_rrmode; /* mode for rr instruction */ 10817109Sbde const void * f_rrname; /* name for rr instruction 1094Srgrimes (or pointer to table) */ 1104Srgrimes}; 1114Srgrimes 11214887Swollmanstatic const char * const db_Grp6[] = { 1134Srgrimes "sldt", 1144Srgrimes "str", 1154Srgrimes "lldt", 1164Srgrimes "ltr", 1174Srgrimes "verr", 1184Srgrimes "verw", 1194Srgrimes "", 1204Srgrimes "" 1214Srgrimes}; 1224Srgrimes 12314887Swollmanstatic const char * const db_Grp7[] = { 1244Srgrimes "sgdt", 1254Srgrimes "sidt", 1264Srgrimes "lgdt", 1274Srgrimes "lidt", 1284Srgrimes "smsw", 1294Srgrimes "", 1304Srgrimes "lmsw", 1314Srgrimes "invlpg" 1324Srgrimes}; 1334Srgrimes 13414887Swollmanstatic const char * const db_Grp8[] = { 1354Srgrimes "", 1364Srgrimes "", 1374Srgrimes "", 1384Srgrimes "", 1394Srgrimes "bt", 1404Srgrimes "bts", 1414Srgrimes "btr", 1424Srgrimes "btc" 1434Srgrimes}; 1444Srgrimes 14521277Sbdestatic const char * const db_Grp9[] = { 14621277Sbde "", 14721277Sbde "cmpxchg8b", 14821277Sbde "", 14921277Sbde "", 15021277Sbde "", 15121277Sbde "", 15221277Sbde "", 15321277Sbde "" 15421277Sbde}; 15521277Sbde 156181606Sjhbstatic const char * const db_Grp15[] = { 157181606Sjhb "fxsave", 158181606Sjhb "fxrstor", 159181606Sjhb "ldmxcsr", 160181606Sjhb "stmxcsr", 161181606Sjhb "", 162181606Sjhb "", 163181606Sjhb "", 164181606Sjhb "clflush" 165181606Sjhb}; 166181606Sjhb 167181606Sjhbstatic const char * const db_Grp15b[] = { 168181606Sjhb "", 169181606Sjhb "", 170181606Sjhb "", 171181606Sjhb "", 172181606Sjhb "", 173181606Sjhb "lfence", 174181606Sjhb "mfence", 175181606Sjhb "sfence" 176181606Sjhb}; 177181606Sjhb 17814887Swollmanstatic const struct inst db_inst_0f0x[] = { 17917109Sbde/*00*/ { "", TRUE, NONE, op1(Ew), db_Grp6 }, 18017109Sbde/*01*/ { "", TRUE, NONE, op1(Ew), db_Grp7 }, 1814Srgrimes/*02*/ { "lar", TRUE, LONG, op2(E,R), 0 }, 1824Srgrimes/*03*/ { "lsl", TRUE, LONG, op2(E,R), 0 }, 1834Srgrimes/*04*/ { "", FALSE, NONE, 0, 0 }, 184181606Sjhb/*05*/ { "syscall",FALSE,NONE, 0, 0 }, 1854Srgrimes/*06*/ { "clts", FALSE, NONE, 0, 0 }, 186181606Sjhb/*07*/ { "sysret",FALSE, NONE, 0, 0 }, 1874Srgrimes 1884Srgrimes/*08*/ { "invd", FALSE, NONE, 0, 0 }, 1894Srgrimes/*09*/ { "wbinvd",FALSE, NONE, 0, 0 }, 1904Srgrimes/*0a*/ { "", FALSE, NONE, 0, 0 }, 1914Srgrimes/*0b*/ { "", FALSE, NONE, 0, 0 }, 1924Srgrimes/*0c*/ { "", FALSE, NONE, 0, 0 }, 1934Srgrimes/*0d*/ { "", FALSE, NONE, 0, 0 }, 1944Srgrimes/*0e*/ { "", FALSE, NONE, 0, 0 }, 1954Srgrimes/*0f*/ { "", FALSE, NONE, 0, 0 }, 1964Srgrimes}; 1974Srgrimes 19817109Sbdestatic const struct inst db_inst_0f2x[] = { 19921277Sbde/*20*/ { "mov", TRUE, LONG, op2(CR,El), 0 }, 20021277Sbde/*21*/ { "mov", TRUE, LONG, op2(DR,El), 0 }, 20121277Sbde/*22*/ { "mov", TRUE, LONG, op2(El,CR), 0 }, 20221277Sbde/*23*/ { "mov", TRUE, LONG, op2(El,DR), 0 }, 20321277Sbde/*24*/ { "mov", TRUE, LONG, op2(TR,El), 0 }, 2044Srgrimes/*25*/ { "", FALSE, NONE, 0, 0 }, 20521277Sbde/*26*/ { "mov", TRUE, LONG, op2(El,TR), 0 }, 2064Srgrimes/*27*/ { "", FALSE, NONE, 0, 0 }, 2074Srgrimes 2084Srgrimes/*28*/ { "", FALSE, NONE, 0, 0 }, 2094Srgrimes/*29*/ { "", FALSE, NONE, 0, 0 }, 2104Srgrimes/*2a*/ { "", FALSE, NONE, 0, 0 }, 2114Srgrimes/*2b*/ { "", FALSE, NONE, 0, 0 }, 2124Srgrimes/*2c*/ { "", FALSE, NONE, 0, 0 }, 2134Srgrimes/*2d*/ { "", FALSE, NONE, 0, 0 }, 2144Srgrimes/*2e*/ { "", FALSE, NONE, 0, 0 }, 2154Srgrimes/*2f*/ { "", FALSE, NONE, 0, 0 }, 2164Srgrimes}; 2174Srgrimes 21814887Swollmanstatic const struct inst db_inst_0f3x[] = { 21914887Swollman/*30*/ { "wrmsr", FALSE, NONE, 0, 0 }, 22014887Swollman/*31*/ { "rdtsc", FALSE, NONE, 0, 0 }, 22114887Swollman/*32*/ { "rdmsr", FALSE, NONE, 0, 0 }, 22214887Swollman/*33*/ { "rdpmc", FALSE, NONE, 0, 0 }, 223181606Sjhb/*34*/ { "sysenter",FALSE,NONE, 0, 0 }, 224181606Sjhb/*35*/ { "sysexit",FALSE,NONE, 0, 0 }, 22514887Swollman/*36*/ { "", FALSE, NONE, 0, 0 }, 226181606Sjhb/*37*/ { "getsec",FALSE, NONE, 0, 0 }, 22714887Swollman 22814887Swollman/*38*/ { "", FALSE, NONE, 0, 0 }, 22914887Swollman/*39*/ { "", FALSE, NONE, 0, 0 }, 23014887Swollman/*3a*/ { "", FALSE, NONE, 0, 0 }, 23114887Swollman/*3b*/ { "", FALSE, NONE, 0, 0 }, 23214887Swollman/*3c*/ { "", FALSE, NONE, 0, 0 }, 23314887Swollman/*3d*/ { "", FALSE, NONE, 0, 0 }, 23414887Swollman/*3e*/ { "", FALSE, NONE, 0, 0 }, 23514887Swollman/*3f*/ { "", FALSE, NONE, 0, 0 }, 23614887Swollman}; 23714887Swollman 238181603Sjhbstatic const struct inst db_inst_0f4x[] = { 239181603Sjhb/*40*/ { "cmovo", TRUE, NONE, op2(E, R), 0 }, 240181603Sjhb/*41*/ { "cmovno", TRUE, NONE, op2(E, R), 0 }, 241181603Sjhb/*42*/ { "cmovb", TRUE, NONE, op2(E, R), 0 }, 242181603Sjhb/*43*/ { "cmovnb", TRUE, NONE, op2(E, R), 0 }, 243181603Sjhb/*44*/ { "cmovz", TRUE, NONE, op2(E, R), 0 }, 244181603Sjhb/*45*/ { "cmovnz", TRUE, NONE, op2(E, R), 0 }, 245181603Sjhb/*46*/ { "cmovbe", TRUE, NONE, op2(E, R), 0 }, 246181603Sjhb/*47*/ { "cmovnbe",TRUE, NONE, op2(E, R), 0 }, 247181603Sjhb 248181603Sjhb/*48*/ { "cmovs", TRUE, NONE, op2(E, R), 0 }, 249181603Sjhb/*49*/ { "cmovns", TRUE, NONE, op2(E, R), 0 }, 250181603Sjhb/*4a*/ { "cmovp", TRUE, NONE, op2(E, R), 0 }, 251181603Sjhb/*4b*/ { "cmovnp", TRUE, NONE, op2(E, R), 0 }, 252181603Sjhb/*4c*/ { "cmovl", TRUE, NONE, op2(E, R), 0 }, 253181603Sjhb/*4d*/ { "cmovnl", TRUE, NONE, op2(E, R), 0 }, 254181603Sjhb/*4e*/ { "cmovle", TRUE, NONE, op2(E, R), 0 }, 255181603Sjhb/*4f*/ { "cmovnle",TRUE, NONE, op2(E, R), 0 }, 256181603Sjhb}; 257181603Sjhb 25817109Sbdestatic const struct inst db_inst_0f8x[] = { 2594Srgrimes/*80*/ { "jo", FALSE, NONE, op1(Dl), 0 }, 2604Srgrimes/*81*/ { "jno", FALSE, NONE, op1(Dl), 0 }, 2614Srgrimes/*82*/ { "jb", FALSE, NONE, op1(Dl), 0 }, 2624Srgrimes/*83*/ { "jnb", FALSE, NONE, op1(Dl), 0 }, 2634Srgrimes/*84*/ { "jz", FALSE, NONE, op1(Dl), 0 }, 2644Srgrimes/*85*/ { "jnz", FALSE, NONE, op1(Dl), 0 }, 2654Srgrimes/*86*/ { "jbe", FALSE, NONE, op1(Dl), 0 }, 2664Srgrimes/*87*/ { "jnbe", FALSE, NONE, op1(Dl), 0 }, 2674Srgrimes 2684Srgrimes/*88*/ { "js", FALSE, NONE, op1(Dl), 0 }, 2694Srgrimes/*89*/ { "jns", FALSE, NONE, op1(Dl), 0 }, 2704Srgrimes/*8a*/ { "jp", FALSE, NONE, op1(Dl), 0 }, 2714Srgrimes/*8b*/ { "jnp", FALSE, NONE, op1(Dl), 0 }, 2724Srgrimes/*8c*/ { "jl", FALSE, NONE, op1(Dl), 0 }, 2734Srgrimes/*8d*/ { "jnl", FALSE, NONE, op1(Dl), 0 }, 2744Srgrimes/*8e*/ { "jle", FALSE, NONE, op1(Dl), 0 }, 2754Srgrimes/*8f*/ { "jnle", FALSE, NONE, op1(Dl), 0 }, 2764Srgrimes}; 2774Srgrimes 27817109Sbdestatic const struct inst db_inst_0f9x[] = { 2794Srgrimes/*90*/ { "seto", TRUE, NONE, op1(Eb), 0 }, 2804Srgrimes/*91*/ { "setno", TRUE, NONE, op1(Eb), 0 }, 2814Srgrimes/*92*/ { "setb", TRUE, NONE, op1(Eb), 0 }, 2824Srgrimes/*93*/ { "setnb", TRUE, NONE, op1(Eb), 0 }, 2834Srgrimes/*94*/ { "setz", TRUE, NONE, op1(Eb), 0 }, 2844Srgrimes/*95*/ { "setnz", TRUE, NONE, op1(Eb), 0 }, 2854Srgrimes/*96*/ { "setbe", TRUE, NONE, op1(Eb), 0 }, 2864Srgrimes/*97*/ { "setnbe",TRUE, NONE, op1(Eb), 0 }, 2874Srgrimes 2884Srgrimes/*98*/ { "sets", TRUE, NONE, op1(Eb), 0 }, 2894Srgrimes/*99*/ { "setns", TRUE, NONE, op1(Eb), 0 }, 2904Srgrimes/*9a*/ { "setp", TRUE, NONE, op1(Eb), 0 }, 2914Srgrimes/*9b*/ { "setnp", TRUE, NONE, op1(Eb), 0 }, 2924Srgrimes/*9c*/ { "setl", TRUE, NONE, op1(Eb), 0 }, 2934Srgrimes/*9d*/ { "setnl", TRUE, NONE, op1(Eb), 0 }, 2944Srgrimes/*9e*/ { "setle", TRUE, NONE, op1(Eb), 0 }, 2954Srgrimes/*9f*/ { "setnle",TRUE, NONE, op1(Eb), 0 }, 2964Srgrimes}; 2974Srgrimes 29817109Sbdestatic const struct inst db_inst_0fax[] = { 2994Srgrimes/*a0*/ { "push", FALSE, NONE, op1(Si), 0 }, 3004Srgrimes/*a1*/ { "pop", FALSE, NONE, op1(Si), 0 }, 30121277Sbde/*a2*/ { "cpuid", FALSE, NONE, 0, 0 }, 30221277Sbde/*a3*/ { "bt", TRUE, LONG, op2(R,E), 0 }, 30317109Sbde/*a4*/ { "shld", TRUE, LONG, op3(Ib,R,E), 0 }, 30417109Sbde/*a5*/ { "shld", TRUE, LONG, op3(CL,R,E), 0 }, 3054Srgrimes/*a6*/ { "", FALSE, NONE, 0, 0 }, 3064Srgrimes/*a7*/ { "", FALSE, NONE, 0, 0 }, 3074Srgrimes 3084Srgrimes/*a8*/ { "push", FALSE, NONE, op1(Si), 0 }, 3094Srgrimes/*a9*/ { "pop", FALSE, NONE, op1(Si), 0 }, 31021277Sbde/*aa*/ { "rsm", FALSE, NONE, 0, 0 }, 31121277Sbde/*ab*/ { "bts", TRUE, LONG, op2(R,E), 0 }, 31217109Sbde/*ac*/ { "shrd", TRUE, LONG, op3(Ib,R,E), 0 }, 31317109Sbde/*ad*/ { "shrd", TRUE, LONG, op3(CL,R,E), 0 }, 314181606Sjhb/*ae*/ { "", TRUE, LONG, op1(E), db_Grp15 }, 315181606Sjhb/*af*/ { "imul", TRUE, LONG, op2(E,R), 0 }, 3164Srgrimes}; 3174Srgrimes 31817109Sbdestatic const struct inst db_inst_0fbx[] = { 31921277Sbde/*b0*/ { "cmpxchg",TRUE, BYTE, op2(R, E), 0 }, 32021277Sbde/*b0*/ { "cmpxchg",TRUE, LONG, op2(R, E), 0 }, 3214Srgrimes/*b2*/ { "lss", TRUE, LONG, op2(E, R), 0 }, 32221277Sbde/*b3*/ { "btr", TRUE, LONG, op2(R, E), 0 }, 3234Srgrimes/*b4*/ { "lfs", TRUE, LONG, op2(E, R), 0 }, 3244Srgrimes/*b5*/ { "lgs", TRUE, LONG, op2(E, R), 0 }, 32521277Sbde/*b6*/ { "movzb", TRUE, LONG, op2(Eb, R), 0 }, 32621277Sbde/*b7*/ { "movzw", TRUE, LONG, op2(Ew, R), 0 }, 3274Srgrimes 3284Srgrimes/*b8*/ { "", FALSE, NONE, 0, 0 }, 3294Srgrimes/*b9*/ { "", FALSE, NONE, 0, 0 }, 33017109Sbde/*ba*/ { "", TRUE, LONG, op2(Ib, E), db_Grp8 }, 3314Srgrimes/*bb*/ { "btc", TRUE, LONG, op2(R, E), 0 }, 3324Srgrimes/*bc*/ { "bsf", TRUE, LONG, op2(E, R), 0 }, 3334Srgrimes/*bd*/ { "bsr", TRUE, LONG, op2(E, R), 0 }, 33421277Sbde/*be*/ { "movsb", TRUE, LONG, op2(Eb, R), 0 }, 33521277Sbde/*bf*/ { "movsw", TRUE, LONG, op2(Ew, R), 0 }, 3364Srgrimes}; 3374Srgrimes 33817109Sbdestatic const struct inst db_inst_0fcx[] = { 3394Srgrimes/*c0*/ { "xadd", TRUE, BYTE, op2(R, E), 0 }, 3404Srgrimes/*c1*/ { "xadd", TRUE, LONG, op2(R, E), 0 }, 3414Srgrimes/*c2*/ { "", FALSE, NONE, 0, 0 }, 3424Srgrimes/*c3*/ { "", FALSE, NONE, 0, 0 }, 3434Srgrimes/*c4*/ { "", FALSE, NONE, 0, 0 }, 3444Srgrimes/*c5*/ { "", FALSE, NONE, 0, 0 }, 3454Srgrimes/*c6*/ { "", FALSE, NONE, 0, 0 }, 34621277Sbde/*c7*/ { "", TRUE, NONE, op1(E), db_Grp9 }, 34721277Sbde/*c8*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 34821277Sbde/*c9*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 34921277Sbde/*ca*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 35021277Sbde/*cb*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 35121277Sbde/*cc*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 35221277Sbde/*cd*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 35321277Sbde/*ce*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 35421277Sbde/*cf*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 3554Srgrimes}; 3564Srgrimes 35714887Swollmanstatic const struct inst * const db_inst_0f[] = { 3584Srgrimes db_inst_0f0x, 3594Srgrimes 0, 3604Srgrimes db_inst_0f2x, 36114887Swollman db_inst_0f3x, 362181603Sjhb db_inst_0f4x, 3634Srgrimes 0, 3644Srgrimes 0, 3654Srgrimes 0, 3664Srgrimes db_inst_0f8x, 3674Srgrimes db_inst_0f9x, 3684Srgrimes db_inst_0fax, 3694Srgrimes db_inst_0fbx, 3704Srgrimes db_inst_0fcx, 3714Srgrimes 0, 37221277Sbde 0, 3734Srgrimes 0 3744Srgrimes}; 3754Srgrimes 37614887Swollmanstatic const char * const db_Esc92[] = { 3774Srgrimes "fnop", "", "", "", "", "", "", "" 3784Srgrimes}; 37914887Swollmanstatic const char * const db_Esc94[] = { 3804Srgrimes "fchs", "fabs", "", "", "ftst", "fxam", "", "" 3814Srgrimes}; 38217109Sbdestatic const char * const db_Esc95[] = { 3834Srgrimes "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz","" 3844Srgrimes}; 38517109Sbdestatic const char * const db_Esc96[] = { 3864Srgrimes "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp", 3874Srgrimes "fincstp" 3884Srgrimes}; 38914887Swollmanstatic const char * const db_Esc97[] = { 3904Srgrimes "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos" 3914Srgrimes}; 3924Srgrimes 39321277Sbdestatic const char * const db_Esca5[] = { 3944Srgrimes "", "fucompp","", "", "", "", "", "" 3954Srgrimes}; 3964Srgrimes 39717109Sbdestatic const char * const db_Escb4[] = { 39821277Sbde "fneni","fndisi", "fnclex","fninit","fsetpm", "", "", "" 3994Srgrimes}; 4004Srgrimes 40114887Swollmanstatic const char * const db_Esce3[] = { 4024Srgrimes "", "fcompp","", "", "", "", "", "" 4034Srgrimes}; 4044Srgrimes 40517109Sbdestatic const char * const db_Escf4[] = { 4064Srgrimes "fnstsw","", "", "", "", "", "", "" 4074Srgrimes}; 4084Srgrimes 40914887Swollmanstatic const struct finst db_Esc8[] = { 4104Srgrimes/*0*/ { "fadd", SNGL, op2(STI,ST), 0 }, 4114Srgrimes/*1*/ { "fmul", SNGL, op2(STI,ST), 0 }, 4124Srgrimes/*2*/ { "fcom", SNGL, op2(STI,ST), 0 }, 4134Srgrimes/*3*/ { "fcomp", SNGL, op2(STI,ST), 0 }, 4144Srgrimes/*4*/ { "fsub", SNGL, op2(STI,ST), 0 }, 4154Srgrimes/*5*/ { "fsubr", SNGL, op2(STI,ST), 0 }, 4164Srgrimes/*6*/ { "fdiv", SNGL, op2(STI,ST), 0 }, 4174Srgrimes/*7*/ { "fdivr", SNGL, op2(STI,ST), 0 }, 4184Srgrimes}; 4194Srgrimes 42014887Swollmanstatic const struct finst db_Esc9[] = { 4214Srgrimes/*0*/ { "fld", SNGL, op1(STI), 0 }, 4224Srgrimes/*1*/ { "", NONE, op1(STI), "fxch" }, 42317109Sbde/*2*/ { "fst", SNGL, op1(X), db_Esc92 }, 42421277Sbde/*3*/ { "fstp", SNGL, 0, 0 }, 42517109Sbde/*4*/ { "fldenv", NONE, op1(X), db_Esc94 }, 42617109Sbde/*5*/ { "fldcw", NONE, op1(X), db_Esc95 }, 42717109Sbde/*6*/ { "fnstenv",NONE, op1(X), db_Esc96 }, 42817109Sbde/*7*/ { "fnstcw", NONE, op1(X), db_Esc97 }, 4294Srgrimes}; 4304Srgrimes 43114887Swollmanstatic const struct finst db_Esca[] = { 43221277Sbde/*0*/ { "fiadd", LONG, 0, 0 }, 43321277Sbde/*1*/ { "fimul", LONG, 0, 0 }, 43421277Sbde/*2*/ { "ficom", LONG, 0, 0 }, 43521277Sbde/*3*/ { "ficomp", LONG, 0, 0 }, 43621277Sbde/*4*/ { "fisub", LONG, 0, 0 }, 43721277Sbde/*5*/ { "fisubr", LONG, op1(X), db_Esca5 }, 43821277Sbde/*6*/ { "fidiv", LONG, 0, 0 }, 43921277Sbde/*7*/ { "fidivr", LONG, 0, 0 } 4404Srgrimes}; 4414Srgrimes 44214887Swollmanstatic const struct finst db_Escb[] = { 44321277Sbde/*0*/ { "fild", LONG, 0, 0 }, 4444Srgrimes/*1*/ { "", NONE, 0, 0 }, 44521277Sbde/*2*/ { "fist", LONG, 0, 0 }, 44621277Sbde/*3*/ { "fistp", LONG, 0, 0 }, 44717109Sbde/*4*/ { "", WORD, op1(X), db_Escb4 }, 4484Srgrimes/*5*/ { "fld", EXTR, 0, 0 }, 4494Srgrimes/*6*/ { "", WORD, 0, 0 }, 4504Srgrimes/*7*/ { "fstp", EXTR, 0, 0 }, 4514Srgrimes}; 4524Srgrimes 45314887Swollmanstatic const struct finst db_Escc[] = { 4544Srgrimes/*0*/ { "fadd", DBLR, op2(ST,STI), 0 }, 4554Srgrimes/*1*/ { "fmul", DBLR, op2(ST,STI), 0 }, 45621277Sbde/*2*/ { "fcom", DBLR, 0, 0 }, 45721277Sbde/*3*/ { "fcomp", DBLR, 0, 0 }, 4584Srgrimes/*4*/ { "fsub", DBLR, op2(ST,STI), "fsubr" }, 4594Srgrimes/*5*/ { "fsubr", DBLR, op2(ST,STI), "fsub" }, 4604Srgrimes/*6*/ { "fdiv", DBLR, op2(ST,STI), "fdivr" }, 4614Srgrimes/*7*/ { "fdivr", DBLR, op2(ST,STI), "fdiv" }, 4624Srgrimes}; 4634Srgrimes 46414887Swollmanstatic const struct finst db_Escd[] = { 4654Srgrimes/*0*/ { "fld", DBLR, op1(STI), "ffree" }, 4664Srgrimes/*1*/ { "", NONE, 0, 0 }, 4674Srgrimes/*2*/ { "fst", DBLR, op1(STI), 0 }, 4684Srgrimes/*3*/ { "fstp", DBLR, op1(STI), 0 }, 4694Srgrimes/*4*/ { "frstor", NONE, op1(STI), "fucom" }, 4704Srgrimes/*5*/ { "", NONE, op1(STI), "fucomp" }, 4714Srgrimes/*6*/ { "fnsave", NONE, 0, 0 }, 4724Srgrimes/*7*/ { "fnstsw", NONE, 0, 0 }, 4734Srgrimes}; 4744Srgrimes 47514887Swollmanstatic const struct finst db_Esce[] = { 47621277Sbde/*0*/ { "fiadd", WORD, op2(ST,STI), "faddp" }, 47721277Sbde/*1*/ { "fimul", WORD, op2(ST,STI), "fmulp" }, 47821277Sbde/*2*/ { "ficom", WORD, 0, 0 }, 47921277Sbde/*3*/ { "ficomp", WORD, op1(X), db_Esce3 }, 48021277Sbde/*4*/ { "fisub", WORD, op2(ST,STI), "fsubrp" }, 48121277Sbde/*5*/ { "fisubr", WORD, op2(ST,STI), "fsubp" }, 48221277Sbde/*6*/ { "fidiv", WORD, op2(ST,STI), "fdivrp" }, 48321277Sbde/*7*/ { "fidivr", WORD, op2(ST,STI), "fdivp" }, 4844Srgrimes}; 4854Srgrimes 48614887Swollmanstatic const struct finst db_Escf[] = { 48721277Sbde/*0*/ { "fild", WORD, 0, 0 }, 48821277Sbde/*1*/ { "", NONE, 0, 0 }, 48921277Sbde/*2*/ { "fist", WORD, 0, 0 }, 49021277Sbde/*3*/ { "fistp", WORD, 0, 0 }, 49117109Sbde/*4*/ { "fbld", NONE, op1(XA), db_Escf4 }, 49221277Sbde/*5*/ { "fild", QUAD, 0, 0 }, 4934Srgrimes/*6*/ { "fbstp", NONE, 0, 0 }, 49421277Sbde/*7*/ { "fistp", QUAD, 0, 0 }, 4954Srgrimes}; 4964Srgrimes 49717109Sbdestatic const struct finst * const db_Esc_inst[] = { 4984Srgrimes db_Esc8, db_Esc9, db_Esca, db_Escb, 4994Srgrimes db_Escc, db_Escd, db_Esce, db_Escf 5004Srgrimes}; 5014Srgrimes 50214887Swollmanstatic const char * const db_Grp1[] = { 5034Srgrimes "add", 5044Srgrimes "or", 5054Srgrimes "adc", 5064Srgrimes "sbb", 5074Srgrimes "and", 5084Srgrimes "sub", 5094Srgrimes "xor", 5104Srgrimes "cmp" 5114Srgrimes}; 5124Srgrimes 51314887Swollmanstatic const char * const db_Grp2[] = { 5144Srgrimes "rol", 5154Srgrimes "ror", 5164Srgrimes "rcl", 5174Srgrimes "rcr", 5184Srgrimes "shl", 5194Srgrimes "shr", 5204Srgrimes "shl", 5214Srgrimes "sar" 5224Srgrimes}; 5234Srgrimes 52414887Swollmanstatic const struct inst db_Grp3[] = { 5254Srgrimes { "test", TRUE, NONE, op2(I,E), 0 }, 5264Srgrimes { "test", TRUE, NONE, op2(I,E), 0 }, 5274Srgrimes { "not", TRUE, NONE, op1(E), 0 }, 5284Srgrimes { "neg", TRUE, NONE, op1(E), 0 }, 5294Srgrimes { "mul", TRUE, NONE, op2(E,A), 0 }, 5304Srgrimes { "imul", TRUE, NONE, op2(E,A), 0 }, 5314Srgrimes { "div", TRUE, NONE, op2(E,A), 0 }, 5324Srgrimes { "idiv", TRUE, NONE, op2(E,A), 0 }, 5334Srgrimes}; 5344Srgrimes 53517109Sbdestatic const struct inst db_Grp4[] = { 5364Srgrimes { "inc", TRUE, BYTE, op1(E), 0 }, 5374Srgrimes { "dec", TRUE, BYTE, op1(E), 0 }, 5384Srgrimes { "", TRUE, NONE, 0, 0 }, 5394Srgrimes { "", TRUE, NONE, 0, 0 }, 5404Srgrimes { "", TRUE, NONE, 0, 0 }, 5414Srgrimes { "", TRUE, NONE, 0, 0 }, 5424Srgrimes { "", TRUE, NONE, 0, 0 }, 5434Srgrimes { "", TRUE, NONE, 0, 0 } 5444Srgrimes}; 5454Srgrimes 54617109Sbdestatic const struct inst db_Grp5[] = { 5474Srgrimes { "inc", TRUE, LONG, op1(E), 0 }, 5484Srgrimes { "dec", TRUE, LONG, op1(E), 0 }, 54921277Sbde { "call", TRUE, LONG, op1(Eind),0 }, 55021277Sbde { "lcall", TRUE, LONG, op1(Eind),0 }, 55121277Sbde { "jmp", TRUE, LONG, op1(Eind),0 }, 55221277Sbde { "ljmp", TRUE, LONG, op1(Eind),0 }, 5534Srgrimes { "push", TRUE, LONG, op1(E), 0 }, 5544Srgrimes { "", TRUE, NONE, 0, 0 } 5554Srgrimes}; 5564Srgrimes 55714887Swollmanstatic const struct inst db_inst_table[256] = { 5584Srgrimes/*00*/ { "add", TRUE, BYTE, op2(R, E), 0 }, 5594Srgrimes/*01*/ { "add", TRUE, LONG, op2(R, E), 0 }, 5604Srgrimes/*02*/ { "add", TRUE, BYTE, op2(E, R), 0 }, 5614Srgrimes/*03*/ { "add", TRUE, LONG, op2(E, R), 0 }, 56221277Sbde/*04*/ { "add", FALSE, BYTE, op2(I, A), 0 }, 5634Srgrimes/*05*/ { "add", FALSE, LONG, op2(Is, A), 0 }, 5644Srgrimes/*06*/ { "push", FALSE, NONE, op1(Si), 0 }, 5654Srgrimes/*07*/ { "pop", FALSE, NONE, op1(Si), 0 }, 5664Srgrimes 5674Srgrimes/*08*/ { "or", TRUE, BYTE, op2(R, E), 0 }, 5684Srgrimes/*09*/ { "or", TRUE, LONG, op2(R, E), 0 }, 5694Srgrimes/*0a*/ { "or", TRUE, BYTE, op2(E, R), 0 }, 5704Srgrimes/*0b*/ { "or", TRUE, LONG, op2(E, R), 0 }, 5714Srgrimes/*0c*/ { "or", FALSE, BYTE, op2(I, A), 0 }, 5724Srgrimes/*0d*/ { "or", FALSE, LONG, op2(I, A), 0 }, 5734Srgrimes/*0e*/ { "push", FALSE, NONE, op1(Si), 0 }, 5744Srgrimes/*0f*/ { "", FALSE, NONE, 0, 0 }, 5754Srgrimes 5764Srgrimes/*10*/ { "adc", TRUE, BYTE, op2(R, E), 0 }, 5774Srgrimes/*11*/ { "adc", TRUE, LONG, op2(R, E), 0 }, 5784Srgrimes/*12*/ { "adc", TRUE, BYTE, op2(E, R), 0 }, 5794Srgrimes/*13*/ { "adc", TRUE, LONG, op2(E, R), 0 }, 58021277Sbde/*14*/ { "adc", FALSE, BYTE, op2(I, A), 0 }, 5814Srgrimes/*15*/ { "adc", FALSE, LONG, op2(Is, A), 0 }, 5824Srgrimes/*16*/ { "push", FALSE, NONE, op1(Si), 0 }, 5834Srgrimes/*17*/ { "pop", FALSE, NONE, op1(Si), 0 }, 5844Srgrimes 5854Srgrimes/*18*/ { "sbb", TRUE, BYTE, op2(R, E), 0 }, 5864Srgrimes/*19*/ { "sbb", TRUE, LONG, op2(R, E), 0 }, 5874Srgrimes/*1a*/ { "sbb", TRUE, BYTE, op2(E, R), 0 }, 5884Srgrimes/*1b*/ { "sbb", TRUE, LONG, op2(E, R), 0 }, 58921277Sbde/*1c*/ { "sbb", FALSE, BYTE, op2(I, A), 0 }, 5904Srgrimes/*1d*/ { "sbb", FALSE, LONG, op2(Is, A), 0 }, 5914Srgrimes/*1e*/ { "push", FALSE, NONE, op1(Si), 0 }, 5924Srgrimes/*1f*/ { "pop", FALSE, NONE, op1(Si), 0 }, 5934Srgrimes 5944Srgrimes/*20*/ { "and", TRUE, BYTE, op2(R, E), 0 }, 5954Srgrimes/*21*/ { "and", TRUE, LONG, op2(R, E), 0 }, 5964Srgrimes/*22*/ { "and", TRUE, BYTE, op2(E, R), 0 }, 5974Srgrimes/*23*/ { "and", TRUE, LONG, op2(E, R), 0 }, 5984Srgrimes/*24*/ { "and", FALSE, BYTE, op2(I, A), 0 }, 5994Srgrimes/*25*/ { "and", FALSE, LONG, op2(I, A), 0 }, 6004Srgrimes/*26*/ { "", FALSE, NONE, 0, 0 }, 60121277Sbde/*27*/ { "daa", FALSE, NONE, 0, 0 }, 6024Srgrimes 6034Srgrimes/*28*/ { "sub", TRUE, BYTE, op2(R, E), 0 }, 6044Srgrimes/*29*/ { "sub", TRUE, LONG, op2(R, E), 0 }, 6054Srgrimes/*2a*/ { "sub", TRUE, BYTE, op2(E, R), 0 }, 6064Srgrimes/*2b*/ { "sub", TRUE, LONG, op2(E, R), 0 }, 60721277Sbde/*2c*/ { "sub", FALSE, BYTE, op2(I, A), 0 }, 6084Srgrimes/*2d*/ { "sub", FALSE, LONG, op2(Is, A), 0 }, 6094Srgrimes/*2e*/ { "", FALSE, NONE, 0, 0 }, 6104Srgrimes/*2f*/ { "das", FALSE, NONE, 0, 0 }, 6114Srgrimes 6124Srgrimes/*30*/ { "xor", TRUE, BYTE, op2(R, E), 0 }, 6134Srgrimes/*31*/ { "xor", TRUE, LONG, op2(R, E), 0 }, 6144Srgrimes/*32*/ { "xor", TRUE, BYTE, op2(E, R), 0 }, 6154Srgrimes/*33*/ { "xor", TRUE, LONG, op2(E, R), 0 }, 6164Srgrimes/*34*/ { "xor", FALSE, BYTE, op2(I, A), 0 }, 6174Srgrimes/*35*/ { "xor", FALSE, LONG, op2(I, A), 0 }, 6184Srgrimes/*36*/ { "", FALSE, NONE, 0, 0 }, 61921277Sbde/*37*/ { "aaa", FALSE, NONE, 0, 0 }, 6204Srgrimes 6214Srgrimes/*38*/ { "cmp", TRUE, BYTE, op2(R, E), 0 }, 6224Srgrimes/*39*/ { "cmp", TRUE, LONG, op2(R, E), 0 }, 6234Srgrimes/*3a*/ { "cmp", TRUE, BYTE, op2(E, R), 0 }, 6244Srgrimes/*3b*/ { "cmp", TRUE, LONG, op2(E, R), 0 }, 62521277Sbde/*3c*/ { "cmp", FALSE, BYTE, op2(I, A), 0 }, 6264Srgrimes/*3d*/ { "cmp", FALSE, LONG, op2(Is, A), 0 }, 6274Srgrimes/*3e*/ { "", FALSE, NONE, 0, 0 }, 6284Srgrimes/*3f*/ { "aas", FALSE, NONE, 0, 0 }, 6294Srgrimes 6304Srgrimes/*40*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6314Srgrimes/*41*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6324Srgrimes/*42*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6334Srgrimes/*43*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6344Srgrimes/*44*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6354Srgrimes/*45*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6364Srgrimes/*46*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6374Srgrimes/*47*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6384Srgrimes 6394Srgrimes/*48*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6404Srgrimes/*49*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6414Srgrimes/*4a*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6424Srgrimes/*4b*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6434Srgrimes/*4c*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6444Srgrimes/*4d*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6454Srgrimes/*4e*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6464Srgrimes/*4f*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6474Srgrimes 6484Srgrimes/*50*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6494Srgrimes/*51*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6504Srgrimes/*52*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6514Srgrimes/*53*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6524Srgrimes/*54*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6534Srgrimes/*55*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6544Srgrimes/*56*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6554Srgrimes/*57*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6564Srgrimes 6574Srgrimes/*58*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6584Srgrimes/*59*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6594Srgrimes/*5a*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6604Srgrimes/*5b*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6614Srgrimes/*5c*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6624Srgrimes/*5d*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6634Srgrimes/*5e*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6644Srgrimes/*5f*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6654Srgrimes 6664Srgrimes/*60*/ { "pusha", FALSE, LONG, 0, 0 }, 6674Srgrimes/*61*/ { "popa", FALSE, LONG, 0, 0 }, 6684Srgrimes/*62*/ { "bound", TRUE, LONG, op2(E, R), 0 }, 66921277Sbde/*63*/ { "arpl", TRUE, NONE, op2(Rw,Ew), 0 }, 6704Srgrimes 6714Srgrimes/*64*/ { "", FALSE, NONE, 0, 0 }, 6724Srgrimes/*65*/ { "", FALSE, NONE, 0, 0 }, 6734Srgrimes/*66*/ { "", FALSE, NONE, 0, 0 }, 6744Srgrimes/*67*/ { "", FALSE, NONE, 0, 0 }, 6754Srgrimes 6764Srgrimes/*68*/ { "push", FALSE, LONG, op1(I), 0 }, 6774Srgrimes/*69*/ { "imul", TRUE, LONG, op3(I,E,R), 0 }, 67821277Sbde/*6a*/ { "push", FALSE, LONG, op1(Ibs), 0 }, 6794Srgrimes/*6b*/ { "imul", TRUE, LONG, op3(Ibs,E,R),0 }, 6804Srgrimes/*6c*/ { "ins", FALSE, BYTE, op2(DX, DI), 0 }, 6814Srgrimes/*6d*/ { "ins", FALSE, LONG, op2(DX, DI), 0 }, 6824Srgrimes/*6e*/ { "outs", FALSE, BYTE, op2(SI, DX), 0 }, 6834Srgrimes/*6f*/ { "outs", FALSE, LONG, op2(SI, DX), 0 }, 6844Srgrimes 6854Srgrimes/*70*/ { "jo", FALSE, NONE, op1(Db), 0 }, 6864Srgrimes/*71*/ { "jno", FALSE, NONE, op1(Db), 0 }, 6874Srgrimes/*72*/ { "jb", FALSE, NONE, op1(Db), 0 }, 6884Srgrimes/*73*/ { "jnb", FALSE, NONE, op1(Db), 0 }, 6894Srgrimes/*74*/ { "jz", FALSE, NONE, op1(Db), 0 }, 6904Srgrimes/*75*/ { "jnz", FALSE, NONE, op1(Db), 0 }, 6914Srgrimes/*76*/ { "jbe", FALSE, NONE, op1(Db), 0 }, 6924Srgrimes/*77*/ { "jnbe", FALSE, NONE, op1(Db), 0 }, 6934Srgrimes 6944Srgrimes/*78*/ { "js", FALSE, NONE, op1(Db), 0 }, 6954Srgrimes/*79*/ { "jns", FALSE, NONE, op1(Db), 0 }, 6964Srgrimes/*7a*/ { "jp", FALSE, NONE, op1(Db), 0 }, 6974Srgrimes/*7b*/ { "jnp", FALSE, NONE, op1(Db), 0 }, 6984Srgrimes/*7c*/ { "jl", FALSE, NONE, op1(Db), 0 }, 6994Srgrimes/*7d*/ { "jnl", FALSE, NONE, op1(Db), 0 }, 7004Srgrimes/*7e*/ { "jle", FALSE, NONE, op1(Db), 0 }, 7014Srgrimes/*7f*/ { "jnle", FALSE, NONE, op1(Db), 0 }, 7024Srgrimes 70317109Sbde/*80*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 }, 70417109Sbde/*81*/ { "", TRUE, LONG, op2(I, E), db_Grp1 }, 70521277Sbde/*82*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 }, 70617109Sbde/*83*/ { "", TRUE, LONG, op2(Ibs,E), db_Grp1 }, 7074Srgrimes/*84*/ { "test", TRUE, BYTE, op2(R, E), 0 }, 7084Srgrimes/*85*/ { "test", TRUE, LONG, op2(R, E), 0 }, 7094Srgrimes/*86*/ { "xchg", TRUE, BYTE, op2(R, E), 0 }, 7104Srgrimes/*87*/ { "xchg", TRUE, LONG, op2(R, E), 0 }, 7114Srgrimes 7124Srgrimes/*88*/ { "mov", TRUE, BYTE, op2(R, E), 0 }, 7134Srgrimes/*89*/ { "mov", TRUE, LONG, op2(R, E), 0 }, 7144Srgrimes/*8a*/ { "mov", TRUE, BYTE, op2(E, R), 0 }, 7154Srgrimes/*8b*/ { "mov", TRUE, LONG, op2(E, R), 0 }, 7164Srgrimes/*8c*/ { "mov", TRUE, NONE, op2(S, Ew), 0 }, 7174Srgrimes/*8d*/ { "lea", TRUE, LONG, op2(E, R), 0 }, 7184Srgrimes/*8e*/ { "mov", TRUE, NONE, op2(Ew, S), 0 }, 7194Srgrimes/*8f*/ { "pop", TRUE, LONG, op1(E), 0 }, 7204Srgrimes 7214Srgrimes/*90*/ { "nop", FALSE, NONE, 0, 0 }, 7224Srgrimes/*91*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7234Srgrimes/*92*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7244Srgrimes/*93*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7254Srgrimes/*94*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7264Srgrimes/*95*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7274Srgrimes/*96*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7284Srgrimes/*97*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7294Srgrimes 7304Srgrimes/*98*/ { "cbw", FALSE, SDEP, 0, "cwde" }, /* cbw/cwde */ 7314Srgrimes/*99*/ { "cwd", FALSE, SDEP, 0, "cdq" }, /* cwd/cdq */ 7324Srgrimes/*9a*/ { "lcall", FALSE, NONE, op1(OS), 0 }, 7334Srgrimes/*9b*/ { "wait", FALSE, NONE, 0, 0 }, 7344Srgrimes/*9c*/ { "pushf", FALSE, LONG, 0, 0 }, 7354Srgrimes/*9d*/ { "popf", FALSE, LONG, 0, 0 }, 7364Srgrimes/*9e*/ { "sahf", FALSE, NONE, 0, 0 }, 7374Srgrimes/*9f*/ { "lahf", FALSE, NONE, 0, 0 }, 7384Srgrimes 7394Srgrimes/*a0*/ { "mov", FALSE, BYTE, op2(O, A), 0 }, 7404Srgrimes/*a1*/ { "mov", FALSE, LONG, op2(O, A), 0 }, 7414Srgrimes/*a2*/ { "mov", FALSE, BYTE, op2(A, O), 0 }, 7424Srgrimes/*a3*/ { "mov", FALSE, LONG, op2(A, O), 0 }, 7434Srgrimes/*a4*/ { "movs", FALSE, BYTE, op2(SI,DI), 0 }, 7444Srgrimes/*a5*/ { "movs", FALSE, LONG, op2(SI,DI), 0 }, 7454Srgrimes/*a6*/ { "cmps", FALSE, BYTE, op2(SI,DI), 0 }, 7464Srgrimes/*a7*/ { "cmps", FALSE, LONG, op2(SI,DI), 0 }, 7474Srgrimes 7484Srgrimes/*a8*/ { "test", FALSE, BYTE, op2(I, A), 0 }, 7494Srgrimes/*a9*/ { "test", FALSE, LONG, op2(I, A), 0 }, 7504Srgrimes/*aa*/ { "stos", FALSE, BYTE, op1(DI), 0 }, 7514Srgrimes/*ab*/ { "stos", FALSE, LONG, op1(DI), 0 }, 752118Srgrimes/*ac*/ { "lods", FALSE, BYTE, op1(SI), 0 }, 753118Srgrimes/*ad*/ { "lods", FALSE, LONG, op1(SI), 0 }, 7544Srgrimes/*ae*/ { "scas", FALSE, BYTE, op1(SI), 0 }, 7554Srgrimes/*af*/ { "scas", FALSE, LONG, op1(SI), 0 }, 7564Srgrimes 7574Srgrimes/*b0*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7584Srgrimes/*b1*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7594Srgrimes/*b2*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7604Srgrimes/*b3*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7614Srgrimes/*b4*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7624Srgrimes/*b5*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7634Srgrimes/*b6*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7644Srgrimes/*b7*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7654Srgrimes 7664Srgrimes/*b8*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7674Srgrimes/*b9*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7684Srgrimes/*ba*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7694Srgrimes/*bb*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7704Srgrimes/*bc*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7714Srgrimes/*bd*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7724Srgrimes/*be*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7734Srgrimes/*bf*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7744Srgrimes 77517109Sbde/*c0*/ { "", TRUE, BYTE, op2(Ib, E), db_Grp2 }, 77617109Sbde/*c1*/ { "", TRUE, LONG, op2(Ib, E), db_Grp2 }, 7774Srgrimes/*c2*/ { "ret", FALSE, NONE, op1(Iw), 0 }, 7784Srgrimes/*c3*/ { "ret", FALSE, NONE, 0, 0 }, 7794Srgrimes/*c4*/ { "les", TRUE, LONG, op2(E, R), 0 }, 7804Srgrimes/*c5*/ { "lds", TRUE, LONG, op2(E, R), 0 }, 7814Srgrimes/*c6*/ { "mov", TRUE, BYTE, op2(I, E), 0 }, 7824Srgrimes/*c7*/ { "mov", TRUE, LONG, op2(I, E), 0 }, 7834Srgrimes 78421277Sbde/*c8*/ { "enter", FALSE, NONE, op2(Iw, Ib), 0 }, 7854Srgrimes/*c9*/ { "leave", FALSE, NONE, 0, 0 }, 7864Srgrimes/*ca*/ { "lret", FALSE, NONE, op1(Iw), 0 }, 7874Srgrimes/*cb*/ { "lret", FALSE, NONE, 0, 0 }, 7884Srgrimes/*cc*/ { "int", FALSE, NONE, op1(o3), 0 }, 7894Srgrimes/*cd*/ { "int", FALSE, NONE, op1(Ib), 0 }, 7904Srgrimes/*ce*/ { "into", FALSE, NONE, 0, 0 }, 7914Srgrimes/*cf*/ { "iret", FALSE, NONE, 0, 0 }, 7924Srgrimes 79317109Sbde/*d0*/ { "", TRUE, BYTE, op2(o1, E), db_Grp2 }, 79417109Sbde/*d1*/ { "", TRUE, LONG, op2(o1, E), db_Grp2 }, 79517109Sbde/*d2*/ { "", TRUE, BYTE, op2(CL, E), db_Grp2 }, 79617109Sbde/*d3*/ { "", TRUE, LONG, op2(CL, E), db_Grp2 }, 79721277Sbde/*d4*/ { "aam", FALSE, NONE, op1(Iba), 0 }, 79821277Sbde/*d5*/ { "aad", FALSE, NONE, op1(Iba), 0 }, 79921277Sbde/*d6*/ { ".byte\t0xd6", FALSE, NONE, 0, 0 }, 8004Srgrimes/*d7*/ { "xlat", FALSE, BYTE, op1(BX), 0 }, 8014Srgrimes 80217109Sbde/*d8*/ { "", TRUE, NONE, 0, db_Esc8 }, 80317109Sbde/*d9*/ { "", TRUE, NONE, 0, db_Esc9 }, 80417109Sbde/*da*/ { "", TRUE, NONE, 0, db_Esca }, 80517109Sbde/*db*/ { "", TRUE, NONE, 0, db_Escb }, 80617109Sbde/*dc*/ { "", TRUE, NONE, 0, db_Escc }, 80717109Sbde/*dd*/ { "", TRUE, NONE, 0, db_Escd }, 80817109Sbde/*de*/ { "", TRUE, NONE, 0, db_Esce }, 80917109Sbde/*df*/ { "", TRUE, NONE, 0, db_Escf }, 8104Srgrimes 8114Srgrimes/*e0*/ { "loopne",FALSE, NONE, op1(Db), 0 }, 8124Srgrimes/*e1*/ { "loope", FALSE, NONE, op1(Db), 0 }, 8134Srgrimes/*e2*/ { "loop", FALSE, NONE, op1(Db), 0 }, 8144Srgrimes/*e3*/ { "jcxz", FALSE, SDEP, op1(Db), "jecxz" }, 8154Srgrimes/*e4*/ { "in", FALSE, BYTE, op2(Ib, A), 0 }, 8164Srgrimes/*e5*/ { "in", FALSE, LONG, op2(Ib, A) , 0 }, 8174Srgrimes/*e6*/ { "out", FALSE, BYTE, op2(A, Ib), 0 }, 8184Srgrimes/*e7*/ { "out", FALSE, LONG, op2(A, Ib) , 0 }, 8194Srgrimes 8204Srgrimes/*e8*/ { "call", FALSE, NONE, op1(Dl), 0 }, 8214Srgrimes/*e9*/ { "jmp", FALSE, NONE, op1(Dl), 0 }, 8224Srgrimes/*ea*/ { "ljmp", FALSE, NONE, op1(OS), 0 }, 8234Srgrimes/*eb*/ { "jmp", FALSE, NONE, op1(Db), 0 }, 8244Srgrimes/*ec*/ { "in", FALSE, BYTE, op2(DX, A), 0 }, 8254Srgrimes/*ed*/ { "in", FALSE, LONG, op2(DX, A) , 0 }, 8264Srgrimes/*ee*/ { "out", FALSE, BYTE, op2(A, DX), 0 }, 8274Srgrimes/*ef*/ { "out", FALSE, LONG, op2(A, DX) , 0 }, 8284Srgrimes 8294Srgrimes/*f0*/ { "", FALSE, NONE, 0, 0 }, 83021277Sbde/*f1*/ { ".byte\t0xf1", FALSE, NONE, 0, 0 }, 8314Srgrimes/*f2*/ { "", FALSE, NONE, 0, 0 }, 8324Srgrimes/*f3*/ { "", FALSE, NONE, 0, 0 }, 8334Srgrimes/*f4*/ { "hlt", FALSE, NONE, 0, 0 }, 8344Srgrimes/*f5*/ { "cmc", FALSE, NONE, 0, 0 }, 83517109Sbde/*f6*/ { "", TRUE, BYTE, 0, db_Grp3 }, 83617109Sbde/*f7*/ { "", TRUE, LONG, 0, db_Grp3 }, 8374Srgrimes 8384Srgrimes/*f8*/ { "clc", FALSE, NONE, 0, 0 }, 8394Srgrimes/*f9*/ { "stc", FALSE, NONE, 0, 0 }, 8404Srgrimes/*fa*/ { "cli", FALSE, NONE, 0, 0 }, 8414Srgrimes/*fb*/ { "sti", FALSE, NONE, 0, 0 }, 8424Srgrimes/*fc*/ { "cld", FALSE, NONE, 0, 0 }, 8434Srgrimes/*fd*/ { "std", FALSE, NONE, 0, 0 }, 84417109Sbde/*fe*/ { "", TRUE, NONE, 0, db_Grp4 }, 84517109Sbde/*ff*/ { "", TRUE, NONE, 0, db_Grp5 }, 8464Srgrimes}; 8474Srgrimes 84817109Sbdestatic const struct inst db_bad_inst = 8494Srgrimes { "???", FALSE, NONE, 0, 0 } 8504Srgrimes; 8514Srgrimes 8524Srgrimes#define f_mod(byte) ((byte)>>6) 8534Srgrimes#define f_reg(byte) (((byte)>>3)&0x7) 8544Srgrimes#define f_rm(byte) ((byte)&0x7) 8554Srgrimes 8564Srgrimes#define sib_ss(byte) ((byte)>>6) 8574Srgrimes#define sib_index(byte) (((byte)>>3)&0x7) 8584Srgrimes#define sib_base(byte) ((byte)&0x7) 8594Srgrimes 86011940Sbdestruct i_addr { 8614Srgrimes int is_reg; /* if reg, reg number is in 'disp' */ 8624Srgrimes int disp; 86314887Swollman const char * base; 86414887Swollman const char * index; 8654Srgrimes int ss; 8664Srgrimes}; 8674Srgrimes 86814887Swollmanstatic const char * const db_index_reg_16[8] = { 8694Srgrimes "%bx,%si", 8704Srgrimes "%bx,%di", 8714Srgrimes "%bp,%si", 8724Srgrimes "%bp,%di", 8734Srgrimes "%si", 8744Srgrimes "%di", 8754Srgrimes "%bp", 8764Srgrimes "%bx" 8774Srgrimes}; 8784Srgrimes 87914887Swollmanstatic const char * const db_reg[3][8] = { 88043314Sdillon { "%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh" }, 88143314Sdillon { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di" }, 88243314Sdillon { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi" } 8834Srgrimes}; 8844Srgrimes 88517109Sbdestatic const char * const db_seg_reg[8] = { 8864Srgrimes "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", "" 8874Srgrimes}; 8884Srgrimes 8894Srgrimes/* 8904Srgrimes * lengths for size attributes 8914Srgrimes */ 89214887Swollmanstatic const int db_lengths[] = { 8934Srgrimes 1, /* BYTE */ 8944Srgrimes 2, /* WORD */ 8954Srgrimes 4, /* LONG */ 8964Srgrimes 8, /* QUAD */ 8974Srgrimes 4, /* SNGL */ 8984Srgrimes 8, /* DBLR */ 8994Srgrimes 10, /* EXTR */ 9004Srgrimes}; 9014Srgrimes 9024Srgrimes#define get_value_inc(result, loc, size, is_signed) \ 9034Srgrimes result = db_get_value((loc), (size), (is_signed)); \ 9044Srgrimes (loc) += (size); 9054Srgrimes 90611940Sbdestatic db_addr_t 90792770Salfred db_disasm_esc(db_addr_t loc, int inst, int short_addr, 90893017Sbde int size, const char *seg); 90992770Salfredstatic void db_print_address(const char *seg, int size, 91093017Sbde struct i_addr *addrp); 91111940Sbdestatic db_addr_t 91293017Sbde db_read_address(db_addr_t loc, int short_addr, int regmodrm, 91393017Sbde struct i_addr *addrp); 91411940Sbde 9154Srgrimes/* 9164Srgrimes * Read address at location and return updated location. 9174Srgrimes */ 91811921Sphkstatic db_addr_t 9194Srgrimesdb_read_address(loc, short_addr, regmodrm, addrp) 9204Srgrimes db_addr_t loc; 9214Srgrimes int short_addr; 9224Srgrimes int regmodrm; 92317109Sbde struct i_addr * addrp; /* out */ 9244Srgrimes{ 9253436Sphk int mod, rm, sib, index, disp; 9264Srgrimes 9274Srgrimes mod = f_mod(regmodrm); 9284Srgrimes rm = f_rm(regmodrm); 9294Srgrimes 9304Srgrimes if (mod == 3) { 9314Srgrimes addrp->is_reg = TRUE; 9324Srgrimes addrp->disp = rm; 9334Srgrimes return (loc); 9344Srgrimes } 9354Srgrimes addrp->is_reg = FALSE; 9364Srgrimes addrp->index = 0; 9374Srgrimes 9384Srgrimes if (short_addr) { 9394Srgrimes addrp->index = 0; 9404Srgrimes addrp->ss = 0; 9414Srgrimes switch (mod) { 9424Srgrimes case 0: 9434Srgrimes if (rm == 6) { 94421277Sbde get_value_inc(disp, loc, 2, FALSE); 9454Srgrimes addrp->disp = disp; 9464Srgrimes addrp->base = 0; 9474Srgrimes } 9484Srgrimes else { 9494Srgrimes addrp->disp = 0; 9504Srgrimes addrp->base = db_index_reg_16[rm]; 9514Srgrimes } 9524Srgrimes break; 9534Srgrimes case 1: 9544Srgrimes get_value_inc(disp, loc, 1, TRUE); 95521277Sbde disp &= 0xFFFF; 9564Srgrimes addrp->disp = disp; 9574Srgrimes addrp->base = db_index_reg_16[rm]; 9584Srgrimes break; 9594Srgrimes case 2: 96021277Sbde get_value_inc(disp, loc, 2, FALSE); 9614Srgrimes addrp->disp = disp; 9624Srgrimes addrp->base = db_index_reg_16[rm]; 9634Srgrimes break; 9644Srgrimes } 9654Srgrimes } 9664Srgrimes else { 9674Srgrimes if (mod != 3 && rm == 4) { 9684Srgrimes get_value_inc(sib, loc, 1, FALSE); 9694Srgrimes rm = sib_base(sib); 9704Srgrimes index = sib_index(sib); 9714Srgrimes if (index != 4) 9724Srgrimes addrp->index = db_reg[LONG][index]; 9734Srgrimes addrp->ss = sib_ss(sib); 9744Srgrimes } 9754Srgrimes 9764Srgrimes switch (mod) { 9774Srgrimes case 0: 9784Srgrimes if (rm == 5) { 9794Srgrimes get_value_inc(addrp->disp, loc, 4, FALSE); 9804Srgrimes addrp->base = 0; 9814Srgrimes } 9824Srgrimes else { 9834Srgrimes addrp->disp = 0; 9844Srgrimes addrp->base = db_reg[LONG][rm]; 9854Srgrimes } 9864Srgrimes break; 9874Srgrimes 9884Srgrimes case 1: 9894Srgrimes get_value_inc(disp, loc, 1, TRUE); 9904Srgrimes addrp->disp = disp; 9914Srgrimes addrp->base = db_reg[LONG][rm]; 9924Srgrimes break; 9934Srgrimes 9944Srgrimes case 2: 9954Srgrimes get_value_inc(disp, loc, 4, FALSE); 9964Srgrimes addrp->disp = disp; 9974Srgrimes addrp->base = db_reg[LONG][rm]; 9984Srgrimes break; 9994Srgrimes } 10004Srgrimes } 10014Srgrimes return (loc); 10024Srgrimes} 10034Srgrimes 100411921Sphkstatic void 10054Srgrimesdb_print_address(seg, size, addrp) 100617109Sbde const char * seg; 10074Srgrimes int size; 100817109Sbde struct i_addr * addrp; 10094Srgrimes{ 10104Srgrimes if (addrp->is_reg) { 10114Srgrimes db_printf("%s", db_reg[size][addrp->disp]); 10124Srgrimes return; 10134Srgrimes } 10144Srgrimes 10154Srgrimes if (seg) { 10164Srgrimes db_printf("%s:", seg); 10174Srgrimes } 10184Srgrimes 10194Srgrimes db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY); 10204Srgrimes if (addrp->base != 0 || addrp->index != 0) { 10214Srgrimes db_printf("("); 10224Srgrimes if (addrp->base) 10234Srgrimes db_printf("%s", addrp->base); 10244Srgrimes if (addrp->index) 10254Srgrimes db_printf(",%s,%d", addrp->index, 1<<addrp->ss); 10264Srgrimes db_printf(")"); 10274Srgrimes } 10284Srgrimes} 10294Srgrimes 10304Srgrimes/* 10314Srgrimes * Disassemble floating-point ("escape") instruction 10324Srgrimes * and return updated location. 10334Srgrimes */ 103411921Sphkstatic db_addr_t 10354Srgrimesdb_disasm_esc(loc, inst, short_addr, size, seg) 10364Srgrimes db_addr_t loc; 10374Srgrimes int inst; 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); 10494Srgrimes fp = &db_Esc_inst[inst - 0xd8][f_reg(regmodrm)]; 10504Srgrimes mod = f_mod(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 */ 10594Srgrimes loc = db_read_address(loc, short_addr, 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"); 10844Srgrimes db_print_address(seg, BYTE, &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; 10934Srgrimes db_printf("%s\t%%st,%%st(%d)",name,f_rm(regmodrm)); 10944Srgrimes break; 10954Srgrimes case op2(STI,ST): 10964Srgrimes name = (fp->f_rrname) ? fp->f_rrname : fp->f_name; 10974Srgrimes db_printf("%s\t%%st(%d),%%st",name, f_rm(regmodrm)); 10984Srgrimes break; 10994Srgrimes case op1(STI): 11004Srgrimes name = (fp->f_rrname) ? fp->f_rrname : fp->f_name; 11014Srgrimes db_printf("%s\t%%st(%d)",name, f_rm(regmodrm)); 11024Srgrimes break; 11034Srgrimes case op1(X): 110421277Sbde name = ((const char * const *)fp->f_rrname)[f_rm(regmodrm)]; 110521277Sbde if (*name == '\0') 110621277Sbde goto bad; 110721277Sbde db_printf("%s", name); 11084Srgrimes break; 11094Srgrimes case op1(XA): 111021277Sbde name = ((const char * const *)fp->f_rrname)[f_rm(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; 1143798Swollman int regmodrm = 0; 11444Srgrimes boolean_t first; 11454Srgrimes int displ; 11464Srgrimes int prefix; 1147181606Sjhb int rep; 11484Srgrimes int imm; 11494Srgrimes int imm2; 11504Srgrimes int len; 11514Srgrimes struct i_addr address; 11524Srgrimes 11534Srgrimes get_value_inc(inst, loc, 1, FALSE); 11544Srgrimes short_addr = FALSE; 11554Srgrimes size = LONG; 11564Srgrimes seg = 0; 11574Srgrimes 11584Srgrimes /* 11594Srgrimes * Get prefixes 11604Srgrimes */ 1161181606Sjhb rep = FALSE; 11624Srgrimes prefix = TRUE; 11634Srgrimes do { 11644Srgrimes switch (inst) { 11654Srgrimes case 0x66: /* data16 */ 11664Srgrimes size = WORD; 11674Srgrimes break; 11684Srgrimes case 0x67: 11694Srgrimes short_addr = TRUE; 11704Srgrimes break; 11714Srgrimes case 0x26: 11724Srgrimes seg = "%es"; 11734Srgrimes break; 11744Srgrimes case 0x36: 11754Srgrimes seg = "%ss"; 11764Srgrimes break; 11774Srgrimes case 0x2e: 11784Srgrimes seg = "%cs"; 11794Srgrimes break; 11804Srgrimes case 0x3e: 11814Srgrimes seg = "%ds"; 11824Srgrimes break; 11834Srgrimes case 0x64: 11844Srgrimes seg = "%fs"; 11854Srgrimes break; 11864Srgrimes case 0x65: 11874Srgrimes seg = "%gs"; 11884Srgrimes break; 11894Srgrimes case 0xf0: 11904Srgrimes db_printf("lock "); 11914Srgrimes break; 11924Srgrimes case 0xf2: 11934Srgrimes db_printf("repne "); 11944Srgrimes break; 11954Srgrimes case 0xf3: 1196181606Sjhb rep = TRUE; 11974Srgrimes break; 11984Srgrimes default: 11994Srgrimes prefix = FALSE; 12004Srgrimes break; 12014Srgrimes } 12024Srgrimes if (prefix) { 12034Srgrimes get_value_inc(inst, loc, 1, FALSE); 12044Srgrimes } 1205181606Sjhb if (rep == TRUE) { 1206181606Sjhb if (inst == 0x90) { 1207181606Sjhb db_printf("pause\n"); 1208181606Sjhb return (loc); 1209181606Sjhb } 1210181606Sjhb db_printf("repe "); /* XXX repe VS rep */ 1211181606Sjhb rep = FALSE; 1212181606Sjhb } 12134Srgrimes } while (prefix); 12144Srgrimes 12154Srgrimes if (inst >= 0xd8 && inst <= 0xdf) { 12164Srgrimes loc = db_disasm_esc(loc, inst, short_addr, size, seg); 12174Srgrimes db_printf("\n"); 12184Srgrimes return (loc); 12194Srgrimes } 12204Srgrimes 12214Srgrimes if (inst == 0x0f) { 12224Srgrimes get_value_inc(inst, loc, 1, FALSE); 12234Srgrimes ip = db_inst_0f[inst>>4]; 12244Srgrimes if (ip == 0) { 12254Srgrimes ip = &db_bad_inst; 12264Srgrimes } 12274Srgrimes else { 12284Srgrimes ip = &ip[inst&0xf]; 12294Srgrimes } 12304Srgrimes } 12314Srgrimes else 12324Srgrimes ip = &db_inst_table[inst]; 12334Srgrimes 12344Srgrimes if (ip->i_has_modrm) { 12354Srgrimes get_value_inc(regmodrm, loc, 1, FALSE); 12364Srgrimes loc = db_read_address(loc, short_addr, regmodrm, &address); 12374Srgrimes } 12384Srgrimes 12394Srgrimes i_name = ip->i_name; 12404Srgrimes i_size = ip->i_size; 12414Srgrimes i_mode = ip->i_mode; 12424Srgrimes 124317109Sbde if (ip->i_extra == db_Grp1 || ip->i_extra == db_Grp2 || 124417109Sbde ip->i_extra == db_Grp6 || ip->i_extra == db_Grp7 || 1245181606Sjhb ip->i_extra == db_Grp8 || ip->i_extra == db_Grp9 || 1246181606Sjhb ip->i_extra == db_Grp15) { 124717109Sbde i_name = ((const char * const *)ip->i_extra)[f_reg(regmodrm)]; 12484Srgrimes } 124917109Sbde else if (ip->i_extra == db_Grp3) { 125017109Sbde ip = ip->i_extra; 12514Srgrimes ip = &ip[f_reg(regmodrm)]; 12524Srgrimes i_name = ip->i_name; 12534Srgrimes i_mode = ip->i_mode; 12544Srgrimes } 125517109Sbde else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) { 125617109Sbde ip = ip->i_extra; 12574Srgrimes ip = &ip[f_reg(regmodrm)]; 12584Srgrimes i_name = ip->i_name; 12594Srgrimes i_mode = ip->i_mode; 12604Srgrimes i_size = ip->i_size; 12614Srgrimes } 12624Srgrimes 1263181606Sjhb /* Special cases that don't fit well in the tables. */ 1264181606Sjhb if (ip->i_extra == db_Grp7 && f_mod(regmodrm) == 3) { 1265181606Sjhb switch (regmodrm) { 1266181606Sjhb case 0xc8: 1267181606Sjhb i_name = "monitor"; 1268181606Sjhb i_size = NONE; 1269181606Sjhb i_mode = 0; 1270181606Sjhb break; 1271181606Sjhb case 0xc9: 1272181606Sjhb i_name = "mwait"; 1273181606Sjhb i_size = NONE; 1274181606Sjhb i_mode = 0; 1275181606Sjhb break; 1276181606Sjhb } 1277181606Sjhb } 1278181606Sjhb if (ip->i_extra == db_Grp15 && f_mod(regmodrm) == 3) { 1279181606Sjhb i_name = db_Grp15b[f_reg(regmodrm)]; 1280181606Sjhb i_size = NONE; 1281181606Sjhb i_mode = 0; 1282181606Sjhb } 1283181606Sjhb 12844Srgrimes if (i_size == SDEP) { 12854Srgrimes if (size == WORD) 128679885Skris db_printf("%s", i_name); 12874Srgrimes else 128879885Skris db_printf("%s", (const char *)ip->i_extra); 12894Srgrimes } 12904Srgrimes else { 129179885Skris db_printf("%s", i_name); 12924Srgrimes if (i_size != NONE) { 12934Srgrimes if (i_size == BYTE) { 12944Srgrimes db_printf("b"); 12954Srgrimes size = BYTE; 12964Srgrimes } 12974Srgrimes else if (i_size == WORD) { 12984Srgrimes db_printf("w"); 12994Srgrimes size = WORD; 13004Srgrimes } 13014Srgrimes else if (size == WORD) 13024Srgrimes db_printf("w"); 13034Srgrimes else 13044Srgrimes db_printf("l"); 13054Srgrimes } 13064Srgrimes } 13074Srgrimes db_printf("\t"); 13084Srgrimes for (first = TRUE; 13094Srgrimes i_mode != 0; 13104Srgrimes i_mode >>= 8, first = FALSE) 13114Srgrimes { 13124Srgrimes if (!first) 13134Srgrimes db_printf(","); 13144Srgrimes 13154Srgrimes switch (i_mode & 0xFF) { 13164Srgrimes 13174Srgrimes case E: 13184Srgrimes db_print_address(seg, size, &address); 13194Srgrimes break; 13204Srgrimes 13214Srgrimes case Eind: 13224Srgrimes db_printf("*"); 13234Srgrimes db_print_address(seg, size, &address); 13244Srgrimes break; 13254Srgrimes 132621277Sbde case El: 132721277Sbde db_print_address(seg, LONG, &address); 132821277Sbde break; 132921277Sbde 13304Srgrimes case Ew: 13314Srgrimes db_print_address(seg, WORD, &address); 13324Srgrimes break; 13334Srgrimes 13344Srgrimes case Eb: 13354Srgrimes db_print_address(seg, BYTE, &address); 13364Srgrimes break; 13374Srgrimes 13384Srgrimes case R: 13394Srgrimes db_printf("%s", db_reg[size][f_reg(regmodrm)]); 13404Srgrimes break; 13414Srgrimes 13424Srgrimes case Rw: 13434Srgrimes db_printf("%s", db_reg[WORD][f_reg(regmodrm)]); 13444Srgrimes break; 13454Srgrimes 13464Srgrimes case Ri: 13474Srgrimes db_printf("%s", db_reg[size][f_rm(inst)]); 13484Srgrimes break; 13494Srgrimes 135021277Sbde case Ril: 135121277Sbde db_printf("%s", db_reg[LONG][f_rm(inst)]); 135221277Sbde break; 135321277Sbde 13544Srgrimes case S: 13554Srgrimes db_printf("%s", db_seg_reg[f_reg(regmodrm)]); 13564Srgrimes break; 13574Srgrimes 13584Srgrimes case Si: 13594Srgrimes db_printf("%s", db_seg_reg[f_reg(inst)]); 13604Srgrimes break; 13614Srgrimes 13624Srgrimes case A: 13634Srgrimes db_printf("%s", db_reg[size][0]); /* acc */ 13644Srgrimes break; 13654Srgrimes 13664Srgrimes case BX: 13674Srgrimes if (seg) 13684Srgrimes db_printf("%s:", seg); 13694Srgrimes db_printf("(%s)", short_addr ? "%bx" : "%ebx"); 13704Srgrimes break; 13714Srgrimes 13724Srgrimes case CL: 13734Srgrimes db_printf("%%cl"); 13744Srgrimes break; 13754Srgrimes 13764Srgrimes case DX: 13774Srgrimes db_printf("%%dx"); 13784Srgrimes break; 13794Srgrimes 13804Srgrimes case SI: 13814Srgrimes if (seg) 13824Srgrimes db_printf("%s:", seg); 13834Srgrimes db_printf("(%s)", short_addr ? "%si" : "%esi"); 13844Srgrimes break; 13854Srgrimes 13864Srgrimes case DI: 13874Srgrimes db_printf("%%es:(%s)", short_addr ? "%di" : "%edi"); 13884Srgrimes break; 13894Srgrimes 13904Srgrimes case CR: 13914Srgrimes db_printf("%%cr%d", f_reg(regmodrm)); 13924Srgrimes break; 13934Srgrimes 13944Srgrimes case DR: 13954Srgrimes db_printf("%%dr%d", f_reg(regmodrm)); 13964Srgrimes break; 13974Srgrimes 13984Srgrimes case TR: 13994Srgrimes db_printf("%%tr%d", f_reg(regmodrm)); 14004Srgrimes break; 14014Srgrimes 14024Srgrimes case I: 14034Srgrimes len = db_lengths[size]; 140421277Sbde get_value_inc(imm, loc, len, FALSE); 140537506Sbde db_printf("$%#r", imm); 14064Srgrimes break; 14074Srgrimes 14084Srgrimes case Is: 14094Srgrimes len = db_lengths[size]; 141021277Sbde get_value_inc(imm, loc, len, FALSE); 141137506Sbde db_printf("$%+#r", imm); 14124Srgrimes break; 14134Srgrimes 14144Srgrimes case Ib: 141521277Sbde get_value_inc(imm, loc, 1, FALSE); 141637506Sbde db_printf("$%#r", imm); 14174Srgrimes break; 14184Srgrimes 141921277Sbde case Iba: 142021277Sbde get_value_inc(imm, loc, 1, FALSE); 142121277Sbde if (imm != 0x0a) 142237506Sbde db_printf("$%#r", imm); 142321277Sbde break; 142421277Sbde 14254Srgrimes case Ibs: 142621277Sbde get_value_inc(imm, loc, 1, TRUE); 142721277Sbde if (size == WORD) 142821277Sbde imm &= 0xFFFF; 142937506Sbde db_printf("$%+#r", imm); 14304Srgrimes break; 14314Srgrimes 14324Srgrimes case Iw: 143321277Sbde get_value_inc(imm, loc, 2, FALSE); 143437506Sbde db_printf("$%#r", imm); 14354Srgrimes break; 14364Srgrimes 14374Srgrimes case O: 143821277Sbde len = (short_addr ? 2 : 4); 143921277Sbde get_value_inc(displ, loc, len, FALSE); 14404Srgrimes if (seg) 144137506Sbde db_printf("%s:%+#r",seg, displ); 14424Srgrimes else 14434Srgrimes db_printsym((db_addr_t)displ, DB_STGY_ANY); 14444Srgrimes break; 14454Srgrimes 14464Srgrimes case Db: 14474Srgrimes get_value_inc(displ, loc, 1, TRUE); 144821277Sbde displ += loc; 144921277Sbde if (size == WORD) 145021277Sbde displ &= 0xFFFF; 145121277Sbde db_printsym((db_addr_t)displ, DB_STGY_XTRN); 14524Srgrimes break; 14534Srgrimes 14544Srgrimes case Dl: 145521277Sbde len = db_lengths[size]; 145621277Sbde get_value_inc(displ, loc, len, FALSE); 145721277Sbde displ += loc; 145821277Sbde if (size == WORD) 145921277Sbde displ &= 0xFFFF; 146021277Sbde db_printsym((db_addr_t)displ, DB_STGY_XTRN); 14614Srgrimes break; 14624Srgrimes 14634Srgrimes case o1: 14644Srgrimes db_printf("$1"); 14654Srgrimes break; 14664Srgrimes 14674Srgrimes case o3: 14684Srgrimes db_printf("$3"); 14694Srgrimes break; 14704Srgrimes 14714Srgrimes case OS: 147221277Sbde len = db_lengths[size]; 147321277Sbde get_value_inc(imm, loc, len, FALSE); /* offset */ 14744Srgrimes get_value_inc(imm2, loc, 2, FALSE); /* segment */ 147537506Sbde db_printf("$%#r,%#r", imm2, imm); 14764Srgrimes break; 14774Srgrimes } 14784Srgrimes } 14794Srgrimes db_printf("\n"); 14804Srgrimes return (loc); 14814Srgrimes} 1482