Coverage Report

Created: 2026-08-14 06:51

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/capstonenext/arch/TMS320C64x/TMS320C64xDisassembler.c
Line
Count
Source
1
/* Capstone Disassembly Engine */
2
/* TMS320C64x Backend by Fotis Loukos <me@fotisl.com> 2016 */
3
4
#ifdef CAPSTONE_HAS_TMS320C64X
5
6
#include <string.h>
7
8
#include "../../cs_priv.h"
9
#include "../../utils.h"
10
11
#include "TMS320C64xDisassembler.h"
12
13
#include "../../MCInst.h"
14
#include "../../MCInstrDesc.h"
15
#include "../../MCFixedLenDisassembler.h"
16
#include "../../MCRegisterInfo.h"
17
#include "../../MCDisassembler.h"
18
#include "../../MathExtras.h"
19
20
static uint64_t getFeatureBits(int mode);
21
22
static DecodeStatus DecodeGPRegsRegisterClass(MCInst *Inst, unsigned RegNo,
23
                uint64_t Address, void *Decoder);
24
25
static DecodeStatus DecodeControlRegsRegisterClass(MCInst *Inst, unsigned RegNo,
26
               uint64_t Address,
27
               void *Decoder);
28
29
static DecodeStatus DecodeScst5(MCInst *Inst, unsigned Val, uint64_t Address,
30
        void *Decoder);
31
32
static DecodeStatus DecodeScst16(MCInst *Inst, unsigned Val, uint64_t Address,
33
         void *Decoder);
34
35
static DecodeStatus DecodePCRelScst7(MCInst *Inst, unsigned Val,
36
             uint64_t Address, void *Decoder);
37
38
static DecodeStatus DecodePCRelScst10(MCInst *Inst, unsigned Val,
39
              uint64_t Address, void *Decoder);
40
41
static DecodeStatus DecodePCRelScst12(MCInst *Inst, unsigned Val,
42
              uint64_t Address, void *Decoder);
43
44
static DecodeStatus DecodePCRelScst21(MCInst *Inst, unsigned Val,
45
              uint64_t Address, void *Decoder);
46
47
static DecodeStatus DecodeMemOperand(MCInst *Inst, unsigned Val,
48
             uint64_t Address, void *Decoder);
49
50
static DecodeStatus DecodeMemOperandSc(MCInst *Inst, unsigned Val,
51
               uint64_t Address, void *Decoder);
52
53
static DecodeStatus DecodeMemOperand2(MCInst *Inst, unsigned Val,
54
              uint64_t Address, void *Decoder);
55
56
static DecodeStatus DecodeRegPair5(MCInst *Inst, unsigned RegNo,
57
           uint64_t Address, void *Decoder);
58
59
static DecodeStatus DecodeRegPair4(MCInst *Inst, unsigned RegNo,
60
           uint64_t Address, void *Decoder);
61
62
static DecodeStatus DecodeCondRegister(MCInst *Inst, unsigned Val,
63
               uint64_t Address, void *Decoder);
64
65
static DecodeStatus DecodeCondRegisterZero(MCInst *Inst, unsigned Val,
66
             uint64_t Address, void *Decoder);
67
68
static DecodeStatus DecodeSide(MCInst *Inst, unsigned Val, uint64_t Address,
69
             void *Decoder);
70
71
static DecodeStatus DecodeParallel(MCInst *Inst, unsigned Val, uint64_t Address,
72
           void *Decoder);
73
74
static DecodeStatus DecodeCrosspathX1(MCInst *Inst, unsigned Val,
75
              uint64_t Address, void *Decoder);
76
77
static DecodeStatus DecodeCrosspathX2(MCInst *Inst, unsigned Val,
78
              uint64_t Address, void *Decoder);
79
80
static DecodeStatus DecodeCrosspathX3(MCInst *Inst, unsigned Val,
81
              uint64_t Address, void *Decoder);
82
83
static DecodeStatus DecodeNop(MCInst *Inst, unsigned Val, uint64_t Address,
84
            void *Decoder);
