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