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