2014-05-14 11:26:41 +08:00
|
|
|
/* Capstone Disassembly Engine */
|
2015-03-04 17:45:23 +08:00
|
|
|
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015 */
|
2014-05-14 11:26:41 +08:00
|
|
|
|
|
|
|
#ifdef CAPSTONE_HAS_POWERPC
|
2013-12-30 00:29:32 +08:00
|
|
|
|
2014-01-05 11:19:04 +08:00
|
|
|
#include "../../utils.h"
|
2013-12-30 00:29:32 +08:00
|
|
|
#include "../../MCRegisterInfo.h"
|
|
|
|
#include "PPCDisassembler.h"
|
|
|
|
#include "PPCInstPrinter.h"
|
2014-01-20 09:47:21 +08:00
|
|
|
#include "PPCMapping.h"
|
2013-12-30 00:29:32 +08:00
|
|
|
|
|
|
|
static cs_err init(cs_struct *ud)
|
|
|
|
{
|
2014-01-23 23:42:40 +08:00
|
|
|
MCRegisterInfo *mri;
|
2014-01-23 01:45:00 +08:00
|
|
|
|
2014-01-21 15:26:02 +08:00
|
|
|
// verify if requested mode is valid
|
|
|
|
if (ud->mode & ~(CS_MODE_LITTLE_ENDIAN | CS_MODE_32 | CS_MODE_64 |
|
2015-03-12 16:52:31 +08:00
|
|
|
CS_MODE_BIG_ENDIAN | CS_MODE_QPX))
|
2014-01-21 15:26:02 +08:00
|
|
|
return CS_ERR_MODE;
|
|
|
|
|
2014-06-30 13:45:40 +08:00
|
|
|
mri = (MCRegisterInfo *) cs_mem_malloc(sizeof(*mri));
|
2013-12-30 00:29:32 +08:00
|
|
|
|
|
|
|
PPC_init(mri);
|
|
|
|
ud->printer = PPC_printInst;
|
|
|
|
ud->printer_info = mri;
|
|
|
|
ud->getinsn_info = mri;
|
2014-01-01 23:28:05 +08:00
|
|
|
ud->disasm = PPC_getInstruction;
|
2014-01-05 10:37:50 +08:00
|
|
|
ud->post_printer = PPC_post_printer;
|
2014-01-01 23:28:05 +08:00
|
|
|
|
2014-01-05 00:00:05 +08:00
|
|
|
ud->reg_name = PPC_reg_name;
|
|
|
|
ud->insn_id = PPC_get_insn_id;
|
|
|
|
ud->insn_name = PPC_insn_name;
|
2014-07-08 08:59:27 +08:00
|
|
|
ud->group_name = PPC_group_name;
|
2013-12-30 00:29:32 +08:00
|
|
|
|
|
|
|
return CS_ERR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)
|
|
|
|
{
|
|
|
|
if (type == CS_OPT_SYNTAX)
|
2014-06-30 13:45:40 +08:00
|
|
|
handle->syntax = (int) value;
|
2013-12-30 00:29:32 +08:00
|
|
|
|
2017-02-01 11:17:13 +08:00
|
|
|
if (type == CS_OPT_MODE) {
|
|
|
|
handle->big_endian = (((cs_mode)value & CS_MODE_BIG_ENDIAN) != 0);
|
|
|
|
}
|
|
|
|
|
2013-12-30 00:29:32 +08:00
|
|
|
return CS_ERR_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-19 12:03:22 +08:00
|
|
|
void PPC_enable(void)
|
2013-12-30 00:29:32 +08:00
|
|
|
{
|
2018-03-29 22:17:37 +08:00
|
|
|
cs_arch_init[CS_ARCH_PPC] = init;
|
|
|
|
cs_arch_option[CS_ARCH_PPC] = option;
|
2013-12-30 00:29:32 +08:00
|
|
|
|
|
|
|
// support this arch
|
|
|
|
all_arch |= (1 << CS_ARCH_PPC);
|
|
|
|
}
|
2014-05-14 11:26:41 +08:00
|
|
|
|
|
|
|
#endif
|