85
86
#include "TMS320C64xGenDisassemblerTables.inc"
87
88
#define GET_REGINFO_ENUM
89
#define GET_REGINFO_MC_DESC
90
#include "TMS320C64xGenRegisterInfo.inc"
91
92
static const unsigned GPRegsDecoderTable[] = {
93
  TMS320C64x_A0,  TMS320C64x_A1,  TMS320C64x_A2,  TMS320C64x_A3,
94
  TMS320C64x_A4,  TMS320C64x_A5,  TMS320C64x_A6,  TMS320C64x_A7,
95
  TMS320C64x_A8,  TMS320C64x_A9,  TMS320C64x_A10, TMS320C64x_A11,
96
  TMS320C64x_A12, TMS320C64x_A13, TMS320C64x_A14, TMS320C64x_A15,
97
  TMS320C64x_A16, TMS320C64x_A17, TMS320C64x_A18, TMS320C64x_A19,
98
  TMS320C64x_A20, TMS320C64x_A21, TMS320C64x_A22, TMS320C64x_A23,
99
  TMS320C64x_A24, TMS320C64x_A25, TMS320C64x_A26, TMS320C64x_A27,
100
  TMS320C64x_A28, TMS320C64x_A29, TMS320C64x_A30, TMS320C64x_A31
101
};
102
103
static const unsigned ControlRegsDecoderTable[] = { TMS320C64x_AMR,
104
                TMS320C64x_CSR,
105
                TMS320C64x_ISR,
106
                TMS320C64x_ICR,
107
                TMS320C64x_IER,
108
                TMS320C64x_ISTP,
109
                TMS320C64x_IRP,
110
                TMS320C64x_NRP,
111
                ~0U,
112
                ~0U,
113
                TMS320C64x_TSCL,
114
                TMS320C64x_TSCH,
115
                ~0U,
116
                TMS320C64x_ILC,
117
                TMS320C64x_RILC,
118
                TMS320C64x_REP,
119
                TMS320C64x_PCE1,
120
                TMS320C64x_DNUM,
121
                ~0U,
122
                ~0U,
123
                ~0U,
124
                TMS320C64x_SSR,
125
                TMS320C64x_GPLYA,
126
                TMS320C64x_GPLYB,
127
                TMS320C64x_GFPGFR,
128
                TMS320C64x_DIER,
129
                TMS320C64x_TSR,
130
                TMS320C64x_ITSR,
131
                TMS320C64x_NTSR,
132
                TMS320C64x_ECR,
133
                ~0U,
134
                TMS320C64x_IERR };
135
136
static uint64_t getFeatureBits(int mode)
137
34.1k
{
138
  // support everything
139
34.1k
  return (uint64_t)-1;
140
34.1k
}
141
142
static unsigned getReg(const unsigned *RegTable, unsigned RegNo)
143
60.2k
{
144
60.2k
  if (RegNo > 31)
145
44
    return ~0U;
146
60.2k
  return RegTable[RegNo];
147
60.2k
}
148
149
static DecodeStatus DecodeGPRegsRegisterClass(MCInst *Inst, unsigned RegNo,
150
                uint64_t Address, void *Decoder)
151
44.1k
{
152
44.1k
  unsigned Reg;
153
154
44.1k
  if (RegNo > 31)
155
0
    return MCDisassembler_Fail;
156
157
44.1k
  Reg = getReg(GPRegsDecoderTable, RegNo);
158
44.1k
  if (Reg == ~0U)
159
0
    return MCDisassembler_Fail;
160
44.1k
  MCOperand_CreateReg0(Inst, Reg);
161
162
44.1k
  return MCDisassembler_Success;
163
44.1k
}
164
165
static DecodeStatus DecodeControlRegsRegisterClass(MCInst *Inst, unsigned RegNo,
166
               uint64_t Address,
167
               void *Decoder)
168
343
{
169
343
  unsigned Reg;
170
171
343
  if (RegNo > 31)
172
0
    return MCDisassembler_Fail;
173
174
343
  Reg = getReg(ControlRegsDecoderTable, RegNo);
175
343
  if (Reg == ~0U)
176
2
    return MCDisassembler_Fail;
177
341
  MCOperand_CreateReg0(Inst, Reg);
178
179
341
  return MCDisassembler_Success;
180
343
}
181
182
static DecodeStatus DecodeScst5(MCInst *Inst, unsigned Val, uint64_t Address,
183
        void *Decoder)
