Coverage Report

Created: 2025-12-05 06:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/capstonev5/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, 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
38.5k
{
115
  // support everything
116
38.5k
  return (uint64_t)-1;
117
38.5k
}
118
119
static unsigned getReg(const unsigned *RegTable, unsigned RegNo)
120
69.3k
{
121
69.3k
  if(RegNo > 31)
122
13
    return ~0U;
123
69.3k
  return RegTable[RegNo];
124
69.3k
}
125
126
static DecodeStatus DecodeGPRegsRegisterClass(MCInst *Inst, unsigned RegNo,
127
    uint64_t Address, void *Decoder)
128
47.8k
{
129
47.8k
  unsigned Reg;
130
131
47.8k
  if(RegNo > 31)
132
0
    return MCDisassembler_Fail;
133
134
47.8k
  Reg = getReg(GPRegsDecoderTable, RegNo);
135
47.8k
  if(Reg == ~0U)
136
0
    return MCDisassembler_Fail;
137
47.8k
  MCOperand_CreateReg0(Inst, Reg);
138
139
47.8k
  return MCDisassembler_Success;
140
47.8k
}
141
142
static DecodeStatus DecodeControlRegsRegisterClass(MCInst *Inst, unsigned RegNo,
143
    uint64_t Address, void *Decoder)
144
1.71k
{
145
1.71k
  unsigned Reg;
146
147
1.71k
  if(RegNo > 31)
148
0
    return MCDisassembler_Fail;
149
150
1.71k
  Reg = getReg(ControlRegsDecoderTable, RegNo);
151
1.71k
  if(Reg == ~0U)
152
2
    return MCDisassembler_Fail;
153
1.71k
  MCOperand_CreateReg0(Inst, Reg);
154
155
1.71k
  return MCDisassembler_Success;
156
1.71k
}
157
158
static DecodeStatus DecodeScst5(MCInst *Inst, unsigned Val,
159
    uint64_t Address, void *Decoder)
160
6.52k
{
161
6.52k
  int32_t imm;
162
163
6.52k
  imm = Val;
164
  /* Sign extend 5 bit value */
165
6.52k
  if(imm & (1 << (5 - 1)))
166
2.36k
    imm |= ~((1 << 5) - 1);
167
168
6.52k
  MCOperand_CreateImm0(Inst, imm);
169
170
6.52k
  return MCDisassembler_Success;
171
6.52k
}
172
173
static DecodeStatus DecodeScst16(MCInst *Inst, unsigned Val,
174
    uint64_t Address, void *Decoder)
175
1.29k
{
176
1.29k
  int32_t imm;
177
178
1.29k
  imm = Val;
179
  /* Sign extend 16 bit value */
180
1.29k
  if(imm & (1 << (16 - 1)))
181
833
    imm |= ~((1 << 16) - 1);
182
183
1.29k
  MCOperand_CreateImm0(Inst, imm);
184
185
1.29k
  return MCDisassembler_Success;
186
1.29k
}
187
188
static DecodeStatus DecodePCRelScst7(MCInst *Inst, unsigned Val,
189
    uint64_t Address, void *Decoder)
190
535
{
191
535
  int32_t imm;
192
193
535
  imm = Val;
194
  /* Sign extend 7 bit value */
195
535
  if(imm & (1 << (7 - 1)))
196
404
    imm |= ~((1 << 7) - 1);
197
198
  /* Address is relative to the address of the first instruction in the fetch packet */
199
535
  MCOperand_CreateImm0(Inst, (Address & ~31) + (imm * 4));
200
201
535
  return MCDisassembler_Success;
202
535
}
203
204
static DecodeStatus DecodePCRelScst10(MCInst *Inst, unsigned Val,
205
    uint64_t Address, void *Decoder)
206
681
{
207
681
  int32_t imm;
208
209
681
  imm = Val;
210
  /* Sign extend 10 bit value */
211
681
  if(imm & (1 << (10 - 1)))
212
86
    imm |= ~((1 << 10) - 1);
213
214
  /* Address is relative to the address of the first instruction in the fetch packet */
215
681
  MCOperand_CreateImm0(Inst, (Address & ~31) + (imm * 4));
216
217
681
  return MCDisassembler_Success;
218
681
}
219
220
static DecodeStatus DecodePCRelScst12(MCInst *Inst, unsigned Val,
221
    uint64_t Address, void *Decoder)
