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