Coverage Report

Created: 2025-07-01 07:03

/src/capstonenext/arch/Mips/MipsDisassembler.c
Line
Count
Source (jump to first uncovered line)
1
/* Capstone Disassembly Engine, http://www.capstone-engine.org */
2
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2022, */
3
/*    Rot127 <unisono@quyllur.org> 2022-2023 */
4
/* Automatically translated source file from LLVM. */
5
6
/* LLVM-commit: <commit> */
7
/* LLVM-tag: <tag> */
8
9
/* Only small edits allowed. */
10
/* For multiple similar edits, please create a Patch for the translator. */
11
12
/* Capstone's C++ file translator: */
13
/* https://github.com/capstone-engine/capstone/tree/next/suite/auto-sync */
14
15
//===- MipsDisassembler.cpp - Disassembler for Mips -----------------------===//
16
//
17
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
18
// See https://llvm.org/LICENSE.txt for license information.
19
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
20
//
21
//===----------------------------------------------------------------------===//
22
//
23
// This file is part of the Mips Disassembler.
24
//
25
//===----------------------------------------------------------------------===//
26
27
#include <stdio.h>
28
#include <string.h>
29
#include <stdlib.h>
30
#include <capstone/platform.h>
31
32
#include "../../MCInst.h"
33
#include "../../MathExtras.h"
34
#include "../../MCInstPrinter.h"
35
#include "../../MCDisassembler.h"
36
#include "../../MCRegisterInfo.h"
37
#include "../../MCFixedLenDisassembler.h"
38
#include "../../cs_priv.h"
39
#include "../../utils.h"
40
#define GET_SUBTARGETINFO_ENUM
41
#include "MipsGenSubtargetInfo.inc"
42
43
#define GET_INSTRINFO_ENUM
44
#include "MipsGenInstrInfo.inc"
45
46
#define GET_REGINFO_ENUM
47
#include "MipsGenRegisterInfo.inc"
48
49
454
#define CONCAT(a, b) CONCAT_(a, b)
50
454
#define CONCAT_(a, b) a##_##b
51
52
#define DEBUG_TYPE "mips-disassembler"
53
54
bool Mips_getFeatureBits(unsigned int mode, unsigned int feature)
55
1.17M
{
56
1.17M
  switch(feature) {
57
80.3k
  case Mips_FeatureGP64Bit:
58
80.3k
    return mode & (CS_MODE_MIPS3 | CS_MODE_MIPS4 | 
59
80.3k
            CS_MODE_MIPS5 | CS_MODE_MIPS64 | 
60
80.3k
            CS_MODE_MIPS64R2 | CS_MODE_MIPS64R3 | 
61
80.3k
            CS_MODE_MIPS64R5 | CS_MODE_MIPS64R6 | 
62
80.3k
            CS_MODE_OCTEON | CS_MODE_OCTEONP);
63
84.7k
  case Mips_FeatureFP64Bit:
64
84.7k
    return mode & (CS_MODE_MIPS32R6 | CS_MODE_MIPS3 | 
65
84.7k
            CS_MODE_MIPS4 | CS_MODE_MIPS5 | 
66
84.7k
            CS_MODE_MIPS32R2 | CS_MODE_MIPS32R3 |
67
84.7k
            CS_MODE_MIPS32R5 | CS_MODE_MIPS64 |
68
84.7k
            CS_MODE_MIPS64R2 | CS_MODE_MIPS64R3 |
69
84.7k
            CS_MODE_MIPS64R5 | CS_MODE_MIPS64R6 |
70
84.7k
            CS_MODE_OCTEON | CS_MODE_OCTEONP);
71
0
  case Mips_FeatureNaN2008:
72
0
    return mode & (CS_MODE_MIPS32R6 | CS_MODE_MIPS64R6);
73
0
  case Mips_FeatureAbs2008:
74
0
    return mode & (CS_MODE_MIPS32R6 | CS_MODE_MIPS64R6);
75
0
  case Mips_FeatureMips1:
76
0
    return mode & (CS_MODE_MIPS1 | CS_MODE_MIPS2 | 
77
0
            CS_MODE_MIPS32 | CS_MODE_MIPS32R2 | 
78
0
            CS_MODE_MIPS32R3 | CS_MODE_MIPS32R5 | 
79
0
            CS_MODE_MIPS32R6 | CS_MODE_MIPS3 | 
80
0
            CS_MODE_MIPS4 | CS_MODE_MIPS5 | 
81
0
            CS_MODE_MIPS64 | CS_MODE_MIPS64R2 | 
82
0
            CS_MODE_MIPS64R3 | CS_MODE_MIPS64R5 | 
83
0
            CS_MODE_MIPS64R6 | CS_MODE_OCTEON | 
84
0
            CS_MODE_OCTEONP);
85
83.8k
  case Mips_FeatureMips2:
86
83.8k
    return mode & (CS_MODE_MIPS2 | CS_MODE_MIPS32 | 
87
83.8k
            CS_MODE_MIPS32R2 | CS_MODE_MIPS32R3 | 
88
83.8k
            CS_MODE_MIPS32R5 | CS_MODE_MIPS32R6 | 
89
83.8k
            CS_MODE_MIPS3 | CS_MODE_MIPS4 | 
90
83.8k
            CS_MODE_MIPS5 | CS_MODE_MIPS64 | 
91
83.8k
            CS_MODE_MIPS64R2 | CS_MODE_MIPS64R3 | 
92
83.8k
            CS_MODE_MIPS64R5 | CS_MODE_MIPS64R6 | 
93
83.8k
            CS_MODE_OCTEON | CS_MODE_OCTEONP);
94
400
  case Mips_FeatureMips3_32:
95
400
    return mode & (CS_MODE_MIPS32 | CS_MODE_MIPS32R2 | 
96
400
            CS_MODE_MIPS32R3 | CS_MODE_MIPS32R5 | 
97
400
            CS_MODE_MIPS32R6 | CS_MODE_MIPS3 | 
98
400
            CS_MODE_MIPS4 | CS_MODE_MIPS5 | 
99
400
            CS_MODE_MIPS64 | CS_MODE_MIPS64R2 | 
100
400
            CS_MODE_MIPS64R3 | CS_MODE_MIPS64R5 | 
101
400
            CS_MODE_MIPS64R6 | CS_MODE_OCTEON | 
102
400
            CS_MODE_OCTEONP);
103
49
  case Mips_FeatureMips3_32r2:
104
49
    return mode & (CS_MODE_MIPS32R2 | CS_MODE_MIPS32R3 | 
105
49
            CS_MODE_MIPS32R5 | CS_MODE_MIPS32R6 | 
106
49
            CS_MODE_MIPS3 | CS_MODE_MIPS4 | 
107
49
            CS_MODE_MIPS5 | CS_MODE_MIPS64 | 
108
49
            CS_MODE_MIPS64R2 | CS_MODE_MIPS64R3 | 
109
49
            CS_MODE_MIPS64R5 | CS_MODE_MIPS64R6 | 
110
49
            CS_MODE_OCTEON | CS_MODE_OCTEONP);
111
4.79k
  case Mips_FeatureMips3:
112
4.79k
    return mode & (CS_MODE_MIPS3 | CS_MODE_MIPS4 | 
113
4.79k
            CS_MODE_MIPS5 | CS_MODE_MIPS64 | 
114
4.79k
            CS_MODE_MIPS64R2 | CS_MODE_MIPS64R3 | 
115
4.79k
            CS_MODE_MIPS64R5 | CS_MODE_MIPS64R6 | 
116
4.79k
            CS_MODE_OCTEON | CS_MODE_OCTEONP);
117
403
  case Mips_FeatureMips4_32:
118
403
    return mode & (CS_MODE_MIPS32 | CS_MODE_MIPS32R2 | 
119
403
            CS_MODE_MIPS32R3 | CS_MODE_MIPS32R5 | 
120
403
            CS_MODE_MIPS32R6 | CS_MODE_MIPS4 | 
121
403
            CS_MODE_MIPS5 | CS_MODE_MIPS64 | 
122
403
            CS_MODE_MIPS64R2 | CS_MODE_MIPS64R3 | 
123
403
            CS_MODE_MIPS64R5 | CS_MODE_MIPS64R6 | 
124
403
            CS_MODE_OCTEON | CS_MODE_OCTEONP);
125
450
  case Mips_FeatureMips4_32r2:
126
450
    return mode & (CS_MODE_MIPS32R2 | CS_MODE_MIPS32R3 | 
127
450
            CS_MODE_MIPS32R5 | CS_MODE_MIPS32R6 | 
128
450
            CS_MODE_MIPS4 | CS_MODE_MIPS5 | 
129
450
            CS_MODE_MIPS64 | CS_MODE_MIPS64R2 | 
130
450
            CS_MODE_MIPS64R3 | CS_MODE_MIPS64R5 | 
131
450
            CS_MODE_MIPS64R6 | CS_MODE_OCTEON | 
132
450
            CS_MODE_OCTEONP);
133
0
  case Mips_FeatureMips4:
134
0
    return mode & (CS_MODE_MIPS4 | CS_MODE_MIPS5 | 
135
0
            CS_MODE_MIPS64 | CS_MODE_MIPS64R2 | 
136
0
            CS_MODE_MIPS64R3 | CS_MODE_MIPS64R5 | 
137
0
            CS_MODE_MIPS64R6 | CS_MODE_OCTEON | 
138
0
            CS_MODE_OCTEONP);
139
67
  case Mips_FeatureMips5_32r2:
140
67
    return mode & (CS_MODE_MIPS32R2 | CS_MODE_MIPS32R3 | 
141
67
            CS_MODE_MIPS32R5 | CS_MODE_MIPS32R6 | 
142
67
            CS_MODE_MIPS5 | CS_MODE_MIPS64 | 
143
67
            CS_MODE_MIPS64R2 | CS_MODE_MIPS64R3 | 
144
67
            CS_MODE_MIPS64R5 | CS_MODE_MIPS64R6 | 
145
67
            CS_MODE_OCTEON | CS_MODE_OCTEONP);
146
0
  case Mips_FeatureMips5:
147
0
    return mode & (CS_MODE_MIPS5 | CS_MODE_MIPS64 | 
148
0
            CS_MODE_MIPS64R2 | CS_MODE_MIPS64R3 | 
149
0
            CS_MODE_MIPS64R5 | CS_MODE_MIPS64R6 | 
150
0
            CS_MODE_OCTEON | CS_MODE_OCTEONP);
151
80.0k
  case Mips_FeatureMips32:
152
80.0k
    return mode & (CS_MODE_MIPS32 | CS_MODE_MIPS32R2 | 
153
80.0k
            CS_MODE_MIPS32R3 | CS_MODE_MIPS32R5 | 
154
80.0k
            CS_MODE_MIPS32R6 | CS_MODE_MIPS64 | 
155
80.0k
            CS_MODE_MIPS64R2 | CS_MODE_MIPS64R3 | 
156
80.0k
            CS_MODE_MIPS64R5 | CS_MODE_MIPS64R6 | 
157
80.0k
            CS_MODE_OCTEON | CS_MODE_OCTEONP);
158
692
  case Mips_FeatureMips32r2:
159
692
    return mode & (CS_MODE_MIPS32R2 | CS_MODE_MIPS32R3 | 
160
692
            CS_MODE_MIPS32R5 | CS_MODE_MIPS32R6 | 
161
692
            CS_MODE_MIPS64R2 | CS_MODE_MIPS64R3 | 
162
692
            CS_MODE_MIPS64R5 | CS_MODE_MIPS64R6 | 
163
692
            CS_MODE_OCTEON | CS_MODE_OCTEONP);
164
0
  case Mips_FeatureMips32r3:
165
0
    return mode & (CS_MODE_MIPS32R3 | CS_MODE_MIPS32R5 | 
166
0
            CS_MODE_MIPS32R6 | CS_MODE_MIPS64R3 | 
167
0
            CS_MODE_MIPS64R5 | CS_MODE_MIPS64R6);
168
341
  case Mips_FeatureMips32r5:
169
341
    return mode & (CS_MODE_MIPS32R5 | CS_MODE_MIPS32R6 | 
170
341
            CS_MODE_MIPS64R5 | CS_MODE_MIPS64R6);
171
129k
  case Mips_FeatureMips32r6:
172
129k
    return mode & (CS_MODE_MIPS32R6 | CS_MODE_MIPS64R6);
173
190
  case Mips_FeatureMips64:
174
190
    return mode & (CS_MODE_MIPS64 | CS_MODE_MIPS64R2 | 
175
190
            CS_MODE_MIPS64R3 | CS_MODE_MIPS64R5 | 
176
190
            CS_MODE_MIPS64R6 | CS_MODE_OCTEON | 
177
190
            CS_MODE_OCTEONP);
178
197
  case Mips_FeatureMips64r2:
179
197
    return mode & (CS_MODE_MIPS64R2 | CS_MODE_MIPS64R3 | 
180
197
            CS_MODE_MIPS64R5 | CS_MODE_MIPS64R6 | 
181
197
            CS_MODE_OCTEON | CS_MODE_OCTEONP);
182
0
  case Mips_FeatureMips64r3:
183
0
    return mode & (CS_MODE_MIPS64R3 | CS_MODE_MIPS64R5 | 
184
0
            CS_MODE_MIPS64R6);
185
1
  case Mips_FeatureMips64r5:
186
1
    return mode & (CS_MODE_MIPS64R5 | CS_MODE_MIPS64R6);
187
89.6k
  case Mips_FeatureMips64r6:
188
89.6k
    return mode & CS_MODE_MIPS64R6;
189
113k
  case Mips_FeatureMips16:
190
113k
    return mode & CS_MODE_MIPS16;
191
156k
  case Mips_FeatureMicroMips:
192
156k
    return mode & CS_MODE_MICRO;
193
94.0k
  case Mips_FeatureNanoMips:
194
94.0k
    return mode & (CS_MODE_NANOMIPS | CS_MODE_NMS1 | 
195
94.0k
            CS_MODE_I7200);
196
0
  case Mips_FeatureNMS1:
197
0
    return mode & CS_MODE_NMS1;
198
0
  case Mips_FeatureTLB:
199
0
    return mode & CS_MODE_I7200;
200
79.2k
  case Mips_FeatureCnMips:
201
79.2k
    return mode & (CS_MODE_OCTEON | CS_MODE_OCTEONP);
202
79.2k
  case Mips_FeatureCnMipsP:
203
79.2k
    return mode & CS_MODE_OCTEONP;
204
81.3k
  case Mips_FeaturePTR64Bit:
205
81.3k
    return mode & CS_MODE_MIPS_PTR64;
206
7.53k
  case Mips_FeatureSoftFloat:
207
7.53k
    return mode & CS_MODE_MIPS_NOFLOAT;
208
0
  case Mips_FeatureI7200:
209
0
    return mode & CS_MODE_I7200;
210
  // optional features always enabled
211
2.52k
  case Mips_FeatureDSP: // Mips DSP ASE
212
2.52k
    return true;
213
490
  case Mips_FeatureDSPR2: // Mips DSP-R2 ASE
214
490
    return true;
215
17
  case Mips_FeatureDSPR3: // Mips DSP-R3 ASE
216
17
    return true;
217
0
  case Mips_FeatureMips3D: // Mips 3D ASE
218
0
    return true;
219
4.18k
  case Mips_FeatureMSA: // Mips MSA ASE
220
4.18k
    return true;
221
520
  case Mips_FeatureEVA: { // Mips EVA ASE
222
520
    if (mode & CS_MODE_NANOMIPS) {
223
0
      return mode & CS_MODE_I7200;
224
0
    }
225
520
    return true;
226
520
  }
227
8
  case Mips_FeatureCRC: // Mips R6 CRC ASE
228
8
    return true;
229
171
  case Mips_FeatureVirt: // Mips Virtualization ASE
230
171
    return true;
231
181
  case Mips_FeatureGINV: // Mips Global Invalidate ASE
232
181
    return true;
233
158
  case Mips_FeatureMT: { // Mips MT ASE
234
158
    if (mode & CS_MODE_NANOMIPS) {
235
0
      return mode & CS_MODE_I7200;
236
0
    }
237
158
    return true;
238
158
  }
239
473
  default:
240
473
    return false;
241
1.17M
  }
242
1.17M
}
243
244
static DecodeStatus getInstruction(MCInst *Instr, uint64_t *Size, const uint8_t *Bytes,
245
          size_t BytesLen, uint64_t Address, SStream *CStream);
246
247
// end anonymous namespace
248
249
// Forward declare these because the autogenerated code will reference them.
250
// Definitions are further down.
251
static DecodeStatus DecodeGPR64RegisterClass(MCInst *Inst, unsigned RegNo,
252
               uint64_t Address,
253
               const void *Decoder);
254
255
static DecodeStatus DecodeCPU16RegsRegisterClass(MCInst *Inst, unsigned RegNo,
256
             uint64_t Address,
257
             const void *Decoder);
258
259
static DecodeStatus DecodeGPRMM16RegisterClass(MCInst *Inst, unsigned RegNo,
260
                 uint64_t Address,
261
                 const void *Decoder);
262
263
static DecodeStatus DecodeGPRMM16ZeroRegisterClass(MCInst *Inst, unsigned RegNo,
264
               uint64_t Address,
265
               const void *Decoder);
266
267
static DecodeStatus DecodeGPRMM16MovePRegisterClass(MCInst *Inst,
268
                unsigned RegNo,
269
                uint64_t Address,
270
                const void *Decoder);
271
272
static DecodeStatus DecodeGPR32RegisterClass(MCInst *Inst, unsigned RegNo,
273
               uint64_t Address,
274
               const void *Decoder);
275
276
static DecodeStatus DecodeGPRNM3RegisterClass(MCInst *Inst, unsigned RegNo,
277
                uint64_t Address,
278
                const void *Decoder);
279
280
static DecodeStatus DecodeGPRNM4RegisterClass(MCInst *Inst, unsigned RegNo,
281
                uint64_t Address,
282
                const void *Decoder);
283
284
static DecodeStatus DecodeGPRNMRARegisterClass(MCInst *Inst, unsigned RegNo,
285
                 uint64_t Address,
286
                 const void *Decoder);
287
288
static DecodeStatus DecodeGPRNM3ZRegisterClass(MCInst *Inst, unsigned RegNo,
289
                 uint64_t Address,
290
                 const void *Decoder);
291
292
static DecodeStatus DecodeGPRNM4ZRegisterClass(MCInst *Inst, unsigned RegNo,
293
                 uint64_t Address,
294
                 const void *Decoder);
295
296
static DecodeStatus DecodeGPRNM32NZRegisterClass(MCInst *Inst, unsigned RegNo,
297
             uint64_t Address,
298
             const void *Decoder);
299
300
static DecodeStatus DecodeGPRNM32RegisterClass(MCInst *Inst, unsigned RegNo,
301
                 uint64_t Address,
302
                 const void *Decoder);
303
304
static DecodeStatus DecodeGPRNM2R1RegisterClass(MCInst *Inst, unsigned RegNo,
305
            uint64_t Address,
306
            const void *Decoder);
307
308
static DecodeStatus DecodeGPRNM1R1RegisterClass(MCInst *Inst, unsigned RegNo,
309
            uint64_t Address,
310
            const void *Decoder);
311
312
static DecodeStatus DecodePtrRegisterClass(MCInst *Inst, uint32_t Insn,
313
             uint64_t Address,
314
             const void *Decoder);
315
316
static DecodeStatus DecodeDSPRRegisterClass(MCInst *Inst, unsigned RegNo,
317
              uint64_t Address,
318
              const void *Decoder);
319
320
static DecodeStatus DecodeFGR64RegisterClass(MCInst *Inst, unsigned RegNo,
321
               uint64_t Address,
322
               const void *Decoder);
323
324
static DecodeStatus DecodeFGR32RegisterClass(MCInst *Inst, unsigned RegNo,
325
               uint64_t Address,
326
               const void *Decoder);
327
328
static DecodeStatus DecodeCCRRegisterClass(MCInst *Inst, unsigned RegNo,
329
             uint64_t Address,
330
             const void *Decoder);
331
332
static DecodeStatus DecodeFCCRegisterClass(MCInst *Inst, unsigned RegNo,
333
             uint64_t Address,
334
             const void *Decoder);
335
336
static DecodeStatus DecodeFGRCCRegisterClass(MCInst *Inst, unsigned RegNo,
337
               uint64_t Address,
338
               const void *Decoder);
339
340
static DecodeStatus DecodeHWRegsRegisterClass(MCInst *Inst, uint32_t Insn,
341
                uint64_t Address,
342
                const void *Decoder);
343
344
static DecodeStatus DecodeAFGR64RegisterClass(MCInst *Inst, unsigned RegNo,
345
                uint64_t Address,
346
                const void *Decoder);
347
348
static DecodeStatus DecodeACC64DSPRegisterClass(MCInst *Inst, unsigned RegNo,
349
            uint64_t Address,
350
            const void *Decoder);
351
352
static DecodeStatus DecodeHI32DSPRegisterClass(MCInst *Inst, unsigned RegNo,
353
                 uint64_t Address,
354
                 const void *Decoder);
355
356
static DecodeStatus DecodeLO32DSPRegisterClass(MCInst *Inst, unsigned RegNo,
357
                 uint64_t Address,
358
                 const void *Decoder);
359
360
static DecodeStatus DecodeMSA128BRegisterClass(MCInst *Inst, unsigned RegNo,
361
                 uint64_t Address,
362
                 const void *Decoder);
363
364
static DecodeStatus DecodeMSA128HRegisterClass(MCInst *Inst, unsigned RegNo,
365
                 uint64_t Address,
366
                 const void *Decoder);
367
368
static DecodeStatus DecodeMSA128WRegisterClass(MCInst *Inst, unsigned RegNo,
369
                 uint64_t Address,
370
                 const void *Decoder);
371
372
static DecodeStatus DecodeMSA128DRegisterClass(MCInst *Inst, unsigned RegNo,
373
                 uint64_t Address,
374
                 const void *Decoder);
375
376
static DecodeStatus DecodeMSACtrlRegisterClass(MCInst *Inst, unsigned RegNo,
377
                 uint64_t Address,
378
                 const void *Decoder);
379
380
static DecodeStatus DecodeCOP0RegisterClass(MCInst *Inst, unsigned RegNo,
381
              uint64_t Address,
382
              const void *Decoder);
383
384
static DecodeStatus DecodeCOP0SelRegisterClass(MCInst *Inst, unsigned RegNo,
385
                 uint64_t Address,
386
                 const void *Decoder);
