xref: /netbsd-src/external/gpl3/binutils/dist/include/opcode/i386.h (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
12a6b7db3Sskrll /* opcode/i386.h -- Intel 80386 opcode macros
2*cb63e24eSchristos    Copyright (C) 1989-2024 Free Software Foundation, Inc.
32a6b7db3Sskrll 
42a6b7db3Sskrll    This file is part of GAS, the GNU Assembler, and GDB, the GNU Debugger.
52a6b7db3Sskrll 
62a6b7db3Sskrll    This program is free software; you can redistribute it and/or modify
72a6b7db3Sskrll    it under the terms of the GNU General Public License as published by
845548106Schristos    the Free Software Foundation; either version 3 of the License, or
92a6b7db3Sskrll    (at your option) any later version.
102a6b7db3Sskrll 
112a6b7db3Sskrll    This program is distributed in the hope that it will be useful,
122a6b7db3Sskrll    but WITHOUT ANY WARRANTY; without even the implied warranty of
132a6b7db3Sskrll    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
142a6b7db3Sskrll    GNU General Public License for more details.
152a6b7db3Sskrll 
162a6b7db3Sskrll    You should have received a copy of the GNU General Public License
172a6b7db3Sskrll    along with this program; if not, write to the Free Software
1845548106Schristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
1945548106Schristos    MA 02110-1301, USA.  */
202a6b7db3Sskrll 
212a6b7db3Sskrll /* The SystemV/386 SVR3.2 assembler, and probably all AT&T derived
222a6b7db3Sskrll    ix86 Unix assemblers, generate floating point instructions with
232a6b7db3Sskrll    reversed source and destination registers in certain cases.
242a6b7db3Sskrll    Unfortunately, gcc and possibly many other programs use this
252a6b7db3Sskrll    reversed syntax, so we're stuck with it.
262a6b7db3Sskrll 
272a6b7db3Sskrll    eg. `fsub %st(3),%st' results in st = st - st(3) as expected, but
282a6b7db3Sskrll    `fsub %st,%st(3)' results in st(3) = st - st(3), rather than
292a6b7db3Sskrll    the expected st(3) = st(3) - st
302a6b7db3Sskrll 
312a6b7db3Sskrll    This happens with all the non-commutative arithmetic floating point
322a6b7db3Sskrll    operations with two register operands, where the source register is
332a6b7db3Sskrll    %st, and destination register is %st(i).
342a6b7db3Sskrll 
352a6b7db3Sskrll    The affected opcode map is dceX, dcfX, deeX, defX.  */
362a6b7db3Sskrll 
3745548106Schristos #ifndef OPCODE_I386_H
3845548106Schristos #define OPCODE_I386_H
3945548106Schristos 
402a6b7db3Sskrll #ifndef SYSV386_COMPAT
412a6b7db3Sskrll /* Set non-zero for broken, compatible instructions.  Set to zero for
422a6b7db3Sskrll    non-broken opcodes at your peril.  gcc generates SystemV/386
432a6b7db3Sskrll    compatible instructions.  */
442a6b7db3Sskrll #define SYSV386_COMPAT 1
452a6b7db3Sskrll #endif
462a6b7db3Sskrll 
472a6b7db3Sskrll #define MOV_AX_DISP32 0xa0
482a6b7db3Sskrll #define POP_SEG_SHORT 0x07
496f4ced0bSchristos #define POP_SEG386_SHORT 0xfa1
502a6b7db3Sskrll #define JUMP_PC_RELATIVE 0xeb
512a6b7db3Sskrll #define INT_OPCODE  0xcd
522a6b7db3Sskrll #define INT3_OPCODE 0xcc
532a6b7db3Sskrll /* The opcode for the fwait instruction, which disassembler treats as a
542a6b7db3Sskrll    prefix when it can.  */
552a6b7db3Sskrll #define FWAIT_OPCODE 0x9b
5645548106Schristos 
5745548106Schristos /* Instruction prefixes.
5845548106Schristos    NOTE: For certain SSE* instructions, 0x66,0xf2,0xf3 are treated as
5945548106Schristos    part of the opcode.  Other prefixes may still appear between them
6045548106Schristos    and the 0x0f part of the opcode.  */
612a6b7db3Sskrll #define ADDR_PREFIX_OPCODE 0x67
622a6b7db3Sskrll #define DATA_PREFIX_OPCODE 0x66
632a6b7db3Sskrll #define LOCK_PREFIX_OPCODE 0xf0
642a6b7db3Sskrll #define CS_PREFIX_OPCODE 0x2e
652a6b7db3Sskrll #define DS_PREFIX_OPCODE 0x3e
662a6b7db3Sskrll #define ES_PREFIX_OPCODE 0x26
672a6b7db3Sskrll #define FS_PREFIX_OPCODE 0x64
682a6b7db3Sskrll #define GS_PREFIX_OPCODE 0x65
692a6b7db3Sskrll #define SS_PREFIX_OPCODE 0x36
702a6b7db3Sskrll #define REPNE_PREFIX_OPCODE 0xf2
712a6b7db3Sskrll #define REPE_PREFIX_OPCODE  0xf3
72883529b6Schristos #define XACQUIRE_PREFIX_OPCODE 0xf2
73883529b6Schristos #define XRELEASE_PREFIX_OPCODE 0xf3
749573673dSchristos #define BND_PREFIX_OPCODE 0xf2
75fc4f4269Schristos #define NOTRACK_PREFIX_OPCODE 0x3e
762a6b7db3Sskrll 
772a6b7db3Sskrll #define TWO_BYTE_OPCODE_ESCAPE 0x0f
782a6b7db3Sskrll #define NOP_OPCODE (char) 0x90
792a6b7db3Sskrll 
802a6b7db3Sskrll /* register numbers */
8145548106Schristos #define EAX_REG_NUM 0
8245548106Schristos #define ECX_REG_NUM 1
8345548106Schristos #define EDX_REG_NUM 2
8445548106Schristos #define EBX_REG_NUM 3
852a6b7db3Sskrll #define ESP_REG_NUM 4
8645548106Schristos #define EBP_REG_NUM 5
8745548106Schristos #define ESI_REG_NUM 6
8845548106Schristos #define EDI_REG_NUM 7
892a6b7db3Sskrll 
902a6b7db3Sskrll /* modrm_byte.regmem for twobyte escape */
912a6b7db3Sskrll #define ESCAPE_TO_TWO_BYTE_ADDRESSING ESP_REG_NUM
922a6b7db3Sskrll /* index_base_byte.index for no index register addressing */
932a6b7db3Sskrll #define NO_INDEX_REGISTER ESP_REG_NUM
942a6b7db3Sskrll /* index_base_byte.base for no base register addressing */
952a6b7db3Sskrll #define NO_BASE_REGISTER EBP_REG_NUM
962a6b7db3Sskrll #define NO_BASE_REGISTER_16 6
972a6b7db3Sskrll 
982a6b7db3Sskrll /* modrm.mode = REGMEM_FIELD_HAS_REG when a register is in there */
992a6b7db3Sskrll #define REGMEM_FIELD_HAS_REG 0x3/* always = 0x3 */
1002a6b7db3Sskrll #define REGMEM_FIELD_HAS_MEM (~REGMEM_FIELD_HAS_REG)
1012a6b7db3Sskrll 
10245548106Schristos /* Extract fields from the mod/rm byte.  */
10345548106Schristos #define MODRM_MOD_FIELD(modrm) (((modrm) >> 6) & 3)
10445548106Schristos #define MODRM_REG_FIELD(modrm) (((modrm) >> 3) & 7)
10545548106Schristos #define MODRM_RM_FIELD(modrm)  (((modrm) >> 0) & 7)
10645548106Schristos 
10745548106Schristos /* Extract fields from the sib byte.  */
10845548106Schristos #define SIB_SCALE_FIELD(sib) (((sib) >> 6) & 3)
10945548106Schristos #define SIB_INDEX_FIELD(sib) (((sib) >> 3) & 7)
11045548106Schristos #define SIB_BASE_FIELD(sib)  (((sib) >> 0) & 7)
11145548106Schristos 
1122a6b7db3Sskrll /* x86-64 extension prefix.  */
1132a6b7db3Sskrll #define REX_OPCODE	0x40
1142a6b7db3Sskrll 
115*cb63e24eSchristos #define REX2_OPCODE	0xd5
116*cb63e24eSchristos 
11745548106Schristos /* Non-zero if OPCODE is the rex prefix.  */
11845548106Schristos #define REX_PREFIX_P(opcode) (((opcode) & 0xf0) == REX_OPCODE)
11945548106Schristos 
120*cb63e24eSchristos /* M0 in rex2 prefix represents map0 or map1.  */
121*cb63e24eSchristos #define REX2_M 0x8
1222a6b7db3Sskrll /* Indicates 64 bit operand size.  */
1232a6b7db3Sskrll #define REX_W	8
1242a6b7db3Sskrll /* High extension to reg field of modrm byte.  */
1252a6b7db3Sskrll #define REX_R	4
1262a6b7db3Sskrll /* High extension to SIB index field.  */
1272a6b7db3Sskrll #define REX_X	2
1282a6b7db3Sskrll /* High extension to base field of modrm or SIB, or reg field of opcode.  */
1292a6b7db3Sskrll #define REX_B	1
1302a6b7db3Sskrll 
1312a6b7db3Sskrll /* max operands per insn */
1322a6b7db3Sskrll #define MAX_OPERANDS 5
1332a6b7db3Sskrll 
1342a6b7db3Sskrll /* max immediates per insn (lcall, ljmp, insertq, extrq) */
1352a6b7db3Sskrll #define MAX_IMMEDIATE_OPERANDS 2
1362a6b7db3Sskrll 
1372a6b7db3Sskrll /* max memory refs per insn (string ops) */
1382a6b7db3Sskrll #define MAX_MEMORY_OPERANDS 2
1392a6b7db3Sskrll 
1402a6b7db3Sskrll /* max size of insn mnemonics.  */
1412a6b7db3Sskrll #define MAX_MNEM_SIZE 20
1422a6b7db3Sskrll 
1432a6b7db3Sskrll /* max size of register name in insn mnemonics.  */
1442a6b7db3Sskrll #define MAX_REG_NAME_SIZE 8
14545548106Schristos 
14645548106Schristos #endif /* OPCODE_I386_H */
147