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