184
5.42k
{
185
5.42k
  int32_t imm;
186
187
5.42k
  imm = Val;
188
  /* Sign extend 5 bit value */
189
5.42k
  if (imm & (1 << (5 - 1)))
190
2.27k
    imm |= ~((1 << 5) - 1);
191
192
5.42k
  MCOperand_CreateImm0(Inst, imm);
193
194
5.42k
  return MCDisassembler_Success;
195
5.42k
}
196
197
static DecodeStatus DecodeScst16(MCInst *Inst, unsigned Val, uint64_t Address,
198
         void *Decoder)
199
2.59k
{
200
2.59k
  int32_t imm;
201
202
2.59k
  imm = Val;
203
  /* Sign extend 16 bit value */
204
2.59k
  if (imm & (1 << (16 - 1)))
205
1.02k
    imm |= ~((1 << 16) - 1);
206
207
2.59k
  MCOperand_CreateImm0(Inst, imm);
208
209
2.59k
  return MCDisassembler_Success;
210
2.59k
}
211
212
static DecodeStatus DecodePCRelScst7(MCInst *Inst, unsigned Val,
213
             uint64_t Address, void *Decoder)
214
227
{
215
227
  int32_t imm;
216
217
227
  imm = Val;
218
  /* Sign extend 7 bit value */
219
227
  if (imm & (1 << (7 - 1)))
220
141
    imm |= ~((1 << 7) - 1);
221
222
  /* Address is relative to the address of the first instruction in the fetch packet */
223
227
  MCOperand_CreateImm0(Inst, (Address & ~31) + (imm * 4));
224
225
227
  return MCDisassembler_Success;
226
227
}
227
228
static DecodeStatus DecodePCRelScst10(MCInst *Inst, unsigned Val,
229
              uint64_t Address, void *Decoder)
230
1.35k
{
231
1.35k
  int32_t imm;
232
233
1.35k
  imm = Val;
234
  /* Sign extend 10 bit value */
235
1.35k
  if (imm & (1 << (10 - 1)))
236
137
    imm |= ~((1 << 10) - 1);
237
238
  /* Address is relative to the address of the first instruction in the fetch packet */
239
1.35k
  MCOperand_CreateImm0(Inst, (Address & ~31) + (imm * 4));
240
241
1.35k
  return MCDisassembler_Success;
242
1.35k
}
243
244
static DecodeStatus DecodePCRelScst12(MCInst *Inst, unsigned Val,
245
              uint64_t Address, void *Decoder)
246
210
{
247
210
  int32_t imm;
248
249
210
  imm = Val;
250
  /* Sign extend 12 bit value */
251
210
  if (imm & (1 << (12 - 1)))
252
74
    imm |= ~((1 << 12) - 1);
253
254
  /* Address is relative to the address of the first instruction in the fetch packet */
255
210
  MCOperand_CreateImm0(Inst, (Address & ~31) + (imm * 4));
256
257
210
  return MCDisassembler_Success;
258
210
}
259
260
static DecodeStatus DecodePCRelScst21(MCInst *Inst, unsigned Val,
261
              uint64_t Address, void *Decoder)
262
1.19k
{
263
1.19k
  int32_t imm;
264
265
1.19k
  imm = Val;
266
  /* Sign extend 21 bit value */
267
1.19k
  if (imm & (1 << (21 - 1)))
268
492
    imm |= ~((1 << 21) - 1);
269
270
  /* Address is relative to the address of the first instruction in the fetch packet */
271
1.19k
  MCOperand_CreateImm0(Inst, (Address & ~31) + (imm * 4));
272
273
1.19k
  return MCDisassembler_Success;
274
1.19k
}
275
276
static DecodeStatus DecodeMemOperand(MCInst *Inst, unsigned Val,
277
             uint64_t Address, void *Decoder)
278
2.54k
{
279
2.54k
  return DecodeMemOperandSc(Inst, Val | (1 << 15), Address, Decoder);
280
2.54k
}
281
282
static DecodeStatus DecodeMemOperandSc(MCInst *Inst, unsigned Val,
283
               uint64_t Address, void *Decoder)
