Coverage Report

Created: 2026-07-16 06:55

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