*BSD News Article 6355


Return to BSD News archive

Newsgroups: comp.unix.bsd
Path: sserve!manuel.anu.edu.au!munnari.oz.au!spool.mu.edu!news.cs.indiana.edu!umn.edu!csus.edu!netcom.com!jtk
From: jtk@netcom.com (Jane Valencia)
Subject: [386BSD] crash 2/2
Message-ID: <1992Oct10.211407.4973@netcom.com>
Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
Date: Sat, 10 Oct 1992 21:14:07 GMT
Lines: 1668

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	disasm.c
#	dump.c
#
echo x - disasm.c
sed 's/^X//' >disasm.c << 'END-of-disasm.c'
X/* 
X * Derived from:
X * Mach Operating System
X * Copyright (c) 1991,1990 Carnegie Mellon University
X * All Rights Reserved.
X */
X#include <unistd.h>
X
Xextern char *nameval();
X
X#define TRUE 1		/* DUH */
X#define FALSE 0
X
X/*
X * Size attributes
X */
X#define	BYTE	0
X#define	WORD	1
X#define	LONG	2
X#define	QUAD	3
X#define	SNGL	4
X#define	DBLR	5
X#define	EXTR	6
X#define	SDEP	7
X#define	NONE	8
X
X/*
X * Addressing modes
X */
X#define	E	1			/* general effective address */
X#define	Eind	2			/* indirect address (jump, call) */
X#define	Ew	3			/* address, word size */
X#define	Eb	4			/* address, byte size */
X#define	R	5			/* register, in 'reg' field */
X#define	Rw	6			/* word register, in 'reg' field */
X#define	Ri	7			/* register in instruction */
X#define	S	8			/* segment reg, in 'reg' field */
X#define	Si	9			/* segment reg, in instruction */
X#define	A	10			/* accumulator */
X#define	BX	11			/* (bx) */
X#define	CL	12			/* cl, for shifts */
X#define	DX	13			/* dx, for IO */
X#define	SI	14			/* si */
X#define	DI	15			/* di */
X#define	CR	16			/* control register */
X#define	DR	17			/* debug register */
X#define	TR	18			/* test register */
X#define	I	19			/* immediate, unsigned */
X#define	Is	20			/* immediate, signed */
X#define	Ib	21			/* byte immediate, unsigned */
X#define	Ibs	22			/* byte immediate, signed */
X#define	Iw	23			/* word immediate, unsigned */
X#define	Il	24			/* long immediate */
X#define	O	25			/* direct address */
X#define	Db	26			/* byte displacement from EIP */
X#define	Dl	27			/* long displacement from EIP */
X#define	o1	28			/* constant 1 */
X#define	o3	29			/* constant 3 */
X#define	OS	30			/* immediate offset/segment */
X#define	ST	31			/* FP stack top */
X#define	STI	32			/* FP stack */
X#define	X	33			/* extended FP op */
X#define	XA	34			/* for 'fstcw %ax' */
X
Xstruct inst {
X	char *	i_name;			/* name */
X	short	i_has_modrm;		/* has regmodrm byte */
X	short	i_size;			/* operand size */
X	int	i_mode;			/* addressing modes */
X	char *	i_extra;		/* pointer to extra opcode table */
X};
X
X#define	op1(x)		(x)
X#define	op2(x,y)	((x)|((y)<<8))
X#define	op3(x,y,z)	((x)|((y)<<8)|((z)<<16))
X
Xstruct finst {
X	char *	f_name;			/* name for memory instruction */
X	int	f_size;			/* size for memory instruction */
X	int	f_rrmode;		/* mode for rr instruction */
X	char *	f_rrname;		/* name for rr instruction
X					   (or pointer to table) */
X};
X
Xchar *	db_Grp6[] = {
X	"sldt",
X	"str",
X	"lldt",
X	"ltr",
X	"verr",
X	"verw",
X	"",
X	""
X};
X
Xchar *	db_Grp7[] = {
X	"sgdt",
X	"sidt",
X	"lgdt",
X	"lidt",
X	"smsw",
X	"",
X	"lmsw",
X	"invlpg"
X};
X
Xchar *	db_Grp8[] = {
X	"",
X	"",
X	"",
X	"",
X	"bt",
X	"bts",
X	"btr",
X	"btc"
X};
X
Xstruct inst db_inst_0f0x[] = {
X/*00*/	{ "",	   TRUE,  NONE,  op1(Ew),     (char *)db_Grp6 },
X/*01*/	{ "",	   TRUE,  NONE,  op1(Ew),     (char *)db_Grp7 },
X/*02*/	{ "lar",   TRUE,  LONG,  op2(E,R),    0 },
X/*03*/	{ "lsl",   TRUE,  LONG,  op2(E,R),    0 },
X/*04*/	{ "",      FALSE, NONE,  0,	      0 },
X/*05*/	{ "",      FALSE, NONE,  0,	      0 },
X/*06*/	{ "clts",  FALSE, NONE,  0,	      0 },
X/*07*/	{ "",      FALSE, NONE,  0,	      0 },
X
X/*08*/	{ "invd",  FALSE, NONE,  0,	      0 },
X/*09*/	{ "wbinvd",FALSE, NONE,  0,	      0 },
X/*0a*/	{ "",      FALSE, NONE,  0,	      0 },
X/*0b*/	{ "",      FALSE, NONE,  0,	      0 },
X/*0c*/	{ "",      FALSE, NONE,  0,	      0 },
X/*0d*/	{ "",      FALSE, NONE,  0,	      0 },
X/*0e*/	{ "",      FALSE, NONE,  0,	      0 },
X/*0f*/	{ "",      FALSE, NONE,  0,	      0 },
X};
X
Xstruct inst	db_inst_0f2x[] = {
X/*20*/	{ "mov",   TRUE,  LONG,  op2(CR,E),   0 }, /* use E for reg */
X/*21*/	{ "mov",   TRUE,  LONG,  op2(DR,E),   0 }, /* since mod == 11 */
X/*22*/	{ "mov",   TRUE,  LONG,  op2(E,CR),   0 },
X/*23*/	{ "mov",   TRUE,  LONG,  op2(E,DR),   0 },
X/*24*/	{ "mov",   TRUE,  LONG,  op2(TR,E),   0 },
X/*25*/	{ "",      FALSE, NONE,  0,	      0 },
X/*26*/	{ "mov",   TRUE,  LONG,  op2(E,TR),   0 },
X/*27*/	{ "",      FALSE, NONE,  0,	      0 },
X
X/*28*/	{ "",      FALSE, NONE,  0,	      0 },
X/*29*/	{ "",      FALSE, NONE,  0,	      0 },
X/*2a*/	{ "",      FALSE, NONE,  0,	      0 },
X/*2b*/	{ "",      FALSE, NONE,  0,	      0 },
X/*2c*/	{ "",      FALSE, NONE,  0,	      0 },
X/*2d*/	{ "",      FALSE, NONE,  0,	      0 },
X/*2e*/	{ "",      FALSE, NONE,  0,	      0 },
X/*2f*/	{ "",      FALSE, NONE,  0,	      0 },
X};
X
Xstruct inst	db_inst_0f8x[] = {
X/*80*/	{ "jo",    FALSE, NONE,  op1(Dl),     0 },
X/*81*/	{ "jno",   FALSE, NONE,  op1(Dl),     0 },
X/*82*/	{ "jb",    FALSE, NONE,  op1(Dl),     0 },
X/*83*/	{ "jnb",   FALSE, NONE,  op1(Dl),     0 },
X/*84*/	{ "jz",    FALSE, NONE,  op1(Dl),     0 },
X/*85*/	{ "jnz",   FALSE, NONE,  op1(Dl),     0 },
X/*86*/	{ "jbe",   FALSE, NONE,  op1(Dl),     0 },
X/*87*/	{ "jnbe",  FALSE, NONE,  op1(Dl),     0 },
X
X/*88*/	{ "js",    FALSE, NONE,  op1(Dl),     0 },
X/*89*/	{ "jns",   FALSE, NONE,  op1(Dl),     0 },
X/*8a*/	{ "jp",    FALSE, NONE,  op1(Dl),     0 },
X/*8b*/	{ "jnp",   FALSE, NONE,  op1(Dl),     0 },
X/*8c*/	{ "jl",    FALSE, NONE,  op1(Dl),     0 },
X/*8d*/	{ "jnl",   FALSE, NONE,  op1(Dl),     0 },
X/*8e*/	{ "jle",   FALSE, NONE,  op1(Dl),     0 },
X/*8f*/	{ "jnle",  FALSE, NONE,  op1(Dl),     0 },
X};
X
Xstruct inst	db_inst_0f9x[] = {
X/*90*/	{ "seto",  TRUE,  NONE,  op1(Eb),     0 },
X/*91*/	{ "setno", TRUE,  NONE,  op1(Eb),     0 },
X/*92*/	{ "setb",  TRUE,  NONE,  op1(Eb),     0 },
X/*93*/	{ "setnb", TRUE,  NONE,  op1(Eb),     0 },
X/*94*/	{ "setz",  TRUE,  NONE,  op1(Eb),     0 },
X/*95*/	{ "setnz", TRUE,  NONE,  op1(Eb),     0 },
X/*96*/	{ "setbe", TRUE,  NONE,  op1(Eb),     0 },
X/*97*/	{ "setnbe",TRUE,  NONE,  op1(Eb),     0 },
X
X/*98*/	{ "sets",  TRUE,  NONE,  op1(Eb),     0 },
X/*99*/	{ "setns", TRUE,  NONE,  op1(Eb),     0 },
X/*9a*/	{ "setp",  TRUE,  NONE,  op1(Eb),     0 },
X/*9b*/	{ "setnp", TRUE,  NONE,  op1(Eb),     0 },
X/*9c*/	{ "setl",  TRUE,  NONE,  op1(Eb),     0 },
X/*9d*/	{ "setnl", TRUE,  NONE,  op1(Eb),     0 },
X/*9e*/	{ "setle", TRUE,  NONE,  op1(Eb),     0 },
X/*9f*/	{ "setnle",TRUE,  NONE,  op1(Eb),     0 },
X};
X
Xstruct inst	db_inst_0fax[] = {
X/*a0*/	{ "push",  FALSE, NONE,  op1(Si),     0 },
X/*a1*/	{ "pop",   FALSE, NONE,  op1(Si),     0 },
X/*a2*/	{ "",      FALSE, NONE,  0,	      0 },
X/*a3*/	{ "bt",    TRUE,  LONG,  op2(E,R),    0 },
X/*a4*/	{ "shld",  TRUE,  LONG,  op3(Ib,E,R), 0 },
X/*a5*/	{ "shld",  TRUE,  LONG,  op3(CL,E,R), 0 },
X/*a6*/	{ "",      FALSE, NONE,  0,	      0 },
X/*a7*/	{ "",      FALSE, NONE,  0,	      0 },
X
X/*a8*/	{ "push",  FALSE, NONE,  op1(Si),     0 },
X/*a9*/	{ "pop",   FALSE, NONE,  op1(Si),     0 },
X/*aa*/	{ "",      FALSE, NONE,  0,	      0 },
X/*ab*/	{ "bts",   TRUE,  LONG,  op2(E,R),    0 },
X/*ac*/	{ "shrd",  TRUE,  LONG,  op3(Ib,E,R), 0 },
X/*ad*/	{ "shrd",  TRUE,  LONG,  op3(CL,E,R), 0 },
X/*a6*/	{ "",      FALSE, NONE,  0,	      0 },
X/*a7*/	{ "imul",  TRUE,  LONG,  op2(E,R),    0 },
X};
X
Xstruct inst	db_inst_0fbx[] = {
X/*b0*/	{ "",      FALSE, NONE,  0,	      0 },
X/*b1*/	{ "",      FALSE, NONE,  0,	      0 },
X/*b2*/	{ "lss",   TRUE,  LONG,  op2(E, R),   0 },
X/*b3*/	{ "bts",   TRUE,  LONG,  op2(R, E),   0 },
X/*b4*/	{ "lfs",   TRUE,  LONG,  op2(E, R),   0 },
X/*b5*/	{ "lgs",   TRUE,  LONG,  op2(E, R),   0 },
X/*b6*/	{ "movzb", TRUE,  LONG,  op2(E, R),   0 },
X/*b7*/	{ "movzw", TRUE,  LONG,  op2(E, R),   0 },
X
X/*b8*/	{ "",      FALSE, NONE,  0,	      0 },
X/*b9*/	{ "",      FALSE, NONE,  0,	      0 },
X/*ba*/	{ "",      TRUE,  LONG,  op2(Is, E),  (char *)db_Grp8 },
X/*bb*/	{ "btc",   TRUE,  LONG,  op2(R, E),   0 },
X/*bc*/	{ "bsf",   TRUE,  LONG,  op2(E, R),   0 },
X/*bd*/	{ "bsr",   TRUE,  LONG,  op2(E, R),   0 },
X/*be*/	{ "movsb", TRUE,  LONG,  op2(E, R),   0 },
X/*bf*/	{ "movsw", TRUE,  LONG,  op2(E, R),   0 },
X};
X
Xstruct inst	db_inst_0fcx[] = {
X/*c0*/	{ "xadd",  TRUE,  BYTE,	 op2(R, E),   0 },
X/*c1*/	{ "xadd",  TRUE,  LONG,	 op2(R, E),   0 },
X/*c2*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*c3*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*c4*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*c5*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*c6*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*c7*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*c8*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
X/*c9*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
X/*ca*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
X/*cb*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
X/*cc*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
X/*cd*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
X/*ce*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
X/*cf*/	{ "bswap", FALSE, LONG,  op1(Ri),     0 },
X};
X
Xstruct inst	db_inst_0fdx[] = {
X/*c0*/	{ "cmpxchg",TRUE, BYTE,	 op2(R, E),   0 },
X/*c1*/	{ "cmpxchg",TRUE, LONG,	 op2(R, E),   0 },
X/*c2*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*c3*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*c4*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*c5*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*c6*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*c7*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*c8*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*c9*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*ca*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*cb*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*cc*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*cd*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*ce*/	{ "",	   FALSE, NONE,	 0,	      0 },
X/*cf*/	{ "",	   FALSE, NONE,	 0,	      0 },
X};
X
Xstruct inst *db_inst_0f[] = {
X	db_inst_0f0x,
X	0,
X	db_inst_0f2x,
X	0,
X	0,
X	0,
X	0,
X	0,
X	db_inst_0f8x,
X	db_inst_0f9x,
X	db_inst_0fax,
X	db_inst_0fbx,
X	db_inst_0fcx,
X	db_inst_0fdx,
X	0,
X	0
X};
X
Xchar *	db_Esc92[] = {
X	"fnop",	"",	"",	"",	"",	"",	"",	""
X};
Xchar *	db_Esc93[] = {
X	"",	"",	"",	"",	"",	"",	"",	""
X};
Xchar *	db_Esc94[] = {
X	"fchs",	"fabs",	"",	"",	"ftst",	"fxam",	"",	""
X};
Xchar *	db_Esc95[] = {
X	"fld1",	"fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
X};
Xchar *	db_Esc96[] = {
X	"f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
X	"fincstp"
X};
Xchar *	db_Esc97[] = {
X	"fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
X};
X
Xchar *	db_Esca4[] = {
X	"",	"fucompp","",	"",	"",	"",	"",	""
X};
X
Xchar *	db_Escb4[] = {
X	"",	"",	"fnclex","fninit","",	"",	"",	""
X};
X
Xchar *	db_Esce3[] = {
X	"",	"fcompp","",	"",	"",	"",	"",	""
X};
X
Xchar *	db_Escf4[] = {
X	"fnstsw","",	"",	"",	"",	"",	"",	""
X};
X
Xstruct finst db_Esc8[] = {
X/*0*/	{ "fadd",   SNGL,  op2(STI,ST),	0 },
X/*1*/	{ "fmul",   SNGL,  op2(STI,ST),	0 },
X/*2*/	{ "fcom",   SNGL,  op2(STI,ST),	0 },
X/*3*/	{ "fcomp",  SNGL,  op2(STI,ST),	0 },
X/*4*/	{ "fsub",   SNGL,  op2(STI,ST),	0 },
X/*5*/	{ "fsubr",  SNGL,  op2(STI,ST),	0 },
X/*6*/	{ "fdiv",   SNGL,  op2(STI,ST),	0 },
X/*7*/	{ "fdivr",  SNGL,  op2(STI,ST),	0 },
X};
X
Xstruct finst db_Esc9[] = {
X/*0*/	{ "fld",    SNGL,  op1(STI),	0 },
X/*1*/	{ "",       NONE,  op1(STI),	"fxch" },
X/*2*/	{ "fst",    SNGL,  op1(X),	(char *)db_Esc92 },
X/*3*/	{ "fstp",   SNGL,  op1(X),	(char *)db_Esc93 },
X/*4*/	{ "fldenv", NONE,  op1(X),	(char *)db_Esc94 },
X/*5*/	{ "fldcw",  NONE,  op1(X),	(char *)db_Esc95 },
X/*6*/	{ "fnstenv",NONE,  op1(X),	(char *)db_Esc96 },
X/*7*/	{ "fnstcw", NONE,  op1(X),	(char *)db_Esc97 },
X};
X
Xstruct finst db_Esca[] = {
X/*0*/	{ "fiadd",  WORD,  0,		0 },
X/*1*/	{ "fimul",  WORD,  0,		0 },
X/*2*/	{ "ficom",  WORD,  0,		0 },
X/*3*/	{ "ficomp", WORD,  0,		0 },
X/*4*/	{ "fisub",  WORD,  op1(X),	(char *)db_Esca4 },
X/*5*/	{ "fisubr", WORD,  0,		0 },
X/*6*/	{ "fidiv",  WORD,  0,		0 },
X/*7*/	{ "fidivr", WORD,  0,		0 }
X};
X
Xstruct finst db_Escb[] = {
X/*0*/	{ "fild",   WORD,  0,		0 },
X/*1*/	{ "",       NONE,  0,		0 },
X/*2*/	{ "fist",   WORD,  0,		0 },
X/*3*/	{ "fistp",  WORD,  0,		0 },
X/*4*/	{ "",       WORD,  op1(X),	(char *)db_Escb4 },
X/*5*/	{ "fld",    EXTR,  0,		0 },
X/*6*/	{ "",       WORD,  0,		0 },
X/*7*/	{ "fstp",   EXTR,  0,		0 },
X};
X
Xstruct finst db_Escc[] = {
X/*0*/	{ "fadd",   DBLR,  op2(ST,STI),	0 },
X/*1*/	{ "fmul",   DBLR,  op2(ST,STI),	0 },
X/*2*/	{ "fcom",   DBLR,  op2(ST,STI),	0 },
X/*3*/	{ "fcomp",  DBLR,  op2(ST,STI),	0 },
X/*4*/	{ "fsub",   DBLR,  op2(ST,STI),	"fsubr" },
X/*5*/	{ "fsubr",  DBLR,  op2(ST,STI),	"fsub" },
X/*6*/	{ "fdiv",   DBLR,  op2(ST,STI),	"fdivr" },
X/*7*/	{ "fdivr",  DBLR,  op2(ST,STI),	"fdiv" },
X};
X
Xstruct finst db_Escd[] = {
X/*0*/	{ "fld",    DBLR,  op1(STI),	"ffree" },
X/*1*/	{ "",       NONE,  0,		0 },
X/*2*/	{ "fst",    DBLR,  op1(STI),	0 },
X/*3*/	{ "fstp",   DBLR,  op1(STI),	0 },
X/*4*/	{ "frstor", NONE,  op1(STI),	"fucom" },
X/*5*/	{ "",       NONE,  op1(STI),	"fucomp" },
X/*6*/	{ "fnsave", NONE,  0,		0 },
X/*7*/	{ "fnstsw", NONE,  0,		0 },
X};
X
Xstruct finst db_Esce[] = {
X/*0*/	{ "fiadd",  LONG,  op2(ST,STI),	"faddp" },
X/*1*/	{ "fimul",  LONG,  op2(ST,STI),	"fmulp" },
X/*2*/	{ "ficom",  LONG,  0,		0 },
X/*3*/	{ "ficomp", LONG,  op1(X),	(char *)db_Esce3 },
X/*4*/	{ "fisub",  LONG,  op2(ST,STI),	"fsubrp" },
X/*5*/	{ "fisubr", LONG,  op2(ST,STI),	"fsubp" },
X/*6*/	{ "fidiv",  LONG,  op2(ST,STI),	"fdivrp" },
X/*7*/	{ "fidivr", LONG,  op2(ST,STI),	"fdivp" },
X};
X
Xstruct finst db_Escf[] = {
X/*0*/	{ "fild",   LONG,  0,		0 },
X/*1*/	{ "",       LONG,  0,		0 },
X/*2*/	{ "fist",   LONG,  0,		0 },
X/*3*/	{ "fistp",  LONG,  0,		0 },
X/*4*/	{ "fbld",   NONE,  op1(XA),	(char *)db_Escf4 },
X/*5*/	{ "fld",    QUAD,  0,		0 },
X/*6*/	{ "fbstp",  NONE,  0,		0 },
X/*7*/	{ "fstp",   QUAD,  0,		0 },
X};
X
Xstruct finst *db_Esc_inst[] = {
X	db_Esc8, db_Esc9, db_Esca, db_Escb,
X	db_Escc, db_Escd, db_Esce, db_Escf
X};
X
Xchar *	db_Grp1[] = {
X	"add",
X	"or",
X	"adc",
X	"sbb",
X	"and",
X	"sub",
X	"xor",
X	"cmp"
X};
X
Xchar *	db_Grp2[] = {
X	"rol",
X	"ror",
X	"rcl",
X	"rcr",
X	"shl",
X	"shr",
X	"shl",
X	"sar"
X};
X
Xstruct inst db_Grp3[] = {
X	{ "test",  TRUE, NONE, op2(I,E), 0 },
X	{ "test",  TRUE, NONE, op2(I,E), 0 },
X	{ "not",   TRUE, NONE, op1(E),   0 },
X	{ "neg",   TRUE, NONE, op1(E),   0 },
X	{ "mul",   TRUE, NONE, op2(E,A), 0 },
X	{ "imul",  TRUE, NONE, op2(E,A), 0 },
X	{ "div",   TRUE, NONE, op2(E,A), 0 },
X	{ "idiv",  TRUE, NONE, op2(E,A), 0 },
X};
X
Xstruct inst	db_Grp4[] = {
X	{ "inc",   TRUE, BYTE, op1(E),   0 },
X	{ "dec",   TRUE, BYTE, op1(E),   0 },
X	{ "",      TRUE, NONE, 0,	 0 },
X	{ "",      TRUE, NONE, 0,	 0 },
X	{ "",      TRUE, NONE, 0,	 0 },
X	{ "",      TRUE, NONE, 0,	 0 },
X	{ "",      TRUE, NONE, 0,	 0 },
X	{ "",      TRUE, NONE, 0,	 0 }
X};
X
Xstruct inst	db_Grp5[] = {
X	{ "inc",   TRUE, LONG, op1(E),   0 },
X	{ "dec",   TRUE, LONG, op1(E),   0 },
X	{ "call",  TRUE, NONE, op1(Eind),0 },
X	{ "lcall", TRUE, NONE, op1(Eind),0 },
X	{ "jmp",   TRUE, NONE, op1(Eind),0 },
X	{ "ljmp",  TRUE, NONE, op1(Eind),0 },
X	{ "push",  TRUE, LONG, op1(E),   0 },
X	{ "",      TRUE, NONE, 0,	 0 }
X};
X
Xstruct inst db_inst_table[256] = {
X/*00*/	{ "add",   TRUE,  BYTE,  op2(R, E),  0 },
X/*01*/	{ "add",   TRUE,  LONG,  op2(R, E),  0 },
X/*02*/	{ "add",   TRUE,  BYTE,  op2(E, R),  0 },
X/*03*/	{ "add",   TRUE,  LONG,  op2(E, R),  0 },
X/*04*/	{ "add",   FALSE, BYTE,  op2(Is, A), 0 },
X/*05*/	{ "add",   FALSE, LONG,  op2(Is, A), 0 },
X/*06*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
X/*07*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },
X
X/*08*/	{ "or",    TRUE,  BYTE,  op2(R, E),  0 },
X/*09*/	{ "or",    TRUE,  LONG,  op2(R, E),  0 },
X/*0a*/	{ "or",    TRUE,  BYTE,  op2(E, R),  0 },
X/*0b*/	{ "or",    TRUE,  LONG,  op2(E, R),  0 },
X/*0c*/	{ "or",    FALSE, BYTE,  op2(I, A),  0 },
X/*0d*/	{ "or",    FALSE, LONG,  op2(I, A),  0 },
X/*0e*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
X/*0f*/	{ "",      FALSE, NONE,  0,	     0 },
X
X/*10*/	{ "adc",   TRUE,  BYTE,  op2(R, E),  0 },
X/*11*/	{ "adc",   TRUE,  LONG,  op2(R, E),  0 },
X/*12*/	{ "adc",   TRUE,  BYTE,  op2(E, R),  0 },
X/*13*/	{ "adc",   TRUE,  LONG,  op2(E, R),  0 },
X/*14*/	{ "adc",   FALSE, BYTE,  op2(Is, A), 0 },
X/*15*/	{ "adc",   FALSE, LONG,  op2(Is, A), 0 },
X/*16*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
X/*17*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },
X
X/*18*/	{ "sbb",   TRUE,  BYTE,  op2(R, E),  0 },
X/*19*/	{ "sbb",   TRUE,  LONG,  op2(R, E),  0 },
X/*1a*/	{ "sbb",   TRUE,  BYTE,  op2(E, R),  0 },
X/*1b*/	{ "sbb",   TRUE,  LONG,  op2(E, R),  0 },
X/*1c*/	{ "sbb",   FALSE, BYTE,  op2(Is, A), 0 },
X/*1d*/	{ "sbb",   FALSE, LONG,  op2(Is, A), 0 },
X/*1e*/	{ "push",  FALSE, NONE,  op1(Si),    0 },
X/*1f*/	{ "pop",   FALSE, NONE,  op1(Si),    0 },
X
X/*20*/	{ "and",   TRUE,  BYTE,  op2(R, E),  0 },
X/*21*/	{ "and",   TRUE,  LONG,  op2(R, E),  0 },
X/*22*/	{ "and",   TRUE,  BYTE,  op2(E, R),  0 },
X/*23*/	{ "and",   TRUE,  LONG,  op2(E, R),  0 },
X/*24*/	{ "and",   FALSE, BYTE,  op2(I, A),  0 },
X/*25*/	{ "and",   FALSE, LONG,  op2(I, A),  0 },
X/*26*/	{ "",      FALSE, NONE,  0,	     0 },
X/*27*/	{ "aaa",   FALSE, NONE,  0,	     0 },
X
X/*28*/	{ "sub",   TRUE,  BYTE,  op2(R, E),  0 },
X/*29*/	{ "sub",   TRUE,  LONG,  op2(R, E),  0 },
X/*2a*/	{ "sub",   TRUE,  BYTE,  op2(E, R),  0 },
X/*2b*/	{ "sub",   TRUE,  LONG,  op2(E, R),  0 },
X/*2c*/	{ "sub",   FALSE, BYTE,  op2(Is, A), 0 },
X/*2d*/	{ "sub",   FALSE, LONG,  op2(Is, A), 0 },
X/*2e*/	{ "",      FALSE, NONE,  0,	     0 },
X/*2f*/	{ "das",   FALSE, NONE,  0,	     0 },
X
X/*30*/	{ "xor",   TRUE,  BYTE,  op2(R, E),  0 },
X/*31*/	{ "xor",   TRUE,  LONG,  op2(R, E),  0 },
X/*32*/	{ "xor",   TRUE,  BYTE,  op2(E, R),  0 },
X/*33*/	{ "xor",   TRUE,  LONG,  op2(E, R),  0 },
X/*34*/	{ "xor",   FALSE, BYTE,  op2(I, A),  0 },
X/*35*/	{ "xor",   FALSE, LONG,  op2(I, A),  0 },
X/*36*/	{ "",      FALSE, NONE,  0,	     0 },
X/*37*/	{ "daa",   FALSE, NONE,  0,	     0 },
X
X/*38*/	{ "cmp",   TRUE,  BYTE,  op2(R, E),  0 },
X/*39*/	{ "cmp",   TRUE,  LONG,  op2(R, E),  0 },
X/*3a*/	{ "cmp",   TRUE,  BYTE,  op2(E, R),  0 },
X/*3b*/	{ "cmp",   TRUE,  LONG,  op2(E, R),  0 },
X/*3c*/	{ "cmp",   FALSE, BYTE,  op2(Is, A), 0 },
X/*3d*/	{ "cmp",   FALSE, LONG,  op2(Is, A), 0 },
X/*3e*/	{ "",      FALSE, NONE,  0,	     0 },
X/*3f*/	{ "aas",   FALSE, NONE,  0,	     0 },
X
X/*40*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
X/*41*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
X/*42*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
X/*43*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
X/*44*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
X/*45*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
X/*46*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
X/*47*/	{ "inc",   FALSE, LONG,  op1(Ri),    0 },
X
X/*48*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
X/*49*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
X/*4a*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
X/*4b*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
X/*4c*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
X/*4d*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
X/*4e*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
X/*4f*/	{ "dec",   FALSE, LONG,  op1(Ri),    0 },
X
X/*50*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
X/*51*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
X/*52*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
X/*53*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
X/*54*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
X/*55*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
X/*56*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
X/*57*/	{ "push",  FALSE, LONG,  op1(Ri),    0 },
X
X/*58*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
X/*59*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
X/*5a*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
X/*5b*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
X/*5c*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
X/*5d*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
X/*5e*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
X/*5f*/	{ "pop",   FALSE, LONG,  op1(Ri),    0 },
X
X/*60*/	{ "pusha", FALSE, LONG,  0,	     0 },
X/*61*/	{ "popa",  FALSE, LONG,  0,	     0 },
X/*62*/  { "bound", TRUE,  LONG,  op2(E, R),  0 },
X/*63*/	{ "arpl",  TRUE,  NONE,  op2(Ew,Rw), 0 },
X
X/*64*/	{ "",      FALSE, NONE,  0,	     0 },
X/*65*/	{ "",      FALSE, NONE,  0,	     0 },
X/*66*/	{ "",      FALSE, NONE,  0,	     0 },
X/*67*/	{ "",      FALSE, NONE,  0,	     0 },
X
X/*68*/	{ "push",  FALSE, LONG,  op1(I),     0 },
X/*69*/  { "imul",  TRUE,  LONG,  op3(I,E,R), 0 },
X/*6a*/	{ "push",  FALSE, LONG,  op1(Ib),    0 },
X/*6b*/  { "imul",  TRUE,  LONG,  op3(Ibs,E,R),0 },
X/*6c*/	{ "ins",   FALSE, BYTE,  op2(DX, DI), 0 },
X/*6d*/	{ "ins",   FALSE, LONG,  op2(DX, DI), 0 },
X/*6e*/	{ "outs",  FALSE, BYTE,  op2(SI, DX), 0 },
X/*6f*/	{ "outs",  FALSE, LONG,  op2(SI, DX), 0 },
X
X/*70*/	{ "jo",    FALSE, NONE,  op1(Db),     0 },
X/*71*/	{ "jno",   FALSE, NONE,  op1(Db),     0 },
X/*72*/	{ "jb",    FALSE, NONE,  op1(Db),     0 },
X/*73*/	{ "jnb",   FALSE, NONE,  op1(Db),     0 },
X/*74*/	{ "jz",    FALSE, NONE,  op1(Db),     0 },
X/*75*/	{ "jnz",   FALSE, NONE,  op1(Db),     0 },
X/*76*/	{ "jbe",   FALSE, NONE,  op1(Db),     0 },
X/*77*/	{ "jnbe",  FALSE, NONE,  op1(Db),     0 },
X
X/*78*/	{ "js",    FALSE, NONE,  op1(Db),     0 },
X/*79*/	{ "jns",   FALSE, NONE,  op1(Db),     0 },
X/*7a*/	{ "jp",    FALSE, NONE,  op1(Db),     0 },
X/*7b*/	{ "jnp",   FALSE, NONE,  op1(Db),     0 },
X/*7c*/	{ "jl",    FALSE, NONE,  op1(Db),     0 },
X/*7d*/	{ "jnl",   FALSE, NONE,  op1(Db),     0 },
X/*7e*/	{ "jle",   FALSE, NONE,  op1(Db),     0 },
X/*7f*/	{ "jnle",  FALSE, NONE,  op1(Db),     0 },
X
X/*80*/  { "",	   TRUE,  BYTE,  op2(I, E),   (char *)db_Grp1 },
X/*81*/  { "",	   TRUE,  LONG,  op2(I, E),   (char *)db_Grp1 },
X/*82*/  { "",	   TRUE,  BYTE,  op2(Is,E),   (char *)db_Grp1 },
X/*83*/  { "",	   TRUE,  LONG,  op2(Ibs,E),  (char *)db_Grp1 },
X/*84*/	{ "test",  TRUE,  BYTE,  op2(R, E),   0 },
X/*85*/	{ "test",  TRUE,  LONG,  op2(R, E),   0 },
X/*86*/	{ "xchg",  TRUE,  BYTE,  op2(R, E),   0 },
X/*87*/	{ "xchg",  TRUE,  LONG,  op2(R, E),   0 },
X
X/*88*/	{ "mov",   TRUE,  BYTE,  op2(R, E),   0 },
X/*89*/	{ "mov",   TRUE,  LONG,  op2(R, E),   0 },
X/*8a*/	{ "mov",   TRUE,  BYTE,  op2(E, R),   0 },
X/*8b*/	{ "mov",   TRUE,  LONG,  op2(E, R),   0 },
X/*8c*/  { "mov",   TRUE,  NONE,  op2(S, Ew),  0 },
X/*8d*/	{ "lea",   TRUE,  LONG,  op2(E, R),   0 },
X/*8e*/	{ "mov",   TRUE,  NONE,  op2(Ew, S),  0 },
X/*8f*/	{ "pop",   TRUE,  LONG,  op1(E),      0 },
X
X/*90*/	{ "nop",   FALSE, NONE,  0,	      0 },
X/*91*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
X/*92*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
X/*93*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
X/*94*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
X/*95*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
X/*96*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
X/*97*/	{ "xchg",  FALSE, LONG,  op2(A, Ri),  0 },
X
X/*98*/	{ "cbw",   FALSE, SDEP,  0,	      "cwde" },	/* cbw/cwde */
X/*99*/	{ "cwd",   FALSE, SDEP,  0,	      "cdq"  },	/* cwd/cdq */
X/*9a*/	{ "lcall", FALSE, NONE,  op1(OS),     0 },
X/*9b*/	{ "wait",  FALSE, NONE,  0,	      0 },
X/*9c*/	{ "pushf", FALSE, LONG,  0,	      0 },
X/*9d*/	{ "popf",  FALSE, LONG,  0,	      0 },
X/*9e*/	{ "sahf",  FALSE, NONE,  0,	      0 },
X/*9f*/	{ "lahf",  FALSE, NONE,  0,	      0 },
X
X/*a0*/	{ "mov",   FALSE, BYTE,  op2(O, A),   0 },
X/*a1*/	{ "mov",   FALSE, LONG,  op2(O, A),   0 },
X/*a2*/	{ "mov",   FALSE, BYTE,  op2(A, O),   0 },
X/*a3*/	{ "mov",   FALSE, LONG,  op2(A, O),   0 },
X/*a4*/	{ "movs",  FALSE, BYTE,  op2(SI,DI),  0 },
X/*a5*/	{ "movs",  FALSE, LONG,  op2(SI,DI),  0 },
X/*a6*/	{ "cmps",  FALSE, BYTE,  op2(SI,DI),  0 },
X/*a7*/	{ "cmps",  FALSE, LONG,  op2(SI,DI),  0 },
X
X/*a8*/	{ "test",  FALSE, BYTE,  op2(I, A),   0 },
X/*a9*/	{ "test",  FALSE, LONG,  op2(I, A),   0 },
X/*aa*/	{ "stos",  FALSE, BYTE,  op1(DI),     0 },
X/*ab*/	{ "stos",  FALSE, LONG,  op1(DI),     0 },
X/*ac*/	{ "ldos",  FALSE, BYTE,  op1(SI),     0 },
X/*ad*/	{ "ldos",  FALSE, LONG,  op1(SI),     0 },
X/*ae*/	{ "scas",  FALSE, BYTE,  op1(SI),     0 },
X/*af*/	{ "scas",  FALSE, LONG,  op1(SI),     0 },
X
X/*b0*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
X/*b1*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
X/*b2*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
X/*b3*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
X/*b4*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
X/*b5*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
X/*b6*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
X/*b7*/	{ "mov",   FALSE, BYTE,  op2(I, Ri),  0 },
X
X/*b8*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
X/*b9*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
X/*ba*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
X/*bb*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
X/*bc*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
X/*bd*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
X/*be*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
X/*bf*/	{ "mov",   FALSE, LONG,  op2(I, Ri),  0 },
X
X/*c0*/	{ "",	   TRUE,  BYTE,  op2(Ib, E),  (char *)db_Grp2 },
X/*c1*/	{ "",	   TRUE,  LONG,  op2(Ib, E),  (char *)db_Grp2 },
X/*c2*/	{ "ret",   FALSE, NONE,  op1(Iw),     0 },
X/*c3*/	{ "ret",   FALSE, NONE,  0,	      0 },
X/*c4*/	{ "les",   TRUE,  LONG,  op2(E, R),   0 },
X/*c5*/	{ "lds",   TRUE,  LONG,  op2(E, R),   0 },
X/*c6*/	{ "mov",   TRUE,  BYTE,  op2(I, E),   0 },
X/*c7*/	{ "mov",   TRUE,  LONG,  op2(I, E),   0 },
X
X/*c8*/	{ "enter", FALSE, NONE,  op2(Ib, Iw), 0 },
X/*c9*/	{ "leave", FALSE, NONE,  0,           0 },
X/*ca*/	{ "lret",  FALSE, NONE,  op1(Iw),     0 },
X/*cb*/	{ "lret",  FALSE, NONE,  0,	      0 },
X/*cc*/	{ "int",   FALSE, NONE,  op1(o3),     0 },
X/*cd*/	{ "int",   FALSE, NONE,  op1(Ib),     0 },
X/*ce*/	{ "into",  FALSE, NONE,  0,	      0 },
X/*cf*/	{ "iret",  FALSE, NONE,  0,	      0 },
X
X/*d0*/	{ "",	   TRUE,  BYTE,  op2(o1, E),  (char *)db_Grp2 },
X/*d1*/	{ "",	   TRUE,  LONG,  op2(o1, E),  (char *)db_Grp2 },
X/*d2*/	{ "",	   TRUE,  BYTE,  op2(CL, E),  (char *)db_Grp2 },
X/*d3*/	{ "",	   TRUE,  LONG,  op2(CL, E),  (char *)db_Grp2 },
X/*d4*/	{ "aam",   TRUE,  NONE,  0,	      0 },
X/*d5*/	{ "aad",   TRUE,  NONE,  0,	      0 },
X/*d6*/	{ "",      FALSE, NONE,  0,	      0 },
X/*d7*/	{ "xlat",  FALSE, BYTE,  op1(BX),     0 },
X
X/*d8*/  { "",      TRUE,  NONE,  0,	      (char *)db_Esc8 },
X/*d9*/  { "",      TRUE,  NONE,  0,	      (char *)db_Esc9 },
X/*da*/  { "",      TRUE,  NONE,  0,	      (char *)db_Esca },
X/*db*/  { "",      TRUE,  NONE,  0,	      (char *)db_Escb },
X/*dc*/  { "",      TRUE,  NONE,  0,	      (char *)db_Escc },
X/*dd*/  { "",      TRUE,  NONE,  0,	      (char *)db_Escd },
X/*de*/  { "",      TRUE,  NONE,  0,	      (char *)db_Esce },
X/*df*/  { "",      TRUE,  NONE,  0,	      (char *)db_Escf },
X
X/*e0*/	{ "loopne",FALSE, NONE,  op1(Db),     0 },
X/*e1*/	{ "loope", FALSE, NONE,  op1(Db),     0 },
X/*e2*/	{ "loop",  FALSE, NONE,  op1(Db),     0 },
X/*e3*/	{ "jcxz",  FALSE, SDEP,  op1(Db),     "jecxz" },
X/*e4*/	{ "in",    FALSE, BYTE,  op2(Ib, A),  0 },
X/*e5*/	{ "in",    FALSE, LONG,  op2(Ib, A) , 0 },
X/*e6*/	{ "out",   FALSE, BYTE,  op2(A, Ib),  0 },
X/*e7*/	{ "out",   FALSE, LONG,  op2(A, Ib) , 0 },
X
X/*e8*/	{ "call",  FALSE, NONE,  op1(Dl),     0 },
X/*e9*/	{ "jmp",   FALSE, NONE,  op1(Dl),     0 },
X/*ea*/	{ "ljmp",  FALSE, NONE,  op1(OS),     0 },
X/*eb*/	{ "jmp",   FALSE, NONE,  op1(Db),     0 },
X/*ec*/	{ "in",    FALSE, BYTE,  op2(DX, A),  0 },
X/*ed*/	{ "in",    FALSE, LONG,  op2(DX, A) , 0 },
X/*ee*/	{ "out",   FALSE, BYTE,  op2(A, DX),  0 },
X/*ef*/	{ "out",   FALSE, LONG,  op2(A, DX) , 0 },
X
X/*f0*/	{ "",      FALSE, NONE,  0,	     0 },
X/*f1*/	{ "",      FALSE, NONE,  0,	     0 },
X/*f2*/	{ "",      FALSE, NONE,  0,	     0 },
X/*f3*/	{ "",      FALSE, NONE,  0,	     0 },
X/*f4*/	{ "hlt",   FALSE, NONE,  0,	     0 },
X/*f5*/	{ "cmc",   FALSE, NONE,  0,	     0 },
X/*f6*/	{ "",      TRUE,  BYTE,  0,	     (char *)db_Grp3 },
X/*f7*/	{ "",	   TRUE,  LONG,  0,	     (char *)db_Grp3 },
X
X/*f8*/	{ "clc",   FALSE, NONE,  0,	     0 },
X/*f9*/	{ "stc",   FALSE, NONE,  0,	     0 },
X/*fa*/	{ "cli",   FALSE, NONE,  0,	     0 },
X/*fb*/	{ "sti",   FALSE, NONE,  0,	     0 },
X/*fc*/	{ "cld",   FALSE, NONE,  0,	     0 },
X/*fd*/	{ "std",   FALSE, NONE,  0,	     0 },
X/*fe*/	{ "",	   TRUE,  NONE,  0,	     (char *)db_Grp4 },
X/*ff*/	{ "",	   TRUE,  NONE,  0,	     (char *)db_Grp5 },
X};
X
Xstruct inst	db_bad_inst =
X	{ "???",   FALSE, NONE,  0,	      0 }
X;
X
X#define	f_mod(byte)	((byte)>>6)
X#define	f_reg(byte)	(((byte)>>3)&0x7)
X#define	f_rm(byte)	((byte)&0x7)
X
X#define	sib_ss(byte)	((byte)>>6)
X#define	sib_index(byte)	(((byte)>>3)&0x7)
X#define	sib_base(byte)	((byte)&0x7)
X
Xstruct i_addr {
X	int		is_reg;	/* if reg, reg number is in 'disp' */
X	int		disp;
X	char *		base;
X	char *		index;
X	int		ss;
X};
X
Xchar *	db_index_reg_16[8] = {
X	"%bx,%si",
X	"%bx,%di",
X	"%bp,%si",
X	"%bp,%di",
X	"%si",
X	"%di",
X	"%bp",
X	"%bx"
X};
X
Xchar *	db_reg[3][8] = {
X	"%al",  "%cl",  "%dl",  "%bl",  "%ah",  "%ch",  "%dh",  "%bh",
X	"%ax",  "%cx",  "%dx",  "%bx",  "%sp",  "%bp",  "%si",  "%di",
X	"%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi"
X};
X
Xchar *	db_seg_reg[8] = {
X	"%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
X};
X
X/*
X * lengths for size attributes
X */
Xint db_lengths[] = {
X	1,	/* BYTE */
X	2,	/* WORD */
X	4,	/* LONG */
X	8,	/* QUAD */
X	4,	/* SNGL */
X	8,	/* DBLR */
X	10,	/* EXTR */
X};
X
X/*
X * Wrapper function to interface to readloc()
X * XXX should allow for physical memory disassembly
X */
Xstatic
Xreadloc2(loc, size)
X	int loc, size;
X{
X	char a; short b; int c;
X
X	switch (size) {
X	case 1:
X		readloc(loc, &a, 1, 0);
X		return(a & 0xFF);
X	case 2:
X		readloc(loc, &b, 2, 0);
X		return(b & 0xFFFF);
X	case 4:
X		readloc(loc, &c, 4, 0);
X		return(c);
X	default:
X		return(0);
X	}
X}
X
X#define	get_value_inc(result, loc, size, is_signed) \
X	result = readloc2(loc, size); \
X	(loc) += (size);
X
X/*
X * Read address at location and return updated location.
X */
Xoff_t
Xdb_read_address(loc, short_addr, regmodrm, addrp)
X	off_t	loc;
X	int		short_addr;
X	int		regmodrm;
X	struct i_addr	*addrp;		/* out */
X{
X	int		mod, rm, sib, index, ss, disp;
X
X	mod = f_mod(regmodrm);
X	rm  = f_rm(regmodrm);
X
X	if (mod == 3) {
X	    addrp->is_reg = TRUE;
X	    addrp->disp = rm;
X	    return (loc);
X	}
X	addrp->is_reg = FALSE;
X	addrp->index = 0;
X
X	if (short_addr) {
X	    addrp->index = 0;
X	    addrp->ss = 0;
X	    switch (mod) {
X		case 0:
X		    if (rm == 6) {
X			get_value_inc(disp, loc, 2, TRUE);
X			addrp->disp = disp;
X			addrp->base = 0;
X		    }
X		    else {
X			addrp->disp = 0;
X			addrp->base = db_index_reg_16[rm];
X		    }
X		    break;
X		case 1:
X		    get_value_inc(disp, loc, 1, TRUE);
X		    addrp->disp = disp;
X		    addrp->base = db_index_reg_16[rm];
X		    break;
X		case 2:
X		    get_value_inc(disp, loc, 2, TRUE);
X		    addrp->disp = disp;
X		    addrp->base = db_index_reg_16[rm];
X		    break;
X	    }
X	}
X	else {
X	    if (mod != 3 && rm == 4) {
X		get_value_inc(sib, loc, 1, FALSE);
X		rm = sib_base(sib);
X		index = sib_index(sib);
X		if (index != 4)
X		    addrp->index = db_reg[LONG][index];
X		addrp->ss = sib_ss(sib);
X	    }
X
X	    switch (mod) {
X		case 0:
X		    if (rm == 5) {
X			get_value_inc(addrp->disp, loc, 4, FALSE);
X			addrp->base = 0;
X		    }
X		    else {
X			addrp->disp = 0;
X			addrp->base = db_reg[LONG][rm];
X		    }
X		    break;
X
X		case 1:
X		    get_value_inc(disp, loc, 1, TRUE);
X		    addrp->disp = disp;
X		    addrp->base = db_reg[LONG][rm];
X		    break;
X
X		case 2:
X		    get_value_inc(disp, loc, 4, FALSE);
X		    addrp->disp = disp;
X		    addrp->base = db_reg[LONG][rm];
X		    break;
X	    }
X	}
X	return (loc);
X}
X
Xstatic void
Xdb_printsym(off)
X	int off;
X{
X	char *p;
X
X	p = nameval(off);
X	if (p)
X		printf("%s", p);
X	else
X		printf("%x", off);
X}
X
Xvoid
Xdb_print_address(seg, size, addrp)
X	char *		seg;
X	int		size;
X	struct i_addr	*addrp;
X{
X	char *p;
X
X	if (addrp->is_reg) {
X	    printf("%s", db_reg[size][addrp->disp]);
X	    return;
X	}
X
X	if (seg) {
X	    printf("%s:", seg);
X	}
X	db_printsym(addrp->disp);
X	if (addrp->base != 0 || addrp->index != 0) {
X	    printf("(");
X	    if (addrp->base)
X		printf("%s", addrp->base);
X	    if (addrp->index)
X		printf(",%s,%d", addrp->index, 1<<addrp->ss);
X	    printf(")");
X	}
X}
X
X/*
X * Disassemble floating-point ("escape") instruction
X * and return updated location.
X */
Xoff_t
Xdb_disasm_esc(loc, inst, short_addr, size, seg)
X	off_t	loc;
X	int		inst;
X	int		short_addr;
X	int		size;
X	char *		seg;
X{
X	int		regmodrm;
X	struct finst	*fp;
X	int		mod;
X	struct i_addr	address;
X	char *		name;
X
X	get_value_inc(regmodrm, loc, 1, FALSE);
X	fp = &db_Esc_inst[inst - 0xd8][f_reg(regmodrm)];
X	mod = f_mod(regmodrm);
X	if (mod != 3) {
X	    /*
X	     * Normal address modes.
X	     */
X	    loc = db_read_address(loc, short_addr, regmodrm, &address);
X	    printf(fp->f_name);
X	    switch(fp->f_size) {
X		case SNGL:
X		    printf("s");
X		    break;
X		case DBLR:
X		    printf("l");
X		    break;
X		case EXTR:
X		    printf("t");
X		    break;
X		case WORD:
X		    printf("s");
X		    break;
X		case LONG:
X		    printf("l");
X		    break;
X		case QUAD:
X		    printf("q");
X		    break;
X		default:
X		    break;
X	    }
X	    printf("\t");
X	    db_print_address(seg, BYTE, &address);
X	}
X	else {
X	    /*
X	     * 'reg-reg' - special formats
X	     */
X	    switch (fp->f_rrmode) {
X		case op2(ST,STI):
X		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
X		    printf("%s\t%%st,%%st(%d)",name,f_rm(regmodrm));
X		    break;
X		case op2(STI,ST):
X		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
X		    printf("%s\t%%st(%d),%%st",name, f_rm(regmodrm));
X		    break;
X		case op1(STI):
X		    name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
X		    printf("%s\t%%st(%d)",name, f_rm(regmodrm));
X		    break;
X		case op1(X):
X		    printf("%s", ((char **)fp->f_rrname)[f_rm(regmodrm)]);
X		    break;
X		case op1(XA):
X		    printf("%s\t%%ax",
X				 ((char **)fp->f_rrname)[f_rm(regmodrm)]);
X		    break;
X		default:
X		    printf("<bad instruction>");
X		    break;
X	    }
X	}
X
X	return (loc);
X}
X
X/*
X * Disassemble instruction at 'loc'.  'altfmt' specifies an
X * (optional) alternate format.  Return address of start of
X * next instruction.
X */
Xoff_t
Xdb_disasm(loc, altfmt)
X	off_t	loc;
X	int	altfmt;
X{
X	int	inst;
X	int	size;
X	int	short_addr;
X	char *	seg;
X	struct inst *	ip;
X	char *	i_name;
X	int	i_size;
X	int	i_mode;
X	int	regmodrm;
X	int	first;
X	int	displ;
X	int	prefix;
X	int	imm;
X	int	imm2;
X	int	len;
X	struct i_addr	address;
X
X	get_value_inc(inst, loc, 1, FALSE);
X	short_addr = FALSE;
X	size = LONG;
X	seg = 0;
X
X	/*
X	 * Get prefixes
X	 */
X	prefix = TRUE;
X	do {
X	    switch (inst) {
X		case 0x66:		/* data16 */
X		    size = WORD;
X		    break;
X		case 0x67:
X		    short_addr = TRUE;
X		    break;
X		case 0x26:
X		    seg = "%es";
X		    break;
X		case 0x36:
X		    seg = "%ss";
X		    break;
X		case 0x2e:
X		    seg = "%cs";
X		    break;
X		case 0x3e:
X		    seg = "%ds";
X		    break;
X		case 0x64:
X		    seg = "%fs";
X		    break;
X		case 0x65:
X		    seg = "%gs";
X		    break;
X		case 0xf0:
X		    printf("lock ");
X		    break;
X		case 0xf2:
X		    printf("repne ");
X		    break;
X		case 0xf3:
X		    printf("repe ");	/* XXX repe VS rep */
X		    break;
X		default:
X		    prefix = FALSE;
X		    break;
X	    }
X	    if (prefix) {
X		get_value_inc(inst, loc, 1, FALSE);
X	    }
X	} while (prefix);
X
X	if (inst >= 0xd8 && inst <= 0xdf) {
X	    loc = db_disasm_esc(loc, inst, short_addr, size, seg);
X	    printf("\n");
X	    return (loc);
X	}
X
X	if (inst == 0x0f) {
X	    get_value_inc(inst, loc, 1, FALSE);
X	    ip = db_inst_0f[inst>>4];
X	    if (ip == 0) {
X		ip = &db_bad_inst;
X	    }
X	    else {
X		ip = &ip[inst&0xf];
X	    }
X	}
X	else
X	    ip = &db_inst_table[inst];
X
X	if (ip->i_has_modrm) {
X	    get_value_inc(regmodrm, loc, 1, FALSE);
X	    loc = db_read_address(loc, short_addr, regmodrm, &address);
X	}
X
X	i_name = ip->i_name;
X	i_size = ip->i_size;
X	i_mode = ip->i_mode;
X
X	if (ip->i_extra == (char *)db_Grp1 ||
X	    ip->i_extra == (char *)db_Grp2 ||
X	    ip->i_extra == (char *)db_Grp6 ||
X	    ip->i_extra == (char *)db_Grp7 ||
X	    ip->i_extra == (char *)db_Grp8) {
X	    i_name = ((char **)ip->i_extra)[f_reg(regmodrm)];
X	}
X	else if (ip->i_extra == (char *)db_Grp3) {
X	    ip = (struct inst *)ip->i_extra;
X	    ip = &ip[f_reg(regmodrm)];
X	    i_name = ip->i_name;
X	    i_mode = ip->i_mode;
X	}
X	else if (ip->i_extra == (char *)db_Grp4 ||
X		 ip->i_extra == (char *)db_Grp5) {
X	    ip = (struct inst *)ip->i_extra;
X	    ip = &ip[f_reg(regmodrm)];
X	    i_name = ip->i_name;
X	    i_mode = ip->i_mode;
X	    i_size = ip->i_size;
X	}
X
X	if (i_size == SDEP) {
X	    if (size == WORD)
X		printf(i_name);
X	    else
X		printf(ip->i_extra);
X	}
X	else {
X	    printf(i_name);
X	    if (i_size != NONE) {
X		if (i_size == BYTE) {
X		    printf("b");
X		    size = BYTE;
X		}
X		else if (i_size == WORD) {
X		    printf("w");
X		    size = WORD;
X		}
X		else if (size == WORD)
X		    printf("w");
X		else
X		    printf("l");
X	    }
X	}
X	printf("\t");
X	for (first = TRUE;
X	     i_mode != 0;
X	     i_mode >>= 8, first = FALSE)
X	{
X	    if (!first)
X		printf(",");
X
X	    switch (i_mode & 0xFF) {
X
X		case E:
X		    db_print_address(seg, size, &address);
X		    break;
X
X		case Eind:
X		    printf("*");
X		    db_print_address(seg, size, &address);
X		    break;
X
X		case Ew:
X		    db_print_address(seg, WORD, &address);
X		    break;
X
X		case Eb:
X		    db_print_address(seg, BYTE, &address);
X		    break;
X
X		case R:
X		    printf("%s", db_reg[size][f_reg(regmodrm)]);
X		    break;
X
X		case Rw:
X		    printf("%s", db_reg[WORD][f_reg(regmodrm)]);
X		    break;
X
X		case Ri:
X		    printf("%s", db_reg[size][f_rm(inst)]);
X		    break;
X
X		case S:
X		    printf("%s", db_seg_reg[f_reg(regmodrm)]);
X		    break;
X
X		case Si:
X		    printf("%s", db_seg_reg[f_reg(inst)]);
X		    break;
X
X		case A:
X		    printf("%s", db_reg[size][0]);	/* acc */
X		    break;
X
X		case BX:
X		    if (seg)
X			printf("%s:", seg);
X		    printf("(%s)", short_addr ? "%bx" : "%ebx");
X		    break;
X
X		case CL:
X		    printf("%%cl");
X		    break;
X
X		case DX:
X		    printf("%%dx");
X		    break;
X
X		case SI:
X		    if (seg)
X			printf("%s:", seg);
X		    printf("(%s)", short_addr ? "%si" : "%esi");
X		    break;
X
X		case DI:
X		    printf("%%es:(%s)", short_addr ? "%di" : "%edi");
X		    break;
X
X		case CR:
X		    printf("%%cr%d", f_reg(regmodrm));
X		    break;
X
X		case DR:
X		    printf("%%dr%d", f_reg(regmodrm));
X		    break;
X
X		case TR:
X		    printf("%%tr%d", f_reg(regmodrm));
X		    break;
X
X		case I:
X		    len = db_lengths[size];
X		    get_value_inc(imm, loc, len, FALSE);/* unsigned */
X		    printf("$%x", imm);
X		    break;
X
X		case Is:
X		    len = db_lengths[size];
X		    get_value_inc(imm, loc, len, TRUE);	/* signed */
X		    printf("$%x", imm);
X		    break;
X
X		case Ib:
X		    get_value_inc(imm, loc, 1, FALSE);	/* unsigned */
X		    printf("$%x", imm);
X		    break;
X
X		case Ibs:
X		    get_value_inc(imm, loc, 1, TRUE);	/* signed */
X		    printf("$%x", imm);
X		    break;
X
X		case Iw:
X		    get_value_inc(imm, loc, 2, FALSE);	/* unsigned */
X		    printf("$%x", imm);
X		    break;
X
X		case Il:
X		    get_value_inc(imm, loc, 4, FALSE);
X		    printf("$%x", imm);
X		    break;
X
X		case O:
X		    if (short_addr) {
X			get_value_inc(displ, loc, 2, TRUE);
X		    }
X		    else {
X			get_value_inc(displ, loc, 4, TRUE);
X		    }
X		    if (seg)
X			printf("%s:%x",seg, displ);
X		    else
X			db_printsym((off_t)displ);
X		    break;
X
X		case Db:
X		    get_value_inc(displ, loc, 1, TRUE);
X		    db_printsym((off_t)(displ + loc));
X		    break;
X
X		case Dl:
X		    get_value_inc(displ, loc, 4, TRUE);
X		    db_printsym((off_t)(displ + loc));
X		    break;
X
X		case o1:
X		    printf("$1");
X		    break;
X
X		case o3:
X		    printf("$3");
X		    break;
X
X		case OS:
X		    get_value_inc(imm, loc, 4, FALSE);	/* offset */
X		    get_value_inc(imm2, loc, 2, FALSE);	/* segment */
X		    printf("$%x,%x", imm2, imm);
X		    break;
X	    }
X	}
X
X	if (altfmt == 0) {
X	    if (inst == 0xe9 || inst == 0xeb) {
X		/*
X		 * GAS pads to longword boundary after unconditional jumps.
X		 */
X		loc = (loc + (4-1)) & ~(4-1);
X	    }
X	}
X	printf("\n");
X	return (loc);
X}
END-of-disasm.c
echo x - dump.c
sed 's/^X//' >dump.c << 'END-of-dump.c'
X/*
X * dump.c
X *	Dump memory in various formats
X */
X#include <unistd.h>
X#include <stdlib.h>
X#include <ctype.h>
X#include <strings.h>
X
Xstatic int dot,			/* Last position we examined */
X	dcount = 0;		/*  ... last count */
Xstatic char lastfmt = 0;	/*  ... last format */
X
X/*
X * get_num()
X *	Convert word to value
X *
X * Numbers, numbers with 0x, and numbers with 0 are treated accordingly.
X * Letters are looked up as a symbol in the symbol table.
X */
Xget_num(str)
X	char *str;
X{
X	char *p;
X	char buf[128];
X	extern int yyval;
X	extern char *expr_line, *expr_pos;
X
X	/*
X	 * Filter garbage
X	 */
X	if (!str || !str[0])
X		return(0);
X
X	/*
X	 * Trim at end of line or next blank
X	 */
X	strcpy(buf, str);
X 	p = strchr(buf, ' ');
X 	if (p)
X 		*p = '\0';
X
X	/*
X	 * Set up for parse, and do the parse
X	 */
X 	expr_line = expr_pos = buf;
X 	(void)yyparse();
X 	return(yyval);
X}
X
X/*
X * dump_s()
X *	Dump strings
X */
Xstatic void
Xdump_s(off, count, phys)
X	int off, count, phys;
X{
X	int x, col = 0;
X	char *buf;
X
X	buf = malloc(count*sizeof(char));
X	if (!buf) {
X		perror("malloc");
X		return;
X	}
X	readloc(off, buf, count*sizeof(char), phys);
X	for (x = 0; x < count; ++x) {
X		printf(" %02x", buf[x] & 0xFF);
X		if (++col >= 16) {
X			int y;
X			char c;
X
X			printf(" ");
X			for (y = 0; y < 16; ++y) {
X				c = buf[x-15+y];
X				if ((c < ' ') || (c >= 0x7F))
X					c = '.';
X				putchar(c);
X			}
X			printf("\n");
X			col = 0;
X		}
X	}
X	if (col) {		/* Partial line */
X		int y;
X
X		for (y = col; y < 16; ++y)
X			printf("   ");
X		for (y = 0; y < col; ++y) {
X			char c;
X
X			c = buf[count-col+y];
X			if ((c < ' ') || (c >= 0x7F))
X				c = '.';
X			putchar(c);
X		}
X		printf("\n");
X	}
X	free(buf);
X}
X
X/*
X * dump_X()
X *	Dump a bunch of hex longwords
X */
Xstatic void
Xdump_X(off, count, phys)
X	int off, count, phys;
X{
X	int x, col = 0;
X	long *buf;
X
X	buf = malloc(count*sizeof(long));
X	if (!buf) {
X		perror("malloc");
X		return;
X	}
X	readloc(off, buf, count*sizeof(long), phys);
X	for (x = 0; x < count; ++x) {
X		printf(" %08X", buf[x]);
X		if (++col >= 8) {
X			printf("\n");
X			col = 0;
X		}
X	}
X	if (col)
X		printf("\n");
X	free(buf);
X}
X
X/*
X * do_dump()
X *	Central workhorse to do the actual memory examination
X */
Xstatic void
Xdo_dump(phys, args)
X	int phys;
X	char *args;
X{
X	char fmt;
X	int count;
X
X	/*
X	 * Use last count, or 1 if no previous count
X	 */
X 	if (dcount > 0)
X 		count = dcount;
X	else
X		count = 1;
X
X	/*
X	 * Use last format, or 'X' if no previous
X	 */
X 	if (lastfmt)
X 		fmt = lastfmt;
X	else
X		fmt = 'X';
X
X	/*
X	 * If first arg non-numeric, use as format
X	 */
X	if (args && args[0] && !isdigit(args[0]) && (args[1] == ' ')) {
X		fmt = args[0];
X		args += 2;
X	}
X
X	/*
X	 * Next arg is address, default to dot otherwise
X	 */
X	if (args && args[0]) {
X		if ((args[0] == '-') && (args[1] == ' ')) {
X			/* Placeholder to specify different count */
X			args += 2;
X		} else {
X			dot = get_num(args);
X			args = strchr(args, ' ');
X			if (args)
X				args += 1;
X		}
X	}
X
X	/*
X	 * Next arg is count, default is 1
X	 */
X 	if (args && args[0]) {
X 		count = get_num(args);
X 	}
X	dcount = count;
X	lastfmt = fmt;
X
X	switch (fmt) {
X	case 'X':
X		dump_X(dot, count, phys);
X		dot += count*4;
X		break;
X	case 's':
X		dump_s(dot, count, phys);
X		dot += count;
X		break;
X	default:
X		printf("Unknown format: '%c'\n", fmt);
X		break;
X	}
X}
X
X/*
X * dump_phys()
X *	Dump memory given physical address
X */
Xdump_phys(args)
X	char *args;
X{
X	do_dump(1, args);
X}
X
X/*
X * dump_virt()
X *	 Dump memory given kernel virtual address
X */
Xdump_virt(args)
X	char *args;
X{
X	do_dump(0, args);
X}
X
X/*
X * dump_instr()
X *	Dump memory, virtual, using instruction format
X */
Xdump_instr(args)
X	char *args;
X{
X	int count = 10, x;
X
X	/*
X	 * Next argument is address
X	 */
X	if (args && args[0]) {
X		dot = get_num(args);
X		args = strchr(args, ' ');
X		if (args)
X			args += 1;
X	}
X
X	/*
X	 * Last argument is count
X	 */
X	if (args && args[0]) {
X		count = get_num(args);
X	}
X
X	/*
X	 * Dump out instructions
X	 */
X 	for (x = 0; x < count; ++x) {
X 		extern char *symloc();
X
X 		printf("%-15s ", symloc(dot));
X 		dot = db_disasm(dot, 0);
X 	}
X}
END-of-dump.c
exit