284
4.01k
{
285
4.01k
  uint8_t scaled, base, offset, mode, unit;
286
4.01k
  unsigned basereg, offsetreg;
287
288
4.01k
  scaled = (Val >> 15) & 1;
289
4.01k
  base = (Val >> 10) & 0x1f;
290
4.01k
  offset = (Val >> 5) & 0x1f;
291
4.01k
  mode = (Val >> 1) & 0xf;
292
4.01k
  unit = Val & 1;
293
294
4.01k
  if ((base >= TMS320C64X_REG_A0) && (base <= TMS320C64X_REG_A31))
295
33
    base = (base - TMS320C64X_REG_A0 + TMS320C64X_REG_B0);
296
  // base cannot be a B register, because it was ANDed above with 0x1f.
297
  // And the TMS320C64X_REG_B0 > 31
298
4.01k
  basereg = getReg(GPRegsDecoderTable, base);
299
4.01k
  if (basereg == ~0U)
300
33
    return MCDisassembler_Fail;
301
302
3.98k
  switch (mode) {
303
426
  case 0:
304
785
  case 1:
305
1.00k
  case 8:
306
1.18k
  case 9:
307
1.43k
  case 10:
308
1.90k
  case 11:
309
1.90k
    MCOperand_CreateImm0(Inst, (scaled << 19) | (basereg << 12) |
310
1.90k
               (offset << 5) | (mode << 1) |
311
1.90k
               unit);
312
1.90k
    break;
313
147
  case 4:
314
306
  case 5:
315
765
  case 12:
316
956
  case 13:
317
1.81k
  case 14:
318
2.05k
  case 15:
319
2.05k
    if ((offset >= TMS320C64X_REG_A0) &&
320
11
        (offset <= TMS320C64X_REG_A31))
321
11
      offset = (offset - TMS320C64X_REG_A0 +
322
11
          TMS320C64X_REG_B0);
323
    // offset cannot be a B register, because it was ANDed above with 0x1f.
324
    // And the TMS320C64X_REG_B0 > 31
325
2.05k
    offsetreg = getReg(GPRegsDecoderTable, offset);
326
2.05k
    if (offsetreg == ~0U)
327
11
      return MCDisassembler_Fail;
328
2.04k
    MCOperand_CreateImm0(Inst, (scaled << 19) | (basereg << 12) |
329
2.04k
               (offsetreg << 5) |
330
2.04k
               (mode << 1) | unit);
331
2.04k
    break;
332
24
  default:
333
24
    return MCDisassembler_Fail;
334
3.98k
  }
335
336
3.94k
  return MCDisassembler_Success;
337
3.98k
}
338
339
static DecodeStatus DecodeMemOperand2(MCInst *Inst, unsigned Val,
340
              uint64_t Address, void *Decoder)
341
5.44k
{
342
5.44k
  uint16_t offset;
343
5.44k
  unsigned basereg;
344
345
5.44k
  if (Val & 1)
346
1.87k
    basereg = TMS320C64X_REG_B15;
347
3.57k
  else
348
3.57k
    basereg = TMS320C64X_REG_B14;
349
350
5.44k
  offset = (Val >> 1) & 0x7fff;
351
5.44k
  MCOperand_CreateImm0(Inst, (offset << 7) | basereg);
352
353
5.44k
  return MCDisassembler_Success;
354
5.44k
}
355
356
static DecodeStatus DecodeRegPair5(MCInst *Inst, unsigned RegNo,
357
           uint64_t Address, void *Decoder)
358
8.18k
{
359
8.18k
  unsigned Reg;
360
361
8.18k
  if (RegNo > 31)
362
0
    return MCDisassembler_Fail;
363
364
8.18k
  Reg = getReg(GPRegsDecoderTable, RegNo);
365
8.18k
  MCOperand_CreateReg0(Inst, Reg);
366
367
8.18k
  return MCDisassembler_Success;
368
8.18k
}
369
370
static DecodeStatus DecodeRegPair4(MCInst *Inst, unsigned RegNo,
371
           uint64_t Address, void *Decoder)
372
1.47k
{
373
1.47k
  unsigned Reg;
374
375
1.47k
  if (RegNo > 15)
376
0
    return MCDisassembler_Fail;
377
378
1.47k
  Reg = getReg(GPRegsDecoderTable, RegNo << 1);
379
1.47k
  MCOperand_CreateReg0(Inst, Reg);
380
381
1.47k
  return MCDisassembler_Success;
382
1.47k
}
383
384
static DecodeStatus DecodeCondRegister(MCInst *Inst, unsigned Val,
385
               uint64_t Address, void *Decoder)
