Coverage Report

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