Debian Codegraph @

cstool/cstool_powerpc.c

raw symbols SCIP
1 /* Capstone Disassembler Engine */
2 /* By Nguyen Anh Quynh <[email protected]>, 2013> */
3
4 #include <stdio.h>
5
6 #include <capstone/capstone.h>
7 #include "cstool.h"
8
9 static const char* get_bc_name(int bc)
10 {
11 switch(bc) {
12 default:
13 case PPC_BC_INVALID:
14 return ("invalid");
15 case PPC_BC_LT:
16 return ("lt");
17 case PPC_BC_LE:
18 return ("le");
19 case PPC_BC_EQ:
20 return ("eq");
21 case PPC_BC_GE:
22 return ("ge");
23 case PPC_BC_GT:
24 return ("gt");
25 case PPC_BC_NE:
26 return ("ne");
27 case PPC_BC_UN:
28 return ("un");
29 case PPC_BC_NU:
30 return ("nu");
31 case PPC_BC_SO:
32 return ("so");
33 case PPC_BC_NS:
34 return ("ns");
35 }
36 }
37
38 void print_insn_detail_ppc(csh handle, cs_insn *ins)
39 {
40 cs_ppc *ppc;
41 int i;
42
43 // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
44 if (ins->detail == NULL)
45 return;
46
47 ppc = &(ins->detail->ppc);
48 if (ppc->op_count)
49 printf("\top_count: %u\n", ppc->op_count);
50
51 for (i = 0; i < ppc->op_count; i++) {
52 cs_ppc_op *op = &(ppc->operands[i]);
53 switch((int)op->type) {
54 default:
55 break;
56 case PPC_OP_REG:
57 printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
58 break;
59 case PPC_OP_IMM:
60 printf("\t\toperands[%u].type: IMM = 0x%"PRIx64"\n", i, op->imm);
61 break;
62 case PPC_OP_MEM:
63 printf("\t\toperands[%u].type: MEM\n", i);
64 if (op->mem.base != PPC_REG_INVALID)
65 printf("\t\t\toperands[%u].mem.base: REG = %s\n",
66 i, cs_reg_name(handle, op->mem.base));
67 if (op->mem.disp != 0)
68 printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp);
69
70 break;
71 case PPC_OP_CRX:
72 printf("\t\toperands[%u].type: CRX\n", i);
73 printf("\t\t\toperands[%u].crx.scale: %d\n", i, op->crx.scale);
74 printf("\t\t\toperands[%u].crx.reg: %s\n", i, cs_reg_name(handle, op->crx.reg));
75 printf("\t\t\toperands[%u].crx.cond: %s\n", i, get_bc_name(op->crx.cond));
76 break;
77 }
78 }
79
80 if (ppc->bc != 0)
81 printf("\tBranch code: %u\n", ppc->bc);
82
83 if (ppc->bh != 0)
84 printf("\tBranch hint: %u\n", ppc->bh);
85
86 if (ppc->update_cr0)
87 printf("\tUpdate-CR0: True\n");
88 }