Coverage Report

Created: 2024-09-08 06:22

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