diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Target/AVR/Disassembler/AVRDisassembler.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Target/AVR/Disassembler/AVRDisassembler.cpp | 137 |
1 files changed, 76 insertions, 61 deletions
diff --git a/contrib/llvm-project/llvm/lib/Target/AVR/Disassembler/AVRDisassembler.cpp b/contrib/llvm-project/llvm/lib/Target/AVR/Disassembler/AVRDisassembler.cpp index 8e7251a74dfd..9dcd370b9f1e 100644 --- a/contrib/llvm-project/llvm/lib/Target/AVR/Disassembler/AVRDisassembler.cpp +++ b/contrib/llvm-project/llvm/lib/Target/AVR/Disassembler/AVRDisassembler.cpp @@ -21,7 +21,7 @@ #include "llvm/MC/MCDisassembler/MCDisassembler.h" #include "llvm/MC/MCFixedLenDisassembler.h" #include "llvm/MC/MCInst.h" -#include "llvm/Support/TargetRegistry.h" +#include "llvm/MC/TargetRegistry.h" using namespace llvm; @@ -42,7 +42,7 @@ public: ArrayRef<uint8_t> Bytes, uint64_t Address, raw_ostream &CStream) const override; }; -} +} // namespace static MCDisassembler *createAVRDisassembler(const Target &T, const MCSubtargetInfo &STI, @@ -50,7 +50,6 @@ static MCDisassembler *createAVRDisassembler(const Target &T, return new AVRDisassembler(STI, Ctx); } - extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAVRDisassembler() { // Register the disassembler. TargetRegistry::RegisterMCDisassembler(getTheAVRTarget(), @@ -58,18 +57,16 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAVRDisassembler() { } static const uint16_t GPRDecoderTable[] = { - AVR::R0, AVR::R1, AVR::R2, AVR::R3, - AVR::R4, AVR::R5, AVR::R6, AVR::R7, - AVR::R8, AVR::R9, AVR::R10, AVR::R11, - AVR::R12, AVR::R13, AVR::R14, AVR::R15, - AVR::R16, AVR::R17, AVR::R18, AVR::R19, - AVR::R20, AVR::R21, AVR::R22, AVR::R23, - AVR::R24, AVR::R25, AVR::R26, AVR::R27, - AVR::R28, AVR::R29, AVR::R30, AVR::R31, + AVR::R0, AVR::R1, AVR::R2, AVR::R3, AVR::R4, AVR::R5, AVR::R6, + AVR::R7, AVR::R8, AVR::R9, AVR::R10, AVR::R11, AVR::R12, AVR::R13, + AVR::R14, AVR::R15, AVR::R16, AVR::R17, AVR::R18, AVR::R19, AVR::R20, + AVR::R21, AVR::R22, AVR::R23, AVR::R24, AVR::R25, AVR::R26, AVR::R27, + AVR::R28, AVR::R29, AVR::R30, AVR::R31, }; static DecodeStatus DecodeGPR8RegisterClass(MCInst &Inst, unsigned RegNo, - uint64_t Address, const void *Decoder) { + uint64_t Address, + const void *Decoder) { if (RegNo > 31) return MCDisassembler::Fail; @@ -79,39 +76,41 @@ static DecodeStatus DecodeGPR8RegisterClass(MCInst &Inst, unsigned RegNo, } static DecodeStatus DecodeLD8RegisterClass(MCInst &Inst, unsigned RegNo, - uint64_t Address, const void *Decoder) { + uint64_t Address, + const void *Decoder) { if (RegNo > 15) return MCDisassembler::Fail; - unsigned Register = GPRDecoderTable[RegNo+16]; + unsigned Register = GPRDecoderTable[RegNo + 16]; Inst.addOperand(MCOperand::createReg(Register)); return MCDisassembler::Success; } static DecodeStatus DecodePTRREGSRegisterClass(MCInst &Inst, unsigned RegNo, - uint64_t Address, const void *Decoder) { + uint64_t Address, + const void *Decoder) { // Note: this function must be defined but does not seem to be called. assert(false && "unimplemented: PTRREGS register class"); return MCDisassembler::Success; } -static DecodeStatus decodeFIOARr(MCInst &Inst, unsigned Insn, - uint64_t Address, const void *Decoder); +static DecodeStatus decodeFIOARr(MCInst &Inst, unsigned Insn, uint64_t Address, + const void *Decoder); -static DecodeStatus decodeFIORdA(MCInst &Inst, unsigned Insn, - uint64_t Address, const void *Decoder); +static DecodeStatus decodeFIORdA(MCInst &Inst, unsigned Insn, uint64_t Address, + const void *Decoder); -static DecodeStatus decodeFIOBIT(MCInst &Inst, unsigned Insn, - uint64_t Address, const void *Decoder); +static DecodeStatus decodeFIOBIT(MCInst &Inst, unsigned Insn, uint64_t Address, + const void *Decoder); static DecodeStatus decodeCallTarget(MCInst &Inst, unsigned Insn, uint64_t Address, const void *Decoder); -static DecodeStatus decodeFRd(MCInst &Inst, unsigned Insn, - uint64_t Address, const void *Decoder); +static DecodeStatus decodeFRd(MCInst &Inst, unsigned Insn, uint64_t Address, + const void *Decoder); -static DecodeStatus decodeFLPMX(MCInst &Inst, unsigned Insn, - uint64_t Address, const void *Decoder); +static DecodeStatus decodeFLPMX(MCInst &Inst, unsigned Insn, uint64_t Address, + const void *Decoder); static DecodeStatus decodeFFMULRdRr(MCInst &Inst, unsigned Insn, uint64_t Address, const void *Decoder); @@ -119,40 +118,42 @@ static DecodeStatus decodeFFMULRdRr(MCInst &Inst, unsigned Insn, static DecodeStatus decodeFMOVWRdRr(MCInst &Inst, unsigned Insn, uint64_t Address, const void *Decoder); -static DecodeStatus decodeFWRdK(MCInst &Inst, unsigned Insn, - uint64_t Address, const void *Decoder); +static DecodeStatus decodeFWRdK(MCInst &Inst, unsigned Insn, uint64_t Address, + const void *Decoder); static DecodeStatus decodeFMUL2RdRr(MCInst &Inst, unsigned Insn, uint64_t Address, const void *Decoder); #include "AVRGenDisassemblerTables.inc" -static DecodeStatus decodeFIOARr(MCInst &Inst, unsigned Insn, - uint64_t Address, const void *Decoder) { +static DecodeStatus decodeFIOARr(MCInst &Inst, unsigned Insn, uint64_t Address, + const void *Decoder) { unsigned addr = 0; addr |= fieldFromInstruction(Insn, 0, 4); addr |= fieldFromInstruction(Insn, 9, 2) << 4; unsigned reg = fieldFromInstruction(Insn, 4, 5); Inst.addOperand(MCOperand::createImm(addr)); - if (DecodeGPR8RegisterClass(Inst, reg, Address, Decoder) == MCDisassembler::Fail) + if (DecodeGPR8RegisterClass(Inst, reg, Address, Decoder) == + MCDisassembler::Fail) return MCDisassembler::Fail; return MCDisassembler::Success; } -static DecodeStatus decodeFIORdA(MCInst &Inst, unsigned Insn, - uint64_t Address, const void *Decoder) { +static DecodeStatus decodeFIORdA(MCInst &Inst, unsigned Insn, uint64_t Address, + const void *Decoder) { unsigned addr = 0; addr |= fieldFromInstruction(Insn, 0, 4); addr |= fieldFromInstruction(Insn, 9, 2) << 4; unsigned reg = fieldFromInstruction(Insn, 4, 5); - if (DecodeGPR8RegisterClass(Inst, reg, Address, Decoder) == MCDisassembler::Fail) + if (DecodeGPR8RegisterClass(Inst, reg, Address, Decoder) == + MCDisassembler::Fail) return MCDisassembler::Fail; Inst.addOperand(MCOperand::createImm(addr)); return MCDisassembler::Success; } -static DecodeStatus decodeFIOBIT(MCInst &Inst, unsigned Insn, - uint64_t Address, const void *Decoder) { +static DecodeStatus decodeFIOBIT(MCInst &Inst, unsigned Insn, uint64_t Address, + const void *Decoder) { unsigned addr = fieldFromInstruction(Insn, 3, 5); unsigned b = fieldFromInstruction(Insn, 0, 3); Inst.addOperand(MCOperand::createImm(addr)); @@ -168,16 +169,17 @@ static DecodeStatus decodeCallTarget(MCInst &Inst, unsigned Field, return MCDisassembler::Success; } -static DecodeStatus decodeFRd(MCInst &Inst, unsigned Insn, - uint64_t Address, const void *Decoder) { +static DecodeStatus decodeFRd(MCInst &Inst, unsigned Insn, uint64_t Address, + const void *Decoder) { unsigned d = fieldFromInstruction(Insn, 4, 5); - if (DecodeGPR8RegisterClass(Inst, d, Address, Decoder) == MCDisassembler::Fail) + if (DecodeGPR8RegisterClass(Inst, d, Address, Decoder) == + MCDisassembler::Fail) return MCDisassembler::Fail; return MCDisassembler::Success; } -static DecodeStatus decodeFLPMX(MCInst &Inst, unsigned Insn, - uint64_t Address, const void *Decoder) { +static DecodeStatus decodeFLPMX(MCInst &Inst, unsigned Insn, uint64_t Address, + const void *Decoder) { if (decodeFRd(Inst, Insn, Address, Decoder) == MCDisassembler::Fail) return MCDisassembler::Fail; Inst.addOperand(MCOperand::createReg(AVR::R31R30)); @@ -188,9 +190,11 @@ static DecodeStatus decodeFFMULRdRr(MCInst &Inst, unsigned Insn, uint64_t Address, const void *Decoder) { unsigned d = fieldFromInstruction(Insn, 4, 3) + 16; unsigned r = fieldFromInstruction(Insn, 0, 3) + 16; - if (DecodeGPR8RegisterClass(Inst, d, Address, Decoder) == MCDisassembler::Fail) + if (DecodeGPR8RegisterClass(Inst, d, Address, Decoder) == + MCDisassembler::Fail) return MCDisassembler::Fail; - if (DecodeGPR8RegisterClass(Inst, r, Address, Decoder) == MCDisassembler::Fail) + if (DecodeGPR8RegisterClass(Inst, r, Address, Decoder) == + MCDisassembler::Fail) return MCDisassembler::Fail; return MCDisassembler::Success; } @@ -199,22 +203,26 @@ static DecodeStatus decodeFMOVWRdRr(MCInst &Inst, unsigned Insn, uint64_t Address, const void *Decoder) { unsigned r = fieldFromInstruction(Insn, 4, 4) * 2; unsigned d = fieldFromInstruction(Insn, 0, 4) * 2; - if (DecodeGPR8RegisterClass(Inst, r, Address, Decoder) == MCDisassembler::Fail) + if (DecodeGPR8RegisterClass(Inst, r, Address, Decoder) == + MCDisassembler::Fail) return MCDisassembler::Fail; - if (DecodeGPR8RegisterClass(Inst, d, Address, Decoder) == MCDisassembler::Fail) + if (DecodeGPR8RegisterClass(Inst, d, Address, Decoder) == + MCDisassembler::Fail) return MCDisassembler::Fail; return MCDisassembler::Success; } -static DecodeStatus decodeFWRdK(MCInst &Inst, unsigned Insn, - uint64_t Address, const void *Decoder) { +static DecodeStatus decodeFWRdK(MCInst &Inst, unsigned Insn, uint64_t Address, + const void *Decoder) { unsigned d = fieldFromInstruction(Insn, 4, 2) * 2 + 24; // starts at r24:r25 unsigned k = 0; k |= fieldFromInstruction(Insn, 0, 4); k |= fieldFromInstruction(Insn, 6, 2) << 4; - if (DecodeGPR8RegisterClass(Inst, d, Address, Decoder) == MCDisassembler::Fail) + if (DecodeGPR8RegisterClass(Inst, d, Address, Decoder) == + MCDisassembler::Fail) return MCDisassembler::Fail; - if (DecodeGPR8RegisterClass(Inst, d, Address, Decoder) == MCDisassembler::Fail) + if (DecodeGPR8RegisterClass(Inst, d, Address, Decoder) == + MCDisassembler::Fail) return MCDisassembler::Fail; Inst.addOperand(MCOperand::createImm(k)); return MCDisassembler::Success; @@ -224,9 +232,11 @@ static DecodeStatus decodeFMUL2RdRr(MCInst &Inst, unsigned Insn, uint64_t Address, const void *Decoder) { unsigned rd = fieldFromInstruction(Insn, 4, 4) + 16; unsigned rr = fieldFromInstruction(Insn, 0, 4) + 16; - if (DecodeGPR8RegisterClass(Inst, rd, Address, Decoder) == MCDisassembler::Fail) + if (DecodeGPR8RegisterClass(Inst, rd, Address, Decoder) == + MCDisassembler::Fail) return MCDisassembler::Fail; - if (DecodeGPR8RegisterClass(Inst, rr, Address, Decoder) == MCDisassembler::Fail) + if (DecodeGPR8RegisterClass(Inst, rr, Address, Decoder) == + MCDisassembler::Fail) return MCDisassembler::Fail; return MCDisassembler::Success; } @@ -253,7 +263,8 @@ static DecodeStatus readInstruction32(ArrayRef<uint8_t> Bytes, uint64_t Address, } Size = 4; - Insn = (Bytes[0] << 16) | (Bytes[1] << 24) | (Bytes[2] << 0) | (Bytes[3] << 8); + Insn = + (Bytes[0] << 16) | (Bytes[1] << 24) | (Bytes[2] << 0) | (Bytes[3] << 8); return MCDisassembler::Success; } @@ -261,9 +272,12 @@ static DecodeStatus readInstruction32(ArrayRef<uint8_t> Bytes, uint64_t Address, static const uint8_t *getDecoderTable(uint64_t Size) { switch (Size) { - case 2: return DecoderTable16; - case 4: return DecoderTable32; - default: llvm_unreachable("instructions must be 16 or 32-bits"); + case 2: + return DecoderTable16; + case 4: + return DecoderTable32; + default: + llvm_unreachable("instructions must be 16 or 32-bits"); } } @@ -279,11 +293,12 @@ DecodeStatus AVRDisassembler::getInstruction(MCInst &Instr, uint64_t &Size, { Result = readInstruction16(Bytes, Address, Size, Insn); - if (Result == MCDisassembler::Fail) return MCDisassembler::Fail; + if (Result == MCDisassembler::Fail) + return MCDisassembler::Fail; // Try to auto-decode a 16-bit instruction. - Result = decodeInstruction(getDecoderTable(Size), Instr, - Insn, Address, this, STI); + Result = decodeInstruction(getDecoderTable(Size), Instr, Insn, Address, + this, STI); if (Result != MCDisassembler::Fail) return Result; @@ -293,10 +308,11 @@ DecodeStatus AVRDisassembler::getInstruction(MCInst &Instr, uint64_t &Size, { Result = readInstruction32(Bytes, Address, Size, Insn); - if (Result == MCDisassembler::Fail) return MCDisassembler::Fail; + if (Result == MCDisassembler::Fail) + return MCDisassembler::Fail; - Result = decodeInstruction(getDecoderTable(Size), Instr, Insn, - Address, this, STI); + Result = decodeInstruction(getDecoderTable(Size), Instr, Insn, Address, + this, STI); if (Result != MCDisassembler::Fail) { return Result; @@ -308,4 +324,3 @@ DecodeStatus AVRDisassembler::getInstruction(MCInst &Instr, uint64_t &Size, typedef DecodeStatus (*DecodeFunc)(MCInst &MI, unsigned insn, uint64_t Address, const void *Decoder); - |