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