222
585
{
223
585
  int32_t imm;
224
225
585
  imm = Val;
226
  /* Sign extend 12 bit value */
227
585
  if(imm & (1 << (12 - 1)))
228
217
    imm |= ~((1 << 12) - 1);
229
230
  /* Address is relative to the address of the first instruction in the fetch packet */
231
585
  MCOperand_CreateImm0(Inst, (Address & ~31) + (imm * 4));
232
233
585
  return MCDisassembler_Success;
234
585
}
235
236
static DecodeStatus DecodePCRelScst21(MCInst *Inst, unsigned Val,
237
    uint64_t Address, void *Decoder)
238
1.04k
{
239
1.04k
  int32_t imm;
240
241
1.04k
  imm = Val;
242
  /* Sign extend 21 bit value */
243
1.04k
  if(imm & (1 << (21 - 1)))
244
527
    imm |= ~((1 << 21) - 1);
245
246
  /* Address is relative to the address of the first instruction in the fetch packet */
247
1.04k
  MCOperand_CreateImm0(Inst, (Address & ~31) + (imm * 4));
248
249
1.04k
  return MCDisassembler_Success;
250
1.04k
}
251
252
static DecodeStatus DecodeMemOperand(MCInst *Inst, unsigned Val,
253
    uint64_t Address, void *Decoder)
254
3.68k
{
255
3.68k
  return DecodeMemOperandSc(Inst, Val | (1 << 15), Address, Decoder);
256
3.68k
}
257
258
static DecodeStatus DecodeMemOperandSc(MCInst *Inst, unsigned Val,
259
    uint64_t Address, void *Decoder)
260
4.35k
{
261
4.35k
  uint8_t scaled, base, offset, mode, unit;
262
4.35k
  unsigned basereg, offsetreg;
263
264
4.35k
  scaled = (Val >> 15) & 1;
265
4.35k
  base = (Val >> 10) & 0x1f;
266
4.35k
  offset = (Val >> 5) & 0x1f;
267
4.35k
  mode = (Val >> 1) & 0xf;
268
4.35k
  unit = Val & 1;
269
270
4.35k
  if((base >= TMS320C64X_REG_A0) && (base <= TMS320C64X_REG_A31))
271
12
    base = (base - TMS320C64X_REG_A0 + TMS320C64X_REG_B0);
272
4.33k
  else if((base >= TMS320C64X_REG_B0) && (base <= TMS320C64X_REG_B31))
273
0
    base = (base - TMS320C64X_REG_B0 + TMS320C64X_REG_A0);
274
4.35k
  basereg = getReg(GPRegsDecoderTable, base);
275
4.35k
  if (basereg ==  ~0U)
276
12
    return MCDisassembler_Fail;
277
278
4.33k
  switch(mode) {
279
259
    case 0:
280
550
    case 1:
281
853
    case 8:
282
1.42k
    case 9:
283
1.96k
    case 10:
284
2.47k
    case 11:
285
2.47k
      MCOperand_CreateImm0(Inst, (scaled << 19) | (basereg << 12) | (offset << 5) | (mode << 1) | unit);
286
2.47k
      break;
287
369
    case 4:
288
590
    case 5:
289
1.31k
    case 12:
290
1.51k
    case 13:
291
1.74k
    case 14:
292
1.85k
    case 15:
293
1.85k
      if((offset >= TMS320C64X_REG_A0) && (offset <= TMS320C64X_REG_A31))
294
1
        offset = (offset - TMS320C64X_REG_A0 + TMS320C64X_REG_B0);
295
1.85k
      else if((offset >= TMS320C64X_REG_B0) && (offset <= TMS320C64X_REG_B31))
296
0
        offset = (offset - TMS320C64X_REG_B0 + TMS320C64X_REG_A0);
297
1.85k
      offsetreg = getReg(GPRegsDecoderTable, offset);
298
1.85k
      if (offsetreg ==  ~0U)
299
1
        return MCDisassembler_Fail;
300
1.85k
      MCOperand_CreateImm0(Inst, (scaled << 19) | (basereg << 12) | (offsetreg << 5) | (mode << 1) | unit);
301
1.85k
      break;
302
12
    default:
303
12
      return MCDisassembler_Fail;
304
4.33k
  }
305
306
4.32k
  return MCDisassembler_Success;
307
4.33k
}
308
309
static DecodeStatus DecodeMemOperand2(MCInst *Inst, unsigned Val,
310
    uint64_t Address, void *Decoder)
