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