Coverage Report

Created: 2024-09-08 06:22

/src/capstonev5/arch/TriCore/TriCoreDisassembler.c
Line
Count
Source (jump to first uncovered line)
1
//===------ TriCoreDisassembler.cpp - Disassembler for TriCore --*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
/* Capstone Disassembly Engine */
11
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 */
12
13
#ifdef CAPSTONE_HAS_TRICORE
14
15
#include <stdio.h> // DEBUG
16
#include <stdlib.h>
17
#include <string.h>
18
19
#include "../../cs_priv.h"
20
#include "../../utils.h"
21
22
#include "../../MCInst.h"
23
#include "../../MCInstrDesc.h"
24
#include "../../MCFixedLenDisassembler.h"
25
#include "../../MCRegisterInfo.h"
26
#include "../../MCDisassembler.h"
27
#include "../../MathExtras.h"
28
29
#include "TriCoreDisassembler.h"
30
#include "TriCoreMapping.h"
31
#include "TriCoreLinkage.h"
32
33
static unsigned getReg(MCRegisterInfo *MRI, unsigned RC, unsigned RegNo)
34
0
{
35
0
  const MCRegisterClass *rc = MCRegisterInfo_getRegClass(MRI, RC);
36
0
  return rc->RegsBegin[RegNo];
37
0
}
38
39
#define tryDecodeReg(i, x)                                                    \
40
0
  status = DecodeRegisterClass(Inst, (x), &desc->OpInfo[(i)], Decoder); \
41
0
  if (status != MCDisassembler_Success)                                 \
42
0
    return status;
43
44
0
#define decodeImm(x) MCOperand_CreateImm0(Inst, (x));
45
46
static DecodeStatus DecodeSBInstruction(MCInst *Inst, unsigned Insn,
47
          uint64_t Address, void *Decoder);
48
49
static DecodeStatus DecodeSBRInstruction(MCInst *Inst, unsigned Insn,
50
           uint64_t Address, void *Decoder);
51
52
static DecodeStatus DecodeSCInstruction(MCInst *Inst, unsigned Insn,
53
          uint64_t Address, void *Decoder);
54
55
static DecodeStatus DecodeSRInstruction(MCInst *Inst, unsigned Insn,
56
          uint64_t Address, void *Decoder);
57
58
static DecodeStatus DecodeSRCInstruction(MCInst *Inst, unsigned Insn,
59
           uint64_t Address, void *Decoder);
60
61
static DecodeStatus DecodeSRRInstruction(MCInst *Inst, unsigned Insn,
62
           uint64_t Address, void *Decoder);
63
64
static DecodeStatus DecodeABSInstruction(MCInst *Inst, unsigned Insn,
65
           uint64_t Address, void *Decoder);
66
67
static DecodeStatus DecodeBInstruction(MCInst *Inst, unsigned Insn,
68
               uint64_t Address, void *Decoder);
69
70
static DecodeStatus DecodeBOInstruction(MCInst *Inst, unsigned Insn,
71
          uint64_t Address, void *Decoder);
72
73
static DecodeStatus DecodeBOLInstruction(MCInst *Inst, unsigned Insn,
74
           uint64_t Address, void *Decoder);
75
76
static DecodeStatus DecodeRCInstruction(MCInst *Inst, unsigned Insn,
77
          uint64_t Address, void *Decoder);
78
79
static DecodeStatus DecodeRCPWInstruction(MCInst *Inst, unsigned Insn,
80
            uint64_t Address, void *Decoder);
81
82
static DecodeStatus DecodeRLCInstruction(MCInst *Inst, unsigned Insn,
83
           uint64_t Address, void *Decoder);
84
85
static DecodeStatus DecodeRRInstruction(MCInst *Inst, unsigned Insn,
86
          uint64_t Address, void *Decoder);
87
88
static DecodeStatus DecodeRR2Instruction(MCInst *Inst, unsigned Insn,
89
           uint64_t Address, void *Decoder);
90
91
static DecodeStatus DecodeRRPWInstruction(MCInst *Inst, unsigned Insn,
92
            uint64_t Address, void *Decoder);
93
94
static DecodeStatus DecodeSLRInstruction(MCInst *Inst, unsigned Insn,
95
           uint64_t Address, void *Decoder);
96
97
static DecodeStatus DecodeSLROInstruction(MCInst *Inst, unsigned Insn,
98
            uint64_t Address, void *Decoder);
99
100
static DecodeStatus DecodeSROInstruction(MCInst *Inst, unsigned Insn,
101
           uint64_t Address, void *Decoder);
102
103
static DecodeStatus DecodeSRRSInstruction(MCInst *Inst, unsigned Insn,
104
            uint64_t Address, void *Decoder);
105
106
static DecodeStatus DecodeSBCInstruction(MCInst *Inst, unsigned Insn,
107
           uint64_t Address, void *Decoder);
108
109
static DecodeStatus DecodeSBRNInstruction(MCInst *Inst, unsigned Insn,
110
            uint64_t Address, void *Decoder);
111
112
static DecodeStatus DecodeSSRInstruction(MCInst *Inst, unsigned Insn,
113
           uint64_t Address, void *Decoder);
114
115
static DecodeStatus DecodeSSROInstruction(MCInst *Inst, unsigned Insn,
116
            uint64_t Address, void *Decoder);
117
118
static DecodeStatus DecodeSYSInstruction(MCInst *Inst, unsigned Insn,
119
           uint64_t Address, void *Decoder);
120
121
static DecodeStatus DecodeRRR2Instruction(MCInst *Inst, unsigned Insn,
122
            uint64_t Address, void *Decoder);
123
124
static DecodeStatus DecodeRRR1Instruction(MCInst *Inst, unsigned Insn,
125
            uint64_t Address, void *Decoder);
126
127
static DecodeStatus DecodeBITInstruction(MCInst *Inst, unsigned Insn,
128
           uint64_t Address, void *Decoder);
129
130
static DecodeStatus DecodeRR1Instruction(MCInst *Inst, unsigned Insn,
131
           uint64_t Address, void *Decoder);
132
133
static DecodeStatus DecodeRCRInstruction(MCInst *Inst, unsigned Insn,
134
           uint64_t Address, void *Decoder);
135
136
static DecodeStatus DecodeRRRWInstruction(MCInst *Inst, unsigned Insn,
137
            uint64_t Address, void *Decoder);
138
139
static DecodeStatus DecodeRCRRInstruction(MCInst *Inst, unsigned Insn,
140
            uint64_t Address, void *Decoder);
141
142
static DecodeStatus DecodeRRRRInstruction(MCInst *Inst, unsigned Insn,
143
            uint64_t Address, void *Decoder);
144
145
static DecodeStatus DecodeBRRInstruction(MCInst *Inst, unsigned Insn,
146
           uint64_t Address, void *Decoder);
147
148
static DecodeStatus DecodeBRCInstruction(MCInst *Inst, unsigned Insn,
149
           uint64_t Address, void *Decoder);
150
151
static DecodeStatus DecodeRRRInstruction(MCInst *Inst, unsigned Insn,
152
           uint64_t Address, void *Decoder);
153
154
static DecodeStatus DecodeABSBInstruction(MCInst *Inst, unsigned Insn,
155
            uint64_t Address, void *Decoder);
156
157
static DecodeStatus DecodeRCRWInstruction(MCInst *Inst, unsigned Insn,
158
            uint64_t Address, void *Decoder);
159
160
static DecodeStatus DecodeBRNInstruction(MCInst *Inst, unsigned Insn,
161
           uint64_t Address, void *Decoder);
