1 /* Capstone Disassembler Engine */
2 /* By Fotis Loukos <me@fotisl.com>, 2017 */
3
4 #include <stdio.h>
5 #include <capstone/capstone.h>
6
7 void print_string_hex(const char *comment, unsigned char *str, size_t len);
8
print_insn_detail_tms320c64x(csh handle,cs_insn * ins)9 void print_insn_detail_tms320c64x(csh handle, cs_insn *ins)
10 {
11 cs_tms320c64x *tms320c64x;
12 int i;
13
14 // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
15 if (ins->detail == NULL)
16 return;
17
18 tms320c64x = &(ins->detail->tms320c64x);
19 if (tms320c64x->op_count)
20 printf("\top_count: %u\n", tms320c64x->op_count);
21
22 for (i = 0; i < tms320c64x->op_count; i++) {
23 cs_tms320c64x_op *op = &(tms320c64x->operands[i]);
24 switch((int)op->type) {
25 default:
26 break;
27 case TMS320C64X_OP_REG:
28 printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
29 break;
30 case TMS320C64X_OP_IMM:
31 printf("\t\toperands[%u].type: IMM = 0x%x\n", i, op->imm);
32 break;
33 case TMS320C64X_OP_MEM:
34 printf("\t\toperands[%u].type: MEM\n", i);
35 if (op->mem.base != TMS320C64X_REG_INVALID)
36 printf("\t\t\toperands[%u].mem.base: REG = %s\n",
37 i, cs_reg_name(handle, op->mem.base));
38 printf("\t\t\toperands[%u].mem.disptype: ", i);
39 if(op->mem.disptype == TMS320C64X_MEM_DISP_INVALID) {
40 printf("Invalid\n");
41 printf("\t\t\toperands[%u].mem.disp: %u\n", i, op->mem.disp);
42 }
43 if(op->mem.disptype == TMS320C64X_MEM_DISP_CONSTANT) {
44 printf("Constant\n");
45 printf("\t\t\toperands[%u].mem.disp: %u\n", i, op->mem.disp);
46 }
47 if(op->mem.disptype == TMS320C64X_MEM_DISP_REGISTER) {
48 printf("Register\n");
49 printf("\t\t\toperands[%u].mem.disp: %s\n", i, cs_reg_name(handle, op->mem.disp));
50 }
51 printf("\t\t\toperands[%u].mem.unit: %u\n", i, op->mem.unit);
52 printf("\t\t\toperands[%u].mem.direction: ", i);
53 if(op->mem.direction == TMS320C64X_MEM_DIR_INVALID)
54 printf("Invalid\n");
55 if(op->mem.direction == TMS320C64X_MEM_DIR_FW)
56 printf("Forward\n");
57 if(op->mem.direction == TMS320C64X_MEM_DIR_BW)
58 printf("Backward\n");
59 printf("\t\t\toperands[%u].mem.modify: ", i);
60 if(op->mem.modify == TMS320C64X_MEM_MOD_INVALID)
61 printf("Invalid\n");
62 if(op->mem.modify == TMS320C64X_MEM_MOD_NO)
63 printf("No\n");
64 if(op->mem.modify == TMS320C64X_MEM_MOD_PRE)
65 printf("Pre\n");
66 if(op->mem.modify == TMS320C64X_MEM_MOD_POST)
67 printf("Post\n");
68 printf("\t\t\toperands[%u].mem.scaled: %u\n", i, op->mem.scaled);
69
70 break;
71 case TMS320C64X_OP_REGPAIR:
72 printf("\t\toperands[%u].type: REGPAIR = %s:%s\n", i, cs_reg_name(handle, op->reg + 1), cs_reg_name(handle, op->reg));
73 break;
74 }
75 }
76
77 printf("\tFunctional unit: ");
78 switch(tms320c64x->funit.unit) {
79 case TMS320C64X_FUNIT_D:
80 printf("D%u\n", tms320c64x->funit.side);
81 break;
82 case TMS320C64X_FUNIT_L:
83 printf("L%u\n", tms320c64x->funit.side);
84 break;
85 case TMS320C64X_FUNIT_M:
86 printf("M%u\n", tms320c64x->funit.side);
87 break;
88 case TMS320C64X_FUNIT_S:
89 printf("S%u\n", tms320c64x->funit.side);
90 break;
91 case TMS320C64X_FUNIT_NO:
92 printf("No Functional Unit\n");
93 break;
94 default:
95 printf("Unknown (Unit %u, Side %u)\n", tms320c64x->funit.unit, tms320c64x->funit.side);
96 break;
97 }
98 if(tms320c64x->funit.crosspath == 1)
99 printf("\tCrosspath: 1\n");
100
101 if(tms320c64x->condition.reg != TMS320C64X_REG_INVALID)
102 printf("\tCondition: [%c%s]\n", (tms320c64x->condition.zero == 1) ? '!' : ' ', cs_reg_name(handle, tms320c64x->condition.reg));
103 printf("\tParallel: %s\n", (tms320c64x->parallel == 1) ? "true" : "false");
104
105 printf("\n");
106 }
107