Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 1 | //===------ PPCDisassembler.cpp - Disassembler for PowerPC ------*- 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 | |
Benjamin Kramer | 27c769d | 2018-09-10 12:53:46 +0000 | [diff] [blame] | 10 | #include "MCTargetDesc/PPCMCTargetDesc.h" |
Benjamin Kramer | f57c197 | 2016-01-26 16:44:37 +0000 | [diff] [blame] | 11 | #include "llvm/MC/MCDisassembler/MCDisassembler.h" |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 12 | #include "llvm/MC/MCFixedLenDisassembler.h" |
| 13 | #include "llvm/MC/MCInst.h" |
| 14 | #include "llvm/MC/MCSubtargetInfo.h" |
Benjamin Kramer | c11fd3e | 2015-07-15 12:56:19 +0000 | [diff] [blame] | 15 | #include "llvm/Support/Endian.h" |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 16 | #include "llvm/Support/TargetRegistry.h" |
| 17 | |
| 18 | using namespace llvm; |
| 19 | |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 20 | DEFINE_PPC_REGCLASSES; |
| 21 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 22 | #define DEBUG_TYPE "ppc-disassembler" |
| 23 | |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 24 | typedef MCDisassembler::DecodeStatus DecodeStatus; |
| 25 | |
| 26 | namespace { |
| 27 | class PPCDisassembler : public MCDisassembler { |
Benjamin Kramer | c11fd3e | 2015-07-15 12:56:19 +0000 | [diff] [blame] | 28 | bool IsLittleEndian; |
| 29 | |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 30 | public: |
Benjamin Kramer | c11fd3e | 2015-07-15 12:56:19 +0000 | [diff] [blame] | 31 | PPCDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx, |
| 32 | bool IsLittleEndian) |
| 33 | : MCDisassembler(STI, Ctx), IsLittleEndian(IsLittleEndian) {} |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 34 | |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 35 | DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 36 | ArrayRef<uint8_t> Bytes, uint64_t Address, |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 37 | raw_ostream &VStream, |
| 38 | raw_ostream &CStream) const override; |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 39 | }; |
| 40 | } // end anonymous namespace |
| 41 | |
| 42 | static MCDisassembler *createPPCDisassembler(const Target &T, |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 43 | const MCSubtargetInfo &STI, |
| 44 | MCContext &Ctx) { |
Benjamin Kramer | c11fd3e | 2015-07-15 12:56:19 +0000 | [diff] [blame] | 45 | return new PPCDisassembler(STI, Ctx, /*IsLittleEndian=*/false); |
| 46 | } |
| 47 | |
| 48 | static MCDisassembler *createPPCLEDisassembler(const Target &T, |
| 49 | const MCSubtargetInfo &STI, |
| 50 | MCContext &Ctx) { |
| 51 | return new PPCDisassembler(STI, Ctx, /*IsLittleEndian=*/true); |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | extern "C" void LLVMInitializePowerPCDisassembler() { |
| 55 | // Register the disassembler for each target. |
Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 56 | TargetRegistry::RegisterMCDisassembler(getThePPC32Target(), |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 57 | createPPCDisassembler); |
Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 58 | TargetRegistry::RegisterMCDisassembler(getThePPC64Target(), |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 59 | createPPCDisassembler); |
Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 60 | TargetRegistry::RegisterMCDisassembler(getThePPC64LETarget(), |
Benjamin Kramer | c11fd3e | 2015-07-15 12:56:19 +0000 | [diff] [blame] | 61 | createPPCLEDisassembler); |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | // FIXME: These can be generated by TableGen from the existing register |
| 65 | // encoding values! |
| 66 | |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 67 | template <std::size_t N> |
| 68 | static DecodeStatus decodeRegisterClass(MCInst &Inst, uint64_t RegNo, |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 69 | const MCPhysReg (&Regs)[N]) { |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 70 | assert(RegNo < N && "Invalid register number"); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 71 | Inst.addOperand(MCOperand::createReg(Regs[RegNo])); |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 72 | return MCDisassembler::Success; |
| 73 | } |
| 74 | |
| 75 | static DecodeStatus DecodeCRRCRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 76 | uint64_t Address, |
| 77 | const void *Decoder) { |
| 78 | return decodeRegisterClass(Inst, RegNo, CRRegs); |
| 79 | } |
| 80 | |
Kit Barton | 535e69d | 2015-03-25 19:36:23 +0000 | [diff] [blame] | 81 | static DecodeStatus DecodeCRRC0RegisterClass(MCInst &Inst, uint64_t RegNo, |
| 82 | uint64_t Address, |
| 83 | const void *Decoder) { |
| 84 | return decodeRegisterClass(Inst, RegNo, CRRegs); |
| 85 | } |
| 86 | |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 87 | static DecodeStatus DecodeCRBITRCRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 88 | uint64_t Address, |
| 89 | const void *Decoder) { |
| 90 | return decodeRegisterClass(Inst, RegNo, CRBITRegs); |
| 91 | } |
| 92 | |
| 93 | static DecodeStatus DecodeF4RCRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 94 | uint64_t Address, |
| 95 | const void *Decoder) { |
| 96 | return decodeRegisterClass(Inst, RegNo, FRegs); |
| 97 | } |
| 98 | |
| 99 | static DecodeStatus DecodeF8RCRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 100 | uint64_t Address, |
| 101 | const void *Decoder) { |
| 102 | return decodeRegisterClass(Inst, RegNo, FRegs); |
| 103 | } |
| 104 | |
Nemanja Ivanovic | 11049f8 | 2016-10-04 06:59:23 +0000 | [diff] [blame] | 105 | static DecodeStatus DecodeVFRCRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 106 | uint64_t Address, |
| 107 | const void *Decoder) { |
| 108 | return decodeRegisterClass(Inst, RegNo, VFRegs); |
| 109 | } |
| 110 | |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 111 | static DecodeStatus DecodeVRRCRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 112 | uint64_t Address, |
| 113 | const void *Decoder) { |
| 114 | return decodeRegisterClass(Inst, RegNo, VRegs); |
| 115 | } |
| 116 | |
Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 117 | static DecodeStatus DecodeVSRCRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 118 | uint64_t Address, |
| 119 | const void *Decoder) { |
| 120 | return decodeRegisterClass(Inst, RegNo, VSRegs); |
| 121 | } |
| 122 | |
Hal Finkel | 19be506 | 2014-03-29 05:29:01 +0000 | [diff] [blame] | 123 | static DecodeStatus DecodeVSFRCRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 124 | uint64_t Address, |
| 125 | const void *Decoder) { |
| 126 | return decodeRegisterClass(Inst, RegNo, VSFRegs); |
| 127 | } |
| 128 | |
Nemanja Ivanovic | f3c94b1 | 2015-05-07 18:24:05 +0000 | [diff] [blame] | 129 | static DecodeStatus DecodeVSSRCRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 130 | uint64_t Address, |
| 131 | const void *Decoder) { |
| 132 | return decodeRegisterClass(Inst, RegNo, VSSRegs); |
| 133 | } |
| 134 | |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 135 | static DecodeStatus DecodeGPRCRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 136 | uint64_t Address, |
| 137 | const void *Decoder) { |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 138 | return decodeRegisterClass(Inst, RegNo, RRegs); |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static DecodeStatus DecodeGPRC_NOR0RegisterClass(MCInst &Inst, uint64_t RegNo, |
| 142 | uint64_t Address, |
| 143 | const void *Decoder) { |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 144 | return decodeRegisterClass(Inst, RegNo, RRegsNoR0); |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static DecodeStatus DecodeG8RCRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 148 | uint64_t Address, |
| 149 | const void *Decoder) { |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 150 | return decodeRegisterClass(Inst, RegNo, XRegs); |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Guozhi Wei | 22e7da9 | 2017-05-11 22:17:35 +0000 | [diff] [blame] | 153 | static DecodeStatus DecodeG8RC_NOX0RegisterClass(MCInst &Inst, uint64_t RegNo, |
| 154 | uint64_t Address, |
| 155 | const void *Decoder) { |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 156 | return decodeRegisterClass(Inst, RegNo, XRegsNoX0); |
Guozhi Wei | 22e7da9 | 2017-05-11 22:17:35 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 159 | #define DecodePointerLikeRegClass0 DecodeGPRCRegisterClass |
| 160 | #define DecodePointerLikeRegClass1 DecodeGPRC_NOR0RegisterClass |
| 161 | |
Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 162 | static DecodeStatus DecodeQFRCRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 163 | uint64_t Address, |
| 164 | const void *Decoder) { |
| 165 | return decodeRegisterClass(Inst, RegNo, QFRegs); |
| 166 | } |
| 167 | |
Justin Hibbits | d52990c | 2018-07-18 04:25:10 +0000 | [diff] [blame] | 168 | static DecodeStatus DecodeSPE4RCRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 169 | uint64_t Address, |
| 170 | const void *Decoder) { |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 171 | return decodeRegisterClass(Inst, RegNo, RRegs); |
Justin Hibbits | d52990c | 2018-07-18 04:25:10 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static DecodeStatus DecodeSPERCRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 175 | uint64_t Address, |
| 176 | const void *Decoder) { |
| 177 | return decodeRegisterClass(Inst, RegNo, SPERegs); |
| 178 | } |
| 179 | |
Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 180 | #define DecodeQSRCRegisterClass DecodeQFRCRegisterClass |
| 181 | #define DecodeQBRCRegisterClass DecodeQFRCRegisterClass |
| 182 | |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 183 | template<unsigned N> |
| 184 | static DecodeStatus decodeUImmOperand(MCInst &Inst, uint64_t Imm, |
| 185 | int64_t Address, const void *Decoder) { |
| 186 | assert(isUInt<N>(Imm) && "Invalid immediate"); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 187 | Inst.addOperand(MCOperand::createImm(Imm)); |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 188 | return MCDisassembler::Success; |
| 189 | } |
| 190 | |
| 191 | template<unsigned N> |
| 192 | static DecodeStatus decodeSImmOperand(MCInst &Inst, uint64_t Imm, |
| 193 | int64_t Address, const void *Decoder) { |
| 194 | assert(isUInt<N>(Imm) && "Invalid immediate"); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 195 | Inst.addOperand(MCOperand::createImm(SignExtend64<N>(Imm))); |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 196 | return MCDisassembler::Success; |
| 197 | } |
| 198 | |
| 199 | static DecodeStatus decodeMemRIOperands(MCInst &Inst, uint64_t Imm, |
| 200 | int64_t Address, const void *Decoder) { |
| 201 | // Decode the memri field (imm, reg), which has the low 16-bits as the |
| 202 | // displacement and the next 5 bits as the register #. |
| 203 | |
| 204 | uint64_t Base = Imm >> 16; |
| 205 | uint64_t Disp = Imm & 0xFFFF; |
| 206 | |
| 207 | assert(Base < 32 && "Invalid base register"); |
| 208 | |
| 209 | switch (Inst.getOpcode()) { |
| 210 | default: break; |
| 211 | case PPC::LBZU: |
| 212 | case PPC::LHAU: |
| 213 | case PPC::LHZU: |
| 214 | case PPC::LWZU: |
| 215 | case PPC::LFSU: |
| 216 | case PPC::LFDU: |
| 217 | // Add the tied output operand. |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 218 | Inst.addOperand(MCOperand::createReg(RRegsNoR0[Base])); |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 219 | break; |
| 220 | case PPC::STBU: |
| 221 | case PPC::STHU: |
| 222 | case PPC::STWU: |
| 223 | case PPC::STFSU: |
| 224 | case PPC::STFDU: |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 225 | Inst.insert(Inst.begin(), MCOperand::createReg(RRegsNoR0[Base])); |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 226 | break; |
| 227 | } |
| 228 | |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 229 | Inst.addOperand(MCOperand::createImm(SignExtend64<16>(Disp))); |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 230 | Inst.addOperand(MCOperand::createReg(RRegsNoR0[Base])); |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 231 | return MCDisassembler::Success; |
| 232 | } |
| 233 | |
| 234 | static DecodeStatus decodeMemRIXOperands(MCInst &Inst, uint64_t Imm, |
| 235 | int64_t Address, const void *Decoder) { |
| 236 | // Decode the memrix field (imm, reg), which has the low 14-bits as the |
| 237 | // displacement and the next 5 bits as the register #. |
| 238 | |
| 239 | uint64_t Base = Imm >> 14; |
| 240 | uint64_t Disp = Imm & 0x3FFF; |
| 241 | |
| 242 | assert(Base < 32 && "Invalid base register"); |
| 243 | |
| 244 | if (Inst.getOpcode() == PPC::LDU) |
| 245 | // Add the tied output operand. |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 246 | Inst.addOperand(MCOperand::createReg(RRegsNoR0[Base])); |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 247 | else if (Inst.getOpcode() == PPC::STDU) |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 248 | Inst.insert(Inst.begin(), MCOperand::createReg(RRegsNoR0[Base])); |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 249 | |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 250 | Inst.addOperand(MCOperand::createImm(SignExtend64<16>(Disp << 2))); |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 251 | Inst.addOperand(MCOperand::createReg(RRegsNoR0[Base])); |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 252 | return MCDisassembler::Success; |
| 253 | } |
| 254 | |
Kit Barton | ba532dc | 2016-03-08 03:49:13 +0000 | [diff] [blame] | 255 | static DecodeStatus decodeMemRIX16Operands(MCInst &Inst, uint64_t Imm, |
| 256 | int64_t Address, const void *Decoder) { |
| 257 | // Decode the memrix16 field (imm, reg), which has the low 12-bits as the |
| 258 | // displacement with 16-byte aligned, and the next 5 bits as the register #. |
| 259 | |
| 260 | uint64_t Base = Imm >> 12; |
| 261 | uint64_t Disp = Imm & 0xFFF; |
| 262 | |
| 263 | assert(Base < 32 && "Invalid base register"); |
| 264 | |
| 265 | Inst.addOperand(MCOperand::createImm(SignExtend64<16>(Disp << 4))); |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 266 | Inst.addOperand(MCOperand::createReg(RRegsNoR0[Base])); |
Kit Barton | ba532dc | 2016-03-08 03:49:13 +0000 | [diff] [blame] | 267 | return MCDisassembler::Success; |
| 268 | } |
| 269 | |
Justin Hibbits | 4fa4fa6 | 2018-07-18 04:24:57 +0000 | [diff] [blame] | 270 | static DecodeStatus decodeSPE8Operands(MCInst &Inst, uint64_t Imm, |
| 271 | int64_t Address, const void *Decoder) { |
| 272 | // Decode the spe8disp field (imm, reg), which has the low 5-bits as the |
| 273 | // displacement with 8-byte aligned, and the next 5 bits as the register #. |
| 274 | |
| 275 | uint64_t Base = Imm >> 5; |
| 276 | uint64_t Disp = Imm & 0x1F; |
| 277 | |
| 278 | assert(Base < 32 && "Invalid base register"); |
| 279 | |
| 280 | Inst.addOperand(MCOperand::createImm(Disp << 3)); |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 281 | Inst.addOperand(MCOperand::createReg(RRegsNoR0[Base])); |
Justin Hibbits | 4fa4fa6 | 2018-07-18 04:24:57 +0000 | [diff] [blame] | 282 | return MCDisassembler::Success; |
| 283 | } |
| 284 | |
| 285 | static DecodeStatus decodeSPE4Operands(MCInst &Inst, uint64_t Imm, |
| 286 | int64_t Address, const void *Decoder) { |
| 287 | // Decode the spe4disp field (imm, reg), which has the low 5-bits as the |
| 288 | // displacement with 4-byte aligned, and the next 5 bits as the register #. |
| 289 | |
| 290 | uint64_t Base = Imm >> 5; |
| 291 | uint64_t Disp = Imm & 0x1F; |
| 292 | |
| 293 | assert(Base < 32 && "Invalid base register"); |
| 294 | |
| 295 | Inst.addOperand(MCOperand::createImm(Disp << 2)); |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 296 | Inst.addOperand(MCOperand::createReg(RRegsNoR0[Base])); |
Justin Hibbits | 4fa4fa6 | 2018-07-18 04:24:57 +0000 | [diff] [blame] | 297 | return MCDisassembler::Success; |
| 298 | } |
| 299 | |
| 300 | static DecodeStatus decodeSPE2Operands(MCInst &Inst, uint64_t Imm, |
| 301 | int64_t Address, const void *Decoder) { |
| 302 | // Decode the spe2disp field (imm, reg), which has the low 5-bits as the |
| 303 | // displacement with 2-byte aligned, and the next 5 bits as the register #. |
| 304 | |
| 305 | uint64_t Base = Imm >> 5; |
| 306 | uint64_t Disp = Imm & 0x1F; |
| 307 | |
| 308 | assert(Base < 32 && "Invalid base register"); |
| 309 | |
| 310 | Inst.addOperand(MCOperand::createImm(Disp << 1)); |
Nemanja Ivanovic | 0dad994 | 2018-12-29 16:13:11 +0000 | [diff] [blame] | 311 | Inst.addOperand(MCOperand::createReg(RRegsNoR0[Base])); |
Justin Hibbits | 4fa4fa6 | 2018-07-18 04:24:57 +0000 | [diff] [blame] | 312 | return MCDisassembler::Success; |
| 313 | } |
| 314 | |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 315 | static DecodeStatus decodeCRBitMOperand(MCInst &Inst, uint64_t Imm, |
| 316 | int64_t Address, const void *Decoder) { |
| 317 | // The cr bit encoding is 0x80 >> cr_reg_num. |
| 318 | |
| 319 | unsigned Zeros = countTrailingZeros(Imm); |
| 320 | assert(Zeros < 8 && "Invalid CR bit value"); |
| 321 | |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 322 | Inst.addOperand(MCOperand::createReg(CRRegs[7 - Zeros])); |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 323 | return MCDisassembler::Success; |
| 324 | } |
| 325 | |
| 326 | #include "PPCGenDisassemblerTables.inc" |
| 327 | |
| 328 | DecodeStatus PPCDisassembler::getInstruction(MCInst &MI, uint64_t &Size, |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 329 | ArrayRef<uint8_t> Bytes, |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 330 | uint64_t Address, raw_ostream &OS, |
| 331 | raw_ostream &CS) const { |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 332 | // Get the four bytes of the instruction. |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 333 | Size = 4; |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 334 | if (Bytes.size() < 4) { |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 335 | Size = 0; |
| 336 | return MCDisassembler::Fail; |
| 337 | } |
| 338 | |
Benjamin Kramer | c11fd3e | 2015-07-15 12:56:19 +0000 | [diff] [blame] | 339 | // Read the instruction in the proper endianness. |
| 340 | uint32_t Inst = IsLittleEndian ? support::endian::read32le(Bytes.data()) |
| 341 | : support::endian::read32be(Bytes.data()); |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 342 | |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 343 | if (STI.getFeatureBits()[PPC::FeatureQPX]) { |
Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 344 | DecodeStatus result = |
| 345 | decodeInstruction(DecoderTableQPX32, MI, Inst, Address, this, STI); |
| 346 | if (result != MCDisassembler::Fail) |
| 347 | return result; |
Justin Hibbits | 4fa4fa6 | 2018-07-18 04:24:57 +0000 | [diff] [blame] | 348 | } else if (STI.getFeatureBits()[PPC::FeatureSPE]) { |
| 349 | DecodeStatus result = |
| 350 | decodeInstruction(DecoderTableSPE32, MI, Inst, Address, this, STI); |
| 351 | if (result != MCDisassembler::Fail) |
| 352 | return result; |
Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Hal Finkel | 2345347 | 2013-12-19 16:13:01 +0000 | [diff] [blame] | 355 | return decodeInstruction(DecoderTable32, MI, Inst, Address, this, STI); |
| 356 | } |
| 357 | |