2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie the
24 * rights to redistribute these changes.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 * Instruction disassembler.
33 #include <sys/param.h>
36 #include <ddb/db_access.h>
37 #include <ddb/db_sym.h>
55 #define E 1 /* general effective address */
56 #define Eind 2 /* indirect address (jump, call) */
57 #define Ew 3 /* address, word size */
58 #define Eb 4 /* address, byte size */
59 #define R 5 /* register, in 'reg' field */
60 #define Rw 6 /* word register, in 'reg' field */
61 #define Ri 7 /* register in instruction */
62 #define S 8 /* segment reg, in 'reg' field */
63 #define Si 9 /* segment reg, in instruction */
64 #define A 10 /* accumulator */
65 #define BX 11 /* (bx) */
66 #define CL 12 /* cl, for shifts */
67 #define DX 13 /* dx, for IO */
68 #define SI 14 /* si */
69 #define DI 15 /* di */
70 #define CR 16 /* control register */
71 #define DR 17 /* debug register */
72 #define TR 18 /* test register */
73 #define I 19 /* immediate, unsigned */
74 #define Is 20 /* immediate, signed */
75 #define Ib 21 /* byte immediate, unsigned */
76 #define Ibs 22 /* byte immediate, signed */
77 #define Iw 23 /* word immediate, unsigned */
78 #define O 25 /* direct address */
79 #define Db 26 /* byte displacement from EIP */
80 #define Dl 27 /* long displacement from EIP */
81 #define o1 28 /* constant 1 */
82 #define o3 29 /* constant 3 */
83 #define OS 30 /* immediate offset/segment */
84 #define ST 31 /* FP stack top */
85 #define STI 32 /* FP stack */
86 #define X 33 /* extended FP op */
87 #define XA 34 /* for 'fstcw %ax' */
88 #define El 35 /* address, long size */
89 #define Ril 36 /* long register in instruction */
90 #define Iba 37 /* byte immediate, don't print if 0xa */
93 const char * i_name
; /* name */
94 short i_has_modrm
; /* has regmodrm byte */
95 short i_size
; /* operand size */
96 int i_mode
; /* addressing modes */
97 const void * i_extra
; /* pointer to extra opcode table */
101 #define op2(x,y) ((x)|((y)<<8))
102 #define op3(x,y,z) ((x)|((y)<<8)|((z)<<16))
105 const char * f_name
; /* name for memory instruction */
106 int f_size
; /* size for memory instruction */
107 int f_rrmode
; /* mode for rr instruction */
108 const void * f_rrname
; /* name for rr instruction
109 (or pointer to table) */
112 static const char * const db_Grp6
[] = {
123 static const char * const db_Grp7
[] = {
134 static const char * const db_Grp8
[] = {
145 static const char * const db_Grp9
[] = {
156 static const char * const db_Grp15
[] = {
167 static const char * const db_Grp15b
[] = {
178 static const struct inst db_inst_0f0x
[] = {
179 /*00*/ { "", TRUE
, NONE
, op1(Ew
), db_Grp6
},
180 /*01*/ { "", TRUE
, NONE
, op1(Ew
), db_Grp7
},
181 /*02*/ { "lar", TRUE
, LONG
, op2(E
,R
), 0 },
182 /*03*/ { "lsl", TRUE
, LONG
, op2(E
,R
), 0 },
183 /*04*/ { "", FALSE
, NONE
, 0, 0 },
184 /*05*/ { "syscall",FALSE
,NONE
, 0, 0 },
185 /*06*/ { "clts", FALSE
, NONE
, 0, 0 },
186 /*07*/ { "sysret",FALSE
, NONE
, 0, 0 },
188 /*08*/ { "invd", FALSE
, NONE
, 0, 0 },
189 /*09*/ { "wbinvd",FALSE
, NONE
, 0, 0 },
190 /*0a*/ { "", FALSE
, NONE
, 0, 0 },
191 /*0b*/ { "", FALSE
, NONE
, 0, 0 },
192 /*0c*/ { "", FALSE
, NONE
, 0, 0 },
193 /*0d*/ { "", FALSE
, NONE
, 0, 0 },
194 /*0e*/ { "", FALSE
, NONE
, 0, 0 },
195 /*0f*/ { "", FALSE
, NONE
, 0, 0 },
198 static const struct inst db_inst_0f1x
[] = {
199 /*10*/ { "", FALSE
, NONE
, 0, 0 },
200 /*11*/ { "", FALSE
, NONE
, 0, 0 },
201 /*12*/ { "", FALSE
, NONE
, 0, 0 },
202 /*13*/ { "", FALSE
, NONE
, 0, 0 },
203 /*14*/ { "", FALSE
, NONE
, 0, 0 },
204 /*15*/ { "", FALSE
, NONE
, 0, 0 },
205 /*16*/ { "", FALSE
, NONE
, 0, 0 },
206 /*17*/ { "", FALSE
, NONE
, 0, 0 },
208 /*18*/ { "", FALSE
, NONE
, 0, 0 },
209 /*19*/ { "", FALSE
, NONE
, 0, 0 },
210 /*1a*/ { "", FALSE
, NONE
, 0, 0 },
211 /*1b*/ { "", FALSE
, NONE
, 0, 0 },
212 /*1c*/ { "", FALSE
, NONE
, 0, 0 },
213 /*1d*/ { "", FALSE
, NONE
, 0, 0 },
214 /*1e*/ { "", FALSE
, NONE
, 0, 0 },
215 /*1f*/ { "nopl", TRUE
, SDEP
, 0, "nopw" },
218 static const struct inst db_inst_0f2x
[] = {
219 /*20*/ { "mov", TRUE
, LONG
, op2(CR
,El
), 0 },
220 /*21*/ { "mov", TRUE
, LONG
, op2(DR
,El
), 0 },
221 /*22*/ { "mov", TRUE
, LONG
, op2(El
,CR
), 0 },
222 /*23*/ { "mov", TRUE
, LONG
, op2(El
,DR
), 0 },
223 /*24*/ { "mov", TRUE
, LONG
, op2(TR
,El
), 0 },
224 /*25*/ { "", FALSE
, NONE
, 0, 0 },
225 /*26*/ { "mov", TRUE
, LONG
, op2(El
,TR
), 0 },
226 /*27*/ { "", FALSE
, NONE
, 0, 0 },
228 /*28*/ { "", FALSE
, NONE
, 0, 0 },
229 /*29*/ { "", FALSE
, NONE
, 0, 0 },
230 /*2a*/ { "", FALSE
, NONE
, 0, 0 },
231 /*2b*/ { "", FALSE
, NONE
, 0, 0 },
232 /*2c*/ { "", FALSE
, NONE
, 0, 0 },
233 /*2d*/ { "", FALSE
, NONE
, 0, 0 },
234 /*2e*/ { "", FALSE
, NONE
, 0, 0 },
235 /*2f*/ { "", FALSE
, NONE
, 0, 0 },
238 static const struct inst db_inst_0f3x
[] = {
239 /*30*/ { "wrmsr", FALSE
, NONE
, 0, 0 },
240 /*31*/ { "rdtsc", FALSE
, NONE
, 0, 0 },
241 /*32*/ { "rdmsr", FALSE
, NONE
, 0, 0 },
242 /*33*/ { "rdpmc", FALSE
, NONE
, 0, 0 },
243 /*34*/ { "sysenter",FALSE
,NONE
, 0, 0 },
244 /*35*/ { "sysexit",FALSE
,NONE
, 0, 0 },
245 /*36*/ { "", FALSE
, NONE
, 0, 0 },
246 /*37*/ { "getsec",FALSE
, NONE
, 0, 0 },
248 /*38*/ { "", FALSE
, NONE
, 0, 0 },
249 /*39*/ { "", FALSE
, NONE
, 0, 0 },
250 /*3a*/ { "", FALSE
, NONE
, 0, 0 },
251 /*3b*/ { "", FALSE
, NONE
, 0, 0 },
252 /*3c*/ { "", FALSE
, NONE
, 0, 0 },
253 /*3d*/ { "", FALSE
, NONE
, 0, 0 },
254 /*3e*/ { "", FALSE
, NONE
, 0, 0 },
255 /*3f*/ { "", FALSE
, NONE
, 0, 0 },
258 static const struct inst db_inst_0f4x
[] = {
259 /*40*/ { "cmovo", TRUE
, NONE
, op2(E
, R
), 0 },
260 /*41*/ { "cmovno", TRUE
, NONE
, op2(E
, R
), 0 },
261 /*42*/ { "cmovb", TRUE
, NONE
, op2(E
, R
), 0 },
262 /*43*/ { "cmovnb", TRUE
, NONE
, op2(E
, R
), 0 },
263 /*44*/ { "cmovz", TRUE
, NONE
, op2(E
, R
), 0 },
264 /*45*/ { "cmovnz", TRUE
, NONE
, op2(E
, R
), 0 },
265 /*46*/ { "cmovbe", TRUE
, NONE
, op2(E
, R
), 0 },
266 /*47*/ { "cmovnbe",TRUE
, NONE
, op2(E
, R
), 0 },
268 /*48*/ { "cmovs", TRUE
, NONE
, op2(E
, R
), 0 },
269 /*49*/ { "cmovns", TRUE
, NONE
, op2(E
, R
), 0 },
270 /*4a*/ { "cmovp", TRUE
, NONE
, op2(E
, R
), 0 },
271 /*4b*/ { "cmovnp", TRUE
, NONE
, op2(E
, R
), 0 },
272 /*4c*/ { "cmovl", TRUE
, NONE
, op2(E
, R
), 0 },
273 /*4d*/ { "cmovnl", TRUE
, NONE
, op2(E
, R
), 0 },
274 /*4e*/ { "cmovle", TRUE
, NONE
, op2(E
, R
), 0 },
275 /*4f*/ { "cmovnle",TRUE
, NONE
, op2(E
, R
), 0 },
278 static const struct inst db_inst_0f8x
[] = {
279 /*80*/ { "jo", FALSE
, NONE
, op1(Dl
), 0 },
280 /*81*/ { "jno", FALSE
, NONE
, op1(Dl
), 0 },
281 /*82*/ { "jb", FALSE
, NONE
, op1(Dl
), 0 },
282 /*83*/ { "jnb", FALSE
, NONE
, op1(Dl
), 0 },
283 /*84*/ { "jz", FALSE
, NONE
, op1(Dl
), 0 },
284 /*85*/ { "jnz", FALSE
, NONE
, op1(Dl
), 0 },
285 /*86*/ { "jbe", FALSE
, NONE
, op1(Dl
), 0 },
286 /*87*/ { "jnbe", FALSE
, NONE
, op1(Dl
), 0 },
288 /*88*/ { "js", FALSE
, NONE
, op1(Dl
), 0 },
289 /*89*/ { "jns", FALSE
, NONE
, op1(Dl
), 0 },
290 /*8a*/ { "jp", FALSE
, NONE
, op1(Dl
), 0 },
291 /*8b*/ { "jnp", FALSE
, NONE
, op1(Dl
), 0 },
292 /*8c*/ { "jl", FALSE
, NONE
, op1(Dl
), 0 },
293 /*8d*/ { "jnl", FALSE
, NONE
, op1(Dl
), 0 },
294 /*8e*/ { "jle", FALSE
, NONE
, op1(Dl
), 0 },
295 /*8f*/ { "jnle", FALSE
, NONE
, op1(Dl
), 0 },
298 static const struct inst db_inst_0f9x
[] = {
299 /*90*/ { "seto", TRUE
, NONE
, op1(Eb
), 0 },
300 /*91*/ { "setno", TRUE
, NONE
, op1(Eb
), 0 },
301 /*92*/ { "setb", TRUE
, NONE
, op1(Eb
), 0 },
302 /*93*/ { "setnb", TRUE
, NONE
, op1(Eb
), 0 },
303 /*94*/ { "setz", TRUE
, NONE
, op1(Eb
), 0 },
304 /*95*/ { "setnz", TRUE
, NONE
, op1(Eb
), 0 },
305 /*96*/ { "setbe", TRUE
, NONE
, op1(Eb
), 0 },
306 /*97*/ { "setnbe",TRUE
, NONE
, op1(Eb
), 0 },
308 /*98*/ { "sets", TRUE
, NONE
, op1(Eb
), 0 },
309 /*99*/ { "setns", TRUE
, NONE
, op1(Eb
), 0 },
310 /*9a*/ { "setp", TRUE
, NONE
, op1(Eb
), 0 },
311 /*9b*/ { "setnp", TRUE
, NONE
, op1(Eb
), 0 },
312 /*9c*/ { "setl", TRUE
, NONE
, op1(Eb
), 0 },
313 /*9d*/ { "setnl", TRUE
, NONE
, op1(Eb
), 0 },
314 /*9e*/ { "setle", TRUE
, NONE
, op1(Eb
), 0 },
315 /*9f*/ { "setnle",TRUE
, NONE
, op1(Eb
), 0 },
318 static const struct inst db_inst_0fax
[] = {
319 /*a0*/ { "push", FALSE
, NONE
, op1(Si
), 0 },
320 /*a1*/ { "pop", FALSE
, NONE
, op1(Si
), 0 },
321 /*a2*/ { "cpuid", FALSE
, NONE
, 0, 0 },
322 /*a3*/ { "bt", TRUE
, LONG
, op2(R
,E
), 0 },
323 /*a4*/ { "shld", TRUE
, LONG
, op3(Ib
,R
,E
), 0 },
324 /*a5*/ { "shld", TRUE
, LONG
, op3(CL
,R
,E
), 0 },
325 /*a6*/ { "", FALSE
, NONE
, 0, 0 },
326 /*a7*/ { "", FALSE
, NONE
, 0, 0 },
328 /*a8*/ { "push", FALSE
, NONE
, op1(Si
), 0 },
329 /*a9*/ { "pop", FALSE
, NONE
, op1(Si
), 0 },
330 /*aa*/ { "rsm", FALSE
, NONE
, 0, 0 },
331 /*ab*/ { "bts", TRUE
, LONG
, op2(R
,E
), 0 },
332 /*ac*/ { "shrd", TRUE
, LONG
, op3(Ib
,R
,E
), 0 },
333 /*ad*/ { "shrd", TRUE
, LONG
, op3(CL
,R
,E
), 0 },
334 /*ae*/ { "", TRUE
, LONG
, op1(E
), db_Grp15
},
335 /*af*/ { "imul", TRUE
, LONG
, op2(E
,R
), 0 },
338 static const struct inst db_inst_0fbx
[] = {
339 /*b0*/ { "cmpxchg",TRUE
, BYTE
, op2(R
, E
), 0 },
340 /*b0*/ { "cmpxchg",TRUE
, LONG
, op2(R
, E
), 0 },
341 /*b2*/ { "lss", TRUE
, LONG
, op2(E
, R
), 0 },
342 /*b3*/ { "btr", TRUE
, LONG
, op2(R
, E
), 0 },
343 /*b4*/ { "lfs", TRUE
, LONG
, op2(E
, R
), 0 },
344 /*b5*/ { "lgs", TRUE
, LONG
, op2(E
, R
), 0 },
345 /*b6*/ { "movzb", TRUE
, LONG
, op2(Eb
, R
), 0 },
346 /*b7*/ { "movzw", TRUE
, LONG
, op2(Ew
, R
), 0 },
348 /*b8*/ { "", FALSE
, NONE
, 0, 0 },
349 /*b9*/ { "", FALSE
, NONE
, 0, 0 },
350 /*ba*/ { "", TRUE
, LONG
, op2(Ib
, E
), db_Grp8
},
351 /*bb*/ { "btc", TRUE
, LONG
, op2(R
, E
), 0 },
352 /*bc*/ { "bsf", TRUE
, LONG
, op2(E
, R
), 0 },
353 /*bd*/ { "bsr", TRUE
, LONG
, op2(E
, R
), 0 },
354 /*be*/ { "movsb", TRUE
, LONG
, op2(Eb
, R
), 0 },
355 /*bf*/ { "movsw", TRUE
, LONG
, op2(Ew
, R
), 0 },
358 static const struct inst db_inst_0fcx
[] = {
359 /*c0*/ { "xadd", TRUE
, BYTE
, op2(R
, E
), 0 },
360 /*c1*/ { "xadd", TRUE
, LONG
, op2(R
, E
), 0 },
361 /*c2*/ { "", FALSE
, NONE
, 0, 0 },
362 /*c3*/ { "", FALSE
, NONE
, 0, 0 },
363 /*c4*/ { "", FALSE
, NONE
, 0, 0 },
364 /*c5*/ { "", FALSE
, NONE
, 0, 0 },
365 /*c6*/ { "", FALSE
, NONE
, 0, 0 },
366 /*c7*/ { "", TRUE
, NONE
, op1(E
), db_Grp9
},
367 /*c8*/ { "bswap", FALSE
, LONG
, op1(Ril
), 0 },
368 /*c9*/ { "bswap", FALSE
, LONG
, op1(Ril
), 0 },
369 /*ca*/ { "bswap", FALSE
, LONG
, op1(Ril
), 0 },
370 /*cb*/ { "bswap", FALSE
, LONG
, op1(Ril
), 0 },
371 /*cc*/ { "bswap", FALSE
, LONG
, op1(Ril
), 0 },
372 /*cd*/ { "bswap", FALSE
, LONG
, op1(Ril
), 0 },
373 /*ce*/ { "bswap", FALSE
, LONG
, op1(Ril
), 0 },
374 /*cf*/ { "bswap", FALSE
, LONG
, op1(Ril
), 0 },
377 static const struct inst
* const db_inst_0f
[] = {
396 static const char * const db_Esc92
[] = {
397 "fnop", "", "", "", "", "", "", ""
399 static const char * const db_Esc94
[] = {
400 "fchs", "fabs", "", "", "ftst", "fxam", "", ""
402 static const char * const db_Esc95
[] = {
403 "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
405 static const char * const db_Esc96
[] = {
406 "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
409 static const char * const db_Esc97
[] = {
410 "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
413 static const char * const db_Esca5
[] = {
414 "", "fucompp","", "", "", "", "", ""
417 static const char * const db_Escb4
[] = {
418 "fneni","fndisi", "fnclex","fninit","fsetpm", "", "", ""
421 static const char * const db_Esce3
[] = {
422 "", "fcompp","", "", "", "", "", ""
425 static const char * const db_Escf4
[] = {
426 "fnstsw","", "", "", "", "", "", ""
429 static const struct finst db_Esc8
[] = {
430 /*0*/ { "fadd", SNGL
, op2(STI
,ST
), 0 },
431 /*1*/ { "fmul", SNGL
, op2(STI
,ST
), 0 },
432 /*2*/ { "fcom", SNGL
, op2(STI
,ST
), 0 },
433 /*3*/ { "fcomp", SNGL
, op2(STI
,ST
), 0 },
434 /*4*/ { "fsub", SNGL
, op2(STI
,ST
), 0 },
435 /*5*/ { "fsubr", SNGL
, op2(STI
,ST
), 0 },
436 /*6*/ { "fdiv", SNGL
, op2(STI
,ST
), 0 },
437 /*7*/ { "fdivr", SNGL
, op2(STI
,ST
), 0 },
440 static const struct finst db_Esc9
[] = {
441 /*0*/ { "fld", SNGL
, op1(STI
), 0 },
442 /*1*/ { "", NONE
, op1(STI
), "fxch" },
443 /*2*/ { "fst", SNGL
, op1(X
), db_Esc92
},
444 /*3*/ { "fstp", SNGL
, 0, 0 },
445 /*4*/ { "fldenv", NONE
, op1(X
), db_Esc94
},
446 /*5*/ { "fldcw", NONE
, op1(X
), db_Esc95
},
447 /*6*/ { "fnstenv",NONE
, op1(X
), db_Esc96
},
448 /*7*/ { "fnstcw", NONE
, op1(X
), db_Esc97
},
451 static const struct finst db_Esca
[] = {
452 /*0*/ { "fiadd", LONG
, 0, 0 },
453 /*1*/ { "fimul", LONG
, 0, 0 },
454 /*2*/ { "ficom", LONG
, 0, 0 },
455 /*3*/ { "ficomp", LONG
, 0, 0 },
456 /*4*/ { "fisub", LONG
, 0, 0 },
457 /*5*/ { "fisubr", LONG
, op1(X
), db_Esca5
},
458 /*6*/ { "fidiv", LONG
, 0, 0 },
459 /*7*/ { "fidivr", LONG
, 0, 0 }
462 static const struct finst db_Escb
[] = {
463 /*0*/ { "fild", LONG
, 0, 0 },
464 /*1*/ { "", NONE
, 0, 0 },
465 /*2*/ { "fist", LONG
, 0, 0 },
466 /*3*/ { "fistp", LONG
, 0, 0 },
467 /*4*/ { "", WORD
, op1(X
), db_Escb4
},
468 /*5*/ { "fld", EXTR
, 0, 0 },
469 /*6*/ { "", WORD
, 0, 0 },
470 /*7*/ { "fstp", EXTR
, 0, 0 },
473 static const struct finst db_Escc
[] = {
474 /*0*/ { "fadd", DBLR
, op2(ST
,STI
), 0 },
475 /*1*/ { "fmul", DBLR
, op2(ST
,STI
), 0 },
476 /*2*/ { "fcom", DBLR
, 0, 0 },
477 /*3*/ { "fcomp", DBLR
, 0, 0 },
478 /*4*/ { "fsub", DBLR
, op2(ST
,STI
), "fsubr" },
479 /*5*/ { "fsubr", DBLR
, op2(ST
,STI
), "fsub" },
480 /*6*/ { "fdiv", DBLR
, op2(ST
,STI
), "fdivr" },
481 /*7*/ { "fdivr", DBLR
, op2(ST
,STI
), "fdiv" },
484 static const struct finst db_Escd
[] = {
485 /*0*/ { "fld", DBLR
, op1(STI
), "ffree" },
486 /*1*/ { "", NONE
, 0, 0 },
487 /*2*/ { "fst", DBLR
, op1(STI
), 0 },
488 /*3*/ { "fstp", DBLR
, op1(STI
), 0 },
489 /*4*/ { "frstor", NONE
, op1(STI
), "fucom" },
490 /*5*/ { "", NONE
, op1(STI
), "fucomp" },
491 /*6*/ { "fnsave", NONE
, 0, 0 },
492 /*7*/ { "fnstsw", NONE
, 0, 0 },
495 static const struct finst db_Esce
[] = {
496 /*0*/ { "fiadd", WORD
, op2(ST
,STI
), "faddp" },
497 /*1*/ { "fimul", WORD
, op2(ST
,STI
), "fmulp" },
498 /*2*/ { "ficom", WORD
, 0, 0 },
499 /*3*/ { "ficomp", WORD
, op1(X
), db_Esce3
},
500 /*4*/ { "fisub", WORD
, op2(ST
,STI
), "fsubrp" },
501 /*5*/ { "fisubr", WORD
, op2(ST
,STI
), "fsubp" },
502 /*6*/ { "fidiv", WORD
, op2(ST
,STI
), "fdivrp" },
503 /*7*/ { "fidivr", WORD
, op2(ST
,STI
), "fdivp" },
506 static const struct finst db_Escf
[] = {
507 /*0*/ { "fild", WORD
, 0, 0 },
508 /*1*/ { "", NONE
, 0, 0 },
509 /*2*/ { "fist", WORD
, 0, 0 },
510 /*3*/ { "fistp", WORD
, 0, 0 },
511 /*4*/ { "fbld", NONE
, op1(XA
), db_Escf4
},
512 /*5*/ { "fild", QUAD
, 0, 0 },
513 /*6*/ { "fbstp", NONE
, 0, 0 },
514 /*7*/ { "fistp", QUAD
, 0, 0 },
517 static const struct finst
* const db_Esc_inst
[] = {
518 db_Esc8
, db_Esc9
, db_Esca
, db_Escb
,
519 db_Escc
, db_Escd
, db_Esce
, db_Escf
522 static const char * const db_Grp1
[] = {
533 static const char * const db_Grp2
[] = {
544 static const struct inst db_Grp3
[] = {
545 { "test", TRUE
, NONE
, op2(I
,E
), 0 },
546 { "test", TRUE
, NONE
, op2(I
,E
), 0 },
547 { "not", TRUE
, NONE
, op1(E
), 0 },
548 { "neg", TRUE
, NONE
, op1(E
), 0 },
549 { "mul", TRUE
, NONE
, op2(E
,A
), 0 },
550 { "imul", TRUE
, NONE
, op2(E
,A
), 0 },
551 { "div", TRUE
, NONE
, op2(E
,A
), 0 },
552 { "idiv", TRUE
, NONE
, op2(E
,A
), 0 },
555 static const struct inst db_Grp4
[] = {
556 { "inc", TRUE
, BYTE
, op1(E
), 0 },
557 { "dec", TRUE
, BYTE
, op1(E
), 0 },
558 { "", TRUE
, NONE
, 0, 0 },
559 { "", TRUE
, NONE
, 0, 0 },
560 { "", TRUE
, NONE
, 0, 0 },
561 { "", TRUE
, NONE
, 0, 0 },
562 { "", TRUE
, NONE
, 0, 0 },
563 { "", TRUE
, NONE
, 0, 0 }
566 static const struct inst db_Grp5
[] = {
567 { "inc", TRUE
, LONG
, op1(E
), 0 },
568 { "dec", TRUE
, LONG
, op1(E
), 0 },
569 { "call", TRUE
, LONG
, op1(Eind
),0 },
570 { "lcall", TRUE
, LONG
, op1(Eind
),0 },
571 { "jmp", TRUE
, LONG
, op1(Eind
),0 },
572 { "ljmp", TRUE
, LONG
, op1(Eind
),0 },
573 { "push", TRUE
, LONG
, op1(E
), 0 },
574 { "", TRUE
, NONE
, 0, 0 }
577 static const struct inst db_inst_table
[256] = {
578 /*00*/ { "add", TRUE
, BYTE
, op2(R
, E
), 0 },
579 /*01*/ { "add", TRUE
, LONG
, op2(R
, E
), 0 },
580 /*02*/ { "add", TRUE
, BYTE
, op2(E
, R
), 0 },
581 /*03*/ { "add", TRUE
, LONG
, op2(E
, R
), 0 },
582 /*04*/ { "add", FALSE
, BYTE
, op2(I
, A
), 0 },
583 /*05*/ { "add", FALSE
, LONG
, op2(Is
, A
), 0 },
584 /*06*/ { "push", FALSE
, NONE
, op1(Si
), 0 },
585 /*07*/ { "pop", FALSE
, NONE
, op1(Si
), 0 },
587 /*08*/ { "or", TRUE
, BYTE
, op2(R
, E
), 0 },
588 /*09*/ { "or", TRUE
, LONG
, op2(R
, E
), 0 },
589 /*0a*/ { "or", TRUE
, BYTE
, op2(E
, R
), 0 },
590 /*0b*/ { "or", TRUE
, LONG
, op2(E
, R
), 0 },
591 /*0c*/ { "or", FALSE
, BYTE
, op2(I
, A
), 0 },
592 /*0d*/ { "or", FALSE
, LONG
, op2(I
, A
), 0 },
593 /*0e*/ { "push", FALSE
, NONE
, op1(Si
), 0 },
594 /*0f*/ { "", FALSE
, NONE
, 0, 0 },
596 /*10*/ { "adc", TRUE
, BYTE
, op2(R
, E
), 0 },
597 /*11*/ { "adc", TRUE
, LONG
, op2(R
, E
), 0 },
598 /*12*/ { "adc", TRUE
, BYTE
, op2(E
, R
), 0 },
599 /*13*/ { "adc", TRUE
, LONG
, op2(E
, R
), 0 },
600 /*14*/ { "adc", FALSE
, BYTE
, op2(I
, A
), 0 },
601 /*15*/ { "adc", FALSE
, LONG
, op2(Is
, A
), 0 },
602 /*16*/ { "push", FALSE
, NONE
, op1(Si
), 0 },
603 /*17*/ { "pop", FALSE
, NONE
, op1(Si
), 0 },
605 /*18*/ { "sbb", TRUE
, BYTE
, op2(R
, E
), 0 },
606 /*19*/ { "sbb", TRUE
, LONG
, op2(R
, E
), 0 },
607 /*1a*/ { "sbb", TRUE
, BYTE
, op2(E
, R
), 0 },
608 /*1b*/ { "sbb", TRUE
, LONG
, op2(E
, R
), 0 },
609 /*1c*/ { "sbb", FALSE
, BYTE
, op2(I
, A
), 0 },
610 /*1d*/ { "sbb", FALSE
, LONG
, op2(Is
, A
), 0 },
611 /*1e*/ { "push", FALSE
, NONE
, op1(Si
), 0 },
612 /*1f*/ { "pop", FALSE
, NONE
, op1(Si
), 0 },
614 /*20*/ { "and", TRUE
, BYTE
, op2(R
, E
), 0 },
615 /*21*/ { "and", TRUE
, LONG
, op2(R
, E
), 0 },
616 /*22*/ { "and", TRUE
, BYTE
, op2(E
, R
), 0 },
617 /*23*/ { "and", TRUE
, LONG
, op2(E
, R
), 0 },
618 /*24*/ { "and", FALSE
, BYTE
, op2(I
, A
), 0 },
619 /*25*/ { "and", FALSE
, LONG
, op2(I
, A
), 0 },
620 /*26*/ { "", FALSE
, NONE
, 0, 0 },
621 /*27*/ { "daa", FALSE
, NONE
, 0, 0 },
623 /*28*/ { "sub", TRUE
, BYTE
, op2(R
, E
), 0 },
624 /*29*/ { "sub", TRUE
, LONG
, op2(R
, E
), 0 },
625 /*2a*/ { "sub", TRUE
, BYTE
, op2(E
, R
), 0 },
626 /*2b*/ { "sub", TRUE
, LONG
, op2(E
, R
), 0 },
627 /*2c*/ { "sub", FALSE
, BYTE
, op2(I
, A
), 0 },
628 /*2d*/ { "sub", FALSE
, LONG
, op2(Is
, A
), 0 },
629 /*2e*/ { "", FALSE
, NONE
, 0, 0 },
630 /*2f*/ { "das", FALSE
, NONE
, 0, 0 },
632 /*30*/ { "xor", TRUE
, BYTE
, op2(R
, E
), 0 },
633 /*31*/ { "xor", TRUE
, LONG
, op2(R
, E
), 0 },
634 /*32*/ { "xor", TRUE
, BYTE
, op2(E
, R
), 0 },
635 /*33*/ { "xor", TRUE
, LONG
, op2(E
, R
), 0 },
636 /*34*/ { "xor", FALSE
, BYTE
, op2(I
, A
), 0 },
637 /*35*/ { "xor", FALSE
, LONG
, op2(I
, A
), 0 },
638 /*36*/ { "", FALSE
, NONE
, 0, 0 },
639 /*37*/ { "aaa", FALSE
, NONE
, 0, 0 },
641 /*38*/ { "cmp", TRUE
, BYTE
, op2(R
, E
), 0 },
642 /*39*/ { "cmp", TRUE
, LONG
, op2(R
, E
), 0 },
643 /*3a*/ { "cmp", TRUE
, BYTE
, op2(E
, R
), 0 },
644 /*3b*/ { "cmp", TRUE
, LONG
, op2(E
, R
), 0 },
645 /*3c*/ { "cmp", FALSE
, BYTE
, op2(I
, A
), 0 },
646 /*3d*/ { "cmp", FALSE
, LONG
, op2(Is
, A
), 0 },
647 /*3e*/ { "", FALSE
, NONE
, 0, 0 },
648 /*3f*/ { "aas", FALSE
, NONE
, 0, 0 },
650 /*40*/ { "inc", FALSE
, LONG
, op1(Ri
), 0 },
651 /*41*/ { "inc", FALSE
, LONG
, op1(Ri
), 0 },
652 /*42*/ { "inc", FALSE
, LONG
, op1(Ri
), 0 },
653 /*43*/ { "inc", FALSE
, LONG
, op1(Ri
), 0 },
654 /*44*/ { "inc", FALSE
, LONG
, op1(Ri
), 0 },
655 /*45*/ { "inc", FALSE
, LONG
, op1(Ri
), 0 },
656 /*46*/ { "inc", FALSE
, LONG
, op1(Ri
), 0 },
657 /*47*/ { "inc", FALSE
, LONG
, op1(Ri
), 0 },
659 /*48*/ { "dec", FALSE
, LONG
, op1(Ri
), 0 },
660 /*49*/ { "dec", FALSE
, LONG
, op1(Ri
), 0 },
661 /*4a*/ { "dec", FALSE
, LONG
, op1(Ri
), 0 },
662 /*4b*/ { "dec", FALSE
, LONG
, op1(Ri
), 0 },
663 /*4c*/ { "dec", FALSE
, LONG
, op1(Ri
), 0 },
664 /*4d*/ { "dec", FALSE
, LONG
, op1(Ri
), 0 },
665 /*4e*/ { "dec", FALSE
, LONG
, op1(Ri
), 0 },
666 /*4f*/ { "dec", FALSE
, LONG
, op1(Ri
), 0 },
668 /*50*/ { "push", FALSE
, LONG
, op1(Ri
), 0 },
669 /*51*/ { "push", FALSE
, LONG
, op1(Ri
), 0 },
670 /*52*/ { "push", FALSE
, LONG
, op1(Ri
), 0 },
671 /*53*/ { "push", FALSE
, LONG
, op1(Ri
), 0 },
672 /*54*/ { "push", FALSE
, LONG
, op1(Ri
), 0 },
673 /*55*/ { "push", FALSE
, LONG
, op1(Ri
), 0 },
674 /*56*/ { "push", FALSE
, LONG
, op1(Ri
), 0 },
675 /*57*/ { "push", FALSE
, LONG
, op1(Ri
), 0 },
677 /*58*/ { "pop", FALSE
, LONG
, op1(Ri
), 0 },
678 /*59*/ { "pop", FALSE
, LONG
, op1(Ri
), 0 },
679 /*5a*/ { "pop", FALSE
, LONG
, op1(Ri
), 0 },
680 /*5b*/ { "pop", FALSE
, LONG
, op1(Ri
), 0 },
681 /*5c*/ { "pop", FALSE
, LONG
, op1(Ri
), 0 },
682 /*5d*/ { "pop", FALSE
, LONG
, op1(Ri
), 0 },
683 /*5e*/ { "pop", FALSE
, LONG
, op1(Ri
), 0 },
684 /*5f*/ { "pop", FALSE
, LONG
, op1(Ri
), 0 },
686 /*60*/ { "pusha", FALSE
, LONG
, 0, 0 },
687 /*61*/ { "popa", FALSE
, LONG
, 0, 0 },
688 /*62*/ { "bound", TRUE
, LONG
, op2(E
, R
), 0 },
689 /*63*/ { "arpl", TRUE
, NONE
, op2(Rw
,Ew
), 0 },
691 /*64*/ { "", FALSE
, NONE
, 0, 0 },
692 /*65*/ { "", FALSE
, NONE
, 0, 0 },
693 /*66*/ { "", FALSE
, NONE
, 0, 0 },
694 /*67*/ { "", FALSE
, NONE
, 0, 0 },
696 /*68*/ { "push", FALSE
, LONG
, op1(I
), 0 },
697 /*69*/ { "imul", TRUE
, LONG
, op3(I
,E
,R
), 0 },
698 /*6a*/ { "push", FALSE
, LONG
, op1(Ibs
), 0 },
699 /*6b*/ { "imul", TRUE
, LONG
, op3(Ibs
,E
,R
),0 },
700 /*6c*/ { "ins", FALSE
, BYTE
, op2(DX
, DI
), 0 },
701 /*6d*/ { "ins", FALSE
, LONG
, op2(DX
, DI
), 0 },
702 /*6e*/ { "outs", FALSE
, BYTE
, op2(SI
, DX
), 0 },
703 /*6f*/ { "outs", FALSE
, LONG
, op2(SI
, DX
), 0 },
705 /*70*/ { "jo", FALSE
, NONE
, op1(Db
), 0 },
706 /*71*/ { "jno", FALSE
, NONE
, op1(Db
), 0 },
707 /*72*/ { "jb", FALSE
, NONE
, op1(Db
), 0 },
708 /*73*/ { "jnb", FALSE
, NONE
, op1(Db
), 0 },
709 /*74*/ { "jz", FALSE
, NONE
, op1(Db
), 0 },
710 /*75*/ { "jnz", FALSE
, NONE
, op1(Db
), 0 },
711 /*76*/ { "jbe", FALSE
, NONE
, op1(Db
), 0 },
712 /*77*/ { "jnbe", FALSE
, NONE
, op1(Db
), 0 },
714 /*78*/ { "js", FALSE
, NONE
, op1(Db
), 0 },
715 /*79*/ { "jns", FALSE
, NONE
, op1(Db
), 0 },
716 /*7a*/ { "jp", FALSE
, NONE
, op1(Db
), 0 },
717 /*7b*/ { "jnp", FALSE
, NONE
, op1(Db
), 0 },
718 /*7c*/ { "jl", FALSE
, NONE
, op1(Db
), 0 },
719 /*7d*/ { "jnl", FALSE
, NONE
, op1(Db
), 0 },
720 /*7e*/ { "jle", FALSE
, NONE
, op1(Db
), 0 },
721 /*7f*/ { "jnle", FALSE
, NONE
, op1(Db
), 0 },
723 /*80*/ { "", TRUE
, BYTE
, op2(I
, E
), db_Grp1
},
724 /*81*/ { "", TRUE
, LONG
, op2(I
, E
), db_Grp1
},
725 /*82*/ { "", TRUE
, BYTE
, op2(I
, E
), db_Grp1
},
726 /*83*/ { "", TRUE
, LONG
, op2(Ibs
,E
), db_Grp1
},
727 /*84*/ { "test", TRUE
, BYTE
, op2(R
, E
), 0 },
728 /*85*/ { "test", TRUE
, LONG
, op2(R
, E
), 0 },
729 /*86*/ { "xchg", TRUE
, BYTE
, op2(R
, E
), 0 },
730 /*87*/ { "xchg", TRUE
, LONG
, op2(R
, E
), 0 },
732 /*88*/ { "mov", TRUE
, BYTE
, op2(R
, E
), 0 },
733 /*89*/ { "mov", TRUE
, LONG
, op2(R
, E
), 0 },
734 /*8a*/ { "mov", TRUE
, BYTE
, op2(E
, R
), 0 },
735 /*8b*/ { "mov", TRUE
, LONG
, op2(E
, R
), 0 },
736 /*8c*/ { "mov", TRUE
, NONE
, op2(S
, Ew
), 0 },
737 /*8d*/ { "lea", TRUE
, LONG
, op2(E
, R
), 0 },
738 /*8e*/ { "mov", TRUE
, NONE
, op2(Ew
, S
), 0 },
739 /*8f*/ { "pop", TRUE
, LONG
, op1(E
), 0 },
741 /*90*/ { "nop", FALSE
, NONE
, 0, 0 },
742 /*91*/ { "xchg", FALSE
, LONG
, op2(A
, Ri
), 0 },
743 /*92*/ { "xchg", FALSE
, LONG
, op2(A
, Ri
), 0 },
744 /*93*/ { "xchg", FALSE
, LONG
, op2(A
, Ri
), 0 },
745 /*94*/ { "xchg", FALSE
, LONG
, op2(A
, Ri
), 0 },
746 /*95*/ { "xchg", FALSE
, LONG
, op2(A
, Ri
), 0 },
747 /*96*/ { "xchg", FALSE
, LONG
, op2(A
, Ri
), 0 },
748 /*97*/ { "xchg", FALSE
, LONG
, op2(A
, Ri
), 0 },
750 /*98*/ { "cbw", FALSE
, SDEP
, 0, "cwde" }, /* cbw/cwde */
751 /*99*/ { "cwd", FALSE
, SDEP
, 0, "cdq" }, /* cwd/cdq */
752 /*9a*/ { "lcall", FALSE
, NONE
, op1(OS
), 0 },
753 /*9b*/ { "wait", FALSE
, NONE
, 0, 0 },
754 /*9c*/ { "pushf", FALSE
, LONG
, 0, 0 },
755 /*9d*/ { "popf", FALSE
, LONG
, 0, 0 },
756 /*9e*/ { "sahf", FALSE
, NONE
, 0, 0 },
757 /*9f*/ { "lahf", FALSE
, NONE
, 0, 0 },
759 /*a0*/ { "mov", FALSE
, BYTE
, op2(O
, A
), 0 },
760 /*a1*/ { "mov", FALSE
, LONG
, op2(O
, A
), 0 },
761 /*a2*/ { "mov", FALSE
, BYTE
, op2(A
, O
), 0 },
762 /*a3*/ { "mov", FALSE
, LONG
, op2(A
, O
), 0 },
763 /*a4*/ { "movs", FALSE
, BYTE
, op2(SI
,DI
), 0 },
764 /*a5*/ { "movs", FALSE
, LONG
, op2(SI
,DI
), 0 },
765 /*a6*/ { "cmps", FALSE
, BYTE
, op2(SI
,DI
), 0 },
766 /*a7*/ { "cmps", FALSE
, LONG
, op2(SI
,DI
), 0 },
768 /*a8*/ { "test", FALSE
, BYTE
, op2(I
, A
), 0 },
769 /*a9*/ { "test", FALSE
, LONG
, op2(I
, A
), 0 },
770 /*aa*/ { "stos", FALSE
, BYTE
, op1(DI
), 0 },
771 /*ab*/ { "stos", FALSE
, LONG
, op1(DI
), 0 },
772 /*ac*/ { "lods", FALSE
, BYTE
, op1(SI
), 0 },
773 /*ad*/ { "lods", FALSE
, LONG
, op1(SI
), 0 },
774 /*ae*/ { "scas", FALSE
, BYTE
, op1(SI
), 0 },
775 /*af*/ { "scas", FALSE
, LONG
, op1(SI
), 0 },
777 /*b0*/ { "mov", FALSE
, BYTE
, op2(I
, Ri
), 0 },
778 /*b1*/ { "mov", FALSE
, BYTE
, op2(I
, Ri
), 0 },
779 /*b2*/ { "mov", FALSE
, BYTE
, op2(I
, Ri
), 0 },
780 /*b3*/ { "mov", FALSE
, BYTE
, op2(I
, Ri
), 0 },
781 /*b4*/ { "mov", FALSE
, BYTE
, op2(I
, Ri
), 0 },
782 /*b5*/ { "mov", FALSE
, BYTE
, op2(I
, Ri
), 0 },
783 /*b6*/ { "mov", FALSE
, BYTE
, op2(I
, Ri
), 0 },
784 /*b7*/ { "mov", FALSE
, BYTE
, op2(I
, Ri
), 0 },
786 /*b8*/ { "mov", FALSE
, LONG
, op2(I
, Ri
), 0 },
787 /*b9*/ { "mov", FALSE
, LONG
, op2(I
, Ri
), 0 },
788 /*ba*/ { "mov", FALSE
, LONG
, op2(I
, Ri
), 0 },
789 /*bb*/ { "mov", FALSE
, LONG
, op2(I
, Ri
), 0 },
790 /*bc*/ { "mov", FALSE
, LONG
, op2(I
, Ri
), 0 },
791 /*bd*/ { "mov", FALSE
, LONG
, op2(I
, Ri
), 0 },
792 /*be*/ { "mov", FALSE
, LONG
, op2(I
, Ri
), 0 },
793 /*bf*/ { "mov", FALSE
, LONG
, op2(I
, Ri
), 0 },
795 /*c0*/ { "", TRUE
, BYTE
, op2(Ib
, E
), db_Grp2
},
796 /*c1*/ { "", TRUE
, LONG
, op2(Ib
, E
), db_Grp2
},
797 /*c2*/ { "ret", FALSE
, NONE
, op1(Iw
), 0 },
798 /*c3*/ { "ret", FALSE
, NONE
, 0, 0 },
799 /*c4*/ { "les", TRUE
, LONG
, op2(E
, R
), 0 },
800 /*c5*/ { "lds", TRUE
, LONG
, op2(E
, R
), 0 },
801 /*c6*/ { "mov", TRUE
, BYTE
, op2(I
, E
), 0 },
802 /*c7*/ { "mov", TRUE
, LONG
, op2(I
, E
), 0 },
804 /*c8*/ { "enter", FALSE
, NONE
, op2(Iw
, Ib
), 0 },
805 /*c9*/ { "leave", FALSE
, NONE
, 0, 0 },
806 /*ca*/ { "lret", FALSE
, NONE
, op1(Iw
), 0 },
807 /*cb*/ { "lret", FALSE
, NONE
, 0, 0 },
808 /*cc*/ { "int", FALSE
, NONE
, op1(o3
), 0 },
809 /*cd*/ { "int", FALSE
, NONE
, op1(Ib
), 0 },
810 /*ce*/ { "into", FALSE
, NONE
, 0, 0 },
811 /*cf*/ { "iret", FALSE
, NONE
, 0, 0 },
813 /*d0*/ { "", TRUE
, BYTE
, op2(o1
, E
), db_Grp2
},
814 /*d1*/ { "", TRUE
, LONG
, op2(o1
, E
), db_Grp2
},
815 /*d2*/ { "", TRUE
, BYTE
, op2(CL
, E
), db_Grp2
},
816 /*d3*/ { "", TRUE
, LONG
, op2(CL
, E
), db_Grp2
},
817 /*d4*/ { "aam", FALSE
, NONE
, op1(Iba
), 0 },
818 /*d5*/ { "aad", FALSE
, NONE
, op1(Iba
), 0 },
819 /*d6*/ { ".byte\t0xd6", FALSE
, NONE
, 0, 0 },
820 /*d7*/ { "xlat", FALSE
, BYTE
, op1(BX
), 0 },
822 /*d8*/ { "", TRUE
, NONE
, 0, db_Esc8
},
823 /*d9*/ { "", TRUE
, NONE
, 0, db_Esc9
},
824 /*da*/ { "", TRUE
, NONE
, 0, db_Esca
},
825 /*db*/ { "", TRUE
, NONE
, 0, db_Escb
},
826 /*dc*/ { "", TRUE
, NONE
, 0, db_Escc
},
827 /*dd*/ { "", TRUE
, NONE
, 0, db_Escd
},
828 /*de*/ { "", TRUE
, NONE
, 0, db_Esce
},
829 /*df*/ { "", TRUE
, NONE
, 0, db_Escf
},
831 /*e0*/ { "loopne",FALSE
, NONE
, op1(Db
), 0 },
832 /*e1*/ { "loope", FALSE
, NONE
, op1(Db
), 0 },
833 /*e2*/ { "loop", FALSE
, NONE
, op1(Db
), 0 },
834 /*e3*/ { "jcxz", FALSE
, SDEP
, op1(Db
), "jecxz" },
835 /*e4*/ { "in", FALSE
, BYTE
, op2(Ib
, A
), 0 },
836 /*e5*/ { "in", FALSE
, LONG
, op2(Ib
, A
) , 0 },
837 /*e6*/ { "out", FALSE
, BYTE
, op2(A
, Ib
), 0 },
838 /*e7*/ { "out", FALSE
, LONG
, op2(A
, Ib
) , 0 },
840 /*e8*/ { "call", FALSE
, NONE
, op1(Dl
), 0 },
841 /*e9*/ { "jmp", FALSE
, NONE
, op1(Dl
), 0 },
842 /*ea*/ { "ljmp", FALSE
, NONE
, op1(OS
), 0 },
843 /*eb*/ { "jmp", FALSE
, NONE
, op1(Db
), 0 },
844 /*ec*/ { "in", FALSE
, BYTE
, op2(DX
, A
), 0 },
845 /*ed*/ { "in", FALSE
, LONG
, op2(DX
, A
) , 0 },
846 /*ee*/ { "out", FALSE
, BYTE
, op2(A
, DX
), 0 },
847 /*ef*/ { "out", FALSE
, LONG
, op2(A
, DX
) , 0 },
849 /*f0*/ { "", FALSE
, NONE
, 0, 0 },
850 /*f1*/ { ".byte\t0xf1", FALSE
, NONE
, 0, 0 },
851 /*f2*/ { "", FALSE
, NONE
, 0, 0 },
852 /*f3*/ { "", FALSE
, NONE
, 0, 0 },
853 /*f4*/ { "hlt", FALSE
, NONE
, 0, 0 },
854 /*f5*/ { "cmc", FALSE
, NONE
, 0, 0 },
855 /*f6*/ { "", TRUE
, BYTE
, 0, db_Grp3
},
856 /*f7*/ { "", TRUE
, LONG
, 0, db_Grp3
},
858 /*f8*/ { "clc", FALSE
, NONE
, 0, 0 },
859 /*f9*/ { "stc", FALSE
, NONE
, 0, 0 },
860 /*fa*/ { "cli", FALSE
, NONE
, 0, 0 },
861 /*fb*/ { "sti", FALSE
, NONE
, 0, 0 },
862 /*fc*/ { "cld", FALSE
, NONE
, 0, 0 },
863 /*fd*/ { "std", FALSE
, NONE
, 0, 0 },
864 /*fe*/ { "", TRUE
, NONE
, 0, db_Grp4
},
865 /*ff*/ { "", TRUE
, NONE
, 0, db_Grp5
},
868 static const struct inst db_bad_inst
=
869 { "???", FALSE
, NONE
, 0, 0 }
872 #define f_mod(byte) ((byte)>>6)
873 #define f_reg(byte) (((byte)>>3)&0x7)
874 #define f_rm(byte) ((byte)&0x7)
876 #define sib_ss(byte) ((byte)>>6)
877 #define sib_index(byte) (((byte)>>3)&0x7)
878 #define sib_base(byte) ((byte)&0x7)
881 int is_reg
; /* if reg, reg number is in 'disp' */
888 static const char * const db_index_reg_16
[8] = {
899 static const char * const db_reg
[3][8] = {
900 { "%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh" },
901 { "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di" },
902 { "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi" }
905 static const char * const db_seg_reg
[8] = {
906 "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
910 * lengths for size attributes
912 static const int db_lengths
[] = {
922 #define get_value_inc(result, loc, size, is_signed) \
923 result = db_get_value((loc), (size), (is_signed)); \
927 db_disasm_esc(db_addr_t loc
, int inst
, int short_addr
,
928 int size
, const char *seg
);
929 static void db_print_address(const char *seg
, int size
,
930 struct i_addr
*addrp
);
932 db_read_address(db_addr_t loc
, int short_addr
, int regmodrm
,
933 struct i_addr
*addrp
);
936 * Read address at location and return updated location.
939 db_read_address(loc
, short_addr
, regmodrm
, addrp
)
943 struct i_addr
* addrp
; /* out */
945 int mod
, rm
, sib
, index
, disp
;
947 mod
= f_mod(regmodrm
);
951 addrp
->is_reg
= TRUE
;
955 addrp
->is_reg
= FALSE
;
964 get_value_inc(disp
, loc
, 2, FALSE
);
970 addrp
->base
= db_index_reg_16
[rm
];
974 get_value_inc(disp
, loc
, 1, TRUE
);
977 addrp
->base
= db_index_reg_16
[rm
];
980 get_value_inc(disp
, loc
, 2, FALSE
);
982 addrp
->base
= db_index_reg_16
[rm
];
987 if (mod
!= 3 && rm
== 4) {
988 get_value_inc(sib
, loc
, 1, FALSE
);
990 index
= sib_index(sib
);
992 addrp
->index
= db_reg
[LONG
][index
];
993 addrp
->ss
= sib_ss(sib
);
999 get_value_inc(addrp
->disp
, loc
, 4, FALSE
);
1004 addrp
->base
= db_reg
[LONG
][rm
];
1009 get_value_inc(disp
, loc
, 1, TRUE
);
1011 addrp
->base
= db_reg
[LONG
][rm
];
1015 get_value_inc(disp
, loc
, 4, FALSE
);
1017 addrp
->base
= db_reg
[LONG
][rm
];
1025 db_print_address(seg
, size
, addrp
)
1028 struct i_addr
* addrp
;
1030 if (addrp
->is_reg
) {
1031 db_printf("%s", db_reg
[size
][addrp
->disp
]);
1036 db_printf("%s:", seg
);
1039 db_printsym((db_addr_t
)addrp
->disp
, DB_STGY_ANY
);
1040 if (addrp
->base
!= NULL
|| addrp
->index
!= NULL
) {
1043 db_printf("%s", addrp
->base
);
1045 db_printf(",%s,%d", addrp
->index
, 1<<addrp
->ss
);
1051 * Disassemble floating-point ("escape") instruction
1052 * and return updated location.
1055 db_disasm_esc(loc
, inst
, short_addr
, size
, seg
)
1063 const struct finst
* fp
;
1065 struct i_addr address
;
1068 get_value_inc(regmodrm
, loc
, 1, FALSE
);
1069 fp
= &db_Esc_inst
[inst
- 0xd8][f_reg(regmodrm
)];
1070 mod
= f_mod(regmodrm
);
1072 if (*fp
->f_name
== '\0') {
1073 db_printf("<bad instruction>");
1077 * Normal address modes.
1079 loc
= db_read_address(loc
, short_addr
, regmodrm
, &address
);
1080 db_printf("%s", fp
->f_name
);
1081 switch(fp
->f_size
) {
1104 db_print_address(seg
, BYTE
, &address
);
1108 * 'reg-reg' - special formats
1110 switch (fp
->f_rrmode
) {
1112 name
= (fp
->f_rrname
) ? fp
->f_rrname
: fp
->f_name
;
1113 db_printf("%s\t%%st,%%st(%d)",name
,f_rm(regmodrm
));
1116 name
= (fp
->f_rrname
) ? fp
->f_rrname
: fp
->f_name
;
1117 db_printf("%s\t%%st(%d),%%st",name
, f_rm(regmodrm
));
1120 name
= (fp
->f_rrname
) ? fp
->f_rrname
: fp
->f_name
;
1121 db_printf("%s\t%%st(%d)",name
, f_rm(regmodrm
));
1124 name
= ((const char * const *)fp
->f_rrname
)[f_rm(regmodrm
)];
1127 db_printf("%s", name
);
1130 name
= ((const char * const *)fp
->f_rrname
)[f_rm(regmodrm
)];
1133 db_printf("%s\t%%ax", name
);
1137 db_printf("<bad instruction>");
1146 * Disassemble instruction at 'loc'. 'altfmt' specifies an
1147 * (optional) alternate format. Return address of start of
1151 db_disasm(db_addr_t loc
, bool altfmt
)
1157 const struct inst
* ip
;
1158 const char * i_name
;
1169 struct i_addr address
;
1171 get_value_inc(inst
, loc
, 1, FALSE
);
1183 case 0x66: /* data16 */
1211 db_printf("repne ");
1221 get_value_inc(inst
, loc
, 1, FALSE
);
1225 db_printf("pause\n");
1228 db_printf("repe "); /* XXX repe VS rep */
1233 if (inst
>= 0xd8 && inst
<= 0xdf) {
1234 loc
= db_disasm_esc(loc
, inst
, short_addr
, size
, seg
);
1240 get_value_inc(inst
, loc
, 1, FALSE
);
1241 ip
= db_inst_0f
[inst
>>4];
1250 ip
= &db_inst_table
[inst
];
1252 if (ip
->i_has_modrm
) {
1253 get_value_inc(regmodrm
, loc
, 1, FALSE
);
1254 loc
= db_read_address(loc
, short_addr
, regmodrm
, &address
);
1257 i_name
= ip
->i_name
;
1258 i_size
= ip
->i_size
;
1259 i_mode
= ip
->i_mode
;
1261 if (ip
->i_extra
== db_Grp1
|| ip
->i_extra
== db_Grp2
||
1262 ip
->i_extra
== db_Grp6
|| ip
->i_extra
== db_Grp7
||
1263 ip
->i_extra
== db_Grp8
|| ip
->i_extra
== db_Grp9
||
1264 ip
->i_extra
== db_Grp15
) {
1265 i_name
= ((const char * const *)ip
->i_extra
)[f_reg(regmodrm
)];
1267 else if (ip
->i_extra
== db_Grp3
) {
1269 ip
= &ip
[f_reg(regmodrm
)];
1270 i_name
= ip
->i_name
;
1271 i_mode
= ip
->i_mode
;
1273 else if (ip
->i_extra
== db_Grp4
|| ip
->i_extra
== db_Grp5
) {
1275 ip
= &ip
[f_reg(regmodrm
)];
1276 i_name
= ip
->i_name
;
1277 i_mode
= ip
->i_mode
;
1278 i_size
= ip
->i_size
;
1281 /* Special cases that don't fit well in the tables. */
1282 if (ip
->i_extra
== db_Grp7
&& f_mod(regmodrm
) == 3) {
1296 if (ip
->i_extra
== db_Grp15
&& f_mod(regmodrm
) == 3) {
1297 i_name
= db_Grp15b
[f_reg(regmodrm
)];
1302 if (i_size
== SDEP
) {
1304 db_printf("%s", i_name
);
1306 db_printf("%s", (const char *)ip
->i_extra
);
1309 db_printf("%s", i_name
);
1310 if (i_size
!= NONE
) {
1311 if (i_size
== BYTE
) {
1315 else if (i_size
== WORD
) {
1319 else if (size
== WORD
)
1328 i_mode
>>= 8, first
= FALSE
)
1333 switch (i_mode
& 0xFF) {
1336 db_print_address(seg
, size
, &address
);
1341 db_print_address(seg
, size
, &address
);
1345 db_print_address(seg
, LONG
, &address
);
1349 db_print_address(seg
, WORD
, &address
);
1353 db_print_address(seg
, BYTE
, &address
);
1357 db_printf("%s", db_reg
[size
][f_reg(regmodrm
)]);
1361 db_printf("%s", db_reg
[WORD
][f_reg(regmodrm
)]);
1365 db_printf("%s", db_reg
[size
][f_rm(inst
)]);
1369 db_printf("%s", db_reg
[LONG
][f_rm(inst
)]);
1373 db_printf("%s", db_seg_reg
[f_reg(regmodrm
)]);
1377 db_printf("%s", db_seg_reg
[f_reg(inst
)]);
1381 db_printf("%s", db_reg
[size
][0]); /* acc */
1386 db_printf("%s:", seg
);
1387 db_printf("(%s)", short_addr
? "%bx" : "%ebx");
1400 db_printf("%s:", seg
);
1401 db_printf("(%s)", short_addr
? "%si" : "%esi");
1405 db_printf("%%es:(%s)", short_addr
? "%di" : "%edi");
1409 db_printf("%%cr%d", f_reg(regmodrm
));
1413 db_printf("%%dr%d", f_reg(regmodrm
));
1417 db_printf("%%tr%d", f_reg(regmodrm
));
1421 len
= db_lengths
[size
];
1422 get_value_inc(imm
, loc
, len
, FALSE
);
1423 db_printf("$%#r", imm
);
1427 len
= db_lengths
[size
];
1428 get_value_inc(imm
, loc
, len
, FALSE
);
1429 db_printf("$%+#r", imm
);
1433 get_value_inc(imm
, loc
, 1, FALSE
);
1434 db_printf("$%#r", imm
);
1438 get_value_inc(imm
, loc
, 1, FALSE
);
1440 db_printf("$%#r", imm
);
1444 get_value_inc(imm
, loc
, 1, TRUE
);
1447 db_printf("$%+#r", imm
);
1451 get_value_inc(imm
, loc
, 2, FALSE
);
1452 db_printf("$%#r", imm
);
1456 len
= (short_addr
? 2 : 4);
1457 get_value_inc(displ
, loc
, len
, FALSE
);
1459 db_printf("%s:%+#r",seg
, displ
);
1461 db_printsym((db_addr_t
)displ
, DB_STGY_ANY
);
1465 get_value_inc(displ
, loc
, 1, TRUE
);
1469 db_printsym((db_addr_t
)displ
, DB_STGY_XTRN
);
1473 len
= db_lengths
[size
];
1474 get_value_inc(displ
, loc
, len
, FALSE
);
1478 db_printsym((db_addr_t
)displ
, DB_STGY_XTRN
);
1490 len
= db_lengths
[size
];
1491 get_value_inc(imm
, loc
, len
, FALSE
); /* offset */
1492 get_value_inc(imm2
, loc
, 2, FALSE
); /* segment */
1493 db_printf("$%#r,%#r", imm2
, imm
);