blob: e4d12c9c4dfd3b6ab28fd91e381e738556f7d137 [file] [log] [blame]
Nguyen Anh Quynh13a7d952013-12-21 12:19:44 +08001/* Capstone Disassembler Engine */
2/* By Dang Hoang Vu <danghvu@gmail.com> 2013 */
3
4#include "../../cs_priv.h"
5#include "../../MCRegisterInfo.h"
6#include "MipsDisassembler.h"
7#include "MipsInstPrinter.h"
8#include "mapping.h"
9
10
Nguyen Anh Quynhec4ead22013-12-28 14:34:21 +080011static cs_err init(cs_struct *ud)
Nguyen Anh Quynh13a7d952013-12-21 12:19:44 +080012{
13 MCRegisterInfo *mri = malloc(sizeof(*mri));
14
15 Mips_init(mri);
16 ud->printer = Mips_printInst;
17 ud->printer_info = mri;
18 ud->getinsn_info = mri;
19 ud->reg_name = Mips_reg_name;
20 ud->insn_id = Mips_get_insn_id;
21 ud->insn_name = Mips_insn_name;
22
23 if (ud->mode & CS_MODE_32)
24 ud->disasm = Mips_getInstruction;
25 else
26 ud->disasm = Mips64_getInstruction;
Nguyen Anh Quynhec4ead22013-12-28 14:34:21 +080027
28 return CS_ERR_OK;
Nguyen Anh Quynh13a7d952013-12-21 12:19:44 +080029}
30
Nguyen Anh Quynhd3458392013-12-22 11:10:56 +080031static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)
Nguyen Anh Quynh13a7d952013-12-21 12:19:44 +080032{
33 if (type == CS_OPT_MODE) {
34 if (value & CS_MODE_32)
35 handle->disasm = Mips_getInstruction;
36 else
37 handle->disasm = Mips64_getInstruction;
38
39 handle->mode = value;
40 }
41 return CS_ERR_OK;
42}
43
Nguyen Anh Quynhb2654062014-01-03 17:08:58 +080044static void destroy(cs_struct *handle)
45{
46 Mips_free_cache();
47}
48
Nguyen Anh Quynh13a7d952013-12-21 12:19:44 +080049static void __attribute__ ((constructor)) __init_mips__()
50{
Nguyen Anh Quynhd3458392013-12-22 11:10:56 +080051 arch_init[CS_ARCH_MIPS] = init;
52 arch_option[CS_ARCH_MIPS] = option;
Nguyen Anh Quynhb2654062014-01-03 17:08:58 +080053 arch_destroy[CS_ARCH_MIPS] = destroy;
Nguyen Anh Quynhf954f872013-12-22 18:49:22 +080054
55 // support this arch
56 all_arch |= (1 << CS_ARCH_MIPS);
Nguyen Anh Quynh13a7d952013-12-21 12:19:44 +080057}