kernel: scheduling fix for ARM
[minix.git] / commands / swifi / db_disasm.c
blobf2ec126f71cf321470084b949e89d122d3955667
1 /*
2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
4 * All Rights Reserved.
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.
28 * Instruction disassembler.
31 #if 0
32 #include <linux/kernel.h>
33 #endif
34 #include "ddb.h"
36 #include "db_access.h"
37 #include "db_sym.h"
40 * Size attributes
42 #define BYTE 0
43 #define WORD 1
44 #define LONG 2
45 #define QUAD 3
46 #define SNGL 4
47 #define DBLR 5
48 #define EXTR 6
49 #define SDEP 7
50 #define NONE 8
53 * Addressing modes
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 */
92 struct inst {
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 */
100 #define op1(x) (x)
101 #define op2(x,y) ((x)|((y)<<8))
102 #define op3(x,y,z) ((x)|((y)<<8)|((z)<<16))
104 struct finst {
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[] = {
113 "sldt",
114 "str",
115 "lldt",
116 "ltr",
117 "verr",
118 "verw",
123 static const char * const db_Grp7[] = {
124 "sgdt",
125 "sidt",
126 "lgdt",
127 "lidt",
128 "smsw",
130 "lmsw",
131 "invlpg"
134 static const char * const db_Grp8[] = {
139 "bt",
140 "bts",
141 "btr",
142 "btc"
145 static const char * const db_Grp9[] = {
147 "cmpxchg8b",
156 static const struct inst db_inst_0f0x[] = {
157 /*00*/ { "", TRUE, NONE, op1(Ew), db_Grp6 },
158 /*01*/ { "", TRUE, NONE, op1(Ew), db_Grp7 },
159 /*02*/ { "lar", TRUE, LONG, op2(E,R), 0 },
160 /*03*/ { "lsl", TRUE, LONG, op2(E,R), 0 },
161 /*04*/ { "", FALSE, NONE, 0, 0 },
162 /*05*/ { "", FALSE, NONE, 0, 0 },
163 /*06*/ { "clts", FALSE, NONE, 0, 0 },
164 /*07*/ { "", FALSE, NONE, 0, 0 },
166 /*08*/ { "invd", FALSE, NONE, 0, 0 },
167 /*09*/ { "wbinvd",FALSE, NONE, 0, 0 },
168 /*0a*/ { "", FALSE, NONE, 0, 0 },
169 /*0b*/ { "", FALSE, NONE, 0, 0 },
170 /*0c*/ { "", FALSE, NONE, 0, 0 },
171 /*0d*/ { "", FALSE, NONE, 0, 0 },
172 /*0e*/ { "", FALSE, NONE, 0, 0 },
173 /*0f*/ { "", FALSE, NONE, 0, 0 },
176 static const struct inst db_inst_0f2x[] = {
177 /*20*/ { "mov", TRUE, LONG, op2(CR,El), 0 },
178 /*21*/ { "mov", TRUE, LONG, op2(DR,El), 0 },
179 /*22*/ { "mov", TRUE, LONG, op2(El,CR), 0 },
180 /*23*/ { "mov", TRUE, LONG, op2(El,DR), 0 },
181 /*24*/ { "mov", TRUE, LONG, op2(TR,El), 0 },
182 /*25*/ { "", FALSE, NONE, 0, 0 },
183 /*26*/ { "mov", TRUE, LONG, op2(El,TR), 0 },
184 /*27*/ { "", FALSE, NONE, 0, 0 },
186 /*28*/ { "", FALSE, NONE, 0, 0 },
187 /*29*/ { "", FALSE, NONE, 0, 0 },
188 /*2a*/ { "", FALSE, NONE, 0, 0 },
189 /*2b*/ { "", FALSE, NONE, 0, 0 },
190 /*2c*/ { "", FALSE, NONE, 0, 0 },
191 /*2d*/ { "", FALSE, NONE, 0, 0 },
192 /*2e*/ { "", FALSE, NONE, 0, 0 },
193 /*2f*/ { "", FALSE, NONE, 0, 0 },
196 static const struct inst db_inst_0f3x[] = {
197 /*30*/ { "wrmsr", FALSE, NONE, 0, 0 },
198 /*31*/ { "rdtsc", FALSE, NONE, 0, 0 },
199 /*32*/ { "rdmsr", FALSE, NONE, 0, 0 },
200 /*33*/ { "rdpmc", FALSE, NONE, 0, 0 },
201 /*34*/ { "", FALSE, NONE, 0, 0 },
202 /*35*/ { "", FALSE, NONE, 0, 0 },
203 /*36*/ { "", FALSE, NONE, 0, 0 },
204 /*37*/ { "", FALSE, NONE, 0, 0 },
206 /*38*/ { "", FALSE, NONE, 0, 0 },
207 /*39*/ { "", FALSE, NONE, 0, 0 },
208 /*3a*/ { "", FALSE, NONE, 0, 0 },
209 /*3b*/ { "", FALSE, NONE, 0, 0 },
210 /*3c*/ { "", FALSE, NONE, 0, 0 },
211 /*3d*/ { "", FALSE, NONE, 0, 0 },
212 /*3e*/ { "", FALSE, NONE, 0, 0 },
213 /*3f*/ { "", FALSE, NONE, 0, 0 },
216 static const struct inst db_inst_0f8x[] = {
217 /*80*/ { "jo", FALSE, NONE, op1(Dl), 0 },
218 /*81*/ { "jno", FALSE, NONE, op1(Dl), 0 },
219 /*82*/ { "jb", FALSE, NONE, op1(Dl), 0 },
220 /*83*/ { "jnb", FALSE, NONE, op1(Dl), 0 },
221 /*84*/ { "jz", FALSE, NONE, op1(Dl), 0 },
222 /*85*/ { "jnz", FALSE, NONE, op1(Dl), 0 },
223 /*86*/ { "jbe", FALSE, NONE, op1(Dl), 0 },
224 /*87*/ { "jnbe", FALSE, NONE, op1(Dl), 0 },
226 /*88*/ { "js", FALSE, NONE, op1(Dl), 0 },
227 /*89*/ { "jns", FALSE, NONE, op1(Dl), 0 },
228 /*8a*/ { "jp", FALSE, NONE, op1(Dl), 0 },
229 /*8b*/ { "jnp", FALSE, NONE, op1(Dl), 0 },
230 /*8c*/ { "jl", FALSE, NONE, op1(Dl), 0 },
231 /*8d*/ { "jnl", FALSE, NONE, op1(Dl), 0 },
232 /*8e*/ { "jle", FALSE, NONE, op1(Dl), 0 },
233 /*8f*/ { "jnle", FALSE, NONE, op1(Dl), 0 },
236 static const struct inst db_inst_0f9x[] = {
237 /*90*/ { "seto", TRUE, NONE, op1(Eb), 0 },
238 /*91*/ { "setno", TRUE, NONE, op1(Eb), 0 },
239 /*92*/ { "setb", TRUE, NONE, op1(Eb), 0 },
240 /*93*/ { "setnb", TRUE, NONE, op1(Eb), 0 },
241 /*94*/ { "setz", TRUE, NONE, op1(Eb), 0 },
242 /*95*/ { "setnz", TRUE, NONE, op1(Eb), 0 },
243 /*96*/ { "setbe", TRUE, NONE, op1(Eb), 0 },
244 /*97*/ { "setnbe",TRUE, NONE, op1(Eb), 0 },
246 /*98*/ { "sets", TRUE, NONE, op1(Eb), 0 },
247 /*99*/ { "setns", TRUE, NONE, op1(Eb), 0 },
248 /*9a*/ { "setp", TRUE, NONE, op1(Eb), 0 },
249 /*9b*/ { "setnp", TRUE, NONE, op1(Eb), 0 },
250 /*9c*/ { "setl", TRUE, NONE, op1(Eb), 0 },
251 /*9d*/ { "setnl", TRUE, NONE, op1(Eb), 0 },
252 /*9e*/ { "setle", TRUE, NONE, op1(Eb), 0 },
253 /*9f*/ { "setnle",TRUE, NONE, op1(Eb), 0 },
256 static const struct inst db_inst_0fax[] = {
257 /*a0*/ { "push", FALSE, NONE, op1(Si), 0 },
258 /*a1*/ { "pop", FALSE, NONE, op1(Si), 0 },
259 /*a2*/ { "cpuid", FALSE, NONE, 0, 0 },
260 /*a3*/ { "bt", TRUE, LONG, op2(R,E), 0 },
261 /*a4*/ { "shld", TRUE, LONG, op3(Ib,R,E), 0 },
262 /*a5*/ { "shld", TRUE, LONG, op3(CL,R,E), 0 },
263 /*a6*/ { "", FALSE, NONE, 0, 0 },
264 /*a7*/ { "", FALSE, NONE, 0, 0 },
266 /*a8*/ { "push", FALSE, NONE, op1(Si), 0 },
267 /*a9*/ { "pop", FALSE, NONE, op1(Si), 0 },
268 /*aa*/ { "rsm", FALSE, NONE, 0, 0 },
269 /*ab*/ { "bts", TRUE, LONG, op2(R,E), 0 },
270 /*ac*/ { "shrd", TRUE, LONG, op3(Ib,R,E), 0 },
271 /*ad*/ { "shrd", TRUE, LONG, op3(CL,R,E), 0 },
272 /*a6*/ { "", FALSE, NONE, 0, 0 },
273 /*a7*/ { "imul", TRUE, LONG, op2(E,R), 0 },
276 static const struct inst db_inst_0fbx[] = {
277 /*b0*/ { "cmpxchg",TRUE, BYTE, op2(R, E), 0 },
278 /*b0*/ { "cmpxchg",TRUE, LONG, op2(R, E), 0 },
279 /*b2*/ { "lss", TRUE, LONG, op2(E, R), 0 },
280 /*b3*/ { "btr", TRUE, LONG, op2(R, E), 0 },
281 /*b4*/ { "lfs", TRUE, LONG, op2(E, R), 0 },
282 /*b5*/ { "lgs", TRUE, LONG, op2(E, R), 0 },
283 /*b6*/ { "movzb", TRUE, LONG, op2(Eb, R), 0 },
284 /*b7*/ { "movzw", TRUE, LONG, op2(Ew, R), 0 },
286 /*b8*/ { "", FALSE, NONE, 0, 0 },
287 /*b9*/ { "", FALSE, NONE, 0, 0 },
288 /*ba*/ { "", TRUE, LONG, op2(Ib, E), db_Grp8 },
289 /*bb*/ { "btc", TRUE, LONG, op2(R, E), 0 },
290 /*bc*/ { "bsf", TRUE, LONG, op2(E, R), 0 },
291 /*bd*/ { "bsr", TRUE, LONG, op2(E, R), 0 },
292 /*be*/ { "movsb", TRUE, LONG, op2(Eb, R), 0 },
293 /*bf*/ { "movsw", TRUE, LONG, op2(Ew, R), 0 },
296 static const struct inst db_inst_0fcx[] = {
297 /*c0*/ { "xadd", TRUE, BYTE, op2(R, E), 0 },
298 /*c1*/ { "xadd", TRUE, LONG, op2(R, E), 0 },
299 /*c2*/ { "", FALSE, NONE, 0, 0 },
300 /*c3*/ { "", FALSE, NONE, 0, 0 },
301 /*c4*/ { "", FALSE, NONE, 0, 0 },
302 /*c5*/ { "", FALSE, NONE, 0, 0 },
303 /*c6*/ { "", FALSE, NONE, 0, 0 },
304 /*c7*/ { "", TRUE, NONE, op1(E), db_Grp9 },
305 /*c8*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
306 /*c9*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
307 /*ca*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
308 /*cb*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
309 /*cc*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
310 /*cd*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
311 /*ce*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
312 /*cf*/ { "bswap", FALSE, LONG, op1(Ril), 0 },
315 static const struct inst * const db_inst_0f[] = {
316 db_inst_0f0x,
318 db_inst_0f2x,
319 db_inst_0f3x,
324 db_inst_0f8x,
325 db_inst_0f9x,
326 db_inst_0fax,
327 db_inst_0fbx,
328 db_inst_0fcx,
334 static const char * const db_Esc92[] = {
335 "fnop", "", "", "", "", "", "", ""
337 static const char * const db_Esc94[] = {
338 "fchs", "fabs", "", "", "ftst", "fxam", "", ""
340 static const char * const db_Esc95[] = {
341 "fld1", "fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz",""
343 static const char * const db_Esc96[] = {
344 "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp",
345 "fincstp"
347 static const char * const db_Esc97[] = {
348 "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"
351 static const char * const db_Esca5[] = {
352 "", "fucompp","", "", "", "", "", ""
355 static const char * const db_Escb4[] = {
356 "fneni","fndisi", "fnclex","fninit","fsetpm", "", "", ""
359 static const char * const db_Esce3[] = {
360 "", "fcompp","", "", "", "", "", ""
363 static const char * const db_Escf4[] = {
364 "fnstsw","", "", "", "", "", "", ""
367 static const struct finst db_Esc8[] = {
368 /*0*/ { "fadd", SNGL, op2(STI,ST), 0 },
369 /*1*/ { "fmul", SNGL, op2(STI,ST), 0 },
370 /*2*/ { "fcom", SNGL, op2(STI,ST), 0 },
371 /*3*/ { "fcomp", SNGL, op2(STI,ST), 0 },
372 /*4*/ { "fsub", SNGL, op2(STI,ST), 0 },
373 /*5*/ { "fsubr", SNGL, op2(STI,ST), 0 },
374 /*6*/ { "fdiv", SNGL, op2(STI,ST), 0 },
375 /*7*/ { "fdivr", SNGL, op2(STI,ST), 0 },
378 static const struct finst db_Esc9[] = {
379 /*0*/ { "fld", SNGL, op1(STI), 0 },
380 /*1*/ { "", NONE, op1(STI), "fxch" },
381 /*2*/ { "fst", SNGL, op1(X), db_Esc92 },
382 /*3*/ { "fstp", SNGL, 0, 0 },
383 /*4*/ { "fldenv", NONE, op1(X), db_Esc94 },
384 /*5*/ { "fldcw", NONE, op1(X), db_Esc95 },
385 /*6*/ { "fnstenv",NONE, op1(X), db_Esc96 },
386 /*7*/ { "fnstcw", NONE, op1(X), db_Esc97 },
389 static const struct finst db_Esca[] = {
390 /*0*/ { "fiadd", LONG, 0, 0 },
391 /*1*/ { "fimul", LONG, 0, 0 },
392 /*2*/ { "ficom", LONG, 0, 0 },
393 /*3*/ { "ficomp", LONG, 0, 0 },
394 /*4*/ { "fisub", LONG, 0, 0 },
395 /*5*/ { "fisubr", LONG, op1(X), db_Esca5 },
396 /*6*/ { "fidiv", LONG, 0, 0 },
397 /*7*/ { "fidivr", LONG, 0, 0 }
400 static const struct finst db_Escb[] = {
401 /*0*/ { "fild", LONG, 0, 0 },
402 /*1*/ { "", NONE, 0, 0 },
403 /*2*/ { "fist", LONG, 0, 0 },
404 /*3*/ { "fistp", LONG, 0, 0 },
405 /*4*/ { "", WORD, op1(X), db_Escb4 },
406 /*5*/ { "fld", EXTR, 0, 0 },
407 /*6*/ { "", WORD, 0, 0 },
408 /*7*/ { "fstp", EXTR, 0, 0 },
411 static const struct finst db_Escc[] = {
412 /*0*/ { "fadd", DBLR, op2(ST,STI), 0 },
413 /*1*/ { "fmul", DBLR, op2(ST,STI), 0 },
414 /*2*/ { "fcom", DBLR, 0, 0 },
415 /*3*/ { "fcomp", DBLR, 0, 0 },
416 /*4*/ { "fsub", DBLR, op2(ST,STI), "fsubr" },
417 /*5*/ { "fsubr", DBLR, op2(ST,STI), "fsub" },
418 /*6*/ { "fdiv", DBLR, op2(ST,STI), "fdivr" },
419 /*7*/ { "fdivr", DBLR, op2(ST,STI), "fdiv" },
422 static const struct finst db_Escd[] = {
423 /*0*/ { "fld", DBLR, op1(STI), "ffree" },
424 /*1*/ { "", NONE, 0, 0 },
425 /*2*/ { "fst", DBLR, op1(STI), 0 },
426 /*3*/ { "fstp", DBLR, op1(STI), 0 },
427 /*4*/ { "frstor", NONE, op1(STI), "fucom" },
428 /*5*/ { "", NONE, op1(STI), "fucomp" },
429 /*6*/ { "fnsave", NONE, 0, 0 },
430 /*7*/ { "fnstsw", NONE, 0, 0 },
433 static const struct finst db_Esce[] = {
434 /*0*/ { "fiadd", WORD, op2(ST,STI), "faddp" },
435 /*1*/ { "fimul", WORD, op2(ST,STI), "fmulp" },
436 /*2*/ { "ficom", WORD, 0, 0 },
437 /*3*/ { "ficomp", WORD, op1(X), db_Esce3 },
438 /*4*/ { "fisub", WORD, op2(ST,STI), "fsubrp" },
439 /*5*/ { "fisubr", WORD, op2(ST,STI), "fsubp" },
440 /*6*/ { "fidiv", WORD, op2(ST,STI), "fdivrp" },
441 /*7*/ { "fidivr", WORD, op2(ST,STI), "fdivp" },
444 static const struct finst db_Escf[] = {
445 /*0*/ { "fild", WORD, 0, 0 },
446 /*1*/ { "", NONE, 0, 0 },
447 /*2*/ { "fist", WORD, 0, 0 },
448 /*3*/ { "fistp", WORD, 0, 0 },
449 /*4*/ { "fbld", NONE, op1(XA), db_Escf4 },
450 /*5*/ { "fild", QUAD, 0, 0 },
451 /*6*/ { "fbstp", NONE, 0, 0 },
452 /*7*/ { "fistp", QUAD, 0, 0 },
455 static const struct finst * const db_Esc_inst[] = {
456 db_Esc8, db_Esc9, db_Esca, db_Escb,
457 db_Escc, db_Escd, db_Esce, db_Escf
460 static const char * const db_Grp1[] = {
461 "add",
462 "or",
463 "adc",
464 "sbb",
465 "and",
466 "sub",
467 "xor",
468 "cmp"
471 static const char * const db_Grp2[] = {
472 "rol",
473 "ror",
474 "rcl",
475 "rcr",
476 "shl",
477 "shr",
478 "shl",
479 "sar"
482 static const struct inst db_Grp3[] = {
483 { "test", TRUE, NONE, op2(I,E), 0 },
484 { "test", TRUE, NONE, op2(I,E), 0 },
485 { "not", TRUE, NONE, op1(E), 0 },
486 { "neg", TRUE, NONE, op1(E), 0 },
487 { "mul", TRUE, NONE, op2(E,A), 0 },
488 { "imul", TRUE, NONE, op2(E,A), 0 },
489 { "div", TRUE, NONE, op2(E,A), 0 },
490 { "idiv", TRUE, NONE, op2(E,A), 0 },
493 static const struct inst db_Grp4[] = {
494 { "inc", TRUE, BYTE, op1(E), 0 },
495 { "dec", TRUE, BYTE, op1(E), 0 },
496 { "", TRUE, NONE, 0, 0 },
497 { "", TRUE, NONE, 0, 0 },
498 { "", TRUE, NONE, 0, 0 },
499 { "", TRUE, NONE, 0, 0 },
500 { "", TRUE, NONE, 0, 0 },
501 { "", TRUE, NONE, 0, 0 }
504 static const struct inst db_Grp5[] = {
505 { "inc", TRUE, LONG, op1(E), 0 },
506 { "dec", TRUE, LONG, op1(E), 0 },
507 { "call", TRUE, LONG, op1(Eind),0 },
508 { "lcall", TRUE, LONG, op1(Eind),0 },
509 { "jmp", TRUE, LONG, op1(Eind),0 },
510 { "ljmp", TRUE, LONG, op1(Eind),0 },
511 { "push", TRUE, LONG, op1(E), 0 },
512 { "", TRUE, NONE, 0, 0 }
515 static const struct inst db_inst_table[256] = {
516 /*00*/ { "add", TRUE, BYTE, op2(R, E), 0 },
517 /*01*/ { "add", TRUE, LONG, op2(R, E), 0 },
518 /*02*/ { "add", TRUE, BYTE, op2(E, R), 0 },
519 /*03*/ { "add", TRUE, LONG, op2(E, R), 0 },
520 /*04*/ { "add", FALSE, BYTE, op2(I, A), 0 },
521 /*05*/ { "add", FALSE, LONG, op2(Is, A), 0 },
522 /*06*/ { "push", FALSE, NONE, op1(Si), 0 },
523 /*07*/ { "pop", FALSE, NONE, op1(Si), 0 },
525 /*08*/ { "or", TRUE, BYTE, op2(R, E), 0 },
526 /*09*/ { "or", TRUE, LONG, op2(R, E), 0 },
527 /*0a*/ { "or", TRUE, BYTE, op2(E, R), 0 },
528 /*0b*/ { "or", TRUE, LONG, op2(E, R), 0 },
529 /*0c*/ { "or", FALSE, BYTE, op2(I, A), 0 },
530 /*0d*/ { "or", FALSE, LONG, op2(I, A), 0 },
531 /*0e*/ { "push", FALSE, NONE, op1(Si), 0 },
532 /*0f*/ { "", FALSE, NONE, 0, 0 },
534 /*10*/ { "adc", TRUE, BYTE, op2(R, E), 0 },
535 /*11*/ { "adc", TRUE, LONG, op2(R, E), 0 },
536 /*12*/ { "adc", TRUE, BYTE, op2(E, R), 0 },
537 /*13*/ { "adc", TRUE, LONG, op2(E, R), 0 },
538 /*14*/ { "adc", FALSE, BYTE, op2(I, A), 0 },
539 /*15*/ { "adc", FALSE, LONG, op2(Is, A), 0 },
540 /*16*/ { "push", FALSE, NONE, op1(Si), 0 },
541 /*17*/ { "pop", FALSE, NONE, op1(Si), 0 },
543 /*18*/ { "sbb", TRUE, BYTE, op2(R, E), 0 },
544 /*19*/ { "sbb", TRUE, LONG, op2(R, E), 0 },
545 /*1a*/ { "sbb", TRUE, BYTE, op2(E, R), 0 },
546 /*1b*/ { "sbb", TRUE, LONG, op2(E, R), 0 },
547 /*1c*/ { "sbb", FALSE, BYTE, op2(I, A), 0 },
548 /*1d*/ { "sbb", FALSE, LONG, op2(Is, A), 0 },
549 /*1e*/ { "push", FALSE, NONE, op1(Si), 0 },
550 /*1f*/ { "pop", FALSE, NONE, op1(Si), 0 },
552 /*20*/ { "and", TRUE, BYTE, op2(R, E), 0 },
553 /*21*/ { "and", TRUE, LONG, op2(R, E), 0 },
554 /*22*/ { "and", TRUE, BYTE, op2(E, R), 0 },
555 /*23*/ { "and", TRUE, LONG, op2(E, R), 0 },
556 /*24*/ { "and", FALSE, BYTE, op2(I, A), 0 },
557 /*25*/ { "and", FALSE, LONG, op2(I, A), 0 },
558 /*26*/ { "", FALSE, NONE, 0, 0 },
559 /*27*/ { "daa", FALSE, NONE, 0, 0 },
561 /*28*/ { "sub", TRUE, BYTE, op2(R, E), 0 },
562 /*29*/ { "sub", TRUE, LONG, op2(R, E), 0 },
563 /*2a*/ { "sub", TRUE, BYTE, op2(E, R), 0 },
564 /*2b*/ { "sub", TRUE, LONG, op2(E, R), 0 },
565 /*2c*/ { "sub", FALSE, BYTE, op2(I, A), 0 },
566 /*2d*/ { "sub", FALSE, LONG, op2(Is, A), 0 },
567 /*2e*/ { "", FALSE, NONE, 0, 0 },
568 /*2f*/ { "das", FALSE, NONE, 0, 0 },
570 /*30*/ { "xor", TRUE, BYTE, op2(R, E), 0 },
571 /*31*/ { "xor", TRUE, LONG, op2(R, E), 0 },
572 /*32*/ { "xor", TRUE, BYTE, op2(E, R), 0 },
573 /*33*/ { "xor", TRUE, LONG, op2(E, R), 0 },
574 /*34*/ { "xor", FALSE, BYTE, op2(I, A), 0 },
575 /*35*/ { "xor", FALSE, LONG, op2(I, A), 0 },
576 /*36*/ { "", FALSE, NONE, 0, 0 },
577 /*37*/ { "aaa", FALSE, NONE, 0, 0 },
579 /*38*/ { "cmp", TRUE, BYTE, op2(R, E), 0 },
580 /*39*/ { "cmp", TRUE, LONG, op2(R, E), 0 },
581 /*3a*/ { "cmp", TRUE, BYTE, op2(E, R), 0 },
582 /*3b*/ { "cmp", TRUE, LONG, op2(E, R), 0 },
583 /*3c*/ { "cmp", FALSE, BYTE, op2(I, A), 0 },
584 /*3d*/ { "cmp", FALSE, LONG, op2(Is, A), 0 },
585 /*3e*/ { "", FALSE, NONE, 0, 0 },
586 /*3f*/ { "aas", FALSE, NONE, 0, 0 },
588 /*40*/ { "inc", FALSE, LONG, op1(Ri), 0 },
589 /*41*/ { "inc", FALSE, LONG, op1(Ri), 0 },
590 /*42*/ { "inc", FALSE, LONG, op1(Ri), 0 },
591 /*43*/ { "inc", FALSE, LONG, op1(Ri), 0 },
592 /*44*/ { "inc", FALSE, LONG, op1(Ri), 0 },
593 /*45*/ { "inc", FALSE, LONG, op1(Ri), 0 },
594 /*46*/ { "inc", FALSE, LONG, op1(Ri), 0 },
595 /*47*/ { "inc", FALSE, LONG, op1(Ri), 0 },
597 /*48*/ { "dec", FALSE, LONG, op1(Ri), 0 },
598 /*49*/ { "dec", FALSE, LONG, op1(Ri), 0 },
599 /*4a*/ { "dec", FALSE, LONG, op1(Ri), 0 },
600 /*4b*/ { "dec", FALSE, LONG, op1(Ri), 0 },
601 /*4c*/ { "dec", FALSE, LONG, op1(Ri), 0 },
602 /*4d*/ { "dec", FALSE, LONG, op1(Ri), 0 },
603 /*4e*/ { "dec", FALSE, LONG, op1(Ri), 0 },
604 /*4f*/ { "dec", FALSE, LONG, op1(Ri), 0 },
606 /*50*/ { "push", FALSE, LONG, op1(Ri), 0 },
607 /*51*/ { "push", FALSE, LONG, op1(Ri), 0 },
608 /*52*/ { "push", FALSE, LONG, op1(Ri), 0 },
609 /*53*/ { "push", FALSE, LONG, op1(Ri), 0 },
610 /*54*/ { "push", FALSE, LONG, op1(Ri), 0 },
611 /*55*/ { "push", FALSE, LONG, op1(Ri), 0 },
612 /*56*/ { "push", FALSE, LONG, op1(Ri), 0 },
613 /*57*/ { "push", FALSE, LONG, op1(Ri), 0 },
615 /*58*/ { "pop", FALSE, LONG, op1(Ri), 0 },
616 /*59*/ { "pop", FALSE, LONG, op1(Ri), 0 },
617 /*5a*/ { "pop", FALSE, LONG, op1(Ri), 0 },
618 /*5b*/ { "pop", FALSE, LONG, op1(Ri), 0 },
619 /*5c*/ { "pop", FALSE, LONG, op1(Ri), 0 },
620 /*5d*/ { "pop", FALSE, LONG, op1(Ri), 0 },
621 /*5e*/ { "pop", FALSE, LONG, op1(Ri), 0 },
622 /*5f*/ { "pop", FALSE, LONG, op1(Ri), 0 },
624 /*60*/ { "pusha", FALSE, LONG, 0, 0 },
625 /*61*/ { "popa", FALSE, LONG, 0, 0 },
626 /*62*/ { "bound", TRUE, LONG, op2(E, R), 0 },
627 /*63*/ { "arpl", TRUE, NONE, op2(Rw,Ew), 0 },
629 /*64*/ { "", FALSE, NONE, 0, 0 },
630 /*65*/ { "", FALSE, NONE, 0, 0 },
631 /*66*/ { "", FALSE, NONE, 0, 0 },
632 /*67*/ { "", FALSE, NONE, 0, 0 },
634 /*68*/ { "push", FALSE, LONG, op1(I), 0 },
635 /*69*/ { "imul", TRUE, LONG, op3(I,E,R), 0 },
636 /*6a*/ { "push", FALSE, LONG, op1(Ibs), 0 },
637 /*6b*/ { "imul", TRUE, LONG, op3(Ibs,E,R),0 },
638 /*6c*/ { "ins", FALSE, BYTE, op2(DX, DI), 0 },
639 /*6d*/ { "ins", FALSE, LONG, op2(DX, DI), 0 },
640 /*6e*/ { "outs", FALSE, BYTE, op2(SI, DX), 0 },
641 /*6f*/ { "outs", FALSE, LONG, op2(SI, DX), 0 },
643 /*70*/ { "jo", FALSE, NONE, op1(Db), 0 },
644 /*71*/ { "jno", FALSE, NONE, op1(Db), 0 },
645 /*72*/ { "jb", FALSE, NONE, op1(Db), 0 },
646 /*73*/ { "jnb", FALSE, NONE, op1(Db), 0 },
647 /*74*/ { "jz", FALSE, NONE, op1(Db), 0 },
648 /*75*/ { "jnz", FALSE, NONE, op1(Db), 0 },
649 /*76*/ { "jbe", FALSE, NONE, op1(Db), 0 },
650 /*77*/ { "jnbe", FALSE, NONE, op1(Db), 0 },
652 /*78*/ { "js", FALSE, NONE, op1(Db), 0 },
653 /*79*/ { "jns", FALSE, NONE, op1(Db), 0 },
654 /*7a*/ { "jp", FALSE, NONE, op1(Db), 0 },
655 /*7b*/ { "jnp", FALSE, NONE, op1(Db), 0 },
656 /*7c*/ { "jl", FALSE, NONE, op1(Db), 0 },
657 /*7d*/ { "jnl", FALSE, NONE, op1(Db), 0 },
658 /*7e*/ { "jle", FALSE, NONE, op1(Db), 0 },
659 /*7f*/ { "jnle", FALSE, NONE, op1(Db), 0 },
661 /*80*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 },
662 /*81*/ { "", TRUE, LONG, op2(I, E), db_Grp1 },
663 /*82*/ { "", TRUE, BYTE, op2(I, E), db_Grp1 },
664 /*83*/ { "", TRUE, LONG, op2(Ibs,E), db_Grp1 },
665 /*84*/ { "test", TRUE, BYTE, op2(R, E), 0 },
666 /*85*/ { "test", TRUE, LONG, op2(R, E), 0 },
667 /*86*/ { "xchg", TRUE, BYTE, op2(R, E), 0 },
668 /*87*/ { "xchg", TRUE, LONG, op2(R, E), 0 },
670 /*88*/ { "mov", TRUE, BYTE, op2(R, E), 0 },
671 /*89*/ { "mov", TRUE, LONG, op2(R, E), 0 },
672 /*8a*/ { "mov", TRUE, BYTE, op2(E, R), 0 },
673 /*8b*/ { "mov", TRUE, LONG, op2(E, R), 0 },
674 /*8c*/ { "mov", TRUE, NONE, op2(S, Ew), 0 },
675 /*8d*/ { "lea", TRUE, LONG, op2(E, R), 0 },
676 /*8e*/ { "mov", TRUE, NONE, op2(Ew, S), 0 },
677 /*8f*/ { "pop", TRUE, LONG, op1(E), 0 },
679 /*90*/ { "nop", FALSE, NONE, 0, 0 },
680 /*91*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
681 /*92*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
682 /*93*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
683 /*94*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
684 /*95*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
685 /*96*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
686 /*97*/ { "xchg", FALSE, LONG, op2(A, Ri), 0 },
688 /*98*/ { "cbw", FALSE, SDEP, 0, "cwde" }, /* cbw/cwde */
689 /*99*/ { "cwd", FALSE, SDEP, 0, "cdq" }, /* cwd/cdq */
690 /*9a*/ { "lcall", FALSE, NONE, op1(OS), 0 },
691 /*9b*/ { "wait", FALSE, NONE, 0, 0 },
692 /*9c*/ { "pushf", FALSE, LONG, 0, 0 },
693 /*9d*/ { "popf", FALSE, LONG, 0, 0 },
694 /*9e*/ { "sahf", FALSE, NONE, 0, 0 },
695 /*9f*/ { "lahf", FALSE, NONE, 0, 0 },
697 /*a0*/ { "mov", FALSE, BYTE, op2(O, A), 0 },
698 /*a1*/ { "mov", FALSE, LONG, op2(O, A), 0 },
699 /*a2*/ { "mov", FALSE, BYTE, op2(A, O), 0 },
700 /*a3*/ { "mov", FALSE, LONG, op2(A, O), 0 },
701 /*a4*/ { "movs", FALSE, BYTE, op2(SI,DI), 0 },
702 /*a5*/ { "movs", FALSE, LONG, op2(SI,DI), 0 },
703 /*a6*/ { "cmps", FALSE, BYTE, op2(SI,DI), 0 },
704 /*a7*/ { "cmps", FALSE, LONG, op2(SI,DI), 0 },
706 /*a8*/ { "test", FALSE, BYTE, op2(I, A), 0 },
707 /*a9*/ { "test", FALSE, LONG, op2(I, A), 0 },
708 /*aa*/ { "stos", FALSE, BYTE, op1(DI), 0 },
709 /*ab*/ { "stos", FALSE, LONG, op1(DI), 0 },
710 /*ac*/ { "lods", FALSE, BYTE, op1(SI), 0 },
711 /*ad*/ { "lods", FALSE, LONG, op1(SI), 0 },
712 /*ae*/ { "scas", FALSE, BYTE, op1(SI), 0 },
713 /*af*/ { "scas", FALSE, LONG, op1(SI), 0 },
715 /*b0*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
716 /*b1*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
717 /*b2*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
718 /*b3*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
719 /*b4*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
720 /*b5*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
721 /*b6*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
722 /*b7*/ { "mov", FALSE, BYTE, op2(I, Ri), 0 },
724 /*b8*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
725 /*b9*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
726 /*ba*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
727 /*bb*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
728 /*bc*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
729 /*bd*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
730 /*be*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
731 /*bf*/ { "mov", FALSE, LONG, op2(I, Ri), 0 },
733 /*c0*/ { "", TRUE, BYTE, op2(Ib, E), db_Grp2 },
734 /*c1*/ { "", TRUE, LONG, op2(Ib, E), db_Grp2 },
735 /*c2*/ { "ret", FALSE, NONE, op1(Iw), 0 },
736 /*c3*/ { "ret", FALSE, NONE, 0, 0 },
737 /*c4*/ { "les", TRUE, LONG, op2(E, R), 0 },
738 /*c5*/ { "lds", TRUE, LONG, op2(E, R), 0 },
739 /*c6*/ { "mov", TRUE, BYTE, op2(I, E), 0 },
740 /*c7*/ { "mov", TRUE, LONG, op2(I, E), 0 },
742 /*c8*/ { "enter", FALSE, NONE, op2(Iw, Ib), 0 },
743 /*c9*/ { "leave", FALSE, NONE, 0, 0 },
744 /*ca*/ { "lret", FALSE, NONE, op1(Iw), 0 },
745 /*cb*/ { "lret", FALSE, NONE, 0, 0 },
746 /*cc*/ { "int", FALSE, NONE, op1(o3), 0 },
747 /*cd*/ { "int", FALSE, NONE, op1(Ib), 0 },
748 /*ce*/ { "into", FALSE, NONE, 0, 0 },
749 /*cf*/ { "iret", FALSE, NONE, 0, 0 },
751 /*d0*/ { "", TRUE, BYTE, op2(o1, E), db_Grp2 },
752 /*d1*/ { "", TRUE, LONG, op2(o1, E), db_Grp2 },
753 /*d2*/ { "", TRUE, BYTE, op2(CL, E), db_Grp2 },
754 /*d3*/ { "", TRUE, LONG, op2(CL, E), db_Grp2 },
755 /*d4*/ { "aam", FALSE, NONE, op1(Iba), 0 },
756 /*d5*/ { "aad", FALSE, NONE, op1(Iba), 0 },
757 /*d6*/ { ".byte\t0xd6", FALSE, NONE, 0, 0 },
758 /*d7*/ { "xlat", FALSE, BYTE, op1(BX), 0 },
760 /*d8*/ { "", TRUE, NONE, 0, db_Esc8 },
761 /*d9*/ { "", TRUE, NONE, 0, db_Esc9 },
762 /*da*/ { "", TRUE, NONE, 0, db_Esca },
763 /*db*/ { "", TRUE, NONE, 0, db_Escb },
764 /*dc*/ { "", TRUE, NONE, 0, db_Escc },
765 /*dd*/ { "", TRUE, NONE, 0, db_Escd },
766 /*de*/ { "", TRUE, NONE, 0, db_Esce },
767 /*df*/ { "", TRUE, NONE, 0, db_Escf },
769 /*e0*/ { "loopne",FALSE, NONE, op1(Db), 0 },
770 /*e1*/ { "loope", FALSE, NONE, op1(Db), 0 },
771 /*e2*/ { "loop", FALSE, NONE, op1(Db), 0 },
772 /*e3*/ { "jcxz", FALSE, SDEP, op1(Db), "jecxz" },
773 /*e4*/ { "in", FALSE, BYTE, op2(Ib, A), 0 },
774 /*e5*/ { "in", FALSE, LONG, op2(Ib, A) , 0 },
775 /*e6*/ { "out", FALSE, BYTE, op2(A, Ib), 0 },
776 /*e7*/ { "out", FALSE, LONG, op2(A, Ib) , 0 },
778 /*e8*/ { "call", FALSE, NONE, op1(Dl), 0 },
779 /*e9*/ { "jmp", FALSE, NONE, op1(Dl), 0 },
780 /*ea*/ { "ljmp", FALSE, NONE, op1(OS), 0 },
781 /*eb*/ { "jmp", FALSE, NONE, op1(Db), 0 },
782 /*ec*/ { "in", FALSE, BYTE, op2(DX, A), 0 },
783 /*ed*/ { "in", FALSE, LONG, op2(DX, A) , 0 },
784 /*ee*/ { "out", FALSE, BYTE, op2(A, DX), 0 },
785 /*ef*/ { "out", FALSE, LONG, op2(A, DX) , 0 },
787 /*f0*/ { "", FALSE, NONE, 0, 0 },
788 /*f1*/ { ".byte\t0xf1", FALSE, NONE, 0, 0 },
789 /*f2*/ { "", FALSE, NONE, 0, 0 },
790 /*f3*/ { "", FALSE, NONE, 0, 0 },
791 /*f4*/ { "hlt", FALSE, NONE, 0, 0 },
792 /*f5*/ { "cmc", FALSE, NONE, 0, 0 },
793 /*f6*/ { "", TRUE, BYTE, 0, db_Grp3 },
794 /*f7*/ { "", TRUE, LONG, 0, db_Grp3 },
796 /*f8*/ { "clc", FALSE, NONE, 0, 0 },
797 /*f9*/ { "stc", FALSE, NONE, 0, 0 },
798 /*fa*/ { "cli", FALSE, NONE, 0, 0 },
799 /*fb*/ { "sti", FALSE, NONE, 0, 0 },
800 /*fc*/ { "cld", FALSE, NONE, 0, 0 },
801 /*fd*/ { "std", FALSE, NONE, 0, 0 },
802 /*fe*/ { "", TRUE, NONE, 0, db_Grp4 },
803 /*ff*/ { "", TRUE, NONE, 0, db_Grp5 },
806 static const struct inst db_bad_inst =
807 { "???", FALSE, NONE, 0, 0 }
810 #define f_mod(byte) ((byte)>>6)
811 #define f_reg(byte) (((byte)>>3)&0x7)
812 #define f_rm(byte) ((byte)&0x7)
814 #define sib_ss(byte) ((byte)>>6)
815 #define sib_index(byte) (((byte)>>3)&0x7)
816 #define sib_base(byte) ((byte)&0x7)
818 struct i_addr {
819 int is_reg; /* if reg, reg number is in 'disp' */
820 int disp;
821 const char * base;
822 const char * index;
823 int ss;
826 static const char * const db_index_reg_16[8] = {
827 "%bx,%si",
828 "%bx,%di",
829 "%bp,%si",
830 "%bp,%di",
831 "%si",
832 "%di",
833 "%bp",
834 "%bx"
837 static const char * const db_reg[3][8] = {
838 {"%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh"},
839 {"%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di"},
840 {"%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi"}
843 static const char * const db_seg_reg[8] = {
844 "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "", ""
848 * lengths for size attributes
850 static const int db_lengths[] = {
851 1, /* BYTE */
852 2, /* WORD */
853 4, /* LONG */
854 8, /* QUAD */
855 4, /* SNGL */
856 8, /* DBLR */
857 10, /* EXTR */
860 #define get_value_inc(result, loc, size, is_signed) \
861 result = db_get_value((loc), (size), (is_signed)); \
862 (loc) += (size);
864 /*static db_addr_t
865 // db_disasm_esc __P((db_addr_t loc, int inst, int short_addr,
866 // int size, const char *seg));
867 //static void db_print_address __P((const char *seg, int size,
868 // struct i_addr *addrp));
870 static db_addr_t
871 db_read_address __P((db_addr_t loc, int short_addr,
872 int regmodrm, struct i_addr *addrp));
875 * Read address at location and return updated location.
877 static db_addr_t
878 db_read_address(loc, short_addr, regmodrm, addrp)
879 db_addr_t loc;
880 int short_addr;
881 int regmodrm;
882 struct i_addr * addrp; /* out */
884 int mod, rm, sib, index, disp;
886 mod = f_mod(regmodrm);
887 rm = f_rm(regmodrm);
889 if (mod == 3) {
890 addrp->is_reg = TRUE;
891 addrp->disp = rm;
892 return (loc);
894 addrp->is_reg = FALSE;
895 addrp->index = 0;
897 if (short_addr) {
898 addrp->index = 0;
899 addrp->ss = 0;
900 switch (mod) {
901 case 0:
902 if (rm == 6) {
903 get_value_inc(disp, loc, 2, FALSE);
904 addrp->disp = disp;
905 addrp->base = 0;
907 else {
908 addrp->disp = 0;
909 addrp->base = db_index_reg_16[rm];
911 break;
912 case 1:
913 get_value_inc(disp, loc, 1, TRUE);
914 disp &= 0xFFFF;
915 addrp->disp = disp;
916 addrp->base = db_index_reg_16[rm];
917 break;
918 case 2:
919 get_value_inc(disp, loc, 2, FALSE);
920 addrp->disp = disp;
921 addrp->base = db_index_reg_16[rm];
922 break;
925 else {
926 if (mod != 3 && rm == 4) {
927 get_value_inc(sib, loc, 1, FALSE);
928 rm = sib_base(sib);
929 index = sib_index(sib);
930 if (index != 4)
931 addrp->index = db_reg[LONG][index];
932 addrp->ss = sib_ss(sib);
935 switch (mod) {
936 case 0:
937 if (rm == 5) {
938 get_value_inc(addrp->disp, loc, 4, FALSE);
939 addrp->base = 0;
941 else {
942 addrp->disp = 0;
943 addrp->base = db_reg[LONG][rm];
945 break;
947 case 1:
948 get_value_inc(disp, loc, 1, TRUE);
949 addrp->disp = disp;
950 addrp->base = db_reg[LONG][rm];
951 break;
953 case 2:
954 get_value_inc(disp, loc, 4, FALSE);
955 addrp->disp = disp;
956 addrp->base = db_reg[LONG][rm];
957 break;
960 return (loc);
964 * NWT: fault injection routine only. disasm floating-point instruction
965 * and return updated location.
967 static db_addr_t
968 my_disasm_esc(
969 db_addr_t loc,
970 int inst,
971 int short_addr,
972 int size,
973 const char * seg)
975 int regmodrm;
976 const struct finst * fp;
977 int mod;
978 struct i_addr address;
979 const char * name;
981 get_value_inc(regmodrm, loc, 1, FALSE);
982 fp = &db_Esc_inst[inst - 0xd8][f_reg(regmodrm)];
983 mod = f_mod(regmodrm);
984 if (mod != 3) {
985 if (*fp->f_name == '\0') {
986 return (loc);
989 * Normal address modes.
991 loc = db_read_address(loc, short_addr, regmodrm, &address);
992 switch(fp->f_size) {
993 case SNGL:
994 break;
995 case DBLR:
996 break;
997 case EXTR:
998 break;
999 case WORD:
1000 break;
1001 case LONG:
1002 break;
1003 case QUAD:
1004 break;
1005 default:
1006 break;
1009 else {
1011 * 'reg-reg' - special formats
1013 switch (fp->f_rrmode) {
1014 case op2(ST,STI):
1015 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1016 break;
1017 case op2(STI,ST):
1018 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1019 break;
1020 case op1(STI):
1021 name = (fp->f_rrname) ? fp->f_rrname : fp->f_name;
1022 break;
1023 case op1(X):
1024 name = ((const char * const *)fp->f_rrname)[f_rm(regmodrm)];
1025 if (*name == '\0')
1026 goto bad;
1027 break;
1028 case op1(XA):
1029 name = ((const char * const *)fp->f_rrname)[f_rm(regmodrm)];
1030 if (*name == '\0')
1031 goto bad;
1032 break;
1033 default:
1034 bad:
1035 break;
1039 return (loc);
1042 * Disassemble instruction at 'loc'. 'altfmt' specifies an
1043 * (optional) alternate format. Return address of start of
1044 * next instruction.
1046 db_addr_t
1047 my_disasm(db_addr_t loc,
1048 boolean_t altfmt)
1050 int inst;
1051 int size;
1052 int short_addr;
1053 const char * seg;
1054 const struct inst * ip;
1055 const char * i_name;
1056 int i_size;
1057 int i_mode;
1058 int regmodrm = 0;
1059 boolean_t first;
1060 int displ;
1061 int prefix;
1062 int imm;
1063 int imm2;
1064 int len;
1065 struct i_addr address;
1067 get_value_inc(inst, loc, 1, FALSE);
1068 short_addr = FALSE;
1069 size = LONG;
1070 seg = 0;
1073 * Get prefixes
1075 prefix = TRUE;
1076 do {
1077 switch (inst) {
1078 case 0x66: /* data16 */
1079 size = WORD;
1080 break;
1081 case 0x67:
1082 short_addr = TRUE;
1083 break;
1084 case 0x26:
1085 seg = "%es";
1086 break;
1087 case 0x36:
1088 seg = "%ss";
1089 break;
1090 case 0x2e:
1091 seg = "%cs";
1092 break;
1093 case 0x3e:
1094 seg = "%ds";
1095 break;
1096 case 0x64:
1097 seg = "%fs";
1098 break;
1099 case 0x65:
1100 seg = "%gs";
1101 break;
1102 case 0xf0:
1103 #if 0
1104 // db_printf("lock ");
1105 #endif
1106 break;
1107 case 0xf2:
1108 #if 0
1109 // db_printf("repne ");
1110 #endif
1111 break;
1112 case 0xf3:
1113 #if 0
1114 // db_printf("repe "); /* XXX repe VS rep */
1115 #endif
1116 break;
1117 default:
1118 prefix = FALSE;
1119 break;
1121 if (prefix) {
1122 get_value_inc(inst, loc, 1, FALSE);
1124 } while (prefix);
1126 if (inst >= 0xd8 && inst <= 0xdf) {
1127 loc = my_disasm_esc(loc, inst, short_addr, size, seg);
1128 return (loc);
1131 if (inst == 0x0f) {
1132 get_value_inc(inst, loc, 1, FALSE);
1133 ip = db_inst_0f[inst>>4];
1134 if (ip == 0) {
1135 ip = &db_bad_inst;
1137 else {
1138 ip = &ip[inst&0xf];
1141 else
1142 ip = &db_inst_table[inst];
1144 if (ip->i_has_modrm) {
1145 unsigned long prev_loc=loc;
1146 extern unsigned long modAddr;
1148 get_value_inc(regmodrm, loc, 1, FALSE);
1149 loc = db_read_address(loc, short_addr, regmodrm, &address);
1150 modAddr=prev_loc;
1151 #if 0
1152 // printf("modrm at %x, offset %d\n", loc, loc-prev_loc);
1153 #endif
1156 i_name = ip->i_name;
1157 i_size = ip->i_size;
1158 i_mode = ip->i_mode;
1160 if (ip->i_extra == db_Grp1 || ip->i_extra == db_Grp2 ||
1161 ip->i_extra == db_Grp6 || ip->i_extra == db_Grp7 ||
1162 ip->i_extra == db_Grp8 || ip->i_extra == db_Grp9) {
1163 i_name = ((const char * const *)ip->i_extra)[f_reg(regmodrm)];
1165 else if (ip->i_extra == db_Grp3) {
1166 ip = ip->i_extra;
1167 ip = &ip[f_reg(regmodrm)];
1168 i_name = ip->i_name;
1169 i_mode = ip->i_mode;
1171 else if (ip->i_extra == db_Grp4 || ip->i_extra == db_Grp5) {
1172 ip = ip->i_extra;
1173 ip = &ip[f_reg(regmodrm)];
1174 i_name = ip->i_name;
1175 i_mode = ip->i_mode;
1176 i_size = ip->i_size;
1179 if (i_size == SDEP) {
1181 else {
1182 if (i_size != NONE) {
1183 if (i_size == BYTE) {
1184 size = BYTE;
1186 else if (i_size == WORD) {
1187 size = WORD;
1191 for (first = TRUE;
1192 i_mode != 0;
1193 i_mode >>= 8, first = FALSE)
1196 switch (i_mode & 0xFF) {
1198 case E:
1199 #if 0
1200 // db_print_address(seg, size, &address);
1201 #endif
1202 break;
1204 case Eind:
1205 #if 0
1206 // db_print_address(seg, size, &address);
1207 #endif
1208 break;
1210 case El:
1211 #if 0
1212 // db_print_address(seg, LONG, &address);
1213 #endif
1214 break;
1216 case Ew:
1217 #if 0
1218 // db_print_address(seg, WORD, &address);
1219 #endif
1220 break;
1222 case Eb:
1223 #if 0
1224 // db_print_address(seg, BYTE, &address);
1225 #endif
1226 break;
1228 case R:
1229 #if 0
1230 // db_printf("%s", db_reg[size][f_reg(regmodrm)]);
1231 #endif
1232 break;
1234 case Rw:
1235 #if 0
1236 // db_printf("%s", db_reg[WORD][f_reg(regmodrm)]);
1237 #endif
1238 break;
1240 case Ri:
1241 #if 0
1242 // db_printf("%s", db_reg[size][f_rm(inst)]);
1243 #endif
1244 break;
1246 case Ril:
1247 #if 0
1248 // db_printf("%s", db_reg[LONG][f_rm(inst)]);
1249 #endif
1250 break;
1252 case S:
1253 #if 0
1254 // db_printf("%s", db_seg_reg[f_reg(regmodrm)]);
1255 #endif
1256 break;
1258 case Si:
1259 #if 0
1260 // db_printf("%s", db_seg_reg[f_reg(inst)]);
1261 #endif
1262 break;
1264 case A:
1265 #if 0
1266 // db_printf("%s", db_reg[size][0]); /* acc */
1267 #endif
1268 break;
1270 case BX:
1271 break;
1273 case CL:
1274 break;
1276 case DX:
1277 break;
1279 case SI:
1280 break;
1282 case DI:
1283 break;
1285 case CR:
1286 break;
1288 case DR:
1289 break;
1291 case TR:
1292 break;
1294 case I:
1295 len = db_lengths[size];
1296 get_value_inc(imm, loc, len, FALSE);
1297 break;
1299 case Is:
1300 len = db_lengths[size];
1301 get_value_inc(imm, loc, len, FALSE);
1303 * XXX the + in this format doesn't seem to work right.
1304 * `Is' is equivalent to `I'.
1306 break;
1308 case Ib:
1309 get_value_inc(imm, loc, 1, FALSE);
1310 break;
1312 case Iba:
1313 get_value_inc(imm, loc, 1, FALSE);
1314 break;
1316 case Ibs:
1317 get_value_inc(imm, loc, 1, TRUE);
1318 if (size == WORD)
1319 imm &= 0xFFFF;
1320 break;
1322 case Iw:
1323 get_value_inc(imm, loc, 2, FALSE);
1324 break;
1326 case O:
1327 len = (short_addr ? 2 : 4);
1328 get_value_inc(displ, loc, len, FALSE);
1329 if (seg) ;
1330 else
1331 #if 0
1332 // db_printsym((db_addr_t)displ, DB_STGY_ANY);
1333 #endif
1334 break;
1336 case Db:
1337 get_value_inc(displ, loc, 1, TRUE);
1338 displ += loc;
1339 if (size == WORD)
1340 displ &= 0xFFFF;
1341 #if 0
1342 // db_printsym((db_addr_t)displ, DB_STGY_XTRN);
1343 #endif
1344 break;
1346 case Dl:
1347 len = db_lengths[size];
1348 get_value_inc(displ, loc, len, FALSE);
1349 displ += loc;
1350 if (size == WORD)
1351 displ &= 0xFFFF;
1352 #if 0
1353 // db_printsym((db_addr_t)displ, DB_STGY_XTRN);
1354 #endif
1355 break;
1357 case o1:
1358 break;
1360 case o3:
1361 break;
1363 case OS:
1364 len = db_lengths[size];
1365 get_value_inc(imm, loc, len, FALSE); /* offset */
1366 get_value_inc(imm2, loc, 2, FALSE); /* segment */
1367 break;
1370 #if 0
1371 // db_printf("\n");
1372 #endif
1373 return (loc);