10 #define DEBUG_TYPE "hexagon-disassembler"
36 using namespace Hexagon;
45 std::unique_ptr<MCInstrInfo const>
const MCII;
46 std::unique_ptr<MCInst *> CurrentBundle;
55 bool &Complete)
const;
60 void addSubinstOperands(
MCInst *
MI,
unsigned opcode,
unsigned inst)
const;
74 assert(Success); (void)Success;
79 HexagonDisassembler
const &disassembler(
void const *Decoder) {
80 return *
static_cast<HexagonDisassembler
const *
>(Decoder);
83 void signedDecoder(
MCInst &MI,
unsigned tmp,
const void *Decoder) {
84 HexagonDisassembler
const &Disassembler = disassembler(Decoder);
86 fullValue(*Disassembler.MCII, **Disassembler.CurrentBundle, MI,
87 SignExtend64<T>(tmp));
88 int64_t Extended = SignExtend64<32>(FullValue);
103 const void *Decoder);
106 const void *Decoder);
109 const void *Decoder);
112 const void *Decoder);
115 uint64_t
Address,
const void *Decoder);
118 const void *Decoder);
121 const void *Decoder);
124 const void *Decoder);
127 const void *Decoder);
130 const void *Decoder);
133 const void *Decoder);
136 uint64_t
Address,
const void *Decoder);
138 uint64_t ,
const void *Decoder);
140 const void *Decoder);
142 const void *Decoder);
144 const void *Decoder);
146 const void *Decoder);
148 const void *Decoder);
150 const void *Decoder);
152 const void *Decoder);
154 const void *Decoder);
157 #include "HexagonGenDisassemblerTables.inc"
176 bool Complete =
false;
179 *CurrentBundle = &
MI;
181 while (Result ==
Success && !Complete) {
185 Result = getSingleInstruction(*Inst, MI, Bytes, Address, os, cs, Complete);
195 *getContext().getRegisterInfo(),
false);
196 if (!Checker.check())
204 case Hexagon::SA1_setin1:
208 case Hexagon::SA1_dec:
230 else if (BundleSize == 1)
240 if ((Instruction & HexagonII::INST_PARSE_MASK) ==
242 unsigned duplexIClass;
243 uint8_t
const *DecodeLow, *DecodeHigh;
244 duplexIClass = ((Instruction >> 28) & 0xe) | ((Instruction >> 13) & 0x1);
245 switch (duplexIClass) {
249 DecodeLow = DecoderTableSUBINSN_L132;
250 DecodeHigh = DecoderTableSUBINSN_L132;
253 DecodeLow = DecoderTableSUBINSN_L232;
254 DecodeHigh = DecoderTableSUBINSN_L132;
257 DecodeLow = DecoderTableSUBINSN_L232;
258 DecodeHigh = DecoderTableSUBINSN_L232;
261 DecodeLow = DecoderTableSUBINSN_A32;
262 DecodeHigh = DecoderTableSUBINSN_A32;
265 DecodeLow = DecoderTableSUBINSN_L132;
266 DecodeHigh = DecoderTableSUBINSN_A32;
269 DecodeLow = DecoderTableSUBINSN_L232;
270 DecodeHigh = DecoderTableSUBINSN_A32;
273 DecodeLow = DecoderTableSUBINSN_S132;
274 DecodeHigh = DecoderTableSUBINSN_A32;
277 DecodeLow = DecoderTableSUBINSN_S232;
278 DecodeHigh = DecoderTableSUBINSN_A32;
281 DecodeLow = DecoderTableSUBINSN_S132;
282 DecodeHigh = DecoderTableSUBINSN_L132;
285 DecodeLow = DecoderTableSUBINSN_S132;
286 DecodeHigh = DecoderTableSUBINSN_L232;
289 DecodeLow = DecoderTableSUBINSN_S132;
290 DecodeHigh = DecoderTableSUBINSN_S132;
293 DecodeLow = DecoderTableSUBINSN_S232;
294 DecodeHigh = DecoderTableSUBINSN_S132;
297 DecodeLow = DecoderTableSUBINSN_S232;
298 DecodeHigh = DecoderTableSUBINSN_L132;
301 DecodeLow = DecoderTableSUBINSN_S232;
302 DecodeHigh = DecoderTableSUBINSN_L232;
305 DecodeLow = DecoderTableSUBINSN_S232;
306 DecodeHigh = DecoderTableSUBINSN_S232;
309 MI.
setOpcode(Hexagon::DuplexIClass0 + duplexIClass);
316 adjustDuplex(*MILow, getContext());
318 DecodeHigh, *MIHigh, (Instruction >> 16) & 0x1fff, Address,
this, STI);
321 adjustDuplex(*MIHigh, getContext());
328 if ((Instruction & HexagonII::INST_PARSE_MASK) ==
332 if (Extender !=
nullptr)
341 STI.getFeatureBits()[Hexagon::ExtensionHVX])
348 case Hexagon::J4_cmpeqn1_f_jumpnv_nt:
349 case Hexagon::J4_cmpeqn1_f_jumpnv_t:
350 case Hexagon::J4_cmpeqn1_fp0_jump_nt:
351 case Hexagon::J4_cmpeqn1_fp0_jump_t:
352 case Hexagon::J4_cmpeqn1_fp1_jump_nt:
353 case Hexagon::J4_cmpeqn1_fp1_jump_t:
354 case Hexagon::J4_cmpeqn1_t_jumpnv_nt:
355 case Hexagon::J4_cmpeqn1_t_jumpnv_t:
356 case Hexagon::J4_cmpeqn1_tp0_jump_nt:
357 case Hexagon::J4_cmpeqn1_tp0_jump_t:
358 case Hexagon::J4_cmpeqn1_tp1_jump_nt:
359 case Hexagon::J4_cmpeqn1_tp1_jump_t:
360 case Hexagon::J4_cmpgtn1_f_jumpnv_nt:
361 case Hexagon::J4_cmpgtn1_f_jumpnv_t:
362 case Hexagon::J4_cmpgtn1_fp0_jump_nt:
363 case Hexagon::J4_cmpgtn1_fp0_jump_t:
364 case Hexagon::J4_cmpgtn1_fp1_jump_nt:
365 case Hexagon::J4_cmpgtn1_fp1_jump_t:
366 case Hexagon::J4_cmpgtn1_t_jumpnv_nt:
367 case Hexagon::J4_cmpgtn1_t_jumpnv_t:
368 case Hexagon::J4_cmpgtn1_tp0_jump_nt:
369 case Hexagon::J4_cmpgtn1_tp0_jump_t:
370 case Hexagon::J4_cmpgtn1_tp1_jump_nt:
371 case Hexagon::J4_cmpgtn1_tp1_jump_t:
382 assert(MCO.
isReg() &&
"New value consumers must be registers");
384 getContext().getRegisterInfo()->getEncodingValue(MCO.
getReg());
385 if ((Register & 0x6) == 0)
388 unsigned Lookback = (Register & 0x6) >> 1;
392 auto i = Instructions.end() - 1;
393 for (
auto n = Instructions.begin() - 1;; --i, ++
Offset) {
402 if (Offset == Lookback)
405 auto const &Inst = *i->getInst();
406 bool SubregBit = (Register & 0x1) != 0;
411 assert(Producer != Hexagon::NoRegister);
416 if (Producer >= Hexagon::W0 && Producer <= Hexagon::W15)
417 Producer = ((Producer - Hexagon::W0) << 1) + SubregBit + Hexagon::V0;
422 assert(Producer != Hexagon::NoRegister);
428 if (Extender !=
nullptr) {
441 if (RegNo < Table.
size()) {
451 const void *Decoder) {
457 const void *Decoder) {
460 Hexagon::R5,
Hexagon::R6, Hexagon::R7, Hexagon::R8, Hexagon::R9,
461 Hexagon::R10, Hexagon::R11, Hexagon::R12, Hexagon::R13, Hexagon::R14,
462 Hexagon::R15, Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19,
463 Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, Hexagon::R24,
464 Hexagon::R25, Hexagon::R26, Hexagon::R27, Hexagon::R28, Hexagon::R29,
465 Hexagon::R30, Hexagon::R31};
473 const void *Decoder) {
474 static const MCPhysReg GeneralSubRegDecoderTable[] = {
475 Hexagon::R0, Hexagon::R1,
Hexagon::R2, Hexagon::R3,
477 Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19,
478 Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23,
486 const void *Decoder) {
487 static const MCPhysReg VecRegDecoderTable[] = {
489 Hexagon::V5, Hexagon::V6, Hexagon::V7, Hexagon::V8, Hexagon::V9,
490 Hexagon::V10, Hexagon::V11, Hexagon::V12, Hexagon::V13, Hexagon::V14,
491 Hexagon::V15, Hexagon::V16, Hexagon::V17, Hexagon::V18, Hexagon::V19,
492 Hexagon::V20, Hexagon::V21, Hexagon::V22, Hexagon::V23, Hexagon::V24,
493 Hexagon::V25, Hexagon::V26, Hexagon::V27, Hexagon::V28, Hexagon::V29,
494 Hexagon::V30, Hexagon::V31};
501 const void *Decoder) {
502 static const MCPhysReg DoubleRegDecoderTable[] = {
503 Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3,
504 Hexagon::D4, Hexagon::D5, Hexagon::D6, Hexagon::D7,
505 Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11,
506 Hexagon::D12, Hexagon::D13, Hexagon::D14, Hexagon::D15};
512 MCInst &Inst,
unsigned RegNo, uint64_t ,
const void *Decoder) {
513 static const MCPhysReg GeneralDoubleLow8RegDecoderTable[] = {
514 Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3,
515 Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11};
522 const void *Decoder) {
523 static const MCPhysReg VecDblRegDecoderTable[] = {
524 Hexagon::W0, Hexagon::W1, Hexagon::W2, Hexagon::W3,
525 Hexagon::W4, Hexagon::W5, Hexagon::W6, Hexagon::W7,
526 Hexagon::W8, Hexagon::W9, Hexagon::W10, Hexagon::W11,
527 Hexagon::W12, Hexagon::W13, Hexagon::W14, Hexagon::W15};
534 const void *Decoder) {
535 static const MCPhysReg PredRegDecoderTable[] = {Hexagon::P0, Hexagon::P1,
536 Hexagon::P2, Hexagon::P3};
543 const void *Decoder) {
544 static const MCPhysReg VecPredRegDecoderTable[] = {Hexagon::Q0, Hexagon::Q1,
545 Hexagon::Q2, Hexagon::Q3};
552 const void *Decoder) {
553 using namespace Hexagon;
554 static const MCPhysReg CtrlRegDecoderTable[] = {
558 CS0, CS1, UPCYCLELO, UPCYCLEHI,
559 FRAMELIMIT, FRAMEKEY, PKTCOUNTLO, PKTCOUNTHI,
562 0, 0, UTIMERLO, UTIMERHI
568 static_assert(NoRegister == 0,
"Expecting NoRegister to be 0");
569 if (CtrlRegDecoderTable[RegNo] == NoRegister)
572 unsigned Register = CtrlRegDecoderTable[RegNo];
579 const void *Decoder) {
580 using namespace Hexagon;
581 static const MCPhysReg CtrlReg64DecoderTable[] = {
586 C17_16, 0, PKTCOUNT, 0,
595 static_assert(NoRegister == 0,
"Expecting NoRegister to be 0");
596 if (CtrlReg64DecoderTable[RegNo] == NoRegister)
599 unsigned Register = CtrlReg64DecoderTable[RegNo];
606 const void *Decoder) {
607 unsigned Register = 0;
610 Register = Hexagon::M0;
613 Register = Hexagon::M1;
624 const void *Decoder) {
625 HexagonDisassembler
const &Disassembler = disassembler(Decoder);
627 fullValue(*Disassembler.MCII, **Disassembler.CurrentBundle, MI, tmp);
628 assert(FullValue >= 0 &&
"Negative in unsigned decoder");
634 uint64_t ,
const void *Decoder) {
635 HexagonDisassembler
const &Disassembler = disassembler(Decoder);
638 signedDecoder<32>(
MI, tmp, Decoder);
644 const void *Decoder) {
645 HexagonDisassembler
const &Disassembler = disassembler(Decoder);
651 fullValue(*Disassembler.MCII, **Disassembler.CurrentBundle, MI,
653 int64_t Extended = SignExtend64<32>(FullValue) + Address;
654 if (!Disassembler.tryAddingSymbolicOperand(MI, Extended, Address,
true, 0, 4))
static MCDisassembler * createHexagonDisassembler(const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx)
bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned short getNewValueOp(MCInstrInfo const &MCII, MCInst const &MCI)
static DecodeStatus s4_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, const void *Decoder)
MCDisassembler::DecodeStatus DecodeStatus
static DecodeStatus s3_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, const void *Decoder)
MCInst const * extenderForIndex(MCInst const &MCB, size_t Index)
static DecodeStatus s32_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, const void *Decoder)
DecodeStatus
Ternary decode status.
static MCOperand createExpr(const MCExpr *Val)
Superclass for all disassemblers.
static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static DecodeStatus DecodeGeneralSubRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.
static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, const void *Decoder)
static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn expects newly produced value.
void setInnerLoop(MCInst &MCI)
MCInstrInfo * createMCInstrInfo() const
createMCInstrInfo - Create a MCInstrInfo implementation.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array...
bool isImmext(MCInst const &MCI)
static MCOperand createReg(unsigned Reg)
MCOperand const & getNewValueOperand2(MCInstrInfo const &MCII, MCInst const &MCI)
static DecodeStatus DecodeVecDblRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static DecodeStatus s6_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, const void *Decoder)
static DecodeStatus DecodeVecPredRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
iterator_range< Hexagon::PacketIterator > bundleInstructions(MCInstrInfo const &MCII, MCInst const &MCI)
Context object for machine code objects.
unsigned getReg() const
Returns the register number.
int decodeInstruction(InternalInstruction *insn, byteReader_t reader, const void *readerArg, dlog_t logger, void *loggerArg, const void *miiArg, uint64_t startLoc, DisassemblerMode mode)
Decode one instruction and store the decoding results in a buffer provided by the consumer...
bool hasNewValue2(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn produces a second value.
size_t size() const
size - Get the array size.
iterator insert(iterator I, const MCOperand &Op)
Instances of this class represent a single low-level machine instruction.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
const MCExpr * getExpr() const
static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static DecodeStatus s4_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, const void *Decoder)
Interface to description of machine instruction set.
void setOuterLoop(MCInst &MCI)
static DecodeStatus DecodeRegisterClass(MCInst &Inst, unsigned RegNo, ArrayRef< MCPhysReg > Table)
static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
void LLVMInitializeHexagonDisassembler()
unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI)
static DecodeStatus DecodeGeneralDoubleLow8RegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static const unsigned IntRegDecoderTable[]
void setOpcode(unsigned Op)
bool isExtendable(MCInstrInfo const &MCII, MCInst const &MCI)
bool isVector(MCInstrInfo const &MCII, MCInst const &MCI)
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
Promote Memory to Register
static DecodeStatus s8_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, const void *Decoder)
static DecodeStatus s4_2ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, const void *Decoder)
unsigned getOpcode() const
Target - Wrapper for Target specific information.
static DecodeStatus s4_1ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, const void *Decoder)
bool isExtended(MCInstrInfo const &MCII, MCInst const &MCI)
static MCOperand createInst(const MCInst *Val)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address, const void *Decoder)
static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
uint32_t read32le(const void *P)
MCSubtargetInfo - Generic base class for all target subtargets.
const MCInst * getInst() const
size_t bundleSize(MCInst const &MCI)
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
void setReg(unsigned Reg)
Set the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
#define HEXAGON_INSTR_SIZE
LLVM Value Representation.
Check for a valid bundle.
This class implements an extremely fast bulk output stream that can only output to a stream...
void addOperand(const MCOperand &Op)
bool hasNewValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn produces a value.
static DecodeStatus DecodeVectorRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
unsigned getExtentAlignment(MCInstrInfo const &MCII, MCInst const &MCI)
Instances of this class represent operands of the MCInst class.
#define HEXAGON_MAX_PACKET_SIZE
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
const MCOperand & getOperand(unsigned i) const
Target & getTheHexagonTarget()
void addConstant(MCInst &MI, uint64_t Value, MCContext &Context)
MCOperand const & getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getExtentBits(MCInstrInfo const &MCII, MCInst const &MCI)