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