• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Capstone testing regression */
2 /* By Do Minh Tuan <tuanit96@gmail.com>, 02-2019 */
3 
4 
5 #include "factory.h"
6 
get_detail_tms320c64x(csh * handle,cs_mode mode,cs_insn * ins)7 char *get_detail_tms320c64x(csh *handle, cs_mode mode, cs_insn *ins)
8 {
9 	cs_tms320c64x *tms320c64x;
10 	int i;
11 	char *result;
12 
13 	result = (char *)malloc(sizeof(char));
14 	result[0] = '\0';
15 
16 	if (ins->detail == NULL)
17 		return result;
18 
19 	tms320c64x = &(ins->detail->tms320c64x);
20 	if (tms320c64x->op_count)
21 		add_str(&result, " ; op_count: %u", tms320c64x->op_count);
22 
23 	for (i = 0; i < tms320c64x->op_count; i++) {
24 		cs_tms320c64x_op *op = &(tms320c64x->operands[i]);
25 		switch((int)op->type) {
26 			default:
27 				break;
28 			case TMS320C64X_OP_REG:
29 				add_str(&result, " ; operands[%u].type: REG = %s", i, cs_reg_name(*handle, op->reg));
30 				break;
31 			case TMS320C64X_OP_IMM:
32 				add_str(&result, " ; operands[%u].type: IMM = 0x%x", i, op->imm);
33 				break;
34 			case TMS320C64X_OP_MEM:
35 				add_str(&result, " ; operands[%u].type: MEM", i);
36 				if (op->mem.base != TMS320C64X_REG_INVALID)
37 					add_str(&result, " ; operands[%u].mem.base: REG = %s", i, cs_reg_name(*handle, op->mem.base));
38 				add_str(&result, " ; operands[%u].mem.disptype: ", i);
39 				if (op->mem.disptype == TMS320C64X_MEM_DISP_INVALID) {
40 					add_str(&result, "Invalid");
41 					add_str(&result, " ; operands[%u].mem.disp: %u", i, op->mem.disp);
42 				}
43 				if (op->mem.disptype == TMS320C64X_MEM_DISP_CONSTANT) {
44 					add_str(&result, "Constant");
45 					add_str(&result, " ; operands[%u].mem.disp: %u", i, op->mem.disp);
46 				}
47 				if (op->mem.disptype == TMS320C64X_MEM_DISP_REGISTER) {
48 					add_str(&result, "Register");
49 					add_str(&result, " ; operands[%u].mem.disp: %s", i, cs_reg_name(*handle, op->mem.disp));
50 				}
51 				add_str(&result, " ; operands[%u].mem.unit: %u", i, op->mem.unit);
52 				add_str(&result, " ; operands[%u].mem.direction: ", i);
53 				if (op->mem.direction == TMS320C64X_MEM_DIR_INVALID)
54 					add_str(&result, "Invalid");
55 				if (op->mem.direction == TMS320C64X_MEM_DIR_FW)
56 					add_str(&result, "Forward");
57 				if (op->mem.direction == TMS320C64X_MEM_DIR_BW)
58 					add_str(&result, "Backward");
59 				add_str(&result, " ; operands[%u].mem.modify: ", i);
60 				if (op->mem.modify == TMS320C64X_MEM_MOD_INVALID)
61 					add_str(&result, "Invalid");
62 				if (op->mem.modify == TMS320C64X_MEM_MOD_NO)
63 					add_str(&result, "No");
64 				if (op->mem.modify == TMS320C64X_MEM_MOD_PRE)
65 					add_str(&result, "Pre");
66 				if (op->mem.modify == TMS320C64X_MEM_MOD_POST)
67 					add_str(&result, "Post");
68 				add_str(&result, " ; operands[%u].mem.scaled: %u", i, op->mem.scaled);
69 
70 				break;
71 			case TMS320C64X_OP_REGPAIR:
72 				add_str(&result, " ; operands[%u].type: REGPAIR = %s:%s", i, cs_reg_name(*handle, op->reg + 1), cs_reg_name(*handle, op->reg));
73 				break;
74 		}
75 	}
76 
77 	add_str(&result, " ; Functional unit: ");
78 	switch(tms320c64x->funit.unit) {
79 		case TMS320C64X_FUNIT_D:
80 			add_str(&result, "D%u", tms320c64x->funit.side);
81 			break;
82 		case TMS320C64X_FUNIT_L:
83 			add_str(&result, "L%u", tms320c64x->funit.side);
84 			break;
85 		case TMS320C64X_FUNIT_M:
86 			add_str(&result, "M%u", tms320c64x->funit.side);
87 			break;
88 		case TMS320C64X_FUNIT_S:
89 			add_str(&result, "S%u", tms320c64x->funit.side);
90 			break;
91 		case TMS320C64X_FUNIT_NO:
92 			add_str(&result, "No Functional Unit");
93 			break;
94 		default:
95 			add_str(&result, "Unknown (Unit %u, Side %u)", tms320c64x->funit.unit, tms320c64x->funit.side);
96 			break;
97 	}
98 	if (tms320c64x->funit.crosspath == 1)
99 		add_str(&result, " ; Crosspath: 1");
100 
101 	if (tms320c64x->condition.reg != TMS320C64X_REG_INVALID)
102 		add_str(&result, " ; Condition: [%c%s]", (tms320c64x->condition.zero == 1) ? '!' : ' ', cs_reg_name(*handle, tms320c64x->condition.reg));
103 	add_str(&result, " ; Parallel: %s", (tms320c64x->parallel == 1) ? "true" : "false");
104 
105 	return result;
106 }
107 
108