Coverage Report

Created: 2025-08-26 06:30

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