aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-02-11 12:38:04 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-02-11 12:38:11 +0000
commite3b557809604d036af6e00c60f012c2025b59a5e (patch)
tree8a11ba2269a3b669601e2fd41145b174008f4da8 /llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp
parent08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff)
Diffstat (limited to 'llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp')
-rw-r--r--llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp347
1 files changed, 16 insertions, 331 deletions
diff --git a/llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp b/llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp
index 1825b95dd6ac..496c08f76a16 100644
--- a/llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp
+++ b/llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp
@@ -155,11 +155,15 @@ static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo,
static DecodeStatus DecodeI64RegsRegisterClass(MCInst &Inst, unsigned RegNo,
uint64_t Address,
const MCDisassembler *Decoder) {
- if (RegNo > 31)
- return MCDisassembler::Fail;
- unsigned Reg = IntRegDecoderTable[RegNo];
- Inst.addOperand(MCOperand::createReg(Reg));
- return MCDisassembler::Success;
+ return DecodeIntRegsRegisterClass(Inst, RegNo, Address, Decoder);
+}
+
+// This is used for the type "ptr_rc", which is either IntRegs or I64Regs
+// depending on SparcRegisterInfo::getPointerRegClass.
+static DecodeStatus DecodePointerLikeRegClass0(MCInst &Inst, unsigned RegNo,
+ uint64_t Address,
+ const MCDisassembler *Decoder) {
+ return DecodeIntRegsRegisterClass(Inst, RegNo, Address, Decoder);
}
static DecodeStatus DecodeFPRegsRegisterClass(MCInst &Inst, unsigned RegNo,
@@ -195,9 +199,9 @@ static DecodeStatus DecodeQFPRegsRegisterClass(MCInst &Inst, unsigned RegNo,
return MCDisassembler::Success;
}
-static DecodeStatus DecodeCPRegsRegisterClass(MCInst &Inst, unsigned RegNo,
- uint64_t Address,
- const MCDisassembler *Decoder) {
+static DecodeStatus
+DecodeCoprocRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address,
+ const MCDisassembler *Decoder) {
if (RegNo > 31)
return MCDisassembler::Fail;
unsigned Reg = CPRegDecoderTable[RegNo];
@@ -226,7 +230,7 @@ static DecodeStatus DecodeASRRegsRegisterClass(MCInst &Inst, unsigned RegNo,
static DecodeStatus DecodePRRegsRegisterClass(MCInst &Inst, unsigned RegNo,
uint64_t Address,
const MCDisassembler *Decoder) {
- if (RegNo >= array_lengthof(PRRegDecoderTable))
+ if (RegNo >= std::size(PRRegDecoderTable))
return MCDisassembler::Fail;
Inst.addOperand(MCOperand::createReg(PRRegDecoderTable[RegNo]));
return MCDisassembler::Success;
@@ -248,9 +252,9 @@ static DecodeStatus DecodeIntPairRegisterClass(MCInst &Inst, unsigned RegNo,
return S;
}
-static DecodeStatus DecodeCPPairRegisterClass(MCInst &Inst, unsigned RegNo,
- uint64_t Address,
- const MCDisassembler *Decoder) {
+static DecodeStatus
+DecodeCoprocPairRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address,
+ const MCDisassembler *Decoder) {
if (RegNo > 31)
return MCDisassembler::Fail;
@@ -259,53 +263,10 @@ static DecodeStatus DecodeCPPairRegisterClass(MCInst &Inst, unsigned RegNo,
return MCDisassembler::Success;
}
-static DecodeStatus DecodeLoadInt(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder);
-static DecodeStatus DecodeLoadIntPair(MCInst &Inst, unsigned insn,
- uint64_t Address,
- const MCDisassembler *Decoder);
-static DecodeStatus DecodeLoadFP(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder);
-static DecodeStatus DecodeLoadDFP(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder);
-static DecodeStatus DecodeLoadQFP(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder);
-static DecodeStatus DecodeLoadCP(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder);
-static DecodeStatus DecodeLoadCPPair(MCInst &Inst, unsigned insn,
- uint64_t Address,
- const MCDisassembler *Decoder);
-static DecodeStatus DecodeStoreInt(MCInst &Inst, unsigned insn,
- uint64_t Address,
- const MCDisassembler *Decoder);
-static DecodeStatus DecodeStoreIntPair(MCInst &Inst, unsigned insn,
- uint64_t Address,
- const MCDisassembler *Decoder);
-static DecodeStatus DecodeStoreFP(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder);
-static DecodeStatus DecodeStoreDFP(MCInst &Inst, unsigned insn,
- uint64_t Address,
- const MCDisassembler *Decoder);
-static DecodeStatus DecodeStoreQFP(MCInst &Inst, unsigned insn,
- uint64_t Address,
- const MCDisassembler *Decoder);
-static DecodeStatus DecodeStoreCP(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder);
-static DecodeStatus DecodeStoreCPPair(MCInst &Inst, unsigned insn,
- uint64_t Address,
- const MCDisassembler *Decoder);
static DecodeStatus DecodeCall(MCInst &Inst, unsigned insn, uint64_t Address,
const MCDisassembler *Decoder);
static DecodeStatus DecodeSIMM13(MCInst &Inst, unsigned insn, uint64_t Address,
const MCDisassembler *Decoder);
-static DecodeStatus DecodeJMPL(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder);
-static DecodeStatus DecodeReturn(MCInst &MI, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder);
-static DecodeStatus DecodeSWAP(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder);
-static DecodeStatus DecodeTRAP(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder);
#include "SparcGenDisassemblerTables.inc"
@@ -363,147 +324,6 @@ DecodeStatus SparcDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,
return MCDisassembler::Fail;
}
-typedef DecodeStatus (*DecodeFunc)(MCInst &MI, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder);
-
-static DecodeStatus DecodeMem(MCInst &MI, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder, bool isLoad,
- DecodeFunc DecodeRD) {
- unsigned rd = fieldFromInstruction(insn, 25, 5);
- unsigned rs1 = fieldFromInstruction(insn, 14, 5);
- bool isImm = fieldFromInstruction(insn, 13, 1);
- bool hasAsi = fieldFromInstruction(insn, 23, 1); // (in op3 field)
- unsigned asi = fieldFromInstruction(insn, 5, 8);
- unsigned rs2 = 0;
- unsigned simm13 = 0;
- if (isImm)
- simm13 = SignExtend32<13>(fieldFromInstruction(insn, 0, 13));
- else
- rs2 = fieldFromInstruction(insn, 0, 5);
-
- DecodeStatus status;
- if (isLoad) {
- status = DecodeRD(MI, rd, Address, Decoder);
- if (status != MCDisassembler::Success)
- return status;
- }
-
- // Decode rs1.
- status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);
- if (status != MCDisassembler::Success)
- return status;
-
- // Decode imm|rs2.
- if (isImm)
- MI.addOperand(MCOperand::createImm(simm13));
- else {
- status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);
- if (status != MCDisassembler::Success)
- return status;
- }
-
- if (hasAsi)
- MI.addOperand(MCOperand::createImm(asi));
-
- if (!isLoad) {
- status = DecodeRD(MI, rd, Address, Decoder);
- if (status != MCDisassembler::Success)
- return status;
- }
- return MCDisassembler::Success;
-}
-
-static DecodeStatus DecodeLoadInt(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder) {
- return DecodeMem(Inst, insn, Address, Decoder, true,
- DecodeIntRegsRegisterClass);
-}
-
-static DecodeStatus DecodeLoadIntPair(MCInst &Inst, unsigned insn,
- uint64_t Address,
- const MCDisassembler *Decoder) {
- return DecodeMem(Inst, insn, Address, Decoder, true,
- DecodeIntPairRegisterClass);
-}
-
-static DecodeStatus DecodeLoadFP(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder) {
- return DecodeMem(Inst, insn, Address, Decoder, true,
- DecodeFPRegsRegisterClass);
-}
-
-static DecodeStatus DecodeLoadDFP(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder) {
- return DecodeMem(Inst, insn, Address, Decoder, true,
- DecodeDFPRegsRegisterClass);
-}
-
-static DecodeStatus DecodeLoadQFP(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder) {
- return DecodeMem(Inst, insn, Address, Decoder, true,
- DecodeQFPRegsRegisterClass);
-}
-
-static DecodeStatus DecodeLoadCP(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder) {
- return DecodeMem(Inst, insn, Address, Decoder, true,
- DecodeCPRegsRegisterClass);
-}
-
-static DecodeStatus DecodeLoadCPPair(MCInst &Inst, unsigned insn,
- uint64_t Address,
- const MCDisassembler *Decoder) {
- return DecodeMem(Inst, insn, Address, Decoder, true,
- DecodeCPPairRegisterClass);
-}
-
-static DecodeStatus DecodeStoreInt(MCInst &Inst, unsigned insn,
- uint64_t Address,
- const MCDisassembler *Decoder) {
- return DecodeMem(Inst, insn, Address, Decoder, false,
- DecodeIntRegsRegisterClass);
-}
-
-static DecodeStatus DecodeStoreIntPair(MCInst &Inst, unsigned insn,
- uint64_t Address,
- const MCDisassembler *Decoder) {
- return DecodeMem(Inst, insn, Address, Decoder, false,
- DecodeIntPairRegisterClass);
-}
-
-static DecodeStatus DecodeStoreFP(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder) {
- return DecodeMem(Inst, insn, Address, Decoder, false,
- DecodeFPRegsRegisterClass);
-}
-
-static DecodeStatus DecodeStoreDFP(MCInst &Inst, unsigned insn,
- uint64_t Address,
- const MCDisassembler *Decoder) {
- return DecodeMem(Inst, insn, Address, Decoder, false,
- DecodeDFPRegsRegisterClass);
-}
-
-static DecodeStatus DecodeStoreQFP(MCInst &Inst, unsigned insn,
- uint64_t Address,
- const MCDisassembler *Decoder) {
- return DecodeMem(Inst, insn, Address, Decoder, false,
- DecodeQFPRegsRegisterClass);
-}
-
-static DecodeStatus DecodeStoreCP(MCInst &Inst, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder) {
- return DecodeMem(Inst, insn, Address, Decoder, false,
- DecodeCPRegsRegisterClass);
-}
-
-static DecodeStatus DecodeStoreCPPair(MCInst &Inst, unsigned insn,
- uint64_t Address,
- const MCDisassembler *Decoder) {
- return DecodeMem(Inst, insn, Address, Decoder, false,
- DecodeCPPairRegisterClass);
-}
-
static bool tryAddingSymbolicOperand(int64_t Value, bool isBranch,
uint64_t Address, uint64_t Offset,
uint64_t Width, MCInst &MI,
@@ -528,138 +348,3 @@ static DecodeStatus DecodeSIMM13(MCInst &MI, unsigned insn, uint64_t Address,
MI.addOperand(MCOperand::createImm(tgt));
return MCDisassembler::Success;
}
-
-static DecodeStatus DecodeJMPL(MCInst &MI, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder) {
-
- unsigned rd = fieldFromInstruction(insn, 25, 5);
- unsigned rs1 = fieldFromInstruction(insn, 14, 5);
- unsigned isImm = fieldFromInstruction(insn, 13, 1);
- unsigned rs2 = 0;
- unsigned simm13 = 0;
- if (isImm)
- simm13 = SignExtend32<13>(fieldFromInstruction(insn, 0, 13));
- else
- rs2 = fieldFromInstruction(insn, 0, 5);
-
- // Decode RD.
- DecodeStatus status = DecodeIntRegsRegisterClass(MI, rd, Address, Decoder);
- if (status != MCDisassembler::Success)
- return status;
-
- // Decode RS1.
- status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);
- if (status != MCDisassembler::Success)
- return status;
-
- // Decode RS1 | SIMM13.
- if (isImm)
- MI.addOperand(MCOperand::createImm(simm13));
- else {
- status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);
- if (status != MCDisassembler::Success)
- return status;
- }
- return MCDisassembler::Success;
-}
-
-static DecodeStatus DecodeReturn(MCInst &MI, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder) {
-
- unsigned rs1 = fieldFromInstruction(insn, 14, 5);
- unsigned isImm = fieldFromInstruction(insn, 13, 1);
- unsigned rs2 = 0;
- unsigned simm13 = 0;
- if (isImm)
- simm13 = SignExtend32<13>(fieldFromInstruction(insn, 0, 13));
- else
- rs2 = fieldFromInstruction(insn, 0, 5);
-
- // Decode RS1.
- DecodeStatus status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);
- if (status != MCDisassembler::Success)
- return status;
-
- // Decode RS2 | SIMM13.
- if (isImm)
- MI.addOperand(MCOperand::createImm(simm13));
- else {
- status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);
- if (status != MCDisassembler::Success)
- return status;
- }
- return MCDisassembler::Success;
-}
-
-static DecodeStatus DecodeSWAP(MCInst &MI, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder) {
-
- unsigned rd = fieldFromInstruction(insn, 25, 5);
- unsigned rs1 = fieldFromInstruction(insn, 14, 5);
- unsigned isImm = fieldFromInstruction(insn, 13, 1);
- bool hasAsi = fieldFromInstruction(insn, 23, 1); // (in op3 field)
- unsigned asi = fieldFromInstruction(insn, 5, 8);
- unsigned rs2 = 0;
- unsigned simm13 = 0;
- if (isImm)
- simm13 = SignExtend32<13>(fieldFromInstruction(insn, 0, 13));
- else
- rs2 = fieldFromInstruction(insn, 0, 5);
-
- // Decode RD.
- DecodeStatus status = DecodeIntRegsRegisterClass(MI, rd, Address, Decoder);
- if (status != MCDisassembler::Success)
- return status;
-
- // Decode RS1.
- status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);
- if (status != MCDisassembler::Success)
- return status;
-
- // Decode RS1 | SIMM13.
- if (isImm)
- MI.addOperand(MCOperand::createImm(simm13));
- else {
- status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);
- if (status != MCDisassembler::Success)
- return status;
- }
-
- if (hasAsi)
- MI.addOperand(MCOperand::createImm(asi));
-
- return MCDisassembler::Success;
-}
-
-static DecodeStatus DecodeTRAP(MCInst &MI, unsigned insn, uint64_t Address,
- const MCDisassembler *Decoder) {
-
- unsigned rs1 = fieldFromInstruction(insn, 14, 5);
- unsigned isImm = fieldFromInstruction(insn, 13, 1);
- unsigned cc =fieldFromInstruction(insn, 25, 4);
- unsigned rs2 = 0;
- unsigned imm7 = 0;
- if (isImm)
- imm7 = fieldFromInstruction(insn, 0, 7);
- else
- rs2 = fieldFromInstruction(insn, 0, 5);
-
- // Decode RS1.
- DecodeStatus status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);
- if (status != MCDisassembler::Success)
- return status;
-
- // Decode RS1 | IMM7.
- if (isImm)
- MI.addOperand(MCOperand::createImm(imm7));
- else {
- status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);
- if (status != MCDisassembler::Success)
- return status;
- }
-
- // Decode CC
- MI.addOperand(MCOperand::createImm(cc));
-
- return MCDisassembler::Success;
-}