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. */
22 * 80386 instruction printer by Pace Willisson (pace@prep.ai.mit.edu)
24 * modified by John Hassey (hassey@dg-rtp.dg.com)
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 */
161 #if 0 /* leave undefined until someone adds the extra flag to objdump */
162 #define SUFFIX_ALWAYS 4
167 typedef void (*op_rtn) PARAMS ((int bytemode, int sizeflag));
169 static void OP_E PARAMS ((int, int));
170 static void OP_G PARAMS ((int, int));
171 static void OP_I PARAMS ((int, int));
172 static void OP_indirE PARAMS ((int, int));
173 static void OP_sI PARAMS ((int, int));
174 static void OP_REG PARAMS ((int, int));
175 static void OP_J PARAMS ((int, int));
176 static void OP_DIR PARAMS ((int, int));
177 static void OP_OFF PARAMS ((int, int));
178 static void OP_ESreg PARAMS ((int, int));
179 static void OP_DSreg PARAMS ((int, int));
180 static void OP_SEG PARAMS ((int, int));
181 static void OP_C PARAMS ((int, int));
182 static void OP_D PARAMS ((int, int));
183 static void OP_T PARAMS ((int, int));
184 static void OP_rm PARAMS ((int, int));
185 static void OP_ST PARAMS ((int, int));
186 static void OP_STi PARAMS ((int, int));
188 static void OP_ONE PARAMS ((int, int));
190 static void OP_MMX PARAMS ((int, int));
191 static void OP_EM PARAMS ((int, int));
192 static void OP_MS PARAMS ((int, int));
194 static void append_seg PARAMS ((void));
195 static void set_op PARAMS ((unsigned int op));
196 static void putop PARAMS ((char *template, int sizeflag));
197 static void dofloat PARAMS ((int sizeflag));
198 static int get16 PARAMS ((void));
199 static int get32 PARAMS ((void));
200 static void ckprefix PARAMS ((void));
201 static void ptr_reg PARAMS ((int, int));
243 #define indir_dx_reg 150
245 #define GRP1b NULL, NULL, 0
246 #define GRP1S NULL, NULL, 1
247 #define GRP1Ss NULL, NULL, 2
248 #define GRP2b NULL, NULL, 3
249 #define GRP2S NULL, NULL, 4
250 #define GRP2b_one NULL, NULL, 5
251 #define GRP2S_one NULL, NULL, 6
252 #define GRP2b_cl NULL, NULL, 7
253 #define GRP2S_cl NULL, NULL, 8
254 #define GRP3b NULL, NULL, 9
255 #define GRP3S NULL, NULL, 10
256 #define GRP4 NULL, NULL, 11
257 #define GRP5 NULL, NULL, 12
258 #define GRP6 NULL, NULL, 13
259 #define GRP7 NULL, NULL, 14
260 #define GRP8 NULL, NULL, 15
261 #define GRP9 NULL, NULL, 16
262 #define GRP10 NULL, NULL, 17
263 #define GRP11 NULL, NULL, 18
264 #define GRP12 NULL, NULL, 19
267 #define FLOAT NULL, NULL, FLOATCODE
279 /* Upper case letters in the instruction names here are macros.
280 'A' => print 'b' if no register operands or suffix_always is true
281 'B' => print 'b' if suffix_always is true
282 'E' => print 'e' if 32-bit form of jcxz
283 'L' => print 'l' if suffix_always is true
284 'N' => print 'n' if instruction has no wait "prefix"
285 'P' => print 'w' or 'l' if instruction has an operand size prefix,
286 or suffix_always is true
287 'Q' => print 'w' or 'l' if no register operands or suffix_always is true
288 'R' => print 'w' or 'l'
289 'S' => print 'w' or 'l' if suffix_always is true
290 'W' => print 'b' or 'w'
293 static struct dis386 dis386[] = {
311 { "(bad)" }, /* 0x0f extended opcode escape */
337 { "(bad)" }, /* SEG ES prefix */
346 { "(bad)" }, /* SEG CS prefix */
355 { "(bad)" }, /* SEG SS prefix */
364 { "(bad)" }, /* SEG DS prefix */
405 { "boundS", Gv, Ma },
407 { "(bad)" }, /* seg fs */
408 { "(bad)" }, /* seg gs */
409 { "(bad)" }, /* op size prefix */
410 { "(bad)" }, /* adr size prefix */
412 { "pushP", Iv }, /* 386 book wrong */
413 { "imulS", Gv, Ev, Iv },
414 { "pushP", sIb }, /* push of byte really pushes 2 or 4 bytes */
415 { "imulS", Gv, Ev, sIb },
416 { "insb", Yb, indirDX },
417 { "insR", Yv, indirDX },
418 { "outsb", indirDX, Xb },
419 { "outsR", indirDX, Xv },
458 { "xchgS", eCX, eAX },
459 { "xchgS", eDX, eAX },
460 { "xchgS", eBX, eAX },
461 { "xchgS", eSP, eAX },
462 { "xchgS", eBP, eAX },
463 { "xchgS", eSI, eAX },
464 { "xchgS", eDI, eAX },
469 { "(bad)" }, /* fwait */
485 { "testS", eAX, Iv },
487 { "stosS", Yv, eAX },
489 { "lodsS", eAX, Xv },
491 { "scasS", eAX, Yv },
520 { "enterP", Iw, Ib },
560 { "inB", AL, indirDX },
561 { "inS", eAX, indirDX },
562 { "outB", indirDX, AL },
563 { "outS", indirDX, eAX },
565 { "(bad)" }, /* lock prefix */
567 { "(bad)" }, /* repne */
568 { "(bad)" }, /* repz */
584 static struct dis386 dis386_twobyte[] = {
599 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
601 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
602 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
604 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
605 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
607 /* these are all backward in appendix A of the intel book */
617 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
618 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
620 { "wrmsr" }, { "rdtsc" }, { "rdmsr" }, { "rdpmc" },
621 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
623 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
624 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
626 { "cmovo", Gv,Ev }, { "cmovno", Gv,Ev }, { "cmovb", Gv,Ev }, { "cmovae", Gv,Ev },
627 { "cmove", Gv,Ev }, { "cmovne", Gv,Ev }, { "cmovbe", Gv,Ev }, { "cmova", Gv,Ev },
629 { "cmovs", Gv,Ev }, { "cmovns", Gv,Ev }, { "cmovp", Gv,Ev }, { "cmovnp", Gv,Ev },
630 { "cmovl", Gv,Ev }, { "cmovge", Gv,Ev }, { "cmovle", Gv,Ev }, { "cmovg", Gv,Ev },
632 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
633 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
635 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
636 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
638 { "punpcklbw", MX, EM },
639 { "punpcklwd", MX, EM },
640 { "punpckldq", MX, EM },
641 { "packsswb", MX, EM },
642 { "pcmpgtb", MX, EM },
643 { "pcmpgtw", MX, EM },
644 { "pcmpgtd", MX, EM },
645 { "packuswb", MX, EM },
647 { "punpckhbw", MX, EM },
648 { "punpckhwd", MX, EM },
649 { "punpckhdq", MX, EM },
650 { "packssdw", MX, EM },
651 { "(bad)" }, { "(bad)" },
659 { "pcmpeqb", MX, EM },
660 { "pcmpeqw", MX, EM },
661 { "pcmpeqd", MX, EM },
664 { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" },
665 { "(bad)" }, { "(bad)" },
709 { "shldS", Ev, Gv, Ib },
710 { "shldS", Ev, Gv, CL },
718 { "shrdS", Ev, Gv, Ib },
719 { "shrdS", Ev, Gv, CL },
723 { "cmpxchgB", Eb, Gb },
724 { "cmpxchgS", Ev, Gv },
725 { "lssS", Gv, Mp }, /* 386 lists only Mp */
727 { "lfsS", Gv, Mp }, /* 386 lists only Mp */
728 { "lgsS", Gv, Mp }, /* 386 lists only Mp */
729 { "movzbR", Gv, Eb },
730 { "movzwR", Gv, Ew }, /* yes, there really is movzww ! */
738 { "movsbR", Gv, Eb },
739 { "movswR", Gv, Ew }, /* yes, there really is movsww ! */
750 { "bswap", eAX }, /* bswap doesn't support 16 bit regs */
764 { "pmullw", MX, EM },
765 { "(bad)" }, { "(bad)" },
767 { "psubusb", MX, EM },
768 { "psubusw", MX, EM },
771 { "paddusb", MX, EM },
772 { "paddusw", MX, EM },
781 { "pmulhw", MX, EM },
782 { "(bad)" }, { "(bad)" },
784 { "psubsb", MX, EM },
785 { "psubsw", MX, EM },
788 { "paddsb", MX, EM },
789 { "paddsw", MX, EM },
798 { "pmaddwd", MX, EM },
799 { "(bad)" }, { "(bad)" },
811 static const unsigned char onebyte_has_modrm[256] = {
812 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
813 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
814 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
815 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
816 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
817 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
818 0,0,1,1,0,0,0,0,0,1,0,1,0,0,0,0,
819 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
820 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
821 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
822 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
823 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
824 1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,
825 1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,
826 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
827 0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1
830 static const unsigned char twobyte_has_modrm[256] = {
831 /* 00 */ 1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0, /* 0f */
832 /* 10 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 1f */
833 /* 20 */ 1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, /* 2f */
834 /* 30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 3f */
835 /* 40 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 4f */
836 /* 50 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 5f */
837 /* 60 */ 1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1, /* 6f */
838 /* 70 */ 0,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1, /* 7f */
839 /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */
840 /* 90 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 9f */
841 /* a0 */ 0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1, /* af */
842 /* b0 */ 1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1, /* bf */
843 /* c0 */ 1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, /* cf */
844 /* d0 */ 0,1,1,1,0,1,0,0,1,1,0,1,1,1,0,1, /* df */
845 /* e0 */ 0,1,1,0,0,1,0,0,1,1,0,1,1,1,0,1, /* ef */
846 /* f0 */ 0,1,1,1,0,1,0,0,1,1,1,0,1,1,1,0 /* ff */
849 static char obuf[100];
851 static char scratchbuf[100];
852 static unsigned char *start_codep;
853 static unsigned char *codep;
854 static disassemble_info *the_info;
858 static void oappend PARAMS ((char *s));
860 static char *names32[]={
861 "%eax","%ecx","%edx","%ebx", "%esp","%ebp","%esi","%edi",
863 static char *names16[] = {
864 "%ax","%cx","%dx","%bx","%sp","%bp","%si","%di",
866 static char *names8[] = {
867 "%al","%cl","%dl","%bl","%ah","%ch","%dh","%bh",
869 static char *names_seg[] = {
870 "%es","%cs","%ss","%ds","%fs","%gs","%?","%?",
872 static char *index16[] = {
873 "bx+si","bx+di","bp+si","bp+di","si","di","bp","bx"
876 static struct dis386 grps[][8] = {
994 { "imulS", eAX, Ev },
996 { "idivS", eAX, Ev },
1013 { "callP", indirEv },
1014 { "lcallP", indirEv },
1015 { "jmpP", indirEv },
1016 { "ljmpP", indirEv },
1056 { "cmpxchg8b", Ev },
1068 { "psrlw", MS, Ib },
1070 { "psraw", MS, Ib },
1072 { "psllw", MS, Ib },
1079 { "psrld", MS, Ib },
1081 { "psrad", MS, Ib },
1083 { "pslld", MS, Ib },
1090 { "psrlq", MS, Ib },
1094 { "psllq", MS, Ib },
1099 #define PREFIX_REPZ 1
1100 #define PREFIX_REPNZ 2
1101 #define PREFIX_LOCK 4
1103 #define PREFIX_SS 0x10
1104 #define PREFIX_DS 0x20
1105 #define PREFIX_ES 0x40
1106 #define PREFIX_FS 0x80
1107 #define PREFIX_GS 0x100
1108 #define PREFIX_DATA 0x200
1109 #define PREFIX_ADDR 0x400
1110 #define PREFIX_FWAIT 0x800
1112 static int prefixes;
1120 FETCH_DATA (the_info, codep + 1);
1124 prefixes |= PREFIX_REPZ;
1127 prefixes |= PREFIX_REPNZ;
1130 prefixes |= PREFIX_LOCK;
1133 prefixes |= PREFIX_CS;
1136 prefixes |= PREFIX_SS;
1139 prefixes |= PREFIX_DS;
1142 prefixes |= PREFIX_ES;
1145 prefixes |= PREFIX_FS;
1148 prefixes |= PREFIX_GS;
1151 prefixes |= PREFIX_DATA;
1154 prefixes |= PREFIX_ADDR;
1157 prefixes |= PREFIX_FWAIT;
1158 codep++; /* fwait is really an instruction */
1159 return; /* so stop accumulating prefixes */
1167 static char op1out[100], op2out[100], op3out[100];
1168 static int op_ad, op_index[3];
1169 static unsigned int op_address[3];
1170 static unsigned int start_pc;
1174 * On the 386's of 1988, the maximum length of an instruction is 15 bytes.
1175 * (see topic "Redundant prefixes" in the "Differences from 8086"
1176 * section of the "Virtual 8086 Mode" chapter.)
1177 * 'pc' should be the address of this instruction, it will
1178 * be used to print the target address if this is a relative jump or call
1179 * The function returns the length of this instruction in bytes.
1182 int print_insn_x86 PARAMS ((bfd_vma pc, disassemble_info *info, int sizeflag));
1185 print_insn_i386 (pc, info)
1187 disassemble_info *info;
1190 if (info->mach == bfd_mach_i386_i386)
1191 flags = AFLAG|DFLAG;
1192 else if (info->mach == bfd_mach_i386_i8086)
1196 return print_insn_x86 (pc, info, flags);
1200 print_insn_x86 (pc, info, sizeflag)
1202 disassemble_info *info;
1208 char *first, *second, *third;
1210 unsigned char need_modrm;
1212 struct dis_private priv;
1213 bfd_byte *inbuf = priv.the_buffer;
1215 /* The output looks better if we put 5 bytes on a line, since that
1216 puts long word instructions on a single line. */
1217 info->bytes_per_line = 5;
1219 info->private_data = (PTR) &priv;
1220 priv.max_fetched = priv.the_buffer;
1221 priv.insn_start = pc;
1222 if (setjmp (priv.bailout) != 0)
1231 op_index[0] = op_index[1] = op_index[2] = -1;
1235 start_codep = inbuf;
1240 FETCH_DATA (info, codep + 1);
1241 two_source_ops = (*codep == 0x62) || (*codep == 0xc8);
1245 if ((prefixes & PREFIX_FWAIT)
1246 && ((*codep < 0xd8) || (*codep > 0xdf)))
1248 /* fwait not followed by floating point instruction. */
1249 (*info->fprintf_func) (info->stream, "fwait");
1250 /* There may be other prefixes. Skip any before the fwait. */
1251 return codep - inbuf;
1254 if (prefixes & PREFIX_REPZ)
1256 if (prefixes & PREFIX_REPNZ)
1258 if (prefixes & PREFIX_LOCK)
1261 if (prefixes & PREFIX_DATA)
1264 if (prefixes & PREFIX_ADDR)
1267 if (sizeflag & AFLAG)
1268 oappend ("addr32 ");
1270 oappend ("addr16 ");
1275 FETCH_DATA (info, codep + 2);
1276 dp = &dis386_twobyte[*++codep];
1277 need_modrm = twobyte_has_modrm[*codep];
1281 dp = &dis386[*codep];
1282 need_modrm = onebyte_has_modrm[*codep];
1288 FETCH_DATA (info, codep + 1);
1289 mod = (*codep >> 6) & 3;
1290 reg = (*codep >> 3) & 7;
1294 if (dp->name == NULL && dp->bytemode1 == FLOATCODE)
1300 if (dp->name == NULL)
1301 dp = &grps[dp->bytemode1][reg];
1303 putop (dp->name, sizeflag);
1308 (*dp->op1)(dp->bytemode1, sizeflag);
1313 (*dp->op2)(dp->bytemode2, sizeflag);
1318 (*dp->op3)(dp->bytemode3, sizeflag);
1321 obufp = obuf + strlen (obuf);
1322 for (i = strlen (obuf); i < 6; i++)
1325 (*info->fprintf_func) (info->stream, "%s", obuf);
1327 /* The enter and bound instructions are printed with operands in the same
1328 order as the intel book; everything else is printed in reverse order. */
1334 op_ad = op_index[0];
1335 op_index[0] = op_index[2];
1336 op_index[2] = op_ad;
1347 if (op_index[0] != -1)
1348 (*info->print_address_func) ((bfd_vma) op_address[op_index[0]], info);
1350 (*info->fprintf_func) (info->stream, "%s", first);
1356 (*info->fprintf_func) (info->stream, ",");
1357 if (op_index[1] != -1)
1358 (*info->print_address_func) ((bfd_vma) op_address[op_index[1]], info);
1360 (*info->fprintf_func) (info->stream, "%s", second);
1366 (*info->fprintf_func) (info->stream, ",");
1367 if (op_index[2] != -1)
1368 (*info->print_address_func) ((bfd_vma) op_address[op_index[2]], info);
1370 (*info->fprintf_func) (info->stream, "%s", third);
1372 return codep - inbuf;
1375 static char *float_mem[] = {
1451 #define STi OP_STi, 0
1453 #define FGRPd9_2 NULL, NULL, 0
1454 #define FGRPd9_4 NULL, NULL, 1
1455 #define FGRPd9_5 NULL, NULL, 2
1456 #define FGRPd9_6 NULL, NULL, 3
1457 #define FGRPd9_7 NULL, NULL, 4
1458 #define FGRPda_5 NULL, NULL, 5
1459 #define FGRPdb_4 NULL, NULL, 6
1460 #define FGRPde_3 NULL, NULL, 7
1461 #define FGRPdf_4 NULL, NULL, 8
1463 static struct dis386 float_reg[][8] = {
1466 { "fadd", ST, STi },
1467 { "fmul", ST, STi },
1470 { "fsub", ST, STi },
1471 { "fsubr", ST, STi },
1472 { "fdiv", ST, STi },
1473 { "fdivr", ST, STi },
1488 { "fcmovb", ST, STi },
1489 { "fcmove", ST, STi },
1490 { "fcmovbe",ST, STi },
1491 { "fcmovu", ST, STi },
1499 { "fcmovnb",ST, STi },
1500 { "fcmovne",ST, STi },
1501 { "fcmovnbe",ST, STi },
1502 { "fcmovnu",ST, STi },
1504 { "fucomi", ST, STi },
1505 { "fcomi", ST, STi },
1510 { "fadd", STi, ST },
1511 { "fmul", STi, ST },
1515 { "fsub", STi, ST },
1516 { "fsubr", STi, ST },
1517 { "fdiv", STi, ST },
1518 { "fdivr", STi, ST },
1520 { "fsubr", STi, ST },
1521 { "fsub", STi, ST },
1522 { "fdivr", STi, ST },
1523 { "fdiv", STi, ST },
1539 { "faddp", STi, ST },
1540 { "fmulp", STi, ST },
1544 { "fsubp", STi, ST },
1545 { "fsubrp", STi, ST },
1546 { "fdivp", STi, ST },
1547 { "fdivrp", STi, ST },
1549 { "fsubrp", STi, ST },
1550 { "fsubp", STi, ST },
1551 { "fdivrp", STi, ST },
1552 { "fdivp", STi, ST },
1562 { "fucomip",ST, STi },
1563 { "fcomip", ST, STi },
1569 static char *fgrps[][8] = {
1572 "fnop","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
1577 "fchs","fabs","(bad)","(bad)","ftst","fxam","(bad)","(bad)",
1582 "fld1","fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz","(bad)",
1587 "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp","fincstp",
1592 "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos",
1597 "(bad)","fucompp","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
1602 "feni(287 only)","fdisi(287 only)","fNclex","fNinit",
1603 "fNsetpm(287 only)","(bad)","(bad)","(bad)",
1608 "(bad)","fcompp","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
1613 "fNstsw","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
1622 unsigned char floatop;
1624 floatop = codep[-1];
1628 putop (float_mem[(floatop - 0xd8) * 8 + reg], sizeflag);
1630 OP_E (v_mode, sizeflag);
1635 dp = &float_reg[floatop - 0xd8][reg];
1636 if (dp->name == NULL)
1638 putop (fgrps[dp->bytemode1][rm], sizeflag);
1639 /* instruction fnstsw is only one with strange arg */
1641 && FETCH_DATA (the_info, codep + 1)
1643 strcpy (op1out, "%eax");
1647 putop (dp->name, sizeflag);
1650 (*dp->op1)(dp->bytemode1, sizeflag);
1653 (*dp->op2)(dp->bytemode2, sizeflag);
1659 OP_ST (ignore, sizeflag)
1668 OP_STi (ignore, sizeflag)
1672 sprintf (scratchbuf, "%%st(%d)", rm);
1673 oappend (scratchbuf);
1677 /* capital letters in template are macros */
1679 putop (template, sizeflag)
1685 for (p = template; *p; p++)
1694 #ifdef SUFFIX_ALWAYS
1695 || (sizeflag & SUFFIX_ALWAYS)
1701 #ifdef SUFFIX_ALWAYS
1702 if (sizeflag & SUFFIX_ALWAYS)
1706 case 'E': /* For jcxz/jecxz */
1707 if (sizeflag & AFLAG)
1711 #ifdef SUFFIX_ALWAYS
1712 if (sizeflag & SUFFIX_ALWAYS)
1717 if ((prefixes & PREFIX_FWAIT) == 0)
1721 if ((prefixes & PREFIX_DATA)
1722 #ifdef SUFFIX_ALWAYS
1723 || (sizeflag & SUFFIX_ALWAYS)
1727 if (sizeflag & DFLAG)
1735 #ifdef SUFFIX_ALWAYS
1736 || (sizeflag & SUFFIX_ALWAYS)
1740 if (sizeflag & DFLAG)
1747 if (sizeflag & DFLAG)
1753 #ifdef SUFFIX_ALWAYS
1754 if (sizeflag & SUFFIX_ALWAYS)
1756 if (sizeflag & DFLAG)
1764 /* operand size flag for cwtl, cbtw */
1765 if (sizeflag & DFLAG)
1780 obufp += strlen (s);
1786 if (prefixes & PREFIX_CS)
1788 if (prefixes & PREFIX_DS)
1790 if (prefixes & PREFIX_SS)
1792 if (prefixes & PREFIX_ES)
1794 if (prefixes & PREFIX_FS)
1796 if (prefixes & PREFIX_GS)
1801 OP_indirE (bytemode, sizeflag)
1806 OP_E (bytemode, sizeflag);
1810 OP_E (bytemode, sizeflag)
1816 /* skip mod/rm byte */
1824 oappend (names8[rm]);
1827 oappend (names16[rm]);
1830 if (sizeflag & DFLAG)
1831 oappend (names32[rm]);
1833 oappend (names16[rm]);
1836 oappend ("<bad dis table>");
1845 if (sizeflag & AFLAG) /* 32 bit address mode */
1860 FETCH_DATA (the_info, codep + 1);
1861 scale = (*codep >> 6) & 3;
1862 index = (*codep >> 3) & 7;
1877 FETCH_DATA (the_info, codep + 1);
1879 if ((disp & 0x80) != 0)
1887 if (mod != 0 || base == 5)
1889 sprintf (scratchbuf, "0x%x", disp);
1890 oappend (scratchbuf);
1893 if (havebase || (havesib && (index != 4 || scale != 0)))
1897 oappend (names32[base]);
1902 sprintf (scratchbuf, ",%s", names32[index]);
1903 oappend (scratchbuf);
1905 sprintf (scratchbuf, ",%d", 1 << scale);
1906 oappend (scratchbuf);
1912 { /* 16 bit address mode */
1919 if ((disp & 0x8000) != 0)
1924 FETCH_DATA (the_info, codep + 1);
1926 if ((disp & 0x80) != 0)
1931 if ((disp & 0x8000) != 0)
1936 if (mod != 0 || rm == 6)
1938 sprintf (scratchbuf, "0x%x", disp);
1939 oappend (scratchbuf);
1942 if (mod != 0 || rm != 6)
1945 oappend (index16[rm]);
1951 #define INTERNAL_DISASSEMBLER_ERROR _("<internal disassembler error>")
1954 OP_G (bytemode, sizeflag)
1961 oappend (names8[reg]);
1964 oappend (names16[reg]);
1967 oappend (names32[reg]);
1970 if (sizeflag & DFLAG)
1971 oappend (names32[reg]);
1973 oappend (names16[reg]);
1976 oappend (INTERNAL_DISASSEMBLER_ERROR);
1986 FETCH_DATA (the_info, codep + 4);
1987 x = *codep++ & 0xff;
1988 x |= (*codep++ & 0xff) << 8;
1989 x |= (*codep++ & 0xff) << 16;
1990 x |= (*codep++ & 0xff) << 24;
1999 FETCH_DATA (the_info, codep + 2);
2000 x = *codep++ & 0xff;
2001 x |= (*codep++ & 0xff) << 8;
2009 op_index[op_ad] = op_ad;
2010 op_address[op_ad] = op;
2014 OP_REG (code, sizeflag)
2022 case indir_dx_reg: s = "(%dx)"; break;
2023 case ax_reg: case cx_reg: case dx_reg: case bx_reg:
2024 case sp_reg: case bp_reg: case si_reg: case di_reg:
2025 s = names16[code - ax_reg];
2027 case es_reg: case ss_reg: case cs_reg:
2028 case ds_reg: case fs_reg: case gs_reg:
2029 s = names_seg[code - es_reg];
2031 case al_reg: case ah_reg: case cl_reg: case ch_reg:
2032 case dl_reg: case dh_reg: case bl_reg: case bh_reg:
2033 s = names8[code - al_reg];
2035 case eAX_reg: case eCX_reg: case eDX_reg: case eBX_reg:
2036 case eSP_reg: case eBP_reg: case eSI_reg: case eDI_reg:
2037 if (sizeflag & DFLAG)
2038 s = names32[code - eAX_reg];
2040 s = names16[code - eAX_reg];
2043 s = INTERNAL_DISASSEMBLER_ERROR;
2050 OP_I (bytemode, sizeflag)
2059 FETCH_DATA (the_info, codep + 1);
2060 op = *codep++ & 0xff;
2063 if (sizeflag & DFLAG)
2072 oappend (INTERNAL_DISASSEMBLER_ERROR);
2075 sprintf (scratchbuf, "$0x%x", op);
2076 oappend (scratchbuf);
2080 OP_sI (bytemode, sizeflag)
2089 FETCH_DATA (the_info, codep + 1);
2091 if ((op & 0x80) != 0)
2095 if (sizeflag & DFLAG)
2100 if ((op & 0x8000) != 0)
2106 if ((op & 0x8000) != 0)
2110 oappend (INTERNAL_DISASSEMBLER_ERROR);
2113 sprintf (scratchbuf, "$0x%x", op);
2114 oappend (scratchbuf);
2118 OP_J (bytemode, sizeflag)
2128 FETCH_DATA (the_info, codep + 1);
2130 if ((disp & 0x80) != 0)
2134 if (sizeflag & DFLAG)
2139 if ((disp & 0x8000) != 0)
2141 /* for some reason, a data16 prefix on a jump instruction
2142 means that the pc is masked to 16 bits after the
2143 displacement is added! */
2148 oappend (INTERNAL_DISASSEMBLER_ERROR);
2151 disp = (start_pc + codep - start_codep + disp) & mask;
2153 sprintf (scratchbuf, "0x%x", disp);
2154 oappend (scratchbuf);
2159 OP_SEG (dummy, sizeflag)
2163 static char *sreg[] = {
2164 "%es","%cs","%ss","%ds","%fs","%gs","%?","%?",
2167 oappend (sreg[reg]);
2171 OP_DIR (size, sizeflag)
2180 if (sizeflag & DFLAG)
2190 sprintf (scratchbuf, "$0x%x,$0x%x", seg, offset);
2191 oappend (scratchbuf);
2194 if (sizeflag & DFLAG)
2199 if ((offset & 0x8000) != 0)
2203 offset = start_pc + codep - start_codep + offset;
2205 sprintf (scratchbuf, "0x%x", offset);
2206 oappend (scratchbuf);
2209 oappend (INTERNAL_DISASSEMBLER_ERROR);
2216 OP_OFF (ignore, sizeflag)
2224 if (sizeflag & AFLAG)
2229 sprintf (scratchbuf, "0x%x", off);
2230 oappend (scratchbuf);
2234 ptr_reg (code, sizeflag)
2240 if (sizeflag & AFLAG)
2241 s = names32[code - eAX_reg];
2243 s = names16[code - eAX_reg];
2249 OP_ESreg (code, sizeflag)
2254 ptr_reg (code, sizeflag);
2258 OP_DSreg (code, sizeflag)
2269 prefixes |= PREFIX_DS;
2271 ptr_reg (code, sizeflag);
2279 OP_ONE (dummy, sizeflag)
2290 OP_C (dummy, sizeflag)
2294 codep++; /* skip mod/rm */
2295 sprintf (scratchbuf, "%%cr%d", reg);
2296 oappend (scratchbuf);
2301 OP_D (dummy, sizeflag)
2305 codep++; /* skip mod/rm */
2306 sprintf (scratchbuf, "%%db%d", reg);
2307 oappend (scratchbuf);
2312 OP_T (dummy, sizeflag)
2316 codep++; /* skip mod/rm */
2317 sprintf (scratchbuf, "%%tr%d", reg);
2318 oappend (scratchbuf);
2322 OP_rm (bytemode, sizeflag)
2329 oappend (names32[rm]);
2332 oappend (names16[rm]);
2338 OP_MMX (ignore, sizeflag)
2342 sprintf (scratchbuf, "%%mm%d", reg);
2343 oappend (scratchbuf);
2347 OP_EM (bytemode, sizeflag)
2353 OP_E (bytemode, sizeflag);
2358 sprintf (scratchbuf, "%%mm%d", rm);
2359 oappend (scratchbuf);
2363 OP_MS (ignore, sizeflag)
2368 sprintf (scratchbuf, "%%mm%d", rm);
2369 oappend (scratchbuf);