387
388
static DecodeStatus DecodeCOP2RegisterClass(MCInst *Inst, unsigned RegNo,
389
              uint64_t Address,
390
              const void *Decoder);
391
392
static DecodeStatus DecodeBranchTarget(MCInst *Inst, unsigned Offset,
393
               uint64_t Address, const void *Decoder);
394
395
static DecodeStatus DecodeBranchTarget1SImm16(MCInst *Inst, unsigned Offset,
396
                uint64_t Address,
397
                const void *Decoder);
398
399
static DecodeStatus DecodeJumpTarget(MCInst *Inst, uint32_t Insn,
400
             uint64_t Address, const void *Decoder);
401
402
static DecodeStatus DecodeBranchTarget21(MCInst *Inst, unsigned Offset,
403
           uint64_t Address, const void *Decoder);
404
405
static DecodeStatus DecodeBranchTarget21MM(MCInst *Inst, unsigned Offset,
406
             uint64_t Address,
407
             const void *Decoder);
408
409
static DecodeStatus DecodeBranchTarget26(MCInst *Inst, unsigned Offset,
410
           uint64_t Address, const void *Decoder);
411
412
// DecodeBranchTarget7MM - Decode microMIPS branch offset, which is
413
// shifted left by 1 bit.
414
static DecodeStatus DecodeBranchTarget7MM(MCInst *Inst, unsigned Offset,
415
            uint64_t Address,
416
            const void *Decoder);
417
418
// DecodeBranchTarget10MM - Decode microMIPS branch offset, which is
419
// shifted left by 1 bit.
420
static DecodeStatus DecodeBranchTarget10MM(MCInst *Inst, unsigned Offset,
421
             uint64_t Address,
422
             const void *Decoder);
423
424
// DecodeBranchTargetMM - Decode microMIPS branch offset, which is
425
// shifted left by 1 bit.
426
static DecodeStatus DecodeBranchTargetMM(MCInst *Inst, unsigned Offset,
427
           uint64_t Address, const void *Decoder);
428
429
// DecodeBranchTarget26MM - Decode microMIPS branch offset, which is
430
// shifted left by 1 bit.
431
static DecodeStatus DecodeBranchTarget26MM(MCInst *Inst, unsigned Offset,
432
             uint64_t Address,
433
             const void *Decoder);
434
435
// DecodeBranchTargetMM - Decode nanoMIPS branch offset, which is
436
// shifted left by 1 bit.
437
#define DECLARE_DecodeBranchTargetNM(bits) \
438
  static DecodeStatus CONCAT(DecodeBranchTargetNM, bits)( \
439
    MCInst * Inst, unsigned Offset, uint64_t Address, \
440
    const void *Decoder);
441
DECLARE_DecodeBranchTargetNM(10);
442
DECLARE_DecodeBranchTargetNM(7);
443
DECLARE_DecodeBranchTargetNM(21);
444
DECLARE_DecodeBranchTargetNM(25);
445
DECLARE_DecodeBranchTargetNM(14);
446
DECLARE_DecodeBranchTargetNM(11);
447
DECLARE_DecodeBranchTargetNM(5);
448
449
// DecodeJumpTargetMM - Decode microMIPS jump target, which is
450
// shifted left by 1 bit.
451
static DecodeStatus DecodeJumpTargetMM(MCInst *Inst, uint32_t Insn,
452
               uint64_t Address, const void *Decoder);
453
454
// DecodeJumpTargetXMM - Decode microMIPS jump and link exchange target,
455
// which is shifted left by 2 bit.
456
static DecodeStatus DecodeJumpTargetXMM(MCInst *Inst, uint32_t Insn,
457
          uint64_t Address, const void *Decoder);
458
459
static DecodeStatus DecodeMem(MCInst *Inst, uint32_t Insn, uint64_t Address,
460
            const void *Decoder);
461
462
#define DECLARE_DecodeMemNM(Offbits, isSigned, rt) \
463
  static DecodeStatus CONCAT(DecodeMemNM, \
464
           CONCAT(Offbits, CONCAT(isSigned, rt)))( \
465
    MCInst * Inst, uint32_t Insn, uint64_t Address, \
466
    const void *Decoder);
467
DECLARE_DecodeMemNM(6, 0, Mips_GPRNM3RegClassID);
468
DECLARE_DecodeMemNM(7, 0, Mips_GPRNMSPRegClassID);
469
DECLARE_DecodeMemNM(9, 0, Mips_GPRNMGPRegClassID);
470
DECLARE_DecodeMemNM(2, 0, Mips_GPRNM3RegClassID);
471
DECLARE_DecodeMemNM(3, 0, Mips_GPRNM3RegClassID);
472
DECLARE_DecodeMemNM(21, 0, Mips_GPRNMGPRegClassID);
473
DECLARE_DecodeMemNM(18, 0, Mips_GPRNMGPRegClassID);
474
DECLARE_DecodeMemNM(12, 0, Mips_GPRNM32RegClassID);
475
DECLARE_DecodeMemNM(9, 1, Mips_GPRNM32RegClassID);
476
477
static DecodeStatus DecodeMemZeroNM(MCInst *Inst, uint32_t Insn,
478
            uint64_t Address, const void *Decoder);
479
480
#define DECLARE_DecodeMemNMRX(rt) \
481
  static DecodeStatus CONCAT(DecodeMemNMRX, \
482
           rt)(MCInst * Inst, uint32_t Insn, \
483
               uint64_t Address, const void *Decoder);
484
DECLARE_DecodeMemNMRX(Mips_GPRNM3RegClassID);
485
DECLARE_DecodeMemNMRX(Mips_GPRNM32RegClassID);
486
487
static DecodeStatus DecodeMemNM4x4(MCInst *Inst, uint32_t Insn,
488
           uint64_t Address, const void *Decoder);
489
490
static DecodeStatus DecodeMemEVA(MCInst *Inst, uint32_t Insn, uint64_t Address,
491
         const void *Decoder);
492
493
static DecodeStatus DecodeLoadByte15(MCInst *Inst, uint32_t Insn,
494
             uint64_t Address, const void *Decoder);
495
496
static DecodeStatus DecodeCacheOp(MCInst *Inst, uint32_t Insn, uint64_t Address,
497
          const void *Decoder);
498
499
static DecodeStatus DecodeCacheeOp_CacheOpR6(MCInst *Inst, uint32_t Insn,
500
               uint64_t Address,
501
               const void *Decoder);
502
503
static DecodeStatus DecodeCacheOpMM(MCInst *Inst, uint32_t Insn,
504
            uint64_t Address, const void *Decoder);
505
506
static DecodeStatus DecodePrefeOpMM(MCInst *Inst, uint32_t Insn,
507
            uint64_t Address, const void *Decoder);
508
509
static DecodeStatus DecodeSyncI(MCInst *Inst, uint32_t Insn, uint64_t Address,
510
        const void *Decoder);
511
512
static DecodeStatus DecodeSyncI_MM(MCInst *Inst, uint32_t Insn,
513
           uint64_t Address, const void *Decoder);
514
515
static DecodeStatus DecodeSynciR6(MCInst *Inst, uint32_t Insn, uint64_t Address,
516
          const void *Decoder);
517
518
static DecodeStatus DecodeMSA128Mem(MCInst *Inst, uint32_t Insn,
519
            uint64_t Address, const void *Decoder);
520
521
static DecodeStatus DecodeMemMMImm4(MCInst *Inst, uint32_t Insn,
522
            uint64_t Address, const void *Decoder);
523
524
static DecodeStatus DecodeMemMMSPImm5Lsl2(MCInst *Inst, uint32_t Insn,
525
            uint64_t Address,
526
            const void *Decoder);
527
528
static DecodeStatus DecodeMemMMGPImm7Lsl2(MCInst *Inst, uint32_t Insn,
529
            uint64_t Address,
530
            const void *Decoder);
531
532
static DecodeStatus DecodeMemMMReglistImm4Lsl2(MCInst *Inst, uint32_t Insn,
533
                 uint64_t Address,
534
                 const void *Decoder);
535
536
static DecodeStatus DecodeMemMMImm9(MCInst *Inst, uint32_t Insn,
537
            uint64_t Address, const void *Decoder);
538
539
static DecodeStatus DecodeMemMMImm12(MCInst *Inst, uint32_t Insn,
540
             uint64_t Address, const void *Decoder);
541
542
static DecodeStatus DecodeMemMMImm16(MCInst *Inst, uint32_t Insn,
543
             uint64_t Address, const void *Decoder);
544
545
static DecodeStatus DecodeFMem(MCInst *Inst, uint32_t Insn, uint64_t Address,
546
             const void *Decoder);
547
548
static DecodeStatus DecodeFMemMMR2(MCInst *Inst, uint32_t Insn,
549
           uint64_t Address, const void *Decoder);
550
551
static DecodeStatus DecodeFMem2(MCInst *Inst, uint32_t Insn, uint64_t Address,
552
        const void *Decoder);
553
554
static DecodeStatus DecodeFMem3(MCInst *Inst, uint32_t Insn, uint64_t Address,
555
        const void *Decoder);
556
557
static DecodeStatus DecodeFMemCop2R6(MCInst *Inst, uint32_t Insn,
558
             uint64_t Address, const void *Decoder);
559
560
static DecodeStatus DecodeFMemCop2MMR6(MCInst *Inst, uint32_t Insn,
561
               uint64_t Address, const void *Decoder);
562
563
static DecodeStatus DecodeSpecial3LlSc(MCInst *Inst, uint32_t Insn,
564
               uint64_t Address, const void *Decoder);
565
566
static DecodeStatus DecodeAddiur2Simm7(MCInst *Inst, unsigned Value,
567
               uint64_t Address, const void *Decoder);
568
569
static DecodeStatus DecodeLi16Imm(MCInst *Inst, unsigned Value,
570
          uint64_t Address, const void *Decoder);
571
572
static DecodeStatus DecodePOOL16BEncodedField(MCInst *Inst, unsigned Value,
573
                uint64_t Address,
574
                const void *Decoder);
575
576
#define DECLARE_DecodeUImmWithOffsetAndScale(Bits, Offset, Scale) \
577
  static DecodeStatus CONCAT(DecodeUImmWithOffsetAndScale, \
578
           CONCAT(Bits, CONCAT(Offset, Scale)))( \
579
    MCInst * Inst, unsigned Value, uint64_t Address, \
580
    const void *Decoder);
581
DECLARE_DecodeUImmWithOffsetAndScale(5, 0, 4);
582
DECLARE_DecodeUImmWithOffsetAndScale(6, 0, 4);
583
DECLARE_DecodeUImmWithOffsetAndScale(2, 1, 1);
584
DECLARE_DecodeUImmWithOffsetAndScale(5, 1, 1);
585
DECLARE_DecodeUImmWithOffsetAndScale(8, 0, 1);
586
DECLARE_DecodeUImmWithOffsetAndScale(18, 0, 1);
587
DECLARE_DecodeUImmWithOffsetAndScale(21, 0, 1);
588
589
#define DEFINE_DecodeUImmWithOffset(Bits, Offset) \
590
  static DecodeStatus CONCAT(DecodeUImmWithOffset, \
591
           CONCAT(Bits, Offset))(MCInst * Inst, \
592
               unsigned Value, \
593
               uint64_t Address, \
594
               const void *Decoder) \
595
454
  { \
596
454
    return CONCAT(DecodeUImmWithOffsetAndScale, \
597
454
            CONCAT(Bits, CONCAT(Offset, 1)))( \
598
454
      Inst, Value, Address, Decoder); \
599
454
  }
MipsDisassembler.c:DecodeUImmWithOffset_5_1
Line
Count
Source
595
321
  { \
596
321
    return CONCAT(DecodeUImmWithOffsetAndScale, \
597
321
            CONCAT(Bits, CONCAT(Offset, 1)))( \
598
321
      Inst, Value, Address, Decoder); \
599
321
  }
MipsDisassembler.c:DecodeUImmWithOffset_2_1
Line
Count
Source
595
133
  { \
596
133
    return CONCAT(DecodeUImmWithOffsetAndScale, \
597
133
            CONCAT(Bits, CONCAT(Offset, 1)))( \
598
133
      Inst, Value, Address, Decoder); \
599
133
  }
600
DEFINE_DecodeUImmWithOffset(5, 1);
601
DEFINE_DecodeUImmWithOffset(2, 1);
602
603
#define DECLARE_DecodeSImmWithOffsetAndScale(Bits, Offset, ScaleBy) \
604
  static DecodeStatus CONCAT( \
605
    DecodeSImmWithOffsetAndScale, \
606
    CONCAT(Bits, CONCAT(Offset, ScaleBy)))( \
607
    MCInst * Inst, unsigned Value, uint64_t Address, \
608
    const void *Decoder);
609
610
#define DECLARE_DecodeSImmWithOffsetAndScale_2(Bits, Offset) DECLARE_DecodeSImmWithOffsetAndScale(Bits, Offset, 1)
611
#define DECLARE_DecodeSImmWithOffsetAndScale_3(Bits) DECLARE_DecodeSImmWithOffsetAndScale(Bits, 0, 1)
612
613
DECLARE_DecodeSImmWithOffsetAndScale_3(16);
614
DECLARE_DecodeSImmWithOffsetAndScale_3(10);
615
DECLARE_DecodeSImmWithOffsetAndScale_3(4);
616
DECLARE_DecodeSImmWithOffsetAndScale_3(6);
617
DECLARE_DecodeSImmWithOffsetAndScale_3(32);
618
619
static DecodeStatus DecodeInsSize(MCInst *Inst, uint32_t Insn, uint64_t Address,
620
          const void *Decoder);
621
622
static DecodeStatus DecodeImmM1To126(MCInst *Inst, unsigned Value,
623
             uint64_t Address, const void *Decoder);
624
625
static DecodeStatus DecodeUImm4Mask(MCInst *Inst, unsigned Value,
626
            uint64_t Address, const void *Decoder);
627
628
static DecodeStatus DecodeUImm3Shift(MCInst *Inst, unsigned Value,
629
             uint64_t Address, const void *Decoder);
630
631
static DecodeStatus DecodeNMRegListOperand(MCInst *Inst, uint32_t Insn,
632
             uint64_t Address,
633
             const void *Decoder);
634
635
static DecodeStatus DecodeNMRegList16Operand(MCInst *Inst, uint32_t Insn,
636
               uint64_t Address,
637
               const void *Decoder);
638
639
static DecodeStatus DecodeNegImm12(MCInst *Inst, uint32_t Insn,
640
           uint64_t Address, const void *Decoder);
641
642
#define DECLARE_DecodeSImmWithReg(Bits, Offset, Scale, RegNum) \
643
  static DecodeStatus CONCAT( \
644
    DecodeSImmWithReg, \
645
    CONCAT(Bits, CONCAT(Offset, CONCAT(Scale, RegNum))))( \
646
    MCInst * Inst, unsigned Value, uint64_t Address, \
647
    const void *Decoder);
648
DECLARE_DecodeSImmWithReg(32, 0, 1, Mips_GP_NM);
649
650
#define DECLARE_DecodeUImmWithReg(Bits, Offset, Scale, RegNum) \
651
  static DecodeStatus CONCAT( \
652
    DecodeUImmWithReg, \
653
    CONCAT(Bits, CONCAT(Offset, CONCAT(Scale, RegNum))))( \
654
    MCInst * Inst, unsigned Value, uint64_t Address, \
655
    const void *Decoder);
656
DECLARE_DecodeUImmWithReg(8, 0, 1, Mips_SP_NM);
657
DECLARE_DecodeUImmWithReg(21, 0, 1, Mips_GP_NM);
658
DECLARE_DecodeUImmWithReg(18, 0, 1, Mips_GP_NM);
659
660
static DecodeStatus DecodeSImm32s12(MCInst *Inst, uint32_t Insn,
661
            uint64_t Address, const void *Decoder);
662
663
#define DECLARE_DecodeAddressPCRelNM(Bits) \
664
  static DecodeStatus CONCAT(DecodeAddressPCRelNM, Bits)( \
665
    MCInst * Inst, uint32_t Insn, uint64_t Address, \
666
    const void *Decoder);
667
DECLARE_DecodeAddressPCRelNM(22);
668
DECLARE_DecodeAddressPCRelNM(32);
669
670
static DecodeStatus DecodeBranchConflictNM(MCInst *Inst, uint32_t Insn,
671
             uint64_t Address,
672
             const void *Decoder);
673
674
static DecodeStatus DecodeSimm19Lsl2(MCInst *Inst, uint32_t Insn,
675
             uint64_t Address, const void *Decoder);
676
677
static DecodeStatus DecodeSimm18Lsl3(MCInst *Inst, uint32_t Insn,
678
             uint64_t Address, const void *Decoder);
679
680
static DecodeStatus DecodeSimm9SP(MCInst *Inst, uint32_t Insn, uint64_t Address,
681
          const void *Decoder);
682
683
static DecodeStatus DecodeANDI16Imm(MCInst *Inst, uint32_t Insn,
684
            uint64_t Address, const void *Decoder);
685
686
static DecodeStatus DecodeSimm23Lsl2(MCInst *Inst, uint32_t Insn,
687
             uint64_t Address, const void *Decoder);
688
689
/// INSVE_[BHWD] have an implicit operand that the generated decoder doesn't
690
/// handle.
691
static DecodeStatus DecodeINSVE_DF(MCInst *MI, uint32_t insn, uint64_t Address,
692
           const void *Decoder);
693
694
/*
695
static DecodeStatus DecodeDAHIDATIMMR6(MCInst *MI, uint32_t insn,
696
            uint64_t Address, const void *Decoder);
697
*/
698
699
static DecodeStatus DecodeDAHIDATI(MCInst *MI, uint32_t insn, uint64_t Address,
700
                                  const void *Decoder);
701
702
static DecodeStatus DecodeAddiGroupBranch(MCInst *MI, uint32_t insn,
703
            uint64_t Address,
704
            const void *Decoder);
705
706
static DecodeStatus DecodePOP35GroupBranchMMR6(MCInst *MI, uint32_t insn,
707
                 uint64_t Address,
708
                 const void *Decoder);
709
710
static DecodeStatus DecodeDaddiGroupBranch(MCInst *MI, uint32_t insn,
711
             uint64_t Address,
712
             const void *Decoder);
713
714
static DecodeStatus DecodePOP37GroupBranchMMR6(MCInst *MI, uint32_t insn,
715
                 uint64_t Address,
716
                 const void *Decoder);
717
718
static DecodeStatus DecodePOP65GroupBranchMMR6(MCInst *MI, uint32_t insn,
719
                 uint64_t Address,
720
                 const void *Decoder);
721
722
static DecodeStatus DecodePOP75GroupBranchMMR6(MCInst *MI, uint32_t insn,
723
                 uint64_t Address,
724
                 const void *Decoder);
725
726
static DecodeStatus DecodeBlezlGroupBranch(MCInst *MI, uint32_t insn,
727
             uint64_t Address,
728
             const void *Decoder);
729
730
static DecodeStatus DecodeBgtzlGroupBranch(MCInst *MI, uint32_t insn,
731
             uint64_t Address,
732
             const void *Decoder);
733
734
static DecodeStatus DecodeBgtzGroupBranch(MCInst *MI, uint32_t insn,
735
            uint64_t Address,
736
            const void *Decoder);
737
738
static DecodeStatus DecodeBlezGroupBranch(MCInst *MI, uint32_t insn,
739
            uint64_t Address,
740
            const void *Decoder);
741
742
static DecodeStatus DecodeBgtzGroupBranchMMR6(MCInst *MI, uint32_t insn,
743
                uint64_t Address,
744
                const void *Decoder);
745
746
static DecodeStatus DecodeBlezGroupBranchMMR6(MCInst *MI, uint32_t insn,
747
                uint64_t Address,
748
                const void *Decoder);
749
750
static DecodeStatus DecodeDINS(MCInst *MI, uint32_t Insn, uint64_t Address,
751
             const void *Decoder);
752
753
static DecodeStatus DecodeDEXT(MCInst *MI, uint32_t Insn, uint64_t Address,
754
             const void *Decoder);
755
756
static DecodeStatus DecodeCRC(MCInst *MI, uint32_t Insn, uint64_t Address,
757
            const void *Decoder);
758
759
static DecodeStatus DecodeRegListOperand(MCInst *Inst, uint32_t Insn,
760
           uint64_t Address, const void *Decoder);
761
762
static DecodeStatus DecodeRegListOperand16(MCInst *Inst, uint32_t Insn,
763
             uint64_t Address,
764
             const void *Decoder);
765
766
static DecodeStatus DecodeMovePRegPair(MCInst *Inst, unsigned RegPair,
767
               uint64_t Address, const void *Decoder);
768
769
static DecodeStatus DecodeMovePOperands(MCInst *Inst, uint32_t Insn,
770
          uint64_t Address, const void *Decoder);
771
772
static DecodeStatus DecodeFIXMEInstruction(MCInst *Inst, uint32_t Insn,
773
             uint64_t Address,
774
             const void *Decoder);
775
776
#include "MipsGenDisassemblerTables.inc"
777
778
static unsigned getReg(const MCInst *Inst, unsigned RC, unsigned RegNo)
779
252k
{
780
252k
  const MCRegisterClass* c = MCRegisterInfo_getRegClass(Inst->MRI, RC);
781
252k
  return MCRegisterClass_getRegister(c, RegNo);
782
252k
}
783
784
typedef DecodeStatus (*DecodeFN)(MCInst *Inst, uint32_t Insn,
785
             uint64_t Address,
786
             const void *Decoder);
787
788
static DecodeStatus DecodeINSVE_DF(MCInst *MI, uint32_t insn, uint64_t Address,
789
           const void *Decoder)
790
120
{
791
  // The size of the n field depends on the element size
792
  // The register class also depends on this.
793
120
  uint32_t tmp = fieldFromInstruction_4(insn, 17, 5);
794
120
  unsigned NSize = 0;
795
120
  DecodeFN RegDecoder = NULL;
796
120
  if ((tmp & 0x18) == 0x00) {    // INSVE_B
797
6
    NSize = 4;
798
6
    RegDecoder = DecodeMSA128BRegisterClass;
799
114
  } else if ((tmp & 0x1c) == 0x10) { // INSVE_H
800
6
    NSize = 3;
801
6
    RegDecoder = DecodeMSA128HRegisterClass;
802
108
  } else if ((tmp & 0x1e) == 0x18) { // INSVE_W
803
33
    NSize = 2;
804
33
    RegDecoder = DecodeMSA128WRegisterClass;
805
75
  } else if ((tmp & 0x1f) == 0x1c) { // INSVE_D
806
75
    NSize = 1;
807
75
    RegDecoder = DecodeMSA128DRegisterClass;
808
75
  } else
809
0
    CS_ASSERT_RET_VAL(0 && "Invalid encoding", MCDisassembler_Fail);
810
811
  // $wd
812
120
  tmp = fieldFromInstruction_4(insn, 6, 5);
813
120
  if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler_Fail)