386
33.8k
{
387
33.8k
  DecodeStatus ret = MCDisassembler_Success;
388
389
33.8k
  if (!Inst->flat_insn->detail)
390
0
    return MCDisassembler_Success;
391
392
33.8k
  switch (Val) {
393
7.76k
  case 0:
394
11.3k
  case 7:
395
11.3k
    Inst->flat_insn->detail->tms320c64x.condition.reg =
396
11.3k
      TMS320C64X_REG_INVALID;
397
11.3k
    break;
398
5.20k
  case 1:
399
5.20k
    Inst->flat_insn->detail->tms320c64x.condition.reg =
400
5.20k
      TMS320C64X_REG_B0;
401
5.20k
    break;
402
4.60k
  case 2:
403
4.60k
    Inst->flat_insn->detail->tms320c64x.condition.reg =
404
4.60k
      TMS320C64X_REG_B1;
405
4.60k
    break;
406
2.79k
  case 3:
407
2.79k
    Inst->flat_insn->detail->tms320c64x.condition.reg =
408
2.79k
      TMS320C64X_REG_B2;
409
2.79k
    break;
410
3.09k
  case 4:
411
3.09k
    Inst->flat_insn->detail->tms320c64x.condition.reg =
412
3.09k
      TMS320C64X_REG_A1;
413
3.09k
    break;
414
4.71k
  case 5:
415
4.71k
    Inst->flat_insn->detail->tms320c64x.condition.reg =
416
4.71k
      TMS320C64X_REG_A2;
417
4.71k
    break;
418
2.11k
  case 6:
419
2.11k
    Inst->flat_insn->detail->tms320c64x.condition.reg =
420
2.11k
      TMS320C64X_REG_A0;
421
2.11k
    break;
422
0
  default:
423
0
    Inst->flat_insn->detail->tms320c64x.condition.reg =
424
0
      TMS320C64X_REG_INVALID;
425
0
    ret = MCDisassembler_Fail;
426
0
    break;
427
33.8k
  }
428
429
33.8k
  return ret;
430
33.8k
}
431
432
static DecodeStatus DecodeCondRegisterZero(MCInst *Inst, unsigned Val,
433
             uint64_t Address, void *Decoder)
434
33.8k
{
435
33.8k
  DecodeStatus ret = MCDisassembler_Success;
436
437
33.8k
  if (!Inst->flat_insn->detail)
438
0
    return MCDisassembler_Success;
439
440
33.8k
  switch (Val) {
441
15.6k
  case 0:
442
15.6k
    Inst->flat_insn->detail->tms320c64x.condition.zero = 0;
443
15.6k
    break;
444
18.2k
  case 1:
445
18.2k
    Inst->flat_insn->detail->tms320c64x.condition.zero = 1;
446
18.2k
    break;
447
0
  default:
448
0
    Inst->flat_insn->detail->tms320c64x.condition.zero = 0;
449
0
    ret = MCDisassembler_Fail;
450
0
    break;
451
33.8k
  }
452
453
33.8k
  return ret;
454
33.8k
}
455
456
static DecodeStatus DecodeSide(MCInst *Inst, unsigned Val, uint64_t Address,
457
             void *Decoder)
