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" |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCDisassembler.h" |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCFixedLenDisassembler.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCInst.h" |
| 20 | #include "llvm/MC/MCSubtargetInfo.h" |
| 21 | #include "llvm/Support/MathExtras.h" |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 22 | #include "llvm/Support/MemoryObject.h" |
| 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 | |
| 27 | typedef MCDisassembler::DecodeStatus DecodeStatus; |
| 28 | |
Benjamin Kramer | cb3e98c | 2012-05-01 14:34:24 +0000 | [diff] [blame] | 29 | namespace { |
| 30 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 31 | /// MipsDisassemblerBase - a disasembler class for Mips. |
| 32 | class MipsDisassemblerBase : public MCDisassembler { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 33 | public: |
| 34 | /// Constructor - Initializes the disassembler. |
| 35 | /// |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 36 | MipsDisassemblerBase(const MCSubtargetInfo &STI, const MCRegisterInfo *Info, |
| 37 | bool bigEndian) : |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 38 | MCDisassembler(STI), RegInfo(Info), |
| 39 | IsN64(STI.getFeatureBits() & Mips::FeatureN64), isBigEndian(bigEndian) {} |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 40 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 41 | virtual ~MipsDisassemblerBase() {} |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 42 | |
Benjamin Kramer | dcfd5b5 | 2013-08-03 22:16:16 +0000 | [diff] [blame] | 43 | const MCRegisterInfo *getRegInfo() const { return RegInfo.get(); } |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 44 | |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 45 | bool isN64() const { return IsN64; } |
| 46 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 47 | private: |
Benjamin Kramer | dcfd5b5 | 2013-08-03 22:16:16 +0000 | [diff] [blame] | 48 | OwningPtr<const MCRegisterInfo> RegInfo; |
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 | /// |
| 60 | MipsDisassembler(const MCSubtargetInfo &STI, const MCRegisterInfo *Info, |
| 61 | bool bigEndian) : |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 62 | MipsDisassemblerBase(STI, Info, bigEndian) { |
| 63 | IsMicroMips = STI.getFeatureBits() & Mips::FeatureMicroMips; |
| 64 | } |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 65 | |
| 66 | /// getInstruction - See MCDisassembler. |
| 67 | virtual 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; |
| 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 | /// |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 81 | Mips64Disassembler(const MCSubtargetInfo &STI, const MCRegisterInfo *Info, |
| 82 | bool bigEndian) : |
| 83 | MipsDisassemblerBase(STI, Info, bigEndian) {} |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 84 | |
| 85 | /// getInstruction - See MCDisassembler. |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 86 | virtual 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; |
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 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 198 | static DecodeStatus DecodeBranchTarget(MCInst &Inst, |
| 199 | unsigned Offset, |
| 200 | uint64_t Address, |
| 201 | const void *Decoder); |
| 202 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 203 | static DecodeStatus DecodeJumpTarget(MCInst &Inst, |
| 204 | unsigned Insn, |
| 205 | uint64_t Address, |
| 206 | const void *Decoder); |
| 207 | |
Zoran Jovanovic | 8a80aa7 | 2013-11-04 14:53:22 +0000 | [diff] [blame] | 208 | // DecodeBranchTargetMM - Decode microMIPS branch offset, which is |
| 209 | // shifted left by 1 bit. |
| 210 | static DecodeStatus DecodeBranchTargetMM(MCInst &Inst, |
| 211 | unsigned Offset, |
| 212 | uint64_t Address, |
| 213 | const void *Decoder); |
| 214 | |
Zoran Jovanovic | 507e084 | 2013-10-29 16:38:59 +0000 | [diff] [blame] | 215 | // DecodeJumpTargetMM - Decode microMIPS jump target, which is |
| 216 | // shifted left by 1 bit. |
| 217 | static DecodeStatus DecodeJumpTargetMM(MCInst &Inst, |
| 218 | unsigned Insn, |
| 219 | uint64_t Address, |
| 220 | const void *Decoder); |
| 221 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 222 | static DecodeStatus DecodeMem(MCInst &Inst, |
| 223 | unsigned Insn, |
| 224 | uint64_t Address, |
| 225 | const void *Decoder); |
| 226 | |
Matheus Almeida | fe0bf9f | 2013-10-21 13:07:13 +0000 | [diff] [blame] | 227 | static DecodeStatus DecodeMSA128Mem(MCInst &Inst, unsigned Insn, |
| 228 | uint64_t Address, const void *Decoder); |
| 229 | |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 230 | static DecodeStatus DecodeMemMMImm12(MCInst &Inst, |
| 231 | unsigned Insn, |
| 232 | uint64_t Address, |
| 233 | const void *Decoder); |
| 234 | |
| 235 | static DecodeStatus DecodeMemMMImm16(MCInst &Inst, |
| 236 | unsigned Insn, |
| 237 | uint64_t Address, |
| 238 | const void *Decoder); |
| 239 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 240 | static DecodeStatus DecodeFMem(MCInst &Inst, unsigned Insn, |
| 241 | uint64_t Address, |
| 242 | const void *Decoder); |
| 243 | |
| 244 | static DecodeStatus DecodeSimm16(MCInst &Inst, |
| 245 | unsigned Insn, |
| 246 | uint64_t Address, |
| 247 | const void *Decoder); |
| 248 | |
Matheus Almeida | 779c593 | 2013-11-18 12:32:49 +0000 | [diff] [blame^] | 249 | // Decode the immediate field of an LSA instruction which |
| 250 | // is off by one. |
| 251 | static DecodeStatus DecodeLSAImm(MCInst &Inst, |
| 252 | unsigned Insn, |
| 253 | uint64_t Address, |
| 254 | const void *Decoder); |
| 255 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 256 | static DecodeStatus DecodeInsSize(MCInst &Inst, |
| 257 | unsigned Insn, |
| 258 | uint64_t Address, |
| 259 | const void *Decoder); |
| 260 | |
| 261 | static DecodeStatus DecodeExtSize(MCInst &Inst, |
| 262 | unsigned Insn, |
| 263 | uint64_t Address, |
| 264 | const void *Decoder); |
| 265 | |
| 266 | namespace llvm { |
| 267 | extern Target TheMipselTarget, TheMipsTarget, TheMips64Target, |
| 268 | TheMips64elTarget; |
| 269 | } |
| 270 | |
| 271 | static MCDisassembler *createMipsDisassembler( |
| 272 | const Target &T, |
| 273 | const MCSubtargetInfo &STI) { |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 274 | return new MipsDisassembler(STI, T.createMCRegInfo(""), true); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | static MCDisassembler *createMipselDisassembler( |
| 278 | const Target &T, |
| 279 | const MCSubtargetInfo &STI) { |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 280 | return new MipsDisassembler(STI, T.createMCRegInfo(""), false); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | static MCDisassembler *createMips64Disassembler( |
| 284 | const Target &T, |
| 285 | const MCSubtargetInfo &STI) { |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 286 | return new Mips64Disassembler(STI, T.createMCRegInfo(""), true); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | static MCDisassembler *createMips64elDisassembler( |
| 290 | const Target &T, |
| 291 | const MCSubtargetInfo &STI) { |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 292 | return new Mips64Disassembler(STI, T.createMCRegInfo(""), false); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | extern "C" void LLVMInitializeMipsDisassembler() { |
| 296 | // Register the disassembler. |
| 297 | TargetRegistry::RegisterMCDisassembler(TheMipsTarget, |
| 298 | createMipsDisassembler); |
| 299 | TargetRegistry::RegisterMCDisassembler(TheMipselTarget, |
| 300 | createMipselDisassembler); |
| 301 | TargetRegistry::RegisterMCDisassembler(TheMips64Target, |
| 302 | createMips64Disassembler); |
| 303 | TargetRegistry::RegisterMCDisassembler(TheMips64elTarget, |
| 304 | createMips64elDisassembler); |
| 305 | } |
| 306 | |
| 307 | |
| 308 | #include "MipsGenDisassemblerTables.inc" |
| 309 | |
| 310 | /// readInstruction - read four bytes from the MemoryObject |
| 311 | /// and return 32 bit word sorted according to the given endianess |
| 312 | static DecodeStatus readInstruction32(const MemoryObject ®ion, |
| 313 | uint64_t address, |
| 314 | uint64_t &size, |
| 315 | uint32_t &insn, |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 316 | bool isBigEndian, |
| 317 | bool IsMicroMips) { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 318 | uint8_t Bytes[4]; |
| 319 | |
| 320 | // We want to read exactly 4 Bytes of data. |
Benjamin Kramer | 534d3a4 | 2013-05-24 10:54:58 +0000 | [diff] [blame] | 321 | if (region.readBytes(address, 4, Bytes) == -1) { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 322 | size = 0; |
| 323 | return MCDisassembler::Fail; |
| 324 | } |
| 325 | |
| 326 | if (isBigEndian) { |
| 327 | // Encoded as a big-endian 32-bit word in the stream. |
| 328 | insn = (Bytes[3] << 0) | |
| 329 | (Bytes[2] << 8) | |
| 330 | (Bytes[1] << 16) | |
| 331 | (Bytes[0] << 24); |
| 332 | } |
| 333 | else { |
| 334 | // Encoded as a small-endian 32-bit word in the stream. |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 335 | // Little-endian byte ordering: |
| 336 | // mips32r2: 4 | 3 | 2 | 1 |
| 337 | // microMIPS: 2 | 1 | 4 | 3 |
| 338 | if (IsMicroMips) { |
| 339 | insn = (Bytes[2] << 0) | |
| 340 | (Bytes[3] << 8) | |
| 341 | (Bytes[0] << 16) | |
| 342 | (Bytes[1] << 24); |
| 343 | } else { |
| 344 | insn = (Bytes[0] << 0) | |
| 345 | (Bytes[1] << 8) | |
| 346 | (Bytes[2] << 16) | |
| 347 | (Bytes[3] << 24); |
| 348 | } |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | return MCDisassembler::Success; |
| 352 | } |
| 353 | |
| 354 | DecodeStatus |
| 355 | MipsDisassembler::getInstruction(MCInst &instr, |
| 356 | uint64_t &Size, |
| 357 | const MemoryObject &Region, |
| 358 | uint64_t Address, |
| 359 | raw_ostream &vStream, |
| 360 | raw_ostream &cStream) const { |
| 361 | uint32_t Insn; |
| 362 | |
| 363 | DecodeStatus Result = readInstruction32(Region, Address, Size, |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 364 | Insn, isBigEndian, IsMicroMips); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 365 | if (Result == MCDisassembler::Fail) |
| 366 | return MCDisassembler::Fail; |
| 367 | |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 368 | if (IsMicroMips) { |
| 369 | // Calling the auto-generated decoder function. |
| 370 | Result = decodeInstruction(DecoderTableMicroMips32, instr, Insn, Address, |
| 371 | this, STI); |
| 372 | if (Result != MCDisassembler::Fail) { |
| 373 | Size = 4; |
| 374 | return Result; |
| 375 | } |
| 376 | return MCDisassembler::Fail; |
| 377 | } |
| 378 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 379 | // Calling the auto-generated decoder function. |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 380 | Result = decodeInstruction(DecoderTableMips32, instr, Insn, Address, |
| 381 | this, STI); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 382 | if (Result != MCDisassembler::Fail) { |
| 383 | Size = 4; |
| 384 | return Result; |
| 385 | } |
| 386 | |
| 387 | return MCDisassembler::Fail; |
| 388 | } |
| 389 | |
| 390 | DecodeStatus |
| 391 | Mips64Disassembler::getInstruction(MCInst &instr, |
| 392 | uint64_t &Size, |
| 393 | const MemoryObject &Region, |
| 394 | uint64_t Address, |
| 395 | raw_ostream &vStream, |
| 396 | raw_ostream &cStream) const { |
| 397 | uint32_t Insn; |
| 398 | |
| 399 | DecodeStatus Result = readInstruction32(Region, Address, Size, |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 400 | Insn, isBigEndian, false); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 401 | if (Result == MCDisassembler::Fail) |
| 402 | return MCDisassembler::Fail; |
| 403 | |
| 404 | // Calling the auto-generated decoder function. |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 405 | Result = decodeInstruction(DecoderTableMips6432, instr, Insn, Address, |
| 406 | this, STI); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 407 | if (Result != MCDisassembler::Fail) { |
| 408 | Size = 4; |
| 409 | return Result; |
| 410 | } |
| 411 | // 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] | 412 | Result = decodeInstruction(DecoderTableMips32, instr, Insn, Address, |
| 413 | this, STI); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 414 | if (Result != MCDisassembler::Fail) { |
| 415 | Size = 4; |
| 416 | return Result; |
| 417 | } |
| 418 | |
| 419 | return MCDisassembler::Fail; |
| 420 | } |
| 421 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 422 | static unsigned getReg(const void *D, unsigned RC, unsigned RegNo) { |
| 423 | const MipsDisassemblerBase *Dis = static_cast<const MipsDisassemblerBase*>(D); |
| 424 | return *(Dis->getRegInfo()->getRegClass(RC).begin() + RegNo); |
| 425 | } |
| 426 | |
Reed Kotler | ec8a549 | 2013-02-14 03:05:25 +0000 | [diff] [blame] | 427 | static DecodeStatus DecodeCPU16RegsRegisterClass(MCInst &Inst, |
| 428 | unsigned RegNo, |
| 429 | uint64_t Address, |
| 430 | const void *Decoder) { |
| 431 | |
| 432 | return MCDisassembler::Fail; |
| 433 | |
| 434 | } |
| 435 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 436 | static DecodeStatus DecodeGPR64RegisterClass(MCInst &Inst, |
| 437 | unsigned RegNo, |
| 438 | uint64_t Address, |
| 439 | const void *Decoder) { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 440 | |
| 441 | if (RegNo > 31) |
| 442 | return MCDisassembler::Fail; |
| 443 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 444 | unsigned Reg = getReg(Decoder, Mips::GPR64RegClassID, RegNo); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 445 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 446 | return MCDisassembler::Success; |
| 447 | } |
| 448 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 449 | static DecodeStatus DecodeGPR32RegisterClass(MCInst &Inst, |
| 450 | unsigned RegNo, |
| 451 | uint64_t Address, |
| 452 | const void *Decoder) { |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 453 | if (RegNo > 31) |
| 454 | return MCDisassembler::Fail; |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 455 | unsigned Reg = getReg(Decoder, Mips::GPR32RegClassID, RegNo); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 456 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 457 | return MCDisassembler::Success; |
| 458 | } |
| 459 | |
Akira Hatanaka | 9bfa2e2 | 2013-08-28 00:55:15 +0000 | [diff] [blame] | 460 | static DecodeStatus DecodePtrRegisterClass(MCInst &Inst, |
| 461 | unsigned RegNo, |
| 462 | uint64_t Address, |
| 463 | const void *Decoder) { |
| 464 | if (static_cast<const MipsDisassembler *>(Decoder)->isN64()) |
| 465 | return DecodeGPR64RegisterClass(Inst, RegNo, Address, Decoder); |
| 466 | |
| 467 | return DecodeGPR32RegisterClass(Inst, RegNo, Address, Decoder); |
| 468 | } |
| 469 | |
Akira Hatanaka | 654655f | 2013-08-14 00:53:38 +0000 | [diff] [blame] | 470 | static DecodeStatus DecodeDSPRRegisterClass(MCInst &Inst, |
| 471 | unsigned RegNo, |
| 472 | uint64_t Address, |
| 473 | const void *Decoder) { |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 474 | return DecodeGPR32RegisterClass(Inst, RegNo, Address, Decoder); |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 475 | } |
| 476 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 477 | static DecodeStatus DecodeFGR64RegisterClass(MCInst &Inst, |
| 478 | unsigned RegNo, |
| 479 | uint64_t Address, |
| 480 | const void *Decoder) { |
| 481 | if (RegNo > 31) |
| 482 | return MCDisassembler::Fail; |
| 483 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 484 | unsigned Reg = getReg(Decoder, Mips::FGR64RegClassID, RegNo); |
| 485 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 486 | return MCDisassembler::Success; |
| 487 | } |
| 488 | |
| 489 | static DecodeStatus DecodeFGR32RegisterClass(MCInst &Inst, |
| 490 | unsigned RegNo, |
| 491 | uint64_t Address, |
| 492 | const void *Decoder) { |
| 493 | if (RegNo > 31) |
| 494 | return MCDisassembler::Fail; |
| 495 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 496 | unsigned Reg = getReg(Decoder, Mips::FGR32RegClassID, RegNo); |
| 497 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 498 | return MCDisassembler::Success; |
| 499 | } |
| 500 | |
Akira Hatanaka | 14e31a2 | 2013-08-20 22:58:56 +0000 | [diff] [blame] | 501 | static DecodeStatus DecodeFGRH32RegisterClass(MCInst &Inst, |
| 502 | unsigned RegNo, |
| 503 | uint64_t Address, |
| 504 | const void *Decoder) { |
| 505 | if (RegNo > 31) |
| 506 | return MCDisassembler::Fail; |
| 507 | |
| 508 | unsigned Reg = getReg(Decoder, Mips::FGRH32RegClassID, RegNo); |
| 509 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 510 | return MCDisassembler::Success; |
| 511 | } |
| 512 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 513 | static DecodeStatus DecodeCCRRegisterClass(MCInst &Inst, |
| 514 | unsigned RegNo, |
| 515 | uint64_t Address, |
| 516 | const void *Decoder) { |
Chad Rosier | 253777f | 2013-06-26 22:23:32 +0000 | [diff] [blame] | 517 | if (RegNo > 31) |
| 518 | return MCDisassembler::Fail; |
| 519 | unsigned Reg = getReg(Decoder, Mips::CCRRegClassID, RegNo); |
| 520 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 521 | return MCDisassembler::Success; |
| 522 | } |
| 523 | |
Akira Hatanaka | 1fb1b8b | 2013-07-26 20:13:47 +0000 | [diff] [blame] | 524 | static DecodeStatus DecodeFCCRegisterClass(MCInst &Inst, |
| 525 | unsigned RegNo, |
| 526 | uint64_t Address, |
| 527 | const void *Decoder) { |
| 528 | if (RegNo > 7) |
| 529 | return MCDisassembler::Fail; |
| 530 | unsigned Reg = getReg(Decoder, Mips::FCCRegClassID, RegNo); |
| 531 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 532 | return MCDisassembler::Success; |
| 533 | } |
| 534 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 535 | static DecodeStatus DecodeMem(MCInst &Inst, |
| 536 | unsigned Insn, |
| 537 | uint64_t Address, |
| 538 | const void *Decoder) { |
| 539 | int Offset = SignExtend32<16>(Insn & 0xffff); |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 540 | unsigned Reg = fieldFromInstruction(Insn, 16, 5); |
| 541 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 542 | |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 543 | Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg); |
| 544 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 545 | |
| 546 | if(Inst.getOpcode() == Mips::SC){ |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 547 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 548 | } |
| 549 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 550 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 551 | Inst.addOperand(MCOperand::CreateReg(Base)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 552 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 553 | |
| 554 | return MCDisassembler::Success; |
| 555 | } |
| 556 | |
Matheus Almeida | fe0bf9f | 2013-10-21 13:07:13 +0000 | [diff] [blame] | 557 | static DecodeStatus DecodeMSA128Mem(MCInst &Inst, unsigned Insn, |
| 558 | uint64_t Address, const void *Decoder) { |
| 559 | int Offset = SignExtend32<10>(fieldFromInstruction(Insn, 16, 10)); |
| 560 | unsigned Reg = fieldFromInstruction(Insn, 6, 5); |
| 561 | unsigned Base = fieldFromInstruction(Insn, 11, 5); |
| 562 | |
| 563 | Reg = getReg(Decoder, Mips::MSA128BRegClassID, Reg); |
| 564 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 565 | |
| 566 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 567 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 568 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 569 | |
| 570 | return MCDisassembler::Success; |
| 571 | } |
| 572 | |
Vladimir Medic | dde3d58 | 2013-09-06 12:30:36 +0000 | [diff] [blame] | 573 | static DecodeStatus DecodeMemMMImm12(MCInst &Inst, |
| 574 | unsigned Insn, |
| 575 | uint64_t Address, |
| 576 | const void *Decoder) { |
| 577 | int Offset = SignExtend32<12>(Insn & 0x0fff); |
| 578 | unsigned Reg = fieldFromInstruction(Insn, 21, 5); |
| 579 | unsigned Base = fieldFromInstruction(Insn, 16, 5); |
| 580 | |
| 581 | Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg); |
| 582 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 583 | |
| 584 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 585 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 586 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 587 | |
| 588 | return MCDisassembler::Success; |
| 589 | } |
| 590 | |
| 591 | static DecodeStatus DecodeMemMMImm16(MCInst &Inst, |
| 592 | unsigned Insn, |
| 593 | uint64_t Address, |
| 594 | const void *Decoder) { |
| 595 | int Offset = SignExtend32<16>(Insn & 0xffff); |
| 596 | unsigned Reg = fieldFromInstruction(Insn, 21, 5); |
| 597 | unsigned Base = fieldFromInstruction(Insn, 16, 5); |
| 598 | |
| 599 | Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg); |
| 600 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
| 601 | |
| 602 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 603 | Inst.addOperand(MCOperand::CreateReg(Base)); |
| 604 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 605 | |
| 606 | return MCDisassembler::Success; |
| 607 | } |
| 608 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 609 | static DecodeStatus DecodeFMem(MCInst &Inst, |
| 610 | unsigned Insn, |
| 611 | uint64_t Address, |
| 612 | const void *Decoder) { |
| 613 | int Offset = SignExtend32<16>(Insn & 0xffff); |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 614 | unsigned Reg = fieldFromInstruction(Insn, 16, 5); |
| 615 | unsigned Base = fieldFromInstruction(Insn, 21, 5); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 616 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 617 | Reg = getReg(Decoder, Mips::FGR64RegClassID, Reg); |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 618 | Base = getReg(Decoder, Mips::GPR32RegClassID, Base); |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 619 | |
| 620 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 621 | Inst.addOperand(MCOperand::CreateReg(Base)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 622 | Inst.addOperand(MCOperand::CreateImm(Offset)); |
| 623 | |
| 624 | return MCDisassembler::Success; |
| 625 | } |
| 626 | |
| 627 | |
| 628 | static DecodeStatus DecodeHWRegsRegisterClass(MCInst &Inst, |
| 629 | unsigned RegNo, |
| 630 | uint64_t Address, |
| 631 | const void *Decoder) { |
| 632 | // Currently only hardware register 29 is supported. |
| 633 | if (RegNo != 29) |
| 634 | return MCDisassembler::Fail; |
| 635 | Inst.addOperand(MCOperand::CreateReg(Mips::HWR29)); |
| 636 | return MCDisassembler::Success; |
| 637 | } |
| 638 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 639 | static DecodeStatus DecodeAFGR64RegisterClass(MCInst &Inst, |
| 640 | unsigned RegNo, |
| 641 | uint64_t Address, |
| 642 | const void *Decoder) { |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 643 | if (RegNo > 30 || RegNo %2) |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 644 | return MCDisassembler::Fail; |
| 645 | |
Akira Hatanaka | 9bf2b56 | 2012-07-09 18:46:47 +0000 | [diff] [blame] | 646 | ; |
| 647 | unsigned Reg = getReg(Decoder, Mips::AFGR64RegClassID, RegNo /2); |
| 648 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 649 | return MCDisassembler::Success; |
| 650 | } |
| 651 | |
Akira Hatanaka | 00fcf2e | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 652 | static DecodeStatus DecodeACC64DSPRegisterClass(MCInst &Inst, |
| 653 | unsigned RegNo, |
| 654 | uint64_t Address, |
| 655 | const void *Decoder) { |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 656 | if (RegNo >= 4) |
| 657 | return MCDisassembler::Fail; |
| 658 | |
Akira Hatanaka | 00fcf2e | 2013-08-08 21:54:26 +0000 | [diff] [blame] | 659 | unsigned Reg = getReg(Decoder, Mips::ACC64DSPRegClassID, RegNo); |
Akira Hatanaka | ecabd1a | 2012-09-27 02:01:10 +0000 | [diff] [blame] | 660 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 661 | return MCDisassembler::Success; |
| 662 | } |
| 663 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 664 | static DecodeStatus DecodeHI32DSPRegisterClass(MCInst &Inst, |
| 665 | unsigned RegNo, |
| 666 | uint64_t Address, |
| 667 | const void *Decoder) { |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 668 | if (RegNo >= 4) |
| 669 | return MCDisassembler::Fail; |
| 670 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 671 | unsigned Reg = getReg(Decoder, Mips::HI32DSPRegClassID, RegNo); |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 672 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 673 | return MCDisassembler::Success; |
| 674 | } |
| 675 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 676 | static DecodeStatus DecodeLO32DSPRegisterClass(MCInst &Inst, |
| 677 | unsigned RegNo, |
| 678 | uint64_t Address, |
| 679 | const void *Decoder) { |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 680 | if (RegNo >= 4) |
| 681 | return MCDisassembler::Fail; |
| 682 | |
Akira Hatanaka | 8002a3f | 2013-08-14 00:47:08 +0000 | [diff] [blame] | 683 | unsigned Reg = getReg(Decoder, Mips::LO32DSPRegClassID, RegNo); |
Akira Hatanaka | 59bfaf7 | 2013-04-18 00:52:44 +0000 | [diff] [blame] | 684 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 685 | return MCDisassembler::Success; |
| 686 | } |
| 687 | |
Jack Carter | 3eb663b | 2013-09-26 00:09:46 +0000 | [diff] [blame] | 688 | static DecodeStatus DecodeMSA128BRegisterClass(MCInst &Inst, |
| 689 | unsigned RegNo, |
| 690 | uint64_t Address, |
| 691 | const void *Decoder) { |
| 692 | if (RegNo > 31) |
| 693 | return MCDisassembler::Fail; |
| 694 | |
| 695 | unsigned Reg = getReg(Decoder, Mips::MSA128BRegClassID, RegNo); |
| 696 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 697 | return MCDisassembler::Success; |
| 698 | } |
| 699 | |
Jack Carter | 5dc8ac9 | 2013-09-25 23:50:44 +0000 | [diff] [blame] | 700 | static DecodeStatus DecodeMSA128HRegisterClass(MCInst &Inst, |
| 701 | unsigned RegNo, |
| 702 | uint64_t Address, |
| 703 | const void *Decoder) { |
| 704 | if (RegNo > 31) |
| 705 | return MCDisassembler::Fail; |
| 706 | |
| 707 | unsigned Reg = getReg(Decoder, Mips::MSA128HRegClassID, RegNo); |
| 708 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 709 | return MCDisassembler::Success; |
| 710 | } |
| 711 | |
| 712 | static DecodeStatus DecodeMSA128WRegisterClass(MCInst &Inst, |
| 713 | unsigned RegNo, |
| 714 | uint64_t Address, |
| 715 | const void *Decoder) { |
| 716 | if (RegNo > 31) |
| 717 | return MCDisassembler::Fail; |
| 718 | |
| 719 | unsigned Reg = getReg(Decoder, Mips::MSA128WRegClassID, RegNo); |
| 720 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 721 | return MCDisassembler::Success; |
| 722 | } |
| 723 | |
| 724 | static DecodeStatus DecodeMSA128DRegisterClass(MCInst &Inst, |
| 725 | unsigned RegNo, |
| 726 | uint64_t Address, |
| 727 | const void *Decoder) { |
| 728 | if (RegNo > 31) |
| 729 | return MCDisassembler::Fail; |
| 730 | |
| 731 | unsigned Reg = getReg(Decoder, Mips::MSA128DRegClassID, RegNo); |
| 732 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 733 | return MCDisassembler::Success; |
| 734 | } |
| 735 | |
Matheus Almeida | a591fdc | 2013-10-21 12:26:50 +0000 | [diff] [blame] | 736 | static DecodeStatus DecodeMSACtrlRegisterClass(MCInst &Inst, |
| 737 | unsigned RegNo, |
| 738 | uint64_t Address, |
| 739 | const void *Decoder) { |
| 740 | if (RegNo > 7) |
| 741 | return MCDisassembler::Fail; |
| 742 | |
| 743 | unsigned Reg = getReg(Decoder, Mips::MSACtrlRegClassID, RegNo); |
| 744 | Inst.addOperand(MCOperand::CreateReg(Reg)); |
| 745 | return MCDisassembler::Success; |
| 746 | } |
| 747 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 748 | static DecodeStatus DecodeBranchTarget(MCInst &Inst, |
| 749 | unsigned Offset, |
| 750 | uint64_t Address, |
| 751 | const void *Decoder) { |
| 752 | unsigned BranchOffset = Offset & 0xffff; |
| 753 | BranchOffset = SignExtend32<18>(BranchOffset << 2) + 4; |
| 754 | Inst.addOperand(MCOperand::CreateImm(BranchOffset)); |
| 755 | return MCDisassembler::Success; |
| 756 | } |
| 757 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 758 | static DecodeStatus DecodeJumpTarget(MCInst &Inst, |
| 759 | unsigned Insn, |
| 760 | uint64_t Address, |
| 761 | const void *Decoder) { |
| 762 | |
Jim Grosbach | ecaef49 | 2012-08-14 19:06:05 +0000 | [diff] [blame] | 763 | unsigned JumpOffset = fieldFromInstruction(Insn, 0, 26) << 2; |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 764 | Inst.addOperand(MCOperand::CreateImm(JumpOffset)); |
| 765 | return MCDisassembler::Success; |
| 766 | } |
| 767 | |
Zoran Jovanovic | 8a80aa7 | 2013-11-04 14:53:22 +0000 | [diff] [blame] | 768 | static DecodeStatus DecodeBranchTargetMM(MCInst &Inst, |
| 769 | unsigned Offset, |
| 770 | uint64_t Address, |
| 771 | const void *Decoder) { |
| 772 | unsigned BranchOffset = Offset & 0xffff; |
| 773 | BranchOffset = SignExtend32<18>(BranchOffset << 1); |
| 774 | Inst.addOperand(MCOperand::CreateImm(BranchOffset)); |
| 775 | return MCDisassembler::Success; |
| 776 | } |
| 777 | |
Zoran Jovanovic | 507e084 | 2013-10-29 16:38:59 +0000 | [diff] [blame] | 778 | static DecodeStatus DecodeJumpTargetMM(MCInst &Inst, |
| 779 | unsigned Insn, |
| 780 | uint64_t Address, |
| 781 | const void *Decoder) { |
| 782 | unsigned JumpOffset = fieldFromInstruction(Insn, 0, 26) << 1; |
| 783 | Inst.addOperand(MCOperand::CreateImm(JumpOffset)); |
| 784 | return MCDisassembler::Success; |
| 785 | } |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 786 | |
| 787 | static DecodeStatus DecodeSimm16(MCInst &Inst, |
| 788 | unsigned Insn, |
| 789 | uint64_t Address, |
| 790 | const void *Decoder) { |
| 791 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<16>(Insn))); |
| 792 | return MCDisassembler::Success; |
| 793 | } |
| 794 | |
Matheus Almeida | 779c593 | 2013-11-18 12:32:49 +0000 | [diff] [blame^] | 795 | static DecodeStatus DecodeLSAImm(MCInst &Inst, |
| 796 | unsigned Insn, |
| 797 | uint64_t Address, |
| 798 | const void *Decoder) { |
| 799 | // We add one to the immediate field as it was encoded as 'imm - 1'. |
| 800 | Inst.addOperand(MCOperand::CreateImm(Insn + 1)); |
| 801 | return MCDisassembler::Success; |
| 802 | } |
| 803 | |
Akira Hatanaka | 71928e6 | 2012-04-17 18:03:21 +0000 | [diff] [blame] | 804 | static DecodeStatus DecodeInsSize(MCInst &Inst, |
| 805 | unsigned Insn, |
| 806 | uint64_t Address, |
| 807 | const void *Decoder) { |
| 808 | // First we need to grab the pos(lsb) from MCInst. |
| 809 | int Pos = Inst.getOperand(2).getImm(); |
| 810 | int Size = (int) Insn - Pos + 1; |
| 811 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<16>(Size))); |
| 812 | return MCDisassembler::Success; |
| 813 | } |
| 814 | |
| 815 | static DecodeStatus DecodeExtSize(MCInst &Inst, |
| 816 | unsigned Insn, |
| 817 | uint64_t Address, |
| 818 | const void *Decoder) { |
| 819 | int Size = (int) Insn + 1; |
| 820 | Inst.addOperand(MCOperand::CreateImm(SignExtend32<16>(Size))); |
| 821 | return MCDisassembler::Success; |
| 822 | } |