/src/capstonev5/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  |  | #ifdef _MSC_VER  | 
7  |  | // Disable security warnings for strcpy  | 
8  |  | #ifndef _CRT_SECURE_NO_WARNINGS  | 
9  |  | #define _CRT_SECURE_NO_WARNINGS  | 
10  |  | #endif  | 
11  |  |  | 
12  |  | // Banned API Usage : strcpy is a Banned API as listed in dontuse.h for  | 
13  |  | // security purposes.  | 
14  |  | #pragma warning(disable:28719)  | 
15  |  | #endif  | 
16  |  |  | 
17  |  | #include <ctype.h>  | 
18  |  | #include <string.h>  | 
19  |  |  | 
20  |  | #include "TMS320C64xInstPrinter.h"  | 
21  |  | #include "../../MCInst.h"  | 
22  |  | #include "../../utils.h"  | 
23  |  | #include "../../SStream.h"  | 
24  |  | #include "../../MCRegisterInfo.h"  | 
25  |  | #include "../../MathExtras.h"  | 
26  |  | #include "TMS320C64xMapping.h"  | 
27  |  |  | 
28  |  | #include "capstone/tms320c64x.h"  | 
29  |  |  | 
30  |  | static const char *getRegisterName(unsigned RegNo);  | 
31  |  | static void printOperand(MCInst *MI, unsigned OpNo, SStream *O);  | 
32  |  | static void printMemOperand(MCInst *MI, unsigned OpNo, SStream *O);  | 
33  |  | static void printMemOperand2(MCInst *MI, unsigned OpNo, SStream *O);  | 
34  |  | static void printRegPair(MCInst *MI, unsigned OpNo, SStream *O);  | 
35  |  |  | 
36  |  | void TMS320C64x_post_printer(csh ud, cs_insn *insn, char *insn_asm, MCInst *mci)  | 
37  | 41.7k  | { | 
38  | 41.7k  |   SStream ss;  | 
39  | 41.7k  |   char *p, *p2, tmp[8];  | 
40  | 41.7k  |   unsigned int unit = 0;  | 
41  | 41.7k  |   int i;  | 
42  | 41.7k  |   cs_tms320c64x *tms320c64x;  | 
43  |  |  | 
44  | 41.7k  |   if (mci->csh->detail) { | 
45  | 41.7k  |     tms320c64x = &mci->flat_insn->detail->tms320c64x;  | 
46  |  |  | 
47  | 41.7k  |     for (i = 0; i < insn->detail->groups_count; i++) { | 
48  | 41.7k  |       switch(insn->detail->groups[i]) { | 
49  | 9.83k  |         case TMS320C64X_GRP_FUNIT_D:  | 
50  | 9.83k  |           unit = TMS320C64X_FUNIT_D;  | 
51  | 9.83k  |           break;  | 
52  | 8.96k  |         case TMS320C64X_GRP_FUNIT_L:  | 
53  | 8.96k  |           unit = TMS320C64X_FUNIT_L;  | 
54  | 8.96k  |           break;  | 
55  | 2.61k  |         case TMS320C64X_GRP_FUNIT_M:  | 
56  | 2.61k  |           unit = TMS320C64X_FUNIT_M;  | 
57  | 2.61k  |           break;  | 
58  | 19.1k  |         case TMS320C64X_GRP_FUNIT_S:  | 
59  | 19.1k  |           unit = TMS320C64X_FUNIT_S;  | 
60  | 19.1k  |           break;  | 
61  | 1.16k  |         case TMS320C64X_GRP_FUNIT_NO:  | 
62  | 1.16k  |           unit = TMS320C64X_FUNIT_NO;  | 
63  | 1.16k  |           break;  | 
64  | 41.7k  |       }  | 
65  | 41.7k  |       if (unit != 0)  | 
66  | 41.7k  |         break;  | 
67  | 41.7k  |     }  | 
68  | 41.7k  |     tms320c64x->funit.unit = unit;  | 
69  |  |  | 
70  | 41.7k  |     SStream_Init(&ss);  | 
71  | 41.7k  |     if (tms320c64x->condition.reg != TMS320C64X_REG_INVALID)  | 
72  | 27.1k  |       SStream_concat(&ss, "[%c%s]|", (tms320c64x->condition.zero == 1) ? '!' : '|', cs_reg_name(ud, tms320c64x->condition.reg));  | 
73  |  |  | 
74  | 41.7k  |     p = strchr(insn_asm, '\t');  | 
75  | 41.7k  |     if (p != NULL)  | 
76  | 41.0k  |       *p++ = '\0';  | 
77  |  |  | 
78  | 41.7k  |     SStream_concat0(&ss, insn_asm);  | 
79  | 41.7k  |     if ((p != NULL) && (((p2 = strchr(p, '[')) != NULL) || ((p2 = strchr(p, '(')) != NULL))) { | 
80  | 27.7k  |       while ((p2 > p) && ((*p2 != 'a') && (*p2 != 'b')))  | 
81  | 21.1k  |         p2--;  | 
82  | 6.56k  |       if (p2 == p) { | 
83  | 0  |         strcpy(insn_asm, "Invalid!");  | 
84  | 0  |         return;  | 
85  | 0  |       }  | 
86  | 6.56k  |       if (*p2 == 'a')  | 
87  | 4.30k  |         strcpy(tmp, "1T");  | 
88  | 2.26k  |       else  | 
89  | 2.26k  |         strcpy(tmp, "2T");  | 
90  | 35.1k  |     } else { | 
91  | 35.1k  |       tmp[0] = '\0';  | 
92  | 35.1k  |     }  | 
93  | 41.7k  |     switch(tms320c64x->funit.unit) { | 
94  | 9.83k  |       case TMS320C64X_FUNIT_D:  | 
95  | 9.83k  |         SStream_concat(&ss, ".D%s%u", tmp, tms320c64x->funit.side);  | 
96  | 9.83k  |         break;  | 
97  | 8.96k  |       case TMS320C64X_FUNIT_L:  | 
98  | 8.96k  |         SStream_concat(&ss, ".L%s%u", tmp, tms320c64x->funit.side);  | 
99  | 8.96k  |         break;  | 
100  | 2.61k  |       case TMS320C64X_FUNIT_M:  | 
101  | 2.61k  |         SStream_concat(&ss, ".M%s%u", tmp, tms320c64x->funit.side);  | 
102  | 2.61k  |         break;  | 
103  | 19.1k  |       case TMS320C64X_FUNIT_S:  | 
104  | 19.1k  |         SStream_concat(&ss, ".S%s%u", tmp, tms320c64x->funit.side);  | 
105  | 19.1k  |         break;  | 
106  | 41.7k  |     }  | 
107  | 41.7k  |     if (tms320c64x->funit.crosspath > 0)  | 
108  | 13.9k  |       SStream_concat0(&ss, "X");  | 
109  |  |  | 
110  | 41.7k  |     if (p != NULL)  | 
111  | 41.0k  |       SStream_concat(&ss, "\t%s", p);  | 
112  |  |  | 
113  | 41.7k  |     if (tms320c64x->parallel != 0)  | 
114  | 21.1k  |       SStream_concat0(&ss, "\t||");  | 
115  |  |  | 
116  |  |     /* insn_asm is a buffer from an SStream, so there should be enough space */  | 
117  | 41.7k  |     strcpy(insn_asm, ss.buffer);  | 
118  | 41.7k  |   }  | 
119  | 41.7k  | }  | 
120  |  |  | 
121  |  | #define PRINT_ALIAS_INSTR  | 
122  |  | #include "TMS320C64xGenAsmWriter.inc"  | 
123  |  |  | 
124  |  | #define GET_INSTRINFO_ENUM  | 
125  |  | #include "TMS320C64xGenInstrInfo.inc"  | 
126  |  |  | 
127  |  | static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)  | 
128  | 138k  | { | 
129  | 138k  |   MCOperand *Op = MCInst_getOperand(MI, OpNo);  | 
130  | 138k  |   unsigned reg;  | 
131  |  |  | 
132  | 138k  |   if (MCOperand_isReg(Op)) { | 
133  | 99.8k  |     reg = MCOperand_getReg(Op);  | 
134  | 99.8k  |     if ((MCInst_getOpcode(MI) == TMS320C64x_MVC_s1_rr) && (OpNo == 1)) { | 
135  | 4.80k  |       switch(reg) { | 
136  | 2.07k  |         case TMS320C64X_REG_EFR:  | 
137  | 2.07k  |           SStream_concat0(O, "EFR");  | 
138  | 2.07k  |           break;  | 
139  | 1.38k  |         case TMS320C64X_REG_IFR:  | 
140  | 1.38k  |           SStream_concat0(O, "IFR");  | 
141  | 1.38k  |           break;  | 
142  | 1.34k  |         default:  | 
143  | 1.34k  |           SStream_concat0(O, getRegisterName(reg));  | 
144  | 1.34k  |           break;  | 
145  | 4.80k  |       }  | 
146  | 95.0k  |     } else { | 
147  | 95.0k  |       SStream_concat0(O, getRegisterName(reg));  | 
148  | 95.0k  |     }  | 
149  |  |  | 
150  | 99.8k  |     if (MI->csh->detail) { | 
151  | 99.8k  |       MI->flat_insn->detail->tms320c64x.operands[MI->flat_insn->detail->tms320c64x.op_count].type = TMS320C64X_OP_REG;  | 
152  | 99.8k  |       MI->flat_insn->detail->tms320c64x.operands[MI->flat_insn->detail->tms320c64x.op_count].reg = reg;  | 
153  | 99.8k  |       MI->flat_insn->detail->tms320c64x.op_count++;  | 
154  | 99.8k  |     }  | 
155  | 99.8k  |   } else if (MCOperand_isImm(Op)) { | 
156  | 39.0k  |     int64_t Imm = MCOperand_getImm(Op);  | 
157  |  |  | 
158  | 39.0k  |     if (Imm >= 0) { | 
159  | 31.8k  |       if (Imm > HEX_THRESHOLD)  | 
160  | 18.0k  |         SStream_concat(O, "0x%"PRIx64, Imm);  | 
161  | 13.7k  |       else  | 
162  | 13.7k  |         SStream_concat(O, "%"PRIu64, Imm);  | 
163  | 31.8k  |     } else { | 
164  | 7.21k  |       if (Imm < -HEX_THRESHOLD)  | 
165  | 5.46k  |         SStream_concat(O, "-0x%"PRIx64, -Imm);  | 
166  | 1.74k  |       else  | 
167  | 1.74k  |         SStream_concat(O, "-%"PRIu64, -Imm);  | 
168  | 7.21k  |     }  | 
169  |  |  | 
170  | 39.0k  |     if (MI->csh->detail) { | 
171  | 39.0k  |       MI->flat_insn->detail->tms320c64x.operands[MI->flat_insn->detail->tms320c64x.op_count].type = TMS320C64X_OP_IMM;  | 
172  | 39.0k  |       MI->flat_insn->detail->tms320c64x.operands[MI->flat_insn->detail->tms320c64x.op_count].imm = Imm;  | 
173  | 39.0k  |       MI->flat_insn->detail->tms320c64x.op_count++;  | 
174  | 39.0k  |     }  | 
175  | 39.0k  |   }  | 
176  | 138k  | }  | 
177  |  |  | 
178  |  | static void printMemOperand(MCInst *MI, unsigned OpNo, SStream *O)  | 
179  | 8.85k  | { | 
180  | 8.85k  |   MCOperand *Op = MCInst_getOperand(MI, OpNo);  | 
181  | 8.85k  |   int64_t Val = MCOperand_getImm(Op);  | 
182  | 8.85k  |   unsigned scaled, base, offset, mode, unit;  | 
183  | 8.85k  |   cs_tms320c64x *tms320c64x;  | 
184  | 8.85k  |   char st, nd;  | 
185  |  |  | 
186  | 8.85k  |   scaled = (Val >> 19) & 1;  | 
187  | 8.85k  |   base = (Val >> 12) & 0x7f;  | 
188  | 8.85k  |   offset = (Val >> 5) & 0x7f;  | 
189  | 8.85k  |   mode = (Val >> 1) & 0xf;  | 
190  | 8.85k  |   unit = Val & 1;  | 
191  |  |  | 
192  | 8.85k  |   if (scaled) { | 
193  | 7.75k  |     st = '[';  | 
194  | 7.75k  |     nd = ']';  | 
195  | 7.75k  |   } else { | 
196  | 1.09k  |     st = '('; | 
197  | 1.09k  |     nd = ')';  | 
198  | 1.09k  |   }  | 
199  |  |  | 
200  | 8.85k  |   switch(mode) { | 
201  | 1.07k  |     case 0:  | 
202  | 1.07k  |       SStream_concat(O, "*-%s%c%u%c", getRegisterName(base), st, offset, nd);  | 
203  | 1.07k  |       break;  | 
204  | 674  |     case 1:  | 
205  | 674  |       SStream_concat(O, "*+%s%c%u%c", getRegisterName(base), st, offset, nd);  | 
206  | 674  |       break;  | 
207  | 452  |     case 4:  | 
208  | 452  |       SStream_concat(O, "*-%s%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);  | 
209  | 452  |       break;  | 
210  | 462  |     case 5:  | 
211  | 462  |       SStream_concat(O, "*+%s%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);  | 
212  | 462  |       break;  | 
213  | 444  |     case 8:  | 
214  | 444  |       SStream_concat(O, "*--%s%c%u%c", getRegisterName(base), st, offset, nd);  | 
215  | 444  |       break;  | 
216  | 1.30k  |     case 9:  | 
217  | 1.30k  |       SStream_concat(O, "*++%s%c%u%c", getRegisterName(base), st, offset, nd);  | 
218  | 1.30k  |       break;  | 
219  | 916  |     case 10:  | 
220  | 916  |       SStream_concat(O, "*%s--%c%u%c", getRegisterName(base), st, offset, nd);  | 
221  | 916  |       break;  | 
222  | 1.24k  |     case 11:  | 
223  | 1.24k  |       SStream_concat(O, "*%s++%c%u%c", getRegisterName(base), st, offset, nd);  | 
224  | 1.24k  |       break;  | 
225  | 592  |     case 12:  | 
226  | 592  |       SStream_concat(O, "*--%s%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);  | 
227  | 592  |       break;  | 
228  | 475  |     case 13:  | 
229  | 475  |       SStream_concat(O, "*++%s%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);  | 
230  | 475  |       break;  | 
231  | 571  |     case 14:  | 
232  | 571  |       SStream_concat(O, "*%s--%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);  | 
233  | 571  |       break;  | 
234  | 653  |     case 15:  | 
235  | 653  |       SStream_concat(O, "*%s++%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);  | 
236  | 653  |       break;  | 
237  | 8.85k  |   }  | 
238  |  |  | 
239  | 8.85k  |   if (MI->csh->detail) { | 
240  | 8.85k  |     tms320c64x = &MI->flat_insn->detail->tms320c64x;  | 
241  |  |  | 
242  | 8.85k  |     tms320c64x->operands[tms320c64x->op_count].type = TMS320C64X_OP_MEM;  | 
243  | 8.85k  |     tms320c64x->operands[tms320c64x->op_count].mem.base = base;  | 
244  | 8.85k  |     tms320c64x->operands[tms320c64x->op_count].mem.disp = offset;  | 
245  | 8.85k  |     tms320c64x->operands[tms320c64x->op_count].mem.unit = unit + 1;  | 
246  | 8.85k  |     tms320c64x->operands[tms320c64x->op_count].mem.scaled = scaled;  | 
247  | 8.85k  |     switch(mode) { | 
248  | 1.07k  |       case 0:  | 
249  | 1.07k  |         tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;  | 
250  | 1.07k  |         tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;  | 
251  | 1.07k  |         tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_NO;  | 
252  | 1.07k  |         break;  | 
253  | 674  |       case 1:  | 
254  | 674  |         tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;  | 
255  | 674  |         tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;  | 
256  | 674  |         tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_NO;  | 
257  | 674  |         break;  | 
258  | 452  |       case 4:  | 
259  | 452  |         tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;  | 
260  | 452  |         tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;  | 
261  | 452  |         tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_NO;  | 
262  | 452  |         break;  | 
263  | 462  |       case 5:  | 
264  | 462  |         tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;  | 
265  | 462  |         tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;  | 
266  | 462  |         tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_NO;  | 
267  | 462  |         break;  | 
268  | 444  |       case 8:  | 
269  | 444  |         tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;  | 
270  | 444  |         tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;  | 
271  | 444  |         tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_PRE;  | 
272  | 444  |         break;  | 
273  | 1.30k  |       case 9:  | 
274  | 1.30k  |         tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;  | 
275  | 1.30k  |         tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;  | 
276  | 1.30k  |         tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_PRE;  | 
277  | 1.30k  |         break;  | 
278  | 916  |       case 10:  | 
279  | 916  |         tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;  | 
280  | 916  |         tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;  | 
281  | 916  |         tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_POST;  | 
282  | 916  |         break;  | 
283  | 1.24k  |       case 11:  | 
284  | 1.24k  |         tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;  | 
285  | 1.24k  |         tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;  | 
286  | 1.24k  |         tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_POST;  | 
287  | 1.24k  |         break;  | 
288  | 592  |       case 12:  | 
289  | 592  |         tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;  | 
290  | 592  |         tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;  | 
291  | 592  |         tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_PRE;  | 
292  | 592  |         break;  | 
293  | 475  |       case 13:  | 
294  | 475  |         tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;  | 
295  | 475  |         tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;  | 
296  | 475  |         tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_PRE;  | 
297  | 475  |         break;  | 
298  | 571  |       case 14:  | 
299  | 571  |         tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;  | 
300  | 571  |         tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;  | 
301  | 571  |         tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_POST;  | 
302  | 571  |         break;  | 
303  | 653  |       case 15:  | 
304  | 653  |         tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;  | 
305  | 653  |         tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;  | 
306  | 653  |         tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_POST;  | 
307  | 653  |         break;  | 
308  | 8.85k  |     }  | 
309  | 8.85k  |     tms320c64x->op_count++;  | 
310  | 8.85k  |   }  | 
311  | 8.85k  | }  | 
312  |  |  | 
313  |  | static void printMemOperand2(MCInst *MI, unsigned OpNo, SStream *O)  | 
314  | 5.20k  | { | 
315  | 5.20k  |   MCOperand *Op = MCInst_getOperand(MI, OpNo);  | 
316  | 5.20k  |   int64_t Val = MCOperand_getImm(Op);  | 
317  | 5.20k  |   uint16_t offset;  | 
318  | 5.20k  |   unsigned basereg;  | 
319  | 5.20k  |   cs_tms320c64x *tms320c64x;  | 
320  |  |  | 
321  | 5.20k  |   basereg = Val & 0x7f;  | 
322  | 5.20k  |   offset = (Val >> 7) & 0x7fff;  | 
323  | 5.20k  |   SStream_concat(O, "*+%s[0x%x]", getRegisterName(basereg), offset);  | 
324  |  |  | 
325  | 5.20k  |   if (MI->csh->detail) { | 
326  | 5.20k  |     tms320c64x = &MI->flat_insn->detail->tms320c64x;  | 
327  |  |  | 
328  | 5.20k  |     tms320c64x->operands[tms320c64x->op_count].type = TMS320C64X_OP_MEM;  | 
329  | 5.20k  |     tms320c64x->operands[tms320c64x->op_count].mem.base = basereg;  | 
330  | 5.20k  |     tms320c64x->operands[tms320c64x->op_count].mem.unit = 2;  | 
331  | 5.20k  |     tms320c64x->operands[tms320c64x->op_count].mem.disp = offset;  | 
332  | 5.20k  |     tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;  | 
333  | 5.20k  |     tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;  | 
334  | 5.20k  |     tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_NO;  | 
335  | 5.20k  |     tms320c64x->op_count++;  | 
336  | 5.20k  |   }  | 
337  | 5.20k  | }  | 
338  |  |  | 
339  |  | static void printRegPair(MCInst *MI, unsigned OpNo, SStream *O)  | 
340  | 26.5k  | { | 
341  | 26.5k  |   MCOperand *Op = MCInst_getOperand(MI, OpNo);  | 
342  | 26.5k  |   unsigned reg = MCOperand_getReg(Op);  | 
343  | 26.5k  |   cs_tms320c64x *tms320c64x;  | 
344  |  |  | 
345  | 26.5k  |   SStream_concat(O, "%s:%s", getRegisterName(reg + 1), getRegisterName(reg));  | 
346  |  |  | 
347  | 26.5k  |   if (MI->csh->detail) { | 
348  | 26.5k  |     tms320c64x = &MI->flat_insn->detail->tms320c64x;  | 
349  |  |  | 
350  | 26.5k  |     tms320c64x->operands[tms320c64x->op_count].type = TMS320C64X_OP_REGPAIR;  | 
351  | 26.5k  |     tms320c64x->operands[tms320c64x->op_count].reg = reg;  | 
352  | 26.5k  |     tms320c64x->op_count++;  | 
353  | 26.5k  |   }  | 
354  | 26.5k  | }  | 
355  |  |  | 
356  |  | static bool printAliasInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)  | 
357  | 78.3k  | { | 
358  | 78.3k  |   unsigned opcode = MCInst_getOpcode(MI);  | 
359  | 78.3k  |   MCOperand *op;  | 
360  |  |  | 
361  | 78.3k  |   switch(opcode) { | 
362  |  |     /* ADD.Dx -i, x, y -> SUB.Dx x, i, y */  | 
363  | 367  |     case TMS320C64x_ADD_d2_rir:  | 
364  |  |     /* ADD.L -i, x, y -> SUB.L x, i, y */  | 
365  | 781  |     case TMS320C64x_ADD_l1_irr:  | 
366  | 1.17k  |     case TMS320C64x_ADD_l1_ipp:  | 
367  |  |     /* ADD.S -i, x, y -> SUB.S x, i, y */  | 
368  | 1.79k  |     case TMS320C64x_ADD_s1_irr:  | 
369  | 1.79k  |       if ((MCInst_getNumOperands(MI) == 3) &&  | 
370  | 1.79k  |         MCOperand_isReg(MCInst_getOperand(MI, 0)) &&  | 
371  | 1.79k  |         MCOperand_isReg(MCInst_getOperand(MI, 1)) &&  | 
372  | 1.79k  |         MCOperand_isImm(MCInst_getOperand(MI, 2)) &&  | 
373  | 1.79k  |         (MCOperand_getImm(MCInst_getOperand(MI, 2)) < 0)) { | 
374  |  |  | 
375  | 495  |         MCInst_setOpcodePub(MI, TMS320C64X_INS_SUB);  | 
376  | 495  |         op = MCInst_getOperand(MI, 2);  | 
377  | 495  |         MCOperand_setImm(op, -MCOperand_getImm(op));  | 
378  |  |  | 
379  | 495  |         SStream_concat0(O, "SUB\t");  | 
380  | 495  |         printOperand(MI, 1, O);  | 
381  | 495  |         SStream_concat0(O, ", ");  | 
382  | 495  |         printOperand(MI, 2, O);  | 
383  | 495  |         SStream_concat0(O, ", ");  | 
384  | 495  |         printOperand(MI, 0, O);  | 
385  |  |  | 
386  | 495  |         return true;  | 
387  | 495  |       }  | 
388  | 1.30k  |       break;  | 
389  | 78.3k  |   }  | 
390  | 77.8k  |   switch(opcode) { | 
391  |  |     /* ADD.D 0, x, y -> MV.D x, y */  | 
392  | 146  |     case TMS320C64x_ADD_d1_rir:  | 
393  |  |     /* OR.D x, 0, y -> MV.D x, y */  | 
394  | 593  |     case TMS320C64x_OR_d2_rir:  | 
395  |  |     /* ADD.L 0, x, y -> MV.L x, y */  | 
396  | 899  |     case TMS320C64x_ADD_l1_irr:  | 
397  | 1.06k  |     case TMS320C64x_ADD_l1_ipp:  | 
398  |  |     /* OR.L 0, x, y -> MV.L x, y */  | 
399  | 1.47k  |     case TMS320C64x_OR_l1_irr:  | 
400  |  |     /* ADD.S 0, x, y -> MV.S x, y */  | 
401  | 2.03k  |     case TMS320C64x_ADD_s1_irr:  | 
402  |  |     /* OR.S 0, x, y -> MV.S x, y */  | 
403  | 2.32k  |     case TMS320C64x_OR_s1_irr:  | 
404  | 2.32k  |       if ((MCInst_getNumOperands(MI) == 3) &&  | 
405  | 2.32k  |         MCOperand_isReg(MCInst_getOperand(MI, 0)) &&  | 
406  | 2.32k  |         MCOperand_isReg(MCInst_getOperand(MI, 1)) &&  | 
407  | 2.32k  |         MCOperand_isImm(MCInst_getOperand(MI, 2)) &&  | 
408  | 2.32k  |         (MCOperand_getImm(MCInst_getOperand(MI, 2)) == 0)) { | 
409  |  |  | 
410  | 184  |         MCInst_setOpcodePub(MI, TMS320C64X_INS_MV);  | 
411  | 184  |         MI->size--;  | 
412  |  |  | 
413  | 184  |         SStream_concat0(O, "MV\t");  | 
414  | 184  |         printOperand(MI, 1, O);  | 
415  | 184  |         SStream_concat0(O, ", ");  | 
416  | 184  |         printOperand(MI, 0, O);  | 
417  |  |  | 
418  | 184  |         return true;  | 
419  | 184  |       }  | 
420  | 2.14k  |       break;  | 
421  | 77.8k  |   }  | 
422  | 77.6k  |   switch(opcode) { | 
423  |  |     /* XOR.D -1, x, y -> NOT.D x, y */  | 
424  | 283  |     case TMS320C64x_XOR_d2_rir:  | 
425  |  |     /* XOR.L -1, x, y -> NOT.L x, y */  | 
426  | 760  |     case TMS320C64x_XOR_l1_irr:  | 
427  |  |     /* XOR.S -1, x, y -> NOT.S x, y */  | 
428  | 1.18k  |     case TMS320C64x_XOR_s1_irr:  | 
429  | 1.18k  |       if ((MCInst_getNumOperands(MI) == 3) &&  | 
430  | 1.18k  |         MCOperand_isReg(MCInst_getOperand(MI, 0)) &&  | 
431  | 1.18k  |         MCOperand_isReg(MCInst_getOperand(MI, 1)) &&  | 
432  | 1.18k  |         MCOperand_isImm(MCInst_getOperand(MI, 2)) &&  | 
433  | 1.18k  |         (MCOperand_getImm(MCInst_getOperand(MI, 2)) == -1)) { | 
434  |  |  | 
435  | 265  |         MCInst_setOpcodePub(MI, TMS320C64X_INS_NOT);  | 
436  | 265  |         MI->size--;  | 
437  |  |  | 
438  | 265  |         SStream_concat0(O, "NOT\t");  | 
439  | 265  |         printOperand(MI, 1, O);  | 
440  | 265  |         SStream_concat0(O, ", ");  | 
441  | 265  |         printOperand(MI, 0, O);  | 
442  |  |  | 
443  | 265  |         return true;  | 
444  | 265  |       }  | 
445  | 917  |       break;  | 
446  | 77.6k  |   }  | 
447  | 77.3k  |   switch(opcode) { | 
448  |  |     /* MVK.D 0, x -> ZERO.D x */  | 
449  | 1.43k  |     case TMS320C64x_MVK_d1_rr:  | 
450  |  |     /* MVK.L 0, x -> ZERO.L x */  | 
451  | 3.56k  |     case TMS320C64x_MVK_l2_ir:  | 
452  | 3.56k  |       if ((MCInst_getNumOperands(MI) == 2) &&  | 
453  | 3.56k  |         MCOperand_isReg(MCInst_getOperand(MI, 0)) &&  | 
454  | 3.56k  |         MCOperand_isImm(MCInst_getOperand(MI, 1)) &&  | 
455  | 3.56k  |         (MCOperand_getImm(MCInst_getOperand(MI, 1)) == 0)) { | 
456  |  |  | 
457  | 944  |         MCInst_setOpcodePub(MI, TMS320C64X_INS_ZERO);  | 
458  | 944  |         MI->size--;  | 
459  |  |  | 
460  | 944  |         SStream_concat0(O, "ZERO\t");  | 
461  | 944  |         printOperand(MI, 0, O);  | 
462  |  |  | 
463  | 944  |         return true;  | 
464  | 944  |       }  | 
465  | 2.62k  |       break;  | 
466  | 77.3k  |   }  | 
467  | 76.4k  |   switch(opcode) { | 
468  |  |     /* SUB.L x, x, y -> ZERO.L y */  | 
469  | 803  |     case TMS320C64x_SUB_l1_rrp_x1:  | 
470  |  |     /* SUB.S x, x, y -> ZERO.S y */  | 
471  | 1.12k  |     case TMS320C64x_SUB_s1_rrr:  | 
472  | 1.12k  |       if ((MCInst_getNumOperands(MI) == 3) &&  | 
473  | 1.12k  |         MCOperand_isReg(MCInst_getOperand(MI, 0)) &&  | 
474  | 1.12k  |         MCOperand_isReg(MCInst_getOperand(MI, 1)) &&  | 
475  | 1.12k  |         MCOperand_isReg(MCInst_getOperand(MI, 2)) &&  | 
476  | 1.12k  |         (MCOperand_getReg(MCInst_getOperand(MI, 1)) == MCOperand_getReg(MCInst_getOperand(MI, 2)))) { | 
477  |  |  | 
478  | 334  |         MCInst_setOpcodePub(MI, TMS320C64X_INS_ZERO);  | 
479  | 334  |         MI->size -= 2;  | 
480  |  |  | 
481  | 334  |         SStream_concat0(O, "ZERO\t");  | 
482  | 334  |         printOperand(MI, 0, O);  | 
483  |  |  | 
484  | 334  |         return true;  | 
485  | 334  |       }  | 
486  | 795  |       break;  | 
487  | 76.4k  |   }  | 
488  | 76.0k  |   switch(opcode) { | 
489  |  |     /* SUB.L 0, x, y -> NEG.L x, y */  | 
490  | 470  |     case TMS320C64x_SUB_l1_irr:  | 
491  | 986  |     case TMS320C64x_SUB_l1_ipp:  | 
492  |  |     /* SUB.S 0, x, y -> NEG.S x, y */  | 
493  | 1.14k  |     case TMS320C64x_SUB_s1_irr:  | 
494  | 1.14k  |       if ((MCInst_getNumOperands(MI) == 3) &&  | 
495  | 1.14k  |         MCOperand_isReg(MCInst_getOperand(MI, 0)) &&  | 
496  | 1.14k  |         MCOperand_isReg(MCInst_getOperand(MI, 1)) &&  | 
497  | 1.14k  |         MCOperand_isImm(MCInst_getOperand(MI, 2)) &&  | 
498  | 1.14k  |         (MCOperand_getImm(MCInst_getOperand(MI, 2)) == 0)) { | 
499  |  |  | 
500  | 325  |         MCInst_setOpcodePub(MI, TMS320C64X_INS_NEG);  | 
501  | 325  |         MI->size--;  | 
502  |  |  | 
503  | 325  |         SStream_concat0(O, "NEG\t");  | 
504  | 325  |         printOperand(MI, 1, O);  | 
505  | 325  |         SStream_concat0(O, ", ");  | 
506  | 325  |         printOperand(MI, 0, O);  | 
507  |  |  | 
508  | 325  |         return true;  | 
509  | 325  |       }  | 
510  | 820  |       break;  | 
511  | 76.0k  |   }  | 
512  | 75.7k  |   switch(opcode) { | 
513  |  |     /* PACKLH2.L x, x, y -> SWAP2.L x, y */  | 
514  | 276  |     case TMS320C64x_PACKLH2_l1_rrr_x2:  | 
515  |  |     /* PACKLH2.S x, x, y -> SWAP2.S x, y */  | 
516  | 786  |     case TMS320C64x_PACKLH2_s1_rrr:  | 
517  | 786  |       if ((MCInst_getNumOperands(MI) == 3) &&  | 
518  | 786  |         MCOperand_isReg(MCInst_getOperand(MI, 0)) &&  | 
519  | 786  |         MCOperand_isReg(MCInst_getOperand(MI, 1)) &&  | 
520  | 786  |         MCOperand_isReg(MCInst_getOperand(MI, 2)) &&  | 
521  | 786  |         (MCOperand_getReg(MCInst_getOperand(MI, 1)) == MCOperand_getReg(MCInst_getOperand(MI, 2)))) { | 
522  |  |  | 
523  | 148  |         MCInst_setOpcodePub(MI, TMS320C64X_INS_SWAP2);  | 
524  | 148  |         MI->size--;  | 
525  |  |  | 
526  | 148  |         SStream_concat0(O, "SWAP2\t");  | 
527  | 148  |         printOperand(MI, 1, O);  | 
528  | 148  |         SStream_concat0(O, ", ");  | 
529  | 148  |         printOperand(MI, 0, O);  | 
530  |  |  | 
531  | 148  |         return true;  | 
532  | 148  |       }  | 
533  | 638  |       break;  | 
534  | 75.7k  |   }  | 
535  | 75.6k  |   switch(opcode) { | 
536  |  |     /* NOP 16 -> IDLE */  | 
537  |  |     /* NOP 1 -> NOP */  | 
538  | 1.79k  |     case TMS320C64x_NOP_n:  | 
539  | 1.79k  |       if ((MCInst_getNumOperands(MI) == 1) &&  | 
540  | 1.79k  |         MCOperand_isImm(MCInst_getOperand(MI, 0)) &&  | 
541  | 1.79k  |         (MCOperand_getReg(MCInst_getOperand(MI, 0)) == 16)) { | 
542  |  |  | 
543  | 385  |         MCInst_setOpcodePub(MI, TMS320C64X_INS_IDLE);  | 
544  | 385  |         MI->size--;  | 
545  |  |  | 
546  | 385  |         SStream_concat0(O, "IDLE");  | 
547  |  |  | 
548  | 385  |         return true;  | 
549  | 385  |       }  | 
550  | 1.41k  |       if ((MCInst_getNumOperands(MI) == 1) &&  | 
551  | 1.41k  |         MCOperand_isImm(MCInst_getOperand(MI, 0)) &&  | 
552  | 1.41k  |         (MCOperand_getReg(MCInst_getOperand(MI, 0)) == 1)) { | 
553  |  |  | 
554  | 896  |         MI->size--;  | 
555  |  |  | 
556  | 896  |         SStream_concat0(O, "NOP");  | 
557  |  |  | 
558  | 896  |         return true;  | 
559  | 896  |       }  | 
560  | 517  |       break;  | 
561  | 75.6k  |   }  | 
562  |  |  | 
563  | 74.3k  |   return false;  | 
564  | 75.6k  | }  | 
565  |  |  | 
566  |  | void TMS320C64x_printInst(MCInst *MI, SStream *O, void *Info)  | 
567  | 78.3k  | { | 
568  | 78.3k  |   if (!printAliasInstruction(MI, O, Info))  | 
569  | 74.3k  |     printInstruction(MI, O, Info);  | 
570  | 78.3k  | }  | 
571  |  |  | 
572  |  | #endif  |