Coverage Report

Created: 2025-10-28 07:02

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