Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 1 | //===- SparcDisassembler.cpp - Disassembler for Sparc -----------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file is part of the Sparc Disassembler. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 14 | #include "Sparc.h" |
| 15 | #include "SparcRegisterInfo.h" |
| 16 | #include "SparcSubtarget.h" |
| 17 | #include "llvm/MC/MCDisassembler.h" |
| 18 | #include "llvm/MC/MCFixedLenDisassembler.h" |
Pete Cooper | 3de83e4 | 2015-05-15 21:58:42 +0000 | [diff] [blame^] | 19 | #include "llvm/MC/MCInst.h" |
Douglas Katzman | 9160e78 | 2015-04-29 20:30:57 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCContext.h" |
| 21 | #include "llvm/MC/MCAsmInfo.h" |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 22 | #include "llvm/Support/TargetRegistry.h" |
| 23 | |
| 24 | using namespace llvm; |
| 25 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 26 | #define DEBUG_TYPE "sparc-disassembler" |
| 27 | |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 28 | typedef MCDisassembler::DecodeStatus DecodeStatus; |
| 29 | |
| 30 | namespace { |
| 31 | |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 32 | /// A disassembler class for Sparc. |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 33 | class SparcDisassembler : public MCDisassembler { |
| 34 | public: |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 35 | SparcDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx) |
| 36 | : MCDisassembler(STI, Ctx) {} |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 37 | virtual ~SparcDisassembler() {} |
| 38 | |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 39 | DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 40 | ArrayRef<uint8_t> Bytes, uint64_t Address, |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 41 | raw_ostream &VStream, |
| 42 | raw_ostream &CStream) const override; |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 43 | }; |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | namespace llvm { |
Douglas Katzman | 9160e78 | 2015-04-29 20:30:57 +0000 | [diff] [blame] | 47 | extern Target TheSparcTarget, TheSparcV9Target, TheSparcelTarget; |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Douglas Katzman | 9160e78 | 2015-04-29 20:30:57 +0000 | [diff] [blame] | 50 | static MCDisassembler *createSparcDisassembler(const Target &T, |
| 51 | const MCSubtargetInfo &STI, |
| 52 | MCContext &Ctx) { |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 53 | return new SparcDisassembler(STI, Ctx); |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | |
| 57 | extern "C" void LLVMInitializeSparcDisassembler() { |
| 58 | // Register the disassembler. |
| 59 | TargetRegistry::RegisterMCDisassembler(TheSparcTarget, |
| 60 | createSparcDisassembler); |
| 61 | TargetRegistry::RegisterMCDisassembler(TheSparcV9Target, |
| 62 | createSparcDisassembler); |
Douglas Katzman | 9160e78 | 2015-04-29 20:30:57 +0000 | [diff] [blame] | 63 | TargetRegistry::RegisterMCDisassembler(TheSparcelTarget, |
| 64 | createSparcDisassembler); |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 67 | static const unsigned IntRegDecoderTable[] = { |
| 68 | SP::G0, SP::G1, SP::G2, SP::G3, |
| 69 | SP::G4, SP::G5, SP::G6, SP::G7, |
| 70 | SP::O0, SP::O1, SP::O2, SP::O3, |
| 71 | SP::O4, SP::O5, SP::O6, SP::O7, |
| 72 | SP::L0, SP::L1, SP::L2, SP::L3, |
| 73 | SP::L4, SP::L5, SP::L6, SP::L7, |
| 74 | SP::I0, SP::I1, SP::I2, SP::I3, |
| 75 | SP::I4, SP::I5, SP::I6, SP::I7 }; |
| 76 | |
| 77 | static const unsigned FPRegDecoderTable[] = { |
| 78 | SP::F0, SP::F1, SP::F2, SP::F3, |
| 79 | SP::F4, SP::F5, SP::F6, SP::F7, |
| 80 | SP::F8, SP::F9, SP::F10, SP::F11, |
| 81 | SP::F12, SP::F13, SP::F14, SP::F15, |
| 82 | SP::F16, SP::F17, SP::F18, SP::F19, |
| 83 | SP::F20, SP::F21, SP::F22, SP::F23, |
| 84 | SP::F24, SP::F25, SP::F26, SP::F27, |
| 85 | SP::F28, SP::F29, SP::F30, SP::F31 }; |
| 86 | |
| 87 | static const unsigned DFPRegDecoderTable[] = { |
| 88 | SP::D0, SP::D16, SP::D1, SP::D17, |
| 89 | SP::D2, SP::D18, SP::D3, SP::D19, |
| 90 | SP::D4, SP::D20, SP::D5, SP::D21, |
| 91 | SP::D6, SP::D22, SP::D7, SP::D23, |
| 92 | SP::D8, SP::D24, SP::D9, SP::D25, |
| 93 | SP::D10, SP::D26, SP::D11, SP::D27, |
| 94 | SP::D12, SP::D28, SP::D13, SP::D29, |
| 95 | SP::D14, SP::D30, SP::D15, SP::D31 }; |
| 96 | |
| 97 | static const unsigned QFPRegDecoderTable[] = { |
Venkatraman Govindaraju | 0b9debf | 2014-01-12 04:34:31 +0000 | [diff] [blame] | 98 | SP::Q0, SP::Q8, ~0U, ~0U, |
| 99 | SP::Q1, SP::Q9, ~0U, ~0U, |
| 100 | SP::Q2, SP::Q10, ~0U, ~0U, |
| 101 | SP::Q3, SP::Q11, ~0U, ~0U, |
| 102 | SP::Q4, SP::Q12, ~0U, ~0U, |
| 103 | SP::Q5, SP::Q13, ~0U, ~0U, |
| 104 | SP::Q6, SP::Q14, ~0U, ~0U, |
| 105 | SP::Q7, SP::Q15, ~0U, ~0U } ; |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 106 | |
Venkatraman Govindaraju | 81aae57 | 2014-03-02 03:39:39 +0000 | [diff] [blame] | 107 | static const unsigned FCCRegDecoderTable[] = { |
| 108 | SP::FCC0, SP::FCC1, SP::FCC2, SP::FCC3 }; |
| 109 | |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 110 | static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, |
| 111 | unsigned RegNo, |
| 112 | uint64_t Address, |
| 113 | const void *Decoder) { |
| 114 | if (RegNo > 31) |
| 115 | return MCDisassembler::Fail; |
| 116 | unsigned Reg = IntRegDecoderTable[RegNo]; |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 117 | Inst.addOperand(MCOperand::createReg(Reg)); |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 118 | return MCDisassembler::Success; |
| 119 | } |
| 120 | |
| 121 | static DecodeStatus DecodeI64RegsRegisterClass(MCInst &Inst, |
| 122 | unsigned RegNo, |
| 123 | uint64_t Address, |
| 124 | const void *Decoder) { |
| 125 | if (RegNo > 31) |
| 126 | return MCDisassembler::Fail; |
| 127 | unsigned Reg = IntRegDecoderTable[RegNo]; |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 128 | Inst.addOperand(MCOperand::createReg(Reg)); |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 129 | return MCDisassembler::Success; |
| 130 | } |
| 131 | |
| 132 | |
| 133 | static DecodeStatus DecodeFPRegsRegisterClass(MCInst &Inst, |
| 134 | unsigned RegNo, |
| 135 | uint64_t Address, |
| 136 | const void *Decoder) { |
| 137 | if (RegNo > 31) |
| 138 | return MCDisassembler::Fail; |
| 139 | unsigned Reg = FPRegDecoderTable[RegNo]; |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 140 | Inst.addOperand(MCOperand::createReg(Reg)); |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 141 | return MCDisassembler::Success; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | static DecodeStatus DecodeDFPRegsRegisterClass(MCInst &Inst, |
| 146 | unsigned RegNo, |
| 147 | uint64_t Address, |
| 148 | const void *Decoder) { |
| 149 | if (RegNo > 31) |
| 150 | return MCDisassembler::Fail; |
| 151 | unsigned Reg = DFPRegDecoderTable[RegNo]; |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 152 | Inst.addOperand(MCOperand::createReg(Reg)); |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 153 | return MCDisassembler::Success; |
| 154 | } |
| 155 | |
| 156 | |
| 157 | static DecodeStatus DecodeQFPRegsRegisterClass(MCInst &Inst, |
| 158 | unsigned RegNo, |
| 159 | uint64_t Address, |
| 160 | const void *Decoder) { |
| 161 | if (RegNo > 31) |
| 162 | return MCDisassembler::Fail; |
| 163 | |
| 164 | unsigned Reg = QFPRegDecoderTable[RegNo]; |
Venkatraman Govindaraju | 0b9debf | 2014-01-12 04:34:31 +0000 | [diff] [blame] | 165 | if (Reg == ~0U) |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 166 | return MCDisassembler::Fail; |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 167 | Inst.addOperand(MCOperand::createReg(Reg)); |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 168 | return MCDisassembler::Success; |
| 169 | } |
| 170 | |
Venkatraman Govindaraju | 81aae57 | 2014-03-02 03:39:39 +0000 | [diff] [blame] | 171 | static DecodeStatus DecodeFCCRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 172 | uint64_t Address, |
| 173 | const void *Decoder) { |
| 174 | if (RegNo > 3) |
| 175 | return MCDisassembler::Fail; |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 176 | Inst.addOperand(MCOperand::createReg(FCCRegDecoderTable[RegNo])); |
Venkatraman Govindaraju | 81aae57 | 2014-03-02 03:39:39 +0000 | [diff] [blame] | 177 | return MCDisassembler::Success; |
| 178 | } |
| 179 | |
| 180 | |
Venkatraman Govindaraju | fb54821 | 2014-03-01 07:46:33 +0000 | [diff] [blame] | 181 | static DecodeStatus DecodeLoadInt(MCInst &Inst, unsigned insn, uint64_t Address, |
| 182 | const void *Decoder); |
| 183 | static DecodeStatus DecodeLoadFP(MCInst &Inst, unsigned insn, uint64_t Address, |
| 184 | const void *Decoder); |
| 185 | static DecodeStatus DecodeLoadDFP(MCInst &Inst, unsigned insn, uint64_t Address, |
| 186 | const void *Decoder); |
| 187 | static DecodeStatus DecodeLoadQFP(MCInst &Inst, unsigned insn, uint64_t Address, |
| 188 | const void *Decoder); |
| 189 | static DecodeStatus DecodeStoreInt(MCInst &Inst, unsigned insn, |
| 190 | uint64_t Address, const void *Decoder); |
| 191 | static DecodeStatus DecodeStoreFP(MCInst &Inst, unsigned insn, |
| 192 | uint64_t Address, const void *Decoder); |
| 193 | static DecodeStatus DecodeStoreDFP(MCInst &Inst, unsigned insn, |
| 194 | uint64_t Address, const void *Decoder); |
| 195 | static DecodeStatus DecodeStoreQFP(MCInst &Inst, unsigned insn, |
| 196 | uint64_t Address, const void *Decoder); |
Venkatraman Govindaraju | 78df2de | 2014-03-01 08:30:58 +0000 | [diff] [blame] | 197 | static DecodeStatus DecodeCall(MCInst &Inst, unsigned insn, |
| 198 | uint64_t Address, const void *Decoder); |
Venkatraman Govindaraju | 484ca1a | 2014-03-01 09:11:57 +0000 | [diff] [blame] | 199 | static DecodeStatus DecodeSIMM13(MCInst &Inst, unsigned insn, |
| 200 | uint64_t Address, const void *Decoder); |
Venkatraman Govindaraju | 4fa2ab2 | 2014-03-02 21:17:44 +0000 | [diff] [blame] | 201 | static DecodeStatus DecodeJMPL(MCInst &Inst, unsigned insn, uint64_t Address, |
| 202 | const void *Decoder); |
Venkatraman Govindaraju | 07d3af2 | 2014-03-02 22:55:53 +0000 | [diff] [blame] | 203 | static DecodeStatus DecodeReturn(MCInst &MI, unsigned insn, uint64_t Address, |
| 204 | const void *Decoder); |
Venkatraman Govindaraju | f703132 | 2014-03-09 23:32:07 +0000 | [diff] [blame] | 205 | static DecodeStatus DecodeSWAP(MCInst &Inst, unsigned insn, uint64_t Address, |
| 206 | const void *Decoder); |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 207 | |
| 208 | #include "SparcGenDisassemblerTables.inc" |
| 209 | |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 210 | /// Read four bytes from the ArrayRef and return 32 bit word. |
| 211 | static DecodeStatus readInstruction32(ArrayRef<uint8_t> Bytes, uint64_t Address, |
Douglas Katzman | 9160e78 | 2015-04-29 20:30:57 +0000 | [diff] [blame] | 212 | uint64_t &Size, uint32_t &Insn, |
| 213 | bool IsLittleEndian) { |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 214 | // We want to read exactly 4 Bytes of data. |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 215 | if (Bytes.size() < 4) { |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 216 | Size = 0; |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 217 | return MCDisassembler::Fail; |
| 218 | } |
| 219 | |
Douglas Katzman | 9160e78 | 2015-04-29 20:30:57 +0000 | [diff] [blame] | 220 | Insn = IsLittleEndian |
| 221 | ? (Bytes[0] << 0) | (Bytes[1] << 8) | (Bytes[2] << 16) | |
| 222 | (Bytes[3] << 24) |
| 223 | : (Bytes[3] << 0) | (Bytes[2] << 8) | (Bytes[1] << 16) | |
| 224 | (Bytes[0] << 24); |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 225 | |
| 226 | return MCDisassembler::Success; |
| 227 | } |
| 228 | |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 229 | DecodeStatus SparcDisassembler::getInstruction(MCInst &Instr, uint64_t &Size, |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 230 | ArrayRef<uint8_t> Bytes, |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 231 | uint64_t Address, |
| 232 | raw_ostream &VStream, |
| 233 | raw_ostream &CStream) const { |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 234 | uint32_t Insn; |
Douglas Katzman | 9160e78 | 2015-04-29 20:30:57 +0000 | [diff] [blame] | 235 | bool isLittleEndian = getContext().getAsmInfo()->isLittleEndian(); |
| 236 | DecodeStatus Result = |
| 237 | readInstruction32(Bytes, Address, Size, Insn, isLittleEndian); |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 238 | if (Result == MCDisassembler::Fail) |
| 239 | return MCDisassembler::Fail; |
| 240 | |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 241 | // Calling the auto-generated decoder function. |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 242 | Result = |
| 243 | decodeInstruction(DecoderTableSparc32, Instr, Insn, Address, this, STI); |
Venkatraman Govindaraju | dfcccc7 | 2014-01-06 08:08:58 +0000 | [diff] [blame] | 244 | |
| 245 | if (Result != MCDisassembler::Fail) { |
| 246 | Size = 4; |
| 247 | return Result; |
| 248 | } |
| 249 | |
| 250 | return MCDisassembler::Fail; |
| 251 | } |
Venkatraman Govindaraju | fb54821 | 2014-03-01 07:46:33 +0000 | [diff] [blame] | 252 | |
| 253 | |
| 254 | typedef DecodeStatus (*DecodeFunc)(MCInst &MI, unsigned insn, uint64_t Address, |
| 255 | const void *Decoder); |
| 256 | |
| 257 | static DecodeStatus DecodeMem(MCInst &MI, unsigned insn, uint64_t Address, |
| 258 | const void *Decoder, |
| 259 | bool isLoad, DecodeFunc DecodeRD) { |
| 260 | unsigned rd = fieldFromInstruction(insn, 25, 5); |
| 261 | unsigned rs1 = fieldFromInstruction(insn, 14, 5); |
| 262 | bool isImm = fieldFromInstruction(insn, 13, 1); |
| 263 | unsigned rs2 = 0; |
| 264 | unsigned simm13 = 0; |
| 265 | if (isImm) |
| 266 | simm13 = SignExtend32<13>(fieldFromInstruction(insn, 0, 13)); |
| 267 | else |
| 268 | rs2 = fieldFromInstruction(insn, 0, 5); |
| 269 | |
| 270 | DecodeStatus status; |
| 271 | if (isLoad) { |
| 272 | status = DecodeRD(MI, rd, Address, Decoder); |
| 273 | if (status != MCDisassembler::Success) |
| 274 | return status; |
| 275 | } |
| 276 | |
| 277 | // Decode rs1. |
| 278 | status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder); |
| 279 | if (status != MCDisassembler::Success) |
| 280 | return status; |
| 281 | |
| 282 | // Decode imm|rs2. |
| 283 | if (isImm) |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 284 | MI.addOperand(MCOperand::createImm(simm13)); |
Venkatraman Govindaraju | fb54821 | 2014-03-01 07:46:33 +0000 | [diff] [blame] | 285 | else { |
| 286 | status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder); |
| 287 | if (status != MCDisassembler::Success) |
| 288 | return status; |
| 289 | } |
| 290 | |
| 291 | if (!isLoad) { |
| 292 | status = DecodeRD(MI, rd, Address, Decoder); |
| 293 | if (status != MCDisassembler::Success) |
| 294 | return status; |
| 295 | } |
| 296 | return MCDisassembler::Success; |
| 297 | } |
| 298 | |
| 299 | static DecodeStatus DecodeLoadInt(MCInst &Inst, unsigned insn, uint64_t Address, |
| 300 | const void *Decoder) { |
| 301 | return DecodeMem(Inst, insn, Address, Decoder, true, |
| 302 | DecodeIntRegsRegisterClass); |
| 303 | } |
| 304 | |
| 305 | static DecodeStatus DecodeLoadFP(MCInst &Inst, unsigned insn, uint64_t Address, |
| 306 | const void *Decoder) { |
| 307 | return DecodeMem(Inst, insn, Address, Decoder, true, |
| 308 | DecodeFPRegsRegisterClass); |
| 309 | } |
| 310 | |
| 311 | static DecodeStatus DecodeLoadDFP(MCInst &Inst, unsigned insn, uint64_t Address, |
| 312 | const void *Decoder) { |
| 313 | return DecodeMem(Inst, insn, Address, Decoder, true, |
| 314 | DecodeDFPRegsRegisterClass); |
| 315 | } |
| 316 | |
| 317 | static DecodeStatus DecodeLoadQFP(MCInst &Inst, unsigned insn, uint64_t Address, |
| 318 | const void *Decoder) { |
| 319 | return DecodeMem(Inst, insn, Address, Decoder, true, |
| 320 | DecodeQFPRegsRegisterClass); |
| 321 | } |
| 322 | |
| 323 | static DecodeStatus DecodeStoreInt(MCInst &Inst, unsigned insn, |
| 324 | uint64_t Address, const void *Decoder) { |
| 325 | return DecodeMem(Inst, insn, Address, Decoder, false, |
| 326 | DecodeIntRegsRegisterClass); |
| 327 | } |
| 328 | |
| 329 | static DecodeStatus DecodeStoreFP(MCInst &Inst, unsigned insn, uint64_t Address, |
| 330 | const void *Decoder) { |
| 331 | return DecodeMem(Inst, insn, Address, Decoder, false, |
| 332 | DecodeFPRegsRegisterClass); |
| 333 | } |
| 334 | |
| 335 | static DecodeStatus DecodeStoreDFP(MCInst &Inst, unsigned insn, |
| 336 | uint64_t Address, const void *Decoder) { |
| 337 | return DecodeMem(Inst, insn, Address, Decoder, false, |
| 338 | DecodeDFPRegsRegisterClass); |
| 339 | } |
| 340 | |
| 341 | static DecodeStatus DecodeStoreQFP(MCInst &Inst, unsigned insn, |
| 342 | uint64_t Address, const void *Decoder) { |
| 343 | return DecodeMem(Inst, insn, Address, Decoder, false, |
| 344 | DecodeQFPRegsRegisterClass); |
| 345 | } |
Venkatraman Govindaraju | 78df2de | 2014-03-01 08:30:58 +0000 | [diff] [blame] | 346 | |
| 347 | static bool tryAddingSymbolicOperand(int64_t Value, bool isBranch, |
| 348 | uint64_t Address, uint64_t Offset, |
| 349 | uint64_t Width, MCInst &MI, |
| 350 | const void *Decoder) { |
| 351 | const MCDisassembler *Dis = static_cast<const MCDisassembler*>(Decoder); |
| 352 | return Dis->tryAddingSymbolicOperand(MI, Value, Address, isBranch, |
| 353 | Offset, Width); |
| 354 | } |
| 355 | |
| 356 | static DecodeStatus DecodeCall(MCInst &MI, unsigned insn, |
| 357 | uint64_t Address, const void *Decoder) { |
| 358 | unsigned tgt = fieldFromInstruction(insn, 0, 30); |
| 359 | tgt <<= 2; |
| 360 | if (!tryAddingSymbolicOperand(tgt+Address, false, Address, |
| 361 | 0, 30, MI, Decoder)) |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 362 | MI.addOperand(MCOperand::createImm(tgt)); |
Venkatraman Govindaraju | 78df2de | 2014-03-01 08:30:58 +0000 | [diff] [blame] | 363 | return MCDisassembler::Success; |
| 364 | } |
Venkatraman Govindaraju | 484ca1a | 2014-03-01 09:11:57 +0000 | [diff] [blame] | 365 | |
| 366 | static DecodeStatus DecodeSIMM13(MCInst &MI, unsigned insn, |
| 367 | uint64_t Address, const void *Decoder) { |
| 368 | unsigned tgt = SignExtend32<13>(fieldFromInstruction(insn, 0, 13)); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 369 | MI.addOperand(MCOperand::createImm(tgt)); |
Venkatraman Govindaraju | 484ca1a | 2014-03-01 09:11:57 +0000 | [diff] [blame] | 370 | return MCDisassembler::Success; |
| 371 | } |
Venkatraman Govindaraju | 4fa2ab2 | 2014-03-02 21:17:44 +0000 | [diff] [blame] | 372 | |
| 373 | static DecodeStatus DecodeJMPL(MCInst &MI, unsigned insn, uint64_t Address, |
| 374 | const void *Decoder) { |
| 375 | |
| 376 | unsigned rd = fieldFromInstruction(insn, 25, 5); |
| 377 | unsigned rs1 = fieldFromInstruction(insn, 14, 5); |
| 378 | unsigned isImm = fieldFromInstruction(insn, 13, 1); |
| 379 | unsigned rs2 = 0; |
| 380 | unsigned simm13 = 0; |
| 381 | if (isImm) |
| 382 | simm13 = SignExtend32<13>(fieldFromInstruction(insn, 0, 13)); |
| 383 | else |
| 384 | rs2 = fieldFromInstruction(insn, 0, 5); |
| 385 | |
| 386 | // Decode RD. |
| 387 | DecodeStatus status = DecodeIntRegsRegisterClass(MI, rd, Address, Decoder); |
| 388 | if (status != MCDisassembler::Success) |
| 389 | return status; |
| 390 | |
| 391 | // Decode RS1. |
| 392 | status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder); |
| 393 | if (status != MCDisassembler::Success) |
| 394 | return status; |
| 395 | |
| 396 | // Decode RS1 | SIMM13. |
| 397 | if (isImm) |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 398 | MI.addOperand(MCOperand::createImm(simm13)); |
Venkatraman Govindaraju | 4fa2ab2 | 2014-03-02 21:17:44 +0000 | [diff] [blame] | 399 | else { |
| 400 | status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder); |
| 401 | if (status != MCDisassembler::Success) |
| 402 | return status; |
| 403 | } |
| 404 | return MCDisassembler::Success; |
| 405 | } |
Venkatraman Govindaraju | 07d3af2 | 2014-03-02 22:55:53 +0000 | [diff] [blame] | 406 | |
| 407 | static DecodeStatus DecodeReturn(MCInst &MI, unsigned insn, uint64_t Address, |
| 408 | const void *Decoder) { |
| 409 | |
| 410 | unsigned rs1 = fieldFromInstruction(insn, 14, 5); |
| 411 | unsigned isImm = fieldFromInstruction(insn, 13, 1); |
| 412 | unsigned rs2 = 0; |
| 413 | unsigned simm13 = 0; |
| 414 | if (isImm) |
| 415 | simm13 = SignExtend32<13>(fieldFromInstruction(insn, 0, 13)); |
| 416 | else |
| 417 | rs2 = fieldFromInstruction(insn, 0, 5); |
| 418 | |
| 419 | // Decode RS1. |
| 420 | DecodeStatus status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder); |
| 421 | if (status != MCDisassembler::Success) |
| 422 | return status; |
| 423 | |
| 424 | // Decode RS2 | SIMM13. |
| 425 | if (isImm) |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 426 | MI.addOperand(MCOperand::createImm(simm13)); |
Venkatraman Govindaraju | 07d3af2 | 2014-03-02 22:55:53 +0000 | [diff] [blame] | 427 | else { |
| 428 | status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder); |
| 429 | if (status != MCDisassembler::Success) |
| 430 | return status; |
| 431 | } |
| 432 | return MCDisassembler::Success; |
| 433 | } |
Venkatraman Govindaraju | f703132 | 2014-03-09 23:32:07 +0000 | [diff] [blame] | 434 | |
| 435 | static DecodeStatus DecodeSWAP(MCInst &MI, unsigned insn, uint64_t Address, |
| 436 | const void *Decoder) { |
| 437 | |
| 438 | unsigned rd = fieldFromInstruction(insn, 25, 5); |
| 439 | unsigned rs1 = fieldFromInstruction(insn, 14, 5); |
| 440 | unsigned isImm = fieldFromInstruction(insn, 13, 1); |
| 441 | unsigned rs2 = 0; |
| 442 | unsigned simm13 = 0; |
| 443 | if (isImm) |
| 444 | simm13 = SignExtend32<13>(fieldFromInstruction(insn, 0, 13)); |
| 445 | else |
| 446 | rs2 = fieldFromInstruction(insn, 0, 5); |
| 447 | |
| 448 | // Decode RD. |
| 449 | DecodeStatus status = DecodeIntRegsRegisterClass(MI, rd, Address, Decoder); |
| 450 | if (status != MCDisassembler::Success) |
| 451 | return status; |
| 452 | |
| 453 | // Decode RS1. |
| 454 | status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder); |
| 455 | if (status != MCDisassembler::Success) |
| 456 | return status; |
| 457 | |
| 458 | // Decode RS1 | SIMM13. |
| 459 | if (isImm) |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 460 | MI.addOperand(MCOperand::createImm(simm13)); |
Venkatraman Govindaraju | f703132 | 2014-03-09 23:32:07 +0000 | [diff] [blame] | 461 | else { |
| 462 | status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder); |
| 463 | if (status != MCDisassembler::Success) |
| 464 | return status; |
| 465 | } |
| 466 | return MCDisassembler::Success; |
| 467 | } |