814
0
    return MCDisassembler_Fail;
815
  // $wd_in
816
120
  if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler_Fail)
817
0
    return MCDisassembler_Fail;
818
  // $n
819
120
  tmp = fieldFromInstruction_4(insn, 16, NSize);
820
120
  MCOperand_CreateImm0(MI, (tmp));
821
  // $ws
822
120
  tmp = fieldFromInstruction_4(insn, 11, 5);
823
120
  if (RegDecoder(MI, tmp, Address, Decoder) == MCDisassembler_Fail)
824
0
    return MCDisassembler_Fail;
825
  // $n2
826
120
  MCOperand_CreateImm0(MI, (0));
827
828
120
  return MCDisassembler_Success;
829
120
}
830
831
/*
832
static DecodeStatus DecodeDAHIDATIMMR6(MCInst *MI, uint32_t insn,
833
                                      uint64_t Address, const void *Decoder)
834
{
835
       uint32_t Rs = fieldFromInstruction_4(insn, 16, 5);
836
       uint32_t Imm = fieldFromInstruction_4(insn, 0, 16);
837
       MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR64RegClassID, Rs)));
838
       MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR64RegClassID, Rs)));
839
       MCOperand_CreateImm0(MI, (Imm));
840
841
       return MCDisassembler_Success;
842
}
843
*/
844
845
static DecodeStatus DecodeDAHIDATI(MCInst *MI, uint32_t insn, uint64_t Address,
846
                                   const void *Decoder)
847
0
 {
848
0
       uint32_t Rs = fieldFromInstruction_4(insn, 21, 5);
849
0
       uint32_t Imm = fieldFromInstruction_4(insn, 0, 16);
850
0
       MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR64RegClassID, Rs)));
851
0
       MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR64RegClassID, Rs)));
852
0
        MCOperand_CreateImm0(MI, (Imm));
853
 
854
0
        return MCDisassembler_Success;
855
0
 }
856
857
static DecodeStatus DecodeAddiGroupBranch(MCInst *MI, uint32_t insn,
858
            uint64_t Address, const void *Decoder)
859
1.57k
{
860
  // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled
861
  // (otherwise we would have matched the ADDI instruction from the earlier
862
  // ISA's instead).
863
  //
864
  // We have:
865
  //    0b001000 sssss ttttt iiiiiiiiiiiiiiii
866
  //      BOVC if rs >= rt
867
  //      BEQZALC if rs == 0 && rt != 0
868
  //      BEQC if rs < rt && rs != 0
869
870
1.57k
  uint32_t Rs = fieldFromInstruction_4(insn, 21, 5);
871
1.57k
  uint32_t Rt = fieldFromInstruction_4(insn, 16, 5);
872
1.57k
  int64_t Imm =
873
1.57k
    SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) * 4 + 4;
874
1.57k
  bool HasRs = false;
875
876
1.57k
  if (Rs >= Rt) {
877
1.14k
    MCInst_setOpcode(MI, (Mips_BOVC));
878
1.14k
    HasRs = true;
879
1.14k
  } else if (Rs != 0 && Rs < Rt) {
880
267
    MCInst_setOpcode(MI, (Mips_BEQC));
881
267
    HasRs = true;
882
267
  } else
883
166
    MCInst_setOpcode(MI, (Mips_BEQZALC));
884
885
1.57k
  if (HasRs)
886
1.40k
    MCOperand_CreateReg0(
887
1.40k
      MI, (getReg(MI, Mips_GPR32RegClassID, Rs)));
888
889
1.57k
  MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
890
1.57k
  MCOperand_CreateImm0(MI, (Imm));
891
892
1.57k
  return MCDisassembler_Success;
893
1.57k
}
894
895
static DecodeStatus DecodePOP35GroupBranchMMR6(MCInst *MI, uint32_t insn,
896
                 uint64_t Address,
897
                 const void *Decoder)
898
1.00k
{
899
1.00k
  uint32_t Rt = fieldFromInstruction_4(insn, 21, 5);
900
1.00k
  uint32_t Rs = fieldFromInstruction_4(insn, 16, 5);
901
1.00k
  int64_t Imm = 0;
902
903
1.00k
  if (Rs >= Rt) {
904
499
    MCInst_setOpcode(MI, (Mips_BOVC_MMR6));
905
499
    MCOperand_CreateReg0(
906
499
      MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
907
499
    MCOperand_CreateReg0(
908
499
      MI, (getReg(MI, Mips_GPR32RegClassID, Rs)));
909
499
    Imm = SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) *
910
499
            2 +
911
499
          4;
912
508
  } else if (Rs != 0 && Rs < Rt) {
913
355
    MCInst_setOpcode(MI, (Mips_BEQC_MMR6));
914
355
    MCOperand_CreateReg0(
915
355
      MI, (getReg(MI, Mips_GPR32RegClassID, Rs)));
916
355
    MCOperand_CreateReg0(
917
355
      MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
918
355
    Imm = SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) *
919
355
            4 +
920
355
          4;
921
355
  } else {
922
153
    MCInst_setOpcode(MI, (Mips_BEQZALC_MMR6));
923
153
    MCOperand_CreateReg0(
924
153
      MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
925
153
    Imm = SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) *
926
153
            2 +
927
153
          4;
928
153
  }
929
930
1.00k
  MCOperand_CreateImm0(MI, (Imm));
931
932
1.00k
  return MCDisassembler_Success;
933
1.00k
}
934
935
static DecodeStatus DecodeDaddiGroupBranch(MCInst *MI, uint32_t insn,
936
             uint64_t Address,
937
             const void *Decoder)
938
317
{
939
  // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled
940
  // (otherwise we would have matched the ADDI instruction from the earlier
941
  // ISA's instead).
942
  //
943
  // We have:
944
  //    0b011000 sssss ttttt iiiiiiiiiiiiiiii
945
  //      BNVC if rs >= rt
946
  //      BNEZALC if rs == 0 && rt != 0
947
  //      BNEC if rs < rt && rs != 0
948
949
317
  uint32_t Rs = fieldFromInstruction_4(insn, 21, 5);
950
317
  uint32_t Rt = fieldFromInstruction_4(insn, 16, 5);
951
317
  int64_t Imm =
952
317
    SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) * 4 + 4;
953
317
  bool HasRs = false;
954
955
317
  if (Rs >= Rt) {
956
216
    MCInst_setOpcode(MI, (Mips_BNVC));
957
216
    HasRs = true;
958
216
  } else if (Rs != 0 && Rs < Rt) {
959
62
    MCInst_setOpcode(MI, (Mips_BNEC));
960
62
    HasRs = true;
961
62
  } else
962
39
    MCInst_setOpcode(MI, (Mips_BNEZALC));
963
964
317
  if (HasRs)
965
278
    MCOperand_CreateReg0(
966
278
      MI, (getReg(MI, Mips_GPR32RegClassID, Rs)));
967
968
317
  MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
969
317
  MCOperand_CreateImm0(MI, (Imm));
970
971
317
  return MCDisassembler_Success;
972
317
}
973
974
static DecodeStatus DecodePOP37GroupBranchMMR6(MCInst *MI, uint32_t insn,
975
                 uint64_t Address,
976
                 const void *Decoder)
977
940
{
978
940
  uint32_t Rt = fieldFromInstruction_4(insn, 21, 5);
979
940
  uint32_t Rs = fieldFromInstruction_4(insn, 16, 5);
980
940
  int64_t Imm = 0;
981
982
940
  if (Rs >= Rt) {
983
817
    MCInst_setOpcode(MI, (Mips_BNVC_MMR6));
984
817
    MCOperand_CreateReg0(
985
817
      MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
986
817
    MCOperand_CreateReg0(
987
817
      MI, (getReg(MI, Mips_GPR32RegClassID, Rs)));
988
817
    Imm = SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) *
989
817
            2 +
990
817
          4;
991
817
  } else if (Rs != 0 && Rs < Rt) {
992
57
    MCInst_setOpcode(MI, (Mips_BNEC_MMR6));
993
57
    MCOperand_CreateReg0(
994
57
      MI, (getReg(MI, Mips_GPR32RegClassID, Rs)));
995
57
    MCOperand_CreateReg0(
996
57
      MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
997
57
    Imm = SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) *
998
57
            4 +
999
57
          4;
1000
66
  } else {
1001
66
    MCInst_setOpcode(MI, (Mips_BNEZALC_MMR6));
1002
66
    MCOperand_CreateReg0(
1003
66
      MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
1004
66
    Imm = SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) *
1005
66
            2 +
1006
66
          4;
1007
66
  }
1008
1009
940
  MCOperand_CreateImm0(MI, (Imm));
1010
1011
940
  return MCDisassembler_Success;
1012
940
}
1013
1014
static DecodeStatus DecodePOP65GroupBranchMMR6(MCInst *MI, uint32_t insn,
1015
                 uint64_t Address,
1016
                 const void *Decoder)
1017
588
{
1018
  // We have:
1019
  //    0b110101 ttttt sssss iiiiiiiiiiiiiiii
1020
  //      Invalid if rt == 0
1021
  //      BGTZC_MMR6   if rs == 0  && rt != 0
1022
  //      BLTZC_MMR6   if rs == rt && rt != 0
1023
  //      BLTC_MMR6    if rs != rt && rs != 0  && rt != 0
1024
1025
588
  uint32_t Rt = fieldFromInstruction_4(insn, 21, 5);
1026
588
  uint32_t Rs = fieldFromInstruction_4(insn, 16, 5);
1027
588
  int64_t Imm =
1028
588
    SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) * 4 + 4;
1029
588
  bool HasRs = false;
1030
1031
588
  if (Rt == 0)
1032
1
    return MCDisassembler_Fail;
1033
587
  else if (Rs == 0)
1034
164
    MCInst_setOpcode(MI, (Mips_BGTZC_MMR6));
1035
423
  else if (Rs == Rt)
1036
206
    MCInst_setOpcode(MI, (Mips_BLTZC_MMR6));
1037
217
  else {
1038
217
    MCInst_setOpcode(MI, (Mips_BLTC_MMR6));
1039
217
    HasRs = true;
1040
217
  }
1041
1042
587
  if (HasRs)
1043
217
    MCOperand_CreateReg0(
1044
217
      MI, (getReg(MI, Mips_GPR32RegClassID, Rs)));
1045
1046
587
  MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
1047
1048
587
  MCOperand_CreateImm0(MI, (Imm));
1049
1050
587
  return MCDisassembler_Success;
1051
588
}
1052
1053
static DecodeStatus DecodePOP75GroupBranchMMR6(MCInst *MI, uint32_t insn,
1054
                 uint64_t Address,
1055
                 const void *Decoder)
1056
319
{
1057
  // We have:
1058
  //    0b111101 ttttt sssss iiiiiiiiiiiiiiii
1059
  //      Invalid if rt == 0
1060
  //      BLEZC_MMR6   if rs == 0  && rt != 0
1061
  //      BGEZC_MMR6   if rs == rt && rt != 0
1062
  //      BGEC_MMR6    if rs != rt && rs != 0  && rt != 0
1063
1064
319
  uint32_t Rt = fieldFromInstruction_4(insn, 21, 5);
1065
319
  uint32_t Rs = fieldFromInstruction_4(insn, 16, 5);
1066
319
  int64_t Imm =
1067
319
    SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) * 4 + 4;
1068
319
  bool HasRs = false;
1069
1070
319
  if (Rt == 0)
1071
1
    return MCDisassembler_Fail;
1072
318
  else if (Rs == 0)
1073
23
    MCInst_setOpcode(MI, (Mips_BLEZC_MMR6));
1074
295
  else if (Rs == Rt)
1075
51
    MCInst_setOpcode(MI, (Mips_BGEZC_MMR6));
1076
244
  else {
1077
244
    HasRs = true;
1078
244
    MCInst_setOpcode(MI, (Mips_BGEC_MMR6));
1079
244
  }
1080
1081
318
  if (HasRs)
1082
244
    MCOperand_CreateReg0(
1083
244
      MI, (getReg(MI, Mips_GPR32RegClassID, Rs)));
1084
1085
318
  MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
1086
1087
318
  MCOperand_CreateImm0(MI, (Imm));
1088
1089
318
  return MCDisassembler_Success;
1090
319
}
1091
1092
static DecodeStatus DecodeBlezlGroupBranch(MCInst *MI, uint32_t insn,
1093
             uint64_t Address,
1094
             const void *Decoder)
1095
117
{
1096
  // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled
1097
  // (otherwise we would have matched the BLEZL instruction from the earlier
1098
  // ISA's instead).
1099
  //
1100
  // We have:
1101
  //    0b010110 sssss ttttt iiiiiiiiiiiiiiii
1102
  //      Invalid if rs == 0
1103
  //      BLEZC   if rs == 0  && rt != 0
1104
  //      BGEZC   if rs == rt && rt != 0
1105
  //      BGEC    if rs != rt && rs != 0  && rt != 0
1106
1107
117
  uint32_t Rs = fieldFromInstruction_4(insn, 21, 5);
1108
117
  uint32_t Rt = fieldFromInstruction_4(insn, 16, 5);
1109
117
  int64_t Imm =
1110
117
    SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) * 4 + 4;
1111
117
  bool HasRs = false;
1112
1113
117
  if (Rt == 0)
1114
12
    return MCDisassembler_Fail;
1115
105
  else if (Rs == 0)
1116
32
    MCInst_setOpcode(MI, (Mips_BLEZC));
1117
73
  else if (Rs == Rt)
1118
30
    MCInst_setOpcode(MI, (Mips_BGEZC));
1119
43
  else {
1120
43
    HasRs = true;
1121
43
    MCInst_setOpcode(MI, (Mips_BGEC));
1122
43
  }
1123
1124
105
  if (HasRs)
1125
43
    MCOperand_CreateReg0(
1126
43
      MI, (getReg(MI, Mips_GPR32RegClassID, Rs)));
1127
1128
105
  MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
1129
1130
105
  MCOperand_CreateImm0(MI, (Imm));
1131
1132
105
  return MCDisassembler_Success;
1133
117
}
1134
1135
static DecodeStatus DecodeBgtzlGroupBranch(MCInst *MI, uint32_t insn,
1136
             uint64_t Address,
1137
             const void *Decoder)
1138
308
{
1139
  // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled
1140
  // (otherwise we would have matched the BGTZL instruction from the earlier
1141
  // ISA's instead).
1142
  //
1143
  // We have:
1144
  //    0b010111 sssss ttttt iiiiiiiiiiiiiiii
1145
  //      Invalid if rs == 0
1146
  //      BGTZC   if rs == 0  && rt != 0
1147
  //      BLTZC   if rs == rt && rt != 0
1148
  //      BLTC    if rs != rt && rs != 0  && rt != 0
1149
1150
308
  bool HasRs = false;
1151
1152
308
  uint32_t Rs = fieldFromInstruction_4(insn, 21, 5);
1153
308
  uint32_t Rt = fieldFromInstruction_4(insn, 16, 5);
1154
308
  int64_t Imm =
1155
308
    SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) * 4 + 4;
1156
1157
308
  if (Rt == 0)
1158
8
    return MCDisassembler_Fail;
1159
300
  else if (Rs == 0)
1160
26
    MCInst_setOpcode(MI, (Mips_BGTZC));
1161
274
  else if (Rs == Rt)
1162
10
    MCInst_setOpcode(MI, (Mips_BLTZC));
1163
264
  else {
1164
264
    MCInst_setOpcode(MI, (Mips_BLTC));
1165
264
    HasRs = true;
1166
264
  }
1167
1168
300
  if (HasRs)
1169
264
    MCOperand_CreateReg0(
1170
264
      MI, (getReg(MI, Mips_GPR32RegClassID, Rs)));
1171
1172
300
  MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
1173
1174
300
  MCOperand_CreateImm0(MI, (Imm));
1175
1176
300
  return MCDisassembler_Success;
1177
308
}
1178
1179
static DecodeStatus DecodeBgtzGroupBranch(MCInst *MI, uint32_t insn,
1180
            uint64_t Address, const void *Decoder)
1181
398
{
1182
  // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled
1183
  // (otherwise we would have matched the BGTZ instruction from the earlier
1184
  // ISA's instead).
1185
  //
1186
  // We have:
1187
  //    0b000111 sssss ttttt iiiiiiiiiiiiiiii
1188
  //      BGTZ    if rt == 0
1189
  //      BGTZALC if rs == 0 && rt != 0
1190
  //      BLTZALC if rs != 0 && rs == rt
1191
  //      BLTUC   if rs != 0 && rs != rt
1192
1193
398
  uint32_t Rs = fieldFromInstruction_4(insn, 21, 5);
1194
398
  uint32_t Rt = fieldFromInstruction_4(insn, 16, 5);
1195
398
  int64_t Imm =
1196
398
    SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) * 4 + 4;
1197
398
  bool HasRs = false;
1198
398
  bool HasRt = false;
1199
1200
398
  if (Rt == 0) {
1201
75
    MCInst_setOpcode(MI, (Mips_BGTZ));
1202
75
    HasRs = true;
1203
323
  } else if (Rs == 0) {
1204
68
    MCInst_setOpcode(MI, (Mips_BGTZALC));
1205
68
    HasRt = true;
1206
255
  } else if (Rs == Rt) {
1207
33
    MCInst_setOpcode(MI, (Mips_BLTZALC));
1208
33
    HasRs = true;
1209
222
  } else {
1210
222
    MCInst_setOpcode(MI, (Mips_BLTUC));
1211
222
    HasRs = true;
1212
222
    HasRt = true;
1213
222
  }
1214
1215
398
  if (HasRs)
1216
330
    MCOperand_CreateReg0(
1217
330
      MI, (getReg(MI, Mips_GPR32RegClassID, Rs)));
1218
1219
398
  if (HasRt)
1220
290
    MCOperand_CreateReg0(
1221
290
      MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
1222
1223
398
  MCOperand_CreateImm0(MI, (Imm));
1224
1225
398
  return MCDisassembler_Success;
1226
398
}
1227
1228
static DecodeStatus DecodeBlezGroupBranch(MCInst *MI, uint32_t insn,
1229
            uint64_t Address, const void *Decoder)
1230
543
{
1231
  // If we are called then we can assume that MIPS32r6/MIPS64r6 is enabled
1232
  // (otherwise we would have matched the BLEZL instruction from the earlier
1233
  // ISA's instead).
1234
  //
1235
  // We have:
1236
  //    0b000110 sssss ttttt iiiiiiiiiiiiiiii
1237
  //      Invalid   if rs == 0
1238
  //      BLEZALC   if rs == 0  && rt != 0
1239
  //      BGEZALC   if rs == rt && rt != 0
1240
  //      BGEUC     if rs != rt && rs != 0  && rt != 0
1241
1242
543
  uint32_t Rs = fieldFromInstruction_4(insn, 21, 5);
1243
543
  uint32_t Rt = fieldFromInstruction_4(insn, 16, 5);
1244
543
  int64_t Imm =
1245
543
    SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) * 4 + 4;
1246
543
  bool HasRs = false;
1247
1248
543
  if (Rt == 0)
1249
202
    return MCDisassembler_Fail;
1250
341
  else if (Rs == 0)
1251
199
    MCInst_setOpcode(MI, (Mips_BLEZALC));
1252
142
  else if (Rs == Rt)
1253
22
    MCInst_setOpcode(MI, (Mips_BGEZALC));
1254
120
  else {
1255
120
    HasRs = true;
1256
120
    MCInst_setOpcode(MI, (Mips_BGEUC));
1257
120
  }
1258
1259
341
  if (HasRs)
1260
120
    MCOperand_CreateReg0(
1261
120
      MI, (getReg(MI, Mips_GPR32RegClassID, Rs)));
1262
341
  MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
1263
1264
341
  MCOperand_CreateImm0(MI, (Imm));
1265
1266
341
  return MCDisassembler_Success;
1267
543
}
1268
1269
// Override the generated disassembler to produce DEXT all the time. This is
1270
// for feature / behaviour parity with  binutils.
1271
static DecodeStatus DecodeDEXT(MCInst *MI, uint32_t Insn, uint64_t Address,
1272
             const void *Decoder)
1273
0
{
1274
0
  unsigned Msbd = fieldFromInstruction_4(Insn, 11, 5);
1275
0
  unsigned Lsb = fieldFromInstruction_4(Insn, 6, 5);
1276
0
  unsigned Size = 0;
1277
0
  unsigned Pos = 0;
1278
1279
0
  switch (MCInst_getOpcode(MI)) {
1280
0
  case Mips_DEXT:
1281
0
    Pos = Lsb;
1282
0
    Size = Msbd + 1;
1283
0
    break;
1284
0
  case Mips_DEXTM:
1285
0
    Pos = Lsb;
1286
0
    Size = Msbd + 1 + 32;
1287
0
    break;
1288
0
  case Mips_DEXTU:
1289
0
    Pos = Lsb + 32;
1290
0
    Size = Msbd + 1;
1291
0
    break;
1292
0
  default:
1293
0
    CS_ASSERT_RET_VAL(0 && "Unknown DEXT instruction!", MCDisassembler_Fail);
1294
0
  }
1295
1296
0
  MCInst_setOpcode(MI, (Mips_DEXT));
1297
1298
0
  uint32_t Rs = fieldFromInstruction_4(Insn, 21, 5);
1299
0
  uint32_t Rt = fieldFromInstruction_4(Insn, 16, 5);
1300
1301
0
  MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR64RegClassID, Rt)));
1302
0
  MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR64RegClassID, Rs)));
1303
0
  MCOperand_CreateImm0(MI, (Pos));
1304
0
  MCOperand_CreateImm0(MI, (Size));
1305
1306
0
  return MCDisassembler_Success;
1307
0
}
1308
1309
// Override the generated disassembler to produce DINS all the time. This is
1310
// for feature / behaviour parity with binutils.
1311
static DecodeStatus DecodeDINS(MCInst *MI, uint32_t Insn, uint64_t Address,
1312
             const void *Decoder)