162
163
#define GET_SUBTARGETINFO_ENUM
164
165
#include "TriCoreGenSubtargetInfo.inc"
166
167
bool TriCore_getFeatureBits(unsigned int mode, unsigned int feature)
168
0
{
169
0
  switch (mode) {
170
0
  case CS_MODE_TRICORE_110: {
171
0
    return feature == TRICORE_HasV110Ops;
172
0
  }
173
0
  case CS_MODE_TRICORE_120: {
174
0
    return feature == TRICORE_HasV120Ops;
175
0
  }
176
0
  case CS_MODE_TRICORE_130: {
177
0
    return feature == TRICORE_HasV130Ops;
178
0
  }
179
0
  case CS_MODE_TRICORE_131: {
180
0
    return feature == TRICORE_HasV131Ops;
181
0
  }
182
0
  case CS_MODE_TRICORE_160: {
183
0
    return feature == TRICORE_HasV160Ops;
184
0
  }
185
0
  case CS_MODE_TRICORE_161: {
186
0
    return feature == TRICORE_HasV161Ops;
187
0
  }
188
0
  case CS_MODE_TRICORE_162: {
189
0
    return feature == TRICORE_HasV162Ops;
190
0
  }
191
0
  default:
192
0
    return false;
193
0
  }
194
0
}
195
196
#include "TriCoreGenDisassemblerTables.inc"
197
198
#define GET_REGINFO_ENUM
199
#define GET_REGINFO_MC_DESC
200
201
#include "TriCoreGenRegisterInfo.inc"
202
203
static DecodeStatus DecodeRegisterClass(MCInst *Inst, unsigned RegNo,
204
          const MCOperandInfo *MCOI,
205
          void *Decoder)
206
0
{
207
0
  unsigned Reg;
208
0
  unsigned RegHalfNo = RegNo / 2;
209
210
0
  if (!MCOI || MCOI->OperandType != MCOI_OPERAND_REGISTER) {
211
0
    return MCDisassembler_Fail;
212
0
  }
213
214
0
  if (RegHalfNo > 15)
215
0
    return MCDisassembler_Fail;
216
217
0
  if (MCOI->RegClass < 3) {
218
0
    Reg = getReg(Decoder, MCOI->RegClass, RegNo);
219
0
  } else {
220
0
    Reg = getReg(Decoder, MCOI->RegClass, RegHalfNo);
221
0
  }
222
223
0
  MCOperand_CreateReg0(Inst, Reg);
224
225
0
  return MCDisassembler_Success;
226
0
}
227
228
#define GET_INSTRINFO_ENUM
229
#define GET_INSTRINFO_MC_DESC
230
231
#include "TriCoreGenInstrInfo.inc"
232
233
static DecodeStatus DecodeSBInstruction(MCInst *Inst, unsigned Insn,
234
          uint64_t Address, void *Decoder)
235
0
{
236
0
  unsigned disp8 = fieldFromInstruction_2(Insn, 8, 8);
237
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
238
239
0
  if (is32Bit) // This instruction is 16-bit
240
0
    return MCDisassembler_Fail;
241
242
  // Decode disp8.
243
0
  MCOperand_CreateImm0(Inst, disp8);
244
245
0
  return MCDisassembler_Success;
246
0
}
247
248
static DecodeStatus DecodeSBRInstruction(MCInst *Inst, unsigned Insn,
249
           uint64_t Address, void *Decoder)
250
0
{
251
0
  DecodeStatus status;
252
0
  unsigned s2 = fieldFromInstruction_2(Insn, 12, 4);
253
0
  unsigned disp4 = fieldFromInstruction_2(Insn, 8, 4);
254
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
255
256
0
  if (is32Bit) // This instruction is 16-bit
257
0
    return MCDisassembler_Fail;
258
259
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
260
0
  status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[0], Decoder);
261
0
  if (status != MCDisassembler_Success)
262
0
    return status;
263
264
  // Decode disp4.
265
0
  MCOperand_CreateImm0(Inst, disp4);
266
267
0
  return MCDisassembler_Success;
268
0
}
269
270
static DecodeStatus DecodeSCInstruction(MCInst *Inst, unsigned Insn,
271
          uint64_t Address, void *Decoder)
272
0
{
273
0
  unsigned const8 = fieldFromInstruction_2(Insn, 8, 8);
274
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
275
276
0
  if (is32Bit) // This instruction is 16-bit
277
0
    return MCDisassembler_Fail;
278
279
  // Decode const8.
280
0
  MCOperand_CreateImm0(Inst, const8);
281
282
0
  return MCDisassembler_Success;
283
0
}
284
285
static DecodeStatus DecodeSRInstruction(MCInst *Inst, unsigned Insn,
286
          uint64_t Address, void *Decoder)
287
0
{
288
0
  DecodeStatus status;
289
0
  unsigned s1_d = fieldFromInstruction_2(Insn, 8, 4);
290
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
291
292
0
  if (is32Bit) // This instruction is 16-bit
293
0
    return MCDisassembler_Fail;
294
295
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
296
0
  if (desc->NumOperands > 0) {
297
0
    status = DecodeRegisterClass(Inst, s1_d, &desc->OpInfo[0],
298
0
               Decoder);
299
0
    if (status != MCDisassembler_Success)
300
0
      return status;
301
0
  }
302
303
0
  if (desc->NumOperands > 1) {
304
0
    status = DecodeRegisterClass(Inst, s1_d, &desc->OpInfo[1],
305
0
               Decoder);
306
0
    if (status != MCDisassembler_Success)
307
0
      return status;
308
0
  }
309
310
0
  return MCDisassembler_Success;
311
0
}
312
313
static DecodeStatus DecodeSRCInstruction(MCInst *Inst, unsigned Insn,
314
           uint64_t Address, void *Decoder)
315
0
{
316
0
  DecodeStatus status;
317
0
  unsigned const4 = fieldFromInstruction_2(Insn, 12, 4);
318
0
  unsigned s1_d = fieldFromInstruction_2(Insn, 8, 4);
319
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
320
321
0
  if (is32Bit) // This instruction is 16-bit
322
0
    return MCDisassembler_Fail;
323
324
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
325
326
  // Decode s1/d.
327
0
  status = DecodeRegisterClass(Inst, s1_d, &desc->OpInfo[0], Decoder);
328
0
  if (status != MCDisassembler_Success)
329
0
    return status;
330
331
  // Decode const4.
332
0
  MCOperand_CreateImm0(Inst, const4);
333
334
0
  return MCDisassembler_Success;
335
0
}
336
337
static DecodeStatus DecodeSRRInstruction(MCInst *Inst, unsigned Insn,
338
           uint64_t Address, void *Decoder)
339
0
{
340
0
  DecodeStatus status;
341
0
  unsigned s2 = fieldFromInstruction_2(Insn, 12, 4);
342
0
  unsigned s1_d = fieldFromInstruction_2(Insn, 8, 4);
343
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
344
345
0
  if (is32Bit) // This instruction is 16-bit
346
0
    return MCDisassembler_Fail;
347
348
  // Decode s1/d.
349
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
350
0
  status = DecodeRegisterClass(Inst, s1_d, &desc->OpInfo[0], Decoder);
351
0
  if (status != MCDisassembler_Success)
352
0
    return status;
353
354
  // Decode s2.
355
0
  status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[1], Decoder);
356
0
  if (status != MCDisassembler_Success)
357
0
    return status;
358
359
0
  return MCDisassembler_Success;
360
0
}
361
362
static DecodeStatus DecodeABSInstruction(MCInst *Inst, unsigned Insn,
363
           uint64_t Address, void *Decoder)
364
0
{
365
0
  DecodeStatus status;
366
0
  unsigned off18_0 = fieldFromInstruction_4(Insn, 16, 6);
367
0
  unsigned off18_1 = fieldFromInstruction_4(Insn, 28, 4);
368
0
  unsigned off18_2 = fieldFromInstruction_4(Insn, 22, 4);
369
0
  unsigned off18_3 = fieldFromInstruction_4(Insn, 12, 4);
370
0
  unsigned off18 = (off18_0 << 0) | (off18_1 << 6) | (off18_2 << 10) |
371
0
       (off18_3 << 14);
372
373
0
  unsigned s1_d = fieldFromInstruction_4(Insn, 8, 4);
374
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
375
376
0
  if (!is32Bit) // This instruction is 32-bit
377
0
    return MCDisassembler_Fail;
378
379
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
380
381
0
  if (desc->NumOperands > 1) {
382
0
    if (desc->OpInfo[0].OperandType == MCOI_OPERAND_REGISTER) {
383
0
      status = DecodeRegisterClass(Inst, s1_d,
384
0
                 &desc->OpInfo[0], Decoder);
385
0
      if (status != MCDisassembler_Success)
386
0
        return status;
387
388
0
      MCOperand_CreateImm0(Inst, off18);
389
0
    } else {
390
0
      MCOperand_CreateImm0(Inst, off18);
391
0
      status = DecodeRegisterClass(Inst, s1_d,
392
0
                 &desc->OpInfo[0], Decoder);
393
0
      if (status != MCDisassembler_Success)
394
0
        return status;
395
0
    }
396
0
  } else {
397
0
    MCOperand_CreateImm0(Inst, off18);
398
0
  }
399
400
0
  return MCDisassembler_Success;
401
0
}
402
403
static DecodeStatus DecodeBInstruction(MCInst *Inst, unsigned Insn,
404
               uint64_t Address, void *Decoder)
