summaryrefslogtreecommitdiff
path: root/arch/powerpc/disassembler.h
diff options
context:
space:
mode:
authorRusty Wagner <rusty.wagner@gmail.com>2024-03-05 19:50:13 -0500
committerRusty Wagner <rusty.wagner@gmail.com>2024-03-05 20:34:34 -0500
commite093c21ed880ac3eb72119be15093ee04f8ce299 (patch)
tree9f720ebdc0ae415734b1199ed341668c69710a94 /arch/powerpc/disassembler.h
parent0609276712622908254065546102381466033141 (diff)
Move architecture modules into the API repo
Diffstat (limited to 'arch/powerpc/disassembler.h')
-rw-r--r--arch/powerpc/disassembler.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/arch/powerpc/disassembler.h b/arch/powerpc/disassembler.h
new file mode 100644
index 00000000..e1701687
--- /dev/null
+++ b/arch/powerpc/disassembler.h
@@ -0,0 +1,69 @@
+/******************************************************************************
+
+This is the layer that the architecture module uses to access disassemble
+functionality.
+
+Currently, it wraps capstone, but that could change in the future. It exists
+precisely to make swapping out disassemblers easy, because disassembler details
+(like capstone types) will not be intertwined in the architecture plugin code.
+
+Also, with the disassembler object separate, we can link it against
+easy-to-compile test harnesses like the speed test.
+
+There are three main functions:
+
+powerpc_init() - initializes this module
+powerpc_release() - un-initializes this module
+powerpc_decompose() - converts bytes into decomp_result
+powerpc_disassemble() - converts decomp_result to string
+
+Then some helpers if you need them:
+
+******************************************************************************/
+
+/* capstone stuff /usr/local/include/capstone */
+#include "capstone/capstone.h"
+#include "capstone/ppc.h"
+
+//*****************************************************************************
+// structs and types
+//*****************************************************************************
+enum ppc_status_t {
+ STATUS_ERROR_UNSPEC=-1, STATUS_SUCCESS=0, STATUS_UNDEF_INSTR
+};
+
+
+/* operand type */
+enum operand_type_t { REG, VAL, LABEL };
+
+struct decomp_request
+{
+ uint8_t *data;
+ int size;
+ uint32_t addr;
+ bool lil_end;
+};
+
+struct decomp_result
+{
+ /* actual capstone handle used, in case caller wants to do extra stuff
+ (this can be one of two handles opened for BE or LE disassembling) */
+ csh handle;
+
+ ppc_status_t status;
+
+ cs_insn insn;
+ cs_detail detail;
+};
+
+//*****************************************************************************
+// function prototypes
+//*****************************************************************************
+extern "C" int powerpc_init(void);
+extern "C" void powerpc_release(void);
+extern "C" int powerpc_decompose(const uint8_t *data, int size, uint32_t addr,
+ bool lil_end, struct decomp_result *result);
+extern "C" int powerpc_disassemble(struct decomp_result *, char *buf, size_t len);
+
+extern "C" const char *powerpc_reg_to_str(uint32_t rid);
+