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.
Defines | |
| #define | TRUE 1 |
| #define | FALSE 0 |
| #define | debug(s) do { x86DisassemblerDebug(__FILE__, __LINE__, s); } while (0) |
| #define | CONSUME_FUNC(name, type) |
| #define | GENERIC_FIXUP_FUNC(name, base, prefix) |
Typedefs | |
| typedef int8_t | bool |
Functions | |
| static InstructionContext | contextForAttrs (uint8_t attrMask) |
| static int | modRMRequired (OpcodeType type, InstructionContext insnContext, uint8_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, uint8_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 | readOpcodeModifier (struct InternalInstruction *insn) |
| 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 | readOperands (struct InternalInstruction *insn) |
| int | decodeInstruction (struct InternalInstruction *insn, byteReader_t reader, const void *readerArg, dlog_t logger, void *loggerArg, const void *miiArg, uint64_t startLoc, DisassemblerMode mode) |
| #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 196 of file X86DisassemblerDecoder.c.
| #define debug | ( | s | ) | do { x86DisassemblerDebug(__FILE__, __LINE__, s); } while (0) |
Definition at line 31 of file X86DisassemblerDecoder.c.
Referenced by decode(), fixupReg(), readImmediate(), readOpcodeModifier(), readPrefixes(), and readSIB().
| #define FALSE 0 |
Definition at line 26 of file X86DisassemblerDecoder.c.
Referenced by is16BitEquivalent(), isPrefixAtLocation(), readDisplacement(), and readPrefixes().
| #define GENERIC_FIXUP_FUNC | ( | name, | |
| base, | |||
| prefix | |||
| ) |
Definition at line 1211 of file X86DisassemblerDecoder.c.
| #define TRUE 1 |
Definition at line 25 of file X86DisassemblerDecoder.c.
Referenced by is16BitEquivalent(), isPrefixAtLocation(), readDisplacement(), readModRM(), readOpcodeModifier(), readPrefixes(), and readSIB().
Definition at line 28 of file X86DisassemblerDecoder.c.
| static int consumeByte | ( | struct InternalInstruction * | insn, |
| uint8_t * | byte | ||
| ) | [static] |
Definition at line 172 of file X86DisassemblerDecoder.c.
References InternalInstruction::reader, InternalInstruction::readerArg, and InternalInstruction::readerCursor.
Referenced by readImmediate(), readModRM(), readOpcode(), readPrefixes(), and readSIB().
| static InstructionContext contextForAttrs | ( | uint8_t | attrMask | ) | [static] |
Definition at line 45 of file X86DisassemblerDecoder.c.
References CONTEXTS_SYM.
Referenced by getIDWithAttrMask().
| static void dbgprintf | ( | struct InternalInstruction * | insn, |
| const char * | format, | ||
| ... | |||
| ) | [static] |
Definition at line 239 of file X86DisassemblerDecoder.c.
References llvm::format(), and llvm::LibFunc::vsnprintf.
Referenced by decodeInstruction(), fixupReg(), getID(), readDisplacement(), readImmediate(), readModRM(), readOpcode(), readOpcodeModifier(), readOpcodeRegister(), readOperands(), readPrefixes(), readSIB(), and readVVVV().
| static InstrUID decode | ( | OpcodeType | type, |
| InstructionContext | insnContext, | ||
| uint8_t | opcode, | ||
| uint8_t | modRM | ||
| ) | [static] |
Definition at line 100 of file X86DisassemblerDecoder.c.
References debug, modFromModRM, ModRMDecision::modrm_type, ONEBYTE, ONEBYTE_SYM, THREEBYTE38_SYM, THREEBYTE3A_SYM, THREEBYTE_38, THREEBYTE_3A, THREEBYTE_A6, THREEBYTE_A7, THREEBYTEA6_SYM, THREEBYTEA7_SYM, TWOBYTE, and TWOBYTE_SYM.
Referenced by getIDWithAttrMask().
| int decodeInstruction | ( | struct InternalInstruction * | insn, |
| byteReader_t | reader, | ||
| const void * | readerArg, | ||
| dlog_t | logger, | ||
| void * | loggerArg, | ||
| const void * | miiArg, | ||
| uint64_t | startLoc, | ||
| DisassemblerMode | mode | ||
| ) |
Definition at line 1639 of file X86DisassemblerDecoder.c.
References dbgprintf(), InternalInstruction::dlog, InternalInstruction::dlogArg, getID(), InternalInstruction::instructionID, InternalInstruction::length, logger(), llvm::LibFunc::memset, InternalInstruction::mode, InternalInstruction::numImmediatesConsumed, InternalInstruction::operands, InternalInstruction::reader, InternalInstruction::readerArg, InternalInstruction::readerCursor, readOpcode(), readOperands(), readPrefixes(), InternalInstruction::spec, and InternalInstruction::startLocation.
Referenced by llvm::X86Disassembler::X86GenericDisassembler::getInstruction().
| static int fixupReg | ( | struct InternalInstruction * | insn, |
| const struct OperandSpecifier * | op | ||
| ) | [static] |
Definition at line 1290 of file X86DisassemblerDecoder.c.
References dbgprintf(), and debug.
Referenced by readOperands().
| static int getID | ( | struct InternalInstruction * | insn, |
| const void * | miiArg | ||
| ) | [static] |
Definition at line 739 of file X86DisassemblerDecoder.c.
References dbgprintf(), getIDWithAttrMask(), InternalInstruction::instructionID, is16BitEquivalent(), isPrefixAtLocation(), lFromVEX2of2, lFromVEX3of3, InternalInstruction::mode, MODE_64BIT, InternalInstruction::necessaryPrefixLocation, ONEBYTE, InternalInstruction::opcode, InternalInstruction::opcodeType, ppFromVEX2of2, ppFromVEX3of3, InternalInstruction::prefixPresent, InternalInstruction::rexPrefix, InternalInstruction::spec, specifierForUID(), VEX_PREFIX_66, VEX_PREFIX_F2, VEX_PREFIX_F3, InternalInstruction::vexPrefix, InternalInstruction::vexSize, and x86DisassemblerGetInstrName().
Referenced by decodeInstruction().
| static int getIDWithAttrMask | ( | uint16_t * | instructionID, |
| struct InternalInstruction * | insn, | ||
| uint8_t | attrMask | ||
| ) | [static] |
Definition at line 672 of file X86DisassemblerDecoder.c.
References contextForAttrs(), decode(), InternalInstruction::modRM, modRMRequired(), InternalInstruction::opcode, InternalInstruction::opcodeType, and readModRM().
Referenced by getID().
| static BOOL is16BitEquivalent | ( | const char * | orig, |
| const char * | equiv | ||
| ) | [static] |
Definition at line 710 of file X86DisassemblerDecoder.c.
Referenced by getID().
| static BOOL isPrefixAtLocation | ( | struct InternalInstruction * | insn, |
| uint8_t | prefix, | ||
| uint64_t | location | ||
| ) | [static] |
Definition at line 283 of file X86DisassemblerDecoder.c.
References FALSE, InternalInstruction::prefixLocations, InternalInstruction::prefixPresent, and TRUE.
Referenced by getID().
| static int lookAtByte | ( | struct InternalInstruction * | insn, |
| uint8_t * | byte | ||
| ) | [static] |
Definition at line 188 of file X86DisassemblerDecoder.c.
References InternalInstruction::reader, InternalInstruction::readerArg, and InternalInstruction::readerCursor.
Referenced by readPrefixes().
| static int modRMRequired | ( | OpcodeType | type, |
| InstructionContext | insnContext, | ||
| uint8_t | opcode | ||
| ) | [static] |
Definition at line 60 of file X86DisassemblerDecoder.c.
References OpcodeDecision::modRMDecisions, ONEBYTE, ONEBYTE_SYM, ContextDecision::opcodeDecisions, THREEBYTE38_SYM, THREEBYTE3A_SYM, THREEBYTE_38, THREEBYTE_3A, THREEBYTE_A6, THREEBYTE_A7, THREEBYTEA6_SYM, THREEBYTEA7_SYM, TWOBYTE, and TWOBYTE_SYM.
Referenced by getIDWithAttrMask().
| static int readDisplacement | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 1034 of file X86DisassemblerDecoder.c.
References InternalInstruction::consumedDisplacement, dbgprintf(), InternalInstruction::displacement, InternalInstruction::displacementOffset, EA_DISP_16, EA_DISP_32, EA_DISP_8, EA_DISP_NONE, InternalInstruction::eaDisplacement, FALSE, InternalInstruction::readerCursor, InternalInstruction::startLocation, and TRUE.
Referenced by readModRM().
| static int readImmediate | ( | struct InternalInstruction * | insn, |
| uint8_t | size | ||
| ) | [static] |
Definition at line 1425 of file X86DisassemblerDecoder.c.
References consumeByte(), dbgprintf(), debug, InternalInstruction::immediateOffset, InternalInstruction::immediates, InternalInstruction::immediateSize, InternalInstruction::numImmediatesConsumed, InternalInstruction::readerCursor, and InternalInstruction::startLocation.
Referenced by readOperands().
| static int readModRM | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 1079 of file X86DisassemblerDecoder.c.
References InternalInstruction::addressSize, bFromREX, consumeByte(), InternalInstruction::consumedModRM, dbgprintf(), EA_BASE_NONE, EA_DISP_16, EA_DISP_32, EA_DISP_8, EA_DISP_NONE, InternalInstruction::eaBase, InternalInstruction::eaBaseBase, InternalInstruction::eaDisplacement, InternalInstruction::eaRegBase, modFromModRM, InternalInstruction::modRM, readDisplacement(), readSIB(), InternalInstruction::reg, InternalInstruction::regBase, regFromModRM, InternalInstruction::registerSize, InternalInstruction::rexPrefix, rFromREX, rmFromModRM, and TRUE.
Referenced by getIDWithAttrMask(), and readOperands().
| static int readOpcode | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 553 of file X86DisassemblerDecoder.c.
References consumeByte(), dbgprintf(), mmmmmFromVEX2of3, ONEBYTE, InternalInstruction::opcode, InternalInstruction::opcodeType, THREEBYTE_38, THREEBYTE_3A, THREEBYTE_A6, THREEBYTE_A7, InternalInstruction::threeByteEscape, TWOBYTE, InternalInstruction::twoByteEscape, VEX_LOB_0F, VEX_LOB_0F38, VEX_LOB_0F3A, InternalInstruction::vexPrefix, and InternalInstruction::vexSize.
Referenced by decodeInstruction().
| static int readOpcodeModifier | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 1340 of file X86DisassemblerDecoder.c.
References InternalInstruction::consumedOpcodeModifier, dbgprintf(), debug, InstructionSpecifier::modifierBase, InstructionSpecifier::modifierType, InternalInstruction::modRM, InternalInstruction::opcode, InternalInstruction::opcodeModifier, InternalInstruction::spec, and TRUE.
Referenced by readOpcodeRegister(), and readOperands().
| static int readOpcodeRegister | ( | struct InternalInstruction * | insn, |
| uint8_t | size | ||
| ) | [static] |
Definition at line 1375 of file X86DisassemblerDecoder.c.
References bFromREX, dbgprintf(), InternalInstruction::opcodeModifier, InternalInstruction::opcodeRegister, readOpcodeModifier(), InternalInstruction::registerSize, and InternalInstruction::rexPrefix.
Referenced by readOperands().
| static int readOperands | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 1502 of file X86DisassemblerDecoder.c.
References InternalInstruction::addressSize, dbgprintf(), fixupReg(), InternalInstruction::immediates, InternalInstruction::immediateSize, InternalInstruction::numImmediatesConsumed, readImmediate(), readModRM(), readOpcodeModifier(), readOpcodeRegister(), readVVVV(), InternalInstruction::spec, InternalInstruction::vvvv, and X86_MAX_OPERANDS.
Referenced by decodeInstruction().
| static int readPrefixes | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 303 of file X86DisassemblerDecoder.c.
References InternalInstruction::addressSize, bFromVEX2of3, consumeByte(), dbgprintf(), debug, InternalInstruction::displacementSize, FALSE, InternalInstruction::immediateSize, lookAtByte(), InternalInstruction::mode, MODE_16BIT, MODE_32BIT, MODE_64BIT, InternalInstruction::necessaryPrefixLocation, ppFromVEX2of2, ppFromVEX3of3, InternalInstruction::readerCursor, InternalInstruction::registerSize, InternalInstruction::rexPrefix, rFromVEX2of2, rFromVEX2of3, SEG_OVERRIDE_CS, SEG_OVERRIDE_DS, SEG_OVERRIDE_ES, SEG_OVERRIDE_FS, SEG_OVERRIDE_GS, SEG_OVERRIDE_SS, InternalInstruction::segmentOverride, setPrefixPresent(), InternalInstruction::startLocation, TRUE, unconsumeByte(), VEX_PREFIX_66, InternalInstruction::vexPrefix, InternalInstruction::vexSize, wFromREX, wFromVEX3of3, and xFromVEX2of3.
Referenced by decodeInstruction().
| static int readSIB | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 936 of file X86DisassemblerDecoder.c.
References InternalInstruction::addressSize, baseFromSIB, bFromREX, consumeByte(), InternalInstruction::consumedSIB, dbgprintf(), debug, EA_DISP_32, EA_DISP_8, InternalInstruction::eaDisplacement, indexFromSIB, modFromModRM, InternalInstruction::modRM, InternalInstruction::rexPrefix, scaleFromSIB, InternalInstruction::sib, SIB_BASE_NONE, SIB_INDEX_NONE, InternalInstruction::sibBase, InternalInstruction::sibIndex, InternalInstruction::sibScale, TRUE, and xFromREX.
Referenced by readModRM().
| static int readVVVV | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 1479 of file X86DisassemblerDecoder.c.
References dbgprintf(), InternalInstruction::mode, MODE_64BIT, InternalInstruction::vexPrefix, InternalInstruction::vexSize, InternalInstruction::vvvv, vvvvFromVEX2of2, and vvvvFromVEX3of3.
Referenced by readOperands().
| static void setPrefixPresent | ( | struct InternalInstruction * | insn, |
| uint8_t | prefix, | ||
| uint64_t | location | ||
| ) | [static] |
Definition at line 266 of file X86DisassemblerDecoder.c.
References llvm::cl::location(), InternalInstruction::prefixLocations, and InternalInstruction::prefixPresent.
Referenced by readPrefixes().
| static struct InstructionSpecifier* specifierForUID | ( | InstrUID | uid | ) | [static, read] |
Definition at line 158 of file X86DisassemblerDecoder.c.
References INSTRUCTIONS_SYM.
Referenced by getID().
| static void unconsumeByte | ( | struct InternalInstruction * | insn | ) | [static] |
Definition at line 192 of file X86DisassemblerDecoder.c.
References InternalInstruction::readerCursor.
Referenced by readPrefixes().