blob: c8a5195e8e6863686722f4daf6c50d4acee3ac5a [file] [log] [blame]
Akira Hatanaka71928e62012-04-17 18:03:21 +00001//===- 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 Hatanaka9bf2b562012-07-09 18:46:47 +000015#include "MipsRegisterInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000016#include "MipsSubtarget.h"
Lang Hamesa1bc0f52014-04-15 04:40:56 +000017#include "llvm/MC/MCContext.h"
Akira Hatanaka71928e62012-04-17 18:03:21 +000018#include "llvm/MC/MCDisassembler.h"
Jim Grosbachecaef492012-08-14 19:06:05 +000019#include "llvm/MC/MCFixedLenDisassembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000020#include "llvm/MC/MCInst.h"
21#include "llvm/MC/MCSubtargetInfo.h"
22#include "llvm/Support/MathExtras.h"
Akira Hatanaka71928e62012-04-17 18:03:21 +000023#include "llvm/Support/TargetRegistry.h"
Akira Hatanaka71928e62012-04-17 18:03:21 +000024
Akira Hatanaka71928e62012-04-17 18:03:21 +000025using namespace llvm;
26
Chandler Carruthe96dd892014-04-21 22:55:11 +000027#define DEBUG_TYPE "mips-disassembler"
28
Akira Hatanaka71928e62012-04-17 18:03:21 +000029typedef MCDisassembler::DecodeStatus DecodeStatus;
30
Benjamin Kramercb3e98c2012-05-01 14:34:24 +000031namespace {
32
Alexei Starovoitov4ea2f602015-01-23 21:00:08 +000033/// A disassembler class for Mips.
Akira Hatanaka9bf2b562012-07-09 18:46:47 +000034class MipsDisassemblerBase : public MCDisassembler {
Akira Hatanaka71928e62012-04-17 18:03:21 +000035public:
Lang Hamesa1bc0f52014-04-15 04:40:56 +000036 MipsDisassemblerBase(const MCSubtargetInfo &STI, MCContext &Ctx,
Rafael Espindola4aa6bea2014-11-10 18:11:10 +000037 bool IsBigEndian)
38 : MCDisassembler(STI, Ctx),
Vladimir Medice8860932014-12-16 15:29:12 +000039 IsGP64Bit(STI.getFeatureBits() & Mips::FeatureGP64Bit),
Rafael Espindola4aa6bea2014-11-10 18:11:10 +000040 IsBigEndian(IsBigEndian) {}
Akira Hatanaka71928e62012-04-17 18:03:21 +000041
Akira Hatanaka9bf2b562012-07-09 18:46:47 +000042 virtual ~MipsDisassemblerBase() {}
Akira Hatanaka71928e62012-04-17 18:03:21 +000043
Vladimir Medice8860932014-12-16 15:29:12 +000044 bool isGP64Bit() const { return IsGP64Bit; }
Akira Hatanaka9bfa2e22013-08-28 00:55:15 +000045
Akira Hatanaka71928e62012-04-17 18:03:21 +000046private:
Vladimir Medice8860932014-12-16 15:29:12 +000047 bool IsGP64Bit;
Akira Hatanaka9bf2b562012-07-09 18:46:47 +000048protected:
Rafael Espindola4aa6bea2014-11-10 18:11:10 +000049 bool IsBigEndian;
Akira Hatanaka71928e62012-04-17 18:03:21 +000050};
51
Alexei Starovoitov4ea2f602015-01-23 21:00:08 +000052/// A disassembler class for Mips32.
Akira Hatanaka9bf2b562012-07-09 18:46:47 +000053class MipsDisassembler : public MipsDisassemblerBase {
Vladimir Medicdde3d582013-09-06 12:30:36 +000054 bool IsMicroMips;
Akira Hatanaka9bf2b562012-07-09 18:46:47 +000055public:
Daniel Sandersc171f652014-06-13 13:15:59 +000056 MipsDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx, bool bigEndian)
57 : MipsDisassemblerBase(STI, Ctx, bigEndian) {
58 IsMicroMips = STI.getFeatureBits() & Mips::FeatureMicroMips;
59 }
Akira Hatanaka9bf2b562012-07-09 18:46:47 +000060
Daniel Sandersc171f652014-06-13 13:15:59 +000061 bool hasMips3() const { return STI.getFeatureBits() & Mips::FeatureMips3; }
62 bool hasMips32() const { return STI.getFeatureBits() & Mips::FeatureMips32; }
63 bool hasMips32r6() const {
Daniel Sanders5c582b22014-05-22 11:23:21 +000064 return STI.getFeatureBits() & Mips::FeatureMips32r6;
65 }
66
Daniel Sanders0fa60412014-06-12 13:39:06 +000067 bool isGP64() const { return STI.getFeatureBits() & Mips::FeatureGP64Bit; }
68
Daniel Sandersc171f652014-06-13 13:15:59 +000069 bool hasCOP3() const {
70 // Only present in MIPS-I and MIPS-II
71 return !hasMips32() && !hasMips3();
72 }
73
Rafael Espindola4aa6bea2014-11-10 18:11:10 +000074 DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
Rafael Espindola7fc5b872014-11-12 02:04:27 +000075 ArrayRef<uint8_t> Bytes, uint64_t Address,
Rafael Espindola4aa6bea2014-11-10 18:11:10 +000076 raw_ostream &VStream,
77 raw_ostream &CStream) const override;
Akira Hatanaka9bf2b562012-07-09 18:46:47 +000078};
79
Alexei Starovoitov4ea2f602015-01-23 21:00:08 +000080/// A disassembler class for Mips64.
Akira Hatanaka9bf2b562012-07-09 18:46:47 +000081class Mips64Disassembler : public MipsDisassemblerBase {
Akira Hatanaka71928e62012-04-17 18:03:21 +000082public:
Lang Hamesa1bc0f52014-04-15 04:40:56 +000083 Mips64Disassembler(const MCSubtargetInfo &STI, MCContext &Ctx,
Akira Hatanaka9bf2b562012-07-09 18:46:47 +000084 bool bigEndian) :
Lang Hamesa1bc0f52014-04-15 04:40:56 +000085 MipsDisassemblerBase(STI, Ctx, bigEndian) {}
Akira Hatanaka71928e62012-04-17 18:03:21 +000086
Rafael Espindola4aa6bea2014-11-10 18:11:10 +000087 DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
Rafael Espindola7fc5b872014-11-12 02:04:27 +000088 ArrayRef<uint8_t> Bytes, uint64_t Address,
Rafael Espindola4aa6bea2014-11-10 18:11:10 +000089 raw_ostream &VStream,
90 raw_ostream &CStream) const override;
Akira Hatanaka71928e62012-04-17 18:03:21 +000091};
92
Benjamin Kramercb3e98c2012-05-01 14:34:24 +000093} // end anonymous namespace
94
Akira Hatanaka71928e62012-04-17 18:03:21 +000095// Forward declare these because the autogenerated code will reference them.
96// Definitions are further down.
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +000097static DecodeStatus DecodeGPR64RegisterClass(MCInst &Inst,
98 unsigned RegNo,
99 uint64_t Address,
100 const void *Decoder);
Akira Hatanaka71928e62012-04-17 18:03:21 +0000101
Reed Kotlerec8a5492013-02-14 03:05:25 +0000102static DecodeStatus DecodeCPU16RegsRegisterClass(MCInst &Inst,
103 unsigned RegNo,
104 uint64_t Address,
105 const void *Decoder);
106
Zoran Jovanovicb0852e52014-10-21 08:23:11 +0000107static DecodeStatus DecodeGPRMM16RegisterClass(MCInst &Inst,
108 unsigned RegNo,
109 uint64_t Address,
110 const void *Decoder);
111
Jozef Kolek1904fa22014-11-24 14:25:53 +0000112static DecodeStatus DecodeGPRMM16ZeroRegisterClass(MCInst &Inst,
113 unsigned RegNo,
114 uint64_t Address,
115 const void *Decoder);
116
Zoran Jovanovic41688672015-02-10 16:36:20 +0000117static DecodeStatus DecodeGPRMM16MovePRegisterClass(MCInst &Inst,
118 unsigned RegNo,
119 uint64_t Address,
120 const void *Decoder);
121
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000122static DecodeStatus DecodeGPR32RegisterClass(MCInst &Inst,
123 unsigned RegNo,
124 uint64_t Address,
125 const void *Decoder);
Akira Hatanaka71928e62012-04-17 18:03:21 +0000126
Akira Hatanaka9bfa2e22013-08-28 00:55:15 +0000127static DecodeStatus DecodePtrRegisterClass(MCInst &Inst,
128 unsigned Insn,
129 uint64_t Address,
130 const void *Decoder);
131
Akira Hatanaka654655f2013-08-14 00:53:38 +0000132static DecodeStatus DecodeDSPRRegisterClass(MCInst &Inst,
133 unsigned RegNo,
134 uint64_t Address,
135 const void *Decoder);
Akira Hatanakaecabd1a2012-09-27 02:01:10 +0000136
Akira Hatanaka71928e62012-04-17 18:03:21 +0000137static DecodeStatus DecodeFGR64RegisterClass(MCInst &Inst,
138 unsigned RegNo,
139 uint64_t Address,
140 const void *Decoder);
141
142static DecodeStatus DecodeFGR32RegisterClass(MCInst &Inst,
143 unsigned RegNo,
144 uint64_t Address,
145 const void *Decoder);
146
147static DecodeStatus DecodeCCRRegisterClass(MCInst &Inst,
148 unsigned RegNo,
149 uint64_t Address,
150 const void *Decoder);
151
Akira Hatanaka1fb1b8b2013-07-26 20:13:47 +0000152static DecodeStatus DecodeFCCRegisterClass(MCInst &Inst,
153 unsigned RegNo,
154 uint64_t Address,
155 const void *Decoder);
156
Daniel Sanders0fa60412014-06-12 13:39:06 +0000157static DecodeStatus DecodeFGRCCRegisterClass(MCInst &Inst, unsigned RegNo,
158 uint64_t Address,
159 const void *Decoder);
160
Akira Hatanaka71928e62012-04-17 18:03:21 +0000161static DecodeStatus DecodeHWRegsRegisterClass(MCInst &Inst,
162 unsigned Insn,
163 uint64_t Address,
164 const void *Decoder);
165
166static DecodeStatus DecodeAFGR64RegisterClass(MCInst &Inst,
167 unsigned RegNo,
168 uint64_t Address,
169 const void *Decoder);
170
Akira Hatanaka00fcf2e2013-08-08 21:54:26 +0000171static DecodeStatus DecodeACC64DSPRegisterClass(MCInst &Inst,
172 unsigned RegNo,
173 uint64_t Address,
174 const void *Decoder);
Akira Hatanakaecabd1a2012-09-27 02:01:10 +0000175
Akira Hatanaka8002a3f2013-08-14 00:47:08 +0000176static DecodeStatus DecodeHI32DSPRegisterClass(MCInst &Inst,
177 unsigned RegNo,
178 uint64_t Address,
179 const void *Decoder);
Akira Hatanaka59bfaf72013-04-18 00:52:44 +0000180
Akira Hatanaka8002a3f2013-08-14 00:47:08 +0000181static DecodeStatus DecodeLO32DSPRegisterClass(MCInst &Inst,
182 unsigned RegNo,
183 uint64_t Address,
184 const void *Decoder);
Akira Hatanaka59bfaf72013-04-18 00:52:44 +0000185
Jack Carter3eb663b2013-09-26 00:09:46 +0000186static DecodeStatus DecodeMSA128BRegisterClass(MCInst &Inst,
187 unsigned RegNo,
188 uint64_t Address,
189 const void *Decoder);
190
Jack Carter5dc8ac92013-09-25 23:50:44 +0000191static DecodeStatus DecodeMSA128HRegisterClass(MCInst &Inst,
192 unsigned RegNo,
193 uint64_t Address,
194 const void *Decoder);
195
196static DecodeStatus DecodeMSA128WRegisterClass(MCInst &Inst,
197 unsigned RegNo,
198 uint64_t Address,
199 const void *Decoder);
200
201static DecodeStatus DecodeMSA128DRegisterClass(MCInst &Inst,
202 unsigned RegNo,
203 uint64_t Address,
204 const void *Decoder);
205
Matheus Almeidaa591fdc2013-10-21 12:26:50 +0000206static DecodeStatus DecodeMSACtrlRegisterClass(MCInst &Inst,
207 unsigned RegNo,
208 uint64_t Address,
209 const void *Decoder);
210
Daniel Sanders2a83d682014-05-21 12:56:39 +0000211static DecodeStatus DecodeCOP2RegisterClass(MCInst &Inst,
212 unsigned RegNo,
213 uint64_t Address,
214 const void *Decoder);
215
Akira Hatanaka71928e62012-04-17 18:03:21 +0000216static DecodeStatus DecodeBranchTarget(MCInst &Inst,
217 unsigned Offset,
218 uint64_t Address,
219 const void *Decoder);
220
Akira Hatanaka71928e62012-04-17 18:03:21 +0000221static DecodeStatus DecodeJumpTarget(MCInst &Inst,
222 unsigned Insn,
223 uint64_t Address,
224 const void *Decoder);
225
Zoran Jovanovic3c8869d2014-05-16 11:03:45 +0000226static DecodeStatus DecodeBranchTarget21(MCInst &Inst,
227 unsigned Offset,
228 uint64_t Address,
229 const void *Decoder);
230
231static DecodeStatus DecodeBranchTarget26(MCInst &Inst,
232 unsigned Offset,
233 uint64_t Address,
234 const void *Decoder);
235
Jozef Kolek9761e962015-01-12 12:03:34 +0000236// DecodeBranchTarget7MM - Decode microMIPS branch offset, which is
237// shifted left by 1 bit.
238static DecodeStatus DecodeBranchTarget7MM(MCInst &Inst,
239 unsigned Offset,
240 uint64_t Address,
241 const void *Decoder);
242
Jozef Kolek5cfebdd2015-01-21 12:39:30 +0000243// DecodeBranchTarget10MM - Decode microMIPS branch offset, which is
244// shifted left by 1 bit.
245static DecodeStatus DecodeBranchTarget10MM(MCInst &Inst,
246 unsigned Offset,
247 uint64_t Address,
248 const void *Decoder);
249
Zoran Jovanovic8a80aa72013-11-04 14:53:22 +0000250// DecodeBranchTargetMM - Decode microMIPS branch offset, which is
251// shifted left by 1 bit.
252static DecodeStatus DecodeBranchTargetMM(MCInst &Inst,
253 unsigned Offset,
254 uint64_t Address,
255 const void *Decoder);
256
Zoran Jovanovic507e0842013-10-29 16:38:59 +0000257// DecodeJumpTargetMM - Decode microMIPS jump target, which is
258// shifted left by 1 bit.
259static DecodeStatus DecodeJumpTargetMM(MCInst &Inst,
260 unsigned Insn,
261 uint64_t Address,
262 const void *Decoder);
263
Akira Hatanaka71928e62012-04-17 18:03:21 +0000264static DecodeStatus DecodeMem(MCInst &Inst,
265 unsigned Insn,
266 uint64_t Address,
267 const void *Decoder);
268
Daniel Sanders92db6b72014-10-01 08:26:55 +0000269static DecodeStatus DecodeCacheOp(MCInst &Inst,
270 unsigned Insn,
271 uint64_t Address,
272 const void *Decoder);
273
Vladimir Medicdf464ae2015-01-29 11:33:41 +0000274static DecodeStatus DecodeCacheOpR6(MCInst &Inst,
275 unsigned Insn,
276 uint64_t Address,
277 const void *Decoder);
278
Jozef Kolekab6d1cc2014-12-23 19:55:34 +0000279static DecodeStatus DecodeCacheOpMM(MCInst &Inst,
280 unsigned Insn,
281 uint64_t Address,
282 const void *Decoder);
283
Daniel Sandersb4484d62014-11-27 17:28:10 +0000284static DecodeStatus DecodeSyncI(MCInst &Inst,
285 unsigned Insn,
286 uint64_t Address,
287 const void *Decoder);
288
Matheus Almeidafe0bf9f2013-10-21 13:07:13 +0000289static DecodeStatus DecodeMSA128Mem(MCInst &Inst, unsigned Insn,
290 uint64_t Address, const void *Decoder);
291
Jozef Kolek315e7ec2014-11-26 18:56:38 +0000292static DecodeStatus DecodeMemMMImm4(MCInst &Inst,
293 unsigned Insn,
294 uint64_t Address,
295 const void *Decoder);
296
Jozef Kolek12c69822014-12-23 16:16:33 +0000297static DecodeStatus DecodeMemMMSPImm5Lsl2(MCInst &Inst,
298 unsigned Insn,
299 uint64_t Address,
300 const void *Decoder);
301
Jozef Koleke10a02e2015-01-28 17:27:26 +0000302static DecodeStatus DecodeMemMMGPImm7Lsl2(MCInst &Inst,
303 unsigned Insn,
304 uint64_t Address,
305 const void *Decoder);
306
Jozef Kolekd68d424a2015-02-10 12:41:13 +0000307static DecodeStatus DecodeMemMMReglistImm4Lsl2(MCInst &Inst,
308 unsigned Insn,
309 uint64_t Address,
310 const void *Decoder);
311
Vladimir Medicdde3d582013-09-06 12:30:36 +0000312static DecodeStatus DecodeMemMMImm12(MCInst &Inst,
313 unsigned Insn,
314 uint64_t Address,
315 const void *Decoder);
316
317static DecodeStatus DecodeMemMMImm16(MCInst &Inst,
318 unsigned Insn,
319 uint64_t Address,
320 const void *Decoder);
321
Akira Hatanaka71928e62012-04-17 18:03:21 +0000322static DecodeStatus DecodeFMem(MCInst &Inst, unsigned Insn,
323 uint64_t Address,
324 const void *Decoder);
325
Daniel Sanders92db6b72014-10-01 08:26:55 +0000326static DecodeStatus DecodeFMem2(MCInst &Inst, unsigned Insn,
327 uint64_t Address,
328 const void *Decoder);
329
330static DecodeStatus DecodeFMem3(MCInst &Inst, unsigned Insn,
331 uint64_t Address,
332 const void *Decoder);
333
Vladimir Medic435cf8a2015-01-21 10:47:36 +0000334static DecodeStatus DecodeFMemCop2R6(MCInst &Inst, unsigned Insn,
335 uint64_t Address,
336 const void *Decoder);
337
Daniel Sanders6a803f62014-06-16 13:13:03 +0000338static DecodeStatus DecodeSpecial3LlSc(MCInst &Inst,
339 unsigned Insn,
340 uint64_t Address,
341 const void *Decoder);
342
Jozef Kolekaa2b9272014-11-27 14:41:44 +0000343static DecodeStatus DecodeAddiur2Simm7(MCInst &Inst,
344 unsigned Value,
345 uint64_t Address,
346 const void *Decoder);
347
348static DecodeStatus DecodeUImm6Lsl2(MCInst &Inst,
349 unsigned Value,
350 uint64_t Address,
351 const void *Decoder);
352
353static DecodeStatus DecodeLiSimm7(MCInst &Inst,
354 unsigned Value,
355 uint64_t Address,
356 const void *Decoder);
357
358static DecodeStatus DecodeSimm4(MCInst &Inst,
359 unsigned Value,
360 uint64_t Address,
361 const void *Decoder);
362
Akira Hatanaka71928e62012-04-17 18:03:21 +0000363static DecodeStatus DecodeSimm16(MCInst &Inst,
364 unsigned Insn,
365 uint64_t Address,
366 const void *Decoder);
367
Matheus Almeida779c5932013-11-18 12:32:49 +0000368// Decode the immediate field of an LSA instruction which
369// is off by one.
370static DecodeStatus DecodeLSAImm(MCInst &Inst,
371 unsigned Insn,
372 uint64_t Address,
373 const void *Decoder);
374
Akira Hatanaka71928e62012-04-17 18:03:21 +0000375static DecodeStatus DecodeInsSize(MCInst &Inst,
376 unsigned Insn,
377 uint64_t Address,
378 const void *Decoder);
379
380static DecodeStatus DecodeExtSize(MCInst &Inst,
381 unsigned Insn,
382 uint64_t Address,
383 const void *Decoder);
384
Daniel Sandersb59e1a42014-05-15 10:45:58 +0000385static DecodeStatus DecodeSimm19Lsl2(MCInst &Inst, unsigned Insn,
386 uint64_t Address, const void *Decoder);
387
Zoran Jovanovic28551422014-06-09 09:49:51 +0000388static DecodeStatus DecodeSimm18Lsl3(MCInst &Inst, unsigned Insn,
389 uint64_t Address, const void *Decoder);
390
Vladimir Medicb682ddf2014-12-01 11:12:04 +0000391static DecodeStatus DecodeSimm9SP(MCInst &Inst, unsigned Insn,
392 uint64_t Address, const void *Decoder);
393
394static DecodeStatus DecodeANDI16Imm(MCInst &Inst, unsigned Insn,
395 uint64_t Address, const void *Decoder);
396
397static DecodeStatus DecodeUImm5lsl2(MCInst &Inst, unsigned Insn,
398 uint64_t Address, const void *Decoder);
399
Jozef Kolek2c6d7322015-01-21 12:10:11 +0000400static DecodeStatus DecodeSimm23Lsl2(MCInst &Inst, unsigned Insn,
401 uint64_t Address, const void *Decoder);
402
Daniel Sandersb50ccf82014-04-01 10:35:28 +0000403/// INSVE_[BHWD] have an implicit operand that the generated decoder doesn't
404/// handle.
405template <typename InsnType>
406static DecodeStatus DecodeINSVE_DF(MCInst &MI, InsnType insn, uint64_t Address,
407 const void *Decoder);
Daniel Sanders5c582b22014-05-22 11:23:21 +0000408
409template <typename InsnType>
410static DecodeStatus
411DecodeAddiGroupBranch(MCInst &MI, InsnType insn, uint64_t Address,
412 const void *Decoder);
413
414template <typename InsnType>
415static DecodeStatus
416DecodeDaddiGroupBranch(MCInst &MI, InsnType insn, uint64_t Address,
417 const void *Decoder);
418
419template <typename InsnType>
420static DecodeStatus
421DecodeBlezlGroupBranch(MCInst &MI, InsnType insn, uint64_t Address,
422 const void *Decoder);
423
424template <typename InsnType>
425static DecodeStatus
426DecodeBgtzlGroupBranch(MCInst &MI, InsnType insn, uint64_t Address,
427 const void *Decoder);
428
429template <typename InsnType>
430static DecodeStatus
431DecodeBgtzGroupBranch(MCInst &MI, InsnType insn, uint64_t Address,
432 const void *Decoder);
433
Zoran Jovanovic28a0ca02014-06-12 11:47:44 +0000434template <typename InsnType>
435static DecodeStatus
436DecodeBlezGroupBranch(MCInst &MI, InsnType insn, uint64_t Address,
437 const void *Decoder);
438
Zoran Jovanovica4c4b5f2014-11-19 16:44:02 +0000439static DecodeStatus DecodeRegListOperand(MCInst &Inst, unsigned Insn,
440 uint64_t Address,
441 const void *Decoder);
442
Zoran Jovanovicf9a02502014-11-27 18:28:59 +0000443static DecodeStatus DecodeRegListOperand16(MCInst &Inst, unsigned Insn,
444 uint64_t Address,
445 const void *Decoder);
446
Zoran Jovanovic41688672015-02-10 16:36:20 +0000447static DecodeStatus DecodeMovePRegPair(MCInst &Inst, unsigned Insn,
448 uint64_t Address,
449 const void *Decoder);
450
Akira Hatanaka71928e62012-04-17 18:03:21 +0000451namespace llvm {
452extern Target TheMipselTarget, TheMipsTarget, TheMips64Target,
453 TheMips64elTarget;
454}
455
456static MCDisassembler *createMipsDisassembler(
457 const Target &T,
Lang Hamesa1bc0f52014-04-15 04:40:56 +0000458 const MCSubtargetInfo &STI,
459 MCContext &Ctx) {
460 return new MipsDisassembler(STI, Ctx, true);
Akira Hatanaka71928e62012-04-17 18:03:21 +0000461}
462
463static MCDisassembler *createMipselDisassembler(
464 const Target &T,
Lang Hamesa1bc0f52014-04-15 04:40:56 +0000465 const MCSubtargetInfo &STI,
466 MCContext &Ctx) {
467 return new MipsDisassembler(STI, Ctx, false);
Akira Hatanaka71928e62012-04-17 18:03:21 +0000468}
469
470static MCDisassembler *createMips64Disassembler(
471 const Target &T,
Lang Hamesa1bc0f52014-04-15 04:40:56 +0000472 const MCSubtargetInfo &STI,
473 MCContext &Ctx) {
474 return new Mips64Disassembler(STI, Ctx, true);
Akira Hatanaka71928e62012-04-17 18:03:21 +0000475}
476
477static MCDisassembler *createMips64elDisassembler(
478 const Target &T,
Lang Hamesa1bc0f52014-04-15 04:40:56 +0000479 const MCSubtargetInfo &STI,
480 MCContext &Ctx) {
481 return new Mips64Disassembler(STI, Ctx, false);
Akira Hatanaka71928e62012-04-17 18:03:21 +0000482}
483
484extern "C" void LLVMInitializeMipsDisassembler() {
485 // Register the disassembler.
486 TargetRegistry::RegisterMCDisassembler(TheMipsTarget,
487 createMipsDisassembler);
488 TargetRegistry::RegisterMCDisassembler(TheMipselTarget,
489 createMipselDisassembler);
490 TargetRegistry::RegisterMCDisassembler(TheMips64Target,
491 createMips64Disassembler);
492 TargetRegistry::RegisterMCDisassembler(TheMips64elTarget,
493 createMips64elDisassembler);
494}
495
Akira Hatanaka71928e62012-04-17 18:03:21 +0000496#include "MipsGenDisassemblerTables.inc"
497
Daniel Sanders5c582b22014-05-22 11:23:21 +0000498static unsigned getReg(const void *D, unsigned RC, unsigned RegNo) {
499 const MipsDisassemblerBase *Dis = static_cast<const MipsDisassemblerBase*>(D);
500 const MCRegisterInfo *RegInfo = Dis->getContext().getRegisterInfo();
501 return *(RegInfo->getRegClass(RC).begin() + RegNo);
502}
503
Daniel Sandersb50ccf82014-04-01 10:35:28 +0000504template <typename InsnType>
505static DecodeStatus DecodeINSVE_DF(MCInst &MI, InsnType insn, uint64_t Address,
506 const void *Decoder) {
507 typedef DecodeStatus (*DecodeFN)(MCInst &, unsigned, uint64_t, const void *);
508 // The size of the n field depends on the element size
509 // The register class also depends on this.
510 InsnType tmp = fieldFromInstruction(insn, 17, 5);
511 unsigned NSize = 0;
512 DecodeFN RegDecoder = nullptr;
513 if ((tmp & 0x18) == 0x00) { // INSVE_B
514 NSize = 4;
515 RegDecoder = DecodeMSA128BRegisterClass;
516 } else if ((tmp & 0x1c) == 0x10) { // INSVE_H
517 NSize = 3;
518 RegDecoder = DecodeMSA128HRegisterClass;
519 } else if ((tmp & 0x1e) == 0x18) { // INSVE_W
520 NSize = 2;
521 RegDecoder = DecodeMSA128WRegisterClass;
522 } else if ((tmp & 0x1f) == 0x1c) { // INSVE_D
523 NSize = 1;
524 RegDecoder = DecodeMSA128DRegisterClass;
525 } else
526 llvm_unreachable("Invalid encoding");
527
528 assert(NSize != 0 && RegDecoder != nullptr);
529
530 // $wd
531 tmp = fieldFromInstruction(insn, 6, 5);
532 if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler::Fail)
533 return MCDisassembler::Fail;
534 // $wd_in
535 if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler::Fail)
536 return MCDisassembler::Fail;
537 // $n
538 tmp = fieldFromInstruction(insn, 16, NSize);
539 MI.addOperand(MCOperand::CreateImm(tmp));
540 // $ws
541 tmp = fieldFromInstruction(insn, 11, 5);
542 if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler::Fail)
543 return MCDisassembler::Fail;
544 // $n2
545 MI.addOperand(MCOperand::CreateImm(0));
546
547 return MCDisassembler::Success;
548}
549
Daniel Sanders5c582b22014-05-22 11:23:21 +0000550template <typename InsnType>
551static DecodeStatus DecodeAddiGroupBranch(MCInst &MI, InsnType insn,
552 uint64_t Address,
553 const void *Decoder) {
554 // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled
555 // (otherwise we would have matched the ADDI instruction from the earlier
556 // ISA's instead).
557 //
558 // We have:
559 // 0b001000 sssss ttttt iiiiiiiiiiiiiiii
560 // BOVC if rs >= rt
561 // BEQZALC if rs == 0 && rt != 0
562 // BEQC if rs < rt && rs != 0
563
564 InsnType Rs = fieldFromInstruction(insn, 21, 5);
565 InsnType Rt = fieldFromInstruction(insn, 16, 5);
Alexey Samsonovd37bab62014-09-02 17:49:16 +0000566 InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4;
Daniel Sanders5c582b22014-05-22 11:23:21 +0000567 bool HasRs = false;
568
569 if (Rs >= Rt) {
570 MI.setOpcode(Mips::BOVC);
571 HasRs = true;
572 } else if (Rs != 0 && Rs < Rt) {
573 MI.setOpcode(Mips::BEQC);
574 HasRs = true;
575 } else
576 MI.setOpcode(Mips::BEQZALC);
577
578 if (HasRs)
579 MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID,
580 Rs)));
581
582 MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID,
583 Rt)));
584 MI.addOperand(MCOperand::CreateImm(Imm));
585
586 return MCDisassembler::Success;
587}
588
589template <typename InsnType>
590static DecodeStatus DecodeDaddiGroupBranch(MCInst &MI, InsnType insn,
591 uint64_t Address,
592 const void *Decoder) {
593 // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled
594 // (otherwise we would have matched the ADDI instruction from the earlier
595 // ISA's instead).
596 //
597 // We have:
598 // 0b011000 sssss ttttt iiiiiiiiiiiiiiii
599 // BNVC if rs >= rt
600 // BNEZALC if rs == 0 && rt != 0
601 // BNEC if rs < rt && rs != 0
602
603 InsnType Rs = fieldFromInstruction(insn, 21, 5);
604 InsnType Rt = fieldFromInstruction(insn, 16, 5);
Alexey Samsonovd37bab62014-09-02 17:49:16 +0000605 InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4;
Daniel Sanders5c582b22014-05-22 11:23:21 +0000606 bool HasRs = false;
607
608 if (Rs >= Rt) {
609 MI.setOpcode(Mips::BNVC);
610 HasRs = true;
611 } else if (Rs != 0 && Rs < Rt) {
612 MI.setOpcode(Mips::BNEC);
613 HasRs = true;
614 } else
615 MI.setOpcode(Mips::BNEZALC);
616
617 if (HasRs)
618 MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID,
619 Rs)));
620
621 MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID,
622 Rt)));
623 MI.addOperand(MCOperand::CreateImm(Imm));
624
625 return MCDisassembler::Success;
626}
627
628template <typename InsnType>
629static DecodeStatus DecodeBlezlGroupBranch(MCInst &MI, InsnType insn,
630 uint64_t Address,
631 const void *Decoder) {
632 // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled
633 // (otherwise we would have matched the BLEZL instruction from the earlier
634 // ISA's instead).
635 //
636 // We have:
637 // 0b010110 sssss ttttt iiiiiiiiiiiiiiii
638 // Invalid if rs == 0
639 // BLEZC if rs == 0 && rt != 0
640 // BGEZC if rs == rt && rt != 0
641 // BGEC if rs != rt && rs != 0 && rt != 0
642
643 InsnType Rs = fieldFromInstruction(insn, 21, 5);
644 InsnType Rt = fieldFromInstruction(insn, 16, 5);
Alexey Samsonovd37bab62014-09-02 17:49:16 +0000645 InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4;
Zoran Jovanovic28a0ca02014-06-12 11:47:44 +0000646 bool HasRs = false;
Daniel Sanders5c582b22014-05-22 11:23:21 +0000647
648 if (Rt == 0)
649 return MCDisassembler::Fail;
650 else if (Rs == 0)
651 MI.setOpcode(Mips::BLEZC);
652 else if (Rs == Rt)
653 MI.setOpcode(Mips::BGEZC);
Zoran Jovanovic28a0ca02014-06-12 11:47:44 +0000654 else {
655 HasRs = true;
656 MI.setOpcode(Mips::BGEC);
657 }
658
659 if (HasRs)
660 MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID,
661 Rs)));
Daniel Sanders5c582b22014-05-22 11:23:21 +0000662
663 MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID,
664 Rt)));
665
666 MI.addOperand(MCOperand::CreateImm(Imm));
667
668 return MCDisassembler::Success;
669}
670
671template <typename InsnType>
672static DecodeStatus DecodeBgtzlGroupBranch(MCInst &MI, InsnType insn,
673 uint64_t Address,
674 const void *Decoder) {
675 // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled
676 // (otherwise we would have matched the BGTZL instruction from the earlier
677 // ISA's instead).
678 //
679 // We have:
680 // 0b010111 sssss ttttt iiiiiiiiiiiiiiii
681 // Invalid if rs == 0
682 // BGTZC if rs == 0 && rt != 0
683 // BLTZC if rs == rt && rt != 0
684 // BLTC if rs != rt && rs != 0 && rt != 0
685
Zoran Jovanovic5c14b062014-06-18 14:36:00 +0000686 bool HasRs = false;
687
Daniel Sanders5c582b22014-05-22 11:23:21 +0000688 InsnType Rs = fieldFromInstruction(insn, 21, 5);
689 InsnType Rt = fieldFromInstruction(insn, 16, 5);
Alexey Samsonovd37bab62014-09-02 17:49:16 +0000690 InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4;
Daniel Sanders5c582b22014-05-22 11:23:21 +0000691
692 if (Rt == 0)
693 return MCDisassembler::Fail;
694 else if (Rs == 0)
695 MI.setOpcode(Mips::BGTZC);
696 else if (Rs == Rt)
697 MI.setOpcode(Mips::BLTZC);
Zoran Jovanovic5c14b062014-06-18 14:36:00 +0000698 else {
699 MI.setOpcode(Mips::BLTC);
700 HasRs = true;
701 }
702
703 if (HasRs)
704 MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID,
705 Rs)));
Daniel Sanders5c582b22014-05-22 11:23:21 +0000706
707 MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID,
708 Rt)));
709
710 MI.addOperand(MCOperand::CreateImm(Imm));
711
712 return MCDisassembler::Success;
713}
714
715template <typename InsnType>
716static DecodeStatus DecodeBgtzGroupBranch(MCInst &MI, InsnType insn,
717 uint64_t Address,
718 const void *Decoder) {
719 // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled
720 // (otherwise we would have matched the BGTZ instruction from the earlier
721 // ISA's instead).
722 //
723 // We have:
724 // 0b000111 sssss ttttt iiiiiiiiiiiiiiii
725 // BGTZ if rt == 0
726 // BGTZALC if rs == 0 && rt != 0
727 // BLTZALC if rs != 0 && rs == rt
728 // BLTUC if rs != 0 && rs != rt
729
730 InsnType Rs = fieldFromInstruction(insn, 21, 5);
731 InsnType Rt = fieldFromInstruction(insn, 16, 5);
Alexey Samsonovd37bab62014-09-02 17:49:16 +0000732 InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4;
Daniel Sanders5c582b22014-05-22 11:23:21 +0000733 bool HasRs = false;
734 bool HasRt = false;
735
736 if (Rt == 0) {
737 MI.setOpcode(Mips::BGTZ);
738 HasRs = true;
739 } else if (Rs == 0) {
740 MI.setOpcode(Mips::BGTZALC);
741 HasRt = true;
742 } else if (Rs == Rt) {
743 MI.setOpcode(Mips::BLTZALC);
744 HasRs = true;
Zoran Jovanovic5c14b062014-06-18 14:36:00 +0000745 } else {
746 MI.setOpcode(Mips::BLTUC);
747 HasRs = true;
748 HasRt = true;
749 }
Daniel Sanders5c582b22014-05-22 11:23:21 +0000750
751 if (HasRs)
752 MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID,
753 Rs)));
754
755 if (HasRt)
756 MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID,
757 Rt)));
758
759 MI.addOperand(MCOperand::CreateImm(Imm));
760
761 return MCDisassembler::Success;
762}
763
Zoran Jovanovic28a0ca02014-06-12 11:47:44 +0000764template <typename InsnType>
765static DecodeStatus DecodeBlezGroupBranch(MCInst &MI, InsnType insn,
766 uint64_t Address,
767 const void *Decoder) {
768 // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled
769 // (otherwise we would have matched the BLEZL instruction from the earlier
770 // ISA's instead).
771 //
772 // We have:
773 // 0b000110 sssss ttttt iiiiiiiiiiiiiiii
774 // Invalid if rs == 0
775 // BLEZALC if rs == 0 && rt != 0
776 // BGEZALC if rs == rt && rt != 0
777 // BGEUC if rs != rt && rs != 0 && rt != 0
778
779 InsnType Rs = fieldFromInstruction(insn, 21, 5);
780 InsnType Rt = fieldFromInstruction(insn, 16, 5);
Alexey Samsonovd37bab62014-09-02 17:49:16 +0000781 InsnType Imm = SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4;
Zoran Jovanovic28a0ca02014-06-12 11:47:44 +0000782 bool HasRs = false;
783
784 if (Rt == 0)
785 return MCDisassembler::Fail;
786 else if (Rs == 0)
787 MI.setOpcode(Mips::BLEZALC);
788 else if (Rs == Rt)
789 MI.setOpcode(Mips::BGEZALC);
790 else {
791 HasRs = true;
792 MI.setOpcode(Mips::BGEUC);
793 }
794
795 if (HasRs)
796 MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID,
797 Rs)));
798 MI.addOperand(MCOperand::CreateReg(getReg(Decoder, Mips::GPR32RegClassID,
799 Rt)));
800
801 MI.addOperand(MCOperand::CreateImm(Imm));
802
803 return MCDisassembler::Success;
804}
805
Jozef Kolekea22c4c2014-11-24 13:29:59 +0000806/// Read two bytes from the ArrayRef and return 16 bit halfword sorted
807/// according to the given endianess.
808static DecodeStatus readInstruction16(ArrayRef<uint8_t> Bytes, uint64_t Address,
809 uint64_t &Size, uint32_t &Insn,
810 bool IsBigEndian) {
811 // We want to read exactly 2 Bytes of data.
812 if (Bytes.size() < 2) {
813 Size = 0;
814 return MCDisassembler::Fail;
815 }
816
817 if (IsBigEndian) {
818 Insn = (Bytes[0] << 8) | Bytes[1];
819 } else {
820 Insn = (Bytes[1] << 8) | Bytes[0];
821 }
822
823 return MCDisassembler::Success;
824}
825
Rafael Espindola7fc5b872014-11-12 02:04:27 +0000826/// Read four bytes from the ArrayRef and return 32 bit word sorted
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000827/// according to the given endianess
Rafael Espindola7fc5b872014-11-12 02:04:27 +0000828static DecodeStatus readInstruction32(ArrayRef<uint8_t> Bytes, uint64_t Address,
829 uint64_t &Size, uint32_t &Insn,
830 bool IsBigEndian, bool IsMicroMips) {
Akira Hatanaka71928e62012-04-17 18:03:21 +0000831 // We want to read exactly 4 Bytes of data.
Rafael Espindola7fc5b872014-11-12 02:04:27 +0000832 if (Bytes.size() < 4) {
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000833 Size = 0;
Akira Hatanaka71928e62012-04-17 18:03:21 +0000834 return MCDisassembler::Fail;
835 }
836
Jozef Kolekea22c4c2014-11-24 13:29:59 +0000837 // High 16 bits of a 32-bit microMIPS instruction (where the opcode is)
838 // always precede the low 16 bits in the instruction stream (that is, they
839 // are placed at lower addresses in the instruction stream).
840 //
841 // microMIPS byte ordering:
842 // Big-endian: 0 | 1 | 2 | 3
843 // Little-endian: 1 | 0 | 3 | 2
844
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000845 if (IsBigEndian) {
Akira Hatanaka71928e62012-04-17 18:03:21 +0000846 // Encoded as a big-endian 32-bit word in the stream.
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000847 Insn =
848 (Bytes[3] << 0) | (Bytes[2] << 8) | (Bytes[1] << 16) | (Bytes[0] << 24);
849 } else {
Vladimir Medicdde3d582013-09-06 12:30:36 +0000850 if (IsMicroMips) {
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000851 Insn = (Bytes[2] << 0) | (Bytes[3] << 8) | (Bytes[0] << 16) |
Vladimir Medicdde3d582013-09-06 12:30:36 +0000852 (Bytes[1] << 24);
853 } else {
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000854 Insn = (Bytes[0] << 0) | (Bytes[1] << 8) | (Bytes[2] << 16) |
Vladimir Medicdde3d582013-09-06 12:30:36 +0000855 (Bytes[3] << 24);
856 }
Akira Hatanaka71928e62012-04-17 18:03:21 +0000857 }
858
859 return MCDisassembler::Success;
860}
861
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000862DecodeStatus MipsDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,
Rafael Espindola7fc5b872014-11-12 02:04:27 +0000863 ArrayRef<uint8_t> Bytes,
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000864 uint64_t Address,
865 raw_ostream &VStream,
866 raw_ostream &CStream) const {
Akira Hatanaka71928e62012-04-17 18:03:21 +0000867 uint32_t Insn;
Jozef Kolekea22c4c2014-11-24 13:29:59 +0000868 DecodeStatus Result;
Akira Hatanaka71928e62012-04-17 18:03:21 +0000869
Vladimir Medicdde3d582013-09-06 12:30:36 +0000870 if (IsMicroMips) {
Jozef Kolekea22c4c2014-11-24 13:29:59 +0000871 Result = readInstruction16(Bytes, Address, Size, Insn, IsBigEndian);
872
873 DEBUG(dbgs() << "Trying MicroMips16 table (16-bit instructions):\n");
874 // Calling the auto-generated decoder function.
875 Result = decodeInstruction(DecoderTableMicroMips16, Instr, Insn, Address,
876 this, STI);
877 if (Result != MCDisassembler::Fail) {
878 Size = 2;
879 return Result;
880 }
881
882 Result = readInstruction32(Bytes, Address, Size, Insn, IsBigEndian, true);
883 if (Result == MCDisassembler::Fail)
884 return MCDisassembler::Fail;
885
886 DEBUG(dbgs() << "Trying MicroMips32 table (32-bit instructions):\n");
Vladimir Medicdde3d582013-09-06 12:30:36 +0000887 // Calling the auto-generated decoder function.
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000888 Result = decodeInstruction(DecoderTableMicroMips32, Instr, Insn, Address,
Vladimir Medicdde3d582013-09-06 12:30:36 +0000889 this, STI);
890 if (Result != MCDisassembler::Fail) {
891 Size = 4;
892 return Result;
893 }
894 return MCDisassembler::Fail;
895 }
896
Jozef Kolekea22c4c2014-11-24 13:29:59 +0000897 Result = readInstruction32(Bytes, Address, Size, Insn, IsBigEndian, false);
898 if (Result == MCDisassembler::Fail)
899 return MCDisassembler::Fail;
900
Daniel Sandersc171f652014-06-13 13:15:59 +0000901 if (hasCOP3()) {
902 DEBUG(dbgs() << "Trying COP3_ table (32-bit opcodes):\n");
903 Result =
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000904 decodeInstruction(DecoderTableCOP3_32, Instr, Insn, Address, this, STI);
Daniel Sandersc171f652014-06-13 13:15:59 +0000905 if (Result != MCDisassembler::Fail) {
906 Size = 4;
907 return Result;
908 }
909 }
910
911 if (hasMips32r6() && isGP64()) {
Daniel Sanders0fa60412014-06-12 13:39:06 +0000912 DEBUG(dbgs() << "Trying Mips32r6_64r6 (GPR64) table (32-bit opcodes):\n");
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000913 Result = decodeInstruction(DecoderTableMips32r6_64r6_GP6432, Instr, Insn,
Daniel Sanders0fa60412014-06-12 13:39:06 +0000914 Address, this, STI);
915 if (Result != MCDisassembler::Fail) {
916 Size = 4;
917 return Result;
918 }
919 }
920
Daniel Sandersc171f652014-06-13 13:15:59 +0000921 if (hasMips32r6()) {
Daniel Sanders0fa60412014-06-12 13:39:06 +0000922 DEBUG(dbgs() << "Trying Mips32r6_64r6 table (32-bit opcodes):\n");
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000923 Result = decodeInstruction(DecoderTableMips32r6_64r632, Instr, Insn,
Daniel Sanders5c582b22014-05-22 11:23:21 +0000924 Address, this, STI);
925 if (Result != MCDisassembler::Fail) {
926 Size = 4;
927 return Result;
928 }
929 }
930
Daniel Sanders0fa60412014-06-12 13:39:06 +0000931 DEBUG(dbgs() << "Trying Mips table (32-bit opcodes):\n");
Akira Hatanaka71928e62012-04-17 18:03:21 +0000932 // Calling the auto-generated decoder function.
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000933 Result =
934 decodeInstruction(DecoderTableMips32, Instr, Insn, Address, this, STI);
Akira Hatanaka71928e62012-04-17 18:03:21 +0000935 if (Result != MCDisassembler::Fail) {
936 Size = 4;
937 return Result;
938 }
939
940 return MCDisassembler::Fail;
941}
942
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000943DecodeStatus Mips64Disassembler::getInstruction(MCInst &Instr, uint64_t &Size,
Rafael Espindola7fc5b872014-11-12 02:04:27 +0000944 ArrayRef<uint8_t> Bytes,
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000945 uint64_t Address,
946 raw_ostream &VStream,
947 raw_ostream &CStream) const {
Akira Hatanaka71928e62012-04-17 18:03:21 +0000948 uint32_t Insn;
949
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000950 DecodeStatus Result =
Rafael Espindola7fc5b872014-11-12 02:04:27 +0000951 readInstruction32(Bytes, Address, Size, Insn, IsBigEndian, false);
Akira Hatanaka71928e62012-04-17 18:03:21 +0000952 if (Result == MCDisassembler::Fail)
953 return MCDisassembler::Fail;
954
955 // Calling the auto-generated decoder function.
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000956 Result =
957 decodeInstruction(DecoderTableMips6432, Instr, Insn, Address, this, STI);
Akira Hatanaka71928e62012-04-17 18:03:21 +0000958 if (Result != MCDisassembler::Fail) {
959 Size = 4;
960 return Result;
961 }
962 // If we fail to decode in Mips64 decoder space we can try in Mips32
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000963 Result =
964 decodeInstruction(DecoderTableMips32, Instr, Insn, Address, this, STI);
Akira Hatanaka71928e62012-04-17 18:03:21 +0000965 if (Result != MCDisassembler::Fail) {
966 Size = 4;
967 return Result;
968 }
969
970 return MCDisassembler::Fail;
971}
972
Reed Kotlerec8a5492013-02-14 03:05:25 +0000973static DecodeStatus DecodeCPU16RegsRegisterClass(MCInst &Inst,
974 unsigned RegNo,
975 uint64_t Address,
976 const void *Decoder) {
977
978 return MCDisassembler::Fail;
979
980}
981
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000982static DecodeStatus DecodeGPR64RegisterClass(MCInst &Inst,
983 unsigned RegNo,
984 uint64_t Address,
985 const void *Decoder) {
Akira Hatanaka71928e62012-04-17 18:03:21 +0000986
987 if (RegNo > 31)
988 return MCDisassembler::Fail;
989
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000990 unsigned Reg = getReg(Decoder, Mips::GPR64RegClassID, RegNo);
Akira Hatanaka9bf2b562012-07-09 18:46:47 +0000991 Inst.addOperand(MCOperand::CreateReg(Reg));
Akira Hatanaka71928e62012-04-17 18:03:21 +0000992 return MCDisassembler::Success;
993}
994
Zoran Jovanovicb0852e52014-10-21 08:23:11 +0000995static DecodeStatus DecodeGPRMM16RegisterClass(MCInst &Inst,
996 unsigned RegNo,
997 uint64_t Address,
998 const void *Decoder) {
Jozef Kolekea22c4c2014-11-24 13:29:59 +0000999 if (RegNo > 7)
1000 return MCDisassembler::Fail;
1001 unsigned Reg = getReg(Decoder, Mips::GPRMM16RegClassID, RegNo);
1002 Inst.addOperand(MCOperand::CreateReg(Reg));
1003 return MCDisassembler::Success;
Zoran Jovanovicb0852e52014-10-21 08:23:11 +00001004}
1005
Jozef Kolek1904fa22014-11-24 14:25:53 +00001006static DecodeStatus DecodeGPRMM16ZeroRegisterClass(MCInst &Inst,
1007 unsigned RegNo,
1008 uint64_t Address,
1009 const void *Decoder) {
Jozef Kolek315e7ec2014-11-26 18:56:38 +00001010 if (RegNo > 7)
1011 return MCDisassembler::Fail;
1012 unsigned Reg = getReg(Decoder, Mips::GPRMM16ZeroRegClassID, RegNo);
1013 Inst.addOperand(MCOperand::CreateReg(Reg));
1014 return MCDisassembler::Success;
Jozef Kolek1904fa22014-11-24 14:25:53 +00001015}
1016
Zoran Jovanovic41688672015-02-10 16:36:20 +00001017static DecodeStatus DecodeGPRMM16MovePRegisterClass(MCInst &Inst,
1018 unsigned RegNo,
1019 uint64_t Address,
1020 const void *Decoder) {
1021 if (RegNo > 7)
1022 return MCDisassembler::Fail;
1023 unsigned Reg = getReg(Decoder, Mips::GPRMM16MovePRegClassID, RegNo);
1024 Inst.addOperand(MCOperand::CreateReg(Reg));
1025 return MCDisassembler::Success;
1026}
1027
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +00001028static DecodeStatus DecodeGPR32RegisterClass(MCInst &Inst,
1029 unsigned RegNo,
1030 uint64_t Address,
1031 const void *Decoder) {
Akira Hatanaka71928e62012-04-17 18:03:21 +00001032 if (RegNo > 31)
1033 return MCDisassembler::Fail;
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +00001034 unsigned Reg = getReg(Decoder, Mips::GPR32RegClassID, RegNo);
Akira Hatanaka9bf2b562012-07-09 18:46:47 +00001035 Inst.addOperand(MCOperand::CreateReg(Reg));
Akira Hatanaka71928e62012-04-17 18:03:21 +00001036 return MCDisassembler::Success;
1037}
1038
Akira Hatanaka9bfa2e22013-08-28 00:55:15 +00001039static DecodeStatus DecodePtrRegisterClass(MCInst &Inst,
1040 unsigned RegNo,
1041 uint64_t Address,
1042 const void *Decoder) {
Vladimir Medice8860932014-12-16 15:29:12 +00001043 if (static_cast<const MipsDisassembler *>(Decoder)->isGP64Bit())
Akira Hatanaka9bfa2e22013-08-28 00:55:15 +00001044 return DecodeGPR64RegisterClass(Inst, RegNo, Address, Decoder);
1045
1046 return DecodeGPR32RegisterClass(Inst, RegNo, Address, Decoder);
1047}
1048
Akira Hatanaka654655f2013-08-14 00:53:38 +00001049static DecodeStatus DecodeDSPRRegisterClass(MCInst &Inst,
1050 unsigned RegNo,
1051 uint64_t Address,
1052 const void *Decoder) {
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +00001053 return DecodeGPR32RegisterClass(Inst, RegNo, Address, Decoder);
Akira Hatanakaecabd1a2012-09-27 02:01:10 +00001054}
1055
Akira Hatanaka71928e62012-04-17 18:03:21 +00001056static DecodeStatus DecodeFGR64RegisterClass(MCInst &Inst,
1057 unsigned RegNo,
1058 uint64_t Address,
1059 const void *Decoder) {
1060 if (RegNo > 31)
1061 return MCDisassembler::Fail;
1062
Akira Hatanaka9bf2b562012-07-09 18:46:47 +00001063 unsigned Reg = getReg(Decoder, Mips::FGR64RegClassID, RegNo);
1064 Inst.addOperand(MCOperand::CreateReg(Reg));
Akira Hatanaka71928e62012-04-17 18:03:21 +00001065 return MCDisassembler::Success;
1066}
1067
1068static DecodeStatus DecodeFGR32RegisterClass(MCInst &Inst,
1069 unsigned RegNo,
1070 uint64_t Address,
1071 const void *Decoder) {
1072 if (RegNo > 31)
1073 return MCDisassembler::Fail;
1074
Akira Hatanaka9bf2b562012-07-09 18:46:47 +00001075 unsigned Reg = getReg(Decoder, Mips::FGR32RegClassID, RegNo);
1076 Inst.addOperand(MCOperand::CreateReg(Reg));
Akira Hatanaka71928e62012-04-17 18:03:21 +00001077 return MCDisassembler::Success;
1078}
1079
1080static DecodeStatus DecodeCCRRegisterClass(MCInst &Inst,
1081 unsigned RegNo,
1082 uint64_t Address,
1083 const void *Decoder) {
Chad Rosier253777f2013-06-26 22:23:32 +00001084 if (RegNo > 31)
1085 return MCDisassembler::Fail;
1086 unsigned Reg = getReg(Decoder, Mips::CCRRegClassID, RegNo);
1087 Inst.addOperand(MCOperand::CreateReg(Reg));
Akira Hatanaka71928e62012-04-17 18:03:21 +00001088 return MCDisassembler::Success;
1089}
1090
Akira Hatanaka1fb1b8b2013-07-26 20:13:47 +00001091static DecodeStatus DecodeFCCRegisterClass(MCInst &Inst,
1092 unsigned RegNo,
1093 uint64_t Address,
1094 const void *Decoder) {
1095 if (RegNo > 7)
1096 return MCDisassembler::Fail;
1097 unsigned Reg = getReg(Decoder, Mips::FCCRegClassID, RegNo);
1098 Inst.addOperand(MCOperand::CreateReg(Reg));
1099 return MCDisassembler::Success;
1100}
1101
Daniel Sanders0fa60412014-06-12 13:39:06 +00001102static DecodeStatus DecodeFGRCCRegisterClass(MCInst &Inst, unsigned RegNo,
1103 uint64_t Address,
1104 const void *Decoder) {
1105 if (RegNo > 31)
1106 return MCDisassembler::Fail;
1107
1108 unsigned Reg = getReg(Decoder, Mips::FGRCCRegClassID, RegNo);
1109 Inst.addOperand(MCOperand::CreateReg(Reg));
1110 return MCDisassembler::Success;
1111}
1112
Akira Hatanaka71928e62012-04-17 18:03:21 +00001113static DecodeStatus DecodeMem(MCInst &Inst,
1114 unsigned Insn,
1115 uint64_t Address,
1116 const void *Decoder) {
1117 int Offset = SignExtend32<16>(Insn & 0xffff);
Jim Grosbachecaef492012-08-14 19:06:05 +00001118 unsigned Reg = fieldFromInstruction(Insn, 16, 5);
1119 unsigned Base = fieldFromInstruction(Insn, 21, 5);
Akira Hatanaka9bf2b562012-07-09 18:46:47 +00001120
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +00001121 Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg);
1122 Base = getReg(Decoder, Mips::GPR32RegClassID, Base);
Akira Hatanaka71928e62012-04-17 18:03:21 +00001123
Vladimir Medicd7ecf492014-12-15 16:19:34 +00001124 if(Inst.getOpcode() == Mips::SC ||
1125 Inst.getOpcode() == Mips::SCD){
Akira Hatanaka9bf2b562012-07-09 18:46:47 +00001126 Inst.addOperand(MCOperand::CreateReg(Reg));
Akira Hatanaka71928e62012-04-17 18:03:21 +00001127 }
1128
Akira Hatanaka9bf2b562012-07-09 18:46:47 +00001129 Inst.addOperand(MCOperand::CreateReg(Reg));
1130 Inst.addOperand(MCOperand::CreateReg(Base));
Akira Hatanaka71928e62012-04-17 18:03:21 +00001131 Inst.addOperand(MCOperand::CreateImm(Offset));
1132
1133 return MCDisassembler::Success;
1134}
1135
Daniel Sanders92db6b72014-10-01 08:26:55 +00001136static DecodeStatus DecodeCacheOp(MCInst &Inst,
1137 unsigned Insn,
1138 uint64_t Address,
1139 const void *Decoder) {
1140 int Offset = SignExtend32<16>(Insn & 0xffff);
1141 unsigned Hint = fieldFromInstruction(Insn, 16, 5);
1142 unsigned Base = fieldFromInstruction(Insn, 21, 5);
1143
1144 Base = getReg(Decoder, Mips::GPR32RegClassID, Base);
1145
1146 Inst.addOperand(MCOperand::CreateReg(Base));
1147 Inst.addOperand(MCOperand::CreateImm(Offset));
1148 Inst.addOperand(MCOperand::CreateImm(Hint));
1149
1150 return MCDisassembler::Success;
1151}
1152
Jozef Kolekab6d1cc2014-12-23 19:55:34 +00001153static DecodeStatus DecodeCacheOpMM(MCInst &Inst,
1154 unsigned Insn,
1155 uint64_t Address,
1156 const void *Decoder) {
1157 int Offset = SignExtend32<12>(Insn & 0xfff);
1158 unsigned Base = fieldFromInstruction(Insn, 16, 5);
1159 unsigned Hint = fieldFromInstruction(Insn, 21, 5);
1160
1161 Base = getReg(Decoder, Mips::GPR32RegClassID, Base);
1162
1163 Inst.addOperand(MCOperand::CreateReg(Base));
1164 Inst.addOperand(MCOperand::CreateImm(Offset));
1165 Inst.addOperand(MCOperand::CreateImm(Hint));
1166
1167 return MCDisassembler::Success;
1168}
1169
Vladimir Medicdf464ae2015-01-29 11:33:41 +00001170static DecodeStatus DecodeCacheOpR6(MCInst &Inst,
1171 unsigned Insn,
1172 uint64_t Address,
1173 const void *Decoder) {
1174 int Offset = fieldFromInstruction(Insn, 7, 9);
1175 unsigned Hint = fieldFromInstruction(Insn, 16, 5);
1176 unsigned Base = fieldFromInstruction(Insn, 21, 5);
1177
1178 Base = getReg(Decoder, Mips::GPR32RegClassID, Base);
1179
1180 Inst.addOperand(MCOperand::CreateReg(Base));
1181 Inst.addOperand(MCOperand::CreateImm(Offset));
1182 Inst.addOperand(MCOperand::CreateImm(Hint));
1183
1184 return MCDisassembler::Success;
1185}
1186
Daniel Sandersb4484d62014-11-27 17:28:10 +00001187static DecodeStatus DecodeSyncI(MCInst &Inst,
1188 unsigned Insn,
1189 uint64_t Address,
1190 const void *Decoder) {
1191 int Offset = SignExtend32<16>(Insn & 0xffff);
1192 unsigned Base = fieldFromInstruction(Insn, 21, 5);
1193
1194 Base = getReg(Decoder, Mips::GPR32RegClassID, Base);
1195
1196 Inst.addOperand(MCOperand::CreateReg(Base));
1197 Inst.addOperand(MCOperand::CreateImm(Offset));
1198
1199 return MCDisassembler::Success;
1200}
1201
Matheus Almeidafe0bf9f2013-10-21 13:07:13 +00001202static DecodeStatus DecodeMSA128Mem(MCInst &Inst, unsigned Insn,
1203 uint64_t Address, const void *Decoder) {
1204 int Offset = SignExtend32<10>(fieldFromInstruction(Insn, 16, 10));
1205 unsigned Reg = fieldFromInstruction(Insn, 6, 5);
1206 unsigned Base = fieldFromInstruction(Insn, 11, 5);
1207
1208 Reg = getReg(Decoder, Mips::MSA128BRegClassID, Reg);
1209 Base = getReg(Decoder, Mips::GPR32RegClassID, Base);
1210
1211 Inst.addOperand(MCOperand::CreateReg(Reg));
1212 Inst.addOperand(MCOperand::CreateReg(Base));
Matheus Almeida6b59c442013-12-05 11:06:22 +00001213
1214 // The immediate field of an LD/ST instruction is scaled which means it must
1215 // be multiplied (when decoding) by the size (in bytes) of the instructions'
1216 // data format.
1217 // .b - 1 byte
1218 // .h - 2 bytes
1219 // .w - 4 bytes
1220 // .d - 8 bytes
1221 switch(Inst.getOpcode())
1222 {
1223 default:
1224 assert (0 && "Unexpected instruction");
1225 return MCDisassembler::Fail;
1226 break;
1227 case Mips::LD_B:
1228 case Mips::ST_B:
1229 Inst.addOperand(MCOperand::CreateImm(Offset));
1230 break;
1231 case Mips::LD_H:
1232 case Mips::ST_H:
Alexey Samsonovd37bab62014-09-02 17:49:16 +00001233 Inst.addOperand(MCOperand::CreateImm(Offset * 2));
Matheus Almeida6b59c442013-12-05 11:06:22 +00001234 break;
1235 case Mips::LD_W:
1236 case Mips::ST_W:
Alexey Samsonovd37bab62014-09-02 17:49:16 +00001237 Inst.addOperand(MCOperand::CreateImm(Offset * 4));
Matheus Almeida6b59c442013-12-05 11:06:22 +00001238 break;
1239 case Mips::LD_D:
1240 case Mips::ST_D:
Alexey Samsonovd37bab62014-09-02 17:49:16 +00001241 Inst.addOperand(MCOperand::CreateImm(Offset * 8));
Matheus Almeida6b59c442013-12-05 11:06:22 +00001242 break;
1243 }
Matheus Almeidafe0bf9f2013-10-21 13:07:13 +00001244
1245 return MCDisassembler::Success;
1246}
1247
Jozef Kolek315e7ec2014-11-26 18:56:38 +00001248static DecodeStatus DecodeMemMMImm4(MCInst &Inst,
1249 unsigned Insn,
1250 uint64_t Address,
1251 const void *Decoder) {
1252 unsigned Offset = Insn & 0xf;
1253 unsigned Reg = fieldFromInstruction(Insn, 7, 3);
1254 unsigned Base = fieldFromInstruction(Insn, 4, 3);
1255
1256 switch (Inst.getOpcode()) {
1257 case Mips::LBU16_MM:
1258 case Mips::LHU16_MM:
1259 case Mips::LW16_MM:
1260 if (DecodeGPRMM16RegisterClass(Inst, Reg, Address, Decoder)
1261 == MCDisassembler::Fail)
1262 return MCDisassembler::Fail;
1263 break;
1264 case Mips::SB16_MM:
1265 case Mips::SH16_MM:
1266 case Mips::SW16_MM:
1267 if (DecodeGPRMM16ZeroRegisterClass(Inst, Reg, Address, Decoder)
1268 == MCDisassembler::Fail)
1269 return MCDisassembler::Fail;
1270 break;
1271 }
1272
1273 if (DecodeGPRMM16RegisterClass(Inst, Base, Address, Decoder)
1274 == MCDisassembler::Fail)
1275 return MCDisassembler::Fail;
1276
1277 switch (Inst.getOpcode()) {
1278 case Mips::LBU16_MM:
1279 if (Offset == 0xf)
1280 Inst.addOperand(MCOperand::CreateImm(-1));
1281 else
1282 Inst.addOperand(MCOperand::CreateImm(Offset));
1283 break;
1284 case Mips::SB16_MM:
1285 Inst.addOperand(MCOperand::CreateImm(Offset));
1286 break;
1287 case Mips::LHU16_MM:
1288 case Mips::SH16_MM:
1289 Inst.addOperand(MCOperand::CreateImm(Offset << 1));
1290 break;
1291 case Mips::LW16_MM:
1292 case Mips::SW16_MM:
1293 Inst.addOperand(MCOperand::CreateImm(Offset << 2));
1294 break;
1295 }
1296
1297 return MCDisassembler::Success;
1298}
1299
Jozef Kolek12c69822014-12-23 16:16:33 +00001300static DecodeStatus DecodeMemMMSPImm5Lsl2(MCInst &Inst,
1301 unsigned Insn,
1302 uint64_t Address,
1303 const void *Decoder) {
1304 unsigned Offset = Insn & 0x1F;
1305 unsigned Reg = fieldFromInstruction(Insn, 5, 5);
1306
1307 Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg);
1308
1309 Inst.addOperand(MCOperand::CreateReg(Reg));
1310 Inst.addOperand(MCOperand::CreateReg(Mips::SP));
1311 Inst.addOperand(MCOperand::CreateImm(Offset << 2));
1312
1313 return MCDisassembler::Success;
1314}
1315
Jozef Koleke10a02e2015-01-28 17:27:26 +00001316static DecodeStatus DecodeMemMMGPImm7Lsl2(MCInst &Inst,
1317 unsigned Insn,
1318 uint64_t Address,
1319 const void *Decoder) {
1320 unsigned Offset = Insn & 0x7F;
1321 unsigned Reg = fieldFromInstruction(Insn, 7, 3);
1322
1323 Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg);
1324
1325 Inst.addOperand(MCOperand::CreateReg(Reg));
1326 Inst.addOperand(MCOperand::CreateReg(Mips::GP));
1327 Inst.addOperand(MCOperand::CreateImm(Offset << 2));
1328
1329 return MCDisassembler::Success;
1330}
1331
Jozef Kolekd68d424a2015-02-10 12:41:13 +00001332static DecodeStatus DecodeMemMMReglistImm4Lsl2(MCInst &Inst,
1333 unsigned Insn,
1334 uint64_t Address,
1335 const void *Decoder) {
1336 int Offset = SignExtend32<4>(Insn & 0xf);
1337
1338 if (DecodeRegListOperand16(Inst, Insn, Address, Decoder)
1339 == MCDisassembler::Fail)
1340 return MCDisassembler::Fail;
1341
1342 Inst.addOperand(MCOperand::CreateReg(Mips::SP));
1343 Inst.addOperand(MCOperand::CreateImm(Offset << 2));
1344
1345 return MCDisassembler::Success;
1346}
1347
Vladimir Medicdde3d582013-09-06 12:30:36 +00001348static DecodeStatus DecodeMemMMImm12(MCInst &Inst,
1349 unsigned Insn,
1350 uint64_t Address,
1351 const void *Decoder) {
1352 int Offset = SignExtend32<12>(Insn & 0x0fff);
1353 unsigned Reg = fieldFromInstruction(Insn, 21, 5);
1354 unsigned Base = fieldFromInstruction(Insn, 16, 5);
1355
1356 Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg);
1357 Base = getReg(Decoder, Mips::GPR32RegClassID, Base);
1358
Zoran Jovanovica4c4b5f2014-11-19 16:44:02 +00001359 switch (Inst.getOpcode()) {
1360 case Mips::SWM32_MM:
1361 case Mips::LWM32_MM:
1362 if (DecodeRegListOperand(Inst, Insn, Address, Decoder)
1363 == MCDisassembler::Fail)
1364 return MCDisassembler::Fail;
1365 Inst.addOperand(MCOperand::CreateReg(Base));
1366 Inst.addOperand(MCOperand::CreateImm(Offset));
1367 break;
1368 case Mips::SC_MM:
Zoran Jovanovic285cc282014-02-28 18:22:56 +00001369 Inst.addOperand(MCOperand::CreateReg(Reg));
Zoran Jovanovica4c4b5f2014-11-19 16:44:02 +00001370 // fallthrough
1371 default:
1372 Inst.addOperand(MCOperand::CreateReg(Reg));
Zoran Jovanovic2deca342014-12-16 14:59:10 +00001373 if (Inst.getOpcode() == Mips::LWP_MM || Inst.getOpcode() == Mips::SWP_MM)
1374 Inst.addOperand(MCOperand::CreateReg(Reg+1));
1375
Zoran Jovanovica4c4b5f2014-11-19 16:44:02 +00001376 Inst.addOperand(MCOperand::CreateReg(Base));
1377 Inst.addOperand(MCOperand::CreateImm(Offset));
1378 }
Vladimir Medicdde3d582013-09-06 12:30:36 +00001379
1380 return MCDisassembler::Success;
1381}
1382
1383static DecodeStatus DecodeMemMMImm16(MCInst &Inst,
1384 unsigned Insn,
1385 uint64_t Address,
1386 const void *Decoder) {
1387 int Offset = SignExtend32<16>(Insn & 0xffff);
1388 unsigned Reg = fieldFromInstruction(Insn, 21, 5);
1389 unsigned Base = fieldFromInstruction(Insn, 16, 5);
1390
1391 Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg);
1392 Base = getReg(Decoder, Mips::GPR32RegClassID, Base);
1393
1394 Inst.addOperand(MCOperand::CreateReg(Reg));
1395 Inst.addOperand(MCOperand::CreateReg(Base));
1396 Inst.addOperand(MCOperand::CreateImm(Offset));
1397
1398 return MCDisassembler::Success;
1399}
1400
Akira Hatanaka71928e62012-04-17 18:03:21 +00001401static DecodeStatus DecodeFMem(MCInst &Inst,
1402 unsigned Insn,
1403 uint64_t Address,
1404 const void *Decoder) {
1405 int Offset = SignExtend32<16>(Insn & 0xffff);
Jim Grosbachecaef492012-08-14 19:06:05 +00001406 unsigned Reg = fieldFromInstruction(Insn, 16, 5);
1407 unsigned Base = fieldFromInstruction(Insn, 21, 5);
Akira Hatanaka71928e62012-04-17 18:03:21 +00001408
Akira Hatanaka9bf2b562012-07-09 18:46:47 +00001409 Reg = getReg(Decoder, Mips::FGR64RegClassID, Reg);
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +00001410 Base = getReg(Decoder, Mips::GPR32RegClassID, Base);
Akira Hatanaka9bf2b562012-07-09 18:46:47 +00001411
1412 Inst.addOperand(MCOperand::CreateReg(Reg));
1413 Inst.addOperand(MCOperand::CreateReg(Base));
Akira Hatanaka71928e62012-04-17 18:03:21 +00001414 Inst.addOperand(MCOperand::CreateImm(Offset));
1415
1416 return MCDisassembler::Success;
1417}
1418
Daniel Sanders92db6b72014-10-01 08:26:55 +00001419static DecodeStatus DecodeFMem2(MCInst &Inst,
1420 unsigned Insn,
1421 uint64_t Address,
1422 const void *Decoder) {
1423 int Offset = SignExtend32<16>(Insn & 0xffff);
1424 unsigned Reg = fieldFromInstruction(Insn, 16, 5);
1425 unsigned Base = fieldFromInstruction(Insn, 21, 5);
1426
1427 Reg = getReg(Decoder, Mips::COP2RegClassID, Reg);
1428 Base = getReg(Decoder, Mips::GPR32RegClassID, Base);
1429
1430 Inst.addOperand(MCOperand::CreateReg(Reg));
1431 Inst.addOperand(MCOperand::CreateReg(Base));
1432 Inst.addOperand(MCOperand::CreateImm(Offset));
1433
1434 return MCDisassembler::Success;
1435}
1436
1437static DecodeStatus DecodeFMem3(MCInst &Inst,
1438 unsigned Insn,
1439 uint64_t Address,
1440 const void *Decoder) {
1441 int Offset = SignExtend32<16>(Insn & 0xffff);
1442 unsigned Reg = fieldFromInstruction(Insn, 16, 5);
1443 unsigned Base = fieldFromInstruction(Insn, 21, 5);
1444
1445 Reg = getReg(Decoder, Mips::COP3RegClassID, Reg);
1446 Base = getReg(Decoder, Mips::GPR32RegClassID, Base);
1447
1448 Inst.addOperand(MCOperand::CreateReg(Reg));
1449 Inst.addOperand(MCOperand::CreateReg(Base));
1450 Inst.addOperand(MCOperand::CreateImm(Offset));
1451
1452 return MCDisassembler::Success;
1453}
1454
Vladimir Medic435cf8a2015-01-21 10:47:36 +00001455static DecodeStatus DecodeFMemCop2R6(MCInst &Inst,
1456 unsigned Insn,
1457 uint64_t Address,
1458 const void *Decoder) {
1459 int Offset = SignExtend32<11>(Insn & 0x07ff);
1460 unsigned Reg = fieldFromInstruction(Insn, 16, 5);
1461 unsigned Base = fieldFromInstruction(Insn, 11, 5);
1462
1463 Reg = getReg(Decoder, Mips::COP2RegClassID, Reg);
1464 Base = getReg(Decoder, Mips::GPR32RegClassID, Base);
1465
1466 Inst.addOperand(MCOperand::CreateReg(Reg));
1467 Inst.addOperand(MCOperand::CreateReg(Base));
1468 Inst.addOperand(MCOperand::CreateImm(Offset));
1469
1470 return MCDisassembler::Success;
1471}
Daniel Sanders6a803f62014-06-16 13:13:03 +00001472static DecodeStatus DecodeSpecial3LlSc(MCInst &Inst,
1473 unsigned Insn,
1474 uint64_t Address,
1475 const void *Decoder) {
1476 int64_t Offset = SignExtend64<9>((Insn >> 7) & 0x1ff);
1477 unsigned Rt = fieldFromInstruction(Insn, 16, 5);
1478 unsigned Base = fieldFromInstruction(Insn, 21, 5);
1479
1480 Rt = getReg(Decoder, Mips::GPR32RegClassID, Rt);
1481 Base = getReg(Decoder, Mips::GPR32RegClassID, Base);
1482
1483 if(Inst.getOpcode() == Mips::SC_R6 || Inst.getOpcode() == Mips::SCD_R6){
1484 Inst.addOperand(MCOperand::CreateReg(Rt));
1485 }
1486
1487 Inst.addOperand(MCOperand::CreateReg(Rt));
1488 Inst.addOperand(MCOperand::CreateReg(Base));
1489 Inst.addOperand(MCOperand::CreateImm(Offset));
1490
1491 return MCDisassembler::Success;
1492}
Akira Hatanaka71928e62012-04-17 18:03:21 +00001493
1494static DecodeStatus DecodeHWRegsRegisterClass(MCInst &Inst,
1495 unsigned RegNo,
1496 uint64_t Address,
1497 const void *Decoder) {
1498 // Currently only hardware register 29 is supported.
1499 if (RegNo != 29)
1500 return MCDisassembler::Fail;
1501 Inst.addOperand(MCOperand::CreateReg(Mips::HWR29));
1502 return MCDisassembler::Success;
1503}
1504
Akira Hatanaka71928e62012-04-17 18:03:21 +00001505static DecodeStatus DecodeAFGR64RegisterClass(MCInst &Inst,
1506 unsigned RegNo,
1507 uint64_t Address,
1508 const void *Decoder) {
Akira Hatanaka9bf2b562012-07-09 18:46:47 +00001509 if (RegNo > 30 || RegNo %2)
Akira Hatanaka71928e62012-04-17 18:03:21 +00001510 return MCDisassembler::Fail;
1511
Akira Hatanaka9bf2b562012-07-09 18:46:47 +00001512 ;
1513 unsigned Reg = getReg(Decoder, Mips::AFGR64RegClassID, RegNo /2);
1514 Inst.addOperand(MCOperand::CreateReg(Reg));
Akira Hatanaka71928e62012-04-17 18:03:21 +00001515 return MCDisassembler::Success;
1516}
1517
Akira Hatanaka00fcf2e2013-08-08 21:54:26 +00001518static DecodeStatus DecodeACC64DSPRegisterClass(MCInst &Inst,
1519 unsigned RegNo,
1520 uint64_t Address,
1521 const void *Decoder) {
Akira Hatanakaecabd1a2012-09-27 02:01:10 +00001522 if (RegNo >= 4)
1523 return MCDisassembler::Fail;
1524
Akira Hatanaka00fcf2e2013-08-08 21:54:26 +00001525 unsigned Reg = getReg(Decoder, Mips::ACC64DSPRegClassID, RegNo);
Akira Hatanakaecabd1a2012-09-27 02:01:10 +00001526 Inst.addOperand(MCOperand::CreateReg(Reg));
1527 return MCDisassembler::Success;
1528}
1529
Akira Hatanaka8002a3f2013-08-14 00:47:08 +00001530static DecodeStatus DecodeHI32DSPRegisterClass(MCInst &Inst,
1531 unsigned RegNo,
1532 uint64_t Address,
1533 const void *Decoder) {
Akira Hatanaka59bfaf72013-04-18 00:52:44 +00001534 if (RegNo >= 4)
1535 return MCDisassembler::Fail;
1536
Akira Hatanaka8002a3f2013-08-14 00:47:08 +00001537 unsigned Reg = getReg(Decoder, Mips::HI32DSPRegClassID, RegNo);
Akira Hatanaka59bfaf72013-04-18 00:52:44 +00001538 Inst.addOperand(MCOperand::CreateReg(Reg));
1539 return MCDisassembler::Success;
1540}
1541
Akira Hatanaka8002a3f2013-08-14 00:47:08 +00001542static DecodeStatus DecodeLO32DSPRegisterClass(MCInst &Inst,
1543 unsigned RegNo,
1544 uint64_t Address,
1545 const void *Decoder) {
Akira Hatanaka59bfaf72013-04-18 00:52:44 +00001546 if (RegNo >= 4)
1547 return MCDisassembler::Fail;
1548
Akira Hatanaka8002a3f2013-08-14 00:47:08 +00001549 unsigned Reg = getReg(Decoder, Mips::LO32DSPRegClassID, RegNo);
Akira Hatanaka59bfaf72013-04-18 00:52:44 +00001550 Inst.addOperand(MCOperand::CreateReg(Reg));
1551 return MCDisassembler::Success;
1552}
1553
Jack Carter3eb663b2013-09-26 00:09:46 +00001554static DecodeStatus DecodeMSA128BRegisterClass(MCInst &Inst,
1555 unsigned RegNo,
1556 uint64_t Address,
1557 const void *Decoder) {
1558 if (RegNo > 31)
1559 return MCDisassembler::Fail;
1560
1561 unsigned Reg = getReg(Decoder, Mips::MSA128BRegClassID, RegNo);
1562 Inst.addOperand(MCOperand::CreateReg(Reg));
1563 return MCDisassembler::Success;
1564}
1565
Jack Carter5dc8ac92013-09-25 23:50:44 +00001566static DecodeStatus DecodeMSA128HRegisterClass(MCInst &Inst,
1567 unsigned RegNo,
1568 uint64_t Address,
1569 const void *Decoder) {
1570 if (RegNo > 31)
1571 return MCDisassembler::Fail;
1572
1573 unsigned Reg = getReg(Decoder, Mips::MSA128HRegClassID, RegNo);
1574 Inst.addOperand(MCOperand::CreateReg(Reg));
1575 return MCDisassembler::Success;
1576}
1577
1578static DecodeStatus DecodeMSA128WRegisterClass(MCInst &Inst,
1579 unsigned RegNo,
1580 uint64_t Address,
1581 const void *Decoder) {
1582 if (RegNo > 31)
1583 return MCDisassembler::Fail;
1584
1585 unsigned Reg = getReg(Decoder, Mips::MSA128WRegClassID, RegNo);
1586 Inst.addOperand(MCOperand::CreateReg(Reg));
1587 return MCDisassembler::Success;
1588}
1589
1590static DecodeStatus DecodeMSA128DRegisterClass(MCInst &Inst,
1591 unsigned RegNo,
1592 uint64_t Address,
1593 const void *Decoder) {
1594 if (RegNo > 31)
1595 return MCDisassembler::Fail;
1596
1597 unsigned Reg = getReg(Decoder, Mips::MSA128DRegClassID, RegNo);
1598 Inst.addOperand(MCOperand::CreateReg(Reg));
1599 return MCDisassembler::Success;
1600}
1601
Matheus Almeidaa591fdc2013-10-21 12:26:50 +00001602static DecodeStatus DecodeMSACtrlRegisterClass(MCInst &Inst,
1603 unsigned RegNo,
1604 uint64_t Address,
1605 const void *Decoder) {
1606 if (RegNo > 7)
1607 return MCDisassembler::Fail;
1608
1609 unsigned Reg = getReg(Decoder, Mips::MSACtrlRegClassID, RegNo);
1610 Inst.addOperand(MCOperand::CreateReg(Reg));
1611 return MCDisassembler::Success;
1612}
1613
Daniel Sanders2a83d682014-05-21 12:56:39 +00001614static DecodeStatus DecodeCOP2RegisterClass(MCInst &Inst,
1615 unsigned RegNo,
1616 uint64_t Address,
1617 const void *Decoder) {
1618 if (RegNo > 31)
1619 return MCDisassembler::Fail;
1620
1621 unsigned Reg = getReg(Decoder, Mips::COP2RegClassID, RegNo);
1622 Inst.addOperand(MCOperand::CreateReg(Reg));
1623 return MCDisassembler::Success;
1624}
1625
Akira Hatanaka71928e62012-04-17 18:03:21 +00001626static DecodeStatus DecodeBranchTarget(MCInst &Inst,
1627 unsigned Offset,
1628 uint64_t Address,
1629 const void *Decoder) {
Alexey Samsonovd37bab62014-09-02 17:49:16 +00001630 int32_t BranchOffset = (SignExtend32<16>(Offset) * 4) + 4;
Akira Hatanaka71928e62012-04-17 18:03:21 +00001631 Inst.addOperand(MCOperand::CreateImm(BranchOffset));
1632 return MCDisassembler::Success;
1633}
1634
Akira Hatanaka71928e62012-04-17 18:03:21 +00001635static DecodeStatus DecodeJumpTarget(MCInst &Inst,
1636 unsigned Insn,
1637 uint64_t Address,
1638 const void *Decoder) {
1639
Jim Grosbachecaef492012-08-14 19:06:05 +00001640 unsigned JumpOffset = fieldFromInstruction(Insn, 0, 26) << 2;
Akira Hatanaka71928e62012-04-17 18:03:21 +00001641 Inst.addOperand(MCOperand::CreateImm(JumpOffset));
1642 return MCDisassembler::Success;
1643}
1644
Zoran Jovanovic3c8869d2014-05-16 11:03:45 +00001645static DecodeStatus DecodeBranchTarget21(MCInst &Inst,
1646 unsigned Offset,
1647 uint64_t Address,
1648 const void *Decoder) {
Alexey Samsonovd37bab62014-09-02 17:49:16 +00001649 int32_t BranchOffset = SignExtend32<21>(Offset) * 4;
Zoran Jovanovic3c8869d2014-05-16 11:03:45 +00001650
1651 Inst.addOperand(MCOperand::CreateImm(BranchOffset));
1652 return MCDisassembler::Success;
1653}
1654
1655static DecodeStatus DecodeBranchTarget26(MCInst &Inst,
1656 unsigned Offset,
1657 uint64_t Address,
1658 const void *Decoder) {
Alexey Samsonovd37bab62014-09-02 17:49:16 +00001659 int32_t BranchOffset = SignExtend32<26>(Offset) * 4;
Zoran Jovanovic3c8869d2014-05-16 11:03:45 +00001660
1661 Inst.addOperand(MCOperand::CreateImm(BranchOffset));
1662 return MCDisassembler::Success;
1663}
1664
Jozef Kolek9761e962015-01-12 12:03:34 +00001665static DecodeStatus DecodeBranchTarget7MM(MCInst &Inst,
1666 unsigned Offset,
1667 uint64_t Address,
1668 const void *Decoder) {
1669 int32_t BranchOffset = SignExtend32<7>(Offset) << 1;
1670 Inst.addOperand(MCOperand::CreateImm(BranchOffset));
1671 return MCDisassembler::Success;
1672}
1673
Jozef Kolek5cfebdd2015-01-21 12:39:30 +00001674static DecodeStatus DecodeBranchTarget10MM(MCInst &Inst,
1675 unsigned Offset,
1676 uint64_t Address,
1677 const void *Decoder) {
1678 int32_t BranchOffset = SignExtend32<10>(Offset) << 1;
1679 Inst.addOperand(MCOperand::CreateImm(BranchOffset));
1680 return MCDisassembler::Success;
1681}
1682
Zoran Jovanovic8a80aa72013-11-04 14:53:22 +00001683static DecodeStatus DecodeBranchTargetMM(MCInst &Inst,
1684 unsigned Offset,
1685 uint64_t Address,
1686 const void *Decoder) {
Alexey Samsonovd37bab62014-09-02 17:49:16 +00001687 int32_t BranchOffset = SignExtend32<16>(Offset) * 2;
Zoran Jovanovic8a80aa72013-11-04 14:53:22 +00001688 Inst.addOperand(MCOperand::CreateImm(BranchOffset));
1689 return MCDisassembler::Success;
1690}
1691
Zoran Jovanovic507e0842013-10-29 16:38:59 +00001692static DecodeStatus DecodeJumpTargetMM(MCInst &Inst,
1693 unsigned Insn,
1694 uint64_t Address,
1695 const void *Decoder) {
1696 unsigned JumpOffset = fieldFromInstruction(Insn, 0, 26) << 1;
1697 Inst.addOperand(MCOperand::CreateImm(JumpOffset));
1698 return MCDisassembler::Success;
1699}
Akira Hatanaka71928e62012-04-17 18:03:21 +00001700
Jozef Kolekaa2b9272014-11-27 14:41:44 +00001701static DecodeStatus DecodeAddiur2Simm7(MCInst &Inst,
1702 unsigned Value,
1703 uint64_t Address,
1704 const void *Decoder) {
1705 if (Value == 0)
1706 Inst.addOperand(MCOperand::CreateImm(1));
1707 else if (Value == 0x7)
1708 Inst.addOperand(MCOperand::CreateImm(-1));
1709 else
1710 Inst.addOperand(MCOperand::CreateImm(Value << 2));
1711 return MCDisassembler::Success;
1712}
1713
1714static DecodeStatus DecodeUImm6Lsl2(MCInst &Inst,
1715 unsigned Value,
1716 uint64_t Address,
1717 const void *Decoder) {
1718 Inst.addOperand(MCOperand::CreateImm(Value << 2));
1719 return MCDisassembler::Success;
1720}
1721
1722static DecodeStatus DecodeLiSimm7(MCInst &Inst,
1723 unsigned Value,
1724 uint64_t Address,
1725 const void *Decoder) {
1726 if (Value == 0x7F)
1727 Inst.addOperand(MCOperand::CreateImm(-1));
1728 else
1729 Inst.addOperand(MCOperand::CreateImm(Value));
1730 return MCDisassembler::Success;
1731}
1732
1733static DecodeStatus DecodeSimm4(MCInst &Inst,
1734 unsigned Value,
1735 uint64_t Address,
1736 const void *Decoder) {
1737 Inst.addOperand(MCOperand::CreateImm(SignExtend32<4>(Value)));
1738 return MCDisassembler::Success;
1739}
1740
Akira Hatanaka71928e62012-04-17 18:03:21 +00001741static DecodeStatus DecodeSimm16(MCInst &Inst,
1742 unsigned Insn,
1743 uint64_t Address,
1744 const void *Decoder) {
1745 Inst.addOperand(MCOperand::CreateImm(SignExtend32<16>(Insn)));
1746 return MCDisassembler::Success;
1747}
1748
Matheus Almeida779c5932013-11-18 12:32:49 +00001749static DecodeStatus DecodeLSAImm(MCInst &Inst,
1750 unsigned Insn,
1751 uint64_t Address,
1752 const void *Decoder) {
1753 // We add one to the immediate field as it was encoded as 'imm - 1'.
1754 Inst.addOperand(MCOperand::CreateImm(Insn + 1));
1755 return MCDisassembler::Success;
1756}
1757
Akira Hatanaka71928e62012-04-17 18:03:21 +00001758static DecodeStatus DecodeInsSize(MCInst &Inst,
1759 unsigned Insn,
1760 uint64_t Address,
1761 const void *Decoder) {
1762 // First we need to grab the pos(lsb) from MCInst.
1763 int Pos = Inst.getOperand(2).getImm();
1764 int Size = (int) Insn - Pos + 1;
1765 Inst.addOperand(MCOperand::CreateImm(SignExtend32<16>(Size)));
1766 return MCDisassembler::Success;
1767}
1768
1769static DecodeStatus DecodeExtSize(MCInst &Inst,
1770 unsigned Insn,
1771 uint64_t Address,
1772 const void *Decoder) {
1773 int Size = (int) Insn + 1;
1774 Inst.addOperand(MCOperand::CreateImm(SignExtend32<16>(Size)));
1775 return MCDisassembler::Success;
1776}
Daniel Sandersb59e1a42014-05-15 10:45:58 +00001777
1778static DecodeStatus DecodeSimm19Lsl2(MCInst &Inst, unsigned Insn,
1779 uint64_t Address, const void *Decoder) {
Alexey Samsonovd37bab62014-09-02 17:49:16 +00001780 Inst.addOperand(MCOperand::CreateImm(SignExtend32<19>(Insn) * 4));
Daniel Sandersb59e1a42014-05-15 10:45:58 +00001781 return MCDisassembler::Success;
1782}
Zoran Jovanovic28551422014-06-09 09:49:51 +00001783
1784static DecodeStatus DecodeSimm18Lsl3(MCInst &Inst, unsigned Insn,
1785 uint64_t Address, const void *Decoder) {
Alexey Samsonovd37bab62014-09-02 17:49:16 +00001786 Inst.addOperand(MCOperand::CreateImm(SignExtend32<18>(Insn) * 8));
Zoran Jovanovic28551422014-06-09 09:49:51 +00001787 return MCDisassembler::Success;
1788}
Zoran Jovanovica4c4b5f2014-11-19 16:44:02 +00001789
Vladimir Medicb682ddf2014-12-01 11:12:04 +00001790static DecodeStatus DecodeSimm9SP(MCInst &Inst, unsigned Insn,
1791 uint64_t Address, const void *Decoder) {
1792 int32_t DecodedValue;
1793 switch (Insn) {
1794 case 0: DecodedValue = 256; break;
1795 case 1: DecodedValue = 257; break;
1796 case 510: DecodedValue = -258; break;
1797 case 511: DecodedValue = -257; break;
1798 default: DecodedValue = SignExtend32<9>(Insn); break;
1799 }
Alexey Samsonov2c559742014-12-23 04:15:53 +00001800 Inst.addOperand(MCOperand::CreateImm(DecodedValue * 4));
Vladimir Medicb682ddf2014-12-01 11:12:04 +00001801 return MCDisassembler::Success;
1802}
1803
1804static DecodeStatus DecodeANDI16Imm(MCInst &Inst, unsigned Insn,
1805 uint64_t Address, const void *Decoder) {
1806 // Insn must be >= 0, since it is unsigned that condition is always true.
1807 assert(Insn < 16);
1808 int32_t DecodedValues[] = {128, 1, 2, 3, 4, 7, 8, 15, 16, 31, 32, 63, 64,
1809 255, 32768, 65535};
1810 Inst.addOperand(MCOperand::CreateImm(DecodedValues[Insn]));
1811 return MCDisassembler::Success;
1812}
1813
1814static DecodeStatus DecodeUImm5lsl2(MCInst &Inst, unsigned Insn,
1815 uint64_t Address, const void *Decoder) {
1816 Inst.addOperand(MCOperand::CreateImm(Insn << 2));
1817 return MCDisassembler::Success;
1818}
1819
Zoran Jovanovica4c4b5f2014-11-19 16:44:02 +00001820static DecodeStatus DecodeRegListOperand(MCInst &Inst,
1821 unsigned Insn,
1822 uint64_t Address,
1823 const void *Decoder) {
1824 unsigned Regs[] = {Mips::S0, Mips::S1, Mips::S2, Mips::S3, Mips::S4, Mips::S5,
1825 Mips::S6, Mips::FP};
1826 unsigned RegNum;
1827
1828 unsigned RegLst = fieldFromInstruction(Insn, 21, 5);
1829 // Empty register lists are not allowed.
1830 if (RegLst == 0)
1831 return MCDisassembler::Fail;
1832
1833 RegNum = RegLst & 0xf;
1834 for (unsigned i = 0; i < RegNum; i++)
1835 Inst.addOperand(MCOperand::CreateReg(Regs[i]));
1836
1837 if (RegLst & 0x10)
1838 Inst.addOperand(MCOperand::CreateReg(Mips::RA));
1839
1840 return MCDisassembler::Success;
1841}
Zoran Jovanovicf9a02502014-11-27 18:28:59 +00001842
1843static DecodeStatus DecodeRegListOperand16(MCInst &Inst, unsigned Insn,
1844 uint64_t Address,
1845 const void *Decoder) {
1846 unsigned Regs[] = {Mips::S0, Mips::S1, Mips::S2, Mips::S3};
Zoran Jovanovicf9a02502014-11-27 18:28:59 +00001847 unsigned RegLst = fieldFromInstruction(Insn, 4, 2);
Jozef Kolekd68d424a2015-02-10 12:41:13 +00001848 unsigned RegNum = RegLst & 0x3;
Zoran Jovanovicf9a02502014-11-27 18:28:59 +00001849
Jozef Kolekd68d424a2015-02-10 12:41:13 +00001850 for (unsigned i = 0; i <= RegNum; i++)
Zoran Jovanovicf9a02502014-11-27 18:28:59 +00001851 Inst.addOperand(MCOperand::CreateReg(Regs[i]));
1852
1853 Inst.addOperand(MCOperand::CreateReg(Mips::RA));
1854
1855 return MCDisassembler::Success;
1856}
Jozef Kolek2c6d7322015-01-21 12:10:11 +00001857
Zoran Jovanovic41688672015-02-10 16:36:20 +00001858static DecodeStatus DecodeMovePRegPair(MCInst &Inst, unsigned Insn,
1859 uint64_t Address, const void *Decoder) {
1860
1861 unsigned RegPair = fieldFromInstruction(Insn, 7, 3);
1862
1863 switch (RegPair) {
1864 default:
1865 return MCDisassembler::Fail;
1866 case 0:
1867 Inst.addOperand(MCOperand::CreateReg(Mips::A1));
1868 Inst.addOperand(MCOperand::CreateReg(Mips::A2));
1869 break;
1870 case 1:
1871 Inst.addOperand(MCOperand::CreateReg(Mips::A1));
1872 Inst.addOperand(MCOperand::CreateReg(Mips::A3));
1873 break;
1874 case 2:
1875 Inst.addOperand(MCOperand::CreateReg(Mips::A2));
1876 Inst.addOperand(MCOperand::CreateReg(Mips::A3));
1877 break;
1878 case 3:
1879 Inst.addOperand(MCOperand::CreateReg(Mips::A0));
1880 Inst.addOperand(MCOperand::CreateReg(Mips::S5));
1881 break;
1882 case 4:
1883 Inst.addOperand(MCOperand::CreateReg(Mips::A0));
1884 Inst.addOperand(MCOperand::CreateReg(Mips::S6));
1885 break;
1886 case 5:
1887 Inst.addOperand(MCOperand::CreateReg(Mips::A0));
1888 Inst.addOperand(MCOperand::CreateReg(Mips::A1));
1889 break;
1890 case 6:
1891 Inst.addOperand(MCOperand::CreateReg(Mips::A0));
1892 Inst.addOperand(MCOperand::CreateReg(Mips::A2));
1893 break;
1894 case 7:
1895 Inst.addOperand(MCOperand::CreateReg(Mips::A0));
1896 Inst.addOperand(MCOperand::CreateReg(Mips::A3));
1897 break;
1898 }
1899
1900 return MCDisassembler::Success;
1901}
1902
Jozef Kolek2c6d7322015-01-21 12:10:11 +00001903static DecodeStatus DecodeSimm23Lsl2(MCInst &Inst, unsigned Insn,
1904 uint64_t Address, const void *Decoder) {
1905 Inst.addOperand(MCOperand::CreateImm(SignExtend32<23>(Insn) << 2));
1906 return MCDisassembler::Success;
1907}