Coverage Report

Created: 2026-03-03 06:14

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
11.6k
{
138
  // support everything
139
11.6k
  return (uint64_t)-1;
140
11.6k
}
141
142
static unsigned getReg(const unsigned *RegTable, unsigned RegNo)
143
21.5k
{
144
21.5k
  if (RegNo > 31)
145
19
    return ~0U;
146
21.5k
  return RegTable[RegNo];
147
21.5k
}
148
149
static DecodeStatus DecodeGPRegsRegisterClass(MCInst *Inst, unsigned RegNo,
150
                uint64_t Address, void *Decoder)
151
16.2k
{
152
16.2k
  unsigned Reg;
153
154
16.2k
  if (RegNo > 31)
155
0
    return MCDisassembler_Fail;
156
157
16.2k
  Reg = getReg(GPRegsDecoderTable, RegNo);
158
16.2k
  if (Reg == ~0U)
159
0
    return MCDisassembler_Fail;
160
16.2k
  MCOperand_CreateReg0(Inst, Reg);
161
162
16.2k
  return MCDisassembler_Success;
163
16.2k
}
164
165
static DecodeStatus DecodeControlRegsRegisterClass(MCInst *Inst, unsigned RegNo,
166
               uint64_t Address,
167
               void *Decoder)
168
983
{
169
983
  unsigned Reg;
170
171
983
  if (RegNo > 31)
172
0
    return MCDisassembler_Fail;
173
174
983
  Reg = getReg(ControlRegsDecoderTable, RegNo);
175
983
  if (Reg == ~0U)
176
1
    return MCDisassembler_Fail;
177
982
  MCOperand_CreateReg0(Inst, Reg);
178
179
982
  return MCDisassembler_Success;
180
983
}
181
182
static DecodeStatus DecodeScst5(MCInst *Inst, unsigned Val, uint64_t Address,
183
        void *Decoder)
184
1.61k
{
185
1.61k
  int32_t imm;
186
187
1.61k
  imm = Val;
188
  /* Sign extend 5 bit value */
189
1.61k
  if (imm & (1 << (5 - 1)))
190
844
    imm |= ~((1 << 5) - 1);
191
192
1.61k
  MCOperand_CreateImm0(Inst, imm);
193
194
1.61k
  return MCDisassembler_Success;
195
1.61k
}
196
197
static DecodeStatus DecodeScst16(MCInst *Inst, unsigned Val, uint64_t Address,
198
         void *Decoder)
199
568
{
200
568
  int32_t imm;
201
202
568
  imm = Val;
203
  /* Sign extend 16 bit value */
204
568
  if (imm & (1 << (16 - 1)))
205
367
    imm |= ~((1 << 16) - 1);
206
207
568
  MCOperand_CreateImm0(Inst, imm);
208
209
568
  return MCDisassembler_Success;
210
568
}
211
212
static DecodeStatus DecodePCRelScst7(MCInst *Inst, unsigned Val,
213
             uint64_t Address, void *Decoder)
214
160
{
215
160
  int32_t imm;
216
217
160
  imm = Val;
218
  /* Sign extend 7 bit value */
219
160
  if (imm & (1 << (7 - 1)))
220
144
    imm |= ~((1 << 7) - 1);
221
222
  /* Address is relative to the address of the first instruction in the fetch packet */
223
160
  MCOperand_CreateImm0(Inst, (Address & ~31) + (imm * 4));
224
225
160
  return MCDisassembler_Success;
226
160
}
227
228
static DecodeStatus DecodePCRelScst10(MCInst *Inst, unsigned Val,
229
              uint64_t Address, void *Decoder)
230
137
{
231
137
  int32_t imm;
232
233
137
  imm = Val;
234
  /* Sign extend 10 bit value */
235
137
  if (imm & (1 << (10 - 1)))
236
40
    imm |= ~((1 << 10) - 1);
237
238
  /* Address is relative to the address of the first instruction in the fetch packet */
239
137
  MCOperand_CreateImm0(Inst, (Address & ~31) + (imm * 4));
240
241
137
  return MCDisassembler_Success;
242
137
}
243
244
static DecodeStatus DecodePCRelScst12(MCInst *Inst, unsigned Val,
245
              uint64_t Address, void *Decoder)
