Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1 | //===- MipsDisassembler.cpp - Disassembler for Mips -------------*- 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 Mips Disassembler. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "Mips.h" |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 15 | #include "MipsRegisterInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "MipsSubtarget.h" |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCContext.h" |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCDisassembler.h" |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCFixedLenDisassembler.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCInst.h" |
| 21 | #include "llvm/MC/MCSubtargetInfo.h" |
| 22 | #include "llvm/Support/MathExtras.h" |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 23 | #include "llvm/Support/TargetRegistry.h" |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 24 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 25 | using namespace llvm; |
| 26 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 27 | #define DEBUG_TYPE "mips-disassembler" |
| 28 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 29 | typedef MCDisassembler::DecodeStatus DecodeStatus; |
| 30 | |
Benjamin Kramer | cb3e98c | 2012-05-01 14:34:24 +0000 | [diff] [blame] | 31 | namespace { |
| 32 | |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 33 | /// A disasembler class for Mips. |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 34 | class MipsDisassemblerBase : public MCDisassembler { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 35 | public: |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 36 | MipsDisassemblerBase(const MCSubtargetInfo &STI, MCContext &Ctx, |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 37 | bool IsBigEndian) |
| 38 | : MCDisassembler(STI, Ctx), |
Vladimir Medic | e886093 | 2014-12-16 15:29:12 +0000 | [diff] [blame] | 39 | IsGP64Bit(STI.getFeatureBits() & Mips::FeatureGP64Bit), |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 40 | IsBigEndian(IsBigEndian) {} |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 41 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 42 | virtual ~MipsDisassemblerBase() {} |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 43 | |
Vladimir Medic | e886093 | 2014-12-16 15:29:12 +0000 | [diff] [blame] | 44 | bool isGP64Bit() const { return IsGP64Bit; } |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 45 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 46 | private: |
Vladimir Medic | e886093 | 2014-12-16 15:29:12 +0000 | [diff] [blame] | 47 | bool IsGP64Bit; |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 48 | protected: |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 49 | bool IsBigEndian; |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 52 | /// A disasembler class for Mips32. |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 53 | class MipsDisassembler : public MipsDisassemblerBase { |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 54 | bool IsMicroMips; |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 55 | public: |
Daniel Sanders | c171f65 | 2014-06-13 13:15:59 +0000 | [diff] [blame] | 56 | MipsDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx, bool bigEndian) |
| 57 | : MipsDisassemblerBase(STI, Ctx, bigEndian) { |
| 58 | IsMicroMips = STI.getFeatureBits() & Mips::FeatureMicroMips; |
| 59 | } |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 60 | |
Daniel Sanders | c171f65 | 2014-06-13 13:15:59 +0000 | [diff] [blame] | 61 | bool hasMips3() const { return STI.getFeatureBits() & Mips::FeatureMips3; } |
| 62 | bool hasMips32() const { return STI.getFeatureBits() & Mips::FeatureMips32; } |
| 63 | bool hasMips32r6() const { |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 64 | return STI.getFeatureBits() & Mips::FeatureMips32r6; |
| 65 | } |
| 66 | |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 67 | bool isGP64() const { return STI.getFeatureBits() & Mips::FeatureGP64Bit; } |
| 68 | |
Daniel Sanders | c171f65 | 2014-06-13 13:15:59 +0000 | [diff] [blame] | 69 | bool hasCOP3() const { |
| 70 | // Only present in MIPS-I and MIPS-II |
| 71 | return !hasMips32() && !hasMips3(); |
| 72 | } |
| 73 | |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 74 | DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 75 | ArrayRef<uint8_t> Bytes, uint64_t Address, |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 76 | raw_ostream &VStream, |
| 77 | raw_ostream &CStream) const override; |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 80 | /// A disasembler class for Mips64. |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 81 | class Mips64Disassembler : public MipsDisassemblerBase { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 82 | public: |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 83 | Mips64Disassembler(const MCSubtargetInfo &STI, MCContext &Ctx, |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 84 | bool bigEndian) : |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 85 | MipsDisassemblerBase(STI, Ctx, bigEndian) {} |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 86 | |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 87 | DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 88 | ArrayRef<uint8_t> Bytes, uint64_t Address, |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 89 | raw_ostream &VStream, |
| 90 | raw_ostream &CStream) const override; |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
Benjamin Kramer | cb3e98c | 2012-05-01 14:34:24 +0000 | [diff] [blame] | 93 | } // end anonymous namespace |
| 94 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 95 | // Forward declare these because the autogenerated code will reference them. |
| 96 | // Definitions are further down. |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 97 | static DecodeStatus DecodeGPR64RegisterClass(MCInst &Inst, |
| 98 | unsigned RegNo, |
| 99 | uint64_t Address, |
| 100 | const void *Decoder); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 101 | |
Reed Kotler | ec8a549 | 2013-02-14 03:05:25 +0000 | [diff] [blame] | 102 | static DecodeStatus DecodeCPU16RegsRegisterClass(MCInst &Inst, |
| 103 | unsigned RegNo, |
| 104 | uint64_t Address, |
| 105 | const void *Decoder); |
| 106 | |
Zoran Jovanovic | b0852e5 | 2014-10-21 08:23:11 +0000 | [diff] [blame] | 107 | static DecodeStatus DecodeGPRMM16RegisterClass(MCInst &Inst, |
| 108 | unsigned RegNo, |
| 109 | uint64_t Address, |
| 110 | const void *Decoder); |
| 111 | |
Jozef Kolek | 1904fa2 | 2014-11-24 14:25:53 +0000 | [diff] [blame] | 112 | static DecodeStatus DecodeGPRMM16ZeroRegisterClass(MCInst &Inst, |
| 113 | unsigned RegNo, |
| 114 | uint64_t Address, |
| 115 | const void *Decoder); |
| 116 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 117 | static DecodeStatus DecodeGPR32RegisterClass(MCInst &Inst, |
| 118 | unsigned RegNo, |
| 119 | uint64_t Address, |
| 120 | const void *Decoder); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 121 | |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 122 | static DecodeStatus DecodePtrRegisterClass(MCInst &Inst, |
| 123 | unsigned Insn, |
| 124 | uint64_t Address, |
| 125 | const void *Decoder); |
| 126 | |
Akira Hatanaka | 654655f | 2013-08-14 00:53:38 +0000 | [diff] [blame] | 127 | static DecodeStatus DecodeDSPRRegisterClass(MCInst &Inst, |
| 128 | unsigned RegNo, |
| 129 | uint64_t Address, |
| 130 | const void *Decoder); |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 131 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 132 | static DecodeStatus DecodeFGR64RegisterClass(MCInst &Inst, |
| 133 | unsigned RegNo, |
| 134 | uint64_t Address, |
| 135 | const void *Decoder); |
| 136 | |
| 137 | static DecodeStatus DecodeFGR32RegisterClass(MCInst &Inst, |
| 138 | unsigned RegNo, |
| 139 | uint64_t Address, |
| 140 | const void *Decoder); |
| 141 | |
| 142 | static DecodeStatus DecodeCCRRegisterClass(MCInst &Inst, |
| 143 | unsigned RegNo, |
| 144 | uint64_t Address, |
| 145 | const void *Decoder); |
| 146 | |
Akira Hatanaka | 1fb1b8b | 2013-07-26 20:13:47 +0000 | [diff] [blame] | 147 | static DecodeStatus DecodeFCCRegisterClass(MCInst &Inst, |
| 148 | unsigned RegNo, |
| 149 | uint64_t Address, |
| 150 | const void *Decoder); |
| 151 | |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 152 | static DecodeStatus DecodeFGRCCRegisterClass(MCInst &Inst, unsigned RegNo, |
| 153 | uint64_t Address, |
| 154 | const void *Decoder); |
| 155 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 156 | static DecodeStatus DecodeHWRegsRegisterClass(MCInst &Inst, |
| 157 | unsigned Insn, |
| 158 | uint64_t Address, |
| 159 | const void *Decoder); |
| 160 | |
| 161 | static DecodeStatus DecodeAFGR64RegisterClass(MCInst &Inst, |
| 162 | unsigned RegNo, |
| 163 | uint64_t Address, |
| 164 | const void *Decoder); |
| 165 | |
Akira Hatanaka | 00fcf2e | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 166 | static DecodeStatus DecodeACC64DSPRegisterClass(MCInst &Inst, |
| 167 | unsigned RegNo, |
| 168 | uint64_t Address, |
| 169 | const void *Decoder); |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 170 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 171 | static DecodeStatus DecodeHI32DSPRegisterClass(MCInst &Inst, |
| 172 | unsigned RegNo, |
| 173 | uint64_t Address, |
| 174 | const void *Decoder); |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 175 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 176 | static DecodeStatus DecodeLO32DSPRegisterClass(MCInst &Inst, |
| 177 | unsigned RegNo, |
| 178 | uint64_t Address, |
| 179 | const void *Decoder); |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 180 | |
Jack Carter | 3eb663b | 2013-09-26 00:09:46 +0000 | [diff] [blame] | 181 | static DecodeStatus DecodeMSA128BRegisterClass(MCInst &Inst, |
| 182 | unsigned RegNo, |
| 183 | uint64_t Address, |
| 184 | const void *Decoder); |
| 185 | |
Jack Carter | 5dc8ac9 | 2013-09-25 23:50:44 +0000 | [diff] [blame] | 186 | static DecodeStatus DecodeMSA128HRegisterClass(MCInst &Inst, |
| 187 | unsigned RegNo, |
| 188 | uint64_t Address, |
| 189 | const void *Decoder); |
| 190 | |
| 191 | static DecodeStatus DecodeMSA128WRegisterClass(MCInst &Inst, |
| 192 | unsigned RegNo, |
| 193 | uint64_t Address, |
| 194 | const void *Decoder); |
| 195 | |
| 196 | static DecodeStatus DecodeMSA128DRegisterClass(MCInst &Inst, |
| 197 | unsigned RegNo, |
| 198 | uint64_t Address, |
| 199 | const void *Decoder); |
| 200 | |
Matheus Almeida | a591fdc | 2013-10-21 12:26:50 +0000 | [diff] [blame] | 201 | static DecodeStatus DecodeMSACtrlRegisterClass(MCInst &Inst, |
| 202 | unsigned RegNo, |
| 203 | uint64_t Address, |
| 204 | const void *Decoder); |
| 205 | |
Daniel Sanders | 2a83d68 | 2014-05-21 12:56:39 +0000 | [diff] [blame] | 206 | static DecodeStatus DecodeCOP2RegisterClass(MCInst &Inst, |
| 207 | unsigned RegNo, |
| 208 | uint64_t Address, |
| 209 | const void *Decoder); |
| 210 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 211 | static DecodeStatus DecodeBranchTarget(MCInst &Inst, |
| 212 | unsigned Offset, |
| 213 | uint64_t Address, |
| 214 | const void *Decoder); |
| 215 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 216 | static DecodeStatus DecodeJumpTarget(MCInst &Inst, |
| 217 | unsigned Insn, |
| 218 | uint64_t Address, |
| 219 | const void *Decoder); |
| 220 | |
Zoran Jovanovic | 3c8869d | 2014-05-16 11:03:45 +0000 | [diff] [blame] | 221 | static DecodeStatus DecodeBranchTarget21(MCInst &Inst, |
| 222 | unsigned Offset, |
| 223 | uint64_t Address, |
| 224 | const void *Decoder); |
| 225 | |
| 226 | static DecodeStatus DecodeBranchTarget26(MCInst &Inst, |
| 227 | unsigned Offset, |
| 228 | uint64_t Address, |
| 229 | const void *Decoder); |
| 230 | |
Jozef Kolek | 9761e96 | 2015-01-12 12:03:34 +0000 | [diff] [blame] | 231 | // DecodeBranchTarget7MM - Decode microMIPS branch offset, which is |
| 232 | // shifted left by 1 bit. |
| 233 | static DecodeStatus DecodeBranchTarget7MM(MCInst &Inst, |
| 234 | unsigned Offset, |
| 235 | uint64_t Address, |
| 236 | const void *Decoder); |
| 237 | |
Zoran Jovanovic | 8a80aa7 | 2013-11-04 14:53:22 +0000 | [diff] [blame] | 238 | // DecodeBranchTargetMM - Decode microMIPS branch offset, which is |
| 239 | // shifted left by 1 bit. |
| 240 | static DecodeStatus DecodeBranchTargetMM(MCInst &Inst, |
| 241 | unsigned Offset, |
| 242 | uint64_t Address, |
| 243 | const void *Decoder); |
| 244 | |
Zoran Jovanovic | 507e084 | 2013-10-29 16:38:59 +0000 | [diff] [blame] | 245 | // DecodeJumpTargetMM - Decode microMIPS jump target, which is |
| 246 | // shifted left by 1 bit. |
| 247 | static DecodeStatus DecodeJumpTargetMM(MCInst &Inst, |
| 248 | unsigned Insn, |
| 249 | uint64_t Address, |
| 250 | const void *Decoder); |
| 251 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 252 | static DecodeStatus DecodeMem(MCInst &Inst, |
| 253 | unsigned Insn, |
| 254 | uint64_t Address, |
| 255 | const void *Decoder); |
| 256 | |
Daniel Sanders | 92db6b7 | 2014-10-01 08:26:55 +0000 | [diff] [blame] | 257 | static DecodeStatus DecodeCacheOp(MCInst &Inst, |
| 258 | unsigned Insn, |
| 259 | uint64_t Address, |
| 260 | const void *Decoder); |
| 261 | |
Jozef Kolek | ab6d1cc | 2014-12-23 19:55:34 +0000 | [diff] [blame] | 262 | static DecodeStatus DecodeCacheOpMM(MCInst &Inst, |
| 263 | unsigned Insn, |
| 264 | uint64_t Address, |
| 265 | const void *Decoder); |
| 266 | |
Daniel Sanders | b4484d6 | 2014-11-27 17:28:10 +0000 | [diff] [blame] | 267 | static DecodeStatus DecodeSyncI(MCInst &Inst, |
| 268 | unsigned Insn, |
| 269 | uint64_t Address, |
| 270 | const void *Decoder); |
| 271 | |
Matheus Almeida | fe0bf9f | 2013-10-21 13:07:13 +0000 | [diff] [blame] | 272 | static DecodeStatus DecodeMSA128Mem(MCInst &Inst, unsigned Insn, |
| 273 | uint64_t Address, const void *Decoder); |
| 274 | |
Jozef Kolek | 315e7ec | 2014-11-26 18:56:38 +0000 | [diff] [blame] | 275 | static DecodeStatus DecodeMemMMImm4(MCInst &Inst, |
| 276 | unsigned Insn, |
| 277 | uint64_t Address, |
| 278 | const void *Decoder); |
| 279 | |
Jozef Kolek | 12c6982 | 2014-12-23 16:16:33 +0000 | [diff] [blame] | 280 | static DecodeStatus DecodeMemMMSPImm5Lsl2(MCInst &Inst, |
| 281 | unsigned Insn, |
| 282 | uint64_t Address, |
| 283 | const void *Decoder); |
| 284 | |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 285 | static DecodeStatus DecodeMemMMImm12(MCInst &Inst, |
| 286 | unsigned Insn, |
| 287 | uint64_t Address, |
| 288 | const void *Decoder); |
| 289 | |
| 290 | static DecodeStatus DecodeMemMMImm16(MCInst &Inst, |
| 291 | unsigned Insn, |
| 292 | uint64_t Address, |
| 293 | const void *Decoder); |
| 294 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 295 | static DecodeStatus DecodeFMem(MCInst &Inst, unsigned Insn, |
| 296 | uint64_t Address, |
| 297 | const void *Decoder); |
| 298 | |
Daniel Sanders | 92db6b7 | 2014-10-01 08:26:55 +0000 | [diff] [blame] | 299 | static DecodeStatus DecodeFMem2(MCInst &Inst, unsigned Insn, |
| 300 | uint64_t Address, |
| 301 | const void *Decoder); |
| 302 | |
| 303 | static DecodeStatus DecodeFMem3(MCInst &Inst, unsigned Insn, |
| 304 | uint64_t Address, |
| 305 | const void *Decoder); |
| 306 | |
Vladimir Medic | 435cf8a | 2015-01-21 10:47:36 +0000 | [diff] [blame] | 307 | static DecodeStatus DecodeFMemCop2R6(MCInst &Inst, unsigned Insn, |
| 308 | uint64_t Address, |
| 309 | const void *Decoder); |
| 310 | |
Daniel Sanders | 6a803f6 | 2014-06-16 13:13:03 +0000 | [diff] [blame] | 311 | static DecodeStatus DecodeSpecial3LlSc(MCInst &Inst, |
| 312 | unsigned Insn, |
| 313 | uint64_t Address, |
| 314 | const void *Decoder); |
| 315 | |
Jozef Kolek | aa2b927 | 2014-11-27 14:41:44 +0000 | [diff] [blame] | 316 | static DecodeStatus DecodeAddiur2Simm7(MCInst &Inst, |
| 317 | unsigned Value, |
| 318 | uint64_t Address, |
| 319 | const void *Decoder); |
| 320 | |
| 321 | static DecodeStatus DecodeUImm6Lsl2(MCInst &Inst, |
| 322 | unsigned Value, |
| 323 | uint64_t Address, |
| 324 | const void *Decoder); |
| 325 | |
| 326 | static DecodeStatus DecodeLiSimm7(MCInst &Inst, |
| 327 | unsigned Value, |
| 328 | uint64_t Address, |
| 329 | const void *Decoder); |
| 330 | |
| 331 | static DecodeStatus DecodeSimm4(MCInst &Inst, |
| 332 | unsigned Value, |
| 333 | uint64_t Address, |
| 334 | const void *Decoder); |
| 335 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 336 | static DecodeStatus DecodeSimm16(MCInst &Inst, |
| 337 | unsigned Insn, |
| 338 | uint64_t Address, |
| 339 | const void *Decoder); |
| 340 | |
Matheus Almeida | 779c593 | 2013-11-18 12:32:49 +0000 | [diff] [blame] | 341 | // Decode the immediate field of an LSA instruction which |
| 342 | // is off by one. |
| 343 | static DecodeStatus DecodeLSAImm(MCInst &Inst, |
| 344 | unsigned Insn, |
| 345 | uint64_t Address, |
| 346 | const void *Decoder); |
| 347 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 348 | static DecodeStatus DecodeInsSize(MCInst &Inst, |
| 349 | unsigned Insn, |
| 350 | uint64_t Address, |
| 351 | const void *Decoder); |
| 352 | |
| 353 | static DecodeStatus DecodeExtSize(MCInst &Inst, |
| 354 | unsigned Insn, |
| 355 | uint64_t Address, |
| 356 | const void *Decoder); |
| 357 | |
Daniel Sanders | b59e1a4 | 2014-05-15 10:45:58 +0000 | [diff] [blame] | 358 | static DecodeStatus DecodeSimm19Lsl2(MCInst &Inst, unsigned Insn, |
| 359 | uint64_t Address, const void *Decoder); |
| 360 | |
Zoran Jovanovic | 2855142 | 2014-06-09 09:49:51 +0000 | [diff] [blame] | 361 | static DecodeStatus DecodeSimm18Lsl3(MCInst &Inst, unsigned Insn, |
| 362 | uint64_t Address, const void *Decoder); |
| 363 | |
Vladimir Medic | b682ddf | 2014-12-01 11:12:04 +0000 | [diff] [blame] | 364 | static DecodeStatus DecodeSimm9SP(MCInst &Inst, unsigned Insn, |
| 365 | uint64_t Address, const void *Decoder); |
| 366 | |
| 367 | static DecodeStatus DecodeANDI16Imm(MCInst &Inst, unsigned Insn, |
| 368 | uint64_t Address, const void *Decoder); |
| 369 | |
| 370 | static DecodeStatus DecodeUImm5lsl2(MCInst &Inst, unsigned Insn, |
| 371 | uint64_t Address, const void *Decoder); |
| 372 | |
Daniel Sanders | b50ccf8 | 2014-04-01 10:35:28 +0000 | [diff] [blame] | 373 | /// INSVE_[BHWD] have an implicit operand that the generated decoder doesn't |
| 374 | /// handle. |
| 375 | template <typename InsnType> |
| 376 | static DecodeStatus DecodeINSVE_DF(MCInst &MI, InsnType insn, uint64_t Address, |
| 377 | const void *Decoder); |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 378 | |
| 379 | template <typename InsnType> |
| 380 | static DecodeStatus |
| 381 | DecodeAddiGroupBranch(MCInst &MI, InsnType insn, uint64_t Address, |
| 382 | const void *Decoder); |
| 383 | |
| 384 | template <typename InsnType> |
| 385 | static DecodeStatus |
| 386 | DecodeDaddiGroupBranch(MCInst &MI, InsnType insn, uint64_t Address, |
| 387 | const void *Decoder); |
| 388 | |
| 389 | template <typename InsnType> |
| 390 | static DecodeStatus |
| 391 | DecodeBlezlGroupBranch(MCInst &MI, InsnType insn, uint64_t Address, |
| 392 | const void *Decoder); |
| 393 | |
| 394 | template <typename InsnType> |
| 395 | static DecodeStatus |
| 396 | DecodeBgtzlGroupBranch(MCInst &MI, InsnType insn, uint64_t Address, |
| 397 | const void *Decoder); |
| 398 | |
| 399 | template <typename InsnType> |
| 400 | static DecodeStatus |
| 401 | DecodeBgtzGroupBranch(MCInst &MI, InsnType insn, uint64_t Address, |
| 402 | const void *Decoder); |
| 403 | |
Zoran Jovanovic | 28a0ca0 | 2014-06-12 11:47:44 +0000 | [diff] [blame] | 404 | template <typename InsnType> |
| 405 | static DecodeStatus |
| 406 | DecodeBlezGroupBranch(MCInst &MI, InsnType insn, uint64_t Address, |
| 407 | const void *Decoder); |
| 408 | |
Zoran Jovanovic | a4c4b5f | 2014-11-19 16:44:02 +0000 | [diff] [blame] | 409 | static DecodeStatus DecodeRegListOperand(MCInst &Inst, unsigned Insn, |
| 410 | uint64_t Address, |
| 411 | const void *Decoder); |
| 412 | |
Zoran Jovanovic | f9a0250 | 2014-11-27 18:28:59 +0000 | [diff] [blame] | 413 | static DecodeStatus DecodeRegListOperand16(MCInst &Inst, unsigned Insn, |
| 414 | uint64_t Address, |
| 415 | const void *Decoder); |
| 416 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 417 | namespace llvm { |
| 418 | extern Target TheMipselTarget, TheMipsTarget, TheMips64Target, |
| 419 | TheMips64elTarget; |
| 420 | } |
| 421 | |
| 422 | static MCDisassembler *createMipsDisassembler( |
| 423 | const Target &T, |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 424 | const MCSubtargetInfo &STI, |
| 425 | MCContext &Ctx) { |
| 426 | return new MipsDisassembler(STI, Ctx, true); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | static MCDisassembler *createMipselDisassembler( |
| 430 | const Target &T, |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 431 | const MCSubtargetInfo &STI, |
| 432 | MCContext &Ctx) { |
| 433 | return new MipsDisassembler(STI, Ctx, false); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | static MCDisassembler *createMips64Disassembler( |
| 437 | const Target &T, |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 438 | const MCSubtargetInfo &STI, |
| 439 | MCContext &Ctx) { |
| 440 | return new Mips64Disassembler(STI, Ctx, true); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | static MCDisassembler *createMips64elDisassembler( |
| 444 | const Target &T, |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 445 | const MCSubtargetInfo &STI, |
| 446 | MCContext &Ctx) { |
| 447 | return new Mips64Disassembler(STI, Ctx, false); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | extern "C" void LLVMInitializeMipsDisassembler() { |
| 451 | // Register the disassembler. |
| 452 | TargetRegistry::RegisterMCDisassembler(TheMipsTarget, |
| 453 | createMipsDisassembler); |
| 454 | TargetRegistry::RegisterMCDisassembler(TheMipselTarget, |
| 455 | createMipselDisassembler); |
| 456 | TargetRegistry::RegisterMCDisassembler(TheMips64Target, |
| 457 | createMips64Disassembler); |
| 458 | TargetRegistry::RegisterMCDisassembler(TheMips64elTarget, |
| 459 | createMips64elDisassembler); |
| 460 | } |
| 461 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 462 | #include "MipsGenDisassemblerTables.inc" |
| 463 | |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 464 | static unsigned getReg(const void *D, unsigned RC, unsigned RegNo) { |
| 465 | const MipsDisassemblerBase *Dis = static_cast<const MipsDisassemblerBase*>(D); |
| 466 | const MCRegisterInfo *RegInfo = Dis->getContext().getRegisterInfo(); |
| 467 | return *(RegInfo->getRegClass(RC).begin() + RegNo); |
| 468 | } |
| 469 | |
Daniel Sanders | b50ccf8 | 2014-04-01 10:35:28 +0000 | [diff] [blame] | 470 | template <typename InsnType> |
| 471 | static DecodeStatus DecodeINSVE_DF(MCInst &MI, InsnType insn, uint64_t Address, |
| 472 | const void *Decoder) { |
| 473 | typedef DecodeStatus (*DecodeFN)(MCInst &, unsigned, uint64_t, const void *); |
| 474 | // The size of the n field depends on the element size |
| 475 | // The register class also depends on this. |
| 476 | InsnType tmp = fieldFromInstruction(insn, 17, 5); |
| 477 | unsigned NSize = 0; |
| 478 | DecodeFN RegDecoder = nullptr; |
| 479 | if ((tmp & 0x18) == 0x00) { // INSVE_B |
| 480 | NSize = 4; |
| 481 | RegDecoder = DecodeMSA128BRegisterClass; |
| 482 | } else if ((tmp & 0x1c) == 0x10) { // INSVE_H |
| 483 | NSize = 3; |
| 484 | RegDecoder = DecodeMSA128HRegisterClass; |
| 485 | } else if ((tmp & 0x1e) == 0x18) { // INSVE_W |
| 486 | NSize = 2; |
| 487 | RegDecoder = DecodeMSA128WRegisterClass; |
| 488 | } else if ((tmp & 0x1f) == 0x1c) { // INSVE_D |
| 489 | NSize = 1; |
| 490 | RegDecoder = DecodeMSA128DRegisterClass; |
| 491 | } else |
| 492 | llvm_unreachable("Invalid encoding"); |
| 493 | |
| 494 | assert(NSize != 0 && RegDecoder != nullptr); |
| 495 | |
| 496 | // $wd |
| 497 | tmp = fieldFromInstruction(insn, 6, 5); |
| 498 | if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler::Fail) |
| 499 | return MCDisassembler::Fail; |
| 500 | // $wd_in |
| 501 | if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler::Fail) |
| 502 | return MCDisassembler::Fail; |
| 503 | // $n |
| 504 | tmp = fieldFromInstruction(insn, 16, NSize); |
| 505 | MI.addOperand(MCOperand::CreateImm(tmp)); |
| 506 | // $ws |
| 507 | tmp = fieldFromInstruction(insn, 11, 5); |
| 508 | if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler::Fail) |
| 509 | return MCDisassembler::Fail; |
| 510 | // $n2 |
| 511 | MI.addOperand(MCOperand::CreateImm(0)); |
| 512 | |
| 513 | return MCDisassembler::Success; |
| 514 | } |
| 515 | |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 516 | template <typename InsnType> |
| 517 | static DecodeStatus DecodeAddiGroupBranch(MCInst &MI, InsnType insn, |
| 518 | uint64_t Address, |
| 519 | const void *Decoder) { |
| 520 | // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled |
| 521 | // (otherwise we would have matched the ADDI instruction from the earlier |
| 522 | // ISA's instead). |
| 523 | // |
| 524 | // We have: |
| 525 | // 0b001000 sssss ttttt iiiiiiiiiiiiiiii |
| 526 | // BOVC if rs >= rt |
| 527 | // BEQZALC if rs == 0 && rt != 0 |
| 528 | // BEQC if rs < rt && rs != 0 |
| 529 | |
| 530 | InsnType Rs = fieldFromInstruction(insn, 21, 5); |
| 531 | InsnType Rt = fieldFromInstruction(insn, 16, 5); |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 532 | InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4; |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 533 | bool HasRs = false; |
| 534 | |
| 535 | if (Rs >= Rt) { |
| 536 | MI.setOpcode(Mips::BOVC); |
| 537 | HasRs = true; |
| 538 | } else if (Rs != 0 && Rs < Rt) { |
| 539 | MI.setOpcode(Mips::BEQC); |
| 540 | HasRs = true; |
| 541 | } else |
| 542 | MI.setOpcode(Mips::BEQZALC); |
| 543 | |
| 544 | if (HasRs) |
| 545 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 546 | Rs))); |
| 547 | |
| 548 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 549 | Rt))); |
| 550 | MI.addOperand(MCOperand::CreateImm(Imm)); |
| 551 | |
| 552 | return MCDisassembler::Success; |
| 553 | } |
| 554 | |
| 555 | template <typename InsnType> |
| 556 | static DecodeStatus DecodeDaddiGroupBranch(MCInst &MI, InsnType insn, |
| 557 | uint64_t Address, |
| 558 | const void *Decoder) { |
| 559 | // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled |
| 560 | // (otherwise we would have matched the ADDI instruction from the earlier |
| 561 | // ISA's instead). |
| 562 | // |
| 563 | // We have: |
| 564 | // 0b011000 sssss ttttt iiiiiiiiiiiiiiii |
| 565 | // BNVC if rs >= rt |
| 566 | // BNEZALC if rs == 0 && rt != 0 |
| 567 | // BNEC if rs < rt && rs != 0 |
| 568 | |
| 569 | InsnType Rs = fieldFromInstruction(insn, 21, 5); |
| 570 | InsnType Rt = fieldFromInstruction(insn, 16, 5); |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 571 | InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4; |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 572 | bool HasRs = false; |
| 573 | |
| 574 | if (Rs >= Rt) { |
| 575 | MI.setOpcode(Mips::BNVC); |
| 576 | HasRs = true; |
| 577 | } else if (Rs != 0 && Rs < Rt) { |
| 578 | MI.setOpcode(Mips::BNEC); |
| 579 | HasRs = true; |
| 580 | } else |
| 581 | MI.setOpcode(Mips::BNEZALC); |
| 582 | |
| 583 | if (HasRs) |
| 584 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 585 | Rs))); |
| 586 | |
| 587 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 588 | Rt))); |
| 589 | MI.addOperand(MCOperand::CreateImm(Imm)); |
| 590 | |
| 591 | return MCDisassembler::Success; |
| 592 | } |
| 593 | |
| 594 | template <typename InsnType> |
| 595 | static DecodeStatus DecodeBlezlGroupBranch(MCInst &MI, InsnType insn, |
| 596 | uint64_t Address, |
| 597 | const void *Decoder) { |
| 598 | // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled |
| 599 | // (otherwise we would have matched the BLEZL instruction from the earlier |
| 600 | // ISA's instead). |
| 601 | // |
| 602 | // We have: |
| 603 | // 0b010110 sssss ttttt iiiiiiiiiiiiiiii |
| 604 | // Invalid if rs == 0 |
| 605 | // BLEZC if rs == 0 && rt != 0 |
| 606 | // BGEZC if rs == rt && rt != 0 |
| 607 | // BGEC if rs != rt && rs != 0 && rt != 0 |
| 608 | |
| 609 | InsnType Rs = fieldFromInstruction(insn, 21, 5); |
| 610 | InsnType Rt = fieldFromInstruction(insn, 16, 5); |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 611 | InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4; |
Zoran Jovanovic | 28a0ca0 | 2014-06-12 11:47:44 +0000 | [diff] [blame] | 612 | bool HasRs = false; |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 613 | |
| 614 | if (Rt == 0) |
| 615 | return MCDisassembler::Fail; |
| 616 | else if (Rs == 0) |
| 617 | MI.setOpcode(Mips::BLEZC); |
| 618 | else if (Rs == Rt) |
| 619 | MI.setOpcode(Mips::BGEZC); |
Zoran Jovanovic | 28a0ca0 | 2014-06-12 11:47:44 +0000 | [diff] [blame] | 620 | else { |
| 621 | HasRs = true; |
| 622 | MI.setOpcode(Mips::BGEC); |
| 623 | } |
| 624 | |
| 625 | if (HasRs) |
| 626 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 627 | Rs))); |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 628 | |
| 629 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 630 | Rt))); |
| 631 | |
| 632 | MI.addOperand(MCOperand::CreateImm(Imm)); |
| 633 | |
| 634 | return MCDisassembler::Success; |
| 635 | } |
| 636 | |
| 637 | template <typename InsnType> |
| 638 | static DecodeStatus DecodeBgtzlGroupBranch(MCInst &MI, InsnType insn, |
| 639 | uint64_t Address, |
| 640 | const void *Decoder) { |
| 641 | // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled |
| 642 | // (otherwise we would have matched the BGTZL instruction from the earlier |
| 643 | // ISA's instead). |
| 644 | // |
| 645 | // We have: |
| 646 | // 0b010111 sssss ttttt iiiiiiiiiiiiiiii |
| 647 | // Invalid if rs == 0 |
| 648 | // BGTZC if rs == 0 && rt != 0 |
| 649 | // BLTZC if rs == rt && rt != 0 |
| 650 | // BLTC if rs != rt && rs != 0 && rt != 0 |
| 651 | |
Zoran Jovanovic | 5c14b06 | 2014-06-18 14:36:00 +0000 | [diff] [blame] | 652 | bool HasRs = false; |
| 653 | |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 654 | InsnType Rs = fieldFromInstruction(insn, 21, 5); |
| 655 | InsnType Rt = fieldFromInstruction(insn, 16, 5); |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 656 | InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4; |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 657 | |
| 658 | if (Rt == 0) |
| 659 | return MCDisassembler::Fail; |
| 660 | else if (Rs == 0) |
| 661 | MI.setOpcode(Mips::BGTZC); |
| 662 | else if (Rs == Rt) |
| 663 | MI.setOpcode(Mips::BLTZC); |
Zoran Jovanovic | 5c14b06 | 2014-06-18 14:36:00 +0000 | [diff] [blame] | 664 | else { |
| 665 | MI.setOpcode(Mips::BLTC); |
| 666 | HasRs = true; |
| 667 | } |
| 668 | |
| 669 | if (HasRs) |
| 670 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 671 | Rs))); |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 672 | |
| 673 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 674 | Rt))); |
| 675 | |
| 676 | MI.addOperand(MCOperand::CreateImm(Imm)); |
| 677 | |
| 678 | return MCDisassembler::Success; |
| 679 | } |
| 680 | |
| 681 | template <typename InsnType> |
| 682 | static DecodeStatus DecodeBgtzGroupBranch(MCInst &MI, InsnType insn, |
| 683 | uint64_t Address, |
| 684 | const void *Decoder) { |
| 685 | // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled |
| 686 | // (otherwise we would have matched the BGTZ instruction from the earlier |
| 687 | // ISA's instead). |
| 688 | // |
| 689 | // We have: |
| 690 | // 0b000111 sssss ttttt iiiiiiiiiiiiiiii |
| 691 | // BGTZ if rt == 0 |
| 692 | // BGTZALC if rs == 0 && rt != 0 |
| 693 | // BLTZALC if rs != 0 && rs == rt |
| 694 | // BLTUC if rs != 0 && rs != rt |
| 695 | |
| 696 | InsnType Rs = fieldFromInstruction(insn, 21, 5); |
| 697 | InsnType Rt = fieldFromInstruction(insn, 16, 5); |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 698 | InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4; |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 699 | bool HasRs = false; |
| 700 | bool HasRt = false; |
| 701 | |
| 702 | if (Rt == 0) { |
| 703 | MI.setOpcode(Mips::BGTZ); |
| 704 | HasRs = true; |
| 705 | } else if (Rs == 0) { |
| 706 | MI.setOpcode(Mips::BGTZALC); |
| 707 | HasRt = true; |
| 708 | } else if (Rs == Rt) { |
| 709 | MI.setOpcode(Mips::BLTZALC); |
| 710 | HasRs = true; |
Zoran Jovanovic | 5c14b06 | 2014-06-18 14:36:00 +0000 | [diff] [blame] | 711 | } else { |
| 712 | MI.setOpcode(Mips::BLTUC); |
| 713 | HasRs = true; |
| 714 | HasRt = true; |
| 715 | } |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 716 | |
| 717 | if (HasRs) |
| 718 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 719 | Rs))); |
| 720 | |
| 721 | if (HasRt) |
| 722 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 723 | Rt))); |
| 724 | |
| 725 | MI.addOperand(MCOperand::CreateImm(Imm)); |
| 726 | |
| 727 | return MCDisassembler::Success; |
| 728 | } |
| 729 | |
Zoran Jovanovic | 28a0ca0 | 2014-06-12 11:47:44 +0000 | [diff] [blame] | 730 | template <typename InsnType> |
| 731 | static DecodeStatus DecodeBlezGroupBranch(MCInst &MI, InsnType insn, |
| 732 | uint64_t Address, |
| 733 | const void *Decoder) { |
| 734 | // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled |
| 735 | // (otherwise we would have matched the BLEZL instruction from the earlier |
| 736 | // ISA's instead). |
| 737 | // |
| 738 | // We have: |
| 739 | // 0b000110 sssss ttttt iiiiiiiiiiiiiiii |
| 740 | // Invalid if rs == 0 |
| 741 | // BLEZALC if rs == 0 && rt != 0 |
| 742 | // BGEZALC if rs == rt && rt != 0 |
| 743 | // BGEUC if rs != rt && rs != 0 && rt != 0 |
| 744 | |
| 745 | InsnType Rs = fieldFromInstruction(insn, 21, 5); |
| 746 | InsnType Rt = fieldFromInstruction(insn, 16, 5); |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 747 | InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4; |
Zoran Jovanovic | 28a0ca0 | 2014-06-12 11:47:44 +0000 | [diff] [blame] | 748 | bool HasRs = false; |
| 749 | |
| 750 | if (Rt == 0) |
| 751 | return MCDisassembler::Fail; |
| 752 | else if (Rs == 0) |
| 753 | MI.setOpcode(Mips::BLEZALC); |
| 754 | else if (Rs == Rt) |
| 755 | MI.setOpcode(Mips::BGEZALC); |
| 756 | else { |
| 757 | HasRs = true; |
| 758 | MI.setOpcode(Mips::BGEUC); |
| 759 | } |
| 760 | |
| 761 | if (HasRs) |
| 762 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 763 | Rs))); |
| 764 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 765 | Rt))); |
| 766 | |
| 767 | MI.addOperand(MCOperand::CreateImm(Imm)); |
| 768 | |
| 769 | return MCDisassembler::Success; |
| 770 | } |
| 771 | |
Jozef Kolek | ea22c4c | 2014-11-24 13:29:59 +0000 | [diff] [blame] | 772 | /// Read two bytes from the ArrayRef and return 16 bit halfword sorted |
| 773 | /// according to the given endianess. |
| 774 | static DecodeStatus readInstruction16(ArrayRef<uint8_t> Bytes, uint64_t Address, |
| 775 | uint64_t &Size, uint32_t &Insn, |
| 776 | bool IsBigEndian) { |
| 777 | // We want to read exactly 2 Bytes of data. |
| 778 | if (Bytes.size() < 2) { |
| 779 | Size = 0; |
| 780 | return MCDisassembler::Fail; |
| 781 | } |
| 782 | |
| 783 | if (IsBigEndian) { |
| 784 | Insn = (Bytes[0] << 8) | Bytes[1]; |
| 785 | } else { |
| 786 | Insn = (Bytes[1] << 8) | Bytes[0]; |
| 787 | } |
| 788 | |
| 789 | return MCDisassembler::Success; |
| 790 | } |
| 791 | |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 792 | /// Read four bytes from the ArrayRef and return 32 bit word sorted |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 793 | /// according to the given endianess |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 794 | static DecodeStatus readInstruction32(ArrayRef<uint8_t> Bytes, uint64_t Address, |
| 795 | uint64_t &Size, uint32_t &Insn, |
| 796 | bool IsBigEndian, bool IsMicroMips) { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 797 | // We want to read exactly 4 Bytes of data. |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 798 | if (Bytes.size() < 4) { |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 799 | Size = 0; |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 800 | return MCDisassembler::Fail; |
| 801 | } |
| 802 | |
Jozef Kolek | ea22c4c | 2014-11-24 13:29:59 +0000 | [diff] [blame] | 803 | // High 16 bits of a 32-bit microMIPS instruction (where the opcode is) |
| 804 | // always precede the low 16 bits in the instruction stream (that is, they |
| 805 | // are placed at lower addresses in the instruction stream). |
| 806 | // |
| 807 | // microMIPS byte ordering: |
| 808 | // Big-endian: 0 | 1 | 2 | 3 |
| 809 | // Little-endian: 1 | 0 | 3 | 2 |
| 810 | |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 811 | if (IsBigEndian) { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 812 | // Encoded as a big-endian 32-bit word in the stream. |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 813 | Insn = |
| 814 | (Bytes[3] << 0) | (Bytes[2] << 8) | (Bytes[1] << 16) | (Bytes[0] << 24); |
| 815 | } else { |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 816 | if (IsMicroMips) { |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 817 | Insn = (Bytes[2] << 0) | (Bytes[3] << 8) | (Bytes[0] << 16) | |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 818 | (Bytes[1] << 24); |
| 819 | } else { |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 820 | Insn = (Bytes[0] << 0) | (Bytes[1] << 8) | (Bytes[2] << 16) | |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 821 | (Bytes[3] << 24); |
| 822 | } |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | return MCDisassembler::Success; |
| 826 | } |
| 827 | |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 828 | DecodeStatus MipsDisassembler::getInstruction(MCInst &Instr, uint64_t &Size, |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 829 | ArrayRef<uint8_t> Bytes, |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 830 | uint64_t Address, |
| 831 | raw_ostream &VStream, |
| 832 | raw_ostream &CStream) const { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 833 | uint32_t Insn; |
Jozef Kolek | ea22c4c | 2014-11-24 13:29:59 +0000 | [diff] [blame] | 834 | DecodeStatus Result; |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 835 | |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 836 | if (IsMicroMips) { |
Jozef Kolek | ea22c4c | 2014-11-24 13:29:59 +0000 | [diff] [blame] | 837 | Result = readInstruction16(Bytes, Address, Size, Insn, IsBigEndian); |
| 838 | |
| 839 | DEBUG(dbgs() << "Trying MicroMips16 table (16-bit instructions):\n"); |
| 840 | // Calling the auto-generated decoder function. |
| 841 | Result = decodeInstruction(DecoderTableMicroMips16, Instr, Insn, Address, |
| 842 | this, STI); |
| 843 | if (Result != MCDisassembler::Fail) { |
| 844 | Size = 2; |
| 845 | return Result; |
| 846 | } |
| 847 | |
| 848 | Result = readInstruction32(Bytes, Address, Size, Insn, IsBigEndian, true); |
| 849 | if (Result == MCDisassembler::Fail) |
| 850 | return MCDisassembler::Fail; |
| 851 | |
| 852 | DEBUG(dbgs() << "Trying MicroMips32 table (32-bit instructions):\n"); |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 853 | // Calling the auto-generated decoder function. |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 854 | Result = decodeInstruction(DecoderTableMicroMips32, Instr, Insn, Address, |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 855 | this, STI); |
| 856 | if (Result != MCDisassembler::Fail) { |
| 857 | Size = 4; |
| 858 | return Result; |
| 859 | } |
| 860 | return MCDisassembler::Fail; |
| 861 | } |
| 862 | |
Jozef Kolek | ea22c4c | 2014-11-24 13:29:59 +0000 | [diff] [blame] | 863 | Result = readInstruction32(Bytes, Address, Size, Insn, IsBigEndian, false); |
| 864 | if (Result == MCDisassembler::Fail) |
| 865 | return MCDisassembler::Fail; |
| 866 | |
Daniel Sanders | c171f65 | 2014-06-13 13:15:59 +0000 | [diff] [blame] | 867 | if (hasCOP3()) { |
| 868 | DEBUG(dbgs() << "Trying COP3_ table (32-bit opcodes):\n"); |
| 869 | Result = |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 870 | decodeInstruction(DecoderTableCOP3_32, Instr, Insn, Address, this, STI); |
Daniel Sanders | c171f65 | 2014-06-13 13:15:59 +0000 | [diff] [blame] | 871 | if (Result != MCDisassembler::Fail) { |
| 872 | Size = 4; |
| 873 | return Result; |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | if (hasMips32r6() && isGP64()) { |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 878 | DEBUG(dbgs() << "Trying Mips32r6_64r6 (GPR64) table (32-bit opcodes):\n"); |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 879 | Result = decodeInstruction(DecoderTableMips32r6_64r6_GP6432, Instr, Insn, |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 880 | Address, this, STI); |
| 881 | if (Result != MCDisassembler::Fail) { |
| 882 | Size = 4; |
| 883 | return Result; |
| 884 | } |
| 885 | } |
| 886 | |
Daniel Sanders | c171f65 | 2014-06-13 13:15:59 +0000 | [diff] [blame] | 887 | if (hasMips32r6()) { |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 888 | DEBUG(dbgs() << "Trying Mips32r6_64r6 table (32-bit opcodes):\n"); |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 889 | Result = decodeInstruction(DecoderTableMips32r6_64r632, Instr, Insn, |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 890 | Address, this, STI); |
| 891 | if (Result != MCDisassembler::Fail) { |
| 892 | Size = 4; |
| 893 | return Result; |
| 894 | } |
| 895 | } |
| 896 | |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 897 | DEBUG(dbgs() << "Trying Mips table (32-bit opcodes):\n"); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 898 | // Calling the auto-generated decoder function. |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 899 | Result = |
| 900 | decodeInstruction(DecoderTableMips32, Instr, Insn, Address, this, STI); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 901 | if (Result != MCDisassembler::Fail) { |
| 902 | Size = 4; |
| 903 | return Result; |
| 904 | } |
| 905 | |
| 906 | return MCDisassembler::Fail; |
| 907 | } |
| 908 | |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 909 | DecodeStatus Mips64Disassembler::getInstruction(MCInst &Instr, uint64_t &Size, |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 910 | ArrayRef<uint8_t> Bytes, |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 911 | uint64_t Address, |
| 912 | raw_ostream &VStream, |
| 913 | raw_ostream &CStream) const { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 914 | uint32_t Insn; |
| 915 | |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 916 | DecodeStatus Result = |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 917 | readInstruction32(Bytes, Address, Size, Insn, IsBigEndian, false); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 918 | if (Result == MCDisassembler::Fail) |
| 919 | return MCDisassembler::Fail; |
| 920 | |
| 921 | // Calling the auto-generated decoder function. |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 922 | Result = |
| 923 | decodeInstruction(DecoderTableMips6432, Instr, Insn, Address, this, STI); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 924 | if (Result != MCDisassembler::Fail) { |
| 925 | Size = 4; |
| 926 | return Result; |
| 927 | } |
| 928 | // If we fail to decode in Mips64 decoder space we can try in Mips32 |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 929 | Result = |
| 930 | decodeInstruction(DecoderTableMips32, Instr, Insn, Address, this, STI); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 931 | if (Result != MCDisassembler::Fail) { |
| 932 | Size = 4; |
| 933 | return Result; |
| 934 | } |
| 935 | |
| 936 | return MCDisassembler::Fail; |
| 937 | } |
| 938 | |
Reed Kotler | ec8a549 | 2013-02-14 03:05:25 +0000 | [diff] [blame] | 939 | static DecodeStatus DecodeCPU16RegsRegisterClass(MCInst &Inst, |
| 940 | unsigned RegNo, |
| 941 | uint64_t Address, |
| 942 | const void *Decoder) { |
| 943 | |
| 944 | return MCDisassembler::Fail; |
| 945 | |
| 946 | } |
| 947 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 948 | static DecodeStatus DecodeGPR64RegisterClass(MCInst &Inst, |
| 949 | unsigned RegNo, |
| 950 | uint64_t Address, |
| 951 | const void *Decoder) { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 952 | |
| 953 | if (RegNo > 31) |
| 954 | return MCDisassembler::Fail; |
| 955 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 956 | unsigned Reg = getReg(Decoder, Mips::GPR64RegClassID, RegNo); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 957 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 958 | return MCDisassembler::Success; |
| 959 | } |
| 960 | |
Zoran Jovanovic | b0852e5 | 2014-10-21 08:23:11 +0000 | [diff] [blame] | 961 | static DecodeStatus DecodeGPRMM16RegisterClass(MCInst &Inst, |
| 962 | unsigned RegNo, |
| 963 | uint64_t Address, |
| 964 | const void *Decoder) { |
Jozef Kolek | ea22c4c | 2014-11-24 13:29:59 +0000 | [diff] [blame] | 965 | if (RegNo > 7) |
| 966 | return MCDisassembler::Fail; |
| 967 | unsigned Reg = getReg(Decoder, Mips::GPRMM16RegClassID, RegNo); |
| 968 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 969 | return MCDisassembler::Success; |
Zoran Jovanovic | b0852e5 | 2014-10-21 08:23:11 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Jozef Kolek | 1904fa2 | 2014-11-24 14:25:53 +0000 | [diff] [blame] | 972 | static DecodeStatus DecodeGPRMM16ZeroRegisterClass(MCInst &Inst, |
| 973 | unsigned RegNo, |
| 974 | uint64_t Address, |
| 975 | const void *Decoder) { |
Jozef Kolek | 315e7ec | 2014-11-26 18:56:38 +0000 | [diff] [blame] | 976 | if (RegNo > 7) |
| 977 | return MCDisassembler::Fail; |
| 978 | unsigned Reg = getReg(Decoder, Mips::GPRMM16ZeroRegClassID, RegNo); |
| 979 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 980 | return MCDisassembler::Success; |
Jozef Kolek | 1904fa2 | 2014-11-24 14:25:53 +0000 | [diff] [blame] | 981 | } |
| 982 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 983 | static DecodeStatus DecodeGPR32RegisterClass(MCInst &Inst, |
| 984 | unsigned RegNo, |
| 985 | uint64_t Address, |
| 986 | const void *Decoder) { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 987 | if (RegNo > 31) |
| 988 | return MCDisassembler::Fail; |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 989 | unsigned Reg = getReg(Decoder, Mips::GPR32RegClassID, RegNo); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 990 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 991 | return MCDisassembler::Success; |
| 992 | } |
| 993 | |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 994 | static DecodeStatus DecodePtrRegisterClass(MCInst &Inst, |
| 995 | unsigned RegNo, |
| 996 | uint64_t Address, |
| 997 | const void *Decoder) { |
Vladimir Medic | e886093 | 2014-12-16 15:29:12 +0000 | [diff] [blame] | 998 | if (static_cast<const MipsDisassembler *>(Decoder)->isGP64Bit()) |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 999 | return DecodeGPR64RegisterClass(Inst, RegNo, Address, Decoder); |
| 1000 | |
| 1001 | return DecodeGPR32RegisterClass(Inst, RegNo, Address, Decoder); |
| 1002 | } |
| 1003 | |
Akira Hatanaka | 654655f | 2013-08-14 00:53:38 +0000 | [diff] [blame] | 1004 | static DecodeStatus DecodeDSPRRegisterClass(MCInst &Inst, |
| 1005 | unsigned RegNo, |
| 1006 | uint64_t Address, |
| 1007 | const void *Decoder) { |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 1008 | return DecodeGPR32RegisterClass(Inst, RegNo, Address, Decoder); |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1011 | static DecodeStatus DecodeFGR64RegisterClass(MCInst &Inst, |
| 1012 | unsigned RegNo, |
| 1013 | uint64_t Address, |
| 1014 | const void *Decoder) { |
| 1015 | if (RegNo > 31) |
| 1016 | return MCDisassembler::Fail; |
| 1017 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 1018 | unsigned Reg = getReg(Decoder, Mips::FGR64RegClassID, RegNo); |
| 1019 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1020 | return MCDisassembler::Success; |
| 1021 | } |
| 1022 | |
| 1023 | static DecodeStatus DecodeFGR32RegisterClass(MCInst &Inst, |
| 1024 | unsigned RegNo, |
| 1025 | uint64_t Address, |
| 1026 | const void *Decoder) { |
| 1027 | if (RegNo > 31) |
| 1028 | return MCDisassembler::Fail; |
| 1029 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 1030 | unsigned Reg = getReg(Decoder, Mips::FGR32RegClassID, RegNo); |
| 1031 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1032 | return MCDisassembler::Success; |
| 1033 | } |
| 1034 | |
| 1035 | static DecodeStatus DecodeCCRRegisterClass(MCInst &Inst, |
| 1036 | unsigned RegNo, |
| 1037 | uint64_t Address, |
| 1038 | const void *Decoder) { |
Chad Rosier | 253777f | 2013-06-26 22:23:32 +0000 | [diff] [blame] | 1039 | if (RegNo > 31) |
| 1040 | return MCDisassembler::Fail; |
| 1041 | unsigned Reg = getReg(Decoder, Mips::CCRRegClassID, RegNo); |
| 1042 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1043 | return MCDisassembler::Success; |
| 1044 | } |
| 1045 | |
Akira Hatanaka | 1fb1b8b | 2013-07-26 20:13:47 +0000 | [diff] [blame] | 1046 | static DecodeStatus DecodeFCCRegisterClass(MCInst &Inst, |
| 1047 | unsigned RegNo, |
| 1048 | uint64_t Address, |
| 1049 | const void *Decoder) { |
| 1050 | if (RegNo > 7) |
| 1051 | return MCDisassembler::Fail; |
| 1052 | unsigned Reg = getReg(Decoder, Mips::FCCRegClassID, RegNo); |
| 1053 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1054 | return MCDisassembler::Success; |
| 1055 | } |
| 1056 | |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 1057 | static DecodeStatus DecodeFGRCCRegisterClass(MCInst &Inst, unsigned RegNo, |
| 1058 | uint64_t Address, |
| 1059 | const void *Decoder) { |
| 1060 | if (RegNo > 31) |
| 1061 | return MCDisassembler::Fail; |
| 1062 | |
| 1063 | unsigned Reg = getReg(Decoder, Mips::FGRCCRegClassID, RegNo); |
| 1064 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1065 | return MCDisassembler::Success; |
| 1066 | } |
| 1067 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1068 | static DecodeStatus DecodeMem(MCInst &Inst, |
| 1069 | unsigned Insn, |
| 1070 | uint64_t Address, |
| 1071 | const void *Decoder) { |
| 1072 | int Offset = SignExtend32<16>(Insn & 0xffff); |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 1073 | unsigned Reg = fieldFromInstruction(Insn, 16, 5); |
| 1074 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 1075 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 1076 | Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg); |
| 1077 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1078 | |
Vladimir Medic | d7ecf49 | 2014-12-15 16:19:34 +0000 | [diff] [blame] | 1079 | if(Inst.getOpcode() == Mips::SC || |
| 1080 | Inst.getOpcode() == Mips::SCD){ |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 1081 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 1084 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1085 | Inst.addOperand(MCOperand::CreateReg(Base)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1086 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1087 | |
| 1088 | return MCDisassembler::Success; |
| 1089 | } |
| 1090 | |
Daniel Sanders | 92db6b7 | 2014-10-01 08:26:55 +0000 | [diff] [blame] | 1091 | static DecodeStatus DecodeCacheOp(MCInst &Inst, |
| 1092 | unsigned Insn, |
| 1093 | uint64_t Address, |
| 1094 | const void *Decoder) { |
| 1095 | int Offset = SignExtend32<16>(Insn & 0xffff); |
| 1096 | unsigned Hint = fieldFromInstruction(Insn, 16, 5); |
| 1097 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
| 1098 | |
| 1099 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1100 | |
| 1101 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 1102 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1103 | Inst.addOperand(MCOperand::CreateImm(Hint)); |
| 1104 | |
| 1105 | return MCDisassembler::Success; |
| 1106 | } |
| 1107 | |
Jozef Kolek | ab6d1cc | 2014-12-23 19:55:34 +0000 | [diff] [blame] | 1108 | static DecodeStatus DecodeCacheOpMM(MCInst &Inst, |
| 1109 | unsigned Insn, |
| 1110 | uint64_t Address, |
| 1111 | const void *Decoder) { |
| 1112 | int Offset = SignExtend32<12>(Insn & 0xfff); |
| 1113 | unsigned Base = fieldFromInstruction(Insn, 16, 5); |
| 1114 | unsigned Hint = fieldFromInstruction(Insn, 21, 5); |
| 1115 | |
| 1116 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1117 | |
| 1118 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 1119 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1120 | Inst.addOperand(MCOperand::CreateImm(Hint)); |
| 1121 | |
| 1122 | return MCDisassembler::Success; |
| 1123 | } |
| 1124 | |
Daniel Sanders | b4484d6 | 2014-11-27 17:28:10 +0000 | [diff] [blame] | 1125 | static DecodeStatus DecodeSyncI(MCInst &Inst, |
| 1126 | unsigned Insn, |
| 1127 | uint64_t Address, |
| 1128 | const void *Decoder) { |
| 1129 | int Offset = SignExtend32<16>(Insn & 0xffff); |
| 1130 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
| 1131 | |
| 1132 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1133 | |
| 1134 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 1135 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1136 | |
| 1137 | return MCDisassembler::Success; |
| 1138 | } |
| 1139 | |
Matheus Almeida | fe0bf9f | 2013-10-21 13:07:13 +0000 | [diff] [blame] | 1140 | static DecodeStatus DecodeMSA128Mem(MCInst &Inst, unsigned Insn, |
| 1141 | uint64_t Address, const void *Decoder) { |
| 1142 | int Offset = SignExtend32<10>(fieldFromInstruction(Insn, 16, 10)); |
| 1143 | unsigned Reg = fieldFromInstruction(Insn, 6, 5); |
| 1144 | unsigned Base = fieldFromInstruction(Insn, 11, 5); |
| 1145 | |
| 1146 | Reg = getReg(Decoder, Mips::MSA128BRegClassID, Reg); |
| 1147 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1148 | |
| 1149 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1150 | Inst.addOperand(MCOperand::CreateReg(Base)); |
Matheus Almeida | 6b59c44 | 2013-12-05 11:06:22 +0000 | [diff] [blame] | 1151 | |
| 1152 | // The immediate field of an LD/ST instruction is scaled which means it must |
| 1153 | // be multiplied (when decoding) by the size (in bytes) of the instructions' |
| 1154 | // data format. |
| 1155 | // .b - 1 byte |
| 1156 | // .h - 2 bytes |
| 1157 | // .w - 4 bytes |
| 1158 | // .d - 8 bytes |
| 1159 | switch(Inst.getOpcode()) |
| 1160 | { |
| 1161 | default: |
| 1162 | assert (0 && "Unexpected instruction"); |
| 1163 | return MCDisassembler::Fail; |
| 1164 | break; |
| 1165 | case Mips::LD_B: |
| 1166 | case Mips::ST_B: |
| 1167 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1168 | break; |
| 1169 | case Mips::LD_H: |
| 1170 | case Mips::ST_H: |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1171 | Inst.addOperand(MCOperand::CreateImm(Offset * 2)); |
Matheus Almeida | 6b59c44 | 2013-12-05 11:06:22 +0000 | [diff] [blame] | 1172 | break; |
| 1173 | case Mips::LD_W: |
| 1174 | case Mips::ST_W: |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1175 | Inst.addOperand(MCOperand::CreateImm(Offset * 4)); |
Matheus Almeida | 6b59c44 | 2013-12-05 11:06:22 +0000 | [diff] [blame] | 1176 | break; |
| 1177 | case Mips::LD_D: |
| 1178 | case Mips::ST_D: |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1179 | Inst.addOperand(MCOperand::CreateImm(Offset * 8)); |
Matheus Almeida | 6b59c44 | 2013-12-05 11:06:22 +0000 | [diff] [blame] | 1180 | break; |
| 1181 | } |
Matheus Almeida | fe0bf9f | 2013-10-21 13:07:13 +0000 | [diff] [blame] | 1182 | |
| 1183 | return MCDisassembler::Success; |
| 1184 | } |
| 1185 | |
Jozef Kolek | 315e7ec | 2014-11-26 18:56:38 +0000 | [diff] [blame] | 1186 | static DecodeStatus DecodeMemMMImm4(MCInst &Inst, |
| 1187 | unsigned Insn, |
| 1188 | uint64_t Address, |
| 1189 | const void *Decoder) { |
| 1190 | unsigned Offset = Insn & 0xf; |
| 1191 | unsigned Reg = fieldFromInstruction(Insn, 7, 3); |
| 1192 | unsigned Base = fieldFromInstruction(Insn, 4, 3); |
| 1193 | |
| 1194 | switch (Inst.getOpcode()) { |
| 1195 | case Mips::LBU16_MM: |
| 1196 | case Mips::LHU16_MM: |
| 1197 | case Mips::LW16_MM: |
| 1198 | if (DecodeGPRMM16RegisterClass(Inst, Reg, Address, Decoder) |
| 1199 | == MCDisassembler::Fail) |
| 1200 | return MCDisassembler::Fail; |
| 1201 | break; |
| 1202 | case Mips::SB16_MM: |
| 1203 | case Mips::SH16_MM: |
| 1204 | case Mips::SW16_MM: |
| 1205 | if (DecodeGPRMM16ZeroRegisterClass(Inst, Reg, Address, Decoder) |
| 1206 | == MCDisassembler::Fail) |
| 1207 | return MCDisassembler::Fail; |
| 1208 | break; |
| 1209 | } |
| 1210 | |
| 1211 | if (DecodeGPRMM16RegisterClass(Inst, Base, Address, Decoder) |
| 1212 | == MCDisassembler::Fail) |
| 1213 | return MCDisassembler::Fail; |
| 1214 | |
| 1215 | switch (Inst.getOpcode()) { |
| 1216 | case Mips::LBU16_MM: |
| 1217 | if (Offset == 0xf) |
| 1218 | Inst.addOperand(MCOperand::CreateImm(-1)); |
| 1219 | else |
| 1220 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1221 | break; |
| 1222 | case Mips::SB16_MM: |
| 1223 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1224 | break; |
| 1225 | case Mips::LHU16_MM: |
| 1226 | case Mips::SH16_MM: |
| 1227 | Inst.addOperand(MCOperand::CreateImm(Offset << 1)); |
| 1228 | break; |
| 1229 | case Mips::LW16_MM: |
| 1230 | case Mips::SW16_MM: |
| 1231 | Inst.addOperand(MCOperand::CreateImm(Offset << 2)); |
| 1232 | break; |
| 1233 | } |
| 1234 | |
| 1235 | return MCDisassembler::Success; |
| 1236 | } |
| 1237 | |
Jozef Kolek | 12c6982 | 2014-12-23 16:16:33 +0000 | [diff] [blame] | 1238 | static DecodeStatus DecodeMemMMSPImm5Lsl2(MCInst &Inst, |
| 1239 | unsigned Insn, |
| 1240 | uint64_t Address, |
| 1241 | const void *Decoder) { |
| 1242 | unsigned Offset = Insn & 0x1F; |
| 1243 | unsigned Reg = fieldFromInstruction(Insn, 5, 5); |
| 1244 | |
| 1245 | Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg); |
| 1246 | |
| 1247 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1248 | Inst.addOperand(MCOperand::CreateReg(Mips::SP)); |
| 1249 | Inst.addOperand(MCOperand::CreateImm(Offset << 2)); |
| 1250 | |
| 1251 | return MCDisassembler::Success; |
| 1252 | } |
| 1253 | |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 1254 | static DecodeStatus DecodeMemMMImm12(MCInst &Inst, |
| 1255 | unsigned Insn, |
| 1256 | uint64_t Address, |
| 1257 | const void *Decoder) { |
| 1258 | int Offset = SignExtend32<12>(Insn & 0x0fff); |
| 1259 | unsigned Reg = fieldFromInstruction(Insn, 21, 5); |
| 1260 | unsigned Base = fieldFromInstruction(Insn, 16, 5); |
| 1261 | |
| 1262 | Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg); |
| 1263 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1264 | |
Zoran Jovanovic | a4c4b5f | 2014-11-19 16:44:02 +0000 | [diff] [blame] | 1265 | switch (Inst.getOpcode()) { |
| 1266 | case Mips::SWM32_MM: |
| 1267 | case Mips::LWM32_MM: |
| 1268 | if (DecodeRegListOperand(Inst, Insn, Address, Decoder) |
| 1269 | == MCDisassembler::Fail) |
| 1270 | return MCDisassembler::Fail; |
| 1271 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 1272 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1273 | break; |
| 1274 | case Mips::SC_MM: |
Zoran Jovanovic | 285cc28 | 2014-02-28 18:22:56 +0000 | [diff] [blame] | 1275 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Zoran Jovanovic | a4c4b5f | 2014-11-19 16:44:02 +0000 | [diff] [blame] | 1276 | // fallthrough |
| 1277 | default: |
| 1278 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Zoran Jovanovic | 2deca34 | 2014-12-16 14:59:10 +0000 | [diff] [blame] | 1279 | if (Inst.getOpcode() == Mips::LWP_MM || Inst.getOpcode() == Mips::SWP_MM) |
| 1280 | Inst.addOperand(MCOperand::CreateReg(Reg+1)); |
| 1281 | |
Zoran Jovanovic | a4c4b5f | 2014-11-19 16:44:02 +0000 | [diff] [blame] | 1282 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 1283 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1284 | } |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 1285 | |
| 1286 | return MCDisassembler::Success; |
| 1287 | } |
| 1288 | |
| 1289 | static DecodeStatus DecodeMemMMImm16(MCInst &Inst, |
| 1290 | unsigned Insn, |
| 1291 | uint64_t Address, |
| 1292 | const void *Decoder) { |
| 1293 | int Offset = SignExtend32<16>(Insn & 0xffff); |
| 1294 | unsigned Reg = fieldFromInstruction(Insn, 21, 5); |
| 1295 | unsigned Base = fieldFromInstruction(Insn, 16, 5); |
| 1296 | |
| 1297 | Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg); |
| 1298 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1299 | |
| 1300 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1301 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 1302 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1303 | |
| 1304 | return MCDisassembler::Success; |
| 1305 | } |
| 1306 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1307 | static DecodeStatus DecodeFMem(MCInst &Inst, |
| 1308 | unsigned Insn, |
| 1309 | uint64_t Address, |
| 1310 | const void *Decoder) { |
| 1311 | int Offset = SignExtend32<16>(Insn & 0xffff); |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 1312 | unsigned Reg = fieldFromInstruction(Insn, 16, 5); |
| 1313 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1314 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 1315 | Reg = getReg(Decoder, Mips::FGR64RegClassID, Reg); |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 1316 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 1317 | |
| 1318 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1319 | Inst.addOperand(MCOperand::CreateReg(Base)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1320 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1321 | |
| 1322 | return MCDisassembler::Success; |
| 1323 | } |
| 1324 | |
Daniel Sanders | 92db6b7 | 2014-10-01 08:26:55 +0000 | [diff] [blame] | 1325 | static DecodeStatus DecodeFMem2(MCInst &Inst, |
| 1326 | unsigned Insn, |
| 1327 | uint64_t Address, |
| 1328 | const void *Decoder) { |
| 1329 | int Offset = SignExtend32<16>(Insn & 0xffff); |
| 1330 | unsigned Reg = fieldFromInstruction(Insn, 16, 5); |
| 1331 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
| 1332 | |
| 1333 | Reg = getReg(Decoder, Mips::COP2RegClassID, Reg); |
| 1334 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1335 | |
| 1336 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1337 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 1338 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1339 | |
| 1340 | return MCDisassembler::Success; |
| 1341 | } |
| 1342 | |
| 1343 | static DecodeStatus DecodeFMem3(MCInst &Inst, |
| 1344 | unsigned Insn, |
| 1345 | uint64_t Address, |
| 1346 | const void *Decoder) { |
| 1347 | int Offset = SignExtend32<16>(Insn & 0xffff); |
| 1348 | unsigned Reg = fieldFromInstruction(Insn, 16, 5); |
| 1349 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
| 1350 | |
| 1351 | Reg = getReg(Decoder, Mips::COP3RegClassID, Reg); |
| 1352 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1353 | |
| 1354 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1355 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 1356 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1357 | |
| 1358 | return MCDisassembler::Success; |
| 1359 | } |
| 1360 | |
Vladimir Medic | 435cf8a | 2015-01-21 10:47:36 +0000 | [diff] [blame] | 1361 | static DecodeStatus DecodeFMemCop2R6(MCInst &Inst, |
| 1362 | unsigned Insn, |
| 1363 | uint64_t Address, |
| 1364 | const void *Decoder) { |
| 1365 | int Offset = SignExtend32<11>(Insn & 0x07ff); |
| 1366 | unsigned Reg = fieldFromInstruction(Insn, 16, 5); |
| 1367 | unsigned Base = fieldFromInstruction(Insn, 11, 5); |
| 1368 | |
| 1369 | Reg = getReg(Decoder, Mips::COP2RegClassID, Reg); |
| 1370 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1371 | |
| 1372 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1373 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 1374 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1375 | |
| 1376 | return MCDisassembler::Success; |
| 1377 | } |
Daniel Sanders | 6a803f6 | 2014-06-16 13:13:03 +0000 | [diff] [blame] | 1378 | static DecodeStatus DecodeSpecial3LlSc(MCInst &Inst, |
| 1379 | unsigned Insn, |
| 1380 | uint64_t Address, |
| 1381 | const void *Decoder) { |
| 1382 | int64_t Offset = SignExtend64<9>((Insn >> 7) & 0x1ff); |
| 1383 | unsigned Rt = fieldFromInstruction(Insn, 16, 5); |
| 1384 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
| 1385 | |
| 1386 | Rt = getReg(Decoder, Mips::GPR32RegClassID, Rt); |
| 1387 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1388 | |
| 1389 | if(Inst.getOpcode() == Mips::SC_R6 || Inst.getOpcode() == Mips::SCD_R6){ |
| 1390 | Inst.addOperand(MCOperand::CreateReg(Rt)); |
| 1391 | } |
| 1392 | |
| 1393 | Inst.addOperand(MCOperand::CreateReg(Rt)); |
| 1394 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 1395 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1396 | |
| 1397 | return MCDisassembler::Success; |
| 1398 | } |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1399 | |
| 1400 | static DecodeStatus DecodeHWRegsRegisterClass(MCInst &Inst, |
| 1401 | unsigned RegNo, |
| 1402 | uint64_t Address, |
| 1403 | const void *Decoder) { |
| 1404 | // Currently only hardware register 29 is supported. |
| 1405 | if (RegNo != 29) |
| 1406 | return MCDisassembler::Fail; |
| 1407 | Inst.addOperand(MCOperand::CreateReg(Mips::HWR29)); |
| 1408 | return MCDisassembler::Success; |
| 1409 | } |
| 1410 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1411 | static DecodeStatus DecodeAFGR64RegisterClass(MCInst &Inst, |
| 1412 | unsigned RegNo, |
| 1413 | uint64_t Address, |
| 1414 | const void *Decoder) { |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 1415 | if (RegNo > 30 || RegNo %2) |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1416 | return MCDisassembler::Fail; |
| 1417 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 1418 | ; |
| 1419 | unsigned Reg = getReg(Decoder, Mips::AFGR64RegClassID, RegNo /2); |
| 1420 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1421 | return MCDisassembler::Success; |
| 1422 | } |
| 1423 | |
Akira Hatanaka | 00fcf2e | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 1424 | static DecodeStatus DecodeACC64DSPRegisterClass(MCInst &Inst, |
| 1425 | unsigned RegNo, |
| 1426 | uint64_t Address, |
| 1427 | const void *Decoder) { |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 1428 | if (RegNo >= 4) |
| 1429 | return MCDisassembler::Fail; |
| 1430 | |
Akira Hatanaka | 00fcf2e | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 1431 | unsigned Reg = getReg(Decoder, Mips::ACC64DSPRegClassID, RegNo); |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 1432 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1433 | return MCDisassembler::Success; |
| 1434 | } |
| 1435 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 1436 | static DecodeStatus DecodeHI32DSPRegisterClass(MCInst &Inst, |
| 1437 | unsigned RegNo, |
| 1438 | uint64_t Address, |
| 1439 | const void *Decoder) { |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 1440 | if (RegNo >= 4) |
| 1441 | return MCDisassembler::Fail; |
| 1442 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 1443 | unsigned Reg = getReg(Decoder, Mips::HI32DSPRegClassID, RegNo); |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 1444 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1445 | return MCDisassembler::Success; |
| 1446 | } |
| 1447 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 1448 | static DecodeStatus DecodeLO32DSPRegisterClass(MCInst &Inst, |
| 1449 | unsigned RegNo, |
| 1450 | uint64_t Address, |
| 1451 | const void *Decoder) { |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 1452 | if (RegNo >= 4) |
| 1453 | return MCDisassembler::Fail; |
| 1454 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 1455 | unsigned Reg = getReg(Decoder, Mips::LO32DSPRegClassID, RegNo); |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 1456 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1457 | return MCDisassembler::Success; |
| 1458 | } |
| 1459 | |
Jack Carter | 3eb663b | 2013-09-26 00:09:46 +0000 | [diff] [blame] | 1460 | static DecodeStatus DecodeMSA128BRegisterClass(MCInst &Inst, |
| 1461 | unsigned RegNo, |
| 1462 | uint64_t Address, |
| 1463 | const void *Decoder) { |
| 1464 | if (RegNo > 31) |
| 1465 | return MCDisassembler::Fail; |
| 1466 | |
| 1467 | unsigned Reg = getReg(Decoder, Mips::MSA128BRegClassID, RegNo); |
| 1468 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1469 | return MCDisassembler::Success; |
| 1470 | } |
| 1471 | |
Jack Carter | 5dc8ac9 | 2013-09-25 23:50:44 +0000 | [diff] [blame] | 1472 | static DecodeStatus DecodeMSA128HRegisterClass(MCInst &Inst, |
| 1473 | unsigned RegNo, |
| 1474 | uint64_t Address, |
| 1475 | const void *Decoder) { |
| 1476 | if (RegNo > 31) |
| 1477 | return MCDisassembler::Fail; |
| 1478 | |
| 1479 | unsigned Reg = getReg(Decoder, Mips::MSA128HRegClassID, RegNo); |
| 1480 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1481 | return MCDisassembler::Success; |
| 1482 | } |
| 1483 | |
| 1484 | static DecodeStatus DecodeMSA128WRegisterClass(MCInst &Inst, |
| 1485 | unsigned RegNo, |
| 1486 | uint64_t Address, |
| 1487 | const void *Decoder) { |
| 1488 | if (RegNo > 31) |
| 1489 | return MCDisassembler::Fail; |
| 1490 | |
| 1491 | unsigned Reg = getReg(Decoder, Mips::MSA128WRegClassID, RegNo); |
| 1492 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1493 | return MCDisassembler::Success; |
| 1494 | } |
| 1495 | |
| 1496 | static DecodeStatus DecodeMSA128DRegisterClass(MCInst &Inst, |
| 1497 | unsigned RegNo, |
| 1498 | uint64_t Address, |
| 1499 | const void *Decoder) { |
| 1500 | if (RegNo > 31) |
| 1501 | return MCDisassembler::Fail; |
| 1502 | |
| 1503 | unsigned Reg = getReg(Decoder, Mips::MSA128DRegClassID, RegNo); |
| 1504 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1505 | return MCDisassembler::Success; |
| 1506 | } |
| 1507 | |
Matheus Almeida | a591fdc | 2013-10-21 12:26:50 +0000 | [diff] [blame] | 1508 | static DecodeStatus DecodeMSACtrlRegisterClass(MCInst &Inst, |
| 1509 | unsigned RegNo, |
| 1510 | uint64_t Address, |
| 1511 | const void *Decoder) { |
| 1512 | if (RegNo > 7) |
| 1513 | return MCDisassembler::Fail; |
| 1514 | |
| 1515 | unsigned Reg = getReg(Decoder, Mips::MSACtrlRegClassID, RegNo); |
| 1516 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1517 | return MCDisassembler::Success; |
| 1518 | } |
| 1519 | |
Daniel Sanders | 2a83d68 | 2014-05-21 12:56:39 +0000 | [diff] [blame] | 1520 | static DecodeStatus DecodeCOP2RegisterClass(MCInst &Inst, |
| 1521 | unsigned RegNo, |
| 1522 | uint64_t Address, |
| 1523 | const void *Decoder) { |
| 1524 | if (RegNo > 31) |
| 1525 | return MCDisassembler::Fail; |
| 1526 | |
| 1527 | unsigned Reg = getReg(Decoder, Mips::COP2RegClassID, RegNo); |
| 1528 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1529 | return MCDisassembler::Success; |
| 1530 | } |
| 1531 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1532 | static DecodeStatus DecodeBranchTarget(MCInst &Inst, |
| 1533 | unsigned Offset, |
| 1534 | uint64_t Address, |
| 1535 | const void *Decoder) { |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1536 | int32_t BranchOffset = (SignExtend32<16>(Offset) * 4) + 4; |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1537 | Inst.addOperand(MCOperand::CreateImm(BranchOffset)); |
| 1538 | return MCDisassembler::Success; |
| 1539 | } |
| 1540 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1541 | static DecodeStatus DecodeJumpTarget(MCInst &Inst, |
| 1542 | unsigned Insn, |
| 1543 | uint64_t Address, |
| 1544 | const void *Decoder) { |
| 1545 | |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 1546 | unsigned JumpOffset = fieldFromInstruction(Insn, 0, 26) << 2; |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1547 | Inst.addOperand(MCOperand::CreateImm(JumpOffset)); |
| 1548 | return MCDisassembler::Success; |
| 1549 | } |
| 1550 | |
Zoran Jovanovic | 3c8869d | 2014-05-16 11:03:45 +0000 | [diff] [blame] | 1551 | static DecodeStatus DecodeBranchTarget21(MCInst &Inst, |
| 1552 | unsigned Offset, |
| 1553 | uint64_t Address, |
| 1554 | const void *Decoder) { |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1555 | int32_t BranchOffset = SignExtend32<21>(Offset) * 4; |
Zoran Jovanovic | 3c8869d | 2014-05-16 11:03:45 +0000 | [diff] [blame] | 1556 | |
| 1557 | Inst.addOperand(MCOperand::CreateImm(BranchOffset)); |
| 1558 | return MCDisassembler::Success; |
| 1559 | } |
| 1560 | |
| 1561 | static DecodeStatus DecodeBranchTarget26(MCInst &Inst, |
| 1562 | unsigned Offset, |
| 1563 | uint64_t Address, |
| 1564 | const void *Decoder) { |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1565 | int32_t BranchOffset = SignExtend32<26>(Offset) * 4; |
Zoran Jovanovic | 3c8869d | 2014-05-16 11:03:45 +0000 | [diff] [blame] | 1566 | |
| 1567 | Inst.addOperand(MCOperand::CreateImm(BranchOffset)); |
| 1568 | return MCDisassembler::Success; |
| 1569 | } |
| 1570 | |
Jozef Kolek | 9761e96 | 2015-01-12 12:03:34 +0000 | [diff] [blame] | 1571 | static DecodeStatus DecodeBranchTarget7MM(MCInst &Inst, |
| 1572 | unsigned Offset, |
| 1573 | uint64_t Address, |
| 1574 | const void *Decoder) { |
| 1575 | int32_t BranchOffset = SignExtend32<7>(Offset) << 1; |
| 1576 | Inst.addOperand(MCOperand::CreateImm(BranchOffset)); |
| 1577 | return MCDisassembler::Success; |
| 1578 | } |
| 1579 | |
Zoran Jovanovic | 8a80aa7 | 2013-11-04 14:53:22 +0000 | [diff] [blame] | 1580 | static DecodeStatus DecodeBranchTargetMM(MCInst &Inst, |
| 1581 | unsigned Offset, |
| 1582 | uint64_t Address, |
| 1583 | const void *Decoder) { |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1584 | int32_t BranchOffset = SignExtend32<16>(Offset) * 2; |
Zoran Jovanovic | 8a80aa7 | 2013-11-04 14:53:22 +0000 | [diff] [blame] | 1585 | Inst.addOperand(MCOperand::CreateImm(BranchOffset)); |
| 1586 | return MCDisassembler::Success; |
| 1587 | } |
| 1588 | |
Zoran Jovanovic | 507e084 | 2013-10-29 16:38:59 +0000 | [diff] [blame] | 1589 | static DecodeStatus DecodeJumpTargetMM(MCInst &Inst, |
| 1590 | unsigned Insn, |
| 1591 | uint64_t Address, |
| 1592 | const void *Decoder) { |
| 1593 | unsigned JumpOffset = fieldFromInstruction(Insn, 0, 26) << 1; |
| 1594 | Inst.addOperand(MCOperand::CreateImm(JumpOffset)); |
| 1595 | return MCDisassembler::Success; |
| 1596 | } |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1597 | |
Jozef Kolek | aa2b927 | 2014-11-27 14:41:44 +0000 | [diff] [blame] | 1598 | static DecodeStatus DecodeAddiur2Simm7(MCInst &Inst, |
| 1599 | unsigned Value, |
| 1600 | uint64_t Address, |
| 1601 | const void *Decoder) { |
| 1602 | if (Value == 0) |
| 1603 | Inst.addOperand(MCOperand::CreateImm(1)); |
| 1604 | else if (Value == 0x7) |
| 1605 | Inst.addOperand(MCOperand::CreateImm(-1)); |
| 1606 | else |
| 1607 | Inst.addOperand(MCOperand::CreateImm(Value << 2)); |
| 1608 | return MCDisassembler::Success; |
| 1609 | } |
| 1610 | |
| 1611 | static DecodeStatus DecodeUImm6Lsl2(MCInst &Inst, |
| 1612 | unsigned Value, |
| 1613 | uint64_t Address, |
| 1614 | const void *Decoder) { |
| 1615 | Inst.addOperand(MCOperand::CreateImm(Value << 2)); |
| 1616 | return MCDisassembler::Success; |
| 1617 | } |
| 1618 | |
| 1619 | static DecodeStatus DecodeLiSimm7(MCInst &Inst, |
| 1620 | unsigned Value, |
| 1621 | uint64_t Address, |
| 1622 | const void *Decoder) { |
| 1623 | if (Value == 0x7F) |
| 1624 | Inst.addOperand(MCOperand::CreateImm(-1)); |
| 1625 | else |
| 1626 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 1627 | return MCDisassembler::Success; |
| 1628 | } |
| 1629 | |
| 1630 | static DecodeStatus DecodeSimm4(MCInst &Inst, |
| 1631 | unsigned Value, |
| 1632 | uint64_t Address, |
| 1633 | const void *Decoder) { |
| 1634 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<4>(Value))); |
| 1635 | return MCDisassembler::Success; |
| 1636 | } |
| 1637 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1638 | static DecodeStatus DecodeSimm16(MCInst &Inst, |
| 1639 | unsigned Insn, |
| 1640 | uint64_t Address, |
| 1641 | const void *Decoder) { |
| 1642 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<16>(Insn))); |
| 1643 | return MCDisassembler::Success; |
| 1644 | } |
| 1645 | |
Matheus Almeida | 779c593 | 2013-11-18 12:32:49 +0000 | [diff] [blame] | 1646 | static DecodeStatus DecodeLSAImm(MCInst &Inst, |
| 1647 | unsigned Insn, |
| 1648 | uint64_t Address, |
| 1649 | const void *Decoder) { |
| 1650 | // We add one to the immediate field as it was encoded as 'imm - 1'. |
| 1651 | Inst.addOperand(MCOperand::CreateImm(Insn + 1)); |
| 1652 | return MCDisassembler::Success; |
| 1653 | } |
| 1654 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1655 | static DecodeStatus DecodeInsSize(MCInst &Inst, |
| 1656 | unsigned Insn, |
| 1657 | uint64_t Address, |
| 1658 | const void *Decoder) { |
| 1659 | // First we need to grab the pos(lsb) from MCInst. |
| 1660 | int Pos = Inst.getOperand(2).getImm(); |
| 1661 | int Size = (int) Insn - Pos + 1; |
| 1662 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<16>(Size))); |
| 1663 | return MCDisassembler::Success; |
| 1664 | } |
| 1665 | |
| 1666 | static DecodeStatus DecodeExtSize(MCInst &Inst, |
| 1667 | unsigned Insn, |
| 1668 | uint64_t Address, |
| 1669 | const void *Decoder) { |
| 1670 | int Size = (int) Insn + 1; |
| 1671 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<16>(Size))); |
| 1672 | return MCDisassembler::Success; |
| 1673 | } |
Daniel Sanders | b59e1a4 | 2014-05-15 10:45:58 +0000 | [diff] [blame] | 1674 | |
| 1675 | static DecodeStatus DecodeSimm19Lsl2(MCInst &Inst, unsigned Insn, |
| 1676 | uint64_t Address, const void *Decoder) { |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1677 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<19>(Insn) * 4)); |
Daniel Sanders | b59e1a4 | 2014-05-15 10:45:58 +0000 | [diff] [blame] | 1678 | return MCDisassembler::Success; |
| 1679 | } |
Zoran Jovanovic | 2855142 | 2014-06-09 09:49:51 +0000 | [diff] [blame] | 1680 | |
| 1681 | static DecodeStatus DecodeSimm18Lsl3(MCInst &Inst, unsigned Insn, |
| 1682 | uint64_t Address, const void *Decoder) { |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1683 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<18>(Insn) * 8)); |
Zoran Jovanovic | 2855142 | 2014-06-09 09:49:51 +0000 | [diff] [blame] | 1684 | return MCDisassembler::Success; |
| 1685 | } |
Zoran Jovanovic | a4c4b5f | 2014-11-19 16:44:02 +0000 | [diff] [blame] | 1686 | |
Vladimir Medic | b682ddf | 2014-12-01 11:12:04 +0000 | [diff] [blame] | 1687 | static DecodeStatus DecodeSimm9SP(MCInst &Inst, unsigned Insn, |
| 1688 | uint64_t Address, const void *Decoder) { |
| 1689 | int32_t DecodedValue; |
| 1690 | switch (Insn) { |
| 1691 | case 0: DecodedValue = 256; break; |
| 1692 | case 1: DecodedValue = 257; break; |
| 1693 | case 510: DecodedValue = -258; break; |
| 1694 | case 511: DecodedValue = -257; break; |
| 1695 | default: DecodedValue = SignExtend32<9>(Insn); break; |
| 1696 | } |
Alexey Samsonov | 2c55974 | 2014-12-23 04:15:53 +0000 | [diff] [blame] | 1697 | Inst.addOperand(MCOperand::CreateImm(DecodedValue * 4)); |
Vladimir Medic | b682ddf | 2014-12-01 11:12:04 +0000 | [diff] [blame] | 1698 | return MCDisassembler::Success; |
| 1699 | } |
| 1700 | |
| 1701 | static DecodeStatus DecodeANDI16Imm(MCInst &Inst, unsigned Insn, |
| 1702 | uint64_t Address, const void *Decoder) { |
| 1703 | // Insn must be >= 0, since it is unsigned that condition is always true. |
| 1704 | assert(Insn < 16); |
| 1705 | int32_t DecodedValues[] = {128, 1, 2, 3, 4, 7, 8, 15, 16, 31, 32, 63, 64, |
| 1706 | 255, 32768, 65535}; |
| 1707 | Inst.addOperand(MCOperand::CreateImm(DecodedValues[Insn])); |
| 1708 | return MCDisassembler::Success; |
| 1709 | } |
| 1710 | |
| 1711 | static DecodeStatus DecodeUImm5lsl2(MCInst &Inst, unsigned Insn, |
| 1712 | uint64_t Address, const void *Decoder) { |
| 1713 | Inst.addOperand(MCOperand::CreateImm(Insn << 2)); |
| 1714 | return MCDisassembler::Success; |
| 1715 | } |
| 1716 | |
Zoran Jovanovic | a4c4b5f | 2014-11-19 16:44:02 +0000 | [diff] [blame] | 1717 | static DecodeStatus DecodeRegListOperand(MCInst &Inst, |
| 1718 | unsigned Insn, |
| 1719 | uint64_t Address, |
| 1720 | const void *Decoder) { |
| 1721 | unsigned Regs[] = {Mips::S0, Mips::S1, Mips::S2, Mips::S3, Mips::S4, Mips::S5, |
| 1722 | Mips::S6, Mips::FP}; |
| 1723 | unsigned RegNum; |
| 1724 | |
| 1725 | unsigned RegLst = fieldFromInstruction(Insn, 21, 5); |
| 1726 | // Empty register lists are not allowed. |
| 1727 | if (RegLst == 0) |
| 1728 | return MCDisassembler::Fail; |
| 1729 | |
| 1730 | RegNum = RegLst & 0xf; |
| 1731 | for (unsigned i = 0; i < RegNum; i++) |
| 1732 | Inst.addOperand(MCOperand::CreateReg(Regs[i])); |
| 1733 | |
| 1734 | if (RegLst & 0x10) |
| 1735 | Inst.addOperand(MCOperand::CreateReg(Mips::RA)); |
| 1736 | |
| 1737 | return MCDisassembler::Success; |
| 1738 | } |
Zoran Jovanovic | f9a0250 | 2014-11-27 18:28:59 +0000 | [diff] [blame] | 1739 | |
| 1740 | static DecodeStatus DecodeRegListOperand16(MCInst &Inst, unsigned Insn, |
| 1741 | uint64_t Address, |
| 1742 | const void *Decoder) { |
| 1743 | unsigned Regs[] = {Mips::S0, Mips::S1, Mips::S2, Mips::S3}; |
| 1744 | unsigned RegNum; |
| 1745 | |
| 1746 | unsigned RegLst = fieldFromInstruction(Insn, 4, 2); |
| 1747 | // Empty register lists are not allowed. |
| 1748 | if (RegLst == 0) |
| 1749 | return MCDisassembler::Fail; |
| 1750 | |
| 1751 | RegNum = RegLst & 0x3; |
| 1752 | for (unsigned i = 0; i < RegNum - 1; i++) |
| 1753 | Inst.addOperand(MCOperand::CreateReg(Regs[i])); |
| 1754 | |
| 1755 | Inst.addOperand(MCOperand::CreateReg(Mips::RA)); |
| 1756 | |
| 1757 | return MCDisassembler::Success; |
| 1758 | } |