db_disasm.c revision 297974
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: head/sys/i386/i386/db_disasm.c 297974 2016-04-14 17:04:06Z pfg $"); 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 198278655Smarkjstatic const struct inst db_inst_0f1x[] = { 199278655Smarkj/*10*/ { "", FALSE, NONE, 0, 0 }, 200278655Smarkj/*11*/ { "", FALSE, NONE, 0, 0 }, 201278655Smarkj/*12*/ { "", FALSE, NONE, 0, 0 }, 202278655Smarkj/*13*/ { "", FALSE, NONE, 0, 0 }, 203278655Smarkj/*14*/ { "", FALSE, NONE, 0, 0 }, 204278655Smarkj/*15*/ { "", FALSE, NONE, 0, 0 }, 205278655Smarkj/*16*/ { "", FALSE, NONE, 0, 0 }, 206278655Smarkj/*17*/ { "", FALSE, NONE, 0, 0 }, 207278655Smarkj 208278655Smarkj/*18*/ { "", FALSE, NONE, 0, 0 }, 209278655Smarkj/*19*/ { "", FALSE, NONE, 0, 0 }, 210278655Smarkj/*1a*/ { "", FALSE, NONE, 0, 0 }, 211278655Smarkj/*1b*/ { "", FALSE, NONE, 0, 0 }, 212278655Smarkj/*1c*/ { "", FALSE, NONE, 0, 0 }, 213278655Smarkj/*1d*/ { "", FALSE, NONE, 0, 0 }, 214278655Smarkj/*1e*/ { "", FALSE, NONE, 0, 0 }, 215278655Smarkj/*1f*/ { "nopl", TRUE, SDEP, 0, "nopw" }, 216278655Smarkj}; 217278655Smarkj 21817109Sbdestatic const struct inst db_inst_0f2x[] = { 21921277Sbde/*20*/ { "mov", TRUE, LONG, op2(CR,El), 0 }, 22021277Sbde/*21*/ { "mov", TRUE, LONG, op2(DR,El), 0 }, 22121277Sbde/*22*/ { "mov", TRUE, LONG, op2(El,CR), 0 }, 22221277Sbde/*23*/ { "mov", TRUE, LONG, op2(El,DR), 0 }, 22321277Sbde/*24*/ { "mov", TRUE, LONG, op2(TR,El), 0 }, 2244Srgrimes/*25*/ { "", FALSE, NONE, 0, 0 }, 22521277Sbde/*26*/ { "mov", TRUE, LONG, op2(El,TR), 0 }, 2264Srgrimes/*27*/ { "", FALSE, NONE, 0, 0 }, 2274Srgrimes 2284Srgrimes/*28*/ { "", FALSE, NONE, 0, 0 }, 2294Srgrimes/*29*/ { "", FALSE, NONE, 0, 0 }, 2304Srgrimes/*2a*/ { "", FALSE, NONE, 0, 0 }, 2314Srgrimes/*2b*/ { "", FALSE, NONE, 0, 0 }, 2324Srgrimes/*2c*/ { "", FALSE, NONE, 0, 0 }, 2334Srgrimes/*2d*/ { "", FALSE, NONE, 0, 0 }, 2344Srgrimes/*2e*/ { "", FALSE, NONE, 0, 0 }, 2354Srgrimes/*2f*/ { "", FALSE, NONE, 0, 0 }, 2364Srgrimes}; 2374Srgrimes 23814887Swollmanstatic const struct inst db_inst_0f3x[] = { 23914887Swollman/*30*/ { "wrmsr", FALSE, NONE, 0, 0 }, 24014887Swollman/*31*/ { "rdtsc", FALSE, NONE, 0, 0 }, 24114887Swollman/*32*/ { "rdmsr", FALSE, NONE, 0, 0 }, 24214887Swollman/*33*/ { "rdpmc", FALSE, NONE, 0, 0 }, 243181606Sjhb/*34*/ { "sysenter",FALSE,NONE, 0, 0 }, 244181606Sjhb/*35*/ { "sysexit",FALSE,NONE, 0, 0 }, 24514887Swollman/*36*/ { "", FALSE, NONE, 0, 0 }, 246181606Sjhb/*37*/ { "getsec",FALSE, NONE, 0, 0 }, 24714887Swollman 24814887Swollman/*38*/ { "", FALSE, NONE, 0, 0 }, 24914887Swollman/*39*/ { "", FALSE, NONE, 0, 0 }, 25014887Swollman/*3a*/ { "", FALSE, NONE, 0, 0 }, 25114887Swollman/*3b*/ { "", FALSE, NONE, 0, 0 }, 25214887Swollman/*3c*/ { "", FALSE, NONE, 0, 0 }, 25314887Swollman/*3d*/ { "", FALSE, NONE, 0, 0 }, 25414887Swollman/*3e*/ { "", FALSE, NONE, 0, 0 }, 25514887Swollman/*3f*/ { "", FALSE, NONE, 0, 0 }, 25614887Swollman}; 25714887Swollman 258181603Sjhbstatic const struct inst db_inst_0f4x[] = { 259181603Sjhb/*40*/ { "cmovo", TRUE, NONE, op2(E, R), 0 }, 260181603Sjhb/*41*/ { "cmovno", TRUE, NONE, op2(E, R), 0 }, 261181603Sjhb/*42*/ { "cmovb", TRUE, NONE, op2(E, R), 0 }, 262181603Sjhb/*43*/ { "cmovnb", TRUE, NONE, op2(E, R), 0 }, 263181603Sjhb/*44*/ { "cmovz", TRUE, NONE, op2(E, R), 0 }, 264181603Sjhb/*45*/ { "cmovnz", TRUE, NONE, op2(E, R), 0 }, 265181603Sjhb/*46*/ { "cmovbe", TRUE, NONE, op2(E, R), 0 }, 266181603Sjhb/*47*/ { "cmovnbe",TRUE, NONE, op2(E, R), 0 }, 267181603Sjhb 268181603Sjhb/*48*/ { "cmovs", TRUE, NONE, op2(E, R), 0 }, 269181603Sjhb/*49*/ { "cmovns", TRUE, NONE, op2(E, R), 0 }, 270181603Sjhb/*4a*/ { "cmovp", TRUE, NONE, op2(E, R), 0 }, 271181603Sjhb/*4b*/ { "cmovnp", TRUE, NONE, op2(E, R), 0 }, 272181603Sjhb/*4c*/ { "cmovl", TRUE, NONE, op2(E, R), 0 }, 273181603Sjhb/*4d*/ { "cmovnl", TRUE, NONE, op2(E, R), 0 }, 274181603Sjhb/*4e*/ { "cmovle", TRUE, NONE, op2(E, R), 0 }, 275181603Sjhb/*4f*/ { "cmovnle",TRUE, NONE, op2(E, R), 0 }, 276181603Sjhb}; 277181603Sjhb 27817109Sbdestatic const struct inst db_inst_0f8x[] = { 2794Srgrimes/*80*/ { "jo", FALSE, NONE, op1(Dl), 0 }, 2804Srgrimes/*81*/ { "jno", FALSE, NONE, op1(Dl), 0 }, 2814Srgrimes/*82*/ { "jb", FALSE, NONE, op1(Dl), 0 }, 2824Srgrimes/*83*/ { "jnb", FALSE, NONE, op1(Dl), 0 }, 2834Srgrimes/*84*/ { "jz", FALSE, NONE, op1(Dl), 0 }, 2844Srgrimes/*85*/ { "jnz", FALSE, NONE, op1(Dl), 0 }, 2854Srgrimes/*86*/ { "jbe", FALSE, NONE, op1(Dl), 0 }, 2864Srgrimes/*87*/ { "jnbe", FALSE, NONE, op1(Dl), 0 }, 2874Srgrimes 2884Srgrimes/*88*/ { "js", FALSE, NONE, op1(Dl), 0 }, 2894Srgrimes/*89*/ { "jns", FALSE, NONE, op1(Dl), 0 }, 2904Srgrimes/*8a*/ { "jp", FALSE, NONE, op1(Dl), 0 }, 2914Srgrimes/*8b*/ { "jnp", FALSE, NONE, op1(Dl), 0 }, 2924Srgrimes/*8c*/ { "jl", FALSE, NONE, op1(Dl), 0 }, 2934Srgrimes/*8d*/ { "jnl", FALSE, NONE, op1(Dl), 0 }, 2944Srgrimes/*8e*/ { "jle", FALSE, NONE, op1(Dl), 0 }, 2954Srgrimes/*8f*/ { "jnle", FALSE, NONE, op1(Dl), 0 }, 2964Srgrimes}; 2974Srgrimes 29817109Sbdestatic const struct inst db_inst_0f9x[] = { 2994Srgrimes/*90*/ { "seto", TRUE, NONE, op1(Eb), 0 }, 3004Srgrimes/*91*/ { "setno", TRUE, NONE, op1(Eb), 0 }, 3014Srgrimes/*92*/ { "setb", TRUE, NONE, op1(Eb), 0 }, 3024Srgrimes/*93*/ { "setnb", TRUE, NONE, op1(Eb), 0 }, 3034Srgrimes/*94*/ { "setz", TRUE, NONE, op1(Eb), 0 }, 3044Srgrimes/*95*/ { "setnz", TRUE, NONE, op1(Eb), 0 }, 3054Srgrimes/*96*/ { "setbe", TRUE, NONE, op1(Eb), 0 }, 3064Srgrimes/*97*/ { "setnbe",TRUE, NONE, op1(Eb), 0 }, 3074Srgrimes 3084Srgrimes/*98*/ { "sets", TRUE, NONE, op1(Eb), 0 }, 3094Srgrimes/*99*/ { "setns", TRUE, NONE, op1(Eb), 0 }, 3104Srgrimes/*9a*/ { "setp", TRUE, NONE, op1(Eb), 0 }, 3114Srgrimes/*9b*/ { "setnp", TRUE, NONE, op1(Eb), 0 }, 3124Srgrimes/*9c*/ { "setl", TRUE, NONE, op1(Eb), 0 }, 3134Srgrimes/*9d*/ { "setnl", TRUE, NONE, op1(Eb), 0 }, 3144Srgrimes/*9e*/ { "setle", TRUE, NONE, op1(Eb), 0 }, 3154Srgrimes/*9f*/ { "setnle",TRUE, NONE, op1(Eb), 0 }, 3164Srgrimes}; 3174Srgrimes 31817109Sbdestatic const struct inst db_inst_0fax[] = { 3194Srgrimes/*a0*/ { "push", FALSE, NONE, op1(Si), 0 }, 3204Srgrimes/*a1*/ { "pop", FALSE, NONE, op1(Si), 0 }, 32121277Sbde/*a2*/ { "cpuid", FALSE, NONE, 0, 0 }, 32221277Sbde/*a3*/ { "bt", TRUE, LONG, op2(R,E), 0 }, 32317109Sbde/*a4*/ { "shld", TRUE, LONG, op3(Ib,R,E), 0 }, 32417109Sbde/*a5*/ { "shld", TRUE, LONG, op3(CL,R,E), 0 }, 3254Srgrimes/*a6*/ { "", FALSE, NONE, 0, 0 }, 3264Srgrimes/*a7*/ { "", FALSE, NONE, 0, 0 }, 3274Srgrimes 3284Srgrimes/*a8*/ { "push", FALSE, NONE, op1(Si), 0 }, 3294Srgrimes/*a9*/ { "pop", FALSE, NONE, op1(Si), 0 }, 33021277Sbde/*aa*/ { "rsm", FALSE, NONE, 0, 0 }, 33121277Sbde/*ab*/ { "bts", TRUE, LONG, op2(R,E), 0 }, 33217109Sbde/*ac*/ { "shrd", TRUE, LONG, op3(Ib,R,E), 0 }, 33317109Sbde/*ad*/ { "shrd", TRUE, LONG, op3(CL,R,E), 0 }, 334181606Sjhb/*ae*/ { "", TRUE, LONG, op1(E), db_Grp15 }, 335181606Sjhb/*af*/ { "imul", TRUE, LONG, op2(E,R), 0 }, 3364Srgrimes}; 3374Srgrimes 33817109Sbdestatic const struct inst db_inst_0fbx[] = { 33921277Sbde/*b0*/ { "cmpxchg",TRUE, BYTE, op2(R, E), 0 }, 34021277Sbde/*b0*/ { "cmpxchg",TRUE, LONG, op2(R, E), 0 }, 3414Srgrimes/*b2*/ { "lss", TRUE, LONG, op2(E, R), 0 }, 34221277Sbde/*b3*/ { "btr", TRUE, LONG, op2(R, E), 0 }, 3434Srgrimes/*b4*/ { "lfs", TRUE, LONG, op2(E, R), 0 }, 3444Srgrimes/*b5*/ { "lgs", TRUE, LONG, op2(E, R), 0 }, 34521277Sbde/*b6*/ { "movzb", TRUE, LONG, op2(Eb, R), 0 }, 34621277Sbde/*b7*/ { "movzw", TRUE, LONG, op2(Ew, R), 0 }, 3474Srgrimes 3484Srgrimes/*b8*/ { "", FALSE, NONE, 0, 0 }, 3494Srgrimes/*b9*/ { "", FALSE, NONE, 0, 0 }, 35017109Sbde/*ba*/ { "", TRUE, LONG, op2(Ib, E), db_Grp8 }, 3514Srgrimes/*bb*/ { "btc", TRUE, LONG, op2(R, E), 0 }, 3524Srgrimes/*bc*/ { "bsf", TRUE, LONG, op2(E, R), 0 }, 3534Srgrimes/*bd*/ { "bsr", TRUE, LONG, op2(E, R), 0 }, 35421277Sbde/*be*/ { "movsb", TRUE, LONG, op2(Eb, R), 0 }, 35521277Sbde/*bf*/ { "movsw", TRUE, LONG, op2(Ew, R), 0 }, 3564Srgrimes}; 3574Srgrimes 35817109Sbdestatic const struct inst db_inst_0fcx[] = { 3594Srgrimes/*c0*/ { "xadd", TRUE, BYTE, op2(R, E), 0 }, 3604Srgrimes/*c1*/ { "xadd", TRUE, LONG, op2(R, E), 0 }, 3614Srgrimes/*c2*/ { "", FALSE, NONE, 0, 0 }, 3624Srgrimes/*c3*/ { "", FALSE, NONE, 0, 0 }, 3634Srgrimes/*c4*/ { "", FALSE, NONE, 0, 0 }, 3644Srgrimes/*c5*/ { "", FALSE, NONE, 0, 0 }, 3654Srgrimes/*c6*/ { "", FALSE, NONE, 0, 0 }, 36621277Sbde/*c7*/ { "", TRUE, NONE, op1(E), db_Grp9 }, 36721277Sbde/*c8*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 36821277Sbde/*c9*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 36921277Sbde/*ca*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 37021277Sbde/*cb*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 37121277Sbde/*cc*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 37221277Sbde/*cd*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 37321277Sbde/*ce*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 37421277Sbde/*cf*/ { "bswap", FALSE, LONG, op1(Ril), 0 }, 3754Srgrimes}; 3764Srgrimes 37714887Swollmanstatic const struct inst * const db_inst_0f[] = { 3784Srgrimes db_inst_0f0x, 379278655Smarkj db_inst_0f1x, 3804Srgrimes db_inst_0f2x, 38114887Swollman db_inst_0f3x, 382181603Sjhb db_inst_0f4x, 3834Srgrimes 0, 3844Srgrimes 0, 3854Srgrimes 0, 3864Srgrimes db_inst_0f8x, 3874Srgrimes db_inst_0f9x, 3884Srgrimes db_inst_0fax, 3894Srgrimes db_inst_0fbx, 3904Srgrimes db_inst_0fcx, 3914Srgrimes 0, 39221277Sbde 0, 3934Srgrimes 0 3944Srgrimes}; 3954Srgrimes 39614887Swollmanstatic const char * const db_Esc92[] = { 3974Srgrimes "fnop", "", "", "", "", "", "", "" 3984Srgrimes}; 39914887Swollmanstatic const char * const db_Esc94[] = { 4004Srgrimes "fchs", "fabs", "", "", "ftst", "fxam", "", "" 4014Srgrimes}; 40217109Sbdestatic const char * const db_Esc95[] = { 4034Srgrimes "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz","" 4044Srgrimes}; 40517109Sbdestatic const char * const db_Esc96[] = { 4064Srgrimes "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp", 4074Srgrimes "fincstp" 4084Srgrimes}; 40914887Swollmanstatic const char * const db_Esc97[] = { 4104Srgrimes "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos" 4114Srgrimes}; 4124Srgrimes 41321277Sbdestatic const char * const db_Esca5[] = { 4144Srgrimes "", "fucompp","", "", "", "", "", "" 4154Srgrimes}; 4164Srgrimes 41717109Sbdestatic const char * const db_Escb4[] = { 41821277Sbde "fneni","fndisi", "fnclex","fninit","fsetpm", "", "", "" 4194Srgrimes}; 4204Srgrimes 42114887Swollmanstatic const char * const db_Esce3[] = { 4224Srgrimes "", "fcompp","", "", "", "", "", "" 4234Srgrimes}; 4244Srgrimes 42517109Sbdestatic const char * const db_Escf4[] = { 4264Srgrimes "fnstsw","", "", "", "", "", "", "" 4274Srgrimes}; 4284Srgrimes 42914887Swollmanstatic const struct finst db_Esc8[] = { 4304Srgrimes/*0*/ { "fadd", SNGL, op2(STI,ST), 0 }, 4314Srgrimes/*1*/ { "fmul", SNGL, op2(STI,ST), 0 }, 4324Srgrimes/*2*/ { "fcom", SNGL, op2(STI,ST), 0 }, 4334Srgrimes/*3*/ { "fcomp", SNGL, op2(STI,ST), 0 }, 4344Srgrimes/*4*/ { "fsub", SNGL, op2(STI,ST), 0 }, 4354Srgrimes/*5*/ { "fsubr", SNGL, op2(STI,ST), 0 }, 4364Srgrimes/*6*/ { "fdiv", SNGL, op2(STI,ST), 0 }, 4374Srgrimes/*7*/ { "fdivr", SNGL, op2(STI,ST), 0 }, 4384Srgrimes}; 4394Srgrimes 44014887Swollmanstatic const struct finst db_Esc9[] = { 4414Srgrimes/*0*/ { "fld", SNGL, op1(STI), 0 }, 4424Srgrimes/*1*/ { "", NONE, op1(STI), "fxch" }, 44317109Sbde/*2*/ { "fst", SNGL, op1(X), db_Esc92 }, 44421277Sbde/*3*/ { "fstp", SNGL, 0, 0 }, 44517109Sbde/*4*/ { "fldenv", NONE, op1(X), db_Esc94 }, 44617109Sbde/*5*/ { "fldcw", NONE, op1(X), db_Esc95 }, 44717109Sbde/*6*/ { "fnstenv",NONE, op1(X), db_Esc96 }, 44817109Sbde/*7*/ { "fnstcw", NONE, op1(X), db_Esc97 }, 4494Srgrimes}; 4504Srgrimes 45114887Swollmanstatic const struct finst db_Esca[] = { 45221277Sbde/*0*/ { "fiadd", LONG, 0, 0 }, 45321277Sbde/*1*/ { "fimul", LONG, 0, 0 }, 45421277Sbde/*2*/ { "ficom", LONG, 0, 0 }, 45521277Sbde/*3*/ { "ficomp", LONG, 0, 0 }, 45621277Sbde/*4*/ { "fisub", LONG, 0, 0 }, 45721277Sbde/*5*/ { "fisubr", LONG, op1(X), db_Esca5 }, 45821277Sbde/*6*/ { "fidiv", LONG, 0, 0 }, 45921277Sbde/*7*/ { "fidivr", LONG, 0, 0 } 4604Srgrimes}; 4614Srgrimes 46214887Swollmanstatic const struct finst db_Escb[] = { 46321277Sbde/*0*/ { "fild", LONG, 0, 0 }, 4644Srgrimes/*1*/ { "", NONE, 0, 0 }, 46521277Sbde/*2*/ { "fist", LONG, 0, 0 }, 46621277Sbde/*3*/ { "fistp", LONG, 0, 0 }, 46717109Sbde/*4*/ { "", WORD, op1(X), db_Escb4 }, 4684Srgrimes/*5*/ { "fld", EXTR, 0, 0 }, 4694Srgrimes/*6*/ { "", WORD, 0, 0 }, 4704Srgrimes/*7*/ { "fstp", EXTR, 0, 0 }, 4714Srgrimes}; 4724Srgrimes 47314887Swollmanstatic const struct finst db_Escc[] = { 4744Srgrimes/*0*/ { "fadd", DBLR, op2(ST,STI), 0 }, 4754Srgrimes/*1*/ { "fmul", DBLR, op2(ST,STI), 0 }, 47621277Sbde/*2*/ { "fcom", DBLR, 0, 0 }, 47721277Sbde/*3*/ { "fcomp", DBLR, 0, 0 }, 4784Srgrimes/*4*/ { "fsub", DBLR, op2(ST,STI), "fsubr" }, 4794Srgrimes/*5*/ { "fsubr", DBLR, op2(ST,STI), "fsub" }, 4804Srgrimes/*6*/ { "fdiv", DBLR, op2(ST,STI), "fdivr" }, 4814Srgrimes/*7*/ { "fdivr", DBLR, op2(ST,STI), "fdiv" }, 4824Srgrimes}; 4834Srgrimes 48414887Swollmanstatic const struct finst db_Escd[] = { 4854Srgrimes/*0*/ { "fld", DBLR, op1(STI), "ffree" }, 4864Srgrimes/*1*/ { "", NONE, 0, 0 }, 4874Srgrimes/*2*/ { "fst", DBLR, op1(STI), 0 }, 4884Srgrimes/*3*/ { "fstp", DBLR, op1(STI), 0 }, 4894Srgrimes/*4*/ { "frstor", NONE, op1(STI), "fucom" }, 4904Srgrimes/*5*/ { "", NONE, op1(STI), "fucomp" }, 4914Srgrimes/*6*/ { "fnsave", NONE, 0, 0 }, 4924Srgrimes/*7*/ { "fnstsw", NONE, 0, 0 }, 4934Srgrimes}; 4944Srgrimes 49514887Swollmanstatic const struct finst db_Esce[] = { 49621277Sbde/*0*/ { "fiadd", WORD, op2(ST,STI), "faddp" }, 49721277Sbde/*1*/ { "fimul", WORD, op2(ST,STI), "fmulp" }, 49821277Sbde/*2*/ { "ficom", WORD, 0, 0 }, 49921277Sbde/*3*/ { "ficomp", WORD, op1(X), db_Esce3 }, 50021277Sbde/*4*/ { "fisub", WORD, op2(ST,STI), "fsubrp" }, 50121277Sbde/*5*/ { "fisubr", WORD, op2(ST,STI), "fsubp" }, 50221277Sbde/*6*/ { "fidiv", WORD, op2(ST,STI), "fdivrp" }, 50321277Sbde/*7*/ { "fidivr", WORD, op2(ST,STI), "fdivp" }, 5044Srgrimes}; 5054Srgrimes 50614887Swollmanstatic const struct finst db_Escf[] = { 50721277Sbde/*0*/ { "fild", WORD, 0, 0 }, 50821277Sbde/*1*/ { "", NONE, 0, 0 }, 50921277Sbde/*2*/ { "fist", WORD, 0, 0 }, 51021277Sbde/*3*/ { "fistp", WORD, 0, 0 }, 51117109Sbde/*4*/ { "fbld", NONE, op1(XA), db_Escf4 }, 51221277Sbde/*5*/ { "fild", QUAD, 0, 0 }, 5134Srgrimes/*6*/ { "fbstp", NONE, 0, 0 }, 51421277Sbde/*7*/ { "fistp", QUAD, 0, 0 }, 5154Srgrimes}; 5164Srgrimes 51717109Sbdestatic const struct finst * const db_Esc_inst[] = { 5184Srgrimes db_Esc8, db_Esc9, db_Esca, db_Escb, 5194Srgrimes db_Escc, db_Escd, db_Esce, db_Escf 5204Srgrimes}; 5214Srgrimes 52214887Swollmanstatic const char * const db_Grp1[] = { 5234Srgrimes "add", 5244Srgrimes "or", 5254Srgrimes "adc", 5264Srgrimes "sbb", 5274Srgrimes "and", 5284Srgrimes "sub", 5294Srgrimes "xor", 5304Srgrimes "cmp" 5314Srgrimes}; 5324Srgrimes 53314887Swollmanstatic const char * const db_Grp2[] = { 5344Srgrimes "rol", 5354Srgrimes "ror", 5364Srgrimes "rcl", 5374Srgrimes "rcr", 5384Srgrimes "shl", 5394Srgrimes "shr", 5404Srgrimes "shl", 5414Srgrimes "sar" 5424Srgrimes}; 5434Srgrimes 54414887Swollmanstatic const struct inst db_Grp3[] = { 5454Srgrimes { "test", TRUE, NONE, op2(I,E), 0 }, 5464Srgrimes { "test", TRUE, NONE, op2(I,E), 0 }, 5474Srgrimes { "not", TRUE, NONE, op1(E), 0 }, 5484Srgrimes { "neg", TRUE, NONE, op1(E), 0 }, 5494Srgrimes { "mul", TRUE, NONE, op2(E,A), 0 }, 5504Srgrimes { "imul", TRUE, NONE, op2(E,A), 0 }, 5514Srgrimes { "div", TRUE, NONE, op2(E,A), 0 }, 5524Srgrimes { "idiv", TRUE, NONE, op2(E,A), 0 }, 5534Srgrimes}; 5544Srgrimes 55517109Sbdestatic const struct inst db_Grp4[] = { 5564Srgrimes { "inc", TRUE, BYTE, op1(E), 0 }, 5574Srgrimes { "dec", TRUE, BYTE, op1(E), 0 }, 5584Srgrimes { "", TRUE, NONE, 0, 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}; 5654Srgrimes 56617109Sbdestatic const struct inst db_Grp5[] = { 5674Srgrimes { "inc", TRUE, LONG, op1(E), 0 }, 5684Srgrimes { "dec", TRUE, LONG, op1(E), 0 }, 56921277Sbde { "call", TRUE, LONG, op1(Eind),0 }, 57021277Sbde { "lcall", TRUE, LONG, op1(Eind),0 }, 57121277Sbde { "jmp", TRUE, LONG, op1(Eind),0 }, 57221277Sbde { "ljmp", TRUE, LONG, op1(Eind),0 }, 5734Srgrimes { "push", TRUE, LONG, op1(E), 0 }, 5744Srgrimes { "", TRUE, NONE, 0, 0 } 5754Srgrimes}; 5764Srgrimes 57714887Swollmanstatic const struct inst db_inst_table[256] = { 5784Srgrimes/*00*/ { "add", TRUE, BYTE, op2(R, E), 0 }, 5794Srgrimes/*01*/ { "add", TRUE, LONG, op2(R, E), 0 }, 5804Srgrimes/*02*/ { "add", TRUE, BYTE, op2(E, R), 0 }, 5814Srgrimes/*03*/ { "add", TRUE, LONG, op2(E, R), 0 }, 58221277Sbde/*04*/ { "add", FALSE, BYTE, op2(I, A), 0 }, 5834Srgrimes/*05*/ { "add", FALSE, LONG, op2(Is, A), 0 }, 5844Srgrimes/*06*/ { "push", FALSE, NONE, op1(Si), 0 }, 5854Srgrimes/*07*/ { "pop", FALSE, NONE, op1(Si), 0 }, 5864Srgrimes 5874Srgrimes/*08*/ { "or", TRUE, BYTE, op2(R, E), 0 }, 5884Srgrimes/*09*/ { "or", TRUE, LONG, op2(R, E), 0 }, 5894Srgrimes/*0a*/ { "or", TRUE, BYTE, op2(E, R), 0 }, 5904Srgrimes/*0b*/ { "or", TRUE, LONG, op2(E, R), 0 }, 5914Srgrimes/*0c*/ { "or", FALSE, BYTE, op2(I, A), 0 }, 5924Srgrimes/*0d*/ { "or", FALSE, LONG, op2(I, A), 0 }, 5934Srgrimes/*0e*/ { "push", FALSE, NONE, op1(Si), 0 }, 5944Srgrimes/*0f*/ { "", FALSE, NONE, 0, 0 }, 5954Srgrimes 5964Srgrimes/*10*/ { "adc", TRUE, BYTE, op2(R, E), 0 }, 5974Srgrimes/*11*/ { "adc", TRUE, LONG, op2(R, E), 0 }, 5984Srgrimes/*12*/ { "adc", TRUE, BYTE, op2(E, R), 0 }, 5994Srgrimes/*13*/ { "adc", TRUE, LONG, op2(E, R), 0 }, 60021277Sbde/*14*/ { "adc", FALSE, BYTE, op2(I, A), 0 }, 6014Srgrimes/*15*/ { "adc", FALSE, LONG, op2(Is, A), 0 }, 6024Srgrimes/*16*/ { "push", FALSE, NONE, op1(Si), 0 }, 6034Srgrimes/*17*/ { "pop", FALSE, NONE, op1(Si), 0 }, 6044Srgrimes 6054Srgrimes/*18*/ { "sbb", TRUE, BYTE, op2(R, E), 0 }, 6064Srgrimes/*19*/ { "sbb", TRUE, LONG, op2(R, E), 0 }, 6074Srgrimes/*1a*/ { "sbb", TRUE, BYTE, op2(E, R), 0 }, 6084Srgrimes/*1b*/ { "sbb", TRUE, LONG, op2(E, R), 0 }, 60921277Sbde/*1c*/ { "sbb", FALSE, BYTE, op2(I, A), 0 }, 6104Srgrimes/*1d*/ { "sbb", FALSE, LONG, op2(Is, A), 0 }, 6114Srgrimes/*1e*/ { "push", FALSE, NONE, op1(Si), 0 }, 6124Srgrimes/*1f*/ { "pop", FALSE, NONE, op1(Si), 0 }, 6134Srgrimes 6144Srgrimes/*20*/ { "and", TRUE, BYTE, op2(R, E), 0 }, 6154Srgrimes/*21*/ { "and", TRUE, LONG, op2(R, E), 0 }, 6164Srgrimes/*22*/ { "and", TRUE, BYTE, op2(E, R), 0 }, 6174Srgrimes/*23*/ { "and", TRUE, LONG, op2(E, R), 0 }, 6184Srgrimes/*24*/ { "and", FALSE, BYTE, op2(I, A), 0 }, 6194Srgrimes/*25*/ { "and", FALSE, LONG, op2(I, A), 0 }, 6204Srgrimes/*26*/ { "", FALSE, NONE, 0, 0 }, 62121277Sbde/*27*/ { "daa", FALSE, NONE, 0, 0 }, 6224Srgrimes 6234Srgrimes/*28*/ { "sub", TRUE, BYTE, op2(R, E), 0 }, 6244Srgrimes/*29*/ { "sub", TRUE, LONG, op2(R, E), 0 }, 6254Srgrimes/*2a*/ { "sub", TRUE, BYTE, op2(E, R), 0 }, 6264Srgrimes/*2b*/ { "sub", TRUE, LONG, op2(E, R), 0 }, 62721277Sbde/*2c*/ { "sub", FALSE, BYTE, op2(I, A), 0 }, 6284Srgrimes/*2d*/ { "sub", FALSE, LONG, op2(Is, A), 0 }, 6294Srgrimes/*2e*/ { "", FALSE, NONE, 0, 0 }, 6304Srgrimes/*2f*/ { "das", FALSE, NONE, 0, 0 }, 6314Srgrimes 6324Srgrimes/*30*/ { "xor", TRUE, BYTE, op2(R, E), 0 }, 6334Srgrimes/*31*/ { "xor", TRUE, LONG, op2(R, E), 0 }, 6344Srgrimes/*32*/ { "xor", TRUE, BYTE, op2(E, R), 0 }, 6354Srgrimes/*33*/ { "xor", TRUE, LONG, op2(E, R), 0 }, 6364Srgrimes/*34*/ { "xor", FALSE, BYTE, op2(I, A), 0 }, 6374Srgrimes/*35*/ { "xor", FALSE, LONG, op2(I, A), 0 }, 6384Srgrimes/*36*/ { "", FALSE, NONE, 0, 0 }, 63921277Sbde/*37*/ { "aaa", FALSE, NONE, 0, 0 }, 6404Srgrimes 6414Srgrimes/*38*/ { "cmp", TRUE, BYTE, op2(R, E), 0 }, 6424Srgrimes/*39*/ { "cmp", TRUE, LONG, op2(R, E), 0 }, 6434Srgrimes/*3a*/ { "cmp", TRUE, BYTE, op2(E, R), 0 }, 6444Srgrimes/*3b*/ { "cmp", TRUE, LONG, op2(E, R), 0 }, 64521277Sbde/*3c*/ { "cmp", FALSE, BYTE, op2(I, A), 0 }, 6464Srgrimes/*3d*/ { "cmp", FALSE, LONG, op2(Is, A), 0 }, 6474Srgrimes/*3e*/ { "", FALSE, NONE, 0, 0 }, 6484Srgrimes/*3f*/ { "aas", FALSE, NONE, 0, 0 }, 6494Srgrimes 6504Srgrimes/*40*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6514Srgrimes/*41*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6524Srgrimes/*42*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6534Srgrimes/*43*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6544Srgrimes/*44*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6554Srgrimes/*45*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6564Srgrimes/*46*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6574Srgrimes/*47*/ { "inc", FALSE, LONG, op1(Ri), 0 }, 6584Srgrimes 6594Srgrimes/*48*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6604Srgrimes/*49*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6614Srgrimes/*4a*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6624Srgrimes/*4b*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6634Srgrimes/*4c*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6644Srgrimes/*4d*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6654Srgrimes/*4e*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6664Srgrimes/*4f*/ { "dec", FALSE, LONG, op1(Ri), 0 }, 6674Srgrimes 6684Srgrimes/*50*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6694Srgrimes/*51*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6704Srgrimes/*52*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6714Srgrimes/*53*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6724Srgrimes/*54*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6734Srgrimes/*55*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6744Srgrimes/*56*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6754Srgrimes/*57*/ { "push", FALSE, LONG, op1(Ri), 0 }, 6764Srgrimes 6774Srgrimes/*58*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6784Srgrimes/*59*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6794Srgrimes/*5a*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6804Srgrimes/*5b*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6814Srgrimes/*5c*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6824Srgrimes/*5d*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6834Srgrimes/*5e*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6844Srgrimes/*5f*/ { "pop", FALSE, LONG, op1(Ri), 0 }, 6854Srgrimes 6864Srgrimes/*60*/ { "pusha", FALSE, LONG, 0, 0 }, 6874Srgrimes/*61*/ { "popa", FALSE, LONG, 0, 0 }, 6884Srgrimes/*62*/ { "bound", TRUE, LONG, op2(E, R), 0 }, 68921277Sbde/*63*/ { "arpl", TRUE, NONE, op2(Rw,Ew), 0 }, 6904Srgrimes 6914Srgrimes/*64*/ { "", FALSE, NONE, 0, 0 }, 6924Srgrimes/*65*/ { "", FALSE, NONE, 0, 0 }, 6934Srgrimes/*66*/ { "", FALSE, NONE, 0, 0 }, 6944Srgrimes/*67*/ { "", FALSE, NONE, 0, 0 }, 6954Srgrimes 6964Srgrimes/*68*/ { "push", FALSE, LONG, op1(I), 0 }, 6974Srgrimes/*69*/ { "imul", TRUE, LONG, op3(I,E,R), 0 }, 69821277Sbde/*6a*/ { "push", FALSE, LONG, op1(Ibs), 0 }, 6994Srgrimes/*6b*/ { "imul", TRUE, LONG, op3(Ibs,E,R),0 }, 7004Srgrimes/*6c*/ { "ins", FALSE, BYTE, op2(DX, DI), 0 }, 7014Srgrimes/*6d*/ { "ins", FALSE, LONG, op2(DX, DI), 0 }, 7024Srgrimes/*6e*/ { "outs", FALSE, BYTE, op2(SI, DX), 0 }, 7034Srgrimes/*6f*/ { "outs", FALSE, LONG, op2(SI, DX), 0 }, 7044Srgrimes 7054Srgrimes/*70*/ { "jo", FALSE, NONE, op1(Db), 0 }, 7064Srgrimes/*71*/ { "jno", FALSE, NONE, op1(Db), 0 }, 7074Srgrimes/*72*/ { "jb", FALSE, NONE, op1(Db), 0 }, 7084Srgrimes/*73*/ { "jnb", FALSE, NONE, op1(Db), 0 }, 7094Srgrimes/*74*/ { "jz", FALSE, NONE, op1(Db), 0 }, 7104Srgrimes/*75*/ { "jnz", FALSE, NONE, op1(Db), 0 }, 7114Srgrimes/*76*/ { "jbe", FALSE, NONE, op1(Db), 0 }, 7124Srgrimes/*77*/ { "jnbe", FALSE, NONE, op1(Db), 0 }, 7134Srgrimes 7144Srgrimes/*78*/ { "js", FALSE, NONE, op1(Db), 0 }, 7154Srgrimes/*79*/ { "jns", FALSE, NONE, op1(Db), 0 }, 7164Srgrimes/*7a*/ { "jp", FALSE, NONE, op1(Db), 0 }, 7174Srgrimes/*7b*/ { "jnp", FALSE, NONE, op1(Db), 0 }, 7184Srgrimes/*7c*/ { "jl", FALSE, NONE, op1(Db), 0 }, 7194Srgrimes/*7d*/ { "jnl", FALSE, NONE, op1(Db), 0 }, 7204Srgrimes/*7e*/ { "jle", FALSE, NONE, op1(Db), 0 }, 7214Srgrimes/*7f*/ { "jnle", FALSE, NONE, op1(Db), 0 }, 7224Srgrimes 72317109Sbde/*80*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 }, 72417109Sbde/*81*/ { "", TRUE, LONG, op2(I, E), db_Grp1 }, 72521277Sbde/*82*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 }, 72617109Sbde/*83*/ { "", TRUE, LONG, op2(Ibs,E), db_Grp1 }, 7274Srgrimes/*84*/ { "test", TRUE, BYTE, op2(R, E), 0 }, 7284Srgrimes/*85*/ { "test", TRUE, LONG, op2(R, E), 0 }, 7294Srgrimes/*86*/ { "xchg", TRUE, BYTE, op2(R, E), 0 }, 7304Srgrimes/*87*/ { "xchg", TRUE, LONG, op2(R, E), 0 }, 7314Srgrimes 7324Srgrimes/*88*/ { "mov", TRUE, BYTE, op2(R, E), 0 }, 7334Srgrimes/*89*/ { "mov", TRUE, LONG, op2(R, E), 0 }, 7344Srgrimes/*8a*/ { "mov", TRUE, BYTE, op2(E, R), 0 }, 7354Srgrimes/*8b*/ { "mov", TRUE, LONG, op2(E, R), 0 }, 7364Srgrimes/*8c*/ { "mov", TRUE, NONE, op2(S, Ew), 0 }, 7374Srgrimes/*8d*/ { "lea", TRUE, LONG, op2(E, R), 0 }, 7384Srgrimes/*8e*/ { "mov", TRUE, NONE, op2(Ew, S), 0 }, 7394Srgrimes/*8f*/ { "pop", TRUE, LONG, op1(E), 0 }, 7404Srgrimes 7414Srgrimes/*90*/ { "nop", FALSE, NONE, 0, 0 }, 7424Srgrimes/*91*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7434Srgrimes/*92*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7444Srgrimes/*93*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7454Srgrimes/*94*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7464Srgrimes/*95*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7474Srgrimes/*96*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7484Srgrimes/*97*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 }, 7494Srgrimes 7504Srgrimes/*98*/ { "cbw", FALSE, SDEP, 0, "cwde" }, /* cbw/cwde */ 7514Srgrimes/*99*/ { "cwd", FALSE, SDEP, 0, "cdq" }, /* cwd/cdq */ 7524Srgrimes/*9a*/ { "lcall", FALSE, NONE, op1(OS), 0 }, 7534Srgrimes/*9b*/ { "wait", FALSE, NONE, 0, 0 }, 7544Srgrimes/*9c*/ { "pushf", FALSE, LONG, 0, 0 }, 7554Srgrimes/*9d*/ { "popf", FALSE, LONG, 0, 0 }, 7564Srgrimes/*9e*/ { "sahf", FALSE, NONE, 0, 0 }, 7574Srgrimes/*9f*/ { "lahf", FALSE, NONE, 0, 0 }, 7584Srgrimes 7594Srgrimes/*a0*/ { "mov", FALSE, BYTE, op2(O, A), 0 }, 7604Srgrimes/*a1*/ { "mov", FALSE, LONG, op2(O, A), 0 }, 7614Srgrimes/*a2*/ { "mov", FALSE, BYTE, op2(A, O), 0 }, 7624Srgrimes/*a3*/ { "mov", FALSE, LONG, op2(A, O), 0 }, 7634Srgrimes/*a4*/ { "movs", FALSE, BYTE, op2(SI,DI), 0 }, 7644Srgrimes/*a5*/ { "movs", FALSE, LONG, op2(SI,DI), 0 }, 7654Srgrimes/*a6*/ { "cmps", FALSE, BYTE, op2(SI,DI), 0 }, 7664Srgrimes/*a7*/ { "cmps", FALSE, LONG, op2(SI,DI), 0 }, 7674Srgrimes 7684Srgrimes/*a8*/ { "test", FALSE, BYTE, op2(I, A), 0 }, 7694Srgrimes/*a9*/ { "test", FALSE, LONG, op2(I, A), 0 }, 7704Srgrimes/*aa*/ { "stos", FALSE, BYTE, op1(DI), 0 }, 7714Srgrimes/*ab*/ { "stos", FALSE, LONG, op1(DI), 0 }, 772118Srgrimes/*ac*/ { "lods", FALSE, BYTE, op1(SI), 0 }, 773118Srgrimes/*ad*/ { "lods", FALSE, LONG, op1(SI), 0 }, 7744Srgrimes/*ae*/ { "scas", FALSE, BYTE, op1(SI), 0 }, 7754Srgrimes/*af*/ { "scas", FALSE, LONG, op1(SI), 0 }, 7764Srgrimes 7774Srgrimes/*b0*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7784Srgrimes/*b1*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7794Srgrimes/*b2*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7804Srgrimes/*b3*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7814Srgrimes/*b4*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7824Srgrimes/*b5*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7834Srgrimes/*b6*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7844Srgrimes/*b7*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 }, 7854Srgrimes 7864Srgrimes/*b8*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7874Srgrimes/*b9*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7884Srgrimes/*ba*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7894Srgrimes/*bb*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7904Srgrimes/*bc*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7914Srgrimes/*bd*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7924Srgrimes/*be*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7934Srgrimes/*bf*/ { "mov", FALSE, LONG, op2(I, Ri), 0 }, 7944Srgrimes 79517109Sbde/*c0*/ { "", TRUE, BYTE, op2(Ib, E), db_Grp2 }, 79617109Sbde/*c1*/ { "", TRUE, LONG, op2(Ib, E), db_Grp2 }, 7974Srgrimes/*c2*/ { "ret", FALSE, NONE, op1(Iw), 0 }, 7984Srgrimes/*c3*/ { "ret", FALSE, NONE, 0, 0 }, 7994Srgrimes/*c4*/ { "les", TRUE, LONG, op2(E, R), 0 }, 8004Srgrimes/*c5*/ { "lds", TRUE, LONG, op2(E, R), 0 }, 8014Srgrimes/*c6*/ { "mov", TRUE, BYTE, op2(I, E), 0 }, 8024Srgrimes/*c7*/ { "mov", TRUE, LONG, op2(I, E), 0 }, 8034Srgrimes 80421277Sbde/*c8*/ { "enter", FALSE, NONE, op2(Iw, Ib), 0 }, 805270844Spfg/*c9*/ { "leave", FALSE, NONE, 0, 0 }, 8064Srgrimes/*ca*/ { "lret", FALSE, NONE, op1(Iw), 0 }, 8074Srgrimes/*cb*/ { "lret", FALSE, NONE, 0, 0 }, 8084Srgrimes/*cc*/ { "int", FALSE, NONE, op1(o3), 0 }, 8094Srgrimes/*cd*/ { "int", FALSE, NONE, op1(Ib), 0 }, 8104Srgrimes/*ce*/ { "into", FALSE, NONE, 0, 0 }, 8114Srgrimes/*cf*/ { "iret", FALSE, NONE, 0, 0 }, 8124Srgrimes 81317109Sbde/*d0*/ { "", TRUE, BYTE, op2(o1, E), db_Grp2 }, 81417109Sbde/*d1*/ { "", TRUE, LONG, op2(o1, E), db_Grp2 }, 81517109Sbde/*d2*/ { "", TRUE, BYTE, op2(CL, E), db_Grp2 }, 81617109Sbde/*d3*/ { "", TRUE, LONG, op2(CL, E), db_Grp2 }, 81721277Sbde/*d4*/ { "aam", FALSE, NONE, op1(Iba), 0 }, 81821277Sbde/*d5*/ { "aad", FALSE, NONE, op1(Iba), 0 }, 81921277Sbde/*d6*/ { ".byte\t0xd6", FALSE, NONE, 0, 0 }, 8204Srgrimes/*d7*/ { "xlat", FALSE, BYTE, op1(BX), 0 }, 8214Srgrimes 82217109Sbde/*d8*/ { "", TRUE, NONE, 0, db_Esc8 }, 82317109Sbde/*d9*/ { "", TRUE, NONE, 0, db_Esc9 }, 82417109Sbde/*da*/ { "", TRUE, NONE, 0, db_Esca }, 82517109Sbde/*db*/ { "", TRUE, NONE, 0, db_Escb }, 82617109Sbde/*dc*/ { "", TRUE, NONE, 0, db_Escc }, 82717109Sbde/*dd*/ { "", TRUE, NONE, 0, db_Escd }, 82817109Sbde/*de*/ { "", TRUE, NONE, 0, db_Esce }, 82917109Sbde/*df*/ { "", TRUE, NONE, 0, db_Escf }, 8304Srgrimes 8314Srgrimes/*e0*/ { "loopne",FALSE, NONE, op1(Db), 0 }, 8324Srgrimes/*e1*/ { "loope", FALSE, NONE, op1(Db), 0 }, 8334Srgrimes/*e2*/ { "loop", FALSE, NONE, op1(Db), 0 }, 8344Srgrimes/*e3*/ { "jcxz", FALSE, SDEP, op1(Db), "jecxz" }, 8354Srgrimes/*e4*/ { "in", FALSE, BYTE, op2(Ib, A), 0 }, 8364Srgrimes/*e5*/ { "in", FALSE, LONG, op2(Ib, A) , 0 }, 8374Srgrimes/*e6*/ { "out", FALSE, BYTE, op2(A, Ib), 0 }, 8384Srgrimes/*e7*/ { "out", FALSE, LONG, op2(A, Ib) , 0 }, 8394Srgrimes 8404Srgrimes/*e8*/ { "call", FALSE, NONE, op1(Dl), 0 }, 8414Srgrimes/*e9*/ { "jmp", FALSE, NONE, op1(Dl), 0 }, 8424Srgrimes/*ea*/ { "ljmp", FALSE, NONE, op1(OS), 0 }, 8434Srgrimes/*eb*/ { "jmp", FALSE, NONE, op1(Db), 0 }, 8444Srgrimes/*ec*/ { "in", FALSE, BYTE, op2(DX, A), 0 }, 8454Srgrimes/*ed*/ { "in", FALSE, LONG, op2(DX, A) , 0 }, 8464Srgrimes/*ee*/ { "out", FALSE, BYTE, op2(A, DX), 0 }, 8474Srgrimes/*ef*/ { "out", FALSE, LONG, op2(A, DX) , 0 }, 8484Srgrimes 8494Srgrimes/*f0*/ { "", FALSE, NONE, 0, 0 }, 85021277Sbde/*f1*/ { ".byte\t0xf1", FALSE, NONE, 0, 0 }, 8514Srgrimes/*f2*/ { "", FALSE, NONE, 0, 0 }, 8524Srgrimes/*f3*/ { "", FALSE, NONE, 0, 0 }, 8534Srgrimes/*f4*/ { "hlt", FALSE, NONE, 0, 0 }, 8544Srgrimes/*f5*/ { "cmc", FALSE, NONE, 0, 0 }, 85517109Sbde/*f6*/ { "", TRUE, BYTE, 0, db_Grp3 }, 85617109Sbde/*f7*/ { "", TRUE, LONG, 0, db_Grp3 }, 8574Srgrimes 8584Srgrimes/*f8*/ { "clc", FALSE, NONE, 0, 0 }, 8594Srgrimes/*f9*/ { "stc", FALSE, NONE, 0, 0 }, 8604Srgrimes/*fa*/ { "cli", FALSE, NONE, 0, 0 }, 8614Srgrimes/*fb*/ { "sti", FALSE, NONE, 0, 0 }, 8624Srgrimes/*fc*/ { "cld", FALSE, NONE, 0, 0 }, 8634Srgrimes/*fd*/ { "std", FALSE, NONE, 0, 0 }, 86417109Sbde/*fe*/ { "", TRUE, NONE, 0, db_Grp4 }, 86517109Sbde/*ff*/ { "", TRUE, NONE, 0, db_Grp5 }, 8664Srgrimes}; 8674Srgrimes 86817109Sbdestatic const struct inst db_bad_inst = 8694Srgrimes { "???", FALSE, NONE, 0, 0 } 8704Srgrimes; 8714Srgrimes 8724Srgrimes#define f_mod(byte) ((byte)>>6) 8734Srgrimes#define f_reg(byte) (((byte)>>3)&0x7) 8744Srgrimes#define f_rm(byte) ((byte)&0x7) 8754Srgrimes 8764Srgrimes#define sib_ss(byte) ((byte)>>6) 8774Srgrimes#define sib_index(byte) (((byte)>>3)&0x7) 8784Srgrimes#define sib_base(byte) ((byte)&0x7) 8794Srgrimes 88011940Sbdestruct i_addr { 8814Srgrimes int is_reg; /* if reg, reg number is in 'disp' */ 8824Srgrimes int disp; 88314887Swollman const char * base; 88414887Swollman const char * index; 8854Srgrimes int ss; 8864Srgrimes}; 8874Srgrimes 88814887Swollmanstatic const char * const db_index_reg_16[8] = { 8894Srgrimes "%bx,%si", 8904Srgrimes "%bx,%di", 8914Srgrimes "%bp,%si", 8924Srgrimes "%bp,%di", 8934Srgrimes "%si", 8944Srgrimes "%di", 8954Srgrimes "%bp", 8964Srgrimes "%bx" 8974Srgrimes}; 8984Srgrimes 89914887Swollmanstatic const char * const db_reg[3][8] = { 90043314Sdillon { "%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh" }, 90143314Sdillon { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di" }, 90243314Sdillon { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi" } 9034Srgrimes}; 9044Srgrimes 90517109Sbdestatic const char * const db_seg_reg[8] = { 9064Srgrimes "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", "" 9074Srgrimes}; 9084Srgrimes 9094Srgrimes/* 9104Srgrimes * lengths for size attributes 9114Srgrimes */ 91214887Swollmanstatic const int db_lengths[] = { 9134Srgrimes 1, /* BYTE */ 9144Srgrimes 2, /* WORD */ 9154Srgrimes 4, /* LONG */ 9164Srgrimes 8, /* QUAD */ 9174Srgrimes 4, /* SNGL */ 9184Srgrimes 8, /* DBLR */ 9194Srgrimes 10, /* EXTR */ 9204Srgrimes}; 9214Srgrimes 9224Srgrimes#define get_value_inc(result, loc, size, is_signed) \ 9234Srgrimes result = db_get_value((loc), (size), (is_signed)); \ 9244Srgrimes (loc) += (size); 9254Srgrimes 92611940Sbdestatic db_addr_t 92792770Salfred db_disasm_esc(db_addr_t loc, int inst, int short_addr, 92893017Sbde int size, const char *seg); 92992770Salfredstatic void db_print_address(const char *seg, int size, 93093017Sbde struct i_addr *addrp); 93111940Sbdestatic db_addr_t 93293017Sbde db_read_address(db_addr_t loc, int short_addr, int regmodrm, 93393017Sbde struct i_addr *addrp); 93411940Sbde 9354Srgrimes/* 9364Srgrimes * Read address at location and return updated location. 9374Srgrimes */ 93811921Sphkstatic db_addr_t 9394Srgrimesdb_read_address(loc, short_addr, regmodrm, addrp) 9404Srgrimes db_addr_t loc; 9414Srgrimes int short_addr; 9424Srgrimes int regmodrm; 94317109Sbde struct i_addr * addrp; /* out */ 9444Srgrimes{ 9453436Sphk int mod, rm, sib, index, disp; 9464Srgrimes 9474Srgrimes mod = f_mod(regmodrm); 9484Srgrimes rm = f_rm(regmodrm); 9494Srgrimes 9504Srgrimes if (mod == 3) { 9514Srgrimes addrp->is_reg = TRUE; 9524Srgrimes addrp->disp = rm; 9534Srgrimes return (loc); 9544Srgrimes } 9554Srgrimes addrp->is_reg = FALSE; 956297974Spfg addrp->index = NULL; 9574Srgrimes 9584Srgrimes if (short_addr) { 959297974Spfg addrp->index = NULL; 9604Srgrimes addrp->ss = 0; 9614Srgrimes switch (mod) { 9624Srgrimes case 0: 9634Srgrimes if (rm == 6) { 96421277Sbde get_value_inc(disp, loc, 2, FALSE); 9654Srgrimes addrp->disp = disp; 966297974Spfg addrp->base = NULL; 9674Srgrimes } 9684Srgrimes else { 9694Srgrimes addrp->disp = 0; 9704Srgrimes addrp->base = db_index_reg_16[rm]; 9714Srgrimes } 9724Srgrimes break; 9734Srgrimes case 1: 9744Srgrimes get_value_inc(disp, loc, 1, TRUE); 97521277Sbde disp &= 0xFFFF; 9764Srgrimes addrp->disp = disp; 9774Srgrimes addrp->base = db_index_reg_16[rm]; 9784Srgrimes break; 9794Srgrimes case 2: 98021277Sbde get_value_inc(disp, loc, 2, FALSE); 9814Srgrimes addrp->disp = disp; 9824Srgrimes addrp->base = db_index_reg_16[rm]; 9834Srgrimes break; 9844Srgrimes } 9854Srgrimes } 9864Srgrimes else { 9874Srgrimes if (mod != 3 && rm == 4) { 9884Srgrimes get_value_inc(sib, loc, 1, FALSE); 9894Srgrimes rm = sib_base(sib); 9904Srgrimes index = sib_index(sib); 9914Srgrimes if (index != 4) 9924Srgrimes addrp->index = db_reg[LONG][index]; 9934Srgrimes addrp->ss = sib_ss(sib); 9944Srgrimes } 9954Srgrimes 9964Srgrimes switch (mod) { 9974Srgrimes case 0: 9984Srgrimes if (rm == 5) { 9994Srgrimes get_value_inc(addrp->disp, loc, 4, FALSE); 1000297974Spfg addrp->base = NULL; 10014Srgrimes } 10024Srgrimes else { 10034Srgrimes addrp->disp = 0; 10044Srgrimes addrp->base = db_reg[LONG][rm]; 10054Srgrimes } 10064Srgrimes break; 10074Srgrimes 10084Srgrimes case 1: 10094Srgrimes get_value_inc(disp, loc, 1, TRUE); 10104Srgrimes addrp->disp = disp; 10114Srgrimes addrp->base = db_reg[LONG][rm]; 10124Srgrimes break; 10134Srgrimes 10144Srgrimes case 2: 10154Srgrimes get_value_inc(disp, loc, 4, FALSE); 10164Srgrimes addrp->disp = disp; 10174Srgrimes addrp->base = db_reg[LONG][rm]; 10184Srgrimes break; 10194Srgrimes } 10204Srgrimes } 10214Srgrimes return (loc); 10224Srgrimes} 10234Srgrimes 102411921Sphkstatic void 10254Srgrimesdb_print_address(seg, size, addrp) 102617109Sbde const char * seg; 10274Srgrimes int size; 102817109Sbde struct i_addr * addrp; 10294Srgrimes{ 10304Srgrimes if (addrp->is_reg) { 10314Srgrimes db_printf("%s", db_reg[size][addrp->disp]); 10324Srgrimes return; 10334Srgrimes } 10344Srgrimes 10354Srgrimes if (seg) { 10364Srgrimes db_printf("%s:", seg); 10374Srgrimes } 10384Srgrimes 10394Srgrimes db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY); 1040297974Spfg if (addrp->base != NULL || addrp->index != NULL) { 10414Srgrimes db_printf("("); 10424Srgrimes if (addrp->base) 10434Srgrimes db_printf("%s", addrp->base); 10444Srgrimes if (addrp->index) 10454Srgrimes db_printf(",%s,%d", addrp->index, 1<<addrp->ss); 10464Srgrimes db_printf(")"); 10474Srgrimes } 10484Srgrimes} 10494Srgrimes 10504Srgrimes/* 10514Srgrimes * Disassemble floating-point ("escape") instruction 10524Srgrimes * and return updated location. 10534Srgrimes */ 105411921Sphkstatic db_addr_t 10554Srgrimesdb_disasm_esc(loc, inst, short_addr, size, seg) 10564Srgrimes db_addr_t loc; 10574Srgrimes int inst; 10584Srgrimes int short_addr; 10594Srgrimes int size; 106017109Sbde const char * seg; 10614Srgrimes{ 10624Srgrimes int regmodrm; 106317109Sbde const struct finst * fp; 10644Srgrimes int mod; 10654Srgrimes struct i_addr address; 106617109Sbde const char * name; 10674Srgrimes 10684Srgrimes get_value_inc(regmodrm, loc, 1, FALSE); 10694Srgrimes fp = &db_Esc_inst[inst - 0xd8][f_reg(regmodrm)]; 10704Srgrimes mod = f_mod(regmodrm); 10714Srgrimes if (mod != 3) { 107221277Sbde if (*fp->f_name == '\0') { 107321277Sbde db_printf("<bad instruction>"); 107421277Sbde return (loc); 107521277Sbde } 10764Srgrimes /* 10774Srgrimes * Normal address modes. 10784Srgrimes */ 10794Srgrimes loc = db_read_address(loc, short_addr, regmodrm, &address); 108079885Skris db_printf("%s", fp->f_name); 10814Srgrimes switch(fp->f_size) { 10824Srgrimes case SNGL: 10834Srgrimes db_printf("s"); 10844Srgrimes break; 10854Srgrimes case DBLR: 10864Srgrimes db_printf("l"); 10874Srgrimes break; 10884Srgrimes case EXTR: 10894Srgrimes db_printf("t"); 10904Srgrimes break; 10914Srgrimes case WORD: 10924Srgrimes db_printf("s"); 10934Srgrimes break; 10944Srgrimes case LONG: 10954Srgrimes db_printf("l"); 10964Srgrimes break; 10974Srgrimes case QUAD: 10984Srgrimes db_printf("q"); 10994Srgrimes break; 11004Srgrimes default: 11014Srgrimes break; 11024Srgrimes } 11034Srgrimes db_printf("\t"); 11044Srgrimes db_print_address(seg, BYTE, &address); 11054Srgrimes } 11064Srgrimes else { 11074Srgrimes /* 11084Srgrimes * 'reg-reg' - special formats 11094Srgrimes */ 11104Srgrimes switch (fp->f_rrmode) { 11114Srgrimes case op2(ST,STI): 11124Srgrimes name = (fp->f_rrname) ? fp->f_rrname : fp->f_name; 11134Srgrimes db_printf("%s\t%%st,%%st(%d)",name,f_rm(regmodrm)); 11144Srgrimes break; 11154Srgrimes case op2(STI,ST): 11164Srgrimes name = (fp->f_rrname) ? fp->f_rrname : fp->f_name; 11174Srgrimes db_printf("%s\t%%st(%d),%%st",name, f_rm(regmodrm)); 11184Srgrimes break; 11194Srgrimes case op1(STI): 11204Srgrimes name = (fp->f_rrname) ? fp->f_rrname : fp->f_name; 11214Srgrimes db_printf("%s\t%%st(%d)",name, f_rm(regmodrm)); 11224Srgrimes break; 11234Srgrimes case op1(X): 112421277Sbde name = ((const char * const *)fp->f_rrname)[f_rm(regmodrm)]; 112521277Sbde if (*name == '\0') 112621277Sbde goto bad; 112721277Sbde db_printf("%s", name); 11284Srgrimes break; 11294Srgrimes case op1(XA): 113021277Sbde name = ((const char * const *)fp->f_rrname)[f_rm(regmodrm)]; 113121277Sbde if (*name == '\0') 113221277Sbde goto bad; 113321277Sbde db_printf("%s\t%%ax", name); 11344Srgrimes break; 11354Srgrimes default: 113621277Sbde bad: 11374Srgrimes db_printf("<bad instruction>"); 11384Srgrimes break; 11394Srgrimes } 11404Srgrimes } 11414Srgrimes 11424Srgrimes return (loc); 11434Srgrimes} 11444Srgrimes 11454Srgrimes/* 11464Srgrimes * Disassemble instruction at 'loc'. 'altfmt' specifies an 11474Srgrimes * (optional) alternate format. Return address of start of 11484Srgrimes * next instruction. 11494Srgrimes */ 11504Srgrimesdb_addr_t 1151283248Spfgdb_disasm(db_addr_t loc, bool altfmt) 11524Srgrimes{ 11534Srgrimes int inst; 11544Srgrimes int size; 11554Srgrimes int short_addr; 115617109Sbde const char * seg; 115714887Swollman const struct inst * ip; 115814887Swollman const char * i_name; 11594Srgrimes int i_size; 11604Srgrimes int i_mode; 1161798Swollman int regmodrm = 0; 11624Srgrimes boolean_t first; 11634Srgrimes int displ; 11644Srgrimes int prefix; 1165181606Sjhb int rep; 11664Srgrimes int imm; 11674Srgrimes int imm2; 11684Srgrimes int len; 11694Srgrimes struct i_addr address; 11704Srgrimes 11714Srgrimes get_value_inc(inst, loc, 1, FALSE); 11724Srgrimes short_addr = FALSE; 11734Srgrimes size = LONG; 1174297974Spfg seg = NULL; 11754Srgrimes 11764Srgrimes /* 11774Srgrimes * Get prefixes 11784Srgrimes */ 1179181606Sjhb rep = FALSE; 11804Srgrimes prefix = TRUE; 11814Srgrimes do { 11824Srgrimes switch (inst) { 11834Srgrimes case 0x66: /* data16 */ 11844Srgrimes size = WORD; 11854Srgrimes break; 11864Srgrimes case 0x67: 11874Srgrimes short_addr = TRUE; 11884Srgrimes break; 11894Srgrimes case 0x26: 11904Srgrimes seg = "%es"; 11914Srgrimes break; 11924Srgrimes case 0x36: 11934Srgrimes seg = "%ss"; 11944Srgrimes break; 11954Srgrimes case 0x2e: 11964Srgrimes seg = "%cs"; 11974Srgrimes break; 11984Srgrimes case 0x3e: 11994Srgrimes seg = "%ds"; 12004Srgrimes break; 12014Srgrimes case 0x64: 12024Srgrimes seg = "%fs"; 12034Srgrimes break; 12044Srgrimes case 0x65: 12054Srgrimes seg = "%gs"; 12064Srgrimes break; 12074Srgrimes case 0xf0: 12084Srgrimes db_printf("lock "); 12094Srgrimes break; 12104Srgrimes case 0xf2: 12114Srgrimes db_printf("repne "); 12124Srgrimes break; 12134Srgrimes case 0xf3: 1214181606Sjhb rep = TRUE; 12154Srgrimes break; 12164Srgrimes default: 12174Srgrimes prefix = FALSE; 12184Srgrimes break; 12194Srgrimes } 12204Srgrimes if (prefix) { 12214Srgrimes get_value_inc(inst, loc, 1, FALSE); 12224Srgrimes } 1223181606Sjhb if (rep == TRUE) { 1224181606Sjhb if (inst == 0x90) { 1225181606Sjhb db_printf("pause\n"); 1226181606Sjhb return (loc); 1227181606Sjhb } 1228181606Sjhb db_printf("repe "); /* XXX repe VS rep */ 1229181606Sjhb rep = FALSE; 1230181606Sjhb } 12314Srgrimes } while (prefix); 12324Srgrimes 12334Srgrimes if (inst >= 0xd8 && inst <= 0xdf) { 12344Srgrimes loc = db_disasm_esc(loc, inst, short_addr, size, seg); 12354Srgrimes db_printf("\n"); 12364Srgrimes return (loc); 12374Srgrimes } 12384Srgrimes 12394Srgrimes if (inst == 0x0f) { 12404Srgrimes get_value_inc(inst, loc, 1, FALSE); 12414Srgrimes ip = db_inst_0f[inst>>4]; 1242297974Spfg if (ip == NULL) { 12434Srgrimes ip = &db_bad_inst; 12444Srgrimes } 12454Srgrimes else { 12464Srgrimes ip = &ip[inst&0xf]; 12474Srgrimes } 12484Srgrimes } 12494Srgrimes else 12504Srgrimes ip = &db_inst_table[inst]; 12514Srgrimes 12524Srgrimes if (ip->i_has_modrm) { 12534Srgrimes get_value_inc(regmodrm, loc, 1, FALSE); 12544Srgrimes loc = db_read_address(loc, short_addr, regmodrm, &address); 12554Srgrimes } 12564Srgrimes 12574Srgrimes i_name = ip->i_name; 12584Srgrimes i_size = ip->i_size; 12594Srgrimes i_mode = ip->i_mode; 12604Srgrimes 126117109Sbde if (ip->i_extra == db_Grp1 || ip->i_extra == db_Grp2 || 126217109Sbde ip->i_extra == db_Grp6 || ip->i_extra == db_Grp7 || 1263181606Sjhb ip->i_extra == db_Grp8 || ip->i_extra == db_Grp9 || 1264181606Sjhb ip->i_extra == db_Grp15) { 126517109Sbde i_name = ((const char * const *)ip->i_extra)[f_reg(regmodrm)]; 12664Srgrimes } 126717109Sbde else if (ip->i_extra == db_Grp3) { 126817109Sbde ip = ip->i_extra; 12694Srgrimes ip = &ip[f_reg(regmodrm)]; 12704Srgrimes i_name = ip->i_name; 12714Srgrimes i_mode = ip->i_mode; 12724Srgrimes } 127317109Sbde else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) { 127417109Sbde ip = ip->i_extra; 12754Srgrimes ip = &ip[f_reg(regmodrm)]; 12764Srgrimes i_name = ip->i_name; 12774Srgrimes i_mode = ip->i_mode; 12784Srgrimes i_size = ip->i_size; 12794Srgrimes } 12804Srgrimes 1281181606Sjhb /* Special cases that don't fit well in the tables. */ 1282181606Sjhb if (ip->i_extra == db_Grp7 && f_mod(regmodrm) == 3) { 1283181606Sjhb switch (regmodrm) { 1284181606Sjhb case 0xc8: 1285181606Sjhb i_name = "monitor"; 1286181606Sjhb i_size = NONE; 1287270844Spfg i_mode = 0; 1288181606Sjhb break; 1289181606Sjhb case 0xc9: 1290181606Sjhb i_name = "mwait"; 1291181606Sjhb i_size = NONE; 1292181606Sjhb i_mode = 0; 1293181606Sjhb break; 1294181606Sjhb } 1295181606Sjhb } 1296181606Sjhb if (ip->i_extra == db_Grp15 && f_mod(regmodrm) == 3) { 1297181606Sjhb i_name = db_Grp15b[f_reg(regmodrm)]; 1298181606Sjhb i_size = NONE; 1299181606Sjhb i_mode = 0; 1300181606Sjhb } 1301181606Sjhb 13024Srgrimes if (i_size == SDEP) { 13034Srgrimes if (size == WORD) 130479885Skris db_printf("%s", i_name); 13054Srgrimes else 130679885Skris db_printf("%s", (const char *)ip->i_extra); 13074Srgrimes } 13084Srgrimes else { 130979885Skris db_printf("%s", i_name); 13104Srgrimes if (i_size != NONE) { 13114Srgrimes if (i_size == BYTE) { 13124Srgrimes db_printf("b"); 13134Srgrimes size = BYTE; 13144Srgrimes } 13154Srgrimes else if (i_size == WORD) { 13164Srgrimes db_printf("w"); 13174Srgrimes size = WORD; 13184Srgrimes } 13194Srgrimes else if (size == WORD) 13204Srgrimes db_printf("w"); 13214Srgrimes else 13224Srgrimes db_printf("l"); 13234Srgrimes } 13244Srgrimes } 13254Srgrimes db_printf("\t"); 13264Srgrimes for (first = TRUE; 13274Srgrimes i_mode != 0; 13284Srgrimes i_mode >>= 8, first = FALSE) 13294Srgrimes { 13304Srgrimes if (!first) 13314Srgrimes db_printf(","); 13324Srgrimes 13334Srgrimes switch (i_mode & 0xFF) { 13344Srgrimes 13354Srgrimes case E: 13364Srgrimes db_print_address(seg, size, &address); 13374Srgrimes break; 13384Srgrimes 13394Srgrimes case Eind: 13404Srgrimes db_printf("*"); 13414Srgrimes db_print_address(seg, size, &address); 13424Srgrimes break; 13434Srgrimes 134421277Sbde case El: 134521277Sbde db_print_address(seg, LONG, &address); 134621277Sbde break; 134721277Sbde 13484Srgrimes case Ew: 13494Srgrimes db_print_address(seg, WORD, &address); 13504Srgrimes break; 13514Srgrimes 13524Srgrimes case Eb: 13534Srgrimes db_print_address(seg, BYTE, &address); 13544Srgrimes break; 13554Srgrimes 13564Srgrimes case R: 13574Srgrimes db_printf("%s", db_reg[size][f_reg(regmodrm)]); 13584Srgrimes break; 13594Srgrimes 13604Srgrimes case Rw: 13614Srgrimes db_printf("%s", db_reg[WORD][f_reg(regmodrm)]); 13624Srgrimes break; 13634Srgrimes 13644Srgrimes case Ri: 13654Srgrimes db_printf("%s", db_reg[size][f_rm(inst)]); 13664Srgrimes break; 13674Srgrimes 136821277Sbde case Ril: 136921277Sbde db_printf("%s", db_reg[LONG][f_rm(inst)]); 137021277Sbde break; 137121277Sbde 13724Srgrimes case S: 13734Srgrimes db_printf("%s", db_seg_reg[f_reg(regmodrm)]); 13744Srgrimes break; 13754Srgrimes 13764Srgrimes case Si: 13774Srgrimes db_printf("%s", db_seg_reg[f_reg(inst)]); 13784Srgrimes break; 13794Srgrimes 13804Srgrimes case A: 13814Srgrimes db_printf("%s", db_reg[size][0]); /* acc */ 13824Srgrimes break; 13834Srgrimes 13844Srgrimes case BX: 13854Srgrimes if (seg) 13864Srgrimes db_printf("%s:", seg); 13874Srgrimes db_printf("(%s)", short_addr ? "%bx" : "%ebx"); 13884Srgrimes break; 13894Srgrimes 13904Srgrimes case CL: 13914Srgrimes db_printf("%%cl"); 13924Srgrimes break; 13934Srgrimes 13944Srgrimes case DX: 13954Srgrimes db_printf("%%dx"); 13964Srgrimes break; 13974Srgrimes 13984Srgrimes case SI: 13994Srgrimes if (seg) 14004Srgrimes db_printf("%s:", seg); 14014Srgrimes db_printf("(%s)", short_addr ? "%si" : "%esi"); 14024Srgrimes break; 14034Srgrimes 14044Srgrimes case DI: 14054Srgrimes db_printf("%%es:(%s)", short_addr ? "%di" : "%edi"); 14064Srgrimes break; 14074Srgrimes 14084Srgrimes case CR: 14094Srgrimes db_printf("%%cr%d", f_reg(regmodrm)); 14104Srgrimes break; 14114Srgrimes 14124Srgrimes case DR: 14134Srgrimes db_printf("%%dr%d", f_reg(regmodrm)); 14144Srgrimes break; 14154Srgrimes 14164Srgrimes case TR: 14174Srgrimes db_printf("%%tr%d", f_reg(regmodrm)); 14184Srgrimes break; 14194Srgrimes 14204Srgrimes case I: 14214Srgrimes len = db_lengths[size]; 142221277Sbde get_value_inc(imm, loc, len, FALSE); 142337506Sbde db_printf("$%#r", imm); 14244Srgrimes break; 14254Srgrimes 14264Srgrimes case Is: 14274Srgrimes len = db_lengths[size]; 142821277Sbde get_value_inc(imm, loc, len, FALSE); 142937506Sbde db_printf("$%+#r", imm); 14304Srgrimes break; 14314Srgrimes 14324Srgrimes case Ib: 143321277Sbde get_value_inc(imm, loc, 1, FALSE); 143437506Sbde db_printf("$%#r", imm); 14354Srgrimes break; 14364Srgrimes 143721277Sbde case Iba: 143821277Sbde get_value_inc(imm, loc, 1, FALSE); 143921277Sbde if (imm != 0x0a) 144037506Sbde db_printf("$%#r", imm); 144121277Sbde break; 144221277Sbde 14434Srgrimes case Ibs: 144421277Sbde get_value_inc(imm, loc, 1, TRUE); 144521277Sbde if (size == WORD) 144621277Sbde imm &= 0xFFFF; 144737506Sbde db_printf("$%+#r", imm); 14484Srgrimes break; 14494Srgrimes 14504Srgrimes case Iw: 145121277Sbde get_value_inc(imm, loc, 2, FALSE); 145237506Sbde db_printf("$%#r", imm); 14534Srgrimes break; 14544Srgrimes 14554Srgrimes case O: 145621277Sbde len = (short_addr ? 2 : 4); 145721277Sbde get_value_inc(displ, loc, len, FALSE); 14584Srgrimes if (seg) 145937506Sbde db_printf("%s:%+#r",seg, displ); 14604Srgrimes else 14614Srgrimes db_printsym((db_addr_t)displ, DB_STGY_ANY); 14624Srgrimes break; 14634Srgrimes 14644Srgrimes case Db: 14654Srgrimes get_value_inc(displ, loc, 1, TRUE); 146621277Sbde displ += loc; 146721277Sbde if (size == WORD) 146821277Sbde displ &= 0xFFFF; 146921277Sbde db_printsym((db_addr_t)displ, DB_STGY_XTRN); 14704Srgrimes break; 14714Srgrimes 14724Srgrimes case Dl: 147321277Sbde len = db_lengths[size]; 147421277Sbde get_value_inc(displ, loc, len, FALSE); 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 o1: 14824Srgrimes db_printf("$1"); 14834Srgrimes break; 14844Srgrimes 14854Srgrimes case o3: 14864Srgrimes db_printf("$3"); 14874Srgrimes break; 14884Srgrimes 14894Srgrimes case OS: 149021277Sbde len = db_lengths[size]; 149121277Sbde get_value_inc(imm, loc, len, FALSE); /* offset */ 14924Srgrimes get_value_inc(imm2, loc, 2, FALSE); /* segment */ 149337506Sbde db_printf("$%#r,%#r", imm2, imm); 14944Srgrimes break; 14954Srgrimes } 14964Srgrimes } 14974Srgrimes db_printf("\n"); 14984Srgrimes return (loc); 14994Srgrimes} 1500