1313
0
{
1314
0
  unsigned Msbd = fieldFromInstruction_4(Insn, 11, 5);
1315
0
  unsigned Lsb = fieldFromInstruction_4(Insn, 6, 5);
1316
0
  unsigned Size = 0;
1317
0
  unsigned Pos = 0;
1318
1319
0
  switch (MCInst_getOpcode(MI)) {
1320
0
  case Mips_DINS:
1321
0
    Pos = Lsb;
1322
0
    Size = Msbd + 1 - Pos;
1323
0
    break;
1324
0
  case Mips_DINSM:
1325
0
    Pos = Lsb;
1326
0
    Size = Msbd + 33 - Pos;
1327
0
    break;
1328
0
  case Mips_DINSU:
1329
0
    Pos = Lsb + 32;
1330
    // mbsd = pos + size - 33
1331
    // mbsd - pos + 33 = size
1332
0
    Size = Msbd + 33 - Pos;
1333
0
    break;
1334
0
  default:
1335
0
    CS_ASSERT_RET_VAL(0 && "Unknown DINS instruction!", MCDisassembler_Fail);
1336
0
  }
1337
1338
0
  uint32_t Rs = fieldFromInstruction_4(Insn, 21, 5);
1339
0
  uint32_t Rt = fieldFromInstruction_4(Insn, 16, 5);
1340
1341
0
  MCInst_setOpcode(MI, (Mips_DINS));
1342
0
  MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR64RegClassID, Rt)));
1343
0
  MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR64RegClassID, Rs)));
1344
0
  MCOperand_CreateImm0(MI, (Pos));
1345
0
  MCOperand_CreateImm0(MI, (Size));
1346
1347
0
  return MCDisassembler_Success;
1348
0
}
1349
1350
// Auto-generated decoder wouldn't add the third operand for CRC32*.
1351
static DecodeStatus DecodeCRC(MCInst *MI, uint32_t Insn, uint64_t Address,
1352
            const void *Decoder)
1353
8
{
1354
8
  uint32_t Rs = fieldFromInstruction_4(Insn, 21, 5);
1355
8
  uint32_t Rt = fieldFromInstruction_4(Insn, 16, 5);
1356
8
  MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
1357
8
  MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR32RegClassID, Rs)));
1358
8
  MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
1359
8
  return MCDisassembler_Success;
1360
8
}
1361
1362
/// Read two bytes from the ArrayRef and return 16 bit halfword sorted
1363
/// according to the given endianness.
1364
static DecodeStatus readInstruction16(const uint8_t *Bytes, size_t BytesLen,
1365
              uint64_t Address, uint64_t *Size,
1366
              uint64_t *Insn, bool IsBigEndian)
1367
47.2k
{
1368
  // We want to read exactly 2 Bytes of data.
1369
47.2k
  if (BytesLen < 2) {
1370
242
    *Size = 0;
1371
242
    return MCDisassembler_Fail;
1372
242
  }
1373
1374
47.0k
  if (IsBigEndian) {
1375
23.7k
    *Insn = (Bytes[0] << 8) | Bytes[1];
1376
23.7k
  } else {
1377
23.2k
    *Insn = (Bytes[1] << 8) | Bytes[0];
1378
23.2k
  }
1379
1380
47.0k
  return MCDisassembler_Success;
1381
47.2k
}
1382
1383
/// Read four bytes from the ArrayRef and return 32 bit word sorted
1384
/// according to the given endianness.
1385
static DecodeStatus readInstruction32(const uint8_t *Bytes, size_t BytesLen,
1386
              uint64_t Address, uint64_t *Size,
1387
              uint64_t *Insn, bool IsBigEndian,
1388
              bool IsMicroMips)
1389
54.1k
{
1390
  // We want to read exactly 4 Bytes of data.
1391
54.1k
  if (BytesLen < 4) {
1392
670
    *Size = 0;
1393
670
    return MCDisassembler_Fail;
1394
670
  }
1395
1396
  // High 16 bits of a 32-bit microMIPS instruction (where the opcode is)
1397
  // always precede the low 16 bits in the instruction stream (that is, they
1398
  // are placed at lower addresses in the instruction stream).
1399
  //
1400
  // microMIPS byte ordering:
1401
  //   Big-endian:    0 | 1 | 2 | 3
1402
  //   Little-endian: 1 | 0 | 3 | 2
1403
1404
53.4k
  if (IsBigEndian) {
1405
    // Encoded as a big-endian 32-bit word in the stream.
1406
26.1k
    *Insn = (Bytes[3] << 0) | (Bytes[2] << 8) | (Bytes[1] << 16) |
1407
26.1k
           ((unsigned)Bytes[0] << 24);
1408
27.3k
  } else {
1409
27.3k
    if (IsMicroMips) {
1410
11.8k
      *Insn = (Bytes[2] << 0) | (Bytes[3] << 8) |
1411
11.8k
             (Bytes[0] << 16) | ((unsigned)Bytes[1] << 24);
1412
15.4k
    } else {
1413
15.4k
      *Insn = (Bytes[0] << 0) | (Bytes[1] << 8) |
1414
15.4k
             (Bytes[2] << 16) | ((unsigned)Bytes[3] << 24);
1415
15.4k
    }
1416
27.3k
  }
1417
1418
53.4k
  return MCDisassembler_Success;
1419
54.1k
}
1420
1421
/// Read 6 bytes from the ArrayRef and return in a 64-bit bit word sorted
1422
/// according to the given endianness and encoding byte-order.
1423
static DecodeStatus readInstruction48(const uint8_t *Bytes, size_t BytesLen,
1424
              uint64_t Address, uint64_t *Size,
1425
              uint64_t *Insn, bool IsBigEndian,
1426
              bool IsNanoMips)
1427
0
{
1428
  // We want to read exactly 6 Bytes of little-endian data in nanoMIPS mode.
1429
0
  if (BytesLen < 6 || IsBigEndian || !IsNanoMips) {
1430
0
    *Size = 0;
1431
0
    return MCDisassembler_Fail;
1432
0
  }
1433
1434
  // High 16 bits of a 32-bit nanoMIPS instruction (where the opcode is)
1435
  // always precede the low 16 bits in the instruction stream (that is, they
1436
  // are placed at lower addresses in the instruction stream).
1437
  //
1438
  // nanoMIPS byte ordering:
1439
  //   Little-endian: 1 | 0 | 3 | 2 | 5 | 4
1440
1441
0
  *Insn = (Bytes[0] << 0) | (Bytes[1] << 8);
1442
0
  *Insn = ((*Insn << 32) | (Bytes[4] << 0) | (Bytes[5] << 8) |
1443
0
    (Bytes[2] << 16) | ((unsigned)Bytes[3] << 24));
1444
0
  return MCDisassembler_Success;
1445
0
}
1446
1447
static DecodeStatus getInstruction(MCInst *Instr, uint64_t *Size, const uint8_t *Bytes,
1448
          size_t BytesLen, uint64_t Address, SStream *CStream)
1449
79.2k
{
1450
79.2k
  uint64_t Insn;
1451
79.2k
  DecodeStatus Result;
1452
79.2k
  *Size = 0;
1453
1454
79.2k
  cs_mode mode = Instr->csh->mode;
1455
79.2k
  bool IsBigEndian = mode & CS_MODE_BIG_ENDIAN;
1456
79.2k
  bool IsMicroMips = Mips_getFeatureBits(mode, Mips_FeatureMicroMips);
1457
79.2k
  bool IsNanoMips = Mips_getFeatureBits(mode, Mips_FeatureNanoMips);
1458
79.2k
  bool IsMips32r6 = Mips_getFeatureBits(mode, Mips_FeatureMips32r6);
1459
79.2k
  bool IsMips64r6 = Mips_getFeatureBits(mode, Mips_FeatureMips64r6);
1460
79.2k
  bool IsMips2 = Mips_getFeatureBits(mode, Mips_FeatureMips2);
1461
79.2k
  bool IsMips16 = Mips_getFeatureBits(mode, Mips_FeatureMips16);
1462
79.2k
  bool IsCnMips = Mips_getFeatureBits(mode, Mips_FeatureCnMips);
1463
79.2k
  bool IsCnMipsP = Mips_getFeatureBits(mode, Mips_FeatureCnMipsP);
1464
79.2k
  bool IsFP64 = Mips_getFeatureBits(mode, Mips_FeatureFP64Bit);
1465
79.2k
  bool IsGP64 = Mips_getFeatureBits(mode, Mips_FeatureGP64Bit);
1466
79.2k
  bool IsPTR64 = Mips_getFeatureBits(mode, Mips_FeaturePTR64Bit);
1467
  // Only present in MIPS-I and MIPS-II
1468
79.2k
  bool HasCOP3 = !Mips_getFeatureBits(mode, Mips_FeatureMips32) &&
1469
79.2k
           !Mips_getFeatureBits(mode, Mips_FeatureMips3);
1470
1471
79.2k
  if (IsNanoMips) {
1472
0
    uint64_t Insn2;
1473
0
    Result = readInstruction48(Bytes, BytesLen, Address, Size,
1474
0
            &Insn2, IsBigEndian, IsNanoMips);
1475
0
    if (Result != MCDisassembler_Fail) {
1476
      // Calling the auto-generated decoder function.
1477
0
      Result = decodeInstruction_8(DecoderTableNanoMips48,
1478
0
               Instr, Insn2, Address, NULL);
1479
0
      if (Result != MCDisassembler_Fail) {
1480
0
        *Size = 6;
1481
0
        return Result;
1482
0
      }
1483
0
    }
1484
1485
0
    Result = readInstruction32(Bytes, BytesLen, Address, Size,
1486
0
            &Insn, IsBigEndian, IsNanoMips);
1487
0
    if (Result != MCDisassembler_Fail) {
1488
      // Calling the auto-generated decoder function.
1489
0
      Result = decodeInstruction_4(DecoderTableNanoMips32,
1490
0
                 Instr, Insn, Address,
1491
0
                 NULL);
1492
0
      if (Result != MCDisassembler_Fail) {
1493
0
        *Size = 4;
1494
0
        return Result;
1495
0
      }
1496
0
    }
1497
1498
0
    Result = readInstruction16(Bytes, BytesLen, Address, Size,
1499
0
            &Insn, IsBigEndian);
1500
0
    if (Result != MCDisassembler_Fail) {
1501
      // Calling the auto-generated decoder function for NanoMips
1502
      // 16-bit instructions.
1503
0
      Result = decodeInstruction_2(DecoderTableNanoMips16,
1504
0
                 Instr, Insn, Address,
1505
0
                 NULL);
1506
0
      if (Result != MCDisassembler_Fail) {
1507
0
        *Size = 2;
1508
0
        return Result;
1509
0
      }
1510
1511
0
      Result = decodeInstruction_2(DecoderTableNanoMips_Conflict_Space16,
1512
0
                 Instr, Insn, Address,
1513
0
                 NULL);
1514
0
      if (Result != MCDisassembler_Fail) {
1515
0
        *Size = 2;
1516
0
        return Result;
1517
0
      }
1518
0
    }
1519
1520
    // This is an invalid instruction. Claim that the Size is 2 bytes. Since
1521
    // nanoMIPS instructions have a minimum alignment of 2, the next 2 bytes
1522
    // could form a valid instruction.
1523
0
    *Size = 2;
1524
0
    return MCDisassembler_Fail;
1525
0
  }
1526
1527
79.2k
  if (IsMicroMips) {
1528
47.2k
    Result = readInstruction16(Bytes, BytesLen, Address, Size,
1529
47.2k
             &Insn, IsBigEndian);
1530
47.2k
    if (Result == MCDisassembler_Fail)
1531
242
      return MCDisassembler_Fail;
1532
1533
47.0k
    if (IsMips32r6) {
1534
      // Calling the auto-generated decoder function for microMIPS32R6
1535
      // 16-bit instructions.
1536
30.1k
      Result = decodeInstruction_2(DecoderTableMicroMipsR616,
1537
30.1k
                 Instr, Insn, Address,
1538
30.1k
                 NULL);
1539
30.1k
      if (Result != MCDisassembler_Fail) {
1540
11.7k
        *Size = 2;
1541
11.7k
        return Result;
1542
11.7k
      }
1543
30.1k
    }
1544
1545
    // Calling the auto-generated decoder function for microMIPS 16-bit
1546
    // instructions.
1547
35.2k
    Result = decodeInstruction_2(DecoderTableMicroMips16, Instr,
1548
35.2k
               Insn, Address, NULL);
1549
35.2k
    if (Result != MCDisassembler_Fail) {
1550
13.1k
      *Size = 2;
1551
13.1k
      return Result;
1552
13.1k
    }
1553
1554
22.0k
    Result = readInstruction32(Bytes, BytesLen, Address, Size,
1555
22.0k
             &Insn, IsBigEndian, IsMicroMips);
1556
22.0k
    if (Result == MCDisassembler_Fail)
1557
140
      return MCDisassembler_Fail;
1558
1559
21.9k
    if (IsMips32r6) {
1560
      // Calling the auto-generated decoder function.
1561
14.5k
      Result = decodeInstruction_4(DecoderTableMicroMipsR6_Ambiguous32,
1562
14.5k
                 Instr, Insn, Address,
1563
14.5k
                 NULL);
1564
14.5k
      if (Result != MCDisassembler_Fail) {
1565
3.40k
        *Size = 4;
1566
3.40k
        return Result;
1567
3.40k
      }
1568
1569
11.0k
      Result = decodeInstruction_4(DecoderTableMicroMipsR632,
1570
11.0k
                 Instr, Insn, Address,
1571
11.0k
                 NULL);
1572
11.0k
      if (Result != MCDisassembler_Fail) {
1573
7.41k
        *Size = 4;
1574
7.41k
        return Result;
1575
7.41k
      }
1576
11.0k
    }
1577
1578
    // Calling the auto-generated decoder function.
1579
11.1k
    Result = decodeInstruction_4(DecoderTableMicroMips32, Instr,
1580
11.1k
               Insn, Address, NULL);
1581
11.1k
    if (Result != MCDisassembler_Fail) {
1582
10.2k
      *Size = 4;
1583
10.2k
      return Result;
1584
10.2k
    }
1585
1586
927
    Result = decodeInstruction_4(DecoderTableMicroMipsDSP32, Instr,
1587
927
               Insn, Address, NULL);
1588
927
    if (Result != MCDisassembler_Fail) {
1589
0
      *Size = 4;
1590
0
      return Result;
1591
0
    }
1592
1593
927
    if (IsFP64) {
1594
845
      Result =
1595
845
        decodeInstruction_4(DecoderTableMicroMipsFP6432,
1596
845
                Instr, Insn, Address, NULL);
1597
845
      if (Result != MCDisassembler_Fail) {
1598
761
        *Size = 4;
1599
761
        return Result;
1600
761
      }
1601
845
    }
1602
1603
    // This is an invalid instruction. Claim that the Size is 2 bytes. Since
1604
    // microMIPS instructions have a minimum alignment of 2, the next 2 bytes
1605
    // could form a valid instruction. The two bytes we rejected as an
1606
    // instruction could have actually beeen an inline constant pool that is
1607
    // unconditionally branched over.
1608
166
    *Size = 2;
1609
166
    return MCDisassembler_Fail;
1610
927
  }
1611
1612
32.0k
  if (IsMips16) {
1613
0
    Result = readInstruction32(Bytes, BytesLen, Address, Size,
1614
0
             &Insn, IsBigEndian, IsMicroMips);
1615
0
    if (Result != MCDisassembler_Fail) {
1616
0
      Result = decodeInstruction_4(DecoderTable32, Instr, Insn, Address,
1617
0
                 NULL);
1618
0
      if (Result != MCDisassembler_Fail) {
1619
0
        *Size = 4;
1620
0
        return Result;
1621
0
      }
1622
0
    }
1623
1624
0
    Result = readInstruction16(Bytes, BytesLen, Address, Size,
1625
0
             &Insn, IsBigEndian);
1626
0
    if (Result == MCDisassembler_Fail) {
1627
0
      return MCDisassembler_Fail;
1628
0
    }
1629
1630
0
    *Size = 2;
1631
0
    return decodeInstruction_2(DecoderTable16, Instr, Insn, Address, NULL);
1632
0
  }
1633
1634
  // Attempt to read the instruction so that we can attempt to decode it. If
1635
  // the buffer is not 4 bytes long, let the higher level logic figure out
1636
  // what to do with a size of zero and MCDisassembler::Fail.
1637
32.0k
  Result = readInstruction32(Bytes, BytesLen, Address, Size, &Insn, IsBigEndian,
1638
32.0k
           IsMicroMips);
1639
32.0k
  if (Result == MCDisassembler_Fail)
1640
530
    return MCDisassembler_Fail;
1641
1642
  // The only instruction size for standard encoded MIPS.
1643
31.4k
  *Size = 4;
1644
1645
31.4k
  if (HasCOP3) {
1646
0
    Result = decodeInstruction_4(DecoderTableCOP3_32, Instr, Insn,
1647
0
               Address, NULL);
1648
0
    if (Result != MCDisassembler_Fail)
1649
0
      return Result;
1650
0
  }
1651
1652
31.4k
  if (IsMips32r6 && IsGP64) {
1653
0
    Result = decodeInstruction_4(DecoderTableMips32r6_64r6_GP6432,
1654
0
               Instr, Insn, Address, NULL);
1655
0
    if (Result != MCDisassembler_Fail)
1656
0
      return Result;
1657
0
  }
1658
1659
31.4k
  if (IsMips32r6 && IsPTR64) {
1660
0
    Result = decodeInstruction_4(DecoderTableMips32r6_64r6_PTR6432,
1661
0
               Instr, Insn, Address, NULL);
1662
0
    if (Result != MCDisassembler_Fail)
1663
0
      return Result;
1664
0
  }
1665
1666
31.4k
  if (IsMips32r6 || IsMips64r6) {
1667
9.86k
    Result = decodeInstruction_4(DecoderTableMips32r6_64r6_BranchZero32, Instr,
1668
9.86k
               Insn, Address, NULL);
1669
9.86k
    if (Result != MCDisassembler_Fail)
1670
0
      return Result;
1671
1672
9.86k
    Result = decodeInstruction_4(DecoderTableMips32r6_64r632, Instr,
1673
9.86k
               Insn, Address, NULL);
1674
9.86k
    if (Result != MCDisassembler_Fail)
1675
4.37k
      return Result;
1676
1677
5.48k
    Result = decodeInstruction_4(DecoderTableMips32r6_64r6_Ambiguous32, Instr,
1678
5.48k
               Insn, Address, NULL);
1679
5.48k
    if (Result != MCDisassembler_Fail)
1680
0
      return Result;
1681
5.48k
  }
1682
1683
27.1k
  if (IsMips2 && IsPTR64) {
1684
0
    Result = decodeInstruction_4(DecoderTableMips32_64_PTR6432,
1685
0
               Instr, Insn, Address, NULL);
1686
0
    if (Result != MCDisassembler_Fail)
1687
0
      return Result;
1688
0
  }
1689
1690
27.1k
  if (IsCnMips) {
1691
0
    Result = decodeInstruction_4(DecoderTableCnMips32, Instr, Insn,
1692
0
               Address, NULL);
1693
0
    if (Result != MCDisassembler_Fail)
1694
0
      return Result;
1695
0
  }
1696
1697
27.1k
  if (IsCnMipsP) {
1698
0
    Result = decodeInstruction_4(DecoderTableCnMipsP32, Instr, Insn,
1699
0
               Address, NULL);
1700
0
    if (Result != MCDisassembler_Fail)
1701
0
      return Result;
1702
0
  }
1703
1704
27.1k
  if (IsGP64) {
1705
19.1k
    Result = decodeInstruction_4(DecoderTableMips6432, Instr, Insn,
1706
19.1k
               Address, NULL);
1707
19.1k
    if (Result != MCDisassembler_Fail)
1708
4.57k
      return Result;
1709
19.1k
  }
1710
1711
22.5k
  if (IsFP64) {
1712
20.1k
    Result = decodeInstruction_4(DecoderTableMipsFP6432, Instr,
1713
20.1k
               Insn, Address, NULL);
1714
20.1k
    if (Result != MCDisassembler_Fail)
1715
1.02k
      return Result;
1716
20.1k
  }
1717
1718
21.5k
  Result = decodeInstruction_4(DecoderTableMipsDSP32, Instr, Insn,
1719
21.5k
             Address, NULL);
1720
21.5k
  if (Result != MCDisassembler_Fail)
1721
383
    return Result;
1722
1723
  // Calling the auto-generated decoder function.
1724
21.1k
  Result = decodeInstruction_4(DecoderTableMips32, Instr, Insn, Address,
1725
21.1k
             NULL);
1726
21.1k
  if (Result != MCDisassembler_Fail)
1727
20.8k
    return Result;
1728
1729
294
  return MCDisassembler_Fail;
1730
21.1k
}
1731
1732
static DecodeStatus DecodeCPU16RegsRegisterClass(MCInst *Inst, unsigned RegNo,
1733
             uint64_t Address,
1734
             const void *Decoder)
1735
0
{
1736
0
  if (RegNo > 7)
1737
0
    return MCDisassembler_Fail;
1738
1739
0
  if (RegNo < 2)
1740
0
    RegNo += 16;
1741
1742
0
  unsigned Reg = getReg(Inst, Mips_GPR32RegClassID, RegNo);
1743
0
  MCOperand_CreateReg0(Inst, (Reg));
1744
0
  return MCDisassembler_Success;
1745
0
}
1746
1747
static DecodeStatus DecodeGPR64RegisterClass(MCInst *Inst, unsigned RegNo,
1748
               uint64_t Address,
1749
               const void *Decoder)
1750
12.9k
{
1751
12.9k
  if (RegNo > 31)
1752
0
    return MCDisassembler_Fail;
1753
1754
12.9k
  unsigned Reg = getReg(Inst, Mips_GPR64RegClassID, RegNo);
1755
12.9k
  MCOperand_CreateReg0(Inst, (Reg));
1756
12.9k
  return MCDisassembler_Success;
1757
12.9k
}
1758
1759
static DecodeStatus DecodeGPRMM16RegisterClass(MCInst *Inst, unsigned RegNo,
1760
                 uint64_t Address,
1761
                 const void *Decoder)
