db_disasm.c revision 17109
18876Srgrimes/*
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.
25118Srgrimes *
2617109Sbde *	$Id: db_disasm.c,v 1.15 1996/06/08 10:15:48 bde Exp $
274Srgrimes */
284Srgrimes
294Srgrimes/*
304Srgrimes * Instruction disassembler.
314Srgrimes */
322056Swollman#include <sys/param.h>
332056Swollman#include <sys/systm.h>
342056Swollman#include <sys/proc.h>
3512662Sdg#include <vm/vm.h>
3612662Sdg#include <vm/vm_param.h>
372056Swollman#include <ddb/ddb.h>
384Srgrimes
394Srgrimes#include <ddb/db_access.h>
404Srgrimes#include <ddb/db_sym.h>
414Srgrimes
424Srgrimes/*
434Srgrimes * Size attributes
444Srgrimes */
454Srgrimes#define	BYTE	0
464Srgrimes#define	WORD	1
474Srgrimes#define	LONG	2
484Srgrimes#define	QUAD	3
494Srgrimes#define	SNGL	4
504Srgrimes#define	DBLR	5
514Srgrimes#define	EXTR	6
524Srgrimes#define	SDEP	7
534Srgrimes#define	NONE	8
544Srgrimes
554Srgrimes/*
564Srgrimes * Addressing modes
574Srgrimes */
584Srgrimes#define	E	1			/* general effective address */
594Srgrimes#define	Eind	2			/* indirect address (jump, call) */
604Srgrimes#define	Ew	3			/* address, word size */
614Srgrimes#define	Eb	4			/* address, byte size */
624Srgrimes#define	R	5			/* register, in 'reg' field */
634Srgrimes#define	Rw	6			/* word register, in 'reg' field */
644Srgrimes#define	Ri	7			/* register in instruction */
654Srgrimes#define	S	8			/* segment reg, in 'reg' field */
664Srgrimes#define	Si	9			/* segment reg, in instruction */
674Srgrimes#define	A	10			/* accumulator */
684Srgrimes#define	BX	11			/* (bx) */
694Srgrimes#define	CL	12			/* cl, for shifts */
704Srgrimes#define	DX	13			/* dx, for IO */
714Srgrimes#define	SI	14			/* si */
724Srgrimes#define	DI	15			/* di */
734Srgrimes#define	CR	16			/* control register */
744Srgrimes#define	DR	17			/* debug register */
754Srgrimes#define	TR	18			/* test register */
764Srgrimes#define	I	19			/* immediate, unsigned */
774Srgrimes#define	Is	20			/* immediate, signed */
784Srgrimes#define	Ib	21			/* byte immediate, unsigned */
794Srgrimes#define	Ibs	22			/* byte immediate, signed */
804Srgrimes#define	Iw	23			/* word immediate, unsigned */
814Srgrimes#define	Il	24			/* long immediate */
824Srgrimes#define	O	25			/* direct address */
834Srgrimes#define	Db	26			/* byte displacement from EIP */
844Srgrimes#define	Dl	27			/* long displacement from EIP */
854Srgrimes#define	o1	28			/* constant 1 */
864Srgrimes#define	o3	29			/* constant 3 */
874Srgrimes#define	OS	30			/* immediate offset/segment */
884Srgrimes#define	ST	31			/* FP stack top */
894Srgrimes#define	STI	32			/* FP stack */
904Srgrimes#define	X	33			/* extended FP op */
914Srgrimes#define	XA	34			/* for 'fstcw %ax' */
924Srgrimes
9311940Sbdestruct inst {
9414887Swollman	const char *	i_name;		/* name */
954Srgrimes	short	i_has_modrm;		/* has regmodrm byte */
964Srgrimes	short	i_size;			/* operand size */
974Srgrimes	int	i_mode;			/* addressing modes */
9817109Sbde	const void *	i_extra;	/* pointer to extra opcode table */
994Srgrimes};
1004Srgrimes
1014Srgrimes#define	op1(x)		(x)
1024Srgrimes#define	op2(x,y)	((x)|((y)<<8))
1034Srgrimes#define	op3(x,y,z)	((x)|((y)<<8)|((z)<<16))
1044Srgrimes
10511940Sbdestruct finst {
10614887Swollman	const char *	f_name;		/* name for memory instruction */
1074Srgrimes	int	f_size;			/* size for memory instruction */
1084Srgrimes	int	f_rrmode;		/* mode for rr instruction */
10917109Sbde	const void *	f_rrname;	/* name for rr instruction
1104Srgrimes					   (or pointer to table) */
1114Srgrimes};
1124Srgrimes
11314887Swollmanstatic const char * const db_Grp6[] = {
1144Srgrimes	"sldt",
1154Srgrimes	"str",
1164Srgrimes	"lldt",
1174Srgrimes	"ltr",
1184Srgrimes	"verr",
1194Srgrimes	"verw",
1204Srgrimes	"",
1214Srgrimes	""
1224Srgrimes};
1234Srgrimes
12414887Swollmanstatic const char * const db_Grp7[] = {
1254Srgrimes	"sgdt",
1264Srgrimes	"sidt",
1274Srgrimes	"lgdt",
1284Srgrimes	"lidt",
1294Srgrimes	"smsw",
1304Srgrimes	"",
1314Srgrimes	"lmsw",
1324Srgrimes	"invlpg"
1334Srgrimes};
1344Srgrimes
13514887Swollmanstatic const char * const db_Grp8[] = {
1364Srgrimes	"",
1374Srgrimes	"",
1384Srgrimes	"",
1394Srgrimes	"",
1404Srgrimes	"bt",
1414Srgrimes	"bts",
1424Srgrimes	"btr",
1434Srgrimes	"btc"
1444Srgrimes};
1454Srgrimes
14614887Swollmanstatic const struct inst db_inst_0f0x[] = {
14717109Sbde/*00*/	{ "",	   TRUE,  NONE,  op1(Ew),     db_Grp6 },
14817109Sbde/*01*/	{ "",	   TRUE,  NONE,  op1(Ew),     db_Grp7 },
1494Srgrimes/*02*/	{ "lar",   TRUE,  LONG,  op2(E,R),    0 },
1504Srgrimes/*03*/	{ "lsl",   TRUE,  LONG,  op2(E,R),    0 },
1514Srgrimes/*04*/	{ "",      FALSE, NONE,  0,	      0 },
1524Srgrimes/*05*/	{ "",      FALSE, NONE,  0,	      0 },
1534Srgrimes/*06*/	{ "clts",  FALSE, NONE,  0,	      0 },
1544Srgrimes/*07*/	{ "",      FALSE, NONE,  0,	      0 },
1554Srgrimes
1564Srgrimes/*08*/	{ "invd",  FALSE, NONE,  0,	      0 },
1574Srgrimes/*09*/	{ "wbinvd",FALSE, NONE,  0,	      0 },
1584Srgrimes/*0a*/	{ "",      FALSE, NONE,  0,	      0 },
1594Srgrimes/*0b*/	{ "",      FALSE, NONE,  0,	      0 },
1604Srgrimes/*0c*/	{ "",      FALSE, NONE,  0,	      0 },
1614Srgrimes/*0d*/	{ "",      FALSE, NONE,  0,	      0 },
1624Srgrimes/*0e*/	{ "",      FALSE, NONE,  0,	      0 },
1634Srgrimes/*0f*/	{ "",      FALSE, NONE,  0,	      0 },
1644Srgrimes};
1654Srgrimes
16617109Sbdestatic const struct inst db_inst_0f2x[] = {
1674Srgrimes/*20*/	{ "mov",   TRUE,  LONG,  op2(CR,E),   0 }, /* use E for reg */
1684Srgrimes/*21*/	{ "mov",   TRUE,  LONG,  op2(DR,E),   0 }, /* since mod == 11 */
1694Srgrimes/*22*/	{ "mov",   TRUE,  LONG,  op2(E,CR),   0 },
1704Srgrimes/*23*/	{ "mov",   TRUE,  LONG,  op2(E,DR),   0 },
1714Srgrimes/*24*/	{ "mov",   TRUE,  LONG,  op2(TR,E),   0 },
1724Srgrimes/*25*/	{ "",      FALSE, NONE,  0,	      0 },
1734Srgrimes/*26*/	{ "mov",   TRUE,  LONG,  op2(E,TR),   0 },
1744Srgrimes/*27*/	{ "",      FALSE, NONE,  0,	      0 },
1754Srgrimes
1764Srgrimes/*28*/	{ "",      FALSE, NONE,  0,	      0 },
1774Srgrimes/*29*/	{ "",      FALSE, NONE,  0,	      0 },
1784Srgrimes/*2a*/	{ "",      FALSE, NONE,  0,	      0 },
1794Srgrimes/*2b*/	{ "",      FALSE, NONE,  0,	      0 },
1804Srgrimes/*2c*/	{ "",      FALSE, NONE,  0,	      0 },
1814Srgrimes/*2d*/	{ "",      FALSE, NONE,  0,	      0 },
1824Srgrimes/*2e*/	{ "",      FALSE, NONE,  0,	      0 },
1834Srgrimes/*2f*/	{ "",      FALSE, NONE,  0,	      0 },
1844Srgrimes};
1854Srgrimes
18614887Swollmanstatic const struct inst db_inst_0f3x[] = {
18714887Swollman/*30*/	{ "wrmsr", FALSE, NONE,  0,	      0 },
18814887Swollman/*31*/	{ "rdtsc", FALSE, NONE,  0,	      0 },
18914887Swollman/*32*/	{ "rdmsr", FALSE, NONE,  0,	      0 },
19014887Swollman/*33*/	{ "rdpmc", FALSE, NONE,  0,	      0 },
19114887Swollman/*34*/	{ "",	   FALSE, NONE,  0,	      0 },
19214887Swollman/*35*/	{ "",	   FALSE, NONE,  0,	      0 },
19314887Swollman/*36*/	{ "",	   FALSE, NONE,  0,	      0 },
19414887Swollman/*37*/	{ "",	   FALSE, NONE,  0,	      0 },
19514887Swollman
19614887Swollman/*38*/	{ "",	   FALSE, NONE,  0,	      0 },
19714887Swollman/*39*/	{ "",	   FALSE, NONE,  0,	      0 },
19814887Swollman/*3a*/	{ "",	   FALSE, NONE,  0,	      0 },
19914887Swollman/*3b*/	{ "",	   FALSE, NONE,  0,	      0 },
20014887Swollman/*3c*/	{ "",	   FALSE, NONE,  0,	      0 },
20114887Swollman/*3d*/	{ "",	   FALSE, NONE,  0,	      0 },
20214887Swollman/*3e*/	{ "",	   FALSE, NONE,  0,	      0 },
20314887Swollman/*3f*/	{ "",	   FALSE, NONE,  0,	      0 },
20414887Swollman};
20514887Swollman
20617109Sbdestatic const struct inst db_inst_0f8x[] = {
2074Srgrimes/*80*/	{ "jo",    FALSE, NONE,  op1(Dl),     0 },
2084Srgrimes/*81*/	{ "jno",   FALSE, NONE,  op1(Dl),     0 },
2094Srgrimes/*82*/	{ "jb",    FALSE, NONE,  op1(Dl),     0 },
2104Srgrimes/*83*/	{ "jnb",   FALSE, NONE,  op1(Dl),     0 },
2114Srgrimes/*84*/	{ "jz",    FALSE, NONE,  op1(Dl),     0 },
2124Srgrimes/*85*/	{ "jnz",   FALSE, NONE,  op1(Dl),     0 },
2134Srgrimes/*86*/	{ "jbe",   FALSE, NONE,  op1(Dl),     0 },
2144Srgrimes/*87*/	{ "jnbe",  FALSE, NONE,  op1(Dl),     0 },
2154Srgrimes
2164Srgrimes/*88*/	{ "js",    FALSE, NONE,  op1(Dl),     0 },
2174Srgrimes/*89*/	{ "jns",   FALSE, NONE,  op1(Dl),     0 },
2184Srgrimes/*8a*/	{ "jp",    FALSE, NONE,  op1(Dl),     0 },
2194Srgrimes/*8b*/	{ "jnp",   FALSE, NONE,  op1(Dl),     0 },
2204Srgrimes/*8c*/	{ "jl",    FALSE, NONE,  op1(Dl),     0 },
2214Srgrimes/*8d*/	{ "jnl",   FALSE, NONE,  op1(Dl),     0 },
2224Srgrimes/*8e*/	{ "jle",   FALSE, NONE,  op1(Dl),     0 },
2234Srgrimes/*8f*/	{ "jnle",  FALSE, NONE,  op1(Dl),     0 },
2244Srgrimes};
2254Srgrimes
22617109Sbdestatic const struct inst db_inst_0f9x[] = {
2274Srgrimes/*90*/	{ "seto",  TRUE,  NONE,  op1(Eb),     0 },
2284Srgrimes/*91*/	{ "setno", TRUE,  NONE,  op1(Eb),     0 },
2294Srgrimes/*92*/	{ "setb",  TRUE,  NONE,  op1(Eb),     0 },
2304Srgrimes/*93*/	{ "setnb", TRUE,  NONE,  op1(Eb),     0 },
2314Srgrimes/*94*/	{ "setz",  TRUE,  NONE,  op1(Eb),     0 },
2324Srgrimes/*95*/	{ "setnz", TRUE,  NONE,  op1(Eb),     0 },
2334Srgrimes/*96*/	{ "setbe", TRUE,  NONE,  op1(Eb),     0 },
2344Srgrimes/*97*/	{ "setnbe",TRUE,  NONE,  op1(Eb),     0 },
2354Srgrimes
2364Srgrimes/*98*/	{ "sets",  TRUE,  NONE,  op1(Eb),     0 },
2374Srgrimes/*99*/	{ "setns", TRUE,  NONE,  op1(Eb),     0 },
2384Srgrimes/*9a*/	{ "setp",  TRUE,  NONE,  op1(Eb),     0 },
2394Srgrimes/*9b*/	{ "setnp", TRUE,  NONE,  op1(Eb),     0 },
2404Srgrimes/*9c*/	{ "setl",  TRUE,  NONE,  op1(Eb),     0 },
2414Srgrimes/*9d*/	{ "setnl", TRUE,  NONE,  op1(Eb),     0 },
2424Srgrimes/*9e*/	{ "setle", TRUE,  NONE,  op1(Eb),     0 },
2434Srgrimes/*9f*/	{ "setnle",TRUE,  NONE,  op1(Eb),     0 },
2444Srgrimes};
2454Srgrimes
24617109Sbdestatic const struct inst db_inst_0fax[] = {
2474Srgrimes/*a0*/	{ "push",  FALSE, NONE,  op1(Si),     0 },
2484Srgrimes/*a1*/	{ "pop",   FALSE, NONE,  op1(Si),     0 },
2494Srgrimes/*a2*/	{ "",      FALSE, NONE,  0,	      0 },
2504Srgrimes/*a3*/	{ "bt",    TRUE,  LONG,  op2(E,R),    0 },
25117109Sbde/*a4*/	{ "shld",  TRUE,  LONG,  op3(Ib,R,E), 0 },
25217109Sbde/*a5*/	{ "shld",  TRUE,  LONG,  op3(CL,R,E), 0 },
2534Srgrimes/*a6*/	{ "",      FALSE, NONE,  0,	      0 },
2544Srgrimes/*a7*/	{ "",      FALSE, NONE,  0,	      0 },
2554Srgrimes
2564Srgrimes/*a8*/	{ "push",  FALSE, NONE,  op1(Si),     0 },
2574Srgrimes/*a9*/	{ "pop",   FALSE, NONE,  op1(Si),     0 },
2584Srgrimes/*aa*/	{ "",      FALSE, NONE,  0,	      0 },
2594Srgrimes/*ab*/	{ "bts",   TRUE,  LONG,  op2(E,R),    0 },
26017109Sbde/*ac*/	{ "shrd",  TRUE,  LONG,  op3(Ib,R,E), 0 },
26117109Sbde/*ad*/	{ "shrd",  TRUE,  LONG,  op3(CL,R,E), 0 },
2624Srgrimes/*a6*/	{ "",      FALSE, NONE,  0,	      0 },
2634Srgrimes/*a7*/	{ "imul",  TRUE,  LONG,  op2(E,R),    0 },
2644Srgrimes};
2654Srgrimes
26617109Sbdestatic const struct inst db_inst_0fbx[] = {
2674Srgrimes/*b0*/	{ "",      FALSE, NONE,  0,	      0 },
2684Srgrimes/*b1*/	{ "",      FALSE, NONE,  0,	      0 },
2694Srgrimes/*b2*/	{ "lss",   TRUE,  LONG,  op2(E, R),   0 },
2704Srgrimes/*b3*/	{ "bts",   TRUE,  LONG,  op2(R, E),   0 },
2714Srgrimes/*b4*/	{ "lfs",   TRUE,  LONG,  op2(E, R),   0 },
2724Srgrimes/*b5*/	{ "lgs",   TRUE,  LONG,  op2(E, R),   0 },
2734Srgrimes/*b6*/	{ "movzb", TRUE,  LONG,  op2(E, R),   0 },
2744Srgrimes/*b7*/	{ "movzw", TRUE,  LONG,  op2(E, R),   0 },
2754Srgrimes
2764Srgrimes/*b8*/	{ "",      FALSE, NONE,  0,	      0 },
2774Srgrimes/*b9*/	{ "",      FALSE, NONE,  0,	      0 },
27817109Sbde/*ba*/	{ "",      TRUE,  LONG,  op2(Ib, E),  db_Grp8 },
2794Srgrimes/*bb*/	{ "btc",   TRUE,  LONG,  op2(R, E),   0 },
2804Srgrimes/*bc*/	{ "bsf",   TRUE,  LONG,  op2(E, R),   0 },
2814Srgrimes/*bd*/	{ "bsr",   TRUE,  LONG,  op2(E, R),   0 },
2824Srgrimes/*be*/	{ "movsb", TRUE,  LONG,  op2(E, R),   0 },
2834Srgrimes/*bf*/	{ "movsw", TRUE,  LONG,  op2(E, R),   0 },
2844Srgrimes};
2854Srgrimes
28617109Sbdestatic const struct inst db_inst_0fcx[] = {
2874Srgrimes/*c0*/	{ "xadd",  TRUE,  BYTE,	 op2(R, E),   0 },
2884Srgrimes/*c1*/	{ "xadd",  TRUE,  LONG,	 op2(R, E),   0 },
2894Srgrimes/*c2*/	{ "",	   FALSE, NONE,	 0,	      0 },
2904Srgrimes/*c3*/	{ "",	   FALSE, NONE,	 0,	      0 },
2914Srgrimes/*c4*/	{ "",	   FALSE, NONE,	 0,	      0 },
2924Srgrimes/*c5*/	{ "",	   FALSE, NONE,	 0,	      0 },
2934Srgrimes/*c6*/	{ "",	   FALSE, NONE,	 0,	      0 },
2944Srgrimes/*c7*/	{ "",	   FALSE, NONE,	 0,	      0 },
2954Srgrimes/*c8*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
2964Srgrimes/*c9*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
2974Srgrimes/*ca*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
2984Srgrimes/*cb*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
2994Srgrimes/*cc*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
3004Srgrimes/*cd*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
3014Srgrimes/*ce*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
3024Srgrimes/*cf*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
3034Srgrimes};
3044Srgrimes
30517109Sbdestatic const struct inst db_inst_0fdx[] = {
3064Srgrimes/*c0*/	{ "cmpxchg",TRUE, BYTE,	 op2(R, E),   0 },
3074Srgrimes/*c1*/	{ "cmpxchg",TRUE, LONG,	 op2(R, E),   0 },
3084Srgrimes/*c2*/	{ "",	   FALSE, NONE,	 0,	      0 },
3094Srgrimes/*c3*/	{ "",	   FALSE, NONE,	 0,	      0 },
3104Srgrimes/*c4*/	{ "",	   FALSE, NONE,	 0,	      0 },
3114Srgrimes/*c5*/	{ "",	   FALSE, NONE,	 0,	      0 },
3124Srgrimes/*c6*/	{ "",	   FALSE, NONE,	 0,	      0 },
3134Srgrimes/*c7*/	{ "",	   FALSE, NONE,	 0,	      0 },
3144Srgrimes/*c8*/	{ "",	   FALSE, NONE,	 0,	      0 },
3154Srgrimes/*c9*/	{ "",	   FALSE, NONE,	 0,	      0 },
3164Srgrimes/*ca*/	{ "",	   FALSE, NONE,	 0,	      0 },
3174Srgrimes/*cb*/	{ "",	   FALSE, NONE,	 0,	      0 },
3184Srgrimes/*cc*/	{ "",	   FALSE, NONE,	 0,	      0 },
3194Srgrimes/*cd*/	{ "",	   FALSE, NONE,	 0,	      0 },
3204Srgrimes/*ce*/	{ "",	   FALSE, NONE,	 0,	      0 },
3214Srgrimes/*cf*/	{ "",	   FALSE, NONE,	 0,	      0 },
3224Srgrimes};
3234Srgrimes
32414887Swollmanstatic const struct inst * const db_inst_0f[] = {
3254Srgrimes	db_inst_0f0x,
3264Srgrimes	0,
3274Srgrimes	db_inst_0f2x,
32814887Swollman	db_inst_0f3x,
3294Srgrimes	0,
3304Srgrimes	0,
3314Srgrimes	0,
3324Srgrimes	0,
3334Srgrimes	db_inst_0f8x,
3344Srgrimes	db_inst_0f9x,
3354Srgrimes	db_inst_0fax,
3364Srgrimes	db_inst_0fbx,
3374Srgrimes	db_inst_0fcx,
3384Srgrimes	db_inst_0fdx,
3394Srgrimes	0,
3404Srgrimes	0
3414Srgrimes};
3424Srgrimes
34314887Swollmanstatic const char * const db_Esc92[] = {
3444Srgrimes	"fnop",	"",	"",	"",	"",	"",	"",	""
3454Srgrimes};
34614887Swollmanstatic const char * const db_Esc93[] = {
3474Srgrimes	"",	"",	"",	"",	"",	"",	"",	""
3484Srgrimes};
34914887Swollmanstatic const char * const db_Esc94[] = {
3504Srgrimes	"fchs",	"fabs",	"",	"",	"ftst",	"fxam",	"",	""
3514Srgrimes};
35217109Sbdestatic const char * const db_Esc95[] = {
3534Srgrimes	"fld1",	"fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
3544Srgrimes};
35517109Sbdestatic const char * const db_Esc96[] = {
3564Srgrimes	"f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
3574Srgrimes	"fincstp"
3584Srgrimes};
35914887Swollmanstatic const char * const db_Esc97[] = {
3604Srgrimes	"fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
3614Srgrimes};
3624Srgrimes
36317109Sbdestatic const char * const db_Esca4[] = {
3644Srgrimes	"",	"fucompp","",	"",	"",	"",	"",	""
3654Srgrimes};
3664Srgrimes
36717109Sbdestatic const char * const db_Escb4[] = {
3684Srgrimes	"",	"",	"fnclex","fninit","",	"",	"",	""
3694Srgrimes};
3704Srgrimes
37114887Swollmanstatic const char * const db_Esce3[] = {
3724Srgrimes	"",	"fcompp","",	"",	"",	"",	"",	""
3734Srgrimes};
3744Srgrimes
37517109Sbdestatic const char * const db_Escf4[] = {
3764Srgrimes	"fnstsw","",	"",	"",	"",	"",	"",	""
3774Srgrimes};
3784Srgrimes
37914887Swollmanstatic const struct finst db_Esc8[] = {
3804Srgrimes/*0*/	{ "fadd",   SNGL,  op2(STI,ST),	0 },
3814Srgrimes/*1*/	{ "fmul",   SNGL,  op2(STI,ST),	0 },
3824Srgrimes/*2*/	{ "fcom",   SNGL,  op2(STI,ST),	0 },
3834Srgrimes/*3*/	{ "fcomp",  SNGL,  op2(STI,ST),	0 },
3844Srgrimes/*4*/	{ "fsub",   SNGL,  op2(STI,ST),	0 },
3854Srgrimes/*5*/	{ "fsubr",  SNGL,  op2(STI,ST),	0 },
3864Srgrimes/*6*/	{ "fdiv",   SNGL,  op2(STI,ST),	0 },
3874Srgrimes/*7*/	{ "fdivr",  SNGL,  op2(STI,ST),	0 },
3884Srgrimes};
3894Srgrimes
39014887Swollmanstatic const struct finst db_Esc9[] = {
3914Srgrimes/*0*/	{ "fld",    SNGL,  op1(STI),	0 },
3924Srgrimes/*1*/	{ "",       NONE,  op1(STI),	"fxch" },
39317109Sbde/*2*/	{ "fst",    SNGL,  op1(X),	db_Esc92 },
39417109Sbde/*3*/	{ "fstp",   SNGL,  op1(X),	db_Esc93 },
39517109Sbde/*4*/	{ "fldenv", NONE,  op1(X),	db_Esc94 },
39617109Sbde/*5*/	{ "fldcw",  NONE,  op1(X),	db_Esc95 },
39717109Sbde/*6*/	{ "fnstenv",NONE,  op1(X),	db_Esc96 },
39817109Sbde/*7*/	{ "fnstcw", NONE,  op1(X),	db_Esc97 },
3994Srgrimes};
4004Srgrimes
40114887Swollmanstatic const struct finst db_Esca[] = {
4024Srgrimes/*0*/	{ "fiadd",  WORD,  0,		0 },
4034Srgrimes/*1*/	{ "fimul",  WORD,  0,		0 },
4044Srgrimes/*2*/	{ "ficom",  WORD,  0,		0 },
4054Srgrimes/*3*/	{ "ficomp", WORD,  0,		0 },
40617109Sbde/*4*/	{ "fisub",  WORD,  op1(X),	db_Esca4 },
4074Srgrimes/*5*/	{ "fisubr", WORD,  0,		0 },
4084Srgrimes/*6*/	{ "fidiv",  WORD,  0,		0 },
4094Srgrimes/*7*/	{ "fidivr", WORD,  0,		0 }
4104Srgrimes};
4114Srgrimes
41214887Swollmanstatic const struct finst db_Escb[] = {
4134Srgrimes/*0*/	{ "fild",   WORD,  0,		0 },
4144Srgrimes/*1*/	{ "",       NONE,  0,		0 },
4154Srgrimes/*2*/	{ "fist",   WORD,  0,		0 },
4164Srgrimes/*3*/	{ "fistp",  WORD,  0,		0 },
41717109Sbde/*4*/	{ "",       WORD,  op1(X),	db_Escb4 },
4184Srgrimes/*5*/	{ "fld",    EXTR,  0,		0 },
4194Srgrimes/*6*/	{ "",       WORD,  0,		0 },
4204Srgrimes/*7*/	{ "fstp",   EXTR,  0,		0 },
4214Srgrimes};
4224Srgrimes
42314887Swollmanstatic const struct finst db_Escc[] = {
4244Srgrimes/*0*/	{ "fadd",   DBLR,  op2(ST,STI),	0 },
4254Srgrimes/*1*/	{ "fmul",   DBLR,  op2(ST,STI),	0 },
4264Srgrimes/*2*/	{ "fcom",   DBLR,  op2(ST,STI),	0 },
4274Srgrimes/*3*/	{ "fcomp",  DBLR,  op2(ST,STI),	0 },
4284Srgrimes/*4*/	{ "fsub",   DBLR,  op2(ST,STI),	"fsubr" },
4294Srgrimes/*5*/	{ "fsubr",  DBLR,  op2(ST,STI),	"fsub" },
4304Srgrimes/*6*/	{ "fdiv",   DBLR,  op2(ST,STI),	"fdivr" },
4314Srgrimes/*7*/	{ "fdivr",  DBLR,  op2(ST,STI),	"fdiv" },
4324Srgrimes};
4334Srgrimes
43414887Swollmanstatic const struct finst db_Escd[] = {
4354Srgrimes/*0*/	{ "fld",    DBLR,  op1(STI),	"ffree" },
4364Srgrimes/*1*/	{ "",       NONE,  0,		0 },
4374Srgrimes/*2*/	{ "fst",    DBLR,  op1(STI),	0 },
4384Srgrimes/*3*/	{ "fstp",   DBLR,  op1(STI),	0 },
4394Srgrimes/*4*/	{ "frstor", NONE,  op1(STI),	"fucom" },
4404Srgrimes/*5*/	{ "",       NONE,  op1(STI),	"fucomp" },
4414Srgrimes/*6*/	{ "fnsave", NONE,  0,		0 },
4424Srgrimes/*7*/	{ "fnstsw", NONE,  0,		0 },
4434Srgrimes};
4444Srgrimes
44514887Swollmanstatic const struct finst db_Esce[] = {
4464Srgrimes/*0*/	{ "fiadd",  LONG,  op2(ST,STI),	"faddp" },
4474Srgrimes/*1*/	{ "fimul",  LONG,  op2(ST,STI),	"fmulp" },
4484Srgrimes/*2*/	{ "ficom",  LONG,  0,		0 },
44917109Sbde/*3*/	{ "ficomp", LONG,  op1(X),	db_Esce3 },
4504Srgrimes/*4*/	{ "fisub",  LONG,  op2(ST,STI),	"fsubrp" },
4514Srgrimes/*5*/	{ "fisubr", LONG,  op2(ST,STI),	"fsubp" },
4524Srgrimes/*6*/	{ "fidiv",  LONG,  op2(ST,STI),	"fdivrp" },
4534Srgrimes/*7*/	{ "fidivr", LONG,  op2(ST,STI),	"fdivp" },
4544Srgrimes};
4554Srgrimes
45614887Swollmanstatic const struct finst db_Escf[] = {
4574Srgrimes/*0*/	{ "fild",   LONG,  0,		0 },
4584Srgrimes/*1*/	{ "",       LONG,  0,		0 },
4594Srgrimes/*2*/	{ "fist",   LONG,  0,		0 },
4604Srgrimes/*3*/	{ "fistp",  LONG,  0,		0 },
46117109Sbde/*4*/	{ "fbld",   NONE,  op1(XA),	db_Escf4 },
4624Srgrimes/*5*/	{ "fld",    QUAD,  0,		0 },
4634Srgrimes/*6*/	{ "fbstp",  NONE,  0,		0 },
4644Srgrimes/*7*/	{ "fstp",   QUAD,  0,		0 },
4654Srgrimes};
4664Srgrimes
46717109Sbdestatic const struct finst * const db_Esc_inst[] = {
4684Srgrimes	db_Esc8, db_Esc9, db_Esca, db_Escb,
4694Srgrimes	db_Escc, db_Escd, db_Esce, db_Escf
4704Srgrimes};
4714Srgrimes
47214887Swollmanstatic const char * const db_Grp1[] = {
4734Srgrimes	"add",
4744Srgrimes	"or",
4754Srgrimes	"adc",
4764Srgrimes	"sbb",
4774Srgrimes	"and",
4784Srgrimes	"sub",
4794Srgrimes	"xor",
4804Srgrimes	"cmp"
4814Srgrimes};
4824Srgrimes
48314887Swollmanstatic const char * const db_Grp2[] = {
4844Srgrimes	"rol",
4854Srgrimes	"ror",
4864Srgrimes	"rcl",
4874Srgrimes	"rcr",
4884Srgrimes	"shl",
4894Srgrimes	"shr",
4904Srgrimes	"shl",
4914Srgrimes	"sar"
4924Srgrimes};
4934Srgrimes
49414887Swollmanstatic const struct inst db_Grp3[] = {
4954Srgrimes	{ "test",  TRUE, NONE, op2(I,E), 0 },
4964Srgrimes	{ "test",  TRUE, NONE, op2(I,E), 0 },
4974Srgrimes	{ "not",   TRUE, NONE, op1(E),   0 },
4984Srgrimes	{ "neg",   TRUE, NONE, op1(E),   0 },
4994Srgrimes	{ "mul",   TRUE, NONE, op2(E,A), 0 },
5004Srgrimes	{ "imul",  TRUE, NONE, op2(E,A), 0 },
5014Srgrimes	{ "div",   TRUE, NONE, op2(E,A), 0 },
5024Srgrimes	{ "idiv",  TRUE, NONE, op2(E,A), 0 },
5034Srgrimes};
5044Srgrimes
50517109Sbdestatic const struct inst db_Grp4[] = {
5064Srgrimes	{ "inc",   TRUE, BYTE, op1(E),   0 },
5074Srgrimes	{ "dec",   TRUE, BYTE, op1(E),   0 },
5084Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
5094Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
5104Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
5114Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
5124Srgrimes	{ "",      TRUE, NONE, 0,	 0 },
5134Srgrimes	{ "",      TRUE, NONE, 0,	 0 }
5144Srgrimes};
5154Srgrimes
51617109Sbdestatic const struct inst db_Grp5[] = {
5174Srgrimes	{ "inc",   TRUE, LONG, op1(E),   0 },
5184Srgrimes	{ "dec",   TRUE, LONG, op1(E),   0 },
5194Srgrimes	{ "call",  TRUE, NONE, op1(Eind),0 },
5204Srgrimes	{ "lcall", TRUE, NONE, op1(Eind),0 },
5214Srgrimes	{ "jmp",   TRUE, NONE, op1(Eind),0 },
5224Srgrimes	{ "ljmp",  TRUE, NONE, op1(Eind),0 },
5234Srgrimes	{ "push",  TRUE, LONG, op1(E),   0 },
5244Srgrimes	{ "",      TRUE, NONE, 0,	 0 }
5254Srgrimes};
5264Srgrimes
52714887Swollmanstatic const struct inst db_inst_table[256] = {
5284Srgrimes/*00*/	{ "add",   TRUE,  BYTE,  op2(R, E),  0 },
5294Srgrimes/*01*/	{ "add",   TRUE,  LONG,  op2(R, E),  0 },
5304Srgrimes/*02*/	{ "add",   TRUE,  BYTE,  op2(E, R),  0 },
5314Srgrimes/*03*/	{ "add",   TRUE,  LONG,  op2(E, R),  0 },
5324Srgrimes/*04*/	{ "add",   FALSE, BYTE,  op2(Is, A), 0 },
5334Srgrimes/*05*/	{ "add",   FALSE, LONG,  op2(Is, A), 0 },
5344Srgrimes/*06*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
5354Srgrimes/*07*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },
5364Srgrimes
5374Srgrimes/*08*/	{ "or",    TRUE,  BYTE,  op2(R, E),  0 },
5384Srgrimes/*09*/	{ "or",    TRUE,  LONG,  op2(R, E),  0 },
5394Srgrimes/*0a*/	{ "or",    TRUE,  BYTE,  op2(E, R),  0 },
5404Srgrimes/*0b*/	{ "or",    TRUE,  LONG,  op2(E, R),  0 },
5414Srgrimes/*0c*/	{ "or",    FALSE, BYTE,  op2(I, A),  0 },
5424Srgrimes/*0d*/	{ "or",    FALSE, LONG,  op2(I, A),  0 },
5434Srgrimes/*0e*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
5444Srgrimes/*0f*/	{ "",      FALSE, NONE,  0,	     0 },
5454Srgrimes
5464Srgrimes/*10*/	{ "adc",   TRUE,  BYTE,  op2(R, E),  0 },
5474Srgrimes/*11*/	{ "adc",   TRUE,  LONG,  op2(R, E),  0 },
5484Srgrimes/*12*/	{ "adc",   TRUE,  BYTE,  op2(E, R),  0 },
5494Srgrimes/*13*/	{ "adc",   TRUE,  LONG,  op2(E, R),  0 },
5504Srgrimes/*14*/	{ "adc",   FALSE, BYTE,  op2(Is, A), 0 },
5514Srgrimes/*15*/	{ "adc",   FALSE, LONG,  op2(Is, A), 0 },
5524Srgrimes/*16*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
5534Srgrimes/*17*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },
5544Srgrimes
5554Srgrimes/*18*/	{ "sbb",   TRUE,  BYTE,  op2(R, E),  0 },
5564Srgrimes/*19*/	{ "sbb",   TRUE,  LONG,  op2(R, E),  0 },
5574Srgrimes/*1a*/	{ "sbb",   TRUE,  BYTE,  op2(E, R),  0 },
5584Srgrimes/*1b*/	{ "sbb",   TRUE,  LONG,  op2(E, R),  0 },
5594Srgrimes/*1c*/	{ "sbb",   FALSE, BYTE,  op2(Is, A), 0 },
5604Srgrimes/*1d*/	{ "sbb",   FALSE, LONG,  op2(Is, A), 0 },
5614Srgrimes/*1e*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
5624Srgrimes/*1f*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },
5634Srgrimes
5644Srgrimes/*20*/	{ "and",   TRUE,  BYTE,  op2(R, E),  0 },
5654Srgrimes/*21*/	{ "and",   TRUE,  LONG,  op2(R, E),  0 },
5664Srgrimes/*22*/	{ "and",   TRUE,  BYTE,  op2(E, R),  0 },
5674Srgrimes/*23*/	{ "and",   TRUE,  LONG,  op2(E, R),  0 },
5684Srgrimes/*24*/	{ "and",   FALSE, BYTE,  op2(I, A),  0 },
5694Srgrimes/*25*/	{ "and",   FALSE, LONG,  op2(I, A),  0 },
5704Srgrimes/*26*/	{ "",      FALSE, NONE,  0,	     0 },
5714Srgrimes/*27*/	{ "aaa",   FALSE, NONE,  0,	     0 },
5724Srgrimes
5734Srgrimes/*28*/	{ "sub",   TRUE,  BYTE,  op2(R, E),  0 },
5744Srgrimes/*29*/	{ "sub",   TRUE,  LONG,  op2(R, E),  0 },
5754Srgrimes/*2a*/	{ "sub",   TRUE,  BYTE,  op2(E, R),  0 },
5764Srgrimes/*2b*/	{ "sub",   TRUE,  LONG,  op2(E, R),  0 },
5774Srgrimes/*2c*/	{ "sub",   FALSE, BYTE,  op2(Is, A), 0 },
5784Srgrimes/*2d*/	{ "sub",   FALSE, LONG,  op2(Is, A), 0 },
5794Srgrimes/*2e*/	{ "",      FALSE, NONE,  0,	     0 },
5804Srgrimes/*2f*/	{ "das",   FALSE, NONE,  0,	     0 },
5814Srgrimes
5824Srgrimes/*30*/	{ "xor",   TRUE,  BYTE,  op2(R, E),  0 },
5834Srgrimes/*31*/	{ "xor",   TRUE,  LONG,  op2(R, E),  0 },
5844Srgrimes/*32*/	{ "xor",   TRUE,  BYTE,  op2(E, R),  0 },
5854Srgrimes/*33*/	{ "xor",   TRUE,  LONG,  op2(E, R),  0 },
5864Srgrimes/*34*/	{ "xor",   FALSE, BYTE,  op2(I, A),  0 },
5874Srgrimes/*35*/	{ "xor",   FALSE, LONG,  op2(I, A),  0 },
5884Srgrimes/*36*/	{ "",      FALSE, NONE,  0,	     0 },
5894Srgrimes/*37*/	{ "daa",   FALSE, NONE,  0,	     0 },
5904Srgrimes
5914Srgrimes/*38*/	{ "cmp",   TRUE,  BYTE,  op2(R, E),  0 },
5924Srgrimes/*39*/	{ "cmp",   TRUE,  LONG,  op2(R, E),  0 },
5934Srgrimes/*3a*/	{ "cmp",   TRUE,  BYTE,  op2(E, R),  0 },
5944Srgrimes/*3b*/	{ "cmp",   TRUE,  LONG,  op2(E, R),  0 },
5954Srgrimes/*3c*/	{ "cmp",   FALSE, BYTE,  op2(Is, A), 0 },
5964Srgrimes/*3d*/	{ "cmp",   FALSE, LONG,  op2(Is, A), 0 },
5974Srgrimes/*3e*/	{ "",      FALSE, NONE,  0,	     0 },
5984Srgrimes/*3f*/	{ "aas",   FALSE, NONE,  0,	     0 },
5994Srgrimes
6004Srgrimes/*40*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
6014Srgrimes/*41*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
6024Srgrimes/*42*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
6034Srgrimes/*43*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
6044Srgrimes/*44*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
6054Srgrimes/*45*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
6064Srgrimes/*46*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
6074Srgrimes/*47*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
6084Srgrimes
6094Srgrimes/*48*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
6104Srgrimes/*49*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
6114Srgrimes/*4a*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
6124Srgrimes/*4b*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
6134Srgrimes/*4c*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
6144Srgrimes/*4d*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
6154Srgrimes/*4e*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
6164Srgrimes/*4f*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
6174Srgrimes
6184Srgrimes/*50*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
6194Srgrimes/*51*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
6204Srgrimes/*52*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
6214Srgrimes/*53*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
6224Srgrimes/*54*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
6234Srgrimes/*55*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
6244Srgrimes/*56*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
6254Srgrimes/*57*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
6264Srgrimes
6274Srgrimes/*58*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
6284Srgrimes/*59*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
6294Srgrimes/*5a*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
6304Srgrimes/*5b*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
6314Srgrimes/*5c*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
6324Srgrimes/*5d*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
6334Srgrimes/*5e*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
6344Srgrimes/*5f*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
6354Srgrimes
6364Srgrimes/*60*/	{ "pusha", FALSE, LONG,  0,	     0 },
6374Srgrimes/*61*/	{ "popa",  FALSE, LONG,  0,	     0 },
6384Srgrimes/*62*/  { "bound", TRUE,  LONG,  op2(E, R),  0 },
6394Srgrimes/*63*/	{ "arpl",  TRUE,  NONE,  op2(Ew,Rw), 0 },
6404Srgrimes
6414Srgrimes/*64*/	{ "",      FALSE, NONE,  0,	     0 },
6424Srgrimes/*65*/	{ "",      FALSE, NONE,  0,	     0 },
6434Srgrimes/*66*/	{ "",      FALSE, NONE,  0,	     0 },
6444Srgrimes/*67*/	{ "",      FALSE, NONE,  0,	     0 },
6454Srgrimes
6464Srgrimes/*68*/	{ "push",  FALSE, LONG,  op1(I),     0 },
6474Srgrimes/*69*/  { "imul",  TRUE,  LONG,  op3(I,E,R), 0 },
6484Srgrimes/*6a*/	{ "push",  FALSE, LONG,  op1(Ib),    0 },
6494Srgrimes/*6b*/  { "imul",  TRUE,  LONG,  op3(Ibs,E,R),0 },
6504Srgrimes/*6c*/	{ "ins",   FALSE, BYTE,  op2(DX, DI), 0 },
6514Srgrimes/*6d*/	{ "ins",   FALSE, LONG,  op2(DX, DI), 0 },
6524Srgrimes/*6e*/	{ "outs",  FALSE, BYTE,  op2(SI, DX), 0 },
6534Srgrimes/*6f*/	{ "outs",  FALSE, LONG,  op2(SI, DX), 0 },
6544Srgrimes
6554Srgrimes/*70*/	{ "jo",    FALSE, NONE,  op1(Db),     0 },
6564Srgrimes/*71*/	{ "jno",   FALSE, NONE,  op1(Db),     0 },
6574Srgrimes/*72*/	{ "jb",    FALSE, NONE,  op1(Db),     0 },
6584Srgrimes/*73*/	{ "jnb",   FALSE, NONE,  op1(Db),     0 },
6594Srgrimes/*74*/	{ "jz",    FALSE, NONE,  op1(Db),     0 },
6604Srgrimes/*75*/	{ "jnz",   FALSE, NONE,  op1(Db),     0 },
6614Srgrimes/*76*/	{ "jbe",   FALSE, NONE,  op1(Db),     0 },
6624Srgrimes/*77*/	{ "jnbe",  FALSE, NONE,  op1(Db),     0 },
6634Srgrimes
6644Srgrimes/*78*/	{ "js",    FALSE, NONE,  op1(Db),     0 },
6654Srgrimes/*79*/	{ "jns",   FALSE, NONE,  op1(Db),     0 },
6664Srgrimes/*7a*/	{ "jp",    FALSE, NONE,  op1(Db),     0 },
6674Srgrimes/*7b*/	{ "jnp",   FALSE, NONE,  op1(Db),     0 },
6684Srgrimes/*7c*/	{ "jl",    FALSE, NONE,  op1(Db),     0 },
6694Srgrimes/*7d*/	{ "jnl",   FALSE, NONE,  op1(Db),     0 },
6704Srgrimes/*7e*/	{ "jle",   FALSE, NONE,  op1(Db),     0 },
6714Srgrimes/*7f*/	{ "jnle",  FALSE, NONE,  op1(Db),     0 },
6724Srgrimes
67317109Sbde/*80*/  { "",	   TRUE,  BYTE,  op2(I, E),   db_Grp1 },
67417109Sbde/*81*/  { "",	   TRUE,  LONG,  op2(I, E),   db_Grp1 },
67517109Sbde/*82*/  { "",	   TRUE,  BYTE,  op2(Is,E),   db_Grp1 },
67617109Sbde/*83*/  { "",	   TRUE,  LONG,  op2(Ibs,E),  db_Grp1 },
6774Srgrimes/*84*/	{ "test",  TRUE,  BYTE,  op2(R, E),   0 },
6784Srgrimes/*85*/	{ "test",  TRUE,  LONG,  op2(R, E),   0 },
6794Srgrimes/*86*/	{ "xchg",  TRUE,  BYTE,  op2(R, E),   0 },
6804Srgrimes/*87*/	{ "xchg",  TRUE,  LONG,  op2(R, E),   0 },
6814Srgrimes
6824Srgrimes/*88*/	{ "mov",   TRUE,  BYTE,  op2(R, E),   0 },
6834Srgrimes/*89*/	{ "mov",   TRUE,  LONG,  op2(R, E),   0 },
6844Srgrimes/*8a*/	{ "mov",   TRUE,  BYTE,  op2(E, R),   0 },
6854Srgrimes/*8b*/	{ "mov",   TRUE,  LONG,  op2(E, R),   0 },
6864Srgrimes/*8c*/  { "mov",   TRUE,  NONE,  op2(S, Ew),  0 },
6874Srgrimes/*8d*/	{ "lea",   TRUE,  LONG,  op2(E, R),   0 },
6884Srgrimes/*8e*/	{ "mov",   TRUE,  NONE,  op2(Ew, S),  0 },
6894Srgrimes/*8f*/	{ "pop",   TRUE,  LONG,  op1(E),      0 },
6904Srgrimes
6914Srgrimes/*90*/	{ "nop",   FALSE, NONE,  0,	      0 },
6924Srgrimes/*91*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
6934Srgrimes/*92*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
6944Srgrimes/*93*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
6954Srgrimes/*94*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
6964Srgrimes/*95*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
6974Srgrimes/*96*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
6984Srgrimes/*97*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
6994Srgrimes
7004Srgrimes/*98*/	{ "cbw",   FALSE, SDEP,  0,	      "cwde" },	/* cbw/cwde */
7014Srgrimes/*99*/	{ "cwd",   FALSE, SDEP,  0,	      "cdq"  },	/* cwd/cdq */
7024Srgrimes/*9a*/	{ "lcall", FALSE, NONE,  op1(OS),     0 },
7034Srgrimes/*9b*/	{ "wait",  FALSE, NONE,  0,	      0 },
7044Srgrimes/*9c*/	{ "pushf", FALSE, LONG,  0,	      0 },
7054Srgrimes/*9d*/	{ "popf",  FALSE, LONG,  0,	      0 },
7064Srgrimes/*9e*/	{ "sahf",  FALSE, NONE,  0,	      0 },
7074Srgrimes/*9f*/	{ "lahf",  FALSE, NONE,  0,	      0 },
7084Srgrimes
7094Srgrimes/*a0*/	{ "mov",   FALSE, BYTE,  op2(O, A),   0 },
7104Srgrimes/*a1*/	{ "mov",   FALSE, LONG,  op2(O, A),   0 },
7114Srgrimes/*a2*/	{ "mov",   FALSE, BYTE,  op2(A, O),   0 },
7124Srgrimes/*a3*/	{ "mov",   FALSE, LONG,  op2(A, O),   0 },
7134Srgrimes/*a4*/	{ "movs",  FALSE, BYTE,  op2(SI,DI),  0 },
7144Srgrimes/*a5*/	{ "movs",  FALSE, LONG,  op2(SI,DI),  0 },
7154Srgrimes/*a6*/	{ "cmps",  FALSE, BYTE,  op2(SI,DI),  0 },
7164Srgrimes/*a7*/	{ "cmps",  FALSE, LONG,  op2(SI,DI),  0 },
7174Srgrimes
7184Srgrimes/*a8*/	{ "test",  FALSE, BYTE,  op2(I, A),   0 },
7194Srgrimes/*a9*/	{ "test",  FALSE, LONG,  op2(I, A),   0 },
7204Srgrimes/*aa*/	{ "stos",  FALSE, BYTE,  op1(DI),     0 },
7214Srgrimes/*ab*/	{ "stos",  FALSE, LONG,  op1(DI),     0 },
722118Srgrimes/*ac*/	{ "lods",  FALSE, BYTE,  op1(SI),     0 },
723118Srgrimes/*ad*/	{ "lods",  FALSE, LONG,  op1(SI),     0 },
7244Srgrimes/*ae*/	{ "scas",  FALSE, BYTE,  op1(SI),     0 },
7254Srgrimes/*af*/	{ "scas",  FALSE, LONG,  op1(SI),     0 },
7264Srgrimes
7274Srgrimes/*b0*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
7284Srgrimes/*b1*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
7294Srgrimes/*b2*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
7304Srgrimes/*b3*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
7314Srgrimes/*b4*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
7324Srgrimes/*b5*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
7334Srgrimes/*b6*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
7344Srgrimes/*b7*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
7354Srgrimes
7364Srgrimes/*b8*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
7374Srgrimes/*b9*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
7384Srgrimes/*ba*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
7394Srgrimes/*bb*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
7404Srgrimes/*bc*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
7414Srgrimes/*bd*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
7424Srgrimes/*be*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
7434Srgrimes/*bf*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
7444Srgrimes
74517109Sbde/*c0*/	{ "",	   TRUE,  BYTE,  op2(Ib, E),  db_Grp2 },
74617109Sbde/*c1*/	{ "",	   TRUE,  LONG,  op2(Ib, E),  db_Grp2 },
7474Srgrimes/*c2*/	{ "ret",   FALSE, NONE,  op1(Iw),     0 },
7484Srgrimes/*c3*/	{ "ret",   FALSE, NONE,  0,	      0 },
7494Srgrimes/*c4*/	{ "les",   TRUE,  LONG,  op2(E, R),   0 },
7504Srgrimes/*c5*/	{ "lds",   TRUE,  LONG,  op2(E, R),   0 },
7514Srgrimes/*c6*/	{ "mov",   TRUE,  BYTE,  op2(I, E),   0 },
7524Srgrimes/*c7*/	{ "mov",   TRUE,  LONG,  op2(I, E),   0 },
7534Srgrimes
7544Srgrimes/*c8*/	{ "enter", FALSE, NONE,  op2(Ib, Iw), 0 },
7554Srgrimes/*c9*/	{ "leave", FALSE, NONE,  0,           0 },
7564Srgrimes/*ca*/	{ "lret",  FALSE, NONE,  op1(Iw),     0 },
7574Srgrimes/*cb*/	{ "lret",  FALSE, NONE,  0,	      0 },
7584Srgrimes/*cc*/	{ "int",   FALSE, NONE,  op1(o3),     0 },
7594Srgrimes/*cd*/	{ "int",   FALSE, NONE,  op1(Ib),     0 },
7604Srgrimes/*ce*/	{ "into",  FALSE, NONE,  0,	      0 },
7614Srgrimes/*cf*/	{ "iret",  FALSE, NONE,  0,	      0 },
7624Srgrimes
76317109Sbde/*d0*/	{ "",	   TRUE,  BYTE,  op2(o1, E),  db_Grp2 },
76417109Sbde/*d1*/	{ "",	   TRUE,  LONG,  op2(o1, E),  db_Grp2 },
76517109Sbde/*d2*/	{ "",	   TRUE,  BYTE,  op2(CL, E),  db_Grp2 },
76617109Sbde/*d3*/	{ "",	   TRUE,  LONG,  op2(CL, E),  db_Grp2 },
7674Srgrimes/*d4*/	{ "aam",   TRUE,  NONE,  0,	      0 },
7684Srgrimes/*d5*/	{ "aad",   TRUE,  NONE,  0,	      0 },
7694Srgrimes/*d6*/	{ "",      FALSE, NONE,  0,	      0 },
7704Srgrimes/*d7*/	{ "xlat",  FALSE, BYTE,  op1(BX),     0 },
7714Srgrimes
77217109Sbde/*d8*/  { "",      TRUE,  NONE,  0,	      db_Esc8 },
77317109Sbde/*d9*/  { "",      TRUE,  NONE,  0,	      db_Esc9 },
77417109Sbde/*da*/  { "",      TRUE,  NONE,  0,	      db_Esca },
77517109Sbde/*db*/  { "",      TRUE,  NONE,  0,	      db_Escb },
77617109Sbde/*dc*/  { "",      TRUE,  NONE,  0,	      db_Escc },
77717109Sbde/*dd*/  { "",      TRUE,  NONE,  0,	      db_Escd },
77817109Sbde/*de*/  { "",      TRUE,  NONE,  0,	      db_Esce },
77917109Sbde/*df*/  { "",      TRUE,  NONE,  0,	      db_Escf },
7804Srgrimes
7814Srgrimes/*e0*/	{ "loopne",FALSE, NONE,  op1(Db),     0 },
7824Srgrimes/*e1*/	{ "loope", FALSE, NONE,  op1(Db),     0 },
7834Srgrimes/*e2*/	{ "loop",  FALSE, NONE,  op1(Db),     0 },
7844Srgrimes/*e3*/	{ "jcxz",  FALSE, SDEP,  op1(Db),     "jecxz" },
7854Srgrimes/*e4*/	{ "in",    FALSE, BYTE,  op2(Ib, A),  0 },
7864Srgrimes/*e5*/	{ "in",    FALSE, LONG,  op2(Ib, A) , 0 },
7874Srgrimes/*e6*/	{ "out",   FALSE, BYTE,  op2(A, Ib),  0 },
7884Srgrimes/*e7*/	{ "out",   FALSE, LONG,  op2(A, Ib) , 0 },
7894Srgrimes
7904Srgrimes/*e8*/	{ "call",  FALSE, NONE,  op1(Dl),     0 },
7914Srgrimes/*e9*/	{ "jmp",   FALSE, NONE,  op1(Dl),     0 },
7924Srgrimes/*ea*/	{ "ljmp",  FALSE, NONE,  op1(OS),     0 },
7934Srgrimes/*eb*/	{ "jmp",   FALSE, NONE,  op1(Db),     0 },
7944Srgrimes/*ec*/	{ "in",    FALSE, BYTE,  op2(DX, A),  0 },
7954Srgrimes/*ed*/	{ "in",    FALSE, LONG,  op2(DX, A) , 0 },
7964Srgrimes/*ee*/	{ "out",   FALSE, BYTE,  op2(A, DX),  0 },
7974Srgrimes/*ef*/	{ "out",   FALSE, LONG,  op2(A, DX) , 0 },
7984Srgrimes
7994Srgrimes/*f0*/	{ "",      FALSE, NONE,  0,	     0 },
8004Srgrimes/*f1*/	{ "",      FALSE, NONE,  0,	     0 },
8014Srgrimes/*f2*/	{ "",      FALSE, NONE,  0,	     0 },
8024Srgrimes/*f3*/	{ "",      FALSE, NONE,  0,	     0 },
8034Srgrimes/*f4*/	{ "hlt",   FALSE, NONE,  0,	     0 },
8044Srgrimes/*f5*/	{ "cmc",   FALSE, NONE,  0,	     0 },
80517109Sbde/*f6*/	{ "",      TRUE,  BYTE,  0,	     db_Grp3 },
80617109Sbde/*f7*/	{ "",	   TRUE,  LONG,  0,	     db_Grp3 },
8074Srgrimes
8084Srgrimes/*f8*/	{ "clc",   FALSE, NONE,  0,	     0 },
8094Srgrimes/*f9*/	{ "stc",   FALSE, NONE,  0,	     0 },
8104Srgrimes/*fa*/	{ "cli",   FALSE, NONE,  0,	     0 },
8114Srgrimes/*fb*/	{ "sti",   FALSE, NONE,  0,	     0 },
8124Srgrimes/*fc*/	{ "cld",   FALSE, NONE,  0,	     0 },
8134Srgrimes/*fd*/	{ "std",   FALSE, NONE,  0,	     0 },
81417109Sbde/*fe*/	{ "",	   TRUE,  NONE,  0,	     db_Grp4 },
81517109Sbde/*ff*/	{ "",	   TRUE,  NONE,  0,	     db_Grp5 },
8164Srgrimes};
8174Srgrimes
81817109Sbdestatic const struct inst db_bad_inst =
8194Srgrimes	{ "???",   FALSE, NONE,  0,	      0 }
8204Srgrimes;
8214Srgrimes
8224Srgrimes#define	f_mod(byte)	((byte)>>6)
8234Srgrimes#define	f_reg(byte)	(((byte)>>3)&0x7)
8244Srgrimes#define	f_rm(byte)	((byte)&0x7)
8254Srgrimes
8264Srgrimes#define	sib_ss(byte)	((byte)>>6)
8274Srgrimes#define	sib_index(byte)	(((byte)>>3)&0x7)
8284Srgrimes#define	sib_base(byte)	((byte)&0x7)
8294Srgrimes
83011940Sbdestruct i_addr {
8314Srgrimes	int		is_reg;	/* if reg, reg number is in 'disp' */
8324Srgrimes	int		disp;
83314887Swollman	const char *	base;
83414887Swollman	const char *	index;
8354Srgrimes	int		ss;
8364Srgrimes};
8374Srgrimes
83814887Swollmanstatic const char * const db_index_reg_16[8] = {
8394Srgrimes	"%bx,%si",
8404Srgrimes	"%bx,%di",
8414Srgrimes	"%bp,%si",
8424Srgrimes	"%bp,%di",
8434Srgrimes	"%si",
8444Srgrimes	"%di",
8454Srgrimes	"%bp",
8464Srgrimes	"%bx"
8474Srgrimes};
8484Srgrimes
84914887Swollmanstatic const char * const db_reg[3][8] = {
8504Srgrimes	"%al",  "%cl",  "%dl",  "%bl",  "%ah",  "%ch",  "%dh",  "%bh",
8514Srgrimes	"%ax",  "%cx",  "%dx",  "%bx",  "%sp",  "%bp",  "%si",  "%di",
8524Srgrimes	"%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi"
8534Srgrimes};
8544Srgrimes
85517109Sbdestatic const char * const db_seg_reg[8] = {
8564Srgrimes	"%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
8574Srgrimes};
8584Srgrimes
8594Srgrimes/*
8604Srgrimes * lengths for size attributes
8614Srgrimes */
86214887Swollmanstatic const int db_lengths[] = {
8634Srgrimes	1,	/* BYTE */
8644Srgrimes	2,	/* WORD */
8654Srgrimes	4,	/* LONG */
8664Srgrimes	8,	/* QUAD */
8674Srgrimes	4,	/* SNGL */
8684Srgrimes	8,	/* DBLR */
8694Srgrimes	10,	/* EXTR */
8704Srgrimes};
8714Srgrimes
8724Srgrimes#define	get_value_inc(result, loc, size, is_signed) \
8734Srgrimes	result = db_get_value((loc), (size), (is_signed)); \
8744Srgrimes	(loc) += (size);
8754Srgrimes
87611940Sbdestatic db_addr_t
87711940Sbde		db_disasm_esc __P((db_addr_t loc, int inst, int short_addr,
87817109Sbde				   int size, const char *seg));
87917109Sbdestatic void	db_print_address __P((const char *seg, int size,
88011940Sbde				      struct i_addr *addrp));
88111940Sbdestatic db_addr_t
88211940Sbde		db_read_address __P((db_addr_t loc, int short_addr,
88311940Sbde				     int regmodrm, struct i_addr *addrp));
88411940Sbde
8854Srgrimes/*
8864Srgrimes * Read address at location and return updated location.
8874Srgrimes */
88811921Sphkstatic db_addr_t
8894Srgrimesdb_read_address(loc, short_addr, regmodrm, addrp)
8904Srgrimes	db_addr_t	loc;
8914Srgrimes	int		short_addr;
8924Srgrimes	int		regmodrm;
89317109Sbde	struct i_addr *	addrp;		/* out */
8944Srgrimes{
8953436Sphk	int		mod, rm, sib, index, disp;
8964Srgrimes
8974Srgrimes	mod = f_mod(regmodrm);
8984Srgrimes	rm  = f_rm(regmodrm);
8994Srgrimes
9004Srgrimes	if (mod == 3) {
9014Srgrimes	    addrp->is_reg = TRUE;
9024Srgrimes	    addrp->disp = rm;
9034Srgrimes	    return (loc);
9044Srgrimes	}
9054Srgrimes	addrp->is_reg = FALSE;
9064Srgrimes	addrp->index = 0;
9074Srgrimes
9084Srgrimes	if (short_addr) {
9094Srgrimes	    addrp->index = 0;
9104Srgrimes	    addrp->ss = 0;
9114Srgrimes	    switch (mod) {
9124Srgrimes		case 0:
9134Srgrimes		    if (rm == 6) {
9144Srgrimes			get_value_inc(disp, loc, 2, TRUE);
9154Srgrimes			addrp->disp = disp;
9164Srgrimes			addrp->base = 0;
9174Srgrimes		    }
9184Srgrimes		    else {
9194Srgrimes			addrp->disp = 0;
9204Srgrimes			addrp->base = db_index_reg_16[rm];
9214Srgrimes		    }
9224Srgrimes		    break;
9234Srgrimes		case 1:
9244Srgrimes		    get_value_inc(disp, loc, 1, TRUE);
9254Srgrimes		    addrp->disp = disp;
9264Srgrimes		    addrp->base = db_index_reg_16[rm];
9274Srgrimes		    break;
9284Srgrimes		case 2:
9294Srgrimes		    get_value_inc(disp, loc, 2, TRUE);
9304Srgrimes		    addrp->disp = disp;
9314Srgrimes		    addrp->base = db_index_reg_16[rm];
9324Srgrimes		    break;
9334Srgrimes	    }
9344Srgrimes	}
9354Srgrimes	else {
9364Srgrimes	    if (mod != 3 && rm == 4) {
9374Srgrimes		get_value_inc(sib, loc, 1, FALSE);
9384Srgrimes		rm = sib_base(sib);
9394Srgrimes		index = sib_index(sib);
9404Srgrimes		if (index != 4)
9414Srgrimes		    addrp->index = db_reg[LONG][index];
9424Srgrimes		addrp->ss = sib_ss(sib);
9434Srgrimes	    }
9444Srgrimes
9454Srgrimes	    switch (mod) {
9464Srgrimes		case 0:
9474Srgrimes		    if (rm == 5) {
9484Srgrimes			get_value_inc(addrp->disp, loc, 4, FALSE);
9494Srgrimes			addrp->base = 0;
9504Srgrimes		    }
9514Srgrimes		    else {
9524Srgrimes			addrp->disp = 0;
9534Srgrimes			addrp->base = db_reg[LONG][rm];
9544Srgrimes		    }
9554Srgrimes		    break;
9564Srgrimes
9574Srgrimes		case 1:
9584Srgrimes		    get_value_inc(disp, loc, 1, TRUE);
9594Srgrimes		    addrp->disp = disp;
9604Srgrimes		    addrp->base = db_reg[LONG][rm];
9614Srgrimes		    break;
9624Srgrimes
9634Srgrimes		case 2:
9644Srgrimes		    get_value_inc(disp, loc, 4, FALSE);
9654Srgrimes		    addrp->disp = disp;
9664Srgrimes		    addrp->base = db_reg[LONG][rm];
9674Srgrimes		    break;
9684Srgrimes	    }
9694Srgrimes	}
9704Srgrimes	return (loc);
9714Srgrimes}
9724Srgrimes
97311921Sphkstatic void
9744Srgrimesdb_print_address(seg, size, addrp)
97517109Sbde	const char *	seg;
9764Srgrimes	int		size;
97717109Sbde	struct i_addr *	addrp;
9784Srgrimes{
9794Srgrimes	if (addrp->is_reg) {
9804Srgrimes	    db_printf("%s", db_reg[size][addrp->disp]);
9814Srgrimes	    return;
9824Srgrimes	}
9834Srgrimes
9844Srgrimes	if (seg) {
9854Srgrimes	    db_printf("%s:", seg);
9864Srgrimes	}
9874Srgrimes
9884Srgrimes	db_printsym((db_addr_t)addrp->disp, DB_STGY_ANY);
9894Srgrimes	if (addrp->base != 0 || addrp->index != 0) {
9904Srgrimes	    db_printf("(");
9914Srgrimes	    if (addrp->base)
9924Srgrimes		db_printf("%s", addrp->base);
9934Srgrimes	    if (addrp->index)
9944Srgrimes		db_printf(",%s,%d", addrp->index, 1<<addrp->ss);
9954Srgrimes	    db_printf(")");
9964Srgrimes	}
9974Srgrimes}
9984Srgrimes
9994Srgrimes/*
10004Srgrimes * Disassemble floating-point ("escape") instruction
10014Srgrimes * and return updated location.
10024Srgrimes */
100311921Sphkstatic db_addr_t
10044Srgrimesdb_disasm_esc(loc, inst, short_addr, size, seg)
10054Srgrimes	db_addr_t	loc;
10064Srgrimes	int		inst;
10074Srgrimes	int		short_addr;
10084Srgrimes	int		size;
100917109Sbde	const char *	seg;
10104Srgrimes{
10114Srgrimes	int		regmodrm;
101217109Sbde	const struct finst *	fp;
10134Srgrimes	int		mod;
10144Srgrimes	struct i_addr	address;
101517109Sbde	const char *	name;
10164Srgrimes
10174Srgrimes	get_value_inc(regmodrm, loc, 1, FALSE);
10184Srgrimes	fp = &db_Esc_inst[inst - 0xd8][f_reg(regmodrm)];
10194Srgrimes	mod = f_mod(regmodrm);
10204Srgrimes	if (mod != 3) {
10214Srgrimes	    /*
10224Srgrimes	     * Normal address modes.
10234Srgrimes	     */
10244Srgrimes	    loc = db_read_address(loc, short_addr, regmodrm, &address);
10254Srgrimes	    db_printf(fp->f_name);
10264Srgrimes	    switch(fp->f_size) {
10274Srgrimes		case SNGL:
10284Srgrimes		    db_printf("s");
10294Srgrimes		    break;
10304Srgrimes		case DBLR:
10314Srgrimes		    db_printf("l");
10324Srgrimes		    break;
10334Srgrimes		case EXTR:
10344Srgrimes		    db_printf("t");
10354Srgrimes		    break;
10364Srgrimes		case WORD:
10374Srgrimes		    db_printf("s");
10384Srgrimes		    break;
10394Srgrimes		case LONG:
10404Srgrimes		    db_printf("l");
10414Srgrimes		    break;
10424Srgrimes		case QUAD:
10434Srgrimes		    db_printf("q");
10444Srgrimes		    break;
10454Srgrimes		default:
10464Srgrimes		    break;
10474Srgrimes	    }
10484Srgrimes	    db_printf("\t");
10494Srgrimes	    db_print_address(seg, BYTE, &address);
10504Srgrimes	}
10514Srgrimes	else {
10524Srgrimes	    /*
10534Srgrimes	     * 'reg-reg' - special formats
10544Srgrimes	     */
10554Srgrimes	    switch (fp->f_rrmode) {
10564Srgrimes		case op2(ST,STI):
10574Srgrimes		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
10584Srgrimes		    db_printf("%s\t%%st,%%st(%d)",name,f_rm(regmodrm));
10594Srgrimes		    break;
10604Srgrimes		case op2(STI,ST):
10614Srgrimes		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
10624Srgrimes		    db_printf("%s\t%%st(%d),%%st",name, f_rm(regmodrm));
10634Srgrimes		    break;
10644Srgrimes		case op1(STI):
10654Srgrimes		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
10664Srgrimes		    db_printf("%s\t%%st(%d)",name, f_rm(regmodrm));
10674Srgrimes		    break;
10684Srgrimes		case op1(X):
106917109Sbde		    db_printf("%s",
107017109Sbde			((const char * const *)fp->f_rrname)[f_rm(regmodrm)]);
10714Srgrimes		    break;
10724Srgrimes		case op1(XA):
10734Srgrimes		    db_printf("%s\t%%ax",
107417109Sbde			((const char * const *)fp->f_rrname)[f_rm(regmodrm)]);
10754Srgrimes		    break;
10764Srgrimes		default:
10774Srgrimes		    db_printf("<bad instruction>");
10784Srgrimes		    break;
10794Srgrimes	    }
10804Srgrimes	}
10814Srgrimes
10824Srgrimes	return (loc);
10834Srgrimes}
10844Srgrimes
10854Srgrimes/*
10864Srgrimes * Disassemble instruction at 'loc'.  'altfmt' specifies an
10874Srgrimes * (optional) alternate format.  Return address of start of
10884Srgrimes * next instruction.
10894Srgrimes */
10904Srgrimesdb_addr_t
10914Srgrimesdb_disasm(loc, altfmt)
10924Srgrimes	db_addr_t	loc;
10934Srgrimes	boolean_t	altfmt;
10944Srgrimes{
10954Srgrimes	int	inst;
10964Srgrimes	int	size;
10974Srgrimes	int	short_addr;
109817109Sbde	const char *	seg;
109914887Swollman	const struct inst *	ip;
110014887Swollman	const char *	i_name;
11014Srgrimes	int	i_size;
11024Srgrimes	int	i_mode;
1103798Swollman	int	regmodrm = 0;
11044Srgrimes	boolean_t	first;
11054Srgrimes	int	displ;
11064Srgrimes	int	prefix;
11074Srgrimes	int	imm;
11084Srgrimes	int	imm2;
11094Srgrimes	int	len;
11104Srgrimes	struct i_addr	address;
11114Srgrimes
11124Srgrimes	get_value_inc(inst, loc, 1, FALSE);
11134Srgrimes	short_addr = FALSE;
11144Srgrimes	size = LONG;
11154Srgrimes	seg = 0;
11164Srgrimes
11174Srgrimes	/*
11184Srgrimes	 * Get prefixes
11194Srgrimes	 */
11204Srgrimes	prefix = TRUE;
11214Srgrimes	do {
11224Srgrimes	    switch (inst) {
11234Srgrimes		case 0x66:		/* data16 */
11244Srgrimes		    size = WORD;
11254Srgrimes		    break;
11264Srgrimes		case 0x67:
11274Srgrimes		    short_addr = TRUE;
11284Srgrimes		    break;
11294Srgrimes		case 0x26:
11304Srgrimes		    seg = "%es";
11314Srgrimes		    break;
11324Srgrimes		case 0x36:
11334Srgrimes		    seg = "%ss";
11344Srgrimes		    break;
11354Srgrimes		case 0x2e:
11364Srgrimes		    seg = "%cs";
11374Srgrimes		    break;
11384Srgrimes		case 0x3e:
11394Srgrimes		    seg = "%ds";
11404Srgrimes		    break;
11414Srgrimes		case 0x64:
11424Srgrimes		    seg = "%fs";
11434Srgrimes		    break;
11444Srgrimes		case 0x65:
11454Srgrimes		    seg = "%gs";
11464Srgrimes		    break;
11474Srgrimes		case 0xf0:
11484Srgrimes		    db_printf("lock ");
11494Srgrimes		    break;
11504Srgrimes		case 0xf2:
11514Srgrimes		    db_printf("repne ");
11524Srgrimes		    break;
11534Srgrimes		case 0xf3:
11544Srgrimes		    db_printf("repe ");	/* XXX repe VS rep */
11554Srgrimes		    break;
11564Srgrimes		default:
11574Srgrimes		    prefix = FALSE;
11584Srgrimes		    break;
11594Srgrimes	    }
11604Srgrimes	    if (prefix) {
11614Srgrimes		get_value_inc(inst, loc, 1, FALSE);
11624Srgrimes	    }
11634Srgrimes	} while (prefix);
11644Srgrimes
11654Srgrimes	if (inst >= 0xd8 && inst <= 0xdf) {
11664Srgrimes	    loc = db_disasm_esc(loc, inst, short_addr, size, seg);
11674Srgrimes	    db_printf("\n");
11684Srgrimes	    return (loc);
11694Srgrimes	}
11704Srgrimes
11714Srgrimes	if (inst == 0x0f) {
11724Srgrimes	    get_value_inc(inst, loc, 1, FALSE);
11734Srgrimes	    ip = db_inst_0f[inst>>4];
11744Srgrimes	    if (ip == 0) {
11754Srgrimes		ip = &db_bad_inst;
11764Srgrimes	    }
11774Srgrimes	    else {
11784Srgrimes		ip = &ip[inst&0xf];
11794Srgrimes	    }
11804Srgrimes	}
11814Srgrimes	else
11824Srgrimes	    ip = &db_inst_table[inst];
11834Srgrimes
11844Srgrimes	if (ip->i_has_modrm) {
11854Srgrimes	    get_value_inc(regmodrm, loc, 1, FALSE);
11864Srgrimes	    loc = db_read_address(loc, short_addr, regmodrm, &address);
11874Srgrimes	}
11884Srgrimes
11894Srgrimes	i_name = ip->i_name;
11904Srgrimes	i_size = ip->i_size;
11914Srgrimes	i_mode = ip->i_mode;
11924Srgrimes
119317109Sbde	if (ip->i_extra == db_Grp1 || ip->i_extra == db_Grp2 ||
119417109Sbde	    ip->i_extra == db_Grp6 || ip->i_extra == db_Grp7 ||
119517109Sbde	    ip->i_extra == db_Grp8) {
119617109Sbde	    i_name = ((const char * const *)ip->i_extra)[f_reg(regmodrm)];
11974Srgrimes	}
119817109Sbde	else if (ip->i_extra == db_Grp3) {
119917109Sbde	    ip = ip->i_extra;
12004Srgrimes	    ip = &ip[f_reg(regmodrm)];
12014Srgrimes	    i_name = ip->i_name;
12024Srgrimes	    i_mode = ip->i_mode;
12034Srgrimes	}
120417109Sbde	else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) {
120517109Sbde	    ip = ip->i_extra;
12064Srgrimes	    ip = &ip[f_reg(regmodrm)];
12074Srgrimes	    i_name = ip->i_name;
12084Srgrimes	    i_mode = ip->i_mode;
12094Srgrimes	    i_size = ip->i_size;
12104Srgrimes	}
12114Srgrimes
12124Srgrimes	if (i_size == SDEP) {
12134Srgrimes	    if (size == WORD)
12144Srgrimes		db_printf(i_name);
12154Srgrimes	    else
121617109Sbde		db_printf((const char *)ip->i_extra);
12174Srgrimes	}
12184Srgrimes	else {
12194Srgrimes	    db_printf(i_name);
12204Srgrimes	    if (i_size != NONE) {
12214Srgrimes		if (i_size == BYTE) {
12224Srgrimes		    db_printf("b");
12234Srgrimes		    size = BYTE;
12244Srgrimes		}
12254Srgrimes		else if (i_size == WORD) {
12264Srgrimes		    db_printf("w");
12274Srgrimes		    size = WORD;
12284Srgrimes		}
12294Srgrimes		else if (size == WORD)
12304Srgrimes		    db_printf("w");
12314Srgrimes		else
12324Srgrimes		    db_printf("l");
12334Srgrimes	    }
12344Srgrimes	}
12354Srgrimes	db_printf("\t");
12364Srgrimes	for (first = TRUE;
12374Srgrimes	     i_mode != 0;
12384Srgrimes	     i_mode >>= 8, first = FALSE)
12394Srgrimes	{
12404Srgrimes	    if (!first)
12414Srgrimes		db_printf(",");
12424Srgrimes
12434Srgrimes	    switch (i_mode & 0xFF) {
12444Srgrimes
12454Srgrimes		case E:
12464Srgrimes		    db_print_address(seg, size, &address);
12474Srgrimes		    break;
12484Srgrimes
12494Srgrimes		case Eind:
12504Srgrimes		    db_printf("*");
12514Srgrimes		    db_print_address(seg, size, &address);
12524Srgrimes		    break;
12534Srgrimes
12544Srgrimes		case Ew:
12554Srgrimes		    db_print_address(seg, WORD, &address);
12564Srgrimes		    break;
12574Srgrimes
12584Srgrimes		case Eb:
12594Srgrimes		    db_print_address(seg, BYTE, &address);
12604Srgrimes		    break;
12614Srgrimes
12624Srgrimes		case R:
12634Srgrimes		    db_printf("%s", db_reg[size][f_reg(regmodrm)]);
12644Srgrimes		    break;
12654Srgrimes
12664Srgrimes		case Rw:
12674Srgrimes		    db_printf("%s", db_reg[WORD][f_reg(regmodrm)]);
12684Srgrimes		    break;
12694Srgrimes
12704Srgrimes		case Ri:
12714Srgrimes		    db_printf("%s", db_reg[size][f_rm(inst)]);
12724Srgrimes		    break;
12734Srgrimes
12744Srgrimes		case S:
12754Srgrimes		    db_printf("%s", db_seg_reg[f_reg(regmodrm)]);
12764Srgrimes		    break;
12774Srgrimes
12784Srgrimes		case Si:
12794Srgrimes		    db_printf("%s", db_seg_reg[f_reg(inst)]);
12804Srgrimes		    break;
12814Srgrimes
12824Srgrimes		case A:
12834Srgrimes		    db_printf("%s", db_reg[size][0]);	/* acc */
12844Srgrimes		    break;
12854Srgrimes
12864Srgrimes		case BX:
12874Srgrimes		    if (seg)
12884Srgrimes			db_printf("%s:", seg);
12894Srgrimes		    db_printf("(%s)", short_addr ? "%bx" : "%ebx");
12904Srgrimes		    break;
12914Srgrimes
12924Srgrimes		case CL:
12934Srgrimes		    db_printf("%%cl");
12944Srgrimes		    break;
12954Srgrimes
12964Srgrimes		case DX:
12974Srgrimes		    db_printf("%%dx");
12984Srgrimes		    break;
12994Srgrimes
13004Srgrimes		case SI:
13014Srgrimes		    if (seg)
13024Srgrimes			db_printf("%s:", seg);
13034Srgrimes		    db_printf("(%s)", short_addr ? "%si" : "%esi");
13044Srgrimes		    break;
13054Srgrimes
13064Srgrimes		case DI:
13074Srgrimes		    db_printf("%%es:(%s)", short_addr ? "%di" : "%edi");
13084Srgrimes		    break;
13094Srgrimes
13104Srgrimes		case CR:
13114Srgrimes		    db_printf("%%cr%d", f_reg(regmodrm));
13124Srgrimes		    break;
13134Srgrimes
13144Srgrimes		case DR:
13154Srgrimes		    db_printf("%%dr%d", f_reg(regmodrm));
13164Srgrimes		    break;
13174Srgrimes
13184Srgrimes		case TR:
13194Srgrimes		    db_printf("%%tr%d", f_reg(regmodrm));
13204Srgrimes		    break;
13214Srgrimes
13224Srgrimes		case I:
13234Srgrimes		    len = db_lengths[size];
13244Srgrimes		    get_value_inc(imm, loc, len, FALSE);/* unsigned */
13254Srgrimes		    db_printf("$%#n", imm);
13264Srgrimes		    break;
13274Srgrimes
13284Srgrimes		case Is:
13294Srgrimes		    len = db_lengths[size];
13304Srgrimes		    get_value_inc(imm, loc, len, TRUE);	/* signed */
133113446Sphk		    db_printf("$%+#n", imm);
13324Srgrimes		    break;
13334Srgrimes
13344Srgrimes		case Ib:
13354Srgrimes		    get_value_inc(imm, loc, 1, FALSE);	/* unsigned */
13364Srgrimes		    db_printf("$%#n", imm);
13374Srgrimes		    break;
13384Srgrimes
13394Srgrimes		case Ibs:
13404Srgrimes		    get_value_inc(imm, loc, 1, TRUE);	/* signed */
134113446Sphk		    db_printf("$%+#n", imm);
13424Srgrimes		    break;
13434Srgrimes
13444Srgrimes		case Iw:
13454Srgrimes		    get_value_inc(imm, loc, 2, FALSE);	/* unsigned */
13464Srgrimes		    db_printf("$%#n", imm);
13474Srgrimes		    break;
13484Srgrimes
13494Srgrimes		case Il:
13504Srgrimes		    get_value_inc(imm, loc, 4, FALSE);
13514Srgrimes		    db_printf("$%#n", imm);
13524Srgrimes		    break;
13534Srgrimes
13544Srgrimes		case O:
13554Srgrimes		    if (short_addr) {
13564Srgrimes			get_value_inc(displ, loc, 2, TRUE);
13574Srgrimes		    }
13584Srgrimes		    else {
13594Srgrimes			get_value_inc(displ, loc, 4, TRUE);
13604Srgrimes		    }
13614Srgrimes		    if (seg)
136213446Sphk			db_printf("%s:%+#n",seg, displ);
13634Srgrimes		    else
13644Srgrimes			db_printsym((db_addr_t)displ, DB_STGY_ANY);
13654Srgrimes		    break;
13664Srgrimes
13674Srgrimes		case Db:
13684Srgrimes		    get_value_inc(displ, loc, 1, TRUE);
13694Srgrimes		    db_printsym((db_addr_t)(displ + loc), DB_STGY_XTRN);
13704Srgrimes		    break;
13714Srgrimes
13724Srgrimes		case Dl:
13734Srgrimes		    get_value_inc(displ, loc, 4, TRUE);
13744Srgrimes		    db_printsym((db_addr_t)(displ + loc), DB_STGY_XTRN);
13754Srgrimes		    break;
13764Srgrimes
13774Srgrimes		case o1:
13784Srgrimes		    db_printf("$1");
13794Srgrimes		    break;
13804Srgrimes
13814Srgrimes		case o3:
13824Srgrimes		    db_printf("$3");
13834Srgrimes		    break;
13844Srgrimes
13854Srgrimes		case OS:
13864Srgrimes		    get_value_inc(imm, loc, 4, FALSE);	/* offset */
13874Srgrimes		    get_value_inc(imm2, loc, 2, FALSE);	/* segment */
13884Srgrimes		    db_printf("$%#n,%#n", imm2, imm);
13894Srgrimes		    break;
13904Srgrimes	    }
13914Srgrimes	}
13924Srgrimes	db_printf("\n");
13934Srgrimes	return (loc);
13944Srgrimes}
13954Srgrimes
1396