aboutsummaryrefslogtreecommitdiffstats
path: root/capstone/cstool/cstool_ppc.c
diff options
context:
space:
mode:
authorAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
committerAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
commitaf1a266670d040d2f4083ff309d732d648afba2a (patch)
tree2fc46203448ddcc6f81546d379abfaeb323575e9 /capstone/cstool/cstool_ppc.c
parente02cda008591317b1625707ff8e115a4841aa889 (diff)
Add submodule dependency filesHEADmaster
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'capstone/cstool/cstool_ppc.c')
-rw-r--r--capstone/cstool/cstool_ppc.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/capstone/cstool/cstool_ppc.c b/capstone/cstool/cstool_ppc.c
new file mode 100644
index 000000000..73de772fd
--- /dev/null
+++ b/capstone/cstool/cstool_ppc.c
@@ -0,0 +1,90 @@
+/* Capstone Disassembler Engine */
+/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013> */
+
+#include <stdio.h>
+
+#include <capstone/capstone.h>
+
+void print_insn_detail_ppc(csh handle, cs_insn *ins);
+
+
+static const char* get_bc_name(int bc)
+{
+ switch(bc) {
+ default:
+ case PPC_BC_INVALID:
+ return ("invalid");
+ case PPC_BC_LT:
+ return ("lt");
+ case PPC_BC_LE:
+ return ("le");
+ case PPC_BC_EQ:
+ return ("eq");
+ case PPC_BC_GE:
+ return ("ge");
+ case PPC_BC_GT:
+ return ("gt");
+ case PPC_BC_NE:
+ return ("ne");
+ case PPC_BC_UN:
+ return ("un");
+ case PPC_BC_NU:
+ return ("nu");
+ case PPC_BC_SO:
+ return ("so");
+ case PPC_BC_NS:
+ return ("ns");
+ }
+}
+
+void print_insn_detail_ppc(csh handle, cs_insn *ins)
+{
+ cs_ppc *ppc;
+ int i;
+
+ // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
+ if (ins->detail == NULL)
+ return;
+
+ ppc = &(ins->detail->ppc);
+ if (ppc->op_count)
+ printf("\top_count: %u\n", ppc->op_count);
+
+ for (i = 0; i < ppc->op_count; i++) {
+ cs_ppc_op *op = &(ppc->operands[i]);
+ switch((int)op->type) {
+ default:
+ break;
+ case PPC_OP_REG:
+ printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
+ break;
+ case PPC_OP_IMM:
+ printf("\t\toperands[%u].type: IMM = 0x%"PRIx64"\n", i, op->imm);
+ break;
+ case PPC_OP_MEM:
+ printf("\t\toperands[%u].type: MEM\n", i);
+ if (op->mem.base != PPC_REG_INVALID)
+ printf("\t\t\toperands[%u].mem.base: REG = %s\n",
+ i, cs_reg_name(handle, op->mem.base));
+ if (op->mem.disp != 0)
+ printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp);
+
+ break;
+ case PPC_OP_CRX:
+ printf("\t\toperands[%u].type: CRX\n", i);
+ printf("\t\t\toperands[%u].crx.scale: %d\n", i, op->crx.scale);
+ printf("\t\t\toperands[%u].crx.reg: %s\n", i, cs_reg_name(handle, op->crx.reg));
+ printf("\t\t\toperands[%u].crx.cond: %s\n", i, get_bc_name(op->crx.cond));
+ break;
+ }
+ }
+
+ if (ppc->bc != 0)
+ printf("\tBranch code: %u\n", ppc->bc);
+
+ if (ppc->bh != 0)
+ printf("\tBranch hint: %u\n", ppc->bh);
+
+ if (ppc->update_cr0)
+ printf("\tUpdate-CR0: True\n");
+}