1 /* Print i386 instructions for GDB, the GNU debugger.
2 Copyright (C) 1988, 89, 91, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 * The main tables describing the instructions is essentially a copy
29 * of the "Opcode Map" chapter (Appendix A) of the Intel 80386
30 * Programmers Manual. Usually, there is a capital letter, followed
31 * by a small letter. The capital letter tell the addressing mode,
32 * and the small letter tells about the operand size. Refer to
33 * the Intel manual for details.
44 #ifndef UNIXWARE_COMPAT
45 /* Set non-zero for broken, compatible instructions. Set to zero for
46 non-broken opcodes. */
47 #define UNIXWARE_COMPAT 1
51 static int fetch_data PARAMS ((struct disassemble_info *, bfd_byte *));
55 /* Points to first byte not fetched. */
56 bfd_byte *max_fetched;
57 bfd_byte the_buffer[MAXLEN];
62 /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
63 to ADDR (exclusive) are valid. Returns 1 for success, longjmps
65 #define FETCH_DATA(info, addr) \
66 ((addr) <= ((struct dis_private *)(info->private_data))->max_fetched \
67 ? 1 : fetch_data ((info), (addr)))
70 fetch_data (info, addr)
71 struct disassemble_info *info;
75 struct dis_private *priv = (struct dis_private *)info->private_data;
76 bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
78 status = (*info->read_memory_func) (start,
80 addr - priv->max_fetched,
84 (*info->memory_error_func) (status, start, info);
85 longjmp (priv->bailout, 1);
88 priv->max_fetched = addr;
92 #define Eb OP_E, b_mode
93 #define indirEb OP_indirE, b_mode
94 #define Gb OP_G, b_mode
95 #define Ev OP_E, v_mode
96 #define indirEv OP_indirE, v_mode
97 #define Ew OP_E, w_mode
98 #define Ma OP_E, v_mode
100 #define Mp OP_E, 0 /* ? */
101 #define Gv OP_G, v_mode
102 #define Gw OP_G, w_mode
103 #define Rw OP_rm, w_mode
104 #define Rd OP_rm, d_mode
105 #define Ib OP_I, b_mode
106 #define sIb OP_sI, b_mode /* sign extened byte */
107 #define Iv OP_I, v_mode
108 #define Iw OP_I, w_mode
109 #define Jb OP_J, b_mode
110 #define Jv OP_J, v_mode
112 #define ONE OP_ONE, 0
114 #define Cd OP_C, d_mode
115 #define Dd OP_D, d_mode
116 #define Td OP_T, d_mode
118 #define eAX OP_REG, eAX_reg
119 #define eBX OP_REG, eBX_reg
120 #define eCX OP_REG, eCX_reg
121 #define eDX OP_REG, eDX_reg
122 #define eSP OP_REG, eSP_reg
123 #define eBP OP_REG, eBP_reg
124 #define eSI OP_REG, eSI_reg
125 #define eDI OP_REG, eDI_reg
126 #define AL OP_REG, al_reg
127 #define CL OP_REG, cl_reg
128 #define DL OP_REG, dl_reg
129 #define BL OP_REG, bl_reg
130 #define AH OP_REG, ah_reg
131 #define CH OP_REG, ch_reg
132 #define DH OP_REG, dh_reg
133 #define BH OP_REG, bh_reg
134 #define AX OP_REG, ax_reg
135 #define DX OP_REG, dx_reg
136 #define indirDX OP_REG, indir_dx_reg
138 #define Sw OP_SEG, w_mode
139 #define Ap OP_DIR, lptr
140 #define Av OP_DIR, v_mode
141 #define Ob OP_OFF, b_mode
142 #define Ov OP_OFF, v_mode
143 #define Xb OP_DSreg, eSI_reg
144 #define Xv OP_DSreg, eSI_reg
145 #define Yb OP_ESreg, eDI_reg
146 #define Yv OP_ESreg, eDI_reg
147 #define DSBX OP_DSreg, eBX_reg
149 #define es OP_REG, es_reg
150 #define ss OP_REG, ss_reg
151 #define cs OP_REG, cs_reg
152 #define ds OP_REG, ds_reg
153 #define fs OP_REG, fs_reg
154 #define gs OP_REG, gs_reg
157 #define EM OP_EM, v_mode
158 #define MS OP_MS, b_mode
160 /* bits in sizeflag */
164 typedef void (*op_rtn) PARAMS ((int bytemode, int sizeflag));
166 static void OP_E PARAMS ((int, int));
167 static void OP_G PARAMS ((int, int));
168 static void OP_I PARAMS ((int, int));
169 static void OP_indirE PARAMS ((int, int));
170 static void OP_sI PARAMS ((int, int));
171 static void OP_REG PARAMS ((int, int));
172 static void OP_J PARAMS ((int, int));
173 static void OP_DIR PARAMS ((int, int));
174 static void OP_OFF PARAMS ((int, int));
175 static void OP_ESreg PARAMS ((int, int));
176 static void OP_DSreg PARAMS ((int, int));
177 static void OP_SEG PARAMS ((int, int));
178 static void OP_C PARAMS ((int, int));
179 static void OP_D PARAMS ((int, int));
180 static void OP_T PARAMS ((int, int));
181 static void OP_rm PARAMS ((int, int));
182 static void OP_ST PARAMS ((int, int));
183 static void OP_STi PARAMS ((int, int));
185 static void OP_ONE PARAMS ((int, int));
187 static void OP_MMX PARAMS ((int, int));
188 static void OP_EM PARAMS ((int, int));
189 static void OP_MS PARAMS ((int, int));
191 static void append_seg PARAMS ((void));
192 static void set_op PARAMS ((unsigned int op));
193 static void putop PARAMS ((char *template, int sizeflag));
194 static void dofloat PARAMS ((int sizeflag));
195 static int get16 PARAMS ((void));
196 static int get32 PARAMS ((void));
197 static void ckprefix PARAMS ((void));
198 static void ptr_reg PARAMS ((int, int));
240 #define indir_dx_reg 150
242 #define GRP1b NULL, NULL, 0
243 #define GRP1S NULL, NULL, 1
244 #define GRP1Ss NULL, NULL, 2
245 #define GRP2b NULL, NULL, 3
246 #define GRP2S NULL, NULL, 4
247 #define GRP2b_one NULL, NULL, 5
248 #define GRP2S_one NULL, NULL, 6
249 #define GRP2b_cl NULL, NULL, 7
250 #define GRP2S_cl NULL, NULL, 8
251 #define GRP3b NULL, NULL, 9
252 #define GRP3S NULL, NULL, 10
253 #define GRP4 NULL, NULL, 11
254 #define GRP5 NULL, NULL, 12
255 #define GRP6 NULL, NULL, 13
256 #define GRP7 NULL, NULL, 14
257 #define GRP8 NULL, NULL, 15
258 #define GRP9 NULL, NULL, 16
259 #define GRP10 NULL, NULL, 17
260 #define GRP11 NULL, NULL, 18
261 #define GRP12 NULL, NULL, 19
264 #define FLOAT NULL, NULL, FLOATCODE
276 static struct dis386 dis386[] = {
294 { "(bad)" }, /* 0x0f extended opcode escape */
320 { "(bad)" }, /* SEG ES prefix */
329 { "(bad)" }, /* SEG CS prefix */
338 { "(bad)" }, /* SEG SS prefix */
347 { "(bad)" }, /* SEG DS prefix */
388 { "boundS", Gv, Ma },
390 { "(bad)" }, /* seg fs */
391 { "(bad)" }, /* seg gs */
392 { "(bad)" }, /* op size prefix */
393 { "(bad)" }, /* adr size prefix */
395 { "pushS", Iv }, /* 386 book wrong */
396 { "imulS", Gv, Ev, Iv },
397 { "pushS", sIb }, /* push of byte really pushes 2 or 4 bytes */
398 { "imulS", Gv, Ev, Ib },
399 { "insb", Yb, indirDX },
400 { "insS", Yv, indirDX },
401 { "outsb", indirDX, Xb },
402 { "outsS", indirDX, Xv },
441 { "xchgS", eCX, eAX },
442 { "xchgS", eDX, eAX },
443 { "xchgS", eBX, eAX },
444 { "xchgS", eSP, eAX },
445 { "xchgS", eBP, eAX },
446 { "xchgS", eSI, eAX },
447 { "xchgS", eDI, eAX },
452 { "(bad)" }, /* fwait */
468 { "testS", eAX, Iv },
470 { "stosS", Yv, eAX },
472 { "lodsS", eAX, Xv },
474 { "scasS", eAX, Yv },
503 { "enterS", Iw, Ib },
543 { "inb", AL, indirDX },
544 { "inS", eAX, indirDX },
545 { "outb", indirDX, AL },
546 { "outS", indirDX, eAX },
548 { "(bad)" }, /* lock prefix */
550 { "(bad)" }, /* repne */
551 { "(bad)" }, /* repz */
567 static struct dis386 dis386_twobyte[] = {
580 { "(bad)" }, { "ud2a" },
581 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
583 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
584 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
586 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
587 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
589 /* these are all backward in appendix A of the intel book */
599 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
600 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
602 { "wrmsr" }, { "rdtsc" }, { "rdmsr" }, { "rdpmc" },
603 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
605 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
606 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
608 { "cmovo", Gv,Ev }, { "cmovno", Gv,Ev }, { "cmovb", Gv,Ev }, { "cmovae", Gv,Ev },
609 { "cmove", Gv,Ev }, { "cmovne", Gv,Ev }, { "cmovbe", Gv,Ev }, { "cmova", Gv,Ev },
611 { "cmovs", Gv,Ev }, { "cmovns", Gv,Ev }, { "cmovp", Gv,Ev }, { "cmovnp", Gv,Ev },
612 { "cmovl", Gv,Ev }, { "cmovge", Gv,Ev }, { "cmovle", Gv,Ev }, { "cmovg", Gv,Ev },
614 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
615 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
617 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
618 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
620 { "punpcklbw", MX, EM },
621 { "punpcklwd", MX, EM },
622 { "punpckldq", MX, EM },
623 { "packsswb", MX, EM },
624 { "pcmpgtb", MX, EM },
625 { "pcmpgtw", MX, EM },
626 { "pcmpgtd", MX, EM },
627 { "packuswb", MX, EM },
629 { "punpckhbw", MX, EM },
630 { "punpckhwd", MX, EM },
631 { "punpckhdq", MX, EM },
632 { "packssdw", MX, EM },
633 { "(bad)" }, { "(bad)" },
641 { "pcmpeqb", MX, EM },
642 { "pcmpeqw", MX, EM },
643 { "pcmpeqd", MX, EM },
646 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
647 { "(bad)" }, { "(bad)" },
691 { "shldS", Ev, Gv, Ib },
692 { "shldS", Ev, Gv, CL },
700 { "shrdS", Ev, Gv, Ib },
701 { "shrdS", Ev, Gv, CL },
705 { "cmpxchgb", Eb, Gb },
706 { "cmpxchgS", Ev, Gv },
707 { "lssS", Gv, Mp }, /* 386 lists only Mp */
709 { "lfsS", Gv, Mp }, /* 386 lists only Mp */
710 { "lgsS", Gv, Mp }, /* 386 lists only Mp */
711 { "movzbS", Gv, Eb },
712 { "movzwS", Gv, Ew },
720 { "movsbS", Gv, Eb },
721 { "movswS", Gv, Ew },
746 { "pmullw", MX, EM },
747 { "(bad)" }, { "(bad)" },
749 { "psubusb", MX, EM },
750 { "psubusw", MX, EM },
753 { "paddusb", MX, EM },
754 { "paddusw", MX, EM },
763 { "pmulhw", MX, EM },
764 { "(bad)" }, { "(bad)" },
766 { "psubsb", MX, EM },
767 { "psubsw", MX, EM },
770 { "paddsb", MX, EM },
771 { "paddsw", MX, EM },
780 { "pmaddwd", MX, EM },
781 { "(bad)" }, { "(bad)" },
793 static const unsigned char onebyte_has_modrm[256] = {
794 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
795 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
796 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
797 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
798 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
799 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
800 0,0,1,1,0,0,0,0,0,1,0,1,0,0,0,0,
801 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
802 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
803 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
804 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
805 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
806 1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,
807 1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,
808 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
809 0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1
812 static const unsigned char twobyte_has_modrm[256] = {
813 /* 00 */ 1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0, /* 0f */
814 /* 10 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 1f */
815 /* 20 */ 1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, /* 2f */
816 /* 30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 3f */
817 /* 40 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 4f */
818 /* 50 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 5f */
819 /* 60 */ 1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1, /* 6f */
820 /* 70 */ 0,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1, /* 7f */
821 /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */
822 /* 90 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 9f */
823 /* a0 */ 0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1, /* af */
824 /* b0 */ 1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1, /* bf */
825 /* c0 */ 1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, /* cf */
826 /* d0 */ 0,1,1,1,0,1,0,0,1,1,0,1,1,1,0,1, /* df */
827 /* e0 */ 0,1,1,0,0,1,0,0,1,1,0,1,1,1,0,1, /* ef */
828 /* f0 */ 0,1,1,1,0,1,0,0,1,1,1,0,1,1,1,0 /* ff */
831 static char obuf[100];
833 static char scratchbuf[100];
834 static unsigned char *start_codep;
835 static unsigned char *codep;
836 static disassemble_info *the_info;
840 static void oappend PARAMS ((char *s));
842 static char *names32[]={
843 "%eax","%ecx","%edx","%ebx", "%esp","%ebp","%esi","%edi",
845 static char *names16[] = {
846 "%ax","%cx","%dx","%bx","%sp","%bp","%si","%di",
848 static char *names8[] = {
849 "%al","%cl","%dl","%bl","%ah","%ch","%dh","%bh",
851 static char *names_seg[] = {
852 "%es","%cs","%ss","%ds","%fs","%gs","%?","%?",
854 static char *index16[] = {
855 "bx+si","bx+di","bp+si","bp+di","si","di","bp","bx"
858 static struct dis386 grps[][8] = {
976 { "imulS", eAX, Ev },
978 { "idivS", eAX, Ev },
996 { "lcall", indirEv },
1038 { "cmpxchg8b", Ev },
1050 { "psrlw", MS, Ib },
1052 { "psraw", MS, Ib },
1054 { "psllw", MS, Ib },
1061 { "psrld", MS, Ib },
1063 { "psrad", MS, Ib },
1065 { "pslld", MS, Ib },
1072 { "psrlq", MS, Ib },
1076 { "psllq", MS, Ib },
1081 #define PREFIX_REPZ 1
1082 #define PREFIX_REPNZ 2
1083 #define PREFIX_LOCK 4
1085 #define PREFIX_SS 0x10
1086 #define PREFIX_DS 0x20
1087 #define PREFIX_ES 0x40
1088 #define PREFIX_FS 0x80
1089 #define PREFIX_GS 0x100
1090 #define PREFIX_DATA 0x200
1091 #define PREFIX_ADDR 0x400
1092 #define PREFIX_FWAIT 0x800
1094 static int prefixes;
1102 FETCH_DATA (the_info, codep + 1);
1106 prefixes |= PREFIX_REPZ;
1109 prefixes |= PREFIX_REPNZ;
1112 prefixes |= PREFIX_LOCK;
1115 prefixes |= PREFIX_CS;
1118 prefixes |= PREFIX_SS;
1121 prefixes |= PREFIX_DS;
1124 prefixes |= PREFIX_ES;
1127 prefixes |= PREFIX_FS;
1130 prefixes |= PREFIX_GS;
1133 prefixes |= PREFIX_DATA;
1136 prefixes |= PREFIX_ADDR;
1139 prefixes |= PREFIX_FWAIT;
1148 static char op1out[100], op2out[100], op3out[100];
1149 static int op_ad, op_index[3];
1150 static unsigned int op_address[3];
1151 static unsigned int start_pc;
1155 * On the 386's of 1988, the maximum length of an instruction is 15 bytes.
1156 * (see topic "Redundant prefixes" in the "Differences from 8086"
1157 * section of the "Virtual 8086 Mode" chapter.)
1158 * 'pc' should be the address of this instruction, it will
1159 * be used to print the target address if this is a relative jump or call
1160 * The function returns the length of this instruction in bytes.
1163 int print_insn_x86 PARAMS ((bfd_vma pc, disassemble_info *info, int sizeflag));
1165 print_insn_i386 (pc, info)
1167 disassemble_info *info;
1169 if (info->mach == bfd_mach_i386_i386)
1170 return print_insn_x86 (pc, info, AFLAG|DFLAG);
1171 else if (info->mach == bfd_mach_i386_i8086)
1172 return print_insn_x86 (pc, info, 0);
1178 print_insn_x86 (pc, info, sizeflag)
1180 disassemble_info *info;
1185 int enter_instruction;
1186 char *first, *second, *third;
1188 unsigned char need_modrm;
1190 struct dis_private priv;
1191 bfd_byte *inbuf = priv.the_buffer;
1193 /* The output looks better if we put 5 bytes on a line, since that
1194 puts long word instructions on a single line. */
1195 info->bytes_per_line = 5;
1197 info->private_data = (PTR) &priv;
1198 priv.max_fetched = priv.the_buffer;
1199 priv.insn_start = pc;
1200 if (setjmp (priv.bailout) != 0)
1209 op_index[0] = op_index[1] = op_index[2] = -1;
1213 start_codep = inbuf;
1218 FETCH_DATA (info, codep + 1);
1220 enter_instruction = 1;
1222 enter_instruction = 0;
1226 if (prefixes & PREFIX_REPZ)
1228 if (prefixes & PREFIX_REPNZ)
1230 if (prefixes & PREFIX_LOCK)
1233 if ((prefixes & PREFIX_FWAIT)
1234 && ((*codep < 0xd8) || (*codep > 0xdf)))
1236 /* fwait not followed by floating point instruction */
1237 (*info->fprintf_func) (info->stream, "fwait");
1241 if (prefixes & PREFIX_DATA)
1244 if (prefixes & PREFIX_ADDR)
1247 if (sizeflag & AFLAG)
1248 oappend ("addr32 ");
1250 oappend ("addr16 ");
1255 FETCH_DATA (info, codep + 2);
1256 dp = &dis386_twobyte[*++codep];
1257 need_modrm = twobyte_has_modrm[*codep];
1261 dp = &dis386[*codep];
1262 need_modrm = onebyte_has_modrm[*codep];
1268 FETCH_DATA (info, codep + 1);
1269 mod = (*codep >> 6) & 3;
1270 reg = (*codep >> 3) & 7;
1274 if (dp->name == NULL && dp->bytemode1 == FLOATCODE)
1280 if (dp->name == NULL)
1281 dp = &grps[dp->bytemode1][reg];
1283 putop (dp->name, sizeflag);
1288 (*dp->op1)(dp->bytemode1, sizeflag);
1293 (*dp->op2)(dp->bytemode2, sizeflag);
1298 (*dp->op3)(dp->bytemode3, sizeflag);
1301 obufp = obuf + strlen (obuf);
1302 for (i = strlen (obuf); i < 6; i++)
1305 (*info->fprintf_func) (info->stream, "%s", obuf);
1307 /* enter instruction is printed with operands in the
1308 * same order as the intel book; everything else
1309 * is printed in reverse order
1311 if (enter_instruction)
1316 op_ad = op_index[0];
1317 op_index[0] = op_index[2];
1318 op_index[2] = op_ad;
1329 if (op_index[0] != -1)
1330 (*info->print_address_func) ((bfd_vma) op_address[op_index[0]], info);
1332 (*info->fprintf_func) (info->stream, "%s", first);
1338 (*info->fprintf_func) (info->stream, ",");
1339 if (op_index[1] != -1)
1340 (*info->print_address_func) ((bfd_vma) op_address[op_index[1]], info);
1342 (*info->fprintf_func) (info->stream, "%s", second);
1348 (*info->fprintf_func) (info->stream, ",");
1349 if (op_index[2] != -1)
1350 (*info->print_address_func) ((bfd_vma) op_address[op_index[2]], info);
1352 (*info->fprintf_func) (info->stream, "%s", third);
1354 return codep - inbuf;
1357 static char *float_mem[] = {
1433 #define STi OP_STi, 0
1435 #define FGRPd9_2 NULL, NULL, 0
1436 #define FGRPd9_4 NULL, NULL, 1
1437 #define FGRPd9_5 NULL, NULL, 2
1438 #define FGRPd9_6 NULL, NULL, 3
1439 #define FGRPd9_7 NULL, NULL, 4
1440 #define FGRPda_5 NULL, NULL, 5
1441 #define FGRPdb_4 NULL, NULL, 6
1442 #define FGRPde_3 NULL, NULL, 7
1443 #define FGRPdf_4 NULL, NULL, 8
1445 static struct dis386 float_reg[][8] = {
1448 { "fadd", ST, STi },
1449 { "fmul", ST, STi },
1452 { "fsub", ST, STi },
1453 { "fsubr", ST, STi },
1454 { "fdiv", ST, STi },
1455 { "fdivr", ST, STi },
1470 { "fcmovb", ST, STi },
1471 { "fcmove", ST, STi },
1472 { "fcmovbe",ST, STi },
1473 { "fcmovu", ST, STi },
1481 { "fcmovnb",ST, STi },
1482 { "fcmovne",ST, STi },
1483 { "fcmovnbe",ST, STi },
1484 { "fcmovnu",ST, STi },
1486 { "fucomi", ST, STi },
1487 { "fcomi", ST, STi },
1492 { "fadd", STi, ST },
1493 { "fmul", STi, ST },
1497 { "fsub", STi, ST },
1498 { "fsubr", STi, ST },
1499 { "fdiv", STi, ST },
1500 { "fdivr", STi, ST },
1502 { "fsubr", STi, ST },
1503 { "fsub", STi, ST },
1504 { "fdivr", STi, ST },
1505 { "fdiv", STi, ST },
1521 { "faddp", STi, ST },
1522 { "fmulp", STi, ST },
1526 { "fsubp", STi, ST },
1527 { "fsubrp", STi, ST },
1528 { "fdivp", STi, ST },
1529 { "fdivrp", STi, ST },
1531 { "fsubrp", STi, ST },
1532 { "fsubp", STi, ST },
1533 { "fdivrp", STi, ST },
1534 { "fdivp", STi, ST },
1544 { "fucomip",ST, STi },
1545 { "fcomip", ST, STi },
1551 static char *fgrps[][8] = {
1554 "fnop","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
1559 "fchs","fabs","(bad)","(bad)","ftst","fxam","(bad)","(bad)",
1564 "fld1","fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz","(bad)",
1569 "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp","fincstp",
1574 "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos",
1579 "(bad)","fucompp","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
1584 "feni(287 only)","fdisi(287 only)","fNclex","fNinit",
1585 "fNsetpm(287 only)","(bad)","(bad)","(bad)",
1590 "(bad)","fcompp","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
1595 "fNstsw","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
1604 unsigned char floatop;
1606 floatop = codep[-1];
1610 putop (float_mem[(floatop - 0xd8) * 8 + reg], sizeflag);
1612 OP_E (v_mode, sizeflag);
1617 dp = &float_reg[floatop - 0xd8][reg];
1618 if (dp->name == NULL)
1620 putop (fgrps[dp->bytemode1][rm], sizeflag);
1621 /* instruction fnstsw is only one with strange arg */
1623 && FETCH_DATA (the_info, codep + 1)
1625 strcpy (op1out, "%eax");
1629 putop (dp->name, sizeflag);
1632 (*dp->op1)(dp->bytemode1, sizeflag);
1635 (*dp->op2)(dp->bytemode2, sizeflag);
1641 OP_ST (ignore, sizeflag)
1650 OP_STi (ignore, sizeflag)
1654 sprintf (scratchbuf, "%%st(%d)", rm);
1655 oappend (scratchbuf);
1659 /* capital letters in template are macros */
1661 putop (template, sizeflag)
1667 for (p = template; *p; p++)
1674 case 'C': /* For jcxz/jecxz */
1675 if (sizeflag & AFLAG)
1679 if ((prefixes & PREFIX_FWAIT) == 0)
1683 /* operand size flag */
1684 if (sizeflag & DFLAG)
1690 /* operand size flag for cwtl, cbtw */
1691 if (sizeflag & DFLAG)
1706 obufp += strlen (s);
1712 if (prefixes & PREFIX_CS)
1714 if (prefixes & PREFIX_DS)
1716 if (prefixes & PREFIX_SS)
1718 if (prefixes & PREFIX_ES)
1720 if (prefixes & PREFIX_FS)
1722 if (prefixes & PREFIX_GS)
1727 OP_indirE (bytemode, sizeflag)
1732 OP_E (bytemode, sizeflag);
1736 OP_E (bytemode, sizeflag)
1742 /* skip mod/rm byte */
1750 oappend (names8[rm]);
1753 oappend (names16[rm]);
1756 if (sizeflag & DFLAG)
1757 oappend (names32[rm]);
1759 oappend (names16[rm]);
1762 oappend ("<bad dis table>");
1771 if (sizeflag & AFLAG) /* 32 bit address mode */
1786 FETCH_DATA (the_info, codep + 1);
1787 scale = (*codep >> 6) & 3;
1788 index = (*codep >> 3) & 7;
1803 FETCH_DATA (the_info, codep + 1);
1805 if ((disp & 0x80) != 0)
1813 if (mod != 0 || base == 5)
1815 sprintf (scratchbuf, "0x%x", disp);
1816 oappend (scratchbuf);
1819 if (havebase || (havesib && (index != 4 || scale != 0)))
1823 oappend (names32[base]);
1828 sprintf (scratchbuf, ",%s", names32[index]);
1829 oappend (scratchbuf);
1831 sprintf (scratchbuf, ",%d", 1 << scale);
1832 oappend (scratchbuf);
1838 { /* 16 bit address mode */
1845 if ((disp & 0x8000) != 0)
1850 FETCH_DATA (the_info, codep + 1);
1852 if ((disp & 0x80) != 0)
1857 if ((disp & 0x8000) != 0)
1862 if (mod != 0 || rm == 6)
1864 sprintf (scratchbuf, "0x%x", disp);
1865 oappend (scratchbuf);
1868 if (mod != 0 || rm != 6)
1871 oappend (index16[rm]);
1877 #define INTERNAL_DISASSEMBLER_ERROR _("<internal disassembler error>")
1880 OP_G (bytemode, sizeflag)
1887 oappend (names8[reg]);
1890 oappend (names16[reg]);
1893 oappend (names32[reg]);
1896 if (sizeflag & DFLAG)
1897 oappend (names32[reg]);
1899 oappend (names16[reg]);
1902 oappend (INTERNAL_DISASSEMBLER_ERROR);
1912 FETCH_DATA (the_info, codep + 4);
1913 x = *codep++ & 0xff;
1914 x |= (*codep++ & 0xff) << 8;
1915 x |= (*codep++ & 0xff) << 16;
1916 x |= (*codep++ & 0xff) << 24;
1925 FETCH_DATA (the_info, codep + 2);
1926 x = *codep++ & 0xff;
1927 x |= (*codep++ & 0xff) << 8;
1935 op_index[op_ad] = op_ad;
1936 op_address[op_ad] = op;
1940 OP_REG (code, sizeflag)
1948 case indir_dx_reg: s = "(%dx)"; break;
1949 case ax_reg: case cx_reg: case dx_reg: case bx_reg:
1950 case sp_reg: case bp_reg: case si_reg: case di_reg:
1951 s = names16[code - ax_reg];
1953 case es_reg: case ss_reg: case cs_reg:
1954 case ds_reg: case fs_reg: case gs_reg:
1955 s = names_seg[code - es_reg];
1957 case al_reg: case ah_reg: case cl_reg: case ch_reg:
1958 case dl_reg: case dh_reg: case bl_reg: case bh_reg:
1959 s = names8[code - al_reg];
1961 case eAX_reg: case eCX_reg: case eDX_reg: case eBX_reg:
1962 case eSP_reg: case eBP_reg: case eSI_reg: case eDI_reg:
1963 if (sizeflag & DFLAG)
1964 s = names32[code - eAX_reg];
1966 s = names16[code - eAX_reg];
1969 s = INTERNAL_DISASSEMBLER_ERROR;
1976 OP_I (bytemode, sizeflag)
1985 FETCH_DATA (the_info, codep + 1);
1986 op = *codep++ & 0xff;
1989 if (sizeflag & DFLAG)
1998 oappend (INTERNAL_DISASSEMBLER_ERROR);
2001 sprintf (scratchbuf, "$0x%x", op);
2002 oappend (scratchbuf);
2006 OP_sI (bytemode, sizeflag)
2015 FETCH_DATA (the_info, codep + 1);
2017 if ((op & 0x80) != 0)
2021 if (sizeflag & DFLAG)
2026 if ((op & 0x8000) != 0)
2032 if ((op & 0x8000) != 0)
2036 oappend (INTERNAL_DISASSEMBLER_ERROR);
2039 sprintf (scratchbuf, "$0x%x", op);
2040 oappend (scratchbuf);
2044 OP_J (bytemode, sizeflag)
2054 FETCH_DATA (the_info, codep + 1);
2056 if ((disp & 0x80) != 0)
2060 if (sizeflag & DFLAG)
2065 if ((disp & 0x8000) != 0)
2067 /* for some reason, a data16 prefix on a jump instruction
2068 means that the pc is masked to 16 bits after the
2069 displacement is added! */
2074 oappend (INTERNAL_DISASSEMBLER_ERROR);
2077 disp = (start_pc + codep - start_codep + disp) & mask;
2079 sprintf (scratchbuf, "0x%x", disp);
2080 oappend (scratchbuf);
2085 OP_SEG (dummy, sizeflag)
2089 static char *sreg[] = {
2090 "%es","%cs","%ss","%ds","%fs","%gs","%?","%?",
2093 oappend (sreg[reg]);
2097 OP_DIR (size, sizeflag)
2106 if (sizeflag & DFLAG)
2116 sprintf (scratchbuf, "0x%x,0x%x", seg, offset);
2117 oappend (scratchbuf);
2120 if (sizeflag & DFLAG)
2125 if ((offset & 0x8000) != 0)
2129 offset = start_pc + codep - start_codep + offset;
2131 sprintf (scratchbuf, "0x%x", offset);
2132 oappend (scratchbuf);
2135 oappend (INTERNAL_DISASSEMBLER_ERROR);
2142 OP_OFF (ignore, sizeflag)
2150 if (sizeflag & AFLAG)
2155 sprintf (scratchbuf, "0x%x", off);
2156 oappend (scratchbuf);
2160 ptr_reg (code, sizeflag)
2166 if (sizeflag & AFLAG)
2167 s = names32[code - eAX_reg];
2169 s = names16[code - eAX_reg];
2175 OP_ESreg (code, sizeflag)
2180 ptr_reg (code, sizeflag);
2184 OP_DSreg (code, sizeflag)
2195 prefixes |= PREFIX_DS;
2197 ptr_reg (code, sizeflag);
2205 OP_ONE (dummy, sizeflag)
2216 OP_C (dummy, sizeflag)
2220 codep++; /* skip mod/rm */
2221 sprintf (scratchbuf, "%%cr%d", reg);
2222 oappend (scratchbuf);
2227 OP_D (dummy, sizeflag)
2231 codep++; /* skip mod/rm */
2232 sprintf (scratchbuf, "%%db%d", reg);
2233 oappend (scratchbuf);
2238 OP_T (dummy, sizeflag)
2242 codep++; /* skip mod/rm */
2243 sprintf (scratchbuf, "%%tr%d", reg);
2244 oappend (scratchbuf);
2248 OP_rm (bytemode, sizeflag)
2255 oappend (names32[rm]);
2258 oappend (names16[rm]);
2264 OP_MMX (ignore, sizeflag)
2268 sprintf (scratchbuf, "%%mm%d", reg);
2269 oappend (scratchbuf);
2273 OP_EM (bytemode, sizeflag)
2279 OP_E (bytemode, sizeflag);
2284 sprintf (scratchbuf, "%%mm%d", rm);
2285 oappend (scratchbuf);
2289 OP_MS (ignore, sizeflag)
2294 sprintf (scratchbuf, "%%mm%d", rm);
2295 oappend (scratchbuf);