1762
32.3k
{
1763
32.3k
  if (RegNo > 7)
1764
0
    return MCDisassembler_Fail;
1765
32.3k
  unsigned Reg = getReg(Inst, Mips_GPRMM16RegClassID, RegNo);
1766
32.3k
  MCOperand_CreateReg0(Inst, (Reg));
1767
32.3k
  return MCDisassembler_Success;
1768
32.3k
}
1769
1770
static DecodeStatus DecodeGPRMM16ZeroRegisterClass(MCInst *Inst, unsigned RegNo,
1771
               uint64_t Address,
1772
               const void *Decoder)
1773
6.00k
{
1774
6.00k
  if (RegNo > 7)
1775
0
    return MCDisassembler_Fail;
1776
6.00k
  unsigned Reg = getReg(Inst, Mips_GPRMM16ZeroRegClassID, RegNo);
1777
6.00k
  MCOperand_CreateReg0(Inst, (Reg));
1778
6.00k
  return MCDisassembler_Success;
1779
6.00k
}
1780
1781
static DecodeStatus DecodeGPRMM16MovePRegisterClass(MCInst *Inst,
1782
                unsigned RegNo,
1783
                uint64_t Address,
1784
                const void *Decoder)
1785
8.24k
{
1786
8.24k
  if (RegNo > 7)
1787
0
    return MCDisassembler_Fail;
1788
8.24k
  unsigned Reg = getReg(Inst, Mips_GPRMM16MovePRegClassID, RegNo);
1789
8.24k
  MCOperand_CreateReg0(Inst, (Reg));
1790
8.24k
  return MCDisassembler_Success;
1791
8.24k
}
1792
1793
static DecodeStatus DecodeGPR32RegisterClass(MCInst *Inst, unsigned RegNo,
1794
               uint64_t Address,
1795
               const void *Decoder)
1796
85.3k
{
1797
85.3k
  if (RegNo > 31)
1798
0
    return MCDisassembler_Fail;
1799
85.3k
  unsigned Reg = getReg(Inst, Mips_GPR32RegClassID, RegNo);
1800
85.3k
  MCOperand_CreateReg0(Inst, (Reg));
1801
85.3k
  return MCDisassembler_Success;
1802
85.3k
}
1803
1804
static DecodeStatus DecodeGPRNM3RegisterClass(MCInst *Inst, unsigned RegNo,
1805
                uint64_t Address,
1806
                const void *Decoder)
1807
0
{
1808
0
  if (RegNo > 7)
1809
0
    return MCDisassembler_Fail;
1810
0
  RegNo |= ((RegNo & 0x4) ^ 0x4) << 2;
1811
0
  unsigned Reg = getReg(Inst, Mips_GPRNM32RegClassID, RegNo);
1812
0
  MCOperand_CreateReg0(Inst, (Reg));
1813
0
  return MCDisassembler_Success;
1814
0
}
1815
1816
static DecodeStatus DecodeGPRNMRARegisterClass(MCInst *Inst, unsigned RegNo,
1817
                 uint64_t Address,
1818
                 const void *Decoder)
1819
0
{
1820
0
  MCOperand_CreateReg0(Inst, (Mips_RA_NM));
1821
0
  return MCDisassembler_Success;
1822
0
}
1823
1824
static DecodeStatus DecodeGPRNM3ZRegisterClass(MCInst *Inst, unsigned RegNo,
1825
                 uint64_t Address,
1826
                 const void *Decoder)
1827
0
{
1828
0
  if (RegNo > 7)
1829
0
    return MCDisassembler_Fail;
1830
0
  if (RegNo != 0)
1831
0
    RegNo |= ((RegNo & 0x4) ^ 0x4) << 2;
1832
0
  unsigned Reg = getReg(Inst, Mips_GPRNM32RegClassID, RegNo);
1833
0
  MCOperand_CreateReg0(Inst, (Reg));
1834
0
  return MCDisassembler_Success;
1835
0
}
1836
1837
static DecodeStatus DecodeGPRNM4RegisterClass(MCInst *Inst, unsigned RegNo,
1838
                uint64_t Address,
1839
                const void *Decoder)
1840
0
{
1841
0
  if (RegNo > 31)
1842
0
    return MCDisassembler_Fail;
1843
0
  RegNo &= ~0x8;
1844
0
  RegNo += (RegNo < 4 ? 8 : 0);
1845
0
  unsigned Reg = getReg(Inst, Mips_GPRNM32RegClassID, RegNo);
1846
0
  MCOperand_CreateReg0(Inst, (Reg));
1847
0
  return MCDisassembler_Success;
1848
0
}
1849
1850
static DecodeStatus DecodeGPRNM4ZRegisterClass(MCInst *Inst, unsigned RegNo,
1851
                 uint64_t Address,
1852
                 const void *Decoder)
1853
0
{
1854
0
  if (RegNo > 31)
1855
0
    return MCDisassembler_Fail;
1856
0
  RegNo &= ~0x8;
1857
0
  if (RegNo == 3)
1858
0
    RegNo = 0;
1859
0
  else
1860
0
    RegNo += (RegNo < 3 ? 8 : 0);
1861
0
  unsigned Reg = getReg(Inst, Mips_GPRNM32RegClassID, RegNo);
1862
0
  MCOperand_CreateReg0(Inst, (Reg));
1863
0
  return MCDisassembler_Success;
1864
0
}
1865
1866
static DecodeStatus DecodeGPRNM32NZRegisterClass(MCInst *Inst, unsigned RegNo,
1867
             uint64_t Address,
1868
             const void *Decoder)
1869
0
{
1870
0
  if (RegNo == 0)
1871
0
    return MCDisassembler_Fail;
1872
0
  unsigned Reg = getReg(Inst, Mips_GPRNM32RegClassID, RegNo);
1873
0
  MCOperand_CreateReg0(Inst, (Reg));
1874
0
  return MCDisassembler_Success;
1875
0
}
1876
1877
static DecodeStatus DecodeGPRNM32RegisterClass(MCInst *Inst, unsigned RegNo,
1878
                 uint64_t Address,
1879
                 const void *Decoder)
1880
0
{
1881
0
  if (RegNo > 31)
1882
0
    return MCDisassembler_Fail;
1883
0
  unsigned Reg = getReg(Inst, Mips_GPRNM32RegClassID, RegNo);
1884
0
  MCOperand_CreateReg0(Inst, (Reg));
1885
0
  return MCDisassembler_Success;
1886
0
}
1887
1888
static DecodeStatus DecodeGPRNM2R1RegisterClass(MCInst *Inst, unsigned RegNo,
1889
            uint64_t Address,
1890
            const void *Decoder)
1891
0
{
1892
0
  if (RegNo > 31)
1893
0
    return MCDisassembler_Fail;
1894
0
  RegNo += 4;
1895
0
  unsigned Reg = getReg(Inst, Mips_GPRNM32RegClassID, RegNo);
1896
0
  MCOperand_CreateReg0(Inst, (Reg));
1897
0
  MCOperand_CreateReg0(Inst, (Reg + 1));
1898
0
  return MCDisassembler_Success;
1899
0
}
1900
1901
static DecodeStatus DecodeGPRNM1R1RegisterClass(MCInst *Inst, unsigned RegNo,
1902
            uint64_t Address,
1903
            const void *Decoder)
1904
0
{
1905
0
  if (RegNo != 0 && RegNo != 1)
1906
0
    return MCDisassembler_Fail;
1907
0
  RegNo += 4;
1908
0
  unsigned Reg = getReg(Inst, Mips_GPRNM32RegClassID, RegNo);
1909
0
  MCOperand_CreateReg0(Inst, (Reg));
1910
0
  return MCDisassembler_Success;
1911
0
}
1912
1913
static DecodeStatus DecodePtrRegisterClass(MCInst *Inst, unsigned RegNo,
1914
             uint64_t Address,
1915
             const void *Decoder)
1916
3.02k
{
1917
3.02k
  if (Mips_getFeatureBits(Inst->csh->mode, Mips_FeatureGP64Bit))
1918
1.93k
    return DecodeGPR64RegisterClass(Inst, RegNo, Address, Decoder);
1919
1920
1.08k
  return DecodeGPR32RegisterClass(Inst, RegNo, Address, Decoder);
1921
3.02k
}
1922
1923
static DecodeStatus DecodeDSPRRegisterClass(MCInst *Inst, unsigned RegNo,
1924
              uint64_t Address,
1925
              const void *Decoder)
1926
3.00k
{
1927
3.00k
  return DecodeGPR32RegisterClass(Inst, RegNo, Address, Decoder);
1928
3.00k
}
1929
1930
static DecodeStatus DecodeFGR64RegisterClass(MCInst *Inst, unsigned RegNo,
1931
               uint64_t Address,
1932
               const void *Decoder)
1933
3.80k
{
1934
3.80k
  if (RegNo > 31)
1935
0
    return MCDisassembler_Fail;
1936
1937
3.80k
  unsigned Reg = getReg(Inst, Mips_FGR64RegClassID, RegNo);
1938
3.80k
  MCOperand_CreateReg0(Inst, (Reg));
1939
3.80k
  return MCDisassembler_Success;
1940
3.80k
}
1941
1942
static DecodeStatus DecodeFGR32RegisterClass(MCInst *Inst, unsigned RegNo,
1943
               uint64_t Address,
1944
               const void *Decoder)
1945
4.50k
{
1946
4.50k
  if (RegNo > 31)
1947
0
    return MCDisassembler_Fail;
1948
1949
4.50k
  unsigned Reg = getReg(Inst, Mips_FGR32RegClassID, RegNo);
1950
4.50k
  MCOperand_CreateReg0(Inst, (Reg));
1951
4.50k
  return MCDisassembler_Success;
1952
4.50k
}
1953
1954
static DecodeStatus DecodeCCRRegisterClass(MCInst *Inst, unsigned RegNo,
1955
             uint64_t Address,
1956
             const void *Decoder)
1957
233
{
1958
233
  if (RegNo > 31)
1959
0
    return MCDisassembler_Fail;
1960
233
  unsigned Reg = getReg(Inst, Mips_CCRRegClassID, RegNo);
1961
233
  MCOperand_CreateReg0(Inst, (Reg));
1962
233
  return MCDisassembler_Success;
1963
233
}
1964
1965
static DecodeStatus DecodeFCCRegisterClass(MCInst *Inst, unsigned RegNo,
1966
             uint64_t Address,
1967
             const void *Decoder)
1968
2.34k
{
1969
2.34k
  if (RegNo > 7)
1970
0
    return MCDisassembler_Fail;
1971
2.34k
  unsigned Reg = getReg(Inst, Mips_FCCRegClassID, RegNo);
1972
2.34k
  MCOperand_CreateReg0(Inst, (Reg));
1973
2.34k
  return MCDisassembler_Success;
1974
2.34k
}
1975
1976
static DecodeStatus DecodeFGRCCRegisterClass(MCInst *Inst, unsigned RegNo,
1977
               uint64_t Address,
1978
               const void *Decoder)
1979
295
{
1980
295
  if (RegNo > 31)
1981
0
    return MCDisassembler_Fail;
1982
1983
295
  unsigned Reg = getReg(Inst, Mips_FGRCCRegClassID, RegNo);
1984
295
  MCOperand_CreateReg0(Inst, (Reg));
1985
295
  return MCDisassembler_Success;
1986
295
}
1987
1988
static DecodeStatus DecodeMem(MCInst *Inst, uint32_t Insn, uint64_t Address,
1989
            const void *Decoder)
1990
10.2k
{
1991
10.2k
  int Offset = SignExtend32((Insn & 0xffff), 16);
1992
10.2k
  unsigned Reg = fieldFromInstruction_4(Insn, 16, 5);
1993
10.2k
  unsigned Base = fieldFromInstruction_4(Insn, 21, 5);
1994
1995
10.2k
  Reg = getReg(Inst, Mips_GPR32RegClassID, Reg);
1996
10.2k
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
1997
1998
10.2k
  if (MCInst_getOpcode(Inst) == Mips_SC ||
1999
10.2k
      MCInst_getOpcode(Inst) == Mips_SCD)
2000
1.10k
    MCOperand_CreateReg0(Inst, (Reg));
2001
2002
10.2k
  MCOperand_CreateReg0(Inst, (Reg));
2003
10.2k
  MCOperand_CreateReg0(Inst, (Base));
2004
10.2k
  MCOperand_CreateImm0(Inst, (Offset));
2005
2006
10.2k
  return MCDisassembler_Success;
2007
10.2k
}
2008
2009
#define DEFINE_DecodeMemNM(Offbits, isSigned, rt) \
2010
  static DecodeStatus CONCAT(DecodeMemNM, \
2011
    CONCAT(Offbits, CONCAT(isSigned, rt)))( \
2012
    MCInst * Inst, uint32_t Insn, uint64_t Address, \
2013
    const void *Decoder) \
2014
0
  { \
2015
0
    int Offset = (Insn & ((1 << Offbits) - 1)); \
2016
0
    if (isSigned) \
2017
0
      Offset = SignExtend32((Offset), Offbits); \
2018
0
    unsigned Base; \
2019
0
\
2020
0
    switch (rt) { \
2021
0
    case Mips_GPRNMGPRegClassID: \
2022
0
    case Mips_GPRNMSPRegClassID: \
2023
0
      Base = 0; \
2024
0
      break; \
2025
0
    case Mips_GPRNM3RegClassID: \
2026
0
      Base = fieldFromInstruction_4(Insn, Offbits, 3); \
2027
0
      break; \
2028
0
    case Mips_GPRNM4RegClassID: \
2029
0
    case Mips_GPRNM4ZRegClassID: \
2030
0
\
2031
0
      break; \
2032
0
    default: \
2033
0
      Base = fieldFromInstruction_4(Insn, Offbits, 5); \
2034
0
    } \
2035
0
    Base = getReg(Inst, rt, Base); \
2036
0
\
2037
0
    MCOperand_CreateReg0(Inst, (Base)); \
2038
0
    MCOperand_CreateImm0(Inst, (Offset)); \
2039
0
\
2040
0
    return MCDisassembler_Success; \
2041
0
  }
Unexecuted instantiation: MipsDisassembler.c:DecodeMemNM_6_0_Mips_GPRNM3RegClassID
Unexecuted instantiation: MipsDisassembler.c:DecodeMemNM_7_0_Mips_GPRNMSPRegClassID
Unexecuted instantiation: MipsDisassembler.c:DecodeMemNM_9_0_Mips_GPRNMGPRegClassID
Unexecuted instantiation: MipsDisassembler.c:DecodeMemNM_2_0_Mips_GPRNM3RegClassID
Unexecuted instantiation: MipsDisassembler.c:DecodeMemNM_3_0_Mips_GPRNM3RegClassID
Unexecuted instantiation: MipsDisassembler.c:DecodeMemNM_21_0_Mips_GPRNMGPRegClassID
Unexecuted instantiation: MipsDisassembler.c:DecodeMemNM_18_0_Mips_GPRNMGPRegClassID
Unexecuted instantiation: MipsDisassembler.c:DecodeMemNM_12_0_Mips_GPRNM32RegClassID
Unexecuted instantiation: MipsDisassembler.c:DecodeMemNM_9_1_Mips_GPRNM32RegClassID
2042
DEFINE_DecodeMemNM(6, 0, Mips_GPRNM3RegClassID);
2043
DEFINE_DecodeMemNM(7, 0, Mips_GPRNMSPRegClassID);
2044
DEFINE_DecodeMemNM(9, 0, Mips_GPRNMGPRegClassID);
2045
DEFINE_DecodeMemNM(2, 0, Mips_GPRNM3RegClassID);
2046
DEFINE_DecodeMemNM(3, 0, Mips_GPRNM3RegClassID);
2047
DEFINE_DecodeMemNM(21, 0, Mips_GPRNMGPRegClassID);
2048
DEFINE_DecodeMemNM(18, 0, Mips_GPRNMGPRegClassID);
2049
DEFINE_DecodeMemNM(12, 0, Mips_GPRNM32RegClassID);
2050
DEFINE_DecodeMemNM(9, 1, Mips_GPRNM32RegClassID);
2051
2052
static DecodeStatus DecodeMemZeroNM(MCInst *Inst, uint32_t Insn,
2053
            uint64_t Address, const void *Decoder)
2054
0
{
2055
0
  unsigned Base;
2056
0
  Base = fieldFromInstruction_4(Insn, 0, 5);
2057
0
  Base = getReg(Inst, Mips_GPRNM32RegClassID, Base);
2058
0
  MCOperand_CreateReg0(Inst, (Base));
2059
2060
0
  return MCDisassembler_Success;
2061
0
}
2062
2063
#define DEFINE_DecodeMemNMRX(RegClass) \
2064
  static DecodeStatus CONCAT(DecodeMemNMRX, RegClass)( \
2065
    MCInst * Inst, uint32_t Insn, uint64_t Address, \
2066
    const void *Decoder) \
2067
0
  { \
2068
0
    unsigned Offset; \
2069
0
    unsigned Base; \
2070
0
    Offset = fieldFromInstruction_4(Insn, 0, 5); \
2071
0
    Base = fieldFromInstruction_4(Insn, 5, 5); \
2072
0
\
2073
0
    Base = getReg(Inst, RegClass, Base); \
2074
0
    Offset = getReg(Inst, RegClass, Offset); \
2075
0
    MCOperand_CreateReg0(Inst, (Base)); \
2076
0
    MCOperand_CreateReg0(Inst, (Offset)); \
2077
0
\
2078
0
    return MCDisassembler_Success; \
2079
0
  }
Unexecuted instantiation: MipsDisassembler.c:DecodeMemNMRX_Mips_GPRNM3RegClassID
Unexecuted instantiation: MipsDisassembler.c:DecodeMemNMRX_Mips_GPRNM32RegClassID
2080
DEFINE_DecodeMemNMRX(Mips_GPRNM3RegClassID);
2081
DEFINE_DecodeMemNMRX(Mips_GPRNM32RegClassID);
2082
2083
static DecodeStatus DecodeMemNM4x4(MCInst *Inst, uint32_t Insn,
2084
           uint64_t Address, const void *Decoder)
2085
0
{
2086
0
  int Offset = fieldFromInstruction_4(Insn, 0, 4);
2087
0
  unsigned Base;
2088
2089
0
  Base = getReg(Inst, Mips_GPRNM32RegClassID,
2090
0
          fieldFromInstruction_4(Insn, 4, 5) & ~0x8);
2091
2092
0
  MCOperand_CreateReg0(Inst, (Base));
2093
0
  MCOperand_CreateImm0(Inst, (Offset));
2094
2095
0
  return MCDisassembler_Success;
2096
0
}
2097
2098
static DecodeStatus DecodeMemEVA(MCInst *Inst, uint32_t Insn, uint64_t Address,
2099
         const void *Decoder)
2100
72
{
2101
72
  int Offset = SignExtend32((Insn >> 7), 9);
2102
72
  unsigned Reg = fieldFromInstruction_4(Insn, 16, 5);
2103
72
  unsigned Base = fieldFromInstruction_4(Insn, 21, 5);
2104
2105
72
  Reg = getReg(Inst, Mips_GPR32RegClassID, Reg);
2106
72
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2107
2108
72
  if (MCInst_getOpcode(Inst) == Mips_SCE)
2109
42
    MCOperand_CreateReg0(Inst, (Reg));
2110
2111
72
  MCOperand_CreateReg0(Inst, (Reg));
2112
72
  MCOperand_CreateReg0(Inst, (Base));
2113
72
  MCOperand_CreateImm0(Inst, (Offset));
2114
2115
72
  return MCDisassembler_Success;
2116
72
}
2117
2118
#include "MipsCP0RegisterMap.h"
2119
2120
static DecodeStatus DecodeCOP0SelRegisterClass(MCInst *Inst, unsigned RegNo,
2121
                 uint64_t Address,
2122
                 const void *Decoder)
2123
0
{
2124
0
  int Reg = COP0Map_getEncIndexMap(RegNo);
2125
2126
0
  if (Reg != -1) {
2127
0
    Reg = getReg(Inst, Mips_COP0SelRegClassID, Reg);
2128
0
    MCOperand_CreateReg0(Inst, (Reg));
2129
0
  } else {
2130
    // Not a named register encoding - print numeric register and select value
2131
0
    switch (MCInst_getOpcode(Inst)) {
2132
0
    case Mips_MFC0Sel_NM:
2133
0
      MCInst_setOpcode(Inst, (Mips_MFC0_NM));
2134
0
      break;
2135
0
    case Mips_MFHC0Sel_NM:
2136
0
      MCInst_setOpcode(Inst, (Mips_MFHC0_NM));
2137
0
      break;
2138
0
    case Mips_MTC0Sel_NM:
2139
0
      MCInst_setOpcode(Inst, (Mips_MTC0_NM));
2140
0
      break;
2141
0
    case Mips_MTHC0Sel_NM:
2142
0
      MCInst_setOpcode(Inst, (Mips_MTHC0_NM));
2143
0
      break;
2144
0
    default:
2145
0
      CS_ASSERT_RET_VAL(0 && "Unknown instruction!", MCDisassembler_Fail);
2146
0
    }
2147
0
    Reg = getReg(Inst, Mips_COP0RegClassID, RegNo >> 5);
2148
0
    MCOperand_CreateReg0(Inst, (Reg));
2149
0
    MCOperand_CreateImm0(Inst, (RegNo & 0x1f));
2150
0
  }
2151
0
  return MCDisassembler_Success;
2152
0
}
2153
2154
static DecodeStatus DecodeLoadByte15(MCInst *Inst, uint32_t Insn,
2155
             uint64_t Address, const void *Decoder)
2156
814
{
2157
814
  int Offset = SignExtend32((Insn & 0xffff), 16);
2158
814
  unsigned Base = fieldFromInstruction_4(Insn, 16, 5);
2159
814
  unsigned Reg = fieldFromInstruction_4(Insn, 21, 5);
2160
2161
814
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2162
814
  Reg = getReg(Inst, Mips_GPR32RegClassID, Reg);
2163
2164
814
  MCOperand_CreateReg0(Inst, (Reg));
2165
814
  MCOperand_CreateReg0(Inst, (Base));
2166
814
  MCOperand_CreateImm0(Inst, (Offset));
2167
2168
814
  return MCDisassembler_Success;
2169
814
}
2170
2171
static DecodeStatus DecodeCacheOp(MCInst *Inst, uint32_t Insn, uint64_t Address,
2172
          const void *Decoder)
