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: stable/11/sys/amd64/amd64/db_disasm.c 315221 2017-03-14 02:06:03Z pfg $");
29118031Sobrien
304Srgrimes/*
314Srgrimes * Instruction disassembler.
324Srgrimes */
332056Swollman#include <sys/param.h>
34238166Sjhb#include <sys/libkern.h>
3524494Sbde
362056Swollman#include <ddb/ddb.h>
374Srgrimes#include <ddb/db_access.h>
384Srgrimes#include <ddb/db_sym.h>
394Srgrimes
404Srgrimes/*
414Srgrimes * Size attributes
424Srgrimes */
434Srgrimes#define	BYTE	0
444Srgrimes#define	WORD	1
454Srgrimes#define	LONG	2
464Srgrimes#define	QUAD	3
474Srgrimes#define	SNGL	4
484Srgrimes#define	DBLR	5
494Srgrimes#define	EXTR	6
504Srgrimes#define	SDEP	7
51238166Sjhb#define	ADEP	8
52238166Sjhb#define	ESC	9
53238166Sjhb#define	NONE	10
544Srgrimes
554Srgrimes/*
56144353Speter * REX prefix and bits
57144353Speter */
58144353Speter#define REX_B	1
59144353Speter#define REX_X	2
60144353Speter#define REX_R	4
61144353Speter#define REX_W	8
62144353Speter#define REX	0x40
63144353Speter
64144353Speter/*
654Srgrimes * Addressing modes
664Srgrimes */
674Srgrimes#define	E	1			/* general effective address */
684Srgrimes#define	Eind	2			/* indirect address (jump, call) */
694Srgrimes#define	Ew	3			/* address, word size */
704Srgrimes#define	Eb	4			/* address, byte size */
714Srgrimes#define	R	5			/* register, in 'reg' field */
724Srgrimes#define	Rw	6			/* word register, in 'reg' field */
73238166Sjhb#define	Rq	39			/* quad register, in 'reg' field */
74266354Sjhb#define	Rv	40			/* register in 'r/m' field */
754Srgrimes#define	Ri	7			/* register in instruction */
764Srgrimes#define	S	8			/* segment reg, in 'reg' field */
774Srgrimes#define	Si	9			/* segment reg, in instruction */
784Srgrimes#define	A	10			/* accumulator */
794Srgrimes#define	BX	11			/* (bx) */
804Srgrimes#define	CL	12			/* cl, for shifts */
814Srgrimes#define	DX	13			/* dx, for IO */
824Srgrimes#define	SI	14			/* si */
834Srgrimes#define	DI	15			/* di */
844Srgrimes#define	CR	16			/* control register */
854Srgrimes#define	DR	17			/* debug register */
864Srgrimes#define	TR	18			/* test register */
874Srgrimes#define	I	19			/* immediate, unsigned */
884Srgrimes#define	Is	20			/* immediate, signed */
894Srgrimes#define	Ib	21			/* byte immediate, unsigned */
904Srgrimes#define	Ibs	22			/* byte immediate, signed */
914Srgrimes#define	Iw	23			/* word immediate, unsigned */
92164263Sjhb#define	Ilq	24			/* long/quad immediate, unsigned */
934Srgrimes#define	O	25			/* direct address */
944Srgrimes#define	Db	26			/* byte displacement from EIP */
954Srgrimes#define	Dl	27			/* long displacement from EIP */
964Srgrimes#define	o1	28			/* constant 1 */
974Srgrimes#define	o3	29			/* constant 3 */
984Srgrimes#define	OS	30			/* immediate offset/segment */
994Srgrimes#define	ST	31			/* FP stack top */
1004Srgrimes#define	STI	32			/* FP stack */
1014Srgrimes#define	X	33			/* extended FP op */
1024Srgrimes#define	XA	34			/* for 'fstcw %ax' */
103144354Speter#define	El	35			/* address, long/quad size */
10421277Sbde#define	Ril	36			/* long register in instruction */
10521277Sbde#define	Iba	37			/* byte immediate, don't print if 0xa */
106144354Speter#define	EL	38			/* address, explicitly long size */
1074Srgrimes
10811940Sbdestruct inst {
10914887Swollman	const char *	i_name;		/* name */
1104Srgrimes	short	i_has_modrm;		/* has regmodrm byte */
1114Srgrimes	short	i_size;			/* operand size */
1124Srgrimes	int	i_mode;			/* addressing modes */
11317109Sbde	const void *	i_extra;	/* pointer to extra opcode table */
1144Srgrimes};
1154Srgrimes
1164Srgrimes#define	op1(x)		(x)
1174Srgrimes#define	op2(x,y)	((x)|((y)<<8))
1184Srgrimes#define	op3(x,y,z)	((x)|((y)<<8)|((z)<<16))
1194Srgrimes
12011940Sbdestruct finst {
12114887Swollman	const char *	f_name;		/* name for memory instruction */
1224Srgrimes	int	f_size;			/* size for memory instruction */
1234Srgrimes	int	f_rrmode;		/* mode for rr instruction */
12417109Sbde	const void *	f_rrname;	/* name for rr instruction
1254Srgrimes					   (or pointer to table) */
1264Srgrimes};
1274Srgrimes
128238166Sjhbstatic const struct inst db_inst_0f388x[] = {
129238166Sjhb/*80*/	{ "",	   TRUE,  SDEP,  op2(E, Rq),  "invept" },
130238166Sjhb/*81*/	{ "",	   TRUE,  SDEP,  op2(E, Rq),  "invvpid" },
131255192Sjhb/*82*/	{ "",	   TRUE,  SDEP,  op2(E, Rq),  "invpcid" },
132238166Sjhb/*83*/	{ "",	   FALSE, NONE,  0,	      0 },
133238166Sjhb/*84*/	{ "",	   FALSE, NONE,  0,	      0 },
134238166Sjhb/*85*/	{ "",	   FALSE, NONE,  0,	      0 },
135238166Sjhb/*86*/	{ "",	   FALSE, NONE,  0,	      0 },
136238166Sjhb/*87*/	{ "",	   FALSE, NONE,  0,	      0 },
137238166Sjhb
138238166Sjhb/*88*/	{ "",	   FALSE, NONE,  0,	      0 },
139238166Sjhb/*89*/	{ "",	   FALSE, NONE,  0,	      0 },
140238166Sjhb/*8a*/	{ "",	   FALSE, NONE,  0,	      0 },
141238166Sjhb/*8b*/	{ "",	   FALSE, NONE,  0,	      0 },
142238166Sjhb/*8c*/	{ "",	   FALSE, NONE,  0,	      0 },
143238166Sjhb/*8d*/	{ "",	   FALSE, NONE,  0,	      0 },
144238166Sjhb/*8e*/	{ "",	   FALSE, NONE,  0,	      0 },
145238166Sjhb/*8f*/	{ "",	   FALSE, NONE,  0,	      0 },
146238166Sjhb};
147238166Sjhb
148238166Sjhbstatic const struct inst * const db_inst_0f38[] = {
149238166Sjhb	0,
150238166Sjhb	0,
151238166Sjhb	0,
152238166Sjhb	0,
153238166Sjhb	0,
154238166Sjhb	0,
155238166Sjhb	0,
156238166Sjhb	0,
157238166Sjhb	db_inst_0f388x,
158238166Sjhb	0,
159238166Sjhb	0,
160238166Sjhb	0,
161238166Sjhb	0,
162238166Sjhb	0,
163238166Sjhb	0,
164238166Sjhb	0
165238166Sjhb};
166238166Sjhb
16714887Swollmanstatic const char * const db_Grp6[] = {
1684Srgrimes	"sldt",
1694Srgrimes	"str",
1704Srgrimes	"lldt",
1714Srgrimes	"ltr",
1724Srgrimes	"verr",
1734Srgrimes	"verw",
1744Srgrimes	"",
1754Srgrimes	""
1764Srgrimes};
1774Srgrimes
17814887Swollmanstatic const char * const db_Grp7[] = {
1794Srgrimes	"sgdt",
1804Srgrimes	"sidt",
1814Srgrimes	"lgdt",
1824Srgrimes	"lidt",
1834Srgrimes	"smsw",
1844Srgrimes	"",
1854Srgrimes	"lmsw",
1864Srgrimes	"invlpg"
1874Srgrimes};
1884Srgrimes
18914887Swollmanstatic const char * const db_Grp8[] = {
1904Srgrimes	"",
1914Srgrimes	"",
1924Srgrimes	"",
1934Srgrimes	"",
1944Srgrimes	"bt",
1954Srgrimes	"bts",
1964Srgrimes	"btr",
1974Srgrimes	"btc"
1984Srgrimes};
1994Srgrimes
20021277Sbdestatic const char * const db_Grp9[] = {
20121277Sbde	"",
20221277Sbde	"cmpxchg8b",
20321277Sbde	"",
20421277Sbde	"",
20521277Sbde	"",
20621277Sbde	"",
207238166Sjhb	"vmptrld",
208238166Sjhb	"vmptrst"
20921277Sbde};
21021277Sbde
211181606Sjhbstatic const char * const db_Grp15[] = {
212181606Sjhb	"fxsave",
213181606Sjhb	"fxrstor",
214181606Sjhb	"ldmxcsr",
215181606Sjhb	"stmxcsr",
216238109Sjhb	"xsave",
217238109Sjhb	"xrstor",
218238109Sjhb	"xsaveopt",
219181606Sjhb	"clflush"
220181606Sjhb};
221181606Sjhb
222181606Sjhbstatic const char * const db_Grp15b[] = {
223181606Sjhb	"",
224181606Sjhb	"",
225181606Sjhb	"",
226181606Sjhb	"",
227181606Sjhb	"",
228181606Sjhb	"lfence",
229181606Sjhb	"mfence",
230181606Sjhb	"sfence"
231181606Sjhb};
232181606Sjhb
23314887Swollmanstatic const struct inst db_inst_0f0x[] = {
23417109Sbde/*00*/	{ "",	   TRUE,  NONE,  op1(Ew),     db_Grp6 },
23517109Sbde/*01*/	{ "",	   TRUE,  NONE,  op1(Ew),     db_Grp7 },
2364Srgrimes/*02*/	{ "lar",   TRUE,  LONG,  op2(E,R),    0 },
2374Srgrimes/*03*/	{ "lsl",   TRUE,  LONG,  op2(E,R),    0 },
2384Srgrimes/*04*/	{ "",      FALSE, NONE,  0,	      0 },
239181606Sjhb/*05*/	{ "syscall",FALSE,NONE,  0,	      0 },
2404Srgrimes/*06*/	{ "clts",  FALSE, NONE,  0,	      0 },
241181606Sjhb/*07*/	{ "sysret",FALSE, NONE,  0,	      0 },
2424Srgrimes
2434Srgrimes/*08*/	{ "invd",  FALSE, NONE,  0,	      0 },
2444Srgrimes/*09*/	{ "wbinvd",FALSE, NONE,  0,	      0 },
2454Srgrimes/*0a*/	{ "",      FALSE, NONE,  0,	      0 },
2464Srgrimes/*0b*/	{ "",      FALSE, NONE,  0,	      0 },
2474Srgrimes/*0c*/	{ "",      FALSE, NONE,  0,	      0 },
2484Srgrimes/*0d*/	{ "",      FALSE, NONE,  0,	      0 },
2494Srgrimes/*0e*/	{ "",      FALSE, NONE,  0,	      0 },
2504Srgrimes/*0f*/	{ "",      FALSE, NONE,  0,	      0 },
2514Srgrimes};
2524Srgrimes
253278655Smarkjstatic const struct inst db_inst_0f1x[] = {
254278655Smarkj/*10*/	{ "",      FALSE, NONE,  0,	      0 },
255278655Smarkj/*11*/	{ "",      FALSE, NONE,  0,	      0 },
256278655Smarkj/*12*/	{ "",      FALSE, NONE,  0,	      0 },
257278655Smarkj/*13*/	{ "",      FALSE, NONE,  0,	      0 },
258278655Smarkj/*14*/	{ "",      FALSE, NONE,  0,	      0 },
259278655Smarkj/*15*/	{ "",      FALSE, NONE,  0,	      0 },
260278655Smarkj/*16*/	{ "",      FALSE, NONE,  0,	      0 },
261278655Smarkj/*17*/	{ "",      FALSE, NONE,  0,	      0 },
262278655Smarkj
263278655Smarkj/*18*/	{ "",      FALSE, NONE,  0,	      0 },
264278655Smarkj/*19*/	{ "",      FALSE, NONE,  0,	      0 },
265278655Smarkj/*1a*/	{ "",      FALSE, NONE,  0,	      0 },
266278655Smarkj/*1b*/	{ "",      FALSE, NONE,  0,	      0 },
267278655Smarkj/*1c*/	{ "",      FALSE, NONE,  0,	      0 },
268278655Smarkj/*1d*/	{ "",      FALSE, NONE,  0,	      0 },
269278655Smarkj/*1e*/	{ "",      FALSE, NONE,  0,	      0 },
270278655Smarkj/*1f*/	{ "nopl",  TRUE,  SDEP,  0,	      "nopw" },
271278655Smarkj};
272278655Smarkj
27317109Sbdestatic const struct inst db_inst_0f2x[] = {
27421277Sbde/*20*/	{ "mov",   TRUE,  LONG,  op2(CR,El),  0 },
27521277Sbde/*21*/	{ "mov",   TRUE,  LONG,  op2(DR,El),  0 },
27621277Sbde/*22*/	{ "mov",   TRUE,  LONG,  op2(El,CR),  0 },
27721277Sbde/*23*/	{ "mov",   TRUE,  LONG,  op2(El,DR),  0 },
27821277Sbde/*24*/	{ "mov",   TRUE,  LONG,  op2(TR,El),  0 },
2794Srgrimes/*25*/	{ "",      FALSE, NONE,  0,	      0 },
28021277Sbde/*26*/	{ "mov",   TRUE,  LONG,  op2(El,TR),  0 },
2814Srgrimes/*27*/	{ "",      FALSE, NONE,  0,	      0 },
2824Srgrimes
2834Srgrimes/*28*/	{ "",      FALSE, NONE,  0,	      0 },
2844Srgrimes/*29*/	{ "",      FALSE, NONE,  0,	      0 },
2854Srgrimes/*2a*/	{ "",      FALSE, NONE,  0,	      0 },
2864Srgrimes/*2b*/	{ "",      FALSE, NONE,  0,	      0 },
2874Srgrimes/*2c*/	{ "",      FALSE, NONE,  0,	      0 },
2884Srgrimes/*2d*/	{ "",      FALSE, NONE,  0,	      0 },
2894Srgrimes/*2e*/	{ "",      FALSE, NONE,  0,	      0 },
2904Srgrimes/*2f*/	{ "",      FALSE, NONE,  0,	      0 },
2914Srgrimes};
2924Srgrimes
29314887Swollmanstatic const struct inst db_inst_0f3x[] = {
29414887Swollman/*30*/	{ "wrmsr", FALSE, NONE,  0,	      0 },
29514887Swollman/*31*/	{ "rdtsc", FALSE, NONE,  0,	      0 },
29614887Swollman/*32*/	{ "rdmsr", FALSE, NONE,  0,	      0 },
29714887Swollman/*33*/	{ "rdpmc", FALSE, NONE,  0,	      0 },
298181606Sjhb/*34*/	{ "sysenter",FALSE,NONE,  0,	      0 },
299181606Sjhb/*35*/	{ "sysexit",FALSE,NONE,  0,	      0 },
30014887Swollman/*36*/	{ "",	   FALSE, NONE,  0,	      0 },
301181606Sjhb/*37*/	{ "getsec",FALSE, NONE,  0,	      0 },
30214887Swollman
303238166Sjhb/*38*/	{ "",	   FALSE, ESC,  0,	      db_inst_0f38 },
30414887Swollman/*39*/	{ "",	   FALSE, NONE,  0,	      0 },
30514887Swollman/*3a*/	{ "",	   FALSE, NONE,  0,	      0 },
30614887Swollman/*3b*/	{ "",	   FALSE, NONE,  0,	      0 },
30714887Swollman/*3c*/	{ "",	   FALSE, NONE,  0,	      0 },
30814887Swollman/*3d*/	{ "",	   FALSE, NONE,  0,	      0 },
30914887Swollman/*3e*/	{ "",	   FALSE, NONE,  0,	      0 },
31014887Swollman/*3f*/	{ "",	   FALSE, NONE,  0,	      0 },
31114887Swollman};
31214887Swollman
313144354Speterstatic const struct inst db_inst_0f4x[] = {
314144354Speter/*40*/	{ "cmovo",  TRUE, NONE,  op2(E, R),   0 },
315144354Speter/*41*/	{ "cmovno", TRUE, NONE,  op2(E, R),   0 },
316144354Speter/*42*/	{ "cmovb",  TRUE, NONE,  op2(E, R),   0 },
317144354Speter/*43*/	{ "cmovnb", TRUE, NONE,  op2(E, R),   0 },
318144354Speter/*44*/	{ "cmovz",  TRUE, NONE,  op2(E, R),   0 },
319144354Speter/*45*/	{ "cmovnz", TRUE, NONE,  op2(E, R),   0 },
320144354Speter/*46*/	{ "cmovbe", TRUE, NONE,  op2(E, R),   0 },
321144354Speter/*47*/	{ "cmovnbe",TRUE, NONE,  op2(E, R),   0 },
322144354Speter
323144354Speter/*48*/	{ "cmovs",  TRUE, NONE,  op2(E, R),   0 },
324144354Speter/*49*/	{ "cmovns", TRUE, NONE,  op2(E, R),   0 },
325144354Speter/*4a*/	{ "cmovp",  TRUE, NONE,  op2(E, R),   0 },
326144354Speter/*4b*/	{ "cmovnp", TRUE, NONE,  op2(E, R),   0 },
327144354Speter/*4c*/	{ "cmovl",  TRUE, NONE,  op2(E, R),   0 },
328144354Speter/*4d*/	{ "cmovnl", TRUE, NONE,  op2(E, R),   0 },
329144354Speter/*4e*/	{ "cmovle", TRUE, NONE,  op2(E, R),   0 },
330144354Speter/*4f*/	{ "cmovnle",TRUE, NONE,  op2(E, R),   0 },
331144354Speter};
332144354Speter
333238166Sjhbstatic const struct inst db_inst_0f7x[] = {
334238166Sjhb/*70*/	{ "",	   FALSE, NONE,  0,	      0 },
335238166Sjhb/*71*/	{ "",	   FALSE, NONE,  0,	      0 },
336238166Sjhb/*72*/	{ "",	   FALSE, NONE,  0,	      0 },
337238166Sjhb/*73*/	{ "",	   FALSE, NONE,  0,	      0 },
338238166Sjhb/*74*/	{ "",	   FALSE, NONE,  0,	      0 },
339238166Sjhb/*75*/	{ "",	   FALSE, NONE,  0,	      0 },
340238166Sjhb/*76*/	{ "",	   FALSE, NONE,  0,	      0 },
341238166Sjhb/*77*/	{ "",	   FALSE, NONE,  0,	      0 },
342238166Sjhb
343238166Sjhb/*78*/	{ "vmread", TRUE, NONE,  op2(Rq, E),  0 },
344238166Sjhb/*79*/	{ "vmwrite",TRUE, NONE,  op2(E, Rq),  0 },
345238166Sjhb/*7a*/	{ "",	   FALSE, NONE,  0,	      0 },
346238166Sjhb/*7b*/	{ "",	   FALSE, NONE,  0,	      0 },
347238166Sjhb/*7c*/	{ "",	   FALSE, NONE,  0,	      0 },
348238166Sjhb/*7d*/	{ "",	   FALSE, NONE,  0,	      0 },
349238166Sjhb/*7e*/	{ "",	   FALSE, NONE,  0,	      0 },
350238166Sjhb/*7f*/	{ "",	   FALSE, NONE,  0,	      0 },
351238166Sjhb};
352238166Sjhb
35317109Sbdestatic const struct inst db_inst_0f8x[] = {
3544Srgrimes/*80*/	{ "jo",    FALSE, NONE,  op1(Dl),     0 },
3554Srgrimes/*81*/	{ "jno",   FALSE, NONE,  op1(Dl),     0 },
3564Srgrimes/*82*/	{ "jb",    FALSE, NONE,  op1(Dl),     0 },
3574Srgrimes/*83*/	{ "jnb",   FALSE, NONE,  op1(Dl),     0 },
3584Srgrimes/*84*/	{ "jz",    FALSE, NONE,  op1(Dl),     0 },
3594Srgrimes/*85*/	{ "jnz",   FALSE, NONE,  op1(Dl),     0 },
3604Srgrimes/*86*/	{ "jbe",   FALSE, NONE,  op1(Dl),     0 },
3614Srgrimes/*87*/	{ "jnbe",  FALSE, NONE,  op1(Dl),     0 },
3624Srgrimes
3634Srgrimes/*88*/	{ "js",    FALSE, NONE,  op1(Dl),     0 },
3644Srgrimes/*89*/	{ "jns",   FALSE, NONE,  op1(Dl),     0 },
3654Srgrimes/*8a*/	{ "jp",    FALSE, NONE,  op1(Dl),     0 },
3664Srgrimes/*8b*/	{ "jnp",   FALSE, NONE,  op1(Dl),     0 },
3674Srgrimes/*8c*/	{ "jl",    FALSE, NONE,  op1(Dl),     0 },
3684Srgrimes/*8d*/	{ "jnl",   FALSE, NONE,  op1(Dl),     0 },
3694Srgrimes/*8e*/	{ "jle",   FALSE, NONE,  op1(Dl),     0 },
3704Srgrimes/*8f*/	{ "jnle",  FALSE, NONE,  op1(Dl),     0 },
3714Srgrimes};
3724Srgrimes
37317109Sbdestatic const struct inst db_inst_0f9x[] = {
3744Srgrimes/*90*/	{ "seto",  TRUE,  NONE,  op1(Eb),     0 },
3754Srgrimes/*91*/	{ "setno", TRUE,  NONE,  op1(Eb),     0 },
3764Srgrimes/*92*/	{ "setb",  TRUE,  NONE,  op1(Eb),     0 },
3774Srgrimes/*93*/	{ "setnb", TRUE,  NONE,  op1(Eb),     0 },
3784Srgrimes/*94*/	{ "setz",  TRUE,  NONE,  op1(Eb),     0 },
3794Srgrimes/*95*/	{ "setnz", TRUE,  NONE,  op1(Eb),     0 },
3804Srgrimes/*96*/	{ "setbe", TRUE,  NONE,  op1(Eb),     0 },
3814Srgrimes/*97*/	{ "setnbe",TRUE,  NONE,  op1(Eb),     0 },
3824Srgrimes
3834Srgrimes/*98*/	{ "sets",  TRUE,  NONE,  op1(Eb),     0 },
3844Srgrimes/*99*/	{ "setns", TRUE,  NONE,  op1(Eb),     0 },
3854Srgrimes/*9a*/	{ "setp",  TRUE,  NONE,  op1(Eb),     0 },
3864Srgrimes/*9b*/	{ "setnp", TRUE,  NONE,  op1(Eb),     0 },
3874Srgrimes/*9c*/	{ "setl",  TRUE,  NONE,  op1(Eb),     0 },
3884Srgrimes/*9d*/	{ "setnl", TRUE,  NONE,  op1(Eb),     0 },
3894Srgrimes/*9e*/	{ "setle", TRUE,  NONE,  op1(Eb),     0 },
3904Srgrimes/*9f*/	{ "setnle",TRUE,  NONE,  op1(Eb),     0 },
3914Srgrimes};
3924Srgrimes
39317109Sbdestatic const struct inst db_inst_0fax[] = {
3944Srgrimes/*a0*/	{ "push",  FALSE, NONE,  op1(Si),     0 },
3954Srgrimes/*a1*/	{ "pop",   FALSE, NONE,  op1(Si),     0 },
39621277Sbde/*a2*/	{ "cpuid", FALSE, NONE,  0,	      0 },
39721277Sbde/*a3*/	{ "bt",    TRUE,  LONG,  op2(R,E),    0 },
39817109Sbde/*a4*/	{ "shld",  TRUE,  LONG,  op3(Ib,R,E), 0 },
39917109Sbde/*a5*/	{ "shld",  TRUE,  LONG,  op3(CL,R,E), 0 },
4004Srgrimes/*a6*/	{ "",      FALSE, NONE,  0,	      0 },
4014Srgrimes/*a7*/	{ "",      FALSE, NONE,  0,	      0 },
4024Srgrimes
4034Srgrimes/*a8*/	{ "push",  FALSE, NONE,  op1(Si),     0 },
4044Srgrimes/*a9*/	{ "pop",   FALSE, NONE,  op1(Si),     0 },
40521277Sbde/*aa*/	{ "rsm",   FALSE, NONE,  0,	      0 },
40621277Sbde/*ab*/	{ "bts",   TRUE,  LONG,  op2(R,E),    0 },
40717109Sbde/*ac*/	{ "shrd",  TRUE,  LONG,  op3(Ib,R,E), 0 },
40817109Sbde/*ad*/	{ "shrd",  TRUE,  LONG,  op3(CL,R,E), 0 },
409181606Sjhb/*ae*/	{ "",      TRUE,  LONG,  op1(E),      db_Grp15 },
410181606Sjhb/*af*/	{ "imul",  TRUE,  LONG,  op2(E,R),    0 },
4114Srgrimes};
4124Srgrimes
41317109Sbdestatic const struct inst db_inst_0fbx[] = {
41421277Sbde/*b0*/	{ "cmpxchg",TRUE, BYTE,	 op2(R, E),   0 },
41521277Sbde/*b0*/	{ "cmpxchg",TRUE, LONG,	 op2(R, E),   0 },
4164Srgrimes/*b2*/	{ "lss",   TRUE,  LONG,  op2(E, R),   0 },
41721277Sbde/*b3*/	{ "btr",   TRUE,  LONG,  op2(R, E),   0 },
4184Srgrimes/*b4*/	{ "lfs",   TRUE,  LONG,  op2(E, R),   0 },
4194Srgrimes/*b5*/	{ "lgs",   TRUE,  LONG,  op2(E, R),   0 },
42021277Sbde/*b6*/	{ "movzb", TRUE,  LONG,  op2(Eb, R),  0 },
42121277Sbde/*b7*/	{ "movzw", TRUE,  LONG,  op2(Ew, R),  0 },
4224Srgrimes
4234Srgrimes/*b8*/	{ "",      FALSE, NONE,  0,	      0 },
4244Srgrimes/*b9*/	{ "",      FALSE, NONE,  0,	      0 },
42517109Sbde/*ba*/	{ "",      TRUE,  LONG,  op2(Ib, E),  db_Grp8 },
4264Srgrimes/*bb*/	{ "btc",   TRUE,  LONG,  op2(R, E),   0 },
4274Srgrimes/*bc*/	{ "bsf",   TRUE,  LONG,  op2(E, R),   0 },
4284Srgrimes/*bd*/	{ "bsr",   TRUE,  LONG,  op2(E, R),   0 },
42921277Sbde/*be*/	{ "movsb", TRUE,  LONG,  op2(Eb, R),  0 },
43021277Sbde/*bf*/	{ "movsw", TRUE,  LONG,  op2(Ew, R),  0 },
4314Srgrimes};
4324Srgrimes
43317109Sbdestatic const struct inst db_inst_0fcx[] = {
4344Srgrimes/*c0*/	{ "xadd",  TRUE,  BYTE,	 op2(R, E),   0 },
4354Srgrimes/*c1*/	{ "xadd",  TRUE,  LONG,	 op2(R, E),   0 },
4364Srgrimes/*c2*/	{ "",	   FALSE, NONE,	 0,	      0 },
4374Srgrimes/*c3*/	{ "",	   FALSE, NONE,	 0,	      0 },
4384Srgrimes/*c4*/	{ "",	   FALSE, NONE,	 0,	      0 },
4394Srgrimes/*c5*/	{ "",	   FALSE, NONE,	 0,	      0 },
4404Srgrimes/*c6*/	{ "",	   FALSE, NONE,	 0,	      0 },
44121277Sbde/*c7*/	{ "",	   TRUE,  NONE,  op1(E),      db_Grp9 },
44221277Sbde/*c8*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
44321277Sbde/*c9*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
44421277Sbde/*ca*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
44521277Sbde/*cb*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
44621277Sbde/*cc*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
44721277Sbde/*cd*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
44821277Sbde/*ce*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
44921277Sbde/*cf*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
4504Srgrimes};
4514Srgrimes
45214887Swollmanstatic const struct inst * const db_inst_0f[] = {
4534Srgrimes	db_inst_0f0x,
454278655Smarkj	db_inst_0f1x,
4554Srgrimes	db_inst_0f2x,
45614887Swollman	db_inst_0f3x,
457144354Speter	db_inst_0f4x,
4584Srgrimes	0,
4594Srgrimes	0,
460238166Sjhb	db_inst_0f7x,
4614Srgrimes	db_inst_0f8x,
4624Srgrimes	db_inst_0f9x,
4634Srgrimes	db_inst_0fax,
4644Srgrimes	db_inst_0fbx,
4654Srgrimes	db_inst_0fcx,
4664Srgrimes	0,
46721277Sbde	0,
4684Srgrimes	0
4694Srgrimes};
4704Srgrimes
47114887Swollmanstatic const char * const db_Esc92[] = {
4724Srgrimes	"fnop",	"",	"",	"",	"",	"",	"",	""
4734Srgrimes};
47414887Swollmanstatic const char * const db_Esc94[] = {
4754Srgrimes	"fchs",	"fabs",	"",	"",	"ftst",	"fxam",	"",	""
4764Srgrimes};
47717109Sbdestatic const char * const db_Esc95[] = {
4784Srgrimes	"fld1",	"fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
4794Srgrimes};
48017109Sbdestatic const char * const db_Esc96[] = {
4814Srgrimes	"f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
4824Srgrimes	"fincstp"
4834Srgrimes};
48414887Swollmanstatic const char * const db_Esc97[] = {
4854Srgrimes	"fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
4864Srgrimes};
4874Srgrimes
48821277Sbdestatic const char * const db_Esca5[] = {
4894Srgrimes	"",	"fucompp","",	"",	"",	"",	"",	""
4904Srgrimes};
4914Srgrimes
49217109Sbdestatic const char * const db_Escb4[] = {
49321277Sbde	"fneni","fndisi",	"fnclex","fninit","fsetpm",	"",	"",	""
4944Srgrimes};
4954Srgrimes
49614887Swollmanstatic const char * const db_Esce3[] = {
4974Srgrimes	"",	"fcompp","",	"",	"",	"",	"",	""
4984Srgrimes};
4994Srgrimes
50017109Sbdestatic const char * const db_Escf4[] = {
5014Srgrimes	"fnstsw","",	"",	"",	"",	"",	"",	""
5024Srgrimes};
5034Srgrimes
50414887Swollmanstatic const struct finst db_Esc8[] = {
5054Srgrimes/*0*/	{ "fadd",   SNGL,  op2(STI,ST),	0 },
5064Srgrimes/*1*/	{ "fmul",   SNGL,  op2(STI,ST),	0 },
5074Srgrimes/*2*/	{ "fcom",   SNGL,  op2(STI,ST),	0 },
5084Srgrimes/*3*/	{ "fcomp",  SNGL,  op2(STI,ST),	0 },
5094Srgrimes/*4*/	{ "fsub",   SNGL,  op2(STI,ST),	0 },
5104Srgrimes/*5*/	{ "fsubr",  SNGL,  op2(STI,ST),	0 },
5114Srgrimes/*6*/	{ "fdiv",   SNGL,  op2(STI,ST),	0 },
5124Srgrimes/*7*/	{ "fdivr",  SNGL,  op2(STI,ST),	0 },
5134Srgrimes};
5144Srgrimes
51514887Swollmanstatic const struct finst db_Esc9[] = {
5164Srgrimes/*0*/	{ "fld",    SNGL,  op1(STI),	0 },
5174Srgrimes/*1*/	{ "",       NONE,  op1(STI),	"fxch" },
51817109Sbde/*2*/	{ "fst",    SNGL,  op1(X),	db_Esc92 },
51921277Sbde/*3*/	{ "fstp",   SNGL,  0,		0 },
52017109Sbde/*4*/	{ "fldenv", NONE,  op1(X),	db_Esc94 },
52117109Sbde/*5*/	{ "fldcw",  NONE,  op1(X),	db_Esc95 },
52217109Sbde/*6*/	{ "fnstenv",NONE,  op1(X),	db_Esc96 },
52317109Sbde/*7*/	{ "fnstcw", NONE,  op1(X),	db_Esc97 },
5244Srgrimes};
5254Srgrimes
52614887Swollmanstatic const struct finst db_Esca[] = {
52721277Sbde/*0*/	{ "fiadd",  LONG,  0,		0 },
52821277Sbde/*1*/	{ "fimul",  LONG,  0,		0 },
52921277Sbde/*2*/	{ "ficom",  LONG,  0,		0 },
53021277Sbde/*3*/	{ "ficomp", LONG,  0,		0 },
53121277Sbde/*4*/	{ "fisub",  LONG,  0,		0 },
53221277Sbde/*5*/	{ "fisubr", LONG,  op1(X),	db_Esca5 },
53321277Sbde/*6*/	{ "fidiv",  LONG,  0,		0 },
53421277Sbde/*7*/	{ "fidivr", LONG,  0,		0 }
5354Srgrimes};
5364Srgrimes
53714887Swollmanstatic const struct finst db_Escb[] = {
53821277Sbde/*0*/	{ "fild",   LONG,  0,		0 },
5394Srgrimes/*1*/	{ "",       NONE,  0,		0 },
54021277Sbde/*2*/	{ "fist",   LONG,  0,		0 },
54121277Sbde/*3*/	{ "fistp",  LONG,  0,		0 },
54217109Sbde/*4*/	{ "",       WORD,  op1(X),	db_Escb4 },
5434Srgrimes/*5*/	{ "fld",    EXTR,  0,		0 },
5444Srgrimes/*6*/	{ "",       WORD,  0,		0 },
5454Srgrimes/*7*/	{ "fstp",   EXTR,  0,		0 },
5464Srgrimes};
5474Srgrimes
54814887Swollmanstatic const struct finst db_Escc[] = {
5494Srgrimes/*0*/	{ "fadd",   DBLR,  op2(ST,STI),	0 },
5504Srgrimes/*1*/	{ "fmul",   DBLR,  op2(ST,STI),	0 },
55121277Sbde/*2*/	{ "fcom",   DBLR,  0,		0 },
55221277Sbde/*3*/	{ "fcomp",  DBLR,  0,		0 },
5534Srgrimes/*4*/	{ "fsub",   DBLR,  op2(ST,STI),	"fsubr" },
5544Srgrimes/*5*/	{ "fsubr",  DBLR,  op2(ST,STI),	"fsub" },
5554Srgrimes/*6*/	{ "fdiv",   DBLR,  op2(ST,STI),	"fdivr" },
5564Srgrimes/*7*/	{ "fdivr",  DBLR,  op2(ST,STI),	"fdiv" },
5574Srgrimes};
5584Srgrimes
55914887Swollmanstatic const struct finst db_Escd[] = {
5604Srgrimes/*0*/	{ "fld",    DBLR,  op1(STI),	"ffree" },
5614Srgrimes/*1*/	{ "",       NONE,  0,		0 },
5624Srgrimes/*2*/	{ "fst",    DBLR,  op1(STI),	0 },
5634Srgrimes/*3*/	{ "fstp",   DBLR,  op1(STI),	0 },
5644Srgrimes/*4*/	{ "frstor", NONE,  op1(STI),	"fucom" },
5654Srgrimes/*5*/	{ "",       NONE,  op1(STI),	"fucomp" },
5664Srgrimes/*6*/	{ "fnsave", NONE,  0,		0 },
5674Srgrimes/*7*/	{ "fnstsw", NONE,  0,		0 },
5684Srgrimes};
5694Srgrimes
57014887Swollmanstatic const struct finst db_Esce[] = {
57121277Sbde/*0*/	{ "fiadd",  WORD,  op2(ST,STI),	"faddp" },
57221277Sbde/*1*/	{ "fimul",  WORD,  op2(ST,STI),	"fmulp" },
57321277Sbde/*2*/	{ "ficom",  WORD,  0,		0 },
57421277Sbde/*3*/	{ "ficomp", WORD,  op1(X),	db_Esce3 },
57521277Sbde/*4*/	{ "fisub",  WORD,  op2(ST,STI),	"fsubrp" },
57621277Sbde/*5*/	{ "fisubr", WORD,  op2(ST,STI),	"fsubp" },
57721277Sbde/*6*/	{ "fidiv",  WORD,  op2(ST,STI),	"fdivrp" },
57821277Sbde/*7*/	{ "fidivr", WORD,  op2(ST,STI),	"fdivp" },
5794Srgrimes};
5804Srgrimes
58114887Swollmanstatic const struct finst db_Escf[] = {
58221277Sbde/*0*/	{ "fild",   WORD,  0,		0 },
58321277Sbde/*1*/	{ "",       NONE,  0,		0 },
58421277Sbde/*2*/	{ "fist",   WORD,  0,		0 },
58521277Sbde/*3*/	{ "fistp",  WORD,  0,		0 },
58617109Sbde/*4*/	{ "fbld",   NONE,  op1(XA),	db_Escf4 },
58721277Sbde/*5*/	{ "fild",   QUAD,  0,		0 },
5884Srgrimes/*6*/	{ "fbstp",  NONE,  0,		0 },
58921277Sbde/*7*/	{ "fistp",  QUAD,  0,		0 },
5904Srgrimes};
5914Srgrimes
59217109Sbdestatic const struct finst * const db_Esc_inst[] = {
5934Srgrimes	db_Esc8, db_Esc9, db_Esca, db_Escb,
5944Srgrimes	db_Escc, db_Escd, db_Esce, db_Escf
5954Srgrimes};
5964Srgrimes
59714887Swollmanstatic const char * const db_Grp1[] = {
5984Srgrimes	"add",
5994Srgrimes	"or",
6004Srgrimes	"adc",
6014Srgrimes	"sbb",
6024Srgrimes	"and",
6034Srgrimes	"sub",
6044Srgrimes	"xor",
6054Srgrimes	"cmp"
6064Srgrimes};
6074Srgrimes
60814887Swollmanstatic const char * const db_Grp2[] = {
6094Srgrimes	"rol",
6104Srgrimes	"ror",
6114Srgrimes	"rcl",
6124Srgrimes	"rcr",
6134Srgrimes	"shl",
6144Srgrimes	"shr",
6154Srgrimes	"shl",
6164Srgrimes	"sar"
6174Srgrimes};
6184Srgrimes
61914887Swollmanstatic const struct inst db_Grp3[] = {
6204Srgrimes	{ "test",  TRUE, NONE, op2(I,E), 0 },
6214Srgrimes	{ "test",  TRUE, NONE, op2(I,E), 0 },
6224Srgrimes	{ "not",   TRUE, NONE, op1(E),   0 },
6234Srgrimes	{ "neg",   TRUE, NONE, op1(E),   0 },
6244Srgrimes	{ "mul",   TRUE, NONE, op2(E,A), 0 },
6254Srgrimes	{ "imul",  TRUE, NONE, op2(E,A), 0 },
6264Srgrimes	{ "div",   TRUE, NONE, op2(E,A), 0 },
6274Srgrimes	{ "idiv",  TRUE, NONE, op2(E,A), 0 },
6284Srgrimes};
6294Srgrimes
63017109Sbdestatic const struct inst db_Grp4[] = {
6314Srgrimes	{ "inc",   TRUE, BYTE, op1(E),   0 },
6324Srgrimes	{ "dec",   TRUE, BYTE, op1(E),   0 },
6334Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
6344Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
6354Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
6364Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
6374Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
6384Srgrimes	{ "",      TRUE, NONE, 0,	 0 }
6394Srgrimes};
6404Srgrimes
64117109Sbdestatic const struct inst db_Grp5[] = {
6424Srgrimes	{ "inc",   TRUE, LONG, op1(E),   0 },
6434Srgrimes	{ "dec",   TRUE, LONG, op1(E),   0 },
64421277Sbde	{ "call",  TRUE, LONG, op1(Eind),0 },
64521277Sbde	{ "lcall", TRUE, LONG, op1(Eind),0 },
64621277Sbde	{ "jmp",   TRUE, LONG, op1(Eind),0 },
64721277Sbde	{ "ljmp",  TRUE, LONG, op1(Eind),0 },
6484Srgrimes	{ "push",  TRUE, LONG, op1(E),   0 },
6494Srgrimes	{ "",      TRUE, NONE, 0,	 0 }
6504Srgrimes};
6514Srgrimes
652266354Sjhbstatic const struct inst db_Grp9b[] = {
653266354Sjhb	{ "",      TRUE, NONE, 0,	 0 },
654266354Sjhb	{ "",      TRUE, NONE, 0,	 0 },
655266354Sjhb	{ "",      TRUE, NONE, 0,	 0 },
656266354Sjhb	{ "",      TRUE, NONE, 0,	 0 },
657266354Sjhb	{ "",      TRUE, NONE, 0,	 0 },
658266354Sjhb	{ "",      TRUE, NONE, 0,	 0 },
659266354Sjhb	{ "rdrand",TRUE, LONG, op1(Rv),  0 },
660266354Sjhb	{ "rdseed",TRUE, LONG, op1(Rv),  0 }
661266354Sjhb};
662266354Sjhb
66314887Swollmanstatic const struct inst db_inst_table[256] = {
6644Srgrimes/*00*/	{ "add",   TRUE,  BYTE,  op2(R, E),  0 },
6654Srgrimes/*01*/	{ "add",   TRUE,  LONG,  op2(R, E),  0 },
6664Srgrimes/*02*/	{ "add",   TRUE,  BYTE,  op2(E, R),  0 },
6674Srgrimes/*03*/	{ "add",   TRUE,  LONG,  op2(E, R),  0 },
66821277Sbde/*04*/	{ "add",   FALSE, BYTE,  op2(I, A),  0 },
6694Srgrimes/*05*/	{ "add",   FALSE, LONG,  op2(Is, A), 0 },
6704Srgrimes/*06*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
6714Srgrimes/*07*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },
6724Srgrimes
6734Srgrimes/*08*/	{ "or",    TRUE,  BYTE,  op2(R, E),  0 },
6744Srgrimes/*09*/	{ "or",    TRUE,  LONG,  op2(R, E),  0 },
6754Srgrimes/*0a*/	{ "or",    TRUE,  BYTE,  op2(E, R),  0 },
6764Srgrimes/*0b*/	{ "or",    TRUE,  LONG,  op2(E, R),  0 },
6774Srgrimes/*0c*/	{ "or",    FALSE, BYTE,  op2(I, A),  0 },
6784Srgrimes/*0d*/	{ "or",    FALSE, LONG,  op2(I, A),  0 },
6794Srgrimes/*0e*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
680238166Sjhb/*0f*/	{ "",      FALSE, ESC,   0,	     db_inst_0f },
6814Srgrimes
6824Srgrimes/*10*/	{ "adc",   TRUE,  BYTE,  op2(R, E),  0 },
6834Srgrimes/*11*/	{ "adc",   TRUE,  LONG,  op2(R, E),  0 },
6844Srgrimes/*12*/	{ "adc",   TRUE,  BYTE,  op2(E, R),  0 },
6854Srgrimes/*13*/	{ "adc",   TRUE,  LONG,  op2(E, R),  0 },
68621277Sbde/*14*/	{ "adc",   FALSE, BYTE,  op2(I, A),  0 },
6874Srgrimes/*15*/	{ "adc",   FALSE, LONG,  op2(Is, A), 0 },
6884Srgrimes/*16*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
6894Srgrimes/*17*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },
6904Srgrimes
6914Srgrimes/*18*/	{ "sbb",   TRUE,  BYTE,  op2(R, E),  0 },
6924Srgrimes/*19*/	{ "sbb",   TRUE,  LONG,  op2(R, E),  0 },
6934Srgrimes/*1a*/	{ "sbb",   TRUE,  BYTE,  op2(E, R),  0 },
6944Srgrimes/*1b*/	{ "sbb",   TRUE,  LONG,  op2(E, R),  0 },
69521277Sbde/*1c*/	{ "sbb",   FALSE, BYTE,  op2(I, A),  0 },
6964Srgrimes/*1d*/	{ "sbb",   FALSE, LONG,  op2(Is, A), 0 },
6974Srgrimes/*1e*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
6984Srgrimes/*1f*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },
6994Srgrimes
7004Srgrimes/*20*/	{ "and",   TRUE,  BYTE,  op2(R, E),  0 },
7014Srgrimes/*21*/	{ "and",   TRUE,  LONG,  op2(R, E),  0 },
7024Srgrimes/*22*/	{ "and",   TRUE,  BYTE,  op2(E, R),  0 },
7034Srgrimes/*23*/	{ "and",   TRUE,  LONG,  op2(E, R),  0 },
7044Srgrimes/*24*/	{ "and",   FALSE, BYTE,  op2(I, A),  0 },
7054Srgrimes/*25*/	{ "and",   FALSE, LONG,  op2(I, A),  0 },
7064Srgrimes/*26*/	{ "",      FALSE, NONE,  0,	     0 },
70721277Sbde/*27*/	{ "daa",   FALSE, NONE,  0,	     0 },
7084Srgrimes
7094Srgrimes/*28*/	{ "sub",   TRUE,  BYTE,  op2(R, E),  0 },
7104Srgrimes/*29*/	{ "sub",   TRUE,  LONG,  op2(R, E),  0 },
7114Srgrimes/*2a*/	{ "sub",   TRUE,  BYTE,  op2(E, R),  0 },
7124Srgrimes/*2b*/	{ "sub",   TRUE,  LONG,  op2(E, R),  0 },
71321277Sbde/*2c*/	{ "sub",   FALSE, BYTE,  op2(I, A),  0 },
7144Srgrimes/*2d*/	{ "sub",   FALSE, LONG,  op2(Is, A), 0 },
7154Srgrimes/*2e*/	{ "",      FALSE, NONE,  0,	     0 },
7164Srgrimes/*2f*/	{ "das",   FALSE, NONE,  0,	     0 },
7174Srgrimes
7184Srgrimes/*30*/	{ "xor",   TRUE,  BYTE,  op2(R, E),  0 },
7194Srgrimes/*31*/	{ "xor",   TRUE,  LONG,  op2(R, E),  0 },
7204Srgrimes/*32*/	{ "xor",   TRUE,  BYTE,  op2(E, R),  0 },
7214Srgrimes/*33*/	{ "xor",   TRUE,  LONG,  op2(E, R),  0 },
7224Srgrimes/*34*/	{ "xor",   FALSE, BYTE,  op2(I, A),  0 },
7234Srgrimes/*35*/	{ "xor",   FALSE, LONG,  op2(I, A),  0 },
7244Srgrimes/*36*/	{ "",      FALSE, NONE,  0,	     0 },
72521277Sbde/*37*/	{ "aaa",   FALSE, NONE,  0,	     0 },
7264Srgrimes
7274Srgrimes/*38*/	{ "cmp",   TRUE,  BYTE,  op2(R, E),  0 },
7284Srgrimes/*39*/	{ "cmp",   TRUE,  LONG,  op2(R, E),  0 },
7294Srgrimes/*3a*/	{ "cmp",   TRUE,  BYTE,  op2(E, R),  0 },
7304Srgrimes/*3b*/	{ "cmp",   TRUE,  LONG,  op2(E, R),  0 },
73121277Sbde/*3c*/	{ "cmp",   FALSE, BYTE,  op2(I, A),  0 },
7324Srgrimes/*3d*/	{ "cmp",   FALSE, LONG,  op2(Is, A), 0 },
7334Srgrimes/*3e*/	{ "",      FALSE, NONE,  0,	     0 },
7344Srgrimes/*3f*/	{ "aas",   FALSE, NONE,  0,	     0 },
7354Srgrimes
736144353Speter/*40*/	{ "rex",   FALSE, NONE,  0,          0 },
737144353Speter/*41*/	{ "rex.b", FALSE, NONE,  0,          0 },
738144353Speter/*42*/	{ "rex.x", FALSE, NONE,  0,          0 },
739144353Speter/*43*/	{ "rex.xb", FALSE, NONE, 0,          0 },
740144353Speter/*44*/	{ "rex.r", FALSE, NONE,  0,          0 },
741144353Speter/*45*/	{ "rex.rb", FALSE, NONE, 0,          0 },
742144353Speter/*46*/	{ "rex.rx", FALSE, NONE, 0,          0 },
743144353Speter/*47*/	{ "rex.rxb", FALSE, NONE, 0,         0 },
7444Srgrimes
745144353Speter/*48*/	{ "rex.w", FALSE, NONE,  0,          0 },
746144353Speter/*49*/	{ "rex.wb", FALSE, NONE, 0,          0 },
747144353Speter/*4a*/	{ "rex.wx", FALSE, NONE, 0,          0 },
748144353Speter/*4b*/	{ "rex.wxb", FALSE, NONE, 0,         0 },
749144353Speter/*4c*/	{ "rex.wr", FALSE, NONE, 0,          0 },
750144353Speter/*4d*/	{ "rex.wrb", FALSE, NONE, 0,         0 },
751144353Speter/*4e*/	{ "rex.wrx", FALSE, NONE, 0,         0 },
752144353Speter/*4f*/	{ "rex.wrxb", FALSE, NONE, 0,        0 },
7534Srgrimes
7544Srgrimes/*50*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
7554Srgrimes/*51*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
7564Srgrimes/*52*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
7574Srgrimes/*53*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
7584Srgrimes/*54*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
7594Srgrimes/*55*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
7604Srgrimes/*56*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
7614Srgrimes/*57*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
7624Srgrimes
7634Srgrimes/*58*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
7644Srgrimes/*59*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
7654Srgrimes/*5a*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
7664Srgrimes/*5b*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
7674Srgrimes/*5c*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
7684Srgrimes/*5d*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
7694Srgrimes/*5e*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
7704Srgrimes/*5f*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
7714Srgrimes
7724Srgrimes/*60*/	{ "pusha", FALSE, LONG,  0,	     0 },
7734Srgrimes/*61*/	{ "popa",  FALSE, LONG,  0,	     0 },
7744Srgrimes/*62*/  { "bound", TRUE,  LONG,  op2(E, R),  0 },
775144354Speter/*63*/	{ "movslq",  TRUE,  NONE,  op2(EL,R), 0 },
7764Srgrimes
7774Srgrimes/*64*/	{ "",      FALSE, NONE,  0,	     0 },
7784Srgrimes/*65*/	{ "",      FALSE, NONE,  0,	     0 },
7794Srgrimes/*66*/	{ "",      FALSE, NONE,  0,	     0 },
7804Srgrimes/*67*/	{ "",      FALSE, NONE,  0,	     0 },
7814Srgrimes
7824Srgrimes/*68*/	{ "push",  FALSE, LONG,  op1(I),     0 },
7834Srgrimes/*69*/  { "imul",  TRUE,  LONG,  op3(I,E,R), 0 },
78421277Sbde/*6a*/	{ "push",  FALSE, LONG,  op1(Ibs),   0 },
7854Srgrimes/*6b*/  { "imul",  TRUE,  LONG,  op3(Ibs,E,R),0 },
7864Srgrimes/*6c*/	{ "ins",   FALSE, BYTE,  op2(DX, DI), 0 },
7874Srgrimes/*6d*/	{ "ins",   FALSE, LONG,  op2(DX, DI), 0 },
7884Srgrimes/*6e*/	{ "outs",  FALSE, BYTE,  op2(SI, DX), 0 },
7894Srgrimes/*6f*/	{ "outs",  FALSE, LONG,  op2(SI, DX), 0 },
7904Srgrimes
7914Srgrimes/*70*/	{ "jo",    FALSE, NONE,  op1(Db),     0 },
7924Srgrimes/*71*/	{ "jno",   FALSE, NONE,  op1(Db),     0 },
7934Srgrimes/*72*/	{ "jb",    FALSE, NONE,  op1(Db),     0 },
7944Srgrimes/*73*/	{ "jnb",   FALSE, NONE,  op1(Db),     0 },
7954Srgrimes/*74*/	{ "jz",    FALSE, NONE,  op1(Db),     0 },
7964Srgrimes/*75*/	{ "jnz",   FALSE, NONE,  op1(Db),     0 },
7974Srgrimes/*76*/	{ "jbe",   FALSE, NONE,  op1(Db),     0 },
7984Srgrimes/*77*/	{ "jnbe",  FALSE, NONE,  op1(Db),     0 },
7994Srgrimes
8004Srgrimes/*78*/	{ "js",    FALSE, NONE,  op1(Db),     0 },
8014Srgrimes/*79*/	{ "jns",   FALSE, NONE,  op1(Db),     0 },
8024Srgrimes/*7a*/	{ "jp",    FALSE, NONE,  op1(Db),     0 },
8034Srgrimes/*7b*/	{ "jnp",   FALSE, NONE,  op1(Db),     0 },
8044Srgrimes/*7c*/	{ "jl",    FALSE, NONE,  op1(Db),     0 },
8054Srgrimes/*7d*/	{ "jnl",   FALSE, NONE,  op1(Db),     0 },
8064Srgrimes/*7e*/	{ "jle",   FALSE, NONE,  op1(Db),     0 },
8074Srgrimes/*7f*/	{ "jnle",  FALSE, NONE,  op1(Db),     0 },
8084Srgrimes
80917109Sbde/*80*/  { "",	   TRUE,  BYTE,  op2(I, E),   db_Grp1 },
81017109Sbde/*81*/  { "",	   TRUE,  LONG,  op2(I, E),   db_Grp1 },
81121277Sbde/*82*/  { "",	   TRUE,  BYTE,  op2(I, E),   db_Grp1 },
81217109Sbde/*83*/  { "",	   TRUE,  LONG,  op2(Ibs,E),  db_Grp1 },
8134Srgrimes/*84*/	{ "test",  TRUE,  BYTE,  op2(R, E),   0 },
8144Srgrimes/*85*/	{ "test",  TRUE,  LONG,  op2(R, E),   0 },
8154Srgrimes/*86*/	{ "xchg",  TRUE,  BYTE,  op2(R, E),   0 },
8164Srgrimes/*87*/	{ "xchg",  TRUE,  LONG,  op2(R, E),   0 },
8174Srgrimes
8184Srgrimes/*88*/	{ "mov",   TRUE,  BYTE,  op2(R, E),   0 },
8194Srgrimes/*89*/	{ "mov",   TRUE,  LONG,  op2(R, E),   0 },
8204Srgrimes/*8a*/	{ "mov",   TRUE,  BYTE,  op2(E, R),   0 },
8214Srgrimes/*8b*/	{ "mov",   TRUE,  LONG,  op2(E, R),   0 },
8224Srgrimes/*8c*/  { "mov",   TRUE,  NONE,  op2(S, Ew),  0 },
8234Srgrimes/*8d*/	{ "lea",   TRUE,  LONG,  op2(E, R),   0 },
8244Srgrimes/*8e*/	{ "mov",   TRUE,  NONE,  op2(Ew, S),  0 },
8254Srgrimes/*8f*/	{ "pop",   TRUE,  LONG,  op1(E),      0 },
8264Srgrimes
8274Srgrimes/*90*/	{ "nop",   FALSE, NONE,  0,	      0 },
8284Srgrimes/*91*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
8294Srgrimes/*92*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
8304Srgrimes/*93*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
8314Srgrimes/*94*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
8324Srgrimes/*95*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
8334Srgrimes/*96*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
8344Srgrimes/*97*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
8354Srgrimes
836238166Sjhb/*98*/	{ "cwde",  FALSE, SDEP,  0,	      "cbw" },
837238166Sjhb/*99*/	{ "cdq",   FALSE, SDEP,  0,	      "cwd" },
8384Srgrimes/*9a*/	{ "lcall", FALSE, NONE,  op1(OS),     0 },
8394Srgrimes/*9b*/	{ "wait",  FALSE, NONE,  0,	      0 },
8404Srgrimes/*9c*/	{ "pushf", FALSE, LONG,  0,	      0 },
8414Srgrimes/*9d*/	{ "popf",  FALSE, LONG,  0,	      0 },
8424Srgrimes/*9e*/	{ "sahf",  FALSE, NONE,  0,	      0 },
8434Srgrimes/*9f*/	{ "lahf",  FALSE, NONE,  0,	      0 },
8444Srgrimes
8454Srgrimes/*a0*/	{ "mov",   FALSE, BYTE,  op2(O, A),   0 },
8464Srgrimes/*a1*/	{ "mov",   FALSE, LONG,  op2(O, A),   0 },
8474Srgrimes/*a2*/	{ "mov",   FALSE, BYTE,  op2(A, O),   0 },
8484Srgrimes/*a3*/	{ "mov",   FALSE, LONG,  op2(A, O),   0 },
8494Srgrimes/*a4*/	{ "movs",  FALSE, BYTE,  op2(SI,DI),  0 },
8504Srgrimes/*a5*/	{ "movs",  FALSE, LONG,  op2(SI,DI),  0 },
8514Srgrimes/*a6*/	{ "cmps",  FALSE, BYTE,  op2(SI,DI),  0 },
8524Srgrimes/*a7*/	{ "cmps",  FALSE, LONG,  op2(SI,DI),  0 },
8534Srgrimes
8544Srgrimes/*a8*/	{ "test",  FALSE, BYTE,  op2(I, A),   0 },
8554Srgrimes/*a9*/	{ "test",  FALSE, LONG,  op2(I, A),   0 },
8564Srgrimes/*aa*/	{ "stos",  FALSE, BYTE,  op1(DI),     0 },
8574Srgrimes/*ab*/	{ "stos",  FALSE, LONG,  op1(DI),     0 },
858118Srgrimes/*ac*/	{ "lods",  FALSE, BYTE,  op1(SI),     0 },
859118Srgrimes/*ad*/	{ "lods",  FALSE, LONG,  op1(SI),     0 },
8604Srgrimes/*ae*/	{ "scas",  FALSE, BYTE,  op1(SI),     0 },
8614Srgrimes/*af*/	{ "scas",  FALSE, LONG,  op1(SI),     0 },
8624Srgrimes
8634Srgrimes/*b0*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
8644Srgrimes/*b1*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
8654Srgrimes/*b2*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
8664Srgrimes/*b3*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
8674Srgrimes/*b4*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
8684Srgrimes/*b5*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
8694Srgrimes/*b6*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
8704Srgrimes/*b7*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
8714Srgrimes
872164263Sjhb/*b8*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
873164263Sjhb/*b9*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
874164263Sjhb/*ba*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
875164263Sjhb/*bb*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
876164263Sjhb/*bc*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
877164263Sjhb/*bd*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
878164263Sjhb/*be*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
879164263Sjhb/*bf*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
8804Srgrimes
88117109Sbde/*c0*/	{ "",	   TRUE,  BYTE,  op2(Ib, E),  db_Grp2 },
88217109Sbde/*c1*/	{ "",	   TRUE,  LONG,  op2(Ib, E),  db_Grp2 },
8834Srgrimes/*c2*/	{ "ret",   FALSE, NONE,  op1(Iw),     0 },
8844Srgrimes/*c3*/	{ "ret",   FALSE, NONE,  0,	      0 },
8854Srgrimes/*c4*/	{ "les",   TRUE,  LONG,  op2(E, R),   0 },
8864Srgrimes/*c5*/	{ "lds",   TRUE,  LONG,  op2(E, R),   0 },
8874Srgrimes/*c6*/	{ "mov",   TRUE,  BYTE,  op2(I, E),   0 },
8884Srgrimes/*c7*/	{ "mov",   TRUE,  LONG,  op2(I, E),   0 },
8894Srgrimes
89021277Sbde/*c8*/	{ "enter", FALSE, NONE,  op2(Iw, Ib), 0 },
8914Srgrimes/*c9*/	{ "leave", FALSE, NONE,  0,           0 },
8924Srgrimes/*ca*/	{ "lret",  FALSE, NONE,  op1(Iw),     0 },
8934Srgrimes/*cb*/	{ "lret",  FALSE, NONE,  0,	      0 },
8944Srgrimes/*cc*/	{ "int",   FALSE, NONE,  op1(o3),     0 },
8954Srgrimes/*cd*/	{ "int",   FALSE, NONE,  op1(Ib),     0 },
8964Srgrimes/*ce*/	{ "into",  FALSE, NONE,  0,	      0 },
8974Srgrimes/*cf*/	{ "iret",  FALSE, NONE,  0,	      0 },
8984Srgrimes
89917109Sbde/*d0*/	{ "",	   TRUE,  BYTE,  op2(o1, E),  db_Grp2 },
90017109Sbde/*d1*/	{ "",	   TRUE,  LONG,  op2(o1, E),  db_Grp2 },
90117109Sbde/*d2*/	{ "",	   TRUE,  BYTE,  op2(CL, E),  db_Grp2 },
90217109Sbde/*d3*/	{ "",	   TRUE,  LONG,  op2(CL, E),  db_Grp2 },
90321277Sbde/*d4*/	{ "aam",   FALSE, NONE,  op1(Iba),    0 },
90421277Sbde/*d5*/	{ "aad",   FALSE, NONE,  op1(Iba),    0 },
90521277Sbde/*d6*/	{ ".byte\t0xd6", FALSE, NONE, 0,      0 },
9064Srgrimes/*d7*/	{ "xlat",  FALSE, BYTE,  op1(BX),     0 },
9074Srgrimes
90817109Sbde/*d8*/  { "",      TRUE,  NONE,  0,	      db_Esc8 },
90917109Sbde/*d9*/  { "",      TRUE,  NONE,  0,	      db_Esc9 },
91017109Sbde/*da*/  { "",      TRUE,  NONE,  0,	      db_Esca },
91117109Sbde/*db*/  { "",      TRUE,  NONE,  0,	      db_Escb },
91217109Sbde/*dc*/  { "",      TRUE,  NONE,  0,	      db_Escc },
91317109Sbde/*dd*/  { "",      TRUE,  NONE,  0,	      db_Escd },
91417109Sbde/*de*/  { "",      TRUE,  NONE,  0,	      db_Esce },
91517109Sbde/*df*/  { "",      TRUE,  NONE,  0,	      db_Escf },
9164Srgrimes
9174Srgrimes/*e0*/	{ "loopne",FALSE, NONE,  op1(Db),     0 },
9184Srgrimes/*e1*/	{ "loope", FALSE, NONE,  op1(Db),     0 },
9194Srgrimes/*e2*/	{ "loop",  FALSE, NONE,  op1(Db),     0 },
920238166Sjhb/*e3*/	{ "jrcxz", FALSE, ADEP,  op1(Db),     "jecxz" },
9214Srgrimes/*e4*/	{ "in",    FALSE, BYTE,  op2(Ib, A),  0 },
9224Srgrimes/*e5*/	{ "in",    FALSE, LONG,  op2(Ib, A) , 0 },
9234Srgrimes/*e6*/	{ "out",   FALSE, BYTE,  op2(A, Ib),  0 },
9244Srgrimes/*e7*/	{ "out",   FALSE, LONG,  op2(A, Ib) , 0 },
9254Srgrimes
9264Srgrimes/*e8*/	{ "call",  FALSE, NONE,  op1(Dl),     0 },
9274Srgrimes/*e9*/	{ "jmp",   FALSE, NONE,  op1(Dl),     0 },
9284Srgrimes/*ea*/	{ "ljmp",  FALSE, NONE,  op1(OS),     0 },
9294Srgrimes/*eb*/	{ "jmp",   FALSE, NONE,  op1(Db),     0 },
9304Srgrimes/*ec*/	{ "in",    FALSE, BYTE,  op2(DX, A),  0 },
9314Srgrimes/*ed*/	{ "in",    FALSE, LONG,  op2(DX, A) , 0 },
9324Srgrimes/*ee*/	{ "out",   FALSE, BYTE,  op2(A, DX),  0 },
9334Srgrimes/*ef*/	{ "out",   FALSE, LONG,  op2(A, DX) , 0 },
9344Srgrimes
9354Srgrimes/*f0*/	{ "",      FALSE, NONE,  0,	     0 },
93621277Sbde/*f1*/	{ ".byte\t0xf1", FALSE, NONE, 0,     0 },
9374Srgrimes/*f2*/	{ "",      FALSE, NONE,  0,	     0 },
9384Srgrimes/*f3*/	{ "",      FALSE, NONE,  0,	     0 },
9394Srgrimes/*f4*/	{ "hlt",   FALSE, NONE,  0,	     0 },
9404Srgrimes/*f5*/	{ "cmc",   FALSE, NONE,  0,	     0 },
94117109Sbde/*f6*/	{ "",      TRUE,  BYTE,  0,	     db_Grp3 },
94217109Sbde/*f7*/	{ "",	   TRUE,  LONG,  0,	     db_Grp3 },
9434Srgrimes
9444Srgrimes/*f8*/	{ "clc",   FALSE, NONE,  0,	     0 },
9454Srgrimes/*f9*/	{ "stc",   FALSE, NONE,  0,	     0 },
9464Srgrimes/*fa*/	{ "cli",   FALSE, NONE,  0,	     0 },
9474Srgrimes/*fb*/	{ "sti",   FALSE, NONE,  0,	     0 },
9484Srgrimes/*fc*/	{ "cld",   FALSE, NONE,  0,	     0 },
9494Srgrimes/*fd*/	{ "std",   FALSE, NONE,  0,	     0 },
95017109Sbde/*fe*/	{ "",	   TRUE,  NONE,  0,	     db_Grp4 },
95117109Sbde/*ff*/	{ "",	   TRUE,  NONE,  0,	     db_Grp5 },
9524Srgrimes};
9534Srgrimes
95417109Sbdestatic const struct inst db_bad_inst =
9554Srgrimes	{ "???",   FALSE, NONE,  0,	      0 }
9564Srgrimes;
9574Srgrimes
958144353Speter#define	f_mod(rex, byte)	((byte)>>6)
959144353Speter#define	f_reg(rex, byte)	((((byte)>>3)&0x7) | (rex & REX_R ? 0x8 : 0x0))
960144353Speter#define	f_rm(rex, byte)		(((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0))
9614Srgrimes
962144353Speter#define	sib_ss(rex, byte)	((byte)>>6)
963144353Speter#define	sib_index(rex, byte)	((((byte)>>3)&0x7) | (rex & REX_X ? 0x8 : 0x0))
964144353Speter#define	sib_base(rex, byte)	(((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0))
9654Srgrimes
96611940Sbdestruct i_addr {
9674Srgrimes	int		is_reg;	/* if reg, reg number is in 'disp' */
9684Srgrimes	int		disp;
96914887Swollman	const char *	base;
97014887Swollman	const char *	index;
9714Srgrimes	int		ss;
9724Srgrimes};
9734Srgrimes
974144353Speterstatic const char * const db_reg[2][4][16] = {
975144353Speter
976144353Speter	{{"%al",  "%cl",  "%dl",  "%bl",  "%ah",  "%ch",  "%dh",  "%bh",
977144353Speter	  "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" },
978144353Speter	{ "%ax",  "%cx",  "%dx",  "%bx",  "%sp",  "%bp",  "%si",  "%di",
979144353Speter	  "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" },
980144353Speter	{ "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
981144353Speter	  "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" },
982144353Speter	{ "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
983144353Speter	  "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }},
984144353Speter
985144353Speter	{{"%al",  "%cl",  "%dl",  "%bl",  "%spl",  "%bpl",  "%sil",  "%dil",
986144353Speter	  "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" },
987144353Speter	{ "%ax",  "%cx",  "%dx",  "%bx",  "%sp",  "%bp",  "%si",  "%di",
988144353Speter	  "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" },
989144353Speter	{ "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
990144353Speter	  "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" },
991144353Speter	{ "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
992144353Speter	  "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }}
9934Srgrimes};
9944Srgrimes
99517109Sbdestatic const char * const db_seg_reg[8] = {
9964Srgrimes	"%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
9974Srgrimes};
9984Srgrimes
9994Srgrimes/*
10004Srgrimes * lengths for size attributes
10014Srgrimes */
100214887Swollmanstatic const int db_lengths[] = {
10034Srgrimes	1,	/* BYTE */
10044Srgrimes	2,	/* WORD */
10054Srgrimes	4,	/* LONG */
10064Srgrimes	8,	/* QUAD */
10074Srgrimes	4,	/* SNGL */
10084Srgrimes	8,	/* DBLR */
10094Srgrimes	10,	/* EXTR */
10104Srgrimes};
10114Srgrimes
10124Srgrimes#define	get_value_inc(result, loc, size, is_signed) \
10134Srgrimes	result = db_get_value((loc), (size), (is_signed)); \
10144Srgrimes	(loc) += (size);
10154Srgrimes
101611940Sbdestatic db_addr_t
1017144353Speter		db_disasm_esc(db_addr_t loc, int inst, int rex, int short_addr,
101893017Sbde		    int size, const char *seg);
1019144353Speterstatic void	db_print_address(const char *seg, int size, int rex,
102093017Sbde		    struct i_addr *addrp);
102111940Sbdestatic db_addr_t
1022144353Speter		db_read_address(db_addr_t loc, int short_addr, int rex, int regmodrm,
102393017Sbde		    struct i_addr *addrp);
102411940Sbde
10254Srgrimes/*
10264Srgrimes * Read address at location and return updated location.
10274Srgrimes */
102811921Sphkstatic db_addr_t
1029144353Speterdb_read_address(loc, short_addr, rex, regmodrm, addrp)
10304Srgrimes	db_addr_t	loc;
10314Srgrimes	int		short_addr;
1032144353Speter	int		rex;
10334Srgrimes	int		regmodrm;
103417109Sbde	struct i_addr *	addrp;		/* out */
10354Srgrimes{
1036164263Sjhb	int		mod, rm, sib, index, disp, size, have_sib;
10374Srgrimes
1038144353Speter	mod = f_mod(rex, regmodrm);
1039144353Speter	rm  = f_rm(rex, regmodrm);
10404Srgrimes
10414Srgrimes	if (mod == 3) {
10424Srgrimes	    addrp->is_reg = TRUE;
10434Srgrimes	    addrp->disp = rm;
10444Srgrimes	    return (loc);
10454Srgrimes	}
10464Srgrimes	addrp->is_reg = FALSE;
1047315221Spfg	addrp->index = NULL;
10484Srgrimes
1049164263Sjhb	if (short_addr)
1050164263Sjhb	    size = LONG;
1051164263Sjhb	else
1052164263Sjhb	    size = QUAD;
10534Srgrimes
1054164263Sjhb	if ((rm & 0x7) == 4) {
1055164263Sjhb	    get_value_inc(sib, loc, 1, FALSE);
1056164263Sjhb	    rm = sib_base(rex, sib);
1057164263Sjhb	    index = sib_index(rex, sib);
1058164263Sjhb	    if (index != 4)
1059164263Sjhb		addrp->index = db_reg[1][size][index];
1060164263Sjhb	    addrp->ss = sib_ss(rex, sib);
1061164263Sjhb	    have_sib = 1;
1062164263Sjhb	} else
1063164263Sjhb	    have_sib = 0;
1064164263Sjhb
1065164263Sjhb	switch (mod) {
1066164263Sjhb	    case 0:
1067164263Sjhb		if (rm == 5) {
1068164263Sjhb		    get_value_inc(addrp->disp, loc, 4, FALSE);
1069164263Sjhb		    if (have_sib)
1070315221Spfg			addrp->base = NULL;
1071164263Sjhb		    else if (short_addr)
1072164263Sjhb			addrp->base = "%eip";
1073164263Sjhb		    else
1074164263Sjhb			addrp->base = "%rip";
1075164263Sjhb		} else {
1076164263Sjhb		    addrp->disp = 0;
1077164263Sjhb		    addrp->base = db_reg[1][size][rm];
1078164263Sjhb		}
1079164263Sjhb		break;
10804Srgrimes
1081164263Sjhb	    case 1:
1082164263Sjhb		get_value_inc(disp, loc, 1, TRUE);
1083164263Sjhb		addrp->disp = disp;
1084164263Sjhb		addrp->base = db_reg[1][size][rm];
1085164263Sjhb		break;
10864Srgrimes
1087164263Sjhb	    case 2:
1088164263Sjhb		get_value_inc(disp, loc, 4, FALSE);
1089164263Sjhb		addrp->disp = disp;
1090164263Sjhb		addrp->base = db_reg[1][size][rm];
1091164263Sjhb		break;
10924Srgrimes	}
10934Srgrimes	return (loc);
10944Srgrimes}
10954Srgrimes
109611921Sphkstatic void
1097144353Speterdb_print_address(seg, size, rex, addrp)
109817109Sbde	const char *	seg;
10994Srgrimes	int		size;
1100144353Speter	int		rex;
110117109Sbde	struct i_addr *	addrp;
11024Srgrimes{
11034Srgrimes	if (addrp->is_reg) {
1104144354Speter	    db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][addrp->disp]);
11054Srgrimes	    return;
11064Srgrimes	}
11074Srgrimes
11084Srgrimes	if (seg) {
11094Srgrimes	    db_printf("%s:", seg);
11104Srgrimes	}
11114Srgrimes
1112315221Spfg	if (addrp->disp != 0 || (addrp->base == NULL && addrp->index == NULL))
1113164263Sjhb		db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY);
1114315221Spfg	if (addrp->base != NULL || addrp->index != NULL) {
11154Srgrimes	    db_printf("(");
11164Srgrimes	    if (addrp->base)
11174Srgrimes		db_printf("%s", addrp->base);
11184Srgrimes	    if (addrp->index)
11194Srgrimes		db_printf(",%s,%d", addrp->index, 1<<addrp->ss);
11204Srgrimes	    db_printf(")");
11214Srgrimes	}
11224Srgrimes}
11234Srgrimes
11244Srgrimes/*
11254Srgrimes * Disassemble floating-point ("escape") instruction
11264Srgrimes * and return updated location.
11274Srgrimes */
112811921Sphkstatic db_addr_t
1129144353Speterdb_disasm_esc(loc, inst, rex, short_addr, size, seg)
11304Srgrimes	db_addr_t	loc;
11314Srgrimes	int		inst;
1132144353Speter	int		rex;
11334Srgrimes	int		short_addr;
11344Srgrimes	int		size;
113517109Sbde	const char *	seg;
11364Srgrimes{
11374Srgrimes	int		regmodrm;
113817109Sbde	const struct finst *	fp;
11394Srgrimes	int		mod;
11404Srgrimes	struct i_addr	address;
114117109Sbde	const char *	name;
11424Srgrimes
11434Srgrimes	get_value_inc(regmodrm, loc, 1, FALSE);
1144144353Speter	fp = &db_Esc_inst[inst - 0xd8][f_reg(rex, regmodrm)];
1145144353Speter	mod = f_mod(rex, regmodrm);
11464Srgrimes	if (mod != 3) {
114721277Sbde	    if (*fp->f_name == '\0') {
114821277Sbde		db_printf("<bad instruction>");
114921277Sbde		return (loc);
115021277Sbde	    }
11514Srgrimes	    /*
11524Srgrimes	     * Normal address modes.
11534Srgrimes	     */
1154144353Speter	    loc = db_read_address(loc, short_addr, rex, regmodrm, &address);
115579885Skris	    db_printf("%s", fp->f_name);
11564Srgrimes	    switch(fp->f_size) {
11574Srgrimes		case SNGL:
11584Srgrimes		    db_printf("s");
11594Srgrimes		    break;
11604Srgrimes		case DBLR:
11614Srgrimes		    db_printf("l");
11624Srgrimes		    break;
11634Srgrimes		case EXTR:
11644Srgrimes		    db_printf("t");
11654Srgrimes		    break;
11664Srgrimes		case WORD:
11674Srgrimes		    db_printf("s");
11684Srgrimes		    break;
11694Srgrimes		case LONG:
11704Srgrimes		    db_printf("l");
11714Srgrimes		    break;
11724Srgrimes		case QUAD:
11734Srgrimes		    db_printf("q");
11744Srgrimes		    break;
11754Srgrimes		default:
11764Srgrimes		    break;
11774Srgrimes	    }
11784Srgrimes	    db_printf("\t");
1179144353Speter	    db_print_address(seg, BYTE, rex, &address);
11804Srgrimes	}
11814Srgrimes	else {
11824Srgrimes	    /*
11834Srgrimes	     * 'reg-reg' - special formats
11844Srgrimes	     */
11854Srgrimes	    switch (fp->f_rrmode) {
11864Srgrimes		case op2(ST,STI):
11874Srgrimes		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1188144353Speter		    db_printf("%s\t%%st,%%st(%d)",name,f_rm(rex, regmodrm));
11894Srgrimes		    break;
11904Srgrimes		case op2(STI,ST):
11914Srgrimes		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1192144353Speter		    db_printf("%s\t%%st(%d),%%st",name, f_rm(rex, regmodrm));
11934Srgrimes		    break;
11944Srgrimes		case op1(STI):
11954Srgrimes		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1196144353Speter		    db_printf("%s\t%%st(%d)",name, f_rm(rex, regmodrm));
11974Srgrimes		    break;
11984Srgrimes		case op1(X):
1199144353Speter		    name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)];
120021277Sbde		    if (*name == '\0')
120121277Sbde			goto bad;
120221277Sbde		    db_printf("%s", name);
12034Srgrimes		    break;
12044Srgrimes		case op1(XA):
1205144353Speter		    name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)];
120621277Sbde		    if (*name == '\0')
120721277Sbde			goto bad;
120821277Sbde		    db_printf("%s\t%%ax", name);
12094Srgrimes		    break;
12104Srgrimes		default:
121121277Sbde		bad:
12124Srgrimes		    db_printf("<bad instruction>");
12134Srgrimes		    break;
12144Srgrimes	    }
12154Srgrimes	}
12164Srgrimes
12174Srgrimes	return (loc);
12184Srgrimes}
12194Srgrimes
12204Srgrimes/*
12214Srgrimes * Disassemble instruction at 'loc'.  'altfmt' specifies an
12224Srgrimes * (optional) alternate format.  Return address of start of
12234Srgrimes * next instruction.
12244Srgrimes */
12254Srgrimesdb_addr_t
1226283248Spfgdb_disasm(db_addr_t loc, bool altfmt)
12274Srgrimes{
12284Srgrimes	int	inst;
12294Srgrimes	int	size;
12304Srgrimes	int	short_addr;
123117109Sbde	const char *	seg;
123214887Swollman	const struct inst *	ip;
123314887Swollman	const char *	i_name;
12344Srgrimes	int	i_size;
12354Srgrimes	int	i_mode;
1236144353Speter	int	rex = 0;
1237798Swollman	int	regmodrm = 0;
12384Srgrimes	boolean_t	first;
12394Srgrimes	int	displ;
12404Srgrimes	int	prefix;
1241181606Sjhb	int	rep;
12424Srgrimes	int	imm;
12434Srgrimes	int	imm2;
1244164263Sjhb	long	imm64;
12454Srgrimes	int	len;
12464Srgrimes	struct i_addr	address;
12474Srgrimes
12484Srgrimes	get_value_inc(inst, loc, 1, FALSE);
12494Srgrimes	short_addr = FALSE;
12504Srgrimes	size = LONG;
1251315221Spfg	seg = NULL;
12524Srgrimes
12534Srgrimes	/*
12544Srgrimes	 * Get prefixes
12554Srgrimes	 */
1256181606Sjhb	rep = FALSE;
12574Srgrimes	prefix = TRUE;
12584Srgrimes	do {
12594Srgrimes	    switch (inst) {
12604Srgrimes		case 0x66:		/* data16 */
12614Srgrimes		    size = WORD;
12624Srgrimes		    break;
12634Srgrimes		case 0x67:
12644Srgrimes		    short_addr = TRUE;
12654Srgrimes		    break;
12664Srgrimes		case 0x26:
12674Srgrimes		    seg = "%es";
12684Srgrimes		    break;
12694Srgrimes		case 0x36:
12704Srgrimes		    seg = "%ss";
12714Srgrimes		    break;
12724Srgrimes		case 0x2e:
12734Srgrimes		    seg = "%cs";
12744Srgrimes		    break;
12754Srgrimes		case 0x3e:
12764Srgrimes		    seg = "%ds";
12774Srgrimes		    break;
12784Srgrimes		case 0x64:
12794Srgrimes		    seg = "%fs";
12804Srgrimes		    break;
12814Srgrimes		case 0x65:
12824Srgrimes		    seg = "%gs";
12834Srgrimes		    break;
12844Srgrimes		case 0xf0:
12854Srgrimes		    db_printf("lock ");
12864Srgrimes		    break;
12874Srgrimes		case 0xf2:
12884Srgrimes		    db_printf("repne ");
12894Srgrimes		    break;
12904Srgrimes		case 0xf3:
1291181606Sjhb		    rep = TRUE;
12924Srgrimes		    break;
12934Srgrimes		default:
12944Srgrimes		    prefix = FALSE;
12954Srgrimes		    break;
12964Srgrimes	    }
1297144353Speter	    if (inst >= 0x40 && inst < 0x50) {
1298144353Speter		rex = inst;
1299144353Speter		prefix = TRUE;
1300144353Speter	    }
13014Srgrimes	    if (prefix) {
13024Srgrimes		get_value_inc(inst, loc, 1, FALSE);
13034Srgrimes	    }
13044Srgrimes	} while (prefix);
13054Srgrimes
13064Srgrimes	if (inst >= 0xd8 && inst <= 0xdf) {
1307144353Speter	    loc = db_disasm_esc(loc, inst, rex, short_addr, size, seg);
13084Srgrimes	    db_printf("\n");
13094Srgrimes	    return (loc);
13104Srgrimes	}
13114Srgrimes
1312238166Sjhb	ip = &db_inst_table[inst];
1313238166Sjhb	while (ip->i_size == ESC) {
13144Srgrimes	    get_value_inc(inst, loc, 1, FALSE);
1315238166Sjhb	    ip = ((const struct inst * const *)ip->i_extra)[inst>>4];
1316315221Spfg	    if (ip == NULL) {
13174Srgrimes		ip = &db_bad_inst;
13184Srgrimes	    }
13194Srgrimes	    else {
13204Srgrimes		ip = &ip[inst&0xf];
13214Srgrimes	    }
13224Srgrimes	}
13234Srgrimes
13244Srgrimes	if (ip->i_has_modrm) {
13254Srgrimes	    get_value_inc(regmodrm, loc, 1, FALSE);
1326144353Speter	    loc = db_read_address(loc, short_addr, rex, regmodrm, &address);
13274Srgrimes	}
13284Srgrimes
13294Srgrimes	i_name = ip->i_name;
13304Srgrimes	i_size = ip->i_size;
13314Srgrimes	i_mode = ip->i_mode;
13324Srgrimes
1333266354Sjhb	if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) == 3) {
1334266354Sjhb	    ip = &db_Grp9b[f_reg(rex, regmodrm)];
1335266354Sjhb	    i_name = ip->i_name;
1336266354Sjhb	    i_size = ip->i_size;
1337266354Sjhb	    i_mode = ip->i_mode;
1338266354Sjhb	}
1339266354Sjhb	else if (ip->i_extra == db_Grp1 || ip->i_extra == db_Grp2 ||
134017109Sbde	    ip->i_extra == db_Grp6 || ip->i_extra == db_Grp7 ||
1341181606Sjhb	    ip->i_extra == db_Grp8 || ip->i_extra == db_Grp9 ||
1342181606Sjhb	    ip->i_extra == db_Grp15) {
1343144353Speter	    i_name = ((const char * const *)ip->i_extra)[f_reg(rex, regmodrm)];
13444Srgrimes	}
134517109Sbde	else if (ip->i_extra == db_Grp3) {
134617109Sbde	    ip = ip->i_extra;
1347144353Speter	    ip = &ip[f_reg(rex, regmodrm)];
13484Srgrimes	    i_name = ip->i_name;
13494Srgrimes	    i_mode = ip->i_mode;
13504Srgrimes	}
135117109Sbde	else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) {
135217109Sbde	    ip = ip->i_extra;
1353144353Speter	    ip = &ip[f_reg(rex, regmodrm)];
13544Srgrimes	    i_name = ip->i_name;
13554Srgrimes	    i_mode = ip->i_mode;
13564Srgrimes	    i_size = ip->i_size;
13574Srgrimes	}
13584Srgrimes
1359181606Sjhb	/* Special cases that don't fit well in the tables. */
1360181606Sjhb	if (ip->i_extra == db_Grp7 && f_mod(rex, regmodrm) == 3) {
1361181606Sjhb		switch (regmodrm) {
1362238166Sjhb		case 0xc1:
1363238166Sjhb			i_name = "vmcall";
1364238166Sjhb			i_size = NONE;
1365238166Sjhb			i_mode = 0;
1366238166Sjhb			break;
1367238166Sjhb		case 0xc2:
1368238166Sjhb			i_name = "vmlaunch";
1369238166Sjhb			i_size = NONE;
1370238166Sjhb			i_mode = 0;
1371238166Sjhb			break;
1372238166Sjhb		case 0xc3:
1373238166Sjhb			i_name = "vmresume";
1374238166Sjhb			i_size = NONE;
1375238166Sjhb			i_mode = 0;
1376238166Sjhb			break;
1377238166Sjhb		case 0xc4:
1378238166Sjhb			i_name = "vmxoff";
1379238166Sjhb			i_size = NONE;
1380238166Sjhb			i_mode = 0;
1381238166Sjhb			break;
1382181606Sjhb		case 0xc8:
1383181606Sjhb			i_name = "monitor";
1384181606Sjhb			i_size = NONE;
1385181606Sjhb			i_mode = 0;
1386181606Sjhb			break;
1387181606Sjhb		case 0xc9:
1388181606Sjhb			i_name = "mwait";
1389181606Sjhb			i_size = NONE;
1390181606Sjhb			i_mode = 0;
1391181606Sjhb			break;
1392261213Sjhb		case 0xca:
1393261213Sjhb			i_name = "clac";
1394261213Sjhb			i_size = NONE;
1395261213Sjhb			i_mode = 0;
1396261213Sjhb			break;
1397261213Sjhb		case 0xcb:
1398261213Sjhb			i_name = "stac";
1399261213Sjhb			i_size = NONE;
1400261213Sjhb			i_mode = 0;
1401261213Sjhb			break;
1402238109Sjhb		case 0xd0:
1403238109Sjhb			i_name = "xgetbv";
1404238109Sjhb			i_size = NONE;
1405238109Sjhb			i_mode = 0;
1406238109Sjhb			break;
1407238109Sjhb		case 0xd1:
1408238109Sjhb			i_name = "xsetbv";
1409238109Sjhb			i_size = NONE;
1410238109Sjhb			i_mode = 0;
1411238109Sjhb			break;
1412266449Sjhb		case 0xd8:
1413266449Sjhb			i_name = "vmrun";
1414266449Sjhb			i_size = NONE;
1415266449Sjhb			i_mode = 0;
1416266449Sjhb			break;
1417266449Sjhb		case 0xd9:
1418266449Sjhb			i_name = "vmmcall";
1419266449Sjhb			i_size = NONE;
1420266449Sjhb			i_mode = 0;
1421266449Sjhb			break;
1422266449Sjhb		case 0xda:
1423266449Sjhb			i_name = "vmload";
1424266449Sjhb			i_size = NONE;
1425266449Sjhb			i_mode = 0;
1426266449Sjhb			break;
1427266449Sjhb		case 0xdb:
1428266449Sjhb			i_name = "vmsave";
1429266449Sjhb			i_size = NONE;
1430266449Sjhb			i_mode = 0;
1431266449Sjhb			break;
1432266449Sjhb		case 0xdc:
1433266449Sjhb			i_name = "stgi";
1434266449Sjhb			i_size = NONE;
1435266449Sjhb			i_mode = 0;
1436266449Sjhb			break;
1437266449Sjhb		case 0xdd:
1438266449Sjhb			i_name = "clgi";
1439266449Sjhb			i_size = NONE;
1440266449Sjhb			i_mode = 0;
1441266449Sjhb			break;
1442266449Sjhb		case 0xde:
1443266449Sjhb			i_name = "skinit";
1444266449Sjhb			i_size = NONE;
1445266449Sjhb			i_mode = 0;
1446266449Sjhb			break;
1447266449Sjhb		case 0xdf:
1448266449Sjhb			i_name = "invlpga";
1449266449Sjhb			i_size = NONE;
1450266449Sjhb			i_mode = 0;
1451266449Sjhb			break;
1452181606Sjhb		case 0xf8:
1453181606Sjhb			i_name = "swapgs";
1454181606Sjhb			i_size = NONE;
1455181606Sjhb			i_mode = 0;
1456181606Sjhb			break;
1457238109Sjhb		case 0xf9:
1458238109Sjhb			i_name = "rdtscp";
1459238109Sjhb			i_size = NONE;
1460238109Sjhb			i_mode = 0;
1461238109Sjhb			break;
1462181606Sjhb		}
1463181606Sjhb	}
1464181606Sjhb	if (ip->i_extra == db_Grp15 && f_mod(rex, regmodrm) == 3) {
1465181606Sjhb		i_name = db_Grp15b[f_reg(rex, regmodrm)];
1466181606Sjhb		i_size = NONE;
1467181606Sjhb		i_mode = 0;
1468181606Sjhb	}
1469181606Sjhb
1470238166Sjhb	/* Handle instructions identified by mandatory prefixes. */
1471238166Sjhb	if (rep == TRUE) {
1472238166Sjhb	    if (inst == 0x90) {
1473238166Sjhb		i_name = "pause";
1474238166Sjhb		i_size = NONE;
1475238166Sjhb		i_mode = 0;
1476238166Sjhb		rep = FALSE;
1477238166Sjhb	    } else if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) != 3 &&
1478238166Sjhb		f_reg(rex, regmodrm) == 0x6) {
1479238166Sjhb		i_name = "vmxon";
1480238166Sjhb		rep = FALSE;
1481238166Sjhb	    }
1482238166Sjhb	}
1483238166Sjhb	if (size == WORD) {
1484238166Sjhb	    if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) != 3 &&
1485238166Sjhb		f_reg(rex, regmodrm) == 0x6) {
1486238166Sjhb		i_name = "vmclear";
1487238166Sjhb	    }
1488238166Sjhb	}
1489238166Sjhb	if (rex & REX_W) {
1490238166Sjhb	    if (strcmp(i_name, "cwde") == 0)
1491238166Sjhb		i_name = "cdqe";
1492238166Sjhb	    else if (strcmp(i_name, "cmpxchg8b") == 0)
1493238166Sjhb		i_name = "cmpxchg16b";
1494238166Sjhb	}
1495238166Sjhb
1496238166Sjhb	if (rep == TRUE)
1497238166Sjhb	    db_printf("repe ");	/* XXX repe VS rep */
1498238166Sjhb
14994Srgrimes	if (i_size == SDEP) {
1500238166Sjhb	    if (size == LONG)
150179885Skris		db_printf("%s", i_name);
15024Srgrimes	    else
150379885Skris		db_printf("%s", (const char *)ip->i_extra);
1504238166Sjhb	} else if (i_size == ADEP) {
1505238166Sjhb	    if (short_addr == FALSE)
1506238166Sjhb		db_printf("%s", i_name);
1507238166Sjhb	    else
1508238166Sjhb		db_printf("%s", (const char *)ip->i_extra);
15094Srgrimes	}
15104Srgrimes	else {
151179885Skris	    db_printf("%s", i_name);
1512144354Speter	    if ((inst >= 0x50 && inst <= 0x5f) || inst == 0x68 || inst == 0x6a) {
1513144354Speter		i_size = NONE;
1514144354Speter		db_printf("q");
1515144354Speter	    }
15164Srgrimes	    if (i_size != NONE) {
15174Srgrimes		if (i_size == BYTE) {
15184Srgrimes		    db_printf("b");
15194Srgrimes		    size = BYTE;
15204Srgrimes		}
15214Srgrimes		else if (i_size == WORD) {
15224Srgrimes		    db_printf("w");
15234Srgrimes		    size = WORD;
15244Srgrimes		}
15254Srgrimes		else if (size == WORD)
15264Srgrimes		    db_printf("w");
1527144353Speter		else {
1528144353Speter		    if (rex & REX_W)
1529144353Speter			db_printf("q");
1530144353Speter		    else
1531144353Speter			db_printf("l");
1532144353Speter		}
15334Srgrimes	    }
15344Srgrimes	}
15354Srgrimes	db_printf("\t");
15364Srgrimes	for (first = TRUE;
15374Srgrimes	     i_mode != 0;
15384Srgrimes	     i_mode >>= 8, first = FALSE)
15394Srgrimes	{
15404Srgrimes	    if (!first)
15414Srgrimes		db_printf(",");
15424Srgrimes
15434Srgrimes	    switch (i_mode & 0xFF) {
15444Srgrimes
15454Srgrimes		case E:
1546144353Speter		    db_print_address(seg, size, rex, &address);
15474Srgrimes		    break;
15484Srgrimes
15494Srgrimes		case Eind:
15504Srgrimes		    db_printf("*");
1551144353Speter		    db_print_address(seg, size, rex, &address);
15524Srgrimes		    break;
15534Srgrimes
155421277Sbde		case El:
1555144353Speter		    db_print_address(seg, (rex & REX_W) ? QUAD : LONG, rex, &address);
155621277Sbde		    break;
155721277Sbde
1558144354Speter		case EL:
1559144354Speter		    db_print_address(seg, LONG, 0, &address);
1560144354Speter		    break;
1561144354Speter
15624Srgrimes		case Ew:
1563144353Speter		    db_print_address(seg, WORD, rex, &address);
15644Srgrimes		    break;
15654Srgrimes
15664Srgrimes		case Eb:
1567144353Speter		    db_print_address(seg, BYTE, rex, &address);
15684Srgrimes		    break;
15694Srgrimes
15704Srgrimes		case R:
1571144354Speter		    db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][f_reg(rex, regmodrm)]);
15724Srgrimes		    break;
15734Srgrimes
15744Srgrimes		case Rw:
1575144353Speter		    db_printf("%s", db_reg[rex != 0 ? 1 : 0][WORD][f_reg(rex, regmodrm)]);
15764Srgrimes		    break;
15774Srgrimes
1578238166Sjhb		case Rq:
1579238166Sjhb		    db_printf("%s", db_reg[rex != 0 ? 1 : 0][QUAD][f_reg(rex, regmodrm)]);
1580238166Sjhb		    break;
1581238166Sjhb
15824Srgrimes		case Ri:
1583144354Speter		    db_printf("%s", db_reg[0][QUAD][f_rm(rex, inst)]);
15844Srgrimes		    break;
15854Srgrimes
158621277Sbde		case Ril:
1587144353Speter		    db_printf("%s", db_reg[rex != 0 ? 1 : 0][(rex & REX_R) ? QUAD : LONG][f_rm(rex, inst)]);
158821277Sbde		    break;
158921277Sbde
1590266354Sjhb	        case Rv:
1591266354Sjhb		    db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][f_rm(rex, regmodrm)]);
1592266354Sjhb		    break;
1593266354Sjhb
15944Srgrimes		case S:
1595144353Speter		    db_printf("%s", db_seg_reg[f_reg(rex, regmodrm)]);
15964Srgrimes		    break;
15974Srgrimes
15984Srgrimes		case Si:
1599144353Speter		    db_printf("%s", db_seg_reg[f_reg(rex, inst)]);
16004Srgrimes		    break;
16014Srgrimes
16024Srgrimes		case A:
1603144353Speter		    db_printf("%s", db_reg[rex != 0 ? 1 : 0][size][0]);	/* acc */
16044Srgrimes		    break;
16054Srgrimes
16064Srgrimes		case BX:
16074Srgrimes		    if (seg)
16084Srgrimes			db_printf("%s:", seg);
16094Srgrimes		    db_printf("(%s)", short_addr ? "%bx" : "%ebx");
16104Srgrimes		    break;
16114Srgrimes
16124Srgrimes		case CL:
16134Srgrimes		    db_printf("%%cl");
16144Srgrimes		    break;
16154Srgrimes
16164Srgrimes		case DX:
16174Srgrimes		    db_printf("%%dx");
16184Srgrimes		    break;
16194Srgrimes
16204Srgrimes		case SI:
16214Srgrimes		    if (seg)
16224Srgrimes			db_printf("%s:", seg);
1623144353Speter		    db_printf("(%s)", short_addr ? "%si" : "%rsi");
16244Srgrimes		    break;
16254Srgrimes
16264Srgrimes		case DI:
1627144353Speter		    db_printf("%%es:(%s)", short_addr ? "%di" : "%rdi");
16284Srgrimes		    break;
16294Srgrimes
16304Srgrimes		case CR:
1631144353Speter		    db_printf("%%cr%d", f_reg(rex, regmodrm));
16324Srgrimes		    break;
16334Srgrimes
16344Srgrimes		case DR:
1635144353Speter		    db_printf("%%dr%d", f_reg(rex, regmodrm));
16364Srgrimes		    break;
16374Srgrimes
16384Srgrimes		case TR:
1639144353Speter		    db_printf("%%tr%d", f_reg(rex, regmodrm));
16404Srgrimes		    break;
16414Srgrimes
16424Srgrimes		case I:
1643144354Speter		    len = db_lengths[size];
164421277Sbde		    get_value_inc(imm, loc, len, FALSE);
164537506Sbde		    db_printf("$%#r", imm);
16464Srgrimes		    break;
16474Srgrimes
16484Srgrimes		case Is:
1649144353Speter		    len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
165021277Sbde		    get_value_inc(imm, loc, len, FALSE);
165137506Sbde		    db_printf("$%+#r", imm);
16524Srgrimes		    break;
16534Srgrimes
16544Srgrimes		case Ib:
165521277Sbde		    get_value_inc(imm, loc, 1, FALSE);
165637506Sbde		    db_printf("$%#r", imm);
16574Srgrimes		    break;
16584Srgrimes
165921277Sbde		case Iba:
166021277Sbde		    get_value_inc(imm, loc, 1, FALSE);
166121277Sbde		    if (imm != 0x0a)
166237506Sbde			db_printf("$%#r", imm);
166321277Sbde		    break;
166421277Sbde
16654Srgrimes		case Ibs:
166621277Sbde		    get_value_inc(imm, loc, 1, TRUE);
166721277Sbde		    if (size == WORD)
166821277Sbde			imm &= 0xFFFF;
166937506Sbde		    db_printf("$%+#r", imm);
16704Srgrimes		    break;
16714Srgrimes
16724Srgrimes		case Iw:
167321277Sbde		    get_value_inc(imm, loc, 2, FALSE);
167437506Sbde		    db_printf("$%#r", imm);
16754Srgrimes		    break;
16764Srgrimes
1677164263Sjhb		case Ilq:
1678164263Sjhb		    len = db_lengths[rex & REX_W ? QUAD : LONG];
1679164263Sjhb		    get_value_inc(imm64, loc, len, FALSE);
1680164263Sjhb		    db_printf("$%#lr", imm64);
1681164263Sjhb		    break;
1682164263Sjhb
16834Srgrimes		case O:
168421277Sbde		    len = (short_addr ? 2 : 4);
168521277Sbde		    get_value_inc(displ, loc, len, FALSE);
16864Srgrimes		    if (seg)
168737506Sbde			db_printf("%s:%+#r",seg, displ);
16884Srgrimes		    else
16894Srgrimes			db_printsym((db_addr_t)displ, DB_STGY_ANY);
16904Srgrimes		    break;
16914Srgrimes
16924Srgrimes		case Db:
16934Srgrimes		    get_value_inc(displ, loc, 1, TRUE);
169421277Sbde		    displ += loc;
169521277Sbde		    if (size == WORD)
169621277Sbde			displ &= 0xFFFF;
169721277Sbde		    db_printsym((db_addr_t)displ, DB_STGY_XTRN);
16984Srgrimes		    break;
16994Srgrimes
17004Srgrimes		case Dl:
1701144353Speter		    len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
170221277Sbde		    get_value_inc(displ, loc, len, FALSE);
170321277Sbde		    displ += loc;
170421277Sbde		    if (size == WORD)
170521277Sbde			displ &= 0xFFFF;
170621277Sbde		    db_printsym((db_addr_t)displ, DB_STGY_XTRN);
17074Srgrimes		    break;
17084Srgrimes
17094Srgrimes		case o1:
17104Srgrimes		    db_printf("$1");
17114Srgrimes		    break;
17124Srgrimes
17134Srgrimes		case o3:
17144Srgrimes		    db_printf("$3");
17154Srgrimes		    break;
17164Srgrimes
17174Srgrimes		case OS:
171821277Sbde		    len = db_lengths[size];
171921277Sbde		    get_value_inc(imm, loc, len, FALSE);	/* offset */
17204Srgrimes		    get_value_inc(imm2, loc, 2, FALSE);	/* segment */
172137506Sbde		    db_printf("$%#r,%#r", imm2, imm);
17224Srgrimes		    break;
17234Srgrimes	    }
17244Srgrimes	}
17254Srgrimes	db_printf("\n");
17264Srgrimes	return (loc);
17274Srgrimes}
1728