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