X86BaseInfo.h revision ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5c
18c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng//===-- X86BaseInfo.h - Top level definitions for X86 -------- --*- C++ -*-===// 28c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// 38c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// The LLVM Compiler Infrastructure 48c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// 58c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// This file is distributed under the University of Illinois Open Source 68c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// License. See LICENSE.TXT for details. 78c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// 88c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng//===----------------------------------------------------------------------===// 98c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// 108c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// This file contains small standalone helper functions and enum definitions for 118c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// the X86 target useful for the compiler back-end and the MC libraries. 128c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// As such, it deliberately does not include references to LLVM core 138c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// code gen types, passes, etc.. 148c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng// 158c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng//===----------------------------------------------------------------------===// 168c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 178c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng#ifndef X86BASEINFO_H 188c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng#define X86BASEINFO_H 198c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 208c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng#include "X86MCTargetDesc.h" 218c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng#include "llvm/Support/DataTypes.h" 228c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng#include <cassert> 238c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 248c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Chengnamespace llvm { 258c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 268c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Chengnamespace X86 { 278c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // Enums for memory operand decoding. Each memory operand is represented with 288c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // a 5 operand sequence in the form: 298c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // [BaseReg, ScaleAmt, IndexReg, Disp, Segment] 308c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // These enums help decode this. 318c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng enum { 328c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng AddrBaseReg = 0, 338c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng AddrScaleAmt = 1, 348c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng AddrIndexReg = 2, 358c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng AddrDisp = 3, 368c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 378c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// AddrSegmentReg - The operand # of the segment in the memory operand. 388c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng AddrSegmentReg = 4, 398c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 408c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// AddrNumOperands - Total number of operands in a memory reference. 418c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng AddrNumOperands = 5 428c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng }; 438c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng} // end namespace X86; 448c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 458c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 468c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng/// X86II - This namespace holds all of the target specific flags that 478c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng/// instruction info tracks. 488c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng/// 498c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Chengnamespace X86II { 508c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// Target Operand Flag enum. 518c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng enum TOF { 528c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //===------------------------------------------------------------------===// 538c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // X86 Specific MachineOperand flags. 548c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 558c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_NO_FLAG, 568c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 578c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_GOT_ABSOLUTE_ADDRESS - On a symbol operand, this represents a 588c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// relocation of: 598c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL + [. - PICBASELABEL] 608c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_GOT_ABSOLUTE_ADDRESS, 618c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 628c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_PIC_BASE_OFFSET - On a symbol operand this indicates that the 638c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// immediate should get the value of the symbol minus the PIC base label: 648c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL - PICBASELABEL 658c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_PIC_BASE_OFFSET, 668c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 678c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_GOT - On a symbol operand this indicates that the immediate is the 688c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// offset to the GOT entry for the symbol name from the base of the GOT. 698c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 708c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See the X86-64 ELF ABI supplement for more details. 718c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @GOT 728c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_GOT, 738c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 748c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_GOTOFF - On a symbol operand this indicates that the immediate is 758c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// the offset to the location of the symbol name from the base of the GOT. 768c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 778c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See the X86-64 ELF ABI supplement for more details. 788c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @GOTOFF 798c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_GOTOFF, 808c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 818c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_GOTPCREL - On a symbol operand this indicates that the immediate is 828c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// offset to the GOT entry for the symbol name from the current code 838c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// location. 848c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 858c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See the X86-64 ELF ABI supplement for more details. 868c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @GOTPCREL 878c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_GOTPCREL, 888c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 898c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_PLT - On a symbol operand this indicates that the immediate is 908c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// offset to the PLT entry of symbol name from the current code location. 918c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 928c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See the X86-64 ELF ABI supplement for more details. 938c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @PLT 948c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_PLT, 958c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 968c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_TLSGD - On a symbol operand this indicates that the immediate is 978c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// some TLS offset. 988c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 998c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See 'ELF Handling for Thread-Local Storage' for more details. 1008c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @TLSGD 1018c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_TLSGD, 1028c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1038c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_GOTTPOFF - On a symbol operand this indicates that the immediate is 1048c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// some TLS offset. 1058c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 1068c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See 'ELF Handling for Thread-Local Storage' for more details. 1078c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @GOTTPOFF 1088c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_GOTTPOFF, 1098c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1108c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_INDNTPOFF - On a symbol operand this indicates that the immediate is 1118c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// some TLS offset. 1128c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 1138c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See 'ELF Handling for Thread-Local Storage' for more details. 1148c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @INDNTPOFF 1158c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_INDNTPOFF, 1168c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1178c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_TPOFF - On a symbol operand this indicates that the immediate is 1188c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// some TLS offset. 1198c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 1208c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See 'ELF Handling for Thread-Local Storage' for more details. 1218c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @TPOFF 1228c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_TPOFF, 1238c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1248c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_NTPOFF - On a symbol operand this indicates that the immediate is 1258c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// some TLS offset. 1268c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 1278c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// See 'ELF Handling for Thread-Local Storage' for more details. 1288c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// SYMBOL_LABEL @NTPOFF 1298c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_NTPOFF, 1308c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1318c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_DLLIMPORT - On a symbol operand "FOO", this indicates that the 1328c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// reference is actually to the "__imp_FOO" symbol. This is used for 1338c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// dllimport linkage on windows. 1348c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_DLLIMPORT, 1358c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1368c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_DARWIN_STUB - On a symbol operand "FOO", this indicates that the 1378c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// reference is actually to the "FOO$stub" symbol. This is used for calls 1388c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// and jumps to external functions on Tiger and earlier. 1398c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_DARWIN_STUB, 1408c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1418c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_DARWIN_NONLAZY - On a symbol operand "FOO", this indicates that the 1428c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// reference is actually to the "FOO$non_lazy_ptr" symbol, which is a 1438c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// non-PIC-base-relative reference to a non-hidden dyld lazy pointer stub. 1448c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_DARWIN_NONLAZY, 1458c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1468c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_DARWIN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this indicates 1478c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// that the reference is actually to "FOO$non_lazy_ptr - PICBASE", which is 1488c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// a PIC-base-relative reference to a non-hidden dyld lazy pointer stub. 1498c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_DARWIN_NONLAZY_PIC_BASE, 1508c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1518c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE - On a symbol operand "FOO", this 1528c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// indicates that the reference is actually to "FOO$non_lazy_ptr -PICBASE", 1538c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// which is a PIC-base-relative reference to a hidden dyld lazy pointer 1548c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// stub. 1558c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE, 1568c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1578c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_TLVP - On a symbol operand this indicates that the immediate is 1588c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// some TLS offset. 1598c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 1608c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// This is the TLS offset for the Darwin TLS mechanism. 1618c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_TLVP, 1628c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1638c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MO_TLVP_PIC_BASE - On a symbol operand this indicates that the immediate 1648c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// is some TLS offset from the picbase. 1658c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 1668c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// This is the 32-bit TLS offset for Darwin TLS in PIC mode. 1678c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MO_TLVP_PIC_BASE 1688c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng }; 1698c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1708c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng enum { 1718c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //===------------------------------------------------------------------===// 1728c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // Instruction encodings. These are the standard/most common forms for X86 1738c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // instructions. 1748c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // 1758c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1768c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // PseudoFrm - This represents an instruction that is a pseudo instruction 1778c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // or one that has not been implemented yet. It is illegal to code generate 1788c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // it, but tolerated for intermediate implementation stages. 1798c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Pseudo = 0, 1808c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1818c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// Raw - This form is for instructions that don't have any operands, so 1828c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// they are just a fixed opcode value, like 'leave'. 1838c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng RawFrm = 1, 1848c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1858c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// AddRegFrm - This form is used for instructions like 'push r32' that have 1868c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// their one register operand added to their opcode. 1878c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng AddRegFrm = 2, 1888c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1898c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MRMDestReg - This form is used for instructions that use the Mod/RM byte 1908c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// to specify a destination, which in this case is a register. 1918c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 1928c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRMDestReg = 3, 1938c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1948c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MRMDestMem - This form is used for instructions that use the Mod/RM byte 1958c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// to specify a destination, which in this case is memory. 1968c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 1978c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRMDestMem = 4, 1988c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 1998c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MRMSrcReg - This form is used for instructions that use the Mod/RM byte 2008c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// to specify a source, which in this case is a register. 2018c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 2028c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRMSrcReg = 5, 2038c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2048c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MRMSrcMem - This form is used for instructions that use the Mod/RM byte 2058c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// to specify a source, which in this case is memory. 2068c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 2078c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRMSrcMem = 6, 2088c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2098c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// MRM[0-7][rm] - These forms are used to represent instructions that use 2108c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// a Mod/RM byte, and use the middle field to hold extended opcode 2118c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// information. In the intel manual these are represented as /0, /1, ... 2128c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 2138c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2148c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // First, instructions that operate on a register r/m operand... 2158c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM0r = 16, MRM1r = 17, MRM2r = 18, MRM3r = 19, // Format /0 /1 /2 /3 2168c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM4r = 20, MRM5r = 21, MRM6r = 22, MRM7r = 23, // Format /4 /5 /6 /7 2178c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2188c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // Next, instructions that operate on a memory r/m operand... 2198c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM0m = 24, MRM1m = 25, MRM2m = 26, MRM3m = 27, // Format /0 /1 /2 /3 2208c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM4m = 28, MRM5m = 29, MRM6m = 30, MRM7m = 31, // Format /4 /5 /6 /7 2218c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2228c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // MRMInitReg - This form is used for instructions whose source and 2238c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // destinations are the same register. 2248c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRMInitReg = 32, 2258c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2268c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //// MRM_C1 - A mod/rm byte of exactly 0xC1. 2278c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM_C1 = 33, 2288c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM_C2 = 34, 2298c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM_C3 = 35, 2308c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM_C4 = 36, 2318c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM_C8 = 37, 2328c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM_C9 = 38, 2338c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM_E8 = 39, 2348c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM_F0 = 40, 2358c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM_F8 = 41, 2368c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM_F9 = 42, 2378c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM_D0 = 45, 2388c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng MRM_D1 = 46, 2398c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2408c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// RawFrmImm8 - This is used for the ENTER instruction, which has two 2418c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// immediates, the first of which is a 16-bit immediate (specified by 2428c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// the imm encoding) and the second is a 8-bit fixed value. 2438c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng RawFrmImm8 = 43, 2448c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2458c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// RawFrmImm16 - This is used for CALL FAR instructions, which have two 2468c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// immediates, the first of which is a 16 or 32-bit immediate (specified by 2478c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// the imm encoding) and the second is a 16-bit fixed value. In the AMD 2488c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// manual, this operand is described as pntr16:32 and pntr16:16 2498c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng RawFrmImm16 = 44, 2508c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2518c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng FormMask = 63, 2528c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2538c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //===------------------------------------------------------------------===// 2548c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // Actual flags... 2558c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2568c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // OpSize - Set if this instruction requires an operand size prefix (0x66), 2578c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // which most often indicates that the instruction operates on 16 bit data 2588c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // instead of 32 bit data. 2598c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng OpSize = 1 << 6, 2608c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2618c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // AsSize - Set if this instruction requires an operand size prefix (0x67), 2628c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // which most often indicates that the instruction address 16 bit address 2638c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // instead of 32 bit address (or 32 bit address in 64 bit mode). 2648c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng AdSize = 1 << 7, 2658c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2668c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //===------------------------------------------------------------------===// 2678c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // Op0Mask - There are several prefix bytes that are used to form two byte 2688c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // opcodes. These are currently 0x0F, 0xF3, and 0xD8-0xDF. This mask is 2698c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // used to obtain the setting of this field. If no bits in this field is 2708c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // set, there is no prefix byte for obtaining a multibyte opcode. 2718c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // 2728c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Op0Shift = 8, 2738c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Op0Mask = 0x1F << Op0Shift, 2748c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2758c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // TB - TwoByte - Set if this instruction has a two byte opcode, which 2768c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // starts with a 0x0F byte before the real opcode. 2778c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng TB = 1 << Op0Shift, 2788c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2798c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // REP - The 0xF3 prefix byte indicating repetition of the following 2808c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // instruction. 2818c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng REP = 2 << Op0Shift, 2828c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2838c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // D8-DF - These escape opcodes are used by the floating point unit. These 2848c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // values must remain sequential. 2858c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng D8 = 3 << Op0Shift, D9 = 4 << Op0Shift, 2868c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng DA = 5 << Op0Shift, DB = 6 << Op0Shift, 2878c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng DC = 7 << Op0Shift, DD = 8 << Op0Shift, 2888c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng DE = 9 << Op0Shift, DF = 10 << Op0Shift, 2898c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2908c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // XS, XD - These prefix codes are for single and double precision scalar 2918c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // floating point operations performed in the SSE registers. 2928c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng XD = 11 << Op0Shift, XS = 12 << Op0Shift, 2938c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 2948c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // T8, TA, A6, A7 - Prefix after the 0x0F prefix. 2958c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng T8 = 13 << Op0Shift, TA = 14 << Op0Shift, 2968c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng A6 = 15 << Op0Shift, A7 = 16 << Op0Shift, 2978c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 298ee62e4f6d192ee31d1ad9dd0ba0c41db6663d3c7Craig Topper // T8XD - Prefix before and after 0x0F. Combination of T8 and XD. 299ee62e4f6d192ee31d1ad9dd0ba0c41db6663d3c7Craig Topper T8XD = 17 << Op0Shift, 300ee62e4f6d192ee31d1ad9dd0ba0c41db6663d3c7Craig Topper 301ee62e4f6d192ee31d1ad9dd0ba0c41db6663d3c7Craig Topper // T8XS - Prefix before and after 0x0F. Combination of T8 and XS. 302ee62e4f6d192ee31d1ad9dd0ba0c41db6663d3c7Craig Topper T8XS = 18 << Op0Shift, 3038c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 30475485d6746f8b5b23c17cf6d2364e7e1e0705992Craig Topper // TAXD - Prefix before and after 0x0F. Combination of TA and XD. 30575485d6746f8b5b23c17cf6d2364e7e1e0705992Craig Topper TAXD = 19 << Op0Shift, 30675485d6746f8b5b23c17cf6d2364e7e1e0705992Craig Topper 307ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5cJan Sjödin // XOP8 - Prefix to include use of imm byte. 308ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5cJan Sjödin XOP8 = 20 << Op0Shift, 309ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5cJan Sjödin 310ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5cJan Sjödin // XOP9 - Prefix to exclude use of imm byte. 311ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5cJan Sjödin XOP9 = 21 << Op0Shift, 312ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5cJan Sjödin 3138c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //===------------------------------------------------------------------===// 3148c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // REX_W - REX prefixes are instruction prefixes used in 64-bit mode. 3158c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // They are used to specify GPRs and SSE registers, 64-bit operand size, 3168c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // etc. We only cares about REX.W and REX.R bits and only the former is 3178c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // statically determined. 3188c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // 3198c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng REXShift = Op0Shift + 5, 3208c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng REX_W = 1 << REXShift, 3218c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3228c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //===------------------------------------------------------------------===// 3238c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // This three-bit field describes the size of an immediate operand. Zero is 3248c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // unused so that we can tell if we forgot to set a value. 3258c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng ImmShift = REXShift + 1, 3268c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng ImmMask = 7 << ImmShift, 3278c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Imm8 = 1 << ImmShift, 3288c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Imm8PCRel = 2 << ImmShift, 3298c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Imm16 = 3 << ImmShift, 3308c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Imm16PCRel = 4 << ImmShift, 3318c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Imm32 = 5 << ImmShift, 3328c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Imm32PCRel = 6 << ImmShift, 3338c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng Imm64 = 7 << ImmShift, 3348c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3358c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //===------------------------------------------------------------------===// 3368c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // FP Instruction Classification... Zero is non-fp instruction. 3378c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3388c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // FPTypeMask - Mask for all of the FP types... 3398c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng FPTypeShift = ImmShift + 3, 3408c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng FPTypeMask = 7 << FPTypeShift, 3418c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3428c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // NotFP - The default, set for instructions that do not use FP registers. 3438c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng NotFP = 0 << FPTypeShift, 3448c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3458c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // ZeroArgFP - 0 arg FP instruction which implicitly pushes ST(0), f.e. fld0 3468c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng ZeroArgFP = 1 << FPTypeShift, 3478c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3488c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // OneArgFP - 1 arg FP instructions which implicitly read ST(0), such as fst 3498c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng OneArgFP = 2 << FPTypeShift, 3508c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3518c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // OneArgFPRW - 1 arg FP instruction which implicitly read ST(0) and write a 3528c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // result back to ST(0). For example, fcos, fsqrt, etc. 3538c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // 3548c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng OneArgFPRW = 3 << FPTypeShift, 3558c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3568c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // TwoArgFP - 2 arg FP instructions which implicitly read ST(0), and an 3578c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // explicit argument, storing the result to either ST(0) or the implicit 3588c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // argument. For example: fadd, fsub, fmul, etc... 3598c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng TwoArgFP = 4 << FPTypeShift, 3608c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3618c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // CompareFP - 2 arg FP instructions which implicitly read ST(0) and an 3628c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // explicit argument, but have no destination. Example: fucom, fucomi, ... 3638c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng CompareFP = 5 << FPTypeShift, 3648c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3658c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // CondMovFP - "2 operand" floating point conditional move instructions. 3668c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng CondMovFP = 6 << FPTypeShift, 3678c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3688c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // SpecialFP - Special instruction forms. Dispatch by opcode explicitly. 3698c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng SpecialFP = 7 << FPTypeShift, 3708c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3718c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // Lock prefix 3728c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng LOCKShift = FPTypeShift + 3, 3738c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng LOCK = 1 << LOCKShift, 3748c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3758c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // Segment override prefixes. Currently we just need ability to address 3768c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // stuff in gs and fs segments. 3778c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng SegOvrShift = LOCKShift + 1, 3788c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng SegOvrMask = 3 << SegOvrShift, 3798c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng FS = 1 << SegOvrShift, 3808c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng GS = 2 << SegOvrShift, 3818c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3828c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // Execution domain for SSE instructions in bits 23, 24. 3838c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // 0 in bits 23-24 means normal, non-SSE instruction. 3848c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng SSEDomainShift = SegOvrShift + 2, 3858c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3868c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng OpcodeShift = SSEDomainShift + 2, 3878c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3888c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //===------------------------------------------------------------------===// 3898c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// VEX - The opcode prefix used by AVX instructions 3908c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng VEXShift = OpcodeShift + 8, 3918c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng VEX = 1U << 0, 3928c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3938c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// VEX_W - Has a opcode specific functionality, but is used in the same 3948c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// way as REX_W is for regular SSE instructions. 3958c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng VEX_W = 1U << 1, 3968c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 3978c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// VEX_4V - Used to specify an additional AVX/SSE register. Several 2 3988c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// address instructions in SSE are represented as 3 address ones in AVX 3998c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// and the additional register is encoded in VEX_VVVV prefix. 4008c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng VEX_4V = 1U << 2, 4018c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 402b53fa8bf19a51f0c49a9f8b6ede3e2ff3bdfb961Craig Topper /// VEX_4VOp3 - Similar to VEX_4V, but used on instructions that encode 403b53fa8bf19a51f0c49a9f8b6ede3e2ff3bdfb961Craig Topper /// operand 3 with VEX.vvvv. 404b53fa8bf19a51f0c49a9f8b6ede3e2ff3bdfb961Craig Topper VEX_4VOp3 = 1U << 3, 405b53fa8bf19a51f0c49a9f8b6ede3e2ff3bdfb961Craig Topper 4068c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// VEX_I8IMM - Specifies that the last register used in a AVX instruction, 4078c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// must be encoded in the i8 immediate field. This usually happens in 4088c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// instructions with 4 operands. 409b53fa8bf19a51f0c49a9f8b6ede3e2ff3bdfb961Craig Topper VEX_I8IMM = 1U << 4, 4108c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4118c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// VEX_L - Stands for a bit in the VEX opcode prefix meaning the current 4128c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// instruction uses 256-bit wide registers. This is usually auto detected 4138c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// if a VR256 register is used, but some AVX instructions also have this 4148c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// field marked when using a f256 memory references. 415b53fa8bf19a51f0c49a9f8b6ede3e2ff3bdfb961Craig Topper VEX_L = 1U << 5, 4168c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4176744a17dcfb941d9fdd869b9f06e20660e18ff88Craig Topper // VEX_LIG - Specifies that this instruction ignores the L-bit in the VEX 4186744a17dcfb941d9fdd869b9f06e20660e18ff88Craig Topper // prefix. Usually used for scalar instructions. Needed by disassembler. 419b53fa8bf19a51f0c49a9f8b6ede3e2ff3bdfb961Craig Topper VEX_LIG = 1U << 6, 4206744a17dcfb941d9fdd869b9f06e20660e18ff88Craig Topper 4218c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// Has3DNow0F0FOpcode - This flag indicates that the instruction uses the 4228c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// wacky 0x0F 0x0F prefix for 3DNow! instructions. The manual documents 4238c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// this as having a 0x0F prefix with a 0x0F opcode, and each instruction 4248c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// storing a classifier in the imm8 field. To simplify our implementation, 4258c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// we handle this by storeing the classifier in the opcode field and using 4268c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// this flag to indicate that the encoder should do the wacky 3DNow! thing. 4271b9b377975b3f437acef8c2ba90de582add52f65Bruno Cardoso Lopes Has3DNow0F0FOpcode = 1U << 7, 4281b9b377975b3f437acef8c2ba90de582add52f65Bruno Cardoso Lopes 4291b9b377975b3f437acef8c2ba90de582add52f65Bruno Cardoso Lopes /// XOP_W - Same bit as VEX_W. Used to indicate swapping of 4301b9b377975b3f437acef8c2ba90de582add52f65Bruno Cardoso Lopes /// operand 3 and 4 to be encoded in ModRM or I8IMM. This is used 4311b9b377975b3f437acef8c2ba90de582add52f65Bruno Cardoso Lopes /// for FMA4 and XOP instructions. 432ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5cJan Sjödin XOP_W = 1U << 8, 433ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5cJan Sjödin 434ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5cJan Sjödin /// XOP - Opcode prefix used by XOP instructions. 435ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5cJan Sjödin XOP = 1U << 9 436ebebe35d1c5ad689caf31cdc4da5b7a9539ffa5cJan Sjödin 4378c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng }; 4388c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4398c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // getBaseOpcodeFor - This function returns the "base" X86 opcode for the 4408c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // specified machine instruction. 4418c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // 4428c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng static inline unsigned char getBaseOpcodeFor(uint64_t TSFlags) { 4438c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return TSFlags >> X86II::OpcodeShift; 4448c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 4458c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4468c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng static inline bool hasImm(uint64_t TSFlags) { 4478c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return (TSFlags & X86II::ImmMask) != 0; 4488c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 4498c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4508c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// getSizeOfImm - Decode the "size of immediate" field from the TSFlags field 4518c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// of the specified instruction. 4528c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng static inline unsigned getSizeOfImm(uint64_t TSFlags) { 4538c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng switch (TSFlags & X86II::ImmMask) { 4548c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng default: assert(0 && "Unknown immediate size"); 4558c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm8: 4568c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm8PCRel: return 1; 4578c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm16: 4588c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm16PCRel: return 2; 4598c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm32: 4608c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm32PCRel: return 4; 4618c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm64: return 8; 4628c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 4638c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 4648c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4658c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// isImmPCRel - Return true if the immediate of the specified instruction's 4668c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// TSFlags indicates that it is pc relative. 4678c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng static inline unsigned isImmPCRel(uint64_t TSFlags) { 4688c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng switch (TSFlags & X86II::ImmMask) { 4698c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng default: assert(0 && "Unknown immediate size"); 4708c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm8PCRel: 4718c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm16PCRel: 4728c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm32PCRel: 4738c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return true; 4748c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm8: 4758c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm16: 4768c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm32: 4778c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Imm64: 4788c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return false; 4798c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 4808c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 4818c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 4828c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// getMemoryOperandNo - The function returns the MCInst operand # for the 4838c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// first field of the memory operand. If the instruction doesn't have a 4848c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// memory operand, this returns -1. 4858c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 4868c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// Note that this ignores tied operands. If there is a tied register which 4878c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// is duplicated in the MCInst (e.g. "EAX = addl EAX, [mem]") it is only 4888c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// counted as one operand. 4898c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// 49017730847d59c919d97f097d46a3fcba1888e5300Craig Topper static inline int getMemoryOperandNo(uint64_t TSFlags, unsigned Opcode) { 4918c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng switch (TSFlags & X86II::FormMask) { 4928c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRMInitReg: assert(0 && "FIXME: Remove this form"); 4938c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng default: assert(0 && "Unknown FormMask value in getMemoryOperandNo!"); 4948c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::Pseudo: 4958c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::RawFrm: 4968c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::AddRegFrm: 4978c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRMDestReg: 4988c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRMSrcReg: 4998c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::RawFrmImm8: 5008c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::RawFrmImm16: 5018c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return -1; 5028c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRMDestMem: 5038c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return 0; 5048c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRMSrcMem: { 5058c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng bool HasVEX_4V = (TSFlags >> X86II::VEXShift) & X86II::VEX_4V; 5061b9b377975b3f437acef8c2ba90de582add52f65Bruno Cardoso Lopes bool HasXOP_W = (TSFlags >> X86II::VEXShift) & X86II::XOP_W; 5078c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng unsigned FirstMemOp = 1; 508b53fa8bf19a51f0c49a9f8b6ede3e2ff3bdfb961Craig Topper if (HasVEX_4V) 5098c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng ++FirstMemOp;// Skip the register source (which is encoded in VEX_VVVV). 5101b9b377975b3f437acef8c2ba90de582add52f65Bruno Cardoso Lopes if (HasXOP_W) 5111b9b377975b3f437acef8c2ba90de582add52f65Bruno Cardoso Lopes ++FirstMemOp;// Skip the register source (which is encoded in I8IMM). 5128c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 5138c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // FIXME: Maybe lea should have its own form? This is a horrible hack. 5148c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng //if (Opcode == X86::LEA64r || Opcode == X86::LEA64_32r || 5158c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng // Opcode == X86::LEA16r || Opcode == X86::LEA32r) 5168c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return FirstMemOp; 5178c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 5188c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM0r: case X86II::MRM1r: 5198c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM2r: case X86II::MRM3r: 5208c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM4r: case X86II::MRM5r: 5218c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM6r: case X86II::MRM7r: 5228c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return -1; 5238c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM0m: case X86II::MRM1m: 5248c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM2m: case X86II::MRM3m: 5258c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM4m: case X86II::MRM5m: 526566f233ba64c0bb2773b5717cb18753c7564f4b7Craig Topper case X86II::MRM6m: case X86II::MRM7m: { 527566f233ba64c0bb2773b5717cb18753c7564f4b7Craig Topper bool HasVEX_4V = (TSFlags >> X86II::VEXShift) & X86II::VEX_4V; 528566f233ba64c0bb2773b5717cb18753c7564f4b7Craig Topper unsigned FirstMemOp = 0; 529566f233ba64c0bb2773b5717cb18753c7564f4b7Craig Topper if (HasVEX_4V) 530566f233ba64c0bb2773b5717cb18753c7564f4b7Craig Topper ++FirstMemOp;// Skip the register dest (which is encoded in VEX_VVVV). 531566f233ba64c0bb2773b5717cb18753c7564f4b7Craig Topper return FirstMemOp; 532566f233ba64c0bb2773b5717cb18753c7564f4b7Craig Topper } 5338c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM_C1: 5348c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM_C2: 5358c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM_C3: 5368c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM_C4: 5378c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM_C8: 5388c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM_C9: 5398c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM_E8: 5408c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM_F0: 5418c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM_F8: 5428c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM_F9: 5438c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM_D0: 5448c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86II::MRM_D1: 5458c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return -1; 5468c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 5478c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 5488c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 5498c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// isX86_64ExtendedReg - Is the MachineOperand a x86-64 extended (r8 or 5508c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng /// higher) register? e.g. r8, xmm8, xmm13, etc. 5518c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng static inline bool isX86_64ExtendedReg(unsigned RegNo) { 5528c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng switch (RegNo) { 5538c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng default: break; 5548c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::R8: case X86::R9: case X86::R10: case X86::R11: 5558c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::R12: case X86::R13: case X86::R14: case X86::R15: 5568c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::R8D: case X86::R9D: case X86::R10D: case X86::R11D: 5578c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::R12D: case X86::R13D: case X86::R14D: case X86::R15D: 5588c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::R8W: case X86::R9W: case X86::R10W: case X86::R11W: 5598c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::R12W: case X86::R13W: case X86::R14W: case X86::R15W: 5608c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::R8B: case X86::R9B: case X86::R10B: case X86::R11B: 5618c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::R12B: case X86::R13B: case X86::R14B: case X86::R15B: 5628c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::XMM8: case X86::XMM9: case X86::XMM10: case X86::XMM11: 5638c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::XMM12: case X86::XMM13: case X86::XMM14: case X86::XMM15: 5648c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::YMM8: case X86::YMM9: case X86::YMM10: case X86::YMM11: 5658c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::YMM12: case X86::YMM13: case X86::YMM14: case X86::YMM15: 5668c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::CR8: case X86::CR9: case X86::CR10: case X86::CR11: 5678c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng case X86::CR12: case X86::CR13: case X86::CR14: case X86::CR15: 5688c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return true; 5698c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 5708c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return false; 5718c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 5728c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 5738c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng static inline bool isX86_64NonExtLowByteReg(unsigned reg) { 5748c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng return (reg == X86::SPL || reg == X86::BPL || 5758c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng reg == X86::SIL || reg == X86::DIL); 5768c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng } 5778c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng} 5788c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 5798c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng} // end namespace llvm; 5808c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng 5818c3fee59038d8fd98db2a01b6a309a8941a16a3fEvan Cheng#endif 582