458
33.8k
{
459
33.8k
  DecodeStatus ret = MCDisassembler_Success;
460
33.8k
  MCOperand *op;
461
33.8k
  int i;
462
463
  /* This is pretty messy, probably we should find a better way */
464
33.8k
  if (Val == 1) {
465
38.3k
    for (i = 0; i < Inst->size; i++) {
466
27.2k
      op = &Inst->Operands[i];
467
27.2k
      if (op->Kind == kRegister) {
468
18.2k
        if ((op->RegVal >= TMS320C64X_REG_A0) &&
469
18.0k
            (op->RegVal <= TMS320C64X_REG_A31))
470
16.3k
          op->RegVal = (op->RegVal -
471
16.3k
                  TMS320C64X_REG_A0 +
472
16.3k
                  TMS320C64X_REG_B0);
473
1.94k
        else if ((op->RegVal >= TMS320C64X_REG_B0) &&
474
1.72k
           (op->RegVal <= TMS320C64X_REG_B31))
475
1.70k
          op->RegVal = (op->RegVal -
476
1.70k
                  TMS320C64X_REG_B0 +
477
1.70k
                  TMS320C64X_REG_A0);
478
18.2k
      }
479
27.2k
    }
480
11.1k
  }
481
482
33.8k
  if (!Inst->flat_insn->detail)
483
0
    return MCDisassembler_Success;
484
485
33.8k
  switch (Val) {
486
22.7k
  case 0:
487
22.7k
    Inst->flat_insn->detail->tms320c64x.funit.side = 1;
488
22.7k
    break;
489
11.1k
  case 1:
490
11.1k
    Inst->flat_insn->detail->tms320c64x.funit.side = 2;
491
11.1k
    break;
492
0
  default:
493
0
    Inst->flat_insn->detail->tms320c64x.funit.side = 0;
494
0
    ret = MCDisassembler_Fail;
495
0
    break;
496
33.8k
  }
497
498
33.8k
  return ret;
499
33.8k
}
500
501
static DecodeStatus DecodeParallel(MCInst *Inst, unsigned Val, uint64_t Address,
502
           void *Decoder)
503
33.8k
{
504
33.8k
  DecodeStatus ret = MCDisassembler_Success;
505
506
33.8k
  if (!Inst->flat_insn->detail)
507
0
    return MCDisassembler_Success;
508
509
33.8k
  switch (Val) {
510
17.4k
  case 0:
511
17.4k
    Inst->flat_insn->detail->tms320c64x.parallel = 0;
512
17.4k
    break;
513
16.3k
  case 1:
514
16.3k
    Inst->flat_insn->detail->tms320c64x.parallel = 1;
515
16.3k
    break;
516
0
  default:
517
0
    Inst->flat_insn->detail->tms320c64x.parallel = -1;
518
0
    ret = MCDisassembler_Fail;
519
0
    break;
520
33.8k
  }
521
522
33.8k
  return ret;
523
33.8k
}
524
525
static DecodeStatus DecodeCrosspathX1(MCInst *Inst, unsigned Val,
526
              uint64_t Address, void *Decoder)
527
698
{
528
698
  DecodeStatus ret = MCDisassembler_Success;
529
698
  MCOperand *op;
530
531
698
  if (!Inst->flat_insn->detail)
532
0
    return MCDisassembler_Success;
533
534
698
  switch (Val) {
535
151
  case 0:
536
151
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = 0;
537
151
    break;
538
547
  case 1:
539
547
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = 1;
540
547
    op = &Inst->Operands[0];
541
547
    if (op->Kind == kRegister) {
542
547
      if ((op->RegVal >= TMS320C64X_REG_A0) &&
543
547
          (op->RegVal <= TMS320C64X_REG_A31))
544
547
        op->RegVal = (op->RegVal - TMS320C64X_REG_A0 +
545
547
                TMS320C64X_REG_B0);
546
0
      else if ((op->RegVal >= TMS320C64X_REG_B0) &&
547
0
         (op->RegVal <= TMS320C64X_REG_B31))
548
0
        op->RegVal = (op->RegVal - TMS320C64X_REG_B0 +
549
0
                TMS320C64X_REG_A0);
550
547
    }
551
547
    break;
552
0
  default:
553
0
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = -1;
554
0
    ret = MCDisassembler_Fail;
555
0
    break;
556
698
  }
557
558
698
  return ret;
559
698
}
560
561
static DecodeStatus DecodeCrosspathX2(MCInst *Inst, unsigned Val,
562
              uint64_t Address, void *Decoder)
