LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Namespaces | Macros | Enumerations | Functions | Variables
X86Disassembler.cpp File Reference
#include "X86Disassembler.h"
#include "X86DisassemblerDecoder.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/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/MemoryObject.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/raw_ostream.h"
#include "X86GenRegisterInfo.inc"
#include "X86GenInstrInfo.inc"
Include dependency graph for X86Disassembler.cpp:

Go to the source code of this file.

Namespaces

 llvm
 List of target independent CodeGen pass IDs.
 
 llvm::X86
 Define some predicates that are used for node matching.
 

Macros

#define GET_REGINFO_ENUM
 
#define GET_INSTRINFO_ENUM
 
#define debug(s)   DEBUG(x86DisassemblerDebug(__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

void x86DisassemblerDebug (const char *file, unsigned line, const char *s)
 
const char * x86DisassemblerGetInstrName (unsigned Opcode, const void *mii)
 
static bool translateInstruction (MCInst &target, InternalInstruction &source, const MCDisassembler *Dis)
 
static int regionReader (const void *arg, uint8_t *byte, uint64_t address)
 
static void logger (void *arg, const char *log)
 
static void translateRegister (MCInst &mcInst, Reg reg)
 
static bool tryAddingSymbolicOperand (int64_t Value, bool isBranch, uint64_t Address, uint64_t Offset, uint64_t Width, MCInst &MI, const MCDisassembler *Dis)
 
static void tryAddingPcLoadReferenceComment (uint64_t Address, uint64_t Value, const void *Decoder)
 
static void translateImmediate (MCInst &mcInst, uint64_t immediate, const OperandSpecifier &operand, InternalInstruction &insn, const MCDisassembler *Dis)
 
static bool translateRMRegister (MCInst &mcInst, InternalInstruction &insn)
 
static bool translateRMMemory (MCInst &mcInst, InternalInstruction &insn, const MCDisassembler *Dis)
 
static bool translateRM (MCInst &mcInst, const OperandSpecifier &operand, InternalInstruction &insn, const MCDisassembler *Dis)
 
static bool translateFPRegister (MCInst &mcInst, uint8_t stackPos)
 
static bool translateOperand (MCInst &mcInst, const OperandSpecifier &operand, InternalInstruction &insn, const MCDisassembler *Dis)
 
static MCDisassemblercreateX86_32Disassembler (const Target &T, const MCSubtargetInfo &STI)
 
static MCDisassemblercreateX86_64Disassembler (const Target &T, const MCSubtargetInfo &STI)
 
void LLVMInitializeX86Disassembler ()
 

Variables

Target llvm::TheX86_32Target
 
Target llvm::TheX86_64Target
 

Macro Definition Documentation

#define debug (   s)    DEBUG(x86DisassemblerDebug(__FILE__, __LINE__, s));
#define ENTRY (   x)    X86::x,
#define ENTRY (   x)    case EA_BASE_##x:
#define ENTRY (   x)
Value:
case EA_REG_##x: \
mcInst.addOperand(MCOperand::CreateReg(X86::x)); break;
#define ENTRY (   x)
Value:
case SIB_BASE_##x: \
baseReg = MCOperand::CreateReg(X86::x); break;
#define ENTRY (   x)
Value:
case SIB_INDEX_##x: \
indexReg = MCOperand::CreateReg(X86::x); break;
#define ENTRY (   x)
Value:
case EA_BASE_##x: \
baseReg = MCOperand::CreateReg(X86::x); break;
#define ENTRY (   x)    case EA_REG_##x:
#define GET_INSTRINFO_ENUM

Definition at line 32 of file X86Disassembler.cpp.

#define GET_REGINFO_ENUM

Definition at line 30 of file X86Disassembler.cpp.

Function Documentation

static MCDisassembler* createX86_32Disassembler ( const Target T,
const MCSubtargetInfo STI 
)
static

Definition at line 711 of file X86Disassembler.cpp.

References llvm::Target::createMCInstrInfo(), and MODE_32BIT.

Referenced by LLVMInitializeX86Disassembler().

static MCDisassembler* createX86_64Disassembler ( const Target T,
const MCSubtargetInfo STI 
)
static

Definition at line 717 of file X86Disassembler.cpp.

References llvm::Target::createMCInstrInfo(), and MODE_64BIT.

Referenced by LLVMInitializeX86Disassembler().

void LLVMInitializeX86Disassembler ( )
static void logger ( void *  arg,
const char *  log 
)
static

logger - a callback function that wraps the operator<< method from raw_ostream.

Parameters
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 102 of file X86Disassembler.cpp.

Referenced by decodeInstruction(), and llvm::X86Disassembler::X86GenericDisassembler::getInstruction().

static int regionReader ( const void *  arg,
uint8_t *  byte,
uint64_t  address 
)
static

regionReader - a callback function that wraps the readByte method from MemoryObject.

Parameters
arg- The generic callback parameter. In this case, this should be a pointer to a MemoryObject.
byte- A pointer to the byte to be read.
address- The address to be read.

Definition at line 91 of file X86Disassembler.cpp.

References llvm::MemoryObject::readByte().

Referenced by llvm::X86Disassembler::X86GenericDisassembler::getInstruction().

static bool translateFPRegister ( MCInst mcInst,
uint8_t  stackPos 
)
static

translateFPRegister - Translates a stack position on the FPU stack to its LLVM form, and appends it to an MCInst.