311
2.92k
{
312
2.92k
  uint16_t offset;
313
2.92k
  unsigned basereg;
314
315
2.92k
  if(Val & 1)
316
1.85k
    basereg = TMS320C64X_REG_B15;
317
1.07k
  else
318
1.07k
    basereg = TMS320C64X_REG_B14;
319
320
2.92k
  offset = (Val >> 1) & 0x7fff;
321
2.92k
  MCOperand_CreateImm0(Inst, (offset << 7) | basereg);
322
323
2.92k
  return MCDisassembler_Success;
324
2.92k
}
325
326
static DecodeStatus DecodeRegPair5(MCInst *Inst, unsigned RegNo,
327
    uint64_t Address, void *Decoder)
328
12.9k
{
329
12.9k
  unsigned Reg;
330
331
12.9k
  if(RegNo > 31)
332
0
    return MCDisassembler_Fail;
333
334
12.9k
  Reg = getReg(GPRegsDecoderTable, RegNo);
335
12.9k
  MCOperand_CreateReg0(Inst, Reg);
336
337
12.9k
  return MCDisassembler_Success;
338
12.9k
}
339
340
static DecodeStatus DecodeRegPair4(MCInst *Inst, unsigned RegNo,
341
    uint64_t Address, void *Decoder)
342
662
{
343
662
  unsigned Reg;
344
345
662
  if(RegNo > 15)
346
0
    return MCDisassembler_Fail;
347
348
662
  Reg = getReg(GPRegsDecoderTable, RegNo << 1);
349
662
  MCOperand_CreateReg0(Inst, Reg);
350
351
662
  return MCDisassembler_Success;
352
662
}
353
354
static DecodeStatus DecodeCondRegister(MCInst *Inst, unsigned Val,
355
    uint64_t Address, void *Decoder)
356
38.3k
{
357
38.3k
  DecodeStatus ret = MCDisassembler_Success;
358
359
38.3k
  if(!Inst->flat_insn->detail)
360
0
    return MCDisassembler_Success;
361
362
38.3k
  switch(Val) {
363
8.30k
    case 0:
364
12.1k
    case 7:
365
12.1k
      Inst->flat_insn->detail->tms320c64x.condition.reg = TMS320C64X_REG_INVALID;
366
12.1k
      break;
367
4.65k
    case 1:
368
4.65k
      Inst->flat_insn->detail->tms320c64x.condition.reg = TMS320C64X_REG_B0;
369
4.65k
      break;
370
4.45k
    case 2:
371
4.45k
      Inst->flat_insn->detail->tms320c64x.condition.reg = TMS320C64X_REG_B1;
372
4.45k
      break;
373
3.17k
    case 3:
374
3.17k
      Inst->flat_insn->detail->tms320c64x.condition.reg = TMS320C64X_REG_B2;
375
3.17k
      break;
376
4.03k
    case 4:
377
4.03k
      Inst->flat_insn->detail->tms320c64x.condition.reg = TMS320C64X_REG_A1;
378
4.03k
      break;
379
6.41k
    case 5:
380
6.41k
      Inst->flat_insn->detail->tms320c64x.condition.reg = TMS320C64X_REG_A2;
381
6.41k
      break;
382
3.52k
    case 6:
383
3.52k
      Inst->flat_insn->detail->tms320c64x.condition.reg = TMS320C64X_REG_A0;
384
3.52k
      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
38.3k
  }
390
391
38.3k
  return ret;
392
38.3k
}
393
394
static DecodeStatus DecodeCondRegisterZero(MCInst *Inst, unsigned Val,
395
    uint64_t Address, void *Decoder)
396
38.3k
{
397
38.3k
  DecodeStatus ret = MCDisassembler_Success;
398
399
38.3k
  if(!Inst->flat_insn->detail)
400
0
    return MCDisassembler_Success;
401
402
38.3k
  switch(Val) {
403
21.0k
    case 0:
404
21.0k
      Inst->flat_insn->detail->tms320c64x.condition.zero = 0;
405
21.0k
      break;
406
17.3k
    case 1:
407
17.3k
      Inst->flat_insn->detail->tms320c64x.condition.zero = 1;
408
17.3k
      break;
409
0
    default:
410
0
      Inst->flat_insn->detail->tms320c64x.condition.zero = 0;
411
0
      ret = MCDisassembler_Fail;
412
0
      break;
413
38.3k
  }
414
415
38.3k
  return ret;
416
38.3k
}
417
418
static DecodeStatus DecodeSide(MCInst *Inst, unsigned Val,
419
    uint64_t Address, void *Decoder)
