Skip to content

Commit eaf2f40

Browse files
maciej-czekajgerekon
authored andcommitted
[Xtensa] Add support for decoding from HIFI namespace
1 parent e22c1ad commit eaf2f40

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

llvm/lib/Target/Xtensa/Disassembler/XtensaDisassembler.cpp

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ class XtensaDisassembler : public MCDisassembler {
4444

4545
bool hasESP32S3Ops() const {
4646
return STI.getFeatureBits()[Xtensa::FeatureESP32S3Ops];
47+
48+
}
49+
50+
bool hasHIFI3() const {
51+
return STI.getFeatureBits()[Xtensa::FeatureHIFI3];
4752
}
4853

4954
DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
@@ -832,7 +837,7 @@ static DecodeStatus decodeMem32nOperand(MCInst &Inst, uint64_t Imm,
832837
/// Read two bytes from the ArrayRef and return 16 bit data sorted
833838
/// according to the given endianness.
834839
static DecodeStatus readInstruction16(ArrayRef<uint8_t> Bytes, uint64_t Address,
835-
uint64_t &Size, uint32_t &Insn,
840+
uint64_t &Size, uint64_t &Insn,
836841
bool IsLittleEndian) {
837842
// We want to read exactly 2 Bytes of data.
838843
if (Bytes.size() < 2) {
@@ -851,7 +856,7 @@ static DecodeStatus readInstruction16(ArrayRef<uint8_t> Bytes, uint64_t Address,
851856

852857
/// Read three bytes from the ArrayRef and return 24 bit data
853858
static DecodeStatus readInstruction24(ArrayRef<uint8_t> Bytes, uint64_t Address,
854-
uint64_t &Size, uint32_t &Insn,
859+
uint64_t &Size, uint64_t &Insn,
855860
bool IsLittleEndian) {
856861
// We want to read exactly 3 Bytes of data.
857862
if (Bytes.size() < 3) {
@@ -870,7 +875,7 @@ static DecodeStatus readInstruction24(ArrayRef<uint8_t> Bytes, uint64_t Address,
870875

871876
/// Read three bytes from the ArrayRef and return 32 bit data
872877
static DecodeStatus readInstruction32(ArrayRef<uint8_t> Bytes, uint64_t Address,
873-
uint64_t &Size, uint32_t &Insn,
878+
uint64_t &Size, uint64_t &Insn,
874879
bool IsLittleEndian) {
875880
// We want to read exactly 4 Bytes of data.
876881
if (Bytes.size() < 4) {
@@ -887,13 +892,37 @@ static DecodeStatus readInstruction32(ArrayRef<uint8_t> Bytes, uint64_t Address,
887892
return MCDisassembler::Success;
888893
}
889894

895+
/// Read InstSize bytes from the ArrayRef and return 24 bit data
896+
static DecodeStatus readInstructionN(ArrayRef<uint8_t> Bytes, uint64_t Address,
897+
unsigned InstSize,
898+
uint64_t &Size, uint64_t &Insn,
899+
bool IsLittleEndian) {
900+
// We want to read exactly 3 Bytes of data.
901+
if (Bytes.size() < InstSize) {
902+
Size = 0;
903+
return MCDisassembler::Fail;
904+
}
905+
906+
if (!IsLittleEndian) {
907+
report_fatal_error("Big-endian mode currently is not supported!");
908+
} else {
909+
Insn = 0;
910+
for (unsigned i = 0; i < InstSize; i++)
911+
Insn |= (Bytes[i] << 8*i);
912+
}
913+
914+
Size = InstSize;
915+
return MCDisassembler::Success;
916+
}
917+
918+
890919
#include "XtensaGenDisassemblerTables.inc"
891920

892921
DecodeStatus XtensaDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
893922
ArrayRef<uint8_t> Bytes,
894923
uint64_t Address,
895924
raw_ostream &CS) const {
896-
uint32_t Insn;
925+
uint64_t Insn;
897926
DecodeStatus Result;
898927

899928
// Parse 16-bit instructions
@@ -946,5 +975,20 @@ DecodeStatus XtensaDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
946975
}
947976
}
948977

978+
if (hasHIFI3()) {
979+
LLVM_DEBUG(dbgs() << "Trying Xtensa HIFI3 24-bit instruction table :\n");
980+
Result = decodeInstruction(DecoderTableHIFI324, MI, Insn, Address, this, STI);
981+
if(Result != MCDisassembler::Fail)
982+
return Result;
983+
984+
Result = readInstructionN(Bytes, Address, 48, Size, Insn, IsLittleEndian);
985+
if (Result == MCDisassembler::Fail)
986+
return MCDisassembler::Fail;
987+
988+
LLVM_DEBUG(dbgs() << "Trying Xtensa HIFI3 48-bit instruction table :\n");
989+
Result = decodeInstruction(DecoderTableHIFI348, MI, Insn, Address, this, STI);
990+
if(Result != MCDisassembler::Fail)
991+
return Result;
992+
}
949993
return Result;
950994
}

0 commit comments

Comments
 (0)