Parameters
mcInst- The MCInst to append to.
stackPos- The stack position to translate.
Returns
- 0 on success; nonzero otherwise.

Definition at line 600 of file X86Disassembler.cpp.

References llvm::MCInst::addOperand(), llvm::MCOperand::CreateReg(), and debug.

Referenced by translateOperand().

static void translateImmediate ( MCInst mcInst,
uint64_t  immediate,
const OperandSpecifier operand,
InternalInstruction insn,
const MCDisassembler Dis 
)
static

translateImmediate - Appends an immediate operand to an MCInst.

Parameters
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 216 of file X86Disassembler.cpp.

References llvm::MCInst::addOperand(), llvm::MCOperand::CreateImm(), llvm::MCOperand::CreateReg(), InternalInstruction::displacementSize, OperandSpecifier::encoding, llvm::MCInst::getOpcode(), if(), InternalInstruction::immediateOffset, InternalInstruction::immediateSize, isBranch(), InternalInstruction::startLocation, tryAddingSymbolicOperand(), and OperandSpecifier::type.

Referenced by translateOperand().

static bool translateInstruction ( MCInst mcInst,
InternalInstruction insn,
const MCDisassembler Dis 
)
static

translateInstruction - Translates an internal instruction and all its operands to an MCInst.

Parameters
mcInst- The MCInst to populate with the instruction's data.
insn- The internal instruction.
Returns
- false on success; true otherwise.

Definition at line 677 of file X86Disassembler.cpp.

References debug, OperandSpecifier::encoding, llvm::MCInst::getOpcode(), InternalInstruction::instructionID, InternalInstruction::numImmediatesTranslated, InternalInstruction::operands, llvm::MCInst::setOpcode(), InternalInstruction::spec, translateOperand(), X86_MAX_OPERANDS, and InternalInstruction::xAcquireRelease.

Referenced by llvm::X86Disassembler::X86GenericDisassembler::getInstruction().

static bool translateOperand ( MCInst mcInst,
const OperandSpecifier operand,
InternalInstruction insn,
const MCDisassembler Dis 
)
static

translateOperand - Translates an operand stored in an internal instruction to LLVM's format and appends it to an MCInst.

Parameters
mcInst- The MCInst to append to.
operand- The operand, as stored in the descriptor table.
insn- The internal instruction.
Returns
- false on success; true otherwise.

Definition at line 619 of file X86Disassembler.cpp.

References debug, OperandSpecifier::encoding, InternalInstruction::immediates, InternalInstruction::numImmediatesTranslated, InternalInstruction::opcodeModifier, InternalInstruction::opcodeRegister, InternalInstruction::operands, InternalInstruction::reg, translateFPRegister(), translateImmediate(), translateRegister(), translateRM(), OperandSpecifier::type, and InternalInstruction::vvvv.

Referenced by translateInstruction().

static void translateRegister ( MCInst mcInst,
Reg  reg 
)
static

translateRegister - Translates an internal register to the appropriate LLVM register, and appends it as an operand to an MCInst.

Parameters
mcInst- The MCInst to append to.
reg- The Reg to append.

Definition at line 158 of file X86Disassembler.cpp.

References llvm::MCInst::addOperand(), ALL_REGS, and llvm::MCOperand::CreateReg().

Referenced by translateOperand().

static bool translateRM ( MCInst mcInst,
const OperandSpecifier operand,
InternalInstruction insn,
const MCDisassembler Dis 
)
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.

Parameters
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.
Returns
- 0 on success; nonzero otherwise

Definition at line 548 of file X86Disassembler.cpp.

References debug, translateRMMemory(), translateRMRegister(), and OperandSpecifier::type.

Referenced by translateOperand().

static bool translateRMMemory ( MCInst mcInst,
InternalInstruction insn,
const MCDisassembler Dis 
)
static
static bool translateRMRegister ( MCInst mcInst,
InternalInstruction insn 
)
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.

Parameters
mcInst- The MCInst to append to.
insn- The internal instruction to extract the R/M field from.
Returns
- 0 on success; -1 otherwise

Definition at line 326 of file X86Disassembler.cpp.

References ALL_EA_BASES, ALL_REGS, debug, EA_BASE_NONE, and InternalInstruction::eaBase.

Referenced by translateRM().

static void tryAddingPcLoadReferenceComment ( uint64_t  Address,
uint64_t  Value,
const void *  Decoder 
)
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 204 of file X86Disassembler.cpp.

References llvm::MCDisassembler::tryAddingPcLoadReferenceComment().

Referenced by translateRMMemory().

static bool tryAddingSymbolicOperand ( int64_t  Value,
bool  isBranch,
uint64_t  Address,
uint64_t  Offset,
uint64_t  Width,
MCInst MI,
const MCDisassembler Dis 
)
static

tryAddingSymbolicOperand - trys to add a symbolic operand in place of the immediate Value in the MCInst.

Parameters
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 189 of file X86Disassembler.cpp.

References llvm::MCDisassembler::tryAddingSymbolicOperand().

Referenced by translateImmediate(), and translateRMMemory().

void x86DisassemblerDebug ( const char *  file,
unsigned  line,
const char *  s 
)

Definition at line 38 of file X86Disassembler.cpp.

References llvm::dbgs().

const char* x86DisassemblerGetInstrName ( unsigned  Opcode,
const void *  mii 
)

Definition at line 44 of file X86Disassembler.cpp.

References llvm::MCInstrInfo::getName(), and MII.

Referenced by getID().