/src/capstonenext/arch/TMS320C64x/TMS320C64xInstPrinter.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 <ctype.h> |
7 | | #include <string.h> |
8 | | |
9 | | #include "TMS320C64xInstPrinter.h" |
10 | | #include "../../MCInst.h" |
11 | | #include "../../utils.h" |
12 | | #include "../../SStream.h" |
13 | | #include "../../MCRegisterInfo.h" |
14 | | #include "../../MathExtras.h" |
15 | | #include "TMS320C64xMapping.h" |
16 | | |
17 | | #include "capstone/tms320c64x.h" |
18 | | |
19 | | static const char *getRegisterName(unsigned RegNo); |
20 | | static void printOperand(MCInst *MI, unsigned OpNo, SStream *O); |
21 | | static void printMemOperand(MCInst *MI, unsigned OpNo, SStream *O); |
22 | | static void printMemOperand2(MCInst *MI, unsigned OpNo, SStream *O); |
23 | | static void printRegPair(MCInst *MI, unsigned OpNo, SStream *O); |
24 | | |
25 | | void TMS320C64x_post_printer(csh ud, cs_insn *insn, SStream *insn_asm, |
26 | | MCInst *mci) |
27 | 33.6k | { |
28 | 33.6k | SStream ss; |
29 | 33.6k | const char *op_str_ptr, *p2; |
30 | 33.6k | char tmp[8] = { 0 }; |
31 | 33.6k | unsigned int unit = 0; |
32 | 33.6k | int i; |
33 | 33.6k | cs_tms320c64x *tms320c64x; |
34 | | |
35 | 33.6k | if (mci->csh->detail_opt) { |
36 | 33.6k | tms320c64x = &mci->flat_insn->detail->tms320c64x; |
37 | | |
38 | 33.6k | for (i = 0; i < insn->detail->groups_count; i++) { |
39 | 33.6k | switch (insn->detail->groups[i]) { |
40 | 8.79k | case TMS320C64X_GRP_FUNIT_D: |
41 | 8.79k | unit = TMS320C64X_FUNIT_D; |
42 | 8.79k | break; |
43 | 7.85k | case TMS320C64X_GRP_FUNIT_L: |
44 | 7.85k | unit = TMS320C64X_FUNIT_L; |
45 | 7.85k | break; |
46 | 1.45k | case TMS320C64X_GRP_FUNIT_M: |
47 | 1.45k | unit = TMS320C64X_FUNIT_M; |
48 | 1.45k | break; |
49 | 14.3k | case TMS320C64X_GRP_FUNIT_S: |
50 | 14.3k | unit = TMS320C64X_FUNIT_S; |
51 | 14.3k | break; |
52 | 1.15k | case TMS320C64X_GRP_FUNIT_NO: |
53 | 1.15k | unit = TMS320C64X_FUNIT_NO; |
54 | 1.15k | break; |
55 | 33.6k | } |
56 | 33.6k | if (unit != 0) |
57 | 33.6k | break; |
58 | 33.6k | } |
59 | 33.6k | tms320c64x->funit.unit = unit; |
60 | | |
61 | 33.6k | SStream_Init(&ss); |
62 | 33.6k | if (tms320c64x->condition.reg != TMS320C64X_REG_INVALID) |
63 | 21.3k | SStream_concat( |
64 | 21.3k | &ss, "[%c%s]|", |
65 | 21.3k | (tms320c64x->condition.zero == 1) ? '!' : '|', |
66 | 21.3k | cs_reg_name(ud, tms320c64x->condition.reg)); |
67 | | |
68 | | // Sorry for all the fixes below. I don't have time to add more helper SStream functions. |
69 | | // Before that they messed around with the private buffer of the stream. |
70 | | // So it is better now. But still not efficient. |
71 | 33.6k | op_str_ptr = strchr(SStream_rbuf(insn_asm), '\t'); |
72 | | |
73 | 33.6k | if ((op_str_ptr != NULL) && |
74 | 32.5k | (((p2 = strchr(op_str_ptr, '[')) != NULL) || |
75 | 25.9k | ((p2 = strchr(op_str_ptr, '(')) != NULL))) { |
76 | 29.7k | while ((p2 > op_str_ptr) && |
77 | 29.7k | ((*p2 != 'a') && (*p2 != 'b'))) |
78 | 22.8k | p2--; |
79 | 6.90k | if (p2 == op_str_ptr) { |
80 | 0 | SStream_Flush(insn_asm, NULL); |
81 | 0 | SStream_concat0(insn_asm, "Invalid!"); |
82 | 0 | return; |
83 | 0 | } |
84 | 6.90k | if (*p2 == 'a') |
85 | 3.16k | strncpy(tmp, "1T", sizeof(tmp)); |
86 | 3.73k | else |
87 | 3.73k | strncpy(tmp, "2T", sizeof(tmp)); |
88 | 26.7k | } else { |
89 | 26.7k | tmp[0] = '\0'; |
90 | 26.7k | } |
91 | 33.6k | SStream mnem_post = { 0 }; |
92 | 33.6k | SStream_Init(&mnem_post); |
93 | 33.6k | switch (tms320c64x->funit.unit) { |
94 | 8.79k | case TMS320C64X_FUNIT_D: |
95 | 8.79k | SStream_concat(&mnem_post, ".D%s%u", tmp, |
96 | 8.79k | tms320c64x->funit.side); |
97 | 8.79k | break; |
98 | 7.85k | case TMS320C64X_FUNIT_L: |
99 | 7.85k | SStream_concat(&mnem_post, ".L%s%u", tmp, |
100 | 7.85k | tms320c64x->funit.side); |
101 | 7.85k | break; |
102 | 1.45k | case TMS320C64X_FUNIT_M: |
103 | 1.45k | SStream_concat(&mnem_post, ".M%s%u", tmp, |
104 | 1.45k | tms320c64x->funit.side); |
105 | 1.45k | break; |
106 | 14.3k | case TMS320C64X_FUNIT_S: |
107 | 14.3k | SStream_concat(&mnem_post, ".S%s%u", tmp, |
108 | 14.3k | tms320c64x->funit.side); |
109 | 14.3k | break; |
110 | 33.6k | } |
111 | 33.6k | if (tms320c64x->funit.crosspath > 0) |
112 | 11.0k | SStream_concat0(&mnem_post, "X"); |
113 | | |
114 | 33.6k | if (op_str_ptr != NULL) { |
115 | | // There is an op_str |
116 | 32.5k | SStream_concat1(&mnem_post, '\t'); |
117 | 32.5k | SStream_replc_str(insn_asm, '\t', |
118 | 32.5k | SStream_rbuf(&mnem_post)); |
119 | 32.5k | } |
120 | | |
121 | 33.6k | if (tms320c64x->parallel != 0) |
122 | 15.4k | SStream_concat0(insn_asm, "\t||"); |
123 | 33.6k | SStream_concat0(&ss, SStream_rbuf(insn_asm)); |
124 | 33.6k | SStream_Flush(insn_asm, NULL); |
125 | 33.6k | SStream_concat0(insn_asm, SStream_rbuf(&ss)); |
126 | 33.6k | } |
127 | 33.6k | } |
128 | | |
129 | | #define PRINT_ALIAS_INSTR |
130 | | #include "TMS320C64xGenAsmWriter.inc" |
131 | | |
132 | | #define GET_INSTRINFO_ENUM |
133 | | #include "TMS320C64xGenInstrInfo.inc" |
134 | | |
135 | | static void printOperand(MCInst *MI, unsigned OpNo, SStream *O) |
136 | 139k | { |
137 | 139k | MCOperand *Op = MCInst_getOperand(MI, OpNo); |
138 | 139k | unsigned reg; |
139 | | |
140 | 139k | if (MCOperand_isReg(Op)) { |
141 | 100k | reg = MCOperand_getReg(Op); |
142 | 100k | if ((MCInst_getOpcode(MI) == TMS320C64x_MVC_s1_rr) && |
143 | 6.76k | (OpNo == 1)) { |
144 | 3.38k | switch (reg) { |
145 | 1.80k | case TMS320C64X_REG_EFR: |
146 | 1.80k | SStream_concat0(O, "EFR"); |
147 | 1.80k | break; |
148 | 712 | case TMS320C64X_REG_IFR: |
149 | 712 | SStream_concat0(O, "IFR"); |
150 | 712 | break; |
151 | 868 | default: |
152 | 868 | SStream_concat0(O, getRegisterName(reg)); |
153 | 868 | break; |
154 | 3.38k | } |
155 | 97.3k | } else { |
156 | 97.3k | SStream_concat0(O, getRegisterName(reg)); |
157 | 97.3k | } |
158 | | |
159 | 100k | if (MI->csh->detail_opt) { |
160 | 100k | MI->flat_insn->detail->tms320c64x |
161 | 100k | .operands[MI->flat_insn->detail->tms320c64x |
162 | 100k | .op_count] |
163 | 100k | .type = TMS320C64X_OP_REG; |
164 | 100k | MI->flat_insn->detail->tms320c64x |
165 | 100k | .operands[MI->flat_insn->detail->tms320c64x |
166 | 100k | .op_count] |
167 | 100k | .reg = reg; |
168 | 100k | MI->flat_insn->detail->tms320c64x.op_count++; |
169 | 100k | } |
170 | 100k | } else if (MCOperand_isImm(Op)) { |
171 | 39.1k | int64_t Imm = MCOperand_getImm(Op); |
172 | | |
173 | 39.1k | if (Imm >= 0) { |
174 | 33.1k | if (Imm > HEX_THRESHOLD) |
175 | 18.0k | SStream_concat(O, "0x%" PRIx64, Imm); |
176 | 15.0k | else |
177 | 15.0k | SStream_concat(O, "%" PRIu64, Imm); |
178 | 33.1k | } else { |
179 | 5.95k | if (Imm < -HEX_THRESHOLD) |
180 | 4.38k | SStream_concat(O, "-0x%" PRIx64, -Imm); |
181 | 1.57k | else |
182 | 1.57k | SStream_concat(O, "-%" PRIu64, -Imm); |
183 | 5.95k | } |
184 | | |
185 | 39.1k | if (MI->csh->detail_opt) { |
186 | 39.1k | MI->flat_insn->detail->tms320c64x |
187 | 39.1k | .operands[MI->flat_insn->detail->tms320c64x |
188 | 39.1k | .op_count] |
189 | 39.1k | .type = TMS320C64X_OP_IMM; |
190 | 39.1k | MI->flat_insn->detail->tms320c64x |
191 | 39.1k | .operands[MI->flat_insn->detail->tms320c64x |
192 | 39.1k | .op_count] |
193 | 39.1k | .imm = Imm; |
194 | 39.1k | MI->flat_insn->detail->tms320c64x.op_count++; |
195 | 39.1k | } |
196 | 39.1k | } |
197 | 139k | } |
198 | | |
199 | | static void printMemOperand(MCInst *MI, unsigned OpNo, SStream *O) |
200 | 7.48k | { |
201 | 7.48k | MCOperand *Op = MCInst_getOperand(MI, OpNo); |
202 | 7.48k | int64_t Val = MCOperand_getImm(Op); |
203 | 7.48k | unsigned scaled, base, offset, mode, unit; |
204 | 7.48k | cs_tms320c64x *tms320c64x; |
205 | 7.48k | char st, nd; |
206 | | |
207 | 7.48k | scaled = (Val >> 19) & 1; |
208 | 7.48k | base = (Val >> 12) & 0x7f; |
209 | 7.48k | offset = (Val >> 5) & 0x7f; |
210 | 7.48k | mode = (Val >> 1) & 0xf; |
211 | 7.48k | unit = Val & 1; |
212 | | |
213 | 7.48k | if (scaled) { |
214 | 6.05k | st = '['; |
215 | 6.05k | nd = ']'; |
216 | 6.05k | } else { |
217 | 1.43k | st = '('; |
218 | 1.43k | nd = ')'; |
219 | 1.43k | } |
220 | | |
221 | 7.48k | switch (mode) { |
222 | 706 | case 0: |
223 | 706 | SStream_concat(O, "*-%s%c%u%c", getRegisterName(base), st, |
224 | 706 | offset, nd); |
225 | 706 | break; |
226 | 494 | case 1: |
227 | 494 | SStream_concat(O, "*+%s%c%u%c", getRegisterName(base), st, |
228 | 494 | offset, nd); |
229 | 494 | break; |
230 | 660 | case 4: |
231 | 660 | SStream_concat(O, "*-%s%c%s%c", getRegisterName(base), st, |
232 | 660 | getRegisterName(offset), nd); |
233 | 660 | break; |
234 | 101 | case 5: |
235 | 101 | SStream_concat(O, "*+%s%c%s%c", getRegisterName(base), st, |
236 | 101 | getRegisterName(offset), nd); |
237 | 101 | break; |
238 | 574 | case 8: |
239 | 574 | SStream_concat(O, "*--%s%c%u%c", getRegisterName(base), st, |
240 | 574 | offset, nd); |
241 | 574 | break; |
242 | 727 | case 9: |
243 | 727 | SStream_concat(O, "*++%s%c%u%c", getRegisterName(base), st, |
244 | 727 | offset, nd); |
245 | 727 | break; |
246 | 988 | case 10: |
247 | 988 | SStream_concat(O, "*%s--%c%u%c", getRegisterName(base), st, |
248 | 988 | offset, nd); |
249 | 988 | break; |
250 | 1.31k | case 11: |
251 | 1.31k | SStream_concat(O, "*%s++%c%u%c", getRegisterName(base), st, |
252 | 1.31k | offset, nd); |
253 | 1.31k | break; |
254 | 387 | case 12: |
255 | 387 | SStream_concat(O, "*--%s%c%s%c", getRegisterName(base), st, |
256 | 387 | getRegisterName(offset), nd); |
257 | 387 | break; |
258 | 413 | case 13: |
259 | 413 | SStream_concat(O, "*++%s%c%s%c", getRegisterName(base), st, |
260 | 413 | getRegisterName(offset), nd); |
261 | 413 | break; |
262 | 262 | case 14: |
263 | 262 | SStream_concat(O, "*%s--%c%s%c", getRegisterName(base), st, |
264 | 262 | getRegisterName(offset), nd); |
265 | 262 | break; |
266 | 858 | case 15: |
267 | 858 | SStream_concat(O, "*%s++%c%s%c", getRegisterName(base), st, |
268 | 858 | getRegisterName(offset), nd); |
269 | 858 | break; |
270 | 7.48k | } |
271 | | |
272 | 7.48k | if (MI->csh->detail_opt) { |
273 | 7.48k | tms320c64x = &MI->flat_insn->detail->tms320c64x; |
274 | | |
275 | 7.48k | tms320c64x->operands[tms320c64x->op_count].type = |
276 | 7.48k | TMS320C64X_OP_MEM; |
277 | 7.48k | tms320c64x->operands[tms320c64x->op_count].mem.base = base; |
278 | 7.48k | tms320c64x->operands[tms320c64x->op_count].mem.disp = offset; |
279 | 7.48k | tms320c64x->operands[tms320c64x->op_count].mem.unit = unit + 1; |
280 | 7.48k | tms320c64x->operands[tms320c64x->op_count].mem.scaled = scaled; |
281 | 7.48k | switch (mode) { |
282 | 706 | case 0: |
283 | 706 | tms320c64x->operands[tms320c64x->op_count].mem.disptype = |
284 | 706 | TMS320C64X_MEM_DISP_CONSTANT; |
285 | 706 | tms320c64x->operands[tms320c64x->op_count] |
286 | 706 | .mem.direction = TMS320C64X_MEM_DIR_BW; |
287 | 706 | tms320c64x->operands[tms320c64x->op_count].mem.modify = |
288 | 706 | TMS320C64X_MEM_MOD_NO; |
289 | 706 | break; |
290 | 494 | case 1: |
291 | 494 | tms320c64x->operands[tms320c64x->op_count].mem.disptype = |
292 | 494 | TMS320C64X_MEM_DISP_CONSTANT; |
293 | 494 | tms320c64x->operands[tms320c64x->op_count] |
294 | 494 | .mem.direction = TMS320C64X_MEM_DIR_FW; |
295 | 494 | tms320c64x->operands[tms320c64x->op_count].mem.modify = |
296 | 494 | TMS320C64X_MEM_MOD_NO; |
297 | 494 | break; |
298 | 660 | case 4: |
299 | 660 | tms320c64x->operands[tms320c64x->op_count].mem.disptype = |
300 | 660 | TMS320C64X_MEM_DISP_REGISTER; |
301 | 660 | tms320c64x->operands[tms320c64x->op_count] |
302 | 660 | .mem.direction = TMS320C64X_MEM_DIR_BW; |
303 | 660 | tms320c64x->operands[tms320c64x->op_count].mem.modify = |
304 | 660 | TMS320C64X_MEM_MOD_NO; |
305 | 660 | break; |
306 | 101 | case 5: |
307 | 101 | tms320c64x->operands[tms320c64x->op_count].mem.disptype = |
308 | 101 | TMS320C64X_MEM_DISP_REGISTER; |
309 | 101 | tms320c64x->operands[tms320c64x->op_count] |
310 | 101 | .mem.direction = TMS320C64X_MEM_DIR_FW; |
311 | 101 | tms320c64x->operands[tms320c64x->op_count].mem.modify = |
312 | 101 | TMS320C64X_MEM_MOD_NO; |
313 | 101 | break; |
314 | 574 | case 8: |
315 | 574 | tms320c64x->operands[tms320c64x->op_count].mem.disptype = |
316 | 574 | TMS320C64X_MEM_DISP_CONSTANT; |
317 | 574 | tms320c64x->operands[tms320c64x->op_count] |
318 | 574 | .mem.direction = TMS320C64X_MEM_DIR_BW; |
319 | 574 | tms320c64x->operands[tms320c64x->op_count].mem.modify = |
320 | 574 | TMS320C64X_MEM_MOD_PRE; |
321 | 574 | break; |
322 | 727 | case 9: |
323 | 727 | tms320c64x->operands[tms320c64x->op_count].mem.disptype = |
324 | 727 | TMS320C64X_MEM_DISP_CONSTANT; |
325 | 727 | tms320c64x->operands[tms320c64x->op_count] |
326 | 727 | .mem.direction = TMS320C64X_MEM_DIR_FW; |
327 | 727 | tms320c64x->operands[tms320c64x->op_count].mem.modify = |
328 | 727 | TMS320C64X_MEM_MOD_PRE; |
329 | 727 | break; |
330 | 988 | case 10: |
331 | 988 | tms320c64x->operands[tms320c64x->op_count].mem.disptype = |
332 | 988 | TMS320C64X_MEM_DISP_CONSTANT; |
333 | 988 | tms320c64x->operands[tms320c64x->op_count] |
334 | 988 | .mem.direction = TMS320C64X_MEM_DIR_BW; |
335 | 988 | tms320c64x->operands[tms320c64x->op_count].mem.modify = |
336 | 988 | TMS320C64X_MEM_MOD_POST; |
337 | 988 | break; |
338 | 1.31k | case 11: |
339 | 1.31k | tms320c64x->operands[tms320c64x->op_count].mem.disptype = |
340 | 1.31k | TMS320C64X_MEM_DISP_CONSTANT; |
341 | 1.31k | tms320c64x->operands[tms320c64x->op_count] |
342 | 1.31k | .mem.direction = TMS320C64X_MEM_DIR_FW; |
343 | 1.31k | tms320c64x->operands[tms320c64x->op_count].mem.modify = |
344 | 1.31k | TMS320C64X_MEM_MOD_POST; |
345 | 1.31k | break; |
346 | 387 | case 12: |
347 | 387 | tms320c64x->operands[tms320c64x->op_count].mem.disptype = |
348 | 387 | TMS320C64X_MEM_DISP_REGISTER; |
349 | 387 | tms320c64x->operands[tms320c64x->op_count] |
350 | 387 | .mem.direction = TMS320C64X_MEM_DIR_BW; |
351 | 387 | tms320c64x->operands[tms320c64x->op_count].mem.modify = |
352 | 387 | TMS320C64X_MEM_MOD_PRE; |
353 | 387 | break; |
354 | 413 | case 13: |
355 | 413 | tms320c64x->operands[tms320c64x->op_count].mem.disptype = |
356 | 413 | TMS320C64X_MEM_DISP_REGISTER; |
357 | 413 | tms320c64x->operands[tms320c64x->op_count] |
358 | 413 | .mem.direction = TMS320C64X_MEM_DIR_FW; |
359 | 413 | tms320c64x->operands[tms320c64x->op_count].mem.modify = |
360 | 413 | TMS320C64X_MEM_MOD_PRE; |
361 | 413 | break; |
362 | 262 | case 14: |
363 | 262 | tms320c64x->operands[tms320c64x->op_count].mem.disptype = |
364 | 262 | TMS320C64X_MEM_DISP_REGISTER; |
365 | 262 | tms320c64x->operands[tms320c64x->op_count] |
366 | 262 | .mem.direction = TMS320C64X_MEM_DIR_BW; |
367 | 262 | tms320c64x->operands[tms320c64x->op_count].mem.modify = |
368 | 262 | TMS320C64X_MEM_MOD_POST; |
369 | 262 | break; |
370 | 858 | case 15: |
371 | 858 | tms320c64x->operands[tms320c64x->op_count].mem.disptype = |
372 | 858 | TMS320C64X_MEM_DISP_REGISTER; |
373 | 858 | tms320c64x->operands[tms320c64x->op_count] |
374 | 858 | .mem.direction = TMS320C64X_MEM_DIR_FW; |
375 | 858 | tms320c64x->operands[tms320c64x->op_count].mem.modify = |
376 | 858 | TMS320C64X_MEM_MOD_POST; |
377 | 858 | break; |
378 | 7.48k | } |
379 | 7.48k | tms320c64x->op_count++; |
380 | 7.48k | } |
381 | 7.48k | } |
382 | | |
383 | | static void printMemOperand2(MCInst *MI, unsigned OpNo, SStream *O) |
384 | 8.22k | { |
385 | 8.22k | MCOperand *Op = MCInst_getOperand(MI, OpNo); |
386 | 8.22k | int64_t Val = MCOperand_getImm(Op); |
387 | 8.22k | uint16_t offset; |
388 | 8.22k | unsigned basereg; |
389 | 8.22k | cs_tms320c64x *tms320c64x; |
390 | | |
391 | 8.22k | basereg = Val & 0x7f; |
392 | 8.22k | offset = (Val >> 7) & 0x7fff; |
393 | 8.22k | SStream_concat(O, "*+%s[0x%x]", getRegisterName(basereg), offset); |
394 | | |
395 | 8.22k | if (MI->csh->detail_opt) { |
396 | 8.22k | tms320c64x = &MI->flat_insn->detail->tms320c64x; |
397 | | |
398 | 8.22k | tms320c64x->operands[tms320c64x->op_count].type = |
399 | 8.22k | TMS320C64X_OP_MEM; |
400 | 8.22k | tms320c64x->operands[tms320c64x->op_count].mem.base = basereg; |
401 | 8.22k | tms320c64x->operands[tms320c64x->op_count].mem.unit = 2; |
402 | 8.22k | tms320c64x->operands[tms320c64x->op_count].mem.disp = offset; |
403 | 8.22k | tms320c64x->operands[tms320c64x->op_count].mem.disptype = |
404 | 8.22k | TMS320C64X_MEM_DISP_CONSTANT; |
405 | 8.22k | tms320c64x->operands[tms320c64x->op_count].mem.direction = |
406 | 8.22k | TMS320C64X_MEM_DIR_FW; |
407 | 8.22k | tms320c64x->operands[tms320c64x->op_count].mem.modify = |
408 | 8.22k | TMS320C64X_MEM_MOD_NO; |
409 | 8.22k | tms320c64x->op_count++; |
410 | 8.22k | } |
411 | 8.22k | } |
412 | | |
413 | | static void printRegPair(MCInst *MI, unsigned OpNo, SStream *O) |
414 | 22.8k | { |
415 | 22.8k | MCOperand *Op = MCInst_getOperand(MI, OpNo); |
416 | 22.8k | unsigned reg = MCOperand_getReg(Op); |
417 | 22.8k | cs_tms320c64x *tms320c64x; |
418 | | |
419 | 22.8k | SStream_concat(O, "%s:%s", getRegisterName(reg + 1), |
420 | 22.8k | getRegisterName(reg)); |
421 | | |
422 | 22.8k | if (MI->csh->detail_opt) { |
423 | 22.8k | tms320c64x = &MI->flat_insn->detail->tms320c64x; |
424 | | |
425 | 22.8k | tms320c64x->operands[tms320c64x->op_count].type = |
426 | 22.8k | TMS320C64X_OP_REGPAIR; |
427 | 22.8k | tms320c64x->operands[tms320c64x->op_count].reg = reg; |
428 | 22.8k | tms320c64x->op_count++; |
429 | 22.8k | } |
430 | 22.8k | } |
431 | | |
432 | | static bool printAliasInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI) |
433 | 75.0k | { |
434 | 75.0k | unsigned opcode = MCInst_getOpcode(MI); |
435 | 75.0k | MCOperand *op; |
436 | | |
437 | 75.0k | switch (opcode) { |
438 | | /* ADD.Dx -i, x, y -> SUB.Dx x, i, y */ |
439 | 78 | case TMS320C64x_ADD_d2_rir: |
440 | | /* ADD.L -i, x, y -> SUB.L x, i, y */ |
441 | 582 | case TMS320C64x_ADD_l1_irr: |
442 | 885 | case TMS320C64x_ADD_l1_ipp: |
443 | | /* ADD.S -i, x, y -> SUB.S x, i, y */ |
444 | 1.51k | case TMS320C64x_ADD_s1_irr: |
445 | 1.51k | if ((MCInst_getNumOperands(MI) == 3) && |
446 | 1.51k | MCOperand_isReg(MCInst_getOperand(MI, 0)) && |
447 | 1.51k | MCOperand_isReg(MCInst_getOperand(MI, 1)) && |
448 | 1.51k | MCOperand_isImm(MCInst_getOperand(MI, 2)) && |
449 | 1.51k | (MCOperand_getImm(MCInst_getOperand(MI, 2)) < 0)) { |
450 | 258 | MCInst_setOpcodePub(MI, TMS320C64X_INS_SUB); |
451 | 258 | op = MCInst_getOperand(MI, 2); |
452 | 258 | MCOperand_setImm(op, -MCOperand_getImm(op)); |
453 | | |
454 | 258 | SStream_concat0(O, "SUB\t"); |
455 | 258 | printOperand(MI, 1, O); |
456 | 258 | SStream_concat0(O, ", "); |
457 | 258 | printOperand(MI, 2, O); |
458 | 258 | SStream_concat0(O, ", "); |
459 | 258 | printOperand(MI, 0, O); |
460 | | |
461 | 258 | return true; |
462 | 258 | } |
463 | 1.25k | break; |
464 | 75.0k | } |
465 | 74.7k | switch (opcode) { |
466 | | /* ADD.D 0, x, y -> MV.D x, y */ |
467 | 225 | case TMS320C64x_ADD_d1_rir: |
468 | | /* OR.D x, 0, y -> MV.D x, y */ |
469 | 358 | case TMS320C64x_OR_d2_rir: |
470 | | /* ADD.L 0, x, y -> MV.L x, y */ |
471 | 649 | case TMS320C64x_ADD_l1_irr: |
472 | 943 | case TMS320C64x_ADD_l1_ipp: |
473 | | /* OR.L 0, x, y -> MV.L x, y */ |
474 | 1.05k | case TMS320C64x_OR_l1_irr: |
475 | | /* ADD.S 0, x, y -> MV.S x, y */ |
476 | 1.65k | case TMS320C64x_ADD_s1_irr: |
477 | | /* OR.S 0, x, y -> MV.S x, y */ |
478 | 2.04k | case TMS320C64x_OR_s1_irr: |
479 | 2.04k | if ((MCInst_getNumOperands(MI) == 3) && |
480 | 2.04k | MCOperand_isReg(MCInst_getOperand(MI, 0)) && |
481 | 2.04k | MCOperand_isReg(MCInst_getOperand(MI, 1)) && |
482 | 2.04k | MCOperand_isImm(MCInst_getOperand(MI, 2)) && |
483 | 2.04k | (MCOperand_getImm(MCInst_getOperand(MI, 2)) == 0)) { |
484 | 360 | MCInst_setOpcodePub(MI, TMS320C64X_INS_MV); |
485 | 360 | MI->size--; |
486 | | |
487 | 360 | SStream_concat0(O, "MV\t"); |
488 | 360 | printOperand(MI, 1, O); |
489 | 360 | SStream_concat0(O, ", "); |
490 | 360 | printOperand(MI, 0, O); |
491 | | |
492 | 360 | return true; |
493 | 360 | } |
494 | 1.68k | break; |
495 | 74.7k | } |
496 | 74.4k | switch (opcode) { |
497 | | /* XOR.D -1, x, y -> NOT.D x, y */ |
498 | 186 | case TMS320C64x_XOR_d2_rir: |
499 | | /* XOR.L -1, x, y -> NOT.L x, y */ |
500 | 730 | case TMS320C64x_XOR_l1_irr: |
501 | | /* XOR.S -1, x, y -> NOT.S x, y */ |
502 | 1.27k | case TMS320C64x_XOR_s1_irr: |
503 | 1.27k | if ((MCInst_getNumOperands(MI) == 3) && |
504 | 1.27k | MCOperand_isReg(MCInst_getOperand(MI, 0)) && |
505 | 1.27k | MCOperand_isReg(MCInst_getOperand(MI, 1)) && |
506 | 1.27k | MCOperand_isImm(MCInst_getOperand(MI, 2)) && |
507 | 1.27k | (MCOperand_getImm(MCInst_getOperand(MI, 2)) == -1)) { |
508 | 431 | MCInst_setOpcodePub(MI, TMS320C64X_INS_NOT); |
509 | 431 | MI->size--; |
510 | | |
511 | 431 | SStream_concat0(O, "NOT\t"); |
512 | 431 | printOperand(MI, 1, O); |
513 | 431 | SStream_concat0(O, ", "); |
514 | 431 | printOperand(MI, 0, O); |
515 | | |
516 | 431 | return true; |
517 | 431 | } |
518 | 844 | break; |
519 | 74.4k | } |
520 | 74.0k | switch (opcode) { |
521 | | /* MVK.D 0, x -> ZERO.D x */ |
522 | 635 | case TMS320C64x_MVK_d1_rr: |
523 | | /* MVK.L 0, x -> ZERO.L x */ |
524 | 2.01k | case TMS320C64x_MVK_l2_ir: |
525 | 2.01k | if ((MCInst_getNumOperands(MI) == 2) && |
526 | 2.01k | MCOperand_isReg(MCInst_getOperand(MI, 0)) && |
527 | 2.01k | MCOperand_isImm(MCInst_getOperand(MI, 1)) && |
528 | 2.01k | (MCOperand_getImm(MCInst_getOperand(MI, 1)) == 0)) { |
529 | 347 | MCInst_setOpcodePub(MI, TMS320C64X_INS_ZERO); |
530 | 347 | MI->size--; |
531 | | |
532 | 347 | SStream_concat0(O, "ZERO\t"); |
533 | 347 | printOperand(MI, 0, O); |
534 | | |
535 | 347 | return true; |
536 | 347 | } |
537 | 1.67k | break; |
538 | 74.0k | } |
539 | 73.6k | switch (opcode) { |
540 | | /* SUB.L x, x, y -> ZERO.L y */ |
541 | 222 | case TMS320C64x_SUB_l1_rrp_x1: |
542 | | /* SUB.S x, x, y -> ZERO.S y */ |
543 | 606 | case TMS320C64x_SUB_s1_rrr: |
544 | 606 | if ((MCInst_getNumOperands(MI) == 3) && |
545 | 606 | MCOperand_isReg(MCInst_getOperand(MI, 0)) && |
546 | 606 | MCOperand_isReg(MCInst_getOperand(MI, 1)) && |
547 | 606 | MCOperand_isReg(MCInst_getOperand(MI, 2)) && |
548 | 606 | (MCOperand_getReg(MCInst_getOperand(MI, 1)) == |
549 | 606 | MCOperand_getReg(MCInst_getOperand(MI, 2)))) { |
550 | 266 | MCInst_setOpcodePub(MI, TMS320C64X_INS_ZERO); |
551 | 266 | MI->size -= 2; |
552 | | |
553 | 266 | SStream_concat0(O, "ZERO\t"); |
554 | 266 | printOperand(MI, 0, O); |
555 | | |
556 | 266 | return true; |
557 | 266 | } |
558 | 340 | break; |
559 | 73.6k | } |
560 | 73.3k | switch (opcode) { |
561 | | /* SUB.L 0, x, y -> NEG.L x, y */ |
562 | 136 | case TMS320C64x_SUB_l1_irr: |
563 | 500 | case TMS320C64x_SUB_l1_ipp: |
564 | | /* SUB.S 0, x, y -> NEG.S x, y */ |
565 | 652 | case TMS320C64x_SUB_s1_irr: |
566 | 652 | if ((MCInst_getNumOperands(MI) == 3) && |
567 | 652 | MCOperand_isReg(MCInst_getOperand(MI, 0)) && |
568 | 652 | MCOperand_isReg(MCInst_getOperand(MI, 1)) && |
569 | 652 | MCOperand_isImm(MCInst_getOperand(MI, 2)) && |
570 | 652 | (MCOperand_getImm(MCInst_getOperand(MI, 2)) == 0)) { |
571 | 129 | MCInst_setOpcodePub(MI, TMS320C64X_INS_NEG); |
572 | 129 | MI->size--; |
573 | | |
574 | 129 | SStream_concat0(O, "NEG\t"); |
575 | 129 | printOperand(MI, 1, O); |
576 | 129 | SStream_concat0(O, ", "); |
577 | 129 | printOperand(MI, 0, O); |
578 | | |
579 | 129 | return true; |
580 | 129 | } |
581 | 523 | break; |
582 | 73.3k | } |
583 | 73.2k | switch (opcode) { |
584 | | /* PACKLH2.L x, x, y -> SWAP2.L x, y */ |
585 | 405 | case TMS320C64x_PACKLH2_l1_rrr_x2: |
586 | | /* PACKLH2.S x, x, y -> SWAP2.S x, y */ |
587 | 1.18k | case TMS320C64x_PACKLH2_s1_rrr: |
588 | 1.18k | if ((MCInst_getNumOperands(MI) == 3) && |
589 | 1.18k | MCOperand_isReg(MCInst_getOperand(MI, 0)) && |
590 | 1.18k | MCOperand_isReg(MCInst_getOperand(MI, 1)) && |
591 | 1.18k | MCOperand_isReg(MCInst_getOperand(MI, 2)) && |
592 | 1.18k | (MCOperand_getReg(MCInst_getOperand(MI, 1)) == |
593 | 1.18k | MCOperand_getReg(MCInst_getOperand(MI, 2)))) { |
594 | 443 | MCInst_setOpcodePub(MI, TMS320C64X_INS_SWAP2); |
595 | 443 | MI->size--; |
596 | | |
597 | 443 | SStream_concat0(O, "SWAP2\t"); |
598 | 443 | printOperand(MI, 1, O); |
599 | 443 | SStream_concat0(O, ", "); |
600 | 443 | printOperand(MI, 0, O); |
601 | | |
602 | 443 | return true; |
603 | 443 | } |
604 | 743 | break; |
605 | 73.2k | } |
606 | 72.8k | switch (opcode) { |
607 | | /* NOP 16 -> IDLE */ |
608 | | /* NOP 1 -> NOP */ |
609 | 2.21k | case TMS320C64x_NOP_n: |
610 | 2.21k | if ((MCInst_getNumOperands(MI) == 1) && |
611 | 2.21k | MCOperand_isImm(MCInst_getOperand(MI, 0)) && |
612 | 2.21k | (MCOperand_getReg(MCInst_getOperand(MI, 0)) == 16)) { |
613 | 298 | MCInst_setOpcodePub(MI, TMS320C64X_INS_IDLE); |
614 | 298 | MI->size--; |
615 | | |
616 | 298 | SStream_concat0(O, "IDLE"); |
617 | | |
618 | 298 | return true; |
619 | 298 | } |
620 | 1.91k | if ((MCInst_getNumOperands(MI) == 1) && |
621 | 1.91k | MCOperand_isImm(MCInst_getOperand(MI, 0)) && |
622 | 1.91k | (MCOperand_getReg(MCInst_getOperand(MI, 0)) == 1)) { |
623 | 1.52k | MI->size--; |
624 | | |
625 | 1.52k | SStream_concat0(O, "NOP"); |
626 | | |
627 | 1.52k | return true; |
628 | 1.52k | } |
629 | 389 | break; |
630 | 72.8k | } |
631 | | |
632 | 70.9k | return false; |
633 | 72.8k | } |
634 | | |
635 | | void TMS320C64x_printInst(MCInst *MI, SStream *O, void *Info) |
636 | 75.0k | { |
637 | 75.0k | if (!printAliasInstruction(MI, O, Info)) |
638 | 70.9k | printInstruction(MI, O, Info); |
639 | 75.0k | } |
640 | | |
641 | | #endif |