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: stable/11/sys/i386/i386/db_disasm.c 308418 2016-11-07 12:10:17Z kib $"); 29115683Sobrien 304Srgrimes/* 314Srgrimes * Instruction disassembler. 324Srgrimes */ 332056Swollman#include <sys/param.h> 34308418Skib#include <sys/kdb.h> 3524494Sbde 362056Swollman#include <ddb/ddb.h> 374Srgrimes#include <ddb/db_access.h> 384Srgrimes#include <ddb/db_sym.h> 394Srgrimes 404Srgrimes/* 414Srgrimes * Size attributes 424Srgrimes */ 434Srgrimes#define BYTE 0 444Srgrimes#define WORD 1 454Srgrimes#define LONG 2 464Srgrimes#define QUAD 3 474Srgrimes#define SNGL 4 484Srgrimes#define DBLR 5 494Srgrimes#define EXTR 6 504Srgrimes#define SDEP 7 514Srgrimes#define NONE 8 524Srgrimes 534Srgrimes/* 544Srgrimes * Addressing modes 554Srgrimes */ 564Srgrimes#define E 1 /* general effective address */ 574Srgrimes#define Eind 2 /* indirect address (jump, call) */ 584Srgrimes#define Ew 3 /* address, word size */ 594Srgrimes#define Eb 4 /* address, byte size */ 604Srgrimes#define R 5 /* register, in 'reg' field */ 614Srgrimes#define Rw 6 /* word register, in 'reg' field */ 624Srgrimes#define Ri 7 /* register in instruction */ 634Srgrimes#define S 8 /* segment reg, in 'reg' field */ 644Srgrimes#define Si 9 /* segment reg, in instruction */ 654Srgrimes#define A 10 /* accumulator */ 664Srgrimes#define BX 11 /* (bx) */ 674Srgrimes#define CL 12 /* cl, for shifts */ 684Srgrimes#define DX 13 /* dx, for IO */ 694Srgrimes#define SI 14 /* si */ 704Srgrimes#define DI 15 /* di */ 714Srgrimes#define CR 16 /* control register */ 724Srgrimes#define DR 17 /* debug register */ 734Srgrimes#define TR 18 /* test register */ 744Srgrimes#define I 19 /* immediate, unsigned */ 754Srgrimes#define Is 20 /* immediate, signed */ 764Srgrimes#define Ib 21 /* byte immediate, unsigned */ 774Srgrimes#define Ibs 22 /* byte immediate, signed */ 784Srgrimes#define Iw 23 /* word immediate, unsigned */ 794Srgrimes#define O 25 /* direct address */ 804Srgrimes#define Db 26 /* byte displacement from EIP */ 814Srgrimes#define Dl 27 /* long displacement from EIP */ 824Srgrimes#define o1 28 /* constant 1 */ 834Srgrimes#define o3 29 /* constant 3 */ 844Srgrimes#define OS 30 /* immediate offset/segment */ 854Srgrimes#define ST 31 /* FP stack top */ 864Srgrimes#define STI 32 /* FP stack */ 874Srgrimes#define X 33 /* extended FP op */ 884Srgrimes#define XA 34 /* for 'fstcw %ax' */ 8921277Sbde#define El 35 /* address, long size */ 9021277Sbde#define Ril 36 /* long register in instruction */ 9121277Sbde#define Iba 37 /* byte immediate, don't print if 0xa */ 924Srgrimes 9311940Sbdestruct inst { 9414887Swollman const char * i_name; /* name */ 954Srgrimes short i_has_modrm; /* has regmodrm byte */ 964Srgrimes short i_size; /* operand size */ 974Srgrimes int i_mode; /* addressing modes */ 9817109Sbde const void * i_extra; /* pointer to extra opcode table */ 994Srgrimes}; 1004Srgrimes 1014Srgrimes#define op1(x) (x) 1024Srgrimes#define op2(x,y) ((x)|((y)<<8)) 1034Srgrimes#define op3(x,y,z) ((x)|((y)<<8)|((z)<<16)) 1044Srgrimes 10511940Sbdestruct finst { 10614887Swollman const char * f_name; /* name for memory instruction */ 1074Srgrimes int f_size; /* size for memory instruction */ 1084Srgrimes int f_rrmode; /* mode for rr instruction */ 10917109Sbde const void * f_rrname; /* name for rr instruction 1104Srgrimes (or pointer to table) */ 1114Srgrimes}; 1124Srgrimes 11314887Swollmanstatic const char * const db_Grp6[] = { 1144Srgrimes "sldt", 1154Srgrimes "str", 1164Srgrimes "lldt", 1174Srgrimes "ltr", 1184Srgrimes "verr", 1194Srgrimes "verw", 1204Srgrimes "", 1214Srgrimes "" 1224Srgrimes}; 1234Srgrimes 12414887Swollmanstatic const char * const db_Grp7[] = { 1254Srgrimes "sgdt", 1264Srgrimes "sidt", 1274Srgrimes "lgdt", 1284Srgrimes "lidt", 1294Srgrimes "smsw", 1304Srgrimes "", 1314Srgrimes "lmsw", 1324Srgrimes "invlpg" 1334Srgrimes}; 1344Srgrimes 13514887Swollmanstatic const char * const db_Grp8[] = { 1364Srgrimes "", 1374Srgrimes "", 1384Srgrimes "", 1394Srgrimes "", 1404Srgrimes "bt", 1414Srgrimes "bts", 1424Srgrimes "btr", 1434Srgrimes "btc" 1444Srgrimes}; 1454Srgrimes 14621277Sbdestatic const char * const db_Grp9[] = { 14721277Sbde "", 14821277Sbde "cmpxchg8b", 14921277Sbde "", 15021277Sbde "", 15121277Sbde "", 15221277Sbde "", 15321277Sbde "", 15421277Sbde "" 15521277Sbde}; 15621277Sbde 157181606Sjhbstatic const char * const db_Grp15[] = { 158181606Sjhb "fxsave", 159181606Sjhb "fxrstor", 160181606Sjhb "ldmxcsr", 161181606Sjhb "stmxcsr", 162181606Sjhb "", 163181606Sjhb "", 164181606Sjhb "", 165181606Sjhb "clflush" 166181606Sjhb}; 167181606Sjhb 168181606Sjhbstatic const char * const db_Grp15b[] = { 169181606Sjhb "", 170181606Sjhb "", 171181606Sjhb "", 172181606Sjhb "", 173181606Sjhb "", 174181606Sjhb "lfence", 175181606Sjhb "mfence", 176181606Sjhb "sfence" 177181606Sjhb}; 178181606Sjhb 17914887Swollmanstatic const struct inst db_inst_0f0x[] = { 18017109Sbde/*00*/ { "", TRUE, NONE, op1(Ew), db_Grp6 }, 18117109Sbde/*01*/ { "", TRUE, NONE, op1(Ew), db_Grp7 }, 1824Srgrimes/*02*/ { "lar", TRUE, LONG, op2(E,R), 0 }, 1834Srgrimes/*03*/ { "lsl", TRUE, LONG, op2(E,R), 0 }, 1844Srgrimes/*04*/ { "", FALSE, NONE, 0, 0 }, 185181606Sjhb/*05*/ { "syscall",FALSE,NONE, 0, 0 }, 1864Srgrimes/*06*/ { "clts", FALSE, NONE, 0, 0 }, 187181606Sjhb/*07*/ { "sysret",FALSE, NONE, 0, 0 }, 1884Srgrimes 1894Srgrimes/*08*/ { "invd", FALSE, NONE, 0, 0 }, 1904Srgrimes/*09*/ { "wbinvd",FALSE, NONE, 0, 0 }, 1914Srgrimes/*0a*/ { "", FALSE, NONE, 0, 0 }, 1924Srgrimes/*0b*/ { "", FALSE, NONE, 0, 0 }, 1934Srgrimes/*0c*/ { "", FALSE, NONE, 0, 0 }, 1944Srgrimes/*0d*/ { "", FALSE, NONE, 0, 0 }, 1954Srgrimes/*0e*/ { "", FALSE, NONE, 0, 0 }, 1964Srgrimes/*0f*/ { "", FALSE, NONE, 0, 0 }, 1974Srgrimes}; 1984Srgrimes 199278655Smarkjstatic const struct inst db_inst_0f1x[] = { 200278655Smarkj/*10*/ { "", FALSE, NONE, 0, 0 }, 201278655Smarkj/*11*/ { "", FALSE, NONE, 0, 0 }, 202278655Smarkj/*12*/ { "", FALSE, NONE, 0, 0 }, 203278655Smarkj/*13*/ { "", FALSE, NONE, 0, 0 }, 204278655Smarkj/*14*/ { "", FALSE, NONE, 0, 0 }, 205278655Smarkj/*15*/ { "", FALSE, NONE, 0, 0 }, 206278655Smarkj/*16*/ { "", FALSE, NONE, 0, 0 }, 207278655Smarkj/*17*/ { "", FALSE, NONE, 0, 0 }, 208278655Smarkj 209278655Smarkj/*18*/ { "", FALSE, NONE, 0, 0 }, 210278655Smarkj/*19*/ { "", FALSE, NONE, 0, 0 }, 211278655Smarkj/*1a*/ { "", FALSE, NONE, 0, 0 }, 212278655Smarkj/*1b*/ { "", FALSE, NONE, 0, 0 }, 213278655Smarkj/*1c*/ { "", FALSE, NONE, 0, 0 }, 214278655Smarkj/*1d*/ { "", FALSE, NONE, 0, 0 }, 215278655Smarkj/*1e*/ { "", FALSE, NONE, 0, 0 }, 216278655Smarkj/*1f*/ { "nopl", TRUE, SDEP, 0, "nopw" }, 217278655Smarkj}; 218278655Smarkj 21917109Sbdestatic const struct inst db_inst_0f2x[] = { 22021277Sbde/*20*/ { "mov", TRUE, LONG, op2(CR,El), 0 }, 22121277Sbde/*21*/ { "mov", TRUE, LONG, op2(DR,El), 0 }, 22221277Sbde/*22*/ { "mov", TRUE, LONG, op2(El,CR), 0 }, 22321277Sbde/*23*/ { "mov", TRUE, LONG, op2(El,DR), 0 }, 22421277Sbde/*24*/ { "mov", TRUE, LONG, op2(TR,El), 0 }, 2254Srgrimes/*25*/ { "", FALSE, NONE, 0, 0 }, 22621277Sbde/*26*/ { "mov", TRUE, LONG, op2(El,TR), 0 }, 2274Srgrimes/*27*/ { "", FALSE, NONE, 0, 0 }, 2284Srgrimes 2294Srgrimes/*28*/ { "", FALSE, NONE, 0, 0 }, 2304Srgrimes/*29*/ { "", FALSE, NONE, 0, 0 }, 2314Srgrimes/*2a*/ { "", FALSE, NONE, 0, 0 }, 2324Srgrimes/*2b*/ { "", FALSE, NONE, 0, 0 }, 2334Srgrimes/*2c*/ { "", FALSE, NONE, 0, 0 }, 2344Srgrimes/*2d*/ { "", FALSE, NONE, 0, 0 }, 2354Srgrimes/*2e*/ { "", FALSE, NONE, 0, 0 }, 2364Srgrimes/*2f*/ { "", FALSE, NONE, 0, 0 }, 2374Srgrimes}; 2384Srgrimes 23914887Swollmanstatic const struct inst db_inst_0f3x[] = { 24014887Swollman/*30*/ { "wrmsr", FALSE, NONE, 0, 0 }, 24114887Swollman/*31*/ { "rdtsc", FALSE, NONE, 0, 0 }, 24214887Swollman/*32*/ { "rdmsr", FALSE, NONE, 0, 0 }, 24314887Swollman/*33*/ { "rdpmc", FALSE, NONE, 0, 0 }, 244181606Sjhb/*34*/ { "sysenter",FALSE,NONE, 0, 0 }, 245181606Sjhb/*35*/ { "sysexit",FALSE,NONE, 0, 0 }, 24614887Swollman/*36*/ { "", FALSE, NONE, 0, 0 }, 247181606Sjhb/*37*/ { "getsec",FALSE, NONE, 0, 0 }, 24814887Swollman 24914887Swollman/*38*/ { "", FALSE, NONE, 0, 0 }, 25014887Swollman/*39*/ { "", FALSE, NONE, 0, 0 }, 25114887Swollman/*3a*/ { "", FALSE, NONE, 0, 0 }, 25214887Swollman/*3b*/ { "", FALSE, NONE, 0, 0 }, 25314887Swollman/*3c*/ { "", FALSE, NONE, 0, 0 }, 25414887Swollman/*3d*/ { "", FALSE, NONE, 0, 0 }, 25514887Swollman/*3e*/ { "", FALSE, NONE, 0, 0 }, 25614887Swollman/*3f*/ { "", FALSE, NONE, 0, 0 }, 25714887Swollman}; 25814887Swollman 259181603Sjhbstatic const struct inst db_inst_0f4x[] = { 260181603Sjhb/*40*/ { "cmovo", TRUE, NONE, op2(E, R), 0 }, 261181603Sjhb/*41*/ { "cmovno", TRUE, NONE, op2(E, R), 0 }, 262181603Sjhb/*42*/ { "cmovb", TRUE, NONE, op2(E, R), 0 }, 263181603Sjhb/*43*/ { "cmovnb", TRUE, NONE, op2(E, R), 0 }, 264181603Sjhb/*44*/ { "cmovz", TRUE, NONE, op2(E, R), 0 }, 265181603Sjhb/*45*/ { "cmovnz", TRUE, NONE, op2(E, R), 0 }, 266181603Sjhb/*46*/ { "cmovbe", TRUE, NONE, op2(E, R), 0 }, 267181603Sjhb/*47*/ { "cmovnbe",TRUE, NONE, op2(E, R), 0 }, 268181603Sjhb 269181603Sjhb/*48*/ { "cmovs", TRUE, NONE, op2(E, R), 0 }, 270181603Sjhb/*49*/ { "cmovns", TRUE, NONE, op2(E, R), 0 }, 271181603Sjhb/*4a*/ { "cmovp", TRUE, NONE, op2(E, R), 0 }, 272181603Sjhb/*4b*/ { "cmovnp", TRUE, NONE, op2(E, R), 0 }, 273181603Sjhb/*4c*/ { "cmovl", TRUE, NONE, op2(E, R), 0 }, 274181603Sjhb/*4d*/ { "cmovnl", TRUE, NONE, op2(E, R), 0 }, 275181603Sjhb/*4e*/ { "cmovle", TRUE, NONE, op2(E, R), 0 }, 276181603Sjhb/*4f*/ { "cmovnle",TRUE, NONE, op2(E, R), 0 }, 277181603Sjhb}; 278181603Sjhb 27917109Sbdestatic const struct inst db_inst_0f8x[] = { 2804Srgrimes/*80*/ { "jo", FALSE, NONE, op1(Dl), 0 }, 2814Srgrimes/*81*/ { "jno", FALSE, NONE, op1(Dl), 0 }, 2824Srgrimes/*82*/ { "jb", FALSE, NONE, op1(Dl), 0 }, 2834Srgrimes/*83*/ { "jnb", FALSE, NONE, op1(Dl), 0 }, 2844Srgrimes/*84*/ { "jz", FALSE, NONE, op1(Dl), 0 }, 2854Srgrimes/*85*/ { "jnz", FALSE, NONE, op1(Dl), 0 }, 2864Srgrimes/*86*/ { "jbe", FALSE, NONE, op1(Dl), 0 }, 2874Srgrimes/*87*/ { "jnbe", FALSE, NONE, op1(Dl), 0 }, 2884Srgrimes 2894Srgrimes/*88*/ { "js", FALSE, NONE, op1(Dl), 0 }, 2904Srgrimes/*89*/ { "jns", FALSE, NONE, op1(Dl), 0 }, 2914Srgrimes/*8a*/ { "jp", FALSE, NONE, op1(Dl), 0 }, 2924Srgrimes/*8b*/ { "jnp", FALSE, NONE, op1(Dl), 0 }, 2934Srgrimes/*8c*/ { "jl", FALSE, NONE, op1(Dl), 0 }, 2944Srgrimes/*8d*/ { "jnl", FALSE, NONE, op1(Dl), 0 }, 2954Srgrimes/*8e*/ { "jle", FALSE, NONE, op1(Dl), 0 }, 2964Srgrimes/*8f*/ { "jnle", FALSE, NONE, op1(Dl), 0 }, 2974Srgrimes}; 2984Srgrimes 29917109Sbdestatic const struct inst db_inst_0f9x[] = { 3004Srgrimes/*90*/ { "seto", TRUE, NONE, op1(Eb), 0 }, 3014Srgrimes/*91*/ { "setno", TRUE, NONE, op1(Eb), 0 }, 3024Srgrimes/*92*/ { "setb", TRUE, NONE, op1(Eb), 0 }, 3034Srgrimes/*93*/ { "setnb", TRUE, NONE, op1(Eb), 0 }, 3044Srgrimes/*94*/ { "setz", TRUE, NONE, op1(Eb), 0 }, 3054Srgrimes/*95*/ { "setnz", TRUE, NONE, op1(Eb), 0 }, 3064Srgrimes/*96*/ { "setbe", TRUE, NONE, op1(Eb), 0 }, 3074Srgrimes/*97*/ { "setnbe",TRUE, NONE, op1(Eb), 0 }, 3084Srgrimes 3094Srgrimes/*98*/ { "sets", TRUE, NONE, op1(Eb), 0 }, 3104Srgrimes/*99*/ { "setns", TRUE, NONE, op1(Eb), 0 }, 3114Srgrimes/*9a*/ { "setp", TRUE, NONE, op1(Eb), 0 }, 3124Srgrimes/*9b*/ { "setnp", TRUE, NONE, op1(Eb), 0 }, 3134Srgrimes/*9c*/ { "setl", TRUE, NONE, op1(Eb), 0 }, 3144Srgrimes/*9d*/ { "setnl", TRUE, NONE, op1(Eb), 0 }, 3154Srgrimes/*9e*/ { "setle", TRUE, NONE, op1(Eb), 0 }, 3164Srgrimes/*9f*/ { "setnle",TRUE, NONE, op1(Eb), 0 }, 3174Srgrimes}; 3184Srgrimes 31917109Sbdestatic const struct inst db_inst_0fax[] = { 3204Srgrimes/*a0*/ { "push", FALSE, NONE, op1(Si), 0 }, 3214Srgrimes/*a1*/ { "pop", FALSE, NONE, op1(Si), 0 }, 32221277Sbde/*a2*/ { "cpuid", FALSE, NONE, 0, 0 }, 32321277Sbde/*a3*/ { "bt", TRUE, LONG, op2(R,E), 0 }, 32417109Sbde/*a4*/ { "shld", TRUE, LONG, op3(Ib,R,E), 0 }, 32517109Sbde/*a5*/ { "shld", TRUE, LONG, op3(CL,R,E), 0 }, 3264Srgrimes/*a6*/ { "", FALSE, NONE, 0, 0 }, 3274Srgrimes/*a7*/ { "", FALSE, NONE, 0, 0 }, 3284Srgrimes 3294Srgrimes/*a8*/ { "push", FALSE, NONE, op1(Si), 0 }, 3304Srgrimes/*a9*/ { "pop", FALSE, NONE, op1(Si), 0 }, 33121277Sbde/*aa*/ { "rsm", FALSE, NONE, 0, 0 }, 33221277Sbde/*ab*/ { "bts", TRUE, LONG, op2(R,E), 0 }, 33317109Sbde/*ac*/ { "shrd", TRUE, LONG, op3(Ib,R,E), 0 }, 33417109Sbde/*ad*/ { "shrd", TRUE, LONG, op3(CL,R,E), 0 }, 335181606Sjhb/*ae*/ { "", TRUE, LONG, op1(E), db_Grp15 }, 336181606Sjhb/*af*/ { "imul", TRUE, LONG, op2(E,R), 0 }, 3374Srgrimes}; 3384Srgrimes 33917109Sbdestatic const struct inst db_inst_0fbx[] = { 34021277Sbde/*b0*/ { "cmpxchg",TRUE, BYTE, op2(R, E), 0 }, 34121277Sbde/*b0*/ { "cmpxchg",TRUE, LONG, op2(R, E), 0 }, 3424Srgrimes/*b2*/ { "lss", TRUE, LONG, op2(E, R), 0 }, 34321277Sbde/*b3*/ { "btr", TRUE, LONG, op2(R, E), 0 }, 3444Srgrimes/*b4*/ { "lfs", TRUE, LONG, op2(E, R), 0 }, 3454Srgrimes/*b5*/ { "lgs", TRUE, LONG, op2(E, R), 0 }, 34621277Sbde/*b6*/ { "movzb", TRUE, LONG, op2(Eb, R), 0 }, 34721277Sbde/*b7*/ { "movzw", TRUE, LONG, op2(Ew, R), 0 }, 3484Srgrimes 3494Srgrimes/*b8*/ { "", FALSE, NONE, 0, 0 }, 3504Srgrimes/*b9*/ { "", FALSE, NONE, 0, 0 }, 35117109Sbde/*ba*/ { "", TRUE, LONG, op2(Ib, E), db_Grp8 }, 3524Srgrimes/*bb*/ { "btc", TRUE, LONG, op2(R, E), 0 }, 3534Srgrimes/*bc*/ { "bsf", TRUE, LONG, op2(E, R), 0 }, 3544Srgrimes/*bd*/ { "bsr", TRUE, LONG, op2(E, R), 0 }, 35521277Sbde/*be*/ { "movsb", TRUE, LONG, op2(Eb, R), 0 }, 35621277Sbde/*bf*/ { "movsw", TRUE, LONG, op2(Ew, R), 0 }, 3574Srgrimes}; 3584Srgrimes 35917109Sbdestatic const struct inst db_inst_0fcx[] = { 3604Srgrimes/*c0*/ { "xadd", TRUE, BYTE, op2(R, E), 0 }, 3614Srgrimes/*c1*/ { "xadd", TRUE, LONG, op2(R, E), 0 }, 3624Srgrimes/*c2*/ { "", FALSE, NONE, 0, 0 }, 3634Srgrimes/*c3*/ { "", FALSE, NONE, 0, 0 }, 3644Srgrimes/*c4*/ { "", FALSE, NONE, 0, 0 }, 3654Srgrimes/*c5*/ { "", FALSE, NONE, 0, 0 }, 3664Srgrimes/*c6*/ { "", FALSE, NONE, 0, 0 }, 36721277Sbde/*c7*/ { "", TRUE, NONE, op1(E), db_Grp9 }, 36821277Sbde/*c8*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 36921277Sbde/*c9*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 37021277Sbde/*ca*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 37121277Sbde/*cb*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 37221277Sbde/*cc*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 37321277Sbde/*cd*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 37421277Sbde/*ce*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 37521277Sbde/*cf*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 3764Srgrimes}; 3774Srgrimes 37814887Swollmanstatic const struct inst * const db_inst_0f[] = { 3794Srgrimes db_inst_0f0x, 380278655Smarkj db_inst_0f1x, 3814Srgrimes db_inst_0f2x, 38214887Swollman db_inst_0f3x, 383181603Sjhb db_inst_0f4x, 3844Srgrimes 0, 3854Srgrimes 0, 3864Srgrimes 0, 3874Srgrimes db_inst_0f8x, 3884Srgrimes db_inst_0f9x, 3894Srgrimes db_inst_0fax, 3904Srgrimes db_inst_0fbx, 3914Srgrimes db_inst_0fcx, 3924Srgrimes 0, 39321277Sbde 0, 3944Srgrimes 0 3954Srgrimes}; 3964Srgrimes 39714887Swollmanstatic const char * const db_Esc92[] = { 3984Srgrimes "fnop", "", "", "", "", "", "", "" 3994Srgrimes}; 40014887Swollmanstatic const char * const db_Esc94[] = { 4014Srgrimes "fchs", "fabs", "", "", "ftst", "fxam", "", "" 4024Srgrimes}; 40317109Sbdestatic const char * const db_Esc95[] = { 4044Srgrimes "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz","" 4054Srgrimes}; 40617109Sbdestatic const char * const db_Esc96[] = { 4074Srgrimes "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp", 4084Srgrimes "fincstp" 4094Srgrimes}; 41014887Swollmanstatic const char * const db_Esc97[] = { 4114Srgrimes "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos" 4124Srgrimes}; 4134Srgrimes 41421277Sbdestatic const char * const db_Esca5[] = { 4154Srgrimes "", "fucompp","", "", "", "", "", "" 4164Srgrimes}; 4174Srgrimes 41817109Sbdestatic const char * const db_Escb4[] = { 41921277Sbde "fneni","fndisi", "fnclex","fninit","fsetpm", "", "", "" 4204Srgrimes}; 4214Srgrimes 42214887Swollmanstatic const char * const db_Esce3[] = { 4234Srgrimes "", "fcompp","", "", "", "", "", "" 4244Srgrimes}; 4254Srgrimes 42617109Sbdestatic const char * const db_Escf4[] = { 4274Srgrimes "fnstsw","", "", "", "", "", "", "" 4284Srgrimes}; 4294Srgrimes 43014887Swollmanstatic const struct finst db_Esc8[] = { 4314Srgrimes/*0*/ { "fadd", SNGL, op2(STI,ST), 0 }, 4324Srgrimes/*1*/ { "fmul", SNGL, op2(STI,ST), 0 }, 4334Srgrimes/*2*/ { "fcom", SNGL, op2(STI,ST), 0 }, 4344Srgrimes/*3*/ { "fcomp", SNGL, op2(STI,ST), 0 }, 4354Srgrimes/*4*/ { "fsub", SNGL, op2(STI,ST), 0 }, 4364Srgrimes/*5*/ { "fsubr", SNGL, op2(STI,ST), 0 }, 4374Srgrimes/*6*/ { "fdiv", SNGL, op2(STI,ST), 0 }, 4384Srgrimes/*7*/ { "fdivr", SNGL, op2(STI,ST), 0 }, 4394Srgrimes}; 4404Srgrimes 44114887Swollmanstatic const struct finst db_Esc9[] = { 4424Srgrimes/*0*/ { "fld", SNGL, op1(STI), 0 }, 4434Srgrimes/*1*/ { "", NONE, op1(STI), "fxch" }, 44417109Sbde/*2*/ { "fst", SNGL, op1(X), db_Esc92 }, 44521277Sbde/*3*/ { "fstp", SNGL, 0, 0 }, 44617109Sbde/*4*/ { "fldenv", NONE, op1(X), db_Esc94 }, 44717109Sbde/*5*/ { "fldcw", NONE, op1(X), db_Esc95 }, 44817109Sbde/*6*/ { "fnstenv",NONE, op1(X), db_Esc96 }, 44917109Sbde/*7*/ { "fnstcw", NONE, op1(X), db_Esc97 }, 4504Srgrimes}; 4514Srgrimes 45214887Swollmanstatic const struct finst db_Esca[] = { 45321277Sbde/*0*/ { "fiadd", LONG, 0, 0 }, 45421277Sbde/*1*/ { "fimul", LONG, 0, 0 }, 45521277Sbde/*2*/ { "ficom", LONG, 0, 0 }, 45621277Sbde/*3*/ { "ficomp", LONG, 0, 0 }, 45721277Sbde/*4*/ { "fisub", LONG, 0, 0 }, 45821277Sbde/*5*/ { "fisubr", LONG, op1(X), db_Esca5 }, 45921277Sbde/*6*/ { "fidiv", LONG, 0, 0 }, 46021277Sbde/*7*/ { "fidivr", LONG, 0, 0 } 4614Srgrimes}; 4624Srgrimes 46314887Swollmanstatic const struct finst db_Escb[] = { 46421277Sbde/*0*/ { "fild", LONG, 0, 0 }, 4654Srgrimes/*1*/ { "", NONE, 0, 0 }, 46621277Sbde/*2*/ { "fist", LONG, 0, 0 }, 46721277Sbde/*3*/ { "fistp", LONG, 0, 0 }, 46817109Sbde/*4*/ { "", WORD, op1(X), db_Escb4 }, 4694Srgrimes/*5*/ { "fld", EXTR, 0, 0 }, 4704Srgrimes/*6*/ { "", WORD, 0, 0 }, 4714Srgrimes/*7*/ { "fstp", EXTR, 0, 0 }, 4724Srgrimes}; 4734Srgrimes 47414887Swollmanstatic const struct finst db_Escc[] = { 4754Srgrimes/*0*/ { "fadd", DBLR, op2(ST,STI), 0 }, 4764Srgrimes/*1*/ { "fmul", DBLR, op2(ST,STI), 0 }, 47721277Sbde/*2*/ { "fcom", DBLR, 0, 0 }, 47821277Sbde/*3*/ { "fcomp", DBLR, 0, 0 }, 4794Srgrimes/*4*/ { "fsub", DBLR, op2(ST,STI), "fsubr" }, 4804Srgrimes/*5*/ { "fsubr", DBLR, op2(ST,STI), "fsub" }, 4814Srgrimes/*6*/ { "fdiv", DBLR, op2(ST,STI), "fdivr" }, 4824Srgrimes/*7*/ { "fdivr", DBLR, op2(ST,STI), "fdiv" }, 4834Srgrimes}; 4844Srgrimes 48514887Swollmanstatic const struct finst db_Escd[] = { 4864Srgrimes/*0*/ { "fld", DBLR, op1(STI), "ffree" }, 4874Srgrimes/*1*/ { "", NONE, 0, 0 }, 4884Srgrimes/*2*/ { "fst", DBLR, op1(STI), 0 }, 4894Srgrimes/*3*/ { "fstp", DBLR, op1(STI), 0 }, 4904Srgrimes/*4*/ { "frstor", NONE, op1(STI), "fucom" }, 4914Srgrimes/*5*/ { "", NONE, op1(STI), "fucomp" }, 4924Srgrimes/*6*/ { "fnsave", NONE, 0, 0 }, 4934Srgrimes/*7*/ { "fnstsw", NONE, 0, 0 }, 4944Srgrimes}; 4954Srgrimes 49614887Swollmanstatic const struct finst db_Esce[] = { 49721277Sbde/*0*/ { "fiadd", WORD, op2(ST,STI), "faddp" }, 49821277Sbde/*1*/ { "fimul", WORD, op2(ST,STI), "fmulp" }, 49921277Sbde/*2*/ { "ficom", WORD, 0, 0 }, 50021277Sbde/*3*/ { "ficomp", WORD, op1(X), db_Esce3 }, 50121277Sbde/*4*/ { "fisub", WORD, op2(ST,STI), "fsubrp" }, 50221277Sbde/*5*/ { "fisubr", WORD, op2(ST,STI), "fsubp" }, 50321277Sbde/*6*/ { "fidiv", WORD, op2(ST,STI), "fdivrp" }, 50421277Sbde/*7*/ { "fidivr", WORD, op2(ST,STI), "fdivp" }, 5054Srgrimes}; 5064Srgrimes 50714887Swollmanstatic const struct finst db_Escf[] = { 50821277Sbde/*0*/ { "fild", WORD, 0, 0 }, 50921277Sbde/*1*/ { "", NONE, 0, 0 }, 51021277Sbde/*2*/ { "fist", WORD, 0, 0 }, 51121277Sbde/*3*/ { "fistp", WORD, 0, 0 }, 51217109Sbde/*4*/ { "fbld", NONE, op1(XA), db_Escf4 }, 51321277Sbde/*5*/ { "fild", QUAD, 0, 0 }, 5144Srgrimes/*6*/ { "fbstp", NONE, 0, 0 }, 51521277Sbde/*7*/ { "fistp", QUAD, 0, 0 }, 5164Srgrimes}; 5174Srgrimes 51817109Sbdestatic const struct finst * const db_Esc_inst[] = { 5194Srgrimes db_Esc8, db_Esc9, db_Esca, db_Escb, 5204Srgrimes db_Escc, db_Escd, db_Esce, db_Escf 5214Srgrimes}; 5224Srgrimes 52314887Swollmanstatic const char * const db_Grp1[] = { 5244Srgrimes "add", 5254Srgrimes "or", 5264Srgrimes "adc", 5274Srgrimes "sbb", 5284Srgrimes "and", 5294Srgrimes "sub", 5304Srgrimes "xor", 5314Srgrimes "cmp" 5324Srgrimes}; 5334Srgrimes 53414887Swollmanstatic const char * const db_Grp2[] = { 5354Srgrimes "rol", 5364Srgrimes "ror", 5374Srgrimes "rcl", 5384Srgrimes "rcr", 5394Srgrimes "shl", 5404Srgrimes "shr", 5414Srgrimes "shl", 5424Srgrimes "sar" 5434Srgrimes}; 5444Srgrimes 54514887Swollmanstatic const struct inst db_Grp3[] = { 5464Srgrimes { "test", TRUE, NONE, op2(I,E), 0 }, 5474Srgrimes { "test", TRUE, NONE, op2(I,E), 0 }, 5484Srgrimes { "not", TRUE, NONE, op1(E), 0 }, 5494Srgrimes { "neg", TRUE, NONE, op1(E), 0 }, 5504Srgrimes { "mul", TRUE, NONE, op2(E,A), 0 }, 5514Srgrimes { "imul", TRUE, NONE, op2(E,A), 0 }, 5524Srgrimes { "div", TRUE, NONE, op2(E,A), 0 }, 5534Srgrimes { "idiv", TRUE, NONE, op2(E,A), 0 }, 5544Srgrimes}; 5554Srgrimes 55617109Sbdestatic const struct inst db_Grp4[] = { 5574Srgrimes { "inc", TRUE, BYTE, op1(E), 0 }, 5584Srgrimes { "dec", TRUE, BYTE, op1(E), 0 }, 5594Srgrimes { "", TRUE, NONE, 0, 0 }, 5604Srgrimes { "", TRUE, NONE, 0, 0 }, 5614Srgrimes { "", TRUE, NONE, 0, 0 }, 5624Srgrimes { "", TRUE, NONE, 0, 0 }, 5634Srgrimes { "", TRUE, NONE, 0, 0 }, 5644Srgrimes { "", TRUE, NONE, 0, 0 } 5654Srgrimes}; 5664Srgrimes 56717109Sbdestatic const struct inst db_Grp5[] = { 5684Srgrimes { "inc", TRUE, LONG, op1(E), 0 }, 5694Srgrimes { "dec", TRUE, LONG, op1(E), 0 }, 57021277Sbde { "call", TRUE, LONG, op1(Eind),0 }, 57121277Sbde { "lcall", TRUE, LONG, op1(Eind),0 }, 57221277Sbde { "jmp", TRUE, LONG, op1(Eind),0 }, 57321277Sbde { "ljmp", TRUE, LONG, op1(Eind),0 }, 5744Srgrimes { "push", TRUE, LONG, op1(E), 0 }, 5754Srgrimes { "", TRUE, NONE, 0, 0 } 5764Srgrimes}; 5774Srgrimes 57814887Swollmanstatic const struct inst db_inst_table[256] = { 5794Srgrimes/*00*/ { "add", TRUE, BYTE, op2(R, E), 0 }, 5804Srgrimes/*01*/ { "add", TRUE, LONG, op2(R, E), 0 }, 5814Srgrimes/*02*/ { "add", TRUE, BYTE, op2(E, R), 0 }, 5824Srgrimes/*03*/ { "add", TRUE, LONG, op2(E, R), 0 }, 58321277Sbde/*04*/ { "add", FALSE, BYTE, op2(I, A), 0 }, 5844Srgrimes/*05*/ { "add", FALSE, LONG, op2(Is, A), 0 }, 5854Srgrimes/*06*/ { "push", FALSE, NONE, op1(Si), 0 }, 5864Srgrimes/*07*/ { "pop", FALSE, NONE, op1(Si), 0 }, 5874Srgrimes 5884Srgrimes/*08*/ { "or", TRUE, BYTE, op2(R, E), 0 }, 5894Srgrimes/*09*/ { "or", TRUE, LONG, op2(R, E), 0 }, 5904Srgrimes/*0a*/ { "or", TRUE, BYTE, op2(E, R), 0 }, 5914Srgrimes/*0b*/ { "or", TRUE, LONG, op2(E, R), 0 }, 5924Srgrimes/*0c*/ { "or", FALSE, BYTE, op2(I, A), 0 }, 5934Srgrimes/*0d*/ { "or", FALSE, LONG, op2(I, A), 0 }, 5944Srgrimes/*0e*/ { "push", FALSE, NONE, op1(Si), 0 }, 5954Srgrimes/*0f*/ { "", FALSE, NONE, 0, 0 }, 5964Srgrimes 5974Srgrimes/*10*/ { "adc", TRUE, BYTE, op2(R, E), 0 }, 5984Srgrimes/*11*/ { "adc", TRUE, LONG, op2(R, E), 0 }, 5994Srgrimes/*12*/ { "adc", TRUE, BYTE, op2(E, R), 0 }, 6004Srgrimes/*13*/ { "adc", TRUE, LONG, op2(E, R), 0 }, 60121277Sbde/*14*/ { "adc", FALSE, BYTE, op2(I, A), 0 }, 6024Srgrimes/*15*/ { "adc", FALSE, LONG, op2(Is, A), 0 }, 6034Srgrimes/*16*/ { "push", FALSE, NONE, op1(Si), 0 }, 6044Srgrimes/*17*/ { "pop", FALSE, NONE, op1(Si), 0 }, 6054Srgrimes 6064Srgrimes/*18*/ { "sbb", TRUE, BYTE, op2(R, E), 0 }, 6074Srgrimes/*19*/ { "sbb", TRUE, LONG, op2(R, E), 0 }, 6084Srgrimes/*1a*/ { "sbb", TRUE, BYTE, op2(E, R), 0 }, 6094Srgrimes/*1b*/ { "sbb", TRUE, LONG, op2(E, R), 0 }, 61021277Sbde/*1c*/ { "sbb", FALSE, BYTE, op2(I, A), 0 }, 6114Srgrimes/*1d*/ { "sbb", FALSE, LONG, op2(Is, A), 0 }, 6124Srgrimes/*1e*/ { "push", FALSE, NONE, op1(Si), 0 }, 6134Srgrimes/*1f*/ { "pop", FALSE, NONE, op1(Si), 0 }, 6144Srgrimes 6154Srgrimes/*20*/ { "and", TRUE, BYTE, op2(R, E), 0 }, 6164Srgrimes/*21*/ { "and", TRUE, LONG, op2(R, E), 0 }, 6174Srgrimes/*22*/ { "and", TRUE, BYTE, op2(E, R), 0 }, 6184Srgrimes/*23*/ { "and", TRUE, LONG, op2(E, R), 0 }, 6194Srgrimes/*24*/ { "and", FALSE, BYTE, op2(I, A), 0 }, 6204Srgrimes/*25*/ { "and", FALSE, LONG, op2(I, A), 0 }, 6214Srgrimes/*26*/ { "", FALSE, NONE, 0, 0 }, 62221277Sbde/*27*/ { "daa", FALSE, NONE, 0, 0 }, 6234Srgrimes 6244Srgrimes/*28*/ { "sub", TRUE, BYTE, op2(R, E), 0 }, 6254Srgrimes/*29*/ { "sub", TRUE, LONG, op2(R, E), 0 }, 6264Srgrimes/*2a*/ { "sub", TRUE, BYTE, op2(E, R), 0 }, 6274Srgrimes/*2b*/ { "sub", TRUE, LONG, op2(E, R), 0 }, 62821277Sbde/*2c*/ { "sub", FALSE, BYTE, op2(I, A), 0 }, 6294Srgrimes/*2d*/ { "sub", FALSE, LONG, op2(Is, A), 0 }, 6304Srgrimes/*2e*/ { "", FALSE, NONE, 0, 0 }, 6314Srgrimes/*2f*/ { "das", FALSE, NONE, 0, 0 }, 6324Srgrimes 6334Srgrimes/*30*/ { "xor", TRUE, BYTE, op2(R, E), 0 }, 6344Srgrimes/*31*/ { "xor", TRUE, LONG, op2(R, E), 0 }, 6354Srgrimes/*32*/ { "xor", TRUE, BYTE, op2(E, R), 0 }, 6364Srgrimes/*33*/ { "xor", TRUE, LONG, op2(E, R), 0 }, 6374Srgrimes/*34*/ { "xor", FALSE, BYTE, op2(I, A), 0 }, 6384Srgrimes/*35*/ { "xor", FALSE, LONG, op2(I, A), 0 }, 6394Srgrimes/*36*/ { "", FALSE, NONE, 0, 0 }, 64021277Sbde/*37*/ { "aaa", FALSE, NONE, 0, 0 }, 6414Srgrimes 6424Srgrimes/*38*/ { "cmp", TRUE, BYTE, op2(R, E), 0 }, 6434Srgrimes/*39*/ { "cmp", TRUE, LONG, op2(R, E), 0 }, 6444Srgrimes/*3a*/ { "cmp", TRUE, BYTE, op2(E, R), 0 }, 6454Srgrimes/*3b*/ { "cmp", TRUE, LONG, op2(E, R), 0 }, 64621277Sbde/*3c*/ { "cmp", FALSE, BYTE, op2(I, A), 0 }, 6474Srgrimes/*3d*/ { "cmp", FALSE, LONG, op2(Is, A), 0 }, 6484Srgrimes/*3e*/ { "", FALSE, NONE, 0, 0 }, 6494Srgrimes/*3f*/ { "aas", FALSE, NONE, 0, 0 }, 6504Srgrimes 6514Srgrimes/*40*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6524Srgrimes/*41*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6534Srgrimes/*42*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6544Srgrimes/*43*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6554Srgrimes/*44*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6564Srgrimes/*45*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6574Srgrimes/*46*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6584Srgrimes/*47*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6594Srgrimes 6604Srgrimes/*48*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6614Srgrimes/*49*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6624Srgrimes/*4a*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6634Srgrimes/*4b*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6644Srgrimes/*4c*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6654Srgrimes/*4d*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6664Srgrimes/*4e*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6674Srgrimes/*4f*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6684Srgrimes 6694Srgrimes/*50*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6704Srgrimes/*51*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6714Srgrimes/*52*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6724Srgrimes/*53*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6734Srgrimes/*54*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6744Srgrimes/*55*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6754Srgrimes/*56*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6764Srgrimes/*57*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6774Srgrimes 6784Srgrimes/*58*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6794Srgrimes/*59*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6804Srgrimes/*5a*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6814Srgrimes/*5b*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6824Srgrimes/*5c*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6834Srgrimes/*5d*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6844Srgrimes/*5e*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6854Srgrimes/*5f*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6864Srgrimes 6874Srgrimes/*60*/ { "pusha", FALSE, LONG, 0, 0 }, 6884Srgrimes/*61*/ { "popa", FALSE, LONG, 0, 0 }, 6894Srgrimes/*62*/ { "bound", TRUE, LONG, op2(E, R), 0 }, 69021277Sbde/*63*/ { "arpl", TRUE, NONE, op2(Rw,Ew), 0 }, 6914Srgrimes 6924Srgrimes/*64*/ { "", FALSE, NONE, 0, 0 }, 6934Srgrimes/*65*/ { "", FALSE, NONE, 0, 0 }, 6944Srgrimes/*66*/ { "", FALSE, NONE, 0, 0 }, 6954Srgrimes/*67*/ { "", FALSE, NONE, 0, 0 }, 6964Srgrimes 6974Srgrimes/*68*/ { "push", FALSE, LONG, op1(I), 0 }, 6984Srgrimes/*69*/ { "imul", TRUE, LONG, op3(I,E,R), 0 }, 69921277Sbde/*6a*/ { "push", FALSE, LONG, op1(Ibs), 0 }, 7004Srgrimes/*6b*/ { "imul", TRUE, LONG, op3(Ibs,E,R),0 }, 7014Srgrimes/*6c*/ { "ins", FALSE, BYTE, op2(DX, DI), 0 }, 7024Srgrimes/*6d*/ { "ins", FALSE, LONG, op2(DX, DI), 0 }, 7034Srgrimes/*6e*/ { "outs", FALSE, BYTE, op2(SI, DX), 0 }, 7044Srgrimes/*6f*/ { "outs", FALSE, LONG, op2(SI, DX), 0 }, 7054Srgrimes 7064Srgrimes/*70*/ { "jo", FALSE, NONE, op1(Db), 0 }, 7074Srgrimes/*71*/ { "jno", FALSE, NONE, op1(Db), 0 }, 7084Srgrimes/*72*/ { "jb", FALSE, NONE, op1(Db), 0 }, 7094Srgrimes/*73*/ { "jnb", FALSE, NONE, op1(Db), 0 }, 7104Srgrimes/*74*/ { "jz", FALSE, NONE, op1(Db), 0 }, 7114Srgrimes/*75*/ { "jnz", FALSE, NONE, op1(Db), 0 }, 7124Srgrimes/*76*/ { "jbe", FALSE, NONE, op1(Db), 0 }, 7134Srgrimes/*77*/ { "jnbe", FALSE, NONE, op1(Db), 0 }, 7144Srgrimes 7154Srgrimes/*78*/ { "js", FALSE, NONE, op1(Db), 0 }, 7164Srgrimes/*79*/ { "jns", FALSE, NONE, op1(Db), 0 }, 7174Srgrimes/*7a*/ { "jp", FALSE, NONE, op1(Db), 0 }, 7184Srgrimes/*7b*/ { "jnp", FALSE, NONE, op1(Db), 0 }, 7194Srgrimes/*7c*/ { "jl", FALSE, NONE, op1(Db), 0 }, 7204Srgrimes/*7d*/ { "jnl", FALSE, NONE, op1(Db), 0 }, 7214Srgrimes/*7e*/ { "jle", FALSE, NONE, op1(Db), 0 }, 7224Srgrimes/*7f*/ { "jnle", FALSE, NONE, op1(Db), 0 }, 7234Srgrimes 72417109Sbde/*80*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 }, 72517109Sbde/*81*/ { "", TRUE, LONG, op2(I, E), db_Grp1 }, 72621277Sbde/*82*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 }, 72717109Sbde/*83*/ { "", TRUE, LONG, op2(Ibs,E), db_Grp1 }, 7284Srgrimes/*84*/ { "test", TRUE, BYTE, op2(R, E), 0 }, 7294Srgrimes/*85*/ { "test", TRUE, LONG, op2(R, E), 0 }, 7304Srgrimes/*86*/ { "xchg", TRUE, BYTE, op2(R, E), 0 }, 7314Srgrimes/*87*/ { "xchg", TRUE, LONG, op2(R, E), 0 }, 7324Srgrimes 7334Srgrimes/*88*/ { "mov", TRUE, BYTE, op2(R, E), 0 }, 7344Srgrimes/*89*/ { "mov", TRUE, LONG, op2(R, E), 0 }, 7354Srgrimes/*8a*/ { "mov", TRUE, BYTE, op2(E, R), 0 }, 7364Srgrimes/*8b*/ { "mov", TRUE, LONG, op2(E, R), 0 }, 7374Srgrimes/*8c*/ { "mov", TRUE, NONE, op2(S, Ew), 0 }, 7384Srgrimes/*8d*/ { "lea", TRUE, LONG, op2(E, R), 0 }, 7394Srgrimes/*8e*/ { "mov", TRUE, NONE, op2(Ew, S), 0 }, 7404Srgrimes/*8f*/ { "pop", TRUE, LONG, op1(E), 0 }, 7414Srgrimes 7424Srgrimes/*90*/ { "nop", FALSE, NONE, 0, 0 }, 7434Srgrimes/*91*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7444Srgrimes/*92*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7454Srgrimes/*93*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7464Srgrimes/*94*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7474Srgrimes/*95*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7484Srgrimes/*96*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7494Srgrimes/*97*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7504Srgrimes 7514Srgrimes/*98*/ { "cbw", FALSE, SDEP, 0, "cwde" }, /* cbw/cwde */ 7524Srgrimes/*99*/ { "cwd", FALSE, SDEP, 0, "cdq" }, /* cwd/cdq */ 7534Srgrimes/*9a*/ { "lcall", FALSE, NONE, op1(OS), 0 }, 7544Srgrimes/*9b*/ { "wait", FALSE, NONE, 0, 0 }, 7554Srgrimes/*9c*/ { "pushf", FALSE, LONG, 0, 0 }, 7564Srgrimes/*9d*/ { "popf", FALSE, LONG, 0, 0 }, 7574Srgrimes/*9e*/ { "sahf", FALSE, NONE, 0, 0 }, 7584Srgrimes/*9f*/ { "lahf", FALSE, NONE, 0, 0 }, 7594Srgrimes 7604Srgrimes/*a0*/ { "mov", FALSE, BYTE, op2(O, A), 0 }, 7614Srgrimes/*a1*/ { "mov", FALSE, LONG, op2(O, A), 0 }, 7624Srgrimes/*a2*/ { "mov", FALSE, BYTE, op2(A, O), 0 }, 7634Srgrimes/*a3*/ { "mov", FALSE, LONG, op2(A, O), 0 }, 7644Srgrimes/*a4*/ { "movs", FALSE, BYTE, op2(SI,DI), 0 }, 7654Srgrimes/*a5*/ { "movs", FALSE, LONG, op2(SI,DI), 0 }, 7664Srgrimes/*a6*/ { "cmps", FALSE, BYTE, op2(SI,DI), 0 }, 7674Srgrimes/*a7*/ { "cmps", FALSE, LONG, op2(SI,DI), 0 }, 7684Srgrimes 7694Srgrimes/*a8*/ { "test", FALSE, BYTE, op2(I, A), 0 }, 7704Srgrimes/*a9*/ { "test", FALSE, LONG, op2(I, A), 0 }, 7714Srgrimes/*aa*/ { "stos", FALSE, BYTE, op1(DI), 0 }, 7724Srgrimes/*ab*/ { "stos", FALSE, LONG, op1(DI), 0 }, 773118Srgrimes/*ac*/ { "lods", FALSE, BYTE, op1(SI), 0 }, 774118Srgrimes/*ad*/ { "lods", FALSE, LONG, op1(SI), 0 }, 7754Srgrimes/*ae*/ { "scas", FALSE, BYTE, op1(SI), 0 }, 7764Srgrimes/*af*/ { "scas", FALSE, LONG, op1(SI), 0 }, 7774Srgrimes 7784Srgrimes/*b0*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7794Srgrimes/*b1*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7804Srgrimes/*b2*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7814Srgrimes/*b3*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7824Srgrimes/*b4*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7834Srgrimes/*b5*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7844Srgrimes/*b6*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7854Srgrimes/*b7*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7864Srgrimes 7874Srgrimes/*b8*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7884Srgrimes/*b9*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7894Srgrimes/*ba*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7904Srgrimes/*bb*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7914Srgrimes/*bc*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7924Srgrimes/*bd*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7934Srgrimes/*be*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7944Srgrimes/*bf*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7954Srgrimes 79617109Sbde/*c0*/ { "", TRUE, BYTE, op2(Ib, E), db_Grp2 }, 79717109Sbde/*c1*/ { "", TRUE, LONG, op2(Ib, E), db_Grp2 }, 7984Srgrimes/*c2*/ { "ret", FALSE, NONE, op1(Iw), 0 }, 7994Srgrimes/*c3*/ { "ret", FALSE, NONE, 0, 0 }, 8004Srgrimes/*c4*/ { "les", TRUE, LONG, op2(E, R), 0 }, 8014Srgrimes/*c5*/ { "lds", TRUE, LONG, op2(E, R), 0 }, 8024Srgrimes/*c6*/ { "mov", TRUE, BYTE, op2(I, E), 0 }, 8034Srgrimes/*c7*/ { "mov", TRUE, LONG, op2(I, E), 0 }, 8044Srgrimes 80521277Sbde/*c8*/ { "enter", FALSE, NONE, op2(Iw, Ib), 0 }, 806270844Spfg/*c9*/ { "leave", FALSE, NONE, 0, 0 }, 8074Srgrimes/*ca*/ { "lret", FALSE, NONE, op1(Iw), 0 }, 8084Srgrimes/*cb*/ { "lret", FALSE, NONE, 0, 0 }, 8094Srgrimes/*cc*/ { "int", FALSE, NONE, op1(o3), 0 }, 8104Srgrimes/*cd*/ { "int", FALSE, NONE, op1(Ib), 0 }, 8114Srgrimes/*ce*/ { "into", FALSE, NONE, 0, 0 }, 8124Srgrimes/*cf*/ { "iret", FALSE, NONE, 0, 0 }, 8134Srgrimes 81417109Sbde/*d0*/ { "", TRUE, BYTE, op2(o1, E), db_Grp2 }, 81517109Sbde/*d1*/ { "", TRUE, LONG, op2(o1, E), db_Grp2 }, 81617109Sbde/*d2*/ { "", TRUE, BYTE, op2(CL, E), db_Grp2 }, 81717109Sbde/*d3*/ { "", TRUE, LONG, op2(CL, E), db_Grp2 }, 81821277Sbde/*d4*/ { "aam", FALSE, NONE, op1(Iba), 0 }, 81921277Sbde/*d5*/ { "aad", FALSE, NONE, op1(Iba), 0 }, 82021277Sbde/*d6*/ { ".byte\t0xd6", FALSE, NONE, 0, 0 }, 8214Srgrimes/*d7*/ { "xlat", FALSE, BYTE, op1(BX), 0 }, 8224Srgrimes 82317109Sbde/*d8*/ { "", TRUE, NONE, 0, db_Esc8 }, 82417109Sbde/*d9*/ { "", TRUE, NONE, 0, db_Esc9 }, 82517109Sbde/*da*/ { "", TRUE, NONE, 0, db_Esca }, 82617109Sbde/*db*/ { "", TRUE, NONE, 0, db_Escb }, 82717109Sbde/*dc*/ { "", TRUE, NONE, 0, db_Escc }, 82817109Sbde/*dd*/ { "", TRUE, NONE, 0, db_Escd }, 82917109Sbde/*de*/ { "", TRUE, NONE, 0, db_Esce }, 83017109Sbde/*df*/ { "", TRUE, NONE, 0, db_Escf }, 8314Srgrimes 8324Srgrimes/*e0*/ { "loopne",FALSE, NONE, op1(Db), 0 }, 8334Srgrimes/*e1*/ { "loope", FALSE, NONE, op1(Db), 0 }, 8344Srgrimes/*e2*/ { "loop", FALSE, NONE, op1(Db), 0 }, 8354Srgrimes/*e3*/ { "jcxz", FALSE, SDEP, op1(Db), "jecxz" }, 8364Srgrimes/*e4*/ { "in", FALSE, BYTE, op2(Ib, A), 0 }, 8374Srgrimes/*e5*/ { "in", FALSE, LONG, op2(Ib, A) , 0 }, 8384Srgrimes/*e6*/ { "out", FALSE, BYTE, op2(A, Ib), 0 }, 8394Srgrimes/*e7*/ { "out", FALSE, LONG, op2(A, Ib) , 0 }, 8404Srgrimes 8414Srgrimes/*e8*/ { "call", FALSE, NONE, op1(Dl), 0 }, 8424Srgrimes/*e9*/ { "jmp", FALSE, NONE, op1(Dl), 0 }, 8434Srgrimes/*ea*/ { "ljmp", FALSE, NONE, op1(OS), 0 }, 8444Srgrimes/*eb*/ { "jmp", FALSE, NONE, op1(Db), 0 }, 8454Srgrimes/*ec*/ { "in", FALSE, BYTE, op2(DX, A), 0 }, 8464Srgrimes/*ed*/ { "in", FALSE, LONG, op2(DX, A) , 0 }, 8474Srgrimes/*ee*/ { "out", FALSE, BYTE, op2(A, DX), 0 }, 8484Srgrimes/*ef*/ { "out", FALSE, LONG, op2(A, DX) , 0 }, 8494Srgrimes 8504Srgrimes/*f0*/ { "", FALSE, NONE, 0, 0 }, 85121277Sbde/*f1*/ { ".byte\t0xf1", FALSE, NONE, 0, 0 }, 8524Srgrimes/*f2*/ { "", FALSE, NONE, 0, 0 }, 8534Srgrimes/*f3*/ { "", FALSE, NONE, 0, 0 }, 8544Srgrimes/*f4*/ { "hlt", FALSE, NONE, 0, 0 }, 8554Srgrimes/*f5*/ { "cmc", FALSE, NONE, 0, 0 }, 85617109Sbde/*f6*/ { "", TRUE, BYTE, 0, db_Grp3 }, 85717109Sbde/*f7*/ { "", TRUE, LONG, 0, db_Grp3 }, 8584Srgrimes 8594Srgrimes/*f8*/ { "clc", FALSE, NONE, 0, 0 }, 8604Srgrimes/*f9*/ { "stc", FALSE, NONE, 0, 0 }, 8614Srgrimes/*fa*/ { "cli", FALSE, NONE, 0, 0 }, 8624Srgrimes/*fb*/ { "sti", FALSE, NONE, 0, 0 }, 8634Srgrimes/*fc*/ { "cld", FALSE, NONE, 0, 0 }, 8644Srgrimes/*fd*/ { "std", FALSE, NONE, 0, 0 }, 86517109Sbde/*fe*/ { "", TRUE, NONE, 0, db_Grp4 }, 86617109Sbde/*ff*/ { "", TRUE, NONE, 0, db_Grp5 }, 8674Srgrimes}; 8684Srgrimes 86917109Sbdestatic const struct inst db_bad_inst = 8704Srgrimes { "???", FALSE, NONE, 0, 0 } 8714Srgrimes; 8724Srgrimes 8734Srgrimes#define f_mod(byte) ((byte)>>6) 8744Srgrimes#define f_reg(byte) (((byte)>>3)&0x7) 8754Srgrimes#define f_rm(byte) ((byte)&0x7) 8764Srgrimes 8774Srgrimes#define sib_ss(byte) ((byte)>>6) 8784Srgrimes#define sib_index(byte) (((byte)>>3)&0x7) 8794Srgrimes#define sib_base(byte) ((byte)&0x7) 8804Srgrimes 88111940Sbdestruct i_addr { 8824Srgrimes int is_reg; /* if reg, reg number is in 'disp' */ 8834Srgrimes int disp; 88414887Swollman const char * base; 88514887Swollman const char * index; 8864Srgrimes int ss; 8874Srgrimes}; 8884Srgrimes 88914887Swollmanstatic const char * const db_index_reg_16[8] = { 8904Srgrimes "%bx,%si", 8914Srgrimes "%bx,%di", 8924Srgrimes "%bp,%si", 8934Srgrimes "%bp,%di", 8944Srgrimes "%si", 8954Srgrimes "%di", 8964Srgrimes "%bp", 8974Srgrimes "%bx" 8984Srgrimes}; 8994Srgrimes 90014887Swollmanstatic const char * const db_reg[3][8] = { 90143314Sdillon { "%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh" }, 90243314Sdillon { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di" }, 90343314Sdillon { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi" } 9044Srgrimes}; 9054Srgrimes 90617109Sbdestatic const char * const db_seg_reg[8] = { 9074Srgrimes "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", "" 9084Srgrimes}; 9094Srgrimes 9104Srgrimes/* 9114Srgrimes * lengths for size attributes 9124Srgrimes */ 91314887Swollmanstatic const int db_lengths[] = { 9144Srgrimes 1, /* BYTE */ 9154Srgrimes 2, /* WORD */ 9164Srgrimes 4, /* LONG */ 9174Srgrimes 8, /* QUAD */ 9184Srgrimes 4, /* SNGL */ 9194Srgrimes 8, /* DBLR */ 9204Srgrimes 10, /* EXTR */ 9214Srgrimes}; 9224Srgrimes 9234Srgrimes#define get_value_inc(result, loc, size, is_signed) \ 9244Srgrimes result = db_get_value((loc), (size), (is_signed)); \ 9254Srgrimes (loc) += (size); 9264Srgrimes 92711940Sbdestatic db_addr_t 92892770Salfred db_disasm_esc(db_addr_t loc, int inst, int short_addr, 92993017Sbde int size, const char *seg); 93092770Salfredstatic void db_print_address(const char *seg, int size, 93193017Sbde struct i_addr *addrp); 93211940Sbdestatic db_addr_t 93393017Sbde db_read_address(db_addr_t loc, int short_addr, int regmodrm, 93493017Sbde struct i_addr *addrp); 93511940Sbde 9364Srgrimes/* 9374Srgrimes * Read address at location and return updated location. 9384Srgrimes */ 93911921Sphkstatic db_addr_t 9404Srgrimesdb_read_address(loc, short_addr, regmodrm, addrp) 9414Srgrimes db_addr_t loc; 9424Srgrimes int short_addr; 9434Srgrimes int regmodrm; 94417109Sbde struct i_addr * addrp; /* out */ 9454Srgrimes{ 9463436Sphk int mod, rm, sib, index, disp; 9474Srgrimes 9484Srgrimes mod = f_mod(regmodrm); 9494Srgrimes rm = f_rm(regmodrm); 9504Srgrimes 9514Srgrimes if (mod == 3) { 9524Srgrimes addrp->is_reg = TRUE; 9534Srgrimes addrp->disp = rm; 9544Srgrimes return (loc); 9554Srgrimes } 9564Srgrimes addrp->is_reg = FALSE; 957297974Spfg addrp->index = NULL; 9584Srgrimes 9594Srgrimes if (short_addr) { 960297974Spfg addrp->index = NULL; 9614Srgrimes addrp->ss = 0; 9624Srgrimes switch (mod) { 9634Srgrimes case 0: 9644Srgrimes if (rm == 6) { 96521277Sbde get_value_inc(disp, loc, 2, FALSE); 9664Srgrimes addrp->disp = disp; 967297974Spfg addrp->base = NULL; 9684Srgrimes } 9694Srgrimes else { 9704Srgrimes addrp->disp = 0; 9714Srgrimes addrp->base = db_index_reg_16[rm]; 9724Srgrimes } 9734Srgrimes break; 9744Srgrimes case 1: 9754Srgrimes get_value_inc(disp, loc, 1, TRUE); 97621277Sbde disp &= 0xFFFF; 9774Srgrimes addrp->disp = disp; 9784Srgrimes addrp->base = db_index_reg_16[rm]; 9794Srgrimes break; 9804Srgrimes case 2: 98121277Sbde get_value_inc(disp, loc, 2, FALSE); 9824Srgrimes addrp->disp = disp; 9834Srgrimes addrp->base = db_index_reg_16[rm]; 9844Srgrimes break; 9854Srgrimes } 9864Srgrimes } 9874Srgrimes else { 9884Srgrimes if (mod != 3 && rm == 4) { 9894Srgrimes get_value_inc(sib, loc, 1, FALSE); 9904Srgrimes rm = sib_base(sib); 9914Srgrimes index = sib_index(sib); 9924Srgrimes if (index != 4) 9934Srgrimes addrp->index = db_reg[LONG][index]; 9944Srgrimes addrp->ss = sib_ss(sib); 9954Srgrimes } 9964Srgrimes 9974Srgrimes switch (mod) { 9984Srgrimes case 0: 9994Srgrimes if (rm == 5) { 10004Srgrimes get_value_inc(addrp->disp, loc, 4, FALSE); 1001297974Spfg addrp->base = NULL; 10024Srgrimes } 10034Srgrimes else { 10044Srgrimes addrp->disp = 0; 10054Srgrimes addrp->base = db_reg[LONG][rm]; 10064Srgrimes } 10074Srgrimes break; 10084Srgrimes 10094Srgrimes case 1: 10104Srgrimes get_value_inc(disp, loc, 1, TRUE); 10114Srgrimes addrp->disp = disp; 10124Srgrimes addrp->base = db_reg[LONG][rm]; 10134Srgrimes break; 10144Srgrimes 10154Srgrimes case 2: 10164Srgrimes get_value_inc(disp, loc, 4, FALSE); 10174Srgrimes addrp->disp = disp; 10184Srgrimes addrp->base = db_reg[LONG][rm]; 10194Srgrimes break; 10204Srgrimes } 10214Srgrimes } 10224Srgrimes return (loc); 10234Srgrimes} 10244Srgrimes 102511921Sphkstatic void 10264Srgrimesdb_print_address(seg, size, addrp) 102717109Sbde const char * seg; 10284Srgrimes int size; 102917109Sbde struct i_addr * addrp; 10304Srgrimes{ 10314Srgrimes if (addrp->is_reg) { 10324Srgrimes db_printf("%s", db_reg[size][addrp->disp]); 10334Srgrimes return; 10344Srgrimes } 10354Srgrimes 10364Srgrimes if (seg) { 10374Srgrimes db_printf("%s:", seg); 10384Srgrimes } 10394Srgrimes 10404Srgrimes db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY); 1041297974Spfg if (addrp->base != NULL || addrp->index != NULL) { 10424Srgrimes db_printf("("); 10434Srgrimes if (addrp->base) 10444Srgrimes db_printf("%s", addrp->base); 10454Srgrimes if (addrp->index) 10464Srgrimes db_printf(",%s,%d", addrp->index, 1<<addrp->ss); 10474Srgrimes db_printf(")"); 10484Srgrimes } 10494Srgrimes} 10504Srgrimes 10514Srgrimes/* 10524Srgrimes * Disassemble floating-point ("escape") instruction 10534Srgrimes * and return updated location. 10544Srgrimes */ 105511921Sphkstatic db_addr_t 10564Srgrimesdb_disasm_esc(loc, inst, short_addr, size, seg) 10574Srgrimes db_addr_t loc; 10584Srgrimes int inst; 10594Srgrimes int short_addr; 10604Srgrimes int size; 106117109Sbde const char * seg; 10624Srgrimes{ 10634Srgrimes int regmodrm; 106417109Sbde const struct finst * fp; 10654Srgrimes int mod; 10664Srgrimes struct i_addr address; 106717109Sbde const char * name; 10684Srgrimes 10694Srgrimes get_value_inc(regmodrm, loc, 1, FALSE); 10704Srgrimes fp = &db_Esc_inst[inst - 0xd8][f_reg(regmodrm)]; 10714Srgrimes mod = f_mod(regmodrm); 10724Srgrimes if (mod != 3) { 107321277Sbde if (*fp->f_name == '\0') { 107421277Sbde db_printf("<bad instruction>"); 107521277Sbde return (loc); 107621277Sbde } 10774Srgrimes /* 10784Srgrimes * Normal address modes. 10794Srgrimes */ 10804Srgrimes loc = db_read_address(loc, short_addr, regmodrm, &address); 108179885Skris db_printf("%s", fp->f_name); 10824Srgrimes switch(fp->f_size) { 10834Srgrimes case SNGL: 10844Srgrimes db_printf("s"); 10854Srgrimes break; 10864Srgrimes case DBLR: 10874Srgrimes db_printf("l"); 10884Srgrimes break; 10894Srgrimes case EXTR: 10904Srgrimes db_printf("t"); 10914Srgrimes break; 10924Srgrimes case WORD: 10934Srgrimes db_printf("s"); 10944Srgrimes break; 10954Srgrimes case LONG: 10964Srgrimes db_printf("l"); 10974Srgrimes break; 10984Srgrimes case QUAD: 10994Srgrimes db_printf("q"); 11004Srgrimes break; 11014Srgrimes default: 11024Srgrimes break; 11034Srgrimes } 11044Srgrimes db_printf("\t"); 11054Srgrimes db_print_address(seg, BYTE, &address); 11064Srgrimes } 11074Srgrimes else { 11084Srgrimes /* 11094Srgrimes * 'reg-reg' - special formats 11104Srgrimes */ 11114Srgrimes switch (fp->f_rrmode) { 11124Srgrimes case op2(ST,STI): 11134Srgrimes name = (fp->f_rrname) ? fp->f_rrname : fp->f_name; 11144Srgrimes db_printf("%s\t%%st,%%st(%d)",name,f_rm(regmodrm)); 11154Srgrimes break; 11164Srgrimes case op2(STI,ST): 11174Srgrimes name = (fp->f_rrname) ? fp->f_rrname : fp->f_name; 11184Srgrimes db_printf("%s\t%%st(%d),%%st",name, f_rm(regmodrm)); 11194Srgrimes break; 11204Srgrimes case op1(STI): 11214Srgrimes name = (fp->f_rrname) ? fp->f_rrname : fp->f_name; 11224Srgrimes db_printf("%s\t%%st(%d)",name, f_rm(regmodrm)); 11234Srgrimes break; 11244Srgrimes case op1(X): 112521277Sbde name = ((const char * const *)fp->f_rrname)[f_rm(regmodrm)]; 112621277Sbde if (*name == '\0') 112721277Sbde goto bad; 112821277Sbde db_printf("%s", name); 11294Srgrimes break; 11304Srgrimes case op1(XA): 113121277Sbde name = ((const char * const *)fp->f_rrname)[f_rm(regmodrm)]; 113221277Sbde if (*name == '\0') 113321277Sbde goto bad; 113421277Sbde db_printf("%s\t%%ax", name); 11354Srgrimes break; 11364Srgrimes default: 113721277Sbde bad: 11384Srgrimes db_printf("<bad instruction>"); 11394Srgrimes break; 11404Srgrimes } 11414Srgrimes } 11424Srgrimes 11434Srgrimes return (loc); 11444Srgrimes} 11454Srgrimes 11464Srgrimes/* 11474Srgrimes * Disassemble instruction at 'loc'. 'altfmt' specifies an 11484Srgrimes * (optional) alternate format. Return address of start of 11494Srgrimes * next instruction. 11504Srgrimes */ 11514Srgrimesdb_addr_t 1152283248Spfgdb_disasm(db_addr_t loc, bool altfmt) 11534Srgrimes{ 11544Srgrimes int inst; 11554Srgrimes int size; 11564Srgrimes int short_addr; 115717109Sbde const char * seg; 115814887Swollman const struct inst * ip; 115914887Swollman const char * i_name; 11604Srgrimes int i_size; 11614Srgrimes int i_mode; 1162798Swollman int regmodrm = 0; 11634Srgrimes boolean_t first; 11644Srgrimes int displ; 11654Srgrimes int prefix; 1166181606Sjhb int rep; 11674Srgrimes int imm; 11684Srgrimes int imm2; 11694Srgrimes int len; 11704Srgrimes struct i_addr address; 11714Srgrimes 1172308418Skib if (db_segsize(kdb_frame) == 16) 1173308418Skib altfmt = !altfmt; 11744Srgrimes get_value_inc(inst, loc, 1, FALSE); 1175308418Skib if (altfmt) { 1176308418Skib short_addr = TRUE; 1177308418Skib size = WORD; 1178308418Skib } 1179308418Skib else { 1180308418Skib short_addr = FALSE; 1181308418Skib size = LONG; 1182308418Skib } 1183297974Spfg seg = NULL; 11844Srgrimes 11854Srgrimes /* 11864Srgrimes * Get prefixes 11874Srgrimes */ 1188181606Sjhb rep = FALSE; 11894Srgrimes prefix = TRUE; 11904Srgrimes do { 11914Srgrimes switch (inst) { 11924Srgrimes case 0x66: /* data16 */ 11934Srgrimes size = WORD; 11944Srgrimes break; 11954Srgrimes case 0x67: 11964Srgrimes short_addr = TRUE; 11974Srgrimes break; 11984Srgrimes case 0x26: 11994Srgrimes seg = "%es"; 12004Srgrimes break; 12014Srgrimes case 0x36: 12024Srgrimes seg = "%ss"; 12034Srgrimes break; 12044Srgrimes case 0x2e: 12054Srgrimes seg = "%cs"; 12064Srgrimes break; 12074Srgrimes case 0x3e: 12084Srgrimes seg = "%ds"; 12094Srgrimes break; 12104Srgrimes case 0x64: 12114Srgrimes seg = "%fs"; 12124Srgrimes break; 12134Srgrimes case 0x65: 12144Srgrimes seg = "%gs"; 12154Srgrimes break; 12164Srgrimes case 0xf0: 12174Srgrimes db_printf("lock "); 12184Srgrimes break; 12194Srgrimes case 0xf2: 12204Srgrimes db_printf("repne "); 12214Srgrimes break; 12224Srgrimes case 0xf3: 1223181606Sjhb rep = TRUE; 12244Srgrimes break; 12254Srgrimes default: 12264Srgrimes prefix = FALSE; 12274Srgrimes break; 12284Srgrimes } 12294Srgrimes if (prefix) { 12304Srgrimes get_value_inc(inst, loc, 1, FALSE); 12314Srgrimes } 1232181606Sjhb if (rep == TRUE) { 1233181606Sjhb if (inst == 0x90) { 1234181606Sjhb db_printf("pause\n"); 1235181606Sjhb return (loc); 1236181606Sjhb } 1237181606Sjhb db_printf("repe "); /* XXX repe VS rep */ 1238181606Sjhb rep = FALSE; 1239181606Sjhb } 12404Srgrimes } while (prefix); 12414Srgrimes 12424Srgrimes if (inst >= 0xd8 && inst <= 0xdf) { 12434Srgrimes loc = db_disasm_esc(loc, inst, short_addr, size, seg); 12444Srgrimes db_printf("\n"); 12454Srgrimes return (loc); 12464Srgrimes } 12474Srgrimes 12484Srgrimes if (inst == 0x0f) { 12494Srgrimes get_value_inc(inst, loc, 1, FALSE); 12504Srgrimes ip = db_inst_0f[inst>>4]; 1251297974Spfg if (ip == NULL) { 12524Srgrimes ip = &db_bad_inst; 12534Srgrimes } 12544Srgrimes else { 12554Srgrimes ip = &ip[inst&0xf]; 12564Srgrimes } 12574Srgrimes } 12584Srgrimes else 12594Srgrimes ip = &db_inst_table[inst]; 12604Srgrimes 12614Srgrimes if (ip->i_has_modrm) { 12624Srgrimes get_value_inc(regmodrm, loc, 1, FALSE); 12634Srgrimes loc = db_read_address(loc, short_addr, regmodrm, &address); 12644Srgrimes } 12654Srgrimes 12664Srgrimes i_name = ip->i_name; 12674Srgrimes i_size = ip->i_size; 12684Srgrimes i_mode = ip->i_mode; 12694Srgrimes 127017109Sbde if (ip->i_extra == db_Grp1 || ip->i_extra == db_Grp2 || 127117109Sbde ip->i_extra == db_Grp6 || ip->i_extra == db_Grp7 || 1272181606Sjhb ip->i_extra == db_Grp8 || ip->i_extra == db_Grp9 || 1273181606Sjhb ip->i_extra == db_Grp15) { 127417109Sbde i_name = ((const char * const *)ip->i_extra)[f_reg(regmodrm)]; 12754Srgrimes } 127617109Sbde else if (ip->i_extra == db_Grp3) { 127717109Sbde ip = ip->i_extra; 12784Srgrimes ip = &ip[f_reg(regmodrm)]; 12794Srgrimes i_name = ip->i_name; 12804Srgrimes i_mode = ip->i_mode; 12814Srgrimes } 128217109Sbde else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) { 128317109Sbde ip = ip->i_extra; 12844Srgrimes ip = &ip[f_reg(regmodrm)]; 12854Srgrimes i_name = ip->i_name; 12864Srgrimes i_mode = ip->i_mode; 12874Srgrimes i_size = ip->i_size; 12884Srgrimes } 12894Srgrimes 1290181606Sjhb /* Special cases that don't fit well in the tables. */ 1291181606Sjhb if (ip->i_extra == db_Grp7 && f_mod(regmodrm) == 3) { 1292181606Sjhb switch (regmodrm) { 1293181606Sjhb case 0xc8: 1294181606Sjhb i_name = "monitor"; 1295181606Sjhb i_size = NONE; 1296270844Spfg i_mode = 0; 1297181606Sjhb break; 1298181606Sjhb case 0xc9: 1299181606Sjhb i_name = "mwait"; 1300181606Sjhb i_size = NONE; 1301181606Sjhb i_mode = 0; 1302181606Sjhb break; 1303181606Sjhb } 1304181606Sjhb } 1305181606Sjhb if (ip->i_extra == db_Grp15 && f_mod(regmodrm) == 3) { 1306181606Sjhb i_name = db_Grp15b[f_reg(regmodrm)]; 1307181606Sjhb i_size = NONE; 1308181606Sjhb i_mode = 0; 1309181606Sjhb } 1310181606Sjhb 13114Srgrimes if (i_size == SDEP) { 13124Srgrimes if (size == WORD) 131379885Skris db_printf("%s", i_name); 13144Srgrimes else 131579885Skris db_printf("%s", (const char *)ip->i_extra); 13164Srgrimes } 13174Srgrimes else { 131879885Skris db_printf("%s", i_name); 13194Srgrimes if (i_size != NONE) { 13204Srgrimes if (i_size == BYTE) { 13214Srgrimes db_printf("b"); 13224Srgrimes size = BYTE; 13234Srgrimes } 13244Srgrimes else if (i_size == WORD) { 13254Srgrimes db_printf("w"); 13264Srgrimes size = WORD; 13274Srgrimes } 13284Srgrimes else if (size == WORD) 13294Srgrimes db_printf("w"); 13304Srgrimes else 13314Srgrimes db_printf("l"); 13324Srgrimes } 13334Srgrimes } 13344Srgrimes db_printf("\t"); 13354Srgrimes for (first = TRUE; 13364Srgrimes i_mode != 0; 13374Srgrimes i_mode >>= 8, first = FALSE) 13384Srgrimes { 13394Srgrimes if (!first) 13404Srgrimes db_printf(","); 13414Srgrimes 13424Srgrimes switch (i_mode & 0xFF) { 13434Srgrimes 13444Srgrimes case E: 13454Srgrimes db_print_address(seg, size, &address); 13464Srgrimes break; 13474Srgrimes 13484Srgrimes case Eind: 13494Srgrimes db_printf("*"); 13504Srgrimes db_print_address(seg, size, &address); 13514Srgrimes break; 13524Srgrimes 135321277Sbde case El: 135421277Sbde db_print_address(seg, LONG, &address); 135521277Sbde break; 135621277Sbde 13574Srgrimes case Ew: 13584Srgrimes db_print_address(seg, WORD, &address); 13594Srgrimes break; 13604Srgrimes 13614Srgrimes case Eb: 13624Srgrimes db_print_address(seg, BYTE, &address); 13634Srgrimes break; 13644Srgrimes 13654Srgrimes case R: 13664Srgrimes db_printf("%s", db_reg[size][f_reg(regmodrm)]); 13674Srgrimes break; 13684Srgrimes 13694Srgrimes case Rw: 13704Srgrimes db_printf("%s", db_reg[WORD][f_reg(regmodrm)]); 13714Srgrimes break; 13724Srgrimes 13734Srgrimes case Ri: 13744Srgrimes db_printf("%s", db_reg[size][f_rm(inst)]); 13754Srgrimes break; 13764Srgrimes 137721277Sbde case Ril: 137821277Sbde db_printf("%s", db_reg[LONG][f_rm(inst)]); 137921277Sbde break; 138021277Sbde 13814Srgrimes case S: 13824Srgrimes db_printf("%s", db_seg_reg[f_reg(regmodrm)]); 13834Srgrimes break; 13844Srgrimes 13854Srgrimes case Si: 13864Srgrimes db_printf("%s", db_seg_reg[f_reg(inst)]); 13874Srgrimes break; 13884Srgrimes 13894Srgrimes case A: 13904Srgrimes db_printf("%s", db_reg[size][0]); /* acc */ 13914Srgrimes break; 13924Srgrimes 13934Srgrimes case BX: 13944Srgrimes if (seg) 13954Srgrimes db_printf("%s:", seg); 13964Srgrimes db_printf("(%s)", short_addr ? "%bx" : "%ebx"); 13974Srgrimes break; 13984Srgrimes 13994Srgrimes case CL: 14004Srgrimes db_printf("%%cl"); 14014Srgrimes break; 14024Srgrimes 14034Srgrimes case DX: 14044Srgrimes db_printf("%%dx"); 14054Srgrimes break; 14064Srgrimes 14074Srgrimes case SI: 14084Srgrimes if (seg) 14094Srgrimes db_printf("%s:", seg); 14104Srgrimes db_printf("(%s)", short_addr ? "%si" : "%esi"); 14114Srgrimes break; 14124Srgrimes 14134Srgrimes case DI: 14144Srgrimes db_printf("%%es:(%s)", short_addr ? "%di" : "%edi"); 14154Srgrimes break; 14164Srgrimes 14174Srgrimes case CR: 14184Srgrimes db_printf("%%cr%d", f_reg(regmodrm)); 14194Srgrimes break; 14204Srgrimes 14214Srgrimes case DR: 14224Srgrimes db_printf("%%dr%d", f_reg(regmodrm)); 14234Srgrimes break; 14244Srgrimes 14254Srgrimes case TR: 14264Srgrimes db_printf("%%tr%d", f_reg(regmodrm)); 14274Srgrimes break; 14284Srgrimes 14294Srgrimes case I: 14304Srgrimes len = db_lengths[size]; 143121277Sbde get_value_inc(imm, loc, len, FALSE); 143237506Sbde db_printf("$%#r", imm); 14334Srgrimes break; 14344Srgrimes 14354Srgrimes case Is: 14364Srgrimes len = db_lengths[size]; 143721277Sbde get_value_inc(imm, loc, len, FALSE); 143837506Sbde db_printf("$%+#r", imm); 14394Srgrimes break; 14404Srgrimes 14414Srgrimes case Ib: 144221277Sbde get_value_inc(imm, loc, 1, FALSE); 144337506Sbde db_printf("$%#r", imm); 14444Srgrimes break; 14454Srgrimes 144621277Sbde case Iba: 144721277Sbde get_value_inc(imm, loc, 1, FALSE); 144821277Sbde if (imm != 0x0a) 144937506Sbde db_printf("$%#r", imm); 145021277Sbde break; 145121277Sbde 14524Srgrimes case Ibs: 145321277Sbde get_value_inc(imm, loc, 1, TRUE); 145421277Sbde if (size == WORD) 145521277Sbde imm &= 0xFFFF; 145637506Sbde db_printf("$%+#r", imm); 14574Srgrimes break; 14584Srgrimes 14594Srgrimes case Iw: 146021277Sbde get_value_inc(imm, loc, 2, FALSE); 146137506Sbde db_printf("$%#r", imm); 14624Srgrimes break; 14634Srgrimes 14644Srgrimes case O: 146521277Sbde len = (short_addr ? 2 : 4); 146621277Sbde get_value_inc(displ, loc, len, FALSE); 14674Srgrimes if (seg) 146837506Sbde db_printf("%s:%+#r",seg, displ); 14694Srgrimes else 14704Srgrimes db_printsym((db_addr_t)displ, DB_STGY_ANY); 14714Srgrimes break; 14724Srgrimes 14734Srgrimes case Db: 14744Srgrimes get_value_inc(displ, loc, 1, TRUE); 147521277Sbde displ += loc; 147621277Sbde if (size == WORD) 147721277Sbde displ &= 0xFFFF; 147821277Sbde db_printsym((db_addr_t)displ, DB_STGY_XTRN); 14794Srgrimes break; 14804Srgrimes 14814Srgrimes case Dl: 148221277Sbde len = db_lengths[size]; 148321277Sbde get_value_inc(displ, loc, len, FALSE); 148421277Sbde displ += loc; 148521277Sbde if (size == WORD) 148621277Sbde displ &= 0xFFFF; 148721277Sbde db_printsym((db_addr_t)displ, DB_STGY_XTRN); 14884Srgrimes break; 14894Srgrimes 14904Srgrimes case o1: 14914Srgrimes db_printf("$1"); 14924Srgrimes break; 14934Srgrimes 14944Srgrimes case o3: 14954Srgrimes db_printf("$3"); 14964Srgrimes break; 14974Srgrimes 14984Srgrimes case OS: 149921277Sbde len = db_lengths[size]; 150021277Sbde get_value_inc(imm, loc, len, FALSE); /* offset */ 15014Srgrimes get_value_inc(imm2, loc, 2, FALSE); /* segment */ 150237506Sbde db_printf("$%#r,%#r", imm2, imm); 15034Srgrimes break; 15044Srgrimes } 15054Srgrimes } 15064Srgrimes db_printf("\n"); 15074Srgrimes return (loc); 15084Srgrimes} 1509