28 #define DEBUG_TYPE "arc-disassembler" 37 std::unique_ptr<MCInstrInfo const>
const MCII;
55 (Bytes[0] << 16) | (Bytes[1] << 24) | (Bytes[2] << 0) | (Bytes[3] << 8);
60 uint64_t &
Size, uint64_t &Insn) {
62 Insn = ((uint64_t)Bytes[0] << 16) | ((uint64_t)Bytes[1] << 24) |
63 ((uint64_t)Bytes[2] << 0) | ((uint64_t)Bytes[3] << 8) |
64 ((uint64_t)Bytes[4] << 48) | ((uint64_t)Bytes[5] << 56) |
65 ((uint64_t)Bytes[6] << 32) | ((uint64_t)Bytes[7] << 40);
70 uint64_t &
Size, uint64_t &Insn) {
72 Insn = ((uint64_t)Bytes[0] << 0) | ((uint64_t)Bytes[1] << 8) |
73 ((uint64_t)Bytes[2] << 32) | ((uint64_t)Bytes[3] << 40) |
74 ((uint64_t)Bytes[4] << 16) | ((uint64_t)Bytes[5] << 24);
81 Insn = (Bytes[0] << 0) | (Bytes[1] << 8);
88 const void *Decoder =
nullptr);
93 const void *Decoder =
nullptr);
97 uint64_t
Address,
const void *Decoder);
115 ARC::R7, ARC::R8, ARC::R9, ARC::R10, ARC::R11, ARC::R12, ARC::R13,
116 ARC::R14, ARC::R15, ARC::R16, ARC::R17, ARC::R18, ARC::R19, ARC::R20,
117 ARC::R21, ARC::R22, ARC::R23, ARC::R24, ARC::R25, ARC::GP, ARC::FP,
118 ARC::SP, ARC::ILINK, ARC::R30, ARC::BLINK};
122 const void *Decoder) {
128 unsigned Reg = GPR32DecoderTable[RegNo];
135 const void *Decoder) {
143 #include "ARCGenDisassemblerTables.inc" 146 return fieldFromInstruction(Insn, 6, 6);
150 return (fieldFromInstruction(Insn, 12, 3) << 3) |
151 fieldFromInstruction(Insn, 24, 3);
155 return fieldFromInstruction(Insn, 0, 6);
161 unsigned S9 = Insn & 0x1ff;
162 unsigned R = (Insn & (0x7fff & ~0x1ff)) >> 9;
169 uint64_t
Value,
const void *Decoder) {
170 static const uint64_t atLeast = 2;
173 return (
nullptr != Disassembler &&
174 Disassembler->tryAddingSymbolicOperand(Inst, Value, Address,
true, 0,
179 uint64_t
Offset,
const void *Decoder) {
180 uint64_t nextAddress = Address +
Offset;
186 template <
unsigned B>
188 uint64_t
Address,
const void *Decoder) {
190 static_assert(
B > 0,
"field is empty");
195 template <
unsigned B>
200 static_assert(
B > 0,
"field is empty");
206 template <
unsigned B>
211 static_assert(
B > 0,
"field is empty");
212 const unsigned max = (1u <<
B) - 1;
220 const void *Decoder) {
221 unsigned SrcC, DstB, LImm;
237 const void *Decoder) {
238 unsigned DstA, SrcB, LImm;
255 const void *Decoder) {
263 LLVM_DEBUG(
dbgs() <<
"Decoding LdRLimm found non-limm register.");
272 const void *Decoder) {
274 using Field = decltype(Insn);
275 Field h = fieldFromInstruction(Insn, 5, 3) |
276 (fieldFromInstruction(Insn, 0, 2) << 3);
277 Field g = fieldFromInstruction(Insn, 8, 3) |
278 (fieldFromInstruction(Insn, 3, 2) << 3);
280 auto DecodeRegisterOrImm = [&Inst,
Address, Decoder](
Field RegNum,
293 return DecodeRegisterOrImm(h, Insn >> 16u);
301 if (Bytes.
size() < 2) {
305 uint8_t DecodeByte = (Bytes[1] & 0xF7) >> 3;
308 if (DecodeByte < 0x08) {
310 if (Bytes.
size() < 4) {
315 if (Bytes.
size() >= 8) {
321 decodeInstruction(DecoderTable64, Instr, Insn64,
Address,
this, STI);
326 LLVM_DEBUG(
dbgs() <<
"Not a 64-bit instruction, falling back to 32-bit.");
333 return decodeInstruction(DecoderTable32, Instr, Insn32,
Address,
this, STI);
335 if (Bytes.
size() >= 6) {
341 decodeInstruction(DecoderTable48, Instr, Insn48,
Address,
this, STI);
344 dbgs() <<
"Successfully decoded 16-bit instruction with limm.");
348 dbgs() <<
"Not a 16-bit instruction with limm, try without it.");
356 return decodeInstruction(DecoderTable16, Instr, Insn16,
Address,
this, STI);
static unsigned decodeCField(unsigned Insn)
This class represents lattice values for constants.
static bool DecodeSymbolicOperand(MCInst &Inst, uint64_t Address, uint64_t Value, const void *Decoder)
DecodeStatus
Ternary decode status.
static const uint16_t GPR32DecoderTable[]
Superclass for all disassemblers.
MCInstrInfo * createMCInstrInfo() const
createMCInstrInfo - Create a MCInstrInfo implementation.
static DecodeStatus DecodeSignedOperand(MCInst &Inst, unsigned InsnS, uint64_t Address=0, const void *Decoder=nullptr)
static DecodeStatus DecodeFromCyclicRange(MCInst &Inst, unsigned InsnS, uint64_t Address=0, const void *Decoder=nullptr)
static DecodeStatus DecodeBranchTargetS(MCInst &Inst, unsigned InsnS, uint64_t Address, const void *Decoder)
Target & getTheARCTarget()
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.
T maskTrailingOnes(unsigned N)
Create a bitmask with the N right-most bits set to 1, and all other bits set to 0.
static bool readInstruction64(ArrayRef< uint8_t > Bytes, uint64_t Address, uint64_t &Size, uint64_t &Insn)
static MCOperand createReg(unsigned Reg)
static bool readInstruction16(ArrayRef< uint8_t > Bytes, uint64_t Address, uint64_t &Size, uint32_t &Insn)
static void DecodeSymbolicOperandOff(MCInst &Inst, uint64_t Address, uint64_t Offset, const void *Decoder)
static DecodeStatus DecodeStLImmInstruction(MCInst &, uint64_t, uint64_t, const void *)
Context object for machine code objects.
static DecodeStatus DecodeLdRLImmInstruction(MCInst &, uint64_t, uint64_t, const void *)
Instances of this class represent a single low-level machine instruction.
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARCDisassembler()
static bool readInstruction48(ArrayRef< uint8_t > Bytes, uint64_t Address, uint64_t &Size, uint64_t &Insn)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
size_t size() const
size - Get the array size.
Interface to description of machine instruction set.
static DecodeStatus DecodeGBR32ShortRegister(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
Align max(MaybeAlign Lhs, Align Rhs)
static DecodeStatus DecodeMoveHRegInstruction(MCInst &Inst, uint64_t, uint64_t, const void *)
static DecodeStatus DecodeMEMrs9(MCInst &, unsigned, uint64_t, const void *)
#define LLVM_EXTERNAL_VISIBILITY
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Target - Wrapper for Target specific information.
static DecodeStatus DecodeGPR32RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static bool readInstruction32(ArrayRef< uint8_t > Bytes, uint64_t Address, uint64_t &Size, uint32_t &Insn)
static MCDisassembler * createARCDisassembler(const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx)
Generic base class for all target subtargets.
static unsigned decodeBField(unsigned Insn)
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...
void addOperand(const MCOperand &Op)
static unsigned decodeAField(unsigned Insn)
static MCOperand createImm(int64_t Val)
static DecodeStatus DecodeLdLImmInstruction(MCInst &, uint64_t, uint64_t, const void *)