LLVM
8.0.1
|
#include "MCTargetDesc/X86BaseInfo.h"
#include "MCTargetDesc/X86MCTargetDesc.h"
#include "X86DisassemblerDecoder.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/raw_ostream.h"
Go to the source code of this file.
Namespaces | |
llvm | |
This class represents lattice values for constants. | |
llvm::X86 | |
Define some predicates that are used for node matching. | |
Macros | |
#define | DEBUG_TYPE "x86-disassembler" |
#define | debug(s) LLVM_DEBUG(Debug(__FILE__, __LINE__, s)); |
#define | ENTRY(x) X86::x, |
#define | ENTRY(x) case EA_BASE_##x: |
#define | ENTRY(x) |
#define | ENTRY(x) |
#define | ENTRY(x) |
#define | ENTRY(x) |
#define | ENTRY(x) case EA_REG_##x: |
Enumerations | |
enum | { llvm::X86::BX_SI = 500, llvm::X86::BX_DI = 501, llvm::X86::BP_SI = 502, llvm::X86::BP_DI = 503, llvm::X86::sib = 504, llvm::X86::sib64 = 505 } |
Functions | |
static bool | translateInstruction (MCInst &mcInst, InternalInstruction &insn, const MCDisassembler *Dis) |
translateInstruction - Translates an internal instruction and all its operands to an MCInst. More... | |
static int | regionReader (const void *Arg, uint8_t *Byte, uint64_t Address) |
A callback function that wraps the readByte method from Region. More... | |
static void | logger (void *arg, const char *log) |
logger - a callback function that wraps the operator<< method from raw_ostream. More... | |
static void | translateRegister (MCInst &mcInst, Reg reg) |
translateRegister - Translates an internal register to the appropriate LLVM register, and appends it as an operand to an MCInst. More... | |
static bool | tryAddingSymbolicOperand (int64_t Value, bool isBranch, uint64_t Address, uint64_t Offset, uint64_t Width, MCInst &MI, const MCDisassembler *Dis) |
tryAddingSymbolicOperand - trys to add a symbolic operand in place of the immediate Value in the MCInst. More... | |
static void | tryAddingPcLoadReferenceComment (uint64_t Address, uint64_t Value, const void *Decoder) |
tryAddingPcLoadReferenceComment - trys to add a comment as to what is being referenced by a load instruction with the base register that is the rip. More... | |
static bool | translateSrcIndex (MCInst &mcInst, InternalInstruction &insn) |
translateSrcIndex - Appends a source index operand to an MCInst. More... | |
static bool | translateDstIndex (MCInst &mcInst, InternalInstruction &insn) |
translateDstIndex - Appends a destination index operand to an MCInst. More... | |
static void | translateImmediate (MCInst &mcInst, uint64_t immediate, const OperandSpecifier &operand, InternalInstruction &insn, const MCDisassembler *Dis) |
translateImmediate - Appends an immediate operand to an MCInst. More... | |
static bool | translateRMRegister (MCInst &mcInst, InternalInstruction &insn) |
translateRMRegister - Translates a register stored in the R/M field of the ModR/M byte to its LLVM equivalent and appends it to an MCInst. More... | |
static bool | translateRMMemory (MCInst &mcInst, InternalInstruction &insn, const MCDisassembler *Dis) |
translateRMMemory - Translates a memory operand stored in the Mod and R/M fields of an internal instruction (and possibly its SIB byte) to a memory operand in LLVM's format, and appends it to an MCInst. More... | |
static bool | translateRM (MCInst &mcInst, const OperandSpecifier &operand, InternalInstruction &insn, const MCDisassembler *Dis) |
translateRM - Translates an operand stored in the R/M (and possibly SIB) byte of an instruction to LLVM form, and appends it to an MCInst. More... | |
static void | translateFPRegister (MCInst &mcInst, uint8_t stackPos) |
translateFPRegister - Translates a stack position on the FPU stack to its LLVM form, and appends it to an MCInst. More... | |
static bool | translateMaskRegister (MCInst &mcInst, uint8_t maskRegNum) |
translateMaskRegister - Translates a 3-bit mask register number to LLVM form, and appends it to an MCInst. More... | |
static bool | translateOperand (MCInst &mcInst, const OperandSpecifier &operand, InternalInstruction &insn, const MCDisassembler *Dis) |
translateOperand - Translates an operand stored in an internal instruction to LLVM's format and appends it to an MCInst. More... | |
static MCDisassembler * | createX86Disassembler (const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx) |
void | LLVMInitializeX86Disassembler () |
Variables | |
static const uint8_t | segmentRegnums [SEG_OVERRIDE_max] |
#define debug | ( | s | ) | LLVM_DEBUG(Debug(__FILE__, __LINE__, s)); |
Definition at line 106 of file X86Disassembler.cpp.
Referenced by llvm::StackMaps::getFnInfos(), translateInstruction(), translateMaskRegister(), translateOperand(), translateRM(), translateRMMemory(), and translateRMRegister().
#define DEBUG_TYPE "x86-disassembler" |
Definition at line 93 of file X86Disassembler.cpp.
#define ENTRY | ( | x | ) | X86::x, |
#define ENTRY | ( | x | ) | case EA_BASE_##x: |
#define ENTRY | ( | x | ) |
#define ENTRY | ( | x | ) |
#define ENTRY | ( | x | ) |
#define ENTRY | ( | x | ) |
#define ENTRY | ( | x | ) | case EA_REG_##x: |
|
static |
Definition at line 1041 of file X86Disassembler.cpp.
References llvm::Target::createMCInstrInfo().
Referenced by LLVMInitializeX86Disassembler().
void LLVMInitializeX86Disassembler | ( | ) |
Definition at line 1048 of file X86Disassembler.cpp.
References createX86Disassembler(), llvm::getTheX86_32Target(), llvm::getTheX86_64Target(), and llvm::TargetRegistry::RegisterMCDisassembler().
logger - a callback function that wraps the operator<< method from raw_ostream.
arg | - The generic callback parameter. This should be a pointe to a raw_ostream. |
log | - A string to be logged. logger() adds a newline. |
Definition at line 202 of file X86Disassembler.cpp.
References llvm::Address, llvm::X86Disassembler::decodeInstruction(), Fail, llvm::X86Disassembler::InternalInstruction::hasAdSize, llvm::X86Disassembler::InternalInstruction::hasLockPrefix, llvm::X86Disassembler::InternalInstruction::hasOpSize, llvm::X86::IP_HAS_AD_SIZE, llvm::X86::IP_HAS_LOCK, llvm::X86::IP_HAS_OP_SIZE, llvm::X86::IP_HAS_REPEAT, llvm::X86::IP_HAS_REPEAT_NE, llvm::X86::IP_NO_PREFIX, llvm::X86Disassembler::InternalInstruction::length, llvm::X86Disassembler::InternalInstruction::mandatoryPrefix, llvm::nulls(), llvm::X86Disassembler::InternalInstruction::opcode, llvm::X86Disassembler::InternalInstruction::readerCursor, regionReader(), llvm::X86Disassembler::InternalInstruction::repeatPrefix, llvm::MipsISD::Ret, llvm::MCInst::setFlags(), Size, Success, and translateInstruction().
Referenced by llvm::X86Disassembler::decodeInstruction().
|
static |
A callback function that wraps the readByte method from Region.
Arg | - The generic callback parameter. In this case, this should be a pointer to a Region. |
Byte | - A pointer to the byte to be read. |
Address | - The address to be read. |
Definition at line 186 of file X86Disassembler.cpp.
References Arg, and llvm::ArrayRef< T >::size().
Referenced by logger().
|
static |
translateDstIndex - Appends a destination index operand to an MCInst.
mcInst | - The MCInst to append to. |
insn | - The internal instruction. |
Definition at line 356 of file X86Disassembler.cpp.
References llvm::MCInst::addOperand(), assert(), llvm::MCOperand::createReg(), llvm::N86::EDI, llvm::X86Disassembler::InternalInstruction::hasAdSize, llvm::X86Disassembler::InternalInstruction::mode, llvm::X86Disassembler::MODE_16BIT, llvm::X86Disassembler::MODE_32BIT, and llvm::X86Disassembler::MODE_64BIT.
Referenced by translateOperand().
|
static |
translateFPRegister - Translates a stack position on the FPU stack to its LLVM form, and appends it to an MCInst.
mcInst | - The MCInst to append to. |
stackPos | - The stack position to translate. |
Definition at line 920 of file X86Disassembler.cpp.
References llvm::MCInst::addOperand(), and llvm::MCOperand::createReg().
Referenced by translateOperand().
|
static |
translateImmediate - Appends an immediate operand to an MCInst.
mcInst | - The MCInst to append to. |
immediate | - The immediate value to append. |
operand | - The operand, as stored in the descriptor table. |
insn | - The internal instruction. |
Definition at line 378 of file X86Disassembler.cpp.
References llvm::MCInst::addOperand(), llvm::MCOperand::createImm(), llvm::MCOperand::createReg(), llvm::X86Disassembler::InternalInstruction::displacementSize, llvm::X86Disassembler::OperandSpecifier::encoding, llvm::MCInst::getOpcode(), if(), llvm::X86Disassembler::InternalInstruction::immediateOffset, llvm::X86Disassembler::InternalInstruction::immediateSize, isBranch(), llvm_unreachable, llvm::X86Disassembler::InternalInstruction::segmentOverride, llvm::MCInst::setOpcode(), llvm::X86Disassembler::InternalInstruction::startLocation, tryAddingSymbolicOperand(), and llvm::X86Disassembler::OperandSpecifier::type.
Referenced by translateOperand().
|
static |
translateInstruction - Translates an internal instruction and all its operands to an MCInst.
mcInst | - The MCInst to populate with the instruction's data. |
insn | - The internal instruction. |
Definition at line 1008 of file X86Disassembler.cpp.
References llvm::MCInst::clear(), debug, llvm::MCInst::getOpcode(), llvm::X86Disassembler::InternalInstruction::instructionID, llvm::X86Disassembler::InternalInstruction::numImmediatesTranslated, llvm::X86Disassembler::InternalInstruction::operands, llvm::MCInst::setOpcode(), llvm::X86Disassembler::InternalInstruction::spec, translateOperand(), and llvm::X86Disassembler::InternalInstruction::xAcquireRelease.
Referenced by logger().
translateMaskRegister - Translates a 3-bit mask register number to LLVM form, and appends it to an MCInst.
mcInst | - The MCInst to append to. |
maskRegNum | - Number of mask register from 0 to 7. |
Definition at line 931 of file X86Disassembler.cpp.
References llvm::MCInst::addOperand(), llvm::MCOperand::createReg(), and debug.
Referenced by translateOperand().
|
static |
translateOperand - Translates an operand stored in an internal instruction to LLVM's format and appends it to an MCInst.
mcInst | - The MCInst to append to. |
operand | - The operand, as stored in the descriptor table. |
insn | - The internal instruction. |
Definition at line 949 of file X86Disassembler.cpp.
References llvm::MCInst::addOperand(), CASE_ENCODING_RM, CASE_ENCODING_VSIB, llvm::MCOperand::createImm(), debug, llvm::X86Disassembler::OperandSpecifier::encoding, llvm::X86Disassembler::InternalInstruction::immediates, llvm::X86Disassembler::InternalInstruction::modRM, llvm::X86Disassembler::InternalInstruction::numImmediatesTranslated, llvm::X86Disassembler::InternalInstruction::opcodeRegister, llvm::X86Disassembler::InternalInstruction::operands, llvm::X86Disassembler::InternalInstruction::RC, llvm::X86Disassembler::InternalInstruction::reg, translateDstIndex(), translateFPRegister(), translateImmediate(), translateMaskRegister(), translateRegister(), translateRM(), translateSrcIndex(), llvm::X86Disassembler::OperandSpecifier::type, llvm::X86Disassembler::InternalInstruction::vvvv, and llvm::X86Disassembler::InternalInstruction::writemask.
Referenced by translateInstruction().
translateRegister - Translates an internal register to the appropriate LLVM register, and appends it as an operand to an MCInst.
mcInst | - The MCInst to append to. |
reg | - The Reg to append. |
Definition at line 268 of file X86Disassembler.cpp.
References llvm::MCInst::addOperand(), ALL_REGS, and llvm::MCOperand::createReg().
Referenced by translateOperand().
|
static |
translateRM - Translates an operand stored in the R/M (and possibly SIB) byte of an instruction to LLVM form, and appends it to an MCInst.
mcInst | - The MCInst to append to. |
operand | - The operand, as stored in the descriptor table. |
insn | - The instruction to extract Mod, R/M, and SIB fields from. |
Definition at line 887 of file X86Disassembler.cpp.
References debug, translateRMMemory(), translateRMRegister(), and llvm::X86Disassembler::OperandSpecifier::type.
Referenced by translateOperand().
|
static |
translateRMMemory - Translates a memory operand stored in the Mod and R/M fields of an internal instruction (and possibly its SIB byte) to a memory operand in LLVM's format, and appends it to an MCInst.
mcInst | - The MCInst to append to. |
insn | - The instruction to extract Mod, R/M, and SIB fields from. |
Definition at line 727 of file X86Disassembler.cpp.
References llvm::MCInst::addOperand(), llvm::X86Disassembler::InternalInstruction::addressSize, ALL_EA_BASES, ALL_REGS, ALL_SIB_BASES, llvm::MCOperand::createImm(), llvm::MCOperand::createReg(), debug, llvm::X86Disassembler::InternalInstruction::displacement, llvm::X86Disassembler::InternalInstruction::displacementOffset, llvm::X86Disassembler::InternalInstruction::displacementSize, llvm::X86Disassembler::EA_BASE_NONE, EA_BASES_32BIT, EA_BASES_64BIT, llvm::X86Disassembler::EA_DISP_NONE, llvm::X86Disassembler::InternalInstruction::eaBase, llvm::X86Disassembler::InternalInstruction::eaDisplacement, llvm::X86Disassembler::InternalInstruction::mode, llvm::X86Disassembler::MODE_64BIT, REGS_XMM, REGS_YMM, REGS_ZMM, llvm::X86Disassembler::InternalInstruction::segmentOverride, SI, llvm::X86Disassembler::SIB_BASE_NONE, llvm::X86Disassembler::SIB_INDEX_NONE, llvm::X86Disassembler::InternalInstruction::sibBase, llvm::X86Disassembler::InternalInstruction::sibIndex, llvm::X86Disassembler::InternalInstruction::sibScale, llvm::X86Disassembler::InternalInstruction::startLocation, tryAddingPcLoadReferenceComment(), and tryAddingSymbolicOperand().
Referenced by translateRM().
|
static |
translateRMRegister - Translates a register stored in the R/M field of the ModR/M byte to its LLVM equivalent and appends it to an MCInst.
mcInst | - The MCInst to append to. |
insn | - The internal instruction to extract the R/M field from. |
Definition at line 689 of file X86Disassembler.cpp.
References ALL_EA_BASES, ALL_REGS, debug, llvm::X86Disassembler::EA_BASE_NONE, and llvm::X86Disassembler::InternalInstruction::eaBase.
Referenced by translateRM().
|
static |
translateSrcIndex - Appends a source index operand to an MCInst.
mcInst | - The MCInst to append to. |
insn | - The internal instruction. |
Definition at line 331 of file X86Disassembler.cpp.
References llvm::MCInst::addOperand(), assert(), llvm::MCOperand::createReg(), llvm::N86::ESI, llvm::X86Disassembler::InternalInstruction::hasAdSize, llvm::X86Disassembler::InternalInstruction::mode, llvm::X86Disassembler::MODE_16BIT, llvm::X86Disassembler::MODE_32BIT, llvm::X86Disassembler::MODE_64BIT, llvm::X86Disassembler::InternalInstruction::segmentOverride, and SI.
Referenced by translateOperand().
|
static |
tryAddingPcLoadReferenceComment - trys to add a comment as to what is being referenced by a load instruction with the base register that is the rip.
These can often be addresses in a literal pool. The Address of the instruction and its immediate Value are used to determine the address being referenced in the literal pool entry. The SymbolLookUp call back will return a pointer to a literal 'C' string if the referenced address is an address into a section with 'C' string literals.
Definition at line 311 of file X86Disassembler.cpp.
References llvm::MCDisassembler::tryAddingPcLoadReferenceComment().
Referenced by translateRMMemory().
|
static |
tryAddingSymbolicOperand - trys to add a symbolic operand in place of the immediate Value in the MCInst.
Value | - The immediate Value, has had any PC adjustment made by the caller. |
isBranch | - If the instruction is a branch instruction |
Address | - The starting address of the instruction |
Offset | - The byte offset to this immediate in the instruction |
Width | - The byte width of this immediate in the instruction |
If the getOpInfo() function was set when setupForSymbolicDisassembly() was called then that function is called to get any symbolic information for the immediate in the instruction using the Address, Offset and Width. If that returns non-zero then the symbolic information it returns is used to create an MCExpr and that is added as an operand to the MCInst. If getOpInfo() returns zero and isBranch is true then a symbol look up for immediate Value is done and if a symbol is found an MCExpr is created with that, else an MCExpr with the immediate Value is created. This function returns true if it adds an operand to the MCInst and false otherwise.
Definition at line 296 of file X86Disassembler.cpp.
References llvm::MCDisassembler::tryAddingSymbolicOperand().
Referenced by translateImmediate(), and translateRMMemory().
|
static |
Definition at line 317 of file X86Disassembler.cpp.