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