Skip to content

Commit c48ffc9

Browse files
committed
[Xtensa] ESP32S3 TIE fix format_32 encoding and disassembler
ambiguities between x24 and format_32 encoding.
1 parent 61a7491 commit c48ffc9

File tree

4 files changed

+1916
-853
lines changed

4 files changed

+1916
-853
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ static DecodeStatus readInstruction16(ArrayRef<uint8_t> Bytes, uint64_t Address,
865865
/// Read three bytes from the ArrayRef and return 24 bit data
866866
static DecodeStatus readInstruction24(ArrayRef<uint8_t> Bytes, uint64_t Address,
867867
uint64_t &Size, uint64_t &Insn,
868-
bool IsLittleEndian) {
868+
bool IsLittleEndian, bool CheckTIE = false) {
869869
// We want to read exactly 3 Bytes of data.
870870
if (Bytes.size() < 3) {
871871
Size = 0;
@@ -875,6 +875,8 @@ static DecodeStatus readInstruction24(ArrayRef<uint8_t> Bytes, uint64_t Address,
875875
if (!IsLittleEndian) {
876876
report_fatal_error("Big-endian mode currently is not supported!");
877877
} else {
878+
if (CheckTIE && (Bytes[0] & 0x8) != 0)
879+
return MCDisassembler::Fail;
878880
Insn = (Bytes[2] << 16) | (Bytes[1] << 8) | (Bytes[0] << 0);
879881
}
880882

@@ -894,6 +896,8 @@ static DecodeStatus readInstruction32(ArrayRef<uint8_t> Bytes, uint64_t Address,
894896
if (!IsLittleEndian) {
895897
report_fatal_error("Big-endian mode currently is not supported!");
896898
} else {
899+
if ((Bytes[0] & 0x8) == 0)
900+
return MCDisassembler::Fail;
897901
Insn = (Bytes[3] << 24) | (Bytes[2] << 16) | (Bytes[1] << 8) | (Bytes[0] << 0);
898902
}
899903

@@ -959,15 +963,15 @@ DecodeStatus XtensaDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
959963

960964
if (hasESP32S3Ops()) {
961965
// Parse ESP32S3 24-bit instructions
962-
Result = readInstruction24(Bytes, Address, Size, Insn, IsLittleEndian);
963-
if (Result == MCDisassembler::Fail)
964-
return MCDisassembler::Fail;
965-
LLVM_DEBUG(dbgs() << "Trying ESP32S3 table (24-bit opcodes):\n");
966-
Result = decodeInstruction(DecoderTableESP32S324, MI, Insn,
967-
Address, this, STI);
966+
Result = readInstruction24(Bytes, Address, Size, Insn, IsLittleEndian, true);
968967
if (Result != MCDisassembler::Fail) {
969-
Size = 3;
970-
return Result;
968+
LLVM_DEBUG(dbgs() << "Trying ESP32S3 table (24-bit opcodes):\n");
969+
Result = decodeInstruction(DecoderTableESP32S324, MI, Insn, Address, this,
970+
STI);
971+
if (Result != MCDisassembler::Fail) {
972+
Size = 3;
973+
return Result;
974+
}
971975
}
972976

973977
// Parse ESP32S3 32-bit instructions

0 commit comments

Comments
 (0)