Coverage Report

Created: 2023-09-25 06:24

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