xref: /dflybsd-src/contrib/binutils-2.27/include/opcode/i386.h (revision e656dc90e3d65d744d534af2f5ea88cf8101ebcf)
1*a9fa9459Szrj /* opcode/i386.h -- Intel 80386 opcode macros
2*a9fa9459Szrj    Copyright (C) 1989-2016 Free Software Foundation, Inc.
3*a9fa9459Szrj 
4*a9fa9459Szrj    This file is part of GAS, the GNU Assembler, and GDB, the GNU Debugger.
5*a9fa9459Szrj 
6*a9fa9459Szrj    This program is free software; you can redistribute it and/or modify
7*a9fa9459Szrj    it under the terms of the GNU General Public License as published by
8*a9fa9459Szrj    the Free Software Foundation; either version 3 of the License, or
9*a9fa9459Szrj    (at your option) any later version.
10*a9fa9459Szrj 
11*a9fa9459Szrj    This program is distributed in the hope that it will be useful,
12*a9fa9459Szrj    but WITHOUT ANY WARRANTY; without even the implied warranty of
13*a9fa9459Szrj    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*a9fa9459Szrj    GNU General Public License for more details.
15*a9fa9459Szrj 
16*a9fa9459Szrj    You should have received a copy of the GNU General Public License
17*a9fa9459Szrj    along with this program; if not, write to the Free Software
18*a9fa9459Szrj    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19*a9fa9459Szrj    MA 02110-1301, USA.  */
20*a9fa9459Szrj 
21*a9fa9459Szrj /* The SystemV/386 SVR3.2 assembler, and probably all AT&T derived
22*a9fa9459Szrj    ix86 Unix assemblers, generate floating point instructions with
23*a9fa9459Szrj    reversed source and destination registers in certain cases.
24*a9fa9459Szrj    Unfortunately, gcc and possibly many other programs use this
25*a9fa9459Szrj    reversed syntax, so we're stuck with it.
26*a9fa9459Szrj 
27*a9fa9459Szrj    eg. `fsub %st(3),%st' results in st = st - st(3) as expected, but
28*a9fa9459Szrj    `fsub %st,%st(3)' results in st(3) = st - st(3), rather than
29*a9fa9459Szrj    the expected st(3) = st(3) - st
30*a9fa9459Szrj 
31*a9fa9459Szrj    This happens with all the non-commutative arithmetic floating point
32*a9fa9459Szrj    operations with two register operands, where the source register is
33*a9fa9459Szrj    %st, and destination register is %st(i).
34*a9fa9459Szrj 
35*a9fa9459Szrj    The affected opcode map is dceX, dcfX, deeX, defX.  */
36*a9fa9459Szrj 
37*a9fa9459Szrj #ifndef OPCODE_I386_H
38*a9fa9459Szrj #define OPCODE_I386_H
39*a9fa9459Szrj 
40*a9fa9459Szrj #ifndef SYSV386_COMPAT
41*a9fa9459Szrj /* Set non-zero for broken, compatible instructions.  Set to zero for
42*a9fa9459Szrj    non-broken opcodes at your peril.  gcc generates SystemV/386
43*a9fa9459Szrj    compatible instructions.  */
44*a9fa9459Szrj #define SYSV386_COMPAT 1
45*a9fa9459Szrj #endif
46*a9fa9459Szrj #ifndef OLDGCC_COMPAT
47*a9fa9459Szrj /* Set non-zero to cater for old (<= 2.8.1) versions of gcc that could
48*a9fa9459Szrj    generate nonsense fsubp, fsubrp, fdivp and fdivrp with operands
49*a9fa9459Szrj    reversed.  */
50*a9fa9459Szrj #define OLDGCC_COMPAT SYSV386_COMPAT
51*a9fa9459Szrj #endif
52*a9fa9459Szrj 
53*a9fa9459Szrj #define MOV_AX_DISP32 0xa0
54*a9fa9459Szrj #define POP_SEG_SHORT 0x07
55*a9fa9459Szrj #define JUMP_PC_RELATIVE 0xeb
56*a9fa9459Szrj #define INT_OPCODE  0xcd
57*a9fa9459Szrj #define INT3_OPCODE 0xcc
58*a9fa9459Szrj /* The opcode for the fwait instruction, which disassembler treats as a
59*a9fa9459Szrj    prefix when it can.  */
60*a9fa9459Szrj #define FWAIT_OPCODE 0x9b
61*a9fa9459Szrj 
62*a9fa9459Szrj /* Instruction prefixes.
63*a9fa9459Szrj    NOTE: For certain SSE* instructions, 0x66,0xf2,0xf3 are treated as
64*a9fa9459Szrj    part of the opcode.  Other prefixes may still appear between them
65*a9fa9459Szrj    and the 0x0f part of the opcode.  */
66*a9fa9459Szrj #define ADDR_PREFIX_OPCODE 0x67
67*a9fa9459Szrj #define DATA_PREFIX_OPCODE 0x66
68*a9fa9459Szrj #define LOCK_PREFIX_OPCODE 0xf0
69*a9fa9459Szrj #define CS_PREFIX_OPCODE 0x2e
70*a9fa9459Szrj #define DS_PREFIX_OPCODE 0x3e
71*a9fa9459Szrj #define ES_PREFIX_OPCODE 0x26
72*a9fa9459Szrj #define FS_PREFIX_OPCODE 0x64
73*a9fa9459Szrj #define GS_PREFIX_OPCODE 0x65
74*a9fa9459Szrj #define SS_PREFIX_OPCODE 0x36
75*a9fa9459Szrj #define REPNE_PREFIX_OPCODE 0xf2
76*a9fa9459Szrj #define REPE_PREFIX_OPCODE  0xf3
77*a9fa9459Szrj #define XACQUIRE_PREFIX_OPCODE 0xf2
78*a9fa9459Szrj #define XRELEASE_PREFIX_OPCODE 0xf3
79*a9fa9459Szrj #define BND_PREFIX_OPCODE 0xf2
80*a9fa9459Szrj 
81*a9fa9459Szrj #define TWO_BYTE_OPCODE_ESCAPE 0x0f
82*a9fa9459Szrj #define NOP_OPCODE (char) 0x90
83*a9fa9459Szrj 
84*a9fa9459Szrj /* register numbers */
85*a9fa9459Szrj #define EAX_REG_NUM 0
86*a9fa9459Szrj #define ECX_REG_NUM 1
87*a9fa9459Szrj #define EDX_REG_NUM 2
88*a9fa9459Szrj #define EBX_REG_NUM 3
89*a9fa9459Szrj #define ESP_REG_NUM 4
90*a9fa9459Szrj #define EBP_REG_NUM 5
91*a9fa9459Szrj #define ESI_REG_NUM 6
92*a9fa9459Szrj #define EDI_REG_NUM 7
93*a9fa9459Szrj 
94*a9fa9459Szrj /* modrm_byte.regmem for twobyte escape */
95*a9fa9459Szrj #define ESCAPE_TO_TWO_BYTE_ADDRESSING ESP_REG_NUM
96*a9fa9459Szrj /* index_base_byte.index for no index register addressing */
97*a9fa9459Szrj #define NO_INDEX_REGISTER ESP_REG_NUM
98*a9fa9459Szrj /* index_base_byte.base for no base register addressing */
99*a9fa9459Szrj #define NO_BASE_REGISTER EBP_REG_NUM
100*a9fa9459Szrj #define NO_BASE_REGISTER_16 6
101*a9fa9459Szrj 
102*a9fa9459Szrj /* modrm.mode = REGMEM_FIELD_HAS_REG when a register is in there */
103*a9fa9459Szrj #define REGMEM_FIELD_HAS_REG 0x3/* always = 0x3 */
104*a9fa9459Szrj #define REGMEM_FIELD_HAS_MEM (~REGMEM_FIELD_HAS_REG)
105*a9fa9459Szrj 
106*a9fa9459Szrj /* Extract fields from the mod/rm byte.  */
107*a9fa9459Szrj #define MODRM_MOD_FIELD(modrm) (((modrm) >> 6) & 3)
108*a9fa9459Szrj #define MODRM_REG_FIELD(modrm) (((modrm) >> 3) & 7)
109*a9fa9459Szrj #define MODRM_RM_FIELD(modrm)  (((modrm) >> 0) & 7)
110*a9fa9459Szrj 
111*a9fa9459Szrj /* Extract fields from the sib byte.  */
112*a9fa9459Szrj #define SIB_SCALE_FIELD(sib) (((sib) >> 6) & 3)
113*a9fa9459Szrj #define SIB_INDEX_FIELD(sib) (((sib) >> 3) & 7)
114*a9fa9459Szrj #define SIB_BASE_FIELD(sib)  (((sib) >> 0) & 7)
115*a9fa9459Szrj 
116*a9fa9459Szrj /* x86-64 extension prefix.  */
117*a9fa9459Szrj #define REX_OPCODE	0x40
118*a9fa9459Szrj 
119*a9fa9459Szrj /* Non-zero if OPCODE is the rex prefix.  */
120*a9fa9459Szrj #define REX_PREFIX_P(opcode) (((opcode) & 0xf0) == REX_OPCODE)
121*a9fa9459Szrj 
122*a9fa9459Szrj /* Indicates 64 bit operand size.  */
123*a9fa9459Szrj #define REX_W	8
124*a9fa9459Szrj /* High extension to reg field of modrm byte.  */
125*a9fa9459Szrj #define REX_R	4
126*a9fa9459Szrj /* High extension to SIB index field.  */
127*a9fa9459Szrj #define REX_X	2
128*a9fa9459Szrj /* High extension to base field of modrm or SIB, or reg field of opcode.  */
129*a9fa9459Szrj #define REX_B	1
130*a9fa9459Szrj 
131*a9fa9459Szrj /* max operands per insn */
132*a9fa9459Szrj #define MAX_OPERANDS 5
133*a9fa9459Szrj 
134*a9fa9459Szrj /* max immediates per insn (lcall, ljmp, insertq, extrq) */
135*a9fa9459Szrj #define MAX_IMMEDIATE_OPERANDS 2
136*a9fa9459Szrj 
137*a9fa9459Szrj /* max memory refs per insn (string ops) */
138*a9fa9459Szrj #define MAX_MEMORY_OPERANDS 2
139*a9fa9459Szrj 
140*a9fa9459Szrj /* max size of insn mnemonics.  */
141*a9fa9459Szrj #define MAX_MNEM_SIZE 20
142*a9fa9459Szrj 
143*a9fa9459Szrj /* max size of register name in insn mnemonics.  */
144*a9fa9459Szrj #define MAX_REG_NAME_SIZE 8
145*a9fa9459Szrj 
146*a9fa9459Szrj #endif /* OPCODE_I386_H */
147