2173
669
{
2174
669
  int Offset = SignExtend32((Insn & 0xffff), 16);
2175
669
  unsigned Hint = fieldFromInstruction_4(Insn, 16, 5);
2176
669
  unsigned Base = fieldFromInstruction_4(Insn, 21, 5);
2177
2178
669
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2179
2180
669
  MCOperand_CreateReg0(Inst, (Base));
2181
669
  MCOperand_CreateImm0(Inst, (Offset));
2182
669
  MCOperand_CreateImm0(Inst, (Hint));
2183
2184
669
  return MCDisassembler_Success;
2185
669
}
2186
2187
static DecodeStatus DecodeCacheOpMM(MCInst *Inst, uint32_t Insn,
2188
            uint64_t Address, const void *Decoder)
2189
102
{
2190
102
  int Offset = SignExtend32((Insn & 0xfff), 12);
2191
102
  unsigned Base = fieldFromInstruction_4(Insn, 16, 5);
2192
102
  unsigned Hint = fieldFromInstruction_4(Insn, 21, 5);
2193
2194
102
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2195
2196
102
  MCOperand_CreateReg0(Inst, (Base));
2197
102
  MCOperand_CreateImm0(Inst, (Offset));
2198
102
  MCOperand_CreateImm0(Inst, (Hint));
2199
2200
102
  return MCDisassembler_Success;
2201
102
}
2202
2203
static DecodeStatus DecodePrefeOpMM(MCInst *Inst, uint32_t Insn,
2204
            uint64_t Address, const void *Decoder)
2205
30
{
2206
30
  int Offset = SignExtend32((Insn & 0x1ff), 9);
2207
30
  unsigned Base = fieldFromInstruction_4(Insn, 16, 5);
2208
30
  unsigned Hint = fieldFromInstruction_4(Insn, 21, 5);
2209
2210
30
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2211
2212
30
  MCOperand_CreateReg0(Inst, (Base));
2213
30
  MCOperand_CreateImm0(Inst, (Offset));
2214
30
  MCOperand_CreateImm0(Inst, (Hint));
2215
2216
30
  return MCDisassembler_Success;
2217
30
}
2218
2219
static DecodeStatus DecodeCacheeOp_CacheOpR6(MCInst *Inst, uint32_t Insn,
2220
               uint64_t Address,
2221
               const void *Decoder)
2222
44
{
2223
44
  int Offset = SignExtend32((Insn >> 7), 9);
2224
44
  unsigned Hint = fieldFromInstruction_4(Insn, 16, 5);
2225
44
  unsigned Base = fieldFromInstruction_4(Insn, 21, 5);
2226
2227
44
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2228
2229
44
  MCOperand_CreateReg0(Inst, (Base));
2230
44
  MCOperand_CreateImm0(Inst, (Offset));
2231
44
  MCOperand_CreateImm0(Inst, (Hint));
2232
2233
44
  return MCDisassembler_Success;
2234
44
}
2235
2236
static DecodeStatus DecodeSyncI(MCInst *Inst, uint32_t Insn, uint64_t Address,
2237
        const void *Decoder)
2238
262
{
2239
262
  int Offset = SignExtend32((Insn & 0xffff), 16);
2240
262
  unsigned Base = fieldFromInstruction_4(Insn, 21, 5);
2241
2242
262
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2243
2244
262
  MCOperand_CreateReg0(Inst, (Base));
2245
262
  MCOperand_CreateImm0(Inst, (Offset));
2246
2247
262
  return MCDisassembler_Success;
2248
262
}
2249
2250
static DecodeStatus DecodeSyncI_MM(MCInst *Inst, uint32_t Insn,
2251
           uint64_t Address, const void *Decoder)
2252
44
{
2253
44
  int Offset = SignExtend32((Insn & 0xffff), 16);
2254
44
  unsigned Base = fieldFromInstruction_4(Insn, 16, 5);
2255
2256
44
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2257
2258
44
  MCOperand_CreateReg0(Inst, (Base));
2259
44
  MCOperand_CreateImm0(Inst, (Offset));
2260
2261
44
  return MCDisassembler_Success;
2262
44
}
2263
2264
static DecodeStatus DecodeSynciR6(MCInst *Inst, uint32_t Insn, uint64_t Address,
2265
          const void *Decoder)
2266
13
{
2267
13
  int Immediate = SignExtend32((Insn & 0xffff), 16);
2268
13
  unsigned Base = fieldFromInstruction_4(Insn, 16, 5);
2269
2270
13
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2271
2272
13
  MCOperand_CreateReg0(Inst, (Base));
2273
13
  MCOperand_CreateImm0(Inst, (Immediate));
2274
2275
13
  return MCDisassembler_Success;
2276
13
}
2277
2278
static DecodeStatus DecodeMSA128Mem(MCInst *Inst, uint32_t Insn,
2279
            uint64_t Address, const void *Decoder)
2280
1.77k
{
2281
1.77k
  int Offset = SignExtend32((fieldFromInstruction_4(Insn, 16, 10)), 10);
2282
1.77k
  unsigned Reg = fieldFromInstruction_4(Insn, 6, 5);
2283
1.77k
  unsigned Base = fieldFromInstruction_4(Insn, 11, 5);
2284
2285
1.77k
  Reg = getReg(Inst, Mips_MSA128BRegClassID, Reg);
2286
1.77k
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2287
2288
1.77k
  MCOperand_CreateReg0(Inst, (Reg));
2289
1.77k
  MCOperand_CreateReg0(Inst, (Base));
2290
2291
  // The immediate field of an LD/ST instruction is scaled which means it must
2292
  // be multiplied (when decoding) by the size (in bytes) of the instructions'
2293
  // data format.
2294
  // .b - 1 byte
2295
  // .h - 2 bytes
2296
  // .w - 4 bytes
2297
  // .d - 8 bytes
2298
1.77k
  switch (MCInst_getOpcode(Inst)) {
2299
0
  default:
2300
2301
0
    return MCDisassembler_Fail;
2302
0
    break;
2303
296
  case Mips_LD_B:
2304
534
  case Mips_ST_B:
2305
534
    MCOperand_CreateImm0(Inst, (Offset));
2306
534
    break;
2307
320
  case Mips_LD_H:
2308
540
  case Mips_ST_H:
2309
540
    MCOperand_CreateImm0(Inst, (Offset * 2));
2310
540
    break;
2311
69
  case Mips_LD_W:
2312
161
  case Mips_ST_W:
2313
161
    MCOperand_CreateImm0(Inst, (Offset * 4));
2314
161
    break;
2315
325
  case Mips_LD_D:
2316
535
  case Mips_ST_D:
2317
535
    MCOperand_CreateImm0(Inst, (Offset * 8));
2318
535
    break;
2319
1.77k
  }
2320
2321
1.77k
  return MCDisassembler_Success;
2322
1.77k
}
2323
2324
static DecodeStatus DecodeMemMMImm4(MCInst *Inst, uint32_t Insn,
2325
            uint64_t Address, const void *Decoder)
2326
7.45k
{
2327
7.45k
  unsigned Offset = Insn & 0xf;
2328
7.45k
  unsigned Reg = fieldFromInstruction_4(Insn, 7, 3);
2329
7.45k
  unsigned Base = fieldFromInstruction_4(Insn, 4, 3);
2330
2331
7.45k
  switch (MCInst_getOpcode(Inst)) {
2332
1.20k
  case Mips_LBU16_MM:
2333
1.50k
  case Mips_LHU16_MM:
2334
2.25k
  case Mips_LW16_MM:
2335
2.25k
    if (DecodeGPRMM16RegisterClass(Inst, Reg, Address, Decoder) ==
2336
2.25k
        MCDisassembler_Fail)
2337
0
      return MCDisassembler_Fail;
2338
2.25k
    break;
2339
2.25k
  case Mips_SB16_MM:
2340
3.69k
  case Mips_SB16_MMR6:
2341
3.89k
  case Mips_SH16_MM:
2342
4.36k
  case Mips_SH16_MMR6:
2343
4.60k
  case Mips_SW16_MM:
2344
5.20k
  case Mips_SW16_MMR6:
2345
5.20k
    if (DecodeGPRMM16ZeroRegisterClass(
2346
5.20k
          Inst, Reg, Address, Decoder) == MCDisassembler_Fail)
2347
0
      return MCDisassembler_Fail;
2348
5.20k
    break;
2349
7.45k
  }
2350
2351
7.45k
  if (DecodeGPRMM16RegisterClass(Inst, Base, Address, Decoder) ==
2352
7.45k
      MCDisassembler_Fail)
2353
0
    return MCDisassembler_Fail;
2354
2355
7.45k
  switch (MCInst_getOpcode(Inst)) {
2356
1.20k
  case Mips_LBU16_MM:
2357
1.20k
    if (Offset == 0xf)
2358
183
      MCOperand_CreateImm0(Inst, (-1));
2359
1.01k
    else
2360
1.01k
      MCOperand_CreateImm0(Inst, (Offset));
2361
1.20k
    break;
2362
324
  case Mips_SB16_MM:
2363
3.69k
  case Mips_SB16_MMR6:
2364
3.69k
    MCOperand_CreateImm0(Inst, (Offset));
2365
3.69k
    break;
2366
308
  case Mips_LHU16_MM:
2367
507
  case Mips_SH16_MM:
2368
973
  case Mips_SH16_MMR6:
2369
973
    MCOperand_CreateImm0(Inst, (Offset << 1));
2370
973
    break;
2371
744
  case Mips_LW16_MM:
2372
991
  case Mips_SW16_MM:
2373
1.58k
  case Mips_SW16_MMR6:
2374
1.58k
    MCOperand_CreateImm0(Inst, (Offset << 2));
2375
1.58k
    break;
2376
7.45k
  }
2377
2378
7.45k
  return MCDisassembler_Success;
2379
7.45k
}
2380
2381
static DecodeStatus DecodeMemMMSPImm5Lsl2(MCInst *Inst, uint32_t Insn,
2382
            uint64_t Address, const void *Decoder)
2383
1.39k
{
2384
1.39k
  unsigned Offset = Insn & 0x1F;
2385
1.39k
  unsigned Reg = fieldFromInstruction_4(Insn, 5, 5);
2386
2387
1.39k
  Reg = getReg(Inst, Mips_GPR32RegClassID, Reg);
2388
2389
1.39k
  MCOperand_CreateReg0(Inst, (Reg));
2390
1.39k
  MCOperand_CreateReg0(Inst, (Mips_SP));
2391
1.39k
  MCOperand_CreateImm0(Inst, (Offset << 2));
2392
2393
1.39k
  return MCDisassembler_Success;
2394
1.39k
}
2395
2396
static DecodeStatus DecodeMemMMGPImm7Lsl2(MCInst *Inst, uint32_t Insn,
2397
            uint64_t Address, const void *Decoder)
2398
1.23k
{
2399
1.23k
  unsigned Offset = Insn & 0x7F;
2400
1.23k
  unsigned Reg = fieldFromInstruction_4(Insn, 7, 3);
2401
2402
1.23k
  Reg = getReg(Inst, Mips_GPR32RegClassID, Reg);
2403
2404
1.23k
  MCOperand_CreateReg0(Inst, (Reg));
2405
1.23k
  MCOperand_CreateReg0(Inst, (Mips_GP));
2406
1.23k
  MCOperand_CreateImm0(Inst, (Offset << 2));
2407
2408
1.23k
  return MCDisassembler_Success;
2409
1.23k
}
2410
2411
static DecodeStatus DecodeMemMMReglistImm4Lsl2(MCInst *Inst, uint32_t Insn,
2412
                 uint64_t Address,
2413
                 const void *Decoder)
2414
397
{
2415
397
  int Offset;
2416
397
  switch (MCInst_getOpcode(Inst)) {
2417
96
  case Mips_LWM16_MMR6:
2418
224
  case Mips_SWM16_MMR6:
2419
224
    Offset = fieldFromInstruction_4(Insn, 4, 4);
2420
224
    break;
2421
173
  default:
2422
173
    Offset = SignExtend32((Insn & 0xf), 4);
2423
173
    break;
2424
397
  }
2425
2426
397
  if (DecodeRegListOperand16(Inst, Insn, Address, Decoder) ==
2427
397
      MCDisassembler_Fail)
2428
0
    return MCDisassembler_Fail;
2429
2430
397
  MCOperand_CreateReg0(Inst, (Mips_SP));
2431
397
  MCOperand_CreateImm0(Inst, (Offset << 2));
2432
2433
397
  return MCDisassembler_Success;
2434
397
}
2435
2436
static DecodeStatus DecodeMemMMImm9(MCInst *Inst, uint32_t Insn,
2437
            uint64_t Address, const void *Decoder)
2438
388
{
2439
388
  int Offset = SignExtend32((Insn & 0x1ff), 9);
2440
388
  unsigned Reg = fieldFromInstruction_4(Insn, 21, 5);
2441
388
  unsigned Base = fieldFromInstruction_4(Insn, 16, 5);
2442
2443
388
  Reg = getReg(Inst, Mips_GPR32RegClassID, Reg);
2444
388
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2445
2446
388
  if (MCInst_getOpcode(Inst) == Mips_SCE_MM ||
2447
388
      MCInst_getOpcode(Inst) == Mips_SC_MMR6)
2448
58
    MCOperand_CreateReg0(Inst, (Reg));
2449
2450
388
  MCOperand_CreateReg0(Inst, (Reg));
2451
388
  MCOperand_CreateReg0(Inst, (Base));
2452
388
  MCOperand_CreateImm0(Inst, (Offset));
2453
2454
388
  return MCDisassembler_Success;
2455
388
}
2456
2457
static DecodeStatus DecodeMemMMImm12(MCInst *Inst, uint32_t Insn,
2458
             uint64_t Address, const void *Decoder)
2459
1.48k
{
2460
1.48k
  int Offset = SignExtend32((Insn & 0x0fff), 12);
2461
1.48k
  unsigned Reg = fieldFromInstruction_4(Insn, 21, 5);
2462
1.48k
  unsigned Base = fieldFromInstruction_4(Insn, 16, 5);
2463
2464
1.48k
  Reg = getReg(Inst, Mips_GPR32RegClassID, Reg);
2465
1.48k
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2466
2467
1.48k
  switch (MCInst_getOpcode(Inst)) {
2468
157
  case Mips_SWM32_MM:
2469
339
  case Mips_LWM32_MM:
2470
339
    if (DecodeRegListOperand(Inst, Insn, Address, Decoder) ==
2471
339
        MCDisassembler_Fail)
2472
2
      return MCDisassembler_Fail;
2473
337
    MCOperand_CreateReg0(Inst, (Base));
2474
337
    MCOperand_CreateImm0(Inst, (Offset));
2475
337
    break;
2476
237
  case Mips_SC_MM:
2477
237
    MCOperand_CreateReg0(Inst, (Reg));
2478
    // fall through
2479
1.14k
  default:
2480
1.14k
    MCOperand_CreateReg0(Inst, (Reg));
2481
1.14k
    if (MCInst_getOpcode(Inst) == Mips_LWP_MM ||
2482
1.14k
        MCInst_getOpcode(Inst) == Mips_SWP_MM)
2483
691
      MCOperand_CreateReg0(Inst, (Reg + 1));
2484
2485
1.14k
    MCOperand_CreateReg0(Inst, (Base));
2486
1.14k
    MCOperand_CreateImm0(Inst, (Offset));
2487
1.48k
  }
2488
2489
1.48k
  return MCDisassembler_Success;
2490
1.48k
}
2491
2492
static DecodeStatus DecodeMemMMImm16(MCInst *Inst, uint32_t Insn,
2493
             uint64_t Address, const void *Decoder)
2494
3.29k
{
2495
3.29k
  int Offset = SignExtend32((Insn & 0xffff), 16);
2496
3.29k
  unsigned Reg = fieldFromInstruction_4(Insn, 21, 5);
2497
3.29k
  unsigned Base = fieldFromInstruction_4(Insn, 16, 5);
2498
2499
3.29k
  Reg = getReg(Inst, Mips_GPR32RegClassID, Reg);
2500
3.29k
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2501
2502
3.29k
  MCOperand_CreateReg0(Inst, (Reg));
2503
3.29k
  MCOperand_CreateReg0(Inst, (Base));
2504
3.29k
  MCOperand_CreateImm0(Inst, (Offset));
2505
2506
3.29k
  return MCDisassembler_Success;
2507
3.29k
}
2508
2509
static DecodeStatus DecodeFMem(MCInst *Inst, uint32_t Insn, uint64_t Address,
2510
             const void *Decoder)
2511
1.58k
{
2512
1.58k
  int Offset = SignExtend32((Insn & 0xffff), 16);
2513
1.58k
  unsigned Reg = fieldFromInstruction_4(Insn, 16, 5);
2514
1.58k
  unsigned Base = fieldFromInstruction_4(Insn, 21, 5);
2515
2516
1.58k
  Reg = getReg(Inst, Mips_FGR64RegClassID, Reg);
2517
1.58k
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2518
2519
1.58k
  MCOperand_CreateReg0(Inst, (Reg));
2520
1.58k
  MCOperand_CreateReg0(Inst, (Base));
2521
1.58k
  MCOperand_CreateImm0(Inst, (Offset));
2522
2523
1.58k
  return MCDisassembler_Success;
2524
1.58k
}
2525
2526
static DecodeStatus DecodeFMemMMR2(MCInst *Inst, uint32_t Insn,
2527
           uint64_t Address, const void *Decoder)
2528
1.83k
{
2529
  // This function is the same as DecodeFMem but with the Reg and Base fields
2530
  // swapped according to microMIPS spec.
2531
1.83k
  int Offset = SignExtend32((Insn & 0xffff), 16);
2532
1.83k
  unsigned Base = fieldFromInstruction_4(Insn, 16, 5);
2533
1.83k
  unsigned Reg = fieldFromInstruction_4(Insn, 21, 5);
2534
2535
1.83k
  Reg = getReg(Inst, Mips_FGR64RegClassID, Reg);
2536
1.83k
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2537
2538
1.83k
  MCOperand_CreateReg0(Inst, (Reg));
2539
1.83k
  MCOperand_CreateReg0(Inst, (Base));
2540
1.83k
  MCOperand_CreateImm0(Inst, (Offset));
2541
2542
1.83k
  return MCDisassembler_Success;
2543
1.83k
}
2544
2545
static DecodeStatus DecodeFMem2(MCInst *Inst, uint32_t Insn, uint64_t Address,
2546
        const void *Decoder)
2547
1.67k
{
2548
1.67k
  int Offset = SignExtend32((Insn & 0xffff), 16);
2549
1.67k
  unsigned Reg = fieldFromInstruction_4(Insn, 16, 5);
2550
1.67k
  unsigned Base = fieldFromInstruction_4(Insn, 21, 5);
2551
2552
1.67k
  Reg = getReg(Inst, Mips_COP2RegClassID, Reg);
2553
1.67k
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2554
2555
1.67k
  MCOperand_CreateReg0(Inst, (Reg));
2556
1.67k
  MCOperand_CreateReg0(Inst, (Base));
2557
1.67k
  MCOperand_CreateImm0(Inst, (Offset));
2558
2559
1.67k
  return MCDisassembler_Success;
2560
1.67k
}
2561
2562
static DecodeStatus DecodeFMem3(MCInst *Inst, uint32_t Insn, uint64_t Address,
2563
        const void *Decoder)
2564
0
{
2565
0
  int Offset = SignExtend32((Insn & 0xffff), 16);
2566
0
  unsigned Reg = fieldFromInstruction_4(Insn, 16, 5);
2567
0
  unsigned Base = fieldFromInstruction_4(Insn, 21, 5);
2568
2569
0
  Reg = getReg(Inst, Mips_COP3RegClassID, Reg);
2570
0
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2571
2572
0
  MCOperand_CreateReg0(Inst, (Reg));
2573
0
  MCOperand_CreateReg0(Inst, (Base));
2574
0
  MCOperand_CreateImm0(Inst, (Offset));
2575
2576
0
  return MCDisassembler_Success;
2577
0
}
2578
2579
static DecodeStatus DecodeFMemCop2R6(MCInst *Inst, uint32_t Insn,
2580
             uint64_t Address, const void *Decoder)
2581
316
{
2582
316
  int Offset = SignExtend32((Insn & 0x07ff), 11);
2583
316
  unsigned Reg = fieldFromInstruction_4(Insn, 16, 5);
2584
316
  unsigned Base = fieldFromInstruction_4(Insn, 11, 5);
2585
2586
316
  Reg = getReg(Inst, Mips_COP2RegClassID, Reg);
2587
316
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2588
2589
316
  MCOperand_CreateReg0(Inst, (Reg));
2590
316
  MCOperand_CreateReg0(Inst, (Base));
2591
316
  MCOperand_CreateImm0(Inst, (Offset));
2592
2593
316
  return MCDisassembler_Success;
2594
316
}
2595
2596
static DecodeStatus DecodeFMemCop2MMR6(MCInst *Inst, uint32_t Insn,
2597
               uint64_t Address, const void *Decoder)
2598
290
{
2599
290
  int Offset = SignExtend32((Insn & 0x07ff), 11);
2600
290
  unsigned Reg = fieldFromInstruction_4(Insn, 21, 5);
2601
290
  unsigned Base = fieldFromInstruction_4(Insn, 16, 5);
2602
2603
290
  Reg = getReg(Inst, Mips_COP2RegClassID, Reg);
2604
290
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2605
2606
290
  MCOperand_CreateReg0(Inst, (Reg));
2607
290
  MCOperand_CreateReg0(Inst, (Base));
2608
290
  MCOperand_CreateImm0(Inst, (Offset));
2609
2610
290
  return MCDisassembler_Success;
2611
290
}
2612
2613
static DecodeStatus DecodeSpecial3LlSc(MCInst *Inst, uint32_t Insn,
2614
               uint64_t Address, const void *Decoder)
2615
346
{
2616
346
  int64_t Offset = SignExtend64(((Insn >> 7) & 0x1ff), 9);
2617
346
  unsigned Rt = fieldFromInstruction_4(Insn, 16, 5);
2618
346
  unsigned Base = fieldFromInstruction_4(Insn, 21, 5);
2619
2620
346
  Rt = getReg(Inst, Mips_GPR32RegClassID, Rt);
2621
346
  Base = getReg(Inst, Mips_GPR32RegClassID, Base);
2622
2623
346
  if (MCInst_getOpcode(Inst) == Mips_SC_R6 ||
2624
346
      MCInst_getOpcode(Inst) == Mips_SCD_R6) {
2625
316
    MCOperand_CreateReg0(Inst, (Rt));
2626
316
  }
2627
2628
346
  MCOperand_CreateReg0(Inst, (Rt));
2629
346
  MCOperand_CreateReg0(Inst, (Base));
2630
346
  MCOperand_CreateImm0(Inst, (Offset));
2631
2632
346
  return MCDisassembler_Success;
2633
346
}
2634
2635
static DecodeStatus DecodeHWRegsRegisterClass(MCInst *Inst, unsigned RegNo,
2636
                uint64_t Address,
2637
                const void *Decoder)
