1 /* Capstone testing regression */
2 /* By Do Minh Tuan <tuanit96@gmail.com>, 02-2019 */
3
4
5 #include "factory.h"
6
get_bc_name(int bc)7 static const char* get_bc_name(int bc)
8 {
9 switch(bc) {
10 default:
11 case PPC_BC_INVALID:
12 return ("invalid");
13 case PPC_BC_LT:
14 return ("lt");
15 case PPC_BC_LE:
16 return ("le");
17 case PPC_BC_EQ:
18 return ("eq");
19 case PPC_BC_GE:
20 return ("ge");
21 case PPC_BC_GT:
22 return ("gt");
23 case PPC_BC_NE:
24 return ("ne");
25 case PPC_BC_UN:
26 return ("un");
27 case PPC_BC_NU:
28 return ("nu");
29 case PPC_BC_SO:
30 return ("so");
31 case PPC_BC_NS:
32 return ("ns");
33 }
34 }
35
get_detail_ppc(csh * handle,cs_mode mode,cs_insn * ins)36 char *get_detail_ppc(csh *handle, cs_mode mode, cs_insn *ins)
37 {
38 cs_ppc *ppc;
39 int i;
40 char *result;
41
42 result = (char *)malloc(sizeof(char));
43 result[0] = '\0';
44
45 if (ins->detail == NULL)
46 return result;
47
48 ppc = &(ins->detail->ppc);
49 if (ppc->op_count)
50 add_str(&result, " ; op_count: %u", ppc->op_count);
51
52 for (i = 0; i < ppc->op_count; i++) {
53 cs_ppc_op *op = &(ppc->operands[i]);
54 switch((int)op->type) {
55 default:
56 break;
57 case PPC_OP_REG:
58 add_str(&result, " ; operands[%u].type: REG = %s", i, cs_reg_name(*handle, op->reg));
59 break;
60 case PPC_OP_IMM:
61 add_str(&result, " ; operands[%u].type: IMM = 0x%"PRIx64"", i, op->imm);
62 break;
63 case PPC_OP_MEM:
64 add_str(&result, " ; operands[%u].type: MEM", i);
65 if (op->mem.base != PPC_REG_INVALID)
66 add_str(&result, " ; operands[%u].mem.base: REG = %s", i, cs_reg_name(*handle, op->mem.base));
67 if (op->mem.disp != 0)
68 add_str(&result, " ; operands[%u].mem.disp: 0x%x", i, op->mem.disp);
69
70 break;
71 case PPC_OP_CRX:
72 add_str(&result, " ; operands[%u].type: CRX", i);
73 add_str(&result, " ; operands[%u].crx.scale: %d", i, op->crx.scale);
74 add_str(&result, " ; operands[%u].crx.reg: %s", i, cs_reg_name(*handle, op->crx.reg));
75 add_str(&result, " ; operands[%u].crx.cond: %s", i, get_bc_name(op->crx.cond));
76 break;
77 }
78 }
79
80 if (ppc->bc != 0)
81 add_str(&result, " ; Branch code: %u", ppc->bc);
82
83 if (ppc->bh != 0)
84 add_str(&result, " ; Branch hint: %u", ppc->bh);
85
86 if (ppc->update_cr0)
87 add_str(&result, " ; Update-CR0: True");
88
89 return result;
90 }
91
92