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