420
38.3k
{
421
38.3k
  DecodeStatus ret = MCDisassembler_Success;
422
38.3k
  MCOperand *op;
423
38.3k
  int i;
424
425
  /* This is pretty messy, probably we should find a better way */
426
38.3k
  if(Val == 1) {
427
56.1k
    for(i = 0; i < Inst->size; i++) {
428
39.4k
      op = &Inst->Operands[i];
429
39.4k
      if(op->Kind == kRegister) {
430
28.6k
        if((op->RegVal >= TMS320C64X_REG_A0) && (op->RegVal <= TMS320C64X_REG_A31))
431
25.2k
          op->RegVal = (op->RegVal - TMS320C64X_REG_A0 + TMS320C64X_REG_B0);
432
3.42k
        else if((op->RegVal >= TMS320C64X_REG_B0) && (op->RegVal <= TMS320C64X_REG_B31))
433
1.81k
          op->RegVal = (op->RegVal - TMS320C64X_REG_B0 + TMS320C64X_REG_A0);
434
28.6k
      }
435
39.4k
    }
436
16.7k
  }
437
438
38.3k
  if(!Inst->flat_insn->detail)
439
0
    return MCDisassembler_Success;
440
441
38.3k
  switch(Val) {
442
21.6k
    case 0:
443
21.6k
      Inst->flat_insn->detail->tms320c64x.funit.side = 1;
444
21.6k
      break;
445
16.7k
    case 1:
446
16.7k
      Inst->flat_insn->detail->tms320c64x.funit.side = 2;
447
16.7k
      break;
448
0
    default:
449
0
      Inst->flat_insn->detail->tms320c64x.funit.side = 0;
450
0
      ret = MCDisassembler_Fail;
451
0
      break;
452
38.3k
  }
453
454
38.3k
  return ret;
455
38.3k
}
456
457
static DecodeStatus DecodeParallel(MCInst *Inst, unsigned Val,
458
    uint64_t Address, void *Decoder)
459
38.3k
{
460
38.3k
  DecodeStatus ret = MCDisassembler_Success;
461
462
38.3k
  if(!Inst->flat_insn->detail)
463
0
    return MCDisassembler_Success;
464
465
38.3k
  switch(Val) {
466
20.4k
    case 0:
467
20.4k
      Inst->flat_insn->detail->tms320c64x.parallel = 0;
468
20.4k
      break;
469
17.9k
    case 1:
470
17.9k
      Inst->flat_insn->detail->tms320c64x.parallel = 1;
471
17.9k
      break;
472
0
    default:
473
0
      Inst->flat_insn->detail->tms320c64x.parallel = -1;
474
0
      ret = MCDisassembler_Fail;
475
0
      break;
476
38.3k
  }
477
478
38.3k
  return ret;
479
38.3k
}
480
481
static DecodeStatus DecodeCrosspathX1(MCInst *Inst, unsigned Val,
482
    uint64_t Address, void *Decoder)
483
522
{
484
522
  DecodeStatus ret = MCDisassembler_Success;
485
522
  MCOperand *op;
486
487
522
  if(!Inst->flat_insn->detail)
488
0
    return MCDisassembler_Success;
489
490
522
  switch(Val) {
491
274
    case 0:
492
274
      Inst->flat_insn->detail->tms320c64x.funit.crosspath = 0;
493
274
      break;
494
248
    case 1:
495
248
      Inst->flat_insn->detail->tms320c64x.funit.crosspath = 1;
496
248
      op = &Inst->Operands[0];
497
248
      if(op->Kind == kRegister) {
498
248
        if((op->RegVal >= TMS320C64X_REG_A0) && (op->RegVal <= TMS320C64X_REG_A31))
499
248
          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
248
      }
503
248
      break;
504
0
    default:
505
0
      Inst->flat_insn->detail->tms320c64x.funit.crosspath = -1;
506
0
      ret = MCDisassembler_Fail;
507
0
      break;
508
522
  }
509
510
522
  return ret;
511
522
}
512
513
static DecodeStatus DecodeCrosspathX2(MCInst *Inst, unsigned Val,
514
    uint64_t Address, void *Decoder)
