Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 1 | //===-- SystemZDisassembler.cpp - Disassembler for SystemZ ------*- 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 | #include "SystemZ.h" |
Benjamin Kramer | f57c197 | 2016-01-26 16:44:37 +0000 | [diff] [blame^] | 11 | #include "llvm/MC/MCDisassembler/MCDisassembler.h" |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 12 | #include "llvm/MC/MCFixedLenDisassembler.h" |
| 13 | #include "llvm/MC/MCInst.h" |
| 14 | #include "llvm/MC/MCSubtargetInfo.h" |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 15 | #include "llvm/Support/TargetRegistry.h" |
| 16 | |
| 17 | using namespace llvm; |
| 18 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 19 | #define DEBUG_TYPE "systemz-disassembler" |
| 20 | |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 21 | typedef MCDisassembler::DecodeStatus DecodeStatus; |
| 22 | |
| 23 | namespace { |
| 24 | class SystemZDisassembler : public MCDisassembler { |
| 25 | public: |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 26 | SystemZDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx) |
| 27 | : MCDisassembler(STI, Ctx) {} |
Alexander Kornienko | f817c1c | 2015-04-11 02:11:45 +0000 | [diff] [blame] | 28 | ~SystemZDisassembler() override {} |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 29 | |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 30 | DecodeStatus getInstruction(MCInst &instr, uint64_t &Size, |
| 31 | ArrayRef<uint8_t> Bytes, uint64_t Address, |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 32 | raw_ostream &VStream, |
| 33 | raw_ostream &CStream) const override; |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 34 | }; |
| 35 | } // end anonymous namespace |
| 36 | |
| 37 | static MCDisassembler *createSystemZDisassembler(const Target &T, |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 38 | const MCSubtargetInfo &STI, |
| 39 | MCContext &Ctx) { |
| 40 | return new SystemZDisassembler(STI, Ctx); |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | extern "C" void LLVMInitializeSystemZDisassembler() { |
| 44 | // Register the disassembler. |
| 45 | TargetRegistry::RegisterMCDisassembler(TheSystemZTarget, |
| 46 | createSystemZDisassembler); |
| 47 | } |
| 48 | |
| 49 | static DecodeStatus decodeRegisterClass(MCInst &Inst, uint64_t RegNo, |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 50 | const unsigned *Regs, unsigned Size) { |
| 51 | assert(RegNo < Size && "Invalid register"); |
Richard Sandiford | 09de091 | 2013-11-13 16:57:53 +0000 | [diff] [blame] | 52 | RegNo = Regs[RegNo]; |
| 53 | if (RegNo == 0) |
| 54 | return MCDisassembler::Fail; |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 55 | Inst.addOperand(MCOperand::createReg(RegNo)); |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 56 | return MCDisassembler::Success; |
| 57 | } |
| 58 | |
| 59 | static DecodeStatus DecodeGR32BitRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 60 | uint64_t Address, |
| 61 | const void *Decoder) { |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 62 | return decodeRegisterClass(Inst, RegNo, SystemZMC::GR32Regs, 16); |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Richard Sandiford | f949606 | 2013-09-30 10:45:16 +0000 | [diff] [blame] | 65 | static DecodeStatus DecodeGRH32BitRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 66 | uint64_t Address, |
| 67 | const void *Decoder) { |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 68 | return decodeRegisterClass(Inst, RegNo, SystemZMC::GRH32Regs, 16); |
Richard Sandiford | f949606 | 2013-09-30 10:45:16 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 71 | static DecodeStatus DecodeGR64BitRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 72 | uint64_t Address, |
| 73 | const void *Decoder) { |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 74 | return decodeRegisterClass(Inst, RegNo, SystemZMC::GR64Regs, 16); |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static DecodeStatus DecodeGR128BitRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 78 | uint64_t Address, |
| 79 | const void *Decoder) { |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 80 | return decodeRegisterClass(Inst, RegNo, SystemZMC::GR128Regs, 16); |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static DecodeStatus DecodeADDR64BitRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 84 | uint64_t Address, |
| 85 | const void *Decoder) { |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 86 | return decodeRegisterClass(Inst, RegNo, SystemZMC::GR64Regs, 16); |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | static DecodeStatus DecodeFP32BitRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 90 | uint64_t Address, |
| 91 | const void *Decoder) { |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 92 | return decodeRegisterClass(Inst, RegNo, SystemZMC::FP32Regs, 16); |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | static DecodeStatus DecodeFP64BitRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 96 | uint64_t Address, |
| 97 | const void *Decoder) { |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 98 | return decodeRegisterClass(Inst, RegNo, SystemZMC::FP64Regs, 16); |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static DecodeStatus DecodeFP128BitRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 102 | uint64_t Address, |
| 103 | const void *Decoder) { |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 104 | return decodeRegisterClass(Inst, RegNo, SystemZMC::FP128Regs, 16); |
| 105 | } |
| 106 | |
| 107 | static DecodeStatus DecodeVR32BitRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 108 | uint64_t Address, |
| 109 | const void *Decoder) { |
| 110 | return decodeRegisterClass(Inst, RegNo, SystemZMC::VR32Regs, 32); |
| 111 | } |
| 112 | |
| 113 | static DecodeStatus DecodeVR64BitRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 114 | uint64_t Address, |
| 115 | const void *Decoder) { |
| 116 | return decodeRegisterClass(Inst, RegNo, SystemZMC::VR64Regs, 32); |
| 117 | } |
| 118 | |
| 119 | static DecodeStatus DecodeVR128BitRegisterClass(MCInst &Inst, uint64_t RegNo, |
| 120 | uint64_t Address, |
| 121 | const void *Decoder) { |
| 122 | return decodeRegisterClass(Inst, RegNo, SystemZMC::VR128Regs, 32); |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | template<unsigned N> |
| 126 | static DecodeStatus decodeUImmOperand(MCInst &Inst, uint64_t Imm) { |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 127 | if (!isUInt<N>(Imm)) |
| 128 | return MCDisassembler::Fail; |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 129 | Inst.addOperand(MCOperand::createImm(Imm)); |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 130 | return MCDisassembler::Success; |
| 131 | } |
| 132 | |
| 133 | template<unsigned N> |
| 134 | static DecodeStatus decodeSImmOperand(MCInst &Inst, uint64_t Imm) { |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 135 | if (!isUInt<N>(Imm)) |
| 136 | return MCDisassembler::Fail; |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 137 | Inst.addOperand(MCOperand::createImm(SignExtend64<N>(Imm))); |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 138 | return MCDisassembler::Success; |
| 139 | } |
| 140 | |
| 141 | static DecodeStatus decodeAccessRegOperand(MCInst &Inst, uint64_t Imm, |
| 142 | uint64_t Address, |
| 143 | const void *Decoder) { |
| 144 | return decodeUImmOperand<4>(Inst, Imm); |
| 145 | } |
| 146 | |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 147 | static DecodeStatus decodeU1ImmOperand(MCInst &Inst, uint64_t Imm, |
| 148 | uint64_t Address, const void *Decoder) { |
| 149 | return decodeUImmOperand<1>(Inst, Imm); |
| 150 | } |
| 151 | |
| 152 | static DecodeStatus decodeU2ImmOperand(MCInst &Inst, uint64_t Imm, |
| 153 | uint64_t Address, const void *Decoder) { |
| 154 | return decodeUImmOperand<2>(Inst, Imm); |
| 155 | } |
| 156 | |
| 157 | static DecodeStatus decodeU3ImmOperand(MCInst &Inst, uint64_t Imm, |
| 158 | uint64_t Address, const void *Decoder) { |
| 159 | return decodeUImmOperand<3>(Inst, Imm); |
| 160 | } |
| 161 | |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 162 | static DecodeStatus decodeU4ImmOperand(MCInst &Inst, uint64_t Imm, |
| 163 | uint64_t Address, const void *Decoder) { |
| 164 | return decodeUImmOperand<4>(Inst, Imm); |
| 165 | } |
| 166 | |
| 167 | static DecodeStatus decodeU6ImmOperand(MCInst &Inst, uint64_t Imm, |
| 168 | uint64_t Address, const void *Decoder) { |
| 169 | return decodeUImmOperand<6>(Inst, Imm); |
| 170 | } |
| 171 | |
| 172 | static DecodeStatus decodeU8ImmOperand(MCInst &Inst, uint64_t Imm, |
| 173 | uint64_t Address, const void *Decoder) { |
| 174 | return decodeUImmOperand<8>(Inst, Imm); |
| 175 | } |
| 176 | |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 177 | static DecodeStatus decodeU12ImmOperand(MCInst &Inst, uint64_t Imm, |
| 178 | uint64_t Address, const void *Decoder) { |
| 179 | return decodeUImmOperand<12>(Inst, Imm); |
| 180 | } |
| 181 | |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 182 | static DecodeStatus decodeU16ImmOperand(MCInst &Inst, uint64_t Imm, |
| 183 | uint64_t Address, const void *Decoder) { |
| 184 | return decodeUImmOperand<16>(Inst, Imm); |
| 185 | } |
| 186 | |
| 187 | static DecodeStatus decodeU32ImmOperand(MCInst &Inst, uint64_t Imm, |
| 188 | uint64_t Address, const void *Decoder) { |
| 189 | return decodeUImmOperand<32>(Inst, Imm); |
| 190 | } |
| 191 | |
| 192 | static DecodeStatus decodeS8ImmOperand(MCInst &Inst, uint64_t Imm, |
| 193 | uint64_t Address, const void *Decoder) { |
| 194 | return decodeSImmOperand<8>(Inst, Imm); |
| 195 | } |
| 196 | |
| 197 | static DecodeStatus decodeS16ImmOperand(MCInst &Inst, uint64_t Imm, |
| 198 | uint64_t Address, const void *Decoder) { |
| 199 | return decodeSImmOperand<16>(Inst, Imm); |
| 200 | } |
| 201 | |
| 202 | static DecodeStatus decodeS32ImmOperand(MCInst &Inst, uint64_t Imm, |
| 203 | uint64_t Address, const void *Decoder) { |
| 204 | return decodeSImmOperand<32>(Inst, Imm); |
| 205 | } |
| 206 | |
| 207 | template<unsigned N> |
| 208 | static DecodeStatus decodePCDBLOperand(MCInst &Inst, uint64_t Imm, |
| 209 | uint64_t Address) { |
| 210 | assert(isUInt<N>(Imm) && "Invalid PC-relative offset"); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 211 | Inst.addOperand(MCOperand::createImm(SignExtend64<N>(Imm) * 2 + Address)); |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 212 | return MCDisassembler::Success; |
| 213 | } |
| 214 | |
| 215 | static DecodeStatus decodePC16DBLOperand(MCInst &Inst, uint64_t Imm, |
| 216 | uint64_t Address, |
| 217 | const void *Decoder) { |
| 218 | return decodePCDBLOperand<16>(Inst, Imm, Address); |
| 219 | } |
| 220 | |
| 221 | static DecodeStatus decodePC32DBLOperand(MCInst &Inst, uint64_t Imm, |
| 222 | uint64_t Address, |
| 223 | const void *Decoder) { |
| 224 | return decodePCDBLOperand<32>(Inst, Imm, Address); |
| 225 | } |
| 226 | |
| 227 | static DecodeStatus decodeBDAddr12Operand(MCInst &Inst, uint64_t Field, |
| 228 | const unsigned *Regs) { |
| 229 | uint64_t Base = Field >> 12; |
| 230 | uint64_t Disp = Field & 0xfff; |
| 231 | assert(Base < 16 && "Invalid BDAddr12"); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 232 | Inst.addOperand(MCOperand::createReg(Base == 0 ? 0 : Regs[Base])); |
| 233 | Inst.addOperand(MCOperand::createImm(Disp)); |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 234 | return MCDisassembler::Success; |
| 235 | } |
| 236 | |
| 237 | static DecodeStatus decodeBDAddr20Operand(MCInst &Inst, uint64_t Field, |
| 238 | const unsigned *Regs) { |
| 239 | uint64_t Base = Field >> 20; |
| 240 | uint64_t Disp = ((Field << 12) & 0xff000) | ((Field >> 8) & 0xfff); |
| 241 | assert(Base < 16 && "Invalid BDAddr20"); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 242 | Inst.addOperand(MCOperand::createReg(Base == 0 ? 0 : Regs[Base])); |
| 243 | Inst.addOperand(MCOperand::createImm(SignExtend64<20>(Disp))); |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 244 | return MCDisassembler::Success; |
| 245 | } |
| 246 | |
| 247 | static DecodeStatus decodeBDXAddr12Operand(MCInst &Inst, uint64_t Field, |
| 248 | const unsigned *Regs) { |
| 249 | uint64_t Index = Field >> 16; |
| 250 | uint64_t Base = (Field >> 12) & 0xf; |
| 251 | uint64_t Disp = Field & 0xfff; |
| 252 | assert(Index < 16 && "Invalid BDXAddr12"); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 253 | Inst.addOperand(MCOperand::createReg(Base == 0 ? 0 : Regs[Base])); |
| 254 | Inst.addOperand(MCOperand::createImm(Disp)); |
| 255 | Inst.addOperand(MCOperand::createReg(Index == 0 ? 0 : Regs[Index])); |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 256 | return MCDisassembler::Success; |
| 257 | } |
| 258 | |
| 259 | static DecodeStatus decodeBDXAddr20Operand(MCInst &Inst, uint64_t Field, |
| 260 | const unsigned *Regs) { |
| 261 | uint64_t Index = Field >> 24; |
| 262 | uint64_t Base = (Field >> 20) & 0xf; |
| 263 | uint64_t Disp = ((Field & 0xfff00) >> 8) | ((Field & 0xff) << 12); |
| 264 | assert(Index < 16 && "Invalid BDXAddr20"); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 265 | Inst.addOperand(MCOperand::createReg(Base == 0 ? 0 : Regs[Base])); |
| 266 | Inst.addOperand(MCOperand::createImm(SignExtend64<20>(Disp))); |
| 267 | Inst.addOperand(MCOperand::createReg(Index == 0 ? 0 : Regs[Index])); |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 268 | return MCDisassembler::Success; |
| 269 | } |
| 270 | |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 271 | static DecodeStatus decodeBDLAddr12Len8Operand(MCInst &Inst, uint64_t Field, |
| 272 | const unsigned *Regs) { |
| 273 | uint64_t Length = Field >> 16; |
| 274 | uint64_t Base = (Field >> 12) & 0xf; |
| 275 | uint64_t Disp = Field & 0xfff; |
| 276 | assert(Length < 256 && "Invalid BDLAddr12Len8"); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 277 | Inst.addOperand(MCOperand::createReg(Base == 0 ? 0 : Regs[Base])); |
| 278 | Inst.addOperand(MCOperand::createImm(Disp)); |
| 279 | Inst.addOperand(MCOperand::createImm(Length + 1)); |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 280 | return MCDisassembler::Success; |
| 281 | } |
| 282 | |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 283 | static DecodeStatus decodeBDVAddr12Operand(MCInst &Inst, uint64_t Field, |
| 284 | const unsigned *Regs) { |
| 285 | uint64_t Index = Field >> 16; |
| 286 | uint64_t Base = (Field >> 12) & 0xf; |
| 287 | uint64_t Disp = Field & 0xfff; |
| 288 | assert(Index < 32 && "Invalid BDVAddr12"); |
Jim Grosbach | e9119e4 | 2015-05-13 18:37:00 +0000 | [diff] [blame] | 289 | Inst.addOperand(MCOperand::createReg(Base == 0 ? 0 : Regs[Base])); |
| 290 | Inst.addOperand(MCOperand::createImm(Disp)); |
| 291 | Inst.addOperand(MCOperand::createReg(SystemZMC::VR128Regs[Index])); |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 292 | return MCDisassembler::Success; |
| 293 | } |
| 294 | |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 295 | static DecodeStatus decodeBDAddr32Disp12Operand(MCInst &Inst, uint64_t Field, |
| 296 | uint64_t Address, |
| 297 | const void *Decoder) { |
| 298 | return decodeBDAddr12Operand(Inst, Field, SystemZMC::GR32Regs); |
| 299 | } |
| 300 | |
| 301 | static DecodeStatus decodeBDAddr32Disp20Operand(MCInst &Inst, uint64_t Field, |
| 302 | uint64_t Address, |
| 303 | const void *Decoder) { |
| 304 | return decodeBDAddr20Operand(Inst, Field, SystemZMC::GR32Regs); |
| 305 | } |
| 306 | |
| 307 | static DecodeStatus decodeBDAddr64Disp12Operand(MCInst &Inst, uint64_t Field, |
| 308 | uint64_t Address, |
| 309 | const void *Decoder) { |
| 310 | return decodeBDAddr12Operand(Inst, Field, SystemZMC::GR64Regs); |
| 311 | } |
| 312 | |
| 313 | static DecodeStatus decodeBDAddr64Disp20Operand(MCInst &Inst, uint64_t Field, |
| 314 | uint64_t Address, |
| 315 | const void *Decoder) { |
| 316 | return decodeBDAddr20Operand(Inst, Field, SystemZMC::GR64Regs); |
| 317 | } |
| 318 | |
| 319 | static DecodeStatus decodeBDXAddr64Disp12Operand(MCInst &Inst, uint64_t Field, |
| 320 | uint64_t Address, |
| 321 | const void *Decoder) { |
| 322 | return decodeBDXAddr12Operand(Inst, Field, SystemZMC::GR64Regs); |
| 323 | } |
| 324 | |
| 325 | static DecodeStatus decodeBDXAddr64Disp20Operand(MCInst &Inst, uint64_t Field, |
| 326 | uint64_t Address, |
| 327 | const void *Decoder) { |
| 328 | return decodeBDXAddr20Operand(Inst, Field, SystemZMC::GR64Regs); |
| 329 | } |
| 330 | |
Richard Sandiford | 1d95900 | 2013-07-02 14:56:45 +0000 | [diff] [blame] | 331 | static DecodeStatus decodeBDLAddr64Disp12Len8Operand(MCInst &Inst, |
| 332 | uint64_t Field, |
| 333 | uint64_t Address, |
| 334 | const void *Decoder) { |
| 335 | return decodeBDLAddr12Len8Operand(Inst, Field, SystemZMC::GR64Regs); |
| 336 | } |
| 337 | |
Ulrich Weigand | a8b04e1 | 2015-05-05 19:23:40 +0000 | [diff] [blame] | 338 | static DecodeStatus decodeBDVAddr64Disp12Operand(MCInst &Inst, uint64_t Field, |
| 339 | uint64_t Address, |
| 340 | const void *Decoder) { |
| 341 | return decodeBDVAddr12Operand(Inst, Field, SystemZMC::GR64Regs); |
| 342 | } |
| 343 | |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 344 | #include "SystemZGenDisassemblerTables.inc" |
| 345 | |
| 346 | DecodeStatus SystemZDisassembler::getInstruction(MCInst &MI, uint64_t &Size, |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 347 | ArrayRef<uint8_t> Bytes, |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 348 | uint64_t Address, |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 349 | raw_ostream &OS, |
| 350 | raw_ostream &CS) const { |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 351 | // Get the first two bytes of the instruction. |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 352 | Size = 0; |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 353 | if (Bytes.size() < 2) |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 354 | return MCDisassembler::Fail; |
| 355 | |
| 356 | // The top 2 bits of the first byte specify the size. |
| 357 | const uint8_t *Table; |
| 358 | if (Bytes[0] < 0x40) { |
| 359 | Size = 2; |
| 360 | Table = DecoderTable16; |
| 361 | } else if (Bytes[0] < 0xc0) { |
| 362 | Size = 4; |
| 363 | Table = DecoderTable32; |
| 364 | } else { |
| 365 | Size = 6; |
| 366 | Table = DecoderTable48; |
| 367 | } |
| 368 | |
| 369 | // Read any remaining bytes. |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 370 | if (Bytes.size() < Size) |
Richard Sandiford | eb9af29 | 2013-05-14 10:17:52 +0000 | [diff] [blame] | 371 | return MCDisassembler::Fail; |
| 372 | |
| 373 | // Construct the instruction. |
| 374 | uint64_t Inst = 0; |
| 375 | for (uint64_t I = 0; I < Size; ++I) |
| 376 | Inst = (Inst << 8) | Bytes[I]; |
| 377 | |
| 378 | return decodeInstruction(Table, MI, Inst, Address, this, STI); |
| 379 | } |