405
0
{
406
0
  unsigned disp24_0 = fieldFromInstruction_4(Insn, 16, 16);
407
0
  unsigned disp24_1 = fieldFromInstruction_4(Insn, 8, 8);
408
0
  unsigned disp24 = (disp24_0 << 0) | (disp24_1 << 16);
409
410
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
411
412
0
  if (!is32Bit) // This instruction is 32-bit
413
0
    return MCDisassembler_Fail;
414
415
  // Decode disp24.
416
0
  MCOperand_CreateImm0(Inst, disp24);
417
418
0
  return MCDisassembler_Success;
419
0
}
420
421
static DecodeStatus DecodeBOInstruction(MCInst *Inst, unsigned Insn,
422
          uint64_t Address, void *Decoder)
423
0
{
424
0
  DecodeStatus status;
425
0
  unsigned off10_0 = fieldFromInstruction_4(Insn, 16, 6);
426
0
  unsigned off10_1 = fieldFromInstruction_4(Insn, 28, 4);
427
0
  unsigned off10 = (off10_0 << 0) | (off10_1 << 6);
428
0
  bool is_store = false;
429
430
0
  unsigned s2 = fieldFromInstruction_4(Insn, 12, 4);
431
0
  unsigned s1_d = fieldFromInstruction_4(Insn, 8, 4);
432
433
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
434
435
0
  if (!is32Bit) // This instruction is 32-bit
436
0
    return MCDisassembler_Fail;
437
438
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
439
440
0
  if (desc->NumOperands == 1) {
441
0
    return DecodeRegisterClass(Inst, s2, &desc->OpInfo[0], Decoder);
442
0
  }
443
444
0
  switch (MCInst_getOpcode(Inst)) {
445
0
  case TRICORE_ST_A_bo_r:
446
0
  case TRICORE_ST_A_bo_c:
447
0
  case TRICORE_ST_B_bo_r:
448
0
  case TRICORE_ST_B_bo_c:
449
0
  case TRICORE_ST_D_bo_r:
450
0
  case TRICORE_ST_D_bo_c:
451
0
  case TRICORE_ST_DA_bo_r:
452
0
  case TRICORE_ST_DA_bo_c:
453
0
  case TRICORE_ST_H_bo_r:
454
0
  case TRICORE_ST_H_bo_c:
455
0
  case TRICORE_ST_Q_bo_r:
456
0
  case TRICORE_ST_Q_bo_c:
457
0
  case TRICORE_ST_W_bo_r:
458
0
  case TRICORE_ST_W_bo_c:
459
0
  case TRICORE_SWAP_W_bo_r:
460
0
  case TRICORE_SWAP_W_bo_c:
461
0
  case TRICORE_SWAPMSK_W_bo_c:
462
0
  case TRICORE_SWAPMSK_W_bo_r: {
463
0
    is_store = true;
464
0
    break;
465
0
  }
466
0
  }
467
468
0
  if (desc->NumOperands == 2) {
469
0
    if (desc->OpInfo[1].OperandType == MCOI_OPERAND_REGISTER) {
470
      // we have [reg+r] instruction
471
0
      if (is_store) {
472
0
        status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[0],
473
0
                   Decoder);
474
0
        if (status != MCDisassembler_Success)
475
0
          return status;
476
0
        return DecodeRegisterClass(Inst, s1_d, &desc->OpInfo[1],
477
0
                 Decoder);
478
0
      } else {
479
0
        status = DecodeRegisterClass(Inst, s1_d, &desc->OpInfo[0],
480
0
                   Decoder);
481
0
        if (status != MCDisassembler_Success)
482
0
          return status;
483
0
        return DecodeRegisterClass(Inst, s2, &desc->OpInfo[1],
484
0
                 Decoder);
485
0
      }
486
0
    } else {
487
      // we have one of the CACHE instructions without destination reg
488
0
      status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[0],
489
0
                 Decoder);
490
0
      if (status != MCDisassembler_Success)
491
0
        return status;
492
493
0
      MCOperand_CreateImm0(Inst, off10);
494
0
    }
495
0
    return MCDisassembler_Success;
496
0
  }
497
498
0
  if (desc->NumOperands > 2) {
499
0
    if (is_store) {
500
      // we have [reg+c] instruction
501
0
      status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[0],
502
0
                 Decoder);
503
0
      if (status != MCDisassembler_Success)
504
0
        return status;
505
506
0
      status = DecodeRegisterClass(Inst, s1_d, &desc->OpInfo[1],
507
0
                 Decoder);
508
0
      if (status != MCDisassembler_Success)
509
0
        return status;
510
0
    } else {
511
0
      status = DecodeRegisterClass(Inst, s1_d, &desc->OpInfo[0],
512
0
                 Decoder);
513
0
      if (status != MCDisassembler_Success)
514
0
        return status;
515
516
0
      status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[1],
517
0
                 Decoder);
518
0
      if (status != MCDisassembler_Success)
519
0
        return status;
520
0
    }
521
0
    MCOperand_CreateImm0(Inst, off10);
522
0
  }
523
524
0
  return MCDisassembler_Success;
525
0
}
526
527
static DecodeStatus DecodeBOLInstruction(MCInst *Inst, unsigned Insn,
528
           uint64_t Address, void *Decoder)
529
0
{
530
0
  DecodeStatus status;
531
0
  unsigned off16_0 = fieldFromInstruction_4(Insn, 16, 6);
532
0
  unsigned off16_1 = fieldFromInstruction_4(Insn, 22, 6);
533
0
  unsigned off16_2 = fieldFromInstruction_4(Insn, 28, 4);
534
0
  unsigned off16 = (off16_0 << 0) | (off16_1 << 10) | (off16_2 << 6);
535
536
0
  unsigned s2 = fieldFromInstruction_4(Insn, 12, 4);
537
0
  unsigned s1_d = fieldFromInstruction_4(Insn, 8, 4);
538
539
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
540
0
  if (!is32Bit) // This instruction is 32-bit
541
0
    return MCDisassembler_Fail;
542
543
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
544
545
0
  switch (MCInst_getOpcode(Inst)) {
546
0
  case TRICORE_LD_A_bol:
547
0
  case TRICORE_LD_B_bol:
548
0
  case TRICORE_LD_BU_bol:
549
0
  case TRICORE_LD_H_bol:
550
0
  case TRICORE_LD_HU_bol:
551
0
  case TRICORE_LD_W_bol:
552
0
  case TRICORE_LEA_bol: {
553
    // Decode s1_d.
554
0
    status = DecodeRegisterClass(Inst, s1_d, &desc->OpInfo[0],
555
0
               Decoder);
556
0
    if (status != MCDisassembler_Success)
557
0
      return status;
558
559
    // Decode s2.
560
0
    status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[1],
561
0
               Decoder);
562
0
    if (status != MCDisassembler_Success)
563
0
      return status;
564
0
    break;
565
0
  }
566
0
  case TRICORE_ST_A_bol:
567
0
  case TRICORE_ST_B_bol:
568
0
  case TRICORE_ST_H_bol:
569
0
  case TRICORE_ST_W_bol: {
570
    // Decode s2.
571
0
    status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[0],
572
0
               Decoder);
573
0
    if (status != MCDisassembler_Success)
574
0
      return status;
575
576
    // Decode s1_d.
577
0
    status = DecodeRegisterClass(Inst, s1_d, &desc->OpInfo[1],
578
0
               Decoder);
579
0
    if (status != MCDisassembler_Success)
580
0
      return status;
581
0
    break;
582
0
  }
583
0
  default:
584
0
    return MCDisassembler_Fail;
585
0
  }
586
587
  // Decode off16.
588
0
  MCOperand_CreateImm0(Inst, off16);
589
590
0
  return MCDisassembler_Success;
591
0
}
592
593
static DecodeStatus DecodeRCInstruction(MCInst *Inst, unsigned Insn,
594
          uint64_t Address, void *Decoder)