2638
273
{
2639
  // Currently only hardware register 29 is supported.
2640
273
  if (RegNo != 29)
2641
17
    return MCDisassembler_Fail;
2642
256
  MCOperand_CreateReg0(Inst, (Mips_HWR29));
2643
256
  return MCDisassembler_Success;
2644
273
}
2645
2646
static DecodeStatus DecodeAFGR64RegisterClass(MCInst *Inst, unsigned RegNo,
2647
                uint64_t Address,
2648
                const void *Decoder)
2649
2.98k
{
2650
2.98k
  if (RegNo > 30 || RegNo % 2)
2651
45
    return MCDisassembler_Fail;
2652
2653
2.93k
  unsigned Reg = getReg(Inst, Mips_AFGR64RegClassID, RegNo / 2);
2654
2.93k
  MCOperand_CreateReg0(Inst, (Reg));
2655
2.93k
  return MCDisassembler_Success;
2656
2.98k
}
2657
2658
static DecodeStatus DecodeACC64DSPRegisterClass(MCInst *Inst, unsigned RegNo,
2659
            uint64_t Address,
2660
            const void *Decoder)
2661
1.37k
{
2662
1.37k
  if (RegNo >= 4)
2663
0
    return MCDisassembler_Fail;
2664
2665
1.37k
  unsigned Reg = getReg(Inst, Mips_ACC64DSPRegClassID, RegNo);
2666
1.37k
  MCOperand_CreateReg0(Inst, (Reg));
2667
1.37k
  return MCDisassembler_Success;
2668
1.37k
}
2669
2670
static DecodeStatus DecodeHI32DSPRegisterClass(MCInst *Inst, unsigned RegNo,
2671
                 uint64_t Address,
2672
                 const void *Decoder)
2673
94
{
2674
94
  if (RegNo >= 4)
2675
0
    return MCDisassembler_Fail;
2676
2677
94
  unsigned Reg = getReg(Inst, Mips_HI32DSPRegClassID, RegNo);
2678
94
  MCOperand_CreateReg0(Inst, (Reg));
2679
94
  return MCDisassembler_Success;
2680
94
}
2681
2682
static DecodeStatus DecodeLO32DSPRegisterClass(MCInst *Inst, unsigned RegNo,
2683
                 uint64_t Address,
2684
                 const void *Decoder)
2685
80
{
2686
80
  if (RegNo >= 4)
2687
0
    return MCDisassembler_Fail;
2688
2689
80
  unsigned Reg = getReg(Inst, Mips_LO32DSPRegClassID, RegNo);
2690
80
  MCOperand_CreateReg0(Inst, (Reg));
2691
80
  return MCDisassembler_Success;
2692
80
}
2693
2694
static DecodeStatus DecodeMSA128BRegisterClass(MCInst *Inst, unsigned RegNo,
2695
                 uint64_t Address,
2696
                 const void *Decoder)
2697
6.47k
{
2698
6.47k
  if (RegNo > 31)
2699
0
    return MCDisassembler_Fail;
2700
2701
6.47k
  unsigned Reg = getReg(Inst, Mips_MSA128BRegClassID, RegNo);
2702
6.47k
  MCOperand_CreateReg0(Inst, (Reg));
2703
6.47k
  return MCDisassembler_Success;
2704
6.47k
}
2705
2706
static DecodeStatus DecodeMSA128HRegisterClass(MCInst *Inst, unsigned RegNo,
2707
                 uint64_t Address,
2708
                 const void *Decoder)
2709
4.92k
{
2710
4.92k
  if (RegNo > 31)
2711
0
    return MCDisassembler_Fail;
2712
2713
4.92k
  unsigned Reg = getReg(Inst, Mips_MSA128HRegClassID, RegNo);
2714
4.92k
  MCOperand_CreateReg0(Inst, (Reg));
2715
4.92k
  return MCDisassembler_Success;
2716
4.92k
}
2717
2718
static DecodeStatus DecodeMSA128WRegisterClass(MCInst *Inst, unsigned RegNo,
2719
                 uint64_t Address,
2720
                 const void *Decoder)
2721
5.06k
{
2722
5.06k
  if (RegNo > 31)
2723
0
    return MCDisassembler_Fail;
2724
2725
5.06k
  unsigned Reg = getReg(Inst, Mips_MSA128WRegClassID, RegNo);
2726
5.06k
  MCOperand_CreateReg0(Inst, (Reg));
2727
5.06k
  return MCDisassembler_Success;
2728
5.06k
}
2729
2730
static DecodeStatus DecodeMSA128DRegisterClass(MCInst *Inst, unsigned RegNo,
2731
                 uint64_t Address,
2732
                 const void *Decoder)
2733
4.17k
{
2734
4.17k
  if (RegNo > 31)
2735
0
    return MCDisassembler_Fail;
2736
2737
4.17k
  unsigned Reg = getReg(Inst, Mips_MSA128DRegClassID, RegNo);
2738
4.17k
  MCOperand_CreateReg0(Inst, (Reg));
2739
4.17k
  return MCDisassembler_Success;
2740
4.17k
}
2741
2742
static DecodeStatus DecodeMSACtrlRegisterClass(MCInst *Inst, unsigned RegNo,
2743
                 uint64_t Address,
2744
                 const void *Decoder)
2745
233
{
2746
233
  if (RegNo > 7)
2747
5
    return MCDisassembler_Fail;
2748
2749
228
  unsigned Reg = getReg(Inst, Mips_MSACtrlRegClassID, RegNo);
2750
228
  MCOperand_CreateReg0(Inst, (Reg));
2751
228
  return MCDisassembler_Success;
2752
233
}
2753
2754
static DecodeStatus DecodeCOP0RegisterClass(MCInst *Inst, unsigned RegNo,
2755
              uint64_t Address,
2756
              const void *Decoder)
2757
194
{
2758
194
  if (RegNo > 31)
2759
0
    return MCDisassembler_Fail;
2760
2761
194
  unsigned Reg = getReg(Inst, Mips_COP0RegClassID, RegNo);
2762
194
  MCOperand_CreateReg0(Inst, (Reg));
2763
194
  return MCDisassembler_Success;
2764
194
}
2765
2766
static DecodeStatus DecodeCOP2RegisterClass(MCInst *Inst, unsigned RegNo,
2767
              uint64_t Address,
2768
              const void *Decoder)
2769
648
{
2770
648
  if (RegNo > 31)
2771
0
    return MCDisassembler_Fail;
2772
2773
648
  unsigned Reg = getReg(Inst, Mips_COP2RegClassID, RegNo);
2774
648
  MCOperand_CreateReg0(Inst, (Reg));
2775
648
  return MCDisassembler_Success;
2776
648
}
2777
2778
static DecodeStatus DecodeBranchTarget(MCInst *Inst, unsigned Offset,
2779
               uint64_t Address, const void *Decoder)
2780
10.8k
{
2781
10.8k
  int32_t BranchOffset = (SignExtend32((Offset), 16) * 4) + 4;
2782
10.8k
  MCOperand_CreateImm0(Inst, (BranchOffset));
2783
10.8k
  return MCDisassembler_Success;
2784
10.8k
}
2785
2786
static DecodeStatus DecodeBranchTarget1SImm16(MCInst *Inst, unsigned Offset,
2787
                uint64_t Address,
2788
                const void *Decoder)
2789
17
{
2790
17
  int32_t BranchOffset = (SignExtend32((Offset), 16) * 2);
2791
17
  MCOperand_CreateImm0(Inst, (BranchOffset));
2792
17
  return MCDisassembler_Success;
2793
17
}
2794
2795
static DecodeStatus DecodeJumpTarget(MCInst *Inst, uint32_t Insn,
2796
             uint64_t Address, const void *Decoder)
2797
2.89k
{
2798
2.89k
  unsigned JumpOffset = fieldFromInstruction_4(Insn, 0, 26) << 2;
2799
2.89k
  MCOperand_CreateImm0(Inst, (JumpOffset));
2800
2.89k
  return MCDisassembler_Success;
2801
2.89k
}
2802
2803
static DecodeStatus DecodeBranchTarget21(MCInst *Inst, unsigned Offset,
2804
           uint64_t Address, const void *Decoder)
2805
561
{
2806
561
  int32_t BranchOffset = SignExtend32((Offset), 21) * 4 + 4;
2807
2808
561
  MCOperand_CreateImm0(Inst, (BranchOffset));
2809
561
  return MCDisassembler_Success;
2810
561
}
2811
2812
static DecodeStatus DecodeBranchTarget21MM(MCInst *Inst, unsigned Offset,
2813
             uint64_t Address,
2814
             const void *Decoder)
2815
169
{
2816
169
  int32_t BranchOffset = SignExtend32((Offset), 21) * 4 + 4;
2817
2818
169
  MCOperand_CreateImm0(Inst, (BranchOffset));
2819
169
  return MCDisassembler_Success;
2820
169
}
2821
2822
static DecodeStatus DecodeBranchTarget26(MCInst *Inst, unsigned Offset,
2823
           uint64_t Address, const void *Decoder)
2824
517
{
2825
517
  int32_t BranchOffset = SignExtend32((Offset), 26) * 4 + 4;
2826
2827
517
  MCOperand_CreateImm0(Inst, (BranchOffset));
2828
517
  return MCDisassembler_Success;
2829
517
}
2830
2831
static DecodeStatus DecodeBranchTarget7MM(MCInst *Inst, unsigned Offset,
2832
            uint64_t Address, const void *Decoder)
2833
1.24k
{
2834
1.24k
  int32_t BranchOffset = SignExtend32((Offset << 1), 8);
2835
1.24k
  MCOperand_CreateImm0(Inst, (BranchOffset));
2836
1.24k
  return MCDisassembler_Success;
2837
1.24k
}
2838
2839
static DecodeStatus DecodeBranchTarget10MM(MCInst *Inst, unsigned Offset,
2840
             uint64_t Address,
2841
             const void *Decoder)
2842
456
{
2843
456
  int32_t BranchOffset = SignExtend32((Offset << 1), 11);
2844
456
  MCOperand_CreateImm0(Inst, (BranchOffset));
2845
456
  return MCDisassembler_Success;
2846
456
}
2847
2848
static DecodeStatus DecodeBranchTargetMM(MCInst *Inst, unsigned Offset,
2849
           uint64_t Address, const void *Decoder)
2850
1.59k
{
2851
1.59k
  int32_t BranchOffset = SignExtend32((Offset), 16) * 2 + 4;
2852
1.59k
  MCOperand_CreateImm0(Inst, (BranchOffset));
2853
1.59k
  return MCDisassembler_Success;
2854
1.59k
}
2855
2856
static DecodeStatus DecodeBranchTarget26MM(MCInst *Inst, unsigned Offset,
2857
             uint64_t Address,
2858
             const void *Decoder)
2859
334
{
2860
334
  int32_t BranchOffset = SignExtend32((Offset << 1), 27);
2861
2862
334
  MCOperand_CreateImm0(Inst, (BranchOffset));
2863
334
  return MCDisassembler_Success;
2864
334
}
2865
2866
static DecodeStatus DecodeJumpTargetMM(MCInst *Inst, uint32_t Insn,
2867
               uint64_t Address, const void *Decoder)
2868
907
{
2869
907
  unsigned JumpOffset = fieldFromInstruction_4(Insn, 0, 26) << 1;
2870
907
  MCOperand_CreateImm0(Inst, (JumpOffset));
2871
907
  return MCDisassembler_Success;
2872
907
}
2873
2874
#define DEFINE_DecodeBranchTargetNM(Bits) \
2875
  static DecodeStatus CONCAT(DecodeBranchTargetNM, Bits)( \
2876
    MCInst * Inst, unsigned Offset, uint64_t Address, \
2877
    const void *Decoder) \
2878
0
  { \
2879
0
    uint32_t InsnSize = (Bits <= 10) ? 2 : 4; \
2880
0
    int32_t BranchOffset = \
2881
0
      SignExtend32((Offset), Bits + 1) + InsnSize; \
2882
0
\
2883
0
    MCOperand_CreateImm0(Inst, (BranchOffset)); \
2884
0
    return MCDisassembler_Success; \
2885
0
  }
Unexecuted instantiation: MipsDisassembler.c:DecodeBranchTargetNM_10
Unexecuted instantiation: MipsDisassembler.c:DecodeBranchTargetNM_7
Unexecuted instantiation: MipsDisassembler.c:DecodeBranchTargetNM_5
Unexecuted instantiation: MipsDisassembler.c:DecodeBranchTargetNM_21
Unexecuted instantiation: MipsDisassembler.c:DecodeBranchTargetNM_25
Unexecuted instantiation: MipsDisassembler.c:DecodeBranchTargetNM_14
Unexecuted instantiation: MipsDisassembler.c:DecodeBranchTargetNM_11
2886
DEFINE_DecodeBranchTargetNM(10);
2887
DEFINE_DecodeBranchTargetNM(7);
2888
DEFINE_DecodeBranchTargetNM(21);
2889
DEFINE_DecodeBranchTargetNM(25);
2890
DEFINE_DecodeBranchTargetNM(14);
2891
DEFINE_DecodeBranchTargetNM(11);
2892
DEFINE_DecodeBranchTargetNM(5);
2893
2894
static DecodeStatus DecodeJumpTargetXMM(MCInst *Inst, uint32_t Insn,
2895
          uint64_t Address, const void *Decoder)
2896
255
{
2897
255
  unsigned JumpOffset = fieldFromInstruction_4(Insn, 0, 26) << 2;
2898
255
  MCOperand_CreateImm0(Inst, (JumpOffset));
2899
255
  return MCDisassembler_Success;
2900
255
}
2901
2902
static DecodeStatus DecodeAddiur2Simm7(MCInst *Inst, unsigned Value,
2903
               uint64_t Address, const void *Decoder)
2904
2.46k
{
2905
2.46k
  if (Value == 0)
2906
191
    MCOperand_CreateImm0(Inst, (1));
2907
2.27k
  else if (Value == 0x7)
2908
842
    MCOperand_CreateImm0(Inst, (-1));
2909
1.43k
  else
2910
1.43k
    MCOperand_CreateImm0(Inst, (Value << 2));
2911
2.46k
  return MCDisassembler_Success;
2912
2.46k
}
2913
2914
static DecodeStatus DecodeLi16Imm(MCInst *Inst, unsigned Value,
2915
          uint64_t Address, const void *Decoder)
2916
622
{
2917
622
  if (Value == 0x7F)
2918
217
    MCOperand_CreateImm0(Inst, (-1));
2919
405
  else
2920
405
    MCOperand_CreateImm0(Inst, (Value));
2921
622
  return MCDisassembler_Success;
2922
622
}
2923
2924
static DecodeStatus DecodePOOL16BEncodedField(MCInst *Inst, unsigned Value,
2925
                uint64_t Address,
2926
                const void *Decoder)
2927
801
{
2928
801
  MCOperand_CreateImm0(Inst, (Value == 0x0 ? 8 : Value));
2929
801
  return MCDisassembler_Success;
2930
801
}
2931
2932
#define DEFINE_DecodeUImmWithOffsetAndScale(Bits, Offset, Scale) \
2933
  static DecodeStatus CONCAT(DecodeUImmWithOffsetAndScale, \
2934
           CONCAT(Bits, CONCAT(Offset, Scale)))( \
2935
    MCInst * Inst, unsigned Value, uint64_t Address, \
2936
    const void *Decoder) \
2937
2.12k
  { \
2938
2.12k
    Value &= ((1 << Bits) - 1); \
2939
2.12k
    Value *= Scale; \
2940
2.12k
    MCOperand_CreateImm0(Inst, (Value + Offset)); \
2941
2.12k
    return MCDisassembler_Success; \
2942
2.12k
  }
MipsDisassembler.c:DecodeUImmWithOffsetAndScale_5_0_4
Line
Count
Source
2937
278
  { \
2938
278
    Value &= ((1 << Bits) - 1); \
2939
278
    Value *= Scale; \
2940
278
    MCOperand_CreateImm0(Inst, (Value + Offset)); \
2941
278
    return MCDisassembler_Success; \
2942
278
  }
MipsDisassembler.c:DecodeUImmWithOffsetAndScale_6_0_4
Line
Count
Source
2937
1.39k
  { \
2938
1.39k
    Value &= ((1 << Bits) - 1); \
2939
1.39k
    Value *= Scale; \
2940
1.39k
    MCOperand_CreateImm0(Inst, (Value + Offset)); \
2941
1.39k
    return MCDisassembler_Success; \
2942
1.39k
  }
MipsDisassembler.c:DecodeUImmWithOffsetAndScale_5_1_1
Line
Count
Source
2937
321
  { \
2938
321
    Value &= ((1 << Bits) - 1); \
2939
321
    Value *= Scale; \
2940
321
    MCOperand_CreateImm0(Inst, (Value + Offset)); \
2941
321
    return MCDisassembler_Success; \
2942
321
  }
MipsDisassembler.c:DecodeUImmWithOffsetAndScale_2_1_1
Line
Count
Source
2937
133
  { \
2938
133
    Value &= ((1 << Bits) - 1); \
2939
133
    Value *= Scale; \
2940
133
    MCOperand_CreateImm0(Inst, (Value + Offset)); \
2941
133
    return MCDisassembler_Success; \
2942
133
  }
Unexecuted instantiation: MipsDisassembler.c:DecodeUImmWithOffsetAndScale_8_0_1
Unexecuted instantiation: MipsDisassembler.c:DecodeUImmWithOffsetAndScale_21_0_1
Unexecuted instantiation: MipsDisassembler.c:DecodeUImmWithOffsetAndScale_18_0_1
2943
DEFINE_DecodeUImmWithOffsetAndScale(5, 0, 4);
2944
DEFINE_DecodeUImmWithOffsetAndScale(6, 0, 4);
2945
DEFINE_DecodeUImmWithOffsetAndScale(2, 1, 1);
2946
DEFINE_DecodeUImmWithOffsetAndScale(5, 1, 1);
2947
DEFINE_DecodeUImmWithOffsetAndScale(8, 0, 1);
2948
DEFINE_DecodeUImmWithOffsetAndScale(18, 0, 1);
2949
DEFINE_DecodeUImmWithOffsetAndScale(21, 0, 1);
2950
2951
#define DEFINE_DecodeSImmWithOffsetAndScale(Bits, Offset, ScaleBy) \
2952
  static DecodeStatus CONCAT(DecodeSImmWithOffsetAndScale, \
2953
           CONCAT(Bits, CONCAT(Offset, ScaleBy)))( \
2954
    MCInst * Inst, unsigned Value, uint64_t Address, \
2955
    const void *Decoder) \
2956
4.99k
  { \
2957
4.99k
    int32_t Imm = SignExtend32((Value), Bits) * ScaleBy; \
2958
4.99k
    MCOperand_CreateImm0(Inst, (Imm + Offset)); \
2959
4.99k
    return MCDisassembler_Success; \
2960
4.99k
  }
MipsDisassembler.c:DecodeSImmWithOffsetAndScale_16_0_1
Line
Count
Source
2956
4.44k
  { \
2957
4.44k
    int32_t Imm = SignExtend32((Value), Bits) * ScaleBy; \
2958
4.44k
    MCOperand_CreateImm0(Inst, (Imm + Offset)); \
2959
4.44k
    return MCDisassembler_Success; \
2960
4.44k
  }
MipsDisassembler.c:DecodeSImmWithOffsetAndScale_10_0_1
Line
Count
Source
2956
28
  { \
2957
28
    int32_t Imm = SignExtend32((Value), Bits) * ScaleBy; \
2958
28
    MCOperand_CreateImm0(Inst, (Imm + Offset)); \
2959
28
    return MCDisassembler_Success; \
2960
28
  }
MipsDisassembler.c:DecodeSImmWithOffsetAndScale_4_0_1
Line
Count
Source
2956
431
  { \
2957
431
    int32_t Imm = SignExtend32((Value), Bits) * ScaleBy; \
2958
431
    MCOperand_CreateImm0(Inst, (Imm + Offset)); \
2959
431
    return MCDisassembler_Success; \
2960
431
  }
MipsDisassembler.c:DecodeSImmWithOffsetAndScale_6_0_1
Line
Count
Source
2956
93
  { \
2957
93
    int32_t Imm = SignExtend32((Value), Bits) * ScaleBy; \
2958
93
    MCOperand_CreateImm0(Inst, (Imm + Offset)); \
2959
93
    return MCDisassembler_Success; \
2960
93
  }
Unexecuted instantiation: MipsDisassembler.c:DecodeSImmWithOffsetAndScale_32_0_1
2961
2962
#define DEFINE_DecodeSImmWithOffsetAndScale_2(Bits, Offset) DEFINE_DecodeSImmWithOffsetAndScale(Bits, Offset, 1)
2963
#define DEFINE_DecodeSImmWithOffsetAndScale_3(Bits) DEFINE_DecodeSImmWithOffsetAndScale(Bits, 0, 1)
2964
2965
DEFINE_DecodeSImmWithOffsetAndScale_3(16);
2966
DEFINE_DecodeSImmWithOffsetAndScale_3(10);
2967
DEFINE_DecodeSImmWithOffsetAndScale_3(4);
2968
DEFINE_DecodeSImmWithOffsetAndScale_3(6);
2969
DEFINE_DecodeSImmWithOffsetAndScale_3(32);
2970
2971
static DecodeStatus DecodeInsSize(MCInst *Inst, uint32_t Insn, uint64_t Address,
2972
          const void *Decoder)
2973
468
{
2974
  // First we need to grab the pos(lsb) from MCInst.
2975
  // This function only handles the 32 bit variants of ins, as dins
2976
  // variants are handled differently.
2977
468
  int Pos = MCOperand_getImm(MCInst_getOperand(Inst, (2)));
2978
468
  int Size = (int)Insn - Pos + 1;
2979
468
  MCOperand_CreateImm0(Inst, (SignExtend32((Size), 16)));
2980
468
  return MCDisassembler_Success;
2981
468
}
2982
2983
static DecodeStatus DecodeSimm19Lsl2(MCInst *Inst, uint32_t Insn,
2984
             uint64_t Address, const void *Decoder)
