1 /* Declarations for Intel 80386 opcode table
2 Copyright 2007, 2008, 2009
3 Free Software Foundation, Inc.
5 This file is part of the GNU opcodes library.
7 This library 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 3, or (at your option)
12 It is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
22 #include "opcode/i386.h"
31 /* Position of cpu flags bitfiled. */
35 /* i186 or better required */
37 /* i286 or better required */
39 /* i386 or better required */
41 /* i486 or better required */
43 /* i585 or better required */
45 /* i686 or better required */
47 /* CLFLUSH Instuction support required */
49 /* SYSCALL Instuctions support required */
51 /* Floating point support required */
53 /* i287 support required */
55 /* i387 support required */
57 /* i686 and floating point support required */
59 /* SSE3 and floating point support required */
61 /* MMX support required */
63 /* SSE support required */
65 /* SSE2 support required */
67 /* 3dnow! support required */
69 /* 3dnow! Extensions support required */
71 /* SSE3 support required */
73 /* VIA PadLock required */
75 /* AMD Secure Virtual Machine Ext-s required */
77 /* VMX Instructions required */
79 /* SMX Instructions required */
81 /* SSSE3 support required */
83 /* SSE4a support required */
85 /* ABM New Instructions required */
87 /* SSE4.1 support required */
89 /* SSE4.2 support required */
91 /* AVX support required */
93 /* Intel L1OM support required */
95 /* Xsave/xrstor New Instuctions support required */
97 /* AES support required */
99 /* PCLMUL support required */
101 /* FMA support required */
103 /* FMA4 support required */
105 /* XOP support required */
107 /* CVT16 support required */
109 /* LWP support required */
111 /* MOVBE Instuction support required */
113 /* EPT Instructions required */
115 /* RDTSCP Instuction support required */
117 /* 64bit support available, used by -march= in assembler. */
119 /* 64bit support required */
121 /* Not supported in the 64bit mode */
123 /* The last bitfield in i386_cpu_flags. */
127 #define CpuNumOfUints \
128 (CpuMax / sizeof (unsigned int) / CHAR_BIT + 1)
129 #define CpuNumOfBits \
130 (CpuNumOfUints * sizeof (unsigned int) * CHAR_BIT)
132 /* If you get a compiler error for zero width of the unused field,
134 #define CpuUnused (CpuMax + 1)
136 /* We can check if an instruction is available with array instead
138 typedef union i386_cpu_flags
142 unsigned int cpui186
:1;
143 unsigned int cpui286
:1;
144 unsigned int cpui386
:1;
145 unsigned int cpui486
:1;
146 unsigned int cpui586
:1;
147 unsigned int cpui686
:1;
148 unsigned int cpuclflush
:1;
149 unsigned int cpusyscall
:1;
150 unsigned int cpu8087
:1;
151 unsigned int cpu287
:1;
152 unsigned int cpu387
:1;
153 unsigned int cpu687
:1;
154 unsigned int cpufisttp
:1;
155 unsigned int cpummx
:1;
156 unsigned int cpusse
:1;
157 unsigned int cpusse2
:1;
158 unsigned int cpua3dnow
:1;
159 unsigned int cpua3dnowa
:1;
160 unsigned int cpusse3
:1;
161 unsigned int cpupadlock
:1;
162 unsigned int cpusvme
:1;
163 unsigned int cpuvmx
:1;
164 unsigned int cpusmx
:1;
165 unsigned int cpussse3
:1;
166 unsigned int cpusse4a
:1;
167 unsigned int cpuabm
:1;
168 unsigned int cpusse4_1
:1;
169 unsigned int cpusse4_2
:1;
170 unsigned int cpuavx
:1;
171 unsigned int cpul1om
:1;
172 unsigned int cpuxsave
:1;
173 unsigned int cpuaes
:1;
174 unsigned int cpupclmul
:1;
175 unsigned int cpufma
:1;
176 unsigned int cpufma4
:1;
177 unsigned int cpuxop
:1;
178 unsigned int cpucvt16
:1;
179 unsigned int cpulwp
:1;
180 unsigned int cpumovbe
:1;
181 unsigned int cpuept
:1;
182 unsigned int cpurdtscp
:1;
183 unsigned int cpulm
:1;
184 unsigned int cpu64
:1;
185 unsigned int cpuno64
:1;
187 unsigned int unused
:(CpuNumOfBits
- CpuUnused
);
190 unsigned int array
[CpuNumOfUints
];
193 /* Position of opcode_modifier bits. */
197 /* has direction bit. */
199 /* set if operands can be words or dwords encoded the canonical way */
201 /* Skip the current insn and use the next insn in i386-opc.tbl to swap
202 operand in encoding. */
204 /* insn has a modrm byte. */
206 /* register is in low 3 bits of opcode */
208 /* special case for jump insns. */
214 /* special case for intersegment leaps/calls */
216 /* FP insn memory format bit, sized by 0x4 */
218 /* src/dest swap for floats. */
220 /* has float insn direction bit. */
222 /* needs size prefix if in 32-bit mode */
224 /* needs size prefix if in 16-bit mode */
226 /* needs size prefix if in 64-bit mode */
228 /* instruction ignores operand size prefix and in Intel mode ignores
229 mnemonic size suffix check. */
231 /* default insn size depends on mode */
233 /* b suffix on instruction illegal */
235 /* w suffix on instruction illegal */
237 /* l suffix on instruction illegal */
239 /* s suffix on instruction illegal */
241 /* q suffix on instruction illegal */
243 /* long double suffix on instruction illegal */
245 /* instruction needs FWAIT */
247 /* quick test for string instructions */
249 /* quick test for lockable instructions */
251 /* fake an extra reg operand for clr, imul and special register
252 processing for some instructions. */
254 /* The first operand must be xmm0 */
256 /* An implicit xmm0 as the first operand */
258 /* BYTE is OK in Intel syntax. */
260 /* Convert to DWORD */
262 /* Convert to QWORD */
264 /* Address prefix changes operand 0 */
266 /* opcode is a prefix */
268 /* instruction has extension in 8 bit imm */
270 /* instruction don't need Rex64 prefix. */
272 /* instruction require Rex64 prefix. */
274 /* deprecated fp insn, gets a warning */
276 /* insn has VEX prefix:
277 1: 128bit VEX prefix.
278 2: 256bit VEX prefix.
281 /* insn has VEX NDS. Register-only source is encoded in Vex prefix.
282 We use VexNDS on insns with VEX DDS since the register-only source
283 is the second source register. */
285 /* insn has VEX NDD. Register destination is encoded in Vex prefix. */
287 /* insn has VEX NDD. Register destination is encoded in Vex prefix
288 and one of the operands can access a memory location. */
290 /* insn has VEX W0. */
292 /* insn has VEX W1. */
294 /* insn has VEX 0x0F opcode prefix. */
296 /* insn has VEX 0x0F38 opcode prefix. */
298 /* insn has VEX 0x0F3A opcode prefix. */
300 /* insn has XOP 0x08 opcode prefix. */
302 /* insn has XOP 0x09 opcode prefix. */
304 /* insn has XOP 0x0A opcode prefix. */
306 /* insn has VEX prefix with 2 sources. */
308 /* insn has VEX prefix with 3 sources. */
310 /* instruction has VEX 8 bit imm */
312 /* SSE to AVX support required */
314 /* No AVX equivalent */
316 /* Compatible with old (<= 2.8.1) versions of gcc */
324 /* The last bitfield in i386_opcode_modifier. */
328 typedef struct i386_opcode_modifier
333 unsigned int modrm
:1;
334 unsigned int shortform
:1;
336 unsigned int jumpdword
:1;
337 unsigned int jumpbyte
:1;
338 unsigned int jumpintersegment
:1;
339 unsigned int floatmf
:1;
340 unsigned int floatr
:1;
341 unsigned int floatd
:1;
342 unsigned int size16
:1;
343 unsigned int size32
:1;
344 unsigned int size64
:1;
345 unsigned int ignoresize
:1;
346 unsigned int defaultsize
:1;
347 unsigned int no_bsuf
:1;
348 unsigned int no_wsuf
:1;
349 unsigned int no_lsuf
:1;
350 unsigned int no_ssuf
:1;
351 unsigned int no_qsuf
:1;
352 unsigned int no_ldsuf
:1;
353 unsigned int fwait
:1;
354 unsigned int isstring
:1;
355 unsigned int islockable
:1;
356 unsigned int regkludge
:1;
357 unsigned int firstxmm0
:1;
358 unsigned int implicit1stxmm0
:1;
359 unsigned int byteokintel
:1;
360 unsigned int todword
:1;
361 unsigned int toqword
:1;
362 unsigned int addrprefixop0
:1;
363 unsigned int isprefix
:1;
364 unsigned int immext
:1;
365 unsigned int norex64
:1;
366 unsigned int rex64
:1;
369 unsigned int vexnds
:1;
370 unsigned int vexndd
:1;
371 unsigned int vexlwp
:1;
372 unsigned int vexw0
:1;
373 unsigned int vexw1
:1;
374 unsigned int vex0f
:1;
375 unsigned int vex0f38
:1;
376 unsigned int vex0f3a
:1;
377 unsigned int xop08
:1;
378 unsigned int xop09
:1;
379 unsigned int xop0a
:1;
380 unsigned int vex2sources
:1;
381 unsigned int vex3sources
:1;
382 unsigned int veximmext
:1;
383 unsigned int sse2avx
:1;
384 unsigned int noavx
:1;
385 unsigned int oldgcc
:1;
386 unsigned int attmnemonic
:1;
387 unsigned int attsyntax
:1;
388 unsigned int intelsyntax
:1;
389 } i386_opcode_modifier
;
391 /* Position of operand_type bits. */
403 /* Floating pointer stack register */
411 /* Control register */
417 /* 2 bit segment register */
419 /* 3 bit segment register */
421 /* 1 bit immediate */
423 /* 8 bit immediate */
425 /* 8 bit immediate sign extended */
427 /* 16 bit immediate */
429 /* 32 bit immediate */
431 /* 32 bit immediate sign extended */
433 /* 64 bit immediate */
435 /* 8bit/16bit/32bit displacements are used in different ways,
436 depending on the instruction. For jumps, they specify the
437 size of the PC relative displacement, for instructions with
438 memory operand, they specify the size of the offset relative
439 to the base register, and for instructions with memory offset
440 such as `mov 1234,%al' they specify the size of the offset
441 relative to the segment base. */
442 /* 8 bit displacement */
444 /* 16 bit displacement */
446 /* 32 bit displacement */
448 /* 32 bit signed displacement */
450 /* 64 bit displacement */
452 /* Accumulator %al/%ax/%eax/%rax */
454 /* Floating pointer top stack register %st(0) */
456 /* Register which can be used for base or index in memory operand. */
458 /* Register to hold in/out port addr = dx */
460 /* Register to hold shift count = cl */
462 /* Absolute address for jump. */
464 /* String insn operand with fixed es segment */
466 /* RegMem is for instructions with a modrm byte where the register
467 destination operand should be encoded in the mod and regmem fields.
468 Normally, it will be encoded in the reg field. We add a RegMem
469 flag to the destination register operand to indicate that it should
470 be encoded in the regmem field. */
476 /* WORD memory. 2 byte */
478 /* DWORD memory. 4 byte */
480 /* FWORD memory. 6 byte */
482 /* QWORD memory. 8 byte */
484 /* TBYTE memory. 10 byte */
486 /* XMMWORD memory. */
488 /* YMMWORD memory. */
490 /* Unspecified memory size. */
492 /* Any memory size. */
495 /* The last bitfield in i386_operand_type. */
499 #define OTNumOfUints \
500 (OTMax / sizeof (unsigned int) / CHAR_BIT + 1)
501 #define OTNumOfBits \
502 (OTNumOfUints * sizeof (unsigned int) * CHAR_BIT)
504 /* If you get a compiler error for zero width of the unused field,
506 #define OTUnused (OTMax + 1)
508 typedef union i386_operand_type
513 unsigned int reg16
:1;
514 unsigned int reg32
:1;
515 unsigned int reg64
:1;
516 unsigned int floatreg
:1;
517 unsigned int regmmx
:1;
518 unsigned int regxmm
:1;
519 unsigned int regymm
:1;
520 unsigned int control
:1;
521 unsigned int debug
:1;
523 unsigned int sreg2
:1;
524 unsigned int sreg3
:1;
527 unsigned int imm8s
:1;
528 unsigned int imm16
:1;
529 unsigned int imm32
:1;
530 unsigned int imm32s
:1;
531 unsigned int imm64
:1;
532 unsigned int disp8
:1;
533 unsigned int disp16
:1;
534 unsigned int disp32
:1;
535 unsigned int disp32s
:1;
536 unsigned int disp64
:1;
538 unsigned int floatacc
:1;
539 unsigned int baseindex
:1;
540 unsigned int inoutportreg
:1;
541 unsigned int shiftcount
:1;
542 unsigned int jumpabsolute
:1;
543 unsigned int esseg
:1;
544 unsigned int regmem
:1;
548 unsigned int dword
:1;
549 unsigned int fword
:1;
550 unsigned int qword
:1;
551 unsigned int tbyte
:1;
552 unsigned int xmmword
:1;
553 unsigned int ymmword
:1;
554 unsigned int unspecified
:1;
555 unsigned int anysize
:1;
557 unsigned int unused
:(OTNumOfBits
- OTUnused
);
560 unsigned int array
[OTNumOfUints
];
563 typedef struct insn_template
565 /* instruction name sans width suffix ("mov" for movl insns) */
568 /* how many operands */
569 unsigned int operands
;
571 /* base_opcode is the fundamental opcode byte without optional
573 unsigned int base_opcode
;
574 #define Opcode_D 0x2 /* Direction bit:
575 set if Reg --> Regmem;
576 unset if Regmem --> Reg. */
577 #define Opcode_FloatR 0x8 /* Bit to swap src/dest for float insns. */
578 #define Opcode_FloatD 0x400 /* Direction bit for float insns. */
580 /* extension_opcode is the 3 bit extension for group <n> insns.
581 This field is also used to store the 8-bit opcode suffix for the
582 AMD 3DNow! instructions.
583 If this template has no extension opcode (the usual case) use None
585 unsigned int extension_opcode
;
586 #define None 0xffff /* If no extension_opcode is possible. */
589 unsigned char opcode_length
;
591 /* cpu feature flags */
592 i386_cpu_flags cpu_flags
;
594 /* the bits in opcode_modifier are used to generate the final opcode from
595 the base_opcode. These bits also are used to detect alternate forms of
596 the same instruction */
597 i386_opcode_modifier opcode_modifier
;
599 /* operand_types[i] describes the type of operand i. This is made
600 by OR'ing together all of the possible type masks. (e.g.
601 'operand_types[i] = Reg|Imm' specifies that operand i can be
602 either a register or an immediate operand. */
603 i386_operand_type operand_types
[MAX_OPERANDS
];
607 extern const insn_template i386_optab
[];
609 /* these are for register name --> number & type hash lookup */
613 i386_operand_type reg_type
;
614 unsigned char reg_flags
;
615 #define RegRex 0x1 /* Extended register. */
616 #define RegRex64 0x2 /* Extended 8 bit register. */
617 unsigned char reg_num
;
618 #define RegRip ((unsigned char ) ~0)
619 #define RegEip (RegRip - 1)
620 /* EIZ and RIZ are fake index registers. */
621 #define RegEiz (RegEip - 1)
622 #define RegRiz (RegEiz - 1)
623 /* FLAT is a fake segment register (Intel mode). */
624 #define RegFlat ((unsigned char) ~0)
625 signed char dw2_regnum
[2];
626 #define Dw2Inval (-1)
630 /* Entries in i386_regtab. */
633 #define REGNAM_EAX 41
635 extern const reg_entry i386_regtab
[];
636 extern const unsigned int i386_regtab_size
;
641 unsigned int seg_prefix
;
645 extern const seg_entry cs
;
646 extern const seg_entry ds
;
647 extern const seg_entry ss
;
648 extern const seg_entry es
;
649 extern const seg_entry fs
;
650 extern const seg_entry gs
;