28#define DEBUG_TYPE "riscv-disassembler"
34 std::unique_ptr<MCInstrInfo const>
const MCII;
46 void addSPOperands(
MCInst &
MI)
const;
64 return new RISCVDisassembler(STI, Ctx,
T.createMCInstrInfo());
80 if (RegNo >= 32 || (IsRVE && RegNo >= 16))
93 if (RegNo >= 32 || (IsRVE && RegNo >= 16))
106 if (RegNo >= 32 || (IsRVE && RegNo >= 16))
118 if (Reg != RISCV::X1 && Reg != RISCV::X5)
214 if (RegNo >= 32 || RegNo % 2)
217 const RISCVDisassembler *Dis =
218 static_cast<const RISCVDisassembler *
>(Decoder);
221 RISCV::X0 + RegNo, RISCV::sub_gpr_even,
222 &RISCVMCRegisterClasses[RISCV::GPRPairRegClassID]);
229 const void *Decoder) {
233 MCRegister Reg = (RegNo < 2) ? (RegNo + RISCV::X8) : (RegNo - 2 + RISCV::X18);
252 if (RegNo >= 32 || RegNo % 2)
255 const RISCVDisassembler *Dis =
256 static_cast<const RISCVDisassembler *
>(Decoder);
260 &RISCVMCRegisterClasses[RISCV::VRM2RegClassID]);
269 if (RegNo >= 32 || RegNo % 4)
272 const RISCVDisassembler *Dis =
273 static_cast<const RISCVDisassembler *
>(Decoder);
277 &RISCVMCRegisterClasses[RISCV::VRM4RegClassID]);
286 if (RegNo >= 32 || RegNo % 8)
289 const RISCVDisassembler *Dis =
290 static_cast<const RISCVDisassembler *
>(Decoder);
294 &RISCVMCRegisterClasses[RISCV::VRM8RegClassID]);
316 MCRegister Reg = (RegNo == 0) ? RISCV::V0 : RISCV::NoRegister;
326 assert(isUInt<N>(Imm) &&
"Invalid immediate");
334 assert(isUInt<6>(Imm) &&
"Invalid immediate");
350 return decodeUImmOperand<N>(Inst, Imm,
Address, Decoder);
365 assert(isUInt<N>(Imm) &&
"Invalid immediate");
377 return decodeSImmOperand<N>(Inst, Imm,
Address, Decoder);
384 assert(isUInt<N>(Imm) &&
"Invalid immediate");
395 assert(isUInt<6>(Imm) &&
"Invalid immediate");
397 Imm = (SignExtend64<6>(Imm) & 0xfffff);
405 assert(isUInt<3>(Imm) &&
"Invalid immediate");
415 assert(isUInt<3>(Imm) &&
"Invalid immediate");
448 uint64_t Address,
const void *Decoder);
454 uint64_t Address,
const void *Decoder);
460#include "RISCVGenDisassemblerTables.inc"
489 fieldFromInstruction(
Insn, 12, 1) << 5 | fieldFromInstruction(
Insn, 2, 5);
491 decodeSImmOperand<6>(Inst, SImm6,
Address, Decoder);
502 fieldFromInstruction(
Insn, 12, 1) << 5 | fieldFromInstruction(
Insn, 2, 5);
504 decodeUImmOperand<6>(Inst, UImm6,
Address, Decoder);
541 decodeUImmOperand<2>(Inst, UImm2,
Address, Decoder);
546 bool IsWordOp = (Opcode == RISCV::TH_LWD || Opcode == RISCV::TH_LWUD ||
547 Opcode == RISCV::TH_SWD);
557 uint64_t Address,
const void *Decoder) {
574 uint64_t Address,
const void *Decoder) {
581void RISCVDisassembler::addSPOperands(
MCInst &
MI)
const {
584 if (MCID.
operands()[i].RegClass == RISCV::SPRegClassID)
588#define TRY_TO_DECODE_WITH_ADDITIONAL_OPERATION(FEATURE_CHECKS, DECODER_TABLE, \
589 DESC, ADDITIONAL_OPERATION) \
591 if (FEATURE_CHECKS) { \
592 LLVM_DEBUG(dbgs() << "Trying " DESC ":\n"); \
593 DecodeStatus Result = \
594 decodeInstruction(DECODER_TABLE, MI, Insn, Address, this, STI); \
595 if (Result != MCDisassembler::Fail) { \
596 ADDITIONAL_OPERATION; \
601#define TRY_TO_DECODE_AND_ADD_SP(FEATURE_CHECKS, DECODER_TABLE, DESC) \
602 TRY_TO_DECODE_WITH_ADDITIONAL_OPERATION(FEATURE_CHECKS, DECODER_TABLE, DESC, \
604#define TRY_TO_DECODE(FEATURE_CHECKS, DECODER_TABLE, DESC) \
605 TRY_TO_DECODE_WITH_ADDITIONAL_OPERATION(FEATURE_CHECKS, DECODER_TABLE, DESC, \
607#define TRY_TO_DECODE_FEATURE(FEATURE, DECODER_TABLE, DESC) \
608 TRY_TO_DECODE(STI.hasFeature(FEATURE), DECODER_TABLE, DESC)
614 if (Bytes.
size() < 4) {
623 !STI.hasFeature(RISCV::Feature64Bit),
624 DecoderTableRV32Zdinx32,
625 "RV32Zdinx table (Double in Integer and rv32)");
627 !STI.hasFeature(RISCV::Feature64Bit),
628 DecoderTableRV32Zacas32,
629 "RV32Zacas table (Compare-And-Swap and rv32)");
631 "RVZfinx table (Float in Integer)");
633 DecoderTableXVentana32,
"Ventana custom opcode table");
635 "XTHeadBa custom opcode table");
637 "XTHeadBb custom opcode table");
639 "XTHeadBs custom opcode table");
641 DecoderTableXTHeadCondMov32,
642 "XTHeadCondMov custom opcode table");
644 "XTHeadCmo custom opcode table");
646 DecoderTableXTHeadFMemIdx32,
647 "XTHeadFMemIdx custom opcode table");
649 "XTHeadMac custom opcode table");
651 DecoderTableXTHeadMemIdx32,
652 "XTHeadMemIdx custom opcode table");
654 DecoderTableXTHeadMemPair32,
655 "XTHeadMemPair custom opcode table");
657 DecoderTableXTHeadSync32,
658 "XTHeadSync custom opcode table");
660 DecoderTableXTHeadVdot32,
661 "XTHeadVdot custom opcode table");
663 "SiFive VCIX custom opcode table");
665 RISCV::FeatureVendorXSfvqmaccdod, DecoderTableXSfvqmaccdod32,
666 "SiFive Matrix Multiplication (2x8 and 8x2) Instruction opcode table");
668 RISCV::FeatureVendorXSfvqmaccqoq, DecoderTableXSfvqmaccqoq32,
669 "SiFive Matrix Multiplication (4x8 and 8x4) Instruction opcode table");
671 RISCV::FeatureVendorXSfvfwmaccqqq, DecoderTableXSfvfwmaccqqq32,
672 "SiFive Matrix Multiplication Instruction opcode table");
674 RISCV::FeatureVendorXSfvfnrclipxfqf, DecoderTableXSfvfnrclipxfqf32,
675 "SiFive FP32-to-int8 Ranged Clip Instructions opcode table");
677 DecoderTableXSiFivecdiscarddlone32,
678 "SiFive sf.cdiscard.d.l1 custom opcode table");
680 DecoderTableXSiFivecflushdlone32,
681 "SiFive sf.cflush.d.l1 custom opcode table");
683 "SiFive sf.cease custom opcode table");
685 DecoderTableXCVbitmanip32,
686 "CORE-V Bit Manipulation custom opcode table");
688 "CORE-V Event load custom opcode table");
690 "CORE-V MAC custom opcode table");
692 "CORE-V MEM custom opcode table");
694 "CORE-V ALU custom opcode table");
696 "CORE-V SIMD extensions custom opcode table");
698 "CORE-V Immediate Branching custom opcode table");
700 "Qualcomm uC CSR custom opcode table");
702 "Qualcomm uC Scaled Load Store custom opcode table");
704 "Qualcomm uC Arithmetic custom opcode table");
706 "Qualcomm uC Conditional Select custom opcode table");
708 "Qualcomm uC Load Store Multiple custom opcode table");
710 RISCV::FeatureVendorXqciac, DecoderTableXqciac32,
711 "Qualcomm uC Load-Store Address Calculation custom opcode table");
713 RISCV::FeatureVendorXqcicli, DecoderTableXqcicli32,
714 "Qualcomm uC Conditional Load Immediate custom opcode table");
716 "Qualcomm uC Conditional Move custom opcode table");
718 "Qualcomm uC Interrupts custom opcode table");
728 if (Bytes.
size() < 2) {
736 DecoderTableRISCV32Only_16,
737 "RISCV32Only_16 table (16-bit Instruction)");
739 "RVZicfiss table (Shadow Stack)");
741 "Zcmt table (16-bit Table Jump Instructions)");
743 RISCV::FeatureStdExtZcmp, DecoderTableRVZcmp16,
744 "Zcmp table (16-bit Push/Pop & Double Move Instructions)");
746 RISCV::FeatureVendorXqciac, DecoderTableXqciac16,
747 "Qualcomm uC Load-Store Address Calculation custom 16bit opcode table");
749 RISCV::FeatureVendorXqcicm, DecoderTableXqcicm16,
750 "Qualcomm uC Conditional Move custom 16bit opcode table");
752 "Qualcomm uC Interrupts custom 16bit opcode table");
755 "WCH QingKe XW custom opcode table");
757 "RISCV_C table (16-bit Instruction)");
766 if (Bytes.
size() < 6) {
773 for (
size_t i =
Size; i-- != 0;) {
777 RISCV::FeatureVendorXqcilo, DecoderTableXqcilo48,
778 "Qualcomm uC Large Offset Load Store custom 48bit opcode table");
788 if ((Bytes[0] & 0b11) != 0b11)
789 return getInstruction16(
MI,
Size, Bytes, Address, CS);
793 if ((Bytes[0] & 0b1'1100) != 0b1'1100)
794 return getInstruction32(
MI,
Size, Bytes, Address, CS);
797 if ((Bytes[0] & 0b11'1111) == 0b01'1111) {
798 return getInstruction48(
MI,
Size, Bytes, Address, CS);
802 if ((Bytes[0] & 0b111'1111) == 0b011'1111) {
808 if (Bytes.
size() < 2) {
815 unsigned nnn = (Bytes[1] >> 4) & 0b111;
817 Size = 10 + (nnn * 2);
SmallVector< AArch64_IMM::ImmInsnModel, 4 > Insn
#define LLVM_EXTERNAL_VISIBILITY
#define TRY_TO_DECODE(FEATURE_CHECKS, DECODER_TABLE, DESC)
static DecodeStatus decodeRegReg(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeZcmpRlist(MCInst &Inst, uint32_t Imm, uint64_t Address, const void *Decoder)
static DecodeStatus decodeRVCInstrRdRs1Rs2(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeUImmLog2XLenOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
MCDisassembler::DecodeStatus DecodeStatus
static DecodeStatus decodeSImmOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRX1X5RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRCRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeFPR64RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeUImmLog2XLenNonZeroOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeRTZArg(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static MCDisassembler * createRISCVDisassembler(const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx)
static DecodeStatus decodeRVCInstrRdRs1ImmZero(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRF16RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
#define TRY_TO_DECODE_FEATURE(FEATURE, DECODER_TABLE, DESC)
static DecodeStatus decodeSImmOperandAndLsl1(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeFPR32CRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeXTHeadMemPair(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeCLUIImmOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeCSSPushPopchk(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeUImmOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeFPR32RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVRM8RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVRM4RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeRVCInstrRdSImm(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVRRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVRM2RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRPairRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeZcmpSpimm(MCInst &Inst, uint32_t Imm, uint64_t Address, const void *Decoder)
static DecodeStatus DecodeGPRNoX0X2RegisterClass(MCInst &Inst, uint64_t RegNo, uint32_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeRVCInstrRdRs2(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeSImmNonZeroOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVMV0RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeFPR64CRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRF32RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVDisassembler()
static DecodeStatus DecodeGPRNoX0RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeFRMArg(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeSR07RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const void *Decoder)
static DecodeStatus decodeRVCInstrRdRs1UImm(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder)
#define TRY_TO_DECODE_AND_ADD_SP(FEATURE_CHECKS, DECODER_TABLE, DESC)
static DecodeStatus DecodeFPR16RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeVMaskReg(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeUImmNonZeroOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Context object for machine code objects.
Superclass for all disassemblers.
const MCSubtargetInfo & getSubtargetInfo() const
DecodeStatus
Ternary decode status.
virtual DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address, raw_ostream &CStream) const =0
Returns the disassembly of a single instruction.
Instances of this class represent a single low-level machine instruction.
unsigned getOpcode() const
void addOperand(const MCOperand Op)
const MCOperand & getOperand(unsigned i) const
Describe properties that are true of each instruction in the target description file.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
ArrayRef< MCOperandInfo > operands() const
Interface to description of machine instruction set.
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
MCRegister getMatchingSuperReg(MCRegister Reg, unsigned SubIdx, const MCRegisterClass *RC) const
Return a super-register of the specified register Reg so its sub-register of index SubIdx is Reg.
Wrapper class representing physical registers. Should be passed by value.
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
Target - Wrapper for Target specific information.
This class implements an extremely fast bulk output stream that can only output to a stream.
static bool isValidRoundingMode(unsigned Mode)
uint16_t read16le(const void *P)
uint32_t read32le(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
Target & getTheRISCV32Target()
Target & getTheRISCV64Target()
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.