db_disasm.c revision 266449
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 266449 2014-05-19 18:07:37Z jhb $");
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
25317109Sbdestatic const struct inst db_inst_0f2x[] = {
25421277Sbde/*20*/	{ "mov",   TRUE,  LONG,  op2(CR,El),  0 },
25521277Sbde/*21*/	{ "mov",   TRUE,  LONG,  op2(DR,El),  0 },
25621277Sbde/*22*/	{ "mov",   TRUE,  LONG,  op2(El,CR),  0 },
25721277Sbde/*23*/	{ "mov",   TRUE,  LONG,  op2(El,DR),  0 },
25821277Sbde/*24*/	{ "mov",   TRUE,  LONG,  op2(TR,El),  0 },
2594Srgrimes/*25*/	{ "",      FALSE, NONE,  0,	      0 },
26021277Sbde/*26*/	{ "mov",   TRUE,  LONG,  op2(El,TR),  0 },
2614Srgrimes/*27*/	{ "",      FALSE, NONE,  0,	      0 },
2624Srgrimes
2634Srgrimes/*28*/	{ "",      FALSE, NONE,  0,	      0 },
2644Srgrimes/*29*/	{ "",      FALSE, NONE,  0,	      0 },
2654Srgrimes/*2a*/	{ "",      FALSE, NONE,  0,	      0 },
2664Srgrimes/*2b*/	{ "",      FALSE, NONE,  0,	      0 },
2674Srgrimes/*2c*/	{ "",      FALSE, NONE,  0,	      0 },
2684Srgrimes/*2d*/	{ "",      FALSE, NONE,  0,	      0 },
2694Srgrimes/*2e*/	{ "",      FALSE, NONE,  0,	      0 },
2704Srgrimes/*2f*/	{ "",      FALSE, NONE,  0,	      0 },
2714Srgrimes};
2724Srgrimes
27314887Swollmanstatic const struct inst db_inst_0f3x[] = {
27414887Swollman/*30*/	{ "wrmsr", FALSE, NONE,  0,	      0 },
27514887Swollman/*31*/	{ "rdtsc", FALSE, NONE,  0,	      0 },
27614887Swollman/*32*/	{ "rdmsr", FALSE, NONE,  0,	      0 },
27714887Swollman/*33*/	{ "rdpmc", FALSE, NONE,  0,	      0 },
278181606Sjhb/*34*/	{ "sysenter",FALSE,NONE,  0,	      0 },
279181606Sjhb/*35*/	{ "sysexit",FALSE,NONE,  0,	      0 },
28014887Swollman/*36*/	{ "",	   FALSE, NONE,  0,	      0 },
281181606Sjhb/*37*/	{ "getsec",FALSE, NONE,  0,	      0 },
28214887Swollman
283238166Sjhb/*38*/	{ "",	   FALSE, ESC,  0,	      db_inst_0f38 },
28414887Swollman/*39*/	{ "",	   FALSE, NONE,  0,	      0 },
28514887Swollman/*3a*/	{ "",	   FALSE, NONE,  0,	      0 },
28614887Swollman/*3b*/	{ "",	   FALSE, NONE,  0,	      0 },
28714887Swollman/*3c*/	{ "",	   FALSE, NONE,  0,	      0 },
28814887Swollman/*3d*/	{ "",	   FALSE, NONE,  0,	      0 },
28914887Swollman/*3e*/	{ "",	   FALSE, NONE,  0,	      0 },
29014887Swollman/*3f*/	{ "",	   FALSE, NONE,  0,	      0 },
29114887Swollman};
29214887Swollman
293144354Speterstatic const struct inst db_inst_0f4x[] = {
294144354Speter/*40*/	{ "cmovo",  TRUE, NONE,  op2(E, R),   0 },
295144354Speter/*41*/	{ "cmovno", TRUE, NONE,  op2(E, R),   0 },
296144354Speter/*42*/	{ "cmovb",  TRUE, NONE,  op2(E, R),   0 },
297144354Speter/*43*/	{ "cmovnb", TRUE, NONE,  op2(E, R),   0 },
298144354Speter/*44*/	{ "cmovz",  TRUE, NONE,  op2(E, R),   0 },
299144354Speter/*45*/	{ "cmovnz", TRUE, NONE,  op2(E, R),   0 },
300144354Speter/*46*/	{ "cmovbe", TRUE, NONE,  op2(E, R),   0 },
301144354Speter/*47*/	{ "cmovnbe",TRUE, NONE,  op2(E, R),   0 },
302144354Speter
303144354Speter/*48*/	{ "cmovs",  TRUE, NONE,  op2(E, R),   0 },
304144354Speter/*49*/	{ "cmovns", TRUE, NONE,  op2(E, R),   0 },
305144354Speter/*4a*/	{ "cmovp",  TRUE, NONE,  op2(E, R),   0 },
306144354Speter/*4b*/	{ "cmovnp", TRUE, NONE,  op2(E, R),   0 },
307144354Speter/*4c*/	{ "cmovl",  TRUE, NONE,  op2(E, R),   0 },
308144354Speter/*4d*/	{ "cmovnl", TRUE, NONE,  op2(E, R),   0 },
309144354Speter/*4e*/	{ "cmovle", TRUE, NONE,  op2(E, R),   0 },
310144354Speter/*4f*/	{ "cmovnle",TRUE, NONE,  op2(E, R),   0 },
311144354Speter};
312144354Speter
313238166Sjhbstatic const struct inst db_inst_0f7x[] = {
314238166Sjhb/*70*/	{ "",	   FALSE, NONE,  0,	      0 },
315238166Sjhb/*71*/	{ "",	   FALSE, NONE,  0,	      0 },
316238166Sjhb/*72*/	{ "",	   FALSE, NONE,  0,	      0 },
317238166Sjhb/*73*/	{ "",	   FALSE, NONE,  0,	      0 },
318238166Sjhb/*74*/	{ "",	   FALSE, NONE,  0,	      0 },
319238166Sjhb/*75*/	{ "",	   FALSE, NONE,  0,	      0 },
320238166Sjhb/*76*/	{ "",	   FALSE, NONE,  0,	      0 },
321238166Sjhb/*77*/	{ "",	   FALSE, NONE,  0,	      0 },
322238166Sjhb
323238166Sjhb/*78*/	{ "vmread", TRUE, NONE,  op2(Rq, E),  0 },
324238166Sjhb/*79*/	{ "vmwrite",TRUE, NONE,  op2(E, Rq),  0 },
325238166Sjhb/*7a*/	{ "",	   FALSE, NONE,  0,	      0 },
326238166Sjhb/*7b*/	{ "",	   FALSE, NONE,  0,	      0 },
327238166Sjhb/*7c*/	{ "",	   FALSE, NONE,  0,	      0 },
328238166Sjhb/*7d*/	{ "",	   FALSE, NONE,  0,	      0 },
329238166Sjhb/*7e*/	{ "",	   FALSE, NONE,  0,	      0 },
330238166Sjhb/*7f*/	{ "",	   FALSE, NONE,  0,	      0 },
331238166Sjhb};
332238166Sjhb
33317109Sbdestatic const struct inst db_inst_0f8x[] = {
3344Srgrimes/*80*/	{ "jo",    FALSE, NONE,  op1(Dl),     0 },
3354Srgrimes/*81*/	{ "jno",   FALSE, NONE,  op1(Dl),     0 },
3364Srgrimes/*82*/	{ "jb",    FALSE, NONE,  op1(Dl),     0 },
3374Srgrimes/*83*/	{ "jnb",   FALSE, NONE,  op1(Dl),     0 },
3384Srgrimes/*84*/	{ "jz",    FALSE, NONE,  op1(Dl),     0 },
3394Srgrimes/*85*/	{ "jnz",   FALSE, NONE,  op1(Dl),     0 },
3404Srgrimes/*86*/	{ "jbe",   FALSE, NONE,  op1(Dl),     0 },
3414Srgrimes/*87*/	{ "jnbe",  FALSE, NONE,  op1(Dl),     0 },
3424Srgrimes
3434Srgrimes/*88*/	{ "js",    FALSE, NONE,  op1(Dl),     0 },
3444Srgrimes/*89*/	{ "jns",   FALSE, NONE,  op1(Dl),     0 },
3454Srgrimes/*8a*/	{ "jp",    FALSE, NONE,  op1(Dl),     0 },
3464Srgrimes/*8b*/	{ "jnp",   FALSE, NONE,  op1(Dl),     0 },
3474Srgrimes/*8c*/	{ "jl",    FALSE, NONE,  op1(Dl),     0 },
3484Srgrimes/*8d*/	{ "jnl",   FALSE, NONE,  op1(Dl),     0 },
3494Srgrimes/*8e*/	{ "jle",   FALSE, NONE,  op1(Dl),     0 },
3504Srgrimes/*8f*/	{ "jnle",  FALSE, NONE,  op1(Dl),     0 },
3514Srgrimes};
3524Srgrimes
35317109Sbdestatic const struct inst db_inst_0f9x[] = {
3544Srgrimes/*90*/	{ "seto",  TRUE,  NONE,  op1(Eb),     0 },
3554Srgrimes/*91*/	{ "setno", TRUE,  NONE,  op1(Eb),     0 },
3564Srgrimes/*92*/	{ "setb",  TRUE,  NONE,  op1(Eb),     0 },
3574Srgrimes/*93*/	{ "setnb", TRUE,  NONE,  op1(Eb),     0 },
3584Srgrimes/*94*/	{ "setz",  TRUE,  NONE,  op1(Eb),     0 },
3594Srgrimes/*95*/	{ "setnz", TRUE,  NONE,  op1(Eb),     0 },
3604Srgrimes/*96*/	{ "setbe", TRUE,  NONE,  op1(Eb),     0 },
3614Srgrimes/*97*/	{ "setnbe",TRUE,  NONE,  op1(Eb),     0 },
3624Srgrimes
3634Srgrimes/*98*/	{ "sets",  TRUE,  NONE,  op1(Eb),     0 },
3644Srgrimes/*99*/	{ "setns", TRUE,  NONE,  op1(Eb),     0 },
3654Srgrimes/*9a*/	{ "setp",  TRUE,  NONE,  op1(Eb),     0 },
3664Srgrimes/*9b*/	{ "setnp", TRUE,  NONE,  op1(Eb),     0 },
3674Srgrimes/*9c*/	{ "setl",  TRUE,  NONE,  op1(Eb),     0 },
3684Srgrimes/*9d*/	{ "setnl", TRUE,  NONE,  op1(Eb),     0 },
3694Srgrimes/*9e*/	{ "setle", TRUE,  NONE,  op1(Eb),     0 },
3704Srgrimes/*9f*/	{ "setnle",TRUE,  NONE,  op1(Eb),     0 },
3714Srgrimes};
3724Srgrimes
37317109Sbdestatic const struct inst db_inst_0fax[] = {
3744Srgrimes/*a0*/	{ "push",  FALSE, NONE,  op1(Si),     0 },
3754Srgrimes/*a1*/	{ "pop",   FALSE, NONE,  op1(Si),     0 },
37621277Sbde/*a2*/	{ "cpuid", FALSE, NONE,  0,	      0 },
37721277Sbde/*a3*/	{ "bt",    TRUE,  LONG,  op2(R,E),    0 },
37817109Sbde/*a4*/	{ "shld",  TRUE,  LONG,  op3(Ib,R,E), 0 },
37917109Sbde/*a5*/	{ "shld",  TRUE,  LONG,  op3(CL,R,E), 0 },
3804Srgrimes/*a6*/	{ "",      FALSE, NONE,  0,	      0 },
3814Srgrimes/*a7*/	{ "",      FALSE, NONE,  0,	      0 },
3824Srgrimes
3834Srgrimes/*a8*/	{ "push",  FALSE, NONE,  op1(Si),     0 },
3844Srgrimes/*a9*/	{ "pop",   FALSE, NONE,  op1(Si),     0 },
38521277Sbde/*aa*/	{ "rsm",   FALSE, NONE,  0,	      0 },
38621277Sbde/*ab*/	{ "bts",   TRUE,  LONG,  op2(R,E),    0 },
38717109Sbde/*ac*/	{ "shrd",  TRUE,  LONG,  op3(Ib,R,E), 0 },
38817109Sbde/*ad*/	{ "shrd",  TRUE,  LONG,  op3(CL,R,E), 0 },
389181606Sjhb/*ae*/	{ "",      TRUE,  LONG,  op1(E),      db_Grp15 },
390181606Sjhb/*af*/	{ "imul",  TRUE,  LONG,  op2(E,R),    0 },
3914Srgrimes};
3924Srgrimes
39317109Sbdestatic const struct inst db_inst_0fbx[] = {
39421277Sbde/*b0*/	{ "cmpxchg",TRUE, BYTE,	 op2(R, E),   0 },
39521277Sbde/*b0*/	{ "cmpxchg",TRUE, LONG,	 op2(R, E),   0 },
3964Srgrimes/*b2*/	{ "lss",   TRUE,  LONG,  op2(E, R),   0 },
39721277Sbde/*b3*/	{ "btr",   TRUE,  LONG,  op2(R, E),   0 },
3984Srgrimes/*b4*/	{ "lfs",   TRUE,  LONG,  op2(E, R),   0 },
3994Srgrimes/*b5*/	{ "lgs",   TRUE,  LONG,  op2(E, R),   0 },
40021277Sbde/*b6*/	{ "movzb", TRUE,  LONG,  op2(Eb, R),  0 },
40121277Sbde/*b7*/	{ "movzw", TRUE,  LONG,  op2(Ew, R),  0 },
4024Srgrimes
4034Srgrimes/*b8*/	{ "",      FALSE, NONE,  0,	      0 },
4044Srgrimes/*b9*/	{ "",      FALSE, NONE,  0,	      0 },
40517109Sbde/*ba*/	{ "",      TRUE,  LONG,  op2(Ib, E),  db_Grp8 },
4064Srgrimes/*bb*/	{ "btc",   TRUE,  LONG,  op2(R, E),   0 },
4074Srgrimes/*bc*/	{ "bsf",   TRUE,  LONG,  op2(E, R),   0 },
4084Srgrimes/*bd*/	{ "bsr",   TRUE,  LONG,  op2(E, R),   0 },
40921277Sbde/*be*/	{ "movsb", TRUE,  LONG,  op2(Eb, R),  0 },
41021277Sbde/*bf*/	{ "movsw", TRUE,  LONG,  op2(Ew, R),  0 },
4114Srgrimes};
4124Srgrimes
41317109Sbdestatic const struct inst db_inst_0fcx[] = {
4144Srgrimes/*c0*/	{ "xadd",  TRUE,  BYTE,	 op2(R, E),   0 },
4154Srgrimes/*c1*/	{ "xadd",  TRUE,  LONG,	 op2(R, E),   0 },
4164Srgrimes/*c2*/	{ "",	   FALSE, NONE,	 0,	      0 },
4174Srgrimes/*c3*/	{ "",	   FALSE, NONE,	 0,	      0 },
4184Srgrimes/*c4*/	{ "",	   FALSE, NONE,	 0,	      0 },
4194Srgrimes/*c5*/	{ "",	   FALSE, NONE,	 0,	      0 },
4204Srgrimes/*c6*/	{ "",	   FALSE, NONE,	 0,	      0 },
42121277Sbde/*c7*/	{ "",	   TRUE,  NONE,  op1(E),      db_Grp9 },
42221277Sbde/*c8*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
42321277Sbde/*c9*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
42421277Sbde/*ca*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
42521277Sbde/*cb*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
42621277Sbde/*cc*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
42721277Sbde/*cd*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
42821277Sbde/*ce*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
42921277Sbde/*cf*/	{ "bswap", FALSE, LONG,  op1(Ril),    0 },
4304Srgrimes};
4314Srgrimes
43214887Swollmanstatic const struct inst * const db_inst_0f[] = {
4334Srgrimes	db_inst_0f0x,
4344Srgrimes	0,
4354Srgrimes	db_inst_0f2x,
43614887Swollman	db_inst_0f3x,
437144354Speter	db_inst_0f4x,
4384Srgrimes	0,
4394Srgrimes	0,
440238166Sjhb	db_inst_0f7x,
4414Srgrimes	db_inst_0f8x,
4424Srgrimes	db_inst_0f9x,
4434Srgrimes	db_inst_0fax,
4444Srgrimes	db_inst_0fbx,
4454Srgrimes	db_inst_0fcx,
4464Srgrimes	0,
44721277Sbde	0,
4484Srgrimes	0
4494Srgrimes};
4504Srgrimes
45114887Swollmanstatic const char * const db_Esc92[] = {
4524Srgrimes	"fnop",	"",	"",	"",	"",	"",	"",	""
4534Srgrimes};
45414887Swollmanstatic const char * const db_Esc94[] = {
4554Srgrimes	"fchs",	"fabs",	"",	"",	"ftst",	"fxam",	"",	""
4564Srgrimes};
45717109Sbdestatic const char * const db_Esc95[] = {
4584Srgrimes	"fld1",	"fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
4594Srgrimes};
46017109Sbdestatic const char * const db_Esc96[] = {
4614Srgrimes	"f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
4624Srgrimes	"fincstp"
4634Srgrimes};
46414887Swollmanstatic const char * const db_Esc97[] = {
4654Srgrimes	"fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
4664Srgrimes};
4674Srgrimes
46821277Sbdestatic const char * const db_Esca5[] = {
4694Srgrimes	"",	"fucompp","",	"",	"",	"",	"",	""
4704Srgrimes};
4714Srgrimes
47217109Sbdestatic const char * const db_Escb4[] = {
47321277Sbde	"fneni","fndisi",	"fnclex","fninit","fsetpm",	"",	"",	""
4744Srgrimes};
4754Srgrimes
47614887Swollmanstatic const char * const db_Esce3[] = {
4774Srgrimes	"",	"fcompp","",	"",	"",	"",	"",	""
4784Srgrimes};
4794Srgrimes
48017109Sbdestatic const char * const db_Escf4[] = {
4814Srgrimes	"fnstsw","",	"",	"",	"",	"",	"",	""
4824Srgrimes};
4834Srgrimes
48414887Swollmanstatic const struct finst db_Esc8[] = {
4854Srgrimes/*0*/	{ "fadd",   SNGL,  op2(STI,ST),	0 },
4864Srgrimes/*1*/	{ "fmul",   SNGL,  op2(STI,ST),	0 },
4874Srgrimes/*2*/	{ "fcom",   SNGL,  op2(STI,ST),	0 },
4884Srgrimes/*3*/	{ "fcomp",  SNGL,  op2(STI,ST),	0 },
4894Srgrimes/*4*/	{ "fsub",   SNGL,  op2(STI,ST),	0 },
4904Srgrimes/*5*/	{ "fsubr",  SNGL,  op2(STI,ST),	0 },
4914Srgrimes/*6*/	{ "fdiv",   SNGL,  op2(STI,ST),	0 },
4924Srgrimes/*7*/	{ "fdivr",  SNGL,  op2(STI,ST),	0 },
4934Srgrimes};
4944Srgrimes
49514887Swollmanstatic const struct finst db_Esc9[] = {
4964Srgrimes/*0*/	{ "fld",    SNGL,  op1(STI),	0 },
4974Srgrimes/*1*/	{ "",       NONE,  op1(STI),	"fxch" },
49817109Sbde/*2*/	{ "fst",    SNGL,  op1(X),	db_Esc92 },
49921277Sbde/*3*/	{ "fstp",   SNGL,  0,		0 },
50017109Sbde/*4*/	{ "fldenv", NONE,  op1(X),	db_Esc94 },
50117109Sbde/*5*/	{ "fldcw",  NONE,  op1(X),	db_Esc95 },
50217109Sbde/*6*/	{ "fnstenv",NONE,  op1(X),	db_Esc96 },
50317109Sbde/*7*/	{ "fnstcw", NONE,  op1(X),	db_Esc97 },
5044Srgrimes};
5054Srgrimes
50614887Swollmanstatic const struct finst db_Esca[] = {
50721277Sbde/*0*/	{ "fiadd",  LONG,  0,		0 },
50821277Sbde/*1*/	{ "fimul",  LONG,  0,		0 },
50921277Sbde/*2*/	{ "ficom",  LONG,  0,		0 },
51021277Sbde/*3*/	{ "ficomp", LONG,  0,		0 },
51121277Sbde/*4*/	{ "fisub",  LONG,  0,		0 },
51221277Sbde/*5*/	{ "fisubr", LONG,  op1(X),	db_Esca5 },
51321277Sbde/*6*/	{ "fidiv",  LONG,  0,		0 },
51421277Sbde/*7*/	{ "fidivr", LONG,  0,		0 }
5154Srgrimes};
5164Srgrimes
51714887Swollmanstatic const struct finst db_Escb[] = {
51821277Sbde/*0*/	{ "fild",   LONG,  0,		0 },
5194Srgrimes/*1*/	{ "",       NONE,  0,		0 },
52021277Sbde/*2*/	{ "fist",   LONG,  0,		0 },
52121277Sbde/*3*/	{ "fistp",  LONG,  0,		0 },
52217109Sbde/*4*/	{ "",       WORD,  op1(X),	db_Escb4 },
5234Srgrimes/*5*/	{ "fld",    EXTR,  0,		0 },
5244Srgrimes/*6*/	{ "",       WORD,  0,		0 },
5254Srgrimes/*7*/	{ "fstp",   EXTR,  0,		0 },
5264Srgrimes};
5274Srgrimes
52814887Swollmanstatic const struct finst db_Escc[] = {
5294Srgrimes/*0*/	{ "fadd",   DBLR,  op2(ST,STI),	0 },
5304Srgrimes/*1*/	{ "fmul",   DBLR,  op2(ST,STI),	0 },
53121277Sbde/*2*/	{ "fcom",   DBLR,  0,		0 },
53221277Sbde/*3*/	{ "fcomp",  DBLR,  0,		0 },
5334Srgrimes/*4*/	{ "fsub",   DBLR,  op2(ST,STI),	"fsubr" },
5344Srgrimes/*5*/	{ "fsubr",  DBLR,  op2(ST,STI),	"fsub" },
5354Srgrimes/*6*/	{ "fdiv",   DBLR,  op2(ST,STI),	"fdivr" },
5364Srgrimes/*7*/	{ "fdivr",  DBLR,  op2(ST,STI),	"fdiv" },
5374Srgrimes};
5384Srgrimes
53914887Swollmanstatic const struct finst db_Escd[] = {
5404Srgrimes/*0*/	{ "fld",    DBLR,  op1(STI),	"ffree" },
5414Srgrimes/*1*/	{ "",       NONE,  0,		0 },
5424Srgrimes/*2*/	{ "fst",    DBLR,  op1(STI),	0 },
5434Srgrimes/*3*/	{ "fstp",   DBLR,  op1(STI),	0 },
5444Srgrimes/*4*/	{ "frstor", NONE,  op1(STI),	"fucom" },
5454Srgrimes/*5*/	{ "",       NONE,  op1(STI),	"fucomp" },
5464Srgrimes/*6*/	{ "fnsave", NONE,  0,		0 },
5474Srgrimes/*7*/	{ "fnstsw", NONE,  0,		0 },
5484Srgrimes};
5494Srgrimes
55014887Swollmanstatic const struct finst db_Esce[] = {
55121277Sbde/*0*/	{ "fiadd",  WORD,  op2(ST,STI),	"faddp" },
55221277Sbde/*1*/	{ "fimul",  WORD,  op2(ST,STI),	"fmulp" },
55321277Sbde/*2*/	{ "ficom",  WORD,  0,		0 },
55421277Sbde/*3*/	{ "ficomp", WORD,  op1(X),	db_Esce3 },
55521277Sbde/*4*/	{ "fisub",  WORD,  op2(ST,STI),	"fsubrp" },
55621277Sbde/*5*/	{ "fisubr", WORD,  op2(ST,STI),	"fsubp" },
55721277Sbde/*6*/	{ "fidiv",  WORD,  op2(ST,STI),	"fdivrp" },
55821277Sbde/*7*/	{ "fidivr", WORD,  op2(ST,STI),	"fdivp" },
5594Srgrimes};
5604Srgrimes
56114887Swollmanstatic const struct finst db_Escf[] = {
56221277Sbde/*0*/	{ "fild",   WORD,  0,		0 },
56321277Sbde/*1*/	{ "",       NONE,  0,		0 },
56421277Sbde/*2*/	{ "fist",   WORD,  0,		0 },
56521277Sbde/*3*/	{ "fistp",  WORD,  0,		0 },
56617109Sbde/*4*/	{ "fbld",   NONE,  op1(XA),	db_Escf4 },
56721277Sbde/*5*/	{ "fild",   QUAD,  0,		0 },
5684Srgrimes/*6*/	{ "fbstp",  NONE,  0,		0 },
56921277Sbde/*7*/	{ "fistp",  QUAD,  0,		0 },
5704Srgrimes};
5714Srgrimes
57217109Sbdestatic const struct finst * const db_Esc_inst[] = {
5734Srgrimes	db_Esc8, db_Esc9, db_Esca, db_Escb,
5744Srgrimes	db_Escc, db_Escd, db_Esce, db_Escf
5754Srgrimes};
5764Srgrimes
57714887Swollmanstatic const char * const db_Grp1[] = {
5784Srgrimes	"add",
5794Srgrimes	"or",
5804Srgrimes	"adc",
5814Srgrimes	"sbb",
5824Srgrimes	"and",
5834Srgrimes	"sub",
5844Srgrimes	"xor",
5854Srgrimes	"cmp"
5864Srgrimes};
5874Srgrimes
58814887Swollmanstatic const char * const db_Grp2[] = {
5894Srgrimes	"rol",
5904Srgrimes	"ror",
5914Srgrimes	"rcl",
5924Srgrimes	"rcr",
5934Srgrimes	"shl",
5944Srgrimes	"shr",
5954Srgrimes	"shl",
5964Srgrimes	"sar"
5974Srgrimes};
5984Srgrimes
59914887Swollmanstatic const struct inst db_Grp3[] = {
6004Srgrimes	{ "test",  TRUE, NONE, op2(I,E), 0 },
6014Srgrimes	{ "test",  TRUE, NONE, op2(I,E), 0 },
6024Srgrimes	{ "not",   TRUE, NONE, op1(E),   0 },
6034Srgrimes	{ "neg",   TRUE, NONE, op1(E),   0 },
6044Srgrimes	{ "mul",   TRUE, NONE, op2(E,A), 0 },
6054Srgrimes	{ "imul",  TRUE, NONE, op2(E,A), 0 },
6064Srgrimes	{ "div",   TRUE, NONE, op2(E,A), 0 },
6074Srgrimes	{ "idiv",  TRUE, NONE, op2(E,A), 0 },
6084Srgrimes};
6094Srgrimes
61017109Sbdestatic const struct inst db_Grp4[] = {
6114Srgrimes	{ "inc",   TRUE, BYTE, op1(E),   0 },
6124Srgrimes	{ "dec",   TRUE, BYTE, op1(E),   0 },
6134Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
6144Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
6154Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
6164Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
6174Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
6184Srgrimes	{ "",      TRUE, NONE, 0,	 0 }
6194Srgrimes};
6204Srgrimes
62117109Sbdestatic const struct inst db_Grp5[] = {
6224Srgrimes	{ "inc",   TRUE, LONG, op1(E),   0 },
6234Srgrimes	{ "dec",   TRUE, LONG, op1(E),   0 },
62421277Sbde	{ "call",  TRUE, LONG, op1(Eind),0 },
62521277Sbde	{ "lcall", TRUE, LONG, op1(Eind),0 },
62621277Sbde	{ "jmp",   TRUE, LONG, op1(Eind),0 },
62721277Sbde	{ "ljmp",  TRUE, LONG, op1(Eind),0 },
6284Srgrimes	{ "push",  TRUE, LONG, op1(E),   0 },
6294Srgrimes	{ "",      TRUE, NONE, 0,	 0 }
6304Srgrimes};
6314Srgrimes
632266354Sjhbstatic const struct inst db_Grp9b[] = {
633266354Sjhb	{ "",      TRUE, NONE, 0,	 0 },
634266354Sjhb	{ "",      TRUE, NONE, 0,	 0 },
635266354Sjhb	{ "",      TRUE, NONE, 0,	 0 },
636266354Sjhb	{ "",      TRUE, NONE, 0,	 0 },
637266354Sjhb	{ "",      TRUE, NONE, 0,	 0 },
638266354Sjhb	{ "",      TRUE, NONE, 0,	 0 },
639266354Sjhb	{ "rdrand",TRUE, LONG, op1(Rv),  0 },
640266354Sjhb	{ "rdseed",TRUE, LONG, op1(Rv),  0 }
641266354Sjhb};
642266354Sjhb
64314887Swollmanstatic const struct inst db_inst_table[256] = {
6444Srgrimes/*00*/	{ "add",   TRUE,  BYTE,  op2(R, E),  0 },
6454Srgrimes/*01*/	{ "add",   TRUE,  LONG,  op2(R, E),  0 },
6464Srgrimes/*02*/	{ "add",   TRUE,  BYTE,  op2(E, R),  0 },
6474Srgrimes/*03*/	{ "add",   TRUE,  LONG,  op2(E, R),  0 },
64821277Sbde/*04*/	{ "add",   FALSE, BYTE,  op2(I, A),  0 },
6494Srgrimes/*05*/	{ "add",   FALSE, LONG,  op2(Is, A), 0 },
6504Srgrimes/*06*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
6514Srgrimes/*07*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },
6524Srgrimes
6534Srgrimes/*08*/	{ "or",    TRUE,  BYTE,  op2(R, E),  0 },
6544Srgrimes/*09*/	{ "or",    TRUE,  LONG,  op2(R, E),  0 },
6554Srgrimes/*0a*/	{ "or",    TRUE,  BYTE,  op2(E, R),  0 },
6564Srgrimes/*0b*/	{ "or",    TRUE,  LONG,  op2(E, R),  0 },
6574Srgrimes/*0c*/	{ "or",    FALSE, BYTE,  op2(I, A),  0 },
6584Srgrimes/*0d*/	{ "or",    FALSE, LONG,  op2(I, A),  0 },
6594Srgrimes/*0e*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
660238166Sjhb/*0f*/	{ "",      FALSE, ESC,   0,	     db_inst_0f },
6614Srgrimes
6624Srgrimes/*10*/	{ "adc",   TRUE,  BYTE,  op2(R, E),  0 },
6634Srgrimes/*11*/	{ "adc",   TRUE,  LONG,  op2(R, E),  0 },
6644Srgrimes/*12*/	{ "adc",   TRUE,  BYTE,  op2(E, R),  0 },
6654Srgrimes/*13*/	{ "adc",   TRUE,  LONG,  op2(E, R),  0 },
66621277Sbde/*14*/	{ "adc",   FALSE, BYTE,  op2(I, A),  0 },
6674Srgrimes/*15*/	{ "adc",   FALSE, LONG,  op2(Is, A), 0 },
6684Srgrimes/*16*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
6694Srgrimes/*17*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },
6704Srgrimes
6714Srgrimes/*18*/	{ "sbb",   TRUE,  BYTE,  op2(R, E),  0 },
6724Srgrimes/*19*/	{ "sbb",   TRUE,  LONG,  op2(R, E),  0 },
6734Srgrimes/*1a*/	{ "sbb",   TRUE,  BYTE,  op2(E, R),  0 },
6744Srgrimes/*1b*/	{ "sbb",   TRUE,  LONG,  op2(E, R),  0 },
67521277Sbde/*1c*/	{ "sbb",   FALSE, BYTE,  op2(I, A),  0 },
6764Srgrimes/*1d*/	{ "sbb",   FALSE, LONG,  op2(Is, A), 0 },
6774Srgrimes/*1e*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
6784Srgrimes/*1f*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },
6794Srgrimes
6804Srgrimes/*20*/	{ "and",   TRUE,  BYTE,  op2(R, E),  0 },
6814Srgrimes/*21*/	{ "and",   TRUE,  LONG,  op2(R, E),  0 },
6824Srgrimes/*22*/	{ "and",   TRUE,  BYTE,  op2(E, R),  0 },
6834Srgrimes/*23*/	{ "and",   TRUE,  LONG,  op2(E, R),  0 },
6844Srgrimes/*24*/	{ "and",   FALSE, BYTE,  op2(I, A),  0 },
6854Srgrimes/*25*/	{ "and",   FALSE, LONG,  op2(I, A),  0 },
6864Srgrimes/*26*/	{ "",      FALSE, NONE,  0,	     0 },
68721277Sbde/*27*/	{ "daa",   FALSE, NONE,  0,	     0 },
6884Srgrimes
6894Srgrimes/*28*/	{ "sub",   TRUE,  BYTE,  op2(R, E),  0 },
6904Srgrimes/*29*/	{ "sub",   TRUE,  LONG,  op2(R, E),  0 },
6914Srgrimes/*2a*/	{ "sub",   TRUE,  BYTE,  op2(E, R),  0 },
6924Srgrimes/*2b*/	{ "sub",   TRUE,  LONG,  op2(E, R),  0 },
69321277Sbde/*2c*/	{ "sub",   FALSE, BYTE,  op2(I, A),  0 },
6944Srgrimes/*2d*/	{ "sub",   FALSE, LONG,  op2(Is, A), 0 },
6954Srgrimes/*2e*/	{ "",      FALSE, NONE,  0,	     0 },
6964Srgrimes/*2f*/	{ "das",   FALSE, NONE,  0,	     0 },
6974Srgrimes
6984Srgrimes/*30*/	{ "xor",   TRUE,  BYTE,  op2(R, E),  0 },
6994Srgrimes/*31*/	{ "xor",   TRUE,  LONG,  op2(R, E),  0 },
7004Srgrimes/*32*/	{ "xor",   TRUE,  BYTE,  op2(E, R),  0 },
7014Srgrimes/*33*/	{ "xor",   TRUE,  LONG,  op2(E, R),  0 },
7024Srgrimes/*34*/	{ "xor",   FALSE, BYTE,  op2(I, A),  0 },
7034Srgrimes/*35*/	{ "xor",   FALSE, LONG,  op2(I, A),  0 },
7044Srgrimes/*36*/	{ "",      FALSE, NONE,  0,	     0 },
70521277Sbde/*37*/	{ "aaa",   FALSE, NONE,  0,	     0 },
7064Srgrimes
7074Srgrimes/*38*/	{ "cmp",   TRUE,  BYTE,  op2(R, E),  0 },
7084Srgrimes/*39*/	{ "cmp",   TRUE,  LONG,  op2(R, E),  0 },
7094Srgrimes/*3a*/	{ "cmp",   TRUE,  BYTE,  op2(E, R),  0 },
7104Srgrimes/*3b*/	{ "cmp",   TRUE,  LONG,  op2(E, R),  0 },
71121277Sbde/*3c*/	{ "cmp",   FALSE, BYTE,  op2(I, A),  0 },
7124Srgrimes/*3d*/	{ "cmp",   FALSE, LONG,  op2(Is, A), 0 },
7134Srgrimes/*3e*/	{ "",      FALSE, NONE,  0,	     0 },
7144Srgrimes/*3f*/	{ "aas",   FALSE, NONE,  0,	     0 },
7154Srgrimes
716144353Speter/*40*/	{ "rex",   FALSE, NONE,  0,          0 },
717144353Speter/*41*/	{ "rex.b", FALSE, NONE,  0,          0 },
718144353Speter/*42*/	{ "rex.x", FALSE, NONE,  0,          0 },
719144353Speter/*43*/	{ "rex.xb", FALSE, NONE, 0,          0 },
720144353Speter/*44*/	{ "rex.r", FALSE, NONE,  0,          0 },
721144353Speter/*45*/	{ "rex.rb", FALSE, NONE, 0,          0 },
722144353Speter/*46*/	{ "rex.rx", FALSE, NONE, 0,          0 },
723144353Speter/*47*/	{ "rex.rxb", FALSE, NONE, 0,         0 },
7244Srgrimes
725144353Speter/*48*/	{ "rex.w", FALSE, NONE,  0,          0 },
726144353Speter/*49*/	{ "rex.wb", FALSE, NONE, 0,          0 },
727144353Speter/*4a*/	{ "rex.wx", FALSE, NONE, 0,          0 },
728144353Speter/*4b*/	{ "rex.wxb", FALSE, NONE, 0,         0 },
729144353Speter/*4c*/	{ "rex.wr", FALSE, NONE, 0,          0 },
730144353Speter/*4d*/	{ "rex.wrb", FALSE, NONE, 0,         0 },
731144353Speter/*4e*/	{ "rex.wrx", FALSE, NONE, 0,         0 },
732144353Speter/*4f*/	{ "rex.wrxb", FALSE, NONE, 0,        0 },
7334Srgrimes
7344Srgrimes/*50*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
7354Srgrimes/*51*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
7364Srgrimes/*52*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
7374Srgrimes/*53*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
7384Srgrimes/*54*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
7394Srgrimes/*55*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
7404Srgrimes/*56*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
7414Srgrimes/*57*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
7424Srgrimes
7434Srgrimes/*58*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
7444Srgrimes/*59*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
7454Srgrimes/*5a*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
7464Srgrimes/*5b*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
7474Srgrimes/*5c*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
7484Srgrimes/*5d*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
7494Srgrimes/*5e*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
7504Srgrimes/*5f*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
7514Srgrimes
7524Srgrimes/*60*/	{ "pusha", FALSE, LONG,  0,	     0 },
7534Srgrimes/*61*/	{ "popa",  FALSE, LONG,  0,	     0 },
7544Srgrimes/*62*/  { "bound", TRUE,  LONG,  op2(E, R),  0 },
755144354Speter/*63*/	{ "movslq",  TRUE,  NONE,  op2(EL,R), 0 },
7564Srgrimes
7574Srgrimes/*64*/	{ "",      FALSE, NONE,  0,	     0 },
7584Srgrimes/*65*/	{ "",      FALSE, NONE,  0,	     0 },
7594Srgrimes/*66*/	{ "",      FALSE, NONE,  0,	     0 },
7604Srgrimes/*67*/	{ "",      FALSE, NONE,  0,	     0 },
7614Srgrimes
7624Srgrimes/*68*/	{ "push",  FALSE, LONG,  op1(I),     0 },
7634Srgrimes/*69*/  { "imul",  TRUE,  LONG,  op3(I,E,R), 0 },
76421277Sbde/*6a*/	{ "push",  FALSE, LONG,  op1(Ibs),   0 },
7654Srgrimes/*6b*/  { "imul",  TRUE,  LONG,  op3(Ibs,E,R),0 },
7664Srgrimes/*6c*/	{ "ins",   FALSE, BYTE,  op2(DX, DI), 0 },
7674Srgrimes/*6d*/	{ "ins",   FALSE, LONG,  op2(DX, DI), 0 },
7684Srgrimes/*6e*/	{ "outs",  FALSE, BYTE,  op2(SI, DX), 0 },
7694Srgrimes/*6f*/	{ "outs",  FALSE, LONG,  op2(SI, DX), 0 },
7704Srgrimes
7714Srgrimes/*70*/	{ "jo",    FALSE, NONE,  op1(Db),     0 },
7724Srgrimes/*71*/	{ "jno",   FALSE, NONE,  op1(Db),     0 },
7734Srgrimes/*72*/	{ "jb",    FALSE, NONE,  op1(Db),     0 },
7744Srgrimes/*73*/	{ "jnb",   FALSE, NONE,  op1(Db),     0 },
7754Srgrimes/*74*/	{ "jz",    FALSE, NONE,  op1(Db),     0 },
7764Srgrimes/*75*/	{ "jnz",   FALSE, NONE,  op1(Db),     0 },
7774Srgrimes/*76*/	{ "jbe",   FALSE, NONE,  op1(Db),     0 },
7784Srgrimes/*77*/	{ "jnbe",  FALSE, NONE,  op1(Db),     0 },
7794Srgrimes
7804Srgrimes/*78*/	{ "js",    FALSE, NONE,  op1(Db),     0 },
7814Srgrimes/*79*/	{ "jns",   FALSE, NONE,  op1(Db),     0 },
7824Srgrimes/*7a*/	{ "jp",    FALSE, NONE,  op1(Db),     0 },
7834Srgrimes/*7b*/	{ "jnp",   FALSE, NONE,  op1(Db),     0 },
7844Srgrimes/*7c*/	{ "jl",    FALSE, NONE,  op1(Db),     0 },
7854Srgrimes/*7d*/	{ "jnl",   FALSE, NONE,  op1(Db),     0 },
7864Srgrimes/*7e*/	{ "jle",   FALSE, NONE,  op1(Db),     0 },
7874Srgrimes/*7f*/	{ "jnle",  FALSE, NONE,  op1(Db),     0 },
7884Srgrimes
78917109Sbde/*80*/  { "",	   TRUE,  BYTE,  op2(I, E),   db_Grp1 },
79017109Sbde/*81*/  { "",	   TRUE,  LONG,  op2(I, E),   db_Grp1 },
79121277Sbde/*82*/  { "",	   TRUE,  BYTE,  op2(I, E),   db_Grp1 },
79217109Sbde/*83*/  { "",	   TRUE,  LONG,  op2(Ibs,E),  db_Grp1 },
7934Srgrimes/*84*/	{ "test",  TRUE,  BYTE,  op2(R, E),   0 },
7944Srgrimes/*85*/	{ "test",  TRUE,  LONG,  op2(R, E),   0 },
7954Srgrimes/*86*/	{ "xchg",  TRUE,  BYTE,  op2(R, E),   0 },
7964Srgrimes/*87*/	{ "xchg",  TRUE,  LONG,  op2(R, E),   0 },
7974Srgrimes
7984Srgrimes/*88*/	{ "mov",   TRUE,  BYTE,  op2(R, E),   0 },
7994Srgrimes/*89*/	{ "mov",   TRUE,  LONG,  op2(R, E),   0 },
8004Srgrimes/*8a*/	{ "mov",   TRUE,  BYTE,  op2(E, R),   0 },
8014Srgrimes/*8b*/	{ "mov",   TRUE,  LONG,  op2(E, R),   0 },
8024Srgrimes/*8c*/  { "mov",   TRUE,  NONE,  op2(S, Ew),  0 },
8034Srgrimes/*8d*/	{ "lea",   TRUE,  LONG,  op2(E, R),   0 },
8044Srgrimes/*8e*/	{ "mov",   TRUE,  NONE,  op2(Ew, S),  0 },
8054Srgrimes/*8f*/	{ "pop",   TRUE,  LONG,  op1(E),      0 },
8064Srgrimes
8074Srgrimes/*90*/	{ "nop",   FALSE, NONE,  0,	      0 },
8084Srgrimes/*91*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
8094Srgrimes/*92*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
8104Srgrimes/*93*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
8114Srgrimes/*94*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
8124Srgrimes/*95*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
8134Srgrimes/*96*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
8144Srgrimes/*97*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
8154Srgrimes
816238166Sjhb/*98*/	{ "cwde",  FALSE, SDEP,  0,	      "cbw" },
817238166Sjhb/*99*/	{ "cdq",   FALSE, SDEP,  0,	      "cwd" },
8184Srgrimes/*9a*/	{ "lcall", FALSE, NONE,  op1(OS),     0 },
8194Srgrimes/*9b*/	{ "wait",  FALSE, NONE,  0,	      0 },
8204Srgrimes/*9c*/	{ "pushf", FALSE, LONG,  0,	      0 },
8214Srgrimes/*9d*/	{ "popf",  FALSE, LONG,  0,	      0 },
8224Srgrimes/*9e*/	{ "sahf",  FALSE, NONE,  0,	      0 },
8234Srgrimes/*9f*/	{ "lahf",  FALSE, NONE,  0,	      0 },
8244Srgrimes
8254Srgrimes/*a0*/	{ "mov",   FALSE, BYTE,  op2(O, A),   0 },
8264Srgrimes/*a1*/	{ "mov",   FALSE, LONG,  op2(O, A),   0 },
8274Srgrimes/*a2*/	{ "mov",   FALSE, BYTE,  op2(A, O),   0 },
8284Srgrimes/*a3*/	{ "mov",   FALSE, LONG,  op2(A, O),   0 },
8294Srgrimes/*a4*/	{ "movs",  FALSE, BYTE,  op2(SI,DI),  0 },
8304Srgrimes/*a5*/	{ "movs",  FALSE, LONG,  op2(SI,DI),  0 },
8314Srgrimes/*a6*/	{ "cmps",  FALSE, BYTE,  op2(SI,DI),  0 },
8324Srgrimes/*a7*/	{ "cmps",  FALSE, LONG,  op2(SI,DI),  0 },
8334Srgrimes
8344Srgrimes/*a8*/	{ "test",  FALSE, BYTE,  op2(I, A),   0 },
8354Srgrimes/*a9*/	{ "test",  FALSE, LONG,  op2(I, A),   0 },
8364Srgrimes/*aa*/	{ "stos",  FALSE, BYTE,  op1(DI),     0 },
8374Srgrimes/*ab*/	{ "stos",  FALSE, LONG,  op1(DI),     0 },
838118Srgrimes/*ac*/	{ "lods",  FALSE, BYTE,  op1(SI),     0 },
839118Srgrimes/*ad*/	{ "lods",  FALSE, LONG,  op1(SI),     0 },
8404Srgrimes/*ae*/	{ "scas",  FALSE, BYTE,  op1(SI),     0 },
8414Srgrimes/*af*/	{ "scas",  FALSE, LONG,  op1(SI),     0 },
8424Srgrimes
8434Srgrimes/*b0*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
8444Srgrimes/*b1*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
8454Srgrimes/*b2*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
8464Srgrimes/*b3*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
8474Srgrimes/*b4*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
8484Srgrimes/*b5*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
8494Srgrimes/*b6*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
8504Srgrimes/*b7*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
8514Srgrimes
852164263Sjhb/*b8*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
853164263Sjhb/*b9*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
854164263Sjhb/*ba*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
855164263Sjhb/*bb*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
856164263Sjhb/*bc*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
857164263Sjhb/*bd*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
858164263Sjhb/*be*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
859164263Sjhb/*bf*/	{ "mov",   FALSE, LONG,  op2(Ilq, Ri),  0 },
8604Srgrimes
86117109Sbde/*c0*/	{ "",	   TRUE,  BYTE,  op2(Ib, E),  db_Grp2 },
86217109Sbde/*c1*/	{ "",	   TRUE,  LONG,  op2(Ib, E),  db_Grp2 },
8634Srgrimes/*c2*/	{ "ret",   FALSE, NONE,  op1(Iw),     0 },
8644Srgrimes/*c3*/	{ "ret",   FALSE, NONE,  0,	      0 },
8654Srgrimes/*c4*/	{ "les",   TRUE,  LONG,  op2(E, R),   0 },
8664Srgrimes/*c5*/	{ "lds",   TRUE,  LONG,  op2(E, R),   0 },
8674Srgrimes/*c6*/	{ "mov",   TRUE,  BYTE,  op2(I, E),   0 },
8684Srgrimes/*c7*/	{ "mov",   TRUE,  LONG,  op2(I, E),   0 },
8694Srgrimes
87021277Sbde/*c8*/	{ "enter", FALSE, NONE,  op2(Iw, Ib), 0 },
8714Srgrimes/*c9*/	{ "leave", FALSE, NONE,  0,           0 },
8724Srgrimes/*ca*/	{ "lret",  FALSE, NONE,  op1(Iw),     0 },
8734Srgrimes/*cb*/	{ "lret",  FALSE, NONE,  0,	      0 },
8744Srgrimes/*cc*/	{ "int",   FALSE, NONE,  op1(o3),     0 },
8754Srgrimes/*cd*/	{ "int",   FALSE, NONE,  op1(Ib),     0 },
8764Srgrimes/*ce*/	{ "into",  FALSE, NONE,  0,	      0 },
8774Srgrimes/*cf*/	{ "iret",  FALSE, NONE,  0,	      0 },
8784Srgrimes
87917109Sbde/*d0*/	{ "",	   TRUE,  BYTE,  op2(o1, E),  db_Grp2 },
88017109Sbde/*d1*/	{ "",	   TRUE,  LONG,  op2(o1, E),  db_Grp2 },
88117109Sbde/*d2*/	{ "",	   TRUE,  BYTE,  op2(CL, E),  db_Grp2 },
88217109Sbde/*d3*/	{ "",	   TRUE,  LONG,  op2(CL, E),  db_Grp2 },
88321277Sbde/*d4*/	{ "aam",   FALSE, NONE,  op1(Iba),    0 },
88421277Sbde/*d5*/	{ "aad",   FALSE, NONE,  op1(Iba),    0 },
88521277Sbde/*d6*/	{ ".byte\t0xd6", FALSE, NONE, 0,      0 },
8864Srgrimes/*d7*/	{ "xlat",  FALSE, BYTE,  op1(BX),     0 },
8874Srgrimes
88817109Sbde/*d8*/  { "",      TRUE,  NONE,  0,	      db_Esc8 },
88917109Sbde/*d9*/  { "",      TRUE,  NONE,  0,	      db_Esc9 },
89017109Sbde/*da*/  { "",      TRUE,  NONE,  0,	      db_Esca },
89117109Sbde/*db*/  { "",      TRUE,  NONE,  0,	      db_Escb },
89217109Sbde/*dc*/  { "",      TRUE,  NONE,  0,	      db_Escc },
89317109Sbde/*dd*/  { "",      TRUE,  NONE,  0,	      db_Escd },
89417109Sbde/*de*/  { "",      TRUE,  NONE,  0,	      db_Esce },
89517109Sbde/*df*/  { "",      TRUE,  NONE,  0,	      db_Escf },
8964Srgrimes
8974Srgrimes/*e0*/	{ "loopne",FALSE, NONE,  op1(Db),     0 },
8984Srgrimes/*e1*/	{ "loope", FALSE, NONE,  op1(Db),     0 },
8994Srgrimes/*e2*/	{ "loop",  FALSE, NONE,  op1(Db),     0 },
900238166Sjhb/*e3*/	{ "jrcxz", FALSE, ADEP,  op1(Db),     "jecxz" },
9014Srgrimes/*e4*/	{ "in",    FALSE, BYTE,  op2(Ib, A),  0 },
9024Srgrimes/*e5*/	{ "in",    FALSE, LONG,  op2(Ib, A) , 0 },
9034Srgrimes/*e6*/	{ "out",   FALSE, BYTE,  op2(A, Ib),  0 },
9044Srgrimes/*e7*/	{ "out",   FALSE, LONG,  op2(A, Ib) , 0 },
9054Srgrimes
9064Srgrimes/*e8*/	{ "call",  FALSE, NONE,  op1(Dl),     0 },
9074Srgrimes/*e9*/	{ "jmp",   FALSE, NONE,  op1(Dl),     0 },
9084Srgrimes/*ea*/	{ "ljmp",  FALSE, NONE,  op1(OS),     0 },
9094Srgrimes/*eb*/	{ "jmp",   FALSE, NONE,  op1(Db),     0 },
9104Srgrimes/*ec*/	{ "in",    FALSE, BYTE,  op2(DX, A),  0 },
9114Srgrimes/*ed*/	{ "in",    FALSE, LONG,  op2(DX, A) , 0 },
9124Srgrimes/*ee*/	{ "out",   FALSE, BYTE,  op2(A, DX),  0 },
9134Srgrimes/*ef*/	{ "out",   FALSE, LONG,  op2(A, DX) , 0 },
9144Srgrimes
9154Srgrimes/*f0*/	{ "",      FALSE, NONE,  0,	     0 },
91621277Sbde/*f1*/	{ ".byte\t0xf1", FALSE, NONE, 0,     0 },
9174Srgrimes/*f2*/	{ "",      FALSE, NONE,  0,	     0 },
9184Srgrimes/*f3*/	{ "",      FALSE, NONE,  0,	     0 },
9194Srgrimes/*f4*/	{ "hlt",   FALSE, NONE,  0,	     0 },
9204Srgrimes/*f5*/	{ "cmc",   FALSE, NONE,  0,	     0 },
92117109Sbde/*f6*/	{ "",      TRUE,  BYTE,  0,	     db_Grp3 },
92217109Sbde/*f7*/	{ "",	   TRUE,  LONG,  0,	     db_Grp3 },
9234Srgrimes
9244Srgrimes/*f8*/	{ "clc",   FALSE, NONE,  0,	     0 },
9254Srgrimes/*f9*/	{ "stc",   FALSE, NONE,  0,	     0 },
9264Srgrimes/*fa*/	{ "cli",   FALSE, NONE,  0,	     0 },
9274Srgrimes/*fb*/	{ "sti",   FALSE, NONE,  0,	     0 },
9284Srgrimes/*fc*/	{ "cld",   FALSE, NONE,  0,	     0 },
9294Srgrimes/*fd*/	{ "std",   FALSE, NONE,  0,	     0 },
93017109Sbde/*fe*/	{ "",	   TRUE,  NONE,  0,	     db_Grp4 },
93117109Sbde/*ff*/	{ "",	   TRUE,  NONE,  0,	     db_Grp5 },
9324Srgrimes};
9334Srgrimes
93417109Sbdestatic const struct inst db_bad_inst =
9354Srgrimes	{ "???",   FALSE, NONE,  0,	      0 }
9364Srgrimes;
9374Srgrimes
938144353Speter#define	f_mod(rex, byte)	((byte)>>6)
939144353Speter#define	f_reg(rex, byte)	((((byte)>>3)&0x7) | (rex & REX_R ? 0x8 : 0x0))
940144353Speter#define	f_rm(rex, byte)		(((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0))
9414Srgrimes
942144353Speter#define	sib_ss(rex, byte)	((byte)>>6)
943144353Speter#define	sib_index(rex, byte)	((((byte)>>3)&0x7) | (rex & REX_X ? 0x8 : 0x0))
944144353Speter#define	sib_base(rex, byte)	(((byte)&0x7) | (rex & REX_B ? 0x8 : 0x0))
9454Srgrimes
94611940Sbdestruct i_addr {
9474Srgrimes	int		is_reg;	/* if reg, reg number is in 'disp' */
9484Srgrimes	int		disp;
94914887Swollman	const char *	base;
95014887Swollman	const char *	index;
9514Srgrimes	int		ss;
9524Srgrimes};
9534Srgrimes
954144353Speterstatic const char * const db_reg[2][4][16] = {
955144353Speter
956144353Speter	{{"%al",  "%cl",  "%dl",  "%bl",  "%ah",  "%ch",  "%dh",  "%bh",
957144353Speter	  "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" },
958144353Speter	{ "%ax",  "%cx",  "%dx",  "%bx",  "%sp",  "%bp",  "%si",  "%di",
959144353Speter	  "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" },
960144353Speter	{ "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
961144353Speter	  "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" },
962144353Speter	{ "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
963144353Speter	  "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }},
964144353Speter
965144353Speter	{{"%al",  "%cl",  "%dl",  "%bl",  "%spl",  "%bpl",  "%sil",  "%dil",
966144353Speter	  "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b" },
967144353Speter	{ "%ax",  "%cx",  "%dx",  "%bx",  "%sp",  "%bp",  "%si",  "%di",
968144353Speter	  "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w" },
969144353Speter	{ "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
970144353Speter	  "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d" },
971144353Speter	{ "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
972144353Speter	  "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" }}
9734Srgrimes};
9744Srgrimes
97517109Sbdestatic const char * const db_seg_reg[8] = {
9764Srgrimes	"%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
9774Srgrimes};
9784Srgrimes
9794Srgrimes/*
9804Srgrimes * lengths for size attributes
9814Srgrimes */
98214887Swollmanstatic const int db_lengths[] = {
9834Srgrimes	1,	/* BYTE */
9844Srgrimes	2,	/* WORD */
9854Srgrimes	4,	/* LONG */
9864Srgrimes	8,	/* QUAD */
9874Srgrimes	4,	/* SNGL */
9884Srgrimes	8,	/* DBLR */
9894Srgrimes	10,	/* EXTR */
9904Srgrimes};
9914Srgrimes
9924Srgrimes#define	get_value_inc(result, loc, size, is_signed) \
9934Srgrimes	result = db_get_value((loc), (size), (is_signed)); \
9944Srgrimes	(loc) += (size);
9954Srgrimes
99611940Sbdestatic db_addr_t
997144353Speter		db_disasm_esc(db_addr_t loc, int inst, int rex, int short_addr,
99893017Sbde		    int size, const char *seg);
999144353Speterstatic void	db_print_address(const char *seg, int size, int rex,
100093017Sbde		    struct i_addr *addrp);
100111940Sbdestatic db_addr_t
1002144353Speter		db_read_address(db_addr_t loc, int short_addr, int rex, int regmodrm,
100393017Sbde		    struct i_addr *addrp);
100411940Sbde
10054Srgrimes/*
10064Srgrimes * Read address at location and return updated location.
10074Srgrimes */
100811921Sphkstatic db_addr_t
1009144353Speterdb_read_address(loc, short_addr, rex, regmodrm, addrp)
10104Srgrimes	db_addr_t	loc;
10114Srgrimes	int		short_addr;
1012144353Speter	int		rex;
10134Srgrimes	int		regmodrm;
101417109Sbde	struct i_addr *	addrp;		/* out */
10154Srgrimes{
1016164263Sjhb	int		mod, rm, sib, index, disp, size, have_sib;
10174Srgrimes
1018144353Speter	mod = f_mod(rex, regmodrm);
1019144353Speter	rm  = f_rm(rex, regmodrm);
10204Srgrimes
10214Srgrimes	if (mod == 3) {
10224Srgrimes	    addrp->is_reg = TRUE;
10234Srgrimes	    addrp->disp = rm;
10244Srgrimes	    return (loc);
10254Srgrimes	}
10264Srgrimes	addrp->is_reg = FALSE;
10274Srgrimes	addrp->index = 0;
10284Srgrimes
1029164263Sjhb	if (short_addr)
1030164263Sjhb	    size = LONG;
1031164263Sjhb	else
1032164263Sjhb	    size = QUAD;
10334Srgrimes
1034164263Sjhb	if ((rm & 0x7) == 4) {
1035164263Sjhb	    get_value_inc(sib, loc, 1, FALSE);
1036164263Sjhb	    rm = sib_base(rex, sib);
1037164263Sjhb	    index = sib_index(rex, sib);
1038164263Sjhb	    if (index != 4)
1039164263Sjhb		addrp->index = db_reg[1][size][index];
1040164263Sjhb	    addrp->ss = sib_ss(rex, sib);
1041164263Sjhb	    have_sib = 1;
1042164263Sjhb	} else
1043164263Sjhb	    have_sib = 0;
1044164263Sjhb
1045164263Sjhb	switch (mod) {
1046164263Sjhb	    case 0:
1047164263Sjhb		if (rm == 5) {
1048164263Sjhb		    get_value_inc(addrp->disp, loc, 4, FALSE);
1049164263Sjhb		    if (have_sib)
10504Srgrimes			addrp->base = 0;
1051164263Sjhb		    else if (short_addr)
1052164263Sjhb			addrp->base = "%eip";
1053164263Sjhb		    else
1054164263Sjhb			addrp->base = "%rip";
1055164263Sjhb		} else {
1056164263Sjhb		    addrp->disp = 0;
1057164263Sjhb		    addrp->base = db_reg[1][size][rm];
1058164263Sjhb		}
1059164263Sjhb		break;
10604Srgrimes
1061164263Sjhb	    case 1:
1062164263Sjhb		get_value_inc(disp, loc, 1, TRUE);
1063164263Sjhb		addrp->disp = disp;
1064164263Sjhb		addrp->base = db_reg[1][size][rm];
1065164263Sjhb		break;
10664Srgrimes
1067164263Sjhb	    case 2:
1068164263Sjhb		get_value_inc(disp, loc, 4, FALSE);
1069164263Sjhb		addrp->disp = disp;
1070164263Sjhb		addrp->base = db_reg[1][size][rm];
1071164263Sjhb		break;
10724Srgrimes	}
10734Srgrimes	return (loc);
10744Srgrimes}
10754Srgrimes
107611921Sphkstatic void
1077144353Speterdb_print_address(seg, size, rex, addrp)
107817109Sbde	const char *	seg;
10794Srgrimes	int		size;
1080144353Speter	int		rex;
108117109Sbde	struct i_addr *	addrp;
10824Srgrimes{
10834Srgrimes	if (addrp->is_reg) {
1084144354Speter	    db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][addrp->disp]);
10854Srgrimes	    return;
10864Srgrimes	}
10874Srgrimes
10884Srgrimes	if (seg) {
10894Srgrimes	    db_printf("%s:", seg);
10904Srgrimes	}
10914Srgrimes
1092164263Sjhb	if (addrp->disp != 0 || (addrp->base == 0 && addrp->index == 0))
1093164263Sjhb		db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY);
10944Srgrimes	if (addrp->base != 0 || addrp->index != 0) {
10954Srgrimes	    db_printf("(");
10964Srgrimes	    if (addrp->base)
10974Srgrimes		db_printf("%s", addrp->base);
10984Srgrimes	    if (addrp->index)
10994Srgrimes		db_printf(",%s,%d", addrp->index, 1<<addrp->ss);
11004Srgrimes	    db_printf(")");
11014Srgrimes	}
11024Srgrimes}
11034Srgrimes
11044Srgrimes/*
11054Srgrimes * Disassemble floating-point ("escape") instruction
11064Srgrimes * and return updated location.
11074Srgrimes */
110811921Sphkstatic db_addr_t
1109144353Speterdb_disasm_esc(loc, inst, rex, short_addr, size, seg)
11104Srgrimes	db_addr_t	loc;
11114Srgrimes	int		inst;
1112144353Speter	int		rex;
11134Srgrimes	int		short_addr;
11144Srgrimes	int		size;
111517109Sbde	const char *	seg;
11164Srgrimes{
11174Srgrimes	int		regmodrm;
111817109Sbde	const struct finst *	fp;
11194Srgrimes	int		mod;
11204Srgrimes	struct i_addr	address;
112117109Sbde	const char *	name;
11224Srgrimes
11234Srgrimes	get_value_inc(regmodrm, loc, 1, FALSE);
1124144353Speter	fp = &db_Esc_inst[inst - 0xd8][f_reg(rex, regmodrm)];
1125144353Speter	mod = f_mod(rex, regmodrm);
11264Srgrimes	if (mod != 3) {
112721277Sbde	    if (*fp->f_name == '\0') {
112821277Sbde		db_printf("<bad instruction>");
112921277Sbde		return (loc);
113021277Sbde	    }
11314Srgrimes	    /*
11324Srgrimes	     * Normal address modes.
11334Srgrimes	     */
1134144353Speter	    loc = db_read_address(loc, short_addr, rex, regmodrm, &address);
113579885Skris	    db_printf("%s", fp->f_name);
11364Srgrimes	    switch(fp->f_size) {
11374Srgrimes		case SNGL:
11384Srgrimes		    db_printf("s");
11394Srgrimes		    break;
11404Srgrimes		case DBLR:
11414Srgrimes		    db_printf("l");
11424Srgrimes		    break;
11434Srgrimes		case EXTR:
11444Srgrimes		    db_printf("t");
11454Srgrimes		    break;
11464Srgrimes		case WORD:
11474Srgrimes		    db_printf("s");
11484Srgrimes		    break;
11494Srgrimes		case LONG:
11504Srgrimes		    db_printf("l");
11514Srgrimes		    break;
11524Srgrimes		case QUAD:
11534Srgrimes		    db_printf("q");
11544Srgrimes		    break;
11554Srgrimes		default:
11564Srgrimes		    break;
11574Srgrimes	    }
11584Srgrimes	    db_printf("\t");
1159144353Speter	    db_print_address(seg, BYTE, rex, &address);
11604Srgrimes	}
11614Srgrimes	else {
11624Srgrimes	    /*
11634Srgrimes	     * 'reg-reg' - special formats
11644Srgrimes	     */
11654Srgrimes	    switch (fp->f_rrmode) {
11664Srgrimes		case op2(ST,STI):
11674Srgrimes		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1168144353Speter		    db_printf("%s\t%%st,%%st(%d)",name,f_rm(rex, regmodrm));
11694Srgrimes		    break;
11704Srgrimes		case op2(STI,ST):
11714Srgrimes		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1172144353Speter		    db_printf("%s\t%%st(%d),%%st",name, f_rm(rex, regmodrm));
11734Srgrimes		    break;
11744Srgrimes		case op1(STI):
11754Srgrimes		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1176144353Speter		    db_printf("%s\t%%st(%d)",name, f_rm(rex, regmodrm));
11774Srgrimes		    break;
11784Srgrimes		case op1(X):
1179144353Speter		    name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)];
118021277Sbde		    if (*name == '\0')
118121277Sbde			goto bad;
118221277Sbde		    db_printf("%s", name);
11834Srgrimes		    break;
11844Srgrimes		case op1(XA):
1185144353Speter		    name = ((const char * const *)fp->f_rrname)[f_rm(rex, regmodrm)];
118621277Sbde		    if (*name == '\0')
118721277Sbde			goto bad;
118821277Sbde		    db_printf("%s\t%%ax", name);
11894Srgrimes		    break;
11904Srgrimes		default:
119121277Sbde		bad:
11924Srgrimes		    db_printf("<bad instruction>");
11934Srgrimes		    break;
11944Srgrimes	    }
11954Srgrimes	}
11964Srgrimes
11974Srgrimes	return (loc);
11984Srgrimes}
11994Srgrimes
12004Srgrimes/*
12014Srgrimes * Disassemble instruction at 'loc'.  'altfmt' specifies an
12024Srgrimes * (optional) alternate format.  Return address of start of
12034Srgrimes * next instruction.
12044Srgrimes */
12054Srgrimesdb_addr_t
12064Srgrimesdb_disasm(loc, altfmt)
12074Srgrimes	db_addr_t	loc;
12084Srgrimes	boolean_t	altfmt;
12094Srgrimes{
12104Srgrimes	int	inst;
12114Srgrimes	int	size;
12124Srgrimes	int	short_addr;
121317109Sbde	const char *	seg;
121414887Swollman	const struct inst *	ip;
121514887Swollman	const char *	i_name;
12164Srgrimes	int	i_size;
12174Srgrimes	int	i_mode;
1218144353Speter	int	rex = 0;
1219798Swollman	int	regmodrm = 0;
12204Srgrimes	boolean_t	first;
12214Srgrimes	int	displ;
12224Srgrimes	int	prefix;
1223181606Sjhb	int	rep;
12244Srgrimes	int	imm;
12254Srgrimes	int	imm2;
1226164263Sjhb	long	imm64;
12274Srgrimes	int	len;
12284Srgrimes	struct i_addr	address;
12294Srgrimes
12304Srgrimes	get_value_inc(inst, loc, 1, FALSE);
12314Srgrimes	short_addr = FALSE;
12324Srgrimes	size = LONG;
12334Srgrimes	seg = 0;
12344Srgrimes
12354Srgrimes	/*
12364Srgrimes	 * Get prefixes
12374Srgrimes	 */
1238181606Sjhb	rep = FALSE;
12394Srgrimes	prefix = TRUE;
12404Srgrimes	do {
12414Srgrimes	    switch (inst) {
12424Srgrimes		case 0x66:		/* data16 */
12434Srgrimes		    size = WORD;
12444Srgrimes		    break;
12454Srgrimes		case 0x67:
12464Srgrimes		    short_addr = TRUE;
12474Srgrimes		    break;
12484Srgrimes		case 0x26:
12494Srgrimes		    seg = "%es";
12504Srgrimes		    break;
12514Srgrimes		case 0x36:
12524Srgrimes		    seg = "%ss";
12534Srgrimes		    break;
12544Srgrimes		case 0x2e:
12554Srgrimes		    seg = "%cs";
12564Srgrimes		    break;
12574Srgrimes		case 0x3e:
12584Srgrimes		    seg = "%ds";
12594Srgrimes		    break;
12604Srgrimes		case 0x64:
12614Srgrimes		    seg = "%fs";
12624Srgrimes		    break;
12634Srgrimes		case 0x65:
12644Srgrimes		    seg = "%gs";
12654Srgrimes		    break;
12664Srgrimes		case 0xf0:
12674Srgrimes		    db_printf("lock ");
12684Srgrimes		    break;
12694Srgrimes		case 0xf2:
12704Srgrimes		    db_printf("repne ");
12714Srgrimes		    break;
12724Srgrimes		case 0xf3:
1273181606Sjhb		    rep = TRUE;
12744Srgrimes		    break;
12754Srgrimes		default:
12764Srgrimes		    prefix = FALSE;
12774Srgrimes		    break;
12784Srgrimes	    }
1279144353Speter	    if (inst >= 0x40 && inst < 0x50) {
1280144353Speter		rex = inst;
1281144353Speter		prefix = TRUE;
1282144353Speter	    }
12834Srgrimes	    if (prefix) {
12844Srgrimes		get_value_inc(inst, loc, 1, FALSE);
12854Srgrimes	    }
12864Srgrimes	} while (prefix);
12874Srgrimes
12884Srgrimes	if (inst >= 0xd8 && inst <= 0xdf) {
1289144353Speter	    loc = db_disasm_esc(loc, inst, rex, short_addr, size, seg);
12904Srgrimes	    db_printf("\n");
12914Srgrimes	    return (loc);
12924Srgrimes	}
12934Srgrimes
1294238166Sjhb	ip = &db_inst_table[inst];
1295238166Sjhb	while (ip->i_size == ESC) {
12964Srgrimes	    get_value_inc(inst, loc, 1, FALSE);
1297238166Sjhb	    ip = ((const struct inst * const *)ip->i_extra)[inst>>4];
12984Srgrimes	    if (ip == 0) {
12994Srgrimes		ip = &db_bad_inst;
13004Srgrimes	    }
13014Srgrimes	    else {
13024Srgrimes		ip = &ip[inst&0xf];
13034Srgrimes	    }
13044Srgrimes	}
13054Srgrimes
13064Srgrimes	if (ip->i_has_modrm) {
13074Srgrimes	    get_value_inc(regmodrm, loc, 1, FALSE);
1308144353Speter	    loc = db_read_address(loc, short_addr, rex, regmodrm, &address);
13094Srgrimes	}
13104Srgrimes
13114Srgrimes	i_name = ip->i_name;
13124Srgrimes	i_size = ip->i_size;
13134Srgrimes	i_mode = ip->i_mode;
13144Srgrimes
1315266354Sjhb	if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) == 3) {
1316266354Sjhb	    ip = &db_Grp9b[f_reg(rex, regmodrm)];
1317266354Sjhb	    i_name = ip->i_name;
1318266354Sjhb	    i_size = ip->i_size;
1319266354Sjhb	    i_mode = ip->i_mode;
1320266354Sjhb	}
1321266354Sjhb	else if (ip->i_extra == db_Grp1 || ip->i_extra == db_Grp2 ||
132217109Sbde	    ip->i_extra == db_Grp6 || ip->i_extra == db_Grp7 ||
1323181606Sjhb	    ip->i_extra == db_Grp8 || ip->i_extra == db_Grp9 ||
1324181606Sjhb	    ip->i_extra == db_Grp15) {
1325144353Speter	    i_name = ((const char * const *)ip->i_extra)[f_reg(rex, regmodrm)];
13264Srgrimes	}
132717109Sbde	else if (ip->i_extra == db_Grp3) {
132817109Sbde	    ip = ip->i_extra;
1329144353Speter	    ip = &ip[f_reg(rex, regmodrm)];
13304Srgrimes	    i_name = ip->i_name;
13314Srgrimes	    i_mode = ip->i_mode;
13324Srgrimes	}
133317109Sbde	else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) {
133417109Sbde	    ip = ip->i_extra;
1335144353Speter	    ip = &ip[f_reg(rex, regmodrm)];
13364Srgrimes	    i_name = ip->i_name;
13374Srgrimes	    i_mode = ip->i_mode;
13384Srgrimes	    i_size = ip->i_size;
13394Srgrimes	}
13404Srgrimes
1341181606Sjhb	/* Special cases that don't fit well in the tables. */
1342181606Sjhb	if (ip->i_extra == db_Grp7 && f_mod(rex, regmodrm) == 3) {
1343181606Sjhb		switch (regmodrm) {
1344238166Sjhb		case 0xc1:
1345238166Sjhb			i_name = "vmcall";
1346238166Sjhb			i_size = NONE;
1347238166Sjhb			i_mode = 0;
1348238166Sjhb			break;
1349238166Sjhb		case 0xc2:
1350238166Sjhb			i_name = "vmlaunch";
1351238166Sjhb			i_size = NONE;
1352238166Sjhb			i_mode = 0;
1353238166Sjhb			break;
1354238166Sjhb		case 0xc3:
1355238166Sjhb			i_name = "vmresume";
1356238166Sjhb			i_size = NONE;
1357238166Sjhb			i_mode = 0;
1358238166Sjhb			break;
1359238166Sjhb		case 0xc4:
1360238166Sjhb			i_name = "vmxoff";
1361238166Sjhb			i_size = NONE;
1362238166Sjhb			i_mode = 0;
1363238166Sjhb			break;
1364181606Sjhb		case 0xc8:
1365181606Sjhb			i_name = "monitor";
1366181606Sjhb			i_size = NONE;
1367181606Sjhb			i_mode = 0;
1368181606Sjhb			break;
1369181606Sjhb		case 0xc9:
1370181606Sjhb			i_name = "mwait";
1371181606Sjhb			i_size = NONE;
1372181606Sjhb			i_mode = 0;
1373181606Sjhb			break;
1374261213Sjhb		case 0xca:
1375261213Sjhb			i_name = "clac";
1376261213Sjhb			i_size = NONE;
1377261213Sjhb			i_mode = 0;
1378261213Sjhb			break;
1379261213Sjhb		case 0xcb:
1380261213Sjhb			i_name = "stac";
1381261213Sjhb			i_size = NONE;
1382261213Sjhb			i_mode = 0;
1383261213Sjhb			break;
1384238109Sjhb		case 0xd0:
1385238109Sjhb			i_name = "xgetbv";
1386238109Sjhb			i_size = NONE;
1387238109Sjhb			i_mode = 0;
1388238109Sjhb			break;
1389238109Sjhb		case 0xd1:
1390238109Sjhb			i_name = "xsetbv";
1391238109Sjhb			i_size = NONE;
1392238109Sjhb			i_mode = 0;
1393238109Sjhb			break;
1394266449Sjhb		case 0xd8:
1395266449Sjhb			i_name = "vmrun";
1396266449Sjhb			i_size = NONE;
1397266449Sjhb			i_mode = 0;
1398266449Sjhb			break;
1399266449Sjhb		case 0xd9:
1400266449Sjhb			i_name = "vmmcall";
1401266449Sjhb			i_size = NONE;
1402266449Sjhb			i_mode = 0;
1403266449Sjhb			break;
1404266449Sjhb		case 0xda:
1405266449Sjhb			i_name = "vmload";
1406266449Sjhb			i_size = NONE;
1407266449Sjhb			i_mode = 0;
1408266449Sjhb			break;
1409266449Sjhb		case 0xdb:
1410266449Sjhb			i_name = "vmsave";
1411266449Sjhb			i_size = NONE;
1412266449Sjhb			i_mode = 0;
1413266449Sjhb			break;
1414266449Sjhb		case 0xdc:
1415266449Sjhb			i_name = "stgi";
1416266449Sjhb			i_size = NONE;
1417266449Sjhb			i_mode = 0;
1418266449Sjhb			break;
1419266449Sjhb		case 0xdd:
1420266449Sjhb			i_name = "clgi";
1421266449Sjhb			i_size = NONE;
1422266449Sjhb			i_mode = 0;
1423266449Sjhb			break;
1424266449Sjhb		case 0xde:
1425266449Sjhb			i_name = "skinit";
1426266449Sjhb			i_size = NONE;
1427266449Sjhb			i_mode = 0;
1428266449Sjhb			break;
1429266449Sjhb		case 0xdf:
1430266449Sjhb			i_name = "invlpga";
1431266449Sjhb			i_size = NONE;
1432266449Sjhb			i_mode = 0;
1433266449Sjhb			break;
1434181606Sjhb		case 0xf8:
1435181606Sjhb			i_name = "swapgs";
1436181606Sjhb			i_size = NONE;
1437181606Sjhb			i_mode = 0;
1438181606Sjhb			break;
1439238109Sjhb		case 0xf9:
1440238109Sjhb			i_name = "rdtscp";
1441238109Sjhb			i_size = NONE;
1442238109Sjhb			i_mode = 0;
1443238109Sjhb			break;
1444181606Sjhb		}
1445181606Sjhb	}
1446181606Sjhb	if (ip->i_extra == db_Grp15 && f_mod(rex, regmodrm) == 3) {
1447181606Sjhb		i_name = db_Grp15b[f_reg(rex, regmodrm)];
1448181606Sjhb		i_size = NONE;
1449181606Sjhb		i_mode = 0;
1450181606Sjhb	}
1451181606Sjhb
1452238166Sjhb	/* Handle instructions identified by mandatory prefixes. */
1453238166Sjhb	if (rep == TRUE) {
1454238166Sjhb	    if (inst == 0x90) {
1455238166Sjhb		i_name = "pause";
1456238166Sjhb		i_size = NONE;
1457238166Sjhb		i_mode = 0;
1458238166Sjhb		rep = FALSE;
1459238166Sjhb	    } else if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) != 3 &&
1460238166Sjhb		f_reg(rex, regmodrm) == 0x6) {
1461238166Sjhb		i_name = "vmxon";
1462238166Sjhb		rep = FALSE;
1463238166Sjhb	    }
1464238166Sjhb	}
1465238166Sjhb	if (size == WORD) {
1466238166Sjhb	    if (ip->i_extra == db_Grp9 && f_mod(rex, regmodrm) != 3 &&
1467238166Sjhb		f_reg(rex, regmodrm) == 0x6) {
1468238166Sjhb		i_name = "vmclear";
1469238166Sjhb	    }
1470238166Sjhb	}
1471238166Sjhb	if (rex & REX_W) {
1472238166Sjhb	    if (strcmp(i_name, "cwde") == 0)
1473238166Sjhb		i_name = "cdqe";
1474238166Sjhb	    else if (strcmp(i_name, "cmpxchg8b") == 0)
1475238166Sjhb		i_name = "cmpxchg16b";
1476238166Sjhb	}
1477238166Sjhb
1478238166Sjhb	if (rep == TRUE)
1479238166Sjhb	    db_printf("repe ");	/* XXX repe VS rep */
1480238166Sjhb
14814Srgrimes	if (i_size == SDEP) {
1482238166Sjhb	    if (size == LONG)
148379885Skris		db_printf("%s", i_name);
14844Srgrimes	    else
148579885Skris		db_printf("%s", (const char *)ip->i_extra);
1486238166Sjhb	} else if (i_size == ADEP) {
1487238166Sjhb	    if (short_addr == FALSE)
1488238166Sjhb		db_printf("%s", i_name);
1489238166Sjhb	    else
1490238166Sjhb		db_printf("%s", (const char *)ip->i_extra);
14914Srgrimes	}
14924Srgrimes	else {
149379885Skris	    db_printf("%s", i_name);
1494144354Speter	    if ((inst >= 0x50 && inst <= 0x5f) || inst == 0x68 || inst == 0x6a) {
1495144354Speter		i_size = NONE;
1496144354Speter		db_printf("q");
1497144354Speter	    }
14984Srgrimes	    if (i_size != NONE) {
14994Srgrimes		if (i_size == BYTE) {
15004Srgrimes		    db_printf("b");
15014Srgrimes		    size = BYTE;
15024Srgrimes		}
15034Srgrimes		else if (i_size == WORD) {
15044Srgrimes		    db_printf("w");
15054Srgrimes		    size = WORD;
15064Srgrimes		}
15074Srgrimes		else if (size == WORD)
15084Srgrimes		    db_printf("w");
1509144353Speter		else {
1510144353Speter		    if (rex & REX_W)
1511144353Speter			db_printf("q");
1512144353Speter		    else
1513144353Speter			db_printf("l");
1514144353Speter		}
15154Srgrimes	    }
15164Srgrimes	}
15174Srgrimes	db_printf("\t");
15184Srgrimes	for (first = TRUE;
15194Srgrimes	     i_mode != 0;
15204Srgrimes	     i_mode >>= 8, first = FALSE)
15214Srgrimes	{
15224Srgrimes	    if (!first)
15234Srgrimes		db_printf(",");
15244Srgrimes
15254Srgrimes	    switch (i_mode & 0xFF) {
15264Srgrimes
15274Srgrimes		case E:
1528144353Speter		    db_print_address(seg, size, rex, &address);
15294Srgrimes		    break;
15304Srgrimes
15314Srgrimes		case Eind:
15324Srgrimes		    db_printf("*");
1533144353Speter		    db_print_address(seg, size, rex, &address);
15344Srgrimes		    break;
15354Srgrimes
153621277Sbde		case El:
1537144353Speter		    db_print_address(seg, (rex & REX_W) ? QUAD : LONG, rex, &address);
153821277Sbde		    break;
153921277Sbde
1540144354Speter		case EL:
1541144354Speter		    db_print_address(seg, LONG, 0, &address);
1542144354Speter		    break;
1543144354Speter
15444Srgrimes		case Ew:
1545144353Speter		    db_print_address(seg, WORD, rex, &address);
15464Srgrimes		    break;
15474Srgrimes
15484Srgrimes		case Eb:
1549144353Speter		    db_print_address(seg, BYTE, rex, &address);
15504Srgrimes		    break;
15514Srgrimes
15524Srgrimes		case R:
1553144354Speter		    db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][f_reg(rex, regmodrm)]);
15544Srgrimes		    break;
15554Srgrimes
15564Srgrimes		case Rw:
1557144353Speter		    db_printf("%s", db_reg[rex != 0 ? 1 : 0][WORD][f_reg(rex, regmodrm)]);
15584Srgrimes		    break;
15594Srgrimes
1560238166Sjhb		case Rq:
1561238166Sjhb		    db_printf("%s", db_reg[rex != 0 ? 1 : 0][QUAD][f_reg(rex, regmodrm)]);
1562238166Sjhb		    break;
1563238166Sjhb
15644Srgrimes		case Ri:
1565144354Speter		    db_printf("%s", db_reg[0][QUAD][f_rm(rex, inst)]);
15664Srgrimes		    break;
15674Srgrimes
156821277Sbde		case Ril:
1569144353Speter		    db_printf("%s", db_reg[rex != 0 ? 1 : 0][(rex & REX_R) ? QUAD : LONG][f_rm(rex, inst)]);
157021277Sbde		    break;
157121277Sbde
1572266354Sjhb	        case Rv:
1573266354Sjhb		    db_printf("%s", db_reg[rex != 0 ? 1 : 0][(size == LONG && (rex & REX_W)) ? QUAD : size][f_rm(rex, regmodrm)]);
1574266354Sjhb		    break;
1575266354Sjhb
15764Srgrimes		case S:
1577144353Speter		    db_printf("%s", db_seg_reg[f_reg(rex, regmodrm)]);
15784Srgrimes		    break;
15794Srgrimes
15804Srgrimes		case Si:
1581144353Speter		    db_printf("%s", db_seg_reg[f_reg(rex, inst)]);
15824Srgrimes		    break;
15834Srgrimes
15844Srgrimes		case A:
1585144353Speter		    db_printf("%s", db_reg[rex != 0 ? 1 : 0][size][0]);	/* acc */
15864Srgrimes		    break;
15874Srgrimes
15884Srgrimes		case BX:
15894Srgrimes		    if (seg)
15904Srgrimes			db_printf("%s:", seg);
15914Srgrimes		    db_printf("(%s)", short_addr ? "%bx" : "%ebx");
15924Srgrimes		    break;
15934Srgrimes
15944Srgrimes		case CL:
15954Srgrimes		    db_printf("%%cl");
15964Srgrimes		    break;
15974Srgrimes
15984Srgrimes		case DX:
15994Srgrimes		    db_printf("%%dx");
16004Srgrimes		    break;
16014Srgrimes
16024Srgrimes		case SI:
16034Srgrimes		    if (seg)
16044Srgrimes			db_printf("%s:", seg);
1605144353Speter		    db_printf("(%s)", short_addr ? "%si" : "%rsi");
16064Srgrimes		    break;
16074Srgrimes
16084Srgrimes		case DI:
1609144353Speter		    db_printf("%%es:(%s)", short_addr ? "%di" : "%rdi");
16104Srgrimes		    break;
16114Srgrimes
16124Srgrimes		case CR:
1613144353Speter		    db_printf("%%cr%d", f_reg(rex, regmodrm));
16144Srgrimes		    break;
16154Srgrimes
16164Srgrimes		case DR:
1617144353Speter		    db_printf("%%dr%d", f_reg(rex, regmodrm));
16184Srgrimes		    break;
16194Srgrimes
16204Srgrimes		case TR:
1621144353Speter		    db_printf("%%tr%d", f_reg(rex, regmodrm));
16224Srgrimes		    break;
16234Srgrimes
16244Srgrimes		case I:
1625144354Speter		    len = db_lengths[size];
162621277Sbde		    get_value_inc(imm, loc, len, FALSE);
162737506Sbde		    db_printf("$%#r", imm);
16284Srgrimes		    break;
16294Srgrimes
16304Srgrimes		case Is:
1631144353Speter		    len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
163221277Sbde		    get_value_inc(imm, loc, len, FALSE);
163337506Sbde		    db_printf("$%+#r", imm);
16344Srgrimes		    break;
16354Srgrimes
16364Srgrimes		case Ib:
163721277Sbde		    get_value_inc(imm, loc, 1, FALSE);
163837506Sbde		    db_printf("$%#r", imm);
16394Srgrimes		    break;
16404Srgrimes
164121277Sbde		case Iba:
164221277Sbde		    get_value_inc(imm, loc, 1, FALSE);
164321277Sbde		    if (imm != 0x0a)
164437506Sbde			db_printf("$%#r", imm);
164521277Sbde		    break;
164621277Sbde
16474Srgrimes		case Ibs:
164821277Sbde		    get_value_inc(imm, loc, 1, TRUE);
164921277Sbde		    if (size == WORD)
165021277Sbde			imm &= 0xFFFF;
165137506Sbde		    db_printf("$%+#r", imm);
16524Srgrimes		    break;
16534Srgrimes
16544Srgrimes		case Iw:
165521277Sbde		    get_value_inc(imm, loc, 2, FALSE);
165637506Sbde		    db_printf("$%#r", imm);
16574Srgrimes		    break;
16584Srgrimes
1659164263Sjhb		case Ilq:
1660164263Sjhb		    len = db_lengths[rex & REX_W ? QUAD : LONG];
1661164263Sjhb		    get_value_inc(imm64, loc, len, FALSE);
1662164263Sjhb		    db_printf("$%#lr", imm64);
1663164263Sjhb		    break;
1664164263Sjhb
16654Srgrimes		case O:
166621277Sbde		    len = (short_addr ? 2 : 4);
166721277Sbde		    get_value_inc(displ, loc, len, FALSE);
16684Srgrimes		    if (seg)
166937506Sbde			db_printf("%s:%+#r",seg, displ);
16704Srgrimes		    else
16714Srgrimes			db_printsym((db_addr_t)displ, DB_STGY_ANY);
16724Srgrimes		    break;
16734Srgrimes
16744Srgrimes		case Db:
16754Srgrimes		    get_value_inc(displ, loc, 1, TRUE);
167621277Sbde		    displ += loc;
167721277Sbde		    if (size == WORD)
167821277Sbde			displ &= 0xFFFF;
167921277Sbde		    db_printsym((db_addr_t)displ, DB_STGY_XTRN);
16804Srgrimes		    break;
16814Srgrimes
16824Srgrimes		case Dl:
1683144353Speter		    len = db_lengths[(size == LONG && (rex & REX_W)) ? QUAD : size];
168421277Sbde		    get_value_inc(displ, loc, len, FALSE);
168521277Sbde		    displ += loc;
168621277Sbde		    if (size == WORD)
168721277Sbde			displ &= 0xFFFF;
168821277Sbde		    db_printsym((db_addr_t)displ, DB_STGY_XTRN);
16894Srgrimes		    break;
16904Srgrimes
16914Srgrimes		case o1:
16924Srgrimes		    db_printf("$1");
16934Srgrimes		    break;
16944Srgrimes
16954Srgrimes		case o3:
16964Srgrimes		    db_printf("$3");
16974Srgrimes		    break;
16984Srgrimes
16994Srgrimes		case OS:
170021277Sbde		    len = db_lengths[size];
170121277Sbde		    get_value_inc(imm, loc, len, FALSE);	/* offset */
17024Srgrimes		    get_value_inc(imm2, loc, 2, FALSE);	/* segment */
170337506Sbde		    db_printf("$%#r,%#r", imm2, imm);
17044Srgrimes		    break;
17054Srgrimes	    }
17064Srgrimes	}
17074Srgrimes	db_printf("\n");
17084Srgrimes	return (loc);
17094Srgrimes}
1710