xref: /netbsd-src/external/gpl3/gdb/dist/include/opcode/i386.h (revision aab831cebf6361fb2b518a47c70732e608d9abd2)
198b9484cSchristos /* opcode/i386.h -- Intel 80386 opcode macros
2*aab831ceSchristos    Copyright (C) 1989-2024 Free Software Foundation, Inc.
398b9484cSchristos 
498b9484cSchristos    This file is part of GAS, the GNU Assembler, and GDB, the GNU Debugger.
598b9484cSchristos 
698b9484cSchristos    This program is free software; you can redistribute it and/or modify
798b9484cSchristos    it under the terms of the GNU General Public License as published by
898b9484cSchristos    the Free Software Foundation; either version 3 of the License, or
998b9484cSchristos    (at your option) any later version.
1098b9484cSchristos 
1198b9484cSchristos    This program is distributed in the hope that it will be useful,
1298b9484cSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1398b9484cSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1498b9484cSchristos    GNU General Public License for more details.
1598b9484cSchristos 
1698b9484cSchristos    You should have received a copy of the GNU General Public License
1798b9484cSchristos    along with this program; if not, write to the Free Software
1898b9484cSchristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
1998b9484cSchristos    MA 02110-1301, USA.  */
2098b9484cSchristos 
2198b9484cSchristos /* The SystemV/386 SVR3.2 assembler, and probably all AT&T derived
2298b9484cSchristos    ix86 Unix assemblers, generate floating point instructions with
2398b9484cSchristos    reversed source and destination registers in certain cases.
2498b9484cSchristos    Unfortunately, gcc and possibly many other programs use this
2598b9484cSchristos    reversed syntax, so we're stuck with it.
2698b9484cSchristos 
2798b9484cSchristos    eg. `fsub %st(3),%st' results in st = st - st(3) as expected, but
2898b9484cSchristos    `fsub %st,%st(3)' results in st(3) = st - st(3), rather than
2998b9484cSchristos    the expected st(3) = st(3) - st
3098b9484cSchristos 
3198b9484cSchristos    This happens with all the non-commutative arithmetic floating point
3298b9484cSchristos    operations with two register operands, where the source register is
3398b9484cSchristos    %st, and destination register is %st(i).
3498b9484cSchristos 
3598b9484cSchristos    The affected opcode map is dceX, dcfX, deeX, defX.  */
3698b9484cSchristos 
3798b9484cSchristos #ifndef OPCODE_I386_H
3898b9484cSchristos #define OPCODE_I386_H
3998b9484cSchristos 
4098b9484cSchristos #ifndef SYSV386_COMPAT
4198b9484cSchristos /* Set non-zero for broken, compatible instructions.  Set to zero for
4298b9484cSchristos    non-broken opcodes at your peril.  gcc generates SystemV/386
4398b9484cSchristos    compatible instructions.  */
4498b9484cSchristos #define SYSV386_COMPAT 1
4598b9484cSchristos #endif
4698b9484cSchristos 
4798b9484cSchristos #define MOV_AX_DISP32 0xa0
4898b9484cSchristos #define POP_SEG_SHORT 0x07
498dffb485Schristos #define POP_SEG386_SHORT 0xfa1
5098b9484cSchristos #define JUMP_PC_RELATIVE 0xeb
5198b9484cSchristos #define INT_OPCODE  0xcd
5298b9484cSchristos #define INT3_OPCODE 0xcc
5398b9484cSchristos /* The opcode for the fwait instruction, which disassembler treats as a
5498b9484cSchristos    prefix when it can.  */
5598b9484cSchristos #define FWAIT_OPCODE 0x9b
5698b9484cSchristos 
5798b9484cSchristos /* Instruction prefixes.
5898b9484cSchristos    NOTE: For certain SSE* instructions, 0x66,0xf2,0xf3 are treated as
5998b9484cSchristos    part of the opcode.  Other prefixes may still appear between them
6098b9484cSchristos    and the 0x0f part of the opcode.  */
6198b9484cSchristos #define ADDR_PREFIX_OPCODE 0x67
6298b9484cSchristos #define DATA_PREFIX_OPCODE 0x66
6398b9484cSchristos #define LOCK_PREFIX_OPCODE 0xf0
6498b9484cSchristos #define CS_PREFIX_OPCODE 0x2e
6598b9484cSchristos #define DS_PREFIX_OPCODE 0x3e
6698b9484cSchristos #define ES_PREFIX_OPCODE 0x26
6798b9484cSchristos #define FS_PREFIX_OPCODE 0x64
6898b9484cSchristos #define GS_PREFIX_OPCODE 0x65
6998b9484cSchristos #define SS_PREFIX_OPCODE 0x36
7098b9484cSchristos #define REPNE_PREFIX_OPCODE 0xf2
7198b9484cSchristos #define REPE_PREFIX_OPCODE  0xf3
72a2e2270fSchristos #define XACQUIRE_PREFIX_OPCODE 0xf2
73a2e2270fSchristos #define XRELEASE_PREFIX_OPCODE 0xf3
7403467a24Schristos #define BND_PREFIX_OPCODE 0xf2
754559860eSchristos #define NOTRACK_PREFIX_OPCODE 0x3e
7698b9484cSchristos 
7798b9484cSchristos #define TWO_BYTE_OPCODE_ESCAPE 0x0f
7898b9484cSchristos #define NOP_OPCODE (char) 0x90
7998b9484cSchristos 
8098b9484cSchristos /* register numbers */
8198b9484cSchristos #define EAX_REG_NUM 0
8298b9484cSchristos #define ECX_REG_NUM 1
8398b9484cSchristos #define EDX_REG_NUM 2
8498b9484cSchristos #define EBX_REG_NUM 3
8598b9484cSchristos #define ESP_REG_NUM 4
8698b9484cSchristos #define EBP_REG_NUM 5
8798b9484cSchristos #define ESI_REG_NUM 6
8898b9484cSchristos #define EDI_REG_NUM 7
8998b9484cSchristos 
9098b9484cSchristos /* modrm_byte.regmem for twobyte escape */
9198b9484cSchristos #define ESCAPE_TO_TWO_BYTE_ADDRESSING ESP_REG_NUM
9298b9484cSchristos /* index_base_byte.index for no index register addressing */
9398b9484cSchristos #define NO_INDEX_REGISTER ESP_REG_NUM
9498b9484cSchristos /* index_base_byte.base for no base register addressing */
9598b9484cSchristos #define NO_BASE_REGISTER EBP_REG_NUM
9698b9484cSchristos #define NO_BASE_REGISTER_16 6
9798b9484cSchristos 
9898b9484cSchristos /* modrm.mode = REGMEM_FIELD_HAS_REG when a register is in there */
9998b9484cSchristos #define REGMEM_FIELD_HAS_REG 0x3/* always = 0x3 */
10098b9484cSchristos #define REGMEM_FIELD_HAS_MEM (~REGMEM_FIELD_HAS_REG)
10198b9484cSchristos 
10298b9484cSchristos /* Extract fields from the mod/rm byte.  */
10398b9484cSchristos #define MODRM_MOD_FIELD(modrm) (((modrm) >> 6) & 3)
10498b9484cSchristos #define MODRM_REG_FIELD(modrm) (((modrm) >> 3) & 7)
10598b9484cSchristos #define MODRM_RM_FIELD(modrm)  (((modrm) >> 0) & 7)
10698b9484cSchristos 
10798b9484cSchristos /* Extract fields from the sib byte.  */
10898b9484cSchristos #define SIB_SCALE_FIELD(sib) (((sib) >> 6) & 3)
10998b9484cSchristos #define SIB_INDEX_FIELD(sib) (((sib) >> 3) & 7)
11098b9484cSchristos #define SIB_BASE_FIELD(sib)  (((sib) >> 0) & 7)
11198b9484cSchristos 
11298b9484cSchristos /* x86-64 extension prefix.  */
11398b9484cSchristos #define REX_OPCODE	0x40
11498b9484cSchristos 
115*aab831ceSchristos #define REX2_OPCODE	0xd5
116*aab831ceSchristos 
11798b9484cSchristos /* Non-zero if OPCODE is the rex prefix.  */
11898b9484cSchristos #define REX_PREFIX_P(opcode) (((opcode) & 0xf0) == REX_OPCODE)
11998b9484cSchristos 
120*aab831ceSchristos /* M0 in rex2 prefix represents map0 or map1.  */
121*aab831ceSchristos #define REX2_M 0x8
12298b9484cSchristos /* Indicates 64 bit operand size.  */
12398b9484cSchristos #define REX_W	8
12498b9484cSchristos /* High extension to reg field of modrm byte.  */
12598b9484cSchristos #define REX_R	4
12698b9484cSchristos /* High extension to SIB index field.  */
12798b9484cSchristos #define REX_X	2
12898b9484cSchristos /* High extension to base field of modrm or SIB, or reg field of opcode.  */
12998b9484cSchristos #define REX_B	1
13098b9484cSchristos 
13198b9484cSchristos /* max operands per insn */
13298b9484cSchristos #define MAX_OPERANDS 5
13398b9484cSchristos 
13498b9484cSchristos /* max immediates per insn (lcall, ljmp, insertq, extrq) */
13598b9484cSchristos #define MAX_IMMEDIATE_OPERANDS 2
13698b9484cSchristos 
13798b9484cSchristos /* max memory refs per insn (string ops) */
13898b9484cSchristos #define MAX_MEMORY_OPERANDS 2
13998b9484cSchristos 
14098b9484cSchristos /* max size of insn mnemonics.  */
14198b9484cSchristos #define MAX_MNEM_SIZE 20
14298b9484cSchristos 
14398b9484cSchristos /* max size of register name in insn mnemonics.  */
14498b9484cSchristos #define MAX_REG_NAME_SIZE 8
14598b9484cSchristos 
14698b9484cSchristos #endif /* OPCODE_I386_H */
147