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