Home | History | Annotate | Line # | Download | only in opcodes
i386-opc.h revision 1.1.1.2
      1      1.1     skrll /* Declarations for Intel 80386 opcode table
      2  1.1.1.2  christos    Copyright 2007, 2008, 2009, 2010
      3      1.1     skrll    Free Software Foundation, Inc.
      4      1.1     skrll 
      5      1.1     skrll    This file is part of the GNU opcodes library.
      6      1.1     skrll 
      7      1.1     skrll    This library is free software; you can redistribute it and/or modify
      8      1.1     skrll    it under the terms of the GNU General Public License as published by
      9      1.1     skrll    the Free Software Foundation; either version 3, or (at your option)
     10      1.1     skrll    any later version.
     11      1.1     skrll 
     12      1.1     skrll    It is distributed in the hope that it will be useful, but WITHOUT
     13      1.1     skrll    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     14      1.1     skrll    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
     15      1.1     skrll    License for more details.
     16      1.1     skrll 
     17      1.1     skrll    You should have received a copy of the GNU General Public License
     18      1.1     skrll    along with GAS; see the file COPYING.  If not, write to the Free
     19      1.1     skrll    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
     20      1.1     skrll    02110-1301, USA.  */
     21      1.1     skrll 
     22      1.1     skrll #include "opcode/i386.h"
     23      1.1     skrll #ifdef HAVE_LIMITS_H
     24      1.1     skrll #include <limits.h>
     25      1.1     skrll #endif
     26      1.1     skrll 
     27      1.1     skrll #ifndef CHAR_BIT
     28      1.1     skrll #define CHAR_BIT 8
     29      1.1     skrll #endif
     30      1.1     skrll 
     31      1.1     skrll /* Position of cpu flags bitfiled.  */
     32      1.1     skrll 
     33  1.1.1.2  christos enum
     34  1.1.1.2  christos {
     35  1.1.1.2  christos   /* i186 or better required */
     36  1.1.1.2  christos   Cpu186 = 0,
     37  1.1.1.2  christos   /* i286 or better required */
     38  1.1.1.2  christos   Cpu286,
     39  1.1.1.2  christos   /* i386 or better required */
     40  1.1.1.2  christos   Cpu386,
     41  1.1.1.2  christos   /* i486 or better required */
     42  1.1.1.2  christos   Cpu486,
     43  1.1.1.2  christos   /* i585 or better required */
     44  1.1.1.2  christos   Cpu586,
     45  1.1.1.2  christos   /* i686 or better required */
     46  1.1.1.2  christos   Cpu686,
     47  1.1.1.2  christos   /* CLFLUSH Instruction support required */
     48  1.1.1.2  christos   CpuClflush,
     49  1.1.1.2  christos   /* NOP Instruction support required */
     50  1.1.1.2  christos   CpuNop,
     51  1.1.1.2  christos   /* SYSCALL Instructions support required */
     52  1.1.1.2  christos   CpuSYSCALL,
     53  1.1.1.2  christos   /* Floating point support required */
     54  1.1.1.2  christos   Cpu8087,
     55  1.1.1.2  christos   /* i287 support required */
     56  1.1.1.2  christos   Cpu287,
     57  1.1.1.2  christos   /* i387 support required */
     58  1.1.1.2  christos   Cpu387,
     59  1.1.1.2  christos   /* i686 and floating point support required */
     60  1.1.1.2  christos   Cpu687,
     61  1.1.1.2  christos   /* SSE3 and floating point support required */
     62  1.1.1.2  christos   CpuFISTTP,
     63  1.1.1.2  christos   /* MMX support required */
     64  1.1.1.2  christos   CpuMMX,
     65  1.1.1.2  christos   /* SSE support required */
     66  1.1.1.2  christos   CpuSSE,
     67  1.1.1.2  christos   /* SSE2 support required */
     68  1.1.1.2  christos   CpuSSE2,
     69  1.1.1.2  christos   /* 3dnow! support required */
     70  1.1.1.2  christos   Cpu3dnow,
     71  1.1.1.2  christos   /* 3dnow! Extensions support required */
     72  1.1.1.2  christos   Cpu3dnowA,
     73  1.1.1.2  christos   /* SSE3 support required */
     74  1.1.1.2  christos   CpuSSE3,
     75  1.1.1.2  christos   /* VIA PadLock required */
     76  1.1.1.2  christos   CpuPadLock,
     77  1.1.1.2  christos   /* AMD Secure Virtual Machine Ext-s required */
     78  1.1.1.2  christos   CpuSVME,
     79  1.1.1.2  christos   /* VMX Instructions required */
     80  1.1.1.2  christos   CpuVMX,
     81  1.1.1.2  christos   /* SMX Instructions required */
     82  1.1.1.2  christos   CpuSMX,
     83  1.1.1.2  christos   /* SSSE3 support required */
     84  1.1.1.2  christos   CpuSSSE3,
     85  1.1.1.2  christos   /* SSE4a support required */
     86  1.1.1.2  christos   CpuSSE4a,
     87  1.1.1.2  christos   /* ABM New Instructions required */
     88  1.1.1.2  christos   CpuABM,
     89  1.1.1.2  christos   /* SSE4.1 support required */
     90  1.1.1.2  christos   CpuSSE4_1,
     91  1.1.1.2  christos   /* SSE4.2 support required */
     92  1.1.1.2  christos   CpuSSE4_2,
     93  1.1.1.2  christos   /* AVX support required */
     94  1.1.1.2  christos   CpuAVX,
     95  1.1.1.2  christos   /* Intel L1OM support required */
     96  1.1.1.2  christos   CpuL1OM,
     97  1.1.1.2  christos   /* Xsave/xrstor New Instructions support required */
     98  1.1.1.2  christos   CpuXsave,
     99  1.1.1.2  christos   /* Xsaveopt New Instructions support required */
    100  1.1.1.2  christos   CpuXsaveopt,
    101  1.1.1.2  christos   /* AES support required */
    102  1.1.1.2  christos   CpuAES,
    103  1.1.1.2  christos   /* PCLMUL support required */
    104  1.1.1.2  christos   CpuPCLMUL,
    105  1.1.1.2  christos   /* FMA support required */
    106  1.1.1.2  christos   CpuFMA,
    107  1.1.1.2  christos   /* FMA4 support required */
    108  1.1.1.2  christos   CpuFMA4,
    109  1.1.1.2  christos   /* XOP support required */
    110  1.1.1.2  christos   CpuXOP,
    111  1.1.1.2  christos   /* LWP support required */
    112  1.1.1.2  christos   CpuLWP,
    113  1.1.1.2  christos   /* MOVBE Instruction support required */
    114  1.1.1.2  christos   CpuMovbe,
    115  1.1.1.2  christos   /* EPT Instructions required */
    116  1.1.1.2  christos   CpuEPT,
    117  1.1.1.2  christos   /* RDTSCP Instruction support required */
    118  1.1.1.2  christos   CpuRdtscp,
    119  1.1.1.2  christos   /* FSGSBASE Instructions required */
    120  1.1.1.2  christos   CpuFSGSBase,
    121  1.1.1.2  christos   /* RDRND Instructions required */
    122  1.1.1.2  christos   CpuRdRnd,
    123  1.1.1.2  christos   /* F16C Instructions required */
    124  1.1.1.2  christos   CpuF16C,
    125  1.1.1.2  christos   /* 64bit support available, used by -march= in assembler.  */
    126  1.1.1.2  christos   CpuLM,
    127  1.1.1.2  christos   /* 64bit support required  */
    128  1.1.1.2  christos   Cpu64,
    129  1.1.1.2  christos   /* Not supported in the 64bit mode  */
    130  1.1.1.2  christos   CpuNo64,
    131  1.1.1.2  christos   /* The last bitfield in i386_cpu_flags.  */
    132  1.1.1.2  christos   CpuMax = CpuNo64
    133  1.1.1.2  christos };
    134      1.1     skrll 
    135      1.1     skrll #define CpuNumOfUints \
    136      1.1     skrll   (CpuMax / sizeof (unsigned int) / CHAR_BIT + 1)
    137      1.1     skrll #define CpuNumOfBits \
    138      1.1     skrll   (CpuNumOfUints * sizeof (unsigned int) * CHAR_BIT)
    139      1.1     skrll 
    140      1.1     skrll /* If you get a compiler error for zero width of the unused field,
    141      1.1     skrll    comment it out.  */
    142      1.1     skrll #define CpuUnused	(CpuMax + 1)
    143      1.1     skrll 
    144      1.1     skrll /* We can check if an instruction is available with array instead
    145      1.1     skrll    of bitfield. */
    146      1.1     skrll typedef union i386_cpu_flags
    147      1.1     skrll {
    148      1.1     skrll   struct
    149      1.1     skrll     {
    150      1.1     skrll       unsigned int cpui186:1;
    151      1.1     skrll       unsigned int cpui286:1;
    152      1.1     skrll       unsigned int cpui386:1;
    153      1.1     skrll       unsigned int cpui486:1;
    154      1.1     skrll       unsigned int cpui586:1;
    155      1.1     skrll       unsigned int cpui686:1;
    156  1.1.1.2  christos       unsigned int cpuclflush:1;
    157  1.1.1.2  christos       unsigned int cpunop:1;
    158  1.1.1.2  christos       unsigned int cpusyscall:1;
    159  1.1.1.2  christos       unsigned int cpu8087:1;
    160  1.1.1.2  christos       unsigned int cpu287:1;
    161  1.1.1.2  christos       unsigned int cpu387:1;
    162  1.1.1.2  christos       unsigned int cpu687:1;
    163  1.1.1.2  christos       unsigned int cpufisttp:1;
    164      1.1     skrll       unsigned int cpummx:1;
    165      1.1     skrll       unsigned int cpusse:1;
    166      1.1     skrll       unsigned int cpusse2:1;
    167      1.1     skrll       unsigned int cpua3dnow:1;
    168      1.1     skrll       unsigned int cpua3dnowa:1;
    169      1.1     skrll       unsigned int cpusse3:1;
    170      1.1     skrll       unsigned int cpupadlock:1;
    171      1.1     skrll       unsigned int cpusvme:1;
    172      1.1     skrll       unsigned int cpuvmx:1;
    173      1.1     skrll       unsigned int cpusmx:1;
    174      1.1     skrll       unsigned int cpussse3:1;
    175      1.1     skrll       unsigned int cpusse4a:1;
    176      1.1     skrll       unsigned int cpuabm:1;
    177      1.1     skrll       unsigned int cpusse4_1:1;
    178      1.1     skrll       unsigned int cpusse4_2:1;
    179      1.1     skrll       unsigned int cpuavx:1;
    180  1.1.1.2  christos       unsigned int cpul1om:1;
    181      1.1     skrll       unsigned int cpuxsave:1;
    182  1.1.1.2  christos       unsigned int cpuxsaveopt:1;
    183      1.1     skrll       unsigned int cpuaes:1;
    184      1.1     skrll       unsigned int cpupclmul:1;
    185      1.1     skrll       unsigned int cpufma:1;
    186  1.1.1.2  christos       unsigned int cpufma4:1;
    187  1.1.1.2  christos       unsigned int cpuxop:1;
    188  1.1.1.2  christos       unsigned int cpulwp:1;
    189      1.1     skrll       unsigned int cpumovbe:1;
    190      1.1     skrll       unsigned int cpuept:1;
    191  1.1.1.2  christos       unsigned int cpurdtscp:1;
    192  1.1.1.2  christos       unsigned int cpufsgsbase:1;
    193  1.1.1.2  christos       unsigned int cpurdrnd:1;
    194  1.1.1.2  christos       unsigned int cpuf16c:1;
    195      1.1     skrll       unsigned int cpulm:1;
    196      1.1     skrll       unsigned int cpu64:1;
    197      1.1     skrll       unsigned int cpuno64:1;
    198      1.1     skrll #ifdef CpuUnused
    199      1.1     skrll       unsigned int unused:(CpuNumOfBits - CpuUnused);
    200      1.1     skrll #endif
    201      1.1     skrll     } bitfield;
    202      1.1     skrll   unsigned int array[CpuNumOfUints];
    203      1.1     skrll } i386_cpu_flags;
    204      1.1     skrll 
    205      1.1     skrll /* Position of opcode_modifier bits.  */
    206      1.1     skrll 
    207  1.1.1.2  christos enum
    208  1.1.1.2  christos {
    209  1.1.1.2  christos   /* has direction bit. */
    210  1.1.1.2  christos   D = 0,
    211  1.1.1.2  christos   /* set if operands can be words or dwords encoded the canonical way */
    212  1.1.1.2  christos   W,
    213  1.1.1.2  christos   /* Skip the current insn and use the next insn in i386-opc.tbl to swap
    214  1.1.1.2  christos      operand in encoding.  */
    215  1.1.1.2  christos   S,
    216  1.1.1.2  christos   /* insn has a modrm byte. */
    217  1.1.1.2  christos   Modrm,
    218  1.1.1.2  christos   /* register is in low 3 bits of opcode */
    219  1.1.1.2  christos   ShortForm,
    220  1.1.1.2  christos   /* special case for jump insns.  */
    221  1.1.1.2  christos   Jump,
    222  1.1.1.2  christos   /* call and jump */
    223  1.1.1.2  christos   JumpDword,
    224  1.1.1.2  christos   /* loop and jecxz */
    225  1.1.1.2  christos   JumpByte,
    226  1.1.1.2  christos   /* special case for intersegment leaps/calls */
    227  1.1.1.2  christos   JumpInterSegment,
    228  1.1.1.2  christos   /* FP insn memory format bit, sized by 0x4 */
    229  1.1.1.2  christos   FloatMF,
    230  1.1.1.2  christos   /* src/dest swap for floats. */
    231  1.1.1.2  christos   FloatR,
    232  1.1.1.2  christos   /* has float insn direction bit. */
    233  1.1.1.2  christos   FloatD,
    234  1.1.1.2  christos   /* needs size prefix if in 32-bit mode */
    235  1.1.1.2  christos   Size16,
    236  1.1.1.2  christos   /* needs size prefix if in 16-bit mode */
    237  1.1.1.2  christos   Size32,
    238  1.1.1.2  christos   /* needs size prefix if in 64-bit mode */
    239  1.1.1.2  christos   Size64,
    240  1.1.1.2  christos   /* check register size.  */
    241  1.1.1.2  christos   CheckRegSize,
    242  1.1.1.2  christos   /* instruction ignores operand size prefix and in Intel mode ignores
    243  1.1.1.2  christos      mnemonic size suffix check.  */
    244  1.1.1.2  christos   IgnoreSize,
    245  1.1.1.2  christos   /* default insn size depends on mode */
    246  1.1.1.2  christos   DefaultSize,
    247  1.1.1.2  christos   /* b suffix on instruction illegal */
    248  1.1.1.2  christos   No_bSuf,
    249  1.1.1.2  christos   /* w suffix on instruction illegal */
    250  1.1.1.2  christos   No_wSuf,
    251  1.1.1.2  christos   /* l suffix on instruction illegal */
    252  1.1.1.2  christos   No_lSuf,
    253  1.1.1.2  christos   /* s suffix on instruction illegal */
    254  1.1.1.2  christos   No_sSuf,
    255  1.1.1.2  christos   /* q suffix on instruction illegal */
    256  1.1.1.2  christos   No_qSuf,
    257  1.1.1.2  christos   /* long double suffix on instruction illegal */
    258  1.1.1.2  christos   No_ldSuf,
    259  1.1.1.2  christos   /* instruction needs FWAIT */
    260  1.1.1.2  christos   FWait,
    261  1.1.1.2  christos   /* quick test for string instructions */
    262  1.1.1.2  christos   IsString,
    263  1.1.1.2  christos   /* quick test for lockable instructions */
    264  1.1.1.2  christos   IsLockable,
    265  1.1.1.2  christos   /* fake an extra reg operand for clr, imul and special register
    266  1.1.1.2  christos      processing for some instructions.  */
    267  1.1.1.2  christos   RegKludge,
    268  1.1.1.2  christos   /* The first operand must be xmm0 */
    269  1.1.1.2  christos   FirstXmm0,
    270  1.1.1.2  christos   /* An implicit xmm0 as the first operand */
    271  1.1.1.2  christos   Implicit1stXmm0,
    272  1.1.1.2  christos   /* Convert to DWORD */
    273  1.1.1.2  christos   ToDword,
    274  1.1.1.2  christos   /* Convert to QWORD */
    275  1.1.1.2  christos   ToQword,
    276  1.1.1.2  christos   /* Address prefix changes operand 0 */
    277  1.1.1.2  christos   AddrPrefixOp0,
    278  1.1.1.2  christos   /* opcode is a prefix */
    279  1.1.1.2  christos   IsPrefix,
    280  1.1.1.2  christos   /* instruction has extension in 8 bit imm */
    281  1.1.1.2  christos   ImmExt,
    282  1.1.1.2  christos   /* instruction don't need Rex64 prefix.  */
    283  1.1.1.2  christos   NoRex64,
    284  1.1.1.2  christos   /* instruction require Rex64 prefix.  */
    285  1.1.1.2  christos   Rex64,
    286  1.1.1.2  christos   /* deprecated fp insn, gets a warning */
    287  1.1.1.2  christos   Ugh,
    288  1.1.1.2  christos   /* insn has VEX prefix:
    289  1.1.1.2  christos 	1: 128bit VEX prefix.
    290  1.1.1.2  christos 	2: 256bit VEX prefix.
    291  1.1.1.2  christos 	3: Scalar VEX prefix.
    292  1.1.1.2  christos    */
    293  1.1.1.2  christos #define VEX128		1
    294  1.1.1.2  christos #define VEX256		2
    295  1.1.1.2  christos #define VEXScalar	3
    296  1.1.1.2  christos   Vex,
    297  1.1.1.2  christos   /* How to encode VEX.vvvv:
    298  1.1.1.2  christos      0: VEX.vvvv must be 1111b.
    299  1.1.1.2  christos      1: VEX.NDS.  Register-only source is encoded in VEX.vvvv where
    300  1.1.1.2  christos 	the content of source registers will be preserved.
    301  1.1.1.2  christos 	VEX.DDS.  The second register operand is encoded in VEX.vvvv
    302  1.1.1.2  christos 	where the content of first source register will be overwritten
    303  1.1.1.2  christos 	by the result.
    304  1.1.1.2  christos 	For assembler, there are no difference between VEX.NDS and
    305  1.1.1.2  christos 	VEX.DDS.
    306  1.1.1.2  christos      2. VEX.NDD.  Register destination is encoded in VEX.vvvv.
    307  1.1.1.2  christos      3. VEX.LWP.  Register destination is encoded in VEX.vvvv and one
    308  1.1.1.2  christos 	of the operands can access a memory location.
    309  1.1.1.2  christos    */
    310  1.1.1.2  christos #define VEXXDS	1
    311  1.1.1.2  christos #define VEXNDD	2
    312  1.1.1.2  christos #define VEXLWP	3
    313  1.1.1.2  christos   VexVVVV,
    314  1.1.1.2  christos   /* How the VEX.W bit is used:
    315  1.1.1.2  christos      0: Set by the REX.W bit.
    316  1.1.1.2  christos      1: VEX.W0.  Should always be 0.
    317  1.1.1.2  christos      2: VEX.W1.  Should always be 1.
    318  1.1.1.2  christos    */
    319  1.1.1.2  christos #define VEXW0	1
    320  1.1.1.2  christos #define VEXW1	2
    321  1.1.1.2  christos   VexW,
    322  1.1.1.2  christos   /* VEX opcode prefix:
    323  1.1.1.2  christos      0: VEX 0x0F opcode prefix.
    324  1.1.1.2  christos      1: VEX 0x0F38 opcode prefix.
    325  1.1.1.2  christos      2: VEX 0x0F3A opcode prefix
    326  1.1.1.2  christos      3: XOP 0x08 opcode prefix.
    327  1.1.1.2  christos      4: XOP 0x09 opcode prefix
    328  1.1.1.2  christos      5: XOP 0x0A opcode prefix.
    329  1.1.1.2  christos    */
    330  1.1.1.2  christos #define VEX0F		0
    331  1.1.1.2  christos #define VEX0F38		1
    332  1.1.1.2  christos #define VEX0F3A		2
    333  1.1.1.2  christos #define XOP08		3
    334  1.1.1.2  christos #define XOP09		4
    335  1.1.1.2  christos #define XOP0A		5
    336  1.1.1.2  christos   VexOpcode,
    337  1.1.1.2  christos   /* number of VEX source operands:
    338  1.1.1.2  christos      0: <= 2 source operands.
    339  1.1.1.2  christos      1: 2 XOP source operands.
    340  1.1.1.2  christos      2: 3 source operands.
    341  1.1.1.2  christos    */
    342  1.1.1.2  christos #define XOP2SOURCES	1
    343  1.1.1.2  christos #define VEX3SOURCES	2
    344  1.1.1.2  christos   VexSources,
    345  1.1.1.2  christos   /* instruction has VEX 8 bit imm */
    346  1.1.1.2  christos   VexImmExt,
    347  1.1.1.2  christos   /* SSE to AVX support required */
    348  1.1.1.2  christos   SSE2AVX,
    349  1.1.1.2  christos   /* No AVX equivalent */
    350  1.1.1.2  christos   NoAVX,
    351  1.1.1.2  christos   /* Compatible with old (<= 2.8.1) versions of gcc  */
    352  1.1.1.2  christos   OldGcc,
    353  1.1.1.2  christos   /* AT&T mnemonic.  */
    354  1.1.1.2  christos   ATTMnemonic,
    355  1.1.1.2  christos   /* AT&T syntax.  */
    356  1.1.1.2  christos   ATTSyntax,
    357  1.1.1.2  christos   /* Intel syntax.  */
    358  1.1.1.2  christos   IntelSyntax,
    359  1.1.1.2  christos   /* The last bitfield in i386_opcode_modifier.  */
    360  1.1.1.2  christos   Opcode_Modifier_Max
    361  1.1.1.2  christos };
    362      1.1     skrll 
    363      1.1     skrll typedef struct i386_opcode_modifier
    364      1.1     skrll {
    365      1.1     skrll   unsigned int d:1;
    366      1.1     skrll   unsigned int w:1;
    367  1.1.1.2  christos   unsigned int s:1;
    368      1.1     skrll   unsigned int modrm:1;
    369      1.1     skrll   unsigned int shortform:1;
    370      1.1     skrll   unsigned int jump:1;
    371      1.1     skrll   unsigned int jumpdword:1;
    372      1.1     skrll   unsigned int jumpbyte:1;
    373      1.1     skrll   unsigned int jumpintersegment:1;
    374      1.1     skrll   unsigned int floatmf:1;
    375      1.1     skrll   unsigned int floatr:1;
    376      1.1     skrll   unsigned int floatd:1;
    377      1.1     skrll   unsigned int size16:1;
    378      1.1     skrll   unsigned int size32:1;
    379      1.1     skrll   unsigned int size64:1;
    380  1.1.1.2  christos   unsigned int checkregsize:1;
    381      1.1     skrll   unsigned int ignoresize:1;
    382      1.1     skrll   unsigned int defaultsize:1;
    383      1.1     skrll   unsigned int no_bsuf:1;
    384      1.1     skrll   unsigned int no_wsuf:1;
    385      1.1     skrll   unsigned int no_lsuf:1;
    386      1.1     skrll   unsigned int no_ssuf:1;
    387      1.1     skrll   unsigned int no_qsuf:1;
    388      1.1     skrll   unsigned int no_ldsuf:1;
    389      1.1     skrll   unsigned int fwait:1;
    390      1.1     skrll   unsigned int isstring:1;
    391  1.1.1.2  christos   unsigned int islockable:1;
    392      1.1     skrll   unsigned int regkludge:1;
    393      1.1     skrll   unsigned int firstxmm0:1;
    394      1.1     skrll   unsigned int implicit1stxmm0:1;
    395      1.1     skrll   unsigned int todword:1;
    396      1.1     skrll   unsigned int toqword:1;
    397      1.1     skrll   unsigned int addrprefixop0:1;
    398      1.1     skrll   unsigned int isprefix:1;
    399      1.1     skrll   unsigned int immext:1;
    400      1.1     skrll   unsigned int norex64:1;
    401      1.1     skrll   unsigned int rex64:1;
    402      1.1     skrll   unsigned int ugh:1;
    403  1.1.1.2  christos   unsigned int vex:2;
    404  1.1.1.2  christos   unsigned int vexvvvv:2;
    405  1.1.1.2  christos   unsigned int vexw:2;
    406  1.1.1.2  christos   unsigned int vexopcode:3;
    407  1.1.1.2  christos   unsigned int vexsources:2;
    408      1.1     skrll   unsigned int veximmext:1;
    409      1.1     skrll   unsigned int sse2avx:1;
    410      1.1     skrll   unsigned int noavx:1;
    411      1.1     skrll   unsigned int oldgcc:1;
    412      1.1     skrll   unsigned int attmnemonic:1;
    413      1.1     skrll   unsigned int attsyntax:1;
    414      1.1     skrll   unsigned int intelsyntax:1;
    415      1.1     skrll } i386_opcode_modifier;
    416      1.1     skrll 
    417      1.1     skrll /* Position of operand_type bits.  */
    418      1.1     skrll 
    419  1.1.1.2  christos enum
    420  1.1.1.2  christos {
    421  1.1.1.2  christos   /* 8bit register */
    422  1.1.1.2  christos   Reg8 = 0,
    423  1.1.1.2  christos   /* 16bit register */
    424  1.1.1.2  christos   Reg16,
    425  1.1.1.2  christos   /* 32bit register */
    426  1.1.1.2  christos   Reg32,
    427  1.1.1.2  christos   /* 64bit register */
    428  1.1.1.2  christos   Reg64,
    429  1.1.1.2  christos   /* Floating pointer stack register */
    430  1.1.1.2  christos   FloatReg,
    431  1.1.1.2  christos   /* MMX register */
    432  1.1.1.2  christos   RegMMX,
    433  1.1.1.2  christos   /* SSE register */
    434  1.1.1.2  christos   RegXMM,
    435  1.1.1.2  christos   /* AVX registers */
    436  1.1.1.2  christos   RegYMM,
    437  1.1.1.2  christos   /* Control register */
    438  1.1.1.2  christos   Control,
    439  1.1.1.2  christos   /* Debug register */
    440  1.1.1.2  christos   Debug,
    441  1.1.1.2  christos   /* Test register */
    442  1.1.1.2  christos   Test,
    443  1.1.1.2  christos   /* 2 bit segment register */
    444  1.1.1.2  christos   SReg2,
    445  1.1.1.2  christos   /* 3 bit segment register */
    446  1.1.1.2  christos   SReg3,
    447  1.1.1.2  christos   /* 1 bit immediate */
    448  1.1.1.2  christos   Imm1,
    449  1.1.1.2  christos   /* 8 bit immediate */
    450  1.1.1.2  christos   Imm8,
    451  1.1.1.2  christos   /* 8 bit immediate sign extended */
    452  1.1.1.2  christos   Imm8S,
    453  1.1.1.2  christos   /* 16 bit immediate */
    454  1.1.1.2  christos   Imm16,
    455  1.1.1.2  christos   /* 32 bit immediate */
    456  1.1.1.2  christos   Imm32,
    457  1.1.1.2  christos   /* 32 bit immediate sign extended */
    458  1.1.1.2  christos   Imm32S,
    459  1.1.1.2  christos   /* 64 bit immediate */
    460  1.1.1.2  christos   Imm64,
    461  1.1.1.2  christos   /* 8bit/16bit/32bit displacements are used in different ways,
    462  1.1.1.2  christos      depending on the instruction.  For jumps, they specify the
    463  1.1.1.2  christos      size of the PC relative displacement, for instructions with
    464  1.1.1.2  christos      memory operand, they specify the size of the offset relative
    465  1.1.1.2  christos      to the base register, and for instructions with memory offset
    466  1.1.1.2  christos      such as `mov 1234,%al' they specify the size of the offset
    467  1.1.1.2  christos      relative to the segment base.  */
    468  1.1.1.2  christos   /* 8 bit displacement */
    469  1.1.1.2  christos   Disp8,
    470  1.1.1.2  christos   /* 16 bit displacement */
    471  1.1.1.2  christos   Disp16,
    472  1.1.1.2  christos   /* 32 bit displacement */
    473  1.1.1.2  christos   Disp32,
    474  1.1.1.2  christos   /* 32 bit signed displacement */
    475  1.1.1.2  christos   Disp32S,
    476  1.1.1.2  christos   /* 64 bit displacement */
    477  1.1.1.2  christos   Disp64,
    478  1.1.1.2  christos   /* Accumulator %al/%ax/%eax/%rax */
    479  1.1.1.2  christos   Acc,
    480  1.1.1.2  christos   /* Floating pointer top stack register %st(0) */
    481  1.1.1.2  christos   FloatAcc,
    482  1.1.1.2  christos   /* Register which can be used for base or index in memory operand.  */
    483  1.1.1.2  christos   BaseIndex,
    484  1.1.1.2  christos   /* Register to hold in/out port addr = dx */
    485  1.1.1.2  christos   InOutPortReg,
    486  1.1.1.2  christos   /* Register to hold shift count = cl */
    487  1.1.1.2  christos   ShiftCount,
    488  1.1.1.2  christos   /* Absolute address for jump.  */
    489  1.1.1.2  christos   JumpAbsolute,
    490  1.1.1.2  christos   /* String insn operand with fixed es segment */
    491  1.1.1.2  christos   EsSeg,
    492  1.1.1.2  christos   /* RegMem is for instructions with a modrm byte where the register
    493  1.1.1.2  christos      destination operand should be encoded in the mod and regmem fields.
    494  1.1.1.2  christos      Normally, it will be encoded in the reg field. We add a RegMem
    495  1.1.1.2  christos      flag to the destination register operand to indicate that it should
    496  1.1.1.2  christos      be encoded in the regmem field.  */
    497  1.1.1.2  christos   RegMem,
    498  1.1.1.2  christos   /* Memory.  */
    499  1.1.1.2  christos   Mem,
    500  1.1.1.2  christos   /* BYTE memory. */
    501  1.1.1.2  christos   Byte,
    502  1.1.1.2  christos   /* WORD memory. 2 byte */
    503  1.1.1.2  christos   Word,
    504  1.1.1.2  christos   /* DWORD memory. 4 byte */
    505  1.1.1.2  christos   Dword,
    506  1.1.1.2  christos   /* FWORD memory. 6 byte */
    507  1.1.1.2  christos   Fword,
    508  1.1.1.2  christos   /* QWORD memory. 8 byte */
    509  1.1.1.2  christos   Qword,
    510  1.1.1.2  christos   /* TBYTE memory. 10 byte */
    511  1.1.1.2  christos   Tbyte,
    512  1.1.1.2  christos   /* XMMWORD memory. */
    513  1.1.1.2  christos   Xmmword,
    514  1.1.1.2  christos   /* YMMWORD memory. */
    515  1.1.1.2  christos   Ymmword,
    516  1.1.1.2  christos   /* Unspecified memory size.  */
    517  1.1.1.2  christos   Unspecified,
    518  1.1.1.2  christos   /* Any memory size.  */
    519  1.1.1.2  christos   Anysize,
    520  1.1.1.2  christos 
    521  1.1.1.2  christos   /* Vector 4 bit immediate.  */
    522  1.1.1.2  christos   Vec_Imm4,
    523  1.1.1.2  christos 
    524  1.1.1.2  christos   /* The last bitfield in i386_operand_type.  */
    525  1.1.1.2  christos   OTMax
    526  1.1.1.2  christos };
    527      1.1     skrll 
    528      1.1     skrll #define OTNumOfUints \
    529      1.1     skrll   (OTMax / sizeof (unsigned int) / CHAR_BIT + 1)
    530      1.1     skrll #define OTNumOfBits \
    531      1.1     skrll   (OTNumOfUints * sizeof (unsigned int) * CHAR_BIT)
    532      1.1     skrll 
    533      1.1     skrll /* If you get a compiler error for zero width of the unused field,
    534      1.1     skrll    comment it out.  */
    535      1.1     skrll #define OTUnused		(OTMax + 1)
    536      1.1     skrll 
    537      1.1     skrll typedef union i386_operand_type
    538      1.1     skrll {
    539      1.1     skrll   struct
    540      1.1     skrll     {
    541      1.1     skrll       unsigned int reg8:1;
    542      1.1     skrll       unsigned int reg16:1;
    543      1.1     skrll       unsigned int reg32:1;
    544      1.1     skrll       unsigned int reg64:1;
    545      1.1     skrll       unsigned int floatreg:1;
    546      1.1     skrll       unsigned int regmmx:1;
    547      1.1     skrll       unsigned int regxmm:1;
    548      1.1     skrll       unsigned int regymm:1;
    549      1.1     skrll       unsigned int control:1;
    550      1.1     skrll       unsigned int debug:1;
    551      1.1     skrll       unsigned int test:1;
    552      1.1     skrll       unsigned int sreg2:1;
    553      1.1     skrll       unsigned int sreg3:1;
    554      1.1     skrll       unsigned int imm1:1;
    555      1.1     skrll       unsigned int imm8:1;
    556      1.1     skrll       unsigned int imm8s:1;
    557      1.1     skrll       unsigned int imm16:1;
    558      1.1     skrll       unsigned int imm32:1;
    559      1.1     skrll       unsigned int imm32s:1;
    560      1.1     skrll       unsigned int imm64:1;
    561      1.1     skrll       unsigned int disp8:1;
    562      1.1     skrll       unsigned int disp16:1;
    563      1.1     skrll       unsigned int disp32:1;
    564      1.1     skrll       unsigned int disp32s:1;
    565      1.1     skrll       unsigned int disp64:1;
    566      1.1     skrll       unsigned int acc:1;
    567      1.1     skrll       unsigned int floatacc:1;
    568      1.1     skrll       unsigned int baseindex:1;
    569      1.1     skrll       unsigned int inoutportreg:1;
    570      1.1     skrll       unsigned int shiftcount:1;
    571      1.1     skrll       unsigned int jumpabsolute:1;
    572      1.1     skrll       unsigned int esseg:1;
    573      1.1     skrll       unsigned int regmem:1;
    574      1.1     skrll       unsigned int mem:1;
    575      1.1     skrll       unsigned int byte:1;
    576      1.1     skrll       unsigned int word:1;
    577      1.1     skrll       unsigned int dword:1;
    578      1.1     skrll       unsigned int fword:1;
    579      1.1     skrll       unsigned int qword:1;
    580      1.1     skrll       unsigned int tbyte:1;
    581      1.1     skrll       unsigned int xmmword:1;
    582      1.1     skrll       unsigned int ymmword:1;
    583      1.1     skrll       unsigned int unspecified:1;
    584      1.1     skrll       unsigned int anysize:1;
    585  1.1.1.2  christos       unsigned int vec_imm4:1;
    586      1.1     skrll #ifdef OTUnused
    587      1.1     skrll       unsigned int unused:(OTNumOfBits - OTUnused);
    588      1.1     skrll #endif
    589      1.1     skrll     } bitfield;
    590      1.1     skrll   unsigned int array[OTNumOfUints];
    591      1.1     skrll } i386_operand_type;
    592      1.1     skrll 
    593  1.1.1.2  christos typedef struct insn_template
    594      1.1     skrll {
    595      1.1     skrll   /* instruction name sans width suffix ("mov" for movl insns) */
    596      1.1     skrll   char *name;
    597      1.1     skrll 
    598      1.1     skrll   /* how many operands */
    599      1.1     skrll   unsigned int operands;
    600      1.1     skrll 
    601      1.1     skrll   /* base_opcode is the fundamental opcode byte without optional
    602      1.1     skrll      prefix(es).  */
    603      1.1     skrll   unsigned int base_opcode;
    604      1.1     skrll #define Opcode_D	0x2 /* Direction bit:
    605      1.1     skrll 			       set if Reg --> Regmem;
    606      1.1     skrll 			       unset if Regmem --> Reg. */
    607      1.1     skrll #define Opcode_FloatR	0x8 /* Bit to swap src/dest for float insns. */
    608      1.1     skrll #define Opcode_FloatD 0x400 /* Direction bit for float insns. */
    609      1.1     skrll 
    610      1.1     skrll   /* extension_opcode is the 3 bit extension for group <n> insns.
    611      1.1     skrll      This field is also used to store the 8-bit opcode suffix for the
    612      1.1     skrll      AMD 3DNow! instructions.
    613      1.1     skrll      If this template has no extension opcode (the usual case) use None
    614  1.1.1.2  christos      Instructions */
    615      1.1     skrll   unsigned int extension_opcode;
    616      1.1     skrll #define None 0xffff		/* If no extension_opcode is possible.  */
    617      1.1     skrll 
    618      1.1     skrll   /* Opcode length.  */
    619      1.1     skrll   unsigned char opcode_length;
    620      1.1     skrll 
    621      1.1     skrll   /* cpu feature flags */
    622      1.1     skrll   i386_cpu_flags cpu_flags;
    623      1.1     skrll 
    624      1.1     skrll   /* the bits in opcode_modifier are used to generate the final opcode from
    625      1.1     skrll      the base_opcode.  These bits also are used to detect alternate forms of
    626      1.1     skrll      the same instruction */
    627      1.1     skrll   i386_opcode_modifier opcode_modifier;
    628      1.1     skrll 
    629      1.1     skrll   /* operand_types[i] describes the type of operand i.  This is made
    630      1.1     skrll      by OR'ing together all of the possible type masks.  (e.g.
    631      1.1     skrll      'operand_types[i] = Reg|Imm' specifies that operand i can be
    632      1.1     skrll      either a register or an immediate operand.  */
    633      1.1     skrll   i386_operand_type operand_types[MAX_OPERANDS];
    634      1.1     skrll }
    635  1.1.1.2  christos insn_template;
    636      1.1     skrll 
    637  1.1.1.2  christos extern const insn_template i386_optab[];
    638      1.1     skrll 
    639      1.1     skrll /* these are for register name --> number & type hash lookup */
    640      1.1     skrll typedef struct
    641      1.1     skrll {
    642      1.1     skrll   char *reg_name;
    643      1.1     skrll   i386_operand_type reg_type;
    644      1.1     skrll   unsigned char reg_flags;
    645      1.1     skrll #define RegRex	    0x1  /* Extended register.  */
    646      1.1     skrll #define RegRex64    0x2  /* Extended 8 bit register.  */
    647      1.1     skrll   unsigned char reg_num;
    648      1.1     skrll #define RegRip	((unsigned char ) ~0)
    649      1.1     skrll #define RegEip	(RegRip - 1)
    650      1.1     skrll /* EIZ and RIZ are fake index registers.  */
    651      1.1     skrll #define RegEiz	(RegEip - 1)
    652      1.1     skrll #define RegRiz	(RegEiz - 1)
    653      1.1     skrll /* FLAT is a fake segment register (Intel mode).  */
    654      1.1     skrll #define RegFlat     ((unsigned char) ~0)
    655      1.1     skrll   signed char dw2_regnum[2];
    656      1.1     skrll #define Dw2Inval (-1)
    657      1.1     skrll }
    658      1.1     skrll reg_entry;
    659      1.1     skrll 
    660      1.1     skrll /* Entries in i386_regtab.  */
    661      1.1     skrll #define REGNAM_AL 1
    662      1.1     skrll #define REGNAM_AX 25
    663      1.1     skrll #define REGNAM_EAX 41
    664      1.1     skrll 
    665      1.1     skrll extern const reg_entry i386_regtab[];
    666      1.1     skrll extern const unsigned int i386_regtab_size;
    667      1.1     skrll 
    668      1.1     skrll typedef struct
    669      1.1     skrll {
    670      1.1     skrll   char *seg_name;
    671      1.1     skrll   unsigned int seg_prefix;
    672      1.1     skrll }
    673      1.1     skrll seg_entry;
    674      1.1     skrll 
    675      1.1     skrll extern const seg_entry cs;
    676      1.1     skrll extern const seg_entry ds;
    677      1.1     skrll extern const seg_entry ss;
    678      1.1     skrll extern const seg_entry es;
    679      1.1     skrll extern const seg_entry fs;
    680      1.1     skrll extern const seg_entry gs;
    681