595
0
{
596
0
  DecodeStatus status;
597
0
  unsigned d = fieldFromInstruction_4(Insn, 28, 4);
598
0
  unsigned const9 = fieldFromInstruction_4(Insn, 12, 9);
599
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
600
601
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
602
603
0
  if (!is32Bit) // This instruction is 32-bit
604
0
    return MCDisassembler_Fail;
605
606
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
607
0
  if (desc->NumOperands > 1) {
608
    // Decode d.
609
0
    status =
610
0
      DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
611
0
    if (status != MCDisassembler_Success)
612
0
      return status;
613
614
    // Decode s1.
615
0
    status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[1],
616
0
               Decoder);
617
0
    if (status != MCDisassembler_Success)
618
0
      return status;
619
0
  }
620
621
  // Decode const9.
622
0
  MCOperand_CreateImm0(Inst, const9);
623
624
0
  return MCDisassembler_Success;
625
0
}
626
627
static DecodeStatus DecodeRCPWInstruction(MCInst *Inst, unsigned Insn,
628
            uint64_t Address, void *Decoder)
629
0
{
630
0
  DecodeStatus status;
631
0
  unsigned d = fieldFromInstruction_4(Insn, 28, 4);
632
0
  unsigned pos = fieldFromInstruction_4(Insn, 23, 5);
633
0
  unsigned width = fieldFromInstruction_4(Insn, 16, 5);
634
0
  unsigned const4 = fieldFromInstruction_4(Insn, 12, 4);
635
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
636
637
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
638
639
0
  if (!is32Bit) // This instruction is 32-bit
640
0
    return MCDisassembler_Fail;
641
642
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
643
  // Decode d.
644
0
  status = DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
645
0
  if (status != MCDisassembler_Success)
646
0
    return status;
647
648
  // Decode s1.
649
0
  status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[1], Decoder);
650
0
  if (status != MCDisassembler_Success)
651
0
    return status;
652
653
  // Decode const4.
654
0
  MCOperand_CreateImm0(Inst, const4);
655
656
  // Decode pos.
657
0
  MCOperand_CreateImm0(Inst, pos);
658
659
  // Decode width.
660
0
  MCOperand_CreateImm0(Inst, width);
661
662
0
  return MCDisassembler_Success;
663
0
}
664
665
static DecodeStatus DecodeRLCInstruction(MCInst *Inst, unsigned Insn,
666
           uint64_t Address, void *Decoder)
667
0
{
668
0
  DecodeStatus status;
669
0
  unsigned d = fieldFromInstruction_4(Insn, 28, 4);
670
0
  unsigned const16 = fieldFromInstruction_4(Insn, 12, 16);
671
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
672
673
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
674
675
0
  if (!is32Bit) // This instruction is 32-bit
676
0
    return MCDisassembler_Fail;
677
678
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
679
0
  if (desc->NumOperands == 3) {
680
0
    status =
681
0
      DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
682
0
    if (status != MCDisassembler_Success)
683
0
      return status;
684
685
0
    status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[1],
686
0
               Decoder);
687
0
    if (status != MCDisassembler_Success)
688
0
      return status;
689
690
0
    MCOperand_CreateImm0(Inst, const16);
691
692
0
    return MCDisassembler_Success;
693
0
  }
694
695
0
  if (desc->OpInfo[0].OperandType == MCOI_OPERAND_REGISTER) {
696
0
    status =
697
0
      DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
698
0
    if (status != MCDisassembler_Success)
699
0
      return status;
700
701
0
    MCOperand_CreateImm0(Inst, const16);
702
0
  } else {
703
0
    MCOperand_CreateImm0(Inst, const16);
704
0
    if (MCInst_getOpcode(Inst) == TRICORE_MTCR_rlc) {
705
0
      status =
706
0
        DecodeRegisterClass(Inst, s1, &desc->OpInfo[1], Decoder);
707
0
    } else {
708
0
      status =
709
0
        DecodeRegisterClass(Inst, d, &desc->OpInfo[1], Decoder);
710
0
    }
711
0
    if (status != MCDisassembler_Success)
712
0
      return status;
713
0
  }
714
0
  return MCDisassembler_Success;
715
0
}
716
717
static DecodeStatus DecodeRRInstruction(MCInst *Inst, unsigned Insn,
718
          uint64_t Address, void *Decoder)
719
0
{
720
0
  DecodeStatus status;
721
0
  unsigned d = fieldFromInstruction_4(Insn, 28, 4);
722
0
  unsigned n = fieldFromInstruction_4(Insn, 16, 2);
723
0
  unsigned s2 = fieldFromInstruction_4(Insn, 12, 4);
724
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
725
726
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
727
728
0
  if (!is32Bit) // This instruction is 32-bit
729
0
    return MCDisassembler_Fail;
730
731
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
732
  /// But even if the instruction is in RR format and has only one operand,
733
  /// we cannot be sure whether the operand is s1 or s2
734
0
  if (desc->NumOperands == 1) {
735
0
    if (desc->OpInfo[0].OperandType == MCOI_OPERAND_REGISTER) {
736
0
      switch (MCInst_getOpcode(Inst)) {
737
0
      case TRICORE_CALLI_rr_v110: {
738
0
        return DecodeRegisterClass(
739
0
          Inst, s2, &desc->OpInfo[0], Decoder);
740
0
      }
741
0
      default: {
742
0
        return DecodeRegisterClass(
743
0
          Inst, s1, &desc->OpInfo[0], Decoder);
744
0
      }
745
0
      }
746
0
    }
747
0
    return MCDisassembler_Fail;
748
0
  }
749
750
0
  if (desc->NumOperands > 0) {
751
    // Decode d.
752
0
    status =
753
0
      DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
754
0
    if (status != MCDisassembler_Success)
755
0
      return status;
756
0
  }
757
758
0
  if (desc->NumOperands > 1) {
759
0
    if (desc->OpInfo[0].OperandType == MCOI_OPERAND_REGISTER) {
760
0
      switch (MCInst_getOpcode(Inst)) {
761
0
      case TRICORE_ABSS_rr:
762
0
      case TRICORE_ABSS_H_rr:
763
0
      case TRICORE_ABS_H_rr:
764
0
      case TRICORE_ABS_B_rr:
765
0
      case TRICORE_ABS_rr: {
766
0
        status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[1],
767
0
                   Decoder);
768
0
        break;
769
0
      default:
770
0
        status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[1],
771
0
                   Decoder);
772
0
      }
773
0
      if (status != MCDisassembler_Success)
774
0
        return status;
775
0
      }
776
0
    }
777
0
  }
778
779
0
  if (desc->NumOperands > 2) {
780
0
    status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[2],
781
0
               Decoder);
782
0
    if (status != MCDisassembler_Success)
783
0
      return status;
784
0
  }
785
786
0
  if (desc->NumOperands > 3) {
787
0
    MCOperand_CreateImm0(Inst, n);
788
0
  }
789
790
0
  return MCDisassembler_Success;
791
0
}
792
793
static DecodeStatus DecodeRR2Instruction(MCInst *Inst, unsigned Insn,
794
           uint64_t Address, void *Decoder)
795
0
{
796
0
  DecodeStatus status;
797
0
  unsigned d = fieldFromInstruction_4(Insn, 28, 4);
798
0
  unsigned s2 = fieldFromInstruction_4(Insn, 12, 4);
799
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
800
801
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
802
803
0
  if (!is32Bit) // This instruction is 32-bit
804
0
    return MCDisassembler_Fail;
805
806
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
807
  // Decode d.
808
0
  status = DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
809
0
  if (status != MCDisassembler_Success)
810
0
    return status;
811
812
  // Decode s1.
813
0
  status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[1], Decoder);
814
0
  if (status != MCDisassembler_Success)
815
0
    return status;
816
817
  // Decode s2.
818
0
  status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[2], Decoder);
819
0
  if (status != MCDisassembler_Success)
820
0
    return status;
821
822
0
  return MCDisassembler_Success;
823
0
}
824
825
static DecodeStatus DecodeRRPWInstruction(MCInst *Inst, unsigned Insn,
826
            uint64_t Address, void *Decoder)
827
0
{
828
0
  DecodeStatus status;
829
0
  unsigned d = fieldFromInstruction_4(Insn, 28, 4);
830
0
  unsigned pos = fieldFromInstruction_4(Insn, 23, 5);
831
0
  unsigned width = fieldFromInstruction_4(Insn, 16, 5);
832
0
  unsigned s2 = fieldFromInstruction_4(Insn, 12, 4);
833
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
834
835
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
836
837
0
  if (!is32Bit) // This instruction is 32-bit
838
0
    return MCDisassembler_Fail;
839
840
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
841
0
  tryDecodeReg(0, d) tryDecodeReg(1, s1) tryDecodeReg(2, s2)
842
0
    decodeImm(pos) decodeImm(width)
843
844
0
      return MCDisassembler_Success;
845
0
}
846
847
static DecodeStatus DecodeSLRInstruction(MCInst *Inst, unsigned Insn,
848
           uint64_t Address, void *Decoder)
