2009-12-19 02:59:52 +00:00
|
|
|
//===- X86RecognizableInstr.cpp - Disassembler instruction spec --*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is part of the X86 Disassembler Emitter.
|
|
|
|
// It contains the implementation of a single recognizable instruction.
|
|
|
|
// Documentation for the disassembler emitter in general can be found in
|
|
|
|
// X86DisasemblerEmitter.h.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "X86RecognizableInstr.h"
|
2012-12-04 10:37:14 +00:00
|
|
|
#include "X86DisassemblerShared.h"
|
2009-12-19 02:59:52 +00:00
|
|
|
#include "X86ModRMFilters.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2010-02-12 23:39:46 +00:00
|
|
|
#define MRM_MAPPING \
|
|
|
|
MAP(C1, 33) \
|
2010-02-13 00:41:14 +00:00
|
|
|
MAP(C2, 34) \
|
|
|
|
MAP(C3, 35) \
|
|
|
|
MAP(C4, 36) \
|
|
|
|
MAP(C8, 37) \
|
|
|
|
MAP(C9, 38) \
|
2013-04-11 04:52:28 +00:00
|
|
|
MAP(CA, 39) \
|
|
|
|
MAP(CB, 40) \
|
|
|
|
MAP(E8, 41) \
|
|
|
|
MAP(F0, 42) \
|
|
|
|
MAP(F8, 45) \
|
|
|
|
MAP(F9, 46) \
|
|
|
|
MAP(D0, 47) \
|
|
|
|
MAP(D1, 48) \
|
|
|
|
MAP(D4, 49) \
|
|
|
|
MAP(D5, 50) \
|
|
|
|
MAP(D6, 51) \
|
|
|
|
MAP(D8, 52) \
|
|
|
|
MAP(D9, 53) \
|
|
|
|
MAP(DA, 54) \
|
|
|
|
MAP(DB, 55) \
|
|
|
|
MAP(DC, 56) \
|
|
|
|
MAP(DD, 57) \
|
|
|
|
MAP(DE, 58) \
|
|
|
|
MAP(DF, 59)
|
2010-02-12 23:39:46 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
// A clone of X86 since we can't depend on something that is generated.
|
|
|
|
namespace X86Local {
|
|
|
|
enum {
|
|
|
|
Pseudo = 0,
|
|
|
|
RawFrm = 1,
|
|
|
|
AddRegFrm = 2,
|
|
|
|
MRMDestReg = 3,
|
|
|
|
MRMDestMem = 4,
|
|
|
|
MRMSrcReg = 5,
|
|
|
|
MRMSrcMem = 6,
|
2014-01-16 07:36:58 +00:00
|
|
|
RawFrmMemOffs = 7,
|
2014-01-22 15:08:08 +00:00
|
|
|
RawFrmSrc = 8,
|
2014-01-22 15:08:21 +00:00
|
|
|
RawFrmDst = 9,
|
2014-01-22 15:08:36 +00:00
|
|
|
RawFrmDstSrc = 10,
|
2012-07-30 04:48:12 +00:00
|
|
|
MRM0r = 16, MRM1r = 17, MRM2r = 18, MRM3r = 19,
|
2009-12-19 02:59:52 +00:00
|
|
|
MRM4r = 20, MRM5r = 21, MRM6r = 22, MRM7r = 23,
|
|
|
|
MRM0m = 24, MRM1m = 25, MRM2m = 26, MRM3m = 27,
|
|
|
|
MRM4m = 28, MRM5m = 29, MRM6m = 30, MRM7m = 31,
|
2012-07-18 23:04:22 +00:00
|
|
|
RawFrmImm8 = 43,
|
|
|
|
RawFrmImm16 = 44,
|
2010-02-12 23:39:46 +00:00
|
|
|
#define MAP(from, to) MRM_##from = to,
|
|
|
|
MRM_MAPPING
|
|
|
|
#undef MAP
|
|
|
|
lastMRM
|
2009-12-19 02:59:52 +00:00
|
|
|
};
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
enum {
|
|
|
|
TB = 1,
|
|
|
|
D8 = 3, D9 = 4, DA = 5, DB = 6,
|
|
|
|
DC = 7, DD = 8, DE = 9, DF = 10,
|
|
|
|
XD = 11, XS = 12,
|
2010-02-12 02:06:33 +00:00
|
|
|
T8 = 13, P_TA = 14,
|
2013-10-03 05:17:48 +00:00
|
|
|
A6 = 15, A7 = 16, T8XD = 17, T8XS = 18, TAXD = 19,
|
2014-01-14 08:07:10 +00:00
|
|
|
XOP8 = 20, XOP9 = 21, XOPA = 22, PD = 23, T8PD = 24, TAPD = 25
|
2009-12-19 02:59:52 +00:00
|
|
|
};
|
|
|
|
}
|
2010-02-12 23:39:46 +00:00
|
|
|
|
|
|
|
// If rows are added to the opcode extension tables, then corresponding entries
|
2012-07-30 04:48:12 +00:00
|
|
|
// must be added here.
|
2010-02-12 23:39:46 +00:00
|
|
|
//
|
|
|
|
// If the row corresponds to a single byte (i.e., 8f), then add an entry for
|
|
|
|
// that byte to ONE_BYTE_EXTENSION_TABLES.
|
|
|
|
//
|
2012-07-30 04:48:12 +00:00
|
|
|
// If the row corresponds to two bytes where the first is 0f, add an entry for
|
2010-02-12 23:39:46 +00:00
|
|
|
// the second byte to TWO_BYTE_EXTENSION_TABLES.
|
|
|
|
//
|
|
|
|
// If the row corresponds to some other set of bytes, you will need to modify
|
|
|
|
// the code in RecognizableInstr::emitDecodePath() as well, and add new prefixes
|
2012-07-30 04:48:12 +00:00
|
|
|
// to the X86 TD files, except in two cases: if the first two bytes of such a
|
2010-02-12 23:39:46 +00:00
|
|
|
// new combination are 0f 38 or 0f 3a, you just have to add maps called
|
|
|
|
// THREE_BYTE_38_EXTENSION_TABLES and THREE_BYTE_3A_EXTENSION_TABLES and add a
|
|
|
|
// switch(Opcode) just below the case X86Local::T8: or case X86Local::TA: line
|
|
|
|
// in RecognizableInstr::emitDecodePath().
|
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
#define ONE_BYTE_EXTENSION_TABLES \
|
|
|
|
EXTENSION_TABLE(80) \
|
|
|
|
EXTENSION_TABLE(81) \
|
|
|
|
EXTENSION_TABLE(82) \
|
|
|
|
EXTENSION_TABLE(83) \
|
|
|
|
EXTENSION_TABLE(8f) \
|
|
|
|
EXTENSION_TABLE(c0) \
|
|
|
|
EXTENSION_TABLE(c1) \
|
|
|
|
EXTENSION_TABLE(c6) \
|
|
|
|
EXTENSION_TABLE(c7) \
|
|
|
|
EXTENSION_TABLE(d0) \
|
|
|
|
EXTENSION_TABLE(d1) \
|
|
|
|
EXTENSION_TABLE(d2) \
|
|
|
|
EXTENSION_TABLE(d3) \
|
|
|
|
EXTENSION_TABLE(f6) \
|
|
|
|
EXTENSION_TABLE(f7) \
|
|
|
|
EXTENSION_TABLE(fe) \
|
|
|
|
EXTENSION_TABLE(ff)
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
#define TWO_BYTE_EXTENSION_TABLES \
|
|
|
|
EXTENSION_TABLE(00) \
|
|
|
|
EXTENSION_TABLE(01) \
|
2013-02-12 00:19:12 +00:00
|
|
|
EXTENSION_TABLE(0d) \
|
2009-12-19 02:59:52 +00:00
|
|
|
EXTENSION_TABLE(18) \
|
|
|
|
EXTENSION_TABLE(71) \
|
|
|
|
EXTENSION_TABLE(72) \
|
|
|
|
EXTENSION_TABLE(73) \
|
|
|
|
EXTENSION_TABLE(ae) \
|
|
|
|
EXTENSION_TABLE(ba) \
|
|
|
|
EXTENSION_TABLE(c7)
|
|
|
|
|
2011-10-15 20:46:47 +00:00
|
|
|
#define THREE_BYTE_38_EXTENSION_TABLES \
|
|
|
|
EXTENSION_TABLE(F3)
|
|
|
|
|
2013-10-03 05:17:48 +00:00
|
|
|
#define XOP9_MAP_EXTENSION_TABLES \
|
|
|
|
EXTENSION_TABLE(01) \
|
|
|
|
EXTENSION_TABLE(02)
|
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
using namespace X86Disassembler;
|
|
|
|
|
|
|
|
/// needsModRMForDecode - Indicates whether a particular instruction requires a
|
2012-07-30 04:48:12 +00:00
|
|
|
/// ModR/M byte for the instruction to be properly decoded. For example, a
|
2009-12-19 02:59:52 +00:00
|
|
|
/// MRMDestReg instruction needs the Mod field in the ModR/M byte to be set to
|
|
|
|
/// 0b11.
|
|
|
|
///
|
|
|
|
/// @param form - The form of the instruction.
|
|
|
|
/// @return - true if the form implies that a ModR/M byte is required, false
|
|
|
|
/// otherwise.
|
|
|
|
static bool needsModRMForDecode(uint8_t form) {
|
|
|
|
if (form == X86Local::MRMDestReg ||
|
|
|
|
form == X86Local::MRMDestMem ||
|
|
|
|
form == X86Local::MRMSrcReg ||
|
|
|
|
form == X86Local::MRMSrcMem ||
|
|
|
|
(form >= X86Local::MRM0r && form <= X86Local::MRM7r) ||
|
|
|
|
(form >= X86Local::MRM0m && form <= X86Local::MRM7m))
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isRegFormat - Indicates whether a particular form requires the Mod field of
|
|
|
|
/// the ModR/M byte to be 0b11.
|
|
|
|
///
|
|
|
|
/// @param form - The form of the instruction.
|
|
|
|
/// @return - true if the form implies that Mod must be 0b11, false
|
|
|
|
/// otherwise.
|
|
|
|
static bool isRegFormat(uint8_t form) {
|
|
|
|
if (form == X86Local::MRMDestReg ||
|
|
|
|
form == X86Local::MRMSrcReg ||
|
|
|
|
(form >= X86Local::MRM0r && form <= X86Local::MRM7r))
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// byteFromBitsInit - Extracts a value at most 8 bits in width from a BitsInit.
|
|
|
|
/// Useful for switch statements and the like.
|
|
|
|
///
|
|
|
|
/// @param init - A reference to the BitsInit to be decoded.
|
|
|
|
/// @return - The field, with the first bit in the BitsInit as the lowest
|
|
|
|
/// order bit.
|
2011-07-29 22:43:06 +00:00
|
|
|
static uint8_t byteFromBitsInit(BitsInit &init) {
|
2009-12-19 02:59:52 +00:00
|
|
|
int width = init.getNumBits();
|
|
|
|
|
|
|
|
assert(width <= 8 && "Field is too large for uint8_t!");
|
|
|
|
|
|
|
|
int index;
|
|
|
|
uint8_t mask = 0x01;
|
|
|
|
|
|
|
|
uint8_t ret = 0;
|
|
|
|
|
|
|
|
for (index = 0; index < width; index++) {
|
2011-07-29 22:43:06 +00:00
|
|
|
if (static_cast<BitInit*>(init.getBit(index))->getValue())
|
2009-12-19 02:59:52 +00:00
|
|
|
ret |= mask;
|
|
|
|
|
|
|
|
mask <<= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// byteFromRec - Extract a value at most 8 bits in with from a Record given the
|
|
|
|
/// name of the field.
|
|
|
|
///
|
|
|
|
/// @param rec - The record from which to extract the value.
|
|
|
|
/// @param name - The name of the field in the record.
|
|
|
|
/// @return - The field, as translated by byteFromBitsInit().
|
|
|
|
static uint8_t byteFromRec(const Record* rec, const std::string &name) {
|
2011-07-29 22:43:06 +00:00
|
|
|
BitsInit* bits = rec->getValueAsBitsInit(name);
|
2009-12-19 02:59:52 +00:00
|
|
|
return byteFromBitsInit(*bits);
|
|
|
|
}
|
|
|
|
|
|
|
|
RecognizableInstr::RecognizableInstr(DisassemblerTables &tables,
|
|
|
|
const CodeGenInstruction &insn,
|
|
|
|
InstrUID uid) {
|
|
|
|
UID = uid;
|
|
|
|
|
|
|
|
Rec = insn.TheDef;
|
|
|
|
Name = Rec->getName();
|
|
|
|
Spec = &tables.specForUID(UID);
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
if (!Rec->isSubClassOf("X86Inst")) {
|
|
|
|
ShouldBeEmitted = false;
|
|
|
|
return;
|
|
|
|
}
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
Prefix = byteFromRec(Rec, "Prefix");
|
|
|
|
Opcode = byteFromRec(Rec, "Opcode");
|
|
|
|
Form = byteFromRec(Rec, "FormBits");
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
HasOpSizePrefix = Rec->getValueAsBit("hasOpSizePrefix");
|
2014-01-15 05:02:02 +00:00
|
|
|
HasOpSize16Prefix = Rec->getValueAsBit("hasOpSize16Prefix");
|
2012-02-27 01:54:29 +00:00
|
|
|
HasAdSizePrefix = Rec->getValueAsBit("hasAdSizePrefix");
|
2009-12-19 02:59:52 +00:00
|
|
|
HasREX_WPrefix = Rec->getValueAsBit("hasREX_WPrefix");
|
2011-03-15 01:23:15 +00:00
|
|
|
HasVEXPrefix = Rec->getValueAsBit("hasVEXPrefix");
|
2010-06-08 22:51:23 +00:00
|
|
|
HasVEX_4VPrefix = Rec->getValueAsBit("hasVEX_4VPrefix");
|
2011-10-16 07:55:05 +00:00
|
|
|
HasVEX_4VOp3Prefix = Rec->getValueAsBit("hasVEX_4VOp3Prefix");
|
2011-03-15 01:23:15 +00:00
|
|
|
HasVEX_WPrefix = Rec->getValueAsBit("hasVEX_WPrefix");
|
2011-12-30 05:20:36 +00:00
|
|
|
HasMemOp4Prefix = Rec->getValueAsBit("hasMemOp4Prefix");
|
2011-10-04 06:30:42 +00:00
|
|
|
IgnoresVEX_L = Rec->getValueAsBit("ignoresVEX_L");
|
2013-07-28 08:28:38 +00:00
|
|
|
HasEVEXPrefix = Rec->getValueAsBit("hasEVEXPrefix");
|
|
|
|
HasEVEX_L2Prefix = Rec->getValueAsBit("hasEVEX_L2");
|
|
|
|
HasEVEX_K = Rec->getValueAsBit("hasEVEX_K");
|
2013-11-03 13:46:31 +00:00
|
|
|
HasEVEX_KZ = Rec->getValueAsBit("hasEVEX_Z");
|
2013-07-28 08:28:38 +00:00
|
|
|
HasEVEX_B = Rec->getValueAsBit("hasEVEX_B");
|
2009-12-19 02:59:52 +00:00
|
|
|
HasLockPrefix = Rec->getValueAsBit("hasLockPrefix");
|
2014-01-31 07:00:55 +00:00
|
|
|
HasREPPrefix = Rec->getValueAsBit("hasREPPrefix");
|
2009-12-19 02:59:52 +00:00
|
|
|
IsCodeGenOnly = Rec->getValueAsBit("isCodeGenOnly");
|
2014-01-05 04:17:28 +00:00
|
|
|
ForceDisassemble = Rec->getValueAsBit("ForceDisassemble");
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
Name = Rec->getName();
|
|
|
|
AsmString = Rec->getValueAsString("AsmString");
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2010-11-01 04:03:32 +00:00
|
|
|
Operands = &insn.Operands.OperandList;
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2012-09-19 06:37:45 +00:00
|
|
|
HasVEX_LPrefix = Rec->getValueAsBit("hasVEX_L");
|
2011-10-16 03:51:13 +00:00
|
|
|
|
2011-07-16 02:41:28 +00:00
|
|
|
// Check for 64-bit inst which does not require REX
|
2011-09-23 06:57:25 +00:00
|
|
|
Is32Bit = false;
|
2011-07-16 02:41:28 +00:00
|
|
|
Is64Bit = false;
|
|
|
|
// FIXME: Is there some better way to check for In64BitMode?
|
|
|
|
std::vector<Record*> Predicates = Rec->getValueAsListOfDefs("Predicates");
|
|
|
|
for (unsigned i = 0, e = Predicates.size(); i != e; ++i) {
|
2013-12-20 02:04:49 +00:00
|
|
|
if (Predicates[i]->getName().find("Not64Bit") != Name.npos ||
|
|
|
|
Predicates[i]->getName().find("In32Bit") != Name.npos) {
|
2011-09-23 06:57:25 +00:00
|
|
|
Is32Bit = true;
|
|
|
|
break;
|
|
|
|
}
|
2013-12-20 02:04:49 +00:00
|
|
|
if (Predicates[i]->getName().find("In64Bit") != Name.npos) {
|
2011-07-16 02:41:28 +00:00
|
|
|
Is64Bit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
ShouldBeEmitted = true;
|
|
|
|
}
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
void RecognizableInstr::processInstr(DisassemblerTables &tables,
|
2012-07-12 06:52:41 +00:00
|
|
|
const CodeGenInstruction &insn,
|
|
|
|
InstrUID uid)
|
2009-12-19 02:59:52 +00:00
|
|
|
{
|
2010-05-20 20:20:32 +00:00
|
|
|
// Ignore "asm parser only" instructions.
|
|
|
|
if (insn.TheDef->getValueAsBit("isAsmParserOnly"))
|
|
|
|
return;
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
RecognizableInstr recogInstr(tables, insn, uid);
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2014-01-02 03:58:45 +00:00
|
|
|
recogInstr.emitInstructionSpecifier();
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
if (recogInstr.shouldBeEmitted())
|
|
|
|
recogInstr.emitDecodePath(tables);
|
|
|
|
}
|
|
|
|
|
2013-11-03 13:46:31 +00:00
|
|
|
#define EVEX_KB(n) (HasEVEX_KZ && HasEVEX_B ? n##_KZ_B : \
|
|
|
|
(HasEVEX_K && HasEVEX_B ? n##_K_B : \
|
|
|
|
(HasEVEX_KZ ? n##_KZ : \
|
|
|
|
(HasEVEX_K? n##_K : (HasEVEX_B ? n##_B : n)))))
|
2013-07-28 08:28:38 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
InstructionContext RecognizableInstr::insnContext() const {
|
|
|
|
InstructionContext insnContext;
|
|
|
|
|
2013-07-28 08:28:38 +00:00
|
|
|
if (HasEVEXPrefix) {
|
|
|
|
if (HasVEX_LPrefix && HasEVEX_L2Prefix) {
|
2013-07-28 21:28:02 +00:00
|
|
|
errs() << "Don't support VEX.L if EVEX_L2 is enabled: " << Name << "\n";
|
|
|
|
llvm_unreachable("Don't support VEX.L if EVEX_L2 is enabled");
|
2013-07-28 08:28:38 +00:00
|
|
|
}
|
|
|
|
// VEX_L & VEX_W
|
|
|
|
if (HasVEX_LPrefix && HasVEX_WPrefix) {
|
2014-01-14 07:41:20 +00:00
|
|
|
if (HasOpSizePrefix || Prefix == X86Local::PD)
|
2013-07-28 08:28:38 +00:00
|
|
|
insnContext = EVEX_KB(IC_EVEX_L_W_OPSIZE);
|
|
|
|
else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
|
|
|
|
insnContext = EVEX_KB(IC_EVEX_L_W_XS);
|
|
|
|
else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
|
|
|
|
Prefix == X86Local::TAXD)
|
|
|
|
insnContext = EVEX_KB(IC_EVEX_L_W_XD);
|
|
|
|
else
|
|
|
|
insnContext = EVEX_KB(IC_EVEX_L_W);
|
|
|
|
} else if (HasVEX_LPrefix) {
|
|
|
|
// VEX_L
|
2014-01-14 07:41:20 +00:00
|
|
|
if (HasOpSizePrefix || Prefix == X86Local::PD ||
|
|
|
|
Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
|
2013-07-28 08:28:38 +00:00
|
|
|
insnContext = EVEX_KB(IC_EVEX_L_OPSIZE);
|
|
|
|
else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
|
|
|
|
insnContext = EVEX_KB(IC_EVEX_L_XS);
|
|
|
|
else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
|
|
|
|
Prefix == X86Local::TAXD)
|
|
|
|
insnContext = EVEX_KB(IC_EVEX_L_XD);
|
|
|
|
else
|
|
|
|
insnContext = EVEX_KB(IC_EVEX_L);
|
|
|
|
}
|
|
|
|
else if (HasEVEX_L2Prefix && HasVEX_WPrefix) {
|
|
|
|
// EVEX_L2 & VEX_W
|
2014-01-14 07:41:20 +00:00
|
|
|
if (HasOpSizePrefix || Prefix == X86Local::PD ||
|
|
|
|
Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
|
2013-07-28 08:28:38 +00:00
|
|
|
insnContext = EVEX_KB(IC_EVEX_L2_W_OPSIZE);
|
|
|
|
else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
|
|
|
|
insnContext = EVEX_KB(IC_EVEX_L2_W_XS);
|
|
|
|
else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
|
|
|
|
Prefix == X86Local::TAXD)
|
|
|
|
insnContext = EVEX_KB(IC_EVEX_L2_W_XD);
|
|
|
|
else
|
|
|
|
insnContext = EVEX_KB(IC_EVEX_L2_W);
|
|
|
|
} else if (HasEVEX_L2Prefix) {
|
|
|
|
// EVEX_L2
|
2014-01-14 07:41:20 +00:00
|
|
|
if (HasOpSizePrefix || Prefix == X86Local::PD ||
|
|
|
|
Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
|
2013-07-28 08:28:38 +00:00
|
|
|
insnContext = EVEX_KB(IC_EVEX_L2_OPSIZE);
|
|
|
|
else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
|
2014-01-14 07:41:20 +00:00
|
|
|
Prefix == X86Local::TAXD)
|
2013-07-28 08:28:38 +00:00
|
|
|
insnContext = EVEX_KB(IC_EVEX_L2_XD);
|
|
|
|
else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
|
|
|
|
insnContext = EVEX_KB(IC_EVEX_L2_XS);
|
|
|
|
else
|
|
|
|
insnContext = EVEX_KB(IC_EVEX_L2);
|
|
|
|
}
|
|
|
|
else if (HasVEX_WPrefix) {
|
|
|
|
// VEX_W
|
2014-01-14 07:41:20 +00:00
|
|
|
if (HasOpSizePrefix || Prefix == X86Local::PD ||
|
|
|
|
Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
|
2013-07-28 08:28:38 +00:00
|
|
|
insnContext = EVEX_KB(IC_EVEX_W_OPSIZE);
|
|
|
|
else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
|
|
|
|
insnContext = EVEX_KB(IC_EVEX_W_XS);
|
|
|
|
else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
|
|
|
|
Prefix == X86Local::TAXD)
|
|
|
|
insnContext = EVEX_KB(IC_EVEX_W_XD);
|
|
|
|
else
|
|
|
|
insnContext = EVEX_KB(IC_EVEX_W);
|
|
|
|
}
|
|
|
|
// No L, no W
|
2014-01-14 07:41:20 +00:00
|
|
|
else if (HasOpSizePrefix || Prefix == X86Local::PD ||
|
|
|
|
Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
|
2013-07-28 08:28:38 +00:00
|
|
|
insnContext = EVEX_KB(IC_EVEX_OPSIZE);
|
|
|
|
else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
|
|
|
|
Prefix == X86Local::TAXD)
|
|
|
|
insnContext = EVEX_KB(IC_EVEX_XD);
|
|
|
|
else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
|
|
|
|
insnContext = EVEX_KB(IC_EVEX_XS);
|
|
|
|
else
|
|
|
|
insnContext = EVEX_KB(IC_EVEX);
|
|
|
|
/// eof EVEX
|
|
|
|
} else if (HasVEX_4VPrefix || HasVEX_4VOp3Prefix|| HasVEXPrefix) {
|
2011-11-06 23:04:08 +00:00
|
|
|
if (HasVEX_LPrefix && HasVEX_WPrefix) {
|
2014-01-14 07:41:20 +00:00
|
|
|
if (HasOpSizePrefix || Prefix == X86Local::PD ||
|
|
|
|
Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
|
2011-11-06 23:04:08 +00:00
|
|
|
insnContext = IC_VEX_L_W_OPSIZE;
|
2013-07-28 08:28:38 +00:00
|
|
|
else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
|
|
|
|
insnContext = IC_VEX_L_W_XS;
|
|
|
|
else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
|
|
|
|
Prefix == X86Local::TAXD)
|
|
|
|
insnContext = IC_VEX_L_W_XD;
|
2011-11-06 23:04:08 +00:00
|
|
|
else
|
2013-07-28 08:28:38 +00:00
|
|
|
insnContext = IC_VEX_L_W;
|
2014-01-14 07:41:20 +00:00
|
|
|
} else if ((HasOpSizePrefix || Prefix == X86Local::PD ||
|
|
|
|
Prefix == X86Local::T8PD || Prefix == X86Local::TAPD) &&
|
|
|
|
HasVEX_LPrefix)
|
2011-03-15 01:23:15 +00:00
|
|
|
insnContext = IC_VEX_L_OPSIZE;
|
2014-01-14 07:41:20 +00:00
|
|
|
else if ((HasOpSizePrefix || Prefix == X86Local::PD ||
|
|
|
|
Prefix == X86Local::T8PD || Prefix == X86Local::TAPD) &&
|
|
|
|
HasVEX_WPrefix)
|
2011-03-15 01:23:15 +00:00
|
|
|
insnContext = IC_VEX_W_OPSIZE;
|
2014-01-14 07:41:20 +00:00
|
|
|
else if (HasOpSizePrefix || Prefix == X86Local::PD ||
|
|
|
|
Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
|
2011-03-15 01:23:15 +00:00
|
|
|
insnContext = IC_VEX_OPSIZE;
|
2011-10-16 16:50:08 +00:00
|
|
|
else if (HasVEX_LPrefix &&
|
|
|
|
(Prefix == X86Local::XS || Prefix == X86Local::T8XS))
|
2011-03-15 01:23:15 +00:00
|
|
|
insnContext = IC_VEX_L_XS;
|
2011-10-23 07:34:00 +00:00
|
|
|
else if (HasVEX_LPrefix && (Prefix == X86Local::XD ||
|
|
|
|
Prefix == X86Local::T8XD ||
|
|
|
|
Prefix == X86Local::TAXD))
|
2011-03-15 01:23:15 +00:00
|
|
|
insnContext = IC_VEX_L_XD;
|
2011-10-16 16:50:08 +00:00
|
|
|
else if (HasVEX_WPrefix &&
|
|
|
|
(Prefix == X86Local::XS || Prefix == X86Local::T8XS))
|
2011-03-15 01:23:15 +00:00
|
|
|
insnContext = IC_VEX_W_XS;
|
2011-10-23 07:34:00 +00:00
|
|
|
else if (HasVEX_WPrefix && (Prefix == X86Local::XD ||
|
|
|
|
Prefix == X86Local::T8XD ||
|
|
|
|
Prefix == X86Local::TAXD))
|
2011-03-15 01:23:15 +00:00
|
|
|
insnContext = IC_VEX_W_XD;
|
|
|
|
else if (HasVEX_WPrefix)
|
|
|
|
insnContext = IC_VEX_W;
|
|
|
|
else if (HasVEX_LPrefix)
|
|
|
|
insnContext = IC_VEX_L;
|
2011-10-23 07:34:00 +00:00
|
|
|
else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
|
|
|
|
Prefix == X86Local::TAXD)
|
2011-03-15 01:23:15 +00:00
|
|
|
insnContext = IC_VEX_XD;
|
2011-10-16 16:50:08 +00:00
|
|
|
else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
|
2011-03-15 01:23:15 +00:00
|
|
|
insnContext = IC_VEX_XS;
|
|
|
|
else
|
|
|
|
insnContext = IC_VEX;
|
2011-07-16 02:41:28 +00:00
|
|
|
} else if (Is64Bit || HasREX_WPrefix) {
|
2014-01-14 07:41:20 +00:00
|
|
|
if (HasREX_WPrefix && (HasOpSizePrefix || Prefix == X86Local::PD ||
|
|
|
|
Prefix == X86Local::T8PD || Prefix == X86Local::TAPD))
|
2009-12-19 02:59:52 +00:00
|
|
|
insnContext = IC_64BIT_REXW_OPSIZE;
|
2011-10-23 07:34:00 +00:00
|
|
|
else if (HasOpSizePrefix && (Prefix == X86Local::XD ||
|
|
|
|
Prefix == X86Local::T8XD ||
|
|
|
|
Prefix == X86Local::TAXD))
|
2011-10-01 19:54:56 +00:00
|
|
|
insnContext = IC_64BIT_XD_OPSIZE;
|
2011-10-16 16:50:08 +00:00
|
|
|
else if (HasOpSizePrefix &&
|
|
|
|
(Prefix == X86Local::XS || Prefix == X86Local::T8XS))
|
2011-10-11 04:34:23 +00:00
|
|
|
insnContext = IC_64BIT_XS_OPSIZE;
|
2014-01-14 07:41:20 +00:00
|
|
|
else if (HasOpSizePrefix || Prefix == X86Local::PD ||
|
|
|
|
Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
|
2009-12-19 02:59:52 +00:00
|
|
|
insnContext = IC_64BIT_OPSIZE;
|
2012-02-27 01:54:29 +00:00
|
|
|
else if (HasAdSizePrefix)
|
|
|
|
insnContext = IC_64BIT_ADSIZE;
|
2011-10-16 16:50:08 +00:00
|
|
|
else if (HasREX_WPrefix &&
|
|
|
|
(Prefix == X86Local::XS || Prefix == X86Local::T8XS))
|
2009-12-19 02:59:52 +00:00
|
|
|
insnContext = IC_64BIT_REXW_XS;
|
2011-10-23 07:34:00 +00:00
|
|
|
else if (HasREX_WPrefix && (Prefix == X86Local::XD ||
|
|
|
|
Prefix == X86Local::T8XD ||
|
|
|
|
Prefix == X86Local::TAXD))
|
2009-12-19 02:59:52 +00:00
|
|
|
insnContext = IC_64BIT_REXW_XD;
|
2011-10-23 07:34:00 +00:00
|
|
|
else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
|
|
|
|
Prefix == X86Local::TAXD)
|
2009-12-19 02:59:52 +00:00
|
|
|
insnContext = IC_64BIT_XD;
|
2011-10-16 16:50:08 +00:00
|
|
|
else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS)
|
2009-12-19 02:59:52 +00:00
|
|
|
insnContext = IC_64BIT_XS;
|
|
|
|
else if (HasREX_WPrefix)
|
|
|
|
insnContext = IC_64BIT_REXW;
|
|
|
|
else
|
|
|
|
insnContext = IC_64BIT;
|
|
|
|
} else {
|
2011-10-23 07:34:00 +00:00
|
|
|
if (HasOpSizePrefix && (Prefix == X86Local::XD ||
|
|
|
|
Prefix == X86Local::T8XD ||
|
|
|
|
Prefix == X86Local::TAXD))
|
2011-10-01 19:54:56 +00:00
|
|
|
insnContext = IC_XD_OPSIZE;
|
2011-10-16 16:50:08 +00:00
|
|
|
else if (HasOpSizePrefix &&
|
|
|
|
(Prefix == X86Local::XS || Prefix == X86Local::T8XS))
|
2011-10-11 04:34:23 +00:00
|
|
|
insnContext = IC_XS_OPSIZE;
|
2014-01-14 07:41:20 +00:00
|
|
|
else if (HasOpSizePrefix || Prefix == X86Local::PD ||
|
|
|
|
Prefix == X86Local::T8PD || Prefix == X86Local::TAPD)
|
2009-12-19 02:59:52 +00:00
|
|
|
insnContext = IC_OPSIZE;
|
2012-02-27 01:54:29 +00:00
|
|
|
else if (HasAdSizePrefix)
|
|
|
|
insnContext = IC_ADSIZE;
|
2011-10-23 07:34:00 +00:00
|
|
|
else if (Prefix == X86Local::XD || Prefix == X86Local::T8XD ||
|
|
|
|
Prefix == X86Local::TAXD)
|
2009-12-19 02:59:52 +00:00
|
|
|
insnContext = IC_XD;
|
2011-10-16 16:50:08 +00:00
|
|
|
else if (Prefix == X86Local::XS || Prefix == X86Local::T8XS ||
|
2014-01-31 07:00:55 +00:00
|
|
|
HasREPPrefix)
|
2009-12-19 02:59:52 +00:00
|
|
|
insnContext = IC_XS;
|
|
|
|
else
|
|
|
|
insnContext = IC;
|
|
|
|
}
|
|
|
|
|
|
|
|
return insnContext;
|
|
|
|
}
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
RecognizableInstr::filter_ret RecognizableInstr::filter() const {
|
2011-03-15 01:23:15 +00:00
|
|
|
///////////////////
|
|
|
|
// FILTER_STRONG
|
|
|
|
//
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
// Filter out intrinsics
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2012-07-30 05:39:34 +00:00
|
|
|
assert(Rec->isSubClassOf("X86Inst") && "Can only filter X86 instructions");
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2014-01-05 04:32:42 +00:00
|
|
|
if (Form == X86Local::Pseudo || (IsCodeGenOnly && !ForceDisassemble))
|
2009-12-19 02:59:52 +00:00
|
|
|
return FILTER_STRONG;
|
2012-07-30 04:48:12 +00:00
|
|
|
|
|
|
|
|
2012-03-09 17:52:49 +00:00
|
|
|
// Filter out artificial instructions but leave in the LOCK_PREFIX so it is
|
|
|
|
// printed as a separate "instruction".
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2011-03-15 01:23:15 +00:00
|
|
|
|
|
|
|
/////////////////
|
|
|
|
// FILTER_WEAK
|
|
|
|
//
|
|
|
|
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
// Filter out instructions with a LOCK prefix;
|
|
|
|
// prefer forms that do not have the prefix
|
|
|
|
if (HasLockPrefix)
|
|
|
|
return FILTER_WEAK;
|
|
|
|
|
|
|
|
// Special cases.
|
2010-09-07 18:10:56 +00:00
|
|
|
|
2014-01-05 06:55:48 +00:00
|
|
|
if (Name == "VMASKMOVDQU64")
|
2009-12-19 02:59:52 +00:00
|
|
|
return FILTER_WEAK;
|
|
|
|
|
2013-06-18 17:08:10 +00:00
|
|
|
// XACQUIRE and XRELEASE reuse REPNE and REP respectively.
|
|
|
|
// For now, just prefer the REP versions.
|
|
|
|
if (Name == "XACQUIRE_PREFIX" ||
|
|
|
|
Name == "XRELEASE_PREFIX")
|
|
|
|
return FILTER_WEAK;
|
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
return FILTER_NORMAL;
|
|
|
|
}
|
2011-03-15 01:23:15 +00:00
|
|
|
|
2012-07-12 06:52:41 +00:00
|
|
|
void RecognizableInstr::handleOperand(bool optional, unsigned &operandIndex,
|
|
|
|
unsigned &physicalOperandIndex,
|
|
|
|
unsigned &numPhysicalOperands,
|
|
|
|
const unsigned *operandMapping,
|
|
|
|
OperandEncoding (*encodingFromString)
|
|
|
|
(const std::string&,
|
|
|
|
bool hasOpSizePrefix)) {
|
2009-12-19 02:59:52 +00:00
|
|
|
if (optional) {
|
|
|
|
if (physicalOperandIndex >= numPhysicalOperands)
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
assert(physicalOperandIndex < numPhysicalOperands);
|
|
|
|
}
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
while (operandMapping[operandIndex] != operandIndex) {
|
|
|
|
Spec->operands[operandIndex].encoding = ENCODING_DUP;
|
|
|
|
Spec->operands[operandIndex].type =
|
|
|
|
(OperandType)(TYPE_DUP0 + operandMapping[operandIndex]);
|
|
|
|
++operandIndex;
|
|
|
|
}
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
const std::string &typeName = (*Operands)[operandIndex].Rec->getName();
|
2011-03-15 01:23:15 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
Spec->operands[operandIndex].encoding = encodingFromString(typeName,
|
|
|
|
HasOpSizePrefix);
|
2012-07-30 04:48:12 +00:00
|
|
|
Spec->operands[operandIndex].type = typeFromString(typeName,
|
2011-03-15 01:23:15 +00:00
|
|
|
HasREX_WPrefix,
|
2014-01-15 05:02:02 +00:00
|
|
|
HasOpSizePrefix,
|
|
|
|
HasOpSize16Prefix);
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
++operandIndex;
|
|
|
|
++physicalOperandIndex;
|
|
|
|
}
|
|
|
|
|
2014-01-02 03:58:45 +00:00
|
|
|
void RecognizableInstr::emitInstructionSpecifier() {
|
2009-12-19 02:59:52 +00:00
|
|
|
Spec->name = Name;
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2012-07-30 05:39:34 +00:00
|
|
|
if (!ShouldBeEmitted)
|
2009-12-19 02:59:52 +00:00
|
|
|
return;
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
switch (filter()) {
|
|
|
|
case FILTER_WEAK:
|
|
|
|
Spec->filtered = true;
|
|
|
|
break;
|
|
|
|
case FILTER_STRONG:
|
|
|
|
ShouldBeEmitted = false;
|
|
|
|
return;
|
|
|
|
case FILTER_NORMAL:
|
|
|
|
break;
|
|
|
|
}
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
Spec->insnContext = insnContext();
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2010-11-01 04:03:32 +00:00
|
|
|
const std::vector<CGIOperandList::OperandInfo> &OperandList = *Operands;
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
unsigned numOperands = OperandList.size();
|
|
|
|
unsigned numPhysicalOperands = 0;
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
// operandMapping maps from operands in OperandList to their originals.
|
|
|
|
// If operandMapping[i] != i, then the entry is a duplicate.
|
|
|
|
unsigned operandMapping[X86_MAX_OPERANDS];
|
2011-12-30 06:23:39 +00:00
|
|
|
assert(numOperands <= X86_MAX_OPERANDS && "X86_MAX_OPERANDS is not large enough");
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2012-07-12 06:52:41 +00:00
|
|
|
for (unsigned operandIndex = 0; operandIndex < numOperands; ++operandIndex) {
|
2009-12-19 02:59:52 +00:00
|
|
|
if (OperandList[operandIndex].Constraints.size()) {
|
2010-11-01 04:03:32 +00:00
|
|
|
const CGIOperandList::ConstraintInfo &Constraint =
|
2010-02-10 01:45:28 +00:00
|
|
|
OperandList[operandIndex].Constraints[0];
|
|
|
|
if (Constraint.isTied()) {
|
2012-07-12 06:52:41 +00:00
|
|
|
operandMapping[operandIndex] = operandIndex;
|
|
|
|
operandMapping[Constraint.getTiedOperand()] = operandIndex;
|
2009-12-19 02:59:52 +00:00
|
|
|
} else {
|
|
|
|
++numPhysicalOperands;
|
|
|
|
operandMapping[operandIndex] = operandIndex;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
++numPhysicalOperands;
|
|
|
|
operandMapping[operandIndex] = operandIndex;
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
#define HANDLE_OPERAND(class) \
|
|
|
|
handleOperand(false, \
|
|
|
|
operandIndex, \
|
|
|
|
physicalOperandIndex, \
|
|
|
|
numPhysicalOperands, \
|
|
|
|
operandMapping, \
|
|
|
|
class##EncodingFromString);
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
#define HANDLE_OPTIONAL(class) \
|
|
|
|
handleOperand(true, \
|
|
|
|
operandIndex, \
|
|
|
|
physicalOperandIndex, \
|
|
|
|
numPhysicalOperands, \
|
|
|
|
operandMapping, \
|
|
|
|
class##EncodingFromString);
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
// operandIndex should always be < numOperands
|
2012-07-12 06:52:41 +00:00
|
|
|
unsigned operandIndex = 0;
|
2009-12-19 02:59:52 +00:00
|
|
|
// physicalOperandIndex should always be < numPhysicalOperands
|
|
|
|
unsigned physicalOperandIndex = 0;
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
switch (Form) {
|
2014-01-16 07:36:58 +00:00
|
|
|
default: llvm_unreachable("Unhandled form");
|
2014-01-22 15:08:08 +00:00
|
|
|
case X86Local::RawFrmSrc:
|
|
|
|
HANDLE_OPERAND(relocation);
|
|
|
|
return;
|
2014-01-22 15:08:21 +00:00
|
|
|
case X86Local::RawFrmDst:
|
|
|
|
HANDLE_OPERAND(relocation);
|
|
|
|
return;
|
2014-01-22 15:08:36 +00:00
|
|
|
case X86Local::RawFrmDstSrc:
|
|
|
|
HANDLE_OPERAND(relocation);
|
|
|
|
HANDLE_OPERAND(relocation);
|
|
|
|
return;
|
2009-12-19 02:59:52 +00:00
|
|
|
case X86Local::RawFrm:
|
|
|
|
// Operand 1 (optional) is an address or immediate.
|
|
|
|
// Operand 2 (optional) is an immediate.
|
2012-07-30 04:48:12 +00:00
|
|
|
assert(numPhysicalOperands <= 2 &&
|
2009-12-19 02:59:52 +00:00
|
|
|
"Unexpected number of operands for RawFrm");
|
|
|
|
HANDLE_OPTIONAL(relocation)
|
|
|
|
HANDLE_OPTIONAL(immediate)
|
|
|
|
break;
|
2014-01-16 07:36:58 +00:00
|
|
|
case X86Local::RawFrmMemOffs:
|
|
|
|
// Operand 1 is an address.
|
|
|
|
HANDLE_OPERAND(relocation);
|
|
|
|
break;
|
2009-12-19 02:59:52 +00:00
|
|
|
case X86Local::AddRegFrm:
|
|
|
|
// Operand 1 is added to the opcode.
|
|
|
|
// Operand 2 (optional) is an address.
|
|
|
|
assert(numPhysicalOperands >= 1 && numPhysicalOperands <= 2 &&
|
|
|
|
"Unexpected number of operands for AddRegFrm");
|
|
|
|
HANDLE_OPERAND(opcodeModifier)
|
|
|
|
HANDLE_OPTIONAL(relocation)
|
|
|
|
break;
|
|
|
|
case X86Local::MRMDestReg:
|
|
|
|
// Operand 1 is a register operand in the R/M field.
|
|
|
|
// Operand 2 is a register operand in the Reg/Opcode field.
|
2011-08-30 07:09:35 +00:00
|
|
|
// - In AVX, there is a register operand in the VEX.vvvv field here -
|
2009-12-19 02:59:52 +00:00
|
|
|
// Operand 3 (optional) is an immediate.
|
2011-08-30 07:09:35 +00:00
|
|
|
if (HasVEX_4VPrefix)
|
|
|
|
assert(numPhysicalOperands >= 3 && numPhysicalOperands <= 4 &&
|
|
|
|
"Unexpected number of operands for MRMDestRegFrm with VEX_4V");
|
|
|
|
else
|
|
|
|
assert(numPhysicalOperands >= 2 && numPhysicalOperands <= 3 &&
|
|
|
|
"Unexpected number of operands for MRMDestRegFrm");
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
HANDLE_OPERAND(rmRegister)
|
2011-08-30 07:09:35 +00:00
|
|
|
|
|
|
|
if (HasVEX_4VPrefix)
|
|
|
|
// FIXME: In AVX, the register below becomes the one encoded
|
|
|
|
// in ModRMVEX and the one above the one in the VEX.VVVV field
|
|
|
|
HANDLE_OPERAND(vvvvRegister)
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
HANDLE_OPERAND(roRegister)
|
|
|
|
HANDLE_OPTIONAL(immediate)
|
|
|
|
break;
|
|
|
|
case X86Local::MRMDestMem:
|
|
|
|
// Operand 1 is a memory operand (possibly SIB-extended)
|
|
|
|
// Operand 2 is a register operand in the Reg/Opcode field.
|
2011-08-30 07:09:35 +00:00
|
|
|
// - In AVX, there is a register operand in the VEX.vvvv field here -
|
2009-12-19 02:59:52 +00:00
|
|
|
// Operand 3 (optional) is an immediate.
|
2011-08-30 07:09:35 +00:00
|
|
|
if (HasVEX_4VPrefix)
|
|
|
|
assert(numPhysicalOperands >= 3 && numPhysicalOperands <= 4 &&
|
|
|
|
"Unexpected number of operands for MRMDestMemFrm with VEX_4V");
|
|
|
|
else
|
|
|
|
assert(numPhysicalOperands >= 2 && numPhysicalOperands <= 3 &&
|
|
|
|
"Unexpected number of operands for MRMDestMemFrm");
|
2009-12-19 02:59:52 +00:00
|
|
|
HANDLE_OPERAND(memory)
|
2011-08-30 07:09:35 +00:00
|
|
|
|
2013-07-28 08:28:38 +00:00
|
|
|
if (HasEVEX_K)
|
|
|
|
HANDLE_OPERAND(writemaskRegister)
|
|
|
|
|
2011-08-30 07:09:35 +00:00
|
|
|
if (HasVEX_4VPrefix)
|
|
|
|
// FIXME: In AVX, the register below becomes the one encoded
|
|
|
|
// in ModRMVEX and the one above the one in the VEX.VVVV field
|
|
|
|
HANDLE_OPERAND(vvvvRegister)
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
HANDLE_OPERAND(roRegister)
|
|
|
|
HANDLE_OPTIONAL(immediate)
|
|
|
|
break;
|
|
|
|
case X86Local::MRMSrcReg:
|
|
|
|
// Operand 1 is a register operand in the Reg/Opcode field.
|
|
|
|
// Operand 2 is a register operand in the R/M field.
|
2011-03-15 01:23:15 +00:00
|
|
|
// - In AVX, there is a register operand in the VEX.vvvv field here -
|
2009-12-19 02:59:52 +00:00
|
|
|
// Operand 3 (optional) is an immediate.
|
2012-05-29 19:05:25 +00:00
|
|
|
// Operand 4 (optional) is an immediate.
|
2010-06-08 22:51:23 +00:00
|
|
|
|
2011-10-16 07:55:05 +00:00
|
|
|
if (HasVEX_4VPrefix || HasVEX_4VOp3Prefix)
|
2011-12-30 06:23:39 +00:00
|
|
|
assert(numPhysicalOperands >= 3 && numPhysicalOperands <= 5 &&
|
2012-07-30 04:48:12 +00:00
|
|
|
"Unexpected number of operands for MRMSrcRegFrm with VEX_4V");
|
2011-03-15 01:23:15 +00:00
|
|
|
else
|
2012-05-29 19:05:25 +00:00
|
|
|
assert(numPhysicalOperands >= 2 && numPhysicalOperands <= 4 &&
|
2011-03-15 01:23:15 +00:00
|
|
|
"Unexpected number of operands for MRMSrcRegFrm");
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2011-03-15 01:23:15 +00:00
|
|
|
HANDLE_OPERAND(roRegister)
|
2011-10-16 03:51:13 +00:00
|
|
|
|
2013-07-28 08:28:38 +00:00
|
|
|
if (HasEVEX_K)
|
|
|
|
HANDLE_OPERAND(writemaskRegister)
|
|
|
|
|
2011-10-16 07:55:05 +00:00
|
|
|
if (HasVEX_4VPrefix)
|
2010-06-11 23:50:47 +00:00
|
|
|
// FIXME: In AVX, the register below becomes the one encoded
|
|
|
|
// in ModRMVEX and the one above the one in the VEX.VVVV field
|
2011-03-15 01:23:15 +00:00
|
|
|
HANDLE_OPERAND(vvvvRegister)
|
2011-10-16 03:51:13 +00:00
|
|
|
|
2011-12-30 05:20:36 +00:00
|
|
|
if (HasMemOp4Prefix)
|
|
|
|
HANDLE_OPERAND(immediate)
|
|
|
|
|
2011-03-15 01:23:15 +00:00
|
|
|
HANDLE_OPERAND(rmRegister)
|
2011-10-16 03:51:13 +00:00
|
|
|
|
2011-10-16 07:55:05 +00:00
|
|
|
if (HasVEX_4VOp3Prefix)
|
2011-10-16 03:51:13 +00:00
|
|
|
HANDLE_OPERAND(vvvvRegister)
|
|
|
|
|
2011-12-30 06:23:39 +00:00
|
|
|
if (!HasMemOp4Prefix)
|
|
|
|
HANDLE_OPTIONAL(immediate)
|
|
|
|
HANDLE_OPTIONAL(immediate) // above might be a register in 7:4
|
2012-05-29 19:05:25 +00:00
|
|
|
HANDLE_OPTIONAL(immediate)
|
2009-12-19 02:59:52 +00:00
|
|
|
break;
|
|
|
|
case X86Local::MRMSrcMem:
|
|
|
|
// Operand 1 is a register operand in the Reg/Opcode field.
|
|
|
|
// Operand 2 is a memory operand (possibly SIB-extended)
|
2011-03-15 01:23:15 +00:00
|
|
|
// - In AVX, there is a register operand in the VEX.vvvv field here -
|
2009-12-19 02:59:52 +00:00
|
|
|
// Operand 3 (optional) is an immediate.
|
2011-10-16 07:55:05 +00:00
|
|
|
|
|
|
|
if (HasVEX_4VPrefix || HasVEX_4VOp3Prefix)
|
2011-12-30 06:23:39 +00:00
|
|
|
assert(numPhysicalOperands >= 3 && numPhysicalOperands <= 5 &&
|
2012-07-30 04:48:12 +00:00
|
|
|
"Unexpected number of operands for MRMSrcMemFrm with VEX_4V");
|
2011-03-15 01:23:15 +00:00
|
|
|
else
|
|
|
|
assert(numPhysicalOperands >= 2 && numPhysicalOperands <= 3 &&
|
|
|
|
"Unexpected number of operands for MRMSrcMemFrm");
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
HANDLE_OPERAND(roRegister)
|
2010-06-11 23:50:47 +00:00
|
|
|
|
2013-07-28 08:28:38 +00:00
|
|
|
if (HasEVEX_K)
|
|
|
|
HANDLE_OPERAND(writemaskRegister)
|
|
|
|
|
2011-10-16 07:55:05 +00:00
|
|
|
if (HasVEX_4VPrefix)
|
2010-06-11 23:50:47 +00:00
|
|
|
// FIXME: In AVX, the register below becomes the one encoded
|
|
|
|
// in ModRMVEX and the one above the one in the VEX.VVVV field
|
2011-03-15 01:23:15 +00:00
|
|
|
HANDLE_OPERAND(vvvvRegister)
|
2010-06-11 23:50:47 +00:00
|
|
|
|
2011-12-30 05:20:36 +00:00
|
|
|
if (HasMemOp4Prefix)
|
|
|
|
HANDLE_OPERAND(immediate)
|
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
HANDLE_OPERAND(memory)
|
2011-10-16 03:51:13 +00:00
|
|
|
|
2011-10-16 07:55:05 +00:00
|
|
|
if (HasVEX_4VOp3Prefix)
|
2011-10-16 03:51:13 +00:00
|
|
|
HANDLE_OPERAND(vvvvRegister)
|
|
|
|
|
2011-12-30 06:23:39 +00:00
|
|
|
if (!HasMemOp4Prefix)
|
|
|
|
HANDLE_OPTIONAL(immediate)
|
|
|
|
HANDLE_OPTIONAL(immediate) // above might be a register in 7:4
|
2009-12-19 02:59:52 +00:00
|
|
|
break;
|
|
|
|
case X86Local::MRM0r:
|
|
|
|
case X86Local::MRM1r:
|
|
|
|
case X86Local::MRM2r:
|
|
|
|
case X86Local::MRM3r:
|
|
|
|
case X86Local::MRM4r:
|
|
|
|
case X86Local::MRM5r:
|
|
|
|
case X86Local::MRM6r:
|
|
|
|
case X86Local::MRM7r:
|
2013-08-22 12:18:28 +00:00
|
|
|
{
|
|
|
|
// Operand 1 is a register operand in the R/M field.
|
|
|
|
// Operand 2 (optional) is an immediate or relocation.
|
|
|
|
// Operand 3 (optional) is an immediate.
|
|
|
|
unsigned kOp = (HasEVEX_K) ? 1:0;
|
|
|
|
unsigned Op4v = (HasVEX_4VPrefix) ? 1:0;
|
|
|
|
if (numPhysicalOperands > 3 + kOp + Op4v)
|
|
|
|
llvm_unreachable("Unexpected number of operands for MRMnr");
|
|
|
|
}
|
2011-03-15 01:23:15 +00:00
|
|
|
if (HasVEX_4VPrefix)
|
2011-10-15 20:46:47 +00:00
|
|
|
HANDLE_OPERAND(vvvvRegister)
|
2013-08-22 12:18:28 +00:00
|
|
|
|
|
|
|
if (HasEVEX_K)
|
|
|
|
HANDLE_OPERAND(writemaskRegister)
|
2009-12-19 02:59:52 +00:00
|
|
|
HANDLE_OPTIONAL(rmRegister)
|
|
|
|
HANDLE_OPTIONAL(relocation)
|
2012-05-29 19:05:25 +00:00
|
|
|
HANDLE_OPTIONAL(immediate)
|
2009-12-19 02:59:52 +00:00
|
|
|
break;
|
|
|
|
case X86Local::MRM0m:
|
|
|
|
case X86Local::MRM1m:
|
|
|
|
case X86Local::MRM2m:
|
|
|
|
case X86Local::MRM3m:
|
|
|
|
case X86Local::MRM4m:
|
|
|
|
case X86Local::MRM5m:
|
|
|
|
case X86Local::MRM6m:
|
|
|
|
case X86Local::MRM7m:
|
2013-08-22 12:18:28 +00:00
|
|
|
{
|
|
|
|
// Operand 1 is a memory operand (possibly SIB-extended)
|
|
|
|
// Operand 2 (optional) is an immediate or relocation.
|
|
|
|
unsigned kOp = (HasEVEX_K) ? 1:0;
|
|
|
|
unsigned Op4v = (HasVEX_4VPrefix) ? 1:0;
|
|
|
|
if (numPhysicalOperands < 1 + kOp + Op4v ||
|
|
|
|
numPhysicalOperands > 2 + kOp + Op4v)
|
|
|
|
llvm_unreachable("Unexpected number of operands for MRMnm");
|
|
|
|
}
|
2011-10-15 20:46:47 +00:00
|
|
|
if (HasVEX_4VPrefix)
|
|
|
|
HANDLE_OPERAND(vvvvRegister)
|
2013-08-22 12:18:28 +00:00
|
|
|
if (HasEVEX_K)
|
|
|
|
HANDLE_OPERAND(writemaskRegister)
|
2009-12-19 02:59:52 +00:00
|
|
|
HANDLE_OPERAND(memory)
|
|
|
|
HANDLE_OPTIONAL(relocation)
|
|
|
|
break;
|
2010-10-04 22:45:51 +00:00
|
|
|
case X86Local::RawFrmImm8:
|
|
|
|
// operand 1 is a 16-bit immediate
|
|
|
|
// operand 2 is an 8-bit immediate
|
|
|
|
assert(numPhysicalOperands == 2 &&
|
|
|
|
"Unexpected number of operands for X86Local::RawFrmImm8");
|
|
|
|
HANDLE_OPERAND(immediate)
|
|
|
|
HANDLE_OPERAND(immediate)
|
|
|
|
break;
|
|
|
|
case X86Local::RawFrmImm16:
|
|
|
|
// operand 1 is a 16-bit immediate
|
|
|
|
// operand 2 is a 16-bit immediate
|
|
|
|
HANDLE_OPERAND(immediate)
|
|
|
|
HANDLE_OPERAND(immediate)
|
|
|
|
break;
|
2013-03-11 21:17:13 +00:00
|
|
|
case X86Local::MRM_F8:
|
|
|
|
if (Opcode == 0xc6) {
|
|
|
|
assert(numPhysicalOperands == 1 &&
|
|
|
|
"Unexpected number of operands for X86Local::MRM_F8");
|
|
|
|
HANDLE_OPERAND(immediate)
|
|
|
|
} else if (Opcode == 0xc7) {
|
|
|
|
assert(numPhysicalOperands == 1 &&
|
|
|
|
"Unexpected number of operands for X86Local::MRM_F8");
|
|
|
|
HANDLE_OPERAND(relocation)
|
|
|
|
}
|
|
|
|
break;
|
2014-01-16 07:36:58 +00:00
|
|
|
case X86Local::MRM_C1:
|
|
|
|
case X86Local::MRM_C2:
|
|
|
|
case X86Local::MRM_C3:
|
|
|
|
case X86Local::MRM_C4:
|
|
|
|
case X86Local::MRM_C8:
|
|
|
|
case X86Local::MRM_C9:
|
|
|
|
case X86Local::MRM_CA:
|
|
|
|
case X86Local::MRM_CB:
|
|
|
|
case X86Local::MRM_E8:
|
|
|
|
case X86Local::MRM_F0:
|
|
|
|
case X86Local::MRM_F9:
|
|
|
|
case X86Local::MRM_D0:
|
|
|
|
case X86Local::MRM_D1:
|
|
|
|
case X86Local::MRM_D4:
|
|
|
|
case X86Local::MRM_D5:
|
|
|
|
case X86Local::MRM_D6:
|
|
|
|
case X86Local::MRM_D8:
|
|
|
|
case X86Local::MRM_D9:
|
|
|
|
case X86Local::MRM_DA:
|
|
|
|
case X86Local::MRM_DB:
|
|
|
|
case X86Local::MRM_DC:
|
|
|
|
case X86Local::MRM_DD:
|
|
|
|
case X86Local::MRM_DE:
|
|
|
|
case X86Local::MRM_DF:
|
2009-12-19 02:59:52 +00:00
|
|
|
// Ignored.
|
|
|
|
break;
|
|
|
|
}
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
#undef HANDLE_OPERAND
|
|
|
|
#undef HANDLE_OPTIONAL
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecognizableInstr::emitDecodePath(DisassemblerTables &tables) const {
|
|
|
|
// Special cases where the LLVM tables are not complete
|
|
|
|
|
2010-02-12 23:39:46 +00:00
|
|
|
#define MAP(from, to) \
|
|
|
|
case X86Local::MRM_##from: \
|
|
|
|
filter = new ExactFilter(0x##from); \
|
|
|
|
break;
|
2009-12-19 02:59:52 +00:00
|
|
|
|
|
|
|
OpcodeType opcodeType = (OpcodeType)-1;
|
2012-07-30 04:48:12 +00:00
|
|
|
|
|
|
|
ModRMFilter* filter = NULL;
|
2009-12-19 02:59:52 +00:00
|
|
|
uint8_t opcodeToSet = 0;
|
|
|
|
|
|
|
|
switch (Prefix) {
|
2013-10-03 05:17:48 +00:00
|
|
|
default: llvm_unreachable("Invalid prefix!");
|
2014-01-14 07:41:20 +00:00
|
|
|
// Extended two-byte opcodes can start with 66 0f, f2 0f, f3 0f, or 0f
|
|
|
|
case X86Local::PD:
|
2009-12-19 02:59:52 +00:00
|
|
|
case X86Local::XD:
|
|
|
|
case X86Local::XS:
|
|
|
|
case X86Local::TB:
|
|
|
|
opcodeType = TWOBYTE;
|
|
|
|
|
|
|
|
switch (Opcode) {
|
2010-02-13 01:48:34 +00:00
|
|
|
default:
|
|
|
|
if (needsModRMForDecode(Form))
|
|
|
|
filter = new ModFilter(isRegFormat(Form));
|
|
|
|
else
|
|
|
|
filter = new DumbFilter();
|
|
|
|
break;
|
2009-12-19 02:59:52 +00:00
|
|
|
#define EXTENSION_TABLE(n) case 0x##n:
|
|
|
|
TWO_BYTE_EXTENSION_TABLES
|
|
|
|
#undef EXTENSION_TABLE
|
|
|
|
switch (Form) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unhandled two-byte extended opcode");
|
|
|
|
case X86Local::MRM0r:
|
|
|
|
case X86Local::MRM1r:
|
|
|
|
case X86Local::MRM2r:
|
|
|
|
case X86Local::MRM3r:
|
|
|
|
case X86Local::MRM4r:
|
|
|
|
case X86Local::MRM5r:
|
|
|
|
case X86Local::MRM6r:
|
|
|
|
case X86Local::MRM7r:
|
|
|
|
filter = new ExtendedFilter(true, Form - X86Local::MRM0r);
|
|
|
|
break;
|
|
|
|
case X86Local::MRM0m:
|
|
|
|
case X86Local::MRM1m:
|
|
|
|
case X86Local::MRM2m:
|
|
|
|
case X86Local::MRM3m:
|
|
|
|
case X86Local::MRM4m:
|
|
|
|
case X86Local::MRM5m:
|
|
|
|
case X86Local::MRM6m:
|
|
|
|
case X86Local::MRM7m:
|
|
|
|
filter = new ExtendedFilter(false, Form - X86Local::MRM0m);
|
|
|
|
break;
|
2010-02-12 23:39:46 +00:00
|
|
|
MRM_MAPPING
|
2009-12-19 02:59:52 +00:00
|
|
|
} // switch (Form)
|
|
|
|
break;
|
2010-02-13 01:48:34 +00:00
|
|
|
} // switch (Opcode)
|
2009-12-19 02:59:52 +00:00
|
|
|
opcodeToSet = Opcode;
|
|
|
|
break;
|
|
|
|
case X86Local::T8:
|
2014-01-14 07:41:20 +00:00
|
|
|
case X86Local::T8PD:
|
2011-10-16 16:50:08 +00:00
|
|
|
case X86Local::T8XD:
|
|
|
|
case X86Local::T8XS:
|
2009-12-19 02:59:52 +00:00
|
|
|
opcodeType = THREEBYTE_38;
|
2011-10-15 20:46:47 +00:00
|
|
|
switch (Opcode) {
|
|
|
|
default:
|
|
|
|
if (needsModRMForDecode(Form))
|
|
|
|
filter = new ModFilter(isRegFormat(Form));
|
|
|
|
else
|
|
|
|
filter = new DumbFilter();
|
|
|
|
break;
|
|
|
|
#define EXTENSION_TABLE(n) case 0x##n:
|
|
|
|
THREE_BYTE_38_EXTENSION_TABLES
|
|
|
|
#undef EXTENSION_TABLE
|
|
|
|
switch (Form) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unhandled two-byte extended opcode");
|
|
|
|
case X86Local::MRM0r:
|
|
|
|
case X86Local::MRM1r:
|
|
|
|
case X86Local::MRM2r:
|
|
|
|
case X86Local::MRM3r:
|
|
|
|
case X86Local::MRM4r:
|
|
|
|
case X86Local::MRM5r:
|
|
|
|
case X86Local::MRM6r:
|
|
|
|
case X86Local::MRM7r:
|
|
|
|
filter = new ExtendedFilter(true, Form - X86Local::MRM0r);
|
|
|
|
break;
|
|
|
|
case X86Local::MRM0m:
|
|
|
|
case X86Local::MRM1m:
|
|
|
|
case X86Local::MRM2m:
|
|
|
|
case X86Local::MRM3m:
|
|
|
|
case X86Local::MRM4m:
|
|
|
|
case X86Local::MRM5m:
|
|
|
|
case X86Local::MRM6m:
|
|
|
|
case X86Local::MRM7m:
|
|
|
|
filter = new ExtendedFilter(false, Form - X86Local::MRM0m);
|
|
|
|
break;
|
|
|
|
MRM_MAPPING
|
|
|
|
} // switch (Form)
|
|
|
|
break;
|
|
|
|
} // switch (Opcode)
|
2009-12-19 02:59:52 +00:00
|
|
|
opcodeToSet = Opcode;
|
|
|
|
break;
|
2010-02-12 02:06:33 +00:00
|
|
|
case X86Local::P_TA:
|
2014-01-14 07:41:20 +00:00
|
|
|
case X86Local::TAPD:
|
2011-10-23 07:34:00 +00:00
|
|
|
case X86Local::TAXD:
|
2009-12-19 02:59:52 +00:00
|
|
|
opcodeType = THREEBYTE_3A;
|
|
|
|
if (needsModRMForDecode(Form))
|
|
|
|
filter = new ModFilter(isRegFormat(Form));
|
|
|
|
else
|
|
|
|
filter = new DumbFilter();
|
|
|
|
opcodeToSet = Opcode;
|
|
|
|
break;
|
2011-04-04 16:58:13 +00:00
|
|
|
case X86Local::A6:
|
|
|
|
opcodeType = THREEBYTE_A6;
|
|
|
|
if (needsModRMForDecode(Form))
|
|
|
|
filter = new ModFilter(isRegFormat(Form));
|
|
|
|
else
|
|
|
|
filter = new DumbFilter();
|
|
|
|
opcodeToSet = Opcode;
|
|
|
|
break;
|
|
|
|
case X86Local::A7:
|
|
|
|
opcodeType = THREEBYTE_A7;
|
|
|
|
if (needsModRMForDecode(Form))
|
|
|
|
filter = new ModFilter(isRegFormat(Form));
|
|
|
|
else
|
|
|
|
filter = new DumbFilter();
|
|
|
|
opcodeToSet = Opcode;
|
|
|
|
break;
|
2013-10-03 05:17:48 +00:00
|
|
|
case X86Local::XOP8:
|
|
|
|
opcodeType = XOP8_MAP;
|
|
|
|
if (needsModRMForDecode(Form))
|
|
|
|
filter = new ModFilter(isRegFormat(Form));
|
|
|
|
else
|
|
|
|
filter = new DumbFilter();
|
|
|
|
opcodeToSet = Opcode;
|
|
|
|
break;
|
|
|
|
case X86Local::XOP9:
|
|
|
|
opcodeType = XOP9_MAP;
|
|
|
|
switch (Opcode) {
|
|
|
|
default:
|
|
|
|
if (needsModRMForDecode(Form))
|
|
|
|
filter = new ModFilter(isRegFormat(Form));
|
|
|
|
else
|
|
|
|
filter = new DumbFilter();
|
|
|
|
break;
|
|
|
|
#define EXTENSION_TABLE(n) case 0x##n:
|
|
|
|
XOP9_MAP_EXTENSION_TABLES
|
|
|
|
#undef EXTENSION_TABLE
|
|
|
|
switch (Form) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unhandled XOP9 extended opcode");
|
|
|
|
case X86Local::MRM0r:
|
|
|
|
case X86Local::MRM1r:
|
|
|
|
case X86Local::MRM2r:
|
|
|
|
case X86Local::MRM3r:
|
|
|
|
case X86Local::MRM4r:
|
|
|
|
case X86Local::MRM5r:
|
|
|
|
case X86Local::MRM6r:
|
|
|
|
case X86Local::MRM7r:
|
|
|
|
filter = new ExtendedFilter(true, Form - X86Local::MRM0r);
|
|
|
|
break;
|
|
|
|
case X86Local::MRM0m:
|
|
|
|
case X86Local::MRM1m:
|
|
|
|
case X86Local::MRM2m:
|
|
|
|
case X86Local::MRM3m:
|
|
|
|
case X86Local::MRM4m:
|
|
|
|
case X86Local::MRM5m:
|
|
|
|
case X86Local::MRM6m:
|
|
|
|
case X86Local::MRM7m:
|
|
|
|
filter = new ExtendedFilter(false, Form - X86Local::MRM0m);
|
|
|
|
break;
|
|
|
|
MRM_MAPPING
|
|
|
|
} // switch (Form)
|
|
|
|
break;
|
|
|
|
} // switch (Opcode)
|
|
|
|
opcodeToSet = Opcode;
|
|
|
|
break;
|
|
|
|
case X86Local::XOPA:
|
|
|
|
opcodeType = XOPA_MAP;
|
|
|
|
if (needsModRMForDecode(Form))
|
|
|
|
filter = new ModFilter(isRegFormat(Form));
|
|
|
|
else
|
|
|
|
filter = new DumbFilter();
|
|
|
|
opcodeToSet = Opcode;
|
|
|
|
break;
|
2009-12-19 02:59:52 +00:00
|
|
|
case X86Local::D8:
|
|
|
|
case X86Local::D9:
|
|
|
|
case X86Local::DA:
|
|
|
|
case X86Local::DB:
|
|
|
|
case X86Local::DC:
|
|
|
|
case X86Local::DD:
|
|
|
|
case X86Local::DE:
|
|
|
|
case X86Local::DF:
|
|
|
|
assert(Opcode >= 0xc0 && "Unexpected opcode for an escape opcode");
|
2014-01-01 14:22:37 +00:00
|
|
|
assert(Form == X86Local::RawFrm);
|
2009-12-19 02:59:52 +00:00
|
|
|
opcodeType = ONEBYTE;
|
2014-01-01 14:22:37 +00:00
|
|
|
filter = new ExactFilter(Opcode);
|
2009-12-19 02:59:52 +00:00
|
|
|
opcodeToSet = 0xd8 + (Prefix - X86Local::D8);
|
|
|
|
break;
|
2013-10-03 05:17:48 +00:00
|
|
|
case 0:
|
2009-12-19 02:59:52 +00:00
|
|
|
opcodeType = ONEBYTE;
|
|
|
|
switch (Opcode) {
|
|
|
|
#define EXTENSION_TABLE(n) case 0x##n:
|
|
|
|
ONE_BYTE_EXTENSION_TABLES
|
|
|
|
#undef EXTENSION_TABLE
|
|
|
|
switch (Form) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Fell through the cracks of a single-byte "
|
|
|
|
"extended opcode");
|
|
|
|
case X86Local::MRM0r:
|
|
|
|
case X86Local::MRM1r:
|
|
|
|
case X86Local::MRM2r:
|
|
|
|
case X86Local::MRM3r:
|
|
|
|
case X86Local::MRM4r:
|
|
|
|
case X86Local::MRM5r:
|
|
|
|
case X86Local::MRM6r:
|
|
|
|
case X86Local::MRM7r:
|
|
|
|
filter = new ExtendedFilter(true, Form - X86Local::MRM0r);
|
|
|
|
break;
|
|
|
|
case X86Local::MRM0m:
|
|
|
|
case X86Local::MRM1m:
|
|
|
|
case X86Local::MRM2m:
|
|
|
|
case X86Local::MRM3m:
|
|
|
|
case X86Local::MRM4m:
|
|
|
|
case X86Local::MRM5m:
|
|
|
|
case X86Local::MRM6m:
|
|
|
|
case X86Local::MRM7m:
|
|
|
|
filter = new ExtendedFilter(false, Form - X86Local::MRM0m);
|
|
|
|
break;
|
2010-02-12 23:39:46 +00:00
|
|
|
MRM_MAPPING
|
2009-12-19 02:59:52 +00:00
|
|
|
} // switch (Form)
|
|
|
|
break;
|
|
|
|
case 0xd8:
|
|
|
|
case 0xd9:
|
|
|
|
case 0xda:
|
|
|
|
case 0xdb:
|
|
|
|
case 0xdc:
|
|
|
|
case 0xdd:
|
|
|
|
case 0xde:
|
|
|
|
case 0xdf:
|
2013-12-30 17:37:10 +00:00
|
|
|
switch (Form) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unhandled escape opcode form");
|
2014-01-01 14:22:37 +00:00
|
|
|
case X86Local::MRM0r:
|
|
|
|
case X86Local::MRM1r:
|
|
|
|
case X86Local::MRM2r:
|
|
|
|
case X86Local::MRM3r:
|
|
|
|
case X86Local::MRM4r:
|
|
|
|
case X86Local::MRM5r:
|
|
|
|
case X86Local::MRM6r:
|
|
|
|
case X86Local::MRM7r:
|
|
|
|
filter = new ExtendedFilter(true, Form - X86Local::MRM0r);
|
|
|
|
break;
|
2013-12-30 17:37:10 +00:00
|
|
|
case X86Local::MRM0m:
|
|
|
|
case X86Local::MRM1m:
|
|
|
|
case X86Local::MRM2m:
|
|
|
|
case X86Local::MRM3m:
|
|
|
|
case X86Local::MRM4m:
|
|
|
|
case X86Local::MRM5m:
|
|
|
|
case X86Local::MRM6m:
|
|
|
|
case X86Local::MRM7m:
|
|
|
|
filter = new ExtendedFilter(false, Form - X86Local::MRM0m);
|
|
|
|
break;
|
|
|
|
} // switch (Form)
|
2009-12-19 02:59:52 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (needsModRMForDecode(Form))
|
|
|
|
filter = new ModFilter(isRegFormat(Form));
|
|
|
|
else
|
|
|
|
filter = new DumbFilter();
|
|
|
|
break;
|
|
|
|
} // switch (Opcode)
|
|
|
|
opcodeToSet = Opcode;
|
|
|
|
} // switch (Prefix)
|
|
|
|
|
|
|
|
assert(opcodeType != (OpcodeType)-1 &&
|
|
|
|
"Opcode type not set");
|
|
|
|
assert(filter && "Filter not set");
|
|
|
|
|
|
|
|
if (Form == X86Local::AddRegFrm) {
|
2014-01-01 15:29:32 +00:00
|
|
|
assert(((opcodeToSet & 7) == 0) &&
|
|
|
|
"ADDREG_FRM opcode not aligned");
|
2014-01-01 14:22:37 +00:00
|
|
|
|
|
|
|
uint8_t currentOpcode;
|
|
|
|
|
|
|
|
for (currentOpcode = opcodeToSet;
|
|
|
|
currentOpcode < opcodeToSet + 8;
|
|
|
|
++currentOpcode)
|
2012-07-30 04:48:12 +00:00
|
|
|
tables.setTableFields(opcodeType,
|
|
|
|
insnContext(),
|
2014-01-01 14:22:37 +00:00
|
|
|
currentOpcode,
|
2012-07-30 04:48:12 +00:00
|
|
|
*filter,
|
2011-10-04 06:30:42 +00:00
|
|
|
UID, Is32Bit, IgnoresVEX_L);
|
2009-12-19 02:59:52 +00:00
|
|
|
} else {
|
|
|
|
tables.setTableFields(opcodeType,
|
|
|
|
insnContext(),
|
|
|
|
opcodeToSet,
|
|
|
|
*filter,
|
2011-10-04 06:30:42 +00:00
|
|
|
UID, Is32Bit, IgnoresVEX_L);
|
2009-12-19 02:59:52 +00:00
|
|
|
}
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
delete filter;
|
2012-07-30 04:48:12 +00:00
|
|
|
|
2010-02-12 23:39:46 +00:00
|
|
|
#undef MAP
|
2009-12-19 02:59:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define TYPE(str, type) if (s == str) return type;
|
|
|
|
OperandType RecognizableInstr::typeFromString(const std::string &s,
|
|
|
|
bool hasREX_WPrefix,
|
2014-01-15 05:02:02 +00:00
|
|
|
bool hasOpSizePrefix,
|
|
|
|
bool hasOpSize16Prefix) {
|
2009-12-19 02:59:52 +00:00
|
|
|
if(hasREX_WPrefix) {
|
|
|
|
// For instructions with a REX_W prefix, a declared 32-bit register encoding
|
|
|
|
// is special.
|
|
|
|
TYPE("GR32", TYPE_R32)
|
|
|
|
}
|
2014-01-15 05:02:02 +00:00
|
|
|
if(hasOpSizePrefix) {
|
|
|
|
// For instructions with an OpSize prefix, a declared 16-bit register or
|
|
|
|
// immediate encoding is special.
|
|
|
|
TYPE("GR16", TYPE_Rv)
|
|
|
|
TYPE("i16imm", TYPE_IMMv)
|
|
|
|
}
|
|
|
|
if(hasOpSize16Prefix) {
|
|
|
|
// For instructions with an OpSize16 prefix, a declared 32-bit register or
|
2009-12-19 02:59:52 +00:00
|
|
|
// immediate encoding is special.
|
2014-01-15 05:02:02 +00:00
|
|
|
TYPE("GR32", TYPE_Rv)
|
2009-12-19 02:59:52 +00:00
|
|
|
}
|
|
|
|
TYPE("i16mem", TYPE_Mv)
|
2014-01-15 05:02:02 +00:00
|
|
|
TYPE("i16imm", TYPE_IMM16)
|
2009-12-19 02:59:52 +00:00
|
|
|
TYPE("i16i8imm", TYPE_IMMv)
|
2014-01-15 05:02:02 +00:00
|
|
|
TYPE("GR16", TYPE_R16)
|
2009-12-19 02:59:52 +00:00
|
|
|
TYPE("i32mem", TYPE_Mv)
|
|
|
|
TYPE("i32imm", TYPE_IMMv)
|
|
|
|
TYPE("i32i8imm", TYPE_IMM32)
|
2011-07-27 23:01:50 +00:00
|
|
|
TYPE("u32u8imm", TYPE_IMM32)
|
2014-01-15 05:02:02 +00:00
|
|
|
TYPE("GR32", TYPE_R32)
|
2013-10-14 04:55:01 +00:00
|
|
|
TYPE("GR32orGR64", TYPE_R32)
|
2009-12-19 02:59:52 +00:00
|
|
|
TYPE("i64mem", TYPE_Mv)
|
|
|
|
TYPE("i64i32imm", TYPE_IMM64)
|
|
|
|
TYPE("i64i8imm", TYPE_IMM64)
|
|
|
|
TYPE("GR64", TYPE_R64)
|
|
|
|
TYPE("i8mem", TYPE_M8)
|
|
|
|
TYPE("i8imm", TYPE_IMM8)
|
|
|
|
TYPE("GR8", TYPE_R8)
|
|
|
|
TYPE("VR128", TYPE_XMM128)
|
2013-07-28 08:28:38 +00:00
|
|
|
TYPE("VR128X", TYPE_XMM128)
|
2009-12-19 02:59:52 +00:00
|
|
|
TYPE("f128mem", TYPE_M128)
|
2010-09-29 02:57:56 +00:00
|
|
|
TYPE("f256mem", TYPE_M256)
|
2013-07-28 08:28:38 +00:00
|
|
|
TYPE("f512mem", TYPE_M512)
|
2009-12-19 02:59:52 +00:00
|
|
|
TYPE("FR64", TYPE_XMM64)
|
2013-07-28 08:28:38 +00:00
|
|
|
TYPE("FR64X", TYPE_XMM64)
|
2009-12-19 02:59:52 +00:00
|
|
|
TYPE("f64mem", TYPE_M64FP)
|
2010-09-29 02:57:56 +00:00
|
|
|
TYPE("sdmem", TYPE_M64FP)
|
2009-12-19 02:59:52 +00:00
|
|
|
TYPE("FR32", TYPE_XMM32)
|
2013-07-28 08:28:38 +00:00
|
|
|
TYPE("FR32X", TYPE_XMM32)
|
2009-12-19 02:59:52 +00:00
|
|
|
TYPE("f32mem", TYPE_M32FP)
|
2010-09-29 02:57:56 +00:00
|
|
|
TYPE("ssmem", TYPE_M32FP)
|
2009-12-19 02:59:52 +00:00
|
|
|
TYPE("RST", TYPE_ST)
|
|
|
|
TYPE("i128mem", TYPE_M128)
|
2011-03-15 01:23:15 +00:00
|
|
|
TYPE("i256mem", TYPE_M256)
|
2013-07-28 08:28:38 +00:00
|
|
|
TYPE("i512mem", TYPE_M512)
|
2009-12-19 02:59:52 +00:00
|
|
|
TYPE("i64i32imm_pcrel", TYPE_REL64)
|
2010-07-07 22:27:31 +00:00
|
|
|
TYPE("i16imm_pcrel", TYPE_REL16)
|
2009-12-19 02:59:52 +00:00
|
|
|
TYPE("i32imm_pcrel", TYPE_REL32)
|
2010-04-07 21:42:19 +00:00
|
|
|
TYPE("SSECC", TYPE_IMM3)
|
2012-04-03 05:20:24 +00:00
|
|
|
TYPE("AVXCC", TYPE_IMM5)
|
2014-01-01 15:12:34 +00:00
|
|
|
TYPE("AVX512RC", TYPE_IMM32)
|
2009-12-19 02:59:52 +00:00
|
|
|
TYPE("brtarget", TYPE_RELv)
|
2010-12-13 19:31:11 +00:00
|
|
|
TYPE("uncondbrtarget", TYPE_RELv)
|
2009-12-19 02:59:52 +00:00
|
|
|
TYPE("brtarget8", TYPE_REL8)
|
|
|
|
TYPE("f80mem", TYPE_M80FP)
|
2009-12-22 21:12:55 +00:00
|
|
|
TYPE("lea32mem", TYPE_LEA)
|
|
|
|
TYPE("lea64_32mem", TYPE_LEA)
|
|
|
|
TYPE("lea64mem", TYPE_LEA)
|
2009-12-19 02:59:52 +00:00
|
|
|
TYPE("VR64", TYPE_MM64)
|
|
|
|
TYPE("i64imm", TYPE_IMMv)
|
|
|
|
TYPE("opaque32mem", TYPE_M1616)
|
|
|
|
TYPE("opaque48mem", TYPE_M1632)
|
|
|
|
TYPE("opaque80mem", TYPE_M1664)
|
|
|
|
TYPE("opaque512mem", TYPE_M512)
|
|
|
|
TYPE("SEGMENT_REG", TYPE_SEGMENTREG)
|
|
|
|
TYPE("DEBUG_REG", TYPE_DEBUGREG)
|
2010-05-06 20:59:00 +00:00
|
|
|
TYPE("CONTROL_REG", TYPE_CONTROLREG)
|
2014-01-22 15:08:08 +00:00
|
|
|
TYPE("srcidx8", TYPE_SRCIDX8)
|
|
|
|
TYPE("srcidx16", TYPE_SRCIDX16)
|
|
|
|
TYPE("srcidx32", TYPE_SRCIDX32)
|
|
|
|
TYPE("srcidx64", TYPE_SRCIDX64)
|
2014-01-22 15:08:21 +00:00
|
|
|
TYPE("dstidx8", TYPE_DSTIDX8)
|
|
|
|
TYPE("dstidx16", TYPE_DSTIDX16)
|
|
|
|
TYPE("dstidx32", TYPE_DSTIDX32)
|
|
|
|
TYPE("dstidx64", TYPE_DSTIDX64)
|
2009-12-19 02:59:52 +00:00
|
|
|
TYPE("offset8", TYPE_MOFFS8)
|
|
|
|
TYPE("offset16", TYPE_MOFFS16)
|
|
|
|
TYPE("offset32", TYPE_MOFFS32)
|
|
|
|
TYPE("offset64", TYPE_MOFFS64)
|
2011-03-15 01:23:15 +00:00
|
|
|
TYPE("VR256", TYPE_XMM256)
|
2013-07-28 08:28:38 +00:00
|
|
|
TYPE("VR256X", TYPE_XMM256)
|
|
|
|
TYPE("VR512", TYPE_XMM512)
|
2013-12-16 13:52:35 +00:00
|
|
|
TYPE("VK1", TYPE_VK1)
|
|
|
|
TYPE("VK1WM", TYPE_VK1)
|
2013-07-28 08:28:38 +00:00
|
|
|
TYPE("VK8", TYPE_VK8)
|
|
|
|
TYPE("VK8WM", TYPE_VK8)
|
|
|
|
TYPE("VK16", TYPE_VK16)
|
|
|
|
TYPE("VK16WM", TYPE_VK16)
|
2011-10-06 06:44:41 +00:00
|
|
|
TYPE("GR16_NOAX", TYPE_Rv)
|
|
|
|
TYPE("GR32_NOAX", TYPE_Rv)
|
|
|
|
TYPE("GR64_NOAX", TYPE_R64)
|
2012-07-18 04:11:12 +00:00
|
|
|
TYPE("vx32mem", TYPE_M32)
|
|
|
|
TYPE("vy32mem", TYPE_M32)
|
2013-07-28 08:28:38 +00:00
|
|
|
TYPE("vz32mem", TYPE_M32)
|
2012-07-18 04:11:12 +00:00
|
|
|
TYPE("vx64mem", TYPE_M64)
|
|
|
|
TYPE("vy64mem", TYPE_M64)
|
2013-07-28 08:28:38 +00:00
|
|
|
TYPE("vy64xmem", TYPE_M64)
|
|
|
|
TYPE("vz64mem", TYPE_M64)
|
2009-12-19 02:59:52 +00:00
|
|
|
errs() << "Unhandled type string " << s << "\n";
|
|
|
|
llvm_unreachable("Unhandled type string");
|
|
|
|
}
|
|
|
|
#undef TYPE
|
|
|
|
|
|
|
|
#define ENCODING(str, encoding) if (s == str) return encoding;
|
|
|
|
OperandEncoding RecognizableInstr::immediateEncodingFromString
|
|
|
|
(const std::string &s,
|
|
|
|
bool hasOpSizePrefix) {
|
|
|
|
if(!hasOpSizePrefix) {
|
|
|
|
// For instructions without an OpSize prefix, a declared 16-bit register or
|
|
|
|
// immediate encoding is special.
|
|
|
|
ENCODING("i16imm", ENCODING_IW)
|
|
|
|
}
|
|
|
|
ENCODING("i32i8imm", ENCODING_IB)
|
2011-07-27 23:01:50 +00:00
|
|
|
ENCODING("u32u8imm", ENCODING_IB)
|
2009-12-19 02:59:52 +00:00
|
|
|
ENCODING("SSECC", ENCODING_IB)
|
2012-04-03 05:20:24 +00:00
|
|
|
ENCODING("AVXCC", ENCODING_IB)
|
2014-01-01 15:12:34 +00:00
|
|
|
ENCODING("AVX512RC", ENCODING_IB)
|
2009-12-19 02:59:52 +00:00
|
|
|
ENCODING("i16imm", ENCODING_Iv)
|
|
|
|
ENCODING("i16i8imm", ENCODING_IB)
|
|
|
|
ENCODING("i32imm", ENCODING_Iv)
|
|
|
|
ENCODING("i64i32imm", ENCODING_ID)
|
|
|
|
ENCODING("i64i8imm", ENCODING_IB)
|
|
|
|
ENCODING("i8imm", ENCODING_IB)
|
2011-03-15 01:23:15 +00:00
|
|
|
// This is not a typo. Instructions like BLENDVPD put
|
|
|
|
// register IDs in 8-bit immediates nowadays.
|
2012-08-31 15:40:30 +00:00
|
|
|
ENCODING("FR32", ENCODING_IB)
|
|
|
|
ENCODING("FR64", ENCODING_IB)
|
2013-07-28 08:28:38 +00:00
|
|
|
ENCODING("VR128", ENCODING_IB)
|
|
|
|
ENCODING("VR256", ENCODING_IB)
|
|
|
|
ENCODING("FR32X", ENCODING_IB)
|
|
|
|
ENCODING("FR64X", ENCODING_IB)
|
|
|
|
ENCODING("VR128X", ENCODING_IB)
|
|
|
|
ENCODING("VR256X", ENCODING_IB)
|
|
|
|
ENCODING("VR512", ENCODING_IB)
|
2009-12-19 02:59:52 +00:00
|
|
|
errs() << "Unhandled immediate encoding " << s << "\n";
|
|
|
|
llvm_unreachable("Unhandled immediate encoding");
|
|
|
|
}
|
|
|
|
|
|
|
|
OperandEncoding RecognizableInstr::rmRegisterEncodingFromString
|
|
|
|
(const std::string &s,
|
|
|
|
bool hasOpSizePrefix) {
|
2014-01-01 14:22:37 +00:00
|
|
|
ENCODING("RST", ENCODING_FP)
|
2009-12-19 02:59:52 +00:00
|
|
|
ENCODING("GR16", ENCODING_RM)
|
|
|
|
ENCODING("GR32", ENCODING_RM)
|
2013-10-14 04:55:01 +00:00
|
|
|
ENCODING("GR32orGR64", ENCODING_RM)
|
2009-12-19 02:59:52 +00:00
|
|
|
ENCODING("GR64", ENCODING_RM)
|
|
|
|
ENCODING("GR8", ENCODING_RM)
|
|
|
|
ENCODING("VR128", ENCODING_RM)
|
2013-07-28 08:28:38 +00:00
|
|
|
ENCODING("VR128X", ENCODING_RM)
|
2009-12-19 02:59:52 +00:00
|
|
|
ENCODING("FR64", ENCODING_RM)
|
|
|
|
ENCODING("FR32", ENCODING_RM)
|
2013-07-28 08:28:38 +00:00
|
|
|
ENCODING("FR64X", ENCODING_RM)
|
|
|
|
ENCODING("FR32X", ENCODING_RM)
|
2009-12-19 02:59:52 +00:00
|
|
|
ENCODING("VR64", ENCODING_RM)
|
2011-03-15 01:23:15 +00:00
|
|
|
ENCODING("VR256", ENCODING_RM)
|
2013-07-28 08:28:38 +00:00
|
|
|
ENCODING("VR256X", ENCODING_RM)
|
|
|
|
ENCODING("VR512", ENCODING_RM)
|
2013-12-16 13:52:35 +00:00
|
|
|
ENCODING("VK1", ENCODING_RM)
|
2013-07-28 08:28:38 +00:00
|
|
|
ENCODING("VK8", ENCODING_RM)
|
|
|
|
ENCODING("VK16", ENCODING_RM)
|
2009-12-19 02:59:52 +00:00
|
|
|
errs() << "Unhandled R/M register encoding " << s << "\n";
|
|
|
|
llvm_unreachable("Unhandled R/M register encoding");
|
|
|
|
}
|
|
|
|
|
|
|
|
OperandEncoding RecognizableInstr::roRegisterEncodingFromString
|
|
|
|
(const std::string &s,
|
|
|
|
bool hasOpSizePrefix) {
|
|
|
|
ENCODING("GR16", ENCODING_REG)
|
|
|
|
ENCODING("GR32", ENCODING_REG)
|
2013-10-14 04:55:01 +00:00
|
|
|
ENCODING("GR32orGR64", ENCODING_REG)
|
2009-12-19 02:59:52 +00:00
|
|
|
ENCODING("GR64", ENCODING_REG)
|
|
|
|
ENCODING("GR8", ENCODING_REG)
|
|
|
|
ENCODING("VR128", ENCODING_REG)
|
|
|
|
ENCODING("FR64", ENCODING_REG)
|
|
|
|
ENCODING("FR32", ENCODING_REG)
|
|
|
|
ENCODING("VR64", ENCODING_REG)
|
|
|
|
ENCODING("SEGMENT_REG", ENCODING_REG)
|
|
|
|
ENCODING("DEBUG_REG", ENCODING_REG)
|
2010-05-06 20:59:00 +00:00
|
|
|
ENCODING("CONTROL_REG", ENCODING_REG)
|
2011-03-15 01:23:15 +00:00
|
|
|
ENCODING("VR256", ENCODING_REG)
|
2013-07-28 08:28:38 +00:00
|
|
|
ENCODING("VR256X", ENCODING_REG)
|
|
|
|
ENCODING("VR128X", ENCODING_REG)
|
|
|
|
ENCODING("FR64X", ENCODING_REG)
|
|
|
|
ENCODING("FR32X", ENCODING_REG)
|
|
|
|
ENCODING("VR512", ENCODING_REG)
|
2013-12-16 13:52:35 +00:00
|
|
|
ENCODING("VK1", ENCODING_REG)
|
2013-07-28 08:28:38 +00:00
|
|
|
ENCODING("VK8", ENCODING_REG)
|
|
|
|
ENCODING("VK16", ENCODING_REG)
|
2013-12-16 13:52:35 +00:00
|
|
|
ENCODING("VK1WM", ENCODING_REG)
|
2013-07-28 08:28:38 +00:00
|
|
|
ENCODING("VK8WM", ENCODING_REG)
|
|
|
|
ENCODING("VK16WM", ENCODING_REG)
|
2009-12-19 02:59:52 +00:00
|
|
|
errs() << "Unhandled reg/opcode register encoding " << s << "\n";
|
|
|
|
llvm_unreachable("Unhandled reg/opcode register encoding");
|
|
|
|
}
|
|
|
|
|
2011-03-15 01:23:15 +00:00
|
|
|
OperandEncoding RecognizableInstr::vvvvRegisterEncodingFromString
|
|
|
|
(const std::string &s,
|
|
|
|
bool hasOpSizePrefix) {
|
2011-10-14 07:06:56 +00:00
|
|
|
ENCODING("GR32", ENCODING_VVVV)
|
|
|
|
ENCODING("GR64", ENCODING_VVVV)
|
2011-03-15 01:23:15 +00:00
|
|
|
ENCODING("FR32", ENCODING_VVVV)
|
|
|
|
ENCODING("FR64", ENCODING_VVVV)
|
|
|
|
ENCODING("VR128", ENCODING_VVVV)
|
|
|
|
ENCODING("VR256", ENCODING_VVVV)
|
2013-07-28 08:28:38 +00:00
|
|
|
ENCODING("FR32X", ENCODING_VVVV)
|
|
|
|
ENCODING("FR64X", ENCODING_VVVV)
|
|
|
|
ENCODING("VR128X", ENCODING_VVVV)
|
|
|
|
ENCODING("VR256X", ENCODING_VVVV)
|
|
|
|
ENCODING("VR512", ENCODING_VVVV)
|
2013-12-16 13:52:35 +00:00
|
|
|
ENCODING("VK1", ENCODING_VVVV)
|
2013-07-28 08:28:38 +00:00
|
|
|
ENCODING("VK8", ENCODING_VVVV)
|
|
|
|
ENCODING("VK16", ENCODING_VVVV)
|
2011-03-15 01:23:15 +00:00
|
|
|
errs() << "Unhandled VEX.vvvv register encoding " << s << "\n";
|
|
|
|
llvm_unreachable("Unhandled VEX.vvvv register encoding");
|
|
|
|
}
|
|
|
|
|
2013-07-28 08:28:38 +00:00
|
|
|
OperandEncoding RecognizableInstr::writemaskRegisterEncodingFromString
|
|
|
|
(const std::string &s,
|
|
|
|
bool hasOpSizePrefix) {
|
2013-12-16 13:52:35 +00:00
|
|
|
ENCODING("VK1WM", ENCODING_WRITEMASK)
|
2013-07-28 08:28:38 +00:00
|
|
|
ENCODING("VK8WM", ENCODING_WRITEMASK)
|
|
|
|
ENCODING("VK16WM", ENCODING_WRITEMASK)
|
|
|
|
errs() << "Unhandled mask register encoding " << s << "\n";
|
|
|
|
llvm_unreachable("Unhandled mask register encoding");
|
|
|
|
}
|
|
|
|
|
2009-12-19 02:59:52 +00:00
|
|
|
OperandEncoding RecognizableInstr::memoryEncodingFromString
|
|
|
|
(const std::string &s,
|
|
|
|
bool hasOpSizePrefix) {
|
|
|
|
ENCODING("i16mem", ENCODING_RM)
|
|
|
|
ENCODING("i32mem", ENCODING_RM)
|
|
|
|
ENCODING("i64mem", ENCODING_RM)
|
|
|
|
ENCODING("i8mem", ENCODING_RM)
|
2010-09-29 02:57:56 +00:00
|
|
|
ENCODING("ssmem", ENCODING_RM)
|
|
|
|
ENCODING("sdmem", ENCODING_RM)
|
2009-12-19 02:59:52 +00:00
|
|
|
ENCODING("f128mem", ENCODING_RM)
|
2010-09-29 02:57:56 +00:00
|
|
|
ENCODING("f256mem", ENCODING_RM)
|
2013-07-28 08:28:38 +00:00
|
|
|
ENCODING("f512mem", ENCODING_RM)
|
2009-12-19 02:59:52 +00:00
|
|
|
ENCODING("f64mem", ENCODING_RM)
|
|
|
|
ENCODING("f32mem", ENCODING_RM)
|
|
|
|
ENCODING("i128mem", ENCODING_RM)
|
2011-03-15 01:23:15 +00:00
|
|
|
ENCODING("i256mem", ENCODING_RM)
|
2013-07-28 08:28:38 +00:00
|
|
|
ENCODING("i512mem", ENCODING_RM)
|
2009-12-19 02:59:52 +00:00
|
|
|
ENCODING("f80mem", ENCODING_RM)
|
|
|
|
ENCODING("lea32mem", ENCODING_RM)
|
|
|
|
ENCODING("lea64_32mem", ENCODING_RM)
|
|
|
|
ENCODING("lea64mem", ENCODING_RM)
|
|
|
|
ENCODING("opaque32mem", ENCODING_RM)
|
|
|
|
ENCODING("opaque48mem", ENCODING_RM)
|
|
|
|
ENCODING("opaque80mem", ENCODING_RM)
|
|
|
|
ENCODING("opaque512mem", ENCODING_RM)
|
2012-07-18 04:11:12 +00:00
|
|
|
ENCODING("vx32mem", ENCODING_RM)
|
|
|
|
ENCODING("vy32mem", ENCODING_RM)
|
2013-07-28 08:28:38 +00:00
|
|
|
ENCODING("vz32mem", ENCODING_RM)
|
2012-07-18 04:11:12 +00:00
|
|
|
ENCODING("vx64mem", ENCODING_RM)
|
|
|
|
ENCODING("vy64mem", ENCODING_RM)
|
2013-07-28 08:28:38 +00:00
|
|
|
ENCODING("vy64xmem", ENCODING_RM)
|
|
|
|
ENCODING("vz64mem", ENCODING_RM)
|
2009-12-19 02:59:52 +00:00
|
|
|
errs() << "Unhandled memory encoding " << s << "\n";
|
|
|
|
llvm_unreachable("Unhandled memory encoding");
|
|
|
|
}
|
|
|
|
|
|
|
|
OperandEncoding RecognizableInstr::relocationEncodingFromString
|
|
|
|
(const std::string &s,
|
|
|
|
bool hasOpSizePrefix) {
|
|
|
|
if(!hasOpSizePrefix) {
|
|
|
|
// For instructions without an OpSize prefix, a declared 16-bit register or
|
|
|
|
// immediate encoding is special.
|
|
|
|
ENCODING("i16imm", ENCODING_IW)
|
|
|
|
}
|
|
|
|
ENCODING("i16imm", ENCODING_Iv)
|
|
|
|
ENCODING("i16i8imm", ENCODING_IB)
|
|
|
|
ENCODING("i32imm", ENCODING_Iv)
|
|
|
|
ENCODING("i32i8imm", ENCODING_IB)
|
|
|
|
ENCODING("i64i32imm", ENCODING_ID)
|
|
|
|
ENCODING("i64i8imm", ENCODING_IB)
|
|
|
|
ENCODING("i8imm", ENCODING_IB)
|
|
|
|
ENCODING("i64i32imm_pcrel", ENCODING_ID)
|
2010-07-07 22:27:31 +00:00
|
|
|
ENCODING("i16imm_pcrel", ENCODING_IW)
|
2009-12-19 02:59:52 +00:00
|
|
|
ENCODING("i32imm_pcrel", ENCODING_ID)
|
|
|
|
ENCODING("brtarget", ENCODING_Iv)
|
|
|
|
ENCODING("brtarget8", ENCODING_IB)
|
|
|
|
ENCODING("i64imm", ENCODING_IO)
|
|
|
|
ENCODING("offset8", ENCODING_Ia)
|
|
|
|
ENCODING("offset16", ENCODING_Ia)
|
|
|
|
ENCODING("offset32", ENCODING_Ia)
|
|
|
|
ENCODING("offset64", ENCODING_Ia)
|
2014-01-22 15:08:08 +00:00
|
|
|
ENCODING("srcidx8", ENCODING_SI)
|
|
|
|
ENCODING("srcidx16", ENCODING_SI)
|
|
|
|
ENCODING("srcidx32", ENCODING_SI)
|
|
|
|
ENCODING("srcidx64", ENCODING_SI)
|
2014-01-22 15:08:21 +00:00
|
|
|
ENCODING("dstidx8", ENCODING_DI)
|
|
|
|
ENCODING("dstidx16", ENCODING_DI)
|
|
|
|
ENCODING("dstidx32", ENCODING_DI)
|
|
|
|
ENCODING("dstidx64", ENCODING_DI)
|
2009-12-19 02:59:52 +00:00
|
|
|
errs() << "Unhandled relocation encoding " << s << "\n";
|
|
|
|
llvm_unreachable("Unhandled relocation encoding");
|
|
|
|
}
|
|
|
|
|
|
|
|
OperandEncoding RecognizableInstr::opcodeModifierEncodingFromString
|
|
|
|
(const std::string &s,
|
|
|
|
bool hasOpSizePrefix) {
|
|
|
|
ENCODING("GR32", ENCODING_Rv)
|
|
|
|
ENCODING("GR64", ENCODING_RO)
|
|
|
|
ENCODING("GR16", ENCODING_Rv)
|
|
|
|
ENCODING("GR8", ENCODING_RB)
|
2011-10-06 06:44:41 +00:00
|
|
|
ENCODING("GR16_NOAX", ENCODING_Rv)
|
|
|
|
ENCODING("GR32_NOAX", ENCODING_Rv)
|
|
|
|
ENCODING("GR64_NOAX", ENCODING_RO)
|
2009-12-19 02:59:52 +00:00
|
|
|
errs() << "Unhandled opcode modifier encoding " << s << "\n";
|
|
|
|
llvm_unreachable("Unhandled opcode modifier encoding");
|
|
|
|
}
|
2009-12-19 04:16:48 +00:00
|
|
|
#undef ENCODING
|