2985
447
{
2986
447
  MCOperand_CreateImm0(Inst, (SignExtend32((Insn), 19) * 4));
2987
447
  return MCDisassembler_Success;
2988
447
}
2989
2990
static DecodeStatus DecodeSimm18Lsl3(MCInst *Inst, uint32_t Insn,
2991
             uint64_t Address, const void *Decoder)
2992
0
{
2993
0
  MCOperand_CreateImm0(Inst, (SignExtend32((Insn), 18) * 8));
2994
0
  return MCDisassembler_Success;
2995
0
}
2996
2997
static DecodeStatus DecodeSimm9SP(MCInst *Inst, uint32_t Insn, uint64_t Address,
2998
          const void *Decoder)
2999
1.56k
{
3000
1.56k
  int32_t DecodedValue;
3001
1.56k
  switch (Insn) {
3002
82
  case 0:
3003
82
    DecodedValue = 256;
3004
82
    break;
3005
227
  case 1:
3006
227
    DecodedValue = 257;
3007
227
    break;
3008
270
  case 510:
3009
270
    DecodedValue = -258;
3010
270
    break;
3011
232
  case 511:
3012
232
    DecodedValue = -257;
3013
232
    break;
3014
755
  default:
3015
755
    DecodedValue = SignExtend32((Insn), 9);
3016
755
    break;
3017
1.56k
  }
3018
1.56k
  MCOperand_CreateImm0(Inst, (DecodedValue * 4));
3019
1.56k
  return MCDisassembler_Success;
3020
1.56k
}
3021
3022
static DecodeStatus DecodeANDI16Imm(MCInst *Inst, uint32_t Insn,
3023
            uint64_t Address, const void *Decoder)
3024
321
{
3025
  // Insn must be >= 0, since it is unsigned that condition is always true.
3026
3027
321
  int32_t DecodedValues[] = { 128, 1,  2,  3,  4,  7,   8,     15,
3028
321
            16,  31, 32, 63, 64, 255, 32768, 65535 };
3029
321
  MCOperand_CreateImm0(Inst, (DecodedValues[Insn]));
3030
321
  return MCDisassembler_Success;
3031
321
}
3032
3033
static DecodeStatus DecodeRegListOperand(MCInst *Inst, uint32_t Insn,
3034
           uint64_t Address, const void *Decoder)
3035
189
{
3036
189
  unsigned Regs[] = { Mips_S0, Mips_S1, Mips_S2, Mips_S3, Mips_S4,
3037
189
          Mips_S5, Mips_S6, Mips_S7, Mips_FP };
3038
189
  unsigned RegNum;
3039
3040
189
  unsigned RegLst = fieldFromInstruction_4(Insn, 21, 5);
3041
3042
  // Empty register lists are not allowed.
3043
189
  if (RegLst == 0)
3044
1
    return MCDisassembler_Fail;
3045
3046
188
  RegNum = RegLst & 0xf;
3047
3048
  // RegLst values 10-15, and 26-31 are reserved.
3049
188
  if (RegNum > 9)
3050
1
    return MCDisassembler_Fail;
3051
3052
1.01k
  for (unsigned i = 0; i < RegNum; i++)
3053
831
    MCOperand_CreateReg0(Inst, (Regs[i]));
3054
3055
187
  if (RegLst & 0x10)
3056
77
    MCOperand_CreateReg0(Inst, (Mips_RA));
3057
3058
187
  return MCDisassembler_Success;
3059
188
}
3060
3061
static DecodeStatus DecodeRegListOperand16(MCInst *Inst, uint32_t Insn,
3062
             uint64_t Address,
3063
             const void *Decoder)
3064
397
{
3065
397
  unsigned Regs[] = { Mips_S0, Mips_S1, Mips_S2, Mips_S3 };
3066
397
  unsigned RegLst;
3067
397
  switch (MCInst_getOpcode(Inst)) {
3068
173
  default:
3069
173
    RegLst = fieldFromInstruction_4(Insn, 4, 2);
3070
173
    break;
3071
96
  case Mips_LWM16_MMR6:
3072
224
  case Mips_SWM16_MMR6:
3073
224
    RegLst = fieldFromInstruction_4(Insn, 8, 2);
3074
224
    break;
3075
397
  }
3076
397
  unsigned RegNum = RegLst & 0x3;
3077
3078
1.40k
  for (unsigned i = 0; i <= RegNum; i++)
3079
1.01k
    MCOperand_CreateReg0(Inst, (Regs[i]));
3080
3081
397
  MCOperand_CreateReg0(Inst, (Mips_RA));
3082
3083
397
  return MCDisassembler_Success;
3084
397
}
3085
3086
static DecodeStatus DecodeMovePOperands(MCInst *Inst, uint32_t Insn,
3087
          uint64_t Address, const void *Decoder)
3088
3.85k
{
3089
3.85k
  unsigned RegPair = fieldFromInstruction_4(Insn, 7, 3);
3090
3.85k
  if (DecodeMovePRegPair(Inst, RegPair, Address, Decoder) ==
3091
3.85k
      MCDisassembler_Fail)
3092
0
    return MCDisassembler_Fail;
3093
3094
3.85k
  unsigned RegRs;
3095
3.85k
  if (Inst->csh->mode & CS_MODE_MIPS32R6)
3096
3.53k
    RegRs = fieldFromInstruction_4(Insn, 0, 2) |
3097
3.53k
      (fieldFromInstruction_4(Insn, 3, 1) << 2);
3098
326
  else
3099
326
    RegRs = fieldFromInstruction_4(Insn, 1, 3);
3100
3.85k
  if (DecodeGPRMM16MovePRegisterClass(Inst, RegRs, Address, Decoder) ==
3101
3.85k
      MCDisassembler_Fail)
3102
0
    return MCDisassembler_Fail;
3103
3104
3.85k
  unsigned RegRt = fieldFromInstruction_4(Insn, 4, 3);
3105
3.85k
  if (DecodeGPRMM16MovePRegisterClass(Inst, RegRt, Address, Decoder) ==
3106
3.85k
      MCDisassembler_Fail)
3107
0
    return MCDisassembler_Fail;
3108
3109
3.85k
  return MCDisassembler_Success;
3110
3.85k
}
3111
3112
static DecodeStatus DecodeMovePRegPair(MCInst *Inst, unsigned RegPair,
3113
               uint64_t Address, const void *Decoder)
3114
4.12k
{
3115
4.12k
  switch (RegPair) {
3116
0
  default:
3117
0
    return MCDisassembler_Fail;
3118
1.22k
  case 0:
3119
1.22k
    MCOperand_CreateReg0(Inst, (Mips_A1));
3120
1.22k
    MCOperand_CreateReg0(Inst, (Mips_A2));
3121
1.22k
    break;
3122
256
  case 1:
3123
256
    MCOperand_CreateReg0(Inst, (Mips_A1));
3124
256
    MCOperand_CreateReg0(Inst, (Mips_A3));
3125
256
    break;
3126
732
  case 2:
3127
732
    MCOperand_CreateReg0(Inst, (Mips_A2));
3128
732
    MCOperand_CreateReg0(Inst, (Mips_A3));
3129
732
    break;
3130
62
  case 3:
3131
62
    MCOperand_CreateReg0(Inst, (Mips_A0));
3132
62
    MCOperand_CreateReg0(Inst, (Mips_S5));
3133
62
    break;
3134
504
  case 4:
3135
504
    MCOperand_CreateReg0(Inst, (Mips_A0));
3136
504
    MCOperand_CreateReg0(Inst, (Mips_S6));
3137
504
    break;
3138
44
  case 5:
3139
44
    MCOperand_CreateReg0(Inst, (Mips_A0));
3140
44
    MCOperand_CreateReg0(Inst, (Mips_A1));
3141
44
    break;
3142
1.29k
  case 6:
3143
1.29k
    MCOperand_CreateReg0(Inst, (Mips_A0));
3144
1.29k
    MCOperand_CreateReg0(Inst, (Mips_A2));
3145
1.29k
    break;
3146
7
  case 7:
3147
7
    MCOperand_CreateReg0(Inst, (Mips_A0));
3148
7
    MCOperand_CreateReg0(Inst, (Mips_A3));
3149
7
    break;
3150
4.12k
  }
3151
3152
4.12k
  return MCDisassembler_Success;
3153
4.12k
}
3154
3155
static DecodeStatus DecodeSimm23Lsl2(MCInst *Inst, uint32_t Insn,
3156
             uint64_t Address, const void *Decoder)
3157
555
{
3158
555
  MCOperand_CreateImm0(Inst, (SignExtend32((Insn << 2), 25)));
3159
555
  return MCDisassembler_Success;
3160
555
}
3161
3162
static DecodeStatus DecodeBgtzGroupBranchMMR6(MCInst *MI, uint32_t insn,
3163
                uint64_t Address,
3164
                const void *Decoder)
3165
620
{
3166
  // We have:
3167
  //    0b000111 ttttt sssss iiiiiiiiiiiiiiii
3168
  //      Invalid      if rt == 0
3169
  //      BGTZALC_MMR6 if rs == 0 && rt != 0
3170
  //      BLTZALC_MMR6 if rs != 0 && rs == rt
3171
  //      BLTUC_MMR6   if rs != 0 && rs != rt
3172
3173
620
  uint32_t Rt = fieldFromInstruction_4(insn, 21, 5);
3174
620
  uint32_t Rs = fieldFromInstruction_4(insn, 16, 5);
3175
620
  uint32_t Imm = 0;
3176
620
  bool HasRs = false;
3177
620
  bool HasRt = false;
3178
3179
620
  if (Rt == 0)
3180
2
    return MCDisassembler_Fail;
3181
618
  else if (Rs == 0) {
3182
285
    MCInst_setOpcode(MI, (Mips_BGTZALC_MMR6));
3183
285
    HasRt = true;
3184
285
    Imm = SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) *
3185
285
            2 +
3186
285
          4;
3187
333
  } else if (Rs == Rt) {
3188
193
    MCInst_setOpcode(MI, (Mips_BLTZALC_MMR6));
3189
193
    HasRs = true;
3190
193
    Imm = SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) *
3191
193
            2 +
3192
193
          4;
3193
193
  } else {
3194
140
    MCInst_setOpcode(MI, (Mips_BLTUC_MMR6));
3195
140
    HasRs = true;
3196
140
    HasRt = true;
3197
140
    Imm = SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) *
3198
140
            4 +
3199
140
          4;
3200
140
  }
3201
3202
618
  if (HasRs)
3203
333
    MCOperand_CreateReg0(
3204
333
      MI, (getReg(MI, Mips_GPR32RegClassID, Rs)));
3205
3206
618
  if (HasRt)
3207
425
    MCOperand_CreateReg0(
3208
425
      MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
3209
3210
618
  MCOperand_CreateImm0(MI, (Imm));
3211
3212
618
  return MCDisassembler_Success;
3213
620
}
3214
3215
static DecodeStatus DecodeBlezGroupBranchMMR6(MCInst *MI, uint32_t insn,
3216
                uint64_t Address,
3217
                const void *Decoder)
3218
848
{
3219
  // We have:
3220
  //    0b000110 ttttt sssss iiiiiiiiiiiiiiii
3221
  //      Invalid        if rt == 0
3222
  //      BLEZALC_MMR6   if rs == 0  && rt != 0
3223
  //      BGEZALC_MMR6   if rs == rt && rt != 0
3224
  //      BGEUC_MMR6     if rs != rt && rs != 0  && rt != 0
3225
3226
848
  uint32_t Rt = fieldFromInstruction_4(insn, 21, 5);
3227
848
  uint32_t Rs = fieldFromInstruction_4(insn, 16, 5);
3228
848
  uint32_t Imm = 0;
3229
848
  bool HasRs = false;
3230
3231
848
  if (Rt == 0)
3232
4
    return MCDisassembler_Fail;
3233
844
  else if (Rs == 0) {
3234
391
    MCInst_setOpcode(MI, (Mips_BLEZALC_MMR6));
3235
391
    Imm = SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) *
3236
391
            2 +
3237
391
          4;
3238
453
  } else if (Rs == Rt) {
3239
15
    MCInst_setOpcode(MI, (Mips_BGEZALC_MMR6));
3240
15
    Imm = SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) *
3241
15
            2 +
3242
15
          4;
3243
438
  } else {
3244
438
    HasRs = true;
3245
438
    MCInst_setOpcode(MI, (Mips_BGEUC_MMR6));
3246
438
    Imm = SignExtend64(fieldFromInstruction_4(insn, 0, 16), 16) *
3247
438
            4 +
3248
438
          4;
3249
438
  }
3250
3251
844
  if (HasRs)
3252
438
    MCOperand_CreateReg0(
3253
438
      MI, (getReg(MI, Mips_GPR32RegClassID, Rs)));
3254
844
  MCOperand_CreateReg0(MI, (getReg(MI, Mips_GPR32RegClassID, Rt)));
3255
3256
844
  MCOperand_CreateImm0(MI, (Imm));
3257
3258
844
  return MCDisassembler_Success;
3259
848
}
3260
3261
// This instruction does not have a working decoder, and needs to be
3262
// fixed. This "fixme" function was introduced to keep the backend compiling,
3263
// while making changes to tablegen code.
3264
static DecodeStatus DecodeFIXMEInstruction(MCInst *Inst, uint32_t Insn,
3265
             uint64_t Address,
3266
             const void *Decoder)
3267
0
{
3268
0
  return MCDisassembler_Fail;
3269
0
}
3270
3271
static DecodeStatus DecodeImmM1To126(MCInst *Inst, unsigned Value,
3272
             uint64_t Address, const void *Decoder)
3273
0
{
3274
0
  if (Value == 127)
3275
0
    MCOperand_CreateImm0(Inst, (-1));
3276
0
  else
3277
0
    MCOperand_CreateImm0(Inst, (Value));
3278
0
  return MCDisassembler_Success;
3279
0
}
3280
3281
static DecodeStatus DecodeUImm4Mask(MCInst *Inst, unsigned Value,
3282
            uint64_t Address, const void *Decoder)
3283
0
{
3284
0
  if (Value == 12)
3285
0
    MCOperand_CreateImm0(Inst, (0xff));
3286
0
  else if (Value == 13)
3287
0
    MCOperand_CreateImm0(Inst, (0xffff));
3288
0
  else
3289
0
    MCOperand_CreateImm0(Inst, (Value));
3290
0
  return MCDisassembler_Success;
3291
0
}
3292
3293
static DecodeStatus DecodeUImm3Shift(MCInst *Inst, unsigned Value,
3294
             uint64_t Address, const void *Decoder)
3295
0
{
3296
0
  if (Value == 0)
3297
0
    MCOperand_CreateImm0(Inst, (8));
3298
0
  else
3299
0
    MCOperand_CreateImm0(Inst, (Value));
3300
0
  return MCDisassembler_Success;
3301
0
}
3302
3303
static DecodeStatus DecodeNMRegListOperand(MCInst *Inst, uint32_t Insn,
3304
             uint64_t Address,
3305
             const void *Decoder)
3306
0
{
3307
0
  unsigned RegStart = fieldFromInstruction_4(Insn, 5, 5);
3308
0
  unsigned RegCount = fieldFromInstruction_4(Insn, 1, 4);
3309
0
  unsigned GP_bit = fieldFromInstruction_4(Insn, 0, 1);
3310
0
  unsigned i;
3311
0
  unsigned RegNo;
3312
3313
0
  MCOperand_CreateReg0(
3314
0
    Inst, (getReg(Inst, Mips_GPRNM32RegClassID, RegStart)));
3315
0
  for (i = RegStart + 1; i < RegStart + RegCount; i++) {
3316
0
    if (i == RegStart + RegCount - 1 && GP_bit)
3317
0
      RegNo = 28;
3318
0
    else if (i > 31)
3319
0
      RegNo = 16 + (i % 32); // $ra+1 wraps to $s0
3320
0
    else
3321
0
      RegNo = i;
3322
0
    MCOperand_CreateReg0(
3323
0
      Inst, (getReg(Inst, Mips_GPRNM32RegClassID, RegNo)));
3324
0
  }
3325
0
  return MCDisassembler_Success;
3326
0
}
3327
3328
static DecodeStatus DecodeNMRegList16Operand(MCInst *Inst, uint32_t Insn,
3329
               uint64_t Address,
3330
               const void *Decoder)
3331
0
{
3332
0
  unsigned RegStart = 30 + fieldFromInstruction_4(Insn, 4, 1);
3333
0
  unsigned RegCount = fieldFromInstruction_4(Insn, 0, 4);
3334
  // Re-encode the parameters for 32-bit instruction operand
3335
  // and call it's decoder
3336
0
  return DecodeNMRegListOperand(Inst, (RegStart << 5) | (RegCount << 1),
3337
0
              Address, Decoder);
3338
0
}
3339
3340
static DecodeStatus DecodeNegImm12(MCInst *Inst, uint32_t Insn,
3341
           uint64_t Address, const void *Decoder)
3342
0
{
3343
0
  int Imm = fieldFromInstruction_4(Insn, 0, 12);
3344
3345
0
  MCOperand_CreateImm0(Inst, (-Imm));
3346
0
  return MCDisassembler_Success;
3347
0
}
3348
3349
#define DEFINE_DecodeSImmWithReg(Bits, Offset, Scale, RegNum) \
3350
  static DecodeStatus CONCAT( \
3351
    DecodeSImmWithReg, \
3352
    CONCAT(Bits, CONCAT(Offset, CONCAT(Scale, RegNum))))( \
3353
    MCInst * Inst, unsigned Value, uint64_t Address, \
3354
    const void *Decoder) \
3355
0
  { \
3356
0
    MCOperand_CreateReg0(Inst, (RegNum)); \
3357
0
    return CONCAT(DecodeSImmWithOffsetAndScale, \
3358
0
            CONCAT(Bits, CONCAT(Offset, Scale)))( \
3359
0
      Inst, Value, Address, Decoder); \
3360
0
  }
3361
DEFINE_DecodeSImmWithReg(32, 0, 1, Mips_GP_NM);
3362
3363
#define DEFINE_DecodeUImmWithReg(Bits, Offset, Scale, RegNum) \
3364
  static DecodeStatus CONCAT( \
3365
    DecodeUImmWithReg, \
3366
    CONCAT(Bits, CONCAT(Offset, CONCAT(Scale, RegNum))))( \
3367
    MCInst * Inst, unsigned Value, uint64_t Address, \
3368
    const void *Decoder) \
3369
0
  { \
3370
0
    MCOperand_CreateReg0(Inst, (RegNum)); \
3371
0
    return CONCAT(DecodeUImmWithOffsetAndScale, \
3372
0
            CONCAT(Bits, CONCAT(Offset, Scale)))( \
3373
0
      Inst, Value, Address, Decoder); \
3374
0
  }
Unexecuted instantiation: MipsDisassembler.c:DecodeUImmWithReg_8_0_1_Mips_SP_NM
Unexecuted instantiation: MipsDisassembler.c:DecodeUImmWithReg_21_0_1_Mips_GP_NM
Unexecuted instantiation: MipsDisassembler.c:DecodeUImmWithReg_18_0_1_Mips_GP_NM
3375
DEFINE_DecodeUImmWithReg(8, 0, 1, Mips_SP_NM);
3376
DEFINE_DecodeUImmWithReg(21, 0, 1, Mips_GP_NM);
3377
DEFINE_DecodeUImmWithReg(18, 0, 1, Mips_GP_NM);
3378
3379
static DecodeStatus DecodeSImm32s12(MCInst *Inst, uint32_t Insn,
3380
            uint64_t Address, const void *Decoder)
3381
0
{
3382
0
  uint64_t Imm = ((uint64_t)Insn) << 12;
3383
0
  MCOperand_CreateImm0(Inst, (Imm));
3384
0
  return MCDisassembler_Success;
3385
0
}
3386
3387
#define DEFINE_DecodeAddressPCRelNM(Bits) \
3388
  static DecodeStatus CONCAT(DecodeAddressPCRelNM, Bits)( \
3389
    MCInst * Inst, unsigned Offset, uint64_t Address, \
3390
    const void *Decoder) \
3391
0
  { \
3392
0
    uint32_t InsnSize = Bits == 32 ? 6 : 4; \
3393
0
    int32_t BranchOffset = \
3394
0
      SignExtend32((Offset), Bits) + InsnSize; \
3395
0
\
3396
0
    MCOperand_CreateImm0(Inst, (BranchOffset)); \
3397
0
    return MCDisassembler_Success; \
3398
0
  }
Unexecuted instantiation: MipsDisassembler.c:DecodeAddressPCRelNM_22
Unexecuted instantiation: MipsDisassembler.c:DecodeAddressPCRelNM_32
3399
DEFINE_DecodeAddressPCRelNM(22);
3400
DEFINE_DecodeAddressPCRelNM(32);
3401
3402
static DecodeStatus DecodeBranchConflictNM(MCInst *Inst, uint32_t Insn,
3403
             uint64_t Address,
3404
             const void *Decoder)
3405
0
{
3406
0
  unsigned Rt = fieldFromInstruction_4(Insn, 7, 3);
3407
0
  unsigned Rs = fieldFromInstruction_4(Insn, 4, 3);
3408
0
  unsigned Offset = fieldFromInstruction_4(Insn, 0, 4) << 1;
3409
0
  if (Rs < Rt)
3410
0
    MCInst_setOpcode(Inst, (Mips_BEQC16_NM));
3411
0
  else
3412
0
    MCInst_setOpcode(Inst, (Mips_BNEC16_NM));
3413
0
  if (DecodeGPRNM3RegisterClass(Inst, Rt, Address, Decoder) ==
3414
0
        MCDisassembler_Success &&
3415
0
      DecodeGPRNM3RegisterClass(Inst, Rs, Address, Decoder) ==
3416
0
        MCDisassembler_Success)
3417
0
    return CONCAT(DecodeBranchTargetNM, 5)(Inst, Offset, Address,
3418
0
                   Decoder);
3419
0
  else
3420
0
    return MCDisassembler_Fail;
3421
0
}
3422
3423
DecodeStatus Mips_LLVM_getInstruction(MCInst *Instr, uint64_t *Size, const uint8_t *Bytes,
3424
          size_t BytesLen, uint64_t Address, SStream *CStream)
3425
79.2k
{
3426
79.2k
  return getInstruction(Instr, Size, Bytes, BytesLen, Address, CStream);
3427
79.2k
}