LLVM  9.0.0svn
Classes | Macros | Functions
X86DisassemblerDecoder.cpp File Reference
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "X86DisassemblerDecoder.h"
#include "X86GenDisassemblerTables.inc"
Include dependency graph for X86DisassemblerDecoder.cpp:

Go to the source code of this file.

Classes

struct  ModRMDecision
 Specifies whether a ModR/M byte is needed and (if so) which instruction each possible value of the ModR/M byte corresponds to. More...
 
struct  OpcodeDecision
 Specifies which set of ModR/M->instruction tables to look at given a particular opcode. More...
 
struct  ContextDecision
 Specifies which opcode->instruction tables to look at given a particular context (set of attributes). More...
 

Macros

#define debug(s)   do { Debug(__FILE__, __LINE__, s); } while (0)
 
#define CONSUME_FUNC(name, type)
 
#define GENERIC_FIXUP_FUNC(name, base, prefix, mask)
 

Functions

static InstructionContext contextForAttrs (uint16_t attrMask)
 
static int modRMRequired (OpcodeType type, InstructionContext insnContext, uint16_t opcode)
 
static InstrUID decode (OpcodeType type, InstructionContext insnContext, uint8_t opcode, uint8_t modRM)
 
static const struct InstructionSpecifierspecifierForUID (InstrUID uid)
 
static int consumeByte (struct InternalInstruction *insn, uint8_t *byte)
 
static int lookAtByte (struct InternalInstruction *insn, uint8_t *byte)
 
static void unconsumeByte (struct InternalInstruction *insn)
 
static void dbgprintf (struct InternalInstruction *insn, const char *format,...)
 
static bool isREX (struct InternalInstruction *insn, uint8_t prefix)
 
static void setPrefixPresent (struct InternalInstruction *insn, uint8_t prefix)
 
static int readPrefixes (struct InternalInstruction *insn)
 
static int readModRM (struct InternalInstruction *insn)
 
static int readOpcode (struct InternalInstruction *insn)
 
static int getIDWithAttrMask (uint16_t *instructionID, struct InternalInstruction *insn, uint16_t attrMask)
 
static bool is16BitEquivalent (const char *orig, const char *equiv)
 
static bool is64Bit (const char *name)
 
static int getID (struct InternalInstruction *insn, const void *miiArg)
 
static int readSIB (struct InternalInstruction *insn)
 
static int readDisplacement (struct InternalInstruction *insn)
 
static int fixupReg (struct InternalInstruction *insn, const struct OperandSpecifier *op)
 
static int readOpcodeRegister (struct InternalInstruction *insn, uint8_t size)
 
static int readImmediate (struct InternalInstruction *insn, uint8_t size)
 
static int readVVVV (struct InternalInstruction *insn)
 
static int readMaskRegister (struct InternalInstruction *insn)
 
static int readOperands (struct InternalInstruction *insn)
 

Macro Definition Documentation

◆ CONSUME_FUNC

#define CONSUME_FUNC (   name,
  type 
)
Value:
static int name(struct InternalInstruction* insn, type* ptr) { \
type combined = 0; \
unsigned offset; \
for (offset = 0; offset < sizeof(type); ++offset) { \
uint8_t byte; \
int ret = insn->reader(insn->readerArg, \
&byte, \
insn->readerCursor + offset); \
if (ret) \
return ret; \
combined = combined | ((uint64_t)byte << (offset * 8)); \
} \
*ptr = combined; \
insn->readerCursor += sizeof(type); \
return 0; \
}
The x86 internal instruction, which is produced by the decoder.
static const char * name

Definition at line 226 of file X86DisassemblerDecoder.cpp.

◆ debug

#define debug (   s)    do { Debug(__FILE__, __LINE__, s); } while (0)

◆ GENERIC_FIXUP_FUNC

#define GENERIC_FIXUP_FUNC (   name,
  base,
  prefix,
  mask 
)

Definition at line 1423 of file X86DisassemblerDecoder.cpp.

Function Documentation

◆ consumeByte()

static int consumeByte ( struct InternalInstruction insn,
uint8_t *  byte 
)
static

◆ contextForAttrs()

static InstructionContext contextForAttrs ( uint16_t  attrMask)
static

Definition at line 63 of file X86DisassemblerDecoder.cpp.

References CONTEXTS_SYM.

Referenced by getIDWithAttrMask().

◆ dbgprintf()

static void dbgprintf ( struct InternalInstruction insn,
const char format,
  ... 
)
static

◆ decode()

static InstrUID decode ( OpcodeType  type,
InstructionContext  insnContext,
uint8_t  opcode,
uint8_t  modRM 
)
static

◆ fixupReg()

static int fixupReg ( struct InternalInstruction insn,
const struct OperandSpecifier op 
)
static

Definition at line 1520 of file X86DisassemblerDecoder.cpp.

References CASE_ENCODING_RM, dbgprintf(), and debug.

Referenced by readOperands().

◆ getID()

static int getID ( struct InternalInstruction insn,
const void *  miiArg 
)
static

Definition at line 852 of file X86DisassemblerDecoder.cpp.