849
0
{
850
0
  DecodeStatus status = MCDisassembler_Fail;
851
0
  unsigned d = fieldFromInstruction_2(Insn, 8, 4);
852
0
  unsigned s2 = fieldFromInstruction_2(Insn, 12, 4);
853
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
854
0
  if (is32Bit) // This instruction is 16-bit
855
0
    return MCDisassembler_Fail;
856
857
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
858
  // Decode d.
859
0
  status = DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
860
0
  if (status != MCDisassembler_Success)
861
0
    return status;
862
863
  // Decode s2.
864
0
  status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[1], Decoder);
865
0
  if (status != MCDisassembler_Success)
866
0
    return status;
867
868
0
  return MCDisassembler_Success;
869
0
}
870
871
static DecodeStatus DecodeSLROInstruction(MCInst *Inst, unsigned Insn,
872
            uint64_t Address, void *Decoder)
873
0
{
874
0
  DecodeStatus status = MCDisassembler_Fail;
875
0
  unsigned d = fieldFromInstruction_2(Insn, 8, 4);
876
0
  unsigned off4 = fieldFromInstruction_2(Insn, 12, 4);
877
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
878
0
  if (is32Bit) // This instruction is 16-bit
879
0
    return MCDisassembler_Fail;
880
881
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
882
  // Decode d.
883
0
  status = DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
884
0
  if (status != MCDisassembler_Success)
885
0
    return status;
886
887
  // Decode off4.
888
0
  MCOperand_CreateImm0(Inst, off4);
889
890
0
  return MCDisassembler_Success;
891
0
}
892
893
static DecodeStatus DecodeSROInstruction(MCInst *Inst, unsigned Insn,
894
           uint64_t Address, void *Decoder)
895
0
{
896
0
  DecodeStatus status = MCDisassembler_Fail;
897
0
  unsigned off4 = fieldFromInstruction_2(Insn, 8, 4);
898
0
  unsigned s2 = fieldFromInstruction_2(Insn, 12, 4);
899
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
900
0
  if (is32Bit) // This instruction is 16-bit
901
0
    return MCDisassembler_Fail;
902
903
  // Decode s2.
904
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
905
0
  status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[0], Decoder);
906
0
  if (status != MCDisassembler_Success)
907
0
    return status;
908
909
  // Decode off4.
910
0
  MCOperand_CreateImm0(Inst, off4);
911
912
0
  return MCDisassembler_Success;
913
0
}
914
915
static DecodeStatus DecodeSRRSInstruction(MCInst *Inst, unsigned Insn,
916
            uint64_t Address, void *Decoder)
917
0
{
918
0
  DecodeStatus status = MCDisassembler_Fail;
919
0
  unsigned n = fieldFromInstruction_2(Insn, 6, 2);
920
0
  unsigned s1_d = fieldFromInstruction_2(Insn, 8, 4);
921
0
  unsigned s2 = fieldFromInstruction_2(Insn, 12, 4);
922
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
923
0
  if (is32Bit) // This instruction is 16-bit
924
0
    return MCDisassembler_Fail;
925
926
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
927
928
  // Decode s1_d.
929
0
  status = DecodeRegisterClass(Inst, s1_d, &desc->OpInfo[0], Decoder);
930
0
  if (status != MCDisassembler_Success)
931
0
    return status;
932
933
  // Decode s2.
934
0
  status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[1], Decoder);
935
0
  if (status != MCDisassembler_Success)
936
0
    return status;
937
938
  // Decode n.
939
0
  MCOperand_CreateImm0(Inst, n);
940
941
0
  return MCDisassembler_Success;
942
0
}
943
944
static DecodeStatus DecodeSBCInstruction(MCInst *Inst, unsigned Insn,
945
           uint64_t Address, void *Decoder)
946
0
{
947
0
  unsigned disp4 = fieldFromInstruction_2(Insn, 8, 4);
948
0
  unsigned const4 = fieldFromInstruction_2(Insn, 12, 4);
949
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
950
0
  if (is32Bit) // This instruction is 16-bit
951
0
    return MCDisassembler_Fail;
952
953
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
954
0
  if (desc->NumOperands != 2) {
955
0
    return MCDisassembler_Fail;
956
0
  }
957
958
  // Decode disp4.
959
0
  MCOperand_CreateImm0(Inst, disp4);
960
961
  // Decode const4.
962
0
  MCOperand_CreateImm0(Inst, const4);
963
964
0
  return MCDisassembler_Success;
965
0
}
966
967
static DecodeStatus DecodeSBRNInstruction(MCInst *Inst, unsigned Insn,
968
            uint64_t Address, void *Decoder)
969
0
{
970
0
  unsigned disp4 = fieldFromInstruction_2(Insn, 8, 4);
971
0
  unsigned n = fieldFromInstruction_2(Insn, 12, 4);
972
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
973
0
  if (is32Bit) // This instruction is 16-bit
974
0
    return MCDisassembler_Fail;
975
976
  // Decode n.
977
0
  MCOperand_CreateImm0(Inst, n);
978
  // Decode disp4.
979
0
  MCOperand_CreateImm0(Inst, disp4);
980
981
0
  return MCDisassembler_Success;
982
0
}
983
984
static DecodeStatus DecodeSSRInstruction(MCInst *Inst, unsigned Insn,
985
           uint64_t Address, void *Decoder)
986
0
{
987
0
  DecodeStatus status = MCDisassembler_Fail;
988
0
  unsigned s1 = fieldFromInstruction_2(Insn, 8, 4);
989
0
  unsigned s2 = fieldFromInstruction_2(Insn, 12, 4);
990
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
991
0
  if (is32Bit) // This instruction is 16-bit
992
0
    return MCDisassembler_Fail;
993
994
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
995
996
  // Decode s2.
997
0
  status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[0], Decoder);
998
0
  if (status != MCDisassembler_Success)
999
0
    return status;
1000
1001
  // Decode s1.
1002
0
  status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[1], Decoder);
1003
0
  if (status != MCDisassembler_Success)
1004
0
    return status;
1005
1006
0
  return MCDisassembler_Success;
1007
0
}
1008
1009
static DecodeStatus DecodeSSROInstruction(MCInst *Inst, unsigned Insn,
1010
            uint64_t Address, void *Decoder)
1011
0
{
1012
0
  DecodeStatus status = MCDisassembler_Fail;
1013
0
  unsigned s1 = fieldFromInstruction_2(Insn, 8, 4);
1014
0
  unsigned off4 = fieldFromInstruction_2(Insn, 12, 4);
1015
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
1016
0
  if (is32Bit) // This instruction is 16-bit
1017
0
    return MCDisassembler_Fail;
1018
1019
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
1020
0
  status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[0], Decoder);
1021
0
  if (status != MCDisassembler_Success)
1022
0
    return status;
1023
1024
  // Decode off4.
1025
0
  MCOperand_CreateImm0(Inst, off4);
1026
1027
0
  return MCDisassembler_Success;
1028
0
}
1029
1030
/// 32-bit Opcode Format
1031
1032
static DecodeStatus DecodeSYSInstruction(MCInst *Inst, unsigned Insn,
1033
           uint64_t Address, void *Decoder)
1034
0
{
1035
0
  DecodeStatus status = MCDisassembler_Fail;
1036
0
  unsigned s1_d = fieldFromInstruction_4(Insn, 8, 4);
1037
1038
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
1039
0
  if (!is32Bit) // This instruction is 32-bit
1040
0
    return MCDisassembler_Fail;
1041
1042
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
1043
0
  if (desc->NumOperands > 0) {
1044
0
    status = DecodeRegisterClass(Inst, s1_d, &desc->OpInfo[0],
1045
0
               Decoder);
1046
0
    if (status != MCDisassembler_Success)
1047
0
      return status;
1048
0
  }
1049
1050
0
  return MCDisassembler_Success;
1051
0
}
1052
1053
static DecodeStatus DecodeRRR2Instruction(MCInst *Inst, unsigned Insn,
1054
            uint64_t Address, void *Decoder)