515
13.3k
{
516
13.3k
  DecodeStatus ret = MCDisassembler_Success;
517
13.3k
  MCOperand *op;
518
519
13.3k
  if(!Inst->flat_insn->detail)
520
0
    return MCDisassembler_Success;
521
522
13.3k
  switch(Val) {
523
5.94k
    case 0:
524
5.94k
      Inst->flat_insn->detail->tms320c64x.funit.crosspath = 0;
525
5.94k
      break;
526
7.39k
    case 1:
527
7.39k
      Inst->flat_insn->detail->tms320c64x.funit.crosspath = 1;
528
7.39k
      op = &Inst->Operands[1];
529
7.39k
      if(op->Kind == kRegister) {
530
5.40k
        if((op->RegVal >= TMS320C64X_REG_A0) && (op->RegVal <= TMS320C64X_REG_A31))
531
3.99k
          op->RegVal = (op->RegVal - TMS320C64X_REG_A0 + TMS320C64X_REG_B0);
532
1.40k
        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
5.40k
      }
535
7.39k
      break;
536
0
    default:
537
0
      Inst->flat_insn->detail->tms320c64x.funit.crosspath = -1;
538
0
      ret = MCDisassembler_Fail;
539
0
      break;
540
13.3k
  }
541
542
13.3k
  return ret;
543
13.3k
}
544
545
static DecodeStatus DecodeCrosspathX3(MCInst *Inst, unsigned Val,
546
    uint64_t Address, void *Decoder)
547
7.35k
{
548
7.35k
  DecodeStatus ret = MCDisassembler_Success;
549
7.35k
  MCOperand *op;
550
551
7.35k
  if(!Inst->flat_insn->detail)
552
0
    return MCDisassembler_Success;
553
554
7.35k
  switch(Val) {
555
4.06k
    case 0:
556
4.06k
      Inst->flat_insn->detail->tms320c64x.funit.crosspath = 0;
557
4.06k
      break;
558
3.28k
    case 1:
559
3.28k
      Inst->flat_insn->detail->tms320c64x.funit.crosspath = 2;
560
3.28k
      op = &Inst->Operands[2];
561
3.28k
      if(op->Kind == kRegister) {
562
1.39k
        if((op->RegVal >= TMS320C64X_REG_A0) && (op->RegVal <= TMS320C64X_REG_A31))
563
1.15k
          op->RegVal = (op->RegVal - TMS320C64X_REG_A0 + TMS320C64X_REG_B0);
564
239
        else if((op->RegVal >= TMS320C64X_REG_B0) && (op->RegVal <= TMS320C64X_REG_B31))
565
163
          op->RegVal = (op->RegVal - TMS320C64X_REG_B0 + TMS320C64X_REG_A0);
566
1.39k
      }
567
3.28k
      break;
568
0
    default:
569
0
      Inst->flat_insn->detail->tms320c64x.funit.crosspath = -1;
570
0
      ret = MCDisassembler_Fail;
571
0
      break;
572
7.35k
  }
573
574
7.35k
  return ret;
575
7.35k
}
576
577
578
static DecodeStatus DecodeNop(MCInst *Inst, unsigned Val,
579
    uint64_t Address, void *Decoder)
580
1.69k
{
581
1.69k
  MCOperand_CreateImm0(Inst, Val + 1);
582
583
1.69k
  return MCDisassembler_Success;
584
1.69k
}
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
38.9k
{
592
38.9k
  uint32_t insn;
593
38.9k
  DecodeStatus result;
594
595
38.9k
  if(code_len < 4) {
596
427
    *size = 0;
597
427
    return MCDisassembler_Fail;
598
427
  }
599
600
38.5k
  if(MI->flat_insn->detail)
601
38.5k
    memset(MI->flat_insn->detail, 0, offsetof(cs_detail, tms320c64x)+sizeof(cs_tms320c64x));
602
603
38.5k
  insn = readBytes32(MI, code);
604
38.5k
  result = decodeInstruction_4(DecoderTable32, MI, insn, address, info, 0);
605
606
38.5k
  if(result == MCDisassembler_Success) {
607
38.3k
    *size = 4;
608
38.3k
    return true;
609
38.3k
  }
610
611
145
  MCInst_clear(MI);
612
145
  *size = 0;
613
145
  return false;
614
38.5k
}
615
616
void TMS320C64x_init(MCRegisterInfo *MRI)
617
1.23k
{
618
1.23k
  MCRegisterInfo_InitMCRegisterInfo(MRI, TMS320C64xRegDesc, 90,
619
1.23k
      0, 0,
620
1.23k
      TMS320C64xMCRegisterClasses, 7,
621
1.23k
      0, 0,
622
1.23k
      TMS320C64xRegDiffLists,
623
1.23k
      0,
624
1.23k
      TMS320C64xSubRegIdxLists, 1,
625
1.23k
      0);
626
1.23k
}
627
628
#endif