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/MemoryObject.h" |
| 24 | #include "llvm/Support/TargetRegistry.h" |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 25 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 28 | #define DEBUG_TYPE "mips-disassembler" |
| 29 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 30 | typedef MCDisassembler::DecodeStatus DecodeStatus; |
| 31 | |
Benjamin Kramer | cb3e98c | 2012-05-01 14:34:24 +0000 | [diff] [blame] | 32 | namespace { |
| 33 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 34 | /// MipsDisassemblerBase - a disasembler class for Mips. |
| 35 | class MipsDisassemblerBase : public MCDisassembler { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 36 | public: |
| 37 | /// Constructor - Initializes the disassembler. |
| 38 | /// |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 39 | MipsDisassemblerBase(const MCSubtargetInfo &STI, MCContext &Ctx, |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 40 | bool bigEndian) : |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 41 | MCDisassembler(STI, Ctx), |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 42 | IsN64(STI.getFeatureBits() & Mips::FeatureN64), isBigEndian(bigEndian) {} |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 43 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 44 | virtual ~MipsDisassemblerBase() {} |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 45 | |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 46 | bool isN64() const { return IsN64; } |
| 47 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 48 | private: |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 49 | bool IsN64; |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 50 | protected: |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 51 | bool isBigEndian; |
| 52 | }; |
| 53 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 54 | /// MipsDisassembler - a disasembler class for Mips32. |
| 55 | class MipsDisassembler : public MipsDisassemblerBase { |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 56 | bool IsMicroMips; |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 57 | public: |
| 58 | /// Constructor - Initializes the disassembler. |
| 59 | /// |
Daniel Sanders | c171f65 | 2014-06-13 13:15:59 +0000 | [diff] [blame] | 60 | MipsDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx, bool bigEndian) |
| 61 | : MipsDisassemblerBase(STI, Ctx, bigEndian) { |
| 62 | IsMicroMips = STI.getFeatureBits() & Mips::FeatureMicroMips; |
| 63 | } |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 64 | |
Daniel Sanders | c171f65 | 2014-06-13 13:15:59 +0000 | [diff] [blame] | 65 | bool hasMips3() const { return STI.getFeatureBits() & Mips::FeatureMips3; } |
| 66 | bool hasMips32() const { return STI.getFeatureBits() & Mips::FeatureMips32; } |
| 67 | bool hasMips32r6() const { |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 68 | return STI.getFeatureBits() & Mips::FeatureMips32r6; |
| 69 | } |
| 70 | |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 71 | bool isGP64() const { return STI.getFeatureBits() & Mips::FeatureGP64Bit; } |
| 72 | |
Daniel Sanders | c171f65 | 2014-06-13 13:15:59 +0000 | [diff] [blame] | 73 | bool hasCOP3() const { |
| 74 | // Only present in MIPS-I and MIPS-II |
| 75 | return !hasMips32() && !hasMips3(); |
| 76 | } |
| 77 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 78 | /// getInstruction - See MCDisassembler. |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 79 | DecodeStatus getInstruction(MCInst &instr, |
| 80 | uint64_t &size, |
| 81 | const MemoryObject ®ion, |
| 82 | uint64_t address, |
| 83 | raw_ostream &vStream, |
| 84 | raw_ostream &cStream) const override; |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 87 | |
| 88 | /// Mips64Disassembler - a disasembler class for Mips64. |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 89 | class Mips64Disassembler : public MipsDisassemblerBase { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 90 | public: |
| 91 | /// Constructor - Initializes the disassembler. |
| 92 | /// |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 93 | Mips64Disassembler(const MCSubtargetInfo &STI, MCContext &Ctx, |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 94 | bool bigEndian) : |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 95 | MipsDisassemblerBase(STI, Ctx, bigEndian) {} |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 96 | |
| 97 | /// getInstruction - See MCDisassembler. |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 98 | DecodeStatus getInstruction(MCInst &instr, |
| 99 | uint64_t &size, |
| 100 | const MemoryObject ®ion, |
| 101 | uint64_t address, |
| 102 | raw_ostream &vStream, |
| 103 | raw_ostream &cStream) const override; |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
Benjamin Kramer | cb3e98c | 2012-05-01 14:34:24 +0000 | [diff] [blame] | 106 | } // end anonymous namespace |
| 107 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 108 | // Forward declare these because the autogenerated code will reference them. |
| 109 | // Definitions are further down. |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 110 | static DecodeStatus DecodeGPR64RegisterClass(MCInst &Inst, |
| 111 | unsigned RegNo, |
| 112 | uint64_t Address, |
| 113 | const void *Decoder); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 114 | |
Reed Kotler | ec8a549 | 2013-02-14 03:05:25 +0000 | [diff] [blame] | 115 | static DecodeStatus DecodeCPU16RegsRegisterClass(MCInst &Inst, |
| 116 | unsigned RegNo, |
| 117 | uint64_t Address, |
| 118 | const void *Decoder); |
| 119 | |
Zoran Jovanovic | b0852e5 | 2014-10-21 08:23:11 +0000 | [diff] [blame^] | 120 | static DecodeStatus DecodeGPRMM16RegisterClass(MCInst &Inst, |
| 121 | unsigned RegNo, |
| 122 | uint64_t Address, |
| 123 | const void *Decoder); |
| 124 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 125 | static DecodeStatus DecodeGPR32RegisterClass(MCInst &Inst, |
| 126 | unsigned RegNo, |
| 127 | uint64_t Address, |
| 128 | const void *Decoder); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 129 | |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 130 | static DecodeStatus DecodePtrRegisterClass(MCInst &Inst, |
| 131 | unsigned Insn, |
| 132 | uint64_t Address, |
| 133 | const void *Decoder); |
| 134 | |
Akira Hatanaka | 654655f | 2013-08-14 00:53:38 +0000 | [diff] [blame] | 135 | static DecodeStatus DecodeDSPRRegisterClass(MCInst &Inst, |
| 136 | unsigned RegNo, |
| 137 | uint64_t Address, |
| 138 | const void *Decoder); |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 139 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 140 | static DecodeStatus DecodeFGR64RegisterClass(MCInst &Inst, |
| 141 | unsigned RegNo, |
| 142 | uint64_t Address, |
| 143 | const void *Decoder); |
| 144 | |
| 145 | static DecodeStatus DecodeFGR32RegisterClass(MCInst &Inst, |
| 146 | unsigned RegNo, |
| 147 | uint64_t Address, |
| 148 | const void *Decoder); |
| 149 | |
| 150 | static DecodeStatus DecodeCCRRegisterClass(MCInst &Inst, |
| 151 | unsigned RegNo, |
| 152 | uint64_t Address, |
| 153 | const void *Decoder); |
| 154 | |
Akira Hatanaka | 1fb1b8b | 2013-07-26 20:13:47 +0000 | [diff] [blame] | 155 | static DecodeStatus DecodeFCCRegisterClass(MCInst &Inst, |
| 156 | unsigned RegNo, |
| 157 | uint64_t Address, |
| 158 | const void *Decoder); |
| 159 | |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 160 | static DecodeStatus DecodeFGRCCRegisterClass(MCInst &Inst, unsigned RegNo, |
| 161 | uint64_t Address, |
| 162 | const void *Decoder); |
| 163 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 164 | static DecodeStatus DecodeHWRegsRegisterClass(MCInst &Inst, |
| 165 | unsigned Insn, |
| 166 | uint64_t Address, |
| 167 | const void *Decoder); |
| 168 | |
| 169 | static DecodeStatus DecodeAFGR64RegisterClass(MCInst &Inst, |
| 170 | unsigned RegNo, |
| 171 | uint64_t Address, |
| 172 | const void *Decoder); |
| 173 | |
Akira Hatanaka | 00fcf2e | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 174 | static DecodeStatus DecodeACC64DSPRegisterClass(MCInst &Inst, |
| 175 | unsigned RegNo, |
| 176 | uint64_t Address, |
| 177 | const void *Decoder); |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 178 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 179 | static DecodeStatus DecodeHI32DSPRegisterClass(MCInst &Inst, |
| 180 | unsigned RegNo, |
| 181 | uint64_t Address, |
| 182 | const void *Decoder); |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 183 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 184 | static DecodeStatus DecodeLO32DSPRegisterClass(MCInst &Inst, |
| 185 | unsigned RegNo, |
| 186 | uint64_t Address, |
| 187 | const void *Decoder); |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 188 | |
Jack Carter | 3eb663b | 2013-09-26 00:09:46 +0000 | [diff] [blame] | 189 | static DecodeStatus DecodeMSA128BRegisterClass(MCInst &Inst, |
| 190 | unsigned RegNo, |
| 191 | uint64_t Address, |
| 192 | const void *Decoder); |
| 193 | |
Jack Carter | 5dc8ac9 | 2013-09-25 23:50:44 +0000 | [diff] [blame] | 194 | static DecodeStatus DecodeMSA128HRegisterClass(MCInst &Inst, |
| 195 | unsigned RegNo, |
| 196 | uint64_t Address, |
| 197 | const void *Decoder); |
| 198 | |
| 199 | static DecodeStatus DecodeMSA128WRegisterClass(MCInst &Inst, |
| 200 | unsigned RegNo, |
| 201 | uint64_t Address, |
| 202 | const void *Decoder); |
| 203 | |
| 204 | static DecodeStatus DecodeMSA128DRegisterClass(MCInst &Inst, |
| 205 | unsigned RegNo, |
| 206 | uint64_t Address, |
| 207 | const void *Decoder); |
| 208 | |
Matheus Almeida | a591fdc | 2013-10-21 12:26:50 +0000 | [diff] [blame] | 209 | static DecodeStatus DecodeMSACtrlRegisterClass(MCInst &Inst, |
| 210 | unsigned RegNo, |
| 211 | uint64_t Address, |
| 212 | const void *Decoder); |
| 213 | |
Daniel Sanders | 2a83d68 | 2014-05-21 12:56:39 +0000 | [diff] [blame] | 214 | static DecodeStatus DecodeCOP2RegisterClass(MCInst &Inst, |
| 215 | unsigned RegNo, |
| 216 | uint64_t Address, |
| 217 | const void *Decoder); |
| 218 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 219 | static DecodeStatus DecodeBranchTarget(MCInst &Inst, |
| 220 | unsigned Offset, |
| 221 | uint64_t Address, |
| 222 | const void *Decoder); |
| 223 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 224 | static DecodeStatus DecodeJumpTarget(MCInst &Inst, |
| 225 | unsigned Insn, |
| 226 | uint64_t Address, |
| 227 | const void *Decoder); |
| 228 | |
Zoran Jovanovic | 3c8869d | 2014-05-16 11:03:45 +0000 | [diff] [blame] | 229 | static DecodeStatus DecodeBranchTarget21(MCInst &Inst, |
| 230 | unsigned Offset, |
| 231 | uint64_t Address, |
| 232 | const void *Decoder); |
| 233 | |
| 234 | static DecodeStatus DecodeBranchTarget26(MCInst &Inst, |
| 235 | unsigned Offset, |
| 236 | uint64_t Address, |
| 237 | const void *Decoder); |
| 238 | |
Zoran Jovanovic | 8a80aa7 | 2013-11-04 14:53:22 +0000 | [diff] [blame] | 239 | // DecodeBranchTargetMM - Decode microMIPS branch offset, which is |
| 240 | // shifted left by 1 bit. |
| 241 | static DecodeStatus DecodeBranchTargetMM(MCInst &Inst, |
| 242 | unsigned Offset, |
| 243 | uint64_t Address, |
| 244 | const void *Decoder); |
| 245 | |
Zoran Jovanovic | 507e084 | 2013-10-29 16:38:59 +0000 | [diff] [blame] | 246 | // DecodeJumpTargetMM - Decode microMIPS jump target, which is |
| 247 | // shifted left by 1 bit. |
| 248 | static DecodeStatus DecodeJumpTargetMM(MCInst &Inst, |
| 249 | unsigned Insn, |
| 250 | uint64_t Address, |
| 251 | const void *Decoder); |
| 252 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 253 | static DecodeStatus DecodeMem(MCInst &Inst, |
| 254 | unsigned Insn, |
| 255 | uint64_t Address, |
| 256 | const void *Decoder); |
| 257 | |
Daniel Sanders | 92db6b7 | 2014-10-01 08:26:55 +0000 | [diff] [blame] | 258 | static DecodeStatus DecodeCacheOp(MCInst &Inst, |
| 259 | unsigned Insn, |
| 260 | uint64_t Address, |
| 261 | const void *Decoder); |
| 262 | |
Matheus Almeida | fe0bf9f | 2013-10-21 13:07:13 +0000 | [diff] [blame] | 263 | static DecodeStatus DecodeMSA128Mem(MCInst &Inst, unsigned Insn, |
| 264 | uint64_t Address, const void *Decoder); |
| 265 | |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 266 | static DecodeStatus DecodeMemMMImm12(MCInst &Inst, |
| 267 | unsigned Insn, |
| 268 | uint64_t Address, |
| 269 | const void *Decoder); |
| 270 | |
| 271 | static DecodeStatus DecodeMemMMImm16(MCInst &Inst, |
| 272 | unsigned Insn, |
| 273 | uint64_t Address, |
| 274 | const void *Decoder); |
| 275 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 276 | static DecodeStatus DecodeFMem(MCInst &Inst, unsigned Insn, |
| 277 | uint64_t Address, |
| 278 | const void *Decoder); |
| 279 | |
Daniel Sanders | 92db6b7 | 2014-10-01 08:26:55 +0000 | [diff] [blame] | 280 | static DecodeStatus DecodeFMem2(MCInst &Inst, unsigned Insn, |
| 281 | uint64_t Address, |
| 282 | const void *Decoder); |
| 283 | |
| 284 | static DecodeStatus DecodeFMem3(MCInst &Inst, unsigned Insn, |
| 285 | uint64_t Address, |
| 286 | const void *Decoder); |
| 287 | |
Daniel Sanders | 6a803f6 | 2014-06-16 13:13:03 +0000 | [diff] [blame] | 288 | static DecodeStatus DecodeSpecial3LlSc(MCInst &Inst, |
| 289 | unsigned Insn, |
| 290 | uint64_t Address, |
| 291 | const void *Decoder); |
| 292 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 293 | static DecodeStatus DecodeSimm16(MCInst &Inst, |
| 294 | unsigned Insn, |
| 295 | uint64_t Address, |
| 296 | const void *Decoder); |
| 297 | |
Matheus Almeida | 779c593 | 2013-11-18 12:32:49 +0000 | [diff] [blame] | 298 | // Decode the immediate field of an LSA instruction which |
| 299 | // is off by one. |
| 300 | static DecodeStatus DecodeLSAImm(MCInst &Inst, |
| 301 | unsigned Insn, |
| 302 | uint64_t Address, |
| 303 | const void *Decoder); |
| 304 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 305 | static DecodeStatus DecodeInsSize(MCInst &Inst, |
| 306 | unsigned Insn, |
| 307 | uint64_t Address, |
| 308 | const void *Decoder); |
| 309 | |
| 310 | static DecodeStatus DecodeExtSize(MCInst &Inst, |
| 311 | unsigned Insn, |
| 312 | uint64_t Address, |
| 313 | const void *Decoder); |
| 314 | |
Daniel Sanders | b59e1a4 | 2014-05-15 10:45:58 +0000 | [diff] [blame] | 315 | static DecodeStatus DecodeSimm19Lsl2(MCInst &Inst, unsigned Insn, |
| 316 | uint64_t Address, const void *Decoder); |
| 317 | |
Zoran Jovanovic | 2855142 | 2014-06-09 09:49:51 +0000 | [diff] [blame] | 318 | static DecodeStatus DecodeSimm18Lsl3(MCInst &Inst, unsigned Insn, |
| 319 | uint64_t Address, const void *Decoder); |
| 320 | |
Daniel Sanders | b50ccf8 | 2014-04-01 10:35:28 +0000 | [diff] [blame] | 321 | /// INSVE_[BHWD] have an implicit operand that the generated decoder doesn't |
| 322 | /// handle. |
| 323 | template <typename InsnType> |
| 324 | static DecodeStatus DecodeINSVE_DF(MCInst &MI, InsnType insn, uint64_t Address, |
| 325 | const void *Decoder); |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 326 | |
| 327 | template <typename InsnType> |
| 328 | static DecodeStatus |
| 329 | DecodeAddiGroupBranch(MCInst &MI, InsnType insn, uint64_t Address, |
| 330 | const void *Decoder); |
| 331 | |
| 332 | template <typename InsnType> |
| 333 | static DecodeStatus |
| 334 | DecodeDaddiGroupBranch(MCInst &MI, InsnType insn, uint64_t Address, |
| 335 | const void *Decoder); |
| 336 | |
| 337 | template <typename InsnType> |
| 338 | static DecodeStatus |
| 339 | DecodeBlezlGroupBranch(MCInst &MI, InsnType insn, uint64_t Address, |
| 340 | const void *Decoder); |
| 341 | |
| 342 | template <typename InsnType> |
| 343 | static DecodeStatus |
| 344 | DecodeBgtzlGroupBranch(MCInst &MI, InsnType insn, uint64_t Address, |
| 345 | const void *Decoder); |
| 346 | |
| 347 | template <typename InsnType> |
| 348 | static DecodeStatus |
| 349 | DecodeBgtzGroupBranch(MCInst &MI, InsnType insn, uint64_t Address, |
| 350 | const void *Decoder); |
| 351 | |
Zoran Jovanovic | 28a0ca0 | 2014-06-12 11:47:44 +0000 | [diff] [blame] | 352 | template <typename InsnType> |
| 353 | static DecodeStatus |
| 354 | DecodeBlezGroupBranch(MCInst &MI, InsnType insn, uint64_t Address, |
| 355 | const void *Decoder); |
| 356 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 357 | namespace llvm { |
| 358 | extern Target TheMipselTarget, TheMipsTarget, TheMips64Target, |
| 359 | TheMips64elTarget; |
| 360 | } |
| 361 | |
| 362 | static MCDisassembler *createMipsDisassembler( |
| 363 | const Target &T, |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 364 | const MCSubtargetInfo &STI, |
| 365 | MCContext &Ctx) { |
| 366 | return new MipsDisassembler(STI, Ctx, true); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | static MCDisassembler *createMipselDisassembler( |
| 370 | const Target &T, |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 371 | const MCSubtargetInfo &STI, |
| 372 | MCContext &Ctx) { |
| 373 | return new MipsDisassembler(STI, Ctx, false); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | static MCDisassembler *createMips64Disassembler( |
| 377 | const Target &T, |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 378 | const MCSubtargetInfo &STI, |
| 379 | MCContext &Ctx) { |
| 380 | return new Mips64Disassembler(STI, Ctx, true); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | static MCDisassembler *createMips64elDisassembler( |
| 384 | const Target &T, |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 385 | const MCSubtargetInfo &STI, |
| 386 | MCContext &Ctx) { |
| 387 | return new Mips64Disassembler(STI, Ctx, false); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | extern "C" void LLVMInitializeMipsDisassembler() { |
| 391 | // Register the disassembler. |
| 392 | TargetRegistry::RegisterMCDisassembler(TheMipsTarget, |
| 393 | createMipsDisassembler); |
| 394 | TargetRegistry::RegisterMCDisassembler(TheMipselTarget, |
| 395 | createMipselDisassembler); |
| 396 | TargetRegistry::RegisterMCDisassembler(TheMips64Target, |
| 397 | createMips64Disassembler); |
| 398 | TargetRegistry::RegisterMCDisassembler(TheMips64elTarget, |
| 399 | createMips64elDisassembler); |
| 400 | } |
| 401 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 402 | #include "MipsGenDisassemblerTables.inc" |
| 403 | |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 404 | static unsigned getReg(const void *D, unsigned RC, unsigned RegNo) { |
| 405 | const MipsDisassemblerBase *Dis = static_cast<const MipsDisassemblerBase*>(D); |
| 406 | const MCRegisterInfo *RegInfo = Dis->getContext().getRegisterInfo(); |
| 407 | return *(RegInfo->getRegClass(RC).begin() + RegNo); |
| 408 | } |
| 409 | |
Daniel Sanders | b50ccf8 | 2014-04-01 10:35:28 +0000 | [diff] [blame] | 410 | template <typename InsnType> |
| 411 | static DecodeStatus DecodeINSVE_DF(MCInst &MI, InsnType insn, uint64_t Address, |
| 412 | const void *Decoder) { |
| 413 | typedef DecodeStatus (*DecodeFN)(MCInst &, unsigned, uint64_t, const void *); |
| 414 | // The size of the n field depends on the element size |
| 415 | // The register class also depends on this. |
| 416 | InsnType tmp = fieldFromInstruction(insn, 17, 5); |
| 417 | unsigned NSize = 0; |
| 418 | DecodeFN RegDecoder = nullptr; |
| 419 | if ((tmp & 0x18) == 0x00) { // INSVE_B |
| 420 | NSize = 4; |
| 421 | RegDecoder = DecodeMSA128BRegisterClass; |
| 422 | } else if ((tmp & 0x1c) == 0x10) { // INSVE_H |
| 423 | NSize = 3; |
| 424 | RegDecoder = DecodeMSA128HRegisterClass; |
| 425 | } else if ((tmp & 0x1e) == 0x18) { // INSVE_W |
| 426 | NSize = 2; |
| 427 | RegDecoder = DecodeMSA128WRegisterClass; |
| 428 | } else if ((tmp & 0x1f) == 0x1c) { // INSVE_D |
| 429 | NSize = 1; |
| 430 | RegDecoder = DecodeMSA128DRegisterClass; |
| 431 | } else |
| 432 | llvm_unreachable("Invalid encoding"); |
| 433 | |
| 434 | assert(NSize != 0 && RegDecoder != nullptr); |
| 435 | |
| 436 | // $wd |
| 437 | tmp = fieldFromInstruction(insn, 6, 5); |
| 438 | if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler::Fail) |
| 439 | return MCDisassembler::Fail; |
| 440 | // $wd_in |
| 441 | if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler::Fail) |
| 442 | return MCDisassembler::Fail; |
| 443 | // $n |
| 444 | tmp = fieldFromInstruction(insn, 16, NSize); |
| 445 | MI.addOperand(MCOperand::CreateImm(tmp)); |
| 446 | // $ws |
| 447 | tmp = fieldFromInstruction(insn, 11, 5); |
| 448 | if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler::Fail) |
| 449 | return MCDisassembler::Fail; |
| 450 | // $n2 |
| 451 | MI.addOperand(MCOperand::CreateImm(0)); |
| 452 | |
| 453 | return MCDisassembler::Success; |
| 454 | } |
| 455 | |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 456 | template <typename InsnType> |
| 457 | static DecodeStatus DecodeAddiGroupBranch(MCInst &MI, InsnType insn, |
| 458 | uint64_t Address, |
| 459 | const void *Decoder) { |
| 460 | // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled |
| 461 | // (otherwise we would have matched the ADDI instruction from the earlier |
| 462 | // ISA's instead). |
| 463 | // |
| 464 | // We have: |
| 465 | // 0b001000 sssss ttttt iiiiiiiiiiiiiiii |
| 466 | // BOVC if rs >= rt |
| 467 | // BEQZALC if rs == 0 && rt != 0 |
| 468 | // BEQC if rs < rt && rs != 0 |
| 469 | |
| 470 | InsnType Rs = fieldFromInstruction(insn, 21, 5); |
| 471 | InsnType Rt = fieldFromInstruction(insn, 16, 5); |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 472 | InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4; |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 473 | bool HasRs = false; |
| 474 | |
| 475 | if (Rs >= Rt) { |
| 476 | MI.setOpcode(Mips::BOVC); |
| 477 | HasRs = true; |
| 478 | } else if (Rs != 0 && Rs < Rt) { |
| 479 | MI.setOpcode(Mips::BEQC); |
| 480 | HasRs = true; |
| 481 | } else |
| 482 | MI.setOpcode(Mips::BEQZALC); |
| 483 | |
| 484 | if (HasRs) |
| 485 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 486 | Rs))); |
| 487 | |
| 488 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 489 | Rt))); |
| 490 | MI.addOperand(MCOperand::CreateImm(Imm)); |
| 491 | |
| 492 | return MCDisassembler::Success; |
| 493 | } |
| 494 | |
| 495 | template <typename InsnType> |
| 496 | static DecodeStatus DecodeDaddiGroupBranch(MCInst &MI, InsnType insn, |
| 497 | uint64_t Address, |
| 498 | const void *Decoder) { |
| 499 | // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled |
| 500 | // (otherwise we would have matched the ADDI instruction from the earlier |
| 501 | // ISA's instead). |
| 502 | // |
| 503 | // We have: |
| 504 | // 0b011000 sssss ttttt iiiiiiiiiiiiiiii |
| 505 | // BNVC if rs >= rt |
| 506 | // BNEZALC if rs == 0 && rt != 0 |
| 507 | // BNEC if rs < rt && rs != 0 |
| 508 | |
| 509 | InsnType Rs = fieldFromInstruction(insn, 21, 5); |
| 510 | InsnType Rt = fieldFromInstruction(insn, 16, 5); |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 511 | InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4; |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 512 | bool HasRs = false; |
| 513 | |
| 514 | if (Rs >= Rt) { |
| 515 | MI.setOpcode(Mips::BNVC); |
| 516 | HasRs = true; |
| 517 | } else if (Rs != 0 && Rs < Rt) { |
| 518 | MI.setOpcode(Mips::BNEC); |
| 519 | HasRs = true; |
| 520 | } else |
| 521 | MI.setOpcode(Mips::BNEZALC); |
| 522 | |
| 523 | if (HasRs) |
| 524 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 525 | Rs))); |
| 526 | |
| 527 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 528 | Rt))); |
| 529 | MI.addOperand(MCOperand::CreateImm(Imm)); |
| 530 | |
| 531 | return MCDisassembler::Success; |
| 532 | } |
| 533 | |
| 534 | template <typename InsnType> |
| 535 | static DecodeStatus DecodeBlezlGroupBranch(MCInst &MI, InsnType insn, |
| 536 | uint64_t Address, |
| 537 | const void *Decoder) { |
| 538 | // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled |
| 539 | // (otherwise we would have matched the BLEZL instruction from the earlier |
| 540 | // ISA's instead). |
| 541 | // |
| 542 | // We have: |
| 543 | // 0b010110 sssss ttttt iiiiiiiiiiiiiiii |
| 544 | // Invalid if rs == 0 |
| 545 | // BLEZC if rs == 0 && rt != 0 |
| 546 | // BGEZC if rs == rt && rt != 0 |
| 547 | // BGEC if rs != rt && rs != 0 && rt != 0 |
| 548 | |
| 549 | InsnType Rs = fieldFromInstruction(insn, 21, 5); |
| 550 | InsnType Rt = fieldFromInstruction(insn, 16, 5); |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 551 | InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4; |
Zoran Jovanovic | 28a0ca0 | 2014-06-12 11:47:44 +0000 | [diff] [blame] | 552 | bool HasRs = false; |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 553 | |
| 554 | if (Rt == 0) |
| 555 | return MCDisassembler::Fail; |
| 556 | else if (Rs == 0) |
| 557 | MI.setOpcode(Mips::BLEZC); |
| 558 | else if (Rs == Rt) |
| 559 | MI.setOpcode(Mips::BGEZC); |
Zoran Jovanovic | 28a0ca0 | 2014-06-12 11:47:44 +0000 | [diff] [blame] | 560 | else { |
| 561 | HasRs = true; |
| 562 | MI.setOpcode(Mips::BGEC); |
| 563 | } |
| 564 | |
| 565 | if (HasRs) |
| 566 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 567 | Rs))); |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 568 | |
| 569 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 570 | Rt))); |
| 571 | |
| 572 | MI.addOperand(MCOperand::CreateImm(Imm)); |
| 573 | |
| 574 | return MCDisassembler::Success; |
| 575 | } |
| 576 | |
| 577 | template <typename InsnType> |
| 578 | static DecodeStatus DecodeBgtzlGroupBranch(MCInst &MI, InsnType insn, |
| 579 | uint64_t Address, |
| 580 | const void *Decoder) { |
| 581 | // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled |
| 582 | // (otherwise we would have matched the BGTZL instruction from the earlier |
| 583 | // ISA's instead). |
| 584 | // |
| 585 | // We have: |
| 586 | // 0b010111 sssss ttttt iiiiiiiiiiiiiiii |
| 587 | // Invalid if rs == 0 |
| 588 | // BGTZC if rs == 0 && rt != 0 |
| 589 | // BLTZC if rs == rt && rt != 0 |
| 590 | // BLTC if rs != rt && rs != 0 && rt != 0 |
| 591 | |
Zoran Jovanovic | 5c14b06 | 2014-06-18 14:36:00 +0000 | [diff] [blame] | 592 | bool HasRs = false; |
| 593 | |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 594 | InsnType Rs = fieldFromInstruction(insn, 21, 5); |
| 595 | InsnType Rt = fieldFromInstruction(insn, 16, 5); |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 596 | InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4; |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 597 | |
| 598 | if (Rt == 0) |
| 599 | return MCDisassembler::Fail; |
| 600 | else if (Rs == 0) |
| 601 | MI.setOpcode(Mips::BGTZC); |
| 602 | else if (Rs == Rt) |
| 603 | MI.setOpcode(Mips::BLTZC); |
Zoran Jovanovic | 5c14b06 | 2014-06-18 14:36:00 +0000 | [diff] [blame] | 604 | else { |
| 605 | MI.setOpcode(Mips::BLTC); |
| 606 | HasRs = true; |
| 607 | } |
| 608 | |
| 609 | if (HasRs) |
| 610 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 611 | Rs))); |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 612 | |
| 613 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 614 | Rt))); |
| 615 | |
| 616 | MI.addOperand(MCOperand::CreateImm(Imm)); |
| 617 | |
| 618 | return MCDisassembler::Success; |
| 619 | } |
| 620 | |
| 621 | template <typename InsnType> |
| 622 | static DecodeStatus DecodeBgtzGroupBranch(MCInst &MI, InsnType insn, |
| 623 | uint64_t Address, |
| 624 | const void *Decoder) { |
| 625 | // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled |
| 626 | // (otherwise we would have matched the BGTZ instruction from the earlier |
| 627 | // ISA's instead). |
| 628 | // |
| 629 | // We have: |
| 630 | // 0b000111 sssss ttttt iiiiiiiiiiiiiiii |
| 631 | // BGTZ if rt == 0 |
| 632 | // BGTZALC if rs == 0 && rt != 0 |
| 633 | // BLTZALC if rs != 0 && rs == rt |
| 634 | // BLTUC if rs != 0 && rs != rt |
| 635 | |
| 636 | InsnType Rs = fieldFromInstruction(insn, 21, 5); |
| 637 | InsnType Rt = fieldFromInstruction(insn, 16, 5); |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 638 | InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4; |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 639 | bool HasRs = false; |
| 640 | bool HasRt = false; |
| 641 | |
| 642 | if (Rt == 0) { |
| 643 | MI.setOpcode(Mips::BGTZ); |
| 644 | HasRs = true; |
| 645 | } else if (Rs == 0) { |
| 646 | MI.setOpcode(Mips::BGTZALC); |
| 647 | HasRt = true; |
| 648 | } else if (Rs == Rt) { |
| 649 | MI.setOpcode(Mips::BLTZALC); |
| 650 | HasRs = true; |
Zoran Jovanovic | 5c14b06 | 2014-06-18 14:36:00 +0000 | [diff] [blame] | 651 | } else { |
| 652 | MI.setOpcode(Mips::BLTUC); |
| 653 | HasRs = true; |
| 654 | HasRt = true; |
| 655 | } |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 656 | |
| 657 | if (HasRs) |
| 658 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 659 | Rs))); |
| 660 | |
| 661 | if (HasRt) |
| 662 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 663 | Rt))); |
| 664 | |
| 665 | MI.addOperand(MCOperand::CreateImm(Imm)); |
| 666 | |
| 667 | return MCDisassembler::Success; |
| 668 | } |
| 669 | |
Zoran Jovanovic | 28a0ca0 | 2014-06-12 11:47:44 +0000 | [diff] [blame] | 670 | template <typename InsnType> |
| 671 | static DecodeStatus DecodeBlezGroupBranch(MCInst &MI, InsnType insn, |
| 672 | uint64_t Address, |
| 673 | const void *Decoder) { |
| 674 | // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled |
| 675 | // (otherwise we would have matched the BLEZL instruction from the earlier |
| 676 | // ISA's instead). |
| 677 | // |
| 678 | // We have: |
| 679 | // 0b000110 sssss ttttt iiiiiiiiiiiiiiii |
| 680 | // Invalid if rs == 0 |
| 681 | // BLEZALC if rs == 0 && rt != 0 |
| 682 | // BGEZALC if rs == rt && rt != 0 |
| 683 | // BGEUC if rs != rt && rs != 0 && rt != 0 |
| 684 | |
| 685 | InsnType Rs = fieldFromInstruction(insn, 21, 5); |
| 686 | InsnType Rt = fieldFromInstruction(insn, 16, 5); |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 687 | InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4; |
Zoran Jovanovic | 28a0ca0 | 2014-06-12 11:47:44 +0000 | [diff] [blame] | 688 | bool HasRs = false; |
| 689 | |
| 690 | if (Rt == 0) |
| 691 | return MCDisassembler::Fail; |
| 692 | else if (Rs == 0) |
| 693 | MI.setOpcode(Mips::BLEZALC); |
| 694 | else if (Rs == Rt) |
| 695 | MI.setOpcode(Mips::BGEZALC); |
| 696 | else { |
| 697 | HasRs = true; |
| 698 | MI.setOpcode(Mips::BGEUC); |
| 699 | } |
| 700 | |
| 701 | if (HasRs) |
| 702 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 703 | Rs))); |
| 704 | MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID, |
| 705 | Rt))); |
| 706 | |
| 707 | MI.addOperand(MCOperand::CreateImm(Imm)); |
| 708 | |
| 709 | return MCDisassembler::Success; |
| 710 | } |
| 711 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 712 | /// readInstruction - read four bytes from the MemoryObject |
| 713 | /// and return 32 bit word sorted according to the given endianess |
| 714 | static DecodeStatus readInstruction32(const MemoryObject ®ion, |
| 715 | uint64_t address, |
| 716 | uint64_t &size, |
| 717 | uint32_t &insn, |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 718 | bool isBigEndian, |
| 719 | bool IsMicroMips) { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 720 | uint8_t Bytes[4]; |
| 721 | |
| 722 | // We want to read exactly 4 Bytes of data. |
Benjamin Kramer | 534d3a4 | 2013-05-24 10:54:58 +0000 | [diff] [blame] | 723 | if (region.readBytes(address, 4, Bytes) == -1) { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 724 | size = 0; |
| 725 | return MCDisassembler::Fail; |
| 726 | } |
| 727 | |
| 728 | if (isBigEndian) { |
| 729 | // Encoded as a big-endian 32-bit word in the stream. |
| 730 | insn = (Bytes[3] << 0) | |
| 731 | (Bytes[2] << 8) | |
| 732 | (Bytes[1] << 16) | |
| 733 | (Bytes[0] << 24); |
| 734 | } |
| 735 | else { |
| 736 | // Encoded as a small-endian 32-bit word in the stream. |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 737 | // Little-endian byte ordering: |
| 738 | // mips32r2: 4 | 3 | 2 | 1 |
| 739 | // microMIPS: 2 | 1 | 4 | 3 |
| 740 | if (IsMicroMips) { |
| 741 | insn = (Bytes[2] << 0) | |
| 742 | (Bytes[3] << 8) | |
| 743 | (Bytes[0] << 16) | |
| 744 | (Bytes[1] << 24); |
| 745 | } else { |
| 746 | insn = (Bytes[0] << 0) | |
| 747 | (Bytes[1] << 8) | |
| 748 | (Bytes[2] << 16) | |
| 749 | (Bytes[3] << 24); |
| 750 | } |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | return MCDisassembler::Success; |
| 754 | } |
| 755 | |
| 756 | DecodeStatus |
| 757 | MipsDisassembler::getInstruction(MCInst &instr, |
| 758 | uint64_t &Size, |
| 759 | const MemoryObject &Region, |
| 760 | uint64_t Address, |
| 761 | raw_ostream &vStream, |
| 762 | raw_ostream &cStream) const { |
| 763 | uint32_t Insn; |
| 764 | |
| 765 | DecodeStatus Result = readInstruction32(Region, Address, Size, |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 766 | Insn, isBigEndian, IsMicroMips); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 767 | if (Result == MCDisassembler::Fail) |
| 768 | return MCDisassembler::Fail; |
| 769 | |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 770 | if (IsMicroMips) { |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 771 | DEBUG(dbgs() << "Trying MicroMips32 table (32-bit opcodes):\n"); |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 772 | // Calling the auto-generated decoder function. |
| 773 | Result = decodeInstruction(DecoderTableMicroMips32, instr, Insn, Address, |
| 774 | this, STI); |
| 775 | if (Result != MCDisassembler::Fail) { |
| 776 | Size = 4; |
| 777 | return Result; |
| 778 | } |
| 779 | return MCDisassembler::Fail; |
| 780 | } |
| 781 | |
Daniel Sanders | c171f65 | 2014-06-13 13:15:59 +0000 | [diff] [blame] | 782 | if (hasCOP3()) { |
| 783 | DEBUG(dbgs() << "Trying COP3_ table (32-bit opcodes):\n"); |
| 784 | Result = |
| 785 | decodeInstruction(DecoderTableCOP3_32, instr, Insn, Address, this, STI); |
| 786 | if (Result != MCDisassembler::Fail) { |
| 787 | Size = 4; |
| 788 | return Result; |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | if (hasMips32r6() && isGP64()) { |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 793 | DEBUG(dbgs() << "Trying Mips32r6_64r6 (GPR64) table (32-bit opcodes):\n"); |
| 794 | Result = decodeInstruction(DecoderTableMips32r6_64r6_GP6432, instr, Insn, |
| 795 | Address, this, STI); |
| 796 | if (Result != MCDisassembler::Fail) { |
| 797 | Size = 4; |
| 798 | return Result; |
| 799 | } |
| 800 | } |
| 801 | |
Daniel Sanders | c171f65 | 2014-06-13 13:15:59 +0000 | [diff] [blame] | 802 | if (hasMips32r6()) { |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 803 | DEBUG(dbgs() << "Trying Mips32r6_64r6 table (32-bit opcodes):\n"); |
Daniel Sanders | 5c582b2 | 2014-05-22 11:23:21 +0000 | [diff] [blame] | 804 | Result = decodeInstruction(DecoderTableMips32r6_64r632, instr, Insn, |
| 805 | Address, this, STI); |
| 806 | if (Result != MCDisassembler::Fail) { |
| 807 | Size = 4; |
| 808 | return Result; |
| 809 | } |
| 810 | } |
| 811 | |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 812 | DEBUG(dbgs() << "Trying Mips table (32-bit opcodes):\n"); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 813 | // Calling the auto-generated decoder function. |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 814 | Result = decodeInstruction(DecoderTableMips32, instr, Insn, Address, |
| 815 | this, STI); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 816 | if (Result != MCDisassembler::Fail) { |
| 817 | Size = 4; |
| 818 | return Result; |
| 819 | } |
| 820 | |
| 821 | return MCDisassembler::Fail; |
| 822 | } |
| 823 | |
| 824 | DecodeStatus |
| 825 | Mips64Disassembler::getInstruction(MCInst &instr, |
| 826 | uint64_t &Size, |
| 827 | const MemoryObject &Region, |
| 828 | uint64_t Address, |
| 829 | raw_ostream &vStream, |
| 830 | raw_ostream &cStream) const { |
| 831 | uint32_t Insn; |
| 832 | |
| 833 | DecodeStatus Result = readInstruction32(Region, Address, Size, |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 834 | Insn, isBigEndian, false); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 835 | if (Result == MCDisassembler::Fail) |
| 836 | return MCDisassembler::Fail; |
| 837 | |
| 838 | // Calling the auto-generated decoder function. |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 839 | Result = decodeInstruction(DecoderTableMips6432, instr, Insn, Address, |
| 840 | this, STI); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 841 | if (Result != MCDisassembler::Fail) { |
| 842 | Size = 4; |
| 843 | return Result; |
| 844 | } |
| 845 | // If we fail to decode in Mips64 decoder space we can try in Mips32 |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 846 | Result = decodeInstruction(DecoderTableMips32, instr, Insn, Address, |
| 847 | this, STI); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 848 | if (Result != MCDisassembler::Fail) { |
| 849 | Size = 4; |
| 850 | return Result; |
| 851 | } |
| 852 | |
| 853 | return MCDisassembler::Fail; |
| 854 | } |
| 855 | |
Reed Kotler | ec8a549 | 2013-02-14 03:05:25 +0000 | [diff] [blame] | 856 | static DecodeStatus DecodeCPU16RegsRegisterClass(MCInst &Inst, |
| 857 | unsigned RegNo, |
| 858 | uint64_t Address, |
| 859 | const void *Decoder) { |
| 860 | |
| 861 | return MCDisassembler::Fail; |
| 862 | |
| 863 | } |
| 864 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 865 | static DecodeStatus DecodeGPR64RegisterClass(MCInst &Inst, |
| 866 | unsigned RegNo, |
| 867 | uint64_t Address, |
| 868 | const void *Decoder) { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 869 | |
| 870 | if (RegNo > 31) |
| 871 | return MCDisassembler::Fail; |
| 872 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 873 | unsigned Reg = getReg(Decoder, Mips::GPR64RegClassID, RegNo); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 874 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 875 | return MCDisassembler::Success; |
| 876 | } |
| 877 | |
Zoran Jovanovic | b0852e5 | 2014-10-21 08:23:11 +0000 | [diff] [blame^] | 878 | static DecodeStatus DecodeGPRMM16RegisterClass(MCInst &Inst, |
| 879 | unsigned RegNo, |
| 880 | uint64_t Address, |
| 881 | const void *Decoder) { |
| 882 | return MCDisassembler::Fail; |
| 883 | } |
| 884 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 885 | static DecodeStatus DecodeGPR32RegisterClass(MCInst &Inst, |
| 886 | unsigned RegNo, |
| 887 | uint64_t Address, |
| 888 | const void *Decoder) { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 889 | if (RegNo > 31) |
| 890 | return MCDisassembler::Fail; |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 891 | unsigned Reg = getReg(Decoder, Mips::GPR32RegClassID, RegNo); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 892 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 893 | return MCDisassembler::Success; |
| 894 | } |
| 895 | |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 896 | static DecodeStatus DecodePtrRegisterClass(MCInst &Inst, |
| 897 | unsigned RegNo, |
| 898 | uint64_t Address, |
| 899 | const void *Decoder) { |
| 900 | if (static_cast<const MipsDisassembler *>(Decoder)->isN64()) |
| 901 | return DecodeGPR64RegisterClass(Inst, RegNo, Address, Decoder); |
| 902 | |
| 903 | return DecodeGPR32RegisterClass(Inst, RegNo, Address, Decoder); |
| 904 | } |
| 905 | |
Akira Hatanaka | 654655f | 2013-08-14 00:53:38 +0000 | [diff] [blame] | 906 | static DecodeStatus DecodeDSPRRegisterClass(MCInst &Inst, |
| 907 | unsigned RegNo, |
| 908 | uint64_t Address, |
| 909 | const void *Decoder) { |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 910 | return DecodeGPR32RegisterClass(Inst, RegNo, Address, Decoder); |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 911 | } |
| 912 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 913 | static DecodeStatus DecodeFGR64RegisterClass(MCInst &Inst, |
| 914 | unsigned RegNo, |
| 915 | uint64_t Address, |
| 916 | const void *Decoder) { |
| 917 | if (RegNo > 31) |
| 918 | return MCDisassembler::Fail; |
| 919 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 920 | unsigned Reg = getReg(Decoder, Mips::FGR64RegClassID, RegNo); |
| 921 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 922 | return MCDisassembler::Success; |
| 923 | } |
| 924 | |
| 925 | static DecodeStatus DecodeFGR32RegisterClass(MCInst &Inst, |
| 926 | unsigned RegNo, |
| 927 | uint64_t Address, |
| 928 | const void *Decoder) { |
| 929 | if (RegNo > 31) |
| 930 | return MCDisassembler::Fail; |
| 931 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 932 | unsigned Reg = getReg(Decoder, Mips::FGR32RegClassID, RegNo); |
| 933 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 934 | return MCDisassembler::Success; |
| 935 | } |
| 936 | |
| 937 | static DecodeStatus DecodeCCRRegisterClass(MCInst &Inst, |
| 938 | unsigned RegNo, |
| 939 | uint64_t Address, |
| 940 | const void *Decoder) { |
Chad Rosier | 253777f | 2013-06-26 22:23:32 +0000 | [diff] [blame] | 941 | if (RegNo > 31) |
| 942 | return MCDisassembler::Fail; |
| 943 | unsigned Reg = getReg(Decoder, Mips::CCRRegClassID, RegNo); |
| 944 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 945 | return MCDisassembler::Success; |
| 946 | } |
| 947 | |
Akira Hatanaka | 1fb1b8b | 2013-07-26 20:13:47 +0000 | [diff] [blame] | 948 | static DecodeStatus DecodeFCCRegisterClass(MCInst &Inst, |
| 949 | unsigned RegNo, |
| 950 | uint64_t Address, |
| 951 | const void *Decoder) { |
| 952 | if (RegNo > 7) |
| 953 | return MCDisassembler::Fail; |
| 954 | unsigned Reg = getReg(Decoder, Mips::FCCRegClassID, RegNo); |
| 955 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 956 | return MCDisassembler::Success; |
| 957 | } |
| 958 | |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 959 | static DecodeStatus DecodeFGRCCRegisterClass(MCInst &Inst, unsigned RegNo, |
| 960 | uint64_t Address, |
| 961 | const void *Decoder) { |
| 962 | if (RegNo > 31) |
| 963 | return MCDisassembler::Fail; |
| 964 | |
| 965 | unsigned Reg = getReg(Decoder, Mips::FGRCCRegClassID, RegNo); |
| 966 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 967 | return MCDisassembler::Success; |
| 968 | } |
| 969 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 970 | static DecodeStatus DecodeMem(MCInst &Inst, |
| 971 | unsigned Insn, |
| 972 | uint64_t Address, |
| 973 | const void *Decoder) { |
| 974 | int Offset = SignExtend32<16>(Insn & 0xffff); |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 975 | unsigned Reg = fieldFromInstruction(Insn, 16, 5); |
| 976 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 977 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 978 | Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg); |
| 979 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 980 | |
| 981 | if(Inst.getOpcode() == Mips::SC){ |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 982 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 983 | } |
| 984 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 985 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 986 | Inst.addOperand(MCOperand::CreateReg(Base)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 987 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 988 | |
| 989 | return MCDisassembler::Success; |
| 990 | } |
| 991 | |
Daniel Sanders | 92db6b7 | 2014-10-01 08:26:55 +0000 | [diff] [blame] | 992 | static DecodeStatus DecodeCacheOp(MCInst &Inst, |
| 993 | unsigned Insn, |
| 994 | uint64_t Address, |
| 995 | const void *Decoder) { |
| 996 | int Offset = SignExtend32<16>(Insn & 0xffff); |
| 997 | unsigned Hint = fieldFromInstruction(Insn, 16, 5); |
| 998 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
| 999 | |
| 1000 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1001 | |
| 1002 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 1003 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1004 | Inst.addOperand(MCOperand::CreateImm(Hint)); |
| 1005 | |
| 1006 | return MCDisassembler::Success; |
| 1007 | } |
| 1008 | |
Matheus Almeida | fe0bf9f | 2013-10-21 13:07:13 +0000 | [diff] [blame] | 1009 | static DecodeStatus DecodeMSA128Mem(MCInst &Inst, unsigned Insn, |
| 1010 | uint64_t Address, const void *Decoder) { |
| 1011 | int Offset = SignExtend32<10>(fieldFromInstruction(Insn, 16, 10)); |
| 1012 | unsigned Reg = fieldFromInstruction(Insn, 6, 5); |
| 1013 | unsigned Base = fieldFromInstruction(Insn, 11, 5); |
| 1014 | |
| 1015 | Reg = getReg(Decoder, Mips::MSA128BRegClassID, Reg); |
| 1016 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1017 | |
| 1018 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1019 | Inst.addOperand(MCOperand::CreateReg(Base)); |
Matheus Almeida | 6b59c44 | 2013-12-05 11:06:22 +0000 | [diff] [blame] | 1020 | |
| 1021 | // The immediate field of an LD/ST instruction is scaled which means it must |
| 1022 | // be multiplied (when decoding) by the size (in bytes) of the instructions' |
| 1023 | // data format. |
| 1024 | // .b - 1 byte |
| 1025 | // .h - 2 bytes |
| 1026 | // .w - 4 bytes |
| 1027 | // .d - 8 bytes |
| 1028 | switch(Inst.getOpcode()) |
| 1029 | { |
| 1030 | default: |
| 1031 | assert (0 && "Unexpected instruction"); |
| 1032 | return MCDisassembler::Fail; |
| 1033 | break; |
| 1034 | case Mips::LD_B: |
| 1035 | case Mips::ST_B: |
| 1036 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1037 | break; |
| 1038 | case Mips::LD_H: |
| 1039 | case Mips::ST_H: |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1040 | Inst.addOperand(MCOperand::CreateImm(Offset * 2)); |
Matheus Almeida | 6b59c44 | 2013-12-05 11:06:22 +0000 | [diff] [blame] | 1041 | break; |
| 1042 | case Mips::LD_W: |
| 1043 | case Mips::ST_W: |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1044 | Inst.addOperand(MCOperand::CreateImm(Offset * 4)); |
Matheus Almeida | 6b59c44 | 2013-12-05 11:06:22 +0000 | [diff] [blame] | 1045 | break; |
| 1046 | case Mips::LD_D: |
| 1047 | case Mips::ST_D: |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1048 | Inst.addOperand(MCOperand::CreateImm(Offset * 8)); |
Matheus Almeida | 6b59c44 | 2013-12-05 11:06:22 +0000 | [diff] [blame] | 1049 | break; |
| 1050 | } |
Matheus Almeida | fe0bf9f | 2013-10-21 13:07:13 +0000 | [diff] [blame] | 1051 | |
| 1052 | return MCDisassembler::Success; |
| 1053 | } |
| 1054 | |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 1055 | static DecodeStatus DecodeMemMMImm12(MCInst &Inst, |
| 1056 | unsigned Insn, |
| 1057 | uint64_t Address, |
| 1058 | const void *Decoder) { |
| 1059 | int Offset = SignExtend32<12>(Insn & 0x0fff); |
| 1060 | unsigned Reg = fieldFromInstruction(Insn, 21, 5); |
| 1061 | unsigned Base = fieldFromInstruction(Insn, 16, 5); |
| 1062 | |
| 1063 | Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg); |
| 1064 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1065 | |
Zoran Jovanovic | 285cc28 | 2014-02-28 18:22:56 +0000 | [diff] [blame] | 1066 | if (Inst.getOpcode() == Mips::SC_MM) |
| 1067 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1068 | |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 1069 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1070 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 1071 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1072 | |
| 1073 | return MCDisassembler::Success; |
| 1074 | } |
| 1075 | |
| 1076 | static DecodeStatus DecodeMemMMImm16(MCInst &Inst, |
| 1077 | unsigned Insn, |
| 1078 | uint64_t Address, |
| 1079 | const void *Decoder) { |
| 1080 | int Offset = SignExtend32<16>(Insn & 0xffff); |
| 1081 | unsigned Reg = fieldFromInstruction(Insn, 21, 5); |
| 1082 | unsigned Base = fieldFromInstruction(Insn, 16, 5); |
| 1083 | |
| 1084 | Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg); |
| 1085 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1086 | |
| 1087 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1088 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 1089 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1090 | |
| 1091 | return MCDisassembler::Success; |
| 1092 | } |
| 1093 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1094 | static DecodeStatus DecodeFMem(MCInst &Inst, |
| 1095 | unsigned Insn, |
| 1096 | uint64_t Address, |
| 1097 | const void *Decoder) { |
| 1098 | int Offset = SignExtend32<16>(Insn & 0xffff); |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 1099 | unsigned Reg = fieldFromInstruction(Insn, 16, 5); |
| 1100 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1101 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 1102 | Reg = getReg(Decoder, Mips::FGR64RegClassID, Reg); |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 1103 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 1104 | |
| 1105 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1106 | Inst.addOperand(MCOperand::CreateReg(Base)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1107 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1108 | |
| 1109 | return MCDisassembler::Success; |
| 1110 | } |
| 1111 | |
Daniel Sanders | 92db6b7 | 2014-10-01 08:26:55 +0000 | [diff] [blame] | 1112 | static DecodeStatus DecodeFMem2(MCInst &Inst, |
| 1113 | unsigned Insn, |
| 1114 | uint64_t Address, |
| 1115 | const void *Decoder) { |
| 1116 | int Offset = SignExtend32<16>(Insn & 0xffff); |
| 1117 | unsigned Reg = fieldFromInstruction(Insn, 16, 5); |
| 1118 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
| 1119 | |
| 1120 | Reg = getReg(Decoder, Mips::COP2RegClassID, Reg); |
| 1121 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1122 | |
| 1123 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1124 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 1125 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1126 | |
| 1127 | return MCDisassembler::Success; |
| 1128 | } |
| 1129 | |
| 1130 | static DecodeStatus DecodeFMem3(MCInst &Inst, |
| 1131 | unsigned Insn, |
| 1132 | uint64_t Address, |
| 1133 | const void *Decoder) { |
| 1134 | int Offset = SignExtend32<16>(Insn & 0xffff); |
| 1135 | unsigned Reg = fieldFromInstruction(Insn, 16, 5); |
| 1136 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
| 1137 | |
| 1138 | Reg = getReg(Decoder, Mips::COP3RegClassID, Reg); |
| 1139 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1140 | |
| 1141 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1142 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 1143 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1144 | |
| 1145 | return MCDisassembler::Success; |
| 1146 | } |
| 1147 | |
Daniel Sanders | 6a803f6 | 2014-06-16 13:13:03 +0000 | [diff] [blame] | 1148 | static DecodeStatus DecodeSpecial3LlSc(MCInst &Inst, |
| 1149 | unsigned Insn, |
| 1150 | uint64_t Address, |
| 1151 | const void *Decoder) { |
| 1152 | int64_t Offset = SignExtend64<9>((Insn >> 7) & 0x1ff); |
| 1153 | unsigned Rt = fieldFromInstruction(Insn, 16, 5); |
| 1154 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
| 1155 | |
| 1156 | Rt = getReg(Decoder, Mips::GPR32RegClassID, Rt); |
| 1157 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 1158 | |
| 1159 | if(Inst.getOpcode() == Mips::SC_R6 || Inst.getOpcode() == Mips::SCD_R6){ |
| 1160 | Inst.addOperand(MCOperand::CreateReg(Rt)); |
| 1161 | } |
| 1162 | |
| 1163 | Inst.addOperand(MCOperand::CreateReg(Rt)); |
| 1164 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 1165 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 1166 | |
| 1167 | return MCDisassembler::Success; |
| 1168 | } |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1169 | |
| 1170 | static DecodeStatus DecodeHWRegsRegisterClass(MCInst &Inst, |
| 1171 | unsigned RegNo, |
| 1172 | uint64_t Address, |
| 1173 | const void *Decoder) { |
| 1174 | // Currently only hardware register 29 is supported. |
| 1175 | if (RegNo != 29) |
| 1176 | return MCDisassembler::Fail; |
| 1177 | Inst.addOperand(MCOperand::CreateReg(Mips::HWR29)); |
| 1178 | return MCDisassembler::Success; |
| 1179 | } |
| 1180 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1181 | static DecodeStatus DecodeAFGR64RegisterClass(MCInst &Inst, |
| 1182 | unsigned RegNo, |
| 1183 | uint64_t Address, |
| 1184 | const void *Decoder) { |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 1185 | if (RegNo > 30 || RegNo %2) |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1186 | return MCDisassembler::Fail; |
| 1187 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 1188 | ; |
| 1189 | unsigned Reg = getReg(Decoder, Mips::AFGR64RegClassID, RegNo /2); |
| 1190 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1191 | return MCDisassembler::Success; |
| 1192 | } |
| 1193 | |
Akira Hatanaka | 00fcf2e | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 1194 | static DecodeStatus DecodeACC64DSPRegisterClass(MCInst &Inst, |
| 1195 | unsigned RegNo, |
| 1196 | uint64_t Address, |
| 1197 | const void *Decoder) { |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 1198 | if (RegNo >= 4) |
| 1199 | return MCDisassembler::Fail; |
| 1200 | |
Akira Hatanaka | 00fcf2e | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 1201 | unsigned Reg = getReg(Decoder, Mips::ACC64DSPRegClassID, RegNo); |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 1202 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1203 | return MCDisassembler::Success; |
| 1204 | } |
| 1205 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 1206 | static DecodeStatus DecodeHI32DSPRegisterClass(MCInst &Inst, |
| 1207 | unsigned RegNo, |
| 1208 | uint64_t Address, |
| 1209 | const void *Decoder) { |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 1210 | if (RegNo >= 4) |
| 1211 | return MCDisassembler::Fail; |
| 1212 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 1213 | unsigned Reg = getReg(Decoder, Mips::HI32DSPRegClassID, RegNo); |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 1214 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1215 | return MCDisassembler::Success; |
| 1216 | } |
| 1217 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 1218 | static DecodeStatus DecodeLO32DSPRegisterClass(MCInst &Inst, |
| 1219 | unsigned RegNo, |
| 1220 | uint64_t Address, |
| 1221 | const void *Decoder) { |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 1222 | if (RegNo >= 4) |
| 1223 | return MCDisassembler::Fail; |
| 1224 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 1225 | unsigned Reg = getReg(Decoder, Mips::LO32DSPRegClassID, RegNo); |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 1226 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1227 | return MCDisassembler::Success; |
| 1228 | } |
| 1229 | |
Jack Carter | 3eb663b | 2013-09-26 00:09:46 +0000 | [diff] [blame] | 1230 | static DecodeStatus DecodeMSA128BRegisterClass(MCInst &Inst, |
| 1231 | unsigned RegNo, |
| 1232 | uint64_t Address, |
| 1233 | const void *Decoder) { |
| 1234 | if (RegNo > 31) |
| 1235 | return MCDisassembler::Fail; |
| 1236 | |
| 1237 | unsigned Reg = getReg(Decoder, Mips::MSA128BRegClassID, RegNo); |
| 1238 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1239 | return MCDisassembler::Success; |
| 1240 | } |
| 1241 | |
Jack Carter | 5dc8ac9 | 2013-09-25 23:50:44 +0000 | [diff] [blame] | 1242 | static DecodeStatus DecodeMSA128HRegisterClass(MCInst &Inst, |
| 1243 | unsigned RegNo, |
| 1244 | uint64_t Address, |
| 1245 | const void *Decoder) { |
| 1246 | if (RegNo > 31) |
| 1247 | return MCDisassembler::Fail; |
| 1248 | |
| 1249 | unsigned Reg = getReg(Decoder, Mips::MSA128HRegClassID, RegNo); |
| 1250 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1251 | return MCDisassembler::Success; |
| 1252 | } |
| 1253 | |
| 1254 | static DecodeStatus DecodeMSA128WRegisterClass(MCInst &Inst, |
| 1255 | unsigned RegNo, |
| 1256 | uint64_t Address, |
| 1257 | const void *Decoder) { |
| 1258 | if (RegNo > 31) |
| 1259 | return MCDisassembler::Fail; |
| 1260 | |
| 1261 | unsigned Reg = getReg(Decoder, Mips::MSA128WRegClassID, RegNo); |
| 1262 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1263 | return MCDisassembler::Success; |
| 1264 | } |
| 1265 | |
| 1266 | static DecodeStatus DecodeMSA128DRegisterClass(MCInst &Inst, |
| 1267 | unsigned RegNo, |
| 1268 | uint64_t Address, |
| 1269 | const void *Decoder) { |
| 1270 | if (RegNo > 31) |
| 1271 | return MCDisassembler::Fail; |
| 1272 | |
| 1273 | unsigned Reg = getReg(Decoder, Mips::MSA128DRegClassID, RegNo); |
| 1274 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1275 | return MCDisassembler::Success; |
| 1276 | } |
| 1277 | |
Matheus Almeida | a591fdc | 2013-10-21 12:26:50 +0000 | [diff] [blame] | 1278 | static DecodeStatus DecodeMSACtrlRegisterClass(MCInst &Inst, |
| 1279 | unsigned RegNo, |
| 1280 | uint64_t Address, |
| 1281 | const void *Decoder) { |
| 1282 | if (RegNo > 7) |
| 1283 | return MCDisassembler::Fail; |
| 1284 | |
| 1285 | unsigned Reg = getReg(Decoder, Mips::MSACtrlRegClassID, RegNo); |
| 1286 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1287 | return MCDisassembler::Success; |
| 1288 | } |
| 1289 | |
Daniel Sanders | 2a83d68 | 2014-05-21 12:56:39 +0000 | [diff] [blame] | 1290 | static DecodeStatus DecodeCOP2RegisterClass(MCInst &Inst, |
| 1291 | unsigned RegNo, |
| 1292 | uint64_t Address, |
| 1293 | const void *Decoder) { |
| 1294 | if (RegNo > 31) |
| 1295 | return MCDisassembler::Fail; |
| 1296 | |
| 1297 | unsigned Reg = getReg(Decoder, Mips::COP2RegClassID, RegNo); |
| 1298 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 1299 | return MCDisassembler::Success; |
| 1300 | } |
| 1301 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1302 | static DecodeStatus DecodeBranchTarget(MCInst &Inst, |
| 1303 | unsigned Offset, |
| 1304 | uint64_t Address, |
| 1305 | const void *Decoder) { |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1306 | int32_t BranchOffset = (SignExtend32<16>(Offset) * 4) + 4; |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1307 | Inst.addOperand(MCOperand::CreateImm(BranchOffset)); |
| 1308 | return MCDisassembler::Success; |
| 1309 | } |
| 1310 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1311 | static DecodeStatus DecodeJumpTarget(MCInst &Inst, |
| 1312 | unsigned Insn, |
| 1313 | uint64_t Address, |
| 1314 | const void *Decoder) { |
| 1315 | |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 1316 | unsigned JumpOffset = fieldFromInstruction(Insn, 0, 26) << 2; |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1317 | Inst.addOperand(MCOperand::CreateImm(JumpOffset)); |
| 1318 | return MCDisassembler::Success; |
| 1319 | } |
| 1320 | |
Zoran Jovanovic | 3c8869d | 2014-05-16 11:03:45 +0000 | [diff] [blame] | 1321 | static DecodeStatus DecodeBranchTarget21(MCInst &Inst, |
| 1322 | unsigned Offset, |
| 1323 | uint64_t Address, |
| 1324 | const void *Decoder) { |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1325 | int32_t BranchOffset = SignExtend32<21>(Offset) * 4; |
Zoran Jovanovic | 3c8869d | 2014-05-16 11:03:45 +0000 | [diff] [blame] | 1326 | |
| 1327 | Inst.addOperand(MCOperand::CreateImm(BranchOffset)); |
| 1328 | return MCDisassembler::Success; |
| 1329 | } |
| 1330 | |
| 1331 | static DecodeStatus DecodeBranchTarget26(MCInst &Inst, |
| 1332 | unsigned Offset, |
| 1333 | uint64_t Address, |
| 1334 | const void *Decoder) { |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1335 | int32_t BranchOffset = SignExtend32<26>(Offset) * 4; |
Zoran Jovanovic | 3c8869d | 2014-05-16 11:03:45 +0000 | [diff] [blame] | 1336 | |
| 1337 | Inst.addOperand(MCOperand::CreateImm(BranchOffset)); |
| 1338 | return MCDisassembler::Success; |
| 1339 | } |
| 1340 | |
Zoran Jovanovic | 8a80aa7 | 2013-11-04 14:53:22 +0000 | [diff] [blame] | 1341 | static DecodeStatus DecodeBranchTargetMM(MCInst &Inst, |
| 1342 | unsigned Offset, |
| 1343 | uint64_t Address, |
| 1344 | const void *Decoder) { |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1345 | int32_t BranchOffset = SignExtend32<16>(Offset) * 2; |
Zoran Jovanovic | 8a80aa7 | 2013-11-04 14:53:22 +0000 | [diff] [blame] | 1346 | Inst.addOperand(MCOperand::CreateImm(BranchOffset)); |
| 1347 | return MCDisassembler::Success; |
| 1348 | } |
| 1349 | |
Zoran Jovanovic | 507e084 | 2013-10-29 16:38:59 +0000 | [diff] [blame] | 1350 | static DecodeStatus DecodeJumpTargetMM(MCInst &Inst, |
| 1351 | unsigned Insn, |
| 1352 | uint64_t Address, |
| 1353 | const void *Decoder) { |
| 1354 | unsigned JumpOffset = fieldFromInstruction(Insn, 0, 26) << 1; |
| 1355 | Inst.addOperand(MCOperand::CreateImm(JumpOffset)); |
| 1356 | return MCDisassembler::Success; |
| 1357 | } |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1358 | |
| 1359 | static DecodeStatus DecodeSimm16(MCInst &Inst, |
| 1360 | unsigned Insn, |
| 1361 | uint64_t Address, |
| 1362 | const void *Decoder) { |
| 1363 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<16>(Insn))); |
| 1364 | return MCDisassembler::Success; |
| 1365 | } |
| 1366 | |
Matheus Almeida | 779c593 | 2013-11-18 12:32:49 +0000 | [diff] [blame] | 1367 | static DecodeStatus DecodeLSAImm(MCInst &Inst, |
| 1368 | unsigned Insn, |
| 1369 | uint64_t Address, |
| 1370 | const void *Decoder) { |
| 1371 | // We add one to the immediate field as it was encoded as 'imm - 1'. |
| 1372 | Inst.addOperand(MCOperand::CreateImm(Insn + 1)); |
| 1373 | return MCDisassembler::Success; |
| 1374 | } |
| 1375 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1376 | static DecodeStatus DecodeInsSize(MCInst &Inst, |
| 1377 | unsigned Insn, |
| 1378 | uint64_t Address, |
| 1379 | const void *Decoder) { |
| 1380 | // First we need to grab the pos(lsb) from MCInst. |
| 1381 | int Pos = Inst.getOperand(2).getImm(); |
| 1382 | int Size = (int) Insn - Pos + 1; |
| 1383 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<16>(Size))); |
| 1384 | return MCDisassembler::Success; |
| 1385 | } |
| 1386 | |
| 1387 | static DecodeStatus DecodeExtSize(MCInst &Inst, |
| 1388 | unsigned Insn, |
| 1389 | uint64_t Address, |
| 1390 | const void *Decoder) { |
| 1391 | int Size = (int) Insn + 1; |
| 1392 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<16>(Size))); |
| 1393 | return MCDisassembler::Success; |
| 1394 | } |
Daniel Sanders | b59e1a4 | 2014-05-15 10:45:58 +0000 | [diff] [blame] | 1395 | |
| 1396 | static DecodeStatus DecodeSimm19Lsl2(MCInst &Inst, unsigned Insn, |
| 1397 | uint64_t Address, const void *Decoder) { |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1398 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<19>(Insn) * 4)); |
Daniel Sanders | b59e1a4 | 2014-05-15 10:45:58 +0000 | [diff] [blame] | 1399 | return MCDisassembler::Success; |
| 1400 | } |
Zoran Jovanovic | 2855142 | 2014-06-09 09:49:51 +0000 | [diff] [blame] | 1401 | |
| 1402 | static DecodeStatus DecodeSimm18Lsl3(MCInst &Inst, unsigned Insn, |
| 1403 | uint64_t Address, const void *Decoder) { |
Alexey Samsonov | d37bab6 | 2014-09-02 17:49:16 +0000 | [diff] [blame] | 1404 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<18>(Insn) * 8)); |
Zoran Jovanovic | 2855142 | 2014-06-09 09:49:51 +0000 | [diff] [blame] | 1405 | return MCDisassembler::Success; |
| 1406 | } |