References aaaFromEVEX4of4, bFromEVEX4of4, llvm::StringRef::data(), dbgprintf(), getIDWithAttrMask(), llvm::X86Disassembler::GetInstrName(), llvm::X86Disassembler::InternalInstruction::hasAdSize, llvm::X86Disassembler::InternalInstruction::hasOpSize, llvm::X86Disassembler::InternalInstruction::instructionID, is16BitEquivalent(), is64Bit(), l2FromEVEX4of4, lFromEVEX4of4, lFromVEX2of2, lFromVEX3of3, lFromXOP3of3, llvm::X86Disassembler::InternalInstruction::mandatoryPrefix, llvm::X86Disassembler::InternalInstruction::mode, llvm::X86Disassembler::MODE_16BIT, llvm::X86Disassembler::MODE_64BIT, llvm::X86Disassembler::ONEBYTE, llvm::X86Disassembler::InternalInstruction::opcode, llvm::X86Disassembler::InternalInstruction::opcodeType, ppFromEVEX3of4, ppFromVEX2of2, ppFromVEX3of3, ppFromXOP3of3, llvm::X86Disassembler::InternalInstruction::repeatPrefix, llvm::X86Disassembler::InternalInstruction::rexPrefix, llvm::X86Disassembler::InternalInstruction::spec, specifierForUID(), llvm::X86Disassembler::THREEBYTE_38, llvm::X86Disassembler::TWOBYTE, llvm::X86Disassembler::TYPE_EVEX, llvm::X86Disassembler::TYPE_NO_VEX_XOP, llvm::X86Disassembler::TYPE_VEX_2B, llvm::X86Disassembler::TYPE_VEX_3B, llvm::X86Disassembler::TYPE_XOP, llvm::X86Disassembler::InternalInstruction::vectorExtensionPrefix, llvm::X86Disassembler::InternalInstruction::vectorExtensionType, llvm::X86Disassembler::VEX_PREFIX_66, llvm::X86Disassembler::VEX_PREFIX_F2, llvm::X86Disassembler::VEX_PREFIX_F3, wFromEVEX3of4, wFromVEX3of3, wFromXOP3of3, and zFromEVEX4of4.

Referenced by llvm::X86Disassembler::decodeInstruction(), getConstantValueForReg(), llvm::MemoryAccess::getID(), llvm::RegisterBankInfo::InstructionMapping::InstructionMapping(), llvm::RegisterBankInfo::InstructionMapping::isValid(), okayForPHIOfOps(), llvm::RegisterBankInfo::InstructionMapping::print(), llvm::MemoryDef::print(), llvm::MemoryPhi::print(), and llvm::MemoryAccess::setBlock().

◆ getIDWithAttrMask()

static int getIDWithAttrMask ( uint16_t *  instructionID,
struct InternalInstruction insn,
uint16_t  attrMask 
)
static

◆ is16BitEquivalent()

static bool is16BitEquivalent ( const char orig,
const char equiv 
)
static

Definition at line 807 of file X86DisassemblerDecoder.cpp.

Referenced by getID().

◆ is64Bit()

static bool is64Bit ( const char name)
static

Definition at line 832 of file X86DisassemblerDecoder.cpp.

Referenced by llvm::object::MachOObjectFile::BindRebaseAddress(), llvm::object::MachOObjectFile::bindTable(), CC_X86_Intr(), CC_X86_VectorCallAssignRegister(), llvm::object::MachOObjectFile::checkSymbolTable(), llvm::createX86FixupSetCC(), createX86MCAsmInfo(), llvm::NVPTXAsmPrinter::doFinalization(), dumpRelocs(), llvm::PPCFrameLowering::eliminateCallFramePseudoInstr(), llvm::PPCRegisterInfo::eliminateFrameIndex(), llvm::NVPTXFrameLowering::emitPrologue(), getAccessVariant(), llvm::object::MachOObjectFile::getBytesInAddress(), getDataLayoutString(), getEffectiveRelocModel(), llvm::object::MachOObjectFile::getFileFormatName(), getFixupKindLog2Size(), llvm::object::MachOObjectFile::getHeader64(), getID(), llvm::object::MachOObjectFile::getNValue(), getOpenCLAlignment(), llvm::X86TargetLowering::getRegForInlineAsmConstraint(), llvm::PPCTargetLowering::getRegisterByName(), getRelaxedOpcode(), llvm::object::MachOObjectFile::getRelocation(), llvm::object::MachOObjectFile::getRelocationSymbol(), llvm::object::MachOObjectFile::getSectionAddress(), llvm::object::MachOObjectFile::getSectionAlignment(), llvm::object::MachOObjectFile::getSectionContents(), llvm::object::MachOObjectFile::getSectionSize(), llvm::object::MachOObjectFile::getSymbolByIndex(), llvm::object::MachOObjectFile::getSymbolIndex(), llvm::X86Subtarget::hasCMov(), llvm::X86Subtarget::hasCmpxchg16b(), llvm::X86Subtarget::hasMFence(), llvm::X86::isCalleePop(), isInSymtab(), llvm::object::MachOObjectFile::isSectionStripped(), llvm::X86Subtarget::isTargetNaCl32(), llvm::X86Subtarget::isTargetNaCl64(), isWeak(), llvm::X86Subtarget::isXRaySupported(), llvm::object::MachOObjectFile::lazyBindTable(), llvm::PPCRegisterInfo::lowerDynamicAreaOffset(), llvm::SparcTargetLowering::LowerF128Compare(), llvm::object::MachOObjectFile::moveSymbolNext(), llvm::object::MachOObjectFile::rebaseTable(), llvm::object::MachOObjectFile::symbol_end(), llvm::object::MachOObjectFile::weakBindTable(), llvm::X86ELFMCAsmInfo::X86ELFMCAsmInfo(), and llvm::X86MCAsmInfoDarwin::X86MCAsmInfoDarwin().

