Rizin
unix-like reverse engineering framework and cli tools
decode_funcs.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2013 th0rpe <josediazfer@yahoo.es>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <string.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include "ins.h"
9 #include "utils.h"
10 
11 char *get_tc2_tc1(ut32 ins_bits) {
12  char *res = "tc1";
13  if (ins_bits) {
14  if (ins_bits != 1) {
15  fprintf(stderr, "Invalid instruction TC2 or TC1 (%d)\n", ins_bits);
16  return NULL;
17  }
18  res = "tc2";
19  }
20  return strdup(res);
21 }
22 
23 char *get_trans_reg(ut32 ins_bits) {
24  char *res = NULL;
25 
26  switch (ins_bits) {
27  case 6:
28  res = "trn0";
29  break;
30  case 7:
31  res = "trn1";
32  break;
33  case 4:
34  res = "trn2";
35  break;
36  case 5:
37  res = "trn3";
38  break;
39  case 2:
40  res = "trn4";
41  break;
42  case 3:
43  res = "trn5";
44  break;
45  case 0:
46  res = "trn6";
47  break;
48  case 1:
49  res = "trn7";
50  break;
51 
52  default:
53  fprintf(stderr, "Invalid transaction instruction 0x%x\n", ins_bits);
54  }
55  return res ? strdup(res) : NULL;
56 }
57 
58 char *get_AR_regs_class1(ut32 ins_bits) {
59  ut32 op = (ins_bits >> 4) & 7;
60  char *res = (char *)calloc(1, 50);
61  if (!res) {
62  return NULL;
63  }
64  switch (op) {
65  case 0:
66  sprintf(res, "*ar-%ld", (long int)ins_bits & 0xF);
67  break;
68  case 1:
69  sprintf(res, "*ar+%ld", (long int)ins_bits & 0xF);
70  break;
71  case 2:
72  sprintf(res, "*ar%ld(t0)", (long int)ins_bits & 0xF);
73  break;
74  case 3:
75  sprintf(res, "*ar%ld", (long int)ins_bits & 0xF);
76  break;
77  case 4:
78  sprintf(res, "*(ar%ld-t0)", (long int)ins_bits & 0xF);
79  break;
80  case 5:
81  sprintf(res, "*(ar%ld-t1)", (long int)ins_bits & 0xF);
82  break;
83  case 6:
84  sprintf(res, "*(ar%ld+t0)", (long int)ins_bits & 0xF);
85  break;
86  case 7:
87  sprintf(res, "*(ar%ld+t1)", (long int)ins_bits & 0xF);
88  break;
89  }
90  return res;
91 }
92 
93 char *get_AR_regs_class2(ut32 ins_bits, ut32 *ret_len, ut32 ins_pos, ut32 idx) {
94  ut8 op, op2, reg_num, type;
95  char *res = NULL;
96 
97  op = ins_bits >> 6;
98  op2 = ins_bits & 3;
99  reg_num = (ins_bits >> 2) & 0xF;
100  if (ret_len) {
101  *ret_len = 0;
102  }
103  // printf("OP1 %x OP2 0x%x %x\n", op, op2, reg_num);
104  res = malloc(50);
105  if (!res) {
106  return NULL;
107  }
108  if (op2 == 2) {
109  if (op) {
110  sprintf(res, "*ar%ld(short(#0x%lx))",
111  (long int)reg_num, (long int)idx * op);
112  } else {
113  sprintf(res, "*ar%ld", (long int)reg_num);
114  }
115  } else {
116  type = (op >> 3 | 2 * op2);
117  if (type == 6) {
118  sprintf(res, "@#0x%lx", (long int)idx * (reg_num | 16 * (op & 7)));
119  } else if (type == 7) {
120  sprintf(res, "*sp(#0x%lx)", (long int)idx * (reg_num | 16 * (op & 7)));
121  } else {
122  type = idx | 16 * op;
123  switch (type) {
124  case 0:
125  sprintf(res, "*ar%ld-", (long int)reg_num);
126  break;
127  case 1:
128  sprintf(res, "*ar%ld+", (long int)reg_num);
129  break;
130  case 2:
131  sprintf(res, "*ar%ld(t0)", (long int)reg_num);
132  break;
133  case 3:
134  sprintf(res, "*ar%ld(t1)", (long int)reg_num);
135  break;
136  case 4:
137  sprintf(res, "*(ar%ld-t0)", (long int)reg_num);
138  break;
139  case 5:
140  sprintf(res, "*(ar%ld-t1)", (long int)reg_num);
141  break;
142  case 6:
143  sprintf(res, "*(ar%ld+t0)", (long int)reg_num);
144  break;
145  case 7:
146  sprintf(res, "*(ar%ld+t1)", (long int)reg_num);
147  break;
148  case 8:
149  sprintf(res, "*-ar%ld", (long int)reg_num);
150  break;
151  case 9:
152  sprintf(res, "*+ar%ld", (long int)reg_num);
153  break;
154  case 10:
155  sprintf(res, "*ar%ld(t2)", (long int)reg_num);
156  break;
157  case 11:
158  sprintf(res, "*ar%ld(t3)", (long int)reg_num);
159  break;
160  case 12:
161  sprintf(res, "*(ar%ld-t2)", (long int)reg_num);
162  break;
163  case 13:
164  sprintf(res, "*(ar%ld-t3)", (long int)reg_num);
165  break;
166  case 14:
167  sprintf(res, "*(ar%ld+t2)", (long int)reg_num);
168  break;
169  case 15:
170  sprintf(res, "*(ar%ld+t3)", (long int)reg_num);
171  break;
172  case 16:
173  sprintf(res, "*(ar%ld-t0b)", (long int)reg_num);
174  break;
175  case 17:
176  sprintf(res, "*(ar%ld+t0b)", (long int)reg_num);
177  break;
178  case 18:
179  sprintf(res, "*ar%ld(t0<<#1)", (long int)reg_num);
180  break;
181  case 19:
182  sprintf(res, "*ar%ld(t1<<#1)", (long int)reg_num);
183  break;
184  case 23:
185  sprintf(res, "*ar%ld(xar15)", (long int)reg_num);
186  break;
187 
188  case 24:
189  case 25:
190  case 26:
191  case 27:
192  idx = get_ins_part(ins_pos, 2);
193  if (ret_len) {
194  *ret_len = 2;
195  }
196  switch (type) {
197  case 24:
198  sprintf(res, "*ar%ld(#%ld)", (long int)reg_num, (long int)op * idx);
199  break;
200  case 25:
201  sprintf(res, "*+ar%ld(#%ld)", (long int)reg_num, (long int)op * idx);
202  break;
203  case 26:
204  sprintf(res, "*abs16(#0x%lx)", (long int)idx);
205  break;
206  default:
207  sprintf(res, "*port(#0x%lx)", (long int)idx);
208  break;
209  }
210  break;
211  case 28:
212  case 29:
213  case 30:
214  idx = get_ins_part(ins_pos, 3);
215  if (ret_len) {
216  *ret_len = 3;
217  }
218  switch (type) {
219  case 28:
220  sprintf(res, "*ar%ld(#0x%lx)", (long int)reg_num, (long int)idx * op);
221  break;
222  case 29:
223  sprintf(res, "*+ar%ld(#0x%lx)", (long int)reg_num, (long int)idx * op);
224  break;
225  default:
226  sprintf(res, "*(#0x%lx)", (long int)idx);
227  break;
228  }
229 
230  break;
231  }
232  }
233  }
234 
235  return res;
236 }
237 
239  char *res = NULL;
240 
241  switch (idx) {
242  case 1: res = "ac0, ac2"; break;
243  case 2: res = "ac1, ac3"; break;
244  case 3: res = "pair(ac0), pair(ac2)"; break;
245  case 4: res = "ar0, ar1"; break;
246  case 5: res = "ar0, ar2"; break;
247  case 6: res = "ar1, ar3"; break;
248  case 7: res = "pair(ar0), pair(ar2)"; break;
249  case 9: res = "t0, t2"; break;
250  case 10: res = "t1, t3"; break;
251  case 11: res = "pair(t0), pair(t2)"; break;
252  case 21: res = "ar4, t0"; break;
253  case 22: res = "ar5, t1"; break;
254  case 23: res = "pair(ar4), pair(t0)"; break;
255  case 25: res = "ar6, t2"; break;
256  case 26: res = "ar7, t3"; break;
257  case 27: res = "pair(ar6), pair(t2)"; break;
258  case 31: res = "block(ar4), block(t0)"; break;
259  default: res = NULL;
260  }
261 
262  if (res != NULL) {
263  res = strdup(res);
264  }
265 
266  return res;
267 }
268 
270  char *res = NULL;
271 
272  switch (idx) {
273  case 0: res = "ac0"; break;
274  case 1: res = "ac1"; break;
275  case 2: res = "ac2"; break;
276  case 3: res = "ac3"; break;
277  case 4: res = "ac4"; break;
278  case 5: res = "ac5"; break;
279  case 6: res = "ac6"; break;
280  case 7: res = "ac7"; break;
281  case 8: res = "ac8"; break;
282  case 9: res = "ac9"; break;
283  case 10: res = "ac10"; break;
284  case 11: res = "ac11"; break;
285  case 12: res = "ac12"; break;
286  case 13: res = "ac13"; break;
287  case 14: res = "ac14"; break;
288  case 15: res = "ac15"; break;
289  case 16: res = "ac16"; break;
290  case 17: res = "ac17"; break;
291  case 18: res = "ac18"; break;
292  case 19: res = "ac19"; break;
293  case 20: res = "ac20"; break;
294  case 21: res = "ac21"; break;
295  case 22: res = "ac22"; break;
296  case 23: res = "ac23"; break;
297  case 24: res = "ac24"; break;
298  case 25: res = "ac25"; break;
299  case 26: res = "ac26"; break;
300  case 27: res = "ac27"; break;
301  case 28: res = "ac28"; break;
302  case 29: res = "ac29"; break;
303  case 30: res = "ac30"; break;
304  case 31: res = "ac31"; break;
305  case 32: res = "xar0"; break;
306  case 33: res = "xar1"; break;
307  case 34: res = "xar2"; break;
308  case 35: res = "xar3"; break;
309  case 36: res = "xar4"; break;
310  case 37: res = "xar5"; break;
311  case 38: res = "xar6"; break;
312  case 39: res = "xar7"; break;
313  case 40: res = "xar8"; break;
314  case 41: res = "xar9"; break;
315  case 42: res = "xar10"; break;
316  case 43: res = "xar11"; break;
317  case 44: res = "xar12"; break;
318  case 45: res = "xar13"; break;
319  case 46: res = "xar14"; break;
320  case 47: res = "xar15"; break;
321  case 52: res = "xssp"; break;
322  case 53: res = "xsp"; break;
323  case 54: res = "xdp"; break;
324  default: res = NULL;
325  }
326 
327  if (res != NULL) {
328  res = strdup(res);
329  }
330  return res;
331 }
332 
334  char *res = NULL;
335 
336  switch (idx) {
337  case 0: res = "ar0"; break;
338  case 1: res = "ar1"; break;
339  case 2: res = "ar2"; break;
340  case 3: res = "ar3"; break;
341  case 4: res = "ar4"; break;
342  case 5: res = "ar5"; break;
343  case 6: res = "ar6"; break;
344  case 7: res = "ar7"; break;
345  case 8: res = "ar8"; break;
346  case 9: res = "ar9"; break;
347  case 10: res = "ar10"; break;
348  case 11: res = "ar11"; break;
349  case 12: res = "ar12"; break;
350  case 13: res = "ar13"; break;
351  case 14: res = "ar14"; break;
352  case 15: res = "ar15"; break;
353  case 16: res = "t0"; break;
354  case 17: res = "t1"; break;
355  case 18: res = "t2"; break;
356  case 19: res = "t3"; break;
357  case 20: res = "ssp"; break;
358  case 21: res = "sp"; break;
359  case 22: res = "dp"; break;
360  case 32: res = "xar0"; break;
361  case 33: res = "xar1"; break;
362  case 34: res = "xar2"; break;
363  case 35: res = "xar3"; break;
364  case 36: res = "xar4"; break;
365  case 37: res = "xar5"; break;
366  case 38: res = "xar6"; break;
367  case 39: res = "xar7"; break;
368  case 40: res = "xar8"; break;
369  case 41: res = "xar9"; break;
370  case 42: res = "xar10"; break;
371  case 43: res = "xar11"; break;
372  case 44: res = "xar12"; break;
373  case 45: res = "xar13"; break;
374  case 46: res = "xar14"; break;
375  case 47: res = "xar15"; break;
376  case 52: res = "xssp"; break;
377  case 53: res = "xsp"; break;
378  case 54: res = "xdp"; break;
379  default: res = NULL;
380  }
381 
382  if (res != NULL) {
383  res = strdup(res);
384  }
385 
386  return res;
387 }
388 
390  char *res = NULL;
391 
392  switch (idx) {
393  case 0: res = "ac0"; break;
394  case 1: res = "ac1"; break;
395  case 2: res = "ac2"; break;
396  case 3: res = "ac3"; break;
397  case 4: res = "ac4"; break;
398  case 5: res = "ac5"; break;
399  case 6: res = "ac6"; break;
400  case 7: res = "ac7"; break;
401  case 8: res = "ac8"; break;
402  case 9: res = "ac9"; break;
403  case 10: res = "ac10"; break;
404  case 11: res = "ac11"; break;
405  case 12: res = "ac12"; break;
406  case 13: res = "ac13"; break;
407  case 14: res = "ac14"; break;
408  case 15: res = "ac15"; break;
409  case 16: res = "ac16"; break;
410  case 17: res = "ac17"; break;
411  case 18: res = "ac18"; break;
412  case 19: res = "ac19"; break;
413  case 20: res = "ac20"; break;
414  case 21: res = "ac21"; break;
415  case 22: res = "ac22"; break;
416  case 23: res = "ac23"; break;
417  case 24: res = "ac24"; break;
418  case 25: res = "ac25"; break;
419  case 26: res = "ac26"; break;
420  case 27: res = "ac27"; break;
421  case 28: res = "ac28"; break;
422  case 29: res = "ac29"; break;
423  case 30: res = "ac30"; break;
424  case 31: res = "ac31"; break;
425  case 32: res = "ar0"; break;
426  case 33: res = "ar1"; break;
427  case 34: res = "ar2"; break;
428  case 35: res = "ar3"; break;
429  case 36: res = "ar4"; break;
430  case 37: res = "ar5"; break;
431  case 38: res = "ar6"; break;
432  case 39: res = "ar7"; break;
433  case 40: res = "ar8"; break;
434  case 41: res = "ar9"; break;
435  case 42: res = "ar10"; break;
436  case 43: res = "ar11"; break;
437  case 44: res = "ar12"; break;
438  case 45: res = "ar13"; break;
439  case 46: res = "ar14"; break;
440  case 47: res = "ar15"; break;
441  case 48: res = "t0"; break;
442  case 49: res = "t1"; break;
443  case 50: res = "t2"; break;
444  case 51: res = "t3"; break;
445  case 52: res = "ssp"; break;
446  case 53: res = "sp"; break;
447  case 54: res = "dp"; break;
448  case 56: res = "csr"; break;
449  case 57: res = "rptc"; break;
450  case 58: res = "brc0"; break;
451  case 59: res = "brc1"; break;
452  case 62: res = "config"; break;
453  case 63: res = "cpurev"; break;
454  case 64: res = "ac0.h"; break;
455  case 65: res = "ac1.h"; break;
456  case 66: res = "ac2.h"; break;
457  case 67: res = "ac3.h"; break;
458  case 68: res = "ac4.h"; break;
459  case 69: res = "ac5.h"; break;
460  case 70: res = "ac6.h"; break;
461  case 71: res = "ac7.h"; break;
462  case 72: res = "ac8.h"; break;
463  case 73: res = "ac9.h"; break;
464  case 74: res = "ac10.h"; break;
465  case 75: res = "ac11.h"; break;
466  case 76: res = "ac12.h"; break;
467  case 77: res = "ac13.h"; break;
468  case 78: res = "ac14.h"; break;
469  case 79: res = "ac15.h"; break;
470  case 80: res = "ac16.h"; break;
471  case 81: res = "ac17.h"; break;
472  case 82: res = "ac18.h"; break;
473  case 83: res = "ac19.h"; break;
474  case 84: res = "ac20.h"; break;
475  case 85: res = "ac21.h"; break;
476  case 86: res = "ac22.h"; break;
477  case 87: res = "ac23.h"; break;
478  case 88: res = "ac24.h"; break;
479  case 89: res = "ac25.h"; break;
480  case 90: res = "ac26.h"; break;
481  case 91: res = "ac27.h"; break;
482  case 92: res = "ac28.h"; break;
483  case 93: res = "ac29.h"; break;
484  case 94: res = "ac30.h"; break;
485  case 95: res = "ac31.h"; break;
486  case 96: res = "ac0.l"; break;
487  case 97: res = "ac1.l"; break;
488  case 98: res = "ac2.l"; break;
489  case 99: res = "ac3.l"; break;
490  case 100: res = "ac4.l"; break;
491  case 101: res = "ac5.l"; break;
492  case 102: res = "ac6.l"; break;
493  case 103: res = "ac7.l"; break;
494  case 104: res = "ac8.l"; break;
495  case 105: res = "ac9.l"; break;
496  case 106: res = "ac10.l"; break;
497  case 107: res = "ac11.l"; break;
498  case 108: res = "ac12.l"; break;
499  case 109: res = "ac13.l"; break;
500  case 110: res = "ac14.l"; break;
501  case 111: res = "ac15.l"; break;
502  case 112: res = "ac16.l"; break;
503  case 113: res = "ac17.l"; break;
504  case 114: res = "ac18.l"; break;
505  case 115: res = "ac19.l"; break;
506  case 116: res = "ac20.l"; break;
507  case 117: res = "ac21.l"; break;
508  case 118: res = "ac22.l"; break;
509  case 119: res = "ac23.l"; break;
510  case 120: res = "ac24.l"; break;
511  case 121: res = "ac25.l"; break;
512  case 122: res = "ac26.l"; break;
513  case 123: res = "ac27.l"; break;
514  case 124: res = "ac28.l"; break;
515  case 125: res = "ac29.l"; break;
516  case 126: res = "ac30.l"; break;
517  case 127: res = "ac31.l"; break;
518  case 128: res = "xar0"; break;
519  case 129: res = "xar1"; break;
520  case 130: res = "xar2"; break;
521  case 131: res = "xar3"; break;
522  case 132: res = "xar4"; break;
523  case 133: res = "xar5"; break;
524  case 134: res = "xar6"; break;
525  case 135: res = "xar7"; break;
526  case 136: res = "xar8"; break;
527  case 137: res = "xar9"; break;
528  case 138: res = "xar10"; break;
529  case 139: res = "xar11"; break;
530  case 140: res = "xar12"; break;
531  case 141: res = "xar13"; break;
532  case 142: res = "xar14"; break;
533  case 143: res = "xar15"; break;
534  case 148: res = "xssp"; break;
535  case 149: res = "xsp"; break;
536  case 150: res = "xdp"; break;
537  case 152: res = "rsa0"; break;
538  case 153: res = "rsa1"; break;
539  case 154: res = "rea0"; break;
540  case 155: res = "rea1"; break;
541  case 156: res = "dbgpaddr"; break;
542  case 157: res = "dbgpdata"; break;
543  case 159: res = "reta"; break;
544  case 160: res = "xar0.h"; break;
545  case 161: res = "xar1.h"; break;
546  case 162: res = "xar2.h"; break;
547  case 163: res = "xar3.h"; break;
548  case 164: res = "xar4.h"; break;
549  case 165: res = "xar5.h"; break;
550  case 166: res = "xar6.h"; break;
551  case 167: res = "xar7.h"; break;
552  case 168: res = "xar8.h"; break;
553  case 169: res = "xar9.h"; break;
554  case 170: res = "xar10.h"; break;
555  case 171: res = "xar11.h"; break;
556  case 172: res = "xar12.h"; break;
557  case 173: res = "xar13.h"; break;
558  case 174: res = "xar14.h"; break;
559  case 175: res = "xar15.h"; break;
560  case 180: res = "xssp.h"; break;
561  case 181: res = "xsp.h"; break;
562  case 182: res = "xdp.h"; break;
563  case 183: res = "pdp"; break;
564  case 184: res = "bsa01"; break;
565  case 185: res = "bsa23"; break;
566  case 186: res = "bsa45"; break;
567  case 187: res = "bsa67"; break;
568  case 188: res = "bsac"; break;
569  case 189: // res = (char *)&off_42FBE8;
570  res = "bkc";
571  break;
572  case 190: res = "bk03"; break;
573  case 191: res = "bk47"; break;
574  case 192: res = "ac0.g"; break;
575  case 193: res = "ac1.g"; break;
576  case 194: res = "ac2.g"; break;
577  case 195: res = "ac3.g"; break;
578  case 196: res = "ac4.g"; break;
579  case 197: res = "ac5.g"; break;
580  case 198: res = "ac6.g"; break;
581  case 199: res = "ac7.g"; break;
582  case 200: res = "ac8.g"; break;
583  case 201: res = "ac9.g"; break;
584  case 202: res = "ac10.g"; break;
585  case 203: res = "ac11.g"; break;
586  case 204: res = "ac12.g"; break;
587  case 205: res = "ac13.g"; break;
588  case 206: res = "ac14.g"; break;
589  case 207: res = "ac15.g"; break;
590  case 208: res = "ac16.g"; break;
591  case 209: res = "ac17.g"; break;
592  case 210: res = "ac18.g"; break;
593  case 211: res = "ac19.g"; break;
594  case 212: res = "ac20.g"; break;
595  case 213: res = "ac21.g"; break;
596  case 214: res = "ac22.g"; break;
597  case 215: res = "ac23.g"; break;
598  case 216: res = "ac24.g"; break;
599  case 217: res = "ac25.g"; break;
600  case 218: res = "ac26.g"; break;
601  case 219: res = "ac27.g"; break;
602  case 220: res = "ac28.g"; break;
603  case 221: res = "ac29.g"; break;
604  case 222: res = "ac30.g"; break;
605  case 223: res = "ac31.g"; break;
606  case 224: res = "st0"; break;
607  case 225: res = "st1"; break;
608  case 226: res = "st2"; break;
609  case 227: res = "st3"; break;
610  case 228: res = "st0_55"; break;
611  case 229: res = "st1_55"; break;
612  case 231: res = "st3_55"; break;
613  case 232: res = "ier0"; break;
614  case 233: res = "ier1"; break;
615  case 234: res = "ifr0"; break;
616  case 235: res = "ifr1"; break;
617  case 236: res = "dbier0"; break;
618  case 237: res = "dbier1"; break;
619  case 238: res = "ivpd"; break;
620  case 239: res = "ivph"; break;
621  case 240: res = "rsa0.h"; break;
622  case 241: res = "rsa1.h"; break;
623  case 242: res = "rea0.h"; break;
624  case 243: res = "rea1.h"; break;
625  case 244: res = "bios"; break;
626  case 245: res = "brs1"; break;
627  case 246: res = "iir"; break;
628  case 247: res = "ber"; break;
629  case 248: res = "rsa0.l"; break;
630  case 249: res = "rsa1.l"; break;
631  case 250: res = "rea0.l"; break;
632  case 251: res = "rea1.l"; break;
633  case 252: res = "tsdr"; break;
634  default: res = NULL;
635  }
636 
637  if (res != NULL) {
638  res = strdup(res);
639  }
640 
641  return res;
642 }
643 
644 char *get_status_regs_and_bits(char *reg_arg, int reg_bit) {
645  char *res = NULL;
646  if (!strncmp(reg_arg, "ST0", 3)) {
647  switch (reg_bit) {
648  case 0:
649  res = "st0_dp07";
650  break;
651  case 1:
652  res = "st0_dp08";
653  break;
654  case 2:
655  res = "st0_dp09";
656  break;
657  case 3:
658  res = "st0_dp10";
659  break;
660  case 4:
661  res = "st0_dp11";
662  break;
663  case 5:
664  res = "st0_dp12";
665  break;
666  case 6:
667  res = "st0_dp13";
668  break;
669  case 7:
670  res = "st0_dp14";
671  break;
672  case 8:
673  res = "st0_dp15";
674  break;
675  case 9:
676  res = "st0_acov1";
677  break;
678  case 10:
679  res = "st0_acov0";
680  break;
681  case 11:
682  res = "st0_carry";
683  break;
684  case 12:
685  res = "st0_tc2";
686  break;
687  case 13:
688  res = "st0_tc1";
689  break;
690  case 14:
691  res = "st0_acov3";
692  break;
693  case 15:
694  res = "st0_acov2";
695  break;
696  }
697  } else if (!strncmp(reg_arg, "ST1", 3)) {
698  switch (reg_bit) {
699  case 0:
700  res = "st1_dr2_00";
701  break;
702  case 1:
703  res = "st1_dr2_01";
704  break;
705  case 2:
706  res = "st1_dr2_02";
707  break;
708  case 3:
709  res = "st1_dr2_03";
710  break;
711  case 4:
712  res = "st1_dr2_04";
713  break;
714  case 5:
715  res = "st1_c54cm";
716  break;
717  case 6:
718  res = "st1_frct";
719  break;
720  case 7:
721  res = "st1_c16";
722  break;
723  case 8:
724  res = "st1_sxmd";
725  break;
726  case 9:
727  res = "st1_satd";
728  break;
729  case 10:
730  res = "st1_m40";
731  break;
732  case 11:
733  res = "st1_intm";
734  break;
735  case 12:
736  res = "st1_hm";
737  break;
738  case 13:
739  res = "st1_xf";
740  break;
741  case 14:
742  res = "st1_cpl";
743  break;
744  case 15:
745  res = "st1_braf";
746  break;
747  }
748  } else if (!strncmp(reg_arg, "ST2", 3)) {
749  switch (reg_bit) {
750  case 0:
751  res = "st2_ar0lc";
752  break;
753  case 1:
754  res = "st2_ar1lc";
755  break;
756  case 2:
757  res = "st2_ar2lc";
758  break;
759  case 3:
760  res = "st2_ar3lc";
761  break;
762  case 4:
763  res = "st2_ar4lc";
764  break;
765  case 5:
766  res = "st2_ar5lc";
767  break;
768  case 6:
769  res = "st2_ar6lc";
770  break;
771  case 7:
772  res = "st2_ar7lc";
773  break;
774  case 8:
775  res = "st2_cdplc";
776  break;
777  case 9:
778  res = "st2_govf";
779  break;
780  case 10:
781  res = "st2_rdm";
782  break;
783  case 11:
784  res = "st2_eallow";
785  break;
786  case 12:
787  res = "st2_dbgm";
788  break;
789  case 13:
790  res = "st2_xcnd";
791  break;
792  case 14:
793  res = "st2_xcna";
794  break;
795  case 15:
796  res = "st2_arms";
797  break;
798  }
799  } else if (!strncmp(reg_arg, "ST3", 3)) {
800  switch (reg_bit) {
801  case 0:
802  res = "st3_sst";
803  break;
804  case 1:
805  res = "st3_smul";
806  break;
807  case 2:
808  res = "st3_clkoff";
809  break;
810  case 3:
811  res = "st3_bptr";
812  break;
813  case 4:
814  res = "st3_avis";
815  break;
816  case 5:
817  res = "st3_sata";
818  break;
819  case 6:
820  res = "st3_mpnmc";
821  break;
822  case 7:
823  res = "st3_cberr";
824  break;
825  case 8:
826  res = "st3_homp";
827  break;
828  case 9:
829  res = "st3_homr";
830  break;
831  case 10:
832  res = "st3_homx";
833  break;
834  case 11:
835  res = "st3_homy";
836  break;
837  case 12:
838  res = "st3_hint";
839  break;
840  case 13:
841  res = "st3_caclr";
842  break;
843  case 14:
844  res = "st3_caen";
845  break;
846  case 15:
847  res = "st3_cafrz";
848  break;
849  }
850  }
851 
852  if (res != NULL) {
853  res = strdup(res);
854  }
855 
856  return res;
857 }
858 
860  char *res = NULL;
861 
862  switch (idx) {
863  case 0:
864  res = "ac0";
865  break;
866  case 1:
867  res = "ac1";
868  break;
869  case 2:
870  res = "ac2";
871  break;
872  case 3:
873  res = "ac3";
874  break;
875  case 4:
876  res = "ac4";
877  break;
878  case 5:
879  res = "ac5";
880  break;
881  case 6:
882  res = "ac6";
883  break;
884  case 7:
885  res = "ac7";
886  break;
887  case 8:
888  res = "t0";
889  break;
890  case 9:
891  res = "t1";
892  break;
893  case 10:
894  res = "t2";
895  break;
896  case 11:
897  res = "t3";
898  break;
899  case 16:
900  res = "ar0";
901  break;
902  case 17:
903  res = "ar1";
904  break;
905  case 18:
906  res = "ar2";
907  break;
908  case 19:
909  res = "ar3";
910  break;
911  case 20:
912  res = "ar4";
913  break;
914  case 21:
915  res = "ar5";
916  break;
917  case 22:
918  res = "ar6";
919  break;
920  case 23:
921  res = "ar7";
922  break;
923  case 24:
924  res = "ac0.l";
925  break;
926  case 25:
927  res = "ac1.l";
928  break;
929  case 26:
930  res = "ac2.l";
931  break;
932  case 27:
933  res = "ac3.l";
934  break;
935  case 28:
936  res = "ac4.l";
937  break;
938  case 29:
939  res = "ac5.l";
940  break;
941  case 30:
942  res = "ac6.l";
943  break;
944  case 31:
945  res = "ac7.l";
946  break;
947  }
948  return res ? strdup(res) : NULL;
949 }
950 
951 char *get_opers(ut8 oper_byte) {
952  switch (oper_byte) {
953  case 0xE0u:
954  return strdup("overflow(ac0)");
955  case 0xE1u:
956  return strdup("overflow(ac1)");
957  case 0xE2u:
958  return strdup("overflow(ac2)");
959  case 0xE3u:
960  return strdup("overflow(ac3)");
961  case 0xE4u:
962  return strdup("tc1");
963  case 0xE5u:
964  return strdup("tc2");
965  case 0xE6u:
966  return strdup("carry");
967  case 0xE7u:
968  return strdup("overflow(govf)");
969  case 0xE8u:
970  return strdup("tc1 & tc2");
971  case 0xE9u:
972  return strdup("tc1 & !tc2");
973  case 0xEAu:
974  return strdup("!tc1 & tc2");
975  case 0xEBu:
976  return strdup("!tc1 & !tc2");
977  case 0xECu:
978  return strdup("word_mode");
979  case 0xEDu:
980  return strdup("byte_mode");
981  case 0xF0u:
982  return strdup("!overflow(ac0)");
983  case 0xF1u:
984  return strdup("!overflow(ac1)");
985  case 0xF2u:
986  return strdup("!overflow(ac2)");
987  case 0xF3u:
988  return strdup("!overflow(ac3)");
989  case 0xF4u:
990  return strdup("!tc1");
991  case 0xF5u:
992  return strdup("!tc2");
993  case 0xF6u:
994  return strdup("!carry");
995  case 0xF7u:
996  return strdup("!overflow(govf)");
997  case 0xF8u:
998  return strdup("tc1 | tc2");
999  case 0xF9u:
1000  return strdup("tc1 | !tc2");
1001  case 0xFAu:
1002  return strdup("!tc1 | tc2");
1003  case 0xFBu:
1004  return strdup("!tc1 | !tc2");
1005  case 0xFCu:
1006  return strdup("tc1 ^ tc2");
1007  case 0xFDu:
1008  return strdup("tc1 ^ !tc2");
1009  case 0xFEu:
1010  return strdup("!tc1 ^ tc2");
1011  case 0xFFu:
1012  return strdup("!tc1 ^ !tc2");
1013  default: {
1014  ut8 oper_type = oper_byte >> 5;
1015  if (oper_type != 6) {
1016  char *reg_name = get_reg_name_4(oper_byte & 0x1F);
1017  switch (oper_type) {
1018  case 1u:
1019  return strcat_dup(reg_name, " != #0", 1);
1020  case 0u:
1021  return strcat_dup(reg_name, " == #0", 1);
1022  case 2u:
1023  return strcat_dup(reg_name, " < #0", 1);
1024  case 3u:
1025  return strcat_dup(reg_name, " >= #0", 1);
1026  case 4u:
1027  return strcat_dup(reg_name, " > #0", 1);
1028  case 5u:
1029  return strcat_dup(reg_name, " <= #0", 1);
1030  default:
1031  free(reg_name);
1032  return NULL;
1033  }
1034  }
1035  char *reg_name = get_reg_name_1((oper_byte & 0xF) + 128);
1036  oper_type = (oper_byte >> 4) - 12;
1037  if (oper_type) {
1038  if (oper_type != 1) {
1039  free(reg_name);
1040  return NULL;
1041  }
1042  return strcat_dup(reg_name, " != #0", 1);
1043  } else {
1044  // coverity may complain but strcat_dup set to null
1045  // reg_name when free
1046  return strcat_dup(reg_name, " == #0", 1);
1047  }
1048  }
1049  }
1050 }
1051 
1053  const char *res = NULL;
1054  switch (idx) {
1055  case 0: res = "=="; break;
1056  case 1: res = "!="; break;
1057  case 2: res = "<"; break;
1058  case 3: res = ">="; break;
1059  }
1060  return res ? strdup(res) : NULL;
1061 }
1062 
1063 char *get_sim_reg(char *reg_arg, ut32 ins_bits) {
1064  st32 code;
1065  char *res = NULL;
1066  char *aux;
1067  code = ins_bits & 3;
1068  switch (code) {
1069  case 0:
1070  if (reg_arg && strchr(reg_arg, 'w')) {
1071  if (code == 62) {
1072  return strdup("sim0");
1073  }
1074  if (code == 63) {
1075  return strdup("sim0");
1076  }
1077  }
1078  aux = get_reg_name_1(ins_bits >> 2);
1079  res = strcat_dup("@", aux, 2);
1080  break;
1081  case 2:
1082  aux = (char *)calloc(1, 50);
1083  if (!aux) {
1084  return NULL;
1085  }
1086  sprintf(aux, "@#0x%x", code);
1087  res = aux;
1088  break;
1089  case 1:
1090  case 3:
1091  res = strdup("<reserved>");
1092  break;
1093  }
1094  return res;
1095 }
ut8 op
Definition: 6502dis.c:13
#define NULL
Definition: cris-opc.c:27
char * get_opers(ut8 oper_byte)
Definition: decode_funcs.c:951
char * get_reg_name_2(ut32 idx)
Definition: decode_funcs.c:333
char * get_AR_regs_class1(ut32 ins_bits)
Definition: decode_funcs.c:58
char * get_sim_reg(char *reg_arg, ut32 ins_bits)
char * get_cmp_op(ut32 idx)
char * get_tc2_tc1(ut32 ins_bits)
Definition: decode_funcs.c:11
char * get_trans_reg(ut32 ins_bits)
Definition: decode_funcs.c:23
char * get_reg_pair(ut32 idx)
Definition: decode_funcs.c:238
char * get_status_regs_and_bits(char *reg_arg, int reg_bit)
Definition: decode_funcs.c:644
char * get_reg_name_4(ut32 idx)
Definition: decode_funcs.c:859
char * get_AR_regs_class2(ut32 ins_bits, ut32 *ret_len, ut32 ins_pos, ut32 idx)
Definition: decode_funcs.c:93
char * get_reg_name_1(ut32 idx)
Definition: decode_funcs.c:389
char * get_reg_name_3(ut32 idx)
Definition: decode_funcs.c:269
uint32_t ut32
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
ut32 get_ins_part(ut32 pos, ut32 len)
Definition: ins.c:51
sprintf
Definition: kernel.h:365
uint8_t ut8
Definition: lh5801.h:11
char * strcat_dup(char *s1, char *s2, st32 n_free)
Definition: utils.c:12
void * malloc(size_t size)
Definition: malloc.c:123
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
int type
Definition: mipsasm.c:17
int idx
Definition: setup.py:197
const char * code
Definition: pal.c:98
#define st32
Definition: rz_types_base.h:12
Definition: inftree9.h:24
Definition: dis.c:32