246
70
{
247
70
  int32_t imm;
248
249
70
  imm = Val;
250
  /* Sign extend 12 bit value */
251
70
  if (imm & (1 << (12 - 1)))
252
22
    imm |= ~((1 << 12) - 1);
253
254
  /* Address is relative to the address of the first instruction in the fetch packet */
255
70
  MCOperand_CreateImm0(Inst, (Address & ~31) + (imm * 4));
256
257
70
  return MCDisassembler_Success;
258
70
}
259
260
static DecodeStatus DecodePCRelScst21(MCInst *Inst, unsigned Val,
261
              uint64_t Address, void *Decoder)
262
545
{
263
545
  int32_t imm;
264
265
545
  imm = Val;
266
  /* Sign extend 21 bit value */
267
545
  if (imm & (1 << (21 - 1)))
268
51
    imm |= ~((1 << 21) - 1);
269
270
  /* Address is relative to the address of the first instruction in the fetch packet */
271
545
  MCOperand_CreateImm0(Inst, (Address & ~31) + (imm * 4));
272
273
545
  return MCDisassembler_Success;
274
545
}
275
276
static DecodeStatus DecodeMemOperand(MCInst *Inst, unsigned Val,
277
             uint64_t Address, void *Decoder)
278
1.23k
{
279
1.23k
  return DecodeMemOperandSc(Inst, Val | (1 << 15), Address, Decoder);
280
1.23k
}
281
282
static DecodeStatus DecodeMemOperandSc(MCInst *Inst, unsigned Val,
283
               uint64_t Address, void *Decoder)
