db_disasm.c revision 164263
1139731Simp/*-
24Srgrimes * Mach Operating System
34Srgrimes * Copyright (c) 1991,1990 Carnegie Mellon University
44Srgrimes * All Rights Reserved.
58876Srgrimes *
64Srgrimes * Permission to use, copy, modify and distribute this software and its
74Srgrimes * documentation is hereby granted, provided that both the copyright
84Srgrimes * notice and this permission notice appear in all copies of the
94Srgrimes * software, derivative works or modified versions, and any portions
104Srgrimes * thereof, and that both notices appear in supporting documentation.
118876Srgrimes *
128876Srgrimes * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
134Srgrimes * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
144Srgrimes * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
158876Srgrimes *
164Srgrimes * Carnegie Mellon requests users of this software to return to
178876Srgrimes *
184Srgrimes *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
194Srgrimes *  School of Computer Science
204Srgrimes *  Carnegie Mellon University
214Srgrimes *  Pittsburgh PA 15213-3890
228876Srgrimes *
234Srgrimes * any improvements or extensions that they make and grant Carnegie the
244Srgrimes * rights to redistribute these changes.
254Srgrimes */
264Srgrimes
27118031Sobrien#include <sys/cdefs.h>
28118031Sobrien__FBSDID("$FreeBSD: head/sys/amd64/amd64/db_disasm.c 164263 2006-11-13 21:14:54Z jhb $");
29118031Sobrien
304Srgrimes/*
314Srgrimes * Instruction disassembler.
324Srgrimes */
332056Swollman#include <sys/param.h>
3424494Sbde
352056Swollman#include <ddb/ddb.h>
364Srgrimes#include <ddb/db_access.h>
374Srgrimes#include <ddb/db_sym.h>
384Srgrimes
394Srgrimes/*
404Srgrimes * Size attributes
414Srgrimes */
424Srgrimes#define	BYTE	0
434Srgrimes#define	WORD	1
444Srgrimes#define	LONG	2
454Srgrimes#define	QUAD	3
464Srgrimes#define	SNGL	4
474Srgrimes#define	DBLR	5
484Srgrimes#define	EXTR	6
494Srgrimes#define	SDEP	7
504Srgrimes#define	NONE	8
514Srgrimes
524Srgrimes/*
53144353Speter * REX prefix and bits
54144353Speter */
55144353Speter#define REX_B	1
56144353Speter#define REX_X	2
57144353Speter#define REX_R	4
58144353Speter#define REX_W	8
59144353Speter#define REX	0x40
60144353Speter
61144353Speter/*
624Srgrimes * Addressing modes
634Srgrimes */
644Srgrimes#define	E	1			/* general effective address */
654Srgrimes#define	Eind	2			/* indirect address (jump, call) */
664Srgrimes#define	Ew	3			/* address, word size */
674Srgrimes#define	Eb	4			/* address, byte size */
684Srgrimes#define	R	5			/* register, in 'reg' field */
694Srgrimes#define	Rw	6			/* word register, in 'reg' field */
704Srgrimes#define	Ri	7			/* register in instruction */
714Srgrimes#define	S	8			/* segment reg, in 'reg' field */
724Srgrimes#define	Si	9			/* segment reg, in instruction */
734Srgrimes#define	A	10			/* accumulator */
744Srgrimes#define	BX	11			/* (bx) */
754Srgrimes#define	CL	12			/* cl, for shifts */
764Srgrimes#define	DX	13			/* dx, for IO */
774Srgrimes#define	SI	14			/* si */
784Srgrimes#define	DI	15			/* di */
794Srgrimes#define	CR	16			/* control register */
804Srgrimes#define	DR	17			/* debug register */
814Srgrimes#define	TR	18			/* test register */
824Srgrimes#define	I	19			/* immediate, unsigned */
834Srgrimes#define	Is	20			/* immediate, signed */
844Srgrimes#define	Ib	21			/* byte immediate, unsigned */
854Srgrimes#define	Ibs	22			/* byte immediate, signed */
864Srgrimes#define	Iw	23			/* word immediate, unsigned */
87164263Sjhb#define	Ilq	24			/* long/quad immediate, unsigned */
884Srgrimes#define	O	25			/* direct address */
894Srgrimes#define	Db	26			/* byte displacement from EIP */
904Srgrimes#define	Dl	27			/* long displacement from EIP */
914Srgrimes#define	o1	28			/* constant 1 */
924Srgrimes#define	o3	29			/* constant 3 */
934Srgrimes#define	OS	30			/* immediate offset/segment */
944Srgrimes#define	ST	31			/* FP stack top */
954Srgrimes#define	STI	32			/* FP stack */
964Srgrimes#define	X	33			/* extended FP op */
974Srgrimes#define	XA	34			/* for 'fstcw %ax' */
98144354Speter#define	El	35			/* address, long/quad size */
9921277Sbde#define	Ril	36			/* long register in instruction */
10021277Sbde#define	Iba	37			/* byte immediate, don't print if 0xa */
101144354Speter#define	EL	38			/* address, explicitly long size */
1024Srgrimes
10311940Sbdestruct inst {
10414887Swollman	const char *	i_name;		/* name */
1054Srgrimes	short	i_has_modrm;		/* has regmodrm byte */
1064Srgrimes	short	i_size;			/* operand size */
1074Srgrimes	int	i_mode;			/* addressing modes */
10817109Sbde	const void *	i_extra;	/* pointer to extra opcode table */
1094Srgrimes};
1104Srgrimes
1114Srgrimes#define	op1(x)		(x)
1124Srgrimes#define	op2(x,y)	((x)|((y)<<8))
1134Srgrimes#define	op3(x,y,z)	((x)|((y)<<8)|((z)<<16))
1144Srgrimes
11511940Sbdestruct finst {
11614887Swollman	const char *	f_name;		/* name for memory instruction */
1174Srgrimes	int	f_size;			/* size for memory instruction */
1184Srgrimes	int	f_rrmode;		/* mode for rr instruction */
11917109Sbde	const void *	f_rrname;	/* name for rr instruction
1204Srgrimes					   (or pointer to table) */
1214Srgrimes};
1224Srgrimes
12314887Swollmanstatic const char * const db_Grp6[] = {
1244Srgrimes	"sldt",
1254Srgrimes	"str",
1264Srgrimes	"lldt",
1274Srgrimes	"ltr",
1284Srgrimes	"verr",
1294Srgrimes	"verw",
1304Srgrimes	"",
1314Srgrimes	""
1324Srgrimes};
1334Srgrimes
13414887Swollmanstatic const char * const db_Grp7[] = {
1354Srgrimes	"sgdt",
1364Srgrimes	"sidt",
1374Srgrimes	"lgdt",
1384Srgrimes	"lidt",
1394Srgrimes	"smsw",
1404Srgrimes	"",
1414Srgrimes	"lmsw",
1424Srgrimes	"invlpg"
1434Srgrimes};
1444Srgrimes
14514887Swollmanstatic const char * const db_Grp8[] = {
1464Srgrimes	"",
1474Srgrimes	"",
1484Srgrimes	"",
1494Srgrimes	"",
1504Srgrimes	"bt",
1514Srgrimes	"bts",
1524Srgrimes	"btr",
1534Srgrimes	"btc"
1544Srgrimes};
1554Srgrimes
15621277Sbdestatic const char * const db_Grp9[] = {
15721277Sbde	"",
15821277Sbde	"cmpxchg8b",
15921277Sbde	"",
16021277Sbde	"",
16121277Sbde	"",
16221277Sbde	"",
16321277Sbde	"",
16421277Sbde	""
16521277Sbde};
16621277Sbde
16714887Swollmanstatic const struct inst db_inst_0f0x[] = {
16817109Sbde/*00*/	{ "",	   TRUE,  NONE,  op1(Ew),     db_Grp6 },
16917109Sbde/*01*/	{ "",	   TRUE,  NONE,  op1(Ew),     db_Grp7 },
1704Srgrimes/*02*/	{ "lar",   TRUE,  LONG,  op2(E,R),    0 },
1714Srgrimes/*03*/	{ "lsl",   TRUE,  LONG,  op2(E,R),    0 },
1724Srgrimes/*04*/	{ "",      FALSE, NONE,  0,	      0 },
1734Srgrimes/*05*/	{ "",      FALSE, NONE,  0,	      0 },
1744Srgrimes/*06*/	{ "clts",  FALSE, NONE,  0,	      0 },
1754Srgrimes/*07*/	{ "",      FALSE, NONE,  0,	      0 },
1764Srgrimes
1774Srgrimes/*08*/	{ "invd",  FALSE, NONE,  0,	      0 },
1784Srgrimes/*09*/	{ "wbinvd",FALSE, NONE,  0,	      0 },
1794Srgrimes/*0a*/	{ "",      FALSE, NONE,  0,	      0 },
1804Srgrimes/*0b*/	{ "",      FALSE, NONE,  0,	      0 },
1814Srgrimes/*0c*/	{ "",      FALSE, NONE,  0,	      0 },
1824Srgrimes/*0d*/	{ "",      FALSE, NONE,  0,	      0 },
1834Srgrimes/*0e*/	{ "",      FALSE, NONE,  0,	      0 },
1844Srgrimes/*0f*/	{ "",      FALSE, NONE,  0,	      0 },
1854Srgrimes};
1864Srgrimes
18717109Sbdestatic const struct inst db_inst_0f2x[] = {
18821277Sbde/*20*/	{ "mov",   TRUE,  LONG,  op2(CR,El),  0 },
18921277Sbde/*21*/	{ "mov",   TRUE,  LONG,  op2(DR,El),  0 },
19021277Sbde/*22*/	{ "mov",   TRUE,  LONG,  op2(El,CR),  0 },
19121277Sbde/*23*/	{ "mov",   TRUE,  LONG,  op2(El,DR),  0 },
19221277Sbde/*24*/	{ "mov",   TRUE,  LONG,  op2(TR,El),  0 },
1934Srgrimes/*25*/	{ "",      FALSE, NONE,  0,	      0 },
19421277Sbde/*26*/	{ "mov",   TRUE,  LONG,  op2(El,TR),  0 },
1954Srgrimes/*27*/	{ "",      FALSE, NONE,  0,	      0 },
1964Srgrimes
1974Srgrimes/*28*/	{ "",      FALSE, NONE,  0,	      0 },
1984Srgrimes/*29*/	{ "",      FALSE, NONE,  0,	      0 },
1994Srgrimes/*2a*/	{ "",      FALSE, NONE,  0,	      0 },
2004Srgrimes/*2b*/	{ "",      FALSE, NONE,  0,	      0 },
2014Srgrimes/*2c*/	{ "",      FALSE, NONE,  0,	      0 },
2024Srgrimes/*2d*/	{ "",      FALSE, NONE,  0,	      0 },
2034Srgrimes/*2e*/	{ "",      FALSE, NONE,  0,	      0 },
2044Srgrimes/*2f*/	{ "",      FALSE, NONE,  0,	      0 },
2054Srgrimes};
2064Srgrimes
20714887Swollmanstatic const struct inst db_inst_0f3x[] = {
20814887Swollman/*30*/	{ "wrmsr", FALSE, NONE,  0,	      0 },
20914887Swollman/*31*/	{ "rdtsc", FALSE, NONE,  0,	      0 },
21014887Swollman/*32*/	{ "rdmsr", FALSE, NONE,  0,	      0 },
21114887Swollman/*33*/	{ "rdpmc", FALSE, NONE,  0,	      0 },
21214887Swollman/*34*/	{ "",	   FALSE, NONE,  0,	      0 },
21314887Swollman/*35*/	{ "",	   FALSE, NONE,  0,	      0 },
21414887Swollman/*36*/	{ "",	   FALSE, NONE,  0,	      0 },
21514887Swollman/*37*/	{ "",	   FALSE, NONE,  0,	      0 },
21614887Swollman
21714887Swollman/*38*/	{ "",	   FALSE, NONE,  0,	      0 },
21814887Swollman/*39*/	{ "",	   FALSE, NONE,  0,	      0 },
21914887Swollman/*3a*/	{ "",	   FALSE, NONE,  0,	      0 },
22014887Swollman/*3b*/	{ "",	   FALSE, NONE,  0,	      0 },
22114887Swollman/*3c*/	{ "",	   FALSE, NONE,  0,	      0 },
22214887Swollman/*3d*/	{ "",	   FALSE, NONE,  0,	      0 },
22314887Swollman/*3e*/	{ "",	   FALSE, NONE,  0,	      0 },
22414887Swollman/*3f*/	{ "",	   FALSE, NONE,  0,	      0 },
22514887Swollman};
22614887Swollman
227144354Speterstatic const struct inst db_inst_0f4x[] = {
228144354Speter/*40*/	{ "cmovo",  TRUE, NONE,  op2(E, R),   0 },
229144354Speter/*41*/	{ "cmovno", TRUE, NONE,  op2(E, R),   0 },
230144354Speter/*42*/	{ "cmovb",  TRUE, NONE,  op2(E, R),   0 },
231144354Speter/*43*/	{ "cmovnb", TRUE, NONE,  op2(E, R),   0 },
232144354Speter/*44*/	{ "cmovz",  TRUE, NONE,  op2(E, R),   0 },
233144354Speter/*45*/	{ "cmovnz", TRUE, NONE,  op2(E, R),   0 },
234144354Speter/*46*/	{ "cmovbe", TRUE, NONE,  op2(E, R),   0 },
235144354Speter/*47*/	{ "cmovnbe",TRUE, NONE,  op2(E, R),   0 },
236144354Speter
237144354Speter/*48*/	{ "cmovs",  TRUE, NONE,  op2(E, R),   0 },
238144354Speter/*49*/	{ "cmovns", TRUE, NONE,  op2(E, R),   0 },
239144354Speter/*4a*/	{ "cmovp",  TRUE, NONE,  op2(E, R),   0 },
240144354Speter/*4b*/	{ "cmovnp", TRUE, NONE,  op2(E, R),   0 },
241144354Speter/*4c*/	{ "cmovl",  TRUE, NONE,  op2(E, R),   0 },
242144354Speter/*4d*/	{ "cmovnl", TRUE, NONE,  op2(E, R),   0 },
243144354Speter/*4e*/	{ "cmovle", TRUE, NONE,  op2(E, R),   0 },
244144354Speter/*4f*/	{ "cmovnle",TRUE, NONE,  op2(E, R),   0 },
245144354Speter};
246144354Speter
24717109Sbdestatic const struct inst db_inst_0f8x[] = {
2484Srgrimes/*80*/	{ "jo",    FALSE, NONE,  op1(Dl),     0 },
2494Srgrimes/*81*/	{ "jno",   FALSE, NONE,  op1(Dl),     0 },
2504Srgrimes/*82*/	{ "jb",    FALSE, NONE,  op1(Dl),     0 },
2514Srgrimes/*83*/	{ "jnb",   FALSE, NONE,  op1(Dl),     0 },
2524Srgrimes/*84*/	{ "jz",    FALSE, NONE,  op1(Dl),     0 },
2534Srgrimes/*85*/	{ "jnz",   FALSE, NONE,  op1(Dl),     0 },
2544Srgrimes/*86*/	{ "jbe",   FALSE, NONE,  op1(Dl),     0 },
2554Srgrimes/*87*/	{ "jnbe",  FALSE, NONE,  op1(Dl),     0 },
2564Srgrimes
2574Srgrimes/*88*/	{ "js",    FALSE, NONE,  op1(Dl),     0 },
2584Srgrimes/*89*/	{ "jns",   FALSE, NONE,  op1(Dl),     0 },
2594Srgrimes/*8a*/	{ "jp",    FALSE, NONE,  op1(Dl),     0 },
2604Srgrimes/*8b*/	{ "jnp",   FALSE, NONE,  op1(Dl),     0 },
2614Srgrimes/*8c*/	{ "jl",    FALSE, NONE,  op1(Dl),     0 },
2624Srgrimes/*8d*/	{ "jnl",   FALSE, NONE,  op1(Dl),     0 },
2634Srgrimes/*8e*/	{ "jle",   FALSE, NONE,  op1(Dl),     0 },
2644Srgrimes/*8f*/	{ "jnle",  FALSE, NONE,  op1(Dl),     0 },
2654Srgrimes};
2664Srgrimes
26717109Sbdestatic const struct inst db_inst_0f9x[] = {
2684Srgrimes/*90*/	{ "seto",  TRUE,  NONE,  op1(Eb),     0 },
2694Srgrimes/*91*/	{ "setno", TRUE,  NONE,  op1(Eb),     0 },
2704Srgrimes/*92*/	{ "setb",  TRUE,  NONE,  op1(Eb),     0 },
2714Srgrimes/*93*/	{ "setnb", TRUE,  NONE,  op1(Eb),     0 },
2724Srgrimes/*94*/	{ "setz",  TRUE,  NONE,  op1(Eb),     0 },
2734Srgrimes/*95*/	{ "setnz", TRUE,  NONE,  op1(Eb),     0 },
2744Srgrimes/*96*/	{ "setbe", TRUE,  NONE,  op1(Eb),     0 },
2754Srgrimes/*97*/	{ "setnbe",TRUE,  NONE,  op1(Eb),     0 },
2764Srgrimes
2774Srgrimes/*98*/	{ "sets",  TRUE,  NONE,  op1(Eb),     0 },
2784Srgrimes/*99*/	{ "setns", TRUE,  NONE,  op1(Eb),     0 },
2794Srgrimes/*9a*/	{ "setp",  TRUE,  NONE,  op1(Eb),     0 },
2804Srgrimes/*9b*/	{ "setnp", TRUE,  NONE,  op1(Eb),     0 },
2814Srgrimes/*9c*/	{ "setl",  TRUE,  NONE,  op1(Eb),     0 },
2824Srgrimes/*9d*/	{ "setnl", TRUE,  NONE,  op1(Eb),     0 },
2834Srgrimes/*9e*/	{ "setle", TRUE,  NONE,  op1(Eb),     0 },
2844Srgrimes/*9f*/	{ "setnle",TRUE,  NONE,  op1(Eb),     0 },
2854Srgrimes};
2864Srgrimes
28717109Sbdestatic const struct inst db_inst_0fax[] = {
2884Srgrimes/*a0*/	{ "push",  FALSE, NONE,  op1(Si),     0 },
2894Srgrimes/*a1*/	{ "pop",   FALSE, NONE,  op1(Si),     0 },
29021277Sbde/*a2*/	{ "cpuid", FALSE, NONE,  0,	      0 },
29121277Sbde/*a3*/	{ "bt",    TRUE,  LONG,  op2(R,E),    0 },
29217109Sbde/*a4*/	{ "shld",  TRUE,  LONG,  op3(Ib,R,E), 0 },
29317109Sbde/*a5*/	{ "shld",  TRUE,  LONG,  op3(CL,R,E), 0 },
2944Srgrimes/*a6*/	{ "",      FALSE, NONE,  0,	      0 },
2954Srgrimes/*a7*/	{ "",      FALSE, NONE,  0,	      0 },
2964Srgrimes
2974Srgrimes/*a8*/	{ "push",  FALSE, NONE,  op1(Si),     0 },
2984Srgrimes/*a9*/	{ "pop",   FALSE, NONE,  op1(Si),     0 },
29921277Sbde/*aa*/	{ "rsm",   FALSE, NONE,  0,	      0 },
30021277Sbde/*ab*/	{ "bts",   TRUE,  LONG,  op2(R,E),    0 },
30117109Sbde/*ac*/	{ "shrd",  TRUE,  LONG,  op3(Ib,R,E), 0 },
30217109Sbde/*ad*/	{ "shrd",  TRUE,  LONG,  op3(CL,R,E), 0 },
3034Srgrimes/*a6*/	{ "",      FALSE, NONE,  0,	      0 },
3044Srgrimes/*a7*/	{ "imul",  TRUE,  LONG,  op2(E,R),    0 },
3054Srgrimes};
3064Srgrimes
30717109Sbdestatic const struct inst db_inst_0fbx[] = {
30821277Sbde/*b0*/	{ "cmpxchg",TRUE, BYTE,	 op2(R, E),   0 },
30921277Sbde/*b0*/	{ "cmpxchg",TRUE, LONG,	 op2(R, E),   0 },
3104Srgrimes/*b2*/	{ "lss",   TRUE,  LONG,  op2(E, R),   0 },
31121277Sbde/*b3*/	{ "btr",   TRUE,  LONG,  op2(R, E),   0 },
3124Srgrimes/*b4*/	{ "lfs",   TRUE,  LONG,  op2(E, R),   0 },
3134Srgrimes/*b5*/	{ "lgs",   TRUE,  LONG,  op2(E, R),   0 },
31421277Sbde/*b6*/	{ "movzb", TRUE,  LONG,  op2(Eb, R),  0 },
31521277Sbde/*b7*/	{ "movzw", TRUE,  LONG,  op2(Ew, R),  0 },
3164Srgrimes
3174Srgrimes/*b8*/	{ "",      FALSE, NONE,  0,	      0 },
3184Srgrimes/*b9*/	{ "",      FALSE, NONE,  0,	      0 },
31917109Sbde/*ba*/	{ "",      TRUE,  LONG,  op2(Ib, E),  db_Grp8 },
3204Srgrimes/*bb*/	{ "btc",   TRUE,  LONG,  op2(R, E),   0 },
3214Srgrimes/*bc*/	{ "bsf",   TRUE,  LONG,  op2(E, R),   0 },
3224Srgrimes/*bd*/	{ "bsr",   TRUE,  LONG,  op2(E, R),   0 },
32321277Sbde/*be*/	{ "movsb", TRUE,  LONG,  op2(Eb, R),  0 },
32421277Sbde/*bf*/	{ "movsw", TRUE,  LONG,  op2(Ew, R),  0 },
3254Srgrimes};
3264Srgrimes
32717109Sbdestatic const struct inst db_inst_0fcx[] = {
3284Srgrimes/*c0*/	{ "xadd",  TRUE,  BYTE,	 op2(R, E),   0 },
3294Srgrimes/*c1*/	{ "xadd",  TRUE,  LONG,	 op2(R, E),   0 },
3304Srgrimes/*c2*/	{ "",	   FALSE, NONE,	 0,	      0 },
3314Srgrimes/*c3*/	{ "",	   FALSE, NONE,	 0,	      0 },
3324Srgrimes/*c4*/	{ "",	   FALSE, NONE,	 0,	      0 },
3334Srgrimes/*c5*/	{ "",	   FALSE, NONE,	 0,	      0 },
3344Srgrimes/*c6*/	{ "",	   FALSE, NONE,	 0,	      0 },
33521277Sbde/*c7*/	{ "",	   TRUE,  NONE,  op1(E),      db_Grp9 },
33621277Sbde/*c8*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
33721277Sbde/*c9*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
33821277Sbde/*ca*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
33921277Sbde/*cb*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
34021277Sbde/*cc*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
34121277Sbde/*cd*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
34221277Sbde/*ce*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
34321277Sbde/*cf*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
3444Srgrimes};
3454Srgrimes
34614887Swollmanstatic const struct inst * const db_inst_0f[] = {
3474Srgrimes	db_inst_0f0x,
3484Srgrimes	0,
3494Srgrimes	db_inst_0f2x,
35014887Swollman	db_inst_0f3x,
351144354Speter	db_inst_0f4x,
3524Srgrimes	0,
3534Srgrimes	0,
3544Srgrimes	0,
3554Srgrimes	db_inst_0f8x,
3564Srgrimes	db_inst_0f9x,
3574Srgrimes	db_inst_0fax,
3584Srgrimes	db_inst_0fbx,
3594Srgrimes	db_inst_0fcx,
3604Srgrimes	0,
36121277Sbde	0,
3624Srgrimes	0
3634Srgrimes};
3644Srgrimes
36514887Swollmanstatic const char * const db_Esc92[] = {
3664Srgrimes	"fnop",	"",	"",	"",	"",	"",	"",	""
3674Srgrimes};
36814887Swollmanstatic const char * const db_Esc94[] = {
3694Srgrimes	"fchs",	"fabs",	"",	"",	"ftst",	"fxam",	"",	""
3704Srgrimes};
37117109Sbdestatic const char * const db_Esc95[] = {
3724Srgrimes	"fld1",	"fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
3734Srgrimes};
37417109Sbdestatic const char * const db_Esc96[] = {
3754Srgrimes	"f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
3764Srgrimes	"fincstp"
3774Srgrimes};
37814887Swollmanstatic const char * const db_Esc97[] = {
3794Srgrimes	"fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
3804Srgrimes};
3814Srgrimes
38221277Sbdestatic const char * const db_Esca5[] = {
3834Srgrimes	"",	"fucompp","",	"",	"",	"",	"",	""
3844Srgrimes};
3854Srgrimes
38617109Sbdestatic const char * const db_Escb4[] = {
38721277Sbde	"fneni","fndisi",	"fnclex","fninit","fsetpm",	"",	"",	""
3884Srgrimes};
3894Srgrimes
39014887Swollmanstatic const char * const db_Esce3[] = {
3914Srgrimes	"",	"fcompp","",	"",	"",	"",	"",	""
3924Srgrimes};
3934Srgrimes
39417109Sbdestatic const char * const db_Escf4[] = {
3954Srgrimes	"fnstsw","",	"",	"",	"",	"",	"",	""
3964Srgrimes};
3974Srgrimes
39814887Swollmanstatic const struct finst db_Esc8[] = {
3994Srgrimes/*0*/	{ "fadd",   SNGL,  op2(STI,ST),	0 },
4004Srgrimes/*1*/	{ "fmul",   SNGL,  op2(STI,ST),	0 },
4014Srgrimes/*2*/	{ "fcom",   SNGL,  op2(STI,ST),	0 },
4024Srgrimes/*3*/	{ "fcomp",  SNGL,  op2(STI,ST),	0 },
4034Srgrimes/*4*/	{ "fsub",   SNGL,  op2(STI,ST),	0 },
4044Srgrimes/*5*/	{ "fsubr",  SNGL,  op2(STI,ST),	0 },
4054Srgrimes/*6*/	{ "fdiv",   SNGL,  op2(STI,ST),	0 },
4064Srgrimes/*7*/	{ "fdivr",  SNGL,  op2(STI,ST),	0 },
4074Srgrimes};
4084Srgrimes
40914887Swollmanstatic const struct finst db_Esc9[] = {
4104Srgrimes/*0*/	{ "fld",    SNGL,  op1(STI),	0 },
4114Srgrimes/*1*/	{ "",       NONE,  op1(STI),	"fxch" },
41217109Sbde/*2*/	{ "fst",    SNGL,  op1(X),	db_Esc92 },
41321277Sbde/*3*/	{ "fstp",   SNGL,  0,		0 },
41417109Sbde/*4*/	{ "fldenv", NONE,  op1(X),	db_Esc94 },
41517109Sbde/*5*/	{ "fldcw",  NONE,  op1(X),	db_Esc95 },
41617109Sbde/*6*/	{ "fnstenv",NONE,  op1(X),	db_Esc96 },
41717109Sbde/*7*/	{ "fnstcw", NONE,  op1(X),	db_Esc97 },
4184Srgrimes};
4194Srgrimes
42014887Swollmanstatic const struct finst db_Esca[] = {
42121277Sbde/*0*/	{ "fiadd",  LONG,  0,		0 },
42221277Sbde/*1*/	{ "fimul",  LONG,  0,		0 },
42321277Sbde/*2*/	{ "ficom",  LONG,  0,		0 },
42421277Sbde/*3*/	{ "ficomp", LONG,  0,		0 },
42521277Sbde/*4*/	{ "fisub",  LONG,  0,		0 },
42621277Sbde/*5*/	{ "fisubr", LONG,  op1(X),	db_Esca5 },
42721277Sbde/*6*/	{ "fidiv",  LONG,  0,		0 },
42821277Sbde/*7*/	{ "fidivr", LONG,  0,		0 }
4294Srgrimes};
4304Srgrimes
43114887Swollmanstatic const struct finst db_Escb[] = {
43221277Sbde/*0*/	{ "fild",   LONG,  0,		0 },
4334Srgrimes/*1*/	{ "",       NONE,  0,		0 },
43421277Sbde/*2*/	{ "fist",   LONG,  0,		0 },
43521277Sbde/*3*/	{ "fistp",  LONG,  0,		0 },
43617109Sbde/*4*/	{ "",       WORD,  op1(X),	db_Escb4 },
4374Srgrimes/*5*/	{ "fld",    EXTR,  0,		0 },
4384Srgrimes/*6*/	{ "",       WORD,  0,		0 },
4394Srgrimes/*7*/	{ "fstp",   EXTR,  0,		0 },
4404Srgrimes};
4414Srgrimes
44214887Swollmanstatic const struct finst db_Escc[] = {
4434Srgrimes/*0*/	{ "fadd",   DBLR,  op2(ST,STI),	0 },
4444Srgrimes/*1*/	{ "fmul",   DBLR,  op2(ST,STI),	0 },
44521277Sbde/*2*/	{ "fcom",   DBLR,  0,		0 },
44621277Sbde/*3*/	{ "fcomp",  DBLR,  0,		0 },
4474Srgrimes/*4*/	{ "fsub",   DBLR,  op2(ST,STI),	"fsubr" },
4484Srgrimes/*5*/	{ "fsubr",  DBLR,  op2(ST,STI),	"fsub" },
4494Srgrimes/*6*/	{ "fdiv",   DBLR,  op2(ST,STI),	"fdivr" },
4504Srgrimes/*7*/	{ "fdivr",  DBLR,  op2(ST,STI),	"fdiv" },
4514Srgrimes};
4524Srgrimes
45314887Swollmanstatic const struct finst db_Escd[] = {
4544Srgrimes/*0*/	{ "fld",    DBLR,  op1(STI),	"ffree" },
4554Srgrimes/*1*/	{ "",       NONE,  0,		0 },
4564Srgrimes/*2*/	{ "fst",    DBLR,  op1(STI),	0 },
4574Srgrimes/*3*/	{ "fstp",   DBLR,  op1(STI),	0 },
4584Srgrimes/*4*/	{ "frstor", NONE,  op1(STI),	"fucom" },
4594Srgrimes/*5*/	{ "",       NONE,  op1(STI),	"fucomp" },
4604Srgrimes/*6*/	{ "fnsave", NONE,  0,		0 },
4614Srgrimes/*7*/	{ "fnstsw", NONE,  0,		0 },
4624Srgrimes};
4634Srgrimes
46414887Swollmanstatic const struct finst db_Esce[] = {
46521277Sbde/*0*/	{ "fiadd",  WORD,  op2(ST,STI),	"faddp" },
46621277Sbde/*1*/	{ "fimul",  WORD,  op2(ST,STI),	"fmulp" },
46721277Sbde/*2*/	{ "ficom",  WORD,  0,		0 },
46821277Sbde/*3*/	{ "ficomp", WORD,  op1(X),	db_Esce3 },
46921277Sbde/*4*/	{ "fisub",  WORD,  op2(ST,STI),	"fsubrp" },
47021277Sbde/*5*/	{ "fisubr", WORD,  op2(ST,STI),	"fsubp" },
47121277Sbde/*6*/	{ "fidiv",  WORD,  op2(ST,STI),	"fdivrp" },
47221277Sbde/*7*/	{ "fidivr", WORD,  op2(ST,STI),	"fdivp" },
4734Srgrimes};
4744Srgrimes
47514887Swollmanstatic const struct finst db_Escf[] = {
47621277Sbde/*0*/	{ "fild",   WORD,  0,		0 },
47721277Sbde/*1*/	{ "",       NONE,  0,		0 },
47821277Sbde/*2*/	{ "fist",   WORD,  0,		0 },
47921277Sbde/*3*/	{ "fistp",  WORD,  0,		0 },
48017109Sbde/*4*/	{ "fbld",   NONE,  op1(XA),	db_Escf4 },
48121277Sbde/*5*/	{ "fild",   QUAD,  0,		0 },
4824Srgrimes/*6*/	{ "fbstp",  NONE,  0,		0 },
48321277Sbde/*7*/	{ "fistp",  QUAD,  0,		0 },
4844Srgrimes};
4854Srgrimes
48617109Sbdestatic const struct finst * const db_Esc_inst[] = {
4874Srgrimes	db_Esc8, db_Esc9, db_Esca, db_Escb,
4884Srgrimes	db_Escc, db_Escd, db_Esce, db_Escf
4894Srgrimes};
4904Srgrimes
49114887Swollmanstatic const char * const db_Grp1[] = {
4924Srgrimes	"add",
4934Srgrimes	"or",
4944Srgrimes	"adc",
4954Srgrimes	"sbb",
4964Srgrimes	"and",
4974Srgrimes	"sub",
4984Srgrimes	"xor",
4994Srgrimes	"cmp"
5004Srgrimes};
5014Srgrimes
50214887Swollmanstatic const char * const db_Grp2[] = {
5034Srgrimes	"rol",
5044Srgrimes	"ror",
5054Srgrimes	"rcl",
5064Srgrimes	"rcr",
5074Srgrimes	"shl",
5084Srgrimes	"shr",
5094Srgrimes	"shl",
5104Srgrimes	"sar"
5114Srgrimes};
5124Srgrimes
51314887Swollmanstatic const struct inst db_Grp3[] = {
5144Srgrimes	{ "test",  TRUE, NONE, op2(I,E), 0 },
5154Srgrimes	{ "test",  TRUE, NONE, op2(I,E), 0 },
5164Srgrimes	{ "not",   TRUE, NONE, op1(E),   0 },
5174Srgrimes	{ "neg",   TRUE, NONE, op1(E),   0 },
5184Srgrimes	{ "mul",   TRUE, NONE, op2(E,A), 0 },
5194Srgrimes	{ "imul",  TRUE, NONE, op2(E,A), 0 },
5204Srgrimes	{ "div",   TRUE, NONE, op2(E,A), 0 },
5214Srgrimes	{ "idiv",  TRUE, NONE, op2(E,A), 0 },
5224Srgrimes};
5234Srgrimes
52417109Sbdestatic const struct inst db_Grp4[] = {
5254Srgrimes	{ "inc",   TRUE, BYTE, op1(E),   0 },
5264Srgrimes	{ "dec",   TRUE, BYTE, op1(E),   0 },
5274Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
5284Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
5294Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
5304Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
5314Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
5324Srgrimes	{ "",      TRUE, NONE, 0,	 0 }
5334Srgrimes};
5344Srgrimes
53517109Sbdestatic const struct inst db_Grp5[] = {
5364Srgrimes	{ "inc",   TRUE, LONG, op1(E),   0 },
5374Srgrimes	{ "dec",   TRUE, LONG, op1(E),   0 },
53821277Sbde	{ "call",  TRUE, LONG, op1(Eind),0 },
53921277Sbde	{ "lcall", TRUE, LONG, op1(Eind),0 },
54021277Sbde	{ "jmp",   TRUE, LONG, op1(Eind),0 },
54121277Sbde	{ "ljmp",  TRUE, LONG, op1(Eind),0 },
5424Srgrimes	{ "push",  TRUE, LONG, op1(E),   0 },
5434Srgrimes	{ "",      TRUE, NONE, 0,	 0 }
5444Srgrimes};
5454Srgrimes
54614887Swollmanstatic const struct inst db_inst_table[256] = {
5474Srgrimes/*00*/	{ "add",   TRUE,  BYTE,  op2(R, E),  0 },
5484Srgrimes/*01*/	{ "add",   TRUE,  LONG,  op2(R, E),  0 },
5494Srgrimes/*02*/	{ "add",   TRUE,  BYTE,  op2(E, R),  0 },
5504Srgrimes/*03*/	{ "add",   TRUE,  LONG,  op2(E, R),  0 },
55121277Sbde/*04*/	{ "add",   FALSE, BYTE,  op2(I, A),  0 },
5524Srgrimes/*05*/	{ "add",   FALSE, LONG,  op2(Is, A), 0 },
5534Srgrimes/*06*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
5544Srgrimes/*07*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },
5554Srgrimes
5564Srgrimes/*08*/	{ "or",    TRUE,  BYTE,  op2(R, E),  0 },
5574Srgrimes/*09*/	{ "or",    TRUE,  LONG,  op2(R, E),  0 },
5584Srgrimes/*0a*/	{ "or",    TRUE,  BYTE,  op2(E, R),  0 },
5594Srgrimes/*0b*/	{ "or",    TRUE,  LONG,  op2(E, R),  0 },
5604Srgrimes/*0c*/	{ "or",    FALSE, BYTE,  op2(I, A),  0 },
5614Srgrimes/*0d*/	{ "or",    FALSE, LONG,  op2(I, A),  0 },
5624Srgrimes/*0e*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
5634Srgrimes/*0f*/	{ "",      FALSE, NONE,  0,	     0 },
5644Srgrimes
5654Srgrimes/*10*/	{ "adc",   TRUE,  BYTE,  op2(R, E),  0 },
5664Srgrimes/*11*/	{ "adc",   TRUE,  LONG,  op2(R, E),  0 },
5674Srgrimes/*12*/	{ "adc",   TRUE,  BYTE,  op2(E, R),  0 },
5684Srgrimes/*13*/	{ "adc",   TRUE,  LONG,  op2(E, R),  0 },
56921277Sbde/*14*/	{ "adc",   FALSE, BYTE,  op2(I, A),  0 },
5704Srgrimes/*15*/	{ "adc",   FALSE, LONG,  op2(Is, A), 0 },
5714Srgrimes/*16*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
5724Srgrimes/*17*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },
5734Srgrimes
5744Srgrimes/*18*/	{ "sbb",   TRUE,  BYTE,  op2(R, E),  0 },
5754Srgrimes/*19*/	{ "sbb",   TRUE,  LONG,  op2(R, E),  0 },
5764Srgrimes/*1a*/	{ "sbb",   TRUE,  BYTE,  op2(E, R),  0 },
5774Srgrimes/*1b*/	{ "sbb",   TRUE,  LONG,  op2(E, R),  0 },
57821277Sbde/*1c*/	{ "sbb",   FALSE, BYTE,  op2(I, A),  0 },
5794Srgrimes/*1d*/	{ "sbb",   FALSE, LONG,  op2(Is, A), 0 },
5804Srgrimes/*1e*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
5814Srgrimes/*1f*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },
5824Srgrimes
5834Srgrimes/*20*/	{ "and",   TRUE,  BYTE,  op2(R, E),  0 },
5844Srgrimes/*21*/	{ "and",   TRUE,  LONG,  op2(R, E),  0 },
5854Srgrimes/*22*/	{ "and",   TRUE,  BYTE,  op2(E, R),  0 },
5864Srgrimes/*23*/	{ "and",   TRUE,  LONG,  op2(E, R),  0 },
5874Srgrimes/*24*/	{ "and",   FALSE, BYTE,  op2(I, A),  0 },
5884Srgrimes/*25*/	{ "and",   FALSE, LONG,  op2(I, A),  0 },
5894Srgrimes/*26*/	{ "",      FALSE, NONE,  0,	     0 },
59021277Sbde/*27*/	{ "daa",   FALSE, NONE,  0,	     0 },
5914Srgrimes
5924Srgrimes/*28*/	{ "sub",   TRUE,  BYTE,  op2(R, E),  0 },
5934Srgrimes/*29*/	{ "sub",   TRUE,  LONG,  op2(R, E),  0 },
5944Srgrimes/*2a*/	{ "sub",   TRUE,  BYTE,  op2(E, R),  0 },
5954Srgrimes/*2b*/	{ "sub",   TRUE,  LONG,  op2(E, R),  0 },
59621277Sbde/*2c*/	{ "sub",   FALSE, BYTE,  op2(I, A),  0 },
5974Srgrimes/*2d*/	{ "sub",   FALSE, LONG,  op2(Is, A), 0 },
5984Srgrimes/*2e*/	{ "",      FALSE, NONE,  0,	     0 },
5994Srgrimes/*2f*/	{ "das",   FALSE, NONE,  0,	     0 },
6004Srgrimes
6014Srgrimes/*30*/	{ "xor",   TRUE,  BYTE,  op2(R, E),  0 },
6024Srgrimes/*31*/	{ "xor",   TRUE,  LONG,  op2(R, E),  0 },
6034Srgrimes/*32*/	{ "xor",   TRUE,  BYTE,  op2(E, R),  0 },
6044Srgrimes/*33*/	{ "xor",   TRUE,  LONG,  op2(E, R),  0 },
6054Srgrimes/*34*/	{ "xor",   FALSE, BYTE,  op2(I, A),  0 },
6064Srgrimes/*35*/	{ "xor",   FALSE, LONG,  op2(I, A),  0 },
6074Srgrimes/*36*/	{ "",      FALSE, NONE,  0,	     0 },
60821277Sbde/*37*/	{ "aaa",   FALSE, NONE,  0,	     0 },
6094Srgrimes
6104Srgrimes/*38*/	{ "cmp",   TRUE,  BYTE,  op2(R, E),  0 },
6114Srgrimes/*39*/	{ "cmp",   TRUE,  LONG,  op2(R, E),  0 },
6124Srgrimes/*3a*/	{ "cmp",   TRUE,  BYTE,  op2(E, R),  0 },
6134Srgrimes/*3b*/	{ "cmp",   TRUE,  LONG,  op2(E, R),  0 },
61421277Sbde/*3c*/	{ "cmp",   FALSE, BYTE,  op2(I, A),  0 },
6154Srgrimes/*3d*/	{ "cmp",   FALSE, LONG,  op2(Is, A), 0 },
6164Srgrimes/*3e*/	{ "",      FALSE, NONE,  0,	     0 },
6174Srgrimes/*3f*/	{ "aas",   FALSE, NONE,  0,	     0 },
6184Srgrimes
619144353Speter/*40*/	{ "rex",   FALSE, NONE,  0,          0 },
620144353Speter/*41*/	{ "rex.b", FALSE, NONE,  0,          0 },
621144353Speter/*42*/	{ "rex.x", FALSE, NONE,  0,          0 },
622144353Speter/*43*/	{ "rex.xb", FALSE, NONE, 0,          0 },
623144353Speter/*44*/	{ "rex.r", FALSE, NONE,  0,          0 },
624144353Speter/*45*/	{ "rex.rb", FALSE, NONE, 0,          0 },
625144353Speter/*46*/	{ "rex.rx", FALSE, NONE, 0,          0 },
626144353Speter/*47*/	{ "rex.rxb", FALSE, NONE, 0,         0 },
6274Srgrimes
628144353Speter/*48*/	{ "rex.w", FALSE, NONE,  0,          0 },
629144353Speter/*49*/	{ "rex.wb", FALSE, NONE, 0,          0 },
630144353Speter/*4a*/	{ "rex.wx", FALSE, NONE, 0,          0 },
631144353Speter/*4b*/	{ "rex.wxb", FALSE, NONE, 0,         0 },
632144353Speter/*4c*/	{ "rex.wr", FALSE, NONE, 0,          0 },
633144353Speter/*4d*/	{ "rex.wrb", FALSE, NONE, 0,         0 },
634144353Speter/*4e*/	{ "rex.wrx", FALSE, NONE, 0,         0 },
635144353Speter/*4f*/	{ "rex.wrxb", FALSE, NONE, 0,        0 },
6364Srgrimes
6374Srgrimes/*50*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
6384Srgrimes/*51*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
6394Srgrimes/*52*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
6404Srgrimes/*53*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
6414Srgrimes/*54*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
6424Srgrimes/*55*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
6434Srgrimes/*56*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
6444Srgrimes/*57*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
6454Srgrimes
6464Srgrimes/*58*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
6474Srgrimes/*59*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
6484Srgrimes/*5a*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
6494Srgrimes/*5b*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
6504Srgrimes/*5c*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
6514Srgrimes/*5d*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
6524Srgrimes/*5e*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
6534Srgrimes/*5f*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
6544Srgrimes
6554Srgrimes/*60*/	{ "pusha", FALSE, LONG,  0,	     0 },
6564Srgrimes/*61*/	{ "popa",  FALSE, LONG,  0,	     0 },
6574Srgrimes/*62*/  { "bound", TRUE,  LONG,  op2(E, R),  0 },
658144354Speter/*63*/	{ "movslq",  TRUE,  NONE,  op2(EL,R), 0 },
6594Srgrimes
6604Srgrimes/*64*/	{ "",      FALSE, NONE,  0,	     0 },
6614Srgrimes/*65*/	{ "",      FALSE, NONE,  0,	     0 },
6624Srgrimes/*66*/	{ "",      FALSE, NONE,  0,	     0 },
6634Srgrimes/*67*/	{ "",      FALSE, NONE,  0,	     0 },
6644Srgrimes
6654Srgrimes/*68*/	{ "push",  FALSE, LONG,  op1(I),     0 },
6664Srgrimes/*69*/  { "imul",  TRUE,  LONG,  op3(I,E,R), 0 },
66721277Sbde/*6a*/	{ "push",  FALSE, LONG,  op1(Ibs),   0 },
6684Srgrimes/*6b*/  { "imul",  TRUE,  LONG,  op3(Ibs,E,R),0 },
6694Srgrimes/*6c*/	{ "ins",   FALSE, BYTE,  op2(DX, DI), 0 },
6704Srgrimes/*6d*/	{ "ins",   FALSE, LONG,  op2(DX, DI), 0 },
6714Srgrimes/*6e*/	{ "outs",  FALSE, BYTE,  op2(SI, DX), 0 },
6724Srgrimes/*6f*/	{ "outs",  FALSE, LONG,  op2(SI, DX), 0 },
6734Srgrimes
6744Srgrimes/*70*/	{ "jo",    FALSE, NONE,  op1(Db),     0 },
6754Srgrimes/*71*/	{ "jno",   FALSE, NONE,  op1(Db),     0 },
6764Srgrimes/*72*/	{ "jb",    FALSE, NONE,  op1(Db),     0 },
6774Srgrimes/*73*/	{ "jnb",   FALSE, NONE,  op1(Db),     0 },
6784Srgrimes/*74*/	{ "jz",    FALSE, NONE,  op1(Db),     0 },
6794Srgrimes/*75*/	{ "jnz",   FALSE, NONE,  op1(Db),     0 },
6804Srgrimes/*76*/	{ "jbe",   FALSE, NONE,  op1(Db),     0 },
6814Srgrimes/*77*/	{ "jnbe",  FALSE, NONE,  op1(Db),     0 },
6824Srgrimes
6834Srgrimes/*78*/	{ "js",    FALSE, NONE,  op1(Db),     0 },
6844Srgrimes/*79*/	{ "jns",   FALSE, NONE,  op1(Db),     0 },
6854Srgrimes/*7a*/	{ "jp",    FALSE, NONE,  op1(Db),     0 },
6864Srgrimes/*7b*/	{ "jnp",   FALSE, NONE,  op1(Db),     0 },
6874Srgrimes/*7c*/	{ "jl",    FALSE, NONE,  op1(Db),     0 },
6884Srgrimes/*7d*/	{ "jnl",   FALSE, NONE,  op1(Db),     0 },
6894Srgrimes/*7e*/	{ "jle",   FALSE, NONE,  op1(Db),     0 },
6904Srgrimes/*7f*/	{ "jnle",  FALSE, NONE,  op1(Db),     0 },
6914Srgrimes
69217109Sbde/*80*/  { "",	   TRUE,  BYTE,  op2(I, E),   db_Grp1 },
69317109Sbde/*81*/  { "",	   TRUE,  LONG,  op2(I, E),   db_Grp1 },
69421277Sbde/*82*/  { "",	   TRUE,  BYTE,  op2(I, E),   db_Grp1 },
69517109Sbde/*83*/  { "",	   TRUE,  LONG,  op2(Ibs,E),  db_Grp1 },
6964Srgrimes/*84*/	{ "test",  TRUE,  BYTE,  op2(R, E),   0 },
6974Srgrimes/*85*/	{ "test",  TRUE,  LONG,  op2(R, E),   0 },
6984Srgrimes/*86*/	{ "xchg",  TRUE,  BYTE,  op2(R, E),   0 },
6994Srgrimes/*87*/	{ "xchg",  TRUE,  LONG,  op2(R, E),   0 },
7004Srgrimes
7014Srgrimes/*88*/	{ "mov",   TRUE,  BYTE,  op2(R, E),   0 },
7024Srgrimes/*89*/	{ "mov",   TRUE,  LONG,  op2(R, E),   0 },
7034Srgrimes/*8a*/	{ "mov",   TRUE,  BYTE,  op2(E, R),   0 },
7044Srgrimes/*8b*/	{ "mov",   TRUE,  LONG,  op2(E, R),   0 },
7054Srgrimes/*8c*/  { "mov",   TRUE,  NONE,  op2(S, Ew),  0 },
7064Srgrimes/*8d*/	{ "lea",   TRUE,  LONG,  op2(E, R),   0 },
7074Srgrimes/*8e*/	{ "mov",   TRUE,  NONE,  op2(Ew, S),  0 },
7084Srgrimes/*8f*/	{ "pop",   TRUE,  LONG,  op1(E),      0 },
7094Srgrimes
7104Srgrimes/*90*/	{ "nop",   FALSE, NONE,  0,	      0 },
7114Srgrimes/*91*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
7124Srgrimes/*92*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
7134Srgrimes/*93*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
7144Srgrimes/*94*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
7154Srgrimes/*95*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
7164Srgrimes/*96*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
7174Srgrimes/*97*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
7184Srgrimes
7194Srgrimes/*98*/	{ "cbw",   FALSE, SDEP,  0,	      "cwde" },	/* cbw/cwde */
7204Srgrimes/*99*/	{ "cwd",   FALSE, SDEP,  0,	      "cdq"  },	/* cwd/cdq */
7214Srgrimes/*9a*/	{ "lcall", FALSE, NONE,  op1(OS),     0 },
7224Srgrimes/*9b*/	{ "wait",  FALSE, NONE,  0,	      0 },
7234Srgrimes/*9c*/	{ "pushf", FALSE, LONG,  0,	      0 },
7244Srgrimes/*9d*/	{ "popf",  FALSE, LONG,  0,	      0 },
7254Srgrimes/*9e*/	{ "sahf",  FALSE, NONE,  0,	      0 },
7264Srgrimes/*9f*/	{ "lahf",  FALSE, NONE,  0,	      0 },
7274Srgrimes
7284Srgrimes/*a0*/	{ "mov",   FALSE, BYTE,  op2(O, A),   0 },
7294Srgrimes/*a1*/	{ "mov",   FALSE, LONG,  op2(O, A),   0 },
7304Srgrimes/*a2*/	{ "mov",   FALSE, BYTE,  op2(A, O),   0 },
7314Srgrimes/*a3*/	{ "mov",   FALSE, LONG,  op2(A, O),   0 },
7324Srgrimes/*a4*/	{ "movs",  FALSE, BYTE,  op2(SI,DI),  0 },
7334Srgrimes/*a5*/	{ "movs",  FALSE, LONG,  op2(SI,DI),  0 },
7344Srgrimes/*a6*/	{ "cmps",  FALSE, BYTE,  op2(SI,DI),  0 },
7354Srgrimes/*a7*/	{ "cmps",  FALSE, LONG,  op2(SI,DI),  0 },
7364Srgrimes
7374Srgrimes/*a8*/	{ "test",  FALSE, BYTE,  op2(I, A),   0 },
7384Srgrimes/*a9*/	{ "test",  FALSE, LONG,  op2(I, A),   0 },
7394Srgrimes/*aa*/	{ "stos",  FALSE, BYTE,  op1(DI),     0 },
7404Srgrimes/*ab*/	{ "stos",  FALSE, LONG,  op1(DI),     0 },
741118Srgrimes/*ac*/	{ "lods",  FALSE, BYTE,  op1(SI),     0 },
742118Srgrimes/*ad*/	{ "lods",  FALSE, LONG,  op1(SI),     0 },
7434Srgrimes/*ae*/	{ "scas",  FALSE, BYTE,  op1(SI),     0 },
7444Srgrimes/*af*/	{ "scas",  FALSE, LONG,  op1(SI),     0 },
7454Srgrimes
7464Srgrimes/*b0*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
7474Srgrimes/*b1*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
7484Srgrimes/*b2*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
7494Srgrimes/*b3*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
7504Srgrimes/*b4*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
7514Srgrimes/*b5*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
7524Srgrimes/*b6*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
7534Srgrimes/*b7*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
7544Srgrimes
755164263Sjhb/*b8*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
756164263Sjhb/*b9*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
757164263Sjhb/*ba*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
758164263Sjhb/*bb*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
759164263Sjhb/*bc*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
760164263Sjhb/*bd*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
761164263Sjhb/*be*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
762164263Sjhb/*bf*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
7634Srgrimes
76417109Sbde/*c0*/	{ "",	   TRUE,  BYTE,  op2(Ib, E),  db_Grp2 },
76517109Sbde/*c1*/	{ "",	   TRUE,  LONG,  op2(Ib, E),  db_Grp2 },
7664Srgrimes/*c2*/	{ "ret",   FALSE, NONE,  op1(Iw),     0 },
7674Srgrimes/*c3*/	{ "ret",   FALSE, NONE,  0,	      0 },
7684Srgrimes/*c4*/	{ "les",   TRUE,  LONG,  op2(E, R),   0 },
7694Srgrimes/*c5*/	{ "lds",   TRUE,  LONG,  op2(E, R),   0 },
7704Srgrimes/*c6*/	{ "mov",   TRUE,  BYTE,  op2(I, E),   0 },
7714Srgrimes/*c7*/	{ "mov",   TRUE,  LONG,  op2(I, E),   0 },
7724Srgrimes
77321277Sbde/*c8*/	{ "enter", FALSE, NONE,  op2(Iw, Ib), 0 },
7744Srgrimes/*c9*/	{ "leave", FALSE, NONE,  0,           0 },
7754Srgrimes/*ca*/	{ "lret",  FALSE, NONE,  op1(Iw),     0 },
7764Srgrimes/*cb*/	{ "lret",  FALSE, NONE,  0,	      0 },
7774Srgrimes/*cc*/	{ "int",   FALSE, NONE,  op1(o3),     0 },
7784Srgrimes/*cd*/	{ "int",   FALSE, NONE,  op1(Ib),     0 },
7794Srgrimes/*ce*/	{ "into",  FALSE, NONE,  0,	      0 },
7804Srgrimes/*cf*/	{ "iret",  FALSE, NONE,  0,	      0 },
7814Srgrimes
78217109Sbde/*d0*/	{ "",	   TRUE,  BYTE,  op2(o1, E),  db_Grp2 },
78317109Sbde/*d1*/	{ "",	   TRUE,  LONG,  op2(o1, E),  db_Grp2 },
78417109Sbde/*d2*/	{ "",	   TRUE,  BYTE,  op2(CL, E),  db_Grp2 },
78517109Sbde/*d3*/	{ "",	   TRUE,  LONG,  op2(CL, E),  db_Grp2 },
78621277Sbde/*d4*/	{ "aam",   FALSE, NONE,  op1(Iba),    0 },
78721277Sbde/*d5*/	{ "aad",   FALSE, NONE,  op1(Iba),    0 },
78821277Sbde/*d6*/	{ ".byte\t0xd6", FALSE, NONE, 0,      0 },
7894Srgrimes/*d7*/	{ "xlat",  FALSE, BYTE,  op1(BX),     0 },
7904Srgrimes
79117109Sbde/*d8*/  { "",      TRUE,  NONE,  0,	      db_Esc8 },
79217109Sbde/*d9*/  { "",      TRUE,  NONE,  0,	      db_Esc9 },
79317109Sbde/*da*/  { "",      TRUE,  NONE,  0,	      db_Esca },
79417109Sbde/*db*/  { "",      TRUE,  NONE,  0,	      db_Escb },
79517109Sbde/*dc*/  { "",      TRUE,  NONE,  0,	      db_Escc },
79617109Sbde/*dd*/  { "",      TRUE,  NONE,  0,	      db_Escd },
79717109Sbde/*de*/  { "",      TRUE,  NONE,  0,	      db_Esce },
79817109Sbde/*df*/  { "",      TRUE,  NONE,  0,	      db_Escf },
7994Srgrimes
8004Srgrimes/*e0*/	{ "loopne",FALSE, NONE,  op1(Db),     0 },
8014Srgrimes/*e1*/	{ "loope", FALSE, NONE,  op1(Db),     0 },
8024Srgrimes/*e2*/	{ "loop",  FALSE, NONE,  op1(Db),     0 },
8034Srgrimes/*e3*/	{ "jcxz",  FALSE, SDEP,  op1(Db),     "jecxz" },
8044Srgrimes/*e4*/	{ "in",    FALSE, BYTE,  op2(Ib, A),  0 },
8054Srgrimes/*e5*/	{ "in",    FALSE, LONG,  op2(Ib, A) , 0 },
8064Srgrimes/*e6*/	{ "out",   FALSE, BYTE,  op2(A, Ib),  0 },
8074Srgrimes/*e7*/	{ "out",   FALSE, LONG,  op2(A, Ib) , 0 },
8084Srgrimes
8094Srgrimes/*e8*/	{ "call",  FALSE, NONE,  op1(Dl),     0 },
8104Srgrimes/*e9*/	{ "jmp",   FALSE, NONE,  op1(Dl),     0 },
8114Srgrimes/*ea*/	{ "ljmp",  FALSE, NONE,  op1(OS),     0 },
8124Srgrimes/*eb*/	{ "jmp",   FALSE, NONE,  op1(Db),     0 },
8134Srgrimes/*ec*/	{ "in",    FALSE, BYTE,  op2(DX, A),  0 },
8144Srgrimes/*ed*/	{ "in",    FALSE, LONG,  op2(DX, A) , 0 },
8154Srgrimes/*ee*/	{ "out",   FALSE, BYTE,  op2(A, DX),  0 },
8164Srgrimes/*ef*/	{ "out",   FALSE, LONG,  op2(A, DX) , 0 },
8174Srgrimes
8184Srgrimes/*f0*/	{ "",      FALSE, NONE,  0,	     0 },
81921277Sbde/*f1*/	{ ".byte\t0xf1", FALSE, NONE, 0,     0 },
8204Srgrimes/*f2*/	{ "",      FALSE, NONE,  0,	     0 },
8214Srgrimes/*f3*/	{ "",      FALSE, NONE,  0,	     0 },
8224Srgrimes/*f4*/	{ "hlt",   FALSE, NONE,  0,	     0 },
8234Srgrimes/*f5*/	{ "cmc",   FALSE, NONE,  0,	     0 },
82417109Sbde/*f6*/	{ "",      TRUE,  BYTE,  0,	     db_Grp3 },
82517109Sbde/*f7*/	{ "",	   TRUE,  LONG,  0,	     db_Grp3 },
8264Srgrimes
8274Srgrimes/*f8*/	{ "clc",   FALSE, NONE,  0,	     0 },
8284Srgrimes/*f9*/	{ "stc",   FALSE, NONE,  0,	     0 },
8294Srgrimes/*fa*/	{ "cli",   FALSE, NONE,  0,	     0 },
8304Srgrimes/*fb*/	{ "sti",   FALSE, NONE,  0,	     0 },
8314Srgrimes/*fc*/	{ "cld",   FALSE, NONE,  0,	     0 },
8324Srgrimes/*fd*/	{ "std",   FALSE, NONE,  0,	     0 },
83317109Sbde/*fe*/	{ "",	   TRUE,  NONE,  0,	     db_Grp4 },
83417109Sbde/*ff*/	{ "",	   TRUE,  NONE,  0,	     db_Grp5 },
8354Srgrimes};
8364Srgrimes
83717109Sbdestatic const struct inst db_bad_inst =
8384Srgrimes	{ "???",   FALSE, NONE,  0,	      0 }
8394Srgrimes;
8404Srgrimes
841144353Speter#define	f_mod(rex, byte)	((byte)>>6)
842144353Speter#define	f_reg(rex, byte)	((((byte)>>3)&0x7) | (rex & REX_R ? 0x8 : 0x0))
843144353Speter#define	f_rm(rex, byte)		(((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0))
8444Srgrimes
845144353Speter#define	sib_ss(rex, byte)	((byte)>>6)
846144353Speter#define	sib_index(rex, byte)	((((byte)>>3)&0x7) | (rex & REX_X ? 0x8 : 0x0))
847144353Speter#define	sib_base(rex, byte)	(((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0))
8484Srgrimes
84911940Sbdestruct i_addr {
8504Srgrimes	int		is_reg;	/* if reg, reg number is in 'disp' */
8514Srgrimes	int		disp;
85214887Swollman	const char *	base;
85314887Swollman	const char *	index;
8544Srgrimes	int		ss;
8554Srgrimes};
8564Srgrimes
857144353Speterstatic const char * const db_reg[2][4][16] = {
858144353Speter
859144353Speter	{{"%al",  "%cl",  "%dl",  "%bl",  "%ah",  "%ch",  "%dh",  "%bh",
860144353Speter	  "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" },
861144353Speter	{ "%ax",  "%cx",  "%dx",  "%bx",  "%sp",  "%bp",  "%si",  "%di",
862144353Speter	  "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" },
863144353Speter	{ "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
864144353Speter	  "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" },
865144353Speter	{ "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
866144353Speter	  "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }},
867144353Speter
868144353Speter	{{"%al",  "%cl",  "%dl",  "%bl",  "%spl",  "%bpl",  "%sil",  "%dil",
869144353Speter	  "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" },
870144353Speter	{ "%ax",  "%cx",  "%dx",  "%bx",  "%sp",  "%bp",  "%si",  "%di",
871144353Speter	  "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" },
872144353Speter	{ "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
873144353Speter	  "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" },
874144353Speter	{ "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
875144353Speter	  "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }}
8764Srgrimes};
8774Srgrimes
87817109Sbdestatic const char * const db_seg_reg[8] = {
8794Srgrimes	"%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
8804Srgrimes};
8814Srgrimes
8824Srgrimes/*
8834Srgrimes * lengths for size attributes
8844Srgrimes */
88514887Swollmanstatic const int db_lengths[] = {
8864Srgrimes	1,	/* BYTE */
8874Srgrimes	2,	/* WORD */
8884Srgrimes	4,	/* LONG */
8894Srgrimes	8,	/* QUAD */
8904Srgrimes	4,	/* SNGL */
8914Srgrimes	8,	/* DBLR */
8924Srgrimes	10,	/* EXTR */
8934Srgrimes};
8944Srgrimes
8954Srgrimes#define	get_value_inc(result, loc, size, is_signed) \
8964Srgrimes	result = db_get_value((loc), (size), (is_signed)); \
8974Srgrimes	(loc) += (size);
8984Srgrimes
89911940Sbdestatic db_addr_t
900144353Speter		db_disasm_esc(db_addr_t loc, int inst, int rex, int short_addr,
90193017Sbde		    int size, const char *seg);
902144353Speterstatic void	db_print_address(const char *seg, int size, int rex,
90393017Sbde		    struct i_addr *addrp);
90411940Sbdestatic db_addr_t
905144353Speter		db_read_address(db_addr_t loc, int short_addr, int rex, int regmodrm,
90693017Sbde		    struct i_addr *addrp);
90711940Sbde
9084Srgrimes/*
9094Srgrimes * Read address at location and return updated location.
9104Srgrimes */
91111921Sphkstatic db_addr_t
912144353Speterdb_read_address(loc, short_addr, rex, regmodrm, addrp)
9134Srgrimes	db_addr_t	loc;
9144Srgrimes	int		short_addr;
915144353Speter	int		rex;
9164Srgrimes	int		regmodrm;
91717109Sbde	struct i_addr *	addrp;		/* out */
9184Srgrimes{
919164263Sjhb	int		mod, rm, sib, index, disp, size, have_sib;
9204Srgrimes
921144353Speter	mod = f_mod(rex, regmodrm);
922144353Speter	rm  = f_rm(rex, regmodrm);
9234Srgrimes
9244Srgrimes	if (mod == 3) {
9254Srgrimes	    addrp->is_reg = TRUE;
9264Srgrimes	    addrp->disp = rm;
9274Srgrimes	    return (loc);
9284Srgrimes	}
9294Srgrimes	addrp->is_reg = FALSE;
9304Srgrimes	addrp->index = 0;
9314Srgrimes
932164263Sjhb	if (short_addr)
933164263Sjhb	    size = LONG;
934164263Sjhb	else
935164263Sjhb	    size = QUAD;
9364Srgrimes
937164263Sjhb	if ((rm & 0x7) == 4) {
938164263Sjhb	    get_value_inc(sib, loc, 1, FALSE);
939164263Sjhb	    rm = sib_base(rex, sib);
940164263Sjhb	    index = sib_index(rex, sib);
941164263Sjhb	    if (index != 4)
942164263Sjhb		addrp->index = db_reg[1][size][index];
943164263Sjhb	    addrp->ss = sib_ss(rex, sib);
944164263Sjhb	    have_sib = 1;
945164263Sjhb	} else
946164263Sjhb	    have_sib = 0;
947164263Sjhb
948164263Sjhb	switch (mod) {
949164263Sjhb	    case 0:
950164263Sjhb		if (rm == 5) {
951164263Sjhb		    get_value_inc(addrp->disp, loc, 4, FALSE);
952164263Sjhb		    if (have_sib)
9534Srgrimes			addrp->base = 0;
954164263Sjhb		    else if (short_addr)
955164263Sjhb			addrp->base = "%eip";
956164263Sjhb		    else
957164263Sjhb			addrp->base = "%rip";
958164263Sjhb		} else {
959164263Sjhb		    addrp->disp = 0;
960164263Sjhb		    addrp->base = db_reg[1][size][rm];
961164263Sjhb		}
962164263Sjhb		break;
9634Srgrimes
964164263Sjhb	    case 1:
965164263Sjhb		get_value_inc(disp, loc, 1, TRUE);
966164263Sjhb		addrp->disp = disp;
967164263Sjhb		addrp->base = db_reg[1][size][rm];
968164263Sjhb		break;
9694Srgrimes
970164263Sjhb	    case 2:
971164263Sjhb		get_value_inc(disp, loc, 4, FALSE);
972164263Sjhb		addrp->disp = disp;
973164263Sjhb		addrp->base = db_reg[1][size][rm];
974164263Sjhb		break;
9754Srgrimes	}
9764Srgrimes	return (loc);
9774Srgrimes}
9784Srgrimes
97911921Sphkstatic void
980144353Speterdb_print_address(seg, size, rex, addrp)
98117109Sbde	const char *	seg;
9824Srgrimes	int		size;
983144353Speter	int		rex;
98417109Sbde	struct i_addr *	addrp;
9854Srgrimes{
9864Srgrimes	if (addrp->is_reg) {
987144354Speter	    db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][addrp->disp]);
9884Srgrimes	    return;
9894Srgrimes	}
9904Srgrimes
9914Srgrimes	if (seg) {
9924Srgrimes	    db_printf("%s:", seg);
9934Srgrimes	}
9944Srgrimes
995164263Sjhb	if (addrp->disp != 0 || (addrp->base == 0 && addrp->index == 0))
996164263Sjhb		db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY);
9974Srgrimes	if (addrp->base != 0 || addrp->index != 0) {
9984Srgrimes	    db_printf("(");
9994Srgrimes	    if (addrp->base)
10004Srgrimes		db_printf("%s", addrp->base);
10014Srgrimes	    if (addrp->index)
10024Srgrimes		db_printf(",%s,%d", addrp->index, 1<<addrp->ss);
10034Srgrimes	    db_printf(")");
10044Srgrimes	}
10054Srgrimes}
10064Srgrimes
10074Srgrimes/*
10084Srgrimes * Disassemble floating-point ("escape") instruction
10094Srgrimes * and return updated location.
10104Srgrimes */
101111921Sphkstatic db_addr_t
1012144353Speterdb_disasm_esc(loc, inst, rex, short_addr, size, seg)
10134Srgrimes	db_addr_t	loc;
10144Srgrimes	int		inst;
1015144353Speter	int		rex;
10164Srgrimes	int		short_addr;
10174Srgrimes	int		size;
101817109Sbde	const char *	seg;
10194Srgrimes{
10204Srgrimes	int		regmodrm;
102117109Sbde	const struct finst *	fp;
10224Srgrimes	int		mod;
10234Srgrimes	struct i_addr	address;
102417109Sbde	const char *	name;
10254Srgrimes
10264Srgrimes	get_value_inc(regmodrm, loc, 1, FALSE);
1027144353Speter	fp = &db_Esc_inst[inst - 0xd8][f_reg(rex, regmodrm)];
1028144353Speter	mod = f_mod(rex, regmodrm);
10294Srgrimes	if (mod != 3) {
103021277Sbde	    if (*fp->f_name == '\0') {
103121277Sbde		db_printf("<bad instruction>");
103221277Sbde		return (loc);
103321277Sbde	    }
10344Srgrimes	    /*
10354Srgrimes	     * Normal address modes.
10364Srgrimes	     */
1037144353Speter	    loc = db_read_address(loc, short_addr, rex, regmodrm, &address);
103879885Skris	    db_printf("%s", fp->f_name);
10394Srgrimes	    switch(fp->f_size) {
10404Srgrimes		case SNGL:
10414Srgrimes		    db_printf("s");
10424Srgrimes		    break;
10434Srgrimes		case DBLR:
10444Srgrimes		    db_printf("l");
10454Srgrimes		    break;
10464Srgrimes		case EXTR:
10474Srgrimes		    db_printf("t");
10484Srgrimes		    break;
10494Srgrimes		case WORD:
10504Srgrimes		    db_printf("s");
10514Srgrimes		    break;
10524Srgrimes		case LONG:
10534Srgrimes		    db_printf("l");
10544Srgrimes		    break;
10554Srgrimes		case QUAD:
10564Srgrimes		    db_printf("q");
10574Srgrimes		    break;
10584Srgrimes		default:
10594Srgrimes		    break;
10604Srgrimes	    }
10614Srgrimes	    db_printf("\t");
1062144353Speter	    db_print_address(seg, BYTE, rex, &address);
10634Srgrimes	}
10644Srgrimes	else {
10654Srgrimes	    /*
10664Srgrimes	     * 'reg-reg' - special formats
10674Srgrimes	     */
10684Srgrimes	    switch (fp->f_rrmode) {
10694Srgrimes		case op2(ST,STI):
10704Srgrimes		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1071144353Speter		    db_printf("%s\t%%st,%%st(%d)",name,f_rm(rex, regmodrm));
10724Srgrimes		    break;
10734Srgrimes		case op2(STI,ST):
10744Srgrimes		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1075144353Speter		    db_printf("%s\t%%st(%d),%%st",name, f_rm(rex, regmodrm));
10764Srgrimes		    break;
10774Srgrimes		case op1(STI):
10784Srgrimes		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1079144353Speter		    db_printf("%s\t%%st(%d)",name, f_rm(rex, regmodrm));
10804Srgrimes		    break;
10814Srgrimes		case op1(X):
1082144353Speter		    name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)];
108321277Sbde		    if (*name == '\0')
108421277Sbde			goto bad;
108521277Sbde		    db_printf("%s", name);
10864Srgrimes		    break;
10874Srgrimes		case op1(XA):
1088144353Speter		    name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)];
108921277Sbde		    if (*name == '\0')
109021277Sbde			goto bad;
109121277Sbde		    db_printf("%s\t%%ax", name);
10924Srgrimes		    break;
10934Srgrimes		default:
109421277Sbde		bad:
10954Srgrimes		    db_printf("<bad instruction>");
10964Srgrimes		    break;
10974Srgrimes	    }
10984Srgrimes	}
10994Srgrimes
11004Srgrimes	return (loc);
11014Srgrimes}
11024Srgrimes
11034Srgrimes/*
11044Srgrimes * Disassemble instruction at 'loc'.  'altfmt' specifies an
11054Srgrimes * (optional) alternate format.  Return address of start of
11064Srgrimes * next instruction.
11074Srgrimes */
11084Srgrimesdb_addr_t
11094Srgrimesdb_disasm(loc, altfmt)
11104Srgrimes	db_addr_t	loc;
11114Srgrimes	boolean_t	altfmt;
11124Srgrimes{
11134Srgrimes	int	inst;
11144Srgrimes	int	size;
11154Srgrimes	int	short_addr;
111617109Sbde	const char *	seg;
111714887Swollman	const struct inst *	ip;
111814887Swollman	const char *	i_name;
11194Srgrimes	int	i_size;
11204Srgrimes	int	i_mode;
1121144353Speter	int	rex = 0;
1122798Swollman	int	regmodrm = 0;
11234Srgrimes	boolean_t	first;
11244Srgrimes	int	displ;
11254Srgrimes	int	prefix;
11264Srgrimes	int	imm;
11274Srgrimes	int	imm2;
1128164263Sjhb	long	imm64;
11294Srgrimes	int	len;
11304Srgrimes	struct i_addr	address;
11314Srgrimes
11324Srgrimes	get_value_inc(inst, loc, 1, FALSE);
11334Srgrimes	short_addr = FALSE;
11344Srgrimes	size = LONG;
11354Srgrimes	seg = 0;
11364Srgrimes
11374Srgrimes	/*
11384Srgrimes	 * Get prefixes
11394Srgrimes	 */
11404Srgrimes	prefix = TRUE;
11414Srgrimes	do {
11424Srgrimes	    switch (inst) {
11434Srgrimes		case 0x66:		/* data16 */
11444Srgrimes		    size = WORD;
11454Srgrimes		    break;
11464Srgrimes		case 0x67:
11474Srgrimes		    short_addr = TRUE;
11484Srgrimes		    break;
11494Srgrimes		case 0x26:
11504Srgrimes		    seg = "%es";
11514Srgrimes		    break;
11524Srgrimes		case 0x36:
11534Srgrimes		    seg = "%ss";
11544Srgrimes		    break;
11554Srgrimes		case 0x2e:
11564Srgrimes		    seg = "%cs";
11574Srgrimes		    break;
11584Srgrimes		case 0x3e:
11594Srgrimes		    seg = "%ds";
11604Srgrimes		    break;
11614Srgrimes		case 0x64:
11624Srgrimes		    seg = "%fs";
11634Srgrimes		    break;
11644Srgrimes		case 0x65:
11654Srgrimes		    seg = "%gs";
11664Srgrimes		    break;
11674Srgrimes		case 0xf0:
11684Srgrimes		    db_printf("lock ");
11694Srgrimes		    break;
11704Srgrimes		case 0xf2:
11714Srgrimes		    db_printf("repne ");
11724Srgrimes		    break;
11734Srgrimes		case 0xf3:
11744Srgrimes		    db_printf("repe ");	/* XXX repe VS rep */
11754Srgrimes		    break;
11764Srgrimes		default:
11774Srgrimes		    prefix = FALSE;
11784Srgrimes		    break;
11794Srgrimes	    }
1180144353Speter	    if (inst >= 0x40 && inst < 0x50) {
1181144353Speter		rex = inst;
1182144353Speter		prefix = TRUE;
1183144353Speter	    }
11844Srgrimes	    if (prefix) {
11854Srgrimes		get_value_inc(inst, loc, 1, FALSE);
11864Srgrimes	    }
11874Srgrimes	} while (prefix);
11884Srgrimes
11894Srgrimes	if (inst >= 0xd8 && inst <= 0xdf) {
1190144353Speter	    loc = db_disasm_esc(loc, inst, rex, short_addr, size, seg);
11914Srgrimes	    db_printf("\n");
11924Srgrimes	    return (loc);
11934Srgrimes	}
11944Srgrimes
11954Srgrimes	if (inst == 0x0f) {
11964Srgrimes	    get_value_inc(inst, loc, 1, FALSE);
11974Srgrimes	    ip = db_inst_0f[inst>>4];
11984Srgrimes	    if (ip == 0) {
11994Srgrimes		ip = &db_bad_inst;
12004Srgrimes	    }
12014Srgrimes	    else {
12024Srgrimes		ip = &ip[inst&0xf];
12034Srgrimes	    }
12044Srgrimes	}
12054Srgrimes	else
12064Srgrimes	    ip = &db_inst_table[inst];
12074Srgrimes
12084Srgrimes	if (ip->i_has_modrm) {
12094Srgrimes	    get_value_inc(regmodrm, loc, 1, FALSE);
1210144353Speter	    loc = db_read_address(loc, short_addr, rex, regmodrm, &address);
12114Srgrimes	}
12124Srgrimes
12134Srgrimes	i_name = ip->i_name;
12144Srgrimes	i_size = ip->i_size;
12154Srgrimes	i_mode = ip->i_mode;
12164Srgrimes
121717109Sbde	if (ip->i_extra == db_Grp1 || ip->i_extra == db_Grp2 ||
121817109Sbde	    ip->i_extra == db_Grp6 || ip->i_extra == db_Grp7 ||
121921277Sbde	    ip->i_extra == db_Grp8 || ip->i_extra == db_Grp9) {
1220144353Speter	    i_name = ((const char * const *)ip->i_extra)[f_reg(rex, regmodrm)];
12214Srgrimes	}
122217109Sbde	else if (ip->i_extra == db_Grp3) {
122317109Sbde	    ip = ip->i_extra;
1224144353Speter	    ip = &ip[f_reg(rex, regmodrm)];
12254Srgrimes	    i_name = ip->i_name;
12264Srgrimes	    i_mode = ip->i_mode;
12274Srgrimes	}
122817109Sbde	else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) {
122917109Sbde	    ip = ip->i_extra;
1230144353Speter	    ip = &ip[f_reg(rex, regmodrm)];
12314Srgrimes	    i_name = ip->i_name;
12324Srgrimes	    i_mode = ip->i_mode;
12334Srgrimes	    i_size = ip->i_size;
12344Srgrimes	}
12354Srgrimes
12364Srgrimes	if (i_size == SDEP) {
12374Srgrimes	    if (size == WORD)
123879885Skris		db_printf("%s", i_name);
12394Srgrimes	    else
124079885Skris		db_printf("%s", (const char *)ip->i_extra);
12414Srgrimes	}
12424Srgrimes	else {
124379885Skris	    db_printf("%s", i_name);
1244144354Speter	    if ((inst >= 0x50 && inst <= 0x5f) || inst == 0x68 || inst == 0x6a) {
1245144354Speter		i_size = NONE;
1246144354Speter		db_printf("q");
1247144354Speter	    }
12484Srgrimes	    if (i_size != NONE) {
12494Srgrimes		if (i_size == BYTE) {
12504Srgrimes		    db_printf("b");
12514Srgrimes		    size = BYTE;
12524Srgrimes		}
12534Srgrimes		else if (i_size == WORD) {
12544Srgrimes		    db_printf("w");
12554Srgrimes		    size = WORD;
12564Srgrimes		}
12574Srgrimes		else if (size == WORD)
12584Srgrimes		    db_printf("w");
1259144353Speter		else {
1260144353Speter		    if (rex & REX_W)
1261144353Speter			db_printf("q");
1262144353Speter		    else
1263144353Speter			db_printf("l");
1264144353Speter		}
12654Srgrimes	    }
12664Srgrimes	}
12674Srgrimes	db_printf("\t");
12684Srgrimes	for (first = TRUE;
12694Srgrimes	     i_mode != 0;
12704Srgrimes	     i_mode >>= 8, first = FALSE)
12714Srgrimes	{
12724Srgrimes	    if (!first)
12734Srgrimes		db_printf(",");
12744Srgrimes
12754Srgrimes	    switch (i_mode & 0xFF) {
12764Srgrimes
12774Srgrimes		case E:
1278144353Speter		    db_print_address(seg, size, rex, &address);
12794Srgrimes		    break;
12804Srgrimes
12814Srgrimes		case Eind:
12824Srgrimes		    db_printf("*");
1283144353Speter		    db_print_address(seg, size, rex, &address);
12844Srgrimes		    break;
12854Srgrimes
128621277Sbde		case El:
1287144353Speter		    db_print_address(seg, (rex & REX_W) ? QUAD : LONG, rex, &address);
128821277Sbde		    break;
128921277Sbde
1290144354Speter		case EL:
1291144354Speter		    db_print_address(seg, LONG, 0, &address);
1292144354Speter		    break;
1293144354Speter
12944Srgrimes		case Ew:
1295144353Speter		    db_print_address(seg, WORD, rex, &address);
12964Srgrimes		    break;
12974Srgrimes
12984Srgrimes		case Eb:
1299144353Speter		    db_print_address(seg, BYTE, rex, &address);
13004Srgrimes		    break;
13014Srgrimes
13024Srgrimes		case R:
1303144354Speter		    db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][f_reg(rex, regmodrm)]);
13044Srgrimes		    break;
13054Srgrimes
13064Srgrimes		case Rw:
1307144353Speter		    db_printf("%s", db_reg[rex != 0 ? 1 : 0][WORD][f_reg(rex, regmodrm)]);
13084Srgrimes		    break;
13094Srgrimes
13104Srgrimes		case Ri:
1311144354Speter		    db_printf("%s", db_reg[0][QUAD][f_rm(rex, inst)]);
13124Srgrimes		    break;
13134Srgrimes
131421277Sbde		case Ril:
1315144353Speter		    db_printf("%s", db_reg[rex != 0 ? 1 : 0][(rex & REX_R) ? QUAD : LONG][f_rm(rex, inst)]);
131621277Sbde		    break;
131721277Sbde
13184Srgrimes		case S:
1319144353Speter		    db_printf("%s", db_seg_reg[f_reg(rex, regmodrm)]);
13204Srgrimes		    break;
13214Srgrimes
13224Srgrimes		case Si:
1323144353Speter		    db_printf("%s", db_seg_reg[f_reg(rex, inst)]);
13244Srgrimes		    break;
13254Srgrimes
13264Srgrimes		case A:
1327144353Speter		    db_printf("%s", db_reg[rex != 0 ? 1 : 0][size][0]);	/* acc */
13284Srgrimes		    break;
13294Srgrimes
13304Srgrimes		case BX:
13314Srgrimes		    if (seg)
13324Srgrimes			db_printf("%s:", seg);
13334Srgrimes		    db_printf("(%s)", short_addr ? "%bx" : "%ebx");
13344Srgrimes		    break;
13354Srgrimes
13364Srgrimes		case CL:
13374Srgrimes		    db_printf("%%cl");
13384Srgrimes		    break;
13394Srgrimes
13404Srgrimes		case DX:
13414Srgrimes		    db_printf("%%dx");
13424Srgrimes		    break;
13434Srgrimes
13444Srgrimes		case SI:
13454Srgrimes		    if (seg)
13464Srgrimes			db_printf("%s:", seg);
1347144353Speter		    db_printf("(%s)", short_addr ? "%si" : "%rsi");
13484Srgrimes		    break;
13494Srgrimes
13504Srgrimes		case DI:
1351144353Speter		    db_printf("%%es:(%s)", short_addr ? "%di" : "%rdi");
13524Srgrimes		    break;
13534Srgrimes
13544Srgrimes		case CR:
1355144353Speter		    db_printf("%%cr%d", f_reg(rex, regmodrm));
13564Srgrimes		    break;
13574Srgrimes
13584Srgrimes		case DR:
1359144353Speter		    db_printf("%%dr%d", f_reg(rex, regmodrm));
13604Srgrimes		    break;
13614Srgrimes
13624Srgrimes		case TR:
1363144353Speter		    db_printf("%%tr%d", f_reg(rex, regmodrm));
13644Srgrimes		    break;
13654Srgrimes
13664Srgrimes		case I:
1367144354Speter		    len = db_lengths[size];
136821277Sbde		    get_value_inc(imm, loc, len, FALSE);
136937506Sbde		    db_printf("$%#r", imm);
13704Srgrimes		    break;
13714Srgrimes
13724Srgrimes		case Is:
1373144353Speter		    len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
137421277Sbde		    get_value_inc(imm, loc, len, FALSE);
137537506Sbde		    db_printf("$%+#r", imm);
13764Srgrimes		    break;
13774Srgrimes
13784Srgrimes		case Ib:
137921277Sbde		    get_value_inc(imm, loc, 1, FALSE);
138037506Sbde		    db_printf("$%#r", imm);
13814Srgrimes		    break;
13824Srgrimes
138321277Sbde		case Iba:
138421277Sbde		    get_value_inc(imm, loc, 1, FALSE);
138521277Sbde		    if (imm != 0x0a)
138637506Sbde			db_printf("$%#r", imm);
138721277Sbde		    break;
138821277Sbde
13894Srgrimes		case Ibs:
139021277Sbde		    get_value_inc(imm, loc, 1, TRUE);
139121277Sbde		    if (size == WORD)
139221277Sbde			imm &= 0xFFFF;
139337506Sbde		    db_printf("$%+#r", imm);
13944Srgrimes		    break;
13954Srgrimes
13964Srgrimes		case Iw:
139721277Sbde		    get_value_inc(imm, loc, 2, FALSE);
139837506Sbde		    db_printf("$%#r", imm);
13994Srgrimes		    break;
14004Srgrimes
1401164263Sjhb		case Ilq:
1402164263Sjhb		    len = db_lengths[rex & REX_W ? QUAD : LONG];
1403164263Sjhb		    get_value_inc(imm64, loc, len, FALSE);
1404164263Sjhb		    db_printf("$%#lr", imm64);
1405164263Sjhb		    break;
1406164263Sjhb
14074Srgrimes		case O:
140821277Sbde		    len = (short_addr ? 2 : 4);
140921277Sbde		    get_value_inc(displ, loc, len, FALSE);
14104Srgrimes		    if (seg)
141137506Sbde			db_printf("%s:%+#r",seg, displ);
14124Srgrimes		    else
14134Srgrimes			db_printsym((db_addr_t)displ, DB_STGY_ANY);
14144Srgrimes		    break;
14154Srgrimes
14164Srgrimes		case Db:
14174Srgrimes		    get_value_inc(displ, loc, 1, TRUE);
141821277Sbde		    displ += loc;
141921277Sbde		    if (size == WORD)
142021277Sbde			displ &= 0xFFFF;
142121277Sbde		    db_printsym((db_addr_t)displ, DB_STGY_XTRN);
14224Srgrimes		    break;
14234Srgrimes
14244Srgrimes		case Dl:
1425144353Speter		    len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
142621277Sbde		    get_value_inc(displ, loc, len, FALSE);
142721277Sbde		    displ += loc;
142821277Sbde		    if (size == WORD)
142921277Sbde			displ &= 0xFFFF;
143021277Sbde		    db_printsym((db_addr_t)displ, DB_STGY_XTRN);
14314Srgrimes		    break;
14324Srgrimes
14334Srgrimes		case o1:
14344Srgrimes		    db_printf("$1");
14354Srgrimes		    break;
14364Srgrimes
14374Srgrimes		case o3:
14384Srgrimes		    db_printf("$3");
14394Srgrimes		    break;
14404Srgrimes
14414Srgrimes		case OS:
144221277Sbde		    len = db_lengths[size];
144321277Sbde		    get_value_inc(imm, loc, len, FALSE);	/* offset */
14444Srgrimes		    get_value_inc(imm2, loc, 2, FALSE);	/* segment */
144537506Sbde		    db_printf("$%#r,%#r", imm2, imm);
14464Srgrimes		    break;
14474Srgrimes	    }
14484Srgrimes	}
14494Srgrimes	db_printf("\n");
14504Srgrimes	return (loc);
14514Srgrimes}
1452