Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 1 | //===- MipsDisassembler.cpp - Disassembler for Mips -------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file is part of the Mips Disassembler. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "Mips.h" |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 15 | #include "MipsRegisterInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "MipsSubtarget.h" |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCContext.h" |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCDisassembler.h" |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCFixedLenDisassembler.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCInst.h" |
| 21 | #include "llvm/MC/MCSubtargetInfo.h" |
| 22 | #include "llvm/Support/MathExtras.h" |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 23 | #include "llvm/Support/MemoryObject.h" |
| 24 | #include "llvm/Support/TargetRegistry.h" |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 25 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 28 | #define DEBUG_TYPE "mips-disassembler" |
| 29 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 30 | typedef MCDisassembler::DecodeStatus DecodeStatus; |
| 31 | |
Benjamin Kramer | cb3e98c | 2012-05-01 14:34:24 +0000 | [diff] [blame] | 32 | namespace { |
| 33 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 34 | /// MipsDisassemblerBase - a disasembler class for Mips. |
| 35 | class MipsDisassemblerBase : public MCDisassembler { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 36 | public: |
| 37 | /// Constructor - Initializes the disassembler. |
| 38 | /// |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 39 | MipsDisassemblerBase(const MCSubtargetInfo &STI, MCContext &Ctx, |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 40 | bool bigEndian) : |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 41 | MCDisassembler(STI, Ctx), |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 42 | IsN64(STI.getFeatureBits() & Mips::FeatureN64), isBigEndian(bigEndian) {} |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 43 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 44 | virtual ~MipsDisassemblerBase() {} |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 45 | |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 46 | bool isN64() const { return IsN64; } |
| 47 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 48 | private: |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 49 | bool IsN64; |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 50 | protected: |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 51 | bool isBigEndian; |
| 52 | }; |
| 53 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 54 | /// MipsDisassembler - a disasembler class for Mips32. |
| 55 | class MipsDisassembler : public MipsDisassemblerBase { |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 56 | bool IsMicroMips; |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 57 | public: |
| 58 | /// Constructor - Initializes the disassembler. |
| 59 | /// |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 60 | MipsDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx, |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 61 | bool bigEndian) : |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 62 | MipsDisassemblerBase(STI, Ctx, bigEndian) { |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 63 | IsMicroMips = STI.getFeatureBits() & Mips::FeatureMicroMips; |
| 64 | } |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 65 | |
| 66 | /// getInstruction - See MCDisassembler. |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 67 | DecodeStatus getInstruction(MCInst &instr, |
| 68 | uint64_t &size, |
| 69 | const MemoryObject ®ion, |
| 70 | uint64_t address, |
| 71 | raw_ostream &vStream, |
| 72 | raw_ostream &cStream) const override; |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 75 | |
| 76 | /// Mips64Disassembler - a disasembler class for Mips64. |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 77 | class Mips64Disassembler : public MipsDisassemblerBase { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 78 | public: |
| 79 | /// Constructor - Initializes the disassembler. |
| 80 | /// |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 81 | Mips64Disassembler(const MCSubtargetInfo &STI, MCContext &Ctx, |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 82 | bool bigEndian) : |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 83 | MipsDisassemblerBase(STI, Ctx, bigEndian) {} |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 84 | |
| 85 | /// getInstruction - See MCDisassembler. |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 86 | DecodeStatus getInstruction(MCInst &instr, |
| 87 | uint64_t &size, |
| 88 | const MemoryObject ®ion, |
| 89 | uint64_t address, |
| 90 | raw_ostream &vStream, |
| 91 | raw_ostream &cStream) const override; |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
Benjamin Kramer | cb3e98c | 2012-05-01 14:34:24 +0000 | [diff] [blame] | 94 | } // end anonymous namespace |
| 95 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 96 | // Forward declare these because the autogenerated code will reference them. |
| 97 | // Definitions are further down. |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 98 | static DecodeStatus DecodeGPR64RegisterClass(MCInst &Inst, |
| 99 | unsigned RegNo, |
| 100 | uint64_t Address, |
| 101 | const void *Decoder); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 102 | |
Reed Kotler | ec8a549 | 2013-02-14 03:05:25 +0000 | [diff] [blame] | 103 | static DecodeStatus DecodeCPU16RegsRegisterClass(MCInst &Inst, |
| 104 | unsigned RegNo, |
| 105 | uint64_t Address, |
| 106 | const void *Decoder); |
| 107 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 108 | static DecodeStatus DecodeGPR32RegisterClass(MCInst &Inst, |
| 109 | unsigned RegNo, |
| 110 | uint64_t Address, |
| 111 | const void *Decoder); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 112 | |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 113 | static DecodeStatus DecodePtrRegisterClass(MCInst &Inst, |
| 114 | unsigned Insn, |
| 115 | uint64_t Address, |
| 116 | const void *Decoder); |
| 117 | |
Akira Hatanaka | 654655f | 2013-08-14 00:53:38 +0000 | [diff] [blame] | 118 | static DecodeStatus DecodeDSPRRegisterClass(MCInst &Inst, |
| 119 | unsigned RegNo, |
| 120 | uint64_t Address, |
| 121 | const void *Decoder); |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 122 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 123 | static DecodeStatus DecodeFGR64RegisterClass(MCInst &Inst, |
| 124 | unsigned RegNo, |
| 125 | uint64_t Address, |
| 126 | const void *Decoder); |
| 127 | |
| 128 | static DecodeStatus DecodeFGR32RegisterClass(MCInst &Inst, |
| 129 | unsigned RegNo, |
| 130 | uint64_t Address, |
| 131 | const void *Decoder); |
| 132 | |
Akira Hatanaka | 14e31a2 | 2013-08-20 22:58:56 +0000 | [diff] [blame] | 133 | static DecodeStatus DecodeFGRH32RegisterClass(MCInst &Inst, |
| 134 | unsigned RegNo, |
| 135 | uint64_t Address, |
| 136 | const void *Decoder); |
| 137 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 138 | static DecodeStatus DecodeCCRRegisterClass(MCInst &Inst, |
| 139 | unsigned RegNo, |
| 140 | uint64_t Address, |
| 141 | const void *Decoder); |
| 142 | |
Akira Hatanaka | 1fb1b8b | 2013-07-26 20:13:47 +0000 | [diff] [blame] | 143 | static DecodeStatus DecodeFCCRegisterClass(MCInst &Inst, |
| 144 | unsigned RegNo, |
| 145 | uint64_t Address, |
| 146 | const void *Decoder); |
| 147 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 148 | static DecodeStatus DecodeHWRegsRegisterClass(MCInst &Inst, |
| 149 | unsigned Insn, |
| 150 | uint64_t Address, |
| 151 | const void *Decoder); |
| 152 | |
| 153 | static DecodeStatus DecodeAFGR64RegisterClass(MCInst &Inst, |
| 154 | unsigned RegNo, |
| 155 | uint64_t Address, |
| 156 | const void *Decoder); |
| 157 | |
Akira Hatanaka | 00fcf2e | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 158 | static DecodeStatus DecodeACC64DSPRegisterClass(MCInst &Inst, |
| 159 | unsigned RegNo, |
| 160 | uint64_t Address, |
| 161 | const void *Decoder); |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 162 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 163 | static DecodeStatus DecodeHI32DSPRegisterClass(MCInst &Inst, |
| 164 | unsigned RegNo, |
| 165 | uint64_t Address, |
| 166 | const void *Decoder); |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 167 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 168 | static DecodeStatus DecodeLO32DSPRegisterClass(MCInst &Inst, |
| 169 | unsigned RegNo, |
| 170 | uint64_t Address, |
| 171 | const void *Decoder); |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 172 | |
Jack Carter | 3eb663b | 2013-09-26 00:09:46 +0000 | [diff] [blame] | 173 | static DecodeStatus DecodeMSA128BRegisterClass(MCInst &Inst, |
| 174 | unsigned RegNo, |
| 175 | uint64_t Address, |
| 176 | const void *Decoder); |
| 177 | |
Jack Carter | 5dc8ac9 | 2013-09-25 23:50:44 +0000 | [diff] [blame] | 178 | static DecodeStatus DecodeMSA128HRegisterClass(MCInst &Inst, |
| 179 | unsigned RegNo, |
| 180 | uint64_t Address, |
| 181 | const void *Decoder); |
| 182 | |
| 183 | static DecodeStatus DecodeMSA128WRegisterClass(MCInst &Inst, |
| 184 | unsigned RegNo, |
| 185 | uint64_t Address, |
| 186 | const void *Decoder); |
| 187 | |
| 188 | static DecodeStatus DecodeMSA128DRegisterClass(MCInst &Inst, |
| 189 | unsigned RegNo, |
| 190 | uint64_t Address, |
| 191 | const void *Decoder); |
| 192 | |
Matheus Almeida | a591fdc | 2013-10-21 12:26:50 +0000 | [diff] [blame] | 193 | static DecodeStatus DecodeMSACtrlRegisterClass(MCInst &Inst, |
| 194 | unsigned RegNo, |
| 195 | uint64_t Address, |
| 196 | const void *Decoder); |
| 197 | |
Daniel Sanders | 2a83d68 | 2014-05-21 12:56:39 +0000 | [diff] [blame] | 198 | static DecodeStatus DecodeCOP2RegisterClass(MCInst &Inst, |
| 199 | unsigned RegNo, |
| 200 | uint64_t Address, |
| 201 | const void *Decoder); |
| 202 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 203 | static DecodeStatus DecodeBranchTarget(MCInst &Inst, |
| 204 | unsigned Offset, |
| 205 | uint64_t Address, |
| 206 | const void *Decoder); |
| 207 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 208 | static DecodeStatus DecodeJumpTarget(MCInst &Inst, |
| 209 | unsigned Insn, |
| 210 | uint64_t Address, |
| 211 | const void *Decoder); |
| 212 | |
Zoran Jovanovic | 3c8869d | 2014-05-16 11:03:45 +0000 | [diff] [blame] | 213 | static DecodeStatus DecodeBranchTarget21(MCInst &Inst, |
| 214 | unsigned Offset, |
| 215 | uint64_t Address, |
| 216 | const void *Decoder); |
| 217 | |
| 218 | static DecodeStatus DecodeBranchTarget26(MCInst &Inst, |
| 219 | unsigned Offset, |
| 220 | uint64_t Address, |
| 221 | const void *Decoder); |
| 222 | |
Zoran Jovanovic | 8a80aa7 | 2013-11-04 14:53:22 +0000 | [diff] [blame] | 223 | // DecodeBranchTargetMM - Decode microMIPS branch offset, which is |
| 224 | // shifted left by 1 bit. |
| 225 | static DecodeStatus DecodeBranchTargetMM(MCInst &Inst, |
| 226 | unsigned Offset, |
| 227 | uint64_t Address, |
| 228 | const void *Decoder); |
| 229 | |
Zoran Jovanovic | 507e084 | 2013-10-29 16:38:59 +0000 | [diff] [blame] | 230 | // DecodeJumpTargetMM - Decode microMIPS jump target, which is |
| 231 | // shifted left by 1 bit. |
| 232 | static DecodeStatus DecodeJumpTargetMM(MCInst &Inst, |
| 233 | unsigned Insn, |
| 234 | uint64_t Address, |
| 235 | const void *Decoder); |
| 236 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 237 | static DecodeStatus DecodeMem(MCInst &Inst, |
| 238 | unsigned Insn, |
| 239 | uint64_t Address, |
| 240 | const void *Decoder); |
| 241 | |
Matheus Almeida | fe0bf9f | 2013-10-21 13:07:13 +0000 | [diff] [blame] | 242 | static DecodeStatus DecodeMSA128Mem(MCInst &Inst, unsigned Insn, |
| 243 | uint64_t Address, const void *Decoder); |
| 244 | |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 245 | static DecodeStatus DecodeMemMMImm12(MCInst &Inst, |
| 246 | unsigned Insn, |
| 247 | uint64_t Address, |
| 248 | const void *Decoder); |
| 249 | |
| 250 | static DecodeStatus DecodeMemMMImm16(MCInst &Inst, |
| 251 | unsigned Insn, |
| 252 | uint64_t Address, |
| 253 | const void *Decoder); |
| 254 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 255 | static DecodeStatus DecodeFMem(MCInst &Inst, unsigned Insn, |
| 256 | uint64_t Address, |
| 257 | const void *Decoder); |
| 258 | |
| 259 | static DecodeStatus DecodeSimm16(MCInst &Inst, |
| 260 | unsigned Insn, |
| 261 | uint64_t Address, |
| 262 | const void *Decoder); |
| 263 | |
Matheus Almeida | 779c593 | 2013-11-18 12:32:49 +0000 | [diff] [blame] | 264 | // Decode the immediate field of an LSA instruction which |
| 265 | // is off by one. |
| 266 | static DecodeStatus DecodeLSAImm(MCInst &Inst, |
| 267 | unsigned Insn, |
| 268 | uint64_t Address, |
| 269 | const void *Decoder); |
| 270 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 271 | static DecodeStatus DecodeInsSize(MCInst &Inst, |
| 272 | unsigned Insn, |
| 273 | uint64_t Address, |
| 274 | const void *Decoder); |
| 275 | |
| 276 | static DecodeStatus DecodeExtSize(MCInst &Inst, |
| 277 | unsigned Insn, |
| 278 | uint64_t Address, |
| 279 | const void *Decoder); |
| 280 | |
Daniel Sanders | b59e1a4 | 2014-05-15 10:45:58 +0000 | [diff] [blame] | 281 | static DecodeStatus DecodeSimm19Lsl2(MCInst &Inst, unsigned Insn, |
| 282 | uint64_t Address, const void *Decoder); |
| 283 | |
Daniel Sanders | b50ccf8 | 2014-04-01 10:35:28 +0000 | [diff] [blame] | 284 | /// INSVE_[BHWD] have an implicit operand that the generated decoder doesn't |
| 285 | /// handle. |
| 286 | template <typename InsnType> |
| 287 | static DecodeStatus DecodeINSVE_DF(MCInst &MI, InsnType insn, uint64_t Address, |
| 288 | const void *Decoder); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 289 | namespace llvm { |
| 290 | extern Target TheMipselTarget, TheMipsTarget, TheMips64Target, |
| 291 | TheMips64elTarget; |
| 292 | } |
| 293 | |
| 294 | static MCDisassembler *createMipsDisassembler( |
| 295 | const Target &T, |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 296 | const MCSubtargetInfo &STI, |
| 297 | MCContext &Ctx) { |
| 298 | return new MipsDisassembler(STI, Ctx, true); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | static MCDisassembler *createMipselDisassembler( |
| 302 | const Target &T, |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 303 | const MCSubtargetInfo &STI, |
| 304 | MCContext &Ctx) { |
| 305 | return new MipsDisassembler(STI, Ctx, false); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | static MCDisassembler *createMips64Disassembler( |
| 309 | const Target &T, |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 310 | const MCSubtargetInfo &STI, |
| 311 | MCContext &Ctx) { |
| 312 | return new Mips64Disassembler(STI, Ctx, true); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | static MCDisassembler *createMips64elDisassembler( |
| 316 | const Target &T, |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 317 | const MCSubtargetInfo &STI, |
| 318 | MCContext &Ctx) { |
| 319 | return new Mips64Disassembler(STI, Ctx, false); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | extern "C" void LLVMInitializeMipsDisassembler() { |
| 323 | // Register the disassembler. |
| 324 | TargetRegistry::RegisterMCDisassembler(TheMipsTarget, |
| 325 | createMipsDisassembler); |
| 326 | TargetRegistry::RegisterMCDisassembler(TheMipselTarget, |
| 327 | createMipselDisassembler); |
| 328 | TargetRegistry::RegisterMCDisassembler(TheMips64Target, |
| 329 | createMips64Disassembler); |
| 330 | TargetRegistry::RegisterMCDisassembler(TheMips64elTarget, |
| 331 | createMips64elDisassembler); |
| 332 | } |
| 333 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 334 | #include "MipsGenDisassemblerTables.inc" |
| 335 | |
Daniel Sanders | b50ccf8 | 2014-04-01 10:35:28 +0000 | [diff] [blame] | 336 | template <typename InsnType> |
| 337 | static DecodeStatus DecodeINSVE_DF(MCInst &MI, InsnType insn, uint64_t Address, |
| 338 | const void *Decoder) { |
| 339 | typedef DecodeStatus (*DecodeFN)(MCInst &, unsigned, uint64_t, const void *); |
| 340 | // The size of the n field depends on the element size |
| 341 | // The register class also depends on this. |
| 342 | InsnType tmp = fieldFromInstruction(insn, 17, 5); |
| 343 | unsigned NSize = 0; |
| 344 | DecodeFN RegDecoder = nullptr; |
| 345 | if ((tmp & 0x18) == 0x00) { // INSVE_B |
| 346 | NSize = 4; |
| 347 | RegDecoder = DecodeMSA128BRegisterClass; |
| 348 | } else if ((tmp & 0x1c) == 0x10) { // INSVE_H |
| 349 | NSize = 3; |
| 350 | RegDecoder = DecodeMSA128HRegisterClass; |
| 351 | } else if ((tmp & 0x1e) == 0x18) { // INSVE_W |
| 352 | NSize = 2; |
| 353 | RegDecoder = DecodeMSA128WRegisterClass; |
| 354 | } else if ((tmp & 0x1f) == 0x1c) { // INSVE_D |
| 355 | NSize = 1; |
| 356 | RegDecoder = DecodeMSA128DRegisterClass; |
| 357 | } else |
| 358 | llvm_unreachable("Invalid encoding"); |
| 359 | |
| 360 | assert(NSize != 0 && RegDecoder != nullptr); |
| 361 | |
| 362 | // $wd |
| 363 | tmp = fieldFromInstruction(insn, 6, 5); |
| 364 | if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler::Fail) |
| 365 | return MCDisassembler::Fail; |
| 366 | // $wd_in |
| 367 | if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler::Fail) |
| 368 | return MCDisassembler::Fail; |
| 369 | // $n |
| 370 | tmp = fieldFromInstruction(insn, 16, NSize); |
| 371 | MI.addOperand(MCOperand::CreateImm(tmp)); |
| 372 | // $ws |
| 373 | tmp = fieldFromInstruction(insn, 11, 5); |
| 374 | if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler::Fail) |
| 375 | return MCDisassembler::Fail; |
| 376 | // $n2 |
| 377 | MI.addOperand(MCOperand::CreateImm(0)); |
| 378 | |
| 379 | return MCDisassembler::Success; |
| 380 | } |
| 381 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 382 | /// readInstruction - read four bytes from the MemoryObject |
| 383 | /// and return 32 bit word sorted according to the given endianess |
| 384 | static DecodeStatus readInstruction32(const MemoryObject ®ion, |
| 385 | uint64_t address, |
| 386 | uint64_t &size, |
| 387 | uint32_t &insn, |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 388 | bool isBigEndian, |
| 389 | bool IsMicroMips) { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 390 | uint8_t Bytes[4]; |
| 391 | |
| 392 | // We want to read exactly 4 Bytes of data. |
Benjamin Kramer | 534d3a4 | 2013-05-24 10:54:58 +0000 | [diff] [blame] | 393 | if (region.readBytes(address, 4, Bytes) == -1) { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 394 | size = 0; |
| 395 | return MCDisassembler::Fail; |
| 396 | } |
| 397 | |
| 398 | if (isBigEndian) { |
| 399 | // Encoded as a big-endian 32-bit word in the stream. |
| 400 | insn = (Bytes[3] << 0) | |
| 401 | (Bytes[2] << 8) | |
| 402 | (Bytes[1] << 16) | |
| 403 | (Bytes[0] << 24); |
| 404 | } |
| 405 | else { |
| 406 | // Encoded as a small-endian 32-bit word in the stream. |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 407 | // Little-endian byte ordering: |
| 408 | // mips32r2: 4 | 3 | 2 | 1 |
| 409 | // microMIPS: 2 | 1 | 4 | 3 |
| 410 | if (IsMicroMips) { |
| 411 | insn = (Bytes[2] << 0) | |
| 412 | (Bytes[3] << 8) | |
| 413 | (Bytes[0] << 16) | |
| 414 | (Bytes[1] << 24); |
| 415 | } else { |
| 416 | insn = (Bytes[0] << 0) | |
| 417 | (Bytes[1] << 8) | |
| 418 | (Bytes[2] << 16) | |
| 419 | (Bytes[3] << 24); |
| 420 | } |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | return MCDisassembler::Success; |
| 424 | } |
| 425 | |
| 426 | DecodeStatus |
| 427 | MipsDisassembler::getInstruction(MCInst &instr, |
| 428 | uint64_t &Size, |
| 429 | const MemoryObject &Region, |
| 430 | uint64_t Address, |
| 431 | raw_ostream &vStream, |
| 432 | raw_ostream &cStream) const { |
| 433 | uint32_t Insn; |
| 434 | |
| 435 | DecodeStatus Result = readInstruction32(Region, Address, Size, |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 436 | Insn, isBigEndian, IsMicroMips); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 437 | if (Result == MCDisassembler::Fail) |
| 438 | return MCDisassembler::Fail; |
| 439 | |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 440 | if (IsMicroMips) { |
| 441 | // Calling the auto-generated decoder function. |
| 442 | Result = decodeInstruction(DecoderTableMicroMips32, instr, Insn, Address, |
| 443 | this, STI); |
| 444 | if (Result != MCDisassembler::Fail) { |
| 445 | Size = 4; |
| 446 | return Result; |
| 447 | } |
| 448 | return MCDisassembler::Fail; |
| 449 | } |
| 450 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 451 | // Calling the auto-generated decoder function. |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 452 | Result = decodeInstruction(DecoderTableMips32, instr, Insn, Address, |
| 453 | this, STI); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 454 | if (Result != MCDisassembler::Fail) { |
| 455 | Size = 4; |
| 456 | return Result; |
| 457 | } |
| 458 | |
| 459 | return MCDisassembler::Fail; |
| 460 | } |
| 461 | |
| 462 | DecodeStatus |
| 463 | Mips64Disassembler::getInstruction(MCInst &instr, |
| 464 | uint64_t &Size, |
| 465 | const MemoryObject &Region, |
| 466 | uint64_t Address, |
| 467 | raw_ostream &vStream, |
| 468 | raw_ostream &cStream) const { |
| 469 | uint32_t Insn; |
| 470 | |
| 471 | DecodeStatus Result = readInstruction32(Region, Address, Size, |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 472 | Insn, isBigEndian, false); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 473 | if (Result == MCDisassembler::Fail) |
| 474 | return MCDisassembler::Fail; |
| 475 | |
| 476 | // Calling the auto-generated decoder function. |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 477 | Result = decodeInstruction(DecoderTableMips6432, instr, Insn, Address, |
| 478 | this, STI); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 479 | if (Result != MCDisassembler::Fail) { |
| 480 | Size = 4; |
| 481 | return Result; |
| 482 | } |
| 483 | // If we fail to decode in Mips64 decoder space we can try in Mips32 |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 484 | Result = decodeInstruction(DecoderTableMips32, instr, Insn, Address, |
| 485 | this, STI); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 486 | if (Result != MCDisassembler::Fail) { |
| 487 | Size = 4; |
| 488 | return Result; |
| 489 | } |
| 490 | |
| 491 | return MCDisassembler::Fail; |
| 492 | } |
| 493 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 494 | static unsigned getReg(const void *D, unsigned RC, unsigned RegNo) { |
| 495 | const MipsDisassemblerBase *Dis = static_cast<const MipsDisassemblerBase*>(D); |
Lang Hames | a1bc0f5 | 2014-04-15 04:40:56 +0000 | [diff] [blame] | 496 | const MCRegisterInfo *RegInfo = Dis->getContext().getRegisterInfo(); |
| 497 | return *(RegInfo->getRegClass(RC).begin() + RegNo); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Reed Kotler | ec8a549 | 2013-02-14 03:05:25 +0000 | [diff] [blame] | 500 | static DecodeStatus DecodeCPU16RegsRegisterClass(MCInst &Inst, |
| 501 | unsigned RegNo, |
| 502 | uint64_t Address, |
| 503 | const void *Decoder) { |
| 504 | |
| 505 | return MCDisassembler::Fail; |
| 506 | |
| 507 | } |
| 508 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 509 | static DecodeStatus DecodeGPR64RegisterClass(MCInst &Inst, |
| 510 | unsigned RegNo, |
| 511 | uint64_t Address, |
| 512 | const void *Decoder) { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 513 | |
| 514 | if (RegNo > 31) |
| 515 | return MCDisassembler::Fail; |
| 516 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 517 | unsigned Reg = getReg(Decoder, Mips::GPR64RegClassID, RegNo); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 518 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 519 | return MCDisassembler::Success; |
| 520 | } |
| 521 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 522 | static DecodeStatus DecodeGPR32RegisterClass(MCInst &Inst, |
| 523 | unsigned RegNo, |
| 524 | uint64_t Address, |
| 525 | const void *Decoder) { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 526 | if (RegNo > 31) |
| 527 | return MCDisassembler::Fail; |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 528 | unsigned Reg = getReg(Decoder, Mips::GPR32RegClassID, RegNo); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 529 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 530 | return MCDisassembler::Success; |
| 531 | } |
| 532 | |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 533 | static DecodeStatus DecodePtrRegisterClass(MCInst &Inst, |
| 534 | unsigned RegNo, |
| 535 | uint64_t Address, |
| 536 | const void *Decoder) { |
| 537 | if (static_cast<const MipsDisassembler *>(Decoder)->isN64()) |
| 538 | return DecodeGPR64RegisterClass(Inst, RegNo, Address, Decoder); |
| 539 | |
| 540 | return DecodeGPR32RegisterClass(Inst, RegNo, Address, Decoder); |
| 541 | } |
| 542 | |
Akira Hatanaka | 654655f | 2013-08-14 00:53:38 +0000 | [diff] [blame] | 543 | static DecodeStatus DecodeDSPRRegisterClass(MCInst &Inst, |
| 544 | unsigned RegNo, |
| 545 | uint64_t Address, |
| 546 | const void *Decoder) { |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 547 | return DecodeGPR32RegisterClass(Inst, RegNo, Address, Decoder); |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 548 | } |
| 549 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 550 | static DecodeStatus DecodeFGR64RegisterClass(MCInst &Inst, |
| 551 | unsigned RegNo, |
| 552 | uint64_t Address, |
| 553 | const void *Decoder) { |
| 554 | if (RegNo > 31) |
| 555 | return MCDisassembler::Fail; |
| 556 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 557 | unsigned Reg = getReg(Decoder, Mips::FGR64RegClassID, RegNo); |
| 558 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 559 | return MCDisassembler::Success; |
| 560 | } |
| 561 | |
| 562 | static DecodeStatus DecodeFGR32RegisterClass(MCInst &Inst, |
| 563 | unsigned RegNo, |
| 564 | uint64_t Address, |
| 565 | const void *Decoder) { |
| 566 | if (RegNo > 31) |
| 567 | return MCDisassembler::Fail; |
| 568 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 569 | unsigned Reg = getReg(Decoder, Mips::FGR32RegClassID, RegNo); |
| 570 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 571 | return MCDisassembler::Success; |
| 572 | } |
| 573 | |
Akira Hatanaka | 14e31a2 | 2013-08-20 22:58:56 +0000 | [diff] [blame] | 574 | static DecodeStatus DecodeFGRH32RegisterClass(MCInst &Inst, |
| 575 | unsigned RegNo, |
| 576 | uint64_t Address, |
| 577 | const void *Decoder) { |
| 578 | if (RegNo > 31) |
| 579 | return MCDisassembler::Fail; |
| 580 | |
| 581 | unsigned Reg = getReg(Decoder, Mips::FGRH32RegClassID, RegNo); |
| 582 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 583 | return MCDisassembler::Success; |
| 584 | } |
| 585 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 586 | static DecodeStatus DecodeCCRRegisterClass(MCInst &Inst, |
| 587 | unsigned RegNo, |
| 588 | uint64_t Address, |
| 589 | const void *Decoder) { |
Chad Rosier | 253777f | 2013-06-26 22:23:32 +0000 | [diff] [blame] | 590 | if (RegNo > 31) |
| 591 | return MCDisassembler::Fail; |
| 592 | unsigned Reg = getReg(Decoder, Mips::CCRRegClassID, RegNo); |
| 593 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 594 | return MCDisassembler::Success; |
| 595 | } |
| 596 | |
Akira Hatanaka | 1fb1b8b | 2013-07-26 20:13:47 +0000 | [diff] [blame] | 597 | static DecodeStatus DecodeFCCRegisterClass(MCInst &Inst, |
| 598 | unsigned RegNo, |
| 599 | uint64_t Address, |
| 600 | const void *Decoder) { |
| 601 | if (RegNo > 7) |
| 602 | return MCDisassembler::Fail; |
| 603 | unsigned Reg = getReg(Decoder, Mips::FCCRegClassID, RegNo); |
| 604 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 605 | return MCDisassembler::Success; |
| 606 | } |
| 607 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 608 | static DecodeStatus DecodeMem(MCInst &Inst, |
| 609 | unsigned Insn, |
| 610 | uint64_t Address, |
| 611 | const void *Decoder) { |
| 612 | int Offset = SignExtend32<16>(Insn & 0xffff); |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 613 | unsigned Reg = fieldFromInstruction(Insn, 16, 5); |
| 614 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 615 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 616 | Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg); |
| 617 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 618 | |
| 619 | if(Inst.getOpcode() == Mips::SC){ |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 620 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 623 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 624 | Inst.addOperand(MCOperand::CreateReg(Base)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 625 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 626 | |
| 627 | return MCDisassembler::Success; |
| 628 | } |
| 629 | |
Matheus Almeida | fe0bf9f | 2013-10-21 13:07:13 +0000 | [diff] [blame] | 630 | static DecodeStatus DecodeMSA128Mem(MCInst &Inst, unsigned Insn, |
| 631 | uint64_t Address, const void *Decoder) { |
| 632 | int Offset = SignExtend32<10>(fieldFromInstruction(Insn, 16, 10)); |
| 633 | unsigned Reg = fieldFromInstruction(Insn, 6, 5); |
| 634 | unsigned Base = fieldFromInstruction(Insn, 11, 5); |
| 635 | |
| 636 | Reg = getReg(Decoder, Mips::MSA128BRegClassID, Reg); |
| 637 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 638 | |
| 639 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 640 | Inst.addOperand(MCOperand::CreateReg(Base)); |
Matheus Almeida | 6b59c44 | 2013-12-05 11:06:22 +0000 | [diff] [blame] | 641 | |
| 642 | // The immediate field of an LD/ST instruction is scaled which means it must |
| 643 | // be multiplied (when decoding) by the size (in bytes) of the instructions' |
| 644 | // data format. |
| 645 | // .b - 1 byte |
| 646 | // .h - 2 bytes |
| 647 | // .w - 4 bytes |
| 648 | // .d - 8 bytes |
| 649 | switch(Inst.getOpcode()) |
| 650 | { |
| 651 | default: |
| 652 | assert (0 && "Unexpected instruction"); |
| 653 | return MCDisassembler::Fail; |
| 654 | break; |
| 655 | case Mips::LD_B: |
| 656 | case Mips::ST_B: |
| 657 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 658 | break; |
| 659 | case Mips::LD_H: |
| 660 | case Mips::ST_H: |
| 661 | Inst.addOperand(MCOperand::CreateImm(Offset << 1)); |
| 662 | break; |
| 663 | case Mips::LD_W: |
| 664 | case Mips::ST_W: |
| 665 | Inst.addOperand(MCOperand::CreateImm(Offset << 2)); |
| 666 | break; |
| 667 | case Mips::LD_D: |
| 668 | case Mips::ST_D: |
| 669 | Inst.addOperand(MCOperand::CreateImm(Offset << 3)); |
| 670 | break; |
| 671 | } |
Matheus Almeida | fe0bf9f | 2013-10-21 13:07:13 +0000 | [diff] [blame] | 672 | |
| 673 | return MCDisassembler::Success; |
| 674 | } |
| 675 | |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 676 | static DecodeStatus DecodeMemMMImm12(MCInst &Inst, |
| 677 | unsigned Insn, |
| 678 | uint64_t Address, |
| 679 | const void *Decoder) { |
| 680 | int Offset = SignExtend32<12>(Insn & 0x0fff); |
| 681 | unsigned Reg = fieldFromInstruction(Insn, 21, 5); |
| 682 | unsigned Base = fieldFromInstruction(Insn, 16, 5); |
| 683 | |
| 684 | Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg); |
| 685 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 686 | |
Zoran Jovanovic | 285cc28 | 2014-02-28 18:22:56 +0000 | [diff] [blame] | 687 | if (Inst.getOpcode() == Mips::SC_MM) |
| 688 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 689 | |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 690 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 691 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 692 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 693 | |
| 694 | return MCDisassembler::Success; |
| 695 | } |
| 696 | |
| 697 | static DecodeStatus DecodeMemMMImm16(MCInst &Inst, |
| 698 | unsigned Insn, |
| 699 | uint64_t Address, |
| 700 | const void *Decoder) { |
| 701 | int Offset = SignExtend32<16>(Insn & 0xffff); |
| 702 | unsigned Reg = fieldFromInstruction(Insn, 21, 5); |
| 703 | unsigned Base = fieldFromInstruction(Insn, 16, 5); |
| 704 | |
| 705 | Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg); |
| 706 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 707 | |
| 708 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 709 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 710 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 711 | |
| 712 | return MCDisassembler::Success; |
| 713 | } |
| 714 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 715 | static DecodeStatus DecodeFMem(MCInst &Inst, |
| 716 | unsigned Insn, |
| 717 | uint64_t Address, |
| 718 | const void *Decoder) { |
| 719 | int Offset = SignExtend32<16>(Insn & 0xffff); |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 720 | unsigned Reg = fieldFromInstruction(Insn, 16, 5); |
| 721 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 722 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 723 | Reg = getReg(Decoder, Mips::FGR64RegClassID, Reg); |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 724 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 725 | |
| 726 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 727 | Inst.addOperand(MCOperand::CreateReg(Base)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 728 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 729 | |
| 730 | return MCDisassembler::Success; |
| 731 | } |
| 732 | |
| 733 | |
| 734 | static DecodeStatus DecodeHWRegsRegisterClass(MCInst &Inst, |
| 735 | unsigned RegNo, |
| 736 | uint64_t Address, |
| 737 | const void *Decoder) { |
| 738 | // Currently only hardware register 29 is supported. |
| 739 | if (RegNo != 29) |
| 740 | return MCDisassembler::Fail; |
| 741 | Inst.addOperand(MCOperand::CreateReg(Mips::HWR29)); |
| 742 | return MCDisassembler::Success; |
| 743 | } |
| 744 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 745 | static DecodeStatus DecodeAFGR64RegisterClass(MCInst &Inst, |
| 746 | unsigned RegNo, |
| 747 | uint64_t Address, |
| 748 | const void *Decoder) { |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 749 | if (RegNo > 30 || RegNo %2) |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 750 | return MCDisassembler::Fail; |
| 751 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 752 | ; |
| 753 | unsigned Reg = getReg(Decoder, Mips::AFGR64RegClassID, RegNo /2); |
| 754 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 755 | return MCDisassembler::Success; |
| 756 | } |
| 757 | |
Akira Hatanaka | 00fcf2e | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 758 | static DecodeStatus DecodeACC64DSPRegisterClass(MCInst &Inst, |
| 759 | unsigned RegNo, |
| 760 | uint64_t Address, |
| 761 | const void *Decoder) { |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 762 | if (RegNo >= 4) |
| 763 | return MCDisassembler::Fail; |
| 764 | |
Akira Hatanaka | 00fcf2e | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 765 | unsigned Reg = getReg(Decoder, Mips::ACC64DSPRegClassID, RegNo); |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 766 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 767 | return MCDisassembler::Success; |
| 768 | } |
| 769 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 770 | static DecodeStatus DecodeHI32DSPRegisterClass(MCInst &Inst, |
| 771 | unsigned RegNo, |
| 772 | uint64_t Address, |
| 773 | const void *Decoder) { |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 774 | if (RegNo >= 4) |
| 775 | return MCDisassembler::Fail; |
| 776 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 777 | unsigned Reg = getReg(Decoder, Mips::HI32DSPRegClassID, RegNo); |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 778 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 779 | return MCDisassembler::Success; |
| 780 | } |
| 781 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 782 | static DecodeStatus DecodeLO32DSPRegisterClass(MCInst &Inst, |
| 783 | unsigned RegNo, |
| 784 | uint64_t Address, |
| 785 | const void *Decoder) { |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 786 | if (RegNo >= 4) |
| 787 | return MCDisassembler::Fail; |
| 788 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 789 | unsigned Reg = getReg(Decoder, Mips::LO32DSPRegClassID, RegNo); |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 790 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 791 | return MCDisassembler::Success; |
| 792 | } |
| 793 | |
Jack Carter | 3eb663b | 2013-09-26 00:09:46 +0000 | [diff] [blame] | 794 | static DecodeStatus DecodeMSA128BRegisterClass(MCInst &Inst, |
| 795 | unsigned RegNo, |
| 796 | uint64_t Address, |
| 797 | const void *Decoder) { |
| 798 | if (RegNo > 31) |
| 799 | return MCDisassembler::Fail; |
| 800 | |
| 801 | unsigned Reg = getReg(Decoder, Mips::MSA128BRegClassID, RegNo); |
| 802 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 803 | return MCDisassembler::Success; |
| 804 | } |
| 805 | |
Jack Carter | 5dc8ac9 | 2013-09-25 23:50:44 +0000 | [diff] [blame] | 806 | static DecodeStatus DecodeMSA128HRegisterClass(MCInst &Inst, |
| 807 | unsigned RegNo, |
| 808 | uint64_t Address, |
| 809 | const void *Decoder) { |
| 810 | if (RegNo > 31) |
| 811 | return MCDisassembler::Fail; |
| 812 | |
| 813 | unsigned Reg = getReg(Decoder, Mips::MSA128HRegClassID, RegNo); |
| 814 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 815 | return MCDisassembler::Success; |
| 816 | } |
| 817 | |
| 818 | static DecodeStatus DecodeMSA128WRegisterClass(MCInst &Inst, |
| 819 | unsigned RegNo, |
| 820 | uint64_t Address, |
| 821 | const void *Decoder) { |
| 822 | if (RegNo > 31) |
| 823 | return MCDisassembler::Fail; |
| 824 | |
| 825 | unsigned Reg = getReg(Decoder, Mips::MSA128WRegClassID, RegNo); |
| 826 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 827 | return MCDisassembler::Success; |
| 828 | } |
| 829 | |
| 830 | static DecodeStatus DecodeMSA128DRegisterClass(MCInst &Inst, |
| 831 | unsigned RegNo, |
| 832 | uint64_t Address, |
| 833 | const void *Decoder) { |
| 834 | if (RegNo > 31) |
| 835 | return MCDisassembler::Fail; |
| 836 | |
| 837 | unsigned Reg = getReg(Decoder, Mips::MSA128DRegClassID, RegNo); |
| 838 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 839 | return MCDisassembler::Success; |
| 840 | } |
| 841 | |
Matheus Almeida | a591fdc | 2013-10-21 12:26:50 +0000 | [diff] [blame] | 842 | static DecodeStatus DecodeMSACtrlRegisterClass(MCInst &Inst, |
| 843 | unsigned RegNo, |
| 844 | uint64_t Address, |
| 845 | const void *Decoder) { |
| 846 | if (RegNo > 7) |
| 847 | return MCDisassembler::Fail; |
| 848 | |
| 849 | unsigned Reg = getReg(Decoder, Mips::MSACtrlRegClassID, RegNo); |
| 850 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 851 | return MCDisassembler::Success; |
| 852 | } |
| 853 | |
Daniel Sanders | 2a83d68 | 2014-05-21 12:56:39 +0000 | [diff] [blame] | 854 | static DecodeStatus DecodeCOP2RegisterClass(MCInst &Inst, |
| 855 | unsigned RegNo, |
| 856 | uint64_t Address, |
| 857 | const void *Decoder) { |
| 858 | if (RegNo > 31) |
| 859 | return MCDisassembler::Fail; |
| 860 | |
| 861 | unsigned Reg = getReg(Decoder, Mips::COP2RegClassID, RegNo); |
| 862 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 863 | return MCDisassembler::Success; |
| 864 | } |
| 865 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 866 | static DecodeStatus DecodeBranchTarget(MCInst &Inst, |
| 867 | unsigned Offset, |
| 868 | uint64_t Address, |
| 869 | const void *Decoder) { |
| 870 | unsigned BranchOffset = Offset & 0xffff; |
| 871 | BranchOffset = SignExtend32<18>(BranchOffset << 2) + 4; |
| 872 | Inst.addOperand(MCOperand::CreateImm(BranchOffset)); |
| 873 | return MCDisassembler::Success; |
| 874 | } |
| 875 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 876 | static DecodeStatus DecodeJumpTarget(MCInst &Inst, |
| 877 | unsigned Insn, |
| 878 | uint64_t Address, |
| 879 | const void *Decoder) { |
| 880 | |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 881 | unsigned JumpOffset = fieldFromInstruction(Insn, 0, 26) << 2; |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 882 | Inst.addOperand(MCOperand::CreateImm(JumpOffset)); |
| 883 | return MCDisassembler::Success; |
| 884 | } |
| 885 | |
Zoran Jovanovic | 3c8869d | 2014-05-16 11:03:45 +0000 | [diff] [blame] | 886 | static DecodeStatus DecodeBranchTarget21(MCInst &Inst, |
| 887 | unsigned Offset, |
| 888 | uint64_t Address, |
| 889 | const void *Decoder) { |
| 890 | int32_t BranchOffset = SignExtend32<21>(Offset) << 2; |
| 891 | |
| 892 | Inst.addOperand(MCOperand::CreateImm(BranchOffset)); |
| 893 | return MCDisassembler::Success; |
| 894 | } |
| 895 | |
| 896 | static DecodeStatus DecodeBranchTarget26(MCInst &Inst, |
| 897 | unsigned Offset, |
| 898 | uint64_t Address, |
| 899 | const void *Decoder) { |
| 900 | int32_t BranchOffset = SignExtend32<26>(Offset) << 2; |
| 901 | |
| 902 | Inst.addOperand(MCOperand::CreateImm(BranchOffset)); |
| 903 | return MCDisassembler::Success; |
| 904 | } |
| 905 | |
Zoran Jovanovic | 8a80aa7 | 2013-11-04 14:53:22 +0000 | [diff] [blame] | 906 | static DecodeStatus DecodeBranchTargetMM(MCInst &Inst, |
| 907 | unsigned Offset, |
| 908 | uint64_t Address, |
| 909 | const void *Decoder) { |
| 910 | unsigned BranchOffset = Offset & 0xffff; |
| 911 | BranchOffset = SignExtend32<18>(BranchOffset << 1); |
| 912 | Inst.addOperand(MCOperand::CreateImm(BranchOffset)); |
| 913 | return MCDisassembler::Success; |
| 914 | } |
| 915 | |
Zoran Jovanovic | 507e084 | 2013-10-29 16:38:59 +0000 | [diff] [blame] | 916 | static DecodeStatus DecodeJumpTargetMM(MCInst &Inst, |
| 917 | unsigned Insn, |
| 918 | uint64_t Address, |
| 919 | const void *Decoder) { |
| 920 | unsigned JumpOffset = fieldFromInstruction(Insn, 0, 26) << 1; |
| 921 | Inst.addOperand(MCOperand::CreateImm(JumpOffset)); |
| 922 | return MCDisassembler::Success; |
| 923 | } |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 924 | |
| 925 | static DecodeStatus DecodeSimm16(MCInst &Inst, |
| 926 | unsigned Insn, |
| 927 | uint64_t Address, |
| 928 | const void *Decoder) { |
| 929 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<16>(Insn))); |
| 930 | return MCDisassembler::Success; |
| 931 | } |
| 932 | |
Matheus Almeida | 779c593 | 2013-11-18 12:32:49 +0000 | [diff] [blame] | 933 | static DecodeStatus DecodeLSAImm(MCInst &Inst, |
| 934 | unsigned Insn, |
| 935 | uint64_t Address, |
| 936 | const void *Decoder) { |
| 937 | // We add one to the immediate field as it was encoded as 'imm - 1'. |
| 938 | Inst.addOperand(MCOperand::CreateImm(Insn + 1)); |
| 939 | return MCDisassembler::Success; |
| 940 | } |
| 941 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 942 | static DecodeStatus DecodeInsSize(MCInst &Inst, |
| 943 | unsigned Insn, |
| 944 | uint64_t Address, |
| 945 | const void *Decoder) { |
| 946 | // First we need to grab the pos(lsb) from MCInst. |
| 947 | int Pos = Inst.getOperand(2).getImm(); |
| 948 | int Size = (int) Insn - Pos + 1; |
| 949 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<16>(Size))); |
| 950 | return MCDisassembler::Success; |
| 951 | } |
| 952 | |
| 953 | static DecodeStatus DecodeExtSize(MCInst &Inst, |
| 954 | unsigned Insn, |
| 955 | uint64_t Address, |
| 956 | const void *Decoder) { |
| 957 | int Size = (int) Insn + 1; |
| 958 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<16>(Size))); |
| 959 | return MCDisassembler::Success; |
| 960 | } |
Daniel Sanders | b59e1a4 | 2014-05-15 10:45:58 +0000 | [diff] [blame] | 961 | |
| 962 | static DecodeStatus DecodeSimm19Lsl2(MCInst &Inst, unsigned Insn, |
| 963 | uint64_t Address, const void *Decoder) { |
| 964 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<19>(Insn) << 2)); |
| 965 | return MCDisassembler::Success; |
| 966 | } |