284
1.42k
{
285
1.42k
  uint8_t scaled, base, offset, mode, unit;
286
1.42k
  unsigned basereg, offsetreg;
287
288
1.42k
  scaled = (Val >> 15) & 1;
289
1.42k
  base = (Val >> 10) & 0x1f;
290
1.42k
  offset = (Val >> 5) & 0x1f;
291
1.42k
  mode = (Val >> 1) & 0xf;
292
1.42k
  unit = Val & 1;
293
294
1.42k
  if ((base >= TMS320C64X_REG_A0) && (base <= TMS320C64X_REG_A31))
295
16
    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
1.42k
  basereg = getReg(GPRegsDecoderTable, base);
299
1.42k
  if (basereg == ~0U)
300
16
    return MCDisassembler_Fail;
301
302
1.40k
  switch (mode) {
303
98
  case 0:
304
164
  case 1:
305
417
  case 8:
306
458
  case 9:
307
612
  case 10:
308
1.12k
  case 11:
309
1.12k
    MCOperand_CreateImm0(Inst, (scaled << 19) | (basereg << 12) |
310
1.12k
               (offset << 5) | (mode << 1) |
311
1.12k
               unit);
312
1.12k
    break;
313
79
  case 4:
314
80
  case 5:
315
120
  case 12:
316
199
  case 13:
317
245
  case 14:
318
265
  case 15:
319
265
    if ((offset >= TMS320C64X_REG_A0) &&
320
3
        (offset <= TMS320C64X_REG_A31))
321
3
      offset = (offset - TMS320C64X_REG_A0 +
322
3
          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
265
    offsetreg = getReg(GPRegsDecoderTable, offset);
326
265
    if (offsetreg == ~0U)
327
3
      return MCDisassembler_Fail;
328
262
    MCOperand_CreateImm0(Inst, (scaled << 19) | (basereg << 12) |
329
262
               (offsetreg << 5) |
330
262
               (mode << 1) | unit);
331
262
    break;
332
15
  default:
333
15
    return MCDisassembler_Fail;
334
1.40k
  }
335
336
1.39k
  return MCDisassembler_Success;
337
1.40k
}
338
339
static DecodeStatus DecodeMemOperand2(MCInst *Inst, unsigned Val,
340
              uint64_t Address, void *Decoder)
341
1.26k
{
342
1.26k
  uint16_t offset;
343
1.26k
  unsigned basereg;
344
345
1.26k
  if (Val & 1)
346
631
    basereg = TMS320C64X_REG_B15;
347
637
  else
348
637
    basereg = TMS320C64X_REG_B14;
349
350
1.26k
  offset = (Val >> 1) & 0x7fff;
351
1.26k
  MCOperand_CreateImm0(Inst, (offset << 7) | basereg);
352
353
1.26k
  return MCDisassembler_Success;
354
1.26k
}
355
356
static DecodeStatus DecodeRegPair5(MCInst *Inst, unsigned RegNo,
357
           uint64_t Address, void *Decoder)
358
2.43k
{
359
2.43k
  unsigned Reg;
360
361
2.43k
  if (RegNo > 31)
362
0
    return MCDisassembler_Fail;
363
364
2.43k
  Reg = getReg(GPRegsDecoderTable, RegNo);
365
2.43k
  MCOperand_CreateReg0(Inst, Reg);
366
367
2.43k
  return MCDisassembler_Success;
368
2.43k
}
369
370
static DecodeStatus DecodeRegPair4(MCInst *Inst, unsigned RegNo,
371
           uint64_t Address, void *Decoder)
372
195
{
373
195
  unsigned Reg;
374
375
195
  if (RegNo > 15)
376
0
    return MCDisassembler_Fail;
377
378
195
  Reg = getReg(GPRegsDecoderTable, RegNo << 1);
379
195
  MCOperand_CreateReg0(Inst, Reg);
380
381
195
  return MCDisassembler_Success;
382
195
}
383
384
static DecodeStatus DecodeCondRegister(MCInst *Inst, unsigned Val,
385
               uint64_t Address, void *Decoder)
386
11.5k
{
387
11.5k
  DecodeStatus ret = MCDisassembler_Success;
388
389
11.5k
  if (!Inst->flat_insn->detail)
390
0
    return MCDisassembler_Success;
391
392
11.5k
  switch (Val) {
393
2.42k
  case 0:
394
3.51k
  case 7:
395
3.51k
    Inst->flat_insn->detail->tms320c64x.condition.reg =
396
3.51k
      TMS320C64X_REG_INVALID;
397
3.51k
    break;
398
1.86k
  case 1:
399
1.86k
    Inst->flat_insn->detail->tms320c64x.condition.reg =
400
1.86k
      TMS320C64X_REG_B0;
401
1.86k
    break;
402
1.40k
  case 2:
403
1.40k
    Inst->flat_insn->detail->tms320c64x.condition.reg =
404
1.40k
      TMS320C64X_REG_B1;
405
1.40k
    break;
406
1.27k
  case 3:
407
1.27k
    Inst->flat_insn->detail->tms320c64x.condition.reg =
408
1.27k
      TMS320C64X_REG_B2;
409
1.27k
    break;
410
1.82k
  case 4:
411
1.82k
    Inst->flat_insn->detail->tms320c64x.condition.reg =
412
1.82k
      TMS320C64X_REG_A1;
413
1.82k
    break;
414
1.12k
  case 5:
415
1.12k
    Inst->flat_insn->detail->tms320c64x.condition.reg =
416
1.12k
      TMS320C64X_REG_A2;
417
1.12k
    break;
418
534
  case 6:
419
534
    Inst->flat_insn->detail->tms320c64x.condition.reg =
420
534
      TMS320C64X_REG_A0;
421
534
    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
11.5k
  }
428
429
11.5k
  return ret;
430
11.5k
}
431
432
static DecodeStatus DecodeCondRegisterZero(MCInst *Inst, unsigned Val,
433
             uint64_t Address, void *Decoder)
434
11.5k
{
435
11.5k
  DecodeStatus ret = MCDisassembler_Success;
436
437
11.5k
  if (!Inst->flat_insn->detail)
438
0
    return MCDisassembler_Success;
439
440
11.5k
  switch (Val) {
441
5.18k
  case 0:
442
5.18k
    Inst->flat_insn->detail->tms320c64x.condition.zero = 0;
443
5.18k
    break;
444
6.36k
  case 1:
445
6.36k
    Inst->flat_insn->detail->tms320c64x.condition.zero = 1;
446
6.36k
    break;
447
0
  default:
448
0
    Inst->flat_insn->detail->tms320c64x.condition.zero = 0;
449
0
    ret = MCDisassembler_Fail;
450
0
    break;
451
11.5k
  }
452
453
11.5k
  return ret;
454
11.5k
}
455
456
static DecodeStatus DecodeSide(MCInst *Inst, unsigned Val, uint64_t Address,
457
             void *Decoder)
458
11.5k
{
459
11.5k
  DecodeStatus ret = MCDisassembler_Success;
460
11.5k
  MCOperand *op;
461
11.5k
  int i;
462
463
  /* This is pretty messy, probably we should find a better way */
464
11.5k
  if (Val == 1) {
465
19.7k
    for (i = 0; i < Inst->size; i++) {
466
13.7k
      op = &Inst->Operands[i];
467
13.7k
      if (op->Kind == kRegister) {
468
9.74k
        if ((op->RegVal >= TMS320C64X_REG_A0) &&
469
8.81k
            (op->RegVal <= TMS320C64X_REG_A31))
470
8.18k
          op->RegVal = (op->RegVal -
471
8.18k
                  TMS320C64X_REG_A0 +
472
8.18k
                  TMS320C64X_REG_B0);
473
1.55k
        else if ((op->RegVal >= TMS320C64X_REG_B0) &&
474
627
           (op->RegVal <= TMS320C64X_REG_B31))
475
578
          op->RegVal = (op->RegVal -
476
578
                  TMS320C64X_REG_B0 +
477
578
                  TMS320C64X_REG_A0);
478
9.74k
      }
479
13.7k
    }
480
5.98k
  }
481
482
11.5k
  if (!Inst->flat_insn->detail)
483
0
    return MCDisassembler_Success;
484
485
11.5k
  switch (Val) {
486
5.56k
  case 0:
487
5.56k
    Inst->flat_insn->detail->tms320c64x.funit.side = 1;
488
5.56k
    break;
489
5.98k
  case 1:
490
5.98k
    Inst->flat_insn->detail->tms320c64x.funit.side = 2;
491
5.98k
    break;
492
0
  default:
493
0
    Inst->flat_insn->detail->tms320c64x.funit.side = 0;
494
0
    ret = MCDisassembler_Fail;
495
0
    break;
496
11.5k
  }
497
498
11.5k
  return ret;
499
11.5k
}
500
501
static DecodeStatus DecodeParallel(MCInst *Inst, unsigned Val, uint64_t Address,
502
           void *Decoder)
503
11.5k
{
504
11.5k
  DecodeStatus ret = MCDisassembler_Success;
505
506
11.5k
  if (!Inst->flat_insn->detail)
507
0
    return MCDisassembler_Success;
508
509
11.5k
  switch (Val) {
510
6.11k
  case 0:
511
6.11k
    Inst->flat_insn->detail->tms320c64x.parallel = 0;
512
6.11k
    break;
513
5.43k
  case 1:
514
5.43k
    Inst->flat_insn->detail->tms320c64x.parallel = 1;
515
5.43k
    break;
516
0
  default:
517
0
    Inst->flat_insn->detail->tms320c64x.parallel = -1;
518
0
    ret = MCDisassembler_Fail;
519
0
    break;
520
11.5k
  }
521
522
11.5k
  return ret;
523
11.5k
}
524
525
static DecodeStatus DecodeCrosspathX1(MCInst *Inst, unsigned Val,
526
              uint64_t Address, void *Decoder)
527
110
{
528
110
  DecodeStatus ret = MCDisassembler_Success;
529
110
  MCOperand *op;
530
531
110
  if (!Inst->flat_insn->detail)
532
0
    return MCDisassembler_Success;
533
534
110
  switch (Val) {
535
103
  case 0:
536
103
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = 0;
537
103
    break;
538
7
  case 1:
539
7
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = 1;
540
7
    op = &Inst->Operands[0];
541
7
    if (op->Kind == kRegister) {
542
7
      if ((op->RegVal >= TMS320C64X_REG_A0) &&
543
7
          (op->RegVal <= TMS320C64X_REG_A31))
544
7
        op->RegVal = (op->RegVal - TMS320C64X_REG_A0 +
545
7
                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
7
    }
551
7
    break;
552
0
  default:
553
0
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = -1;
554
0
    ret = MCDisassembler_Fail;
555
0
    break;
556
110
  }
557
558
110
  return ret;
559
110
}
560
561
static DecodeStatus DecodeCrosspathX2(MCInst *Inst, unsigned Val,
562
              uint64_t Address, void *Decoder)
563
4.81k
{
564
4.81k
  DecodeStatus ret = MCDisassembler_Success;
565
4.81k
  MCOperand *op;
566
567
4.81k
  if (!Inst->flat_insn->detail)
568
0
    return MCDisassembler_Success;
569
570
4.81k
  switch (Val) {
571
2.03k
  case 0:
572
2.03k
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = 0;
573
2.03k
    break;
574
2.78k
  case 1:
575
2.78k
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = 1;
576
2.78k
    op = &Inst->Operands[1];
577
2.78k
    if (op->Kind == kRegister) {
578
2.34k
      if ((op->RegVal >= TMS320C64X_REG_A0) &&
579
1.41k
          (op->RegVal <= TMS320C64X_REG_A31))
580
1.36k
        op->RegVal = (op->RegVal - TMS320C64X_REG_A0 +
581
1.36k
                TMS320C64X_REG_B0);
582
977
      else if ((op->RegVal >= TMS320C64X_REG_B0) &&
583
49
         (op->RegVal <= TMS320C64X_REG_B31))
584
0
        op->RegVal = (op->RegVal - TMS320C64X_REG_B0 +
585
0
                TMS320C64X_REG_A0);
586
2.34k
    }
587
2.78k
    break;
588
0
  default:
589
0
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = -1;
590
0
    ret = MCDisassembler_Fail;
591
0
    break;
592
4.81k
  }
593
594
4.81k
  return ret;
595
4.81k
}
596
597
static DecodeStatus DecodeCrosspathX3(MCInst *Inst, unsigned Val,
598
              uint64_t Address, void *Decoder)
599
1.43k
{
600
1.43k
  DecodeStatus ret = MCDisassembler_Success;
601
1.43k
  MCOperand *op;
602
603
1.43k
  if (!Inst->flat_insn->detail)
604
0
    return MCDisassembler_Success;
605
606
1.43k
  switch (Val) {
607
526
  case 0:
608
526
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = 0;
609
526
    break;
610
913
  case 1:
611
913
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = 2;
612
913
    op = &Inst->Operands[2];
613
913
    if (op->Kind == kRegister) {
614
152
      if ((op->RegVal >= TMS320C64X_REG_A0) &&
615
152
          (op->RegVal <= TMS320C64X_REG_A31))
616
152
        op->RegVal = (op->RegVal - TMS320C64X_REG_A0 +
617
152
                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
152
    }
623
913
    break;
624
0
  default:
625
0
    Inst->flat_insn->detail->tms320c64x.funit.crosspath = -1;
626
0
    ret = MCDisassembler_Fail;
627
0
    break;
628
1.43k
  }
629
630
1.43k
  return ret;
631
1.43k
}
632
633
static DecodeStatus DecodeNop(MCInst *Inst, unsigned Val, uint64_t Address,
634
            void *Decoder)
635
123
{
636
123
  MCOperand_CreateImm0(Inst, Val + 1);
637
638
123
  return MCDisassembler_Success;
639
123
}
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
11.8k
{
648
11.8k
  uint32_t insn;
649
11.8k
  DecodeStatus result;
650
651
11.8k
  if (code_len < 4) {
652
142
    *size = 0;
653
142
    return MCDisassembler_Fail;
654
142
  }
655
656
11.6k
  if (MI->flat_insn->detail)
657
11.6k
    memset(MI->flat_insn->detail, 0,
658
11.6k
           offsetof(cs_detail, tms320c64x) + sizeof(cs_tms320c64x));
659
660
11.6k
  insn = readBytes32(MI, code);
661
11.6k
  result =
662
11.6k
    decodeInstruction_4(DecoderTable32, MI, insn, address, info, 0);
663
664
11.6k
  if (result == MCDisassembler_Success) {
665
11.5k
    *size = 4;
666
11.5k
    return true;
667
11.5k
  }
668
669
142
  MCInst_clear(MI);
670
142
  *size = 0;
671
142
  return false;
672
11.6k
}
673
674
void TMS320C64x_init(MCRegisterInfo *MRI)
675
396
{
676
396
  MCRegisterInfo_InitMCRegisterInfo(MRI, TMS320C64xRegDesc, 90, 0, 0,
677
396
            TMS320C64xMCRegisterClasses, 7, 0, 0,
678
396
            TMS320C64xRegDiffLists, 0,
679
396
            TMS320C64xSubRegIdxLists, 1, 0);
680
396
}
681
682
#endif