xref: /netbsd-src/external/gpl3/binutils.old/dist/include/opcode/i386.h (revision e992f068c547fd6e84b3f104dc2340adcc955732)
175fd0b74Schristos /* opcode/i386.h -- Intel 80386 opcode macros
2*e992f068Schristos    Copyright (C) 1989-2022 Free Software Foundation, Inc.
375fd0b74Schristos 
475fd0b74Schristos    This file is part of GAS, the GNU Assembler, and GDB, the GNU Debugger.
575fd0b74Schristos 
675fd0b74Schristos    This program is free software; you can redistribute it and/or modify
775fd0b74Schristos    it under the terms of the GNU General Public License as published by
875fd0b74Schristos    the Free Software Foundation; either version 3 of the License, or
975fd0b74Schristos    (at your option) any later version.
1075fd0b74Schristos 
1175fd0b74Schristos    This program is distributed in the hope that it will be useful,
1275fd0b74Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1375fd0b74Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1475fd0b74Schristos    GNU General Public License for more details.
1575fd0b74Schristos 
1675fd0b74Schristos    You should have received a copy of the GNU General Public License
1775fd0b74Schristos    along with this program; if not, write to the Free Software
1875fd0b74Schristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
1975fd0b74Schristos    MA 02110-1301, USA.  */
2075fd0b74Schristos 
2175fd0b74Schristos /* The SystemV/386 SVR3.2 assembler, and probably all AT&T derived
2275fd0b74Schristos    ix86 Unix assemblers, generate floating point instructions with
2375fd0b74Schristos    reversed source and destination registers in certain cases.
2475fd0b74Schristos    Unfortunately, gcc and possibly many other programs use this
2575fd0b74Schristos    reversed syntax, so we're stuck with it.
2675fd0b74Schristos 
2775fd0b74Schristos    eg. `fsub %st(3),%st' results in st = st - st(3) as expected, but
2875fd0b74Schristos    `fsub %st,%st(3)' results in st(3) = st - st(3), rather than
2975fd0b74Schristos    the expected st(3) = st(3) - st
3075fd0b74Schristos 
3175fd0b74Schristos    This happens with all the non-commutative arithmetic floating point
3275fd0b74Schristos    operations with two register operands, where the source register is
3375fd0b74Schristos    %st, and destination register is %st(i).
3475fd0b74Schristos 
3575fd0b74Schristos    The affected opcode map is dceX, dcfX, deeX, defX.  */
3675fd0b74Schristos 
3775fd0b74Schristos #ifndef OPCODE_I386_H
3875fd0b74Schristos #define OPCODE_I386_H
3975fd0b74Schristos 
4075fd0b74Schristos #ifndef SYSV386_COMPAT
4175fd0b74Schristos /* Set non-zero for broken, compatible instructions.  Set to zero for
4275fd0b74Schristos    non-broken opcodes at your peril.  gcc generates SystemV/386
4375fd0b74Schristos    compatible instructions.  */
4475fd0b74Schristos #define SYSV386_COMPAT 1
4575fd0b74Schristos #endif
4675fd0b74Schristos 
4775fd0b74Schristos #define MOV_AX_DISP32 0xa0
4875fd0b74Schristos #define POP_SEG_SHORT 0x07
49012573ebSchristos #define POP_SEG386_SHORT 0xfa1
5075fd0b74Schristos #define JUMP_PC_RELATIVE 0xeb
5175fd0b74Schristos #define INT_OPCODE  0xcd
5275fd0b74Schristos #define INT3_OPCODE 0xcc
5375fd0b74Schristos /* The opcode for the fwait instruction, which disassembler treats as a
5475fd0b74Schristos    prefix when it can.  */
5575fd0b74Schristos #define FWAIT_OPCODE 0x9b
5675fd0b74Schristos 
5775fd0b74Schristos /* Instruction prefixes.
5875fd0b74Schristos    NOTE: For certain SSE* instructions, 0x66,0xf2,0xf3 are treated as
5975fd0b74Schristos    part of the opcode.  Other prefixes may still appear between them
6075fd0b74Schristos    and the 0x0f part of the opcode.  */
6175fd0b74Schristos #define ADDR_PREFIX_OPCODE 0x67
6275fd0b74Schristos #define DATA_PREFIX_OPCODE 0x66
6375fd0b74Schristos #define LOCK_PREFIX_OPCODE 0xf0
6475fd0b74Schristos #define CS_PREFIX_OPCODE 0x2e
6575fd0b74Schristos #define DS_PREFIX_OPCODE 0x3e
6675fd0b74Schristos #define ES_PREFIX_OPCODE 0x26
6775fd0b74Schristos #define FS_PREFIX_OPCODE 0x64
6875fd0b74Schristos #define GS_PREFIX_OPCODE 0x65
6975fd0b74Schristos #define SS_PREFIX_OPCODE 0x36
7075fd0b74Schristos #define REPNE_PREFIX_OPCODE 0xf2
7175fd0b74Schristos #define REPE_PREFIX_OPCODE  0xf3
7275fd0b74Schristos #define XACQUIRE_PREFIX_OPCODE 0xf2
7375fd0b74Schristos #define XRELEASE_PREFIX_OPCODE 0xf3
7475fd0b74Schristos #define BND_PREFIX_OPCODE 0xf2
75ede78133Schristos #define NOTRACK_PREFIX_OPCODE 0x3e
7675fd0b74Schristos 
7775fd0b74Schristos #define TWO_BYTE_OPCODE_ESCAPE 0x0f
7875fd0b74Schristos #define NOP_OPCODE (char) 0x90
7975fd0b74Schristos 
8075fd0b74Schristos /* register numbers */
8175fd0b74Schristos #define EAX_REG_NUM 0
8275fd0b74Schristos #define ECX_REG_NUM 1
8375fd0b74Schristos #define EDX_REG_NUM 2
8475fd0b74Schristos #define EBX_REG_NUM 3
8575fd0b74Schristos #define ESP_REG_NUM 4
8675fd0b74Schristos #define EBP_REG_NUM 5
8775fd0b74Schristos #define ESI_REG_NUM 6
8875fd0b74Schristos #define EDI_REG_NUM 7
8975fd0b74Schristos 
9075fd0b74Schristos /* modrm_byte.regmem for twobyte escape */
9175fd0b74Schristos #define ESCAPE_TO_TWO_BYTE_ADDRESSING ESP_REG_NUM
9275fd0b74Schristos /* index_base_byte.index for no index register addressing */
9375fd0b74Schristos #define NO_INDEX_REGISTER ESP_REG_NUM
9475fd0b74Schristos /* index_base_byte.base for no base register addressing */
9575fd0b74Schristos #define NO_BASE_REGISTER EBP_REG_NUM
9675fd0b74Schristos #define NO_BASE_REGISTER_16 6
9775fd0b74Schristos 
9875fd0b74Schristos /* modrm.mode = REGMEM_FIELD_HAS_REG when a register is in there */
9975fd0b74Schristos #define REGMEM_FIELD_HAS_REG 0x3/* always = 0x3 */
10075fd0b74Schristos #define REGMEM_FIELD_HAS_MEM (~REGMEM_FIELD_HAS_REG)
10175fd0b74Schristos 
10275fd0b74Schristos /* Extract fields from the mod/rm byte.  */
10375fd0b74Schristos #define MODRM_MOD_FIELD(modrm) (((modrm) >> 6) & 3)
10475fd0b74Schristos #define MODRM_REG_FIELD(modrm) (((modrm) >> 3) & 7)
10575fd0b74Schristos #define MODRM_RM_FIELD(modrm)  (((modrm) >> 0) & 7)
10675fd0b74Schristos 
10775fd0b74Schristos /* Extract fields from the sib byte.  */
10875fd0b74Schristos #define SIB_SCALE_FIELD(sib) (((sib) >> 6) & 3)
10975fd0b74Schristos #define SIB_INDEX_FIELD(sib) (((sib) >> 3) & 7)
11075fd0b74Schristos #define SIB_BASE_FIELD(sib)  (((sib) >> 0) & 7)
11175fd0b74Schristos 
11275fd0b74Schristos /* x86-64 extension prefix.  */
11375fd0b74Schristos #define REX_OPCODE	0x40
11475fd0b74Schristos 
11575fd0b74Schristos /* Non-zero if OPCODE is the rex prefix.  */
11675fd0b74Schristos #define REX_PREFIX_P(opcode) (((opcode) & 0xf0) == REX_OPCODE)
11775fd0b74Schristos 
11875fd0b74Schristos /* Indicates 64 bit operand size.  */
11975fd0b74Schristos #define REX_W	8
12075fd0b74Schristos /* High extension to reg field of modrm byte.  */
12175fd0b74Schristos #define REX_R	4
12275fd0b74Schristos /* High extension to SIB index field.  */
12375fd0b74Schristos #define REX_X	2
12475fd0b74Schristos /* High extension to base field of modrm or SIB, or reg field of opcode.  */
12575fd0b74Schristos #define REX_B	1
12675fd0b74Schristos 
12775fd0b74Schristos /* max operands per insn */
12875fd0b74Schristos #define MAX_OPERANDS 5
12975fd0b74Schristos 
13075fd0b74Schristos /* max immediates per insn (lcall, ljmp, insertq, extrq) */
13175fd0b74Schristos #define MAX_IMMEDIATE_OPERANDS 2
13275fd0b74Schristos 
13375fd0b74Schristos /* max memory refs per insn (string ops) */
13475fd0b74Schristos #define MAX_MEMORY_OPERANDS 2
13575fd0b74Schristos 
13675fd0b74Schristos /* max size of insn mnemonics.  */
13775fd0b74Schristos #define MAX_MNEM_SIZE 20
13875fd0b74Schristos 
13975fd0b74Schristos /* max size of register name in insn mnemonics.  */
14075fd0b74Schristos #define MAX_REG_NAME_SIZE 8
14175fd0b74Schristos 
14275fd0b74Schristos #endif /* OPCODE_I386_H */
143