563
9.52k
{
564
9.52k
  DecodeStatus ret = MCDisassembler_Success;
565
9.52k
  MCOperand *op;
566
567
9.52k
  if (!Inst->flat_insn->detail)
568
0
    return MCDisassembler_Success;
569
570
9.52k
  switch (Val) {
571
4.88k
  case 0:
572
4.88k
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = 0;
573
4.88k
    break;
574
4.63k
  case 1:
575
4.63k
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = 1;
576
4.63k
    op = &Inst->Operands[1];
577
4.63k
    if (op->Kind == kRegister) {
578
4.35k
      if ((op->RegVal >= TMS320C64X_REG_A0) &&
579
4.18k
          (op->RegVal <= TMS320C64X_REG_A31))
580
4.16k
        op->RegVal = (op->RegVal - TMS320C64X_REG_A0 +
581
4.16k
                TMS320C64X_REG_B0);
582
196
      else if ((op->RegVal >= TMS320C64X_REG_B0) &&
583
24
         (op->RegVal <= TMS320C64X_REG_B31))
584
0
        op->RegVal = (op->RegVal - TMS320C64X_REG_B0 +
585
0
                TMS320C64X_REG_A0);
586
4.35k
    }
587
4.63k
    break;
588
0
  default:
589
0
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = -1;
590
0
    ret = MCDisassembler_Fail;
591
0
    break;
592
9.52k
  }
593
594
9.52k
  return ret;
595
9.52k
}
596
597
static DecodeStatus DecodeCrosspathX3(MCInst *Inst, unsigned Val,
598
              uint64_t Address, void *Decoder)
599
5.29k
{
600
5.29k
  DecodeStatus ret = MCDisassembler_Success;
601
5.29k
  MCOperand *op;
602
603
5.29k
  if (!Inst->flat_insn->detail)
604
0
    return MCDisassembler_Success;
605
606
5.29k
  switch (Val) {
607
2.01k
  case 0:
608
2.01k
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = 0;
609
2.01k
    break;
610
3.28k
  case 1:
611
3.28k
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = 2;
612
3.28k
    op = &Inst->Operands[2];
613
3.28k
    if (op->Kind == kRegister) {
614
970
      if ((op->RegVal >= TMS320C64X_REG_A0) &&
615
970
          (op->RegVal <= TMS320C64X_REG_A31))
616
970
        op->RegVal = (op->RegVal - TMS320C64X_REG_A0 +
617
970
                TMS320C64X_REG_B0);
618
0
      else if ((op->RegVal >= TMS320C64X_REG_B0) &&
619
0
         (op->RegVal <= TMS320C64X_REG_B31))
620
0
        op->RegVal = (op->RegVal - TMS320C64X_REG_B0 +
621
0
                TMS320C64X_REG_A0);
622
970
    }
623
3.28k
    break;
624
0
  default:
625
0
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = -1;
626
0
    ret = MCDisassembler_Fail;
627
0
    break;
628
5.29k
  }
629
630
5.29k
  return ret;
631
5.29k
}
632
633
static DecodeStatus DecodeNop(MCInst *Inst, unsigned Val, uint64_t Address,
634
            void *Decoder)
635
960
{
636
960
  MCOperand_CreateImm0(Inst, Val + 1);
637
638
960
  return MCDisassembler_Success;
639
960
}
640
641
#define GET_INSTRINFO_ENUM
642
#include "TMS320C64xGenInstrInfo.inc"
643
644
bool TMS320C64x_getInstruction(csh ud, const uint8_t *code, size_t code_len,
645
             MCInst *MI, uint16_t *size, uint64_t address,
646
             void *info)
647
34.4k
{
648
34.4k
  uint32_t insn;
649
34.4k
  DecodeStatus result;
650
651
34.4k
  if (code_len < 4) {
652
345
    *size = 0;
653
345
    return MCDisassembler_Fail;
654
345
  }
655
656
34.1k
  if (MI->flat_insn->detail)
657
34.1k
    memset(MI->flat_insn->detail, 0,
658
34.1k
           offsetof(cs_detail, tms320c64x) + sizeof(cs_tms320c64x));
659
660
34.1k
  insn = readBytes32(MI, code);
661
34.1k
  result =
662
34.1k
    decodeInstruction_4(DecoderTable32, MI, insn, address, info, 0);
663
664
34.1k
  if (result == MCDisassembler_Success) {
665
33.8k
    *size = 4;
666
33.8k
    return true;
667
33.8k
  }
668
669
265
  MCInst_clear(MI);
670
265
  *size = 0;
671
265
  return false;
672
34.1k
}
673
674
void TMS320C64x_init(MCRegisterInfo *MRI)
675
792
{
676
792
  MCRegisterInfo_InitMCRegisterInfo(MRI, TMS320C64xRegDesc, 90, 0, 0,
677
792
            TMS320C64xMCRegisterClasses, 7, 0, 0,
678
792
            TMS320C64xRegDiffLists, 0,
679
792
            TMS320C64xSubRegIdxLists, 1, 0);
680
792
}
681
682
#endif