◆ isREX()

static bool isREX ( struct InternalInstruction insn,
uint8_t  prefix 
)
static

◆ lookAtByte()

static int lookAtByte ( struct InternalInstruction insn,
uint8_t *  byte 
)
static

◆ modRMRequired()

static int modRMRequired ( OpcodeType  type,
InstructionContext  insnContext,
uint16_t  opcode 
)
static

◆ readDisplacement()

static int readDisplacement ( struct InternalInstruction insn)
static

◆ readImmediate()

static int readImmediate ( struct InternalInstruction insn,
uint8_t  size 
)
static

◆ readMaskRegister()

static int readMaskRegister ( struct InternalInstruction insn)
static

◆ readModRM()

static int readModRM ( struct InternalInstruction insn)
static

◆ readOpcode()

static int readOpcode ( struct InternalInstruction insn)
static

◆ readOpcodeRegister()

static int readOpcodeRegister ( struct InternalInstruction insn,
uint8_t  size 
)
static

◆ readOperands()

static int readOperands ( struct InternalInstruction insn)
static

◆ readPrefixes()

static int readPrefixes ( struct InternalInstruction insn)
static

Definition at line 337 of file X86DisassemblerDecoder.cpp.

References llvm::X86Disassembler::InternalInstruction::addressSize, bFromEVEX2of4, bFromVEX2of3, bFromXOP2of3, consumeByte(), dbgprintf(), debug, llvm::X86Disassembler::InternalInstruction::displacementSize, llvm::X86Disassembler::InternalInstruction::hasAdSize, llvm::X86Disassembler::InternalInstruction::hasOpSize, llvm::X86Disassembler::InternalInstruction::immediateSize, isPrefix(), isREX(), lookAtByte(), llvm::X86Disassembler::InternalInstruction::mode, llvm::X86Disassembler::MODE_16BIT, llvm::X86Disassembler::MODE_32BIT, llvm::X86Disassembler::MODE_64BIT, nextByte(), ppFromVEX2of2, ppFromXOP3of3, llvm::X86Disassembler::InternalInstruction::readerCursor, readModRM(), llvm::X86Disassembler::InternalInstruction::registerSize, llvm::X86Disassembler::InternalInstruction::rexPrefix, rFromEVEX2of4, rFromVEX2of2, rFromVEX2of3, rFromXOP2of3, llvm::X86Disassembler::SEG_OVERRIDE_CS, llvm::X86Disassembler::SEG_OVERRIDE_DS, llvm::X86Disassembler::SEG_OVERRIDE_ES, llvm::X86Disassembler::SEG_OVERRIDE_FS, llvm::X86Disassembler::SEG_OVERRIDE_GS, llvm::X86Disassembler::SEG_OVERRIDE_SS, llvm::X86Disassembler::InternalInstruction::segmentOverride, setPrefixPresent(), llvm::X86Disassembler::InternalInstruction::startLocation, llvm::X86Disassembler::TYPE_EVEX, llvm::X86Disassembler::TYPE_NO_VEX_XOP, llvm::X86Disassembler::TYPE_VEX_2B, llvm::X86Disassembler::TYPE_VEX_3B, llvm::X86Disassembler::TYPE_XOP, unconsumeByte(), llvm::X86Disassembler::InternalInstruction::vectorExtensionPrefix, llvm::X86Disassembler::InternalInstruction::vectorExtensionType, llvm::X86Disassembler::VEX_PREFIX_66, wFromEVEX3of4, wFromREX, wFromVEX3of3, wFromXOP3of3, llvm::X86Disassembler::InternalInstruction::xAcquireRelease, xFromEVEX2of4, xFromVEX2of3, and xFromXOP2of3.

Referenced by llvm::X86Disassembler::decodeInstruction().

◆ readSIB()

static int readSIB ( struct InternalInstruction insn)
static

◆ readVVVV()

static int readVVVV ( struct InternalInstruction insn)
static

◆ setPrefixPresent()

static void setPrefixPresent ( struct InternalInstruction insn,
uint8_t  prefix 
)
static

◆ specifierForUID()

static const struct InstructionSpecifier* specifierForUID ( InstrUID  uid)
static

Definition at line 188 of file X86DisassemblerDecoder.cpp.

References INSTRUCTIONS_SYM.

Referenced by getID().

◆ unconsumeByte()

static void unconsumeByte ( struct InternalInstruction insn)
static