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