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