LLVM API Documentation
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "X86DisassemblerDecoder.h"
#include "X86GenDisassemblerTables.inc"
Go to the source code of this file.
Classes | |
struct | ModRMDecision |
struct | OpcodeDecision |
struct | ContextDecision |
Defines | |
#define | debug(s) do { Debug(__FILE__, __LINE__, s); } while (0) |
#define | CONSUME_FUNC(name, type) |
#define | GENERIC_FIXUP_FUNC(name, base, prefix) |
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 struct InstructionSpecifier * | specifierForUID (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 void | setPrefixPresent (struct InternalInstruction *insn, uint8_t prefix, uint64_t location) |
static bool | isPrefixAtLocation (struct InternalInstruction *insn, uint8_t prefix, uint64_t location) |
static int | readPrefixes (struct InternalInstruction *insn) |
static int | readOpcode (struct InternalInstruction *insn) |
static int | readModRM (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 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) |
#define CONSUME_FUNC | ( | name, | |
type | |||
) |
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; \ }
Definition at line 222 of file X86DisassemblerDecoder.cpp.
Definition at line 51 of file X86DisassemblerDecoder.cpp.
Referenced by decode(), fixupReg(), readImmediate(), readPrefixes(), and readSIB().
#define GENERIC_FIXUP_FUNC | ( | name, | |
base, | |||
prefix | |||
) |
Definition at line 1380 of file X86DisassemblerDecoder.cpp.
static int consumeByte | ( | struct InternalInstruction * | insn, |
uint8_t * | byte | ||
) | [static] |
Definition at line 198 of file X86DisassemblerDecoder.cpp.
References llvm::X86Disassembler::InternalInstruction::reader, llvm::X86Disassembler::InternalInstruction::readerArg, and llvm::X86Disassembler::InternalInstruction::readerCursor.
Referenced by readImmediate(), readModRM(), readOpcode(), readPrefixes(), and readSIB().
static InstructionContext contextForAttrs | ( | uint16_t | attrMask | ) | [static] |
Definition at line 65 of file X86DisassemblerDecoder.cpp.
References CONTEXTS_SYM.
Referenced by getIDWithAttrMask().
static void dbgprintf | ( | struct InternalInstruction * | insn, |
const char * | format, | ||
... | |||
) | [static] |
Definition at line 265 of file X86DisassemblerDecoder.cpp.
References llvm::format(), and llvm::LibFunc::vsnprintf.
Referenced by llvm::X86Disassembler::decodeInstruction(), fixupReg(), getID(), readDisplacement(), readImmediate(), readMaskRegister(), readModRM(), readOpcode(), readOpcodeRegister(), readOperands(), readPrefixes(), readSIB(), and readVVVV().
static InstrUID decode | ( | OpcodeType | type, |
InstructionContext | insnContext, | ||
uint8_t | opcode, | ||
uint8_t | modRM | ||
) | [static] |
Definition at line 123 of file X86DisassemblerDecoder.cpp.
References debug, ModRMDecision::instructionIDs, modFromModRM, ModRMDecision::modrm_type, llvm::X86Disassembler::ONEBYTE, ONEBYTE_SYM, THREEBYTE38_SYM, THREEBYTE3A_SYM, llvm::X86Disassembler::THREEBYTE_38, llvm::X86Disassembler::THREEBYTE_3A, llvm::X86Disassembler::TWOBYTE, TWOBYTE_SYM, llvm::X86Disassembler::XOP8_MAP, XOP8_MAP_SYM, llvm::X86Disassembler::XOP9_MAP, XOP9_MAP_SYM, llvm::X86Disassembler::XOPA_MAP, and XOPA_MAP_SYM.
Referenced by getIDWithAttrMask().
static int fixupReg | ( | struct InternalInstruction * | insn, |
const struct OperandSpecifier * | op | ||
) | [static] |
Definition at line 1465 of file X86DisassemblerDecoder.cpp.
References CASE_ENCODING_RM, dbgprintf(), and debug.
Referenced by readOperands().
static int getID | ( | struct InternalInstruction * | insn, |
const void * | miiArg | ||
) | [static] |
Definition at line 877 of file X86DisassemblerDecoder.cpp.
References aaaFromEVEX4of4, bFromEVEX4of4, dbgprintf(), getIDWithAttrMask(), llvm::X86Disassembler::GetInstrName(), llvm::X86Disassembler::InternalInstruction::instructionID, is16BitEquivalent(), isPrefixAtLocation(), l2FromEVEX4of4, lFromEVEX4of4, lFromVEX2of2, lFromVEX3of3, lFromXOP3of3, llvm::X86Disassembler::InternalInstruction::mode, llvm::X86Disassembler::MODE_16BIT, llvm::X86Disassembler::MODE_64BIT, llvm::X86Disassembler::InternalInstruction::necessaryPrefixLocation, llvm::X86Disassembler::ONEBYTE, llvm::X86Disassembler::InternalInstruction::opcode, llvm::X86Disassembler::InternalInstruction::opcodeType, llvm::X86Disassembler::InstructionSpecifier::operands, ppFromEVEX3of4, ppFromVEX2of2, ppFromVEX3of3, ppFromXOP3of3, llvm::X86Disassembler::InternalInstruction::prefixPresent, llvm::X86Disassembler::InternalInstruction::rexPrefix, llvm::X86Disassembler::InternalInstruction::spec, specifierForUID(), 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, and zFromEVEX4of4.
Referenced by llvm::X86Disassembler::decodeInstruction().
static int getIDWithAttrMask | ( | uint16_t * | instructionID, |
struct InternalInstruction * | insn, | ||
uint16_t | attrMask | ||
) | [static] |
Definition at line 812 of file X86DisassemblerDecoder.cpp.
References contextForAttrs(), decode(), llvm::X86Disassembler::InternalInstruction::modRM, modRMRequired(), llvm::X86Disassembler::InternalInstruction::opcode, llvm::X86Disassembler::InternalInstruction::opcodeType, and readModRM().
Referenced by getID().
static bool is16BitEquivalent | ( | const char * | orig, |
const char * | equiv | ||
) | [static] |
Definition at line 848 of file X86DisassemblerDecoder.cpp.
Referenced by getID().
static bool isPrefixAtLocation | ( | struct InternalInstruction * | insn, |
uint8_t | prefix, | ||
uint64_t | location | ||
) | [static] |
Definition at line 309 of file X86DisassemblerDecoder.cpp.
References llvm::X86Disassembler::InternalInstruction::prefixLocations, and llvm::X86Disassembler::InternalInstruction::prefixPresent.
Referenced by getID().
static int lookAtByte | ( | struct InternalInstruction * | insn, |
uint8_t * | byte | ||
) | [static] |
Definition at line 214 of file X86DisassemblerDecoder.cpp.
References llvm::X86Disassembler::InternalInstruction::reader, llvm::X86Disassembler::InternalInstruction::readerArg, and llvm::X86Disassembler::InternalInstruction::readerCursor.
Referenced by readPrefixes().
static int modRMRequired | ( | OpcodeType | type, |
InstructionContext | insnContext, | ||
uint16_t | opcode | ||
) | [static] |
Definition at line 80 of file X86DisassemblerDecoder.cpp.
References OpcodeDecision::modRMDecisions, llvm::X86Disassembler::ONEBYTE, ONEBYTE_SYM, ContextDecision::opcodeDecisions, THREEBYTE38_SYM, THREEBYTE3A_SYM, llvm::X86Disassembler::THREEBYTE_38, llvm::X86Disassembler::THREEBYTE_3A, llvm::X86Disassembler::TWOBYTE, TWOBYTE_SYM, llvm::X86Disassembler::XOP8_MAP, XOP8_MAP_SYM, llvm::X86Disassembler::XOP9_MAP, XOP9_MAP_SYM, llvm::X86Disassembler::XOPA_MAP, and XOPA_MAP_SYM.
Referenced by getIDWithAttrMask().
static int readDisplacement | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 1196 of file X86DisassemblerDecoder.cpp.
References llvm::X86Disassembler::InternalInstruction::consumedDisplacement, dbgprintf(), llvm::X86Disassembler::InternalInstruction::displacement, llvm::X86Disassembler::InternalInstruction::displacementOffset, llvm::X86Disassembler::EA_DISP_16, llvm::X86Disassembler::EA_DISP_32, llvm::X86Disassembler::EA_DISP_8, llvm::X86Disassembler::EA_DISP_NONE, llvm::X86Disassembler::InternalInstruction::eaDisplacement, llvm::X86Disassembler::InternalInstruction::readerCursor, and llvm::X86Disassembler::InternalInstruction::startLocation.
Referenced by readModRM().
static int readImmediate | ( | struct InternalInstruction * | insn, |
uint8_t | size | ||
) | [static] |
Definition at line 1564 of file X86DisassemblerDecoder.cpp.
References consumeByte(), dbgprintf(), debug, llvm::X86Disassembler::InternalInstruction::immediateOffset, llvm::X86Disassembler::InternalInstruction::immediates, llvm::X86Disassembler::InternalInstruction::immediateSize, llvm::X86Disassembler::InternalInstruction::numImmediatesConsumed, llvm::X86Disassembler::InternalInstruction::readerCursor, and llvm::X86Disassembler::InternalInstruction::startLocation.
Referenced by readOperands().
static int readMaskRegister | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 1648 of file X86DisassemblerDecoder.cpp.
References aaaFromEVEX4of4, dbgprintf(), llvm::X86Disassembler::TYPE_EVEX, llvm::X86Disassembler::InternalInstruction::vectorExtensionPrefix, llvm::X86Disassembler::InternalInstruction::vectorExtensionType, and llvm::X86Disassembler::InternalInstruction::writemask.
Referenced by readOperands().
static int readModRM | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 1241 of file X86DisassemblerDecoder.cpp.
References llvm::X86Disassembler::InternalInstruction::addressSize, bFromREX, consumeByte(), llvm::X86Disassembler::InternalInstruction::consumedModRM, dbgprintf(), llvm::X86Disassembler::InternalInstruction::displacementSize, llvm::X86Disassembler::EA_BASE_NONE, llvm::X86Disassembler::EA_DISP_16, llvm::X86Disassembler::EA_DISP_32, llvm::X86Disassembler::EA_DISP_8, llvm::X86Disassembler::EA_DISP_NONE, llvm::X86Disassembler::InternalInstruction::eaBase, llvm::X86Disassembler::InternalInstruction::eaBaseBase, llvm::X86Disassembler::InternalInstruction::eaDisplacement, llvm::X86Disassembler::InternalInstruction::eaRegBase, modFromModRM, llvm::X86Disassembler::InternalInstruction::modRM, r2FromEVEX2of4, readDisplacement(), readSIB(), llvm::X86Disassembler::InternalInstruction::reg, llvm::X86Disassembler::InternalInstruction::regBase, regFromModRM, llvm::X86Disassembler::InternalInstruction::registerSize, llvm::X86Disassembler::InternalInstruction::rexPrefix, rFromREX, rmFromModRM, llvm::X86Disassembler::TYPE_EVEX, llvm::X86Disassembler::InternalInstruction::vectorExtensionPrefix, llvm::X86Disassembler::InternalInstruction::vectorExtensionType, and xFromEVEX2of4.
Referenced by getIDWithAttrMask(), and readOperands().
static int readOpcode | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 692 of file X86DisassemblerDecoder.cpp.
References consumeByte(), dbgprintf(), mmFromEVEX2of4, mmmmmFromVEX2of3, mmmmmFromXOP2of3, llvm::X86Disassembler::ONEBYTE, llvm::X86Disassembler::InternalInstruction::opcode, llvm::X86Disassembler::InternalInstruction::opcodeType, llvm::X86Disassembler::THREEBYTE_38, llvm::X86Disassembler::THREEBYTE_3A, llvm::X86Disassembler::TWOBYTE, llvm::X86Disassembler::TYPE_EVEX, 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_LOB_0F, llvm::X86Disassembler::VEX_LOB_0F38, llvm::X86Disassembler::VEX_LOB_0F3A, llvm::X86Disassembler::XOP8_MAP, llvm::X86Disassembler::XOP9_MAP, llvm::X86Disassembler::XOP_MAP_SELECT_8, llvm::X86Disassembler::XOP_MAP_SELECT_9, llvm::X86Disassembler::XOP_MAP_SELECT_A, and llvm::X86Disassembler::XOPA_MAP.
Referenced by llvm::X86Disassembler::decodeInstruction().
static int readOpcodeRegister | ( | struct InternalInstruction * | insn, |
uint8_t | size | ||
) | [static] |
Definition at line 1517 of file X86DisassemblerDecoder.cpp.
References bFromREX, dbgprintf(), llvm::X86Disassembler::InternalInstruction::opcode, llvm::X86Disassembler::InternalInstruction::opcodeRegister, llvm::X86Disassembler::InternalInstruction::registerSize, and llvm::X86Disassembler::InternalInstruction::rexPrefix.
Referenced by readOperands().
static int readOperands | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 1666 of file X86DisassemblerDecoder.cpp.
References llvm::X86Disassembler::InternalInstruction::addressSize, CASE_ENCODING_RM, dbgprintf(), llvm::X86Disassembler::InternalInstruction::displacement, llvm::X86Disassembler::EA_DISP_8, llvm::X86Disassembler::InternalInstruction::eaDisplacement, fixupReg(), llvm::X86Disassembler::InternalInstruction::immediates, llvm::X86Disassembler::InternalInstruction::immediateSize, llvm::X86Disassembler::InternalInstruction::numImmediatesConsumed, llvm::X86Disassembler::InstructionSpecifier::operands, readImmediate(), readMaskRegister(), readModRM(), readOpcodeRegister(), readVVVV(), llvm::X86Disassembler::InternalInstruction::spec, and llvm::X86Disassembler::InternalInstruction::vvvv.
Referenced by llvm::X86Disassembler::decodeInstruction().
static int readPrefixes | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 329 of file X86DisassemblerDecoder.cpp.
References llvm::X86Disassembler::InternalInstruction::addressSize, bFromEVEX2of4, bFromVEX2of3, bFromXOP2of3, consumeByte(), dbgprintf(), debug, llvm::X86Disassembler::InternalInstruction::displacementSize, llvm::X86Disassembler::InternalInstruction::immediateSize, lookAtByte(), llvm::X86Disassembler::InternalInstruction::mode, llvm::X86Disassembler::MODE_16BIT, llvm::X86Disassembler::MODE_32BIT, llvm::X86Disassembler::MODE_64BIT, llvm::X86Disassembler::InternalInstruction::necessaryPrefixLocation, ppFromVEX2of2, ppFromXOP3of3, llvm::X86Disassembler::InternalInstruction::readerCursor, 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().
static int readSIB | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 1098 of file X86DisassemblerDecoder.cpp.
References llvm::X86Disassembler::InternalInstruction::addressSize, baseFromSIB, bFromREX, consumeByte(), llvm::X86Disassembler::InternalInstruction::consumedSIB, dbgprintf(), debug, llvm::X86Disassembler::EA_DISP_32, llvm::X86Disassembler::EA_DISP_8, llvm::X86Disassembler::InternalInstruction::eaDisplacement, indexFromSIB, modFromModRM, llvm::X86Disassembler::InternalInstruction::modRM, llvm::X86Disassembler::InternalInstruction::rexPrefix, scaleFromSIB, llvm::X86Disassembler::InternalInstruction::sib, llvm::X86Disassembler::SIB_BASE_NONE, llvm::X86Disassembler::SIB_INDEX_NONE, llvm::X86Disassembler::InternalInstruction::sibBase, llvm::X86Disassembler::InternalInstruction::sibIndex, llvm::X86Disassembler::InternalInstruction::sibScale, llvm::X86Disassembler::TYPE_EVEX, v2FromEVEX4of4, llvm::X86Disassembler::InternalInstruction::vectorExtensionPrefix, llvm::X86Disassembler::InternalInstruction::vectorExtensionType, and xFromREX.
Referenced by readModRM().
static int readVVVV | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 1618 of file X86DisassemblerDecoder.cpp.
References dbgprintf(), llvm::X86Disassembler::InternalInstruction::mode, llvm::X86Disassembler::MODE_64BIT, llvm::X86Disassembler::TYPE_EVEX, llvm::X86Disassembler::TYPE_VEX_2B, llvm::X86Disassembler::TYPE_VEX_3B, llvm::X86Disassembler::TYPE_XOP, v2FromEVEX4of4, llvm::X86Disassembler::InternalInstruction::vectorExtensionPrefix, llvm::X86Disassembler::InternalInstruction::vectorExtensionType, llvm::X86Disassembler::InternalInstruction::vvvv, vvvvFromEVEX3of4, vvvvFromVEX2of2, vvvvFromVEX3of3, and vvvvFromXOP3of3.
Referenced by readOperands().
static void setPrefixPresent | ( | struct InternalInstruction * | insn, |
uint8_t | prefix, | ||
uint64_t | location | ||
) | [static] |
Definition at line 292 of file X86DisassemblerDecoder.cpp.
References llvm::cl::location(), llvm::X86Disassembler::InternalInstruction::prefixLocations, and llvm::X86Disassembler::InternalInstruction::prefixPresent.
Referenced by readPrefixes().
static struct InstructionSpecifier* specifierForUID | ( | InstrUID | uid | ) | [static, read] |
Definition at line 184 of file X86DisassemblerDecoder.cpp.
References INSTRUCTIONS_SYM.
Referenced by getID().
static void unconsumeByte | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 218 of file X86DisassemblerDecoder.cpp.
References llvm::X86Disassembler::InternalInstruction::readerCursor.
Referenced by readPrefixes().