1055
0
{
1056
0
  DecodeStatus status = MCDisassembler_Fail;
1057
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
1058
0
  unsigned s2 = fieldFromInstruction_4(Insn, 12, 4);
1059
0
  unsigned s3 = fieldFromInstruction_4(Insn, 24, 4);
1060
0
  unsigned d = fieldFromInstruction_4(Insn, 28, 4);
1061
1062
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
1063
0
  if (!is32Bit) // This instruction is 32-bit
1064
0
    return MCDisassembler_Fail;
1065
1066
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
1067
0
  status = DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
1068
0
  if (status != MCDisassembler_Success)
1069
0
    return status;
1070
1071
  // Decode s1.
1072
0
  status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[1], Decoder);
1073
0
  if (status != MCDisassembler_Success)
1074
0
    return status;
1075
1076
  // Decode s2.
1077
0
  status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[2], Decoder);
1078
0
  if (status != MCDisassembler_Success)
1079
0
    return status;
1080
1081
  // Decode s3.
1082
0
  status = DecodeRegisterClass(Inst, s3, &desc->OpInfo[3], Decoder);
1083
0
  if (status != MCDisassembler_Success)
1084
0
    return status;
1085
1086
0
  return MCDisassembler_Success;
1087
0
}
1088
1089
static DecodeStatus DecodeRRR1Instruction(MCInst *Inst, unsigned Insn,
1090
            uint64_t Address, void *Decoder)
1091
0
{
1092
0
  DecodeStatus status = MCDisassembler_Fail;
1093
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
1094
0
  unsigned s2 = fieldFromInstruction_4(Insn, 12, 4);
1095
0
  unsigned n = fieldFromInstruction_4(Insn, 16, 2);
1096
0
  unsigned s3 = fieldFromInstruction_4(Insn, 24, 4);
1097
0
  unsigned d = fieldFromInstruction_4(Insn, 28, 4);
1098
1099
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
1100
0
  if (!is32Bit) // This instruction is 32-bit
1101
0
    return MCDisassembler_Fail;
1102
1103
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
1104
0
  status = DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
1105
0
  if (status != MCDisassembler_Success)
1106
0
    return status;
1107
1108
  // Decode s1.
1109
0
  status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[1], Decoder);
1110
0
  if (status != MCDisassembler_Success)
1111
0
    return status;
1112
1113
  // Decode s2.
1114
0
  status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[2], Decoder);
1115
0
  if (status != MCDisassembler_Success)
1116
0
    return status;
1117
1118
  // Decode s3.
1119
0
  status = DecodeRegisterClass(Inst, s3, &desc->OpInfo[3], Decoder);
1120
0
  if (status != MCDisassembler_Success)
1121
0
    return status;
1122
1123
  // Decode n.
1124
0
  MCOperand_CreateImm0(Inst, n);
1125
1126
0
  return MCDisassembler_Success;
1127
0
}
1128
1129
static DecodeStatus DecodeBITInstruction(MCInst *Inst, unsigned Insn,
1130
           uint64_t Address, void *Decoder)
1131
0
{
1132
0
  DecodeStatus status = MCDisassembler_Fail;
1133
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
1134
0
  unsigned s2 = fieldFromInstruction_4(Insn, 12, 4);
1135
0
  unsigned pos1 = fieldFromInstruction_4(Insn, 16, 5);
1136
0
  unsigned pos2 = fieldFromInstruction_4(Insn, 23, 5);
1137
0
  unsigned d = fieldFromInstruction_4(Insn, 28, 4);
1138
1139
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
1140
0
  if (!is32Bit) // This instruction is 32-bit
1141
0
    return MCDisassembler_Fail;
1142
1143
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
1144
0
  status = DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
1145
0
  if (status != MCDisassembler_Success)
1146
0
    return status;
1147
1148
  // Decode s1.
1149
0
  status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[1], Decoder);
1150
0
  if (status != MCDisassembler_Success)
1151
0
    return status;
1152
1153
  // Decode s2.
1154
0
  status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[2], Decoder);
1155
0
  if (status != MCDisassembler_Success)
1156
0
    return status;
1157
1158
  // Decode pos1.
1159
0
  MCOperand_CreateImm0(Inst, pos1);
1160
1161
  // Decode pos2.
1162
0
  MCOperand_CreateImm0(Inst, pos2);
1163
1164
0
  return MCDisassembler_Success;
1165
0
}
1166
1167
static DecodeStatus DecodeRR1Instruction(MCInst *Inst, unsigned Insn,
1168
           uint64_t Address, void *Decoder)
1169
0
{
1170
0
  DecodeStatus status = MCDisassembler_Fail;
1171
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
1172
0
  unsigned s2 = fieldFromInstruction_4(Insn, 12, 4);
1173
0
  unsigned n = fieldFromInstruction_4(Insn, 16, 2);
1174
0
  unsigned d = fieldFromInstruction_4(Insn, 28, 4);
1175
1176
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
1177
0
  if (!is32Bit) // This instruction is 32-bit
1178
0
    return MCDisassembler_Fail;
1179
1180
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
1181
0
  status = DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
1182
0
  if (status != MCDisassembler_Success)
1183
0
    return status;
1184
1185
  // Decode s1.
1186
0
  status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[1], Decoder);
1187
0
  if (status != MCDisassembler_Success)
1188
0
    return status;
1189
1190
  // Decode s2.
1191
0
  status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[2], Decoder);
1192
0
  if (status != MCDisassembler_Success)
1193
0
    return status;
1194
1195
  // Decode n.
1196
0
  MCOperand_CreateImm0(Inst, n);
1197
1198
0
  return MCDisassembler_Success;
1199
0
}
1200
1201
static DecodeStatus DecodeRCRInstruction(MCInst *Inst, unsigned Insn,
1202
           uint64_t Address, void *Decoder)
1203
0
{
1204
0
  DecodeStatus status = MCDisassembler_Fail;
1205
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
1206
0
  unsigned const9 = fieldFromInstruction_4(Insn, 12, 9);
1207
0
  unsigned s3 = fieldFromInstruction_4(Insn, 24, 4);
1208
0
  unsigned d = fieldFromInstruction_4(Insn, 28, 4);
1209
1210
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
1211
0
  if (!is32Bit) // This instruction is 32-bit
1212
0
    return MCDisassembler_Fail;
1213
1214
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
1215
0
  status = DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
1216
0
  if (status != MCDisassembler_Success)
1217
0
    return status;
1218
1219
  // Decode s1.
1220
0
  status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[1], Decoder);
1221
0
  if (status != MCDisassembler_Success)
1222
0
    return status;
1223
1224
  // Decode s3.
1225
0
  status = DecodeRegisterClass(Inst, s3, &desc->OpInfo[2], Decoder);
1226
0
  if (status != MCDisassembler_Success)
1227
0
    return status;
1228
1229
  // Decode const9.
1230
0
  MCOperand_CreateImm0(Inst, const9);
1231
1232
0
  return MCDisassembler_Success;
1233
0
}
1234
1235
static DecodeStatus DecodeRRRWInstruction(MCInst *Inst, unsigned Insn,
1236
            uint64_t Address, void *Decoder)
1237
0
{
1238
0
  DecodeStatus status = MCDisassembler_Fail;
1239
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
1240
0
  unsigned s2 = fieldFromInstruction_4(Insn, 12, 4);
1241
0
  unsigned width = fieldFromInstruction_4(Insn, 16, 5);
1242
0
  unsigned s3 = fieldFromInstruction_4(Insn, 24, 4);
1243
0
  unsigned d = fieldFromInstruction_4(Insn, 28, 4);
1244
1245
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
1246
0
  if (!is32Bit) // This instruction is 32-bit
1247
0
    return MCDisassembler_Fail;
1248
1249
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
1250
0
  status = DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
1251
0
  if (status != MCDisassembler_Success)
1252
0
    return status;
1253
1254
  // Decode s1.
1255
0
  status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[1], Decoder);
1256
0
  if (status != MCDisassembler_Success)
1257
0
    return status;
1258
1259
  // Decode s2.
1260
0
  status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[2], Decoder);
1261
0
  if (status != MCDisassembler_Success)
1262
0
    return status;
1263
1264
  // Decode s3.
1265
0
  status = DecodeRegisterClass(Inst, s3, &desc->OpInfo[3], Decoder);
