gas/
[deliverable/binutils-gdb.git] / opcodes / i386-dis.c
1 /* Print i386 instructions for GDB, the GNU debugger.
2 Copyright 1988, 1989, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
20
21 /* 80386 instruction printer by Pace Willisson (pace@prep.ai.mit.edu)
22 July 1988
23 modified by John Hassey (hassey@dg-rtp.dg.com)
24 x86-64 support added by Jan Hubicka (jh@suse.cz)
25 VIA PadLock support by Michal Ludvig (mludvig@suse.cz). */
26
27 /* The main tables describing the instructions is essentially a copy
28 of the "Opcode Map" chapter (Appendix A) of the Intel 80386
29 Programmers Manual. Usually, there is a capital letter, followed
30 by a small letter. The capital letter tell the addressing mode,
31 and the small letter tells about the operand size. Refer to
32 the Intel manual for details. */
33
34 #include "dis-asm.h"
35 #include "sysdep.h"
36 #include "opintl.h"
37 #include "opcode/i386.h"
38
39 #include <setjmp.h>
40
41 static int fetch_data (struct disassemble_info *, bfd_byte *);
42 static void ckprefix (void);
43 static const char *prefix_name (int, int);
44 static int print_insn (bfd_vma, disassemble_info *);
45 static void dofloat (int);
46 static void OP_ST (int, int);
47 static void OP_STi (int, int);
48 static int putop (const char *, int);
49 static void oappend (const char *);
50 static void append_seg (void);
51 static void OP_indirE (int, int);
52 static void print_operand_value (char *, int, bfd_vma);
53 static void OP_E (int, int);
54 static void OP_G (int, int);
55 static bfd_vma get64 (void);
56 static bfd_signed_vma get32 (void);
57 static bfd_signed_vma get32s (void);
58 static int get16 (void);
59 static void set_op (bfd_vma, int);
60 static void OP_REG (int, int);
61 static void OP_IMREG (int, int);
62 static void OP_I (int, int);
63 static void OP_I64 (int, int);
64 static void OP_sI (int, int);
65 static void OP_J (int, int);
66 static void OP_SEG (int, int);
67 static void OP_DIR (int, int);
68 static void OP_OFF (int, int);
69 static void OP_OFF64 (int, int);
70 static void ptr_reg (int, int);
71 static void OP_ESreg (int, int);
72 static void OP_DSreg (int, int);
73 static void OP_C (int, int);
74 static void OP_D (int, int);
75 static void OP_T (int, int);
76 static void OP_R (int, int);
77 static void OP_MMX (int, int);
78 static void OP_XMM (int, int);
79 static void OP_EM (int, int);
80 static void OP_EX (int, int);
81 static void OP_EMC (int,int);
82 static void OP_MXC (int,int);
83 static void OP_MS (int, int);
84 static void OP_XS (int, int);
85 static void OP_M (int, int);
86 static void OP_VMX (int, int);
87 static void OP_0fae (int, int);
88 static void OP_0f07 (int, int);
89 static void NOP_Fixup1 (int, int);
90 static void NOP_Fixup2 (int, int);
91 static void OP_3DNowSuffix (int, int);
92 static void OP_SIMD_Suffix (int, int);
93 static void SIMD_Fixup (int, int);
94 static void PNI_Fixup (int, int);
95 static void SVME_Fixup (int, int);
96 static void INVLPG_Fixup (int, int);
97 static void BadOp (void);
98 static void VMX_Fixup (int, int);
99 static void REP_Fixup (int, int);
100 static void CMPXCHG8B_Fixup (int, int);
101 static void XMM_Fixup (int, int);
102 static void CRC32_Fixup (int, int);
103
104 struct dis_private {
105 /* Points to first byte not fetched. */
106 bfd_byte *max_fetched;
107 bfd_byte the_buffer[MAX_MNEM_SIZE];
108 bfd_vma insn_start;
109 int orig_sizeflag;
110 jmp_buf bailout;
111 };
112
113 enum address_mode
114 {
115 mode_16bit,
116 mode_32bit,
117 mode_64bit
118 };
119
120 enum address_mode address_mode;
121
122 /* Flags for the prefixes for the current instruction. See below. */
123 static int prefixes;
124
125 /* REX prefix the current instruction. See below. */
126 static int rex;
127 /* Bits of REX we've already used. */
128 static int rex_used;
129 /* Mark parts used in the REX prefix. When we are testing for
130 empty prefix (for 8bit register REX extension), just mask it
131 out. Otherwise test for REX bit is excuse for existence of REX
132 only in case value is nonzero. */
133 #define USED_REX(value) \
134 { \
135 if (value) \
136 { \
137 if ((rex & value)) \
138 rex_used |= (value) | REX_OPCODE; \
139 } \
140 else \
141 rex_used |= REX_OPCODE; \
142 }
143
144 /* Flags for prefixes which we somehow handled when printing the
145 current instruction. */
146 static int used_prefixes;
147
148 /* Flags stored in PREFIXES. */
149 #define PREFIX_REPZ 1
150 #define PREFIX_REPNZ 2
151 #define PREFIX_LOCK 4
152 #define PREFIX_CS 8
153 #define PREFIX_SS 0x10
154 #define PREFIX_DS 0x20
155 #define PREFIX_ES 0x40
156 #define PREFIX_FS 0x80
157 #define PREFIX_GS 0x100
158 #define PREFIX_DATA 0x200
159 #define PREFIX_ADDR 0x400
160 #define PREFIX_FWAIT 0x800
161
162 /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
163 to ADDR (exclusive) are valid. Returns 1 for success, longjmps
164 on error. */
165 #define FETCH_DATA(info, addr) \
166 ((addr) <= ((struct dis_private *) (info->private_data))->max_fetched \
167 ? 1 : fetch_data ((info), (addr)))
168
169 static int
170 fetch_data (struct disassemble_info *info, bfd_byte *addr)
171 {
172 int status;
173 struct dis_private *priv = (struct dis_private *) info->private_data;
174 bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
175
176 if (addr <= priv->the_buffer + MAX_MNEM_SIZE)
177 status = (*info->read_memory_func) (start,
178 priv->max_fetched,
179 addr - priv->max_fetched,
180 info);
181 else
182 status = -1;
183 if (status != 0)
184 {
185 /* If we did manage to read at least one byte, then
186 print_insn_i386 will do something sensible. Otherwise, print
187 an error. We do that here because this is where we know
188 STATUS. */
189 if (priv->max_fetched == priv->the_buffer)
190 (*info->memory_error_func) (status, start, info);
191 longjmp (priv->bailout, 1);
192 }
193 else
194 priv->max_fetched = addr;
195 return 1;
196 }
197
198 #define XX { NULL, 0 }
199
200 #define Eb { OP_E, b_mode }
201 #define Ev { OP_E, v_mode }
202 #define Ed { OP_E, d_mode }
203 #define Edq { OP_E, dq_mode }
204 #define Edqw { OP_E, dqw_mode }
205 #define Edqb { OP_E, dqb_mode }
206 #define Edqd { OP_E, dqd_mode }
207 #define indirEv { OP_indirE, stack_v_mode }
208 #define indirEp { OP_indirE, f_mode }
209 #define stackEv { OP_E, stack_v_mode }
210 #define Em { OP_E, m_mode }
211 #define Ew { OP_E, w_mode }
212 #define M { OP_M, 0 } /* lea, lgdt, etc. */
213 #define Ma { OP_M, v_mode }
214 #define Mp { OP_M, f_mode } /* 32 or 48 bit memory operand for LDS, LES etc */
215 #define Mq { OP_M, q_mode }
216 #define Gb { OP_G, b_mode }
217 #define Gv { OP_G, v_mode }
218 #define Gd { OP_G, d_mode }
219 #define Gdq { OP_G, dq_mode }
220 #define Gm { OP_G, m_mode }
221 #define Gw { OP_G, w_mode }
222 #define Rd { OP_R, d_mode }
223 #define Rm { OP_R, m_mode }
224 #define Ib { OP_I, b_mode }
225 #define sIb { OP_sI, b_mode } /* sign extened byte */
226 #define Iv { OP_I, v_mode }
227 #define Iq { OP_I, q_mode }
228 #define Iv64 { OP_I64, v_mode }
229 #define Iw { OP_I, w_mode }
230 #define I1 { OP_I, const_1_mode }
231 #define Jb { OP_J, b_mode }
232 #define Jv { OP_J, v_mode }
233 #define Cm { OP_C, m_mode }
234 #define Dm { OP_D, m_mode }
235 #define Td { OP_T, d_mode }
236
237 #define RMeAX { OP_REG, eAX_reg }
238 #define RMeBX { OP_REG, eBX_reg }
239 #define RMeCX { OP_REG, eCX_reg }
240 #define RMeDX { OP_REG, eDX_reg }
241 #define RMeSP { OP_REG, eSP_reg }
242 #define RMeBP { OP_REG, eBP_reg }
243 #define RMeSI { OP_REG, eSI_reg }
244 #define RMeDI { OP_REG, eDI_reg }
245 #define RMrAX { OP_REG, rAX_reg }
246 #define RMrBX { OP_REG, rBX_reg }
247 #define RMrCX { OP_REG, rCX_reg }
248 #define RMrDX { OP_REG, rDX_reg }
249 #define RMrSP { OP_REG, rSP_reg }
250 #define RMrBP { OP_REG, rBP_reg }
251 #define RMrSI { OP_REG, rSI_reg }
252 #define RMrDI { OP_REG, rDI_reg }
253 #define RMAL { OP_REG, al_reg }
254 #define RMAL { OP_REG, al_reg }
255 #define RMCL { OP_REG, cl_reg }
256 #define RMDL { OP_REG, dl_reg }
257 #define RMBL { OP_REG, bl_reg }
258 #define RMAH { OP_REG, ah_reg }
259 #define RMCH { OP_REG, ch_reg }
260 #define RMDH { OP_REG, dh_reg }
261 #define RMBH { OP_REG, bh_reg }
262 #define RMAX { OP_REG, ax_reg }
263 #define RMDX { OP_REG, dx_reg }
264
265 #define eAX { OP_IMREG, eAX_reg }
266 #define eBX { OP_IMREG, eBX_reg }
267 #define eCX { OP_IMREG, eCX_reg }
268 #define eDX { OP_IMREG, eDX_reg }
269 #define eSP { OP_IMREG, eSP_reg }
270 #define eBP { OP_IMREG, eBP_reg }
271 #define eSI { OP_IMREG, eSI_reg }
272 #define eDI { OP_IMREG, eDI_reg }
273 #define AL { OP_IMREG, al_reg }
274 #define CL { OP_IMREG, cl_reg }
275 #define DL { OP_IMREG, dl_reg }
276 #define BL { OP_IMREG, bl_reg }
277 #define AH { OP_IMREG, ah_reg }
278 #define CH { OP_IMREG, ch_reg }
279 #define DH { OP_IMREG, dh_reg }
280 #define BH { OP_IMREG, bh_reg }
281 #define AX { OP_IMREG, ax_reg }
282 #define DX { OP_IMREG, dx_reg }
283 #define zAX { OP_IMREG, z_mode_ax_reg }
284 #define indirDX { OP_IMREG, indir_dx_reg }
285
286 #define Sw { OP_SEG, w_mode }
287 #define Sv { OP_SEG, v_mode }
288 #define Ap { OP_DIR, 0 }
289 #define Ob { OP_OFF64, b_mode }
290 #define Ov { OP_OFF64, v_mode }
291 #define Xb { OP_DSreg, eSI_reg }
292 #define Xv { OP_DSreg, eSI_reg }
293 #define Xz { OP_DSreg, eSI_reg }
294 #define Yb { OP_ESreg, eDI_reg }
295 #define Yv { OP_ESreg, eDI_reg }
296 #define DSBX { OP_DSreg, eBX_reg }
297
298 #define es { OP_REG, es_reg }
299 #define ss { OP_REG, ss_reg }
300 #define cs { OP_REG, cs_reg }
301 #define ds { OP_REG, ds_reg }
302 #define fs { OP_REG, fs_reg }
303 #define gs { OP_REG, gs_reg }
304
305 #define MX { OP_MMX, 0 }
306 #define XM { OP_XMM, 0 }
307 #define EM { OP_EM, v_mode }
308 #define EX { OP_EX, v_mode }
309 #define MS { OP_MS, v_mode }
310 #define XS { OP_XS, v_mode }
311 #define EMC { OP_EMC, v_mode }
312 #define MXC { OP_MXC, 0 }
313 #define VM { OP_VMX, q_mode }
314 #define OPSUF { OP_3DNowSuffix, 0 }
315 #define OPSIMD { OP_SIMD_Suffix, 0 }
316 #define XMM0 { XMM_Fixup, 0 }
317
318 /* Used handle "rep" prefix for string instructions. */
319 #define Xbr { REP_Fixup, eSI_reg }
320 #define Xvr { REP_Fixup, eSI_reg }
321 #define Ybr { REP_Fixup, eDI_reg }
322 #define Yvr { REP_Fixup, eDI_reg }
323 #define Yzr { REP_Fixup, eDI_reg }
324 #define indirDXr { REP_Fixup, indir_dx_reg }
325 #define ALr { REP_Fixup, al_reg }
326 #define eAXr { REP_Fixup, eAX_reg }
327
328 #define cond_jump_flag { NULL, cond_jump_mode }
329 #define loop_jcxz_flag { NULL, loop_jcxz_mode }
330
331 /* bits in sizeflag */
332 #define SUFFIX_ALWAYS 4
333 #define AFLAG 2
334 #define DFLAG 1
335
336 #define b_mode 1 /* byte operand */
337 #define v_mode 2 /* operand size depends on prefixes */
338 #define w_mode 3 /* word operand */
339 #define d_mode 4 /* double word operand */
340 #define q_mode 5 /* quad word operand */
341 #define t_mode 6 /* ten-byte operand */
342 #define x_mode 7 /* 16-byte XMM operand */
343 #define m_mode 8 /* d_mode in 32bit, q_mode in 64bit mode. */
344 #define cond_jump_mode 9
345 #define loop_jcxz_mode 10
346 #define dq_mode 11 /* operand size depends on REX prefixes. */
347 #define dqw_mode 12 /* registers like dq_mode, memory like w_mode. */
348 #define f_mode 13 /* 4- or 6-byte pointer operand */
349 #define const_1_mode 14
350 #define stack_v_mode 15 /* v_mode for stack-related opcodes. */
351 #define z_mode 16 /* non-quad operand size depends on prefixes */
352 #define o_mode 17 /* 16-byte operand */
353 #define dqb_mode 18 /* registers like dq_mode, memory like b_mode. */
354 #define dqd_mode 19 /* registers like dq_mode, memory like d_mode. */
355
356 #define es_reg 100
357 #define cs_reg 101
358 #define ss_reg 102
359 #define ds_reg 103
360 #define fs_reg 104
361 #define gs_reg 105
362
363 #define eAX_reg 108
364 #define eCX_reg 109
365 #define eDX_reg 110
366 #define eBX_reg 111
367 #define eSP_reg 112
368 #define eBP_reg 113
369 #define eSI_reg 114
370 #define eDI_reg 115
371
372 #define al_reg 116
373 #define cl_reg 117
374 #define dl_reg 118
375 #define bl_reg 119
376 #define ah_reg 120
377 #define ch_reg 121
378 #define dh_reg 122
379 #define bh_reg 123
380
381 #define ax_reg 124
382 #define cx_reg 125
383 #define dx_reg 126
384 #define bx_reg 127
385 #define sp_reg 128
386 #define bp_reg 129
387 #define si_reg 130
388 #define di_reg 131
389
390 #define rAX_reg 132
391 #define rCX_reg 133
392 #define rDX_reg 134
393 #define rBX_reg 135
394 #define rSP_reg 136
395 #define rBP_reg 137
396 #define rSI_reg 138
397 #define rDI_reg 139
398
399 #define z_mode_ax_reg 149
400 #define indir_dx_reg 150
401
402 #define FLOATCODE 1
403 #define USE_GROUPS 2
404 #define USE_PREFIX_USER_TABLE 3
405 #define X86_64_SPECIAL 4
406 #define IS_3BYTE_OPCODE 5
407
408 #define FLOAT NULL, { { NULL, FLOATCODE } }
409
410 #define GRP1a NULL, { { NULL, USE_GROUPS }, { NULL, 0 } }
411 #define GRP1b NULL, { { NULL, USE_GROUPS }, { NULL, 1 } }
412 #define GRP1S NULL, { { NULL, USE_GROUPS }, { NULL, 2 } }
413 #define GRP1Ss NULL, { { NULL, USE_GROUPS }, { NULL, 3 } }
414 #define GRP2b NULL, { { NULL, USE_GROUPS }, { NULL, 4 } }
415 #define GRP2S NULL, { { NULL, USE_GROUPS }, { NULL, 5 } }
416 #define GRP2b_one NULL, { { NULL, USE_GROUPS }, { NULL, 6 } }
417 #define GRP2S_one NULL, { { NULL, USE_GROUPS }, { NULL, 7 } }
418 #define GRP2b_cl NULL, { { NULL, USE_GROUPS }, { NULL, 8 } }
419 #define GRP2S_cl NULL, { { NULL, USE_GROUPS }, { NULL, 9 } }
420 #define GRP3b NULL, { { NULL, USE_GROUPS }, { NULL, 10 } }
421 #define GRP3S NULL, { { NULL, USE_GROUPS }, { NULL, 11 } }
422 #define GRP4 NULL, { { NULL, USE_GROUPS }, { NULL, 12 } }
423 #define GRP5 NULL, { { NULL, USE_GROUPS }, { NULL, 13 } }
424 #define GRP6 NULL, { { NULL, USE_GROUPS }, { NULL, 14 } }
425 #define GRP7 NULL, { { NULL, USE_GROUPS }, { NULL, 15 } }
426 #define GRP8 NULL, { { NULL, USE_GROUPS }, { NULL, 16 } }
427 #define GRP9 NULL, { { NULL, USE_GROUPS }, { NULL, 17 } }
428 #define GRP11_C6 NULL, { { NULL, USE_GROUPS }, { NULL, 18 } }
429 #define GRP11_C7 NULL, { { NULL, USE_GROUPS }, { NULL, 19 } }
430 #define GRP12 NULL, { { NULL, USE_GROUPS }, { NULL, 20 } }
431 #define GRP13 NULL, { { NULL, USE_GROUPS }, { NULL, 21 } }
432 #define GRP14 NULL, { { NULL, USE_GROUPS }, { NULL, 22 } }
433 #define GRP15 NULL, { { NULL, USE_GROUPS }, { NULL, 23 } }
434 #define GRP16 NULL, { { NULL, USE_GROUPS }, { NULL, 24 } }
435 #define GRPAMD NULL, { { NULL, USE_GROUPS }, { NULL, 25 } }
436 #define GRPPADLCK1 NULL, { { NULL, USE_GROUPS }, { NULL, 26 } }
437 #define GRPPADLCK2 NULL, { { NULL, USE_GROUPS }, { NULL, 27 } }
438
439 #define PREGRP0 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 0 } }
440 #define PREGRP1 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 1 } }
441 #define PREGRP2 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 2 } }
442 #define PREGRP3 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 3 } }
443 #define PREGRP4 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 4 } }
444 #define PREGRP5 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 5 } }
445 #define PREGRP6 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 6 } }
446 #define PREGRP7 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 7 } }
447 #define PREGRP8 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 8 } }
448 #define PREGRP9 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 9 } }
449 #define PREGRP10 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 10 } }
450 #define PREGRP11 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 11 } }
451 #define PREGRP12 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 12 } }
452 #define PREGRP13 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 13 } }
453 #define PREGRP14 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 14 } }
454 #define PREGRP15 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 15 } }
455 #define PREGRP16 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 16 } }
456 #define PREGRP17 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 17 } }
457 #define PREGRP18 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 18 } }
458 #define PREGRP19 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 19 } }
459 #define PREGRP20 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 20 } }
460 #define PREGRP21 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 21 } }
461 #define PREGRP22 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 22 } }
462 #define PREGRP23 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 23 } }
463 #define PREGRP24 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 24 } }
464 #define PREGRP25 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 25 } }
465 #define PREGRP26 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 26 } }
466 #define PREGRP27 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 27 } }
467 #define PREGRP28 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 28 } }
468 #define PREGRP29 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 29 } }
469 #define PREGRP30 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 30 } }
470 #define PREGRP31 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 31 } }
471 #define PREGRP32 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 32 } }
472 #define PREGRP33 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 33 } }
473 #define PREGRP34 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 34 } }
474 #define PREGRP35 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 35 } }
475 #define PREGRP36 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 36 } }
476 #define PREGRP37 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 37 } }
477 #define PREGRP38 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 38 } }
478 #define PREGRP39 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 39 } }
479 #define PREGRP40 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 40 } }
480 #define PREGRP41 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 41 } }
481 #define PREGRP42 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 42 } }
482 #define PREGRP43 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 43 } }
483 #define PREGRP44 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 44 } }
484 #define PREGRP45 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 45 } }
485 #define PREGRP46 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 46 } }
486 #define PREGRP47 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 47 } }
487 #define PREGRP48 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 48 } }
488 #define PREGRP49 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 49 } }
489 #define PREGRP50 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 50 } }
490 #define PREGRP51 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 51 } }
491 #define PREGRP52 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 52 } }
492 #define PREGRP53 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 53 } }
493 #define PREGRP54 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 54 } }
494 #define PREGRP55 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 55 } }
495 #define PREGRP56 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 56 } }
496 #define PREGRP57 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 57 } }
497 #define PREGRP58 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 58 } }
498 #define PREGRP59 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 59 } }
499 #define PREGRP60 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 60 } }
500 #define PREGRP61 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 61 } }
501 #define PREGRP62 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 62 } }
502 #define PREGRP63 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 63 } }
503 #define PREGRP64 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 64 } }
504 #define PREGRP65 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 65 } }
505 #define PREGRP66 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 66 } }
506 #define PREGRP67 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 67 } }
507 #define PREGRP68 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 68 } }
508 #define PREGRP69 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 69 } }
509 #define PREGRP70 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 70 } }
510 #define PREGRP71 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 71 } }
511 #define PREGRP72 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 72 } }
512 #define PREGRP73 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 73 } }
513 #define PREGRP74 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 74 } }
514 #define PREGRP75 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 75 } }
515 #define PREGRP76 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 76 } }
516 #define PREGRP77 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 77 } }
517 #define PREGRP78 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 78 } }
518 #define PREGRP79 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 79 } }
519 #define PREGRP80 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 80 } }
520 #define PREGRP81 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 81 } }
521 #define PREGRP82 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 82 } }
522 #define PREGRP83 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 83 } }
523 #define PREGRP84 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 84 } }
524 #define PREGRP85 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 85 } }
525 #define PREGRP86 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 86 } }
526 #define PREGRP87 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 87 } }
527 #define PREGRP88 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 88 } }
528 #define PREGRP89 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 89 } }
529 #define PREGRP90 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 90 } }
530 #define PREGRP91 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 91 } }
531 #define PREGRP92 NULL, { { NULL, USE_PREFIX_USER_TABLE }, { NULL, 92 } }
532
533
534 #define X86_64_0 NULL, { { NULL, X86_64_SPECIAL }, { NULL, 0 } }
535 #define X86_64_1 NULL, { { NULL, X86_64_SPECIAL }, { NULL, 1 } }
536 #define X86_64_2 NULL, { { NULL, X86_64_SPECIAL }, { NULL, 2 } }
537 #define X86_64_3 NULL, { { NULL, X86_64_SPECIAL }, { NULL, 3 } }
538
539 #define THREE_BYTE_0 NULL, { { NULL, IS_3BYTE_OPCODE }, { NULL, 0 } }
540 #define THREE_BYTE_1 NULL, { { NULL, IS_3BYTE_OPCODE }, { NULL, 1 } }
541
542 typedef void (*op_rtn) (int bytemode, int sizeflag);
543
544 struct dis386 {
545 const char *name;
546 struct
547 {
548 op_rtn rtn;
549 int bytemode;
550 } op[MAX_OPERANDS];
551 };
552
553 /* Upper case letters in the instruction names here are macros.
554 'A' => print 'b' if no register operands or suffix_always is true
555 'B' => print 'b' if suffix_always is true
556 'C' => print 's' or 'l' ('w' or 'd' in Intel mode) depending on operand
557 . size prefix
558 'D' => print 'w' if no register operands or 'w', 'l' or 'q', if
559 . suffix_always is true
560 'E' => print 'e' if 32-bit form of jcxz
561 'F' => print 'w' or 'l' depending on address size prefix (loop insns)
562 'G' => print 'w' or 'l' depending on operand size prefix (i/o insns)
563 'H' => print ",pt" or ",pn" branch hint
564 'I' => honor following macro letter even in Intel mode (implemented only
565 . for some of the macro letters)
566 'J' => print 'l'
567 'K' => print 'd' or 'q' if rex prefix is present.
568 'L' => print 'l' if suffix_always is true
569 'N' => print 'n' if instruction has no wait "prefix"
570 'O' => print 'd' or 'o' (or 'q' in Intel mode)
571 'P' => print 'w', 'l' or 'q' if instruction has an operand size prefix,
572 . or suffix_always is true. print 'q' if rex prefix is present.
573 'Q' => print 'w', 'l' or 'q' if no register operands or suffix_always
574 . is true
575 'R' => print 'w', 'l' or 'q' ('d' for 'l' and 'e' in Intel mode)
576 'S' => print 'w', 'l' or 'q' if suffix_always is true
577 'T' => print 'q' in 64bit mode and behave as 'P' otherwise
578 'U' => print 'q' in 64bit mode and behave as 'Q' otherwise
579 'V' => print 'q' in 64bit mode and behave as 'S' otherwise
580 'W' => print 'b', 'w' or 'l' ('d' in Intel mode)
581 'X' => print 's', 'd' depending on data16 prefix (for XMM)
582 'Y' => 'q' if instruction has an REX 64bit overwrite prefix
583 'Z' => print 'q' in 64bit mode and behave as 'L' otherwise
584
585 Many of the above letters print nothing in Intel mode. See "putop"
586 for the details.
587
588 Braces '{' and '}', and vertical bars '|', indicate alternative
589 mnemonic strings for AT&T, Intel, X86_64 AT&T, and X86_64 Intel
590 modes. In cases where there are only two alternatives, the X86_64
591 instruction is reserved, and "(bad)" is printed.
592 */
593
594 static const struct dis386 dis386[] = {
595 /* 00 */
596 { "addB", { Eb, Gb } },
597 { "addS", { Ev, Gv } },
598 { "addB", { Gb, Eb } },
599 { "addS", { Gv, Ev } },
600 { "addB", { AL, Ib } },
601 { "addS", { eAX, Iv } },
602 { "push{T|}", { es } },
603 { "pop{T|}", { es } },
604 /* 08 */
605 { "orB", { Eb, Gb } },
606 { "orS", { Ev, Gv } },
607 { "orB", { Gb, Eb } },
608 { "orS", { Gv, Ev } },
609 { "orB", { AL, Ib } },
610 { "orS", { eAX, Iv } },
611 { "push{T|}", { cs } },
612 { "(bad)", { XX } }, /* 0x0f extended opcode escape */
613 /* 10 */
614 { "adcB", { Eb, Gb } },
615 { "adcS", { Ev, Gv } },
616 { "adcB", { Gb, Eb } },
617 { "adcS", { Gv, Ev } },
618 { "adcB", { AL, Ib } },
619 { "adcS", { eAX, Iv } },
620 { "push{T|}", { ss } },
621 { "pop{T|}", { ss } },
622 /* 18 */
623 { "sbbB", { Eb, Gb } },
624 { "sbbS", { Ev, Gv } },
625 { "sbbB", { Gb, Eb } },
626 { "sbbS", { Gv, Ev } },
627 { "sbbB", { AL, Ib } },
628 { "sbbS", { eAX, Iv } },
629 { "push{T|}", { ds } },
630 { "pop{T|}", { ds } },
631 /* 20 */
632 { "andB", { Eb, Gb } },
633 { "andS", { Ev, Gv } },
634 { "andB", { Gb, Eb } },
635 { "andS", { Gv, Ev } },
636 { "andB", { AL, Ib } },
637 { "andS", { eAX, Iv } },
638 { "(bad)", { XX } }, /* SEG ES prefix */
639 { "daa{|}", { XX } },
640 /* 28 */
641 { "subB", { Eb, Gb } },
642 { "subS", { Ev, Gv } },
643 { "subB", { Gb, Eb } },
644 { "subS", { Gv, Ev } },
645 { "subB", { AL, Ib } },
646 { "subS", { eAX, Iv } },
647 { "(bad)", { XX } }, /* SEG CS prefix */
648 { "das{|}", { XX } },
649 /* 30 */
650 { "xorB", { Eb, Gb } },
651 { "xorS", { Ev, Gv } },
652 { "xorB", { Gb, Eb } },
653 { "xorS", { Gv, Ev } },
654 { "xorB", { AL, Ib } },
655 { "xorS", { eAX, Iv } },
656 { "(bad)", { XX } }, /* SEG SS prefix */
657 { "aaa{|}", { XX } },
658 /* 38 */
659 { "cmpB", { Eb, Gb } },
660 { "cmpS", { Ev, Gv } },
661 { "cmpB", { Gb, Eb } },
662 { "cmpS", { Gv, Ev } },
663 { "cmpB", { AL, Ib } },
664 { "cmpS", { eAX, Iv } },
665 { "(bad)", { XX } }, /* SEG DS prefix */
666 { "aas{|}", { XX } },
667 /* 40 */
668 { "inc{S|}", { RMeAX } },
669 { "inc{S|}", { RMeCX } },
670 { "inc{S|}", { RMeDX } },
671 { "inc{S|}", { RMeBX } },
672 { "inc{S|}", { RMeSP } },
673 { "inc{S|}", { RMeBP } },
674 { "inc{S|}", { RMeSI } },
675 { "inc{S|}", { RMeDI } },
676 /* 48 */
677 { "dec{S|}", { RMeAX } },
678 { "dec{S|}", { RMeCX } },
679 { "dec{S|}", { RMeDX } },
680 { "dec{S|}", { RMeBX } },
681 { "dec{S|}", { RMeSP } },
682 { "dec{S|}", { RMeBP } },
683 { "dec{S|}", { RMeSI } },
684 { "dec{S|}", { RMeDI } },
685 /* 50 */
686 { "pushV", { RMrAX } },
687 { "pushV", { RMrCX } },
688 { "pushV", { RMrDX } },
689 { "pushV", { RMrBX } },
690 { "pushV", { RMrSP } },
691 { "pushV", { RMrBP } },
692 { "pushV", { RMrSI } },
693 { "pushV", { RMrDI } },
694 /* 58 */
695 { "popV", { RMrAX } },
696 { "popV", { RMrCX } },
697 { "popV", { RMrDX } },
698 { "popV", { RMrBX } },
699 { "popV", { RMrSP } },
700 { "popV", { RMrBP } },
701 { "popV", { RMrSI } },
702 { "popV", { RMrDI } },
703 /* 60 */
704 { X86_64_0 },
705 { X86_64_1 },
706 { X86_64_2 },
707 { X86_64_3 },
708 { "(bad)", { XX } }, /* seg fs */
709 { "(bad)", { XX } }, /* seg gs */
710 { "(bad)", { XX } }, /* op size prefix */
711 { "(bad)", { XX } }, /* adr size prefix */
712 /* 68 */
713 { "pushT", { Iq } },
714 { "imulS", { Gv, Ev, Iv } },
715 { "pushT", { sIb } },
716 { "imulS", { Gv, Ev, sIb } },
717 { "ins{b||b|}", { Ybr, indirDX } },
718 { "ins{R||G|}", { Yzr, indirDX } },
719 { "outs{b||b|}", { indirDXr, Xb } },
720 { "outs{R||G|}", { indirDXr, Xz } },
721 /* 70 */
722 { "joH", { Jb, XX, cond_jump_flag } },
723 { "jnoH", { Jb, XX, cond_jump_flag } },
724 { "jbH", { Jb, XX, cond_jump_flag } },
725 { "jaeH", { Jb, XX, cond_jump_flag } },
726 { "jeH", { Jb, XX, cond_jump_flag } },
727 { "jneH", { Jb, XX, cond_jump_flag } },
728 { "jbeH", { Jb, XX, cond_jump_flag } },
729 { "jaH", { Jb, XX, cond_jump_flag } },
730 /* 78 */
731 { "jsH", { Jb, XX, cond_jump_flag } },
732 { "jnsH", { Jb, XX, cond_jump_flag } },
733 { "jpH", { Jb, XX, cond_jump_flag } },
734 { "jnpH", { Jb, XX, cond_jump_flag } },
735 { "jlH", { Jb, XX, cond_jump_flag } },
736 { "jgeH", { Jb, XX, cond_jump_flag } },
737 { "jleH", { Jb, XX, cond_jump_flag } },
738 { "jgH", { Jb, XX, cond_jump_flag } },
739 /* 80 */
740 { GRP1b },
741 { GRP1S },
742 { "(bad)", { XX } },
743 { GRP1Ss },
744 { "testB", { Eb, Gb } },
745 { "testS", { Ev, Gv } },
746 { "xchgB", { Eb, Gb } },
747 { "xchgS", { Ev, Gv } },
748 /* 88 */
749 { "movB", { Eb, Gb } },
750 { "movS", { Ev, Gv } },
751 { "movB", { Gb, Eb } },
752 { "movS", { Gv, Ev } },
753 { "movD", { Sv, Sw } },
754 { "leaS", { Gv, M } },
755 { "movD", { Sw, Sv } },
756 { GRP1a },
757 /* 90 */
758 { PREGRP38 },
759 { "xchgS", { RMeCX, eAX } },
760 { "xchgS", { RMeDX, eAX } },
761 { "xchgS", { RMeBX, eAX } },
762 { "xchgS", { RMeSP, eAX } },
763 { "xchgS", { RMeBP, eAX } },
764 { "xchgS", { RMeSI, eAX } },
765 { "xchgS", { RMeDI, eAX } },
766 /* 98 */
767 { "cW{t||t|}R", { XX } },
768 { "cR{t||t|}O", { XX } },
769 { "Jcall{T|}", { Ap } },
770 { "(bad)", { XX } }, /* fwait */
771 { "pushfT", { XX } },
772 { "popfT", { XX } },
773 { "sahf{|}", { XX } },
774 { "lahf{|}", { XX } },
775 /* a0 */
776 { "movB", { AL, Ob } },
777 { "movS", { eAX, Ov } },
778 { "movB", { Ob, AL } },
779 { "movS", { Ov, eAX } },
780 { "movs{b||b|}", { Ybr, Xb } },
781 { "movs{R||R|}", { Yvr, Xv } },
782 { "cmps{b||b|}", { Xb, Yb } },
783 { "cmps{R||R|}", { Xv, Yv } },
784 /* a8 */
785 { "testB", { AL, Ib } },
786 { "testS", { eAX, Iv } },
787 { "stosB", { Ybr, AL } },
788 { "stosS", { Yvr, eAX } },
789 { "lodsB", { ALr, Xb } },
790 { "lodsS", { eAXr, Xv } },
791 { "scasB", { AL, Yb } },
792 { "scasS", { eAX, Yv } },
793 /* b0 */
794 { "movB", { RMAL, Ib } },
795 { "movB", { RMCL, Ib } },
796 { "movB", { RMDL, Ib } },
797 { "movB", { RMBL, Ib } },
798 { "movB", { RMAH, Ib } },
799 { "movB", { RMCH, Ib } },
800 { "movB", { RMDH, Ib } },
801 { "movB", { RMBH, Ib } },
802 /* b8 */
803 { "movS", { RMeAX, Iv64 } },
804 { "movS", { RMeCX, Iv64 } },
805 { "movS", { RMeDX, Iv64 } },
806 { "movS", { RMeBX, Iv64 } },
807 { "movS", { RMeSP, Iv64 } },
808 { "movS", { RMeBP, Iv64 } },
809 { "movS", { RMeSI, Iv64 } },
810 { "movS", { RMeDI, Iv64 } },
811 /* c0 */
812 { GRP2b },
813 { GRP2S },
814 { "retT", { Iw } },
815 { "retT", { XX } },
816 { "les{S|}", { Gv, Mp } },
817 { "ldsS", { Gv, Mp } },
818 { GRP11_C6 },
819 { GRP11_C7 },
820 /* c8 */
821 { "enterT", { Iw, Ib } },
822 { "leaveT", { XX } },
823 { "lretP", { Iw } },
824 { "lretP", { XX } },
825 { "int3", { XX } },
826 { "int", { Ib } },
827 { "into{|}", { XX } },
828 { "iretP", { XX } },
829 /* d0 */
830 { GRP2b_one },
831 { GRP2S_one },
832 { GRP2b_cl },
833 { GRP2S_cl },
834 { "aam{|}", { sIb } },
835 { "aad{|}", { sIb } },
836 { "(bad)", { XX } },
837 { "xlat", { DSBX } },
838 /* d8 */
839 { FLOAT },
840 { FLOAT },
841 { FLOAT },
842 { FLOAT },
843 { FLOAT },
844 { FLOAT },
845 { FLOAT },
846 { FLOAT },
847 /* e0 */
848 { "loopneFH", { Jb, XX, loop_jcxz_flag } },
849 { "loopeFH", { Jb, XX, loop_jcxz_flag } },
850 { "loopFH", { Jb, XX, loop_jcxz_flag } },
851 { "jEcxzH", { Jb, XX, loop_jcxz_flag } },
852 { "inB", { AL, Ib } },
853 { "inG", { zAX, Ib } },
854 { "outB", { Ib, AL } },
855 { "outG", { Ib, zAX } },
856 /* e8 */
857 { "callT", { Jv } },
858 { "jmpT", { Jv } },
859 { "Jjmp{T|}", { Ap } },
860 { "jmp", { Jb } },
861 { "inB", { AL, indirDX } },
862 { "inG", { zAX, indirDX } },
863 { "outB", { indirDX, AL } },
864 { "outG", { indirDX, zAX } },
865 /* f0 */
866 { "(bad)", { XX } }, /* lock prefix */
867 { "icebp", { XX } },
868 { "(bad)", { XX } }, /* repne */
869 { "(bad)", { XX } }, /* repz */
870 { "hlt", { XX } },
871 { "cmc", { XX } },
872 { GRP3b },
873 { GRP3S },
874 /* f8 */
875 { "clc", { XX } },
876 { "stc", { XX } },
877 { "cli", { XX } },
878 { "sti", { XX } },
879 { "cld", { XX } },
880 { "std", { XX } },
881 { GRP4 },
882 { GRP5 },
883 };
884
885 static const struct dis386 dis386_twobyte[] = {
886 /* 00 */
887 { GRP6 },
888 { GRP7 },
889 { "larS", { Gv, Ew } },
890 { "lslS", { Gv, Ew } },
891 { "(bad)", { XX } },
892 { "syscall", { XX } },
893 { "clts", { XX } },
894 { "sysretP", { XX } },
895 /* 08 */
896 { "invd", { XX } },
897 { "wbinvd", { XX } },
898 { "(bad)", { XX } },
899 { "ud2a", { XX } },
900 { "(bad)", { XX } },
901 { GRPAMD },
902 { "femms", { XX } },
903 { "", { MX, EM, OPSUF } }, /* See OP_3DNowSuffix. */
904 /* 10 */
905 { PREGRP8 },
906 { PREGRP9 },
907 { PREGRP30 },
908 { "movlpX", { EX, XM, { SIMD_Fixup, 'h' } } },
909 { "unpcklpX", { XM, EX } },
910 { "unpckhpX", { XM, EX } },
911 { PREGRP31 },
912 { "movhpX", { EX, XM, { SIMD_Fixup, 'l' } } },
913 /* 18 */
914 { GRP16 },
915 { "(bad)", { XX } },
916 { "(bad)", { XX } },
917 { "(bad)", { XX } },
918 { "(bad)", { XX } },
919 { "(bad)", { XX } },
920 { "(bad)", { XX } },
921 { "nopQ", { Ev } },
922 /* 20 */
923 { "movZ", { Rm, Cm } },
924 { "movZ", { Rm, Dm } },
925 { "movZ", { Cm, Rm } },
926 { "movZ", { Dm, Rm } },
927 { "movL", { Rd, Td } },
928 { "(bad)", { XX } },
929 { "movL", { Td, Rd } },
930 { "(bad)", { XX } },
931 /* 28 */
932 { "movapX", { XM, EX } },
933 { "movapX", { EX, XM } },
934 { PREGRP2 },
935 { PREGRP33 },
936 { PREGRP4 },
937 { PREGRP3 },
938 { "ucomisX", { XM,EX } },
939 { "comisX", { XM,EX } },
940 /* 30 */
941 { "wrmsr", { XX } },
942 { "rdtsc", { XX } },
943 { "rdmsr", { XX } },
944 { "rdpmc", { XX } },
945 { "sysenter", { XX } },
946 { "sysexit", { XX } },
947 { "(bad)", { XX } },
948 { "(bad)", { XX } },
949 /* 38 */
950 { THREE_BYTE_0 },
951 { "(bad)", { XX } },
952 { THREE_BYTE_1 },
953 { "(bad)", { XX } },
954 { "(bad)", { XX } },
955 { "(bad)", { XX } },
956 { "(bad)", { XX } },
957 { "(bad)", { XX } },
958 /* 40 */
959 { "cmovo", { Gv, Ev } },
960 { "cmovno", { Gv, Ev } },
961 { "cmovb", { Gv, Ev } },
962 { "cmovae", { Gv, Ev } },
963 { "cmove", { Gv, Ev } },
964 { "cmovne", { Gv, Ev } },
965 { "cmovbe", { Gv, Ev } },
966 { "cmova", { Gv, Ev } },
967 /* 48 */
968 { "cmovs", { Gv, Ev } },
969 { "cmovns", { Gv, Ev } },
970 { "cmovp", { Gv, Ev } },
971 { "cmovnp", { Gv, Ev } },
972 { "cmovl", { Gv, Ev } },
973 { "cmovge", { Gv, Ev } },
974 { "cmovle", { Gv, Ev } },
975 { "cmovg", { Gv, Ev } },
976 /* 50 */
977 { "movmskpX", { Gdq, XS } },
978 { PREGRP13 },
979 { PREGRP12 },
980 { PREGRP11 },
981 { "andpX", { XM, EX } },
982 { "andnpX", { XM, EX } },
983 { "orpX", { XM, EX } },
984 { "xorpX", { XM, EX } },
985 /* 58 */
986 { PREGRP0 },
987 { PREGRP10 },
988 { PREGRP17 },
989 { PREGRP16 },
990 { PREGRP14 },
991 { PREGRP7 },
992 { PREGRP5 },
993 { PREGRP6 },
994 /* 60 */
995 { "punpcklbw", { MX, EM } },
996 { "punpcklwd", { MX, EM } },
997 { "punpckldq", { MX, EM } },
998 { "packsswb", { MX, EM } },
999 { "pcmpgtb", { MX, EM } },
1000 { "pcmpgtw", { MX, EM } },
1001 { "pcmpgtd", { MX, EM } },
1002 { "packuswb", { MX, EM } },
1003 /* 68 */
1004 { "punpckhbw", { MX, EM } },
1005 { "punpckhwd", { MX, EM } },
1006 { "punpckhdq", { MX, EM } },
1007 { "packssdw", { MX, EM } },
1008 { PREGRP26 },
1009 { PREGRP24 },
1010 { "movd", { MX, Edq } },
1011 { PREGRP19 },
1012 /* 70 */
1013 { PREGRP22 },
1014 { GRP12 },
1015 { GRP13 },
1016 { GRP14 },
1017 { "pcmpeqb", { MX, EM } },
1018 { "pcmpeqw", { MX, EM } },
1019 { "pcmpeqd", { MX, EM } },
1020 { "emms", { XX } },
1021 /* 78 */
1022 { PREGRP34 },
1023 { PREGRP35 },
1024 { "(bad)", { XX } },
1025 { "(bad)", { XX } },
1026 { PREGRP28 },
1027 { PREGRP29 },
1028 { PREGRP23 },
1029 { PREGRP20 },
1030 /* 80 */
1031 { "joH", { Jv, XX, cond_jump_flag } },
1032 { "jnoH", { Jv, XX, cond_jump_flag } },
1033 { "jbH", { Jv, XX, cond_jump_flag } },
1034 { "jaeH", { Jv, XX, cond_jump_flag } },
1035 { "jeH", { Jv, XX, cond_jump_flag } },
1036 { "jneH", { Jv, XX, cond_jump_flag } },
1037 { "jbeH", { Jv, XX, cond_jump_flag } },
1038 { "jaH", { Jv, XX, cond_jump_flag } },
1039 /* 88 */
1040 { "jsH", { Jv, XX, cond_jump_flag } },
1041 { "jnsH", { Jv, XX, cond_jump_flag } },
1042 { "jpH", { Jv, XX, cond_jump_flag } },
1043 { "jnpH", { Jv, XX, cond_jump_flag } },
1044 { "jlH", { Jv, XX, cond_jump_flag } },
1045 { "jgeH", { Jv, XX, cond_jump_flag } },
1046 { "jleH", { Jv, XX, cond_jump_flag } },
1047 { "jgH", { Jv, XX, cond_jump_flag } },
1048 /* 90 */
1049 { "seto", { Eb } },
1050 { "setno", { Eb } },
1051 { "setb", { Eb } },
1052 { "setae", { Eb } },
1053 { "sete", { Eb } },
1054 { "setne", { Eb } },
1055 { "setbe", { Eb } },
1056 { "seta", { Eb } },
1057 /* 98 */
1058 { "sets", { Eb } },
1059 { "setns", { Eb } },
1060 { "setp", { Eb } },
1061 { "setnp", { Eb } },
1062 { "setl", { Eb } },
1063 { "setge", { Eb } },
1064 { "setle", { Eb } },
1065 { "setg", { Eb } },
1066 /* a0 */
1067 { "pushT", { fs } },
1068 { "popT", { fs } },
1069 { "cpuid", { XX } },
1070 { "btS", { Ev, Gv } },
1071 { "shldS", { Ev, Gv, Ib } },
1072 { "shldS", { Ev, Gv, CL } },
1073 { GRPPADLCK2 },
1074 { GRPPADLCK1 },
1075 /* a8 */
1076 { "pushT", { gs } },
1077 { "popT", { gs } },
1078 { "rsm", { XX } },
1079 { "btsS", { Ev, Gv } },
1080 { "shrdS", { Ev, Gv, Ib } },
1081 { "shrdS", { Ev, Gv, CL } },
1082 { GRP15 },
1083 { "imulS", { Gv, Ev } },
1084 /* b0 */
1085 { "cmpxchgB", { Eb, Gb } },
1086 { "cmpxchgS", { Ev, Gv } },
1087 { "lssS", { Gv, Mp } },
1088 { "btrS", { Ev, Gv } },
1089 { "lfsS", { Gv, Mp } },
1090 { "lgsS", { Gv, Mp } },
1091 { "movz{bR|x|bR|x}", { Gv, Eb } },
1092 { "movz{wR|x|wR|x}", { Gv, Ew } }, /* yes, there really is movzww ! */
1093 /* b8 */
1094 { PREGRP37 },
1095 { "ud2b", { XX } },
1096 { GRP8 },
1097 { "btcS", { Ev, Gv } },
1098 { "bsfS", { Gv, Ev } },
1099 { PREGRP36 },
1100 { "movs{bR|x|bR|x}", { Gv, Eb } },
1101 { "movs{wR|x|wR|x}", { Gv, Ew } }, /* yes, there really is movsww ! */
1102 /* c0 */
1103 { "xaddB", { Eb, Gb } },
1104 { "xaddS", { Ev, Gv } },
1105 { PREGRP1 },
1106 { "movntiS", { Ev, Gv } },
1107 { "pinsrw", { MX, Edqw, Ib } },
1108 { "pextrw", { Gdq, MS, Ib } },
1109 { "shufpX", { XM, EX, Ib } },
1110 { GRP9 },
1111 /* c8 */
1112 { "bswap", { RMeAX } },
1113 { "bswap", { RMeCX } },
1114 { "bswap", { RMeDX } },
1115 { "bswap", { RMeBX } },
1116 { "bswap", { RMeSP } },
1117 { "bswap", { RMeBP } },
1118 { "bswap", { RMeSI } },
1119 { "bswap", { RMeDI } },
1120 /* d0 */
1121 { PREGRP27 },
1122 { "psrlw", { MX, EM } },
1123 { "psrld", { MX, EM } },
1124 { "psrlq", { MX, EM } },
1125 { "paddq", { MX, EM } },
1126 { "pmullw", { MX, EM } },
1127 { PREGRP21 },
1128 { "pmovmskb", { Gdq, MS } },
1129 /* d8 */
1130 { "psubusb", { MX, EM } },
1131 { "psubusw", { MX, EM } },
1132 { "pminub", { MX, EM } },
1133 { "pand", { MX, EM } },
1134 { "paddusb", { MX, EM } },
1135 { "paddusw", { MX, EM } },
1136 { "pmaxub", { MX, EM } },
1137 { "pandn", { MX, EM } },
1138 /* e0 */
1139 { "pavgb", { MX, EM } },
1140 { "psraw", { MX, EM } },
1141 { "psrad", { MX, EM } },
1142 { "pavgw", { MX, EM } },
1143 { "pmulhuw", { MX, EM } },
1144 { "pmulhw", { MX, EM } },
1145 { PREGRP15 },
1146 { PREGRP25 },
1147 /* e8 */
1148 { "psubsb", { MX, EM } },
1149 { "psubsw", { MX, EM } },
1150 { "pminsw", { MX, EM } },
1151 { "por", { MX, EM } },
1152 { "paddsb", { MX, EM } },
1153 { "paddsw", { MX, EM } },
1154 { "pmaxsw", { MX, EM } },
1155 { "pxor", { MX, EM } },
1156 /* f0 */
1157 { PREGRP32 },
1158 { "psllw", { MX, EM } },
1159 { "pslld", { MX, EM } },
1160 { "psllq", { MX, EM } },
1161 { "pmuludq", { MX, EM } },
1162 { "pmaddwd", { MX, EM } },
1163 { "psadbw", { MX, EM } },
1164 { PREGRP18 },
1165 /* f8 */
1166 { "psubb", { MX, EM } },
1167 { "psubw", { MX, EM } },
1168 { "psubd", { MX, EM } },
1169 { "psubq", { MX, EM } },
1170 { "paddb", { MX, EM } },
1171 { "paddw", { MX, EM } },
1172 { "paddd", { MX, EM } },
1173 { "(bad)", { XX } },
1174 };
1175
1176 static const unsigned char onebyte_has_modrm[256] = {
1177 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1178 /* ------------------------------- */
1179 /* 00 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0, /* 00 */
1180 /* 10 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0, /* 10 */
1181 /* 20 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0, /* 20 */
1182 /* 30 */ 1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0, /* 30 */
1183 /* 40 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 40 */
1184 /* 50 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 50 */
1185 /* 60 */ 0,0,1,1,0,0,0,0,0,1,0,1,0,0,0,0, /* 60 */
1186 /* 70 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 70 */
1187 /* 80 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 80 */
1188 /* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 90 */
1189 /* a0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* a0 */
1190 /* b0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* b0 */
1191 /* c0 */ 1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0, /* c0 */
1192 /* d0 */ 1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1, /* d0 */
1193 /* e0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* e0 */
1194 /* f0 */ 0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1 /* f0 */
1195 /* ------------------------------- */
1196 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1197 };
1198
1199 static const unsigned char twobyte_has_modrm[256] = {
1200 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1201 /* ------------------------------- */
1202 /* 00 */ 1,1,1,1,0,0,0,0,0,0,0,0,0,1,0,1, /* 0f */
1203 /* 10 */ 1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1, /* 1f */
1204 /* 20 */ 1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1, /* 2f */
1205 /* 30 */ 0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0, /* 3f */
1206 /* 40 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 4f */
1207 /* 50 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 5f */
1208 /* 60 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 6f */
1209 /* 70 */ 1,1,1,1,1,1,1,0,1,1,0,0,1,1,1,1, /* 7f */
1210 /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */
1211 /* 90 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 9f */
1212 /* a0 */ 0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1, /* af */
1213 /* b0 */ 1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1, /* bf */
1214 /* c0 */ 1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, /* cf */
1215 /* d0 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* df */
1216 /* e0 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* ef */
1217 /* f0 */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 /* ff */
1218 /* ------------------------------- */
1219 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1220 };
1221
1222 static const unsigned char twobyte_uses_DATA_prefix[256] = {
1223 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1224 /* ------------------------------- */
1225 /* 00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0f */
1226 /* 10 */ 1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0, /* 1f */
1227 /* 20 */ 0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0, /* 2f */
1228 /* 30 */ 0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0, /* 3f */
1229 /* 40 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 4f */
1230 /* 50 */ 0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1, /* 5f */
1231 /* 60 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1, /* 6f */
1232 /* 70 */ 1,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1, /* 7f */
1233 /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */
1234 /* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 9f */
1235 /* a0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* af */
1236 /* b0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* bf */
1237 /* c0 */ 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, /* cf */
1238 /* d0 */ 1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0, /* df */
1239 /* e0 */ 0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0, /* ef */
1240 /* f0 */ 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0 /* ff */
1241 /* ------------------------------- */
1242 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1243 };
1244
1245 static const unsigned char twobyte_uses_REPNZ_prefix[256] = {
1246 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1247 /* ------------------------------- */
1248 /* 00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0f */
1249 /* 10 */ 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 1f */
1250 /* 20 */ 0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0, /* 2f */
1251 /* 30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 3f */
1252 /* 40 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 4f */
1253 /* 50 */ 0,1,0,0,0,0,0,0,1,1,1,0,1,1,1,1, /* 5f */
1254 /* 60 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 6f */
1255 /* 70 */ 1,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0, /* 7f */
1256 /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */
1257 /* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 9f */
1258 /* a0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* af */
1259 /* b0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* bf */
1260 /* c0 */ 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, /* cf */
1261 /* d0 */ 1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0, /* df */
1262 /* e0 */ 0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0, /* ef */
1263 /* f0 */ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ff */
1264 /* ------------------------------- */
1265 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1266 };
1267
1268 static const unsigned char twobyte_uses_REPZ_prefix[256] = {
1269 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1270 /* ------------------------------- */
1271 /* 00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0f */
1272 /* 10 */ 1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0, /* 1f */
1273 /* 20 */ 0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0, /* 2f */
1274 /* 30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 3f */
1275 /* 40 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 4f */
1276 /* 50 */ 0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1, /* 5f */
1277 /* 60 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, /* 6f */
1278 /* 70 */ 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1, /* 7f */
1279 /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */
1280 /* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 9f */
1281 /* a0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* af */
1282 /* b0 */ 0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0, /* bf */
1283 /* c0 */ 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, /* cf */
1284 /* d0 */ 0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0, /* df */
1285 /* e0 */ 0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0, /* ef */
1286 /* f0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ff */
1287 /* ------------------------------- */
1288 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1289 };
1290
1291 /* This is used to determine if opcode 0f 38 XX uses DATA prefix. */
1292 static const unsigned char threebyte_0x38_uses_DATA_prefix[256] = {
1293 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1294 /* ------------------------------- */
1295 /* 00 */ 1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0, /* 0f */
1296 /* 10 */ 0,0,0,0,1,1,0,1,0,0,0,0,1,1,1,0, /* 1f */
1297 /* 20 */ 1,1,1,1,1,1,0,0,1,1,1,1,0,0,0,0, /* 2f */
1298 /* 30 */ 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1, /* 3f */
1299 /* 40 */ 1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 4f */
1300 /* 50 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 5f */
1301 /* 60 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 6f */
1302 /* 70 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 7f */
1303 /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */
1304 /* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 9f */
1305 /* a0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* af */
1306 /* b0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* bf */
1307 /* c0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* cf */
1308 /* d0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* df */
1309 /* e0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ef */
1310 /* f0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ff */
1311 /* ------------------------------- */
1312 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1313 };
1314
1315 /* This is used to determine if opcode 0f 38 XX uses REPNZ prefix. */
1316 static const unsigned char threebyte_0x38_uses_REPNZ_prefix[256] = {
1317 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1318 /* ------------------------------- */
1319 /* 00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0f */
1320 /* 10 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 1f */
1321 /* 20 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 2f */
1322 /* 30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 3f */
1323 /* 40 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 4f */
1324 /* 50 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 5f */
1325 /* 60 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 6f */
1326 /* 70 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 7f */
1327 /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */
1328 /* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 9f */
1329 /* a0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* af */
1330 /* b0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* bf */
1331 /* c0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* cf */
1332 /* d0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* df */
1333 /* e0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ef */
1334 /* f0 */ 1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ff */
1335 /* ------------------------------- */
1336 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1337 };
1338
1339 /* This is used to determine if opcode 0f 38 XX uses REPZ prefix. */
1340 static const unsigned char threebyte_0x38_uses_REPZ_prefix[256] = {
1341 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1342 /* ------------------------------- */
1343 /* 00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0f */
1344 /* 10 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 1f */
1345 /* 20 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 2f */
1346 /* 30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 3f */
1347 /* 40 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 4f */
1348 /* 50 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 5f */
1349 /* 60 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 6f */
1350 /* 70 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 7f */
1351 /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */
1352 /* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 9f */
1353 /* a0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* af */
1354 /* b0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* bf */
1355 /* c0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* cf */
1356 /* d0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* df */
1357 /* e0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ef */
1358 /* f0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ff */
1359 /* ------------------------------- */
1360 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1361 };
1362
1363 /* This is used to determine if opcode 0f 3a XX uses DATA prefix. */
1364 static const unsigned char threebyte_0x3a_uses_DATA_prefix[256] = {
1365 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1366 /* ------------------------------- */
1367 /* 00 */ 0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1, /* 0f */
1368 /* 10 */ 0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0, /* 1f */
1369 /* 20 */ 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 2f */
1370 /* 30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 3f */
1371 /* 40 */ 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 4f */
1372 /* 50 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 5f */
1373 /* 60 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 6f */
1374 /* 70 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 7f */
1375 /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */
1376 /* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 9f */
1377 /* a0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* af */
1378 /* b0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* bf */
1379 /* c0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* cf */
1380 /* d0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* df */
1381 /* e0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ef */
1382 /* f0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ff */
1383 /* ------------------------------- */
1384 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1385 };
1386
1387 /* This is used to determine if opcode 0f 3a XX uses REPNZ prefix. */
1388 static const unsigned char threebyte_0x3a_uses_REPNZ_prefix[256] = {
1389 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1390 /* ------------------------------- */
1391 /* 00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0f */
1392 /* 10 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 1f */
1393 /* 20 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 2f */
1394 /* 30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 3f */
1395 /* 40 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 4f */
1396 /* 50 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 5f */
1397 /* 60 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 6f */
1398 /* 70 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 7f */
1399 /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */
1400 /* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 9f */
1401 /* a0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* af */
1402 /* b0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* bf */
1403 /* c0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* cf */
1404 /* d0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* df */
1405 /* e0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ef */
1406 /* f0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ff */
1407 /* ------------------------------- */
1408 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1409 };
1410
1411 /* This is used to determine if opcode 0f 3a XX uses REPZ prefix. */
1412 static const unsigned char threebyte_0x3a_uses_REPZ_prefix[256] = {
1413 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1414 /* ------------------------------- */
1415 /* 00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0f */
1416 /* 10 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 1f */
1417 /* 20 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 2f */
1418 /* 30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 3f */
1419 /* 40 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 4f */
1420 /* 50 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 5f */
1421 /* 60 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 6f */
1422 /* 70 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 7f */
1423 /* 80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 8f */
1424 /* 90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 9f */
1425 /* a0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* af */
1426 /* b0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* bf */
1427 /* c0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* cf */
1428 /* d0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* df */
1429 /* e0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ef */
1430 /* f0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ff */
1431 /* ------------------------------- */
1432 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
1433 };
1434
1435 static char obuf[100];
1436 static char *obufp;
1437 static char scratchbuf[100];
1438 static unsigned char *start_codep;
1439 static unsigned char *insn_codep;
1440 static unsigned char *codep;
1441 static disassemble_info *the_info;
1442 static struct
1443 {
1444 int mod;
1445 int rm;
1446 int reg;
1447 }
1448 modrm;
1449 static unsigned char need_modrm;
1450
1451 /* If we are accessing mod/rm/reg without need_modrm set, then the
1452 values are stale. Hitting this abort likely indicates that you
1453 need to update onebyte_has_modrm or twobyte_has_modrm. */
1454 #define MODRM_CHECK if (!need_modrm) abort ()
1455
1456 static const char **names64;
1457 static const char **names32;
1458 static const char **names16;
1459 static const char **names8;
1460 static const char **names8rex;
1461 static const char **names_seg;
1462 static const char **index16;
1463
1464 static const char *intel_names64[] = {
1465 "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
1466 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
1467 };
1468 static const char *intel_names32[] = {
1469 "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
1470 "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d"
1471 };
1472 static const char *intel_names16[] = {
1473 "ax", "cx", "dx", "bx", "sp", "bp", "si", "di",
1474 "r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w"
1475 };
1476 static const char *intel_names8[] = {
1477 "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh",
1478 };
1479 static const char *intel_names8rex[] = {
1480 "al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil",
1481 "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b"
1482 };
1483 static const char *intel_names_seg[] = {
1484 "es", "cs", "ss", "ds", "fs", "gs", "?", "?",
1485 };
1486 static const char *intel_index16[] = {
1487 "bx+si", "bx+di", "bp+si", "bp+di", "si", "di", "bp", "bx"
1488 };
1489
1490 static const char *att_names64[] = {
1491 "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
1492 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15"
1493 };
1494 static const char *att_names32[] = {
1495 "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
1496 "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d"
1497 };
1498 static const char *att_names16[] = {
1499 "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di",
1500 "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w"
1501 };
1502 static const char *att_names8[] = {
1503 "%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh",
1504 };
1505 static const char *att_names8rex[] = {
1506 "%al", "%cl", "%dl", "%bl", "%spl", "%bpl", "%sil", "%dil",
1507 "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b"
1508 };
1509 static const char *att_names_seg[] = {
1510 "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "%?", "%?",
1511 };
1512 static const char *att_index16[] = {
1513 "%bx,%si", "%bx,%di", "%bp,%si", "%bp,%di", "%si", "%di", "%bp", "%bx"
1514 };
1515
1516 static const struct dis386 grps[][8] = {
1517 /* GRP1a */
1518 {
1519 { "popU", { stackEv } },
1520 { "(bad)", { XX } },
1521 { "(bad)", { XX } },
1522 { "(bad)", { XX } },
1523 { "(bad)", { XX } },
1524 { "(bad)", { XX } },
1525 { "(bad)", { XX } },
1526 { "(bad)", { XX } },
1527 },
1528 /* GRP1b */
1529 {
1530 { "addA", { Eb, Ib } },
1531 { "orA", { Eb, Ib } },
1532 { "adcA", { Eb, Ib } },
1533 { "sbbA", { Eb, Ib } },
1534 { "andA", { Eb, Ib } },
1535 { "subA", { Eb, Ib } },
1536 { "xorA", { Eb, Ib } },
1537 { "cmpA", { Eb, Ib } },
1538 },
1539 /* GRP1S */
1540 {
1541 { "addQ", { Ev, Iv } },
1542 { "orQ", { Ev, Iv } },
1543 { "adcQ", { Ev, Iv } },
1544 { "sbbQ", { Ev, Iv } },
1545 { "andQ", { Ev, Iv } },
1546 { "subQ", { Ev, Iv } },
1547 { "xorQ", { Ev, Iv } },
1548 { "cmpQ", { Ev, Iv } },
1549 },
1550 /* GRP1Ss */
1551 {
1552 { "addQ", { Ev, sIb } },
1553 { "orQ", { Ev, sIb } },
1554 { "adcQ", { Ev, sIb } },
1555 { "sbbQ", { Ev, sIb } },
1556 { "andQ", { Ev, sIb } },
1557 { "subQ", { Ev, sIb } },
1558 { "xorQ", { Ev, sIb } },
1559 { "cmpQ", { Ev, sIb } },
1560 },
1561 /* GRP2b */
1562 {
1563 { "rolA", { Eb, Ib } },
1564 { "rorA", { Eb, Ib } },
1565 { "rclA", { Eb, Ib } },
1566 { "rcrA", { Eb, Ib } },
1567 { "shlA", { Eb, Ib } },
1568 { "shrA", { Eb, Ib } },
1569 { "(bad)", { XX } },
1570 { "sarA", { Eb, Ib } },
1571 },
1572 /* GRP2S */
1573 {
1574 { "rolQ", { Ev, Ib } },
1575 { "rorQ", { Ev, Ib } },
1576 { "rclQ", { Ev, Ib } },
1577 { "rcrQ", { Ev, Ib } },
1578 { "shlQ", { Ev, Ib } },
1579 { "shrQ", { Ev, Ib } },
1580 { "(bad)", { XX } },
1581 { "sarQ", { Ev, Ib } },
1582 },
1583 /* GRP2b_one */
1584 {
1585 { "rolA", { Eb, I1 } },
1586 { "rorA", { Eb, I1 } },
1587 { "rclA", { Eb, I1 } },
1588 { "rcrA", { Eb, I1 } },
1589 { "shlA", { Eb, I1 } },
1590 { "shrA", { Eb, I1 } },
1591 { "(bad)", { XX } },
1592 { "sarA", { Eb, I1 } },
1593 },
1594 /* GRP2S_one */
1595 {
1596 { "rolQ", { Ev, I1 } },
1597 { "rorQ", { Ev, I1 } },
1598 { "rclQ", { Ev, I1 } },
1599 { "rcrQ", { Ev, I1 } },
1600 { "shlQ", { Ev, I1 } },
1601 { "shrQ", { Ev, I1 } },
1602 { "(bad)", { XX } },
1603 { "sarQ", { Ev, I1 } },
1604 },
1605 /* GRP2b_cl */
1606 {
1607 { "rolA", { Eb, CL } },
1608 { "rorA", { Eb, CL } },
1609 { "rclA", { Eb, CL } },
1610 { "rcrA", { Eb, CL } },
1611 { "shlA", { Eb, CL } },
1612 { "shrA", { Eb, CL } },
1613 { "(bad)", { XX } },
1614 { "sarA", { Eb, CL } },
1615 },
1616 /* GRP2S_cl */
1617 {
1618 { "rolQ", { Ev, CL } },
1619 { "rorQ", { Ev, CL } },
1620 { "rclQ", { Ev, CL } },
1621 { "rcrQ", { Ev, CL } },
1622 { "shlQ", { Ev, CL } },
1623 { "shrQ", { Ev, CL } },
1624 { "(bad)", { XX } },
1625 { "sarQ", { Ev, CL } },
1626 },
1627 /* GRP3b */
1628 {
1629 { "testA", { Eb, Ib } },
1630 { "(bad)", { Eb } },
1631 { "notA", { Eb } },
1632 { "negA", { Eb } },
1633 { "mulA", { Eb } }, /* Don't print the implicit %al register, */
1634 { "imulA", { Eb } }, /* to distinguish these opcodes from other */
1635 { "divA", { Eb } }, /* mul/imul opcodes. Do the same for div */
1636 { "idivA", { Eb } }, /* and idiv for consistency. */
1637 },
1638 /* GRP3S */
1639 {
1640 { "testQ", { Ev, Iv } },
1641 { "(bad)", { XX } },
1642 { "notQ", { Ev } },
1643 { "negQ", { Ev } },
1644 { "mulQ", { Ev } }, /* Don't print the implicit register. */
1645 { "imulQ", { Ev } },
1646 { "divQ", { Ev } },
1647 { "idivQ", { Ev } },
1648 },
1649 /* GRP4 */
1650 {
1651 { "incA", { Eb } },
1652 { "decA", { Eb } },
1653 { "(bad)", { XX } },
1654 { "(bad)", { XX } },
1655 { "(bad)", { XX } },
1656 { "(bad)", { XX } },
1657 { "(bad)", { XX } },
1658 { "(bad)", { XX } },
1659 },
1660 /* GRP5 */
1661 {
1662 { "incQ", { Ev } },
1663 { "decQ", { Ev } },
1664 { "callT", { indirEv } },
1665 { "JcallT", { indirEp } },
1666 { "jmpT", { indirEv } },
1667 { "JjmpT", { indirEp } },
1668 { "pushU", { stackEv } },
1669 { "(bad)", { XX } },
1670 },
1671 /* GRP6 */
1672 {
1673 { "sldtD", { Sv } },
1674 { "strD", { Sv } },
1675 { "lldt", { Ew } },
1676 { "ltr", { Ew } },
1677 { "verr", { Ew } },
1678 { "verw", { Ew } },
1679 { "(bad)", { XX } },
1680 { "(bad)", { XX } },
1681 },
1682 /* GRP7 */
1683 {
1684 { "sgdt{Q|IQ||}", { { VMX_Fixup, 0 } } },
1685 { "sidt{Q|IQ||}", { { PNI_Fixup, 0 } } },
1686 { "lgdt{Q|Q||}", { M } },
1687 { "lidt{Q|Q||}", { { SVME_Fixup, 0 } } },
1688 { "smswD", { Sv } },
1689 { "(bad)", { XX } },
1690 { "lmsw", { Ew } },
1691 { "invlpg", { { INVLPG_Fixup, w_mode } } },
1692 },
1693 /* GRP8 */
1694 {
1695 { "(bad)", { XX } },
1696 { "(bad)", { XX } },
1697 { "(bad)", { XX } },
1698 { "(bad)", { XX } },
1699 { "btQ", { Ev, Ib } },
1700 { "btsQ", { Ev, Ib } },
1701 { "btrQ", { Ev, Ib } },
1702 { "btcQ", { Ev, Ib } },
1703 },
1704 /* GRP9 */
1705 {
1706 { "(bad)", { XX } },
1707 { "cmpxchg8b", { { CMPXCHG8B_Fixup, q_mode } } },
1708 { "(bad)", { XX } },
1709 { "(bad)", { XX } },
1710 { "(bad)", { XX } },
1711 { "(bad)", { XX } },
1712 { "", { VM } }, /* See OP_VMX. */
1713 { "vmptrst", { Mq } },
1714 },
1715 /* GRP11_C6 */
1716 {
1717 { "movA", { Eb, Ib } },
1718 { "(bad)", { XX } },
1719 { "(bad)", { XX } },
1720 { "(bad)", { XX } },
1721 { "(bad)", { XX } },
1722 { "(bad)", { XX } },
1723 { "(bad)", { XX } },
1724 { "(bad)", { XX } },
1725 },
1726 /* GRP11_C7 */
1727 {
1728 { "movQ", { Ev, Iv } },
1729 { "(bad)", { XX } },
1730 { "(bad)", { XX } },
1731 { "(bad)", { XX } },
1732 { "(bad)", { XX } },
1733 { "(bad)", { XX } },
1734 { "(bad)", { XX } },
1735 { "(bad)", { XX } },
1736 },
1737 /* GRP12 */
1738 {
1739 { "(bad)", { XX } },
1740 { "(bad)", { XX } },
1741 { "psrlw", { MS, Ib } },
1742 { "(bad)", { XX } },
1743 { "psraw", { MS, Ib } },
1744 { "(bad)", { XX } },
1745 { "psllw", { MS, Ib } },
1746 { "(bad)", { XX } },
1747 },
1748 /* GRP13 */
1749 {
1750 { "(bad)", { XX } },
1751 { "(bad)", { XX } },
1752 { "psrld", { MS, Ib } },
1753 { "(bad)", { XX } },
1754 { "psrad", { MS, Ib } },
1755 { "(bad)", { XX } },
1756 { "pslld", { MS, Ib } },
1757 { "(bad)", { XX } },
1758 },
1759 /* GRP14 */
1760 {
1761 { "(bad)", { XX } },
1762 { "(bad)", { XX } },
1763 { "psrlq", { MS, Ib } },
1764 { "psrldq", { MS, Ib } },
1765 { "(bad)", { XX } },
1766 { "(bad)", { XX } },
1767 { "psllq", { MS, Ib } },
1768 { "pslldq", { MS, Ib } },
1769 },
1770 /* GRP15 */
1771 {
1772 { "fxsave", { Ev } },
1773 { "fxrstor", { Ev } },
1774 { "ldmxcsr", { Ev } },
1775 { "stmxcsr", { Ev } },
1776 { "(bad)", { XX } },
1777 { "lfence", { { OP_0fae, 0 } } },
1778 { "mfence", { { OP_0fae, 0 } } },
1779 { "clflush", { { OP_0fae, 0 } } },
1780 },
1781 /* GRP16 */
1782 {
1783 { "prefetchnta", { Ev } },
1784 { "prefetcht0", { Ev } },
1785 { "prefetcht1", { Ev } },
1786 { "prefetcht2", { Ev } },
1787 { "(bad)", { XX } },
1788 { "(bad)", { XX } },
1789 { "(bad)", { XX } },
1790 { "(bad)", { XX } },
1791 },
1792 /* GRPAMD */
1793 {
1794 { "prefetch", { Eb } },
1795 { "prefetchw", { Eb } },
1796 { "(bad)", { XX } },
1797 { "(bad)", { XX } },
1798 { "(bad)", { XX } },
1799 { "(bad)", { XX } },
1800 { "(bad)", { XX } },
1801 { "(bad)", { XX } },
1802 },
1803 /* GRPPADLCK1 */
1804 {
1805 { "xstore-rng", { { OP_0f07, 0 } } },
1806 { "xcrypt-ecb", { { OP_0f07, 0 } } },
1807 { "xcrypt-cbc", { { OP_0f07, 0 } } },
1808 { "xcrypt-ctr", { { OP_0f07, 0 } } },
1809 { "xcrypt-cfb", { { OP_0f07, 0 } } },
1810 { "xcrypt-ofb", { { OP_0f07, 0 } } },
1811 { "(bad)", { { OP_0f07, 0 } } },
1812 { "(bad)", { { OP_0f07, 0 } } },
1813 },
1814 /* GRPPADLCK2 */
1815 {
1816 { "montmul", { { OP_0f07, 0 } } },
1817 { "xsha1", { { OP_0f07, 0 } } },
1818 { "xsha256", { { OP_0f07, 0 } } },
1819 { "(bad)", { { OP_0f07, 0 } } },
1820 { "(bad)", { { OP_0f07, 0 } } },
1821 { "(bad)", { { OP_0f07, 0 } } },
1822 { "(bad)", { { OP_0f07, 0 } } },
1823 { "(bad)", { { OP_0f07, 0 } } },
1824 }
1825 };
1826
1827 static const struct dis386 prefix_user_table[][4] = {
1828 /* PREGRP0 */
1829 {
1830 { "addps", { XM, EX } },
1831 { "addss", { XM, EX } },
1832 { "addpd", { XM, EX } },
1833 { "addsd", { XM, EX } },
1834 },
1835 /* PREGRP1 */
1836 {
1837 { "", { XM, EX, OPSIMD } }, /* See OP_SIMD_SUFFIX. */
1838 { "", { XM, EX, OPSIMD } },
1839 { "", { XM, EX, OPSIMD } },
1840 { "", { XM, EX, OPSIMD } },
1841 },
1842 /* PREGRP2 */
1843 {
1844 { "cvtpi2ps", { XM, EMC } },
1845 { "cvtsi2ssY", { XM, Ev } },
1846 { "cvtpi2pd", { XM, EMC } },
1847 { "cvtsi2sdY", { XM, Ev } },
1848 },
1849 /* PREGRP3 */
1850 {
1851 { "cvtps2pi", { MXC, EX } },
1852 { "cvtss2siY", { Gv, EX } },
1853 { "cvtpd2pi", { MXC, EX } },
1854 { "cvtsd2siY", { Gv, EX } },
1855 },
1856 /* PREGRP4 */
1857 {
1858 { "cvttps2pi", { MXC, EX } },
1859 { "cvttss2siY", { Gv, EX } },
1860 { "cvttpd2pi", { MXC, EX } },
1861 { "cvttsd2siY", { Gv, EX } },
1862 },
1863 /* PREGRP5 */
1864 {
1865 { "divps", { XM, EX } },
1866 { "divss", { XM, EX } },
1867 { "divpd", { XM, EX } },
1868 { "divsd", { XM, EX } },
1869 },
1870 /* PREGRP6 */
1871 {
1872 { "maxps", { XM, EX } },
1873 { "maxss", { XM, EX } },
1874 { "maxpd", { XM, EX } },
1875 { "maxsd", { XM, EX } },
1876 },
1877 /* PREGRP7 */
1878 {
1879 { "minps", { XM, EX } },
1880 { "minss", { XM, EX } },
1881 { "minpd", { XM, EX } },
1882 { "minsd", { XM, EX } },
1883 },
1884 /* PREGRP8 */
1885 {
1886 { "movups", { XM, EX } },
1887 { "movss", { XM, EX } },
1888 { "movupd", { XM, EX } },
1889 { "movsd", { XM, EX } },
1890 },
1891 /* PREGRP9 */
1892 {
1893 { "movups", { EX, XM } },
1894 { "movss", { EX, XM } },
1895 { "movupd", { EX, XM } },
1896 { "movsd", { EX, XM } },
1897 },
1898 /* PREGRP10 */
1899 {
1900 { "mulps", { XM, EX } },
1901 { "mulss", { XM, EX } },
1902 { "mulpd", { XM, EX } },
1903 { "mulsd", { XM, EX } },
1904 },
1905 /* PREGRP11 */
1906 {
1907 { "rcpps", { XM, EX } },
1908 { "rcpss", { XM, EX } },
1909 { "(bad)", { XM, EX } },
1910 { "(bad)", { XM, EX } },
1911 },
1912 /* PREGRP12 */
1913 {
1914 { "rsqrtps",{ XM, EX } },
1915 { "rsqrtss",{ XM, EX } },
1916 { "(bad)", { XM, EX } },
1917 { "(bad)", { XM, EX } },
1918 },
1919 /* PREGRP13 */
1920 {
1921 { "sqrtps", { XM, EX } },
1922 { "sqrtss", { XM, EX } },
1923 { "sqrtpd", { XM, EX } },
1924 { "sqrtsd", { XM, EX } },
1925 },
1926 /* PREGRP14 */
1927 {
1928 { "subps", { XM, EX } },
1929 { "subss", { XM, EX } },
1930 { "subpd", { XM, EX } },
1931 { "subsd", { XM, EX } },
1932 },
1933 /* PREGRP15 */
1934 {
1935 { "(bad)", { XM, EX } },
1936 { "cvtdq2pd", { XM, EX } },
1937 { "cvttpd2dq", { XM, EX } },
1938 { "cvtpd2dq", { XM, EX } },
1939 },
1940 /* PREGRP16 */
1941 {
1942 { "cvtdq2ps", { XM, EX } },
1943 { "cvttps2dq", { XM, EX } },
1944 { "cvtps2dq", { XM, EX } },
1945 { "(bad)", { XM, EX } },
1946 },
1947 /* PREGRP17 */
1948 {
1949 { "cvtps2pd", { XM, EX } },
1950 { "cvtss2sd", { XM, EX } },
1951 { "cvtpd2ps", { XM, EX } },
1952 { "cvtsd2ss", { XM, EX } },
1953 },
1954 /* PREGRP18 */
1955 {
1956 { "maskmovq", { MX, MS } },
1957 { "(bad)", { XM, EX } },
1958 { "maskmovdqu", { XM, XS } },
1959 { "(bad)", { XM, EX } },
1960 },
1961 /* PREGRP19 */
1962 {
1963 { "movq", { MX, EM } },
1964 { "movdqu", { XM, EX } },
1965 { "movdqa", { XM, EX } },
1966 { "(bad)", { XM, EX } },
1967 },
1968 /* PREGRP20 */
1969 {
1970 { "movq", { EM, MX } },
1971 { "movdqu", { EX, XM } },
1972 { "movdqa", { EX, XM } },
1973 { "(bad)", { EX, XM } },
1974 },
1975 /* PREGRP21 */
1976 {
1977 { "(bad)", { EX, XM } },
1978 { "movq2dq",{ XM, MS } },
1979 { "movq", { EX, XM } },
1980 { "movdq2q",{ MX, XS } },
1981 },
1982 /* PREGRP22 */
1983 {
1984 { "pshufw", { MX, EM, Ib } },
1985 { "pshufhw",{ XM, EX, Ib } },
1986 { "pshufd", { XM, EX, Ib } },
1987 { "pshuflw",{ XM, EX, Ib } },
1988 },
1989 /* PREGRP23 */
1990 {
1991 { "movd", { Edq, MX } },
1992 { "movq", { XM, EX } },
1993 { "movd", { Edq, XM } },
1994 { "(bad)", { Ed, XM } },
1995 },
1996 /* PREGRP24 */
1997 {
1998 { "(bad)", { MX, EX } },
1999 { "(bad)", { XM, EX } },
2000 { "punpckhqdq", { XM, EX } },
2001 { "(bad)", { XM, EX } },
2002 },
2003 /* PREGRP25 */
2004 {
2005 { "movntq", { EM, MX } },
2006 { "(bad)", { EM, XM } },
2007 { "movntdq",{ EM, XM } },
2008 { "(bad)", { EM, XM } },
2009 },
2010 /* PREGRP26 */
2011 {
2012 { "(bad)", { MX, EX } },
2013 { "(bad)", { XM, EX } },
2014 { "punpcklqdq", { XM, EX } },
2015 { "(bad)", { XM, EX } },
2016 },
2017 /* PREGRP27 */
2018 {
2019 { "(bad)", { MX, EX } },
2020 { "(bad)", { XM, EX } },
2021 { "addsubpd", { XM, EX } },
2022 { "addsubps", { XM, EX } },
2023 },
2024 /* PREGRP28 */
2025 {
2026 { "(bad)", { MX, EX } },
2027 { "(bad)", { XM, EX } },
2028 { "haddpd", { XM, EX } },
2029 { "haddps", { XM, EX } },
2030 },
2031 /* PREGRP29 */
2032 {
2033 { "(bad)", { MX, EX } },
2034 { "(bad)", { XM, EX } },
2035 { "hsubpd", { XM, EX } },
2036 { "hsubps", { XM, EX } },
2037 },
2038 /* PREGRP30 */
2039 {
2040 { "movlpX", { XM, EX, { SIMD_Fixup, 'h' } } }, /* really only 2 operands */
2041 { "movsldup", { XM, EX } },
2042 { "movlpd", { XM, EX } },
2043 { "movddup", { XM, EX } },
2044 },
2045 /* PREGRP31 */
2046 {
2047 { "movhpX", { XM, EX, { SIMD_Fixup, 'l' } } },
2048 { "movshdup", { XM, EX } },
2049 { "movhpd", { XM, EX } },
2050 { "(bad)", { XM, EX } },
2051 },
2052 /* PREGRP32 */
2053 {
2054 { "(bad)", { XM, EX } },
2055 { "(bad)", { XM, EX } },
2056 { "(bad)", { XM, EX } },
2057 { "lddqu", { XM, M } },
2058 },
2059 /* PREGRP33 */
2060 {
2061 {"movntps", { Ev, XM } },
2062 {"movntss", { Ev, XM } },
2063 {"movntpd", { Ev, XM } },
2064 {"movntsd", { Ev, XM } },
2065 },
2066
2067 /* PREGRP34 */
2068 {
2069 {"vmread", { Em, Gm } },
2070 {"(bad)", { XX } },
2071 {"extrq", { XS, Ib, Ib } },
2072 {"insertq", { XM, XS, Ib, Ib } },
2073 },
2074
2075 /* PREGRP35 */
2076 {
2077 {"vmwrite", { Gm, Em } },
2078 {"(bad)", { XX } },
2079 {"extrq", { XM, XS } },
2080 {"insertq", { XM, XS } },
2081 },
2082
2083 /* PREGRP36 */
2084 {
2085 { "bsrS", { Gv, Ev } },
2086 { "lzcntS", { Gv, Ev } },
2087 { "bsrS", { Gv, Ev } },
2088 { "(bad)", { XX } },
2089 },
2090
2091 /* PREGRP37 */
2092 {
2093 { "(bad)", { XX } },
2094 { "popcntS", { Gv, Ev } },
2095 { "(bad)", { XX } },
2096 { "(bad)", { XX } },
2097 },
2098
2099 /* PREGRP38 */
2100 {
2101 { "xchgS", { { NOP_Fixup1, eAX_reg }, { NOP_Fixup2, eAX_reg } } },
2102 { "pause", { XX } },
2103 { "xchgS", { { NOP_Fixup1, eAX_reg }, { NOP_Fixup2, eAX_reg } } },
2104 { "(bad)", { XX } },
2105 },
2106
2107 /* PREGRP39 */
2108 {
2109 { "(bad)", { XX } },
2110 { "(bad)", { XX } },
2111 { "pblendvb", {XM, EX, XMM0 } },
2112 { "(bad)", { XX } },
2113 },
2114
2115 /* PREGRP40 */
2116 {
2117 { "(bad)", { XX } },
2118 { "(bad)", { XX } },
2119 { "blendvps", {XM, EX, XMM0 } },
2120 { "(bad)", { XX } },
2121 },
2122
2123 /* PREGRP41 */
2124 {
2125 { "(bad)", { XX } },
2126 { "(bad)", { XX } },
2127 { "blendvpd", { XM, EX, XMM0 } },
2128 { "(bad)", { XX } },
2129 },
2130
2131 /* PREGRP42 */
2132 {
2133 { "(bad)", { XX } },
2134 { "(bad)", { XX } },
2135 { "ptest", { XM, EX } },
2136 { "(bad)", { XX } },
2137 },
2138
2139 /* PREGRP43 */
2140 {
2141 { "(bad)", { XX } },
2142 { "(bad)", { XX } },
2143 { "pmovsxbw", { XM, EX } },
2144 { "(bad)", { XX } },
2145 },
2146
2147 /* PREGRP44 */
2148 {
2149 { "(bad)", { XX } },
2150 { "(bad)", { XX } },
2151 { "pmovsxbd", { XM, EX } },
2152 { "(bad)", { XX } },
2153 },
2154
2155 /* PREGRP45 */
2156 {
2157 { "(bad)", { XX } },
2158 { "(bad)", { XX } },
2159 { "pmovsxbq", { XM, EX } },
2160 { "(bad)", { XX } },
2161 },
2162
2163 /* PREGRP46 */
2164 {
2165 { "(bad)", { XX } },
2166 { "(bad)", { XX } },
2167 { "pmovsxwd", { XM, EX } },
2168 { "(bad)", { XX } },
2169 },
2170
2171 /* PREGRP47 */
2172 {
2173 { "(bad)", { XX } },
2174 { "(bad)", { XX } },
2175 { "pmovsxwq", { XM, EX } },
2176 { "(bad)", { XX } },
2177 },
2178
2179 /* PREGRP48 */
2180 {
2181 { "(bad)", { XX } },
2182 { "(bad)", { XX } },
2183 { "pmovsxdq", { XM, EX } },
2184 { "(bad)", { XX } },
2185 },
2186
2187 /* PREGRP49 */
2188 {
2189 { "(bad)", { XX } },
2190 { "(bad)", { XX } },
2191 { "pmuldq", { XM, EX } },
2192 { "(bad)", { XX } },
2193 },
2194
2195 /* PREGRP50 */
2196 {
2197 { "(bad)", { XX } },
2198 { "(bad)", { XX } },
2199 { "pcmpeqq", { XM, EX } },
2200 { "(bad)", { XX } },
2201 },
2202
2203 /* PREGRP51 */
2204 {
2205 { "(bad)", { XX } },
2206 { "(bad)", { XX } },
2207 { "movntdqa", { XM, EM } },
2208 { "(bad)", { XX } },
2209 },
2210
2211 /* PREGRP52 */
2212 {
2213 { "(bad)", { XX } },
2214 { "(bad)", { XX } },
2215 { "packusdw", { XM, EX } },
2216 { "(bad)", { XX } },
2217 },
2218
2219 /* PREGRP53 */
2220 {
2221 { "(bad)", { XX } },
2222 { "(bad)", { XX } },
2223 { "pmovzxbw", { XM, EX } },
2224 { "(bad)", { XX } },
2225 },
2226
2227 /* PREGRP54 */
2228 {
2229 { "(bad)", { XX } },
2230 { "(bad)", { XX } },
2231 { "pmovzxbd", { XM, EX } },
2232 { "(bad)", { XX } },
2233 },
2234
2235 /* PREGRP55 */
2236 {
2237 { "(bad)", { XX } },
2238 { "(bad)", { XX } },
2239 { "pmovzxbq", { XM, EX } },
2240 { "(bad)", { XX } },
2241 },
2242
2243 /* PREGRP56 */
2244 {
2245 { "(bad)", { XX } },
2246 { "(bad)", { XX } },
2247 { "pmovzxwd", { XM, EX } },
2248 { "(bad)", { XX } },
2249 },
2250
2251 /* PREGRP57 */
2252 {
2253 { "(bad)", { XX } },
2254 { "(bad)", { XX } },
2255 { "pmovzxwq", { XM, EX } },
2256 { "(bad)", { XX } },
2257 },
2258
2259 /* PREGRP58 */
2260 {
2261 { "(bad)", { XX } },
2262 { "(bad)", { XX } },
2263 { "pmovzxdq", { XM, EX } },
2264 { "(bad)", { XX } },
2265 },
2266
2267 /* PREGRP59 */
2268 {
2269 { "(bad)", { XX } },
2270 { "(bad)", { XX } },
2271 { "pminsb", { XM, EX } },
2272 { "(bad)", { XX } },
2273 },
2274
2275 /* PREGRP60 */
2276 {
2277 { "(bad)", { XX } },
2278 { "(bad)", { XX } },
2279 { "pminsd", { XM, EX } },
2280 { "(bad)", { XX } },
2281 },
2282
2283 /* PREGRP61 */
2284 {
2285 { "(bad)", { XX } },
2286 { "(bad)", { XX } },
2287 { "pminuw", { XM, EX } },
2288 { "(bad)", { XX } },
2289 },
2290
2291 /* PREGRP62 */
2292 {
2293 { "(bad)", { XX } },
2294 { "(bad)", { XX } },
2295 { "pminud", { XM, EX } },
2296 { "(bad)", { XX } },
2297 },
2298
2299 /* PREGRP63 */
2300 {
2301 { "(bad)", { XX } },
2302 { "(bad)", { XX } },
2303 { "pmaxsb", { XM, EX } },
2304 { "(bad)", { XX } },
2305 },
2306
2307 /* PREGRP64 */
2308 {
2309 { "(bad)", { XX } },
2310 { "(bad)", { XX } },
2311 { "pmaxsd", { XM, EX } },
2312 { "(bad)", { XX } },
2313 },
2314
2315 /* PREGRP65 */
2316 {
2317 { "(bad)", { XX } },
2318 { "(bad)", { XX } },
2319 { "pmaxuw", { XM, EX } },
2320 { "(bad)", { XX } },
2321 },
2322
2323 /* PREGRP66 */
2324 {
2325 { "(bad)", { XX } },
2326 { "(bad)", { XX } },
2327 { "pmaxud", { XM, EX } },
2328 { "(bad)", { XX } },
2329 },
2330
2331 /* PREGRP67 */
2332 {
2333 { "(bad)", { XX } },
2334 { "(bad)", { XX } },
2335 { "pmulld", { XM, EX } },
2336 { "(bad)", { XX } },
2337 },
2338
2339 /* PREGRP68 */
2340 {
2341 { "(bad)", { XX } },
2342 { "(bad)", { XX } },
2343 { "phminposuw", { XM, EX } },
2344 { "(bad)", { XX } },
2345 },
2346
2347 /* PREGRP69 */
2348 {
2349 { "(bad)", { XX } },
2350 { "(bad)", { XX } },
2351 { "roundps", { XM, EX, Ib } },
2352 { "(bad)", { XX } },
2353 },
2354
2355 /* PREGRP70 */
2356 {
2357 { "(bad)", { XX } },
2358 { "(bad)", { XX } },
2359 { "roundpd", { XM, EX, Ib } },
2360 { "(bad)", { XX } },
2361 },
2362
2363 /* PREGRP71 */
2364 {
2365 { "(bad)", { XX } },
2366 { "(bad)", { XX } },
2367 { "roundss", { XM, EX, Ib } },
2368 { "(bad)", { XX } },
2369 },
2370
2371 /* PREGRP72 */
2372 {
2373 { "(bad)", { XX } },
2374 { "(bad)", { XX } },
2375 { "roundsd", { XM, EX, Ib } },
2376 { "(bad)", { XX } },
2377 },
2378
2379 /* PREGRP73 */
2380 {
2381 { "(bad)", { XX } },
2382 { "(bad)", { XX } },
2383 { "blendps", { XM, EX, Ib } },
2384 { "(bad)", { XX } },
2385 },
2386
2387 /* PREGRP74 */
2388 {
2389 { "(bad)", { XX } },
2390 { "(bad)", { XX } },
2391 { "blendpd", { XM, EX, Ib } },
2392 { "(bad)", { XX } },
2393 },
2394
2395 /* PREGRP75 */
2396 {
2397 { "(bad)", { XX } },
2398 { "(bad)", { XX } },
2399 { "pblendw", { XM, EX, Ib } },
2400 { "(bad)", { XX } },
2401 },
2402
2403 /* PREGRP76 */
2404 {
2405 { "(bad)", { XX } },
2406 { "(bad)", { XX } },
2407 { "pextrb", { Edqb, XM, Ib } },
2408 { "(bad)", { XX } },
2409 },
2410
2411 /* PREGRP77 */
2412 {
2413 { "(bad)", { XX } },
2414 { "(bad)", { XX } },
2415 { "pextrw", { Edqw, XM, Ib } },
2416 { "(bad)", { XX } },
2417 },
2418
2419 /* PREGRP78 */
2420 {
2421 { "(bad)", { XX } },
2422 { "(bad)", { XX } },
2423 { "pextrK", { Edq, XM, Ib } },
2424 { "(bad)", { XX } },
2425 },
2426
2427 /* PREGRP79 */
2428 {
2429 { "(bad)", { XX } },
2430 { "(bad)", { XX } },
2431 { "extractps", { Edqd, XM, Ib } },
2432 { "(bad)", { XX } },
2433 },
2434
2435 /* PREGRP80 */
2436 {
2437 { "(bad)", { XX } },
2438 { "(bad)", { XX } },
2439 { "pinsrb", { XM, Edqb, Ib } },
2440 { "(bad)", { XX } },
2441 },
2442
2443 /* PREGRP81 */
2444 {
2445 { "(bad)", { XX } },
2446 { "(bad)", { XX } },
2447 { "insertps", { XM, EX, Ib } },
2448 { "(bad)", { XX } },
2449 },
2450
2451 /* PREGRP82 */
2452 {
2453 { "(bad)", { XX } },
2454 { "(bad)", { XX } },
2455 { "pinsrK", { XM, Edq, Ib } },
2456 { "(bad)", { XX } },
2457 },
2458
2459 /* PREGRP83 */
2460 {
2461 { "(bad)", { XX } },
2462 { "(bad)", { XX } },
2463 { "dpps", { XM, EX, Ib } },
2464 { "(bad)", { XX } },
2465 },
2466
2467 /* PREGRP84 */
2468 {
2469 { "(bad)", { XX } },
2470 { "(bad)", { XX } },
2471 { "dppd", { XM, EX, Ib } },
2472 { "(bad)", { XX } },
2473 },
2474
2475 /* PREGRP85 */
2476 {
2477 { "(bad)", { XX } },
2478 { "(bad)", { XX } },
2479 { "mpsadbw", { XM, EX, Ib } },
2480 { "(bad)", { XX } },
2481 },
2482
2483 /* PREGRP86 */
2484 {
2485 { "(bad)", { XX } },
2486 { "(bad)", { XX } },
2487 { "pcmpgtq", { XM, EX } },
2488 { "(bad)", { XX } },
2489 },
2490
2491 /* PREGRP87 */
2492 {
2493 { "(bad)", { XX } },
2494 { "(bad)", { XX } },
2495 { "(bad)", { XX } },
2496 { "crc32", { Gdq, { CRC32_Fixup, b_mode } } },
2497 },
2498
2499 /* PREGRP88 */
2500 {
2501 { "(bad)", { XX } },
2502 { "(bad)", { XX } },
2503 { "(bad)", { XX } },
2504 { "crc32", { Gdq, { CRC32_Fixup, v_mode } } },
2505 },
2506
2507 /* PREGRP89 */
2508 {
2509 { "(bad)", { XX } },
2510 { "(bad)", { XX } },
2511 { "pcmpestrm", { XM, EX, Ib } },
2512 { "(bad)", { XX } },
2513 },
2514
2515 /* PREGRP90 */
2516 {
2517 { "(bad)", { XX } },
2518 { "(bad)", { XX } },
2519 { "pcmpestri", { XM, EX, Ib } },
2520 { "(bad)", { XX } },
2521 },
2522
2523 /* PREGRP91 */
2524 {
2525 { "(bad)", { XX } },
2526 { "(bad)", { XX } },
2527 { "pcmpistrm", { XM, EX, Ib } },
2528 { "(bad)", { XX } },
2529 },
2530
2531 /* PREGRP92 */
2532 {
2533 { "(bad)", { XX } },
2534 { "(bad)", { XX } },
2535 { "pcmpistri", { XM, EX, Ib } },
2536 { "(bad)", { XX } },
2537 },
2538 };
2539
2540 static const struct dis386 x86_64_table[][2] = {
2541 {
2542 { "pusha{P|}", { XX } },
2543 { "(bad)", { XX } },
2544 },
2545 {
2546 { "popa{P|}", { XX } },
2547 { "(bad)", { XX } },
2548 },
2549 {
2550 { "bound{S|}", { Gv, Ma } },
2551 { "(bad)", { XX } },
2552 },
2553 {
2554 { "arpl", { Ew, Gw } },
2555 { "movs{||lq|xd}", { Gv, Ed } },
2556 },
2557 };
2558
2559 static const struct dis386 three_byte_table[][256] = {
2560 /* THREE_BYTE_0 */
2561 {
2562 /* 00 */
2563 { "pshufb", { MX, EM } },
2564 { "phaddw", { MX, EM } },
2565 { "phaddd", { MX, EM } },
2566 { "phaddsw", { MX, EM } },
2567 { "pmaddubsw", { MX, EM } },
2568 { "phsubw", { MX, EM } },
2569 { "phsubd", { MX, EM } },
2570 { "phsubsw", { MX, EM } },
2571 /* 08 */
2572 { "psignb", { MX, EM } },
2573 { "psignw", { MX, EM } },
2574 { "psignd", { MX, EM } },
2575 { "pmulhrsw", { MX, EM } },
2576 { "(bad)", { XX } },
2577 { "(bad)", { XX } },
2578 { "(bad)", { XX } },
2579 { "(bad)", { XX } },
2580 /* 10 */
2581 { PREGRP39 },
2582 { "(bad)", { XX } },
2583 { "(bad)", { XX } },
2584 { "(bad)", { XX } },
2585 { PREGRP40 },
2586 { PREGRP41 },
2587 { "(bad)", { XX } },
2588 { PREGRP42 },
2589 /* 18 */
2590 { "(bad)", { XX } },
2591 { "(bad)", { XX } },
2592 { "(bad)", { XX } },
2593 { "(bad)", { XX } },
2594 { "pabsb", { MX, EM } },
2595 { "pabsw", { MX, EM } },
2596 { "pabsd", { MX, EM } },
2597 { "(bad)", { XX } },
2598 /* 20 */
2599 { PREGRP43 },
2600 { PREGRP44 },
2601 { PREGRP45 },
2602 { PREGRP46 },
2603 { PREGRP47 },
2604 { PREGRP48 },
2605 { "(bad)", { XX } },
2606 { "(bad)", { XX } },
2607 /* 28 */
2608 { PREGRP49 },
2609 { PREGRP50 },
2610 { PREGRP51 },
2611 { PREGRP52 },
2612 { "(bad)", { XX } },
2613 { "(bad)", { XX } },
2614 { "(bad)", { XX } },
2615 { "(bad)", { XX } },
2616 /* 30 */
2617 { PREGRP53 },
2618 { PREGRP54 },
2619 { PREGRP55 },
2620 { PREGRP56 },
2621 { PREGRP57 },
2622 { PREGRP58 },
2623 { "(bad)", { XX } },
2624 { PREGRP86 },
2625 /* 38 */
2626 { PREGRP59 },
2627 { PREGRP60 },
2628 { PREGRP61 },
2629 { PREGRP62 },
2630 { PREGRP63 },
2631 { PREGRP64 },
2632 { PREGRP65 },
2633 { PREGRP66 },
2634 /* 40 */
2635 { PREGRP67 },
2636 { PREGRP68 },
2637 { "(bad)", { XX } },
2638 { "(bad)", { XX } },
2639 { "(bad)", { XX } },
2640 { "(bad)", { XX } },
2641 { "(bad)", { XX } },
2642 { "(bad)", { XX } },
2643 /* 48 */
2644 { "(bad)", { XX } },
2645 { "(bad)", { XX } },
2646 { "(bad)", { XX } },
2647 { "(bad)", { XX } },
2648 { "(bad)", { XX } },
2649 { "(bad)", { XX } },
2650 { "(bad)", { XX } },
2651 { "(bad)", { XX } },
2652 /* 50 */
2653 { "(bad)", { XX } },
2654 { "(bad)", { XX } },
2655 { "(bad)", { XX } },
2656 { "(bad)", { XX } },
2657 { "(bad)", { XX } },
2658 { "(bad)", { XX } },
2659 { "(bad)", { XX } },
2660 { "(bad)", { XX } },
2661 /* 58 */
2662 { "(bad)", { XX } },
2663 { "(bad)", { XX } },
2664 { "(bad)", { XX } },
2665 { "(bad)", { XX } },
2666 { "(bad)", { XX } },
2667 { "(bad)", { XX } },
2668 { "(bad)", { XX } },
2669 { "(bad)", { XX } },
2670 /* 60 */
2671 { "(bad)", { XX } },
2672 { "(bad)", { XX } },
2673 { "(bad)", { XX } },
2674 { "(bad)", { XX } },
2675 { "(bad)", { XX } },
2676 { "(bad)", { XX } },
2677 { "(bad)", { XX } },
2678 { "(bad)", { XX } },
2679 /* 68 */
2680 { "(bad)", { XX } },
2681 { "(bad)", { XX } },
2682 { "(bad)", { XX } },
2683 { "(bad)", { XX } },
2684 { "(bad)", { XX } },
2685 { "(bad)", { XX } },
2686 { "(bad)", { XX } },
2687 { "(bad)", { XX } },
2688 /* 70 */
2689 { "(bad)", { XX } },
2690 { "(bad)", { XX } },
2691 { "(bad)", { XX } },
2692 { "(bad)", { XX } },
2693 { "(bad)", { XX } },
2694 { "(bad)", { XX } },
2695 { "(bad)", { XX } },
2696 { "(bad)", { XX } },
2697 /* 78 */
2698 { "(bad)", { XX } },
2699 { "(bad)", { XX } },
2700 { "(bad)", { XX } },
2701 { "(bad)", { XX } },
2702 { "(bad)", { XX } },
2703 { "(bad)", { XX } },
2704 { "(bad)", { XX } },
2705 { "(bad)", { XX } },
2706 /* 80 */
2707 { "(bad)", { XX } },
2708 { "(bad)", { XX } },
2709 { "(bad)", { XX } },
2710 { "(bad)", { XX } },
2711 { "(bad)", { XX } },
2712 { "(bad)", { XX } },
2713 { "(bad)", { XX } },
2714 { "(bad)", { XX } },
2715 /* 88 */
2716 { "(bad)", { XX } },
2717 { "(bad)", { XX } },
2718 { "(bad)", { XX } },
2719 { "(bad)", { XX } },
2720 { "(bad)", { XX } },
2721 { "(bad)", { XX } },
2722 { "(bad)", { XX } },
2723 { "(bad)", { XX } },
2724 /* 90 */
2725 { "(bad)", { XX } },
2726 { "(bad)", { XX } },
2727 { "(bad)", { XX } },
2728 { "(bad)", { XX } },
2729 { "(bad)", { XX } },
2730 { "(bad)", { XX } },
2731 { "(bad)", { XX } },
2732 { "(bad)", { XX } },
2733 /* 98 */
2734 { "(bad)", { XX } },
2735 { "(bad)", { XX } },
2736 { "(bad)", { XX } },
2737 { "(bad)", { XX } },
2738 { "(bad)", { XX } },
2739 { "(bad)", { XX } },
2740 { "(bad)", { XX } },
2741 { "(bad)", { XX } },
2742 /* a0 */
2743 { "(bad)", { XX } },
2744 { "(bad)", { XX } },
2745 { "(bad)", { XX } },
2746 { "(bad)", { XX } },
2747 { "(bad)", { XX } },
2748 { "(bad)", { XX } },
2749 { "(bad)", { XX } },
2750 { "(bad)", { XX } },
2751 /* a8 */
2752 { "(bad)", { XX } },
2753 { "(bad)", { XX } },
2754 { "(bad)", { XX } },
2755 { "(bad)", { XX } },
2756 { "(bad)", { XX } },
2757 { "(bad)", { XX } },
2758 { "(bad)", { XX } },
2759 { "(bad)", { XX } },
2760 /* b0 */
2761 { "(bad)", { XX } },
2762 { "(bad)", { XX } },
2763 { "(bad)", { XX } },
2764 { "(bad)", { XX } },
2765 { "(bad)", { XX } },
2766 { "(bad)", { XX } },
2767 { "(bad)", { XX } },
2768 { "(bad)", { XX } },
2769 /* b8 */
2770 { "(bad)", { XX } },
2771 { "(bad)", { XX } },
2772 { "(bad)", { XX } },
2773 { "(bad)", { XX } },
2774 { "(bad)", { XX } },
2775 { "(bad)", { XX } },
2776 { "(bad)", { XX } },
2777 { "(bad)", { XX } },
2778 /* c0 */
2779 { "(bad)", { XX } },
2780 { "(bad)", { XX } },
2781 { "(bad)", { XX } },
2782 { "(bad)", { XX } },
2783 { "(bad)", { XX } },
2784 { "(bad)", { XX } },
2785 { "(bad)", { XX } },
2786 { "(bad)", { XX } },
2787 /* c8 */
2788 { "(bad)", { XX } },
2789 { "(bad)", { XX } },
2790 { "(bad)", { XX } },
2791 { "(bad)", { XX } },
2792 { "(bad)", { XX } },
2793 { "(bad)", { XX } },
2794 { "(bad)", { XX } },
2795 { "(bad)", { XX } },
2796 /* d0 */
2797 { "(bad)", { XX } },
2798 { "(bad)", { XX } },
2799 { "(bad)", { XX } },
2800 { "(bad)", { XX } },
2801 { "(bad)", { XX } },
2802 { "(bad)", { XX } },
2803 { "(bad)", { XX } },
2804 { "(bad)", { XX } },
2805 /* d8 */
2806 { "(bad)", { XX } },
2807 { "(bad)", { XX } },
2808 { "(bad)", { XX } },
2809 { "(bad)", { XX } },
2810 { "(bad)", { XX } },
2811 { "(bad)", { XX } },
2812 { "(bad)", { XX } },
2813 { "(bad)", { XX } },
2814 /* e0 */
2815 { "(bad)", { XX } },
2816 { "(bad)", { XX } },
2817 { "(bad)", { XX } },
2818 { "(bad)", { XX } },
2819 { "(bad)", { XX } },
2820 { "(bad)", { XX } },
2821 { "(bad)", { XX } },
2822 { "(bad)", { XX } },
2823 /* e8 */
2824 { "(bad)", { XX } },
2825 { "(bad)", { XX } },
2826 { "(bad)", { XX } },
2827 { "(bad)", { XX } },
2828 { "(bad)", { XX } },
2829 { "(bad)", { XX } },
2830 { "(bad)", { XX } },
2831 { "(bad)", { XX } },
2832 /* f0 */
2833 { PREGRP87 },
2834 { PREGRP88 },
2835 { "(bad)", { XX } },
2836 { "(bad)", { XX } },
2837 { "(bad)", { XX } },
2838 { "(bad)", { XX } },
2839 { "(bad)", { XX } },
2840 { "(bad)", { XX } },
2841 /* f8 */
2842 { "(bad)", { XX } },
2843 { "(bad)", { XX } },
2844 { "(bad)", { XX } },
2845 { "(bad)", { XX } },
2846 { "(bad)", { XX } },
2847 { "(bad)", { XX } },
2848 { "(bad)", { XX } },
2849 { "(bad)", { XX } },
2850 },
2851 /* THREE_BYTE_1 */
2852 {
2853 /* 00 */
2854 { "(bad)", { XX } },
2855 { "(bad)", { XX } },
2856 { "(bad)", { XX } },
2857 { "(bad)", { XX } },
2858 { "(bad)", { XX } },
2859 { "(bad)", { XX } },
2860 { "(bad)", { XX } },
2861 { "(bad)", { XX } },
2862 /* 08 */
2863 { PREGRP69 },
2864 { PREGRP70 },
2865 { PREGRP71 },
2866 { PREGRP72 },
2867 { PREGRP73 },
2868 { PREGRP74 },
2869 { PREGRP75 },
2870 { "palignr", { MX, EM, Ib } },
2871 /* 10 */
2872 { "(bad)", { XX } },
2873 { "(bad)", { XX } },
2874 { "(bad)", { XX } },
2875 { "(bad)", { XX } },
2876 { PREGRP76 },
2877 { PREGRP77 },
2878 { PREGRP78 },
2879 { PREGRP79 },
2880 /* 18 */
2881 { "(bad)", { XX } },
2882 { "(bad)", { XX } },
2883 { "(bad)", { XX } },
2884 { "(bad)", { XX } },
2885 { "(bad)", { XX } },
2886 { "(bad)", { XX } },
2887 { "(bad)", { XX } },
2888 { "(bad)", { XX } },
2889 /* 20 */
2890 { PREGRP80 },
2891 { PREGRP81 },
2892 { PREGRP82 },
2893 { "(bad)", { XX } },
2894 { "(bad)", { XX } },
2895 { "(bad)", { XX } },
2896 { "(bad)", { XX } },
2897 { "(bad)", { XX } },
2898 /* 28 */
2899 { "(bad)", { XX } },
2900 { "(bad)", { XX } },
2901 { "(bad)", { XX } },
2902 { "(bad)", { XX } },
2903 { "(bad)", { XX } },
2904 { "(bad)", { XX } },
2905 { "(bad)", { XX } },
2906 { "(bad)", { XX } },
2907 /* 30 */
2908 { "(bad)", { XX } },
2909 { "(bad)", { XX } },
2910 { "(bad)", { XX } },
2911 { "(bad)", { XX } },
2912 { "(bad)", { XX } },
2913 { "(bad)", { XX } },
2914 { "(bad)", { XX } },
2915 { "(bad)", { XX } },
2916 /* 38 */
2917 { "(bad)", { XX } },
2918 { "(bad)", { XX } },
2919 { "(bad)", { XX } },
2920 { "(bad)", { XX } },
2921 { "(bad)", { XX } },
2922 { "(bad)", { XX } },
2923 { "(bad)", { XX } },
2924 { "(bad)", { XX } },
2925 /* 40 */
2926 { PREGRP83 },
2927 { PREGRP84 },
2928 { PREGRP85 },
2929 { "(bad)", { XX } },
2930 { "(bad)", { XX } },
2931 { "(bad)", { XX } },
2932 { "(bad)", { XX } },
2933 { "(bad)", { XX } },
2934 /* 48 */
2935 { "(bad)", { XX } },
2936 { "(bad)", { XX } },
2937 { "(bad)", { XX } },
2938 { "(bad)", { XX } },
2939 { "(bad)", { XX } },
2940 { "(bad)", { XX } },
2941 { "(bad)", { XX } },
2942 { "(bad)", { XX } },
2943 /* 50 */
2944 { "(bad)", { XX } },
2945 { "(bad)", { XX } },
2946 { "(bad)", { XX } },
2947 { "(bad)", { XX } },
2948 { "(bad)", { XX } },
2949 { "(bad)", { XX } },
2950 { "(bad)", { XX } },
2951 { "(bad)", { XX } },
2952 /* 58 */
2953 { "(bad)", { XX } },
2954 { "(bad)", { XX } },
2955 { "(bad)", { XX } },
2956 { "(bad)", { XX } },
2957 { "(bad)", { XX } },
2958 { "(bad)", { XX } },
2959 { "(bad)", { XX } },
2960 { "(bad)", { XX } },
2961 /* 60 */
2962 { PREGRP89 },
2963 { PREGRP90 },
2964 { PREGRP91 },
2965 { PREGRP92 },
2966 { "(bad)", { XX } },
2967 { "(bad)", { XX } },
2968 { "(bad)", { XX } },
2969 { "(bad)", { XX } },
2970 /* 68 */
2971 { "(bad)", { XX } },
2972 { "(bad)", { XX } },
2973 { "(bad)", { XX } },
2974 { "(bad)", { XX } },
2975 { "(bad)", { XX } },
2976 { "(bad)", { XX } },
2977 { "(bad)", { XX } },
2978 { "(bad)", { XX } },
2979 /* 70 */
2980 { "(bad)", { XX } },
2981 { "(bad)", { XX } },
2982 { "(bad)", { XX } },
2983 { "(bad)", { XX } },
2984 { "(bad)", { XX } },
2985 { "(bad)", { XX } },
2986 { "(bad)", { XX } },
2987 { "(bad)", { XX } },
2988 /* 78 */
2989 { "(bad)", { XX } },
2990 { "(bad)", { XX } },
2991 { "(bad)", { XX } },
2992 { "(bad)", { XX } },
2993 { "(bad)", { XX } },
2994 { "(bad)", { XX } },
2995 { "(bad)", { XX } },
2996 { "(bad)", { XX } },
2997 /* 80 */
2998 { "(bad)", { XX } },
2999 { "(bad)", { XX } },
3000 { "(bad)", { XX } },
3001 { "(bad)", { XX } },
3002 { "(bad)", { XX } },
3003 { "(bad)", { XX } },
3004 { "(bad)", { XX } },
3005 { "(bad)", { XX } },
3006 /* 88 */
3007 { "(bad)", { XX } },
3008 { "(bad)", { XX } },
3009 { "(bad)", { XX } },
3010 { "(bad)", { XX } },
3011 { "(bad)", { XX } },
3012 { "(bad)", { XX } },
3013 { "(bad)", { XX } },
3014 { "(bad)", { XX } },
3015 /* 90 */
3016 { "(bad)", { XX } },
3017 { "(bad)", { XX } },
3018 { "(bad)", { XX } },
3019 { "(bad)", { XX } },
3020 { "(bad)", { XX } },
3021 { "(bad)", { XX } },
3022 { "(bad)", { XX } },
3023 { "(bad)", { XX } },
3024 /* 98 */
3025 { "(bad)", { XX } },
3026 { "(bad)", { XX } },
3027 { "(bad)", { XX } },
3028 { "(bad)", { XX } },
3029 { "(bad)", { XX } },
3030 { "(bad)", { XX } },
3031 { "(bad)", { XX } },
3032 { "(bad)", { XX } },
3033 /* a0 */
3034 { "(bad)", { XX } },
3035 { "(bad)", { XX } },
3036 { "(bad)", { XX } },
3037 { "(bad)", { XX } },
3038 { "(bad)", { XX } },
3039 { "(bad)", { XX } },
3040 { "(bad)", { XX } },
3041 { "(bad)", { XX } },
3042 /* a8 */
3043 { "(bad)", { XX } },
3044 { "(bad)", { XX } },
3045 { "(bad)", { XX } },
3046 { "(bad)", { XX } },
3047 { "(bad)", { XX } },
3048 { "(bad)", { XX } },
3049 { "(bad)", { XX } },
3050 { "(bad)", { XX } },
3051 /* b0 */
3052 { "(bad)", { XX } },
3053 { "(bad)", { XX } },
3054 { "(bad)", { XX } },
3055 { "(bad)", { XX } },
3056 { "(bad)", { XX } },
3057 { "(bad)", { XX } },
3058 { "(bad)", { XX } },
3059 { "(bad)", { XX } },
3060 /* b8 */
3061 { "(bad)", { XX } },
3062 { "(bad)", { XX } },
3063 { "(bad)", { XX } },
3064 { "(bad)", { XX } },
3065 { "(bad)", { XX } },
3066 { "(bad)", { XX } },
3067 { "(bad)", { XX } },
3068 { "(bad)", { XX } },
3069 /* c0 */
3070 { "(bad)", { XX } },
3071 { "(bad)", { XX } },
3072 { "(bad)", { XX } },
3073 { "(bad)", { XX } },
3074 { "(bad)", { XX } },
3075 { "(bad)", { XX } },
3076 { "(bad)", { XX } },
3077 { "(bad)", { XX } },
3078 /* c8 */
3079 { "(bad)", { XX } },
3080 { "(bad)", { XX } },
3081 { "(bad)", { XX } },
3082 { "(bad)", { XX } },
3083 { "(bad)", { XX } },
3084 { "(bad)", { XX } },
3085 { "(bad)", { XX } },
3086 { "(bad)", { XX } },
3087 /* d0 */
3088 { "(bad)", { XX } },
3089 { "(bad)", { XX } },
3090 { "(bad)", { XX } },
3091 { "(bad)", { XX } },
3092 { "(bad)", { XX } },
3093 { "(bad)", { XX } },
3094 { "(bad)", { XX } },
3095 { "(bad)", { XX } },
3096 /* d8 */
3097 { "(bad)", { XX } },
3098 { "(bad)", { XX } },
3099 { "(bad)", { XX } },
3100 { "(bad)", { XX } },
3101 { "(bad)", { XX } },
3102 { "(bad)", { XX } },
3103 { "(bad)", { XX } },
3104 { "(bad)", { XX } },
3105 /* e0 */
3106 { "(bad)", { XX } },
3107 { "(bad)", { XX } },
3108 { "(bad)", { XX } },
3109 { "(bad)", { XX } },
3110 { "(bad)", { XX } },
3111 { "(bad)", { XX } },
3112 { "(bad)", { XX } },
3113 { "(bad)", { XX } },
3114 /* e8 */
3115 { "(bad)", { XX } },
3116 { "(bad)", { XX } },
3117 { "(bad)", { XX } },
3118 { "(bad)", { XX } },
3119 { "(bad)", { XX } },
3120 { "(bad)", { XX } },
3121 { "(bad)", { XX } },
3122 { "(bad)", { XX } },
3123 /* f0 */
3124 { "(bad)", { XX } },
3125 { "(bad)", { XX } },
3126 { "(bad)", { XX } },
3127 { "(bad)", { XX } },
3128 { "(bad)", { XX } },
3129 { "(bad)", { XX } },
3130 { "(bad)", { XX } },
3131 { "(bad)", { XX } },
3132 /* f8 */
3133 { "(bad)", { XX } },
3134 { "(bad)", { XX } },
3135 { "(bad)", { XX } },
3136 { "(bad)", { XX } },
3137 { "(bad)", { XX } },
3138 { "(bad)", { XX } },
3139 { "(bad)", { XX } },
3140 { "(bad)", { XX } },
3141 }
3142 };
3143
3144 #define INTERNAL_DISASSEMBLER_ERROR _("<internal disassembler error>")
3145
3146 static void
3147 ckprefix (void)
3148 {
3149 int newrex;
3150 rex = 0;
3151 prefixes = 0;
3152 used_prefixes = 0;
3153 rex_used = 0;
3154 while (1)
3155 {
3156 FETCH_DATA (the_info, codep + 1);
3157 newrex = 0;
3158 switch (*codep)
3159 {
3160 /* REX prefixes family. */
3161 case 0x40:
3162 case 0x41:
3163 case 0x42:
3164 case 0x43:
3165 case 0x44:
3166 case 0x45:
3167 case 0x46:
3168 case 0x47:
3169 case 0x48:
3170 case 0x49:
3171 case 0x4a:
3172 case 0x4b:
3173 case 0x4c:
3174 case 0x4d:
3175 case 0x4e:
3176 case 0x4f:
3177 if (address_mode == mode_64bit)
3178 newrex = *codep;
3179 else
3180 return;
3181 break;
3182 case 0xf3:
3183 prefixes |= PREFIX_REPZ;
3184 break;
3185 case 0xf2:
3186 prefixes |= PREFIX_REPNZ;
3187 break;
3188 case 0xf0:
3189 prefixes |= PREFIX_LOCK;
3190 break;
3191 case 0x2e:
3192 prefixes |= PREFIX_CS;
3193 break;
3194 case 0x36:
3195 prefixes |= PREFIX_SS;
3196 break;
3197 case 0x3e:
3198 prefixes |= PREFIX_DS;
3199 break;
3200 case 0x26:
3201 prefixes |= PREFIX_ES;
3202 break;
3203 case 0x64:
3204 prefixes |= PREFIX_FS;
3205 break;
3206 case 0x65:
3207 prefixes |= PREFIX_GS;
3208 break;
3209 case 0x66:
3210 prefixes |= PREFIX_DATA;
3211 break;
3212 case 0x67:
3213 prefixes |= PREFIX_ADDR;
3214 break;
3215 case FWAIT_OPCODE:
3216 /* fwait is really an instruction. If there are prefixes
3217 before the fwait, they belong to the fwait, *not* to the
3218 following instruction. */
3219 if (prefixes || rex)
3220 {
3221 prefixes |= PREFIX_FWAIT;
3222 codep++;
3223 return;
3224 }
3225 prefixes = PREFIX_FWAIT;
3226 break;
3227 default:
3228 return;
3229 }
3230 /* Rex is ignored when followed by another prefix. */
3231 if (rex)
3232 {
3233 rex_used = rex;
3234 return;
3235 }
3236 rex = newrex;
3237 codep++;
3238 }
3239 }
3240
3241 /* Return the name of the prefix byte PREF, or NULL if PREF is not a
3242 prefix byte. */
3243
3244 static const char *
3245 prefix_name (int pref, int sizeflag)
3246 {
3247 static const char *rexes [16] =
3248 {
3249 "rex", /* 0x40 */
3250 "rex.B", /* 0x41 */
3251 "rex.X", /* 0x42 */
3252 "rex.XB", /* 0x43 */
3253 "rex.R", /* 0x44 */
3254 "rex.RB", /* 0x45 */
3255 "rex.RX", /* 0x46 */
3256 "rex.RXB", /* 0x47 */
3257 "rex.W", /* 0x48 */
3258 "rex.WB", /* 0x49 */
3259 "rex.WX", /* 0x4a */
3260 "rex.WXB", /* 0x4b */
3261 "rex.WR", /* 0x4c */
3262 "rex.WRB", /* 0x4d */
3263 "rex.WRX", /* 0x4e */
3264 "rex.WRXB", /* 0x4f */
3265 };
3266
3267 switch (pref)
3268 {
3269 /* REX prefixes family. */
3270 case 0x40:
3271 case 0x41:
3272 case 0x42:
3273 case 0x43:
3274 case 0x44:
3275 case 0x45:
3276 case 0x46:
3277 case 0x47:
3278 case 0x48:
3279 case 0x49:
3280 case 0x4a:
3281 case 0x4b:
3282 case 0x4c:
3283 case 0x4d:
3284 case 0x4e:
3285 case 0x4f:
3286 return rexes [pref - 0x40];
3287 case 0xf3:
3288 return "repz";
3289 case 0xf2:
3290 return "repnz";
3291 case 0xf0:
3292 return "lock";
3293 case 0x2e:
3294 return "cs";
3295 case 0x36:
3296 return "ss";
3297 case 0x3e:
3298 return "ds";
3299 case 0x26:
3300 return "es";
3301 case 0x64:
3302 return "fs";
3303 case 0x65:
3304 return "gs";
3305 case 0x66:
3306 return (sizeflag & DFLAG) ? "data16" : "data32";
3307 case 0x67:
3308 if (address_mode == mode_64bit)
3309 return (sizeflag & AFLAG) ? "addr32" : "addr64";
3310 else
3311 return (sizeflag & AFLAG) ? "addr16" : "addr32";
3312 case FWAIT_OPCODE:
3313 return "fwait";
3314 default:
3315 return NULL;
3316 }
3317 }
3318
3319 static char op_out[MAX_OPERANDS][100];
3320 static int op_ad, op_index[MAX_OPERANDS];
3321 static int two_source_ops;
3322 static bfd_vma op_address[MAX_OPERANDS];
3323 static bfd_vma op_riprel[MAX_OPERANDS];
3324 static bfd_vma start_pc;
3325
3326 /*
3327 * On the 386's of 1988, the maximum length of an instruction is 15 bytes.
3328 * (see topic "Redundant prefixes" in the "Differences from 8086"
3329 * section of the "Virtual 8086 Mode" chapter.)
3330 * 'pc' should be the address of this instruction, it will
3331 * be used to print the target address if this is a relative jump or call
3332 * The function returns the length of this instruction in bytes.
3333 */
3334
3335 static char intel_syntax;
3336 static char open_char;
3337 static char close_char;
3338 static char separator_char;
3339 static char scale_char;
3340
3341 /* Here for backwards compatibility. When gdb stops using
3342 print_insn_i386_att and print_insn_i386_intel these functions can
3343 disappear, and print_insn_i386 be merged into print_insn. */
3344 int
3345 print_insn_i386_att (bfd_vma pc, disassemble_info *info)
3346 {
3347 intel_syntax = 0;
3348
3349 return print_insn (pc, info);
3350 }
3351
3352 int
3353 print_insn_i386_intel (bfd_vma pc, disassemble_info *info)
3354 {
3355 intel_syntax = 1;
3356
3357 return print_insn (pc, info);
3358 }
3359
3360 int
3361 print_insn_i386 (bfd_vma pc, disassemble_info *info)
3362 {
3363 intel_syntax = -1;
3364
3365 return print_insn (pc, info);
3366 }
3367
3368 void
3369 print_i386_disassembler_options (FILE *stream)
3370 {
3371 fprintf (stream, _("\n\
3372 The following i386/x86-64 specific disassembler options are supported for use\n\
3373 with the -M switch (multiple options should be separated by commas):\n"));
3374
3375 fprintf (stream, _(" x86-64 Disassemble in 64bit mode\n"));
3376 fprintf (stream, _(" i386 Disassemble in 32bit mode\n"));
3377 fprintf (stream, _(" i8086 Disassemble in 16bit mode\n"));
3378 fprintf (stream, _(" att Display instruction in AT&T syntax\n"));
3379 fprintf (stream, _(" intel Display instruction in Intel syntax\n"));
3380 fprintf (stream, _(" addr64 Assume 64bit address size\n"));
3381 fprintf (stream, _(" addr32 Assume 32bit address size\n"));
3382 fprintf (stream, _(" addr16 Assume 16bit address size\n"));
3383 fprintf (stream, _(" data32 Assume 32bit data size\n"));
3384 fprintf (stream, _(" data16 Assume 16bit data size\n"));
3385 fprintf (stream, _(" suffix Always display instruction suffix in AT&T syntax\n"));
3386 }
3387
3388 static int
3389 print_insn (bfd_vma pc, disassemble_info *info)
3390 {
3391 const struct dis386 *dp;
3392 int i;
3393 char *op_txt[MAX_OPERANDS];
3394 int needcomma;
3395 unsigned char uses_DATA_prefix, uses_LOCK_prefix;
3396 unsigned char uses_REPNZ_prefix, uses_REPZ_prefix;
3397 int sizeflag;
3398 const char *p;
3399 struct dis_private priv;
3400 unsigned char op;
3401
3402 if (info->mach == bfd_mach_x86_64_intel_syntax
3403 || info->mach == bfd_mach_x86_64)
3404 address_mode = mode_64bit;
3405 else
3406 address_mode = mode_32bit;
3407
3408 if (intel_syntax == (char) -1)
3409 intel_syntax = (info->mach == bfd_mach_i386_i386_intel_syntax
3410 || info->mach == bfd_mach_x86_64_intel_syntax);
3411
3412 if (info->mach == bfd_mach_i386_i386
3413 || info->mach == bfd_mach_x86_64
3414 || info->mach == bfd_mach_i386_i386_intel_syntax
3415 || info->mach == bfd_mach_x86_64_intel_syntax)
3416 priv.orig_sizeflag = AFLAG | DFLAG;
3417 else if (info->mach == bfd_mach_i386_i8086)
3418 priv.orig_sizeflag = 0;
3419 else
3420 abort ();
3421
3422 for (p = info->disassembler_options; p != NULL; )
3423 {
3424 if (CONST_STRNEQ (p, "x86-64"))
3425 {
3426 address_mode = mode_64bit;
3427 priv.orig_sizeflag = AFLAG | DFLAG;
3428 }
3429 else if (CONST_STRNEQ (p, "i386"))
3430 {
3431 address_mode = mode_32bit;
3432 priv.orig_sizeflag = AFLAG | DFLAG;
3433 }
3434 else if (CONST_STRNEQ (p, "i8086"))
3435 {
3436 address_mode = mode_16bit;
3437 priv.orig_sizeflag = 0;
3438 }
3439 else if (CONST_STRNEQ (p, "intel"))
3440 {
3441 intel_syntax = 1;
3442 }
3443 else if (CONST_STRNEQ (p, "att"))
3444 {
3445 intel_syntax = 0;
3446 }
3447 else if (CONST_STRNEQ (p, "addr"))
3448 {
3449 if (address_mode == mode_64bit)
3450 {
3451 if (p[4] == '3' && p[5] == '2')
3452 priv.orig_sizeflag &= ~AFLAG;
3453 else if (p[4] == '6' && p[5] == '4')
3454 priv.orig_sizeflag |= AFLAG;
3455 }
3456 else
3457 {
3458 if (p[4] == '1' && p[5] == '6')
3459 priv.orig_sizeflag &= ~AFLAG;
3460 else if (p[4] == '3' && p[5] == '2')
3461 priv.orig_sizeflag |= AFLAG;
3462 }
3463 }
3464 else if (CONST_STRNEQ (p, "data"))
3465 {
3466 if (p[4] == '1' && p[5] == '6')
3467 priv.orig_sizeflag &= ~DFLAG;
3468 else if (p[4] == '3' && p[5] == '2')
3469 priv.orig_sizeflag |= DFLAG;
3470 }
3471 else if (CONST_STRNEQ (p, "suffix"))
3472 priv.orig_sizeflag |= SUFFIX_ALWAYS;
3473
3474 p = strchr (p, ',');
3475 if (p != NULL)
3476 p++;
3477 }
3478
3479 if (intel_syntax)
3480 {
3481 names64 = intel_names64;
3482 names32 = intel_names32;
3483 names16 = intel_names16;
3484 names8 = intel_names8;
3485 names8rex = intel_names8rex;
3486 names_seg = intel_names_seg;
3487 index16 = intel_index16;
3488 open_char = '[';
3489 close_char = ']';
3490 separator_char = '+';
3491 scale_char = '*';
3492 }
3493 else
3494 {
3495 names64 = att_names64;
3496 names32 = att_names32;
3497 names16 = att_names16;
3498 names8 = att_names8;
3499 names8rex = att_names8rex;
3500 names_seg = att_names_seg;
3501 index16 = att_index16;
3502 open_char = '(';
3503 close_char = ')';
3504 separator_char = ',';
3505 scale_char = ',';
3506 }
3507
3508 /* The output looks better if we put 7 bytes on a line, since that
3509 puts most long word instructions on a single line. */
3510 info->bytes_per_line = 7;
3511
3512 info->private_data = &priv;
3513 priv.max_fetched = priv.the_buffer;
3514 priv.insn_start = pc;
3515
3516 obuf[0] = 0;
3517 for (i = 0; i < MAX_OPERANDS; ++i)
3518 {
3519 op_out[i][0] = 0;
3520 op_index[i] = -1;
3521 }
3522
3523 the_info = info;
3524 start_pc = pc;
3525 start_codep = priv.the_buffer;
3526 codep = priv.the_buffer;
3527
3528 if (setjmp (priv.bailout) != 0)
3529 {
3530 const char *name;
3531
3532 /* Getting here means we tried for data but didn't get it. That
3533 means we have an incomplete instruction of some sort. Just
3534 print the first byte as a prefix or a .byte pseudo-op. */
3535 if (codep > priv.the_buffer)
3536 {
3537 name = prefix_name (priv.the_buffer[0], priv.orig_sizeflag);
3538 if (name != NULL)
3539 (*info->fprintf_func) (info->stream, "%s", name);
3540 else
3541 {
3542 /* Just print the first byte as a .byte instruction. */
3543 (*info->fprintf_func) (info->stream, ".byte 0x%x",
3544 (unsigned int) priv.the_buffer[0]);
3545 }
3546
3547 return 1;
3548 }
3549
3550 return -1;
3551 }
3552
3553 obufp = obuf;
3554 ckprefix ();
3555
3556 insn_codep = codep;
3557 sizeflag = priv.orig_sizeflag;
3558
3559 FETCH_DATA (info, codep + 1);
3560 two_source_ops = (*codep == 0x62) || (*codep == 0xc8);
3561
3562 if (((prefixes & PREFIX_FWAIT)
3563 && ((*codep < 0xd8) || (*codep > 0xdf)))
3564 || (rex && rex_used))
3565 {
3566 const char *name;
3567
3568 /* fwait not followed by floating point instruction, or rex followed
3569 by other prefixes. Print the first prefix. */
3570 name = prefix_name (priv.the_buffer[0], priv.orig_sizeflag);
3571 if (name == NULL)
3572 name = INTERNAL_DISASSEMBLER_ERROR;
3573 (*info->fprintf_func) (info->stream, "%s", name);
3574 return 1;
3575 }
3576
3577 op = 0;
3578 if (*codep == 0x0f)
3579 {
3580 unsigned char threebyte;
3581 FETCH_DATA (info, codep + 2);
3582 threebyte = *++codep;
3583 dp = &dis386_twobyte[threebyte];
3584 need_modrm = twobyte_has_modrm[*codep];
3585 uses_DATA_prefix = twobyte_uses_DATA_prefix[*codep];
3586 uses_REPNZ_prefix = twobyte_uses_REPNZ_prefix[*codep];
3587 uses_REPZ_prefix = twobyte_uses_REPZ_prefix[*codep];
3588 uses_LOCK_prefix = (*codep & ~0x02) == 0x20;
3589 codep++;
3590 if (dp->name == NULL && dp->op[0].bytemode == IS_3BYTE_OPCODE)
3591 {
3592 FETCH_DATA (info, codep + 2);
3593 op = *codep++;
3594 switch (threebyte)
3595 {
3596 case 0x38:
3597 uses_DATA_prefix = threebyte_0x38_uses_DATA_prefix[op];
3598 uses_REPNZ_prefix = threebyte_0x38_uses_REPNZ_prefix[op];
3599 uses_REPZ_prefix = threebyte_0x38_uses_REPZ_prefix[op];
3600 break;
3601 case 0x3a:
3602 uses_DATA_prefix = threebyte_0x3a_uses_DATA_prefix[op];
3603 uses_REPNZ_prefix = threebyte_0x3a_uses_REPNZ_prefix[op];
3604 uses_REPZ_prefix = threebyte_0x3a_uses_REPZ_prefix[op];
3605 break;
3606 default:
3607 break;
3608 }
3609 }
3610 }
3611 else
3612 {
3613 dp = &dis386[*codep];
3614 need_modrm = onebyte_has_modrm[*codep];
3615 uses_DATA_prefix = 0;
3616 uses_REPNZ_prefix = 0;
3617 /* pause is 0xf3 0x90. */
3618 uses_REPZ_prefix = *codep == 0x90;
3619 uses_LOCK_prefix = 0;
3620 codep++;
3621 }
3622
3623 if (!uses_REPZ_prefix && (prefixes & PREFIX_REPZ))
3624 {
3625 oappend ("repz ");
3626 used_prefixes |= PREFIX_REPZ;
3627 }
3628 if (!uses_REPNZ_prefix && (prefixes & PREFIX_REPNZ))
3629 {
3630 oappend ("repnz ");
3631 used_prefixes |= PREFIX_REPNZ;
3632 }
3633
3634 if (!uses_LOCK_prefix && (prefixes & PREFIX_LOCK))
3635 {
3636 oappend ("lock ");
3637 used_prefixes |= PREFIX_LOCK;
3638 }
3639
3640 if (prefixes & PREFIX_ADDR)
3641 {
3642 sizeflag ^= AFLAG;
3643 if (dp->op[2].bytemode != loop_jcxz_mode || intel_syntax)
3644 {
3645 if ((sizeflag & AFLAG) || address_mode == mode_64bit)
3646 oappend ("addr32 ");
3647 else
3648 oappend ("addr16 ");
3649 used_prefixes |= PREFIX_ADDR;
3650 }
3651 }
3652
3653 if (!uses_DATA_prefix && (prefixes & PREFIX_DATA))
3654 {
3655 sizeflag ^= DFLAG;
3656 if (dp->op[2].bytemode == cond_jump_mode
3657 && dp->op[0].bytemode == v_mode
3658 && !intel_syntax)
3659 {
3660 if (sizeflag & DFLAG)
3661 oappend ("data32 ");
3662 else
3663 oappend ("data16 ");
3664 used_prefixes |= PREFIX_DATA;
3665 }
3666 }
3667
3668 if (dp->name == NULL && dp->op[0].bytemode == IS_3BYTE_OPCODE)
3669 {
3670 dp = &three_byte_table[dp->op[1].bytemode][op];
3671 modrm.mod = (*codep >> 6) & 3;
3672 modrm.reg = (*codep >> 3) & 7;
3673 modrm.rm = *codep & 7;
3674 }
3675 else if (need_modrm)
3676 {
3677 FETCH_DATA (info, codep + 1);
3678 modrm.mod = (*codep >> 6) & 3;
3679 modrm.reg = (*codep >> 3) & 7;
3680 modrm.rm = *codep & 7;
3681 }
3682
3683 if (dp->name == NULL && dp->op[0].bytemode == FLOATCODE)
3684 {
3685 dofloat (sizeflag);
3686 }
3687 else
3688 {
3689 int index;
3690 if (dp->name == NULL)
3691 {
3692 switch (dp->op[0].bytemode)
3693 {
3694 case USE_GROUPS:
3695 dp = &grps[dp->op[1].bytemode][modrm.reg];
3696 break;
3697
3698 case USE_PREFIX_USER_TABLE:
3699 index = 0;
3700 used_prefixes |= (prefixes & PREFIX_REPZ);
3701 if (prefixes & PREFIX_REPZ)
3702 index = 1;
3703 else
3704 {
3705 /* We should check PREFIX_REPNZ and PREFIX_REPZ
3706 before PREFIX_DATA. */
3707 used_prefixes |= (prefixes & PREFIX_REPNZ);
3708 if (prefixes & PREFIX_REPNZ)
3709 index = 3;
3710 else
3711 {
3712 used_prefixes |= (prefixes & PREFIX_DATA);
3713 if (prefixes & PREFIX_DATA)
3714 index = 2;
3715 }
3716 }
3717 dp = &prefix_user_table[dp->op[1].bytemode][index];
3718 break;
3719
3720 case X86_64_SPECIAL:
3721 index = address_mode == mode_64bit ? 1 : 0;
3722 dp = &x86_64_table[dp->op[1].bytemode][index];
3723 break;
3724
3725 default:
3726 oappend (INTERNAL_DISASSEMBLER_ERROR);
3727 break;
3728 }
3729 }
3730
3731 if (putop (dp->name, sizeflag) == 0)
3732 {
3733 for (i = 0; i < MAX_OPERANDS; ++i)
3734 {
3735 obufp = op_out[i];
3736 op_ad = MAX_OPERANDS - 1 - i;
3737 if (dp->op[i].rtn)
3738 (*dp->op[i].rtn) (dp->op[i].bytemode, sizeflag);
3739 }
3740 }
3741 }
3742
3743 /* See if any prefixes were not used. If so, print the first one
3744 separately. If we don't do this, we'll wind up printing an
3745 instruction stream which does not precisely correspond to the
3746 bytes we are disassembling. */
3747 if ((prefixes & ~used_prefixes) != 0)
3748 {
3749 const char *name;
3750
3751 name = prefix_name (priv.the_buffer[0], priv.orig_sizeflag);
3752 if (name == NULL)
3753 name = INTERNAL_DISASSEMBLER_ERROR;
3754 (*info->fprintf_func) (info->stream, "%s", name);
3755 return 1;
3756 }
3757 if (rex & ~rex_used)
3758 {
3759 const char *name;
3760 name = prefix_name (rex | 0x40, priv.orig_sizeflag);
3761 if (name == NULL)
3762 name = INTERNAL_DISASSEMBLER_ERROR;
3763 (*info->fprintf_func) (info->stream, "%s ", name);
3764 }
3765
3766 obufp = obuf + strlen (obuf);
3767 for (i = strlen (obuf); i < 6; i++)
3768 oappend (" ");
3769 oappend (" ");
3770 (*info->fprintf_func) (info->stream, "%s", obuf);
3771
3772 /* The enter and bound instructions are printed with operands in the same
3773 order as the intel book; everything else is printed in reverse order. */
3774 if (intel_syntax || two_source_ops)
3775 {
3776 for (i = 0; i < MAX_OPERANDS; ++i)
3777 op_txt[i] = op_out[i];
3778
3779 for (i = 0; i < (MAX_OPERANDS >> 1); ++i)
3780 {
3781 op_ad = op_index[i];
3782 op_index[i] = op_index[MAX_OPERANDS - 1 - i];
3783 op_index[MAX_OPERANDS - 1 - i] = op_ad;
3784 }
3785 }
3786 else
3787 {
3788 for (i = 0; i < MAX_OPERANDS; ++i)
3789 op_txt[MAX_OPERANDS - 1 - i] = op_out[i];
3790 }
3791
3792 needcomma = 0;
3793 for (i = 0; i < MAX_OPERANDS; ++i)
3794 if (*op_txt[i])
3795 {
3796 if (needcomma)
3797 (*info->fprintf_func) (info->stream, ",");
3798 if (op_index[i] != -1 && !op_riprel[i])
3799 (*info->print_address_func) ((bfd_vma) op_address[op_index[i]], info);
3800 else
3801 (*info->fprintf_func) (info->stream, "%s", op_txt[i]);
3802 needcomma = 1;
3803 }
3804
3805 for (i = 0; i < MAX_OPERANDS; i++)
3806 if (op_index[i] != -1 && op_riprel[i])
3807 {
3808 (*info->fprintf_func) (info->stream, " # ");
3809 (*info->print_address_func) ((bfd_vma) (start_pc + codep - start_codep
3810 + op_address[op_index[i]]), info);
3811 }
3812 return codep - priv.the_buffer;
3813 }
3814
3815 static const char *float_mem[] = {
3816 /* d8 */
3817 "fadd{s||s|}",
3818 "fmul{s||s|}",
3819 "fcom{s||s|}",
3820 "fcomp{s||s|}",
3821 "fsub{s||s|}",
3822 "fsubr{s||s|}",
3823 "fdiv{s||s|}",
3824 "fdivr{s||s|}",
3825 /* d9 */
3826 "fld{s||s|}",
3827 "(bad)",
3828 "fst{s||s|}",
3829 "fstp{s||s|}",
3830 "fldenvIC",
3831 "fldcw",
3832 "fNstenvIC",
3833 "fNstcw",
3834 /* da */
3835 "fiadd{l||l|}",
3836 "fimul{l||l|}",
3837 "ficom{l||l|}",
3838 "ficomp{l||l|}",
3839 "fisub{l||l|}",
3840 "fisubr{l||l|}",
3841 "fidiv{l||l|}",
3842 "fidivr{l||l|}",
3843 /* db */
3844 "fild{l||l|}",
3845 "fisttp{l||l|}",
3846 "fist{l||l|}",
3847 "fistp{l||l|}",
3848 "(bad)",
3849 "fld{t||t|}",
3850 "(bad)",
3851 "fstp{t||t|}",
3852 /* dc */
3853 "fadd{l||l|}",
3854 "fmul{l||l|}",
3855 "fcom{l||l|}",
3856 "fcomp{l||l|}",
3857 "fsub{l||l|}",
3858 "fsubr{l||l|}",
3859 "fdiv{l||l|}",
3860 "fdivr{l||l|}",
3861 /* dd */
3862 "fld{l||l|}",
3863 "fisttp{ll||ll|}",
3864 "fst{l||l|}",
3865 "fstp{l||l|}",
3866 "frstorIC",
3867 "(bad)",
3868 "fNsaveIC",
3869 "fNstsw",
3870 /* de */
3871 "fiadd",
3872 "fimul",
3873 "ficom",
3874 "ficomp",
3875 "fisub",
3876 "fisubr",
3877 "fidiv",
3878 "fidivr",
3879 /* df */
3880 "fild",
3881 "fisttp",
3882 "fist",
3883 "fistp",
3884 "fbld",
3885 "fild{ll||ll|}",
3886 "fbstp",
3887 "fistp{ll||ll|}",
3888 };
3889
3890 static const unsigned char float_mem_mode[] = {
3891 /* d8 */
3892 d_mode,
3893 d_mode,
3894 d_mode,
3895 d_mode,
3896 d_mode,
3897 d_mode,
3898 d_mode,
3899 d_mode,
3900 /* d9 */
3901 d_mode,
3902 0,
3903 d_mode,
3904 d_mode,
3905 0,
3906 w_mode,
3907 0,
3908 w_mode,
3909 /* da */
3910 d_mode,
3911 d_mode,
3912 d_mode,
3913 d_mode,
3914 d_mode,
3915 d_mode,
3916 d_mode,
3917 d_mode,
3918 /* db */
3919 d_mode,
3920 d_mode,
3921 d_mode,
3922 d_mode,
3923 0,
3924 t_mode,
3925 0,
3926 t_mode,
3927 /* dc */
3928 q_mode,
3929 q_mode,
3930 q_mode,
3931 q_mode,
3932 q_mode,
3933 q_mode,
3934 q_mode,
3935 q_mode,
3936 /* dd */
3937 q_mode,
3938 q_mode,
3939 q_mode,
3940 q_mode,
3941 0,
3942 0,
3943 0,
3944 w_mode,
3945 /* de */
3946 w_mode,
3947 w_mode,
3948 w_mode,
3949 w_mode,
3950 w_mode,
3951 w_mode,
3952 w_mode,
3953 w_mode,
3954 /* df */
3955 w_mode,
3956 w_mode,
3957 w_mode,
3958 w_mode,
3959 t_mode,
3960 q_mode,
3961 t_mode,
3962 q_mode
3963 };
3964
3965 #define ST { OP_ST, 0 }
3966 #define STi { OP_STi, 0 }
3967
3968 #define FGRPd9_2 NULL, { { NULL, 0 } }
3969 #define FGRPd9_4 NULL, { { NULL, 1 } }
3970 #define FGRPd9_5 NULL, { { NULL, 2 } }
3971 #define FGRPd9_6 NULL, { { NULL, 3 } }
3972 #define FGRPd9_7 NULL, { { NULL, 4 } }
3973 #define FGRPda_5 NULL, { { NULL, 5 } }
3974 #define FGRPdb_4 NULL, { { NULL, 6 } }
3975 #define FGRPde_3 NULL, { { NULL, 7 } }
3976 #define FGRPdf_4 NULL, { { NULL, 8 } }
3977
3978 static const struct dis386 float_reg[][8] = {
3979 /* d8 */
3980 {
3981 { "fadd", { ST, STi } },
3982 { "fmul", { ST, STi } },
3983 { "fcom", { STi } },
3984 { "fcomp", { STi } },
3985 { "fsub", { ST, STi } },
3986 { "fsubr", { ST, STi } },
3987 { "fdiv", { ST, STi } },
3988 { "fdivr", { ST, STi } },
3989 },
3990 /* d9 */
3991 {
3992 { "fld", { STi } },
3993 { "fxch", { STi } },
3994 { FGRPd9_2 },
3995 { "(bad)", { XX } },
3996 { FGRPd9_4 },
3997 { FGRPd9_5 },
3998 { FGRPd9_6 },
3999 { FGRPd9_7 },
4000 },
4001 /* da */
4002 {
4003 { "fcmovb", { ST, STi } },
4004 { "fcmove", { ST, STi } },
4005 { "fcmovbe",{ ST, STi } },
4006 { "fcmovu", { ST, STi } },
4007 { "(bad)", { XX } },
4008 { FGRPda_5 },
4009 { "(bad)", { XX } },
4010 { "(bad)", { XX } },
4011 },
4012 /* db */
4013 {
4014 { "fcmovnb",{ ST, STi } },
4015 { "fcmovne",{ ST, STi } },
4016 { "fcmovnbe",{ ST, STi } },
4017 { "fcmovnu",{ ST, STi } },
4018 { FGRPdb_4 },
4019 { "fucomi", { ST, STi } },
4020 { "fcomi", { ST, STi } },
4021 { "(bad)", { XX } },
4022 },
4023 /* dc */
4024 {
4025 { "fadd", { STi, ST } },
4026 { "fmul", { STi, ST } },
4027 { "(bad)", { XX } },
4028 { "(bad)", { XX } },
4029 #if SYSV386_COMPAT
4030 { "fsub", { STi, ST } },
4031 { "fsubr", { STi, ST } },
4032 { "fdiv", { STi, ST } },
4033 { "fdivr", { STi, ST } },
4034 #else
4035 { "fsubr", { STi, ST } },
4036 { "fsub", { STi, ST } },
4037 { "fdivr", { STi, ST } },
4038 { "fdiv", { STi, ST } },
4039 #endif
4040 },
4041 /* dd */
4042 {
4043 { "ffree", { STi } },
4044 { "(bad)", { XX } },
4045 { "fst", { STi } },
4046 { "fstp", { STi } },
4047 { "fucom", { STi } },
4048 { "fucomp", { STi } },
4049 { "(bad)", { XX } },
4050 { "(bad)", { XX } },
4051 },
4052 /* de */
4053 {
4054 { "faddp", { STi, ST } },
4055 { "fmulp", { STi, ST } },
4056 { "(bad)", { XX } },
4057 { FGRPde_3 },
4058 #if SYSV386_COMPAT
4059 { "fsubp", { STi, ST } },
4060 { "fsubrp", { STi, ST } },
4061 { "fdivp", { STi, ST } },
4062 { "fdivrp", { STi, ST } },
4063 #else
4064 { "fsubrp", { STi, ST } },
4065 { "fsubp", { STi, ST } },
4066 { "fdivrp", { STi, ST } },
4067 { "fdivp", { STi, ST } },
4068 #endif
4069 },
4070 /* df */
4071 {
4072 { "ffreep", { STi } },
4073 { "(bad)", { XX } },
4074 { "(bad)", { XX } },
4075 { "(bad)", { XX } },
4076 { FGRPdf_4 },
4077 { "fucomip", { ST, STi } },
4078 { "fcomip", { ST, STi } },
4079 { "(bad)", { XX } },
4080 },
4081 };
4082
4083 static char *fgrps[][8] = {
4084 /* d9_2 0 */
4085 {
4086 "fnop","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
4087 },
4088
4089 /* d9_4 1 */
4090 {
4091 "fchs","fabs","(bad)","(bad)","ftst","fxam","(bad)","(bad)",
4092 },
4093
4094 /* d9_5 2 */
4095 {
4096 "fld1","fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz","(bad)",
4097 },
4098
4099 /* d9_6 3 */
4100 {
4101 "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp","fincstp",
4102 },
4103
4104 /* d9_7 4 */
4105 {
4106 "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos",
4107 },
4108
4109 /* da_5 5 */
4110 {
4111 "(bad)","fucompp","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
4112 },
4113
4114 /* db_4 6 */
4115 {
4116 "feni(287 only)","fdisi(287 only)","fNclex","fNinit",
4117 "fNsetpm(287 only)","(bad)","(bad)","(bad)",
4118 },
4119
4120 /* de_3 7 */
4121 {
4122 "(bad)","fcompp","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
4123 },
4124
4125 /* df_4 8 */
4126 {
4127 "fNstsw","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
4128 },
4129 };
4130
4131 static void
4132 dofloat (int sizeflag)
4133 {
4134 const struct dis386 *dp;
4135 unsigned char floatop;
4136
4137 floatop = codep[-1];
4138
4139 if (modrm.mod != 3)
4140 {
4141 int fp_indx = (floatop - 0xd8) * 8 + modrm.reg;
4142
4143 putop (float_mem[fp_indx], sizeflag);
4144 obufp = op_out[0];
4145 op_ad = 2;
4146 OP_E (float_mem_mode[fp_indx], sizeflag);
4147 return;
4148 }
4149 /* Skip mod/rm byte. */
4150 MODRM_CHECK;
4151 codep++;
4152
4153 dp = &float_reg[floatop - 0xd8][modrm.reg];
4154 if (dp->name == NULL)
4155 {
4156 putop (fgrps[dp->op[0].bytemode][modrm.rm], sizeflag);
4157
4158 /* Instruction fnstsw is only one with strange arg. */
4159 if (floatop == 0xdf && codep[-1] == 0xe0)
4160 strcpy (op_out[0], names16[0]);
4161 }
4162 else
4163 {
4164 putop (dp->name, sizeflag);
4165
4166 obufp = op_out[0];
4167 op_ad = 2;
4168 if (dp->op[0].rtn)
4169 (*dp->op[0].rtn) (dp->op[0].bytemode, sizeflag);
4170
4171 obufp = op_out[1];
4172 op_ad = 1;
4173 if (dp->op[1].rtn)
4174 (*dp->op[1].rtn) (dp->op[1].bytemode, sizeflag);
4175 }
4176 }
4177
4178 static void
4179 OP_ST (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
4180 {
4181 oappend ("%st" + intel_syntax);
4182 }
4183
4184 static void
4185 OP_STi (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
4186 {
4187 sprintf (scratchbuf, "%%st(%d)", modrm.rm);
4188 oappend (scratchbuf + intel_syntax);
4189 }
4190
4191 /* Capital letters in template are macros. */
4192 static int
4193 putop (const char *template, int sizeflag)
4194 {
4195 const char *p;
4196 int alt = 0;
4197
4198 for (p = template; *p; p++)
4199 {
4200 switch (*p)
4201 {
4202 default:
4203 *obufp++ = *p;
4204 break;
4205 case '{':
4206 alt = 0;
4207 if (intel_syntax)
4208 alt += 1;
4209 if (address_mode == mode_64bit)
4210 alt += 2;
4211 while (alt != 0)
4212 {
4213 while (*++p != '|')
4214 {
4215 if (*p == '}')
4216 {
4217 /* Alternative not valid. */
4218 strcpy (obuf, "(bad)");
4219 obufp = obuf + 5;
4220 return 1;
4221 }
4222 else if (*p == '\0')
4223 abort ();
4224 }
4225 alt--;
4226 }
4227 /* Fall through. */
4228 case 'I':
4229 alt = 1;
4230 continue;
4231 case '|':
4232 while (*++p != '}')
4233 {
4234 if (*p == '\0')
4235 abort ();
4236 }
4237 break;
4238 case '}':
4239 break;
4240 case 'A':
4241 if (intel_syntax)
4242 break;
4243 if (modrm.mod != 3 || (sizeflag & SUFFIX_ALWAYS))
4244 *obufp++ = 'b';
4245 break;
4246 case 'B':
4247 if (intel_syntax)
4248 break;
4249 if (sizeflag & SUFFIX_ALWAYS)
4250 *obufp++ = 'b';
4251 break;
4252 case 'C':
4253 if (intel_syntax && !alt)
4254 break;
4255 if ((prefixes & PREFIX_DATA) || (sizeflag & SUFFIX_ALWAYS))
4256 {
4257 if (sizeflag & DFLAG)
4258 *obufp++ = intel_syntax ? 'd' : 'l';
4259 else
4260 *obufp++ = intel_syntax ? 'w' : 's';
4261 used_prefixes |= (prefixes & PREFIX_DATA);
4262 }
4263 break;
4264 case 'D':
4265 if (intel_syntax || !(sizeflag & SUFFIX_ALWAYS))
4266 break;
4267 USED_REX (REX_W);
4268 if (modrm.mod == 3)
4269 {
4270 if (rex & REX_W)
4271 *obufp++ = 'q';
4272 else if (sizeflag & DFLAG)
4273 *obufp++ = intel_syntax ? 'd' : 'l';
4274 else
4275 *obufp++ = 'w';
4276 used_prefixes |= (prefixes & PREFIX_DATA);
4277 }
4278 else
4279 *obufp++ = 'w';
4280 break;
4281 case 'E': /* For jcxz/jecxz */
4282 if (address_mode == mode_64bit)
4283 {
4284 if (sizeflag & AFLAG)
4285 *obufp++ = 'r';
4286 else
4287 *obufp++ = 'e';
4288 }
4289 else
4290 if (sizeflag & AFLAG)
4291 *obufp++ = 'e';
4292 used_prefixes |= (prefixes & PREFIX_ADDR);
4293 break;
4294 case 'F':
4295 if (intel_syntax)
4296 break;
4297 if ((prefixes & PREFIX_ADDR) || (sizeflag & SUFFIX_ALWAYS))
4298 {
4299 if (sizeflag & AFLAG)
4300 *obufp++ = address_mode == mode_64bit ? 'q' : 'l';
4301 else
4302 *obufp++ = address_mode == mode_64bit ? 'l' : 'w';
4303 used_prefixes |= (prefixes & PREFIX_ADDR);
4304 }
4305 break;
4306 case 'G':
4307 if (intel_syntax || (obufp[-1] != 's' && !(sizeflag & SUFFIX_ALWAYS)))
4308 break;
4309 if ((rex & REX_W) || (sizeflag & DFLAG))
4310 *obufp++ = 'l';
4311 else
4312 *obufp++ = 'w';
4313 if (!(rex & REX_W))
4314 used_prefixes |= (prefixes & PREFIX_DATA);
4315 break;
4316 case 'H':
4317 if (intel_syntax)
4318 break;
4319 if ((prefixes & (PREFIX_CS | PREFIX_DS)) == PREFIX_CS
4320 || (prefixes & (PREFIX_CS | PREFIX_DS)) == PREFIX_DS)
4321 {
4322 used_prefixes |= prefixes & (PREFIX_CS | PREFIX_DS);
4323 *obufp++ = ',';
4324 *obufp++ = 'p';
4325 if (prefixes & PREFIX_DS)
4326 *obufp++ = 't';
4327 else
4328 *obufp++ = 'n';
4329 }
4330 break;
4331 case 'J':
4332 if (intel_syntax)
4333 break;
4334 *obufp++ = 'l';
4335 break;
4336 case 'K':
4337 USED_REX (REX_W);
4338 if (rex & REX_W)
4339 *obufp++ = 'q';
4340 else
4341 *obufp++ = 'd';
4342 break;
4343 case 'Z':
4344 if (intel_syntax)
4345 break;
4346 if (address_mode == mode_64bit && (sizeflag & SUFFIX_ALWAYS))
4347 {
4348 *obufp++ = 'q';
4349 break;
4350 }
4351 /* Fall through. */
4352 case 'L':
4353 if (intel_syntax)
4354 break;
4355 if (sizeflag & SUFFIX_ALWAYS)
4356 *obufp++ = 'l';
4357 break;
4358 case 'N':
4359 if ((prefixes & PREFIX_FWAIT) == 0)
4360 *obufp++ = 'n';
4361 else
4362 used_prefixes |= PREFIX_FWAIT;
4363 break;
4364 case 'O':
4365 USED_REX (REX_W);
4366 if (rex & REX_W)
4367 *obufp++ = 'o';
4368 else if (intel_syntax && (sizeflag & DFLAG))
4369 *obufp++ = 'q';
4370 else
4371 *obufp++ = 'd';
4372 if (!(rex & REX_W))
4373 used_prefixes |= (prefixes & PREFIX_DATA);
4374 break;
4375 case 'T':
4376 if (intel_syntax)
4377 break;
4378 if (address_mode == mode_64bit && (sizeflag & DFLAG))
4379 {
4380 *obufp++ = 'q';
4381 break;
4382 }
4383 /* Fall through. */
4384 case 'P':
4385 if (intel_syntax)
4386 break;
4387 if ((prefixes & PREFIX_DATA)
4388 || (rex & REX_W)
4389 || (sizeflag & SUFFIX_ALWAYS))
4390 {
4391 USED_REX (REX_W);
4392 if (rex & REX_W)
4393 *obufp++ = 'q';
4394 else
4395 {
4396 if (sizeflag & DFLAG)
4397 *obufp++ = 'l';
4398 else
4399 *obufp++ = 'w';
4400 }
4401 used_prefixes |= (prefixes & PREFIX_DATA);
4402 }
4403 break;
4404 case 'U':
4405 if (intel_syntax)
4406 break;
4407 if (address_mode == mode_64bit && (sizeflag & DFLAG))
4408 {
4409 if (modrm.mod != 3 || (sizeflag & SUFFIX_ALWAYS))
4410 *obufp++ = 'q';
4411 break;
4412 }
4413 /* Fall through. */
4414 case 'Q':
4415 if (intel_syntax && !alt)
4416 break;
4417 USED_REX (REX_W);
4418 if (modrm.mod != 3 || (sizeflag & SUFFIX_ALWAYS))
4419 {
4420 if (rex & REX_W)
4421 *obufp++ = 'q';
4422 else
4423 {
4424 if (sizeflag & DFLAG)
4425 *obufp++ = intel_syntax ? 'd' : 'l';
4426 else
4427 *obufp++ = 'w';
4428 }
4429 used_prefixes |= (prefixes & PREFIX_DATA);
4430 }
4431 break;
4432 case 'R':
4433 USED_REX (REX_W);
4434 if (rex & REX_W)
4435 *obufp++ = 'q';
4436 else if (sizeflag & DFLAG)
4437 {
4438 if (intel_syntax)
4439 *obufp++ = 'd';
4440 else
4441 *obufp++ = 'l';
4442 }
4443 else
4444 *obufp++ = 'w';
4445 if (intel_syntax && !p[1]
4446 && ((rex & REX_W) || (sizeflag & DFLAG)))
4447 *obufp++ = 'e';
4448 if (!(rex & REX_W))
4449 used_prefixes |= (prefixes & PREFIX_DATA);
4450 break;
4451 case 'V':
4452 if (intel_syntax)
4453 break;
4454 if (address_mode == mode_64bit && (sizeflag & DFLAG))
4455 {
4456 if (sizeflag & SUFFIX_ALWAYS)
4457 *obufp++ = 'q';
4458 break;
4459 }
4460 /* Fall through. */
4461 case 'S':
4462 if (intel_syntax)
4463 break;
4464 if (sizeflag & SUFFIX_ALWAYS)
4465 {
4466 if (rex & REX_W)
4467 *obufp++ = 'q';
4468 else
4469 {
4470 if (sizeflag & DFLAG)
4471 *obufp++ = 'l';
4472 else
4473 *obufp++ = 'w';
4474 used_prefixes |= (prefixes & PREFIX_DATA);
4475 }
4476 }
4477 break;
4478 case 'X':
4479 if (prefixes & PREFIX_DATA)
4480 *obufp++ = 'd';
4481 else
4482 *obufp++ = 's';
4483 used_prefixes |= (prefixes & PREFIX_DATA);
4484 break;
4485 case 'Y':
4486 if (intel_syntax)
4487 break;
4488 if (rex & REX_W)
4489 {
4490 USED_REX (REX_W);
4491 *obufp++ = 'q';
4492 }
4493 break;
4494 /* implicit operand size 'l' for i386 or 'q' for x86-64 */
4495 case 'W':
4496 /* operand size flag for cwtl, cbtw */
4497 USED_REX (REX_W);
4498 if (rex & REX_W)
4499 {
4500 if (intel_syntax)
4501 *obufp++ = 'd';
4502 else
4503 *obufp++ = 'l';
4504 }
4505 else if (sizeflag & DFLAG)
4506 *obufp++ = 'w';
4507 else
4508 *obufp++ = 'b';
4509 if (!(rex & REX_W))
4510 used_prefixes |= (prefixes & PREFIX_DATA);
4511 break;
4512 }
4513 alt = 0;
4514 }
4515 *obufp = 0;
4516 return 0;
4517 }
4518
4519 static void
4520 oappend (const char *s)
4521 {
4522 strcpy (obufp, s);
4523 obufp += strlen (s);
4524 }
4525
4526 static void
4527 append_seg (void)
4528 {
4529 if (prefixes & PREFIX_CS)
4530 {
4531 used_prefixes |= PREFIX_CS;
4532 oappend ("%cs:" + intel_syntax);
4533 }
4534 if (prefixes & PREFIX_DS)
4535 {
4536 used_prefixes |= PREFIX_DS;
4537 oappend ("%ds:" + intel_syntax);
4538 }
4539 if (prefixes & PREFIX_SS)
4540 {
4541 used_prefixes |= PREFIX_SS;
4542 oappend ("%ss:" + intel_syntax);
4543 }
4544 if (prefixes & PREFIX_ES)
4545 {
4546 used_prefixes |= PREFIX_ES;
4547 oappend ("%es:" + intel_syntax);
4548 }
4549 if (prefixes & PREFIX_FS)
4550 {
4551 used_prefixes |= PREFIX_FS;
4552 oappend ("%fs:" + intel_syntax);
4553 }
4554 if (prefixes & PREFIX_GS)
4555 {
4556 used_prefixes |= PREFIX_GS;
4557 oappend ("%gs:" + intel_syntax);
4558 }
4559 }
4560
4561 static void
4562 OP_indirE (int bytemode, int sizeflag)
4563 {
4564 if (!intel_syntax)
4565 oappend ("*");
4566 OP_E (bytemode, sizeflag);
4567 }
4568
4569 static void
4570 print_operand_value (char *buf, int hex, bfd_vma disp)
4571 {
4572 if (address_mode == mode_64bit)
4573 {
4574 if (hex)
4575 {
4576 char tmp[30];
4577 int i;
4578 buf[0] = '0';
4579 buf[1] = 'x';
4580 sprintf_vma (tmp, disp);
4581 for (i = 0; tmp[i] == '0' && tmp[i + 1]; i++);
4582 strcpy (buf + 2, tmp + i);
4583 }
4584 else
4585 {
4586 bfd_signed_vma v = disp;
4587 char tmp[30];
4588 int i;
4589 if (v < 0)
4590 {
4591 *(buf++) = '-';
4592 v = -disp;
4593 /* Check for possible overflow on 0x8000000000000000. */
4594 if (v < 0)
4595 {
4596 strcpy (buf, "9223372036854775808");
4597 return;
4598 }
4599 }
4600 if (!v)
4601 {
4602 strcpy (buf, "0");
4603 return;
4604 }
4605
4606 i = 0;
4607 tmp[29] = 0;
4608 while (v)
4609 {
4610 tmp[28 - i] = (v % 10) + '0';
4611 v /= 10;
4612 i++;
4613 }
4614 strcpy (buf, tmp + 29 - i);
4615 }
4616 }
4617 else
4618 {
4619 if (hex)
4620 sprintf (buf, "0x%x", (unsigned int) disp);
4621 else
4622 sprintf (buf, "%d", (int) disp);
4623 }
4624 }
4625
4626 static void
4627 intel_operand_size (int bytemode, int sizeflag)
4628 {
4629 switch (bytemode)
4630 {
4631 case b_mode:
4632 case dqb_mode:
4633 oappend ("BYTE PTR ");
4634 break;
4635 case w_mode:
4636 case dqw_mode:
4637 oappend ("WORD PTR ");
4638 break;
4639 case stack_v_mode:
4640 if (address_mode == mode_64bit && (sizeflag & DFLAG))
4641 {
4642 oappend ("QWORD PTR ");
4643 used_prefixes |= (prefixes & PREFIX_DATA);
4644 break;
4645 }
4646 /* FALLTHRU */
4647 case v_mode:
4648 case dq_mode:
4649 USED_REX (REX_W);
4650 if (rex & REX_W)
4651 oappend ("QWORD PTR ");
4652 else if ((sizeflag & DFLAG) || bytemode == dq_mode)
4653 oappend ("DWORD PTR ");
4654 else
4655 oappend ("WORD PTR ");
4656 used_prefixes |= (prefixes & PREFIX_DATA);
4657 break;
4658 case z_mode:
4659 if ((rex & REX_W) || (sizeflag & DFLAG))
4660 *obufp++ = 'D';
4661 oappend ("WORD PTR ");
4662 if (!(rex & REX_W))
4663 used_prefixes |= (prefixes & PREFIX_DATA);
4664 break;
4665 case d_mode:
4666 case dqd_mode:
4667 oappend ("DWORD PTR ");
4668 break;
4669 case q_mode:
4670 oappend ("QWORD PTR ");
4671 break;
4672 case m_mode:
4673 if (address_mode == mode_64bit)
4674 oappend ("QWORD PTR ");
4675 else
4676 oappend ("DWORD PTR ");
4677 break;
4678 case f_mode:
4679 if (sizeflag & DFLAG)
4680 oappend ("FWORD PTR ");
4681 else
4682 oappend ("DWORD PTR ");
4683 used_prefixes |= (prefixes & PREFIX_DATA);
4684 break;
4685 case t_mode:
4686 oappend ("TBYTE PTR ");
4687 break;
4688 case x_mode:
4689 oappend ("XMMWORD PTR ");
4690 break;
4691 case o_mode:
4692 oappend ("OWORD PTR ");
4693 break;
4694 default:
4695 break;
4696 }
4697 }
4698
4699 static void
4700 OP_E (int bytemode, int sizeflag)
4701 {
4702 bfd_vma disp;
4703 int add = 0;
4704 int riprel = 0;
4705 USED_REX (REX_B);
4706 if (rex & REX_B)
4707 add += 8;
4708
4709 /* Skip mod/rm byte. */
4710 MODRM_CHECK;
4711 codep++;
4712
4713 if (modrm.mod == 3)
4714 {
4715 switch (bytemode)
4716 {
4717 case b_mode:
4718 USED_REX (0);
4719 if (rex)
4720 oappend (names8rex[modrm.rm + add]);
4721 else
4722 oappend (names8[modrm.rm + add]);
4723 break;
4724 case w_mode:
4725 oappend (names16[modrm.rm + add]);
4726 break;
4727 case d_mode:
4728 oappend (names32[modrm.rm + add]);
4729 break;
4730 case q_mode:
4731 oappend (names64[modrm.rm + add]);
4732 break;
4733 case m_mode:
4734 if (address_mode == mode_64bit)
4735 oappend (names64[modrm.rm + add]);
4736 else
4737 oappend (names32[modrm.rm + add]);
4738 break;
4739 case stack_v_mode:
4740 if (address_mode == mode_64bit && (sizeflag & DFLAG))
4741 {
4742 oappend (names64[modrm.rm + add]);
4743 used_prefixes |= (prefixes & PREFIX_DATA);
4744 break;
4745 }
4746 bytemode = v_mode;
4747 /* FALLTHRU */
4748 case v_mode:
4749 case dq_mode:
4750 case dqb_mode:
4751 case dqd_mode:
4752 case dqw_mode:
4753 USED_REX (REX_W);
4754 if (rex & REX_W)
4755 oappend (names64[modrm.rm + add]);
4756 else if ((sizeflag & DFLAG) || bytemode != v_mode)
4757 oappend (names32[modrm.rm + add]);
4758 else
4759 oappend (names16[modrm.rm + add]);
4760 used_prefixes |= (prefixes & PREFIX_DATA);
4761 break;
4762 case 0:
4763 break;
4764 default:
4765 oappend (INTERNAL_DISASSEMBLER_ERROR);
4766 break;
4767 }
4768 return;
4769 }
4770
4771 disp = 0;
4772 if (intel_syntax)
4773 intel_operand_size (bytemode, sizeflag);
4774 append_seg ();
4775
4776 if ((sizeflag & AFLAG) || address_mode == mode_64bit) /* 32 bit address mode */
4777 {
4778 int havesib;
4779 int havebase;
4780 int base;
4781 int index = 0;
4782 int scale = 0;
4783
4784 havesib = 0;
4785 havebase = 1;
4786 base = modrm.rm;
4787
4788 if (base == 4)
4789 {
4790 havesib = 1;
4791 FETCH_DATA (the_info, codep + 1);
4792 index = (*codep >> 3) & 7;
4793 if (address_mode == mode_64bit || index != 0x4)
4794 /* When INDEX == 0x4 in 32 bit mode, SCALE is ignored. */
4795 scale = (*codep >> 6) & 3;
4796 base = *codep & 7;
4797 USED_REX (REX_X);
4798 if (rex & REX_X)
4799 index += 8;
4800 codep++;
4801 }
4802 base += add;
4803
4804 switch (modrm.mod)
4805 {
4806 case 0:
4807 if ((base & 7) == 5)
4808 {
4809 havebase = 0;
4810 if (address_mode == mode_64bit && !havesib)
4811 riprel = 1;
4812 disp = get32s ();
4813 }
4814 break;
4815 case 1:
4816 FETCH_DATA (the_info, codep + 1);
4817 disp = *codep++;
4818 if ((disp & 0x80) != 0)
4819 disp -= 0x100;
4820 break;
4821 case 2:
4822 disp = get32s ();
4823 break;
4824 }
4825
4826 if (!intel_syntax)
4827 if (modrm.mod != 0 || (base & 7) == 5)
4828 {
4829 print_operand_value (scratchbuf, !riprel, disp);
4830 oappend (scratchbuf);
4831 if (riprel)
4832 {
4833 set_op (disp, 1);
4834 oappend ("(%rip)");
4835 }
4836 }
4837
4838 if (havebase || (havesib && (index != 4 || scale != 0)))
4839 {
4840 *obufp++ = open_char;
4841 if (intel_syntax && riprel)
4842 oappend ("rip + ");
4843 *obufp = '\0';
4844 if (havebase)
4845 oappend (address_mode == mode_64bit && (sizeflag & AFLAG)
4846 ? names64[base] : names32[base]);
4847 if (havesib)
4848 {
4849 if (index != 4)
4850 {
4851 if (!intel_syntax || havebase)
4852 {
4853 *obufp++ = separator_char;
4854 *obufp = '\0';
4855 }
4856 oappend (address_mode == mode_64bit && (sizeflag & AFLAG)
4857 ? names64[index] : names32[index]);
4858 }
4859 if (scale != 0 || (!intel_syntax && index != 4))
4860 {
4861 *obufp++ = scale_char;
4862 *obufp = '\0';
4863 sprintf (scratchbuf, "%d", 1 << scale);
4864 oappend (scratchbuf);
4865 }
4866 }
4867 if (intel_syntax && disp)
4868 {
4869 if ((bfd_signed_vma) disp > 0)
4870 {
4871 *obufp++ = '+';
4872 *obufp = '\0';
4873 }
4874 else if (modrm.mod != 1)
4875 {
4876 *obufp++ = '-';
4877 *obufp = '\0';
4878 disp = - (bfd_signed_vma) disp;
4879 }
4880
4881 print_operand_value (scratchbuf, modrm.mod != 1, disp);
4882 oappend (scratchbuf);
4883 }
4884
4885 *obufp++ = close_char;
4886 *obufp = '\0';
4887 }
4888 else if (intel_syntax)
4889 {
4890 if (modrm.mod != 0 || (base & 7) == 5)
4891 {
4892 if (prefixes & (PREFIX_CS | PREFIX_SS | PREFIX_DS
4893 | PREFIX_ES | PREFIX_FS | PREFIX_GS))
4894 ;
4895 else
4896 {
4897 oappend (names_seg[ds_reg - es_reg]);
4898 oappend (":");
4899 }
4900 print_operand_value (scratchbuf, 1, disp);
4901 oappend (scratchbuf);
4902 }
4903 }
4904 }
4905 else
4906 { /* 16 bit address mode */
4907 switch (modrm.mod)
4908 {
4909 case 0:
4910 if (modrm.rm == 6)
4911 {
4912 disp = get16 ();
4913 if ((disp & 0x8000) != 0)
4914 disp -= 0x10000;
4915 }
4916 break;
4917 case 1:
4918 FETCH_DATA (the_info, codep + 1);
4919 disp = *codep++;
4920 if ((disp & 0x80) != 0)
4921 disp -= 0x100;
4922 break;
4923 case 2:
4924 disp = get16 ();
4925 if ((disp & 0x8000) != 0)
4926 disp -= 0x10000;
4927 break;
4928 }
4929
4930 if (!intel_syntax)
4931 if (modrm.mod != 0 || modrm.rm == 6)
4932 {
4933 print_operand_value (scratchbuf, 0, disp);
4934 oappend (scratchbuf);
4935 }
4936
4937 if (modrm.mod != 0 || modrm.rm != 6)
4938 {
4939 *obufp++ = open_char;
4940 *obufp = '\0';
4941 oappend (index16[modrm.rm]);
4942 if (intel_syntax && disp)
4943 {
4944 if ((bfd_signed_vma) disp > 0)
4945 {
4946 *obufp++ = '+';
4947 *obufp = '\0';
4948 }
4949 else if (modrm.mod != 1)
4950 {
4951 *obufp++ = '-';
4952 *obufp = '\0';
4953 disp = - (bfd_signed_vma) disp;
4954 }
4955
4956 print_operand_value (scratchbuf, modrm.mod != 1, disp);
4957 oappend (scratchbuf);
4958 }
4959
4960 *obufp++ = close_char;
4961 *obufp = '\0';
4962 }
4963 else if (intel_syntax)
4964 {
4965 if (prefixes & (PREFIX_CS | PREFIX_SS | PREFIX_DS
4966 | PREFIX_ES | PREFIX_FS | PREFIX_GS))
4967 ;
4968 else
4969 {
4970 oappend (names_seg[ds_reg - es_reg]);
4971 oappend (":");
4972 }
4973 print_operand_value (scratchbuf, 1, disp & 0xffff);
4974 oappend (scratchbuf);
4975 }
4976 }
4977 }
4978
4979 static void
4980 OP_G (int bytemode, int sizeflag)
4981 {
4982 int add = 0;
4983 USED_REX (REX_R);
4984 if (rex & REX_R)
4985 add += 8;
4986 switch (bytemode)
4987 {
4988 case b_mode:
4989 USED_REX (0);
4990 if (rex)
4991 oappend (names8rex[modrm.reg + add]);
4992 else
4993 oappend (names8[modrm.reg + add]);
4994 break;
4995 case w_mode:
4996 oappend (names16[modrm.reg + add]);
4997 break;
4998 case d_mode:
4999 oappend (names32[modrm.reg + add]);
5000 break;
5001 case q_mode:
5002 oappend (names64[modrm.reg + add]);
5003 break;
5004 case v_mode:
5005 case dq_mode:
5006 case dqb_mode:
5007 case dqd_mode:
5008 case dqw_mode:
5009 USED_REX (REX_W);
5010 if (rex & REX_W)
5011 oappend (names64[modrm.reg + add]);
5012 else if ((sizeflag & DFLAG) || bytemode != v_mode)
5013 oappend (names32[modrm.reg + add]);
5014 else
5015 oappend (names16[modrm.reg + add]);
5016 used_prefixes |= (prefixes & PREFIX_DATA);
5017 break;
5018 case m_mode:
5019 if (address_mode == mode_64bit)
5020 oappend (names64[modrm.reg + add]);
5021 else
5022 oappend (names32[modrm.reg + add]);
5023 break;
5024 default:
5025 oappend (INTERNAL_DISASSEMBLER_ERROR);
5026 break;
5027 }
5028 }
5029
5030 static bfd_vma
5031 get64 (void)
5032 {
5033 bfd_vma x;
5034 #ifdef BFD64
5035 unsigned int a;
5036 unsigned int b;
5037
5038 FETCH_DATA (the_info, codep + 8);
5039 a = *codep++ & 0xff;
5040 a |= (*codep++ & 0xff) << 8;
5041 a |= (*codep++ & 0xff) << 16;
5042 a |= (*codep++ & 0xff) << 24;
5043 b = *codep++ & 0xff;
5044 b |= (*codep++ & 0xff) << 8;
5045 b |= (*codep++ & 0xff) << 16;
5046 b |= (*codep++ & 0xff) << 24;
5047 x = a + ((bfd_vma) b << 32);
5048 #else
5049 abort ();
5050 x = 0;
5051 #endif
5052 return x;
5053 }
5054
5055 static bfd_signed_vma
5056 get32 (void)
5057 {
5058 bfd_signed_vma x = 0;
5059
5060 FETCH_DATA (the_info, codep + 4);
5061 x = *codep++ & (bfd_signed_vma) 0xff;
5062 x |= (*codep++ & (bfd_signed_vma) 0xff) << 8;
5063 x |= (*codep++ & (bfd_signed_vma) 0xff) << 16;
5064 x |= (*codep++ & (bfd_signed_vma) 0xff) << 24;
5065 return x;
5066 }
5067
5068 static bfd_signed_vma
5069 get32s (void)
5070 {
5071 bfd_signed_vma x = 0;
5072
5073 FETCH_DATA (the_info, codep + 4);
5074 x = *codep++ & (bfd_signed_vma) 0xff;
5075 x |= (*codep++ & (bfd_signed_vma) 0xff) << 8;
5076 x |= (*codep++ & (bfd_signed_vma) 0xff) << 16;
5077 x |= (*codep++ & (bfd_signed_vma) 0xff) << 24;
5078
5079 x = (x ^ ((bfd_signed_vma) 1 << 31)) - ((bfd_signed_vma) 1 << 31);
5080
5081 return x;
5082 }
5083
5084 static int
5085 get16 (void)
5086 {
5087 int x = 0;
5088
5089 FETCH_DATA (the_info, codep + 2);
5090 x = *codep++ & 0xff;
5091 x |= (*codep++ & 0xff) << 8;
5092 return x;
5093 }
5094
5095 static void
5096 set_op (bfd_vma op, int riprel)
5097 {
5098 op_index[op_ad] = op_ad;
5099 if (address_mode == mode_64bit)
5100 {
5101 op_address[op_ad] = op;
5102 op_riprel[op_ad] = riprel;
5103 }
5104 else
5105 {
5106 /* Mask to get a 32-bit address. */
5107 op_address[op_ad] = op & 0xffffffff;
5108 op_riprel[op_ad] = riprel & 0xffffffff;
5109 }
5110 }
5111
5112 static void
5113 OP_REG (int code, int sizeflag)
5114 {
5115 const char *s;
5116 int add = 0;
5117 USED_REX (REX_B);
5118 if (rex & REX_B)
5119 add = 8;
5120
5121 switch (code)
5122 {
5123 case ax_reg: case cx_reg: case dx_reg: case bx_reg:
5124 case sp_reg: case bp_reg: case si_reg: case di_reg:
5125 s = names16[code - ax_reg + add];
5126 break;
5127 case es_reg: case ss_reg: case cs_reg:
5128 case ds_reg: case fs_reg: case gs_reg:
5129 s = names_seg[code - es_reg + add];
5130 break;
5131 case al_reg: case ah_reg: case cl_reg: case ch_reg:
5132 case dl_reg: case dh_reg: case bl_reg: case bh_reg:
5133 USED_REX (0);
5134 if (rex)
5135 s = names8rex[code - al_reg + add];
5136 else
5137 s = names8[code - al_reg];
5138 break;
5139 case rAX_reg: case rCX_reg: case rDX_reg: case rBX_reg:
5140 case rSP_reg: case rBP_reg: case rSI_reg: case rDI_reg:
5141 if (address_mode == mode_64bit && (sizeflag & DFLAG))
5142 {
5143 s = names64[code - rAX_reg + add];
5144 break;
5145 }
5146 code += eAX_reg - rAX_reg;
5147 /* Fall through. */
5148 case eAX_reg: case eCX_reg: case eDX_reg: case eBX_reg:
5149 case eSP_reg: case eBP_reg: case eSI_reg: case eDI_reg:
5150 USED_REX (REX_W);
5151 if (rex & REX_W)
5152 s = names64[code - eAX_reg + add];
5153 else if (sizeflag & DFLAG)
5154 s = names32[code - eAX_reg + add];
5155 else
5156 s = names16[code - eAX_reg + add];
5157 used_prefixes |= (prefixes & PREFIX_DATA);
5158 break;
5159 default:
5160 s = INTERNAL_DISASSEMBLER_ERROR;
5161 break;
5162 }
5163 oappend (s);
5164 }
5165
5166 static void
5167 OP_IMREG (int code, int sizeflag)
5168 {
5169 const char *s;
5170
5171 switch (code)
5172 {
5173 case indir_dx_reg:
5174 if (intel_syntax)
5175 s = "dx";
5176 else
5177 s = "(%dx)";
5178 break;
5179 case ax_reg: case cx_reg: case dx_reg: case bx_reg:
5180 case sp_reg: case bp_reg: case si_reg: case di_reg:
5181 s = names16[code - ax_reg];
5182 break;
5183 case es_reg: case ss_reg: case cs_reg:
5184 case ds_reg: case fs_reg: case gs_reg:
5185 s = names_seg[code - es_reg];
5186 break;
5187 case al_reg: case ah_reg: case cl_reg: case ch_reg:
5188 case dl_reg: case dh_reg: case bl_reg: case bh_reg:
5189 USED_REX (0);
5190 if (rex)
5191 s = names8rex[code - al_reg];
5192 else
5193 s = names8[code - al_reg];
5194 break;
5195 case eAX_reg: case eCX_reg: case eDX_reg: case eBX_reg:
5196 case eSP_reg: case eBP_reg: case eSI_reg: case eDI_reg:
5197 USED_REX (REX_W);
5198 if (rex & REX_W)
5199 s = names64[code - eAX_reg];
5200 else if (sizeflag & DFLAG)
5201 s = names32[code - eAX_reg];
5202 else
5203 s = names16[code - eAX_reg];
5204 used_prefixes |= (prefixes & PREFIX_DATA);
5205 break;
5206 case z_mode_ax_reg:
5207 if ((rex & REX_W) || (sizeflag & DFLAG))
5208 s = *names32;
5209 else
5210 s = *names16;
5211 if (!(rex & REX_W))
5212 used_prefixes |= (prefixes & PREFIX_DATA);
5213 break;
5214 default:
5215 s = INTERNAL_DISASSEMBLER_ERROR;
5216 break;
5217 }
5218 oappend (s);
5219 }
5220
5221 static void
5222 OP_I (int bytemode, int sizeflag)
5223 {
5224 bfd_signed_vma op;
5225 bfd_signed_vma mask = -1;
5226
5227 switch (bytemode)
5228 {
5229 case b_mode:
5230 FETCH_DATA (the_info, codep + 1);
5231 op = *codep++;
5232 mask = 0xff;
5233 break;
5234 case q_mode:
5235 if (address_mode == mode_64bit)
5236 {
5237 op = get32s ();
5238 break;
5239 }
5240 /* Fall through. */
5241 case v_mode:
5242 USED_REX (REX_W);
5243 if (rex & REX_W)
5244 op = get32s ();
5245 else if (sizeflag & DFLAG)
5246 {
5247 op = get32 ();
5248 mask = 0xffffffff;
5249 }
5250 else
5251 {
5252 op = get16 ();
5253 mask = 0xfffff;
5254 }
5255 used_prefixes |= (prefixes & PREFIX_DATA);
5256 break;
5257 case w_mode:
5258 mask = 0xfffff;
5259 op = get16 ();
5260 break;
5261 case const_1_mode:
5262 if (intel_syntax)
5263 oappend ("1");
5264 return;
5265 default:
5266 oappend (INTERNAL_DISASSEMBLER_ERROR);
5267 return;
5268 }
5269
5270 op &= mask;
5271 scratchbuf[0] = '$';
5272 print_operand_value (scratchbuf + 1, 1, op);
5273 oappend (scratchbuf + intel_syntax);
5274 scratchbuf[0] = '\0';
5275 }
5276
5277 static void
5278 OP_I64 (int bytemode, int sizeflag)
5279 {
5280 bfd_signed_vma op;
5281 bfd_signed_vma mask = -1;
5282
5283 if (address_mode != mode_64bit)
5284 {
5285 OP_I (bytemode, sizeflag);
5286 return;
5287 }
5288
5289 switch (bytemode)
5290 {
5291 case b_mode:
5292 FETCH_DATA (the_info, codep + 1);
5293 op = *codep++;
5294 mask = 0xff;
5295 break;
5296 case v_mode:
5297 USED_REX (REX_W);
5298 if (rex & REX_W)
5299 op = get64 ();
5300 else if (sizeflag & DFLAG)
5301 {
5302 op = get32 ();
5303 mask = 0xffffffff;
5304 }
5305 else
5306 {
5307 op = get16 ();
5308 mask = 0xfffff;
5309 }
5310 used_prefixes |= (prefixes & PREFIX_DATA);
5311 break;
5312 case w_mode:
5313 mask = 0xfffff;
5314 op = get16 ();
5315 break;
5316 default:
5317 oappend (INTERNAL_DISASSEMBLER_ERROR);
5318 return;
5319 }
5320
5321 op &= mask;
5322 scratchbuf[0] = '$';
5323 print_operand_value (scratchbuf + 1, 1, op);
5324 oappend (scratchbuf + intel_syntax);
5325 scratchbuf[0] = '\0';
5326 }
5327
5328 static void
5329 OP_sI (int bytemode, int sizeflag)
5330 {
5331 bfd_signed_vma op;
5332 bfd_signed_vma mask = -1;
5333
5334 switch (bytemode)
5335 {
5336 case b_mode:
5337 FETCH_DATA (the_info, codep + 1);
5338 op = *codep++;
5339 if ((op & 0x80) != 0)
5340 op -= 0x100;
5341 mask = 0xffffffff;
5342 break;
5343 case v_mode:
5344 USED_REX (REX_W);
5345 if (rex & REX_W)
5346 op = get32s ();
5347 else if (sizeflag & DFLAG)
5348 {
5349 op = get32s ();
5350 mask = 0xffffffff;
5351 }
5352 else
5353 {
5354 mask = 0xffffffff;
5355 op = get16 ();
5356 if ((op & 0x8000) != 0)
5357 op -= 0x10000;
5358 }
5359 used_prefixes |= (prefixes & PREFIX_DATA);
5360 break;
5361 case w_mode:
5362 op = get16 ();
5363 mask = 0xffffffff;
5364 if ((op & 0x8000) != 0)
5365 op -= 0x10000;
5366 break;
5367 default:
5368 oappend (INTERNAL_DISASSEMBLER_ERROR);
5369 return;
5370 }
5371
5372 scratchbuf[0] = '$';
5373 print_operand_value (scratchbuf + 1, 1, op);
5374 oappend (scratchbuf + intel_syntax);
5375 }
5376
5377 static void
5378 OP_J (int bytemode, int sizeflag)
5379 {
5380 bfd_vma disp;
5381 bfd_vma mask = -1;
5382 bfd_vma segment = 0;
5383
5384 switch (bytemode)
5385 {
5386 case b_mode:
5387 FETCH_DATA (the_info, codep + 1);
5388 disp = *codep++;
5389 if ((disp & 0x80) != 0)
5390 disp -= 0x100;
5391 break;
5392 case v_mode:
5393 if ((sizeflag & DFLAG) || (rex & REX_W))
5394 disp = get32s ();
5395 else
5396 {
5397 disp = get16 ();
5398 if ((disp & 0x8000) != 0)
5399 disp -= 0x10000;
5400 /* In 16bit mode, address is wrapped around at 64k within
5401 the same segment. Otherwise, a data16 prefix on a jump
5402 instruction means that the pc is masked to 16 bits after
5403 the displacement is added! */
5404 mask = 0xffff;
5405 if ((prefixes & PREFIX_DATA) == 0)
5406 segment = ((start_pc + codep - start_codep)
5407 & ~((bfd_vma) 0xffff));
5408 }
5409 used_prefixes |= (prefixes & PREFIX_DATA);
5410 break;
5411 default:
5412 oappend (INTERNAL_DISASSEMBLER_ERROR);
5413 return;
5414 }
5415 disp = ((start_pc + codep - start_codep + disp) & mask) | segment;
5416 set_op (disp, 0);
5417 print_operand_value (scratchbuf, 1, disp);
5418 oappend (scratchbuf);
5419 }
5420
5421 static void
5422 OP_SEG (int bytemode, int sizeflag)
5423 {
5424 if (bytemode == w_mode)
5425 oappend (names_seg[modrm.reg]);
5426 else
5427 OP_E (modrm.mod == 3 ? bytemode : w_mode, sizeflag);
5428 }
5429
5430 static void
5431 OP_DIR (int dummy ATTRIBUTE_UNUSED, int sizeflag)
5432 {
5433 int seg, offset;
5434
5435 if (sizeflag & DFLAG)
5436 {
5437 offset = get32 ();
5438 seg = get16 ();
5439 }
5440 else
5441 {
5442 offset = get16 ();
5443 seg = get16 ();
5444 }
5445 used_prefixes |= (prefixes & PREFIX_DATA);
5446 if (intel_syntax)
5447 sprintf (scratchbuf, "0x%x:0x%x", seg, offset);
5448 else
5449 sprintf (scratchbuf, "$0x%x,$0x%x", seg, offset);
5450 oappend (scratchbuf);
5451 }
5452
5453 static void
5454 OP_OFF (int bytemode, int sizeflag)
5455 {
5456 bfd_vma off;
5457
5458 if (intel_syntax && (sizeflag & SUFFIX_ALWAYS))
5459 intel_operand_size (bytemode, sizeflag);
5460 append_seg ();
5461
5462 if ((sizeflag & AFLAG) || address_mode == mode_64bit)
5463 off = get32 ();
5464 else
5465 off = get16 ();
5466
5467 if (intel_syntax)
5468 {
5469 if (!(prefixes & (PREFIX_CS | PREFIX_SS | PREFIX_DS
5470 | PREFIX_ES | PREFIX_FS | PREFIX_GS)))
5471 {
5472 oappend (names_seg[ds_reg - es_reg]);
5473 oappend (":");
5474 }
5475 }
5476 print_operand_value (scratchbuf, 1, off);
5477 oappend (scratchbuf);
5478 }
5479
5480 static void
5481 OP_OFF64 (int bytemode, int sizeflag)
5482 {
5483 bfd_vma off;
5484
5485 if (address_mode != mode_64bit
5486 || (prefixes & PREFIX_ADDR))
5487 {
5488 OP_OFF (bytemode, sizeflag);
5489 return;
5490 }
5491
5492 if (intel_syntax && (sizeflag & SUFFIX_ALWAYS))
5493 intel_operand_size (bytemode, sizeflag);
5494 append_seg ();
5495
5496 off = get64 ();
5497
5498 if (intel_syntax)
5499 {
5500 if (!(prefixes & (PREFIX_CS | PREFIX_SS | PREFIX_DS
5501 | PREFIX_ES | PREFIX_FS | PREFIX_GS)))
5502 {
5503 oappend (names_seg[ds_reg - es_reg]);
5504 oappend (":");
5505 }
5506 }
5507 print_operand_value (scratchbuf, 1, off);
5508 oappend (scratchbuf);
5509 }
5510
5511 static void
5512 ptr_reg (int code, int sizeflag)
5513 {
5514 const char *s;
5515
5516 *obufp++ = open_char;
5517 used_prefixes |= (prefixes & PREFIX_ADDR);
5518 if (address_mode == mode_64bit)
5519 {
5520 if (!(sizeflag & AFLAG))
5521 s = names32[code - eAX_reg];
5522 else
5523 s = names64[code - eAX_reg];
5524 }
5525 else if (sizeflag & AFLAG)
5526 s = names32[code - eAX_reg];
5527 else
5528 s = names16[code - eAX_reg];
5529 oappend (s);
5530 *obufp++ = close_char;
5531 *obufp = 0;
5532 }
5533
5534 static void
5535 OP_ESreg (int code, int sizeflag)
5536 {
5537 if (intel_syntax)
5538 {
5539 switch (codep[-1])
5540 {
5541 case 0x6d: /* insw/insl */
5542 intel_operand_size (z_mode, sizeflag);
5543 break;
5544 case 0xa5: /* movsw/movsl/movsq */
5545 case 0xa7: /* cmpsw/cmpsl/cmpsq */
5546 case 0xab: /* stosw/stosl */
5547 case 0xaf: /* scasw/scasl */
5548 intel_operand_size (v_mode, sizeflag);
5549 break;
5550 default:
5551 intel_operand_size (b_mode, sizeflag);
5552 }
5553 }
5554 oappend ("%es:" + intel_syntax);
5555 ptr_reg (code, sizeflag);
5556 }
5557
5558 static void
5559 OP_DSreg (int code, int sizeflag)
5560 {
5561 if (intel_syntax)
5562 {
5563 switch (codep[-1])
5564 {
5565 case 0x6f: /* outsw/outsl */
5566 intel_operand_size (z_mode, sizeflag);
5567 break;
5568 case 0xa5: /* movsw/movsl/movsq */
5569 case 0xa7: /* cmpsw/cmpsl/cmpsq */
5570 case 0xad: /* lodsw/lodsl/lodsq */
5571 intel_operand_size (v_mode, sizeflag);
5572 break;
5573 default:
5574 intel_operand_size (b_mode, sizeflag);
5575 }
5576 }
5577 if ((prefixes
5578 & (PREFIX_CS
5579 | PREFIX_DS
5580 | PREFIX_SS
5581 | PREFIX_ES
5582 | PREFIX_FS
5583 | PREFIX_GS)) == 0)
5584 prefixes |= PREFIX_DS;
5585 append_seg ();
5586 ptr_reg (code, sizeflag);
5587 }
5588
5589 static void
5590 OP_C (int dummy ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
5591 {
5592 int add = 0;
5593 if (rex & REX_R)
5594 {
5595 USED_REX (REX_R);
5596 add = 8;
5597 }
5598 else if (address_mode != mode_64bit && (prefixes & PREFIX_LOCK))
5599 {
5600 used_prefixes |= PREFIX_LOCK;
5601 add = 8;
5602 }
5603 sprintf (scratchbuf, "%%cr%d", modrm.reg + add);
5604 oappend (scratchbuf + intel_syntax);
5605 }
5606
5607 static void
5608 OP_D (int dummy ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
5609 {
5610 int add = 0;
5611 USED_REX (REX_R);
5612 if (rex & REX_R)
5613 add = 8;
5614 if (intel_syntax)
5615 sprintf (scratchbuf, "db%d", modrm.reg + add);
5616 else
5617 sprintf (scratchbuf, "%%db%d", modrm.reg + add);
5618 oappend (scratchbuf);
5619 }
5620
5621 static void
5622 OP_T (int dummy ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
5623 {
5624 sprintf (scratchbuf, "%%tr%d", modrm.reg);
5625 oappend (scratchbuf + intel_syntax);
5626 }
5627
5628 static void
5629 OP_R (int bytemode, int sizeflag)
5630 {
5631 if (modrm.mod == 3)
5632 OP_E (bytemode, sizeflag);
5633 else
5634 BadOp ();
5635 }
5636
5637 static void
5638 OP_MMX (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
5639 {
5640 used_prefixes |= (prefixes & PREFIX_DATA);
5641 if (prefixes & PREFIX_DATA)
5642 {
5643 int add = 0;
5644 USED_REX (REX_R);
5645 if (rex & REX_R)
5646 add = 8;
5647 sprintf (scratchbuf, "%%xmm%d", modrm.reg + add);
5648 }
5649 else
5650 sprintf (scratchbuf, "%%mm%d", modrm.reg);
5651 oappend (scratchbuf + intel_syntax);
5652 }
5653
5654 static void
5655 OP_XMM (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
5656 {
5657 int add = 0;
5658 USED_REX (REX_R);
5659 if (rex & REX_R)
5660 add = 8;
5661 sprintf (scratchbuf, "%%xmm%d", modrm.reg + add);
5662 oappend (scratchbuf + intel_syntax);
5663 }
5664
5665 static void
5666 OP_EM (int bytemode, int sizeflag)
5667 {
5668 if (modrm.mod != 3)
5669 {
5670 if (intel_syntax && bytemode == v_mode)
5671 {
5672 bytemode = (prefixes & PREFIX_DATA) ? x_mode : q_mode;
5673 used_prefixes |= (prefixes & PREFIX_DATA);
5674 }
5675 OP_E (bytemode, sizeflag);
5676 return;
5677 }
5678
5679 /* Skip mod/rm byte. */
5680 MODRM_CHECK;
5681 codep++;
5682 used_prefixes |= (prefixes & PREFIX_DATA);
5683 if (prefixes & PREFIX_DATA)
5684 {
5685 int add = 0;
5686
5687 USED_REX (REX_B);
5688 if (rex & REX_B)
5689 add = 8;
5690 sprintf (scratchbuf, "%%xmm%d", modrm.rm + add);
5691 }
5692 else
5693 sprintf (scratchbuf, "%%mm%d", modrm.rm);
5694 oappend (scratchbuf + intel_syntax);
5695 }
5696
5697 /* cvt* are the only instructions in sse2 which have
5698 both SSE and MMX operands and also have 0x66 prefix
5699 in their opcode. 0x66 was originally used to differentiate
5700 between SSE and MMX instruction(operands). So we have to handle the
5701 cvt* separately using OP_EMC and OP_MXC */
5702 static void
5703 OP_EMC (int bytemode, int sizeflag)
5704 {
5705 if (modrm.mod != 3)
5706 {
5707 if (intel_syntax && bytemode == v_mode)
5708 {
5709 bytemode = (prefixes & PREFIX_DATA) ? x_mode : q_mode;
5710 used_prefixes |= (prefixes & PREFIX_DATA);
5711 }
5712 OP_E (bytemode, sizeflag);
5713 return;
5714 }
5715
5716 /* Skip mod/rm byte. */
5717 MODRM_CHECK;
5718 codep++;
5719 used_prefixes |= (prefixes & PREFIX_DATA);
5720 sprintf (scratchbuf, "%%mm%d", modrm.rm);
5721 oappend (scratchbuf + intel_syntax);
5722 }
5723
5724 static void
5725 OP_MXC (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
5726 {
5727 used_prefixes |= (prefixes & PREFIX_DATA);
5728 sprintf (scratchbuf, "%%mm%d", modrm.reg);
5729 oappend (scratchbuf + intel_syntax);
5730 }
5731
5732 static void
5733 OP_EX (int bytemode, int sizeflag)
5734 {
5735 int add = 0;
5736 if (modrm.mod != 3)
5737 {
5738 if (intel_syntax && bytemode == v_mode)
5739 {
5740 switch (prefixes & (PREFIX_DATA|PREFIX_REPZ|PREFIX_REPNZ))
5741 {
5742 case 0: bytemode = x_mode; break;
5743 case PREFIX_REPZ: bytemode = d_mode; used_prefixes |= PREFIX_REPZ; break;
5744 case PREFIX_DATA: bytemode = x_mode; used_prefixes |= PREFIX_DATA; break;
5745 case PREFIX_REPNZ: bytemode = q_mode; used_prefixes |= PREFIX_REPNZ; break;
5746 default: bytemode = 0; break;
5747 }
5748 }
5749 OP_E (bytemode, sizeflag);
5750 return;
5751 }
5752 USED_REX (REX_B);
5753 if (rex & REX_B)
5754 add = 8;
5755
5756 /* Skip mod/rm byte. */
5757 MODRM_CHECK;
5758 codep++;
5759 sprintf (scratchbuf, "%%xmm%d", modrm.rm + add);
5760 oappend (scratchbuf + intel_syntax);
5761 }
5762
5763 static void
5764 OP_MS (int bytemode, int sizeflag)
5765 {
5766 if (modrm.mod == 3)
5767 OP_EM (bytemode, sizeflag);
5768 else
5769 BadOp ();
5770 }
5771
5772 static void
5773 OP_XS (int bytemode, int sizeflag)
5774 {
5775 if (modrm.mod == 3)
5776 OP_EX (bytemode, sizeflag);
5777 else
5778 BadOp ();
5779 }
5780
5781 static void
5782 OP_M (int bytemode, int sizeflag)
5783 {
5784 if (modrm.mod == 3)
5785 /* bad bound,lea,lds,les,lfs,lgs,lss,cmpxchg8b,vmptrst modrm */
5786 BadOp ();
5787 else
5788 OP_E (bytemode, sizeflag);
5789 }
5790
5791 static void
5792 OP_0f07 (int bytemode, int sizeflag)
5793 {
5794 if (modrm.mod != 3 || modrm.rm != 0)
5795 BadOp ();
5796 else
5797 OP_E (bytemode, sizeflag);
5798 }
5799
5800 static void
5801 OP_0fae (int bytemode, int sizeflag)
5802 {
5803 if (modrm.mod == 3)
5804 {
5805 if (modrm.reg == 7)
5806 strcpy (obuf + strlen (obuf) - sizeof ("clflush") + 1, "sfence");
5807
5808 if (modrm.reg < 5 || modrm.rm != 0)
5809 {
5810 BadOp (); /* bad sfence, mfence, or lfence */
5811 return;
5812 }
5813 }
5814 else if (modrm.reg != 7)
5815 {
5816 BadOp (); /* bad clflush */
5817 return;
5818 }
5819
5820 OP_E (bytemode, sizeflag);
5821 }
5822
5823 /* NOP is an alias of "xchg %ax,%ax" in 16bit mode, "xchg %eax,%eax" in
5824 32bit mode and "xchg %rax,%rax" in 64bit mode. */
5825
5826 static void
5827 NOP_Fixup1 (int bytemode, int sizeflag)
5828 {
5829 if ((prefixes & PREFIX_DATA) != 0
5830 || (rex != 0
5831 && rex != 0x48
5832 && address_mode == mode_64bit))
5833 OP_REG (bytemode, sizeflag);
5834 else
5835 strcpy (obuf, "nop");
5836 }
5837
5838 static void
5839 NOP_Fixup2 (int bytemode, int sizeflag)
5840 {
5841 if ((prefixes & PREFIX_DATA) != 0
5842 || (rex != 0
5843 && rex != 0x48
5844 && address_mode == mode_64bit))
5845 OP_IMREG (bytemode, sizeflag);
5846 }
5847
5848 static const char *const Suffix3DNow[] = {
5849 /* 00 */ NULL, NULL, NULL, NULL,
5850 /* 04 */ NULL, NULL, NULL, NULL,
5851 /* 08 */ NULL, NULL, NULL, NULL,
5852 /* 0C */ "pi2fw", "pi2fd", NULL, NULL,
5853 /* 10 */ NULL, NULL, NULL, NULL,
5854 /* 14 */ NULL, NULL, NULL, NULL,
5855 /* 18 */ NULL, NULL, NULL, NULL,
5856 /* 1C */ "pf2iw", "pf2id", NULL, NULL,
5857 /* 20 */ NULL, NULL, NULL, NULL,
5858 /* 24 */ NULL, NULL, NULL, NULL,
5859 /* 28 */ NULL, NULL, NULL, NULL,
5860 /* 2C */ NULL, NULL, NULL, NULL,
5861 /* 30 */ NULL, NULL, NULL, NULL,
5862 /* 34 */ NULL, NULL, NULL, NULL,
5863 /* 38 */ NULL, NULL, NULL, NULL,
5864 /* 3C */ NULL, NULL, NULL, NULL,
5865 /* 40 */ NULL, NULL, NULL, NULL,
5866 /* 44 */ NULL, NULL, NULL, NULL,
5867 /* 48 */ NULL, NULL, NULL, NULL,
5868 /* 4C */ NULL, NULL, NULL, NULL,
5869 /* 50 */ NULL, NULL, NULL, NULL,
5870 /* 54 */ NULL, NULL, NULL, NULL,
5871 /* 58 */ NULL, NULL, NULL, NULL,
5872 /* 5C */ NULL, NULL, NULL, NULL,
5873 /* 60 */ NULL, NULL, NULL, NULL,
5874 /* 64 */ NULL, NULL, NULL, NULL,
5875 /* 68 */ NULL, NULL, NULL, NULL,
5876 /* 6C */ NULL, NULL, NULL, NULL,
5877 /* 70 */ NULL, NULL, NULL, NULL,
5878 /* 74 */ NULL, NULL, NULL, NULL,
5879 /* 78 */ NULL, NULL, NULL, NULL,
5880 /* 7C */ NULL, NULL, NULL, NULL,
5881 /* 80 */ NULL, NULL, NULL, NULL,
5882 /* 84 */ NULL, NULL, NULL, NULL,
5883 /* 88 */ NULL, NULL, "pfnacc", NULL,
5884 /* 8C */ NULL, NULL, "pfpnacc", NULL,
5885 /* 90 */ "pfcmpge", NULL, NULL, NULL,
5886 /* 94 */ "pfmin", NULL, "pfrcp", "pfrsqrt",
5887 /* 98 */ NULL, NULL, "pfsub", NULL,
5888 /* 9C */ NULL, NULL, "pfadd", NULL,
5889 /* A0 */ "pfcmpgt", NULL, NULL, NULL,
5890 /* A4 */ "pfmax", NULL, "pfrcpit1", "pfrsqit1",
5891 /* A8 */ NULL, NULL, "pfsubr", NULL,
5892 /* AC */ NULL, NULL, "pfacc", NULL,
5893 /* B0 */ "pfcmpeq", NULL, NULL, NULL,
5894 /* B4 */ "pfmul", NULL, "pfrcpit2", "pfmulhrw",
5895 /* B8 */ NULL, NULL, NULL, "pswapd",
5896 /* BC */ NULL, NULL, NULL, "pavgusb",
5897 /* C0 */ NULL, NULL, NULL, NULL,
5898 /* C4 */ NULL, NULL, NULL, NULL,
5899 /* C8 */ NULL, NULL, NULL, NULL,
5900 /* CC */ NULL, NULL, NULL, NULL,
5901 /* D0 */ NULL, NULL, NULL, NULL,
5902 /* D4 */ NULL, NULL, NULL, NULL,
5903 /* D8 */ NULL, NULL, NULL, NULL,
5904 /* DC */ NULL, NULL, NULL, NULL,
5905 /* E0 */ NULL, NULL, NULL, NULL,
5906 /* E4 */ NULL, NULL, NULL, NULL,
5907 /* E8 */ NULL, NULL, NULL, NULL,
5908 /* EC */ NULL, NULL, NULL, NULL,
5909 /* F0 */ NULL, NULL, NULL, NULL,
5910 /* F4 */ NULL, NULL, NULL, NULL,
5911 /* F8 */ NULL, NULL, NULL, NULL,
5912 /* FC */ NULL, NULL, NULL, NULL,
5913 };
5914
5915 static void
5916 OP_3DNowSuffix (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
5917 {
5918 const char *mnemonic;
5919
5920 FETCH_DATA (the_info, codep + 1);
5921 /* AMD 3DNow! instructions are specified by an opcode suffix in the
5922 place where an 8-bit immediate would normally go. ie. the last
5923 byte of the instruction. */
5924 obufp = obuf + strlen (obuf);
5925 mnemonic = Suffix3DNow[*codep++ & 0xff];
5926 if (mnemonic)
5927 oappend (mnemonic);
5928 else
5929 {
5930 /* Since a variable sized modrm/sib chunk is between the start
5931 of the opcode (0x0f0f) and the opcode suffix, we need to do
5932 all the modrm processing first, and don't know until now that
5933 we have a bad opcode. This necessitates some cleaning up. */
5934 op_out[0][0] = '\0';
5935 op_out[1][0] = '\0';
5936 BadOp ();
5937 }
5938 }
5939
5940 static const char *simd_cmp_op[] = {
5941 "eq",
5942 "lt",
5943 "le",
5944 "unord",
5945 "neq",
5946 "nlt",
5947 "nle",
5948 "ord"
5949 };
5950
5951 static void
5952 OP_SIMD_Suffix (int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED)
5953 {
5954 unsigned int cmp_type;
5955
5956 FETCH_DATA (the_info, codep + 1);
5957 obufp = obuf + strlen (obuf);
5958 cmp_type = *codep++ & 0xff;
5959 if (cmp_type < 8)
5960 {
5961 char suffix1 = 'p', suffix2 = 's';
5962 used_prefixes |= (prefixes & PREFIX_REPZ);
5963 if (prefixes & PREFIX_REPZ)
5964 suffix1 = 's';
5965 else
5966 {
5967 used_prefixes |= (prefixes & PREFIX_DATA);
5968 if (prefixes & PREFIX_DATA)
5969 suffix2 = 'd';
5970 else
5971 {
5972 used_prefixes |= (prefixes & PREFIX_REPNZ);
5973 if (prefixes & PREFIX_REPNZ)
5974 suffix1 = 's', suffix2 = 'd';
5975 }
5976 }
5977 sprintf (scratchbuf, "cmp%s%c%c",
5978 simd_cmp_op[cmp_type], suffix1, suffix2);
5979 used_prefixes |= (prefixes & PREFIX_REPZ);
5980 oappend (scratchbuf);
5981 }
5982 else
5983 {
5984 /* We have a bad extension byte. Clean up. */
5985 op_out[0][0] = '\0';
5986 op_out[1][0] = '\0';
5987 BadOp ();
5988 }
5989 }
5990
5991 static void
5992 SIMD_Fixup (int extrachar, int sizeflag ATTRIBUTE_UNUSED)
5993 {
5994 /* Change movlps/movhps to movhlps/movlhps for 2 register operand
5995 forms of these instructions. */
5996 if (modrm.mod == 3)
5997 {
5998 char *p = obuf + strlen (obuf);
5999 *(p + 1) = '\0';
6000 *p = *(p - 1);
6001 *(p - 1) = *(p - 2);
6002 *(p - 2) = *(p - 3);
6003 *(p - 3) = extrachar;
6004 }
6005 }
6006
6007 static void
6008 PNI_Fixup (int extrachar ATTRIBUTE_UNUSED, int sizeflag)
6009 {
6010 if (modrm.mod == 3 && modrm.reg == 1 && modrm.rm <= 1)
6011 {
6012 /* Override "sidt". */
6013 size_t olen = strlen (obuf);
6014 char *p = obuf + olen - 4;
6015 const char **names = (address_mode == mode_64bit
6016 ? names64 : names32);
6017
6018 /* We might have a suffix when disassembling with -Msuffix. */
6019 if (*p == 'i')
6020 --p;
6021
6022 /* Remove "addr16/addr32" if we aren't in Intel mode. */
6023 if (!intel_syntax
6024 && (prefixes & PREFIX_ADDR)
6025 && olen >= (4 + 7)
6026 && *(p - 1) == ' '
6027 && CONST_STRNEQ (p - 7, "addr")
6028 && (CONST_STRNEQ (p - 3, "16")
6029 || CONST_STRNEQ (p - 3, "32")))
6030 p -= 7;
6031
6032 if (modrm.rm)
6033 {
6034 /* mwait %eax,%ecx */
6035 strcpy (p, "mwait");
6036 if (!intel_syntax)
6037 strcpy (op_out[0], names[0]);
6038 }
6039 else
6040 {
6041 /* monitor %eax,%ecx,%edx" */
6042 strcpy (p, "monitor");
6043 if (!intel_syntax)
6044 {
6045 const char **op1_names;
6046 if (!(prefixes & PREFIX_ADDR))
6047 op1_names = (address_mode == mode_16bit
6048 ? names16 : names);
6049 else
6050 {
6051 op1_names = (address_mode != mode_32bit
6052 ? names32 : names16);
6053 used_prefixes |= PREFIX_ADDR;
6054 }
6055 strcpy (op_out[0], op1_names[0]);
6056 strcpy (op_out[2], names[2]);
6057 }
6058 }
6059 if (!intel_syntax)
6060 {
6061 strcpy (op_out[1], names[1]);
6062 two_source_ops = 1;
6063 }
6064
6065 codep++;
6066 }
6067 else
6068 OP_M (0, sizeflag);
6069 }
6070
6071 static void
6072 SVME_Fixup (int bytemode, int sizeflag)
6073 {
6074 const char *alt;
6075 char *p;
6076
6077 switch (*codep)
6078 {
6079 case 0xd8:
6080 alt = "vmrun";
6081 break;
6082 case 0xd9:
6083 alt = "vmmcall";
6084 break;
6085 case 0xda:
6086 alt = "vmload";
6087 break;
6088 case 0xdb:
6089 alt = "vmsave";
6090 break;
6091 case 0xdc:
6092 alt = "stgi";
6093 break;
6094 case 0xdd:
6095 alt = "clgi";
6096 break;
6097 case 0xde:
6098 alt = "skinit";
6099 break;
6100 case 0xdf:
6101 alt = "invlpga";
6102 break;
6103 default:
6104 OP_M (bytemode, sizeflag);
6105 return;
6106 }
6107 /* Override "lidt". */
6108 p = obuf + strlen (obuf) - 4;
6109 /* We might have a suffix. */
6110 if (*p == 'i')
6111 --p;
6112 strcpy (p, alt);
6113 if (!(prefixes & PREFIX_ADDR))
6114 {
6115 ++codep;
6116 return;
6117 }
6118 used_prefixes |= PREFIX_ADDR;
6119 switch (*codep++)
6120 {
6121 case 0xdf:
6122 strcpy (op_out[1], names32[1]);
6123 two_source_ops = 1;
6124 /* Fall through. */
6125 case 0xd8:
6126 case 0xda:
6127 case 0xdb:
6128 *obufp++ = open_char;
6129 if (address_mode == mode_64bit || (sizeflag & AFLAG))
6130 alt = names32[0];
6131 else
6132 alt = names16[0];
6133 strcpy (obufp, alt);
6134 obufp += strlen (alt);
6135 *obufp++ = close_char;
6136 *obufp = '\0';
6137 break;
6138 }
6139 }
6140
6141 static void
6142 INVLPG_Fixup (int bytemode, int sizeflag)
6143 {
6144 const char *alt;
6145
6146 switch (*codep)
6147 {
6148 case 0xf8:
6149 alt = "swapgs";
6150 break;
6151 case 0xf9:
6152 alt = "rdtscp";
6153 break;
6154 default:
6155 OP_M (bytemode, sizeflag);
6156 return;
6157 }
6158 /* Override "invlpg". */
6159 strcpy (obuf + strlen (obuf) - 6, alt);
6160 codep++;
6161 }
6162
6163 static void
6164 BadOp (void)
6165 {
6166 /* Throw away prefixes and 1st. opcode byte. */
6167 codep = insn_codep + 1;
6168 oappend ("(bad)");
6169 }
6170
6171 static void
6172 VMX_Fixup (int extrachar ATTRIBUTE_UNUSED, int sizeflag)
6173 {
6174 if (modrm.mod == 3
6175 && modrm.reg == 0
6176 && modrm.rm >=1
6177 && modrm.rm <= 4)
6178 {
6179 /* Override "sgdt". */
6180 char *p = obuf + strlen (obuf) - 4;
6181
6182 /* We might have a suffix when disassembling with -Msuffix. */
6183 if (*p == 'g')
6184 --p;
6185
6186 switch (modrm.rm)
6187 {
6188 case 1:
6189 strcpy (p, "vmcall");
6190 break;
6191 case 2:
6192 strcpy (p, "vmlaunch");
6193 break;
6194 case 3:
6195 strcpy (p, "vmresume");
6196 break;
6197 case 4:
6198 strcpy (p, "vmxoff");
6199 break;
6200 }
6201
6202 codep++;
6203 }
6204 else
6205 OP_E (0, sizeflag);
6206 }
6207
6208 static void
6209 OP_VMX (int bytemode, int sizeflag)
6210 {
6211 used_prefixes |= (prefixes & (PREFIX_DATA | PREFIX_REPZ));
6212 if (prefixes & PREFIX_DATA)
6213 strcpy (obuf, "vmclear");
6214 else if (prefixes & PREFIX_REPZ)
6215 strcpy (obuf, "vmxon");
6216 else
6217 strcpy (obuf, "vmptrld");
6218 OP_E (bytemode, sizeflag);
6219 }
6220
6221 static void
6222 REP_Fixup (int bytemode, int sizeflag)
6223 {
6224 /* The 0xf3 prefix should be displayed as "rep" for ins, outs, movs,
6225 lods and stos. */
6226 size_t ilen = 0;
6227
6228 if (prefixes & PREFIX_REPZ)
6229 switch (*insn_codep)
6230 {
6231 case 0x6e: /* outsb */
6232 case 0x6f: /* outsw/outsl */
6233 case 0xa4: /* movsb */
6234 case 0xa5: /* movsw/movsl/movsq */
6235 if (!intel_syntax)
6236 ilen = 5;
6237 else
6238 ilen = 4;
6239 break;
6240 case 0xaa: /* stosb */
6241 case 0xab: /* stosw/stosl/stosq */
6242 case 0xac: /* lodsb */
6243 case 0xad: /* lodsw/lodsl/lodsq */
6244 if (!intel_syntax && (sizeflag & SUFFIX_ALWAYS))
6245 ilen = 5;
6246 else
6247 ilen = 4;
6248 break;
6249 case 0x6c: /* insb */
6250 case 0x6d: /* insl/insw */
6251 if (!intel_syntax)
6252 ilen = 4;
6253 else
6254 ilen = 3;
6255 break;
6256 default:
6257 abort ();
6258 break;
6259 }
6260
6261 if (ilen != 0)
6262 {
6263 size_t olen;
6264 char *p;
6265
6266 olen = strlen (obuf);
6267 p = obuf + olen - ilen - 1 - 4;
6268 /* Handle "repz [addr16|addr32]". */
6269 if ((prefixes & PREFIX_ADDR))
6270 p -= 1 + 6;
6271
6272 memmove (p + 3, p + 4, olen - (p + 3 - obuf));
6273 }
6274
6275 switch (bytemode)
6276 {
6277 case al_reg:
6278 case eAX_reg:
6279 case indir_dx_reg:
6280 OP_IMREG (bytemode, sizeflag);
6281 break;
6282 case eDI_reg:
6283 OP_ESreg (bytemode, sizeflag);
6284 break;
6285 case eSI_reg:
6286 OP_DSreg (bytemode, sizeflag);
6287 break;
6288 default:
6289 abort ();
6290 break;
6291 }
6292 }
6293
6294 static void
6295 CMPXCHG8B_Fixup (int bytemode, int sizeflag)
6296 {
6297 USED_REX (REX_W);
6298 if (rex & REX_W)
6299 {
6300 /* Change cmpxchg8b to cmpxchg16b. */
6301 char *p = obuf + strlen (obuf) - 2;
6302 strcpy (p, "16b");
6303 bytemode = o_mode;
6304 }
6305 OP_M (bytemode, sizeflag);
6306 }
6307
6308 static void
6309 XMM_Fixup (int reg, int sizeflag ATTRIBUTE_UNUSED)
6310 {
6311 sprintf (scratchbuf, "%%xmm%d", reg);
6312 oappend (scratchbuf + intel_syntax);
6313 }
6314
6315 static void
6316 CRC32_Fixup (int bytemode, int sizeflag)
6317 {
6318 /* Add proper suffix to "crc32". */
6319 char *p = obuf + strlen (obuf);
6320
6321 switch (bytemode)
6322 {
6323 case b_mode:
6324 *p++ = 'b';
6325 break;
6326 case v_mode:
6327 USED_REX (REX_W);
6328 if (rex & REX_W)
6329 *p++ = 'q';
6330 else if ((prefixes & PREFIX_DATA))
6331 {
6332 *p++ = 'w';
6333 used_prefixes |= (prefixes & PREFIX_DATA);
6334 }
6335 else
6336 *p++ = 'l';
6337 break;
6338 default:
6339 oappend (INTERNAL_DISASSEMBLER_ERROR);
6340 break;
6341 }
6342 *p = '\0';
6343
6344 if (modrm.mod == 3)
6345 {
6346 int add;
6347
6348 /* Skip mod/rm byte. */
6349 MODRM_CHECK;
6350 codep++;
6351
6352 USED_REX (REX_B);
6353 add = (rex & REX_B) ? 8 : 0;
6354 if (bytemode == b_mode)
6355 {
6356 USED_REX (0);
6357 if (rex)
6358 oappend (names8rex[modrm.rm + add]);
6359 else
6360 oappend (names8[modrm.rm + add]);
6361 }
6362 else
6363 {
6364 USED_REX (REX_W);
6365 if (rex & REX_W)
6366 oappend (names64[modrm.rm + add]);
6367 else if ((prefixes & PREFIX_DATA))
6368 oappend (names16[modrm.rm + add]);
6369 else
6370 oappend (names32[modrm.rm + add]);
6371 }
6372 }
6373 else
6374 OP_E (v_mode, sizeflag);
6375 }
This page took 0.218871 seconds and 4 git commands to generate.