Rizin
unix-like reverse engineering framework and cli tools
cr16_disas.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2014 Fedor Sakharov <fedor.sakharov@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_types.h>
5 #include <rz_util.h>
6 
7 #include "cr16_disas.h"
8 
9 #define GET_BIT(x, n) ((((x)) >> ((n))) & 1)
10 
11 static const char *cr16_regs_names[] = {
12  [CR16_R0] = "r0",
13  [CR16_R1] = "r1",
14  [CR16_R2] = "r2",
15  [CR16_R3] = "r3",
16  [CR16_R4] = "r4",
17  [CR16_R5] = "r5",
18  [CR16_R6] = "r6",
19  [CR16_R7] = "r7",
20  [CR16_R8] = "r8",
21  [CR16_R9] = "r9",
22  [CR16_R10] = "r10",
23  [CR16_R11] = "r11",
24  [CR16_R12] = "r12",
25  [CR16_R13] = "r13",
26  [CR16_RA] = "ra",
27  [CR16_SP] = "sp",
28  [CR16_LAST] = "XX",
29 };
30 
31 static const char *instrs_4bit[] = {
32  [CR16_ADD] = "add",
33  [CR16_ADDU] = "addu",
34  [CR16_MUL] = "mul",
35  [CR16_ASHU] = "ashu",
36  [CR16_LSH] = "lsh",
37  [CR16_XOR] = "xor",
38  [CR16_CMP] = "cmp",
39  [CR16_AND] = "and",
40  [CR16_ADDC] = "addc",
41  [CR16_TBIT] = "tbit",
42  [CR16_TBIT_R_R] = "tbit",
43  [CR16_TBIT_I_R] = "tbit",
44  [CR16_MOV] = "mov",
45  [CR16_SUB] = "sub",
46  [CR16_SUBC] = "subc",
47  [CR16_OR] = "or",
48  [CR16_LPR] = "lpr",
49  [CR16_SPR] = "spr",
50  [CR16_LOADM] = "loadm",
51  [CR16_STORM] = "storm",
52 };
53 
54 static const char *cr16_conds[] = {
55  [CR16_COND_EQ] = "eq",
56  [CR16_COND_NE] = "ne",
57  [CR16_COND_GE] = "ge",
58  [CR16_COND_CS] = "cs",
59  [CR16_COND_CC] = "cc",
60  [CR16_COND_HI] = "hi",
61  [CR16_COND_LS] = "ls",
62  [CR16_COND_LO] = "lo",
63  [CR16_COND_HS] = "hs",
64  [CR16_COND_GT] = "gt",
65  [CR16_COND_LE] = "le",
66  [CR16_COND_FS] = "fs",
67  [CR16_COND_FC] = "fc",
68  [CR16_COND_LT] = "lt",
69 };
70 
71 static const char *ld_sw[] = {
72  [0x0] = "stor",
73  [0x1] = "stor",
74  [0x2] = "load",
75  [0x3] = "stor",
76 };
77 
78 static const char *dedicated_regs[] = {
79  [0x1] = "psr",
80  [0x3] = "intbaseh",
81  [0x4] = "intbasel",
82  [0x5] = "cfg",
83  [0x7] = "dsr",
84  [0x9] = "dcr",
85  [0xB] = "isp",
86  [0xD] = "carl",
87  [0xE] = "carh",
88 };
89 
90 static const char *ops_biti[] = {
91  [0x0] = "cbit",
92  [0x1] = "sbit",
93  [0x2] = "tbit",
94 };
95 
96 static inline ut8 cr16_get_opcode_low(const ut16 instr) {
97  return (instr >> 9) & 0xF;
98 }
99 
100 static inline ut8 cr16_get_opcode_hi(const ut16 instr) {
101  return instr >> 14;
102 }
103 
104 static inline ut8 cr16_get_opcode_i(const ut16 instr) {
105  return (instr >> 13) & 1;
106 }
107 
108 static inline ut8 cr16_get_short_imm(const ut16 instr) {
109  return instr & 0x1F;
110 }
111 
112 static inline ut8 cr16_get_dstreg(const ut16 instr) {
113  return (instr >> 5) & 0xF;
114 }
115 
116 static inline ut8 cr16_get_srcreg(const ut16 instr) {
117  return (instr >> 1) & 0xF;
118 }
119 
120 static inline int cr16_check_instrs_4bit_bndrs(const ut8 opcode) {
121  if (opcode >= sizeof(instrs_4bit) / sizeof(void *) || !instrs_4bit[opcode]) {
122  return -1;
123  }
124  return 0;
125 }
126 
127 static inline ut16 cr16_get_opcode_159_0(const ut16 opc) {
128  return (opc & 1) | ((opc >> 8) & 0xFE);
129 }
130 
131 static inline int cr16_check_reg_boundaries(const ut8 reg) {
132  if (reg >= sizeof(cr16_regs_names) / sizeof(void *) || !cr16_regs_names[reg]) {
133  return -1;
134  }
135  return 0;
136 }
137 
138 static inline int cr16_print_ld_sw_opcode(struct cr16_cmd *cmd, ut16 instr) {
139  ut8 opcode = instr >> 14;
140 
141  if (opcode >= sizeof(ld_sw) / sizeof(void *) || !ld_sw[opcode]) {
142  return -1;
143  }
144 
145  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "%s%c", ld_sw[opcode],
146  cr16_get_opcode_i(instr) ? 'w' : 'b');
147 
148  cmd->type = CR16_TYPE_MOV;
149 
150  cmd->instr[CR16_INSTR_MAXLEN - 1] = '\0';
151 
152  return 0;
153 }
154 
155 static inline int cr16_print_short_reg(struct cr16_cmd *cmd, ut8 sh, ut8 reg) {
157  return -1;
158  }
159 
160  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
161  "$0x%02x,%s", sh, cr16_regs_names[reg]);
162 
163  return 0;
164 }
165 
166 static inline int cr16_print_reg_short(struct cr16_cmd *cmd, ut8 sh, ut8 reg) {
168  return -1;
169  }
170 
171  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
172  "%s,$0x%02x", cr16_regs_names[reg], sh);
173 
174  return 0;
175 }
176 
177 static inline int cr16_print_med_reg(struct cr16_cmd *cmd, ut16 med, ut8 reg) {
179  return -1;
180  }
181 
182  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
183  "$0x%04x,%s", med, cr16_regs_names[reg]);
184 
185  return 0;
186 }
187 
188 static inline int cr16_print_reg_med(struct cr16_cmd *cmd, ut16 med, ut8 reg) {
190  return -1;
191  }
192 
193  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
194  "%s,$0x%04x", cr16_regs_names[reg], med);
195 
196  return 0;
197 }
198 
199 static inline int cr16_print_short_abs18(struct cr16_cmd *cmd,
200  ut8 sh, ut32 abs) {
201  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
202  "$0x%02x,0x%08x", sh, abs);
203  return 0;
204 }
205 
206 static inline int cr16_print_reg_reg_rel(struct cr16_cmd *cmd,
207  ut8 src, ut16 rel, ut8 dst, ut8 swap) {
209  return -1;
210  }
211 
212  if (swap) {
213  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "%s,0x%04x(%s)",
215  } else {
216  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "0x%04x(%s),%s",
218  }
219 
220  return 0;
221 }
222 
223 static inline int cr16_print_short_reg_rel(struct cr16_cmd *cmd,
224  ut8 sh, ut16 rel, ut8 reg) {
226  return -1;
227  }
228 
229  if (rel) {
230  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
231  "$0x%02x,0x%04x(%s)", sh, rel, cr16_regs_names[reg]);
232  } else {
233  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
234  "$0x%02x,0(%s)", sh, cr16_regs_names[reg]);
235  }
236 
237  return 0;
238 }
239 
240 static inline int cr16_print_reg_rel_reg(struct cr16_cmd *cmd,
241  ut32 rel, ut8 srcreg, ut8 dstreg, ut8 swap) {
242  if (cr16_check_reg_boundaries(srcreg)) {
243  return -1;
244  }
245 
246  if (cr16_check_reg_boundaries(dstreg)) {
247  return -1;
248  }
249 
250  if (swap) {
251  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "%s,0x%08x(%s)",
252  cr16_regs_names[dstreg], rel, cr16_regs_names[srcreg]);
253  } else {
254  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "0x%08x(%s),%s",
255  rel, cr16_regs_names[srcreg], cr16_regs_names[dstreg]);
256  }
257 
258  return 0;
259 }
260 
261 static inline int cr16_print_long_reg(struct cr16_cmd *cmd, ut32 l, ut8 reg, ut8 swap) {
263  return -1;
264  }
265 
266  if (swap) {
267  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
268  "%s,0x%08x", cr16_regs_names[reg], l);
269  } else {
270  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
271  "0x%08x,%s", l, cr16_regs_names[reg]);
272  }
273 
274  return 0;
275 }
276 
277 static inline int cr16_print_longregreg_reg(struct cr16_cmd *cmd,
278  ut32 rel, ut8 src, ut8 dst, ut8 swap) {
280  return -1;
281  }
282 
283  if (swap) {
284  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
285  "%s,0x%08x(%s,%s)", cr16_regs_names[src], rel,
286  cr16_regs_names[dst + 1],
288  } else {
289  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
290  "0x%08x(%s,%s),%s", rel, cr16_regs_names[src + 1],
292  }
293  return 0;
294 }
295 
296 static inline int cr16_print_reg_reg(struct cr16_cmd *cmd, ut8 src, ut8 dst) {
298  return -1;
299  }
300 
301  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "%s,%s",
303 
304  return 0;
305 }
306 
307 static inline int cr16_print_4biti_opcode(struct cr16_cmd *cmd, ut16 instr) {
309  return -1;
310  }
311 
312  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "%s%c",
314  cr16_get_opcode_i(instr) ? 'w' : 'b');
315  return 0;
316 }
317 
318 static inline int cr16_print_4bit_opcode(struct cr16_cmd *cmd, ut16 instr) {
320  return -1;
321  }
322 
323  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "%s",
325 
326  return 0;
327 }
328 
329 static inline void cr16_analysis_4bit_opcode(const ut16 in, struct cr16_cmd *cmd) {
330  switch (cr16_get_opcode_low(in)) {
331  case CR16_ADDU:
332  case CR16_ADD:
333  cmd->type = CR16_TYPE_ADD;
334  break;
335  case CR16_BITI:
336  cmd->type = CR16_TYPE_BIT;
337  break;
338  case CR16_MUL:
339  cmd->type = CR16_TYPE_MUL;
340  break;
341  case CR16_SUBC:
342  case CR16_SUB:
343  cmd->type = CR16_TYPE_SUB;
344  break;
345  case CR16_CMP:
346  cmd->type = CR16_TYPE_CMP;
347  break;
348  case CR16_XOR:
349  cmd->type = CR16_TYPE_XOR;
350  break;
351  case CR16_OR:
352  cmd->type = CR16_TYPE_OR;
353  break;
354  case CR16_ASHU:
355  case CR16_LSH:
356  cmd->type = CR16_TYPE_SHIFT;
357  break;
358  case CR16_MOV:
359  cmd->type = CR16_TYPE_MOV;
360  break;
361  case CR16_AND:
362  cmd->type = CR16_TYPE_AND;
363  break;
364  }
365 }
366 
367 static inline int cr16_decode_i_r(const ut8 *instr, struct cr16_cmd *cmd, int len) {
368  int ret = 2;
369  ut16 in, immed, dstreg;
370 
371  if (len < 2) {
372  return -1;
373  }
374  in = rz_read_le16(instr);
375 
376  if (in == 0x0200) {
377  return -1;
378  }
379 
380  if (((in >> 9) != CR16_TBIT_I_R) && ((in >> 9) != CR16_TBIT_R_R)) {
382  return -1;
383  }
385  } else {
386  if (cr16_print_4bit_opcode(cmd, in)) {
387  return -1;
388  }
389  }
390 
391  switch ((in & 0x1F) ^ 0x11) {
392  case 0:
393  if ((in & 0x1) == 0x1) {
394  if (len < 4) {
395  return -1;
396  }
397  immed = rz_read_at_le16(instr, 2);
398  ret = 4;
399  } else {
400  immed = cr16_get_short_imm(in);
401  }
402  if (((in >> 9) != CR16_TBIT_I_R) && ((in >> 9) != CR16_TBIT_R_R)) {
403  if (cr16_print_med_reg(cmd, immed, cr16_get_dstreg(in))) {
404  return -1;
405  }
406  } else {
407  if (cr16_print_reg_med(cmd, immed, cr16_get_dstreg(in))) {
408  return -1;
409  }
410  }
411  break;
412  default:
413  dstreg = cr16_get_dstreg(in);
414 
415  if (cr16_check_reg_boundaries(dstreg)) {
416  ret = -1;
417  break;
418  }
419 
420  if (((in >> 9) != CR16_TBIT_I_R) && ((in >> 9) != CR16_TBIT_R_R)) {
422  cr16_get_dstreg(in))) {
423  return -1;
424  }
425  } else {
427  cr16_get_dstreg(in))) {
428  return -1;
429  }
430  }
431  break;
432  }
433 
434  return ret;
435 }
436 
437 static inline int cr16_decode_ld_st(const ut8 *instr, struct cr16_cmd *cmd, int len) {
438  int ret = 2;
439  ut32 disp32;
440  ut16 disp16;
441 
442  if (len < 2) {
443  return -1;
444  }
445  ut16 c = rz_read_le16(instr);
446 
447  if (cr16_print_ld_sw_opcode(cmd, c)) {
448  return -1;
449  }
450 
451  switch (cr16_get_opcode_159_0(c) & (~0x20)) {
452  case 0x04:
453  ret = 4;
454  if ((c & 0xC0) != 0xC0) {
455  ret = -1;
456  break;
457  }
458  if (len < 4) {
459  return -1;
460  }
461  disp16 = rz_read_at_le16(instr, 2);
462 
463  disp32 = disp16 | ((c & 0x0100) << 9) | ((c & 0x0020) << 11);
464 
466  break;
467  case 0x05:
468  ret = 4;
469  if (len < 4) {
470  return -1;
471  }
472  disp16 = rz_read_at_le16(instr, 2);
473 
475  disp16, cr16_get_dstreg(c) & 0x9)) {
476  return -1;
477  }
478  break;
479  case 0x45:
480  if (!(c & 0x1) || ((c >> 6) & 0x3) != 0x3) {
481  ret = -1;
482  break;
483  }
485  cr16_get_dstreg(c) & 0x9)) {
486  return -1;
487  }
488  break;
489  default:
490  ret = -1;
491  }
492 
493  if (ret != -1) {
494  return ret;
495  }
496 
497  switch ((c >> 11) & (~0x4)) {
498  case 0x12:
499  ret = 4;
500  if (!(c & 1)) {
501  ret = -1;
502  break;
503  }
504  if (len < 4) {
505  return -1;
506  }
507  disp16 = rz_read_at_le16(instr, 2);
508  disp32 = disp16 | (((c >> 9) & 0x3) << 16);
509 
511  cr16_get_dstreg(c), 0);
512  break;
513 
514  case 0x13:
515  ret = 4;
516  if (len < 4) {
517  return -1;
518  }
519  disp16 = rz_read_at_le16(instr, 2);
520  disp32 = disp16 | (((c >> 9) & 0x3) << 16);
521 
522  if (cr16_get_srcreg(c) == 0xF) {
524  } else {
526  cr16_get_dstreg(c), 0);
527  }
528  break;
529  case 0x1B:
530  ret = 4;
531  if (len < 4) {
532  return -1;
533  }
534  disp16 = rz_read_at_le16(instr, 2);
535  disp32 = disp16 | (((c >> 9) & 0x3) << 16);
536 
537  if (cr16_get_srcreg(c) == 0xF) {
539  } else {
541  cr16_get_srcreg(c), 1);
542  }
543  break;
544  case 0x1A:
545  ret = 4;
546  if (len < 4) {
547  return -1;
548  }
549  disp16 = rz_read_at_le16(instr, 2);
550  disp32 = disp16 | (((c >> 9) & 0x3) << 16);
551 
553  cr16_get_dstreg(c), 1);
554 
555  break;
556  default:
557  ret = -1;
558  }
559 
560  if (ret != -1) {
561  return ret;
562  }
563 
564  switch (c >> 14) {
565  case 0x3:
566  ret = 2;
567  disp16 = (c & 0x1) | ((c >> 8) & 0x1E);
569  disp16, cr16_get_dstreg(c), 1);
570  break;
571  case 0x2:
572  ret = 2;
573  disp16 = (c & 0x1) | ((c >> 8) & 0x1E);
575  disp16, cr16_get_dstreg(c), 0);
576  break;
577  default:
578  ret = -1;
579  }
580  return ret;
581 }
582 
583 static int cr16_decode_slpr(const ut8 *instr, struct cr16_cmd *cmd, int len) {
584  int ret = 2;
585 
586  if (len < 2) {
587  return -1;
588  }
589  ut16 c = rz_read_le16(instr);
590 
591  const char *ins = instrs_4bit[c >> 9];
592  if (ins) {
593  rz_str_ncpy(cmd->instr, ins, sizeof(cmd->instr) - 1);
594  } else {
595  *cmd->instr = 0;
596  }
597 
598  switch (c >> 9) {
599  case CR16_LPR:
600  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
601  "%s,%s", cr16_regs_names[cr16_get_srcreg(c)],
603  break;
604  case CR16_SPR:
605  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
606  "%s,%s", dedicated_regs[cr16_get_dstreg(c)],
608  break;
609  }
610 
611  cmd->type = CR16_TYPE_SLPR;
612 
613  return ret;
614 }
615 
616 static int cr16_decode_r_r(const ut8 *instr, struct cr16_cmd *cmd, int len) {
617  int ret = 2;
618  ut16 c;
619 
620  if (len < 2) {
621  return -1;
622  }
623  c = rz_read_le16(instr);
624 
625  if (!(c & 0x1)) {
626  return -1;
627  }
628 
629  if (((c >> 9) != CR16_TBIT_I_R) && ((c >> 9) != CR16_TBIT_R_R)) {
630  if (cr16_print_4biti_opcode(cmd, c)) {
631  return -1;
632  }
634  } else {
635  if (cr16_print_4bit_opcode(cmd, c)) {
636  return -1;
637  }
638  }
639 
641  return -1;
642  }
643 
644  return ret;
645 }
646 
647 static inline ut8 cr16_get_cond(const ut16 c) {
648  return ((c >> 5) & 0xF);
649 }
650 
651 static int cr16_decode_push_pop(const ut8 *instr, struct cr16_cmd *cmd, int len) {
652  int ret = 2;
653  ut16 c;
654 
655  if (len < 2) {
656  return -1;
657  }
658  c = rz_read_le16(instr);
659 
660  if ((c & 1)) {
661  return -1;
662  }
663 
664  switch (c >> 7) {
665  case CR16_PUSH:
666  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "push");
667  break;
668  case CR16_POP:
669  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "pop");
670  break;
671  case CR16_POPRET_1:
672  case CR16_POPRET_2:
673  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "popret");
674  break;
675  }
676 
677  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "$0x%x,%s",
678  ((c >> 5) & 0x3) + 1,
679  cr16_regs_names[(c >> 1) & 0xF]);
680 
681  return ret;
682 }
683 
684 static int cr16_decode_jmp(const ut8 *instr, struct cr16_cmd *cmd, int len) {
685  ut16 c;
686  int ret = 2;
687 
688  if (len < 2) {
689  return -1;
690  }
691  c = rz_read_le16(instr);
692 
693  switch (c >> 9) {
694  case CR16_JUMP:
695  if (((c >> 5) & 0xf) == 0xE) {
696  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "jump");
697  } else {
698  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "j%s",
700  }
701  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "%s",
703  break;
704  case CR16_JAL:
705  if (!(c & 1)) {
706  ret = -1;
707  break;
708  }
709  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "jal");
711  cmd->type = CR16_TYPE_JUMP_UNK;
712  break;
713  case 0x0B:
714  if (!(c & 1)) {
715  strncpy(cmd->instr, "jal", CR16_INSTR_MAXLEN - 1);
716  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "(%s,%s),(%s,%s)",
721  } else if (cr16_get_dstreg(c) != 0xE) {
722  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "j%s",
724  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "(%s,%s)",
727  } else {
728  strncpy(cmd->instr, "jump", CR16_INSTR_MAXLEN - 1);
729  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "(%s,%s)",
732  }
733  break;
734  default:
735  return -1;
736  }
737 
738  cmd->type = CR16_TYPE_JUMP_UNK;
739  return ret;
740 }
741 
742 static int cr16_decode_bcond_br(const ut8 *instr, struct cr16_cmd *cmd, int len) {
743  int ret = 2;
744 
745  ut16 c, disp;
746  ut32 disp32;
747 
748  if (len < 2) {
749  return -1;
750  }
751  c = rz_read_le16(instr);
752 
753  if (c & 0x1) {
754  return -1;
755  }
756 
757  if (!(c >> 14) && cr16_get_opcode_low(c) != 0xA) {
758  return -1;
759  }
760 
761  if (((c >> 5) & 0xF) == 0xE) {
762  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "br");
763  if (((c >> 1) & 0x7) == 0x7) {
764  if (len < 4) {
765  return -1;
766  }
767  disp = rz_read_at_le16(instr, 2);
768 
769  disp32 = disp | (((c >> 4) & 0x1) << 16);
770  ret = 4;
771  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
772  "0x%08x", disp32);
773 
774  if (disp32 & 0x10000) {
775  disp32 |= 0xFFFE0000;
776  cmd->reladdr = (st32)disp32;
777  } else {
778  cmd->reladdr = disp32;
779  }
780  } else {
781  if (cr16_get_opcode_i(c)) {
782  ret = 4;
783  if (len < 4) {
784  return -1;
785  }
786  disp = rz_read_at_le16(instr, 2);
787  disp32 = disp | (((c >> 1) & 0x7) << 17) | (((c >> 4) & 1) << 16);
788  if (disp32 & 0x80000) {
789  disp32 |= 0xFFF00000;
790  cmd->reladdr = (st32)disp32;
791  } else {
792  cmd->reladdr = disp32;
793  }
794  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "0x%08x", disp32);
795  } else {
796  disp = (c & 0x1F) | ((c >> 4) & 0x1E0);
797 
798  if (disp & 0x0100) {
799  disp |= 0xFE00;
800  cmd->reladdr = (st16)disp;
801  } else {
802  cmd->reladdr = disp;
803  }
804 
805  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "0x%04x", disp);
806  }
807  }
808  cmd->type = CR16_TYPE_JUMP;
809  } else {
810  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "b%s",
812  if (c & 0x1) {
813  return -1;
814  }
815 
816  if ((c >> 8) == CR16_BCOND_2) {
817  if (len < 4) {
818  return -1;
819  }
820  disp = rz_read_at_le16(instr, 2);
821  disp32 = disp | (GET_BIT(c, 4) << 16);
822  if (disp32 & 0x80000) {
823  disp32 |= 0xFFF00000;
824  cmd->reladdr = (st32)disp32;
825  } else {
826  cmd->reladdr = disp32;
827  }
828  ret = 4;
829  } else {
830  disp = (c & 0x1F) | ((c >> 4) & 0x1E0);
831 
832  if (disp & 0x0100) {
833  disp |= 0xFE00;
834  cmd->reladdr = (st16)disp;
835  } else {
836  cmd->reladdr = disp;
837  }
838 
839  disp32 = disp;
840  }
841 
842  cmd->type = CR16_TYPE_BCOND;
843  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "0x%04x", disp32);
844  }
845 
846  return ret;
847 }
848 
849 static int cr16_decode_bcond01i(const ut8 *instr, struct cr16_cmd *cmd, int len) {
850  ut16 c;
851  int ret = 2;
852 
853  if (len < 2) {
854  return -1;
855  }
856  c = rz_read_le16(instr);
857 
858  if (!(c & 1)) {
859  return -1;
860  }
861 
862  if (c >> 14) {
863  return -1;
864  }
865 
866  switch ((c >> 6) & 0x3) {
867  case 0x0:
868  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "%s%c",
869  "beq0", cr16_get_opcode_i(c) ? 'w' : 'b');
870  break;
871  case 0x1:
872  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "%s%c",
873  "beq1", cr16_get_opcode_i(c) ? 'w' : 'b');
874  break;
875  case 0x2:
876  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "%s%c",
877  "bne0", cr16_get_opcode_i(c) ? 'w' : 'b');
878  break;
879  case 0x3:
880  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "%s%c",
881  "bne1", cr16_get_opcode_i(c) ? 'w' : 'b');
882  break;
883  }
884 
885  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "%s,0x%x",
887  (c >> 1) & 0xF);
888 
889  cmd->type = CR16_TYPE_BCOND;
890 
891  return ret;
892 }
893 
894 static int cr16_decode_misc(const ut8 *instr, struct cr16_cmd *cmd, int len) {
895  ut16 c;
896  int ret = 2;
897 
898  if (len < 2) {
899  return -1;
900  }
901  c = rz_read_le16(instr);
902 
903  cmd->operands[0] = '\0';
904  switch (c) {
905  case CR16_RETX:
906  strncpy(cmd->instr, "retx", CR16_INSTR_MAXLEN - 1);
907  cmd->type = CR16_TYPE_RETX;
908  break;
909  case CR16_DI:
910  strncpy(cmd->instr, "di", CR16_INSTR_MAXLEN - 1);
911  cmd->type = CR16_TYPE_DI;
912  break;
913  case CR16_EI:
914  strncpy(cmd->instr, "ei", CR16_INSTR_MAXLEN - 1);
915  cmd->type = CR16_TYPE_EI;
916  break;
917  case CR16_NOP:
918  strncpy(cmd->instr, "nop", CR16_INSTR_MAXLEN - 1);
919  cmd->type = CR16_TYPE_NOP;
920  break;
921  case CR16_WAIT:
922  strncpy(cmd->instr, "wait", CR16_INSTR_MAXLEN - 1);
923  cmd->type = CR16_TYPE_WAIT;
924  break;
925  case CR16_EWAIT:
926  strncpy(cmd->instr, "eiwait", CR16_INSTR_MAXLEN - 1);
927  cmd->type = CR16_TYPE_EWAIT;
928  break;
929  default:
930  switch (c >> 5) {
931  case 0x3DF:
932  strncpy(cmd->instr, "excp", CR16_INSTR_MAXLEN - 1);
933  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
934  "0x%x", (c >> 1) & 0xF);
935  cmd->type = CR16_TYPE_EXCP;
936  break;
937  default:
938  ret = -1;
939  }
940  }
941 
942  return ret;
943 }
944 
945 static int cr16_decode_bal(const ut8 *instr, struct cr16_cmd *cmd, int len) {
946  int ret = 4;
947  ut16 c, disp16;
948  ut32 disp32;
949 
950  if (len < 4) {
951  return -1;
952  }
953  c = rz_read_le16(instr);
954  disp16 = rz_read_at_le16(instr, 2);
955 
956  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "bal");
957 
958  switch (c >> 9) {
959  case CR16_BAL:
960  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "%s,0x%x",
961  cr16_regs_names[cr16_get_dstreg(c)], disp16);
962  break;
963  case CR16_TBIT_R_R:
964  disp32 = disp16 | (((c >> 1) & 0xF) << 16);
965  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "(%s,%s),0x%08x",
967  cr16_regs_names[cr16_get_dstreg(c)], disp32);
968  break;
969  default:
970  return -1;
971  }
972 
973  return ret;
974 }
975 
976 int cr16_decode_loadm_storm(const ut8 *instr, struct cr16_cmd *cmd, int len) {
977  int ret = 2;
978  ut16 c;
979 
980  if (len < 2) {
981  return -1;
982  }
983  c = rz_read_le16(instr);
984 
985  if ((c & 0x1F) != 4) {
986  return -1;
987  }
988 
989  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "%s",
990  instrs_4bit[c >> 7]);
991  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "$0x%x",
992  ((c >> 5) & 0x3) + 1);
993 
994  cmd->type = CR16_TYPE_MOV;
995 
996  return ret;
997 }
998 
999 int cr16_decode_movz(const ut8 *instr, struct cr16_cmd *cmd, int len) {
1000  int ret = 2;
1001  ut16 c;
1002 
1003  if (len < 2) {
1004  return -1;
1005  }
1006  c = rz_read_le16(instr);
1007 
1008  if (c & 1) {
1009  return -1;
1010  }
1011 
1012  switch (c >> 9) {
1013  case CR16_MOVXB:
1014  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "movxb");
1015  break;
1016  case CR16_MOVZB:
1017  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "movzb");
1018  break;
1019  default:
1020  return -1;
1021  }
1022 
1023  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "%s,%s",
1026 
1027  return ret;
1028 }
1029 
1030 int cr16_decode_movd(const ut8 *instr, struct cr16_cmd *cmd, int len) {
1031  int ret = 4;
1032  ut16 c;
1033  ut16 imm;
1034  ut32 imm32;
1035 
1036  if (len < 4) {
1037  return -1;
1038  }
1039  c = rz_read_le16(instr);
1040  imm = rz_read_at_le16(instr, 2);
1041 
1042  if (c & 1) {
1043  return -1;
1044  }
1045 
1046  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "movd");
1047 
1048  imm32 = imm | (((c >> 4) & 1) << 16) | (((c >> 9) & 1) << 20) | (((c >> 1) & 0x7) << 17);
1049  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "$0x%08x,(%s,%s)", imm32,
1050  cr16_regs_names[((c >> 5) & 0xF) + 1],
1051  cr16_regs_names[(c >> 5) & 0xF]);
1052 
1053  return ret;
1054 }
1055 
1056 int cr16_decode_muls(const ut8 *instr, struct cr16_cmd *cmd, int len) {
1057  int ret = 2;
1058  ut16 c;
1059 
1060  if (len < 2) {
1061  return -1;
1062  }
1063  c = rz_read_le16(instr);
1064 
1065  switch (c >> 9) {
1066  case CR16_MULSB:
1067  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "mulsb");
1068  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "%s,%s",
1071  break;
1072  case CR16_MULSW:
1073  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "mulsw");
1074  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "%s,(%s,%s)",
1078  break;
1079  case CR16_MULUW:
1080  if (c & 0x000C) {
1081  return -1;
1082  }
1083 
1084  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "muluw");
1085  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "%s,(%s,%s)",
1089  break;
1090  }
1091 
1092  return ret;
1093 }
1094 
1095 int cr16_decode_scond(const ut8 *instr, struct cr16_cmd *cmd, int len) {
1096  int ret = 2;
1097  ut16 c;
1098 
1099  if (len < 2) {
1100  return -1;
1101  }
1102  c = rz_read_le16(instr);
1103 
1104  if (c & 1) {
1105  return -1;
1106  }
1107 
1108  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "s%s",
1110  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "%s",
1112 
1113  cmd->type = CR16_TYPE_SCOND;
1114 
1115  return ret;
1116 }
1117 
1118 int cr16_decode_biti(const ut8 *instr, struct cr16_cmd *cmd, int len) {
1119  int ret = 2;
1120  ut32 abs18;
1121  ut16 c, disp16;
1122  ut8 reg, position;
1123 
1124  if (len < 2) {
1125  return -1;
1126  }
1127  c = rz_read_le16(instr);
1128 
1129  if (((c >> 6) & 0x3) == 0x3) {
1130  return -1;
1131  }
1132 
1133  reg = cr16_get_dstreg(c);
1134  position = cr16_get_srcreg(c);
1135 
1136  if (!(reg & 0x6)) {
1137  return -1;
1138  }
1139 
1140  snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "%s%c",
1141  ops_biti[(c >> 6) & 0x3],
1142  cr16_get_opcode_i(c) ? 'w' : 'b');
1143 
1144  switch (((c >> 13) & 0x2) | (c & 0x1)) {
1145  case 0x0:
1146  ret = 4;
1147  if (len < 4) {
1148  return -1;
1149  }
1150  disp16 = rz_read_at_le16(instr, 2);
1151 
1152  abs18 = disp16 | ((reg & 0x1) << 16) | ((reg >> 3) << 17);
1153 
1154  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
1155  "$0x%02x,0x%08x", position, abs18);
1156 
1157  break;
1158  case 0x1:
1159  ret = 4;
1160 
1161  if (len < 4) {
1162  return -1;
1163  }
1164  disp16 = rz_read_at_le16(instr, 2);
1165 
1166  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
1167  "$0x%02x,0x%04x(%s)", position,
1168  disp16, cr16_regs_names[reg & 0x9]);
1169 
1170  break;
1171  case 0x3:
1172  snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1,
1173  "$0x%02x,0(%s)", position,
1174  cr16_regs_names[reg & 0x9]);
1175  break;
1176  default:
1177  ret = -1;
1178  }
1179 
1180  cmd->type = CR16_TYPE_BIT;
1181  return ret;
1182 }
1183 
1184 int cr16_decode_command(const ut8 *instr, struct cr16_cmd *cmd, int len) {
1185  int ret;
1186  ut16 in;
1187  if (len < 2) {
1188  return -1;
1189  }
1190  in = rz_read_le16(instr);
1191 
1192  switch (cr16_get_opcode_low(in)) {
1193  case CR16_MOV:
1194  case CR16_ADD:
1195  case CR16_ADDU:
1196  case CR16_ADDC:
1197  case CR16_MUL:
1198  case CR16_SUB:
1199  case CR16_SUBC:
1200  case CR16_CMP:
1201  case CR16_AND:
1202  case CR16_OR:
1203  case CR16_XOR:
1204  case CR16_ASHU:
1205  case CR16_LSH:
1206  switch (cr16_get_opcode_hi(in)) {
1207  case CR16_I_R:
1208  ret = cr16_decode_i_r(instr, cmd, len);
1209  break;
1210  case CR16_R_R:
1211  ret = cr16_decode_r_r(instr, cmd, len);
1212  break;
1213  default:
1214  ret = -1;
1215  }
1216  if (ret == -1 && cr16_get_opcode_low(in) == CR16_CMP) {
1217  ret = cr16_decode_scond(instr, cmd, len);
1218  }
1219  break;
1220  case CR16_BCOND01:
1221  ret = cr16_decode_bcond01i(instr, cmd, len);
1222  break;
1223  case CR16_BITI:
1224  ret = cr16_decode_biti(instr, cmd, len);
1225  break;
1226  default:
1227  ret = -1;
1228  }
1229 
1230  if (ret != -1) {
1231  return ret;
1232  }
1233 
1234  switch ((in >> 13)) {
1235  case 0x2:
1236  case 0x0:
1237  ret = cr16_decode_bcond_br(instr, cmd, len);
1238  break;
1239  }
1240 
1241  if (ret != -1) {
1242  return ret;
1243  }
1244 
1245  switch (in >> 9) {
1246  case CR16_LPR:
1247  case CR16_SPR:
1248  ret = cr16_decode_slpr(instr, cmd, len);
1249  break;
1250  case CR16_TBIT_R_R:
1251  ret = cr16_decode_r_r(instr, cmd, len);
1252  if (ret == -1) {
1253  ret = cr16_decode_bal(instr, cmd, len);
1254  }
1255  break;
1256  case CR16_TBIT_I_R:
1257  ret = cr16_decode_i_r(instr, cmd, len);
1258  break;
1259  case CR16_BAL:
1260  ret = cr16_decode_bal(instr, cmd, len);
1261  break;
1262  case CR16_JUMP:
1263  case CR16_JAL:
1264  case 0x0B:
1265  ret = cr16_decode_jmp(instr, cmd, len);
1266  if (ret == -1) {
1267  ret = cr16_decode_bcond_br(instr, cmd, len);
1268  }
1269  break;
1270  case CR16_MOVXB:
1271  case CR16_MOVZB:
1272  ret = cr16_decode_movz(instr, cmd, len);
1273  break;
1274  case CR16_MULSB:
1275  case CR16_MULSW:
1276  case CR16_MULUW:
1277  ret = cr16_decode_muls(instr, cmd, len);
1278  break;
1279  }
1280 
1281  if (ret != -1) {
1282  return ret;
1283  }
1284 
1285  switch (in >> 7) {
1286  case CR16_PUSH:
1287  case CR16_POP:
1288  case CR16_POPRET_1:
1289  case CR16_POPRET_2:
1290  ret = cr16_decode_push_pop(instr, cmd, len);
1291  break;
1292  case CR16_LOADM:
1293  case CR16_STORM:
1294  ret = cr16_decode_loadm_storm(instr, cmd, len);
1295  break;
1296  }
1297 
1298  if (ret != -1) {
1299  return ret;
1300  }
1301 
1302  switch (in >> 10) {
1303  case CR16_MOVD:
1304  ret = cr16_decode_movd(instr, cmd, len);
1305  break;
1306  }
1307 
1308  if (ret != -1) {
1309  return ret;
1310  }
1311 
1312  ret = cr16_decode_misc(instr, cmd, len);
1313 
1314  if (ret != -1) {
1315  return ret;
1316  }
1317 
1318  switch (cr16_get_opcode_hi(in)) {
1319  case 0x2:
1320  case 0x3:
1321  case 0x1:
1322  case 0x0:
1323  ret = cr16_decode_ld_st(instr, cmd, len);
1324  break;
1325  }
1326 
1327  if (ret != -1) {
1328  return ret;
1329  }
1330  return ret;
1331 }
size_t len
Definition: 6502dis.c:15
#define imm
lzma_index * src
Definition: index.h:567
const lzma_allocator const uint8_t * in
Definition: block.h:527
static int cr16_decode_push_pop(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:651
static ut8 cr16_get_opcode_low(const ut16 instr)
Definition: cr16_disas.c:96
static int cr16_decode_bal(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:945
static int cr16_print_reg_rel_reg(struct cr16_cmd *cmd, ut32 rel, ut8 srcreg, ut8 dstreg, ut8 swap)
Definition: cr16_disas.c:240
static int cr16_print_reg_reg_rel(struct cr16_cmd *cmd, ut8 src, ut16 rel, ut8 dst, ut8 swap)
Definition: cr16_disas.c:206
int cr16_decode_loadm_storm(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:976
static ut8 cr16_get_opcode_i(const ut16 instr)
Definition: cr16_disas.c:104
static int cr16_print_longregreg_reg(struct cr16_cmd *cmd, ut32 rel, ut8 src, ut8 dst, ut8 swap)
Definition: cr16_disas.c:277
static const char * ops_biti[]
Definition: cr16_disas.c:90
static int cr16_decode_r_r(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:616
static int cr16_decode_bcond01i(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:849
static ut8 cr16_get_cond(const ut16 c)
Definition: cr16_disas.c:647
static ut8 cr16_get_opcode_hi(const ut16 instr)
Definition: cr16_disas.c:100
static int cr16_print_short_abs18(struct cr16_cmd *cmd, ut8 sh, ut32 abs)
Definition: cr16_disas.c:199
static int cr16_print_4biti_opcode(struct cr16_cmd *cmd, ut16 instr)
Definition: cr16_disas.c:307
static const char * cr16_regs_names[]
Definition: cr16_disas.c:11
static int cr16_check_instrs_4bit_bndrs(const ut8 opcode)
Definition: cr16_disas.c:120
static int cr16_print_short_reg_rel(struct cr16_cmd *cmd, ut8 sh, ut16 rel, ut8 reg)
Definition: cr16_disas.c:223
static int cr16_print_reg_med(struct cr16_cmd *cmd, ut16 med, ut8 reg)
Definition: cr16_disas.c:188
static int cr16_print_reg_short(struct cr16_cmd *cmd, ut8 sh, ut8 reg)
Definition: cr16_disas.c:166
int cr16_decode_movd(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:1030
static ut8 cr16_get_srcreg(const ut16 instr)
Definition: cr16_disas.c:116
static int cr16_print_long_reg(struct cr16_cmd *cmd, ut32 l, ut8 reg, ut8 swap)
Definition: cr16_disas.c:261
static int cr16_decode_misc(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:894
static int cr16_print_reg_reg(struct cr16_cmd *cmd, ut8 src, ut8 dst)
Definition: cr16_disas.c:296
int cr16_decode_movz(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:999
static int cr16_print_short_reg(struct cr16_cmd *cmd, ut8 sh, ut8 reg)
Definition: cr16_disas.c:155
int cr16_decode_scond(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:1095
static int cr16_decode_ld_st(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:437
static int cr16_check_reg_boundaries(const ut8 reg)
Definition: cr16_disas.c:131
static ut8 cr16_get_dstreg(const ut16 instr)
Definition: cr16_disas.c:112
#define GET_BIT(x, n)
Definition: cr16_disas.c:9
static int cr16_decode_i_r(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:367
static int cr16_decode_jmp(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:684
static int cr16_decode_bcond_br(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:742
int cr16_decode_muls(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:1056
static ut16 cr16_get_opcode_159_0(const ut16 opc)
Definition: cr16_disas.c:127
static int cr16_print_ld_sw_opcode(struct cr16_cmd *cmd, ut16 instr)
Definition: cr16_disas.c:138
static const char * ld_sw[]
Definition: cr16_disas.c:71
int cr16_decode_biti(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:1118
static ut8 cr16_get_short_imm(const ut16 instr)
Definition: cr16_disas.c:108
static const char * instrs_4bit[]
Definition: cr16_disas.c:31
int cr16_decode_command(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:1184
static int cr16_print_med_reg(struct cr16_cmd *cmd, ut16 med, ut8 reg)
Definition: cr16_disas.c:177
static void cr16_analysis_4bit_opcode(const ut16 in, struct cr16_cmd *cmd)
Definition: cr16_disas.c:329
static int cr16_print_4bit_opcode(struct cr16_cmd *cmd, ut16 instr)
Definition: cr16_disas.c:318
static const char * dedicated_regs[]
Definition: cr16_disas.c:78
static int cr16_decode_slpr(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:583
@ CR16_R_R
Definition: cr16_disas.h:105
@ CR16_I_R
Definition: cr16_disas.h:104
@ CR16_CMP
Definition: cr16_disas.h:62
@ CR16_ASHU
Definition: cr16_disas.h:59
@ CR16_SUB
Definition: cr16_disas.h:68
@ CR16_JUMP
Definition: cr16_disas.h:80
@ CR16_MULUW
Definition: cr16_disas.h:74
@ CR16_BCOND01
Definition: cr16_disas.h:65
@ CR16_MOVD
Definition: cr16_disas.h:71
@ CR16_PUSH
Definition: cr16_disas.h:86
@ CR16_BCOND_2
Definition: cr16_disas.h:85
@ CR16_SUBC
Definition: cr16_disas.h:69
@ CR16_LSH
Definition: cr16_disas.h:60
@ CR16_XOR
Definition: cr16_disas.h:61
@ CR16_LOADM
Definition: cr16_disas.h:90
@ CR16_OR
Definition: cr16_disas.h:70
@ CR16_MOV
Definition: cr16_disas.h:67
@ CR16_BAL
Definition: cr16_disas.h:82
@ CR16_AND
Definition: cr16_disas.h:63
@ CR16_BITI
Definition: cr16_disas.h:57
@ CR16_ADDU
Definition: cr16_disas.h:56
@ CR16_ADD
Definition: cr16_disas.h:55
@ CR16_MOVXB
Definition: cr16_disas.h:75
@ CR16_POPRET_2
Definition: cr16_disas.h:89
@ CR16_TBIT_R_R
Definition: cr16_disas.h:78
@ CR16_MOVZB
Definition: cr16_disas.h:76
@ CR16_POP
Definition: cr16_disas.h:87
@ CR16_MUL
Definition: cr16_disas.h:58
@ CR16_SPR
Definition: cr16_disas.h:84
@ CR16_TBIT_I_R
Definition: cr16_disas.h:79
@ CR16_LPR
Definition: cr16_disas.h:83
@ CR16_ADDC
Definition: cr16_disas.h:64
@ CR16_MULSB
Definition: cr16_disas.h:72
@ CR16_STORM
Definition: cr16_disas.h:91
@ CR16_MULSW
Definition: cr16_disas.h:73
@ CR16_POPRET_1
Definition: cr16_disas.h:88
@ CR16_TBIT
Definition: cr16_disas.h:66
@ CR16_JAL
Definition: cr16_disas.h:81
@ CR16_RA
Definition: cr16_disas.h:123
@ CR16_LAST
Definition: cr16_disas.h:125
@ CR16_R4
Definition: cr16_disas.h:113
@ CR16_R0
Definition: cr16_disas.h:109
@ CR16_R1
Definition: cr16_disas.h:110
@ CR16_R8
Definition: cr16_disas.h:117
@ CR16_R12
Definition: cr16_disas.h:121
@ CR16_R2
Definition: cr16_disas.h:111
@ CR16_R7
Definition: cr16_disas.h:116
@ CR16_R6
Definition: cr16_disas.h:115
@ CR16_R9
Definition: cr16_disas.h:118
@ CR16_R5
Definition: cr16_disas.h:114
@ CR16_SP
Definition: cr16_disas.h:124
@ CR16_R10
Definition: cr16_disas.h:119
@ CR16_R11
Definition: cr16_disas.h:120
@ CR16_R13
Definition: cr16_disas.h:122
@ CR16_R3
Definition: cr16_disas.h:112
@ CR16_WAIT
Definition: cr16_disas.h:99
@ CR16_EWAIT
Definition: cr16_disas.h:100
@ CR16_DI
Definition: cr16_disas.h:96
@ CR16_NOP
Definition: cr16_disas.h:98
@ CR16_EI
Definition: cr16_disas.h:97
@ CR16_RETX
Definition: cr16_disas.h:95
cr16_conds
Definition: cr16_disas.h:134
@ CR16_COND_EQ
Definition: cr16_disas.h:135
@ CR16_COND_HI
Definition: cr16_disas.h:139
@ CR16_COND_CC
Definition: cr16_disas.h:138
@ CR16_COND_LE
Definition: cr16_disas.h:142
@ CR16_COND_GT
Definition: cr16_disas.h:141
@ CR16_COND_LT
Definition: cr16_disas.h:147
@ CR16_COND_GE
Definition: cr16_disas.h:148
@ CR16_COND_HS
Definition: cr16_disas.h:146
@ CR16_COND_FC
Definition: cr16_disas.h:144
@ CR16_COND_FS
Definition: cr16_disas.h:143
@ CR16_COND_LO
Definition: cr16_disas.h:145
@ CR16_COND_LS
Definition: cr16_disas.h:140
@ CR16_COND_CS
Definition: cr16_disas.h:137
@ CR16_COND_NE
Definition: cr16_disas.h:136
#define CR16_INSTR_MAXLEN
Definition: cr16_disas.h:7
@ CR16_TYPE_EI
Definition: cr16_disas.h:39
@ CR16_TYPE_DI
Definition: cr16_disas.h:38
@ CR16_TYPE_EXCP
Definition: cr16_disas.h:28
@ CR16_TYPE_JUMP
Definition: cr16_disas.h:31
@ CR16_TYPE_BIT
Definition: cr16_disas.h:23
@ CR16_TYPE_RETX
Definition: cr16_disas.h:33
@ CR16_TYPE_MOV
Definition: cr16_disas.h:11
@ CR16_TYPE_SLPR
Definition: cr16_disas.h:24
@ CR16_TYPE_MUL
Definition: cr16_disas.h:13
@ CR16_TYPE_SUB
Definition: cr16_disas.h:14
@ CR16_TYPE_WAIT
Definition: cr16_disas.h:41
@ CR16_TYPE_JUMP_UNK
Definition: cr16_disas.h:32
@ CR16_TYPE_SCOND
Definition: cr16_disas.h:20
@ CR16_TYPE_OR
Definition: cr16_disas.h:19
@ CR16_TYPE_XOR
Definition: cr16_disas.h:21
@ CR16_TYPE_SHIFT
Definition: cr16_disas.h:22
@ CR16_TYPE_ADD
Definition: cr16_disas.h:12
@ CR16_TYPE_CMP
Definition: cr16_disas.h:15
@ CR16_TYPE_NOP
Definition: cr16_disas.h:40
@ CR16_TYPE_EWAIT
Definition: cr16_disas.h:42
@ CR16_TYPE_BCOND
Definition: cr16_disas.h:25
@ CR16_TYPE_AND
Definition: cr16_disas.h:18
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
Definition: sflib.h:79
uint16_t ut16
uint32_t ut32
static ut64 opc
Definition: desil.c:33
snprintf
Definition: kernel.h:364
#define reg(n)
uint8_t ut8
Definition: lh5801.h:11
char * dst
Definition: lz4.h:724
#define swap(a, b)
Definition: qsort.h:111
static ut16 rz_read_at_le16(const void *src, size_t offset)
Definition: rz_endian.h:214
static ut16 rz_read_le16(const void *src)
Definition: rz_endian.h:206
RZ_API size_t rz_str_ncpy(char *dst, const char *src, size_t n)
Secure string copy with null terminator.
Definition: str.c:923
#define st16
Definition: rz_types_base.h:14
#define st32
Definition: rz_types_base.h:12
#define c(i)
Definition: sha256.c:43