1266
0
  if (status != MCDisassembler_Success)
1267
0
    return status;
1268
1269
  // Decode width.
1270
0
  MCOperand_CreateImm0(Inst, width);
1271
1272
0
  return MCDisassembler_Success;
1273
0
}
1274
1275
static DecodeStatus DecodeRCRRInstruction(MCInst *Inst, unsigned Insn,
1276
            uint64_t Address, void *Decoder)
1277
0
{
1278
0
  DecodeStatus status = MCDisassembler_Fail;
1279
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
1280
0
  unsigned const4 = fieldFromInstruction_4(Insn, 12, 4);
1281
0
  unsigned s3 = fieldFromInstruction_4(Insn, 24, 4);
1282
0
  unsigned d = fieldFromInstruction_4(Insn, 28, 4);
1283
1284
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
1285
0
  if (!is32Bit) // This instruction is 32-bit
1286
0
    return MCDisassembler_Fail;
1287
1288
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
1289
0
  status = DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
1290
0
  if (status != MCDisassembler_Success)
1291
0
    return status;
1292
1293
  // Decode s1.
1294
0
  status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[1], Decoder);
1295
0
  if (status != MCDisassembler_Success)
1296
0
    return status;
1297
1298
  // Decode const4.
1299
0
  MCOperand_CreateImm0(Inst, const4);
1300
1301
  // Decode s3.
1302
0
  status = DecodeRegisterClass(Inst, s3, &desc->OpInfo[3], Decoder);
1303
0
  if (status != MCDisassembler_Success)
1304
0
    return status;
1305
1306
0
  return MCDisassembler_Success;
1307
0
}
1308
1309
static DecodeStatus DecodeRRRRInstruction(MCInst *Inst, unsigned Insn,
1310
            uint64_t Address, void *Decoder)
1311
0
{
1312
0
  DecodeStatus status = MCDisassembler_Fail;
1313
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
1314
0
  unsigned s2 = fieldFromInstruction_4(Insn, 12, 4);
1315
0
  unsigned s3 = fieldFromInstruction_4(Insn, 24, 4);
1316
0
  unsigned d = fieldFromInstruction_4(Insn, 28, 4);
1317
1318
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
1319
0
  if (!is32Bit) // This instruction is 32-bit
1320
0
    return MCDisassembler_Fail;
1321
1322
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
1323
0
  status = DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
1324
0
  if (status != MCDisassembler_Success)
1325
0
    return status;
1326
1327
  // Decode s1.
1328
0
  status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[1], Decoder);
1329
0
  if (status != MCDisassembler_Success)
1330
0
    return status;
1331
1332
0
  if (desc->NumOperands == 3) {
1333
0
    switch (MCInst_getOpcode(Inst)) {
1334
0
    case TRICORE_EXTR_rrrr:
1335
0
    case TRICORE_EXTR_U_rrrr:
1336
0
      return DecodeRegisterClass(Inst, s3, &desc->OpInfo[2], Decoder);
1337
0
    default:
1338
0
      return DecodeRegisterClass(Inst, s2, &desc->OpInfo[2], Decoder);
1339
0
    }
1340
0
  }
1341
1342
  // Decode s2.
1343
0
  status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[2], Decoder);
1344
0
  if (status != MCDisassembler_Success)
1345
0
    return status;
1346
  // Decode s3.
1347
0
  status = DecodeRegisterClass(Inst, s3, &desc->OpInfo[3], Decoder);
1348
0
  if (status != MCDisassembler_Success)
1349
0
    return status;
1350
1351
0
  return MCDisassembler_Success;
1352
0
}
1353
1354
static DecodeStatus DecodeBRRInstruction(MCInst *Inst, unsigned Insn,
1355
           uint64_t Address, void *Decoder)
1356
0
{
1357
0
  DecodeStatus status = MCDisassembler_Fail;
1358
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
1359
0
  unsigned s2 = fieldFromInstruction_4(Insn, 12, 4);
1360
0
  unsigned disp15 = fieldFromInstruction_4(Insn, 16, 15);
1361
1362
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
1363
0
  if (!is32Bit) // This instruction is 32-bit
1364
0
    return MCDisassembler_Fail;
1365
1366
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
1367
0
  if (MCInst_getOpcode(Inst) == TRICORE_LOOP_brr) {
1368
0
    status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[0],
1369
0
               Decoder);
1370
0
    if (status != MCDisassembler_Success)
1371
0
      return status;
1372
1373
0
    MCOperand_CreateImm0(Inst, disp15);
1374
0
    return MCDisassembler_Success;
1375
0
  }
1376
1377
0
  if (desc->NumOperands >= 2) {
1378
0
    status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[0],
1379
0
               Decoder);
1380
0
    if (status != MCDisassembler_Success)
1381
0
      return status;
1382
1383
0
    if (desc->NumOperands >= 3) {
1384
0
      status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[1],
1385
0
                 Decoder);
1386
0
      if (status != MCDisassembler_Success)
1387
0
        return status;
1388
0
    }
1389
0
  }
1390
1391
  // Decode disp15.
1392
0
  MCOperand_CreateImm0(Inst, disp15);
1393
1394
0
  return MCDisassembler_Success;
1395
0
}
1396
1397
static DecodeStatus DecodeBRCInstruction(MCInst *Inst, unsigned Insn,
1398
           uint64_t Address, void *Decoder)
1399
0
{
1400
0
  DecodeStatus status = MCDisassembler_Fail;
1401
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
1402
0
  unsigned const4 = fieldFromInstruction_4(Insn, 12, 4);
1403
0
  unsigned disp15 = fieldFromInstruction_4(Insn, 16, 15);
1404
1405
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
1406
0
  if (!is32Bit) // This instruction is 32-bit
1407
0
    return MCDisassembler_Fail;
1408
1409
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
1410
0
  status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[0], Decoder);
1411
0
  if (status != MCDisassembler_Success)
1412
0
    return status;
1413
1414
  // Decode const4.
1415
0
  MCOperand_CreateImm0(Inst, const4);
1416
1417
  // Decode disp15.
1418
0
  MCOperand_CreateImm0(Inst, disp15);
1419
1420
0
  return MCDisassembler_Success;
1421
0
}
1422
1423
static DecodeStatus DecodeRRRInstruction(MCInst *Inst, unsigned Insn,
1424
           uint64_t Address, void *Decoder)
1425
0
{
1426
0
  DecodeStatus status = MCDisassembler_Fail;
1427
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
1428
0
  unsigned s2 = fieldFromInstruction_4(Insn, 12, 4);
1429
  //  unsigned n = fieldFromInstruction_4(Insn, 16, 2);
1430
0
  unsigned s3 = fieldFromInstruction_4(Insn, 24, 4);
1431
0
  unsigned d = fieldFromInstruction_4(Insn, 28, 4);
1432
1433
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
1434
0
  if (!is32Bit) // This instruction is 32-bit
1435
0
    return MCDisassembler_Fail;
1436
1437
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
1438
0
  status = DecodeRegisterClass(Inst, d, &desc->OpInfo[0], Decoder);
1439
0
  if (status != MCDisassembler_Success)
1440
0
    return status;
1441
1442
  // Decode s1.
1443
0
  status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[1], Decoder);
1444
0
  if (status != MCDisassembler_Success)
1445
0
    return status;
1446
1447
  // Decode s2.
1448
0
  status = DecodeRegisterClass(Inst, s2, &desc->OpInfo[2], Decoder);
1449
0
  if (status != MCDisassembler_Success)
1450
0
    return status;
1451
1452
  // Decode s3.
1453
0
  status = DecodeRegisterClass(Inst, s3, &desc->OpInfo[3], Decoder);
1454
0
  if (status != MCDisassembler_Success)
1455
0
    return status;
1456
1457
0
  return MCDisassembler_Success;
1458
0
}
1459
1460
static DecodeStatus DecodeABSBInstruction(MCInst *Inst, unsigned Insn,
1461
            uint64_t Address, void *Decoder)
