/src/capstonev5/arch/Mips/MipsDisassembler.c
Line  | Count  | Source  | 
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  |  | /* Capstone Disassembly Engine */  | 
15  |  | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015 */  | 
16  |  |  | 
17  |  | #ifdef CAPSTONE_HAS_MIPS  | 
18  |  |  | 
19  |  | #include <stdio.h>  | 
20  |  | #include <string.h>  | 
21  |  |  | 
22  |  | #include "capstone/platform.h"  | 
23  |  |  | 
24  |  | #include "MipsDisassembler.h"  | 
25  |  |  | 
26  |  | #include "../../utils.h"  | 
27  |  |  | 
28  |  | #include "../../MCRegisterInfo.h"  | 
29  |  | #include "../../SStream.h"  | 
30  |  |  | 
31  |  | #include "../../MathExtras.h"  | 
32  |  |  | 
33  |  | //#include "Mips.h"  | 
34  |  | //#include "MipsRegisterInfo.h"  | 
35  |  | //#include "MipsSubtarget.h"  | 
36  |  | #include "../../MCFixedLenDisassembler.h"  | 
37  |  | #include "../../MCInst.h"  | 
38  |  | //#include "llvm/MC/MCSubtargetInfo.h"  | 
39  |  | #include "../../MCRegisterInfo.h"  | 
40  |  | #include "../../MCDisassembler.h"  | 
41  |  |  | 
42  |  | // Forward declare these because the autogenerated code will reference them.  | 
43  |  | // Definitions are further down.  | 
44  |  | static DecodeStatus DecodeGPR64RegisterClass(MCInst *Inst,  | 
45  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
46  |  |  | 
47  |  | static DecodeStatus DecodeCPU16RegsRegisterClass(MCInst *Inst,  | 
48  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
49  |  |  | 
50  |  | static DecodeStatus DecodeGPRMM16RegisterClass(MCInst *Inst,  | 
51  |  |     unsigned RegNo, uint64_t Address, MCRegisterInfo *Decoder);  | 
52  |  |  | 
53  |  | static DecodeStatus DecodeGPRMM16ZeroRegisterClass(MCInst *Inst,  | 
54  |  |     unsigned RegNo, uint64_t Address, MCRegisterInfo *Decoder);  | 
55  |  |  | 
56  |  | static DecodeStatus DecodeGPRMM16MovePRegisterClass(MCInst *Inst,  | 
57  |  |     unsigned RegNo, uint64_t Address, MCRegisterInfo *Decoder);  | 
58  |  |  | 
59  |  | static DecodeStatus DecodeGPR32RegisterClass(MCInst *Inst,  | 
60  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
61  |  |  | 
62  |  | static DecodeStatus DecodePtrRegisterClass(MCInst *Inst,  | 
63  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
64  |  |  | 
65  |  | static DecodeStatus DecodeDSPRRegisterClass(MCInst *Inst,  | 
66  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
67  |  |  | 
68  |  | static DecodeStatus DecodeFGR64RegisterClass(MCInst *Inst,  | 
69  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
70  |  |  | 
71  |  | static DecodeStatus DecodeFGR32RegisterClass(MCInst *Inst,  | 
72  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
73  |  |  | 
74  |  | static DecodeStatus DecodeCCRRegisterClass(MCInst *Inst,  | 
75  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
76  |  |  | 
77  |  | static DecodeStatus DecodeFCCRegisterClass(MCInst *Inst,  | 
78  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
79  |  |  | 
80  |  | static DecodeStatus DecodeCCRegisterClass(MCInst *Inst,  | 
81  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
82  |  |  | 
83  |  | static DecodeStatus DecodeFGRCCRegisterClass(MCInst *Inst,  | 
84  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
85  |  |  | 
86  |  | static DecodeStatus DecodeHWRegsRegisterClass(MCInst *Inst,  | 
87  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
88  |  |  | 
89  |  | static DecodeStatus DecodeAFGR64RegisterClass(MCInst *Inst,  | 
90  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
91  |  |  | 
92  |  | static DecodeStatus DecodeACC64DSPRegisterClass(MCInst *Inst,  | 
93  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
94  |  |  | 
95  |  | static DecodeStatus DecodeHI32DSPRegisterClass(MCInst *Inst,  | 
96  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
97  |  |  | 
98  |  | static DecodeStatus DecodeLO32DSPRegisterClass(MCInst *Inst,  | 
99  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
100  |  |  | 
101  |  | static DecodeStatus DecodeMSA128BRegisterClass(MCInst *Inst,  | 
102  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
103  |  |  | 
104  |  | static DecodeStatus DecodeMSA128HRegisterClass(MCInst *Inst,  | 
105  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
106  |  |  | 
107  |  | static DecodeStatus DecodeMSA128WRegisterClass(MCInst *Inst,  | 
108  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
109  |  |  | 
110  |  | static DecodeStatus DecodeMSA128DRegisterClass(MCInst *Inst,  | 
111  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
112  |  |  | 
113  |  | static DecodeStatus DecodeMSACtrlRegisterClass(MCInst *Inst,  | 
114  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
115  |  |  | 
116  |  | static DecodeStatus DecodeCOP2RegisterClass(MCInst *Inst,  | 
117  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder);  | 
118  |  |  | 
119  |  | static DecodeStatus DecodeBranchTarget(MCInst *Inst,  | 
120  |  |     unsigned Offset, uint64_t Address, const MCRegisterInfo *Decoder);  | 
121  |  |  | 
122  |  | static DecodeStatus DecodeJumpTarget(MCInst *Inst,  | 
123  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
124  |  |  | 
125  |  | static DecodeStatus DecodeBranchTarget21(MCInst *Inst,  | 
126  |  |     unsigned Offset, uint64_t Address, const MCRegisterInfo *Decoder);  | 
127  |  |  | 
128  |  | static DecodeStatus DecodeBranchTarget26(MCInst *Inst,  | 
129  |  |     unsigned Offset, uint64_t Address, const MCRegisterInfo *Decoder);  | 
130  |  |  | 
131  |  | // DecodeBranchTarget7MM - Decode microMIPS branch offset, which is  | 
132  |  | // shifted left by 1 bit.  | 
133  |  | static DecodeStatus DecodeBranchTarget7MM(MCInst *Inst,  | 
134  |  |     unsigned Offset, uint64_t Address, MCRegisterInfo *Decoder);  | 
135  |  |  | 
136  |  | // DecodeBranchTarget10MM - Decode microMIPS branch offset, which is  | 
137  |  | // shifted left by 1 bit.  | 
138  |  | static DecodeStatus DecodeBranchTarget10MM(MCInst *Inst,  | 
139  |  |     unsigned Offset, uint64_t Address, MCRegisterInfo *Decoder);  | 
140  |  |  | 
141  |  | // DecodeBranchTargetMM - Decode microMIPS branch offset, which is  | 
142  |  | // shifted left by 1 bit.  | 
143  |  | static DecodeStatus DecodeBranchTargetMM(MCInst *Inst,  | 
144  |  |     unsigned Offset, uint64_t Address, const MCRegisterInfo *Decoder);  | 
145  |  |  | 
146  |  | // DecodeJumpTargetMM - Decode microMIPS jump target, which is  | 
147  |  | // shifted left by 1 bit.  | 
148  |  | static DecodeStatus DecodeJumpTargetMM(MCInst *Inst,  | 
149  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
150  |  |  | 
151  |  | static DecodeStatus DecodeMem(MCInst *Inst,  | 
152  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
153  |  |  | 
154  |  | static DecodeStatus DecodeCacheOp(MCInst *Inst,  | 
155  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder);  | 
156  |  |  | 
157  |  | static DecodeStatus DecodeCacheOpR6(MCInst *Inst,  | 
158  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder);  | 
159  |  |  | 
160  |  | static DecodeStatus DecodeCacheOpMM(MCInst *Inst,  | 
161  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder);  | 
162  |  |  | 
163  |  | static DecodeStatus DecodeSyncI(MCInst *Inst,  | 
164  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder);  | 
165  |  |  | 
166  |  | static DecodeStatus DecodeMSA128Mem(MCInst *Inst,  | 
167  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
168  |  |  | 
169  |  | static DecodeStatus DecodeMemMMImm4(MCInst *Inst,  | 
170  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder);  | 
171  |  |  | 
172  |  | static DecodeStatus DecodeMemMMSPImm5Lsl2(MCInst *Inst,  | 
173  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder);  | 
174  |  |  | 
175  |  | static DecodeStatus DecodeMemMMGPImm7Lsl2(MCInst *Inst,  | 
176  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder);  | 
177  |  |  | 
178  |  | static DecodeStatus DecodeMemMMReglistImm4Lsl2(MCInst *Inst,  | 
179  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder);  | 
180  |  |  | 
181  |  | static DecodeStatus DecodeMemMMImm12(MCInst *Inst,  | 
182  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
183  |  |  | 
184  |  | static DecodeStatus DecodeMemMMImm16(MCInst *Inst,  | 
185  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
186  |  |  | 
187  |  | static DecodeStatus DecodeFMem(MCInst *Inst, unsigned Insn,  | 
188  |  |     uint64_t Address, const MCRegisterInfo *Decoder);  | 
189  |  |  | 
190  |  | static DecodeStatus DecodeFMem2(MCInst *Inst, unsigned Insn,  | 
191  |  |     uint64_t Address, MCRegisterInfo *Decoder);  | 
192  |  |  | 
193  |  | static DecodeStatus DecodeFMem3(MCInst *Inst, unsigned Insn,  | 
194  |  |     uint64_t Address, MCRegisterInfo *Decoder);  | 
195  |  |  | 
196  |  | static DecodeStatus DecodeFMemCop2R6(MCInst *Inst, unsigned Insn,  | 
197  |  |     uint64_t Address, MCRegisterInfo *Decoder);  | 
198  |  |  | 
199  |  | static DecodeStatus DecodeSpecial3LlSc(MCInst *Inst,  | 
200  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
201  |  |  | 
202  |  | static DecodeStatus DecodeAddiur2Simm7(MCInst *Inst,  | 
203  |  |     unsigned Value, uint64_t Address, MCRegisterInfo *Decoder);  | 
204  |  |  | 
205  |  | static DecodeStatus DecodeUImm6Lsl2(MCInst *Inst,  | 
206  |  |     unsigned Value, uint64_t Address, MCRegisterInfo *Decoder);  | 
207  |  |  | 
208  |  | static DecodeStatus DecodeLiSimm7(MCInst *Inst,  | 
209  |  |     unsigned Value, uint64_t Address, MCRegisterInfo *Decoder);  | 
210  |  |  | 
211  |  | static DecodeStatus DecodeSimm4(MCInst *Inst,  | 
212  |  |     unsigned Value, uint64_t Address, MCRegisterInfo *Decoder);  | 
213  |  |  | 
214  |  | static DecodeStatus DecodeSimm16(MCInst *Inst,  | 
215  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
216  |  |  | 
217  |  | // Decode the immediate field of an LSA instruction which  | 
218  |  | // is off by one.  | 
219  |  | static DecodeStatus DecodeLSAImm(MCInst *Inst,  | 
220  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
221  |  |  | 
222  |  | static DecodeStatus DecodeInsSize(MCInst *Inst,  | 
223  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
224  |  |  | 
225  |  | static DecodeStatus DecodeExtSize(MCInst *Inst,  | 
226  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
227  |  |  | 
228  |  | static DecodeStatus DecodeSimm19Lsl2(MCInst *Inst,  | 
229  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
230  |  |  | 
231  |  | static DecodeStatus DecodeSimm18Lsl3(MCInst *Inst,  | 
232  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
233  |  |  | 
234  |  | static DecodeStatus DecodeSimm9SP(MCInst *Inst,  | 
235  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder);  | 
236  |  |  | 
237  |  | static DecodeStatus DecodeANDI16Imm(MCInst *Inst,  | 
238  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder);  | 
239  |  |  | 
240  |  | static DecodeStatus DecodeUImm5lsl2(MCInst *Inst,  | 
241  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder);  | 
242  |  |  | 
243  |  | static DecodeStatus DecodeSimm23Lsl2(MCInst *Inst,  | 
244  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder);  | 
245  |  |  | 
246  |  | /// INSVE_[BHWD] have an implicit operand that the generated decoder doesn't  | 
247  |  | /// handle.  | 
248  |  | static DecodeStatus DecodeINSVE_DF_4(MCInst *MI,  | 
249  |  |     uint32_t insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
250  |  |  | 
251  |  | static DecodeStatus DecodeAddiGroupBranch_4(MCInst *MI,  | 
252  |  |     uint32_t insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
253  |  |  | 
254  |  | static DecodeStatus DecodeDaddiGroupBranch_4(MCInst *MI,  | 
255  |  |     uint32_t insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
256  |  |  | 
257  |  | static DecodeStatus DecodeBlezlGroupBranch_4(MCInst *MI,  | 
258  |  |     uint32_t insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
259  |  |  | 
260  |  | static DecodeStatus DecodeBgtzlGroupBranch_4(MCInst *MI,  | 
261  |  |     uint32_t insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
262  |  |  | 
263  |  | static DecodeStatus DecodeBgtzGroupBranch_4(MCInst *MI,  | 
264  |  |     uint32_t insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
265  |  |  | 
266  |  | static DecodeStatus DecodeBlezGroupBranch_4(MCInst *MI,  | 
267  |  |     uint32_t insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
268  |  |  | 
269  |  | static DecodeStatus DecodeRegListOperand(MCInst *Inst,  | 
270  |  |     uint32_t insn, uint64_t Address, const MCRegisterInfo *Decoder);  | 
271  |  |  | 
272  |  | static DecodeStatus DecodeRegListOperand16(MCInst *Inst,  | 
273  |  |     uint32_t insn, uint64_t Address, MCRegisterInfo *Decoder);  | 
274  |  |  | 
275  |  | static DecodeStatus DecodeMovePRegPair(MCInst *Inst,  | 
276  |  |     uint32_t insn, uint64_t Address, MCRegisterInfo *Decoder);  | 
277  |  |  | 
278  |  | #define GET_SUBTARGETINFO_ENUM  | 
279  |  | #include "MipsGenSubtargetInfo.inc"  | 
280  |  |  | 
281  |  | // Hacky: enable all features for disassembler  | 
282  |  | static uint64_t getFeatureBits(int mode)  | 
283  | 143k  | { | 
284  | 143k  |   uint64_t Bits = (uint64_t)-1; // include every features at first  | 
285  |  |  | 
286  |  |   // By default we do not support Mips1  | 
287  | 143k  |   Bits &= ~Mips_FeatureMips1;  | 
288  |  |  | 
289  |  |   // No MicroMips  | 
290  | 143k  |   Bits &= ~Mips_FeatureMicroMips;  | 
291  |  |  | 
292  |  |   // ref: MipsGenDisassemblerTables.inc::checkDecoderPredicate()  | 
293  |  |   // some features are mutually execlusive  | 
294  | 143k  |   if (mode & CS_MODE_16) { | 
295  |  |     //Bits &= ~Mips_FeatureMips32r2;  | 
296  |  |     //Bits &= ~Mips_FeatureMips32;  | 
297  |  |     //Bits &= ~Mips_FeatureFPIdx;  | 
298  |  |     //Bits &= ~Mips_FeatureBitCount;  | 
299  |  |     //Bits &= ~Mips_FeatureSwap;  | 
300  |  |     //Bits &= ~Mips_FeatureSEInReg;  | 
301  |  |     //Bits &= ~Mips_FeatureMips64r2;  | 
302  |  |     //Bits &= ~Mips_FeatureFP64Bit;  | 
303  | 143k  |   } else if (mode & CS_MODE_32) { | 
304  | 27.7k  |     Bits &= ~Mips_FeatureMips16;  | 
305  | 27.7k  |     Bits &= ~Mips_FeatureFP64Bit;  | 
306  | 27.7k  |     Bits &= ~Mips_FeatureMips64r2;  | 
307  | 27.7k  |     Bits &= ~Mips_FeatureMips32r6;  | 
308  | 27.7k  |     Bits &= ~Mips_FeatureMips64r6;  | 
309  | 115k  |   } else if (mode & CS_MODE_64) { | 
310  | 74.2k  |     Bits &= ~Mips_FeatureMips16;  | 
311  | 74.2k  |     Bits &= ~Mips_FeatureMips64r6;  | 
312  | 74.2k  |     Bits &= ~Mips_FeatureMips32r6;  | 
313  | 74.2k  |   } else if (mode & CS_MODE_MIPS32R6) { | 
314  | 41.1k  |     Bits |= Mips_FeatureMips32r6;  | 
315  | 41.1k  |     Bits &= ~Mips_FeatureMips16;  | 
316  | 41.1k  |     Bits &= ~Mips_FeatureFP64Bit;  | 
317  | 41.1k  |     Bits &= ~Mips_FeatureMips64r6;  | 
318  | 41.1k  |     Bits &= ~Mips_FeatureMips64r2;  | 
319  | 41.1k  |   }  | 
320  |  |  | 
321  | 143k  |   if (mode & CS_MODE_MICRO) { | 
322  | 29.3k  |     Bits |= Mips_FeatureMicroMips;  | 
323  | 29.3k  |     Bits &= ~Mips_FeatureMips4_32r2;  | 
324  | 29.3k  |     Bits &= ~Mips_FeatureMips2;  | 
325  | 29.3k  |   }  | 
326  |  |  | 
327  | 143k  |   return Bits;  | 
328  | 143k  | }  | 
329  |  |  | 
330  |  | #include "MipsGenDisassemblerTables.inc"  | 
331  |  |  | 
332  |  | #define GET_REGINFO_ENUM  | 
333  |  | #include "MipsGenRegisterInfo.inc"  | 
334  |  |  | 
335  |  | #define GET_REGINFO_MC_DESC  | 
336  |  | #include "MipsGenRegisterInfo.inc"  | 
337  |  |  | 
338  |  | #define GET_INSTRINFO_ENUM  | 
339  |  | #include "MipsGenInstrInfo.inc"  | 
340  |  |  | 
341  |  | void Mips_init(MCRegisterInfo *MRI)  | 
342  | 3.30k  | { | 
343  |  |   // InitMCRegisterInfo(MipsRegDesc, 394, RA, PC,  | 
344  |  |   //    MipsMCRegisterClasses, 62,  | 
345  |  |   //    MipsRegUnitRoots,  | 
346  |  |   //    273,  | 
347  |  |   //    MipsRegDiffLists,  | 
348  |  |   //    MipsLaneMaskLists,  | 
349  |  |   //    MipsRegStrings,  | 
350  |  |   //    MipsRegClassStrings,  | 
351  |  |   //    MipsSubRegIdxLists,  | 
352  |  |   //    12,  | 
353  |  |   //    MipsSubRegIdxRanges,  | 
354  |  |   //    MipsRegEncodingTable);  | 
355  |  |  | 
356  |  |  | 
357  | 3.30k  |   MCRegisterInfo_InitMCRegisterInfo(MRI, MipsRegDesc, 394,  | 
358  | 3.30k  |       0, 0,  | 
359  | 3.30k  |       MipsMCRegisterClasses, 62,  | 
360  | 3.30k  |       0, 0,  | 
361  | 3.30k  |       MipsRegDiffLists,  | 
362  | 3.30k  |       0,  | 
363  | 3.30k  |       MipsSubRegIdxLists, 12,  | 
364  | 3.30k  |       0);  | 
365  | 3.30k  | }  | 
366  |  |  | 
367  |  | /// Read two bytes from the ArrayRef and return 16 bit halfword sorted  | 
368  |  | /// according to the given endianess.  | 
369  |  | static void readInstruction16(unsigned char *code, uint32_t *insn,  | 
370  |  |     bool isBigEndian)  | 
371  | 19.7k  | { | 
372  |  |   // We want to read exactly 2 Bytes of data.  | 
373  | 19.7k  |   if (isBigEndian)  | 
374  | 9.17k  |     *insn = (code[0] << 8) | code[1];  | 
375  | 10.6k  |   else  | 
376  | 10.6k  |     *insn = (code[1] << 8) | code[0];  | 
377  | 19.7k  | }  | 
378  |  |  | 
379  |  | /// readInstruction - read four bytes from the MemoryObject  | 
380  |  | /// and return 32 bit word sorted according to the given endianess  | 
381  |  | static void readInstruction32(unsigned char *code, uint32_t *insn, bool isBigEndian, bool isMicroMips)  | 
382  | 81.1k  | { | 
383  |  |   // High 16 bits of a 32-bit microMIPS instruction (where the opcode is)  | 
384  |  |   // always precede the low 16 bits in the instruction stream (that is, they  | 
385  |  |   // are placed at lower addresses in the instruction stream).  | 
386  |  |   //  | 
387  |  |   // microMIPS byte ordering:  | 
388  |  |   //   Big-endian:    0 | 1 | 2 | 3  | 
389  |  |   //   Little-endian: 1 | 0 | 3 | 2  | 
390  |  |  | 
391  |  |   // We want to read exactly 4 Bytes of data.  | 
392  | 81.1k  |   if (isBigEndian) { | 
393  |  |     // Encoded as a big-endian 32-bit word in the stream.  | 
394  | 49.8k  |     *insn =  | 
395  | 49.8k  |       (code[3] << 0) | (code[2] << 8) | (code[1] << 16) | ((uint32_t) code[0] << 24);  | 
396  | 49.8k  |   } else { | 
397  | 31.2k  |     if (isMicroMips) { | 
398  | 5.21k  |       *insn = (code[2] << 0) | (code[3] << 8) | (code[0] << 16) |  | 
399  | 5.21k  |         ((uint32_t) code[1] << 24);  | 
400  | 26.0k  |     } else { | 
401  | 26.0k  |       *insn = (code[0] << 0) | (code[1] << 8) | (code[2] << 16) |  | 
402  | 26.0k  |         ((uint32_t) code[3] << 24);  | 
403  | 26.0k  |     }  | 
404  | 31.2k  |   }  | 
405  | 81.1k  | }  | 
406  |  |  | 
407  |  | static DecodeStatus MipsDisassembler_getInstruction(int mode, MCInst *instr,  | 
408  |  |     const uint8_t *code, size_t code_len,  | 
409  |  |     uint16_t *Size,  | 
410  |  |     uint64_t Address, bool isBigEndian, MCRegisterInfo *MRI)  | 
411  | 92.1k  | { | 
412  | 92.1k  |   uint32_t Insn;  | 
413  | 92.1k  |   DecodeStatus Result;  | 
414  |  |  | 
415  | 92.1k  |   if (instr->flat_insn->detail) { | 
416  | 92.1k  |     memset(instr->flat_insn->detail, 0, offsetof(cs_detail, mips)+sizeof(cs_mips));  | 
417  | 92.1k  |   }  | 
418  |  |  | 
419  | 92.1k  |   if (mode & CS_MODE_MICRO) { | 
420  | 19.8k  |     if (code_len < 2)  | 
421  |  |       // not enough data  | 
422  | 83  |       return MCDisassembler_Fail;  | 
423  |  |  | 
424  | 19.7k  |     readInstruction16((unsigned char*)code, &Insn, isBigEndian);  | 
425  |  |  | 
426  |  |     // Calling the auto-generated decoder function.  | 
427  | 19.7k  |     Result = decodeInstruction(DecoderTableMicroMips16, instr, Insn, Address, MRI, mode);  | 
428  | 19.7k  |     if (Result != MCDisassembler_Fail) { | 
429  | 10.1k  |       *Size = 2;  | 
430  | 10.1k  |       return Result;  | 
431  | 10.1k  |     }  | 
432  |  |  | 
433  | 9.60k  |     if (code_len < 4)  | 
434  |  |       // not enough data  | 
435  | 55  |       return MCDisassembler_Fail;  | 
436  |  |  | 
437  | 9.54k  |     readInstruction32((unsigned char*)code, &Insn, isBigEndian, true);  | 
438  |  |  | 
439  |  |     //DEBUG(dbgs() << "Trying MicroMips32 table (32-bit instructions):\n");  | 
440  |  |     // Calling the auto-generated decoder function.  | 
441  | 9.54k  |     Result = decodeInstruction(DecoderTableMicroMips32, instr, Insn, Address, MRI, mode);  | 
442  | 9.54k  |     if (Result != MCDisassembler_Fail) { | 
443  | 9.49k  |       *Size = 4;  | 
444  | 9.49k  |       return Result;  | 
445  | 9.49k  |     }  | 
446  | 54  |     return MCDisassembler_Fail;  | 
447  | 9.54k  |   }  | 
448  |  |  | 
449  | 72.3k  |   if (code_len < 4)  | 
450  |  |     // not enough data  | 
451  | 757  |     return MCDisassembler_Fail;  | 
452  |  |  | 
453  | 71.5k  |   readInstruction32((unsigned char*)code, &Insn, isBigEndian, false);  | 
454  |  |  | 
455  | 71.5k  |   if ((mode & CS_MODE_MIPS2) && ((mode & CS_MODE_MIPS3) == 0)) { | 
456  |  |     // DEBUG(dbgs() << "Trying COP3_ table (32-bit opcodes):\n");  | 
457  | 0  |     Result = decodeInstruction(DecoderTableCOP3_32, instr, Insn, Address, MRI, mode);  | 
458  | 0  |     if (Result != MCDisassembler_Fail) { | 
459  | 0  |       *Size = 4;  | 
460  | 0  |       return Result;  | 
461  | 0  |     }  | 
462  | 0  |   }  | 
463  |  |  | 
464  | 71.5k  |   if ((mode & CS_MODE_MIPS32R6) && (mode & CS_MODE_MIPS64)) { | 
465  |  |     // DEBUG(dbgs() << "Trying Mips32r6_64r6 (GPR64) table (32-bit opcodes):\n");  | 
466  | 0  |     Result = decodeInstruction(DecoderTableMips32r6_64r6_GP6432, instr, Insn,  | 
467  | 0  |         Address, MRI, mode);  | 
468  | 0  |     if (Result != MCDisassembler_Fail) { | 
469  | 0  |       *Size = 4;  | 
470  | 0  |       return Result;  | 
471  | 0  |     }  | 
472  | 0  |   }  | 
473  |  |  | 
474  | 71.5k  |   if (mode & CS_MODE_MIPS32R6) { | 
475  |  |     // DEBUG(dbgs() << "Trying Mips32r6_64r6 table (32-bit opcodes):\n");  | 
476  | 16.6k  |     Result = decodeInstruction(DecoderTableMips32r6_64r632, instr, Insn,  | 
477  | 16.6k  |         Address, MRI, mode);  | 
478  | 16.6k  |     if (Result != MCDisassembler_Fail) { | 
479  | 6.92k  |       *Size = 4;  | 
480  | 6.92k  |       return Result;  | 
481  | 6.92k  |     }  | 
482  | 16.6k  |   }  | 
483  |  |  | 
484  | 64.6k  |   if (mode & CS_MODE_MIPS64) { | 
485  |  |     // DEBUG(dbgs() << "Trying Mips64 (GPR64) table (32-bit opcodes):\n");  | 
486  | 41.7k  |     Result = decodeInstruction(DecoderTableMips6432, instr, Insn,  | 
487  | 41.7k  |         Address, MRI, mode);  | 
488  | 41.7k  |     if (Result != MCDisassembler_Fail) { | 
489  | 9.26k  |       *Size = 4;  | 
490  | 9.26k  |       return Result;  | 
491  | 9.26k  |     }  | 
492  | 41.7k  |   }  | 
493  |  |  | 
494  |  |   // DEBUG(dbgs() << "Trying Mips table (32-bit opcodes):\n");  | 
495  |  |   // Calling the auto-generated decoder function.  | 
496  | 55.3k  |   Result = decodeInstruction(DecoderTableMips32, instr, Insn, Address, MRI, mode);  | 
497  | 55.3k  |   if (Result != MCDisassembler_Fail) { | 
498  | 55.0k  |     *Size = 4;  | 
499  | 55.0k  |     return Result;  | 
500  | 55.0k  |   }  | 
501  |  |  | 
502  | 304  |   return MCDisassembler_Fail;  | 
503  | 55.3k  | }  | 
504  |  |  | 
505  |  | bool Mips_getInstruction(csh ud, const uint8_t *code, size_t code_len, MCInst *instr,  | 
506  |  |     uint16_t *size, uint64_t address, void *info)  | 
507  | 92.1k  | { | 
508  | 92.1k  |   cs_struct *handle = (cs_struct *)(uintptr_t)ud;  | 
509  |  |  | 
510  | 92.1k  |   DecodeStatus status = MipsDisassembler_getInstruction(handle->mode, instr,  | 
511  | 92.1k  |       code, code_len,  | 
512  | 92.1k  |       size,  | 
513  | 92.1k  |       address, MODE_IS_BIG_ENDIAN(handle->mode), (MCRegisterInfo *)info);  | 
514  |  |  | 
515  | 92.1k  |   return status == MCDisassembler_Success;  | 
516  | 92.1k  | }  | 
517  |  |  | 
518  |  | static unsigned getReg(const MCRegisterInfo *MRI, unsigned RC, unsigned RegNo)  | 
519  | 165k  | { | 
520  | 165k  |   const MCRegisterClass *rc = MCRegisterInfo_getRegClass(MRI, RC);  | 
521  | 165k  |   return rc->RegsBegin[RegNo];  | 
522  | 165k  | }  | 
523  |  |  | 
524  |  | static DecodeStatus DecodeINSVE_DF_4(MCInst *MI, uint32_t insn,  | 
525  |  |     uint64_t Address, const MCRegisterInfo *Decoder)  | 
526  | 911  | { | 
527  | 911  |   typedef DecodeStatus (*DecodeFN)(MCInst *, unsigned, uint64_t, const MCRegisterInfo *);  | 
528  |  |   // The size of the n field depends on the element size  | 
529  |  |   // The register class also depends on this.  | 
530  | 911  |   uint32_t tmp = fieldFromInstruction(insn, 17, 5);  | 
531  | 911  |   unsigned NSize = 0;  | 
532  | 911  |   DecodeFN RegDecoder = NULL;  | 
533  |  |  | 
534  | 911  |   if ((tmp & 0x18) == 0x00) { // INSVE_B | 
535  | 536  |     NSize = 4;  | 
536  | 536  |     RegDecoder = DecodeMSA128BRegisterClass;  | 
537  | 536  |   } else if ((tmp & 0x1c) == 0x10) { // INSVE_H | 
538  | 66  |     NSize = 3;  | 
539  | 66  |     RegDecoder = DecodeMSA128HRegisterClass;  | 
540  | 309  |   } else if ((tmp & 0x1e) == 0x18) { // INSVE_W | 
541  | 198  |     NSize = 2;  | 
542  | 198  |     RegDecoder = DecodeMSA128WRegisterClass;  | 
543  | 198  |   } else if ((tmp & 0x1f) == 0x1c) { // INSVE_D | 
544  | 111  |     NSize = 1;  | 
545  | 111  |     RegDecoder = DecodeMSA128DRegisterClass;  | 
546  | 111  |   } //else llvm_unreachable("Invalid encoding"); | 
547  |  |  | 
548  |  |   //assert(NSize != 0 && RegDecoder != nullptr);  | 
549  | 911  |   if (NSize == 0 || RegDecoder == NULL)  | 
550  | 0  |     return MCDisassembler_Fail;  | 
551  |  |  | 
552  |  |   // $wd  | 
553  | 911  |   tmp = fieldFromInstruction(insn, 6, 5);  | 
554  | 911  |   if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler_Fail)  | 
555  | 0  |     return MCDisassembler_Fail;  | 
556  |  |  | 
557  |  |   // $wd_in  | 
558  | 911  |   if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler_Fail)  | 
559  | 0  |     return MCDisassembler_Fail;  | 
560  |  |  | 
561  |  |   // $n  | 
562  | 911  |   tmp = fieldFromInstruction(insn, 16, NSize);  | 
563  | 911  |   MCOperand_CreateImm0(MI, tmp);  | 
564  |  |  | 
565  |  |   // $ws  | 
566  | 911  |   tmp = fieldFromInstruction(insn, 11, 5);  | 
567  | 911  |   if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler_Fail)  | 
568  | 0  |     return MCDisassembler_Fail;  | 
569  |  |  | 
570  |  |   // $n2  | 
571  | 911  |   MCOperand_CreateImm0(MI, 0);  | 
572  |  |  | 
573  | 911  |   return MCDisassembler_Success;  | 
574  | 911  | }  | 
575  |  |  | 
576  |  | static DecodeStatus DecodeAddiGroupBranch_4(MCInst *MI, uint32_t insn,  | 
577  |  |     uint64_t Address, const MCRegisterInfo *Decoder)  | 
578  | 607  | { | 
579  |  |   // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled  | 
580  |  |   // (otherwise we would have matched the ADDI instruction from the earlier  | 
581  |  |   // ISA's instead).  | 
582  |  |   //  | 
583  |  |   // We have:  | 
584  |  |   //    0b001000 sssss ttttt iiiiiiiiiiiiiiii  | 
585  |  |   //      BOVC if rs >= rt  | 
586  |  |   //      BEQZALC if rs == 0 && rt != 0  | 
587  |  |   //      BEQC if rs < rt && rs != 0  | 
588  |  |  | 
589  | 607  |   uint32_t Rs = fieldFromInstruction(insn, 21, 5);  | 
590  | 607  |   uint32_t Rt = fieldFromInstruction(insn, 16, 5);  | 
591  | 607  |   uint32_t Imm = (uint32_t)SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4;  | 
592  | 607  |   bool HasRs = false;  | 
593  |  |  | 
594  | 607  |   if (Rs >= Rt) { | 
595  | 305  |     MCInst_setOpcode(MI, Mips_BOVC);  | 
596  | 305  |     HasRs = true;  | 
597  | 305  |   } else if (Rs != 0 && Rs < Rt) { | 
598  | 228  |     MCInst_setOpcode(MI, Mips_BEQC);  | 
599  | 228  |     HasRs = true;  | 
600  | 228  |   } else  | 
601  | 74  |     MCInst_setOpcode(MI, Mips_BEQZALC);  | 
602  |  |  | 
603  | 607  |   if (HasRs)  | 
604  | 533  |     MCOperand_CreateReg0(MI, getReg(Decoder, Mips_GPR32RegClassID, Rs));  | 
605  |  |  | 
606  | 607  |   MCOperand_CreateReg0(MI, getReg(Decoder, Mips_GPR32RegClassID, Rt));  | 
607  | 607  |   MCOperand_CreateImm0(MI, Imm);  | 
608  |  |  | 
609  | 607  |   return MCDisassembler_Success;  | 
610  | 607  | }  | 
611  |  |  | 
612  |  | static DecodeStatus DecodeDaddiGroupBranch_4(MCInst *MI, uint32_t insn,  | 
613  |  |     uint64_t Address, const MCRegisterInfo *Decoder)  | 
614  | 653  | { | 
615  |  |   // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled  | 
616  |  |   // (otherwise we would have matched the ADDI instruction from the earlier  | 
617  |  |   // ISA's instead).  | 
618  |  |   //  | 
619  |  |   // We have:  | 
620  |  |   //    0b011000 sssss ttttt iiiiiiiiiiiiiiii  | 
621  |  |   //      BNVC if rs >= rt  | 
622  |  |   //      BNEZALC if rs == 0 && rt != 0  | 
623  |  |   //      BNEC if rs < rt && rs != 0  | 
624  |  |  | 
625  | 653  |   uint32_t Rs = fieldFromInstruction(insn, 21, 5);  | 
626  | 653  |   uint32_t Rt = fieldFromInstruction(insn, 16, 5);  | 
627  | 653  |   uint32_t Imm = (uint32_t)SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4;  | 
628  | 653  |   bool HasRs = false;  | 
629  |  |  | 
630  | 653  |   if (Rs >= Rt) { | 
631  | 245  |     MCInst_setOpcode(MI, Mips_BNVC);  | 
632  | 245  |     HasRs = true;  | 
633  | 408  |   } else if (Rs != 0 && Rs < Rt) { | 
634  | 210  |     MCInst_setOpcode(MI, Mips_BNEC);  | 
635  | 210  |     HasRs = true;  | 
636  | 210  |   } else  | 
637  | 198  |     MCInst_setOpcode(MI, Mips_BNEZALC);  | 
638  |  |  | 
639  | 653  |   if (HasRs)  | 
640  | 455  |     MCOperand_CreateReg0(MI, getReg(Decoder, Mips_GPR32RegClassID, Rs));  | 
641  |  |  | 
642  | 653  |   MCOperand_CreateReg0(MI, getReg(Decoder, Mips_GPR32RegClassID, Rt));  | 
643  | 653  |   MCOperand_CreateImm0(MI, Imm);  | 
644  |  |  | 
645  | 653  |   return MCDisassembler_Success;  | 
646  | 653  | }  | 
647  |  |  | 
648  |  | static DecodeStatus DecodeBlezlGroupBranch_4(MCInst *MI, uint32_t insn,  | 
649  |  |     uint64_t Address, const MCRegisterInfo *Decoder)  | 
650  | 656  | { | 
651  |  |   // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled  | 
652  |  |   // (otherwise we would have matched the BLEZL instruction from the earlier  | 
653  |  |   // ISA's instead).  | 
654  |  |   //  | 
655  |  |   // We have:  | 
656  |  |   //    0b010110 sssss ttttt iiiiiiiiiiiiiiii  | 
657  |  |   //      Invalid if rs == 0  | 
658  |  |   //      BLEZC   if rs == 0  && rt != 0  | 
659  |  |   //      BGEZC   if rs == rt && rt != 0  | 
660  |  |   //      BGEC    if rs != rt && rs != 0  && rt != 0  | 
661  |  |  | 
662  | 656  |   uint32_t Rs = fieldFromInstruction(insn, 21, 5);  | 
663  | 656  |   uint32_t Rt = fieldFromInstruction(insn, 16, 5);  | 
664  | 656  |   uint32_t Imm = (uint32_t)SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4;  | 
665  | 656  |   bool HasRs = false;  | 
666  |  |  | 
667  | 656  |   if (Rt == 0)  | 
668  | 1  |     return MCDisassembler_Fail;  | 
669  | 655  |   else if (Rs == 0)  | 
670  | 67  |     MCInst_setOpcode(MI, Mips_BLEZC);  | 
671  | 588  |   else if (Rs == Rt)  | 
672  | 197  |     MCInst_setOpcode(MI, Mips_BGEZC);  | 
673  | 391  |   else { | 
674  | 391  |     HasRs = true;  | 
675  | 391  |     MCInst_setOpcode(MI, Mips_BGEC);  | 
676  | 391  |   }  | 
677  |  |  | 
678  | 655  |   if (HasRs)  | 
679  | 391  |     MCOperand_CreateReg0(MI, getReg(Decoder, Mips_GPR32RegClassID, Rs));  | 
680  |  |  | 
681  | 655  |   MCOperand_CreateReg0(MI, getReg(Decoder, Mips_GPR32RegClassID, Rt));  | 
682  |  |  | 
683  | 655  |   MCOperand_CreateImm0(MI, Imm);  | 
684  |  |  | 
685  | 655  |   return MCDisassembler_Success;  | 
686  | 656  | }  | 
687  |  |  | 
688  |  | static DecodeStatus DecodeBgtzlGroupBranch_4(MCInst *MI, uint32_t insn,  | 
689  |  |     uint64_t Address, const MCRegisterInfo *Decoder)  | 
690  | 545  | { | 
691  |  |   // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled  | 
692  |  |   // (otherwise we would have matched the BGTZL instruction from the earlier  | 
693  |  |   // ISA's instead).  | 
694  |  |   //  | 
695  |  |   // We have:  | 
696  |  |   //    0b010111 sssss ttttt iiiiiiiiiiiiiiii  | 
697  |  |   //      Invalid if rs == 0  | 
698  |  |   //      BGTZC   if rs == 0  && rt != 0  | 
699  |  |   //      BLTZC   if rs == rt && rt != 0  | 
700  |  |   //      BLTC    if rs != rt && rs != 0  && rt != 0  | 
701  |  |  | 
702  | 545  |   bool HasRs = false;  | 
703  |  |  | 
704  | 545  |   uint32_t Rs = fieldFromInstruction(insn, 21, 5);  | 
705  | 545  |   uint32_t Rt = fieldFromInstruction(insn, 16, 5);  | 
706  | 545  |   uint32_t Imm = (uint32_t)SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4;  | 
707  |  |  | 
708  | 545  |   if (Rt == 0)  | 
709  | 1  |     return MCDisassembler_Fail;  | 
710  | 544  |   else if (Rs == 0)  | 
711  | 195  |     MCInst_setOpcode(MI, Mips_BGTZC);  | 
712  | 349  |   else if (Rs == Rt)  | 
713  | 68  |     MCInst_setOpcode(MI, Mips_BLTZC);  | 
714  | 281  |   else { | 
715  | 281  |     MCInst_setOpcode(MI, Mips_BLTC);  | 
716  | 281  |     HasRs = true;  | 
717  | 281  |   }  | 
718  |  |  | 
719  | 544  |   if (HasRs)  | 
720  | 281  |     MCOperand_CreateReg0(MI, getReg(Decoder, Mips_GPR32RegClassID, Rs));  | 
721  |  |  | 
722  | 544  |   MCOperand_CreateReg0(MI, getReg(Decoder, Mips_GPR32RegClassID, Rt));  | 
723  | 544  |   MCOperand_CreateImm0(MI, Imm);  | 
724  |  |  | 
725  | 544  |   return MCDisassembler_Success;  | 
726  | 545  | }  | 
727  |  |  | 
728  |  | static DecodeStatus DecodeBgtzGroupBranch_4(MCInst *MI, uint32_t insn,  | 
729  |  |     uint64_t Address, const MCRegisterInfo *Decoder)  | 
730  | 784  | { | 
731  |  |   // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled  | 
732  |  |   // (otherwise we would have matched the BGTZ instruction from the earlier  | 
733  |  |   // ISA's instead).  | 
734  |  |   //  | 
735  |  |   // We have:  | 
736  |  |   //    0b000111 sssss ttttt iiiiiiiiiiiiiiii  | 
737  |  |   //      BGTZ    if rt == 0  | 
738  |  |   //      BGTZALC if rs == 0 && rt != 0  | 
739  |  |   //      BLTZALC if rs != 0 && rs == rt  | 
740  |  |   //      BLTUC   if rs != 0 && rs != rt  | 
741  |  |  | 
742  | 784  |   uint32_t Rs = fieldFromInstruction(insn, 21, 5);  | 
743  | 784  |   uint32_t Rt = fieldFromInstruction(insn, 16, 5);  | 
744  | 784  |   uint32_t Imm = (uint32_t)SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4;  | 
745  | 784  |   bool HasRs = false;  | 
746  | 784  |   bool HasRt = false;  | 
747  |  |  | 
748  | 784  |   if (Rt == 0) { | 
749  | 213  |     MCInst_setOpcode(MI, Mips_BGTZ);  | 
750  | 213  |     HasRs = true;  | 
751  | 571  |   } else if (Rs == 0) { | 
752  | 195  |     MCInst_setOpcode(MI, Mips_BGTZALC);  | 
753  | 195  |     HasRt = true;  | 
754  | 376  |   } else if (Rs == Rt) { | 
755  | 66  |     MCInst_setOpcode(MI, Mips_BLTZALC);  | 
756  | 66  |     HasRs = true;  | 
757  | 310  |   } else { | 
758  | 310  |     MCInst_setOpcode(MI, Mips_BLTUC);  | 
759  | 310  |     HasRs = true;  | 
760  | 310  |     HasRt = true;  | 
761  | 310  |   }  | 
762  |  |  | 
763  | 784  |   if (HasRs)  | 
764  | 589  |     MCOperand_CreateReg0(MI, getReg(Decoder, Mips_GPR32RegClassID, Rs));  | 
765  |  |  | 
766  | 784  |   if (HasRt)  | 
767  | 505  |     MCOperand_CreateReg0(MI, getReg(Decoder, Mips_GPR32RegClassID, Rt));  | 
768  |  |  | 
769  | 784  |   MCOperand_CreateImm0(MI, Imm);  | 
770  |  |  | 
771  | 784  |   return MCDisassembler_Success;  | 
772  | 784  | }  | 
773  |  |  | 
774  |  | static DecodeStatus DecodeBlezGroupBranch_4(MCInst *MI, uint32_t insn,  | 
775  |  |     uint64_t Address, const MCRegisterInfo *Decoder)  | 
776  | 858  | { | 
777  |  |   // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled  | 
778  |  |   // (otherwise we would have matched the BLEZL instruction from the earlier  | 
779  |  |   // ISA's instead).  | 
780  |  |   //  | 
781  |  |   // We have:  | 
782  |  |   //    0b000110 sssss ttttt iiiiiiiiiiiiiiii  | 
783  |  |   //      Invalid   if rs == 0  | 
784  |  |   //      BLEZALC   if rs == 0  && rt != 0  | 
785  |  |   //      BGEZALC   if rs == rt && rt != 0  | 
786  |  |   //      BGEUC     if rs != rt && rs != 0  && rt != 0  | 
787  |  |  | 
788  | 858  |   uint32_t Rs = fieldFromInstruction(insn, 21, 5);  | 
789  | 858  |   uint32_t Rt = fieldFromInstruction(insn, 16, 5);  | 
790  | 858  |   uint32_t Imm = (uint32_t)SignExtend64(fieldFromInstruction(insn, 0, 16), 16) * 4;  | 
791  | 858  |   bool HasRs = false;  | 
792  |  |  | 
793  | 858  |   if (Rt == 0)  | 
794  | 220  |     return MCDisassembler_Fail;  | 
795  | 638  |   else if (Rs == 0)  | 
796  | 204  |     MCInst_setOpcode(MI, Mips_BLEZALC);  | 
797  | 434  |   else if (Rs == Rt)  | 
798  | 198  |     MCInst_setOpcode(MI, Mips_BGEZALC);  | 
799  | 236  |   else { | 
800  | 236  |     HasRs = true;  | 
801  | 236  |     MCInst_setOpcode(MI, Mips_BGEUC);  | 
802  | 236  |   }  | 
803  |  |  | 
804  | 638  |   if (HasRs)  | 
805  | 236  |     MCOperand_CreateReg0(MI, getReg(Decoder, Mips_GPR32RegClassID, Rs));  | 
806  |  |  | 
807  | 638  |   MCOperand_CreateReg0(MI, getReg(Decoder, Mips_GPR32RegClassID, Rt));  | 
808  |  |  | 
809  | 638  |   MCOperand_CreateImm0(MI, Imm);  | 
810  |  |  | 
811  | 638  |   return MCDisassembler_Success;  | 
812  | 858  | }  | 
813  |  |  | 
814  |  | static DecodeStatus DecodeCPU16RegsRegisterClass(MCInst *Inst,  | 
815  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
816  | 0  | { | 
817  | 0  |   return MCDisassembler_Fail;  | 
818  | 0  | }  | 
819  |  |  | 
820  |  | static DecodeStatus DecodeGPR64RegisterClass(MCInst *Inst,  | 
821  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
822  | 10.3k  | { | 
823  | 10.3k  |   unsigned Reg;  | 
824  |  |  | 
825  | 10.3k  |   if (RegNo > 31)  | 
826  | 0  |     return MCDisassembler_Fail;  | 
827  |  |  | 
828  | 10.3k  |   Reg = getReg(Decoder, Mips_GPR64RegClassID, RegNo);  | 
829  | 10.3k  |   MCOperand_CreateReg0(Inst, Reg);  | 
830  | 10.3k  |   return MCDisassembler_Success;  | 
831  | 10.3k  | }  | 
832  |  |  | 
833  |  | static DecodeStatus DecodeGPRMM16RegisterClass(MCInst *Inst,  | 
834  |  |     unsigned RegNo, uint64_t Address, MCRegisterInfo *Decoder)  | 
835  | 10.7k  | { | 
836  | 10.7k  |   unsigned Reg;  | 
837  |  |  | 
838  | 10.7k  |   if (RegNo > 7)  | 
839  | 0  |     return MCDisassembler_Fail;  | 
840  |  |  | 
841  | 10.7k  |   Reg = getReg(Decoder, Mips_GPRMM16RegClassID, RegNo);  | 
842  | 10.7k  |   MCOperand_CreateReg0(Inst, Reg);  | 
843  | 10.7k  |   return MCDisassembler_Success;  | 
844  | 10.7k  | }  | 
845  |  |  | 
846  |  | static DecodeStatus DecodeGPRMM16ZeroRegisterClass(MCInst *Inst,  | 
847  |  |     unsigned RegNo, uint64_t Address, MCRegisterInfo *Decoder)  | 
848  | 1.20k  | { | 
849  | 1.20k  |   unsigned Reg;  | 
850  |  |  | 
851  | 1.20k  |   if (RegNo > 7)  | 
852  | 0  |     return MCDisassembler_Fail;  | 
853  |  |  | 
854  | 1.20k  |   Reg = getReg(Decoder, Mips_GPRMM16ZeroRegClassID, RegNo);  | 
855  | 1.20k  |   MCOperand_CreateReg0(Inst, Reg);  | 
856  | 1.20k  |   return MCDisassembler_Success;  | 
857  | 1.20k  | }  | 
858  |  |  | 
859  |  | static DecodeStatus DecodeGPRMM16MovePRegisterClass(MCInst *Inst,  | 
860  |  |     unsigned RegNo, uint64_t Address, MCRegisterInfo *Decoder)  | 
861  | 528  | { | 
862  | 528  |   unsigned Reg;  | 
863  |  |  | 
864  | 528  |   if (RegNo > 7)  | 
865  | 0  |     return MCDisassembler_Fail;  | 
866  |  |  | 
867  | 528  |   Reg = getReg(Decoder, Mips_GPRMM16MovePRegClassID, RegNo);  | 
868  | 528  |   MCOperand_CreateReg0(Inst, Reg);  | 
869  | 528  |   return MCDisassembler_Success;  | 
870  | 528  | }  | 
871  |  |  | 
872  |  | static DecodeStatus DecodeGPR32RegisterClass(MCInst *Inst,  | 
873  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
874  | 61.8k  | { | 
875  | 61.8k  |   unsigned Reg;  | 
876  |  |  | 
877  | 61.8k  |   if (RegNo > 31)  | 
878  | 0  |     return MCDisassembler_Fail;  | 
879  |  |  | 
880  | 61.8k  |   Reg = getReg(Decoder, Mips_GPR32RegClassID, RegNo);  | 
881  | 61.8k  |   MCOperand_CreateReg0(Inst, Reg);  | 
882  | 61.8k  |   return MCDisassembler_Success;  | 
883  | 61.8k  | }  | 
884  |  |  | 
885  |  | static DecodeStatus DecodePtrRegisterClass(MCInst *Inst,  | 
886  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
887  | 3.14k  | { | 
888  |  |   // if (static_cast<const MipsDisassembler *>(Decoder)->isGP64())  | 
889  | 3.14k  |   if (Inst->csh->mode & CS_MODE_MIPS64)  | 
890  | 1.78k  |     return DecodeGPR64RegisterClass(Inst, RegNo, Address, Decoder);  | 
891  |  |  | 
892  | 1.36k  |   return DecodeGPR32RegisterClass(Inst, RegNo, Address, Decoder);  | 
893  | 3.14k  | }  | 
894  |  |  | 
895  |  | static DecodeStatus DecodeDSPRRegisterClass(MCInst *Inst,  | 
896  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
897  | 2.73k  | { | 
898  | 2.73k  |   return DecodeGPR32RegisterClass(Inst, RegNo, Address, Decoder);  | 
899  | 2.73k  | }  | 
900  |  |  | 
901  |  | static DecodeStatus DecodeFGR64RegisterClass(MCInst *Inst,  | 
902  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
903  | 5.91k  | { | 
904  | 5.91k  |   unsigned Reg;  | 
905  |  |  | 
906  | 5.91k  |   if (RegNo > 31)  | 
907  | 0  |     return MCDisassembler_Fail;  | 
908  |  |  | 
909  | 5.91k  |   Reg = getReg(Decoder, Mips_FGR64RegClassID, RegNo);  | 
910  | 5.91k  |   MCOperand_CreateReg0(Inst, Reg);  | 
911  | 5.91k  |   return MCDisassembler_Success;  | 
912  | 5.91k  | }  | 
913  |  |  | 
914  |  | static DecodeStatus DecodeFGR32RegisterClass(MCInst *Inst,  | 
915  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
916  | 3.41k  | { | 
917  | 3.41k  |   unsigned Reg;  | 
918  |  |  | 
919  | 3.41k  |   if (RegNo > 31)  | 
920  | 0  |     return MCDisassembler_Fail;  | 
921  |  |  | 
922  | 3.41k  |   Reg = getReg(Decoder, Mips_FGR32RegClassID, RegNo);  | 
923  | 3.41k  |   MCOperand_CreateReg0(Inst, Reg);  | 
924  | 3.41k  |   return MCDisassembler_Success;  | 
925  | 3.41k  | }  | 
926  |  |  | 
927  |  | static DecodeStatus DecodeCCRRegisterClass(MCInst *Inst,  | 
928  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
929  | 283  | { | 
930  | 283  |   unsigned Reg;  | 
931  |  |  | 
932  | 283  |   if (RegNo > 31)  | 
933  | 0  |     return MCDisassembler_Fail;  | 
934  |  |  | 
935  | 283  |   Reg = getReg(Decoder, Mips_CCRRegClassID, RegNo);  | 
936  | 283  |   MCOperand_CreateReg0(Inst, Reg);  | 
937  | 283  |   return MCDisassembler_Success;  | 
938  | 283  | }  | 
939  |  |  | 
940  |  | static DecodeStatus DecodeFCCRegisterClass(MCInst *Inst,  | 
941  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
942  | 2.19k  | { | 
943  | 2.19k  |   unsigned Reg;  | 
944  |  |  | 
945  | 2.19k  |   if (RegNo > 7)  | 
946  | 0  |     return MCDisassembler_Fail;  | 
947  |  |  | 
948  | 2.19k  |   Reg = getReg(Decoder, Mips_FCCRegClassID, RegNo);  | 
949  | 2.19k  |   MCOperand_CreateReg0(Inst, Reg);  | 
950  | 2.19k  |   return MCDisassembler_Success;  | 
951  | 2.19k  | }  | 
952  |  |  | 
953  |  | static DecodeStatus DecodeCCRegisterClass(MCInst *Inst,  | 
954  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
955  | 4.40k  | { | 
956  | 4.40k  |   unsigned Reg;  | 
957  |  |  | 
958  | 4.40k  |   if (RegNo > 7)  | 
959  | 0  |     return MCDisassembler_Fail;  | 
960  |  |  | 
961  | 4.40k  |   Reg = getReg(Decoder, Mips_CCRegClassID, RegNo);  | 
962  | 4.40k  |   MCOperand_CreateReg0(Inst, Reg);  | 
963  | 4.40k  |   return MCDisassembler_Success;  | 
964  | 4.40k  | }  | 
965  |  |  | 
966  |  | static DecodeStatus DecodeFGRCCRegisterClass(MCInst *Inst,  | 
967  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
968  | 265  | { | 
969  | 265  |   unsigned Reg;  | 
970  |  |  | 
971  | 265  |   if (RegNo > 31)  | 
972  | 0  |     return MCDisassembler_Fail;  | 
973  |  |  | 
974  | 265  |   Reg = getReg(Decoder, Mips_FGRCCRegClassID, RegNo);  | 
975  | 265  |   MCOperand_CreateReg0(Inst, Reg);  | 
976  | 265  |   return MCDisassembler_Success;  | 
977  | 265  | }  | 
978  |  |  | 
979  |  | static DecodeStatus DecodeMem(MCInst *Inst,  | 
980  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder)  | 
981  | 6.64k  | { | 
982  | 6.64k  |   int Offset = SignExtend32(Insn & 0xffff, 16);  | 
983  | 6.64k  |   unsigned Reg = fieldFromInstruction(Insn, 16, 5);  | 
984  | 6.64k  |   unsigned Base = fieldFromInstruction(Insn, 21, 5);  | 
985  | 6.64k  |   int opcode = MCInst_getOpcode(Inst);  | 
986  |  |  | 
987  | 6.64k  |   Reg = getReg(Decoder, Mips_GPR32RegClassID, Reg);  | 
988  | 6.64k  |   Base = getReg(Decoder, Mips_GPR32RegClassID, Base);  | 
989  |  |  | 
990  | 6.64k  |   if (opcode == Mips_SC || opcode == Mips_SCD) { | 
991  | 627  |     MCOperand_CreateReg0(Inst, Reg);  | 
992  | 627  |   }  | 
993  |  |  | 
994  | 6.64k  |   MCOperand_CreateReg0(Inst, Reg);  | 
995  | 6.64k  |   MCOperand_CreateReg0(Inst, Base);  | 
996  | 6.64k  |   MCOperand_CreateImm0(Inst, Offset);  | 
997  |  |  | 
998  | 6.64k  |   return MCDisassembler_Success;  | 
999  | 6.64k  | }  | 
1000  |  |  | 
1001  |  | static DecodeStatus DecodeCacheOp(MCInst *Inst,  | 
1002  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder)  | 
1003  | 309  | { | 
1004  | 309  |   int Offset = SignExtend32(Insn & 0xffff, 16);  | 
1005  | 309  |   unsigned Hint = fieldFromInstruction(Insn, 16, 5);  | 
1006  | 309  |   unsigned Base = fieldFromInstruction(Insn, 21, 5);  | 
1007  |  |  | 
1008  | 309  |   Base = getReg(Decoder, Mips_GPR32RegClassID, Base);  | 
1009  |  |  | 
1010  | 309  |   MCOperand_CreateReg0(Inst, Base);  | 
1011  | 309  |   MCOperand_CreateImm0(Inst, Offset);  | 
1012  | 309  |   MCOperand_CreateImm0(Inst, Hint);  | 
1013  |  |  | 
1014  | 309  |   return MCDisassembler_Success;  | 
1015  | 309  | }  | 
1016  |  |  | 
1017  |  | static DecodeStatus DecodeCacheOpMM(MCInst *Inst,  | 
1018  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder)  | 
1019  | 198  | { | 
1020  | 198  |   int Offset = SignExtend32(Insn & 0xfff, 12);  | 
1021  | 198  |   unsigned Base = fieldFromInstruction(Insn, 16, 5);  | 
1022  | 198  |   unsigned Hint = fieldFromInstruction(Insn, 21, 5);  | 
1023  |  |  | 
1024  | 198  |   Base = getReg(Decoder, Mips_GPR32RegClassID, Base);  | 
1025  |  |  | 
1026  | 198  |   MCOperand_CreateReg0(Inst, Base);  | 
1027  | 198  |   MCOperand_CreateImm0(Inst, Offset);  | 
1028  | 198  |   MCOperand_CreateImm0(Inst, Hint);  | 
1029  |  |  | 
1030  | 198  |   return MCDisassembler_Success;  | 
1031  | 198  | }  | 
1032  |  |  | 
1033  |  | static DecodeStatus DecodeCacheOpR6(MCInst *Inst,  | 
1034  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder)  | 
1035  | 66  | { | 
1036  | 66  |   int Offset = fieldFromInstruction(Insn, 7, 9);  | 
1037  | 66  |   unsigned Hint = fieldFromInstruction(Insn, 16, 5);  | 
1038  | 66  |   unsigned Base = fieldFromInstruction(Insn, 21, 5);  | 
1039  |  |  | 
1040  | 66  |   Base = getReg(Decoder, Mips_GPR32RegClassID, Base);  | 
1041  |  |  | 
1042  | 66  |   MCOperand_CreateReg0(Inst, Base);  | 
1043  | 66  |   MCOperand_CreateImm0(Inst, Offset);  | 
1044  | 66  |   MCOperand_CreateImm0(Inst, Hint);  | 
1045  |  |  | 
1046  | 66  |   return MCDisassembler_Success;  | 
1047  | 66  | }  | 
1048  |  |  | 
1049  |  | static DecodeStatus DecodeSyncI(MCInst *Inst,  | 
1050  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder)  | 
1051  | 199  | { | 
1052  | 199  |   int Offset = SignExtend32(Insn & 0xffff, 16);  | 
1053  | 199  |   unsigned Base = fieldFromInstruction(Insn, 21, 5);  | 
1054  |  |  | 
1055  | 199  |   Base = getReg(Decoder, Mips_GPR32RegClassID, Base);  | 
1056  |  |  | 
1057  | 199  |   MCOperand_CreateReg0(Inst, Base);  | 
1058  | 199  |   MCOperand_CreateImm0(Inst, Offset);  | 
1059  |  |  | 
1060  | 199  |   return MCDisassembler_Success;  | 
1061  | 199  | }  | 
1062  |  |  | 
1063  |  | static DecodeStatus DecodeMSA128Mem(MCInst *Inst, unsigned Insn,  | 
1064  |  |     uint64_t Address, const MCRegisterInfo *Decoder)  | 
1065  | 1.66k  | { | 
1066  | 1.66k  |   int Offset = SignExtend32(fieldFromInstruction(Insn, 16, 10), 10);  | 
1067  | 1.66k  |   unsigned Reg = fieldFromInstruction(Insn, 6, 5);  | 
1068  | 1.66k  |   unsigned Base = fieldFromInstruction(Insn, 11, 5);  | 
1069  |  |  | 
1070  | 1.66k  |   Reg = getReg(Decoder, Mips_MSA128BRegClassID, Reg);  | 
1071  | 1.66k  |   Base = getReg(Decoder, Mips_GPR32RegClassID, Base);  | 
1072  |  |  | 
1073  | 1.66k  |   MCOperand_CreateReg0(Inst, Reg);  | 
1074  | 1.66k  |   MCOperand_CreateReg0(Inst, Base);  | 
1075  |  |   // MCOperand_CreateImm0(Inst, Offset);  | 
1076  |  |  | 
1077  |  |   // The immediate field of an LD/ST instruction is scaled which means it must  | 
1078  |  |   // be multiplied (when decoding) by the size (in bytes) of the instructions'  | 
1079  |  |   // data format.  | 
1080  |  |   // .b - 1 byte  | 
1081  |  |   // .h - 2 bytes  | 
1082  |  |   // .w - 4 bytes  | 
1083  |  |   // .d - 8 bytes  | 
1084  | 1.66k  |   switch(MCInst_getOpcode(Inst)) { | 
1085  | 0  |     default:  | 
1086  |  |       //assert (0 && "Unexpected instruction");  | 
1087  | 0  |       return MCDisassembler_Fail;  | 
1088  | 0  |       break;  | 
1089  | 218  |     case Mips_LD_B:  | 
1090  | 287  |     case Mips_ST_B:  | 
1091  | 287  |       MCOperand_CreateImm0(Inst, Offset);  | 
1092  | 287  |       break;  | 
1093  | 214  |     case Mips_LD_H:  | 
1094  | 514  |     case Mips_ST_H:  | 
1095  | 514  |       MCOperand_CreateImm0(Inst, Offset * 2);  | 
1096  | 514  |       break;  | 
1097  | 219  |     case Mips_LD_W:  | 
1098  | 522  |     case Mips_ST_W:  | 
1099  | 522  |       MCOperand_CreateImm0(Inst, Offset * 4);  | 
1100  | 522  |       break;  | 
1101  | 260  |     case Mips_LD_D:  | 
1102  | 341  |     case Mips_ST_D:  | 
1103  | 341  |       MCOperand_CreateImm0(Inst, Offset * 8);  | 
1104  | 341  |       break;  | 
1105  | 1.66k  |   }  | 
1106  |  |  | 
1107  | 1.66k  |   return MCDisassembler_Success;  | 
1108  | 1.66k  | }  | 
1109  |  |  | 
1110  |  | static DecodeStatus DecodeMemMMImm4(MCInst *Inst,  | 
1111  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder)  | 
1112  | 2.58k  | { | 
1113  | 2.58k  |   unsigned Offset = Insn & 0xf;  | 
1114  | 2.58k  |   unsigned Reg = fieldFromInstruction(Insn, 7, 3);  | 
1115  | 2.58k  |   unsigned Base = fieldFromInstruction(Insn, 4, 3);  | 
1116  |  |  | 
1117  | 2.58k  |   switch (MCInst_getOpcode(Inst)) { | 
1118  | 454  |     case Mips_LBU16_MM:  | 
1119  | 873  |     case Mips_LHU16_MM:  | 
1120  | 1.38k  |     case Mips_LW16_MM:  | 
1121  | 1.38k  |       if (DecodeGPRMM16RegisterClass(Inst, Reg, Address, Decoder)  | 
1122  | 1.38k  |           == MCDisassembler_Fail)  | 
1123  | 0  |         return MCDisassembler_Fail;  | 
1124  | 1.38k  |       break;  | 
1125  | 1.38k  |     case Mips_SB16_MM:  | 
1126  | 855  |     case Mips_SH16_MM:  | 
1127  | 1.20k  |     case Mips_SW16_MM:  | 
1128  | 1.20k  |       if (DecodeGPRMM16ZeroRegisterClass(Inst, Reg, Address, Decoder)  | 
1129  | 1.20k  |           == MCDisassembler_Fail)  | 
1130  | 0  |         return MCDisassembler_Fail;  | 
1131  | 1.20k  |       break;  | 
1132  | 2.58k  |   }  | 
1133  |  |  | 
1134  | 2.58k  |   if (DecodeGPRMM16RegisterClass(Inst, Base, Address, Decoder)  | 
1135  | 2.58k  |       == MCDisassembler_Fail)  | 
1136  | 0  |     return MCDisassembler_Fail;  | 
1137  |  |  | 
1138  | 2.58k  |   switch (MCInst_getOpcode(Inst)) { | 
1139  | 454  |     case Mips_LBU16_MM:  | 
1140  | 454  |       if (Offset == 0xf)  | 
1141  | 195  |         MCOperand_CreateImm0(Inst, -1);  | 
1142  | 259  |       else  | 
1143  | 259  |         MCOperand_CreateImm0(Inst, Offset);  | 
1144  | 454  |       break;  | 
1145  | 451  |     case Mips_SB16_MM:  | 
1146  | 451  |       MCOperand_CreateImm0(Inst, Offset);  | 
1147  | 451  |       break;  | 
1148  | 419  |     case Mips_LHU16_MM:  | 
1149  | 823  |     case Mips_SH16_MM:  | 
1150  | 823  |       MCOperand_CreateImm0(Inst, Offset << 1);  | 
1151  | 823  |       break;  | 
1152  | 510  |     case Mips_LW16_MM:  | 
1153  | 859  |     case Mips_SW16_MM:  | 
1154  | 859  |       MCOperand_CreateImm0(Inst, Offset << 2);  | 
1155  | 859  |       break;  | 
1156  | 2.58k  |   }  | 
1157  |  |  | 
1158  | 2.58k  |   return MCDisassembler_Success;  | 
1159  | 2.58k  | }  | 
1160  |  |  | 
1161  |  | static DecodeStatus DecodeMemMMSPImm5Lsl2(MCInst *Inst,  | 
1162  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder)  | 
1163  | 211  | { | 
1164  | 211  |   unsigned Offset = Insn & 0x1F;  | 
1165  | 211  |   unsigned Reg = fieldFromInstruction(Insn, 5, 5);  | 
1166  |  |  | 
1167  | 211  |   Reg = getReg(Decoder, Mips_GPR32RegClassID, Reg);  | 
1168  |  |  | 
1169  | 211  |   MCOperand_CreateReg0(Inst, Reg);  | 
1170  | 211  |   MCOperand_CreateReg0(Inst, Mips_SP);  | 
1171  | 211  |   MCOperand_CreateImm0(Inst, Offset << 2);  | 
1172  |  |  | 
1173  | 211  |   return MCDisassembler_Success;  | 
1174  | 211  | }  | 
1175  |  |  | 
1176  |  | static DecodeStatus DecodeMemMMGPImm7Lsl2(MCInst *Inst,  | 
1177  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder)  | 
1178  | 238  | { | 
1179  | 238  |   unsigned Offset = Insn & 0x7F;  | 
1180  | 238  |   unsigned Reg = fieldFromInstruction(Insn, 7, 3);  | 
1181  |  |  | 
1182  | 238  |   Reg = getReg(Decoder, Mips_GPR32RegClassID, Reg);  | 
1183  |  |  | 
1184  | 238  |   MCOperand_CreateReg0(Inst, Reg);  | 
1185  | 238  |   MCOperand_CreateReg0(Inst, Mips_GP);  | 
1186  | 238  |   MCOperand_CreateImm0(Inst, Offset << 2);  | 
1187  |  |  | 
1188  | 238  |   return MCDisassembler_Success;  | 
1189  | 238  | }  | 
1190  |  |  | 
1191  |  | static DecodeStatus DecodeMemMMReglistImm4Lsl2(MCInst *Inst,  | 
1192  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder)  | 
1193  | 533  | { | 
1194  | 533  |   int Offset = SignExtend32(Insn & 0xf, 4);  | 
1195  |  |  | 
1196  | 533  |   if (DecodeRegListOperand16(Inst, Insn, Address, Decoder) == MCDisassembler_Fail)  | 
1197  | 0  |     return MCDisassembler_Fail;  | 
1198  |  |  | 
1199  | 533  |   MCOperand_CreateReg0(Inst, Mips_SP);  | 
1200  | 533  |   MCOperand_CreateImm0(Inst, Offset * 4);  | 
1201  |  |  | 
1202  | 533  |   return MCDisassembler_Success;  | 
1203  | 533  | }  | 
1204  |  |  | 
1205  |  | static DecodeStatus DecodeMemMMImm12(MCInst *Inst,  | 
1206  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1207  | 1.03k  | { | 
1208  | 1.03k  |   int Offset = SignExtend32(Insn & 0x0fff, 12);  | 
1209  | 1.03k  |   unsigned Reg = fieldFromInstruction(Insn, 21, 5);  | 
1210  | 1.03k  |   unsigned Base = fieldFromInstruction(Insn, 16, 5);  | 
1211  |  |  | 
1212  | 1.03k  |   Reg = getReg(Decoder, Mips_GPR32RegClassID, Reg);  | 
1213  | 1.03k  |   Base = getReg(Decoder, Mips_GPR32RegClassID, Base);  | 
1214  |  |  | 
1215  | 1.03k  |   switch (MCInst_getOpcode(Inst)) { | 
1216  | 359  |     case Mips_SWM32_MM:  | 
1217  | 504  |     case Mips_LWM32_MM:  | 
1218  | 504  |       if (DecodeRegListOperand(Inst, Insn, Address, Decoder)  | 
1219  | 504  |           == MCDisassembler_Fail)  | 
1220  | 1  |         return MCDisassembler_Fail;  | 
1221  | 503  |       MCOperand_CreateReg0(Inst, Base);  | 
1222  | 503  |       MCOperand_CreateImm0(Inst, Offset);  | 
1223  | 503  |       break;  | 
1224  | 66  |     case Mips_SC_MM:  | 
1225  | 66  |       MCOperand_CreateReg0(Inst, Reg);  | 
1226  |  |       // fallthrough  | 
1227  | 526  |     default:  | 
1228  | 526  |       MCOperand_CreateReg0(Inst, Reg);  | 
1229  | 526  |       if (MCInst_getOpcode(Inst) == Mips_LWP_MM || MCInst_getOpcode(Inst) == Mips_SWP_MM)  | 
1230  | 287  |         MCOperand_CreateReg0(Inst, Reg + 1);  | 
1231  |  |  | 
1232  | 526  |       MCOperand_CreateReg0(Inst, Base);  | 
1233  | 526  |       MCOperand_CreateImm0(Inst, Offset);  | 
1234  | 1.03k  |   }  | 
1235  |  |  | 
1236  | 1.02k  |   return MCDisassembler_Success;  | 
1237  | 1.03k  | }  | 
1238  |  |  | 
1239  |  | static DecodeStatus DecodeMemMMImm16(MCInst *Inst,  | 
1240  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1241  | 1.11k  | { | 
1242  | 1.11k  |   int Offset = SignExtend32(Insn & 0xffff, 16);  | 
1243  | 1.11k  |   unsigned Reg = fieldFromInstruction(Insn, 21, 5);  | 
1244  | 1.11k  |   unsigned Base = fieldFromInstruction(Insn, 16, 5);  | 
1245  |  |  | 
1246  | 1.11k  |   Reg = getReg(Decoder, Mips_GPR32RegClassID, Reg);  | 
1247  | 1.11k  |   Base = getReg(Decoder, Mips_GPR32RegClassID, Base);  | 
1248  |  |  | 
1249  | 1.11k  |   MCOperand_CreateReg0(Inst, Reg);  | 
1250  | 1.11k  |   MCOperand_CreateReg0(Inst, Base);  | 
1251  | 1.11k  |   MCOperand_CreateImm0(Inst, Offset);  | 
1252  |  |  | 
1253  | 1.11k  |   return MCDisassembler_Success;  | 
1254  | 1.11k  | }  | 
1255  |  |  | 
1256  |  | static DecodeStatus DecodeFMem(MCInst *Inst,  | 
1257  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1258  | 584  | { | 
1259  | 584  |   int Offset = SignExtend32(Insn & 0xffff, 16);  | 
1260  | 584  |   unsigned Reg = fieldFromInstruction(Insn, 16, 5);  | 
1261  | 584  |   unsigned Base = fieldFromInstruction(Insn, 21, 5);  | 
1262  |  |  | 
1263  | 584  |   Reg = getReg(Decoder, Mips_FGR64RegClassID, Reg);  | 
1264  | 584  |   Base = getReg(Decoder, Mips_GPR32RegClassID, Base);  | 
1265  |  |  | 
1266  | 584  |   MCOperand_CreateReg0(Inst, Reg);  | 
1267  | 584  |   MCOperand_CreateReg0(Inst, Base);  | 
1268  | 584  |   MCOperand_CreateImm0(Inst, Offset);  | 
1269  |  |  | 
1270  | 584  |   return MCDisassembler_Success;  | 
1271  | 584  | }  | 
1272  |  |  | 
1273  |  | static DecodeStatus DecodeFMem2(MCInst *Inst,  | 
1274  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder)  | 
1275  | 731  | { | 
1276  | 731  |   int Offset = SignExtend32(Insn & 0xffff, 16);  | 
1277  | 731  |   unsigned Reg = fieldFromInstruction(Insn, 16, 5);  | 
1278  | 731  |   unsigned Base = fieldFromInstruction(Insn, 21, 5);  | 
1279  |  |  | 
1280  | 731  |   Reg = getReg(Decoder, Mips_COP2RegClassID, Reg);  | 
1281  | 731  |   Base = getReg(Decoder, Mips_GPR32RegClassID, Base);  | 
1282  |  |  | 
1283  | 731  |   MCOperand_CreateReg0(Inst, Reg);  | 
1284  | 731  |   MCOperand_CreateReg0(Inst, Base);  | 
1285  | 731  |   MCOperand_CreateImm0(Inst, Offset);  | 
1286  |  |  | 
1287  | 731  |   return MCDisassembler_Success;  | 
1288  | 731  | }  | 
1289  |  |  | 
1290  |  | static DecodeStatus DecodeFMem3(MCInst *Inst,  | 
1291  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder)  | 
1292  | 0  | { | 
1293  | 0  |   int Offset = SignExtend32(Insn & 0xffff, 16);  | 
1294  | 0  |   unsigned Reg = fieldFromInstruction(Insn, 16, 5);  | 
1295  | 0  |   unsigned Base = fieldFromInstruction(Insn, 21, 5);  | 
1296  |  | 
  | 
1297  | 0  |   Reg = getReg(Decoder, Mips_COP3RegClassID, Reg);  | 
1298  | 0  |   Base = getReg(Decoder, Mips_GPR32RegClassID, Base);  | 
1299  |  | 
  | 
1300  | 0  |   MCOperand_CreateReg0(Inst, Reg);  | 
1301  | 0  |   MCOperand_CreateReg0(Inst, Base);  | 
1302  | 0  |   MCOperand_CreateImm0(Inst, Offset);  | 
1303  |  | 
  | 
1304  | 0  |   return MCDisassembler_Success;  | 
1305  | 0  | }  | 
1306  |  |  | 
1307  |  | static DecodeStatus DecodeFMemCop2R6(MCInst *Inst,  | 
1308  |  |     unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder)  | 
1309  | 272  | { | 
1310  | 272  |   int Offset = SignExtend32(Insn & 0x07ff, 11);  | 
1311  | 272  |   unsigned Reg = fieldFromInstruction(Insn, 16, 5);  | 
1312  | 272  |   unsigned Base = fieldFromInstruction(Insn, 11, 5);  | 
1313  |  |  | 
1314  | 272  |   Reg = getReg(Decoder, Mips_COP2RegClassID, Reg);  | 
1315  | 272  |   Base = getReg(Decoder, Mips_GPR32RegClassID, Base);  | 
1316  |  |  | 
1317  | 272  |   MCOperand_CreateReg0(Inst, Reg);  | 
1318  | 272  |   MCOperand_CreateReg0(Inst, Base);  | 
1319  | 272  |   MCOperand_CreateImm0(Inst, Offset);  | 
1320  |  |  | 
1321  | 272  |   return MCDisassembler_Success;  | 
1322  | 272  | }  | 
1323  |  |  | 
1324  |  | static DecodeStatus DecodeSpecial3LlSc(MCInst *Inst,  | 
1325  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1326  | 338  | { | 
1327  | 338  |   int64_t Offset = SignExtend64((Insn >> 7) & 0x1ff, 9);  | 
1328  | 338  |   unsigned Rt = fieldFromInstruction(Insn, 16, 5);  | 
1329  | 338  |   unsigned Base = fieldFromInstruction(Insn, 21, 5);  | 
1330  |  |  | 
1331  | 338  |   Rt = getReg(Decoder, Mips_GPR32RegClassID, Rt);  | 
1332  | 338  |   Base = getReg(Decoder, Mips_GPR32RegClassID, Base);  | 
1333  |  |  | 
1334  | 338  |   if (MCInst_getOpcode(Inst) == Mips_SC_R6 ||  | 
1335  | 271  |       MCInst_getOpcode(Inst) == Mips_SCD_R6) { | 
1336  | 271  |     MCOperand_CreateReg0(Inst, Rt);  | 
1337  | 271  |   }  | 
1338  |  |  | 
1339  | 338  |   MCOperand_CreateReg0(Inst, Rt);  | 
1340  | 338  |   MCOperand_CreateReg0(Inst, Base);  | 
1341  | 338  |   MCOperand_CreateImm0(Inst, Offset);  | 
1342  |  |  | 
1343  | 338  |   return MCDisassembler_Success;  | 
1344  | 338  | }  | 
1345  |  |  | 
1346  |  | static DecodeStatus DecodeHWRegsRegisterClass(MCInst *Inst,  | 
1347  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1348  | 144  | { | 
1349  |  |   // Currently only hardware register 29 is supported.  | 
1350  | 144  |   if (RegNo != 29)  | 
1351  | 10  |     return  MCDisassembler_Fail;  | 
1352  |  |  | 
1353  | 134  |   MCOperand_CreateReg0(Inst, Mips_HWR29);  | 
1354  |  |  | 
1355  | 134  |   return MCDisassembler_Success;  | 
1356  | 144  | }  | 
1357  |  |  | 
1358  |  | static DecodeStatus DecodeAFGR64RegisterClass(MCInst *Inst,  | 
1359  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1360  | 2.15k  | { | 
1361  | 2.15k  |   unsigned Reg;  | 
1362  |  |  | 
1363  | 2.15k  |   if (RegNo > 30 || RegNo % 2)  | 
1364  | 21  |     return MCDisassembler_Fail;  | 
1365  |  |  | 
1366  | 2.13k  |   Reg = getReg(Decoder, Mips_AFGR64RegClassID, RegNo /2);  | 
1367  | 2.13k  |   MCOperand_CreateReg0(Inst, Reg);  | 
1368  |  |  | 
1369  | 2.13k  |   return MCDisassembler_Success;  | 
1370  | 2.15k  | }  | 
1371  |  |  | 
1372  |  | static DecodeStatus DecodeACC64DSPRegisterClass(MCInst *Inst,  | 
1373  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1374  | 1.65k  | { | 
1375  | 1.65k  |   unsigned Reg;  | 
1376  |  |  | 
1377  | 1.65k  |   if (RegNo >= 4)  | 
1378  | 0  |     return MCDisassembler_Fail;  | 
1379  |  |  | 
1380  | 1.65k  |   Reg = getReg(Decoder, Mips_ACC64DSPRegClassID, RegNo);  | 
1381  | 1.65k  |   MCOperand_CreateReg0(Inst, Reg);  | 
1382  | 1.65k  |   return MCDisassembler_Success;  | 
1383  | 1.65k  | }  | 
1384  |  |  | 
1385  |  | static DecodeStatus DecodeHI32DSPRegisterClass(MCInst *Inst,  | 
1386  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1387  | 71  | { | 
1388  | 71  |   unsigned Reg;  | 
1389  |  |  | 
1390  | 71  |   if (RegNo >= 4)  | 
1391  | 0  |     return MCDisassembler_Fail;  | 
1392  |  |  | 
1393  | 71  |   Reg = getReg(Decoder, Mips_HI32DSPRegClassID, RegNo);  | 
1394  | 71  |   MCOperand_CreateReg0(Inst, Reg);  | 
1395  |  |  | 
1396  | 71  |   return MCDisassembler_Success;  | 
1397  | 71  | }  | 
1398  |  |  | 
1399  |  | static DecodeStatus DecodeLO32DSPRegisterClass(MCInst *Inst,  | 
1400  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1401  | 298  | { | 
1402  | 298  |   unsigned Reg;  | 
1403  |  |  | 
1404  | 298  |   if (RegNo >= 4)  | 
1405  | 0  |     return MCDisassembler_Fail;  | 
1406  |  |  | 
1407  | 298  |   Reg = getReg(Decoder, Mips_LO32DSPRegClassID, RegNo);  | 
1408  | 298  |   MCOperand_CreateReg0(Inst, Reg);  | 
1409  |  |  | 
1410  | 298  |   return MCDisassembler_Success;  | 
1411  | 298  | }  | 
1412  |  |  | 
1413  |  | static DecodeStatus DecodeMSA128BRegisterClass(MCInst *Inst,  | 
1414  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1415  | 8.99k  | { | 
1416  | 8.99k  |   unsigned Reg;  | 
1417  |  |  | 
1418  | 8.99k  |   if (RegNo > 31)  | 
1419  | 0  |     return MCDisassembler_Fail;  | 
1420  |  |  | 
1421  | 8.99k  |   Reg = getReg(Decoder, Mips_MSA128BRegClassID, RegNo);  | 
1422  | 8.99k  |   MCOperand_CreateReg0(Inst, Reg);  | 
1423  |  |  | 
1424  | 8.99k  |   return MCDisassembler_Success;  | 
1425  | 8.99k  | }  | 
1426  |  |  | 
1427  |  | static DecodeStatus DecodeMSA128HRegisterClass(MCInst *Inst,  | 
1428  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1429  | 6.28k  | { | 
1430  | 6.28k  |   unsigned Reg;  | 
1431  |  |  | 
1432  | 6.28k  |   if (RegNo > 31)  | 
1433  | 0  |     return MCDisassembler_Fail;  | 
1434  |  |  | 
1435  | 6.28k  |   Reg = getReg(Decoder, Mips_MSA128HRegClassID, RegNo);  | 
1436  | 6.28k  |   MCOperand_CreateReg0(Inst, Reg);  | 
1437  |  |  | 
1438  | 6.28k  |   return MCDisassembler_Success;  | 
1439  | 6.28k  | }  | 
1440  |  |  | 
1441  |  | static DecodeStatus DecodeMSA128WRegisterClass(MCInst *Inst,  | 
1442  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1443  | 6.93k  | { | 
1444  | 6.93k  |   unsigned Reg;  | 
1445  |  |  | 
1446  | 6.93k  |   if (RegNo > 31)  | 
1447  | 0  |     return MCDisassembler_Fail;  | 
1448  |  |  | 
1449  | 6.93k  |   Reg = getReg(Decoder, Mips_MSA128WRegClassID, RegNo);  | 
1450  | 6.93k  |   MCOperand_CreateReg0(Inst, Reg);  | 
1451  |  |  | 
1452  | 6.93k  |   return MCDisassembler_Success;  | 
1453  | 6.93k  | }  | 
1454  |  |  | 
1455  |  | static DecodeStatus DecodeMSA128DRegisterClass(MCInst *Inst,  | 
1456  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1457  | 5.73k  | { | 
1458  | 5.73k  |   unsigned Reg;  | 
1459  |  |  | 
1460  | 5.73k  |   if (RegNo > 31)  | 
1461  | 0  |     return MCDisassembler_Fail;  | 
1462  |  |  | 
1463  | 5.73k  |   Reg = getReg(Decoder, Mips_MSA128DRegClassID, RegNo);  | 
1464  | 5.73k  |   MCOperand_CreateReg0(Inst, Reg);  | 
1465  |  |  | 
1466  | 5.73k  |   return MCDisassembler_Success;  | 
1467  | 5.73k  | }  | 
1468  |  |  | 
1469  |  | static DecodeStatus DecodeMSACtrlRegisterClass(MCInst *Inst,  | 
1470  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1471  | 134  | { | 
1472  | 134  |   unsigned Reg;  | 
1473  |  |  | 
1474  | 134  |   if (RegNo > 7)  | 
1475  | 2  |     return MCDisassembler_Fail;  | 
1476  |  |  | 
1477  | 132  |   Reg = getReg(Decoder, Mips_MSACtrlRegClassID, RegNo);  | 
1478  | 132  |   MCOperand_CreateReg0(Inst, Reg);  | 
1479  |  |  | 
1480  | 132  |   return MCDisassembler_Success;  | 
1481  | 134  | }  | 
1482  |  |  | 
1483  |  | static DecodeStatus DecodeCOP2RegisterClass(MCInst *Inst,  | 
1484  |  |     unsigned RegNo, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1485  | 204  | { | 
1486  | 204  |   unsigned Reg;  | 
1487  |  |  | 
1488  | 204  |   if (RegNo > 31)  | 
1489  | 0  |     return MCDisassembler_Fail;  | 
1490  |  |  | 
1491  | 204  |   Reg = getReg(Decoder, Mips_COP2RegClassID, RegNo);  | 
1492  | 204  |   MCOperand_CreateReg0(Inst, Reg);  | 
1493  |  |  | 
1494  | 204  |   return MCDisassembler_Success;  | 
1495  | 204  | }  | 
1496  |  |  | 
1497  |  | static DecodeStatus DecodeBranchTarget(MCInst *Inst,  | 
1498  |  |     unsigned Offset, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1499  | 11.6k  | { | 
1500  | 11.6k  |   uint64_t TargetAddress = (SignExtend32(Offset, 16) * 4) + Address + 4;  | 
1501  | 11.6k  |   MCOperand_CreateImm0(Inst, TargetAddress);  | 
1502  |  |  | 
1503  | 11.6k  |   return MCDisassembler_Success;  | 
1504  | 11.6k  | }  | 
1505  |  |  | 
1506  |  | static DecodeStatus DecodeJumpTarget(MCInst *Inst,  | 
1507  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1508  | 2.57k  | { | 
1509  | 2.57k  |   uint64_t TargetAddress = (fieldFromInstruction(Insn, 0, 26) << 2) | ((Address + 4) & ~0x0FFFFFFF);  | 
1510  | 2.57k  |   MCOperand_CreateImm0(Inst, TargetAddress);  | 
1511  |  |  | 
1512  | 2.57k  |   return MCDisassembler_Success;  | 
1513  | 2.57k  | }  | 
1514  |  |  | 
1515  |  | static DecodeStatus DecodeBranchTarget21(MCInst *Inst,  | 
1516  |  |     unsigned Offset, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1517  | 280  | { | 
1518  | 280  |   int32_t BranchOffset = SignExtend32(Offset, 21) * 4;  | 
1519  |  |  | 
1520  | 280  |   MCOperand_CreateImm0(Inst, BranchOffset);  | 
1521  |  |  | 
1522  | 280  |   return MCDisassembler_Success;  | 
1523  | 280  | }  | 
1524  |  |  | 
1525  |  | static DecodeStatus DecodeBranchTarget26(MCInst *Inst,  | 
1526  |  |     unsigned Offset, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1527  | 339  | { | 
1528  | 339  |   int32_t BranchOffset = SignExtend32(Offset, 26) * 4;  | 
1529  |  |  | 
1530  | 339  |   MCOperand_CreateImm0(Inst, BranchOffset);  | 
1531  | 339  |   return MCDisassembler_Success;  | 
1532  | 339  | }  | 
1533  |  |  | 
1534  |  | static DecodeStatus DecodeBranchTarget7MM(MCInst *Inst,  | 
1535  |  |     unsigned Offset, uint64_t Address, MCRegisterInfo *Decoder)  | 
1536  | 265  | { | 
1537  | 265  |   int32_t BranchOffset = SignExtend32(Offset, 7) * 2;  | 
1538  | 265  |   MCOperand_CreateImm0(Inst, BranchOffset);  | 
1539  | 265  |   return MCDisassembler_Success;  | 
1540  | 265  | }  | 
1541  |  |  | 
1542  |  | static DecodeStatus DecodeBranchTarget10MM(MCInst *Inst,  | 
1543  |  |     unsigned Offset, uint64_t Address, MCRegisterInfo *Decoder)  | 
1544  | 299  | { | 
1545  | 299  |   int32_t BranchOffset = SignExtend32(Offset, 10) * 2;  | 
1546  | 299  |   MCOperand_CreateImm0(Inst, BranchOffset);  | 
1547  | 299  |   return MCDisassembler_Success;  | 
1548  | 299  | }  | 
1549  |  |  | 
1550  |  | static DecodeStatus DecodeBranchTargetMM(MCInst *Inst,  | 
1551  |  |     unsigned Offset, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1552  | 574  | { | 
1553  | 574  |   int32_t BranchOffset = SignExtend32(Offset, 16) * 2;  | 
1554  | 574  |   MCOperand_CreateImm0(Inst, BranchOffset);  | 
1555  |  |  | 
1556  | 574  |   return MCDisassembler_Success;  | 
1557  | 574  | }  | 
1558  |  |  | 
1559  |  | static DecodeStatus DecodeJumpTargetMM(MCInst *Inst,  | 
1560  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1561  | 675  | { | 
1562  | 675  |   unsigned JumpOffset = fieldFromInstruction(Insn, 0, 26) << 1;  | 
1563  | 675  |   MCOperand_CreateImm0(Inst, JumpOffset);  | 
1564  |  |  | 
1565  | 675  |   return MCDisassembler_Success;  | 
1566  | 675  | }  | 
1567  |  |  | 
1568  |  | static DecodeStatus DecodeAddiur2Simm7(MCInst *Inst,  | 
1569  |  |     unsigned Value, uint64_t Address, MCRegisterInfo *Decoder)  | 
1570  | 1.03k  | { | 
1571  | 1.03k  |   if (Value == 0)  | 
1572  | 207  |     MCOperand_CreateImm0(Inst, 1);  | 
1573  | 827  |   else if (Value == 0x7)  | 
1574  | 448  |     MCOperand_CreateImm0(Inst, -1);  | 
1575  | 379  |   else  | 
1576  | 379  |     MCOperand_CreateImm0(Inst, Value << 2);  | 
1577  |  |  | 
1578  | 1.03k  |   return MCDisassembler_Success;  | 
1579  | 1.03k  | }  | 
1580  |  |  | 
1581  |  | static DecodeStatus DecodeUImm6Lsl2(MCInst *Inst,  | 
1582  |  |     unsigned Value, uint64_t Address, MCRegisterInfo *Decoder)  | 
1583  | 222  | { | 
1584  | 222  |   MCOperand_CreateImm0(Inst, Value << 2);  | 
1585  |  |  | 
1586  | 222  |   return MCDisassembler_Success;  | 
1587  | 222  | }  | 
1588  |  |  | 
1589  |  | static DecodeStatus DecodeLiSimm7(MCInst *Inst,  | 
1590  |  |     unsigned Value, uint64_t Address, MCRegisterInfo *Decoder)  | 
1591  | 942  | { | 
1592  | 942  |   if (Value == 0x7F)  | 
1593  | 194  |     MCOperand_CreateImm0(Inst, -1);  | 
1594  | 748  |   else  | 
1595  | 748  |     MCOperand_CreateImm0(Inst, Value);  | 
1596  |  |  | 
1597  | 942  |   return MCDisassembler_Success;  | 
1598  | 942  | }  | 
1599  |  |  | 
1600  |  | static DecodeStatus DecodeSimm4(MCInst *Inst,  | 
1601  |  |     unsigned Value, uint64_t Address, MCRegisterInfo *Decoder)  | 
1602  | 218  | { | 
1603  | 218  |   MCOperand_CreateImm0(Inst, SignExtend32(Value, 4));  | 
1604  |  |  | 
1605  | 218  |   return MCDisassembler_Success;  | 
1606  | 218  | }  | 
1607  |  |  | 
1608  |  | static DecodeStatus DecodeSimm16(MCInst *Inst,  | 
1609  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1610  | 5.12k  | { | 
1611  | 5.12k  |   MCOperand_CreateImm0(Inst, SignExtend32(Insn, 16));  | 
1612  |  |  | 
1613  | 5.12k  |   return MCDisassembler_Success;  | 
1614  | 5.12k  | }  | 
1615  |  |  | 
1616  |  | static DecodeStatus DecodeLSAImm(MCInst *Inst,  | 
1617  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1618  | 298  | { | 
1619  |  |   // We add one to the immediate field as it was encoded as 'imm - 1'.  | 
1620  | 298  |   MCOperand_CreateImm0(Inst, Insn + 1);  | 
1621  |  |  | 
1622  | 298  |   return MCDisassembler_Success;  | 
1623  | 298  | }  | 
1624  |  |  | 
1625  |  | static DecodeStatus DecodeInsSize(MCInst *Inst,  | 
1626  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1627  | 601  | { | 
1628  |  |   // First we need to grab the pos(lsb) from MCInst.  | 
1629  | 601  |   int Pos = (int)MCOperand_getImm(MCInst_getOperand(Inst, 2));  | 
1630  | 601  |   int Size = (int) Insn - Pos + 1;  | 
1631  | 601  |   MCOperand_CreateImm0(Inst, SignExtend32(Size, 16));  | 
1632  |  |  | 
1633  | 601  |   return MCDisassembler_Success;  | 
1634  | 601  | }  | 
1635  |  |  | 
1636  |  | static DecodeStatus DecodeExtSize(MCInst *Inst,  | 
1637  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1638  | 619  | { | 
1639  | 619  |   int Size = (int)Insn  + 1;  | 
1640  |  |  | 
1641  | 619  |   MCOperand_CreateImm0(Inst, SignExtend32(Size, 16));  | 
1642  |  |  | 
1643  | 619  |   return MCDisassembler_Success;  | 
1644  | 619  | }  | 
1645  |  |  | 
1646  |  | static DecodeStatus DecodeSimm19Lsl2(MCInst *Inst,  | 
1647  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1648  | 249  | { | 
1649  | 249  |   MCOperand_CreateImm0(Inst, SignExtend32(Insn, 19) * 4);  | 
1650  |  |  | 
1651  | 249  |   return MCDisassembler_Success;  | 
1652  | 249  | }  | 
1653  |  |  | 
1654  |  | static DecodeStatus DecodeSimm18Lsl3(MCInst *Inst,  | 
1655  |  |     unsigned Insn, uint64_t Address, const MCRegisterInfo *Decoder)  | 
1656  | 0  | { | 
1657  | 0  |   MCOperand_CreateImm0(Inst, SignExtend32(Insn, 18) * 8);  | 
1658  |  | 
  | 
1659  | 0  |   return MCDisassembler_Success;  | 
1660  | 0  | }  | 
1661  |  |  | 
1662  |  | static DecodeStatus DecodeSimm9SP(MCInst *Inst, unsigned Insn,  | 
1663  |  |     uint64_t Address, MCRegisterInfo *Decoder)  | 
1664  | 911  | { | 
1665  | 911  |   int32_t DecodedValue;  | 
1666  |  |  | 
1667  | 911  |   switch (Insn) { | 
1668  | 197  |     case 0: DecodedValue = 256; break;  | 
1669  | 197  |     case 1: DecodedValue = 257; break;  | 
1670  | 195  |     case 510: DecodedValue = -258; break;  | 
1671  | 69  |     case 511: DecodedValue = -257; break;  | 
1672  | 253  |     default: DecodedValue = SignExtend32(Insn, 9); break;  | 
1673  | 911  |   }  | 
1674  | 911  |   MCOperand_CreateImm0(Inst, DecodedValue * 4);  | 
1675  |  |  | 
1676  | 911  |   return MCDisassembler_Success;  | 
1677  | 911  | }  | 
1678  |  |  | 
1679  |  | static DecodeStatus DecodeANDI16Imm(MCInst *Inst, unsigned Insn,  | 
1680  |  |     uint64_t Address, MCRegisterInfo *Decoder)  | 
1681  | 219  | { | 
1682  |  |   // Insn must be >= 0, since it is unsigned that condition is always true.  | 
1683  |  |   // assert(Insn < 16);  | 
1684  | 219  |   int32_t DecodedValues[] = {128, 1, 2, 3, 4, 7, 8, 15, 16, 31, 32, 63, 64, | 
1685  | 219  |     255, 32768, 65535};  | 
1686  |  |  | 
1687  | 219  |   if (Insn >= 16)  | 
1688  | 0  |     return MCDisassembler_Fail;  | 
1689  |  |  | 
1690  | 219  |   MCOperand_CreateImm0(Inst, DecodedValues[Insn]);  | 
1691  |  |  | 
1692  | 219  |   return MCDisassembler_Success;  | 
1693  | 219  | }  | 
1694  |  |  | 
1695  |  | static DecodeStatus DecodeUImm5lsl2(MCInst *Inst, unsigned Insn,  | 
1696  |  |     uint64_t Address, MCRegisterInfo *Decoder)  | 
1697  | 66  | { | 
1698  | 66  |   MCOperand_CreateImm0(Inst, Insn << 2);  | 
1699  |  |  | 
1700  | 66  |   return MCDisassembler_Success;  | 
1701  | 66  | }  | 
1702  |  |  | 
1703  |  | static DecodeStatus DecodeRegListOperand(MCInst *Inst, unsigned Insn,  | 
1704  |  |     uint64_t Address, const MCRegisterInfo *Decoder)  | 
1705  | 504  | { | 
1706  | 504  |   unsigned Regs[] = {Mips_S0, Mips_S1, Mips_S2, Mips_S3, Mips_S4, Mips_S5, | 
1707  | 504  |     Mips_S6, Mips_FP};  | 
1708  | 504  |   unsigned RegNum;  | 
1709  | 504  |   unsigned int i;  | 
1710  |  |  | 
1711  | 504  |   unsigned RegLst = fieldFromInstruction(Insn, 21, 5);  | 
1712  |  |   // Empty register lists are not allowed.  | 
1713  | 504  |   if (RegLst == 0)  | 
1714  | 1  |     return MCDisassembler_Fail;  | 
1715  |  |  | 
1716  | 503  |   RegNum = RegLst & 0xf;  | 
1717  | 2.33k  |   for (i = 0; i < MIN(RegNum, ARR_SIZE(Regs)); i++)  | 
1718  | 1.82k  |     MCOperand_CreateReg0(Inst, Regs[i]);  | 
1719  |  |  | 
1720  | 503  |   if (RegLst & 0x10)  | 
1721  | 424  |     MCOperand_CreateReg0(Inst, Mips_RA);  | 
1722  |  |  | 
1723  | 503  |   return MCDisassembler_Success;  | 
1724  | 504  | }  | 
1725  |  |  | 
1726  |  | static DecodeStatus DecodeRegListOperand16(MCInst *Inst, unsigned Insn,  | 
1727  |  |     uint64_t Address, MCRegisterInfo *Decoder)  | 
1728  | 533  | { | 
1729  | 533  |   unsigned Regs[] = {Mips_S0, Mips_S1, Mips_S2, Mips_S3}; | 
1730  | 533  |   unsigned RegLst = fieldFromInstruction(Insn, 4, 2);  | 
1731  | 533  |   unsigned RegNum = RegLst & 0x3;  | 
1732  | 533  |   unsigned int i;  | 
1733  |  |  | 
1734  | 1.64k  |   for (i = 0; i <= RegNum; i++)  | 
1735  | 1.11k  |     MCOperand_CreateReg0(Inst, Regs[i]);  | 
1736  |  |  | 
1737  | 533  |   MCOperand_CreateReg0(Inst, Mips_RA);  | 
1738  |  |  | 
1739  | 533  |   return MCDisassembler_Success;  | 
1740  | 533  | }  | 
1741  |  |  | 
1742  |  | static DecodeStatus DecodeMovePRegPair(MCInst *Inst, unsigned Insn,  | 
1743  |  |     uint64_t Address, MCRegisterInfo *Decoder)  | 
1744  | 264  | { | 
1745  | 264  |   unsigned RegPair = fieldFromInstruction(Insn, 7, 3);  | 
1746  |  |  | 
1747  | 264  |   switch (RegPair) { | 
1748  | 0  |     default:  | 
1749  | 0  |       return MCDisassembler_Fail;  | 
1750  | 264  |     case 0:  | 
1751  | 264  |       MCOperand_CreateReg0(Inst, Mips_A1);  | 
1752  | 264  |       MCOperand_CreateReg0(Inst, Mips_A2);  | 
1753  | 264  |       break;  | 
1754  | 0  |     case 1:  | 
1755  | 0  |       MCOperand_CreateReg0(Inst, Mips_A1);  | 
1756  | 0  |       MCOperand_CreateReg0(Inst, Mips_A3);  | 
1757  | 0  |       break;  | 
1758  | 0  |     case 2:  | 
1759  | 0  |       MCOperand_CreateReg0(Inst, Mips_A2);  | 
1760  | 0  |       MCOperand_CreateReg0(Inst, Mips_A3);  | 
1761  | 0  |       break;  | 
1762  | 0  |     case 3:  | 
1763  | 0  |       MCOperand_CreateReg0(Inst, Mips_A0);  | 
1764  | 0  |       MCOperand_CreateReg0(Inst, Mips_S5);  | 
1765  | 0  |       break;  | 
1766  | 0  |     case 4:  | 
1767  | 0  |       MCOperand_CreateReg0(Inst, Mips_A0);  | 
1768  | 0  |       MCOperand_CreateReg0(Inst, Mips_S6);  | 
1769  | 0  |       break;  | 
1770  | 0  |     case 5:  | 
1771  | 0  |       MCOperand_CreateReg0(Inst, Mips_A0);  | 
1772  | 0  |       MCOperand_CreateReg0(Inst, Mips_A1);  | 
1773  | 0  |       break;  | 
1774  | 0  |     case 6:  | 
1775  | 0  |       MCOperand_CreateReg0(Inst, Mips_A0);  | 
1776  | 0  |       MCOperand_CreateReg0(Inst, Mips_A2);  | 
1777  | 0  |       break;  | 
1778  | 0  |     case 7:  | 
1779  | 0  |       MCOperand_CreateReg0(Inst, Mips_A0);  | 
1780  | 0  |       MCOperand_CreateReg0(Inst, Mips_A3);  | 
1781  | 0  |       break;  | 
1782  | 264  |   }  | 
1783  |  |  | 
1784  | 264  |   return MCDisassembler_Success;  | 
1785  | 264  | }  | 
1786  |  |  | 
1787  |  | static DecodeStatus DecodeSimm23Lsl2(MCInst *Inst, unsigned Insn,  | 
1788  |  |     uint64_t Address, MCRegisterInfo *Decoder)  | 
1789  | 381  | { | 
1790  | 381  |   MCOperand_CreateImm0(Inst, SignExtend32(Insn, 23) * 4);  | 
1791  | 381  |   return MCDisassembler_Success;  | 
1792  | 381  | }  | 
1793  |  |  | 
1794  |  | #endif  |