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