1462
0
{
1463
0
  unsigned bpos3 = fieldFromInstruction_4(Insn, 8, 3);
1464
0
  unsigned b = fieldFromInstruction_4(Insn, 12, 1);
1465
1466
0
  unsigned off18_0_5 = fieldFromInstruction_4(Insn, 16, 6);
1467
0
  unsigned off18_6_9 = fieldFromInstruction_4(Insn, 28, 4);
1468
0
  unsigned off18_10_13 = fieldFromInstruction_4(Insn, 22, 4);
1469
0
  unsigned off18_14_17 = fieldFromInstruction_4(Insn, 12, 4);
1470
0
  unsigned off18 = (off18_0_5 << 0) | (off18_6_9 << 6) |
1471
0
       (off18_10_13 << 10) | (off18_14_17 << 14);
1472
1473
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
1474
0
  if (!is32Bit) // This instruction is 32-bit
1475
0
    return MCDisassembler_Fail;
1476
1477
0
  decodeImm(off18) decodeImm(bpos3) decodeImm(b)
1478
1479
0
    return MCDisassembler_Success;
1480
0
}
1481
1482
static DecodeStatus DecodeRCRWInstruction(MCInst *Inst, unsigned Insn,
1483
            uint64_t Address, void *Decoder)
1484
0
{
1485
0
  DecodeStatus status = MCDisassembler_Fail;
1486
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
1487
0
  unsigned const4 = fieldFromInstruction_4(Insn, 12, 4);
1488
0
  unsigned width = fieldFromInstruction_4(Insn, 16, 5);
1489
0
  unsigned s3 = fieldFromInstruction_4(Insn, 24, 4);
1490
0
  unsigned d = fieldFromInstruction_4(Insn, 28, 4);
1491
1492
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
1493
0
  if (!is32Bit) // This instruction is 32-bit
1494
0
    return MCDisassembler_Fail;
1495
1496
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
1497
0
  tryDecodeReg(0, d) tryDecodeReg(1, s1) tryDecodeReg(2, s3)
1498
0
    decodeImm(const4) decodeImm(width)
1499
1500
0
      return MCDisassembler_Success;
1501
0
}
1502
1503
static DecodeStatus DecodeBRNInstruction(MCInst *Inst, unsigned Insn,
1504
           uint64_t Address, void *Decoder)
1505
0
{
1506
0
  DecodeStatus status = MCDisassembler_Fail;
1507
0
  unsigned s1 = fieldFromInstruction_4(Insn, 8, 4);
1508
1509
0
  unsigned n_0_3 = fieldFromInstruction_4(Insn, 12, 4);
1510
0
  unsigned n_4 = fieldFromInstruction_4(Insn, 7, 1);
1511
0
  unsigned n = (n_0_3 << 0) | (n_4 << 4);
1512
1513
0
  unsigned disp15 = fieldFromInstruction_4(Insn, 16, 15);
1514
1515
0
  unsigned is32Bit = fieldFromInstruction_4(Insn, 0, 1);
1516
0
  if (!is32Bit) // This instruction is 32-bit
1517
0
    return MCDisassembler_Fail;
1518
1519
0
  const MCInstrDesc *desc = &TriCoreInsts[MCInst_getOpcode(Inst)];
1520
0
  status = DecodeRegisterClass(Inst, s1, &desc->OpInfo[0], Decoder);
1521
0
  if (status != MCDisassembler_Success)
1522
0
    return status;
1523
1524
  // Decode n.
1525
0
  MCOperand_CreateImm0(Inst, n);
1526
1527
  // Decode disp15.
1528
0
  MCOperand_CreateImm0(Inst, disp15);
1529
1530
0
  return MCDisassembler_Success;
1531
0
}
1532
1533
#define GET_SUBTARGETINFO_ENUM
1534
1535
#include "TriCoreGenInstrInfo.inc"
1536
1537
static inline bool tryGetInstruction16(const uint8_t *code, size_t code_len,
1538
               MCInst *MI, uint16_t *size,
1539
               uint64_t address, void *info,
1540
               const uint8_t *decoderTable16)
1541
0
{
1542
0
  if (code_len < 2) {
1543
0
    return false;
1544
0
  }
1545
0
  uint16_t insn16 = readBytes16(MI, code);
1546
0
  DecodeStatus Result = decodeInstruction_2(decoderTable16, MI, insn16,
1547
0
              address, info, 0);
1548
0
  if (Result != MCDisassembler_Fail) {
1549
0
    *size = 2;
1550
0
    return true;
1551
0
  }
1552
0
  return false;
1553
0
}
1554
1555
static inline bool tryGetInstruction32(const uint8_t *code, size_t code_len,
1556
               MCInst *MI, uint16_t *size,
1557
               uint64_t address, void *info,
1558
               const uint8_t *decoderTable32)
1559
0
{
1560
0
  if (code_len < 4) {
1561
0
    return false;
1562
0
  }
1563
0
  uint32_t insn32 = readBytes32(MI, code);
1564
0
  DecodeStatus Result = decodeInstruction_4(decoderTable32, MI, insn32,
1565
0
              address, info, 0);
1566
0
  if (Result != MCDisassembler_Fail) {
1567
0
    *size = 4;
1568
0
    return true;
1569
0
  }
1570
0
  return false;
1571
0
}
1572
1573
static bool getInstruction(csh ud, const uint8_t *code, size_t code_len,
1574
         MCInst *MI, uint16_t *size, uint64_t address,
1575
         void *info)
1576
0
{
1577
0
  if (!ud) {
1578
0
    return false;
1579
0
  }
1580
1581
0
  struct cs_struct *cs = (struct cs_struct *)ud;
1582
0
  if (MI->flat_insn->detail) {
1583
0
    memset(MI->flat_insn->detail, 0, sizeof(cs_detail));
1584
0
  }
1585
1586
0
  switch (cs->mode) {
1587
0
  case CS_MODE_TRICORE_110: {
1588
0
    if (tryGetInstruction16(code, code_len, MI, size, address, info,
1589
0
          DecoderTablev11016) ||
1590
0
        tryGetInstruction32(code, code_len, MI, size, address, info,
1591
0
          DecoderTablev11032)) {
1592
0
      return true;
1593
0
    }
1594
0
    break;
1595
0
  }
1596
0
  case CS_MODE_TRICORE_161: {
1597
0
    if (tryGetInstruction32(code, code_len, MI, size, address, info,
1598
0
          DecoderTablev16132)) {
1599
0
      return true;
1600
0
    }
1601
0
    break;
1602
0
  }
1603
0
  case CS_MODE_TRICORE_162: {
1604
0
    if (tryGetInstruction16(code, code_len, MI, size, address, info,
1605
0
          DecoderTablev16216) ||
1606
0
        tryGetInstruction32(code, code_len, MI, size, address, info,
1607
0
          DecoderTablev16232)) {
1608
0
      return true;
1609
0
    }
1610
0
    break;
1611
0
  }
1612
0
  default:
1613
0
    break;
1614
0
  }
1615
1616
0
  return tryGetInstruction16(code, code_len, MI, size, address, info,
1617
0
           DecoderTable16) ||
1618
0
         tryGetInstruction32(code, code_len, MI, size, address, info,
1619
0
           DecoderTable32);
1620
0
}
1621
1622
bool TriCore_LLVM_getInstruction(csh handle, const uint8_t *Bytes,
1623
         size_t ByteLen, MCInst *MI, uint16_t *Size,
1624
         uint64_t Address, void *Info)
1625
0
{
1626
0
  bool Result =
1627
0
    getInstruction(handle, Bytes, ByteLen, MI, Size, Address, Info);
1628
0
  if (Result) {
1629
0
    TriCore_set_instr_map_data(MI);
1630
0
  }
1631
0
  return Result;
1632
0
}
1633
1634
void TriCore_init_mri(MCRegisterInfo *MRI)
1635
0
{
1636
  /*
1637
  InitMCRegisterInfo(TriCoreRegDesc, 45, RA, PC,
1638
      TriCoreMCRegisterClasses, 4,
1639
      TriCoreRegUnitRoots,
1640
      16,
1641
      TriCoreRegDiffLists,
1642
      TriCoreRegStrings,
1643
      TriCoreSubRegIdxLists,
1644
      1,
1645
      TriCoreSubRegIdxRanges,
1646
      TriCoreRegEncodingTable);
1647
  */
1648
1649
0
  MCRegisterInfo_InitMCRegisterInfo(
1650
0
    MRI, TriCoreRegDesc, ARR_SIZE(TriCoreRegDesc), 0, 0,
1651
0
    TriCoreMCRegisterClasses, ARR_SIZE(TriCoreMCRegisterClasses), 0,
1652
0
    0, TriCoreRegDiffLists, 0, TriCoreSubRegIdxLists, 1, 0);
1653
0
}
1654
1655
#endif