28#define DEBUG_TYPE "riscv-disassembler"
34 std::unique_ptr<MCInstrInfo const>
const MCII;
46 void addSPOperands(
MCInst &
MI)
const;
60 return new RISCVDisassembler(STI, Ctx,
T.createMCInstrInfo());
76 if (RegNo >= 32 || (IsRVE && RegNo >= 16))
89 if (RegNo >= 32 || (IsRVE && RegNo >= 16))
102 if (RegNo >= 32 || (IsRVE && RegNo >= 16))
114 if (Reg != RISCV::X1 && Reg != RISCV::X5)
210 if (RegNo >= 32 || RegNo % 2)
213 const RISCVDisassembler *Dis =
214 static_cast<const RISCVDisassembler *
>(Decoder);
217 RISCV::X0 + RegNo, RISCV::sub_gpr_even,
218 &RISCVMCRegisterClasses[RISCV::GPRPairRegClassID]);
225 const void *Decoder) {
229 MCRegister Reg = (RegNo < 2) ? (RegNo + RISCV::X8) : (RegNo - 2 + RISCV::X18);
248 if (RegNo >= 32 || RegNo % 2)
251 const RISCVDisassembler *Dis =
252 static_cast<const RISCVDisassembler *
>(Decoder);
256 &RISCVMCRegisterClasses[RISCV::VRM2RegClassID]);
265 if (RegNo >= 32 || RegNo % 4)
268 const RISCVDisassembler *Dis =
269 static_cast<const RISCVDisassembler *
>(Decoder);
273 &RISCVMCRegisterClasses[RISCV::VRM4RegClassID]);
282 if (RegNo >= 32 || RegNo % 8)
285 const RISCVDisassembler *Dis =
286 static_cast<const RISCVDisassembler *
>(Decoder);
290 &RISCVMCRegisterClasses[RISCV::VRM8RegClassID]);
302 MCRegister Reg = (RegNo == 0) ? RISCV::V0 : RISCV::NoRegister;
312 assert(isUInt<N>(Imm) &&
"Invalid immediate");
320 assert(isUInt<6>(Imm) &&
"Invalid immediate");
336 return decodeUImmOperand<N>(Inst, Imm,
Address, Decoder);
351 assert(isUInt<N>(Imm) &&
"Invalid immediate");
363 return decodeSImmOperand<N>(Inst, Imm,
Address, Decoder);
370 assert(isUInt<N>(Imm) &&
"Invalid immediate");
381 assert(isUInt<6>(Imm) &&
"Invalid immediate");
383 Imm = (SignExtend64<6>(Imm) & 0xfffff);
391 assert(isUInt<3>(Imm) &&
"Invalid immediate");
401 assert(isUInt<3>(Imm) &&
"Invalid immediate");
434 uint64_t Address,
const void *Decoder);
440 uint64_t Address,
const void *Decoder);
446#include "RISCVGenDisassemblerTables.inc"
475 fieldFromInstruction(
Insn, 12, 1) << 5 | fieldFromInstruction(
Insn, 2, 5);
477 decodeSImmOperand<6>(Inst, SImm6,
Address, Decoder);
488 fieldFromInstruction(
Insn, 12, 1) << 5 | fieldFromInstruction(
Insn, 2, 5);
490 decodeUImmOperand<6>(Inst, UImm6,
Address, Decoder);
527 decodeUImmOperand<2>(Inst, UImm2,
Address, Decoder);
532 bool IsWordOp = (Opcode == RISCV::TH_LWD || Opcode == RISCV::TH_LWUD ||
533 Opcode == RISCV::TH_SWD);
543 uint64_t Address,
const void *Decoder) {
560 uint64_t Address,
const void *Decoder) {
567void RISCVDisassembler::addSPOperands(
MCInst &
MI)
const {
570 if (MCID.
operands()[i].RegClass == RISCV::SPRegClassID)
574#define TRY_TO_DECODE_WITH_ADDITIONAL_OPERATION(FEATURE_CHECKS, DECODER_TABLE, \
575 DESC, ADDITIONAL_OPERATION) \
577 if (FEATURE_CHECKS) { \
578 LLVM_DEBUG(dbgs() << "Trying " DESC ":\n"); \
579 DecodeStatus Result = \
580 decodeInstruction(DECODER_TABLE, MI, Insn, Address, this, STI); \
581 if (Result != MCDisassembler::Fail) { \
582 ADDITIONAL_OPERATION; \
587#define TRY_TO_DECODE_AND_ADD_SP(FEATURE_CHECKS, DECODER_TABLE, DESC) \
588 TRY_TO_DECODE_WITH_ADDITIONAL_OPERATION(FEATURE_CHECKS, DECODER_TABLE, DESC, \
590#define TRY_TO_DECODE(FEATURE_CHECKS, DECODER_TABLE, DESC) \
591 TRY_TO_DECODE_WITH_ADDITIONAL_OPERATION(FEATURE_CHECKS, DECODER_TABLE, DESC, \
593#define TRY_TO_DECODE_FEATURE(FEATURE, DECODER_TABLE, DESC) \
594 TRY_TO_DECODE(STI.hasFeature(FEATURE), DECODER_TABLE, DESC)
600 if (Bytes.
size() < 4) {
609 !STI.hasFeature(RISCV::Feature64Bit),
610 DecoderTableRV32Zdinx32,
611 "RV32Zdinx table (Double in Integer and rv32)");
613 !STI.hasFeature(RISCV::Feature64Bit),
614 DecoderTableRV32Zacas32,
615 "RV32Zacas table (Compare-And-Swap and rv32)");
617 "RVZfinx table (Float in Integer)");
619 DecoderTableXVentana32,
"Ventana custom opcode table");
621 "XTHeadBa custom opcode table");
623 "XTHeadBb custom opcode table");
625 "XTHeadBs custom opcode table");
627 DecoderTableXTHeadCondMov32,
628 "XTHeadCondMov custom opcode table");
630 "XTHeadCmo custom opcode table");
632 DecoderTableXTHeadFMemIdx32,
633 "XTHeadFMemIdx custom opcode table");
635 "XTHeadMac custom opcode table");
637 DecoderTableXTHeadMemIdx32,
638 "XTHeadMemIdx custom opcode table");
640 DecoderTableXTHeadMemPair32,
641 "XTHeadMemPair custom opcode table");
643 DecoderTableXTHeadSync32,
644 "XTHeadSync custom opcode table");
646 DecoderTableXTHeadVdot32,
647 "XTHeadVdot custom opcode table");
649 "SiFive VCIX custom opcode table");
651 RISCV::FeatureVendorXSfvqmaccdod, DecoderTableXSfvqmaccdod32,
652 "SiFive Matrix Multiplication (2x8 and 8x2) Instruction opcode table");
654 RISCV::FeatureVendorXSfvqmaccqoq, DecoderTableXSfvqmaccqoq32,
655 "SiFive Matrix Multiplication (4x8 and 8x4) Instruction opcode table");
657 RISCV::FeatureVendorXSfvfwmaccqqq, DecoderTableXSfvfwmaccqqq32,
658 "SiFive Matrix Multiplication Instruction opcode table");
660 RISCV::FeatureVendorXSfvfnrclipxfqf, DecoderTableXSfvfnrclipxfqf32,
661 "SiFive FP32-to-int8 Ranged Clip Instructions opcode table");
663 DecoderTableXSiFivecdiscarddlone32,
664 "SiFive sf.cdiscard.d.l1 custom opcode table");
666 DecoderTableXSiFivecflushdlone32,
667 "SiFive sf.cflush.d.l1 custom opcode table");
669 "SiFive sf.cease custom opcode table");
671 DecoderTableXCVbitmanip32,
672 "CORE-V Bit Manipulation custom opcode table");
674 "CORE-V Event load custom opcode table");
676 "CORE-V MAC custom opcode table");
678 "CORE-V MEM custom opcode table");
680 "CORE-V ALU custom opcode table");
682 "CORE-V SIMD extensions custom opcode table");
684 "CORE-V Immediate Branching custom opcode table");
686 "Qualcomm uC CSR custom opcode table");
688 "Qualcomm uC Scaled Load Store custom opcode table");
690 "Qualcomm uC Arithmetic custom opcode table");
692 "Qualcomm uC Conditional Select custom opcode table");
694 "Qualcomm uC Load Store Multiple custom opcode table");
704 if (Bytes.
size() < 2) {
712 DecoderTableRISCV32Only_16,
713 "RISCV32Only_16 table (16-bit Instruction)");
715 "RVZicfiss table (Shadow Stack)");
717 "Zcmt table (16-bit Table Jump Instructions)");
719 RISCV::FeatureStdExtZcmp, DecoderTableRVZcmp16,
720 "Zcmp table (16-bit Push/Pop & Double Move Instructions)");
723 "WCH QingKe XW custom opcode table");
725 "RISCV_C table (16-bit Instruction)");
735 if ((Bytes[0] & 0b11) != 0b11)
736 return getInstruction16(
MI,
Size, Bytes, Address, CS);
740 if ((Bytes[0] & 0b1'1100) != 0b1'1100)
741 return getInstruction32(
MI,
Size, Bytes, Address, CS);
744 if ((Bytes[0] & 0b11'1111) == 0b01'1111) {
750 if ((Bytes[0] & 0b111'1111) == 0b011'1111) {
756 if (Bytes.
size() < 2) {
763 unsigned nnn = (Bytes[1] >> 4) & 0b111;
765 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 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.