10 #define REGOFF(x) (ulong)(&((struct Ureg *) 0)->x)
12 #define REGSIZE sizeof(struct Ureg)
13 #define FP_CTL(x) (REGSIZE+4*(x))
14 #define FP_REG(x) (FP_CTL(7)+10*(x))
15 #define FPREGSIZE (6*4+8*10)
18 * i386-specific debugger interface
21 static char *i386excep(Map*, Regs*);
24 static int i386trace(Map*, ulong, ulong, ulong, Tracer);
25 static ulong i386frame(Map*, ulong, ulong, ulong, ulong);
27 static int i386foll(Map*, Regs*, ulong, ulong*);
28 static int i386hexinst(Map*, ulong, char*, int);
29 static int i386das(Map*, ulong, char, char*, int);
30 static int i386instlen(Map*, ulong);
31 static int i386unwind(Map*, Regs*, ulong*, Symbol*);
33 static char *i386windregs[] = {
46 static Regdesc i386reglist[] = {
47 {"DI", REGOFF(di), RINT, 'X'},
48 {"SI", REGOFF(si), RINT, 'X'},
49 {"BP", REGOFF(bp), RINT, 'X'},
50 {"BX", REGOFF(bx), RINT, 'X'},
51 {"DX", REGOFF(dx), RINT, 'X'},
52 {"CX", REGOFF(cx), RINT, 'X'},
53 {"AX", REGOFF(ax), RINT, 'X'},
54 {"GS", REGOFF(gs), RINT, 'X'},
55 {"FS", REGOFF(fs), RINT, 'X'},
56 {"ES", REGOFF(es), RINT, 'X'},
57 {"DS", REGOFF(ds), RINT, 'X'},
58 {"TRAP", REGOFF(trap), RINT, 'X'},
59 {"ECODE", REGOFF(ecode), RINT, 'X'},
60 {"PC", REGOFF(pc), RINT, 'X'},
61 {"CS", REGOFF(cs), RINT, 'X'},
62 {"EFLAGS", REGOFF(flags), RINT, 'X'},
63 {"SP", REGOFF(sp), RINT, 'X'},
64 {"SS", REGOFF(ss), RINT, 'X'},
66 {"E0", FP_CTL(0), RFLT, 'X'},
67 {"E1", FP_CTL(1), RFLT, 'X'},
68 {"E2", FP_CTL(2), RFLT, 'X'},
69 {"E3", FP_CTL(3), RFLT, 'X'},
70 {"E4", FP_CTL(4), RFLT, 'X'},
71 {"E5", FP_CTL(5), RFLT, 'X'},
72 {"E6", FP_CTL(6), RFLT, 'X'},
73 {"F0", FP_REG(7), RFLT, '3'},
74 {"F1", FP_REG(6), RFLT, '3'},
75 {"F2", FP_REG(5), RFLT, '3'},
76 {"F3", FP_REG(4), RFLT, '3'},
77 {"F4", FP_REG(3), RFLT, '3'},
78 {"F5", FP_REG(2), RFLT, '3'},
79 {"F6", FP_REG(1), RFLT, '3'},
80 {"F7", FP_REG(0), RFLT, '3'},
87 M386, /* machine type */
88 i386reglist, /* register list */
89 REGSIZE, /* size of registers in bytes */
90 FPREGSIZE, /* size of fp registers in bytes */
91 "PC", /* name of PC */
92 "SP", /* name of SP */
93 "BP", /* name of FP */
94 0, /* link register */
95 "setSB", /* static base register name (bogus anyways) */
96 0, /* static base register value */
97 0x1000, /* page size */
98 0x80100000, /* kernel base */
99 0, /* kernel text mask */
100 1, /* quantization of pc */
106 i386windregs, /* locations unwound in stack trace */
109 {0xCC, 0, 0, 0}, /* break point: INT 3 */
110 1, /* break point size */
112 i386foll, /* following addresses */
113 i386excep, /* print exception */
114 i386unwind, /* stack unwind */
116 leswap2, /* convert short to local byte order */
117 leswap4, /* convert long to local byte order */
118 leswap8, /* convert vlong to local byte order */
119 leieeeftoa32, /* single precision float pointer */
120 leieeeftoa64, /* double precision float pointer */
121 leieeeftoa80, /* long double precision floating point */
123 i386das, /* dissembler */
124 i386das, /* plan9-format disassembler */
125 0, /* commercial disassembler */
126 i386hexinst, /* print instruction */
127 i386instlen, /* instruction size calculation */
131 * The wrapper code around Linux system calls
132 * saves AX on the stack before calling some calls
133 * (at least, __libc_nanosleep), when running in
137 syscallhack(Map *map, Regs *regs, int *spoff)
142 rget(regs, "PC", &pc);
143 if(i386das(map, pc-2, 0, buf, sizeof buf) != 2 || strncmp(buf, "INTB\t$", 6) != 0)
145 if(i386das(map, pc, 0, buf, sizeof buf) != 2 || strcmp(buf, "MOVL\tDX,BX") != 0)
147 if(i386das(map, pc+2, 0, buf, sizeof buf) != 3 || strcmp(buf, "XCHGL\tAX,0(SP)") != 0)
153 i386unwind(Map *map, Regs *regs, ulong *next, Symbol *sym)
155 int i, isp, ipc, ibp, havebp, n, spoff, off[9];
160 /*print("i386unwind %s\n", sym ? sym->name : nil); */
161 isp = windindex("SP");
162 ipc = windindex("PC");
163 ibp = windindex("BP");
164 if(isp < 0 || ipc < 0 || ibp < 0){
165 werrstr("i386unwind: cannot happen");
170 * Disassemble entry to figure out
171 * where values have been saved.
172 * Perhaps should disassemble exit path
173 * instead -- a random walk on the code
174 * should suffice to get us to a RET.
178 /*print("startpc %lux\n", pc); */
179 memset(off, 0xff, sizeof off);
183 if((n = i386das(map, pc, 0, buf, sizeof buf)) < 0)
185 /*print("%s\n", buf); */
187 if(strncmp(buf, "PUSHL\t", 6) == 0){
189 if((i = windindex(buf+6)) >= 0)
191 }else if(strcmp(buf, "MOVL\tSP,BP") == 0 && spoff == 4 && off[ibp] == 4){
193 }else if(strncmp(buf, "SUBL\t$", 6) == 0){
194 if((p = strrchr(buf, ',')) && strcmp(p, ",SP") == 0){
195 /*print("spoff %s\n", buf+6); */
196 spoff += strtol(buf+6, 0, 16);
199 }else if(strncmp(buf, "XORL\t", 5) == 0 || strncmp(buf, "MOVL\t", 5) == 0){
201 * Hope these are rescheduled non-prologue instructions
202 * like XORL AX, AX or MOVL $0x3, AX and thus ignorable.
208 syscallhack(map, regs, &spoff);
211 /*print("havebp\n"); */
212 rget(regs, "BP", &next[isp]);
213 get4(map, next[isp], &v);
217 rget(regs, "SP", &next[isp]);
218 /*print("old sp %lux + %d\n", next[isp], spoff); */
221 for(i=0; i<nelem(off); i++)
223 get4(map, next[isp]-off[i], &v);
227 if(get4(map, next[isp], &v) < 0)
229 /*print("new pc %lux => %lux\n", next[isp], v); */
236 * Rely on bp chaining
238 if(rget(regs, "BP", &next[isp]) < 0
239 || get4(map, next[isp], &v) < 0)
243 if(get4(map, next[isp], &v) < 0)
250 /*static char STARTSYM[] = "_main"; */
251 /*static char PROFSYM[] = "_mainp"; */
252 static char FRAMENAME[] = ".frame";
253 static char *excname[] =
255 "divide error", /* 0 */
256 "debug exception", /* 1 */
259 "bounds check", /* 5 */
260 "invalid opcode", /* 6 */
261 "math coprocessor emulation", /* 7 */
262 "double fault", /* 8 */
263 "math coprocessor overrun", /* 9 */
264 "invalid TSS", /* 10 */
265 "segment not present", /* 11 */
266 "stack exception", /* 12 */
267 "general protection violation", /* 13 */
268 "page fault", /* 14 */
270 "math coprocessor error", /* 16 */
271 0,0,0,0,0,0,0, /* 17-23 */
275 "modem status", /* 27 */
276 "serial line status", /* 28 */
278 "floppy disk", /* 30 */
279 0,0,0,0,0, /* 31-35 */
281 "math coprocessor", /* 37 */
282 "hard disk", /* 38 */
283 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,/* 39-54 */
284 0,0,0,0,0,0,0,0,0, /* 55-63 */
285 "system call", /* 64 */
289 i386excep(Map *map, Regs *regs)
295 if(rget(regs, "TRAP", &c) < 0)
296 return "no trap register";
298 if(c > 64 || excname[c] == 0) {
300 if (rget(regs, "PC", &pc) >= 0)
301 if (get1(map, pc, (uchar*)buf, mach->bpsize) > 0)
302 if (memcmp(buf, mach->bpinst, mach->bpsize) == 0)
305 sprint(buf, "exception %ld", c);
311 /* I386/486 - Disassembler and related functions */
316 typedef struct Instr Instr;
319 uchar mem[1+1+1+1+2+1+1+4+4]; /* raw instruction */
320 ulong addr; /* address of start of instruction */
321 int n; /* number of bytes in instruction */
322 char *prefix; /* instr prefix */
323 char *segment; /* segment override */
324 uchar jumptype; /* set to the operand type for jump/ret/call */
325 char osize; /* 'W' or 'L' */
326 char asize; /* address size 'W' or 'L' */
327 uchar mod; /* bits 6-7 of mod r/m field */
328 uchar reg; /* bits 3-5 of mod r/m field */
329 schar ss; /* bits 6-7 of SIB */
330 schar index; /* bits 3-5 of SIB */
331 schar base; /* bits 0-2 of SIB */
332 short seg; /* segment of far address */
333 ulong disp; /* displacement */
334 ulong imm; /* immediate */
335 ulong imm2; /* second immediate operand */
336 char *curr; /* fill level in output buffer */
337 char *end; /* end of output buffer */
338 char *err; /* error message */
341 /* 386 register (ha!) set */
352 /* Operand Format codes */
354 %A - address size register modifier (!asize -> 'E')
355 %C - Control register CR0/CR1/CR2
356 %D - Debug register DR0/DR1/DR2/DR3/DR6/DR7
357 %I - second immediate operand
358 %O - Operand size register modifier (!osize -> 'E')
359 %T - Test register TR6/TR7
360 %S - size code ('W' or 'L')
361 %X - Weird opcode: OSIZE == 'W' => "CBW"; else => "CWDE"
362 %d - displacement 16-32 bits
363 %e - effective address - Mod R/M value
364 %f - floating point register F0-F7 - from Mod R/M register
365 %g - segment register
366 %i - immediate operand 8-32 bits
367 %p - PC-relative - signed displacement in immediate field
368 %r - Reg from Mod R/M
369 %x - Weird opcode: OSIZE == 'W' => "CWD"; else => "CDQ"
372 typedef struct Optable Optable;
376 void *proto; /* actually either (char*) or (Optable*) */
378 /* Operand decoding codes */
380 Ib = 1, /* 8-bit immediate - (no sign extension)*/
381 Ibs, /* 8-bit immediate (sign extended) */
382 Jbs, /* 8-bit sign-extended immediate in jump or call */
383 Iw, /* 16-bit immediate -> imm */
384 Iw2, /* 16-bit immediate -> imm2 */
385 Iwd, /* Operand-sized immediate (no sign extension)*/
386 Awd, /* Address offset */
387 Iwds, /* Operand-sized immediate (sign extended) */
388 RM, /* Word or long R/M field with register (/r) */
389 RMB, /* Byte R/M field with register (/r) */
390 RMOP, /* Word or long R/M field with op code (/digit) */
391 RMOPB, /* Byte R/M field with op code (/digit) */
392 RMR, /* R/M register only (mod = 11) */
393 RMM, /* R/M memory only (mod = 0/1/2) */
394 R0, /* Base reg of Mod R/M is literal 0x00 */
395 R1, /* Base reg of Mod R/M is literal 0x01 */
396 FRMOP, /* Floating point R/M field with opcode */
397 FRMEX, /* Extended floating point R/M field with opcode */
398 JUMP, /* Jump or Call flag - no operand */
399 RET, /* Return flag - no operand */
400 OA, /* literal 0x0a byte */
401 PTR, /* Seg:Displacement addr (ptr16:16 or ptr16:32) */
402 AUX, /* Multi-byte op code - Auxiliary table */
403 PRE, /* Instr Prefix */
404 SEG, /* Segment Prefix */
405 OPOVER, /* Operand size override */
406 ADDOVER /* Address size override */
409 static Optable optab0F00[8]=
411 0,0, "MOVW LDT,%e", /* 0x00 */
412 0,0, "MOVW TR,%e", /* 0x01 */
413 0,0, "MOVW %e,LDT", /* 0x02 */
414 0,0, "MOVW %e,TR", /* 0x03 */
415 0,0, "VERR %e", /* 0x04 */
416 0,0, "VERW %e", /* 0x05 */
419 static Optable optab0F01[8]=
421 0,0, "MOVL GDTR,%e", /* 0x00 */
422 0,0, "MOVL IDTR,%e", /* 0x01 */
423 0,0, "MOVL %e,GDTR", /* 0x02 */
424 0,0, "MOVL %e,IDTR", /* 0x03 */
425 0,0, "MOVW MSW,%e", /* 0x04 */ /* word */
427 0,0, "MOVW %e,MSW", /* 0x06 */ /* word */
430 static Optable optab0FBA[8]=
436 Ib,0, "BT%S %i,%e", /* 0x04 */
437 Ib,0, "BTS%S %i,%e", /* 0x05 */
438 Ib,0, "BTR%S %i,%e", /* 0x06 */
439 Ib,0, "BTC%S %i,%e", /* 0x07 */
442 static Optable optab0F[256]=
444 RMOP,0, optab0F00, /* 0x00 */
445 RMOP,0, optab0F01, /* 0x01 */
446 RM,0, "LAR %e,%r", /* 0x02 */
447 RM,0, "LSL %e,%r", /* 0x03 */
450 0,0, "CLTS", /* 0x06 */
452 0,0, "INVD", /* 0x08 */
453 0,0, "WBINVD", /* 0x09 */
476 RMR,0, "MOVL %C,%e", /* 0x20 */
477 RMR,0, "MOVL %D,%e", /* 0x21 */
478 RMR,0, "MOVL %e,%C", /* 0x22 */
479 RMR,0, "MOVL %e,%D", /* 0x23 */
480 RMR,0, "MOVL %T,%e", /* 0x24 */
482 RMR,0, "MOVL %e,%T", /* 0x26 */
492 0,0, "WRMSR", /* 0x30 */
493 0,0, "RDTSC", /* 0x31 */
494 0,0, "RDMSR", /* 0x32 */
572 Iwds,0, "JOS %p", /* 0x80 */
573 Iwds,0, "JOC %p", /* 0x81 */
574 Iwds,0, "JCS %p", /* 0x82 */
575 Iwds,0, "JCC %p", /* 0x83 */
576 Iwds,0, "JEQ %p", /* 0x84 */
577 Iwds,0, "JNE %p", /* 0x85 */
578 Iwds,0, "JLS %p", /* 0x86 */
579 Iwds,0, "JHI %p", /* 0x87 */
580 Iwds,0, "JMI %p", /* 0x88 */
581 Iwds,0, "JPL %p", /* 0x89 */
582 Iwds,0, "JPS %p", /* 0x8a */
583 Iwds,0, "JPC %p", /* 0x8b */
584 Iwds,0, "JLT %p", /* 0x8c */
585 Iwds,0, "JGE %p", /* 0x8d */
586 Iwds,0, "JLE %p", /* 0x8e */
587 Iwds,0, "JGT %p", /* 0x8f */
588 RMB,0, "SETOS %e", /* 0x90 */
589 RMB,0, "SETOC %e", /* 0x91 */
590 RMB,0, "SETCS %e", /* 0x92 */
591 RMB,0, "SETCC %e", /* 0x93 */
592 RMB,0, "SETEQ %e", /* 0x94 */
593 RMB,0, "SETNE %e", /* 0x95 */
594 RMB,0, "SETLS %e", /* 0x96 */
595 RMB,0, "SETHI %e", /* 0x97 */
596 RMB,0, "SETMI %e", /* 0x98 */
597 RMB,0, "SETPL %e", /* 0x99 */
598 RMB,0, "SETPS %e", /* 0x9a */
599 RMB,0, "SETPC %e", /* 0x9b */
600 RMB,0, "SETLT %e", /* 0x9c */
601 RMB,0, "SETGE %e", /* 0x9d */
602 RMB,0, "SETLE %e", /* 0x9e */
603 RMB,0, "SETGT %e", /* 0x9f */
604 0,0, "PUSHL FS", /* 0xa0 */
605 0,0, "POPL FS", /* 0xa1 */
606 0,0, "CPUID", /* 0xa2 */
607 RM,0, "BT%S %r,%e", /* 0xa3 */
608 RM,Ib, "SHLD%S %r,%i,%e", /* 0xa4 */
609 RM,0, "SHLD%S %r,CL,%e", /* 0xa5 */
612 0,0, "PUSHL GS", /* 0xa8 */
613 0,0, "POPL GS", /* 0xa9 */
615 RM,0, "BTS%S %r,%e", /* 0xab */
616 RM,Ib, "SHRD%S %r,%i,%e", /* 0xac */
617 RM,0, "SHRD%S %r,CL,%e", /* 0xad */
619 RM,0, "IMUL%S %e,%r", /* 0xaf */
622 RMM,0, "LSS %e,%r", /* 0xb2 */
623 RM,0, "BTR%S %r,%e", /* 0xb3 */
624 RMM,0, "LFS %e,%r", /* 0xb4 */
625 RMM,0, "LGS %e,%r", /* 0xb5 */
626 RMB,0, "MOVBZX %e,%R", /* 0xb6 */
627 RM,0, "MOVWZX %e,%R", /* 0xb7 */
630 RMOP,0, optab0FBA, /* 0xba */
631 RM,0, "BTC%S %e,%r", /* 0xbb */
632 RM,0, "BSF%S %e,%r", /* 0xbc */
633 RM,0, "BSR%S %e,%r", /* 0xbd */
634 RMB,0, "MOVBSX %e,%R", /* 0xbe */
635 RM,0, "MOVWSX %e,%R", /* 0xbf */
638 static Optable optab80[8]=
640 Ib,0, "ADDB %i,%e", /* 0x00 */
641 Ib,0, "ORB %i,%e", /* 0x01 */
642 Ib,0, "ADCB %i,%e", /* 0x02 */
643 Ib,0, "SBBB %i,%e", /* 0x03 */
644 Ib,0, "ANDB %i,%e", /* 0x04 */
645 Ib,0, "SUBB %i,%e", /* 0x05 */
646 Ib,0, "XORB %i,%e", /* 0x06 */
647 Ib,0, "CMPB %e,%i", /* 0x07 */
650 static Optable optab81[8]=
652 Iwd,0, "ADD%S %i,%e", /* 0x00 */
653 Iwd,0, "OR%S %i,%e", /* 0x01 */
654 Iwd,0, "ADC%S %i,%e", /* 0x02 */
655 Iwd,0, "SBB%S %i,%e", /* 0x03 */
656 Iwd,0, "AND%S %i,%e", /* 0x04 */
657 Iwd,0, "SUB%S %i,%e", /* 0x05 */
658 Iwd,0, "XOR%S %i,%e", /* 0x06 */
659 Iwd,0, "CMP%S %e,%i", /* 0x07 */
662 static Optable optab83[8]=
664 Ibs,0, "ADD%S %i,%e", /* 0x00 */
665 Ibs,0, "OR%S %i,%e", /* 0x01 */
666 Ibs,0, "ADC%S %i,%e", /* 0x02 */
667 Ibs,0, "SBB%S %i,%e", /* 0x03 */
668 Ibs,0, "AND%S %i,%e", /* 0x04 */
669 Ibs,0, "SUB%S %i,%e", /* 0x05 */
670 Ibs,0, "XOR%S %i,%e", /* 0x06 */
671 Ibs,0, "CMP%S %e,%i", /* 0x07 */
674 static Optable optabC0[8] =
676 Ib,0, "ROLB %i,%e", /* 0x00 */
677 Ib,0, "RORB %i,%e", /* 0x01 */
678 Ib,0, "RCLB %i,%e", /* 0x02 */
679 Ib,0, "RCRB %i,%e", /* 0x03 */
680 Ib,0, "SHLB %i,%e", /* 0x04 */
681 Ib,0, "SHRB %i,%e", /* 0x05 */
683 Ib,0, "SARB %i,%e", /* 0x07 */
686 static Optable optabC1[8] =
688 Ib,0, "ROL%S %i,%e", /* 0x00 */
689 Ib,0, "ROR%S %i,%e", /* 0x01 */
690 Ib,0, "RCL%S %i,%e", /* 0x02 */
691 Ib,0, "RCR%S %i,%e", /* 0x03 */
692 Ib,0, "SHL%S %i,%e", /* 0x04 */
693 Ib,0, "SHR%S %i,%e", /* 0x05 */
695 Ib,0, "SAR%S %i,%e", /* 0x07 */
698 static Optable optabD0[8] =
700 0,0, "ROLB %e", /* 0x00 */
701 0,0, "RORB %e", /* 0x01 */
702 0,0, "RCLB %e", /* 0x02 */
703 0,0, "RCRB %e", /* 0x03 */
704 0,0, "SHLB %e", /* 0x04 */
705 0,0, "SHRB %e", /* 0x05 */
707 0,0, "SARB %e", /* 0x07 */
710 static Optable optabD1[8] =
712 0,0, "ROL%S %e", /* 0x00 */
713 0,0, "ROR%S %e", /* 0x01 */
714 0,0, "RCL%S %e", /* 0x02 */
715 0,0, "RCR%S %e", /* 0x03 */
716 0,0, "SHL%S %e", /* 0x04 */
717 0,0, "SHR%S %e", /* 0x05 */
719 0,0, "SAR%S %e", /* 0x07 */
722 static Optable optabD2[8] =
724 0,0, "ROLB CL,%e", /* 0x00 */
725 0,0, "RORB CL,%e", /* 0x01 */
726 0,0, "RCLB CL,%e", /* 0x02 */
727 0,0, "RCRB CL,%e", /* 0x03 */
728 0,0, "SHLB CL,%e", /* 0x04 */
729 0,0, "SHRB CL,%e", /* 0x05 */
731 0,0, "SARB CL,%e", /* 0x07 */
734 static Optable optabD3[8] =
736 0,0, "ROL%S CL,%e", /* 0x00 */
737 0,0, "ROR%S CL,%e", /* 0x01 */
738 0,0, "RCL%S CL,%e", /* 0x02 */
739 0,0, "RCR%S CL,%e", /* 0x03 */
740 0,0, "SHL%S CL,%e", /* 0x04 */
741 0,0, "SHR%S CL,%e", /* 0x05 */
743 0,0, "SAR%S CL,%e", /* 0x07 */
746 static Optable optabD8[8+8] =
748 0,0, "FADDF %e,F0", /* 0x00 */
749 0,0, "FMULF %e,F0", /* 0x01 */
750 0,0, "FCOMF %e,F0", /* 0x02 */
751 0,0, "FCOMFP %e,F0", /* 0x03 */
752 0,0, "FSUBF %e,F0", /* 0x04 */
753 0,0, "FSUBRF %e,F0", /* 0x05 */
754 0,0, "FDIVF %e,F0", /* 0x06 */
755 0,0, "FDIVRF %e,F0", /* 0x07 */
756 0,0, "FADDD %f,F0", /* 0x08 */
757 0,0, "FMULD %f,F0", /* 0x09 */
758 0,0, "FCOMD %f,F0", /* 0x0a */
759 0,0, "FCOMPD %f,F0", /* 0x0b */
760 0,0, "FSUBD %f,F0", /* 0x0c */
761 0,0, "FSUBRD %f,F0", /* 0x0d */
762 0,0, "FDIVD %f,F0", /* 0x0e */
763 0,0, "FDIVRD %f,F0", /* 0x0f */
766 * optabD9 and optabDB use the following encoding:
767 * if (0 <= modrm <= 2) instruction = optabDx[modrm&0x07];
768 * else instruction = optabDx[(modrm&0x3f)+8];
770 * the instructions for MOD == 3, follow the 8 instructions
771 * for the other MOD values stored at the front of the table.
773 static Optable optabD9[64+8] =
775 0,0, "FMOVF %e,F0", /* 0x00 */
777 0,0, "FMOVF F0,%e", /* 0x02 */
778 0,0, "FMOVFP F0,%e", /* 0x03 */
779 0,0, "FLDENV%S %e", /* 0x04 */
780 0,0, "FLDCW %e", /* 0x05 */
781 0,0, "FSTENV%S %e", /* 0x06 */
782 0,0, "FSTCW %e", /* 0x07 */
783 0,0, "FMOVD F0,F0", /* 0x08 */ /* Mod R/M = 11xx xxxx*/
784 0,0, "FMOVD F1,F0", /* 0x09 */
785 0,0, "FMOVD F2,F0", /* 0x0a */
786 0,0, "FMOVD F3,F0", /* 0x0b */
787 0,0, "FMOVD F4,F0", /* 0x0c */
788 0,0, "FMOVD F5,F0", /* 0x0d */
789 0,0, "FMOVD F6,F0", /* 0x0e */
790 0,0, "FMOVD F7,F0", /* 0x0f */
791 0,0, "FXCHD F0,F0", /* 0x10 */
792 0,0, "FXCHD F1,F0", /* 0x11 */
793 0,0, "FXCHD F2,F0", /* 0x12 */
794 0,0, "FXCHD F3,F0", /* 0x13 */
795 0,0, "FXCHD F4,F0", /* 0x14 */
796 0,0, "FXCHD F5,F0", /* 0x15 */
797 0,0, "FXCHD F6,F0", /* 0x16 */
798 0,0, "FXCHD F7,F0", /* 0x17 */
799 0,0, "FNOP", /* 0x18 */
815 0,0, "FCHS", /* 0x28 */
816 0,0, "FABS", /* 0x29 */
819 0,0, "FTST", /* 0x2c */
820 0,0, "FXAM", /* 0x2d */
823 0,0, "FLD1", /* 0x30 */
824 0,0, "FLDL2T", /* 0x31 */
825 0,0, "FLDL2E", /* 0x32 */
826 0,0, "FLDPI", /* 0x33 */
827 0,0, "FLDLG2", /* 0x34 */
828 0,0, "FLDLN2", /* 0x35 */
829 0,0, "FLDZ", /* 0x36 */
831 0,0, "F2XM1", /* 0x38 */
832 0,0, "FYL2X", /* 0x39 */
833 0,0, "FPTAN", /* 0x3a */
834 0,0, "FPATAN", /* 0x3b */
835 0,0, "FXTRACT", /* 0x3c */
836 0,0, "FPREM1", /* 0x3d */
837 0,0, "FDECSTP", /* 0x3e */
838 0,0, "FNCSTP", /* 0x3f */
839 0,0, "FPREM", /* 0x40 */
840 0,0, "FYL2XP1", /* 0x41 */
841 0,0, "FSQRT", /* 0x42 */
842 0,0, "FSINCOS", /* 0x43 */
843 0,0, "FRNDINT", /* 0x44 */
844 0,0, "FSCALE", /* 0x45 */
845 0,0, "FSIN", /* 0x46 */
846 0,0, "FCOS", /* 0x47 */
849 static Optable optabDA[8+8] =
851 0,0, "FADDL %e,F0", /* 0x00 */
852 0,0, "FMULL %e,F0", /* 0x01 */
853 0,0, "FCOML %e,F0", /* 0x02 */
854 0,0, "FCOMLP %e,F0", /* 0x03 */
855 0,0, "FSUBL %e,F0", /* 0x04 */
856 0,0, "FSUBRL %e,F0", /* 0x05 */
857 0,0, "FDIVL %e,F0", /* 0x06 */
858 0,0, "FDIVRL %e,F0", /* 0x07 */
864 R1,0, "FUCOMPP", /* 0x0d */
867 static Optable optabDB[8+64] =
869 0,0, "FMOVL %e,F0", /* 0x00 */
871 0,0, "FMOVL F0,%e", /* 0x02 */
872 0,0, "FMOVLP F0,%e", /* 0x03 */
874 0,0, "FMOVX %e,F0", /* 0x05 */
876 0,0, "FMOVXP F0,%e", /* 0x07 */
911 0,0, "FCLEX", /* 0x2a */
912 0,0, "FINIT", /* 0x2b */
915 static Optable optabDC[8+8] =
917 0,0, "FADDD %e,F0", /* 0x00 */
918 0,0, "FMULD %e,F0", /* 0x01 */
919 0,0, "FCOMD %e,F0", /* 0x02 */
920 0,0, "FCOMDP %e,F0", /* 0x03 */
921 0,0, "FSUBD %e,F0", /* 0x04 */
922 0,0, "FSUBRD %e,F0", /* 0x05 */
923 0,0, "FDIVD %e,F0", /* 0x06 */
924 0,0, "FDIVRD %e,F0", /* 0x07 */
925 0,0, "FADDD F0,%f", /* 0x08 */
926 0,0, "FMULD F0,%f", /* 0x09 */
929 0,0, "FSUBRD F0,%f", /* 0x0c */
930 0,0, "FSUBD F0,%f", /* 0x0d */
931 0,0, "FDIVRD F0,%f", /* 0x0e */
932 0,0, "FDIVD F0,%f", /* 0x0f */
935 static Optable optabDD[8+8] =
937 0,0, "FMOVD %e,F0", /* 0x00 */
939 0,0, "FMOVD F0,%e", /* 0x02 */
940 0,0, "FMOVDP F0,%e", /* 0x03 */
941 0,0, "FRSTOR%S %e", /* 0x04 */
943 0,0, "FSAVE%S %e", /* 0x06 */
944 0,0, "FSTSW %e", /* 0x07 */
945 0,0, "FFREED %f", /* 0x08 */
947 0,0, "FMOVD %f,F0", /* 0x0a */
948 0,0, "FMOVDP %f,F0", /* 0x0b */
949 0,0, "FUCOMD %f,F0", /* 0x0c */
950 0,0, "FUCOMDP %f,F0", /* 0x0d */
953 static Optable optabDE[8+8] =
955 0,0, "FADDW %e,F0", /* 0x00 */
956 0,0, "FMULW %e,F0", /* 0x01 */
957 0,0, "FCOMW %e,F0", /* 0x02 */
958 0,0, "FCOMWP %e,F0", /* 0x03 */
959 0,0, "FSUBW %e,F0", /* 0x04 */
960 0,0, "FSUBRW %e,F0", /* 0x05 */
961 0,0, "FDIVW %e,F0", /* 0x06 */
962 0,0, "FDIVRW %e,F0", /* 0x07 */
963 0,0, "FADDDP F0,%f", /* 0x08 */
964 0,0, "FMULDP F0,%f", /* 0x09 */
966 R1,0, "FCOMPDP", /* 0x0b */
967 0,0, "FSUBRDP F0,%f", /* 0x0c */
968 0,0, "FSUBDP F0,%f", /* 0x0d */
969 0,0, "FDIVRDP F0,%f", /* 0x0e */
970 0,0, "FDIVDP F0,%f", /* 0x0f */
973 static Optable optabDF[8+8] =
975 0,0, "FMOVW %e,F0", /* 0x00 */
977 0,0, "FMOVW F0,%e", /* 0x02 */
978 0,0, "FMOVWP F0,%e", /* 0x03 */
979 0,0, "FBLD %e", /* 0x04 */
980 0,0, "FMOVL %e,F0", /* 0x05 */
981 0,0, "FBSTP %e", /* 0x06 */
982 0,0, "FMOVLP F0,%e", /* 0x07 */
987 R0,0, "FSTSW %OAX", /* 0x0c */
990 static Optable optabF6[8] =
992 Ib,0, "TESTB %i,%e", /* 0x00 */
994 0,0, "NOTB %e", /* 0x02 */
995 0,0, "NEGB %e", /* 0x03 */
996 0,0, "MULB AL,%e", /* 0x04 */
997 0,0, "IMULB AL,%e", /* 0x05 */
998 0,0, "DIVB AL,%e", /* 0x06 */
999 0,0, "IDIVB AL,%e", /* 0x07 */
1002 static Optable optabF7[8] =
1004 Iwd,0, "TEST%S %i,%e", /* 0x00 */
1006 0,0, "NOT%S %e", /* 0x02 */
1007 0,0, "NEG%S %e", /* 0x03 */
1008 0,0, "MUL%S %OAX,%e", /* 0x04 */
1009 0,0, "IMUL%S %OAX,%e", /* 0x05 */
1010 0,0, "DIV%S %OAX,%e", /* 0x06 */
1011 0,0, "IDIV%S %OAX,%e", /* 0x07 */
1014 static Optable optabFE[8] =
1016 0,0, "INCB %e", /* 0x00 */
1017 0,0, "DECB %e", /* 0x01 */
1020 static Optable optabFF[8] =
1022 0,0, "INC%S %e", /* 0x00 */
1023 0,0, "DEC%S %e", /* 0x01 */
1024 JUMP,0, "CALL*%S %e", /* 0x02 */
1025 JUMP,0, "CALLF*%S %e", /* 0x03 */
1026 JUMP,0, "JMP*%S %e", /* 0x04 */
1027 JUMP,0, "JMPF*%S %e", /* 0x05 */
1028 0,0, "PUSHL %e", /* 0x06 */
1031 static Optable optable[256] =
1033 RMB,0, "ADDB %r,%e", /* 0x00 */
1034 RM,0, "ADD%S %r,%e", /* 0x01 */
1035 RMB,0, "ADDB %e,%r", /* 0x02 */
1036 RM,0, "ADD%S %e,%r", /* 0x03 */
1037 Ib,0, "ADDB %i,AL", /* 0x04 */
1038 Iwd,0, "ADD%S %i,%OAX", /* 0x05 */
1039 0,0, "PUSHL ES", /* 0x06 */
1040 0,0, "POPL ES", /* 0x07 */
1041 RMB,0, "ORB %r,%e", /* 0x08 */
1042 RM,0, "OR%S %r,%e", /* 0x09 */
1043 RMB,0, "ORB %e,%r", /* 0x0a */
1044 RM,0, "OR%S %e,%r", /* 0x0b */
1045 Ib,0, "ORB %i,AL", /* 0x0c */
1046 Iwd,0, "OR%S %i,%OAX", /* 0x0d */
1047 0,0, "PUSHL CS", /* 0x0e */
1048 AUX,0, optab0F, /* 0x0f */
1049 RMB,0, "ADCB %r,%e", /* 0x10 */
1050 RM,0, "ADC%S %r,%e", /* 0x11 */
1051 RMB,0, "ADCB %e,%r", /* 0x12 */
1052 RM,0, "ADC%S %e,%r", /* 0x13 */
1053 Ib,0, "ADCB %i,AL", /* 0x14 */
1054 Iwd,0, "ADC%S %i,%OAX", /* 0x15 */
1055 0,0, "PUSHL SS", /* 0x16 */
1056 0,0, "POPL SS", /* 0x17 */
1057 RMB,0, "SBBB %r,%e", /* 0x18 */
1058 RM,0, "SBB%S %r,%e", /* 0x19 */
1059 RMB,0, "SBBB %e,%r", /* 0x1a */
1060 RM,0, "SBB%S %e,%r", /* 0x1b */
1061 Ib,0, "SBBB %i,AL", /* 0x1c */
1062 Iwd,0, "SBB%S %i,%OAX", /* 0x1d */
1063 0,0, "PUSHL DS", /* 0x1e */
1064 0,0, "POPL DS", /* 0x1f */
1065 RMB,0, "ANDB %r,%e", /* 0x20 */
1066 RM,0, "AND%S %r,%e", /* 0x21 */
1067 RMB,0, "ANDB %e,%r", /* 0x22 */
1068 RM,0, "AND%S %e,%r", /* 0x23 */
1069 Ib,0, "ANDB %i,AL", /* 0x24 */
1070 Iwd,0, "AND%S %i,%OAX", /* 0x25 */
1071 SEG,0, "ES:", /* 0x26 */
1072 0,0, "DAA", /* 0x27 */
1073 RMB,0, "SUBB %r,%e", /* 0x28 */
1074 RM,0, "SUB%S %r,%e", /* 0x29 */
1075 RMB,0, "SUBB %e,%r", /* 0x2a */
1076 RM,0, "SUB%S %e,%r", /* 0x2b */
1077 Ib,0, "SUBB %i,AL", /* 0x2c */
1078 Iwd,0, "SUB%S %i,%OAX", /* 0x2d */
1079 SEG,0, "CS:", /* 0x2e */
1080 0,0, "DAS", /* 0x2f */
1081 RMB,0, "XORB %r,%e", /* 0x30 */
1082 RM,0, "XOR%S %r,%e", /* 0x31 */
1083 RMB,0, "XORB %e,%r", /* 0x32 */
1084 RM,0, "XOR%S %e,%r", /* 0x33 */
1085 Ib,0, "XORB %i,AL", /* 0x34 */
1086 Iwd,0, "XOR%S %i,%OAX", /* 0x35 */
1087 SEG,0, "SS:", /* 0x36 */
1088 0,0, "AAA", /* 0x37 */
1089 RMB,0, "CMPB %r,%e", /* 0x38 */
1090 RM,0, "CMP%S %r,%e", /* 0x39 */
1091 RMB,0, "CMPB %e,%r", /* 0x3a */
1092 RM,0, "CMP%S %e,%r", /* 0x3b */
1093 Ib,0, "CMPB %i,AL", /* 0x3c */
1094 Iwd,0, "CMP%S %i,%OAX", /* 0x3d */
1095 SEG,0, "DS:", /* 0x3e */
1096 0,0, "AAS", /* 0x3f */
1097 0,0, "INC%S %OAX", /* 0x40 */
1098 0,0, "INC%S %OCX", /* 0x41 */
1099 0,0, "INC%S %ODX", /* 0x42 */
1100 0,0, "INC%S %OBX", /* 0x43 */
1101 0,0, "INC%S %OSP", /* 0x44 */
1102 0,0, "INC%S %OBP", /* 0x45 */
1103 0,0, "INC%S %OSI", /* 0x46 */
1104 0,0, "INC%S %ODI", /* 0x47 */
1105 0,0, "DEC%S %OAX", /* 0x48 */
1106 0,0, "DEC%S %OCX", /* 0x49 */
1107 0,0, "DEC%S %ODX", /* 0x4a */
1108 0,0, "DEC%S %OBX", /* 0x4b */
1109 0,0, "DEC%S %OSP", /* 0x4c */
1110 0,0, "DEC%S %OBP", /* 0x4d */
1111 0,0, "DEC%S %OSI", /* 0x4e */
1112 0,0, "DEC%S %ODI", /* 0x4f */
1113 0,0, "PUSH%S %OAX", /* 0x50 */
1114 0,0, "PUSH%S %OCX", /* 0x51 */
1115 0,0, "PUSH%S %ODX", /* 0x52 */
1116 0,0, "PUSH%S %OBX", /* 0x53 */
1117 0,0, "PUSH%S %OSP", /* 0x54 */
1118 0,0, "PUSH%S %OBP", /* 0x55 */
1119 0,0, "PUSH%S %OSI", /* 0x56 */
1120 0,0, "PUSH%S %ODI", /* 0x57 */
1121 0,0, "POP%S %OAX", /* 0x58 */
1122 0,0, "POP%S %OCX", /* 0x59 */
1123 0,0, "POP%S %ODX", /* 0x5a */
1124 0,0, "POP%S %OBX", /* 0x5b */
1125 0,0, "POP%S %OSP", /* 0x5c */
1126 0,0, "POP%S %OBP", /* 0x5d */
1127 0,0, "POP%S %OSI", /* 0x5e */
1128 0,0, "POP%S %ODI", /* 0x5f */
1129 0,0, "PUSHA%S", /* 0x60 */
1130 0,0, "POPA%S", /* 0x61 */
1131 RMM,0, "BOUND %e,%r", /* 0x62 */
1132 RM,0, "ARPL %r,%e", /* 0x63 */
1133 SEG,0, "FS:", /* 0x64 */
1134 SEG,0, "GS:", /* 0x65 */
1135 OPOVER,0, "", /* 0x66 */
1136 ADDOVER,0, "", /* 0x67 */
1137 Iwd,0, "PUSH%S %i", /* 0x68 */
1138 RM,Iwd, "IMUL%S %e,%i,%r", /* 0x69 */
1139 Ib,0, "PUSH%S %i", /* 0x6a */
1140 RM,Ibs, "IMUL%S %e,%i,%r", /* 0x6b */
1141 0,0, "INSB DX,(%ODI)", /* 0x6c */
1142 0,0, "INS%S DX,(%ODI)", /* 0x6d */
1143 0,0, "OUTSB (%ASI),DX", /* 0x6e */
1144 0,0, "OUTS%S (%ASI),DX", /* 0x6f */
1145 Jbs,0, "JOS %p", /* 0x70 */
1146 Jbs,0, "JOC %p", /* 0x71 */
1147 Jbs,0, "JCS %p", /* 0x72 */
1148 Jbs,0, "JCC %p", /* 0x73 */
1149 Jbs,0, "JEQ %p", /* 0x74 */
1150 Jbs,0, "JNE %p", /* 0x75 */
1151 Jbs,0, "JLS %p", /* 0x76 */
1152 Jbs,0, "JHI %p", /* 0x77 */
1153 Jbs,0, "JMI %p", /* 0x78 */
1154 Jbs,0, "JPL %p", /* 0x79 */
1155 Jbs,0, "JPS %p", /* 0x7a */
1156 Jbs,0, "JPC %p", /* 0x7b */
1157 Jbs,0, "JLT %p", /* 0x7c */
1158 Jbs,0, "JGE %p", /* 0x7d */
1159 Jbs,0, "JLE %p", /* 0x7e */
1160 Jbs,0, "JGT %p", /* 0x7f */
1161 RMOPB,0, optab80, /* 0x80 */
1162 RMOP,0, optab81, /* 0x81 */
1164 RMOP,0, optab83, /* 0x83 */
1165 RMB,0, "TESTB %r,%e", /* 0x84 */
1166 RM,0, "TEST%S %r,%e", /* 0x85 */
1167 RMB,0, "XCHGB %r,%e", /* 0x86 */
1168 RM,0, "XCHG%S %r,%e", /* 0x87 */
1169 RMB,0, "MOVB %r,%e", /* 0x88 */
1170 RM,0, "MOV%S %r,%e", /* 0x89 */
1171 RMB,0, "MOVB %e,%r", /* 0x8a */
1172 RM,0, "MOV%S %e,%r", /* 0x8b */
1173 RM,0, "MOVW %g,%e", /* 0x8c */
1174 RM,0, "LEA %e,%r", /* 0x8d */
1175 RM,0, "MOVW %e,%g", /* 0x8e */
1176 RM,0, "POP%S %e", /* 0x8f */
1177 0,0, "NOP", /* 0x90 */
1178 0,0, "XCHG %OCX,%OAX", /* 0x91 */
1179 0,0, "XCHG %OCX,%OAX", /* 0x92 */
1180 0,0, "XCHG %OCX,%OAX", /* 0x93 */
1181 0,0, "XCHG %OSP,%OAX", /* 0x94 */
1182 0,0, "XCHG %OBP,%OAX", /* 0x95 */
1183 0,0, "XCHG %OSI,%OAX", /* 0x96 */
1184 0,0, "XCHG %ODI,%OAX", /* 0x97 */
1185 0,0, "%X", /* 0x98 */ /* miserable CBW or CWDE */
1186 0,0, "%x", /* 0x99 */ /* idiotic CWD or CDQ */
1187 PTR,0, "CALL%S %d", /* 0x9a */
1188 0,0, "WAIT", /* 0x9b */
1189 0,0, "PUSHF", /* 0x9c */
1190 0,0, "POPF", /* 0x9d */
1191 0,0, "SAHF", /* 0x9e */
1192 0,0, "LAHF", /* 0x9f */
1193 Awd,0, "MOVB %i,AL", /* 0xa0 */
1194 Awd,0, "MOV%S %i,%OAX", /* 0xa1 */
1195 Awd,0, "MOVB AL,%i", /* 0xa2 */
1196 Awd,0, "MOV%S %OAX,%i", /* 0xa3 */
1197 0,0, "MOVSB (%ASI),(%ADI)", /* 0xa4 */
1198 0,0, "MOVS%S (%ASI),(%ADI)", /* 0xa5 */
1199 0,0, "CMPSB (%ASI),(%ADI)", /* 0xa6 */
1200 0,0, "CMPS%S (%ASI),(%ADI)", /* 0xa7 */
1201 Ib,0, "TESTB %i,AL", /* 0xa8 */
1202 Iwd,0, "TEST%S %i,%OAX", /* 0xa9 */
1203 0,0, "STOSB AL,(%ADI)", /* 0xaa */
1204 0,0, "STOS%S %OAX,(%ADI)", /* 0xab */
1205 0,0, "LODSB (%ASI),AL", /* 0xac */
1206 0,0, "LODS%S (%ASI),%OAX", /* 0xad */
1207 0,0, "SCASB (%ADI),AL", /* 0xae */
1208 0,0, "SCAS%S (%ADI),%OAX", /* 0xaf */
1209 Ib,0, "MOVB %i,AL", /* 0xb0 */
1210 Ib,0, "MOVB %i,CL", /* 0xb1 */
1211 Ib,0, "MOVB %i,DL", /* 0xb2 */
1212 Ib,0, "MOVB %i,BL", /* 0xb3 */
1213 Ib,0, "MOVB %i,AH", /* 0xb4 */
1214 Ib,0, "MOVB %i,CH", /* 0xb5 */
1215 Ib,0, "MOVB %i,DH", /* 0xb6 */
1216 Ib,0, "MOVB %i,BH", /* 0xb7 */
1217 Iwd,0, "MOV%S %i,%OAX", /* 0xb8 */
1218 Iwd,0, "MOV%S %i,%OCX", /* 0xb9 */
1219 Iwd,0, "MOV%S %i,%ODX", /* 0xba */
1220 Iwd,0, "MOV%S %i,%OBX", /* 0xbb */
1221 Iwd,0, "MOV%S %i,%OSP", /* 0xbc */
1222 Iwd,0, "MOV%S %i,%OBP", /* 0xbd */
1223 Iwd,0, "MOV%S %i,%OSI", /* 0xbe */
1224 Iwd,0, "MOV%S %i,%ODI", /* 0xbf */
1225 RMOPB,0, optabC0, /* 0xc0 */
1226 RMOP,0, optabC1, /* 0xc1 */
1227 Iw,0, "RET %i", /* 0xc2 */
1228 RET,0, "RET", /* 0xc3 */
1229 RM,0, "LES %e,%r", /* 0xc4 */
1230 RM,0, "LDS %e,%r", /* 0xc5 */
1231 RMB,Ib, "MOVB %i,%e", /* 0xc6 */
1232 RM,Iwd, "MOV%S %i,%e", /* 0xc7 */
1233 Iw2,Ib, "ENTER %i,%I", /* 0xc8 */ /* loony ENTER */
1234 RET,0, "LEAVE", /* 0xc9 */ /* bizarre LEAVE */
1235 Iw,0, "RETF %i", /* 0xca */
1236 RET,0, "RETF", /* 0xcb */
1237 0,0, "INT 3", /* 0xcc */
1238 Ib,0, "INTB %i", /* 0xcd */
1239 0,0, "INTO", /* 0xce */
1240 0,0, "IRET", /* 0xcf */
1241 RMOPB,0, optabD0, /* 0xd0 */
1242 RMOP,0, optabD1, /* 0xd1 */
1243 RMOPB,0, optabD2, /* 0xd2 */
1244 RMOP,0, optabD3, /* 0xd3 */
1245 OA,0, "AAM", /* 0xd4 */
1246 OA,0, "AAD", /* 0xd5 */
1248 0,0, "XLAT", /* 0xd7 */
1249 FRMOP,0, optabD8, /* 0xd8 */
1250 FRMEX,0, optabD9, /* 0xd9 */
1251 FRMOP,0, optabDA, /* 0xda */
1252 FRMEX,0, optabDB, /* 0xdb */
1253 FRMOP,0, optabDC, /* 0xdc */
1254 FRMOP,0, optabDD, /* 0xdd */
1255 FRMOP,0, optabDE, /* 0xde */
1256 FRMOP,0, optabDF, /* 0xdf */
1257 Jbs,0, "LOOPNE %p", /* 0xe0 */
1258 Jbs,0, "LOOPE %p", /* 0xe1 */
1259 Jbs,0, "LOOP %p", /* 0xe2 */
1260 Jbs,0, "JCXZ %p", /* 0xe3 */
1261 Ib,0, "INB %i,AL", /* 0xe4 */
1262 Ib,0, "IN%S %i,%OAX", /* 0xe5 */
1263 Ib,0, "OUTB AL,%i", /* 0xe6 */
1264 Ib,0, "OUT%S %OAX,%i", /* 0xe7 */
1265 Iwds,0, "CALL %p", /* 0xe8 */
1266 Iwds,0, "JMP %p", /* 0xe9 */
1267 PTR,0, "JMP %d", /* 0xea */
1268 Jbs,0, "JMP %p", /* 0xeb */
1269 0,0, "INB DX,AL", /* 0xec */
1270 0,0, "IN%S DX,%OAX", /* 0xed */
1271 0,0, "OUTB AL,DX", /* 0xee */
1272 0,0, "OUT%S %OAX,DX", /* 0xef */
1273 PRE,0, "LOCK", /* 0xf0 */
1275 PRE,0, "REPNE", /* 0xf2 */
1276 PRE,0, "REP", /* 0xf3 */
1277 0,0, "HALT", /* 0xf4 */
1278 0,0, "CMC", /* 0xf5 */
1279 RMOPB,0, optabF6, /* 0xf6 */
1280 RMOP,0, optabF7, /* 0xf7 */
1281 0,0, "CLC", /* 0xf8 */
1282 0,0, "STC", /* 0xf9 */
1283 0,0, "CLI", /* 0xfa */
1284 0,0, "STI", /* 0xfb */
1285 0,0, "CLD", /* 0xfc */
1286 0,0, "STD", /* 0xfd */
1287 RMOPB,0, optabFE, /* 0xfe */
1288 RMOP,0, optabFF, /* 0xff */
1292 * get a byte of the instruction
1295 igetc(Map * map, Instr *ip, uchar *c)
1297 if(ip->n+1 > sizeof(ip->mem)){
1298 werrstr("instruction too long");
1301 if (get1(map, ip->addr+ip->n, c, 1) < 0) {
1302 werrstr("can't read instruction: %r");
1305 ip->mem[ip->n++] = *c;
1310 * get two bytes of the instruction
1313 igets(Map *map, Instr *ip, ushort *sp)
1318 if (igetc(map, ip, &c) < 0)
1321 if (igetc(map, ip, &c) < 0)
1329 * get 4 bytes of the instruction
1332 igetl(Map *map, Instr *ip, ulong *lp)
1337 if (igets(map, ip, &s) < 0)
1340 if (igets(map, ip, &s) < 0)
1348 getdisp(Map *map, Instr *ip, int mod, int rm, int code)
1356 if (igetc(map, ip, &c) < 0)
1359 ip->disp = c|0xffffff00;
1362 } else if (mod == 2 || rm == code) {
1363 if (ip->asize == 'E') {
1364 if (igetl(map, ip, &ip->disp) < 0)
1367 if (igets(map, ip, &s) < 0)
1370 ip->disp = s|0xffff0000;
1381 modrm(Map *map, Instr *ip, uchar c)
1390 if (mod == 3) /* register */
1392 if (ip->asize == 0) { /* 16-bit mode */
1396 ip->base = BX; ip->index = SI;
1399 ip->base = BX; ip->index = DI;
1402 ip->base = BP; ip->index = SI;
1405 ip->base = BP; ip->index = DI;
1422 return getdisp(map, ip, mod, rm, 6);
1424 if (rm == 4) { /* scummy sib byte */
1425 if (igetc(map, ip, &c) < 0)
1427 ip->ss = (c>>6)&0x03;
1428 ip->index = (c>>3)&0x07;
1432 return getdisp(map, ip, mod, ip->base, 5);
1434 return getdisp(map, ip, mod, rm, 5);
1438 mkinstr(Map *map, Instr *ip, ulong pc)
1443 Optable *op, *obase;
1446 memset(ip, 0, sizeof(*ip));
1449 if(0) /* asstype == AI8086) */
1456 if (igetc(map, ip, &c) < 0)
1461 if (op->proto == 0) {
1463 n = snprint(buf, sizeof(buf), "opcode: ??");
1464 for (i = 0; i < ip->n && n < sizeof(buf)-3; i++, n+=2)
1465 _hexify(buf+n, ip->mem[i], 1);
1466 strcpy(buf+n, "??");
1470 for(i = 0; i < 2 && op->operand[i]; i++) {
1471 switch(op->operand[i])
1473 case Ib: /* 8-bit immediate - (no sign extension)*/
1474 if (igetc(map, ip, &c) < 0)
1478 case Jbs: /* 8-bit jump immediate (sign extended) */
1479 if (igetc(map, ip, &c) < 0)
1482 ip->imm = c|0xffffff00;
1487 case Ibs: /* 8-bit immediate (sign extended) */
1488 if (igetc(map, ip, &c) < 0)
1491 if (ip->osize == 'L')
1492 ip->imm = c|0xffffff00;
1498 case Iw: /* 16-bit immediate -> imm */
1499 if (igets(map, ip, &s) < 0)
1504 case Iw2: /* 16-bit immediate -> in imm2*/
1505 if (igets(map, ip, &s) < 0)
1507 ip->imm2 = s&0xffff;
1509 case Iwd: /* Operand-sized immediate (no sign extension)*/
1510 if (ip->osize == 'L') {
1511 if (igetl(map, ip, &ip->imm) < 0)
1514 if (igets(map, ip, &s)< 0)
1519 case Awd: /* Address-sized immediate (no sign extension)*/
1520 if (ip->asize == 'E') {
1521 if (igetl(map, ip, &ip->imm) < 0)
1524 if (igets(map, ip, &s)< 0)
1529 case Iwds: /* Operand-sized immediate (sign extended) */
1530 if (ip->osize == 'L') {
1531 if (igetl(map, ip, &ip->imm) < 0)
1534 if (igets(map, ip, &s)< 0)
1537 ip->imm = s|0xffff0000;
1541 ip->jumptype = Iwds;
1543 case OA: /* literal 0x0a byte */
1544 if (igetc(map, ip, &c) < 0)
1549 case R0: /* base register must be R0 */
1553 case R1: /* base register must be R1 */
1557 case RMB: /* R/M field with byte register (/r)*/
1558 if (igetc(map, ip, &c) < 0)
1560 if (modrm(map, ip, c) < 0)
1564 case RM: /* R/M field with register (/r) */
1565 if (igetc(map, ip, &c) < 0)
1567 if (modrm(map, ip, c) < 0)
1570 case RMOPB: /* R/M field with op code (/digit) */
1571 if (igetc(map, ip, &c) < 0)
1573 if (modrm(map, ip, c) < 0)
1575 c = ip->reg; /* secondary op code */
1576 obase = (Optable*)op->proto;
1579 case RMOP: /* R/M field with op code (/digit) */
1580 if (igetc(map, ip, &c) < 0)
1582 if (modrm(map, ip, c) < 0)
1585 obase = (Optable*)op->proto;
1587 case FRMOP: /* FP R/M field with op code (/digit) */
1588 if (igetc(map, ip, &c) < 0)
1590 if (modrm(map, ip, c) < 0)
1592 if ((c&0xc0) == 0xc0)
1593 c = ip->reg+8; /* 16 entry table */
1596 obase = (Optable*)op->proto;
1598 case FRMEX: /* Extended FP R/M field with op code (/digit) */
1599 if (igetc(map, ip, &c) < 0)
1601 if (modrm(map, ip, c) < 0)
1603 if ((c&0xc0) == 0xc0)
1604 c = (c&0x3f)+8; /* 64-entry table */
1607 obase = (Optable*)op->proto;
1609 case RMR: /* R/M register only (mod = 11) */
1610 if (igetc(map, ip, &c) < 0)
1612 if ((c&0xc0) != 0xc0) {
1613 werrstr("invalid R/M register: %x", c);
1616 if (modrm(map, ip, c) < 0)
1619 case RMM: /* R/M register only (mod = 11) */
1620 if (igetc(map, ip, &c) < 0)
1622 if ((c&0xc0) == 0xc0) {
1623 werrstr("invalid R/M memory mode: %x", c);
1626 if (modrm(map, ip, c) < 0)
1629 case PTR: /* Seg:Displacement addr (ptr16:16 or ptr16:32) */
1630 if (ip->osize == 'L') {
1631 if (igetl(map, ip, &ip->disp) < 0)
1634 if (igets(map, ip, &s)< 0)
1636 ip->disp = s&0xffff;
1638 if (igets(map, ip, (ushort*)&ip->seg) < 0)
1642 case AUX: /* Multi-byte op code - Auxiliary table */
1643 obase = (Optable*)op->proto;
1644 if (igetc(map, ip, &c) < 0)
1647 case PRE: /* Instr Prefix */
1648 ip->prefix = (char*)op->proto;
1649 if (igetc(map, ip, &c) < 0)
1652 case SEG: /* Segment Prefix */
1653 ip->segment = (char*)op->proto;
1654 if (igetc(map, ip, &c) < 0)
1657 case OPOVER: /* Operand size override */
1659 if (igetc(map, ip, &c) < 0)
1662 case ADDOVER: /* Address size override */
1664 if (igetc(map, ip, &c) < 0)
1667 case JUMP: /* mark instruction as JUMP or RET */
1669 ip->jumptype = op->operand[i];
1672 werrstr("bad operand type %d", op->operand[i]);
1680 bprint(Instr *ip, char *fmt, ...)
1685 ip->curr = vseprint(ip->curr, ip->end, fmt, arg);
1690 * if we want to call 16 bit regs AX,BX,CX,...
1691 * and 32 bit regs EAX,EBX,ECX,... then
1692 * change the defs of ANAME and ONAME to:
1693 * #define ANAME(ip) ((ip->asize == 'E' ? "E" : "")
1694 * #define ONAME(ip) ((ip)->osize == 'L' ? "E" : "")
1696 #define ANAME(ip) ""
1697 #define ONAME(ip) ""
1699 static char *reg[] = {
1710 static char *breg[] = { "AL", "CL", "DL", "BL", "AH", "CH", "DH", "BH" };
1711 static char *sreg[] = { "ES", "CS", "SS", "DS", "FS", "GS" };
1721 l.offset = ip->disp;
1729 if(findsym(li, CTEXT, &s) < 0)
1733 if(ip->base==SP && lookuplsym(&s, FRAMENAME, &s) >= 0){
1734 /* translate stack offset to offset from plan 9 frame pointer */
1735 /* XXX not sure how to do this */
1738 if(name==nil && findlsym(&s, l, &s) >= 0)
1742 bprint(ip, "%s+", name);
1745 bprint(ip, "%lx(%s)", l.offset, l.reg);
1751 switch(ip->jumptype){
1762 * This is too smart for its own good, but it really is nice
1763 * to have accurate translations when debugging, and it
1764 * helps us identify which code is different in binaries that
1765 * are changed on sources.
1768 issymref(Instr *ip, Symbol *s, long w, long val)
1771 long isstring, size;
1775 if (s->class==CTEXT && w==0)
1777 if (s->class==CDATA) {
1778 /* use first bss symbol (or "end") rather than edata */
1779 if (s->name[0]=='e' && strcmp(s->name, "edata") == 0){
1780 if((indexsym(s->index+1, &tmp) && loccmp(&tmp.loc, &s->loc)==0)
1781 || (indexsym(s->index-1, &tmp) && loccmp(&tmp.loc, &s->loc)==0))
1786 for (next=*s; next.loc.addr==s->loc.addr; next=tmp)
1787 if (!indexsym(next.index+1, &tmp))
1789 size = next.loc.addr - s->loc.addr;
1794 /* huge distances are usually wrong except in .string */
1795 isstring = (s->name[0]=='.' && strcmp(s->name, ".string") == 0);
1796 if (w > 8192 && !isstring)
1798 /* medium distances are tricky - look for constants */
1799 /* near powers of two */
1800 if ((val&(val-1)) == 0 || (val&(val+1)) == 0)
1808 immediate(Instr *ip, long val)
1816 if (findsym(l, CANY, &s) >= 0) {
1817 w = val - s.loc.addr;
1820 if (issymref(ip, &s, w, val)) {
1822 bprint(ip, "%s+%lux(SB)", s.name, w);
1824 bprint(ip, "%s(SB)", s.name);
1827 if (s.class==CDATA && indexsym(s.index+1, &s) >= 0) {
1828 w = s.loc.addr - val;
1832 bprint(ip, "%s-%lux(SB)", s.name, w);
1837 bprint(ip, "%lux", val);
1844 if (ip->osize == 'B')
1845 bprint(ip, breg[(uchar)ip->base]);
1847 bprint(ip, "%s%s", ANAME(ip), reg[(uchar)ip->base]);
1851 bprint(ip, ip->segment);
1852 if (ip->asize == 'E' && (ip->base == SP || ip->base == BP))
1856 immediate(ip, ip->disp);
1858 bprint(ip, "%lux", ip->disp);
1859 bprint(ip,"(%s%s)", ANAME(ip), reg[(uchar)ip->base]);
1863 bprint(ip,"(%s%s*%d)", ANAME(ip), reg[(uchar)ip->index], 1<<ip->ss);
1867 prinstr(Instr *ip, char *fmt)
1870 bprint(ip, "%s ", ip->prefix);
1871 for (; *fmt && ip->curr < ip->end; fmt++) {
1880 bprint(ip, "%s", ANAME(ip));
1883 bprint(ip, "CR%d", ip->reg);
1886 if (ip->reg < 4 || ip->reg == 6 || ip->reg == 7)
1887 bprint(ip, "DR%d",ip->reg);
1893 immediate(ip, ip->imm2);
1896 bprint(ip,"%s", ONAME(ip));
1900 immediate(ip,ip->imm);
1903 bprint(ip, "%s%s", ONAME(ip), reg[ip->reg]);
1906 bprint(ip, "%c", ip->osize);
1909 if (ip->reg == 6 || ip->reg == 7)
1910 bprint(ip, "TR%d",ip->reg);
1915 if (ip->osize == 'L')
1921 bprint(ip,"%lux:%lux",ip->seg,ip->disp);
1927 bprint(ip, "F%d", ip->base);
1931 bprint(ip,"%s",sreg[ip->reg]);
1936 immediate(ip, ip->imm+ip->addr+ip->n);
1939 if (ip->osize == 'B')
1940 bprint(ip,"%s",breg[ip->reg]);
1942 bprint(ip, reg[ip->reg]);
1945 if (ip->osize == 'L')
1951 bprint(ip, "%%%c", *fmt);
1955 *ip->curr = 0; /* there's always room for 1 byte */
1959 i386das(Map *map, ulong pc, char modifier, char *buf, int n)
1965 op = mkinstr(map, &instr, pc);
1971 instr.end = buf+n-1;
1972 prinstr(&instr, op->proto);
1977 i386hexinst(Map *map, ulong pc, char *buf, int n)
1982 if (mkinstr(map, &instr, pc) == 0) {
1986 for(i = 0; i < instr.n && n > 2; i++) {
1987 _hexify(buf, instr.mem[i], 1);
1996 i386instlen(Map *map, ulong pc)
2000 if (mkinstr(map, &i, pc))
2006 i386foll(Map *map, Regs *regs, ulong pc, ulong *foll)
2015 op = mkinstr(map, &i, pc);
2021 switch(i.jumptype) {
2022 case RET: /* RETURN or LEAVE */
2023 case Iw: /* RETURN */
2024 if (strcmp(op->proto, "LEAVE") == 0) {
2025 if (lget4(map, regs, locindir("BP", 0), &l) < 0)
2027 } else if (lget4(map, regs, locindir(mach->sp, 0), &l) < 0)
2031 case Iwds: /* pc relative JUMP or CALL*/
2032 case Jbs: /* pc relative JUMP or CALL */
2033 foll[0] = pc+i.imm+i.n;
2036 case PTR: /* seg:displacement JUMP or CALL */
2037 foll[0] = (i.seg<<4)+i.disp;
2039 case JUMP: /* JUMP or CALL EA */
2042 if (rget(regs, reg[(uchar)i.base], &foll[0]) < 0)
2046 /* calculate the effective address */
2049 if (lget4(map, regs, locindir(reg[(uchar)i.base], 0), &l) < 0)
2054 if (lget4(map, regs, locindir(reg[(uchar)i.index], 0), &l) < 0)
2056 addr += l*(1<<i.ss);
2058 /* now retrieve a seg:disp value at that address */
2059 if (get2(map, addr, &s) < 0) /* seg */
2063 if (i.asize == 'L') {
2064 if (get4(map, addr, &l) < 0) /* disp32 */
2067 } else { /* disp16 */
2068 if (get2(map, addr, &s) < 0)
2076 if (strncmp(op->proto,"JMP", 3) == 0 || strncmp(op->proto,"CALL", 4) == 0)