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 */
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 ((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_address
[3], op_ad
, op_index
[3];
1150 static int start_pc
;
1154 * On the 386's of 1988, the maximum length of an instruction is 15 bytes.
1155 * (see topic "Redundant prefixes" in the "Differences from 8086"
1156 * section of the "Virtual 8086 Mode" chapter.)
1157 * 'pc' should be the address of this instruction, it will
1158 * be used to print the target address if this is a relative jump or call
1159 * The function returns the length of this instruction in bytes.
1162 int print_insn_x86
PARAMS ((bfd_vma pc
, disassemble_info
*info
, int sizeflag
));
1164 print_insn_i386 (pc
, info
)
1166 disassemble_info
*info
;
1168 if (info
->mach
== bfd_mach_i386_i386
)
1169 return print_insn_x86 (pc
, info
, AFLAG
|DFLAG
);
1170 else if (info
->mach
== bfd_mach_i386_i8086
)
1171 return print_insn_x86 (pc
, info
, 0);
1177 print_insn_x86 (pc
, info
, sizeflag
)
1179 disassemble_info
*info
;
1184 int enter_instruction
;
1185 char *first
, *second
, *third
;
1187 unsigned char need_modrm
;
1189 struct dis_private priv
;
1190 bfd_byte
*inbuf
= priv
.the_buffer
;
1192 /* The output looks better if we put 5 bytes on a line, since that
1193 puts long word instructions on a single line. */
1194 info
->bytes_per_line
= 5;
1196 info
->private_data
= (PTR
) &priv
;
1197 priv
.max_fetched
= priv
.the_buffer
;
1198 priv
.insn_start
= pc
;
1199 if (setjmp (priv
.bailout
) != 0)
1208 op_index
[0] = op_index
[1] = op_index
[2] = -1;
1212 start_codep
= inbuf
;
1217 FETCH_DATA (info
, codep
+ 1);
1219 enter_instruction
= 1;
1221 enter_instruction
= 0;
1225 if (prefixes
& PREFIX_REPZ
)
1227 if (prefixes
& PREFIX_REPNZ
)
1229 if (prefixes
& PREFIX_LOCK
)
1232 if ((prefixes
& PREFIX_FWAIT
)
1233 && ((*codep
< 0xd8) || (*codep
> 0xdf)))
1235 /* fwait not followed by floating point instruction */
1236 (*info
->fprintf_func
) (info
->stream
, "fwait");
1240 if (prefixes
& PREFIX_DATA
)
1243 if (prefixes
& PREFIX_ADDR
)
1246 if (sizeflag
& AFLAG
)
1247 oappend ("addr32 ");
1249 oappend ("addr16 ");
1254 FETCH_DATA (info
, codep
+ 2);
1255 dp
= &dis386_twobyte
[*++codep
];
1256 need_modrm
= twobyte_has_modrm
[*codep
];
1260 dp
= &dis386
[*codep
];
1261 need_modrm
= onebyte_has_modrm
[*codep
];
1267 FETCH_DATA (info
, codep
+ 1);
1268 mod
= (*codep
>> 6) & 3;
1269 reg
= (*codep
>> 3) & 7;
1273 if (dp
->name
== NULL
&& dp
->bytemode1
== FLOATCODE
)
1279 if (dp
->name
== NULL
)
1280 dp
= &grps
[dp
->bytemode1
][reg
];
1282 putop (dp
->name
, sizeflag
);
1287 (*dp
->op1
)(dp
->bytemode1
, sizeflag
);
1292 (*dp
->op2
)(dp
->bytemode2
, sizeflag
);
1297 (*dp
->op3
)(dp
->bytemode3
, sizeflag
);
1300 obufp
= obuf
+ strlen (obuf
);
1301 for (i
= strlen (obuf
); i
< 6; i
++)
1304 (*info
->fprintf_func
) (info
->stream
, "%s", obuf
);
1306 /* enter instruction is printed with operands in the
1307 * same order as the intel book; everything else
1308 * is printed in reverse order
1310 if (enter_instruction
)
1315 op_ad
= op_index
[0];
1316 op_index
[0] = op_index
[2];
1317 op_index
[2] = op_ad
;
1328 if (op_index
[0] != -1)
1329 (*info
->print_address_func
) (op_address
[op_index
[0]], info
);
1331 (*info
->fprintf_func
) (info
->stream
, "%s", first
);
1337 (*info
->fprintf_func
) (info
->stream
, ",");
1338 if (op_index
[1] != -1)
1339 (*info
->print_address_func
) (op_address
[op_index
[1]], info
);
1341 (*info
->fprintf_func
) (info
->stream
, "%s", second
);
1347 (*info
->fprintf_func
) (info
->stream
, ",");
1348 if (op_index
[2] != -1)
1349 (*info
->print_address_func
) (op_address
[op_index
[2]], info
);
1351 (*info
->fprintf_func
) (info
->stream
, "%s", third
);
1353 return codep
- inbuf
;
1356 static char *float_mem
[] = {
1432 #define STi OP_STi, 0
1434 #define FGRPd9_2 NULL, NULL, 0
1435 #define FGRPd9_4 NULL, NULL, 1
1436 #define FGRPd9_5 NULL, NULL, 2
1437 #define FGRPd9_6 NULL, NULL, 3
1438 #define FGRPd9_7 NULL, NULL, 4
1439 #define FGRPda_5 NULL, NULL, 5
1440 #define FGRPdb_4 NULL, NULL, 6
1441 #define FGRPde_3 NULL, NULL, 7
1442 #define FGRPdf_4 NULL, NULL, 8
1444 static struct dis386 float_reg
[][8] = {
1447 { "fadd", ST
, STi
},
1448 { "fmul", ST
, STi
},
1451 { "fsub", ST
, STi
},
1452 { "fsubr", ST
, STi
},
1453 { "fdiv", ST
, STi
},
1454 { "fdivr", ST
, STi
},
1469 { "fcmovb", ST
, STi
},
1470 { "fcmove", ST
, STi
},
1471 { "fcmovbe",ST
, STi
},
1472 { "fcmovu", ST
, STi
},
1480 { "fcmovnb",ST
, STi
},
1481 { "fcmovne",ST
, STi
},
1482 { "fcmovnbe",ST
, STi
},
1483 { "fcmovnu",ST
, STi
},
1485 { "fucomi", ST
, STi
},
1486 { "fcomi", ST
, STi
},
1491 { "fadd", STi
, ST
},
1492 { "fmul", STi
, ST
},
1496 { "fsub", STi
, ST
},
1497 { "fsubr", STi
, ST
},
1498 { "fdiv", STi
, ST
},
1499 { "fdivr", STi
, ST
},
1501 { "fsubr", STi
, ST
},
1502 { "fsub", STi
, ST
},
1503 { "fdivr", STi
, ST
},
1504 { "fdiv", STi
, ST
},
1520 { "faddp", STi
, ST
},
1521 { "fmulp", STi
, ST
},
1525 { "fsubp", STi
, ST
},
1526 { "fsubrp", STi
, ST
},
1527 { "fdivp", STi
, ST
},
1528 { "fdivrp", STi
, ST
},
1530 { "fsubrp", STi
, ST
},
1531 { "fsubp", STi
, ST
},
1532 { "fdivrp", STi
, ST
},
1533 { "fdivp", STi
, ST
},
1543 { "fucomip",ST
, STi
},
1544 { "fcomip", ST
, STi
},
1550 static char *fgrps
[][8] = {
1553 "fnop","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
1558 "fchs","fabs","(bad)","(bad)","ftst","fxam","(bad)","(bad)",
1563 "fld1","fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz","(bad)",
1568 "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp","fincstp",
1573 "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos",
1578 "(bad)","fucompp","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
1583 "feni(287 only)","fdisi(287 only)","fNclex","fNinit",
1584 "fNsetpm(287 only)","(bad)","(bad)","(bad)",
1589 "(bad)","fcompp","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
1594 "fNstsw","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
1603 unsigned char floatop
;
1605 floatop
= codep
[-1];
1609 putop (float_mem
[(floatop
- 0xd8) * 8 + reg
], sizeflag
);
1611 OP_E (v_mode
, sizeflag
);
1616 dp
= &float_reg
[floatop
- 0xd8][reg
];
1617 if (dp
->name
== NULL
)
1619 putop (fgrps
[dp
->bytemode1
][rm
], sizeflag
);
1620 /* instruction fnstsw is only one with strange arg */
1622 && FETCH_DATA (the_info
, codep
+ 1)
1624 strcpy (op1out
, "%eax");
1628 putop (dp
->name
, sizeflag
);
1631 (*dp
->op1
)(dp
->bytemode1
, sizeflag
);
1634 (*dp
->op2
)(dp
->bytemode2
, sizeflag
);
1640 OP_ST (ignore
, sizeflag
)
1649 OP_STi (ignore
, sizeflag
)
1653 sprintf (scratchbuf
, "%%st(%d)", rm
);
1654 oappend (scratchbuf
);
1658 /* capital letters in template are macros */
1660 putop (template, sizeflag
)
1666 for (p
= template; *p
; p
++)
1673 case 'C': /* For jcxz/jecxz */
1674 if (sizeflag
& AFLAG
)
1678 if ((prefixes
& PREFIX_FWAIT
) == 0)
1682 /* operand size flag */
1683 if (sizeflag
& DFLAG
)
1689 /* operand size flag for cwtl, cbtw */
1690 if (sizeflag
& DFLAG
)
1705 obufp
+= strlen (s
);
1711 if (prefixes
& PREFIX_CS
)
1713 if (prefixes
& PREFIX_DS
)
1715 if (prefixes
& PREFIX_SS
)
1717 if (prefixes
& PREFIX_ES
)
1719 if (prefixes
& PREFIX_FS
)
1721 if (prefixes
& PREFIX_GS
)
1726 OP_indirE (bytemode
, sizeflag
)
1731 OP_E (bytemode
, sizeflag
);
1735 OP_E (bytemode
, sizeflag
)
1741 /* skip mod/rm byte */
1749 oappend (names8
[rm
]);
1752 oappend (names16
[rm
]);
1755 if (sizeflag
& DFLAG
)
1756 oappend (names32
[rm
]);
1758 oappend (names16
[rm
]);
1761 oappend ("<bad dis table>");
1770 if (sizeflag
& AFLAG
) /* 32 bit address mode */
1785 FETCH_DATA (the_info
, codep
+ 1);
1786 scale
= (*codep
>> 6) & 3;
1787 index
= (*codep
>> 3) & 7;
1802 FETCH_DATA (the_info
, codep
+ 1);
1804 if ((disp
& 0x80) != 0)
1812 if (mod
!= 0 || base
== 5)
1814 sprintf (scratchbuf
, "0x%x", disp
);
1815 oappend (scratchbuf
);
1818 if (havebase
|| (havesib
&& (index
!= 4 || scale
!= 0)))
1822 oappend (names32
[base
]);
1827 sprintf (scratchbuf
, ",%s", names32
[index
]);
1828 oappend (scratchbuf
);
1830 sprintf (scratchbuf
, ",%d", 1 << scale
);
1831 oappend (scratchbuf
);
1837 { /* 16 bit address mode */
1844 if ((disp
& 0x8000) != 0)
1849 FETCH_DATA (the_info
, codep
+ 1);
1851 if ((disp
& 0x80) != 0)
1856 if ((disp
& 0x8000) != 0)
1861 if (mod
!= 0 || rm
== 6)
1863 sprintf (scratchbuf
, "0x%x", disp
);
1864 oappend (scratchbuf
);
1867 if (mod
!= 0 || rm
!= 6)
1870 oappend (index16
[rm
]);
1876 #define INTERNAL_DISASSEMBLER_ERROR _("<internal disassembler error>")
1879 OP_G (bytemode
, sizeflag
)
1886 oappend (names8
[reg
]);
1889 oappend (names16
[reg
]);
1892 oappend (names32
[reg
]);
1895 if (sizeflag
& DFLAG
)
1896 oappend (names32
[reg
]);
1898 oappend (names16
[reg
]);
1901 oappend (INTERNAL_DISASSEMBLER_ERROR
);
1911 FETCH_DATA (the_info
, codep
+ 4);
1912 x
= *codep
++ & 0xff;
1913 x
|= (*codep
++ & 0xff) << 8;
1914 x
|= (*codep
++ & 0xff) << 16;
1915 x
|= (*codep
++ & 0xff) << 24;
1924 FETCH_DATA (the_info
, codep
+ 2);
1925 x
= *codep
++ & 0xff;
1926 x
|= (*codep
++ & 0xff) << 8;
1934 op_index
[op_ad
] = op_ad
;
1935 op_address
[op_ad
] = op
;
1939 OP_REG (code
, sizeflag
)
1947 case indir_dx_reg
: s
= "(%dx)"; break;
1948 case ax_reg
: case cx_reg
: case dx_reg
: case bx_reg
:
1949 case sp_reg
: case bp_reg
: case si_reg
: case di_reg
:
1950 s
= names16
[code
- ax_reg
];
1952 case es_reg
: case ss_reg
: case cs_reg
:
1953 case ds_reg
: case fs_reg
: case gs_reg
:
1954 s
= names_seg
[code
- es_reg
];
1956 case al_reg
: case ah_reg
: case cl_reg
: case ch_reg
:
1957 case dl_reg
: case dh_reg
: case bl_reg
: case bh_reg
:
1958 s
= names8
[code
- al_reg
];
1960 case eAX_reg
: case eCX_reg
: case eDX_reg
: case eBX_reg
:
1961 case eSP_reg
: case eBP_reg
: case eSI_reg
: case eDI_reg
:
1962 if (sizeflag
& DFLAG
)
1963 s
= names32
[code
- eAX_reg
];
1965 s
= names16
[code
- eAX_reg
];
1968 s
= INTERNAL_DISASSEMBLER_ERROR
;
1975 OP_I (bytemode
, sizeflag
)
1984 FETCH_DATA (the_info
, codep
+ 1);
1985 op
= *codep
++ & 0xff;
1988 if (sizeflag
& DFLAG
)
1997 oappend (INTERNAL_DISASSEMBLER_ERROR
);
2000 sprintf (scratchbuf
, "$0x%x", op
);
2001 oappend (scratchbuf
);
2005 OP_sI (bytemode
, sizeflag
)
2014 FETCH_DATA (the_info
, codep
+ 1);
2016 if ((op
& 0x80) != 0)
2020 if (sizeflag
& DFLAG
)
2025 if ((op
& 0x8000) != 0)
2031 if ((op
& 0x8000) != 0)
2035 oappend (INTERNAL_DISASSEMBLER_ERROR
);
2038 sprintf (scratchbuf
, "$0x%x", op
);
2039 oappend (scratchbuf
);
2043 OP_J (bytemode
, sizeflag
)
2053 FETCH_DATA (the_info
, codep
+ 1);
2055 if ((disp
& 0x80) != 0)
2059 if (sizeflag
& DFLAG
)
2064 if ((disp
& 0x8000) != 0)
2066 /* for some reason, a data16 prefix on a jump instruction
2067 means that the pc is masked to 16 bits after the
2068 displacement is added! */
2073 oappend (INTERNAL_DISASSEMBLER_ERROR
);
2076 disp
= (start_pc
+ codep
- start_codep
+ disp
) & mask
;
2078 sprintf (scratchbuf
, "0x%x", disp
);
2079 oappend (scratchbuf
);
2084 OP_SEG (dummy
, sizeflag
)
2088 static char *sreg
[] = {
2089 "%es","%cs","%ss","%ds","%fs","%gs","%?","%?",
2092 oappend (sreg
[reg
]);
2096 OP_DIR (size
, sizeflag
)
2105 if (sizeflag
& DFLAG
)
2115 sprintf (scratchbuf
, "0x%x,0x%x", seg
, offset
);
2116 oappend (scratchbuf
);
2119 if (sizeflag
& DFLAG
)
2124 if ((offset
& 0x8000) != 0)
2128 offset
= start_pc
+ codep
- start_codep
+ offset
;
2130 sprintf (scratchbuf
, "0x%x", offset
);
2131 oappend (scratchbuf
);
2134 oappend (INTERNAL_DISASSEMBLER_ERROR
);
2141 OP_OFF (ignore
, sizeflag
)
2149 if (sizeflag
& AFLAG
)
2154 sprintf (scratchbuf
, "0x%x", off
);
2155 oappend (scratchbuf
);
2159 ptr_reg (code
, sizeflag
)
2165 if (sizeflag
& AFLAG
)
2166 s
= names32
[code
- eAX_reg
];
2168 s
= names16
[code
- eAX_reg
];
2174 OP_ESreg (code
, sizeflag
)
2179 ptr_reg (code
, sizeflag
);
2183 OP_DSreg (code
, sizeflag
)
2194 prefixes
|= PREFIX_DS
;
2196 ptr_reg (code
, sizeflag
);
2204 OP_ONE (dummy
, sizeflag
)
2215 OP_C (dummy
, sizeflag
)
2219 codep
++; /* skip mod/rm */
2220 sprintf (scratchbuf
, "%%cr%d", reg
);
2221 oappend (scratchbuf
);
2226 OP_D (dummy
, sizeflag
)
2230 codep
++; /* skip mod/rm */
2231 sprintf (scratchbuf
, "%%db%d", reg
);
2232 oappend (scratchbuf
);
2237 OP_T (dummy
, sizeflag
)
2241 codep
++; /* skip mod/rm */
2242 sprintf (scratchbuf
, "%%tr%d", reg
);
2243 oappend (scratchbuf
);
2247 OP_rm (bytemode
, sizeflag
)
2254 oappend (names32
[rm
]);
2257 oappend (names16
[rm
]);
2263 OP_MMX (ignore
, sizeflag
)
2267 sprintf (scratchbuf
, "%%mm%d", reg
);
2268 oappend (scratchbuf
);
2272 OP_EM (bytemode
, sizeflag
)
2278 OP_E (bytemode
, sizeflag
);
2283 sprintf (scratchbuf
, "%%mm%d", rm
);
2284 oappend (scratchbuf
);
2288 OP_MS (ignore
, sizeflag
)
2293 sprintf (scratchbuf
, "%%mm%d", rm
);
2294 oappend (scratchbuf
);