• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Capstone Disassembly Engine */
2 /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 */
3 
4 #ifdef CAPSTONE_HAS_POWERPC
5 
6 #include "../../utils.h"
7 #include "../../MCRegisterInfo.h"
8 #include "PPCDisassembler.h"
9 #include "PPCInstPrinter.h"
10 #include "PPCMapping.h"
11 
init(cs_struct * ud)12 static cs_err init(cs_struct *ud)
13 {
14 	MCRegisterInfo *mri;
15 
16 	// verify if requested mode is valid
17 	if (ud->mode & ~(CS_MODE_LITTLE_ENDIAN | CS_MODE_32 | CS_MODE_64 |
18 				CS_MODE_BIG_ENDIAN))
19 		return CS_ERR_MODE;
20 
21 	mri = (MCRegisterInfo *) cs_mem_malloc(sizeof(*mri));
22 
23 	PPC_init(mri);
24 	ud->printer = PPC_printInst;
25 	ud->printer_info = mri;
26 	ud->getinsn_info = mri;
27 	ud->disasm = PPC_getInstruction;
28 	ud->post_printer = PPC_post_printer;
29 
30 	ud->reg_name = PPC_reg_name;
31 	ud->insn_id = PPC_get_insn_id;
32 	ud->insn_name = PPC_insn_name;
33 	ud->group_name = PPC_group_name;
34 
35 	return CS_ERR_OK;
36 }
37 
option(cs_struct * handle,cs_opt_type type,size_t value)38 static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)
39 {
40 	if (type == CS_OPT_SYNTAX)
41 		handle->syntax = (int) value;
42 
43 	if (type == CS_OPT_MODE) {
44 		handle->big_endian = (((cs_mode)value & CS_MODE_BIG_ENDIAN) != 0);
45 	}
46 
47 	return CS_ERR_OK;
48 }
49 
destroy(cs_struct * handle)50 static void destroy(cs_struct *handle)
51 {
52 }
53 
PPC_enable(void)54 void PPC_enable(void)
55 {
56 	arch_init[CS_ARCH_PPC] = init;
57 	arch_option[CS_ARCH_PPC] = option;
58 	arch_destroy[CS_ARCH_PPC] = destroy;
59 
60 	// support this arch
61 	all_arch |= (1 << CS_ARCH_PPC);
62 }
63 
64 #endif
65