Nguyen Anh Quynh | 13a7d95 | 2013-12-21 12:19:44 +0800 | [diff] [blame] | 1 | /* 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 Quynh | ec4ead2 | 2013-12-28 14:34:21 +0800 | [diff] [blame] | 11 | static cs_err init(cs_struct *ud) |
Nguyen Anh Quynh | 13a7d95 | 2013-12-21 12:19:44 +0800 | [diff] [blame] | 12 | { |
| 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 Quynh | ec4ead2 | 2013-12-28 14:34:21 +0800 | [diff] [blame] | 27 | |
| 28 | return CS_ERR_OK; |
Nguyen Anh Quynh | 13a7d95 | 2013-12-21 12:19:44 +0800 | [diff] [blame] | 29 | } |
| 30 | |
Nguyen Anh Quynh | d345839 | 2013-12-22 11:10:56 +0800 | [diff] [blame] | 31 | static cs_err option(cs_struct *handle, cs_opt_type type, size_t value) |
Nguyen Anh Quynh | 13a7d95 | 2013-12-21 12:19:44 +0800 | [diff] [blame] | 32 | { |
| 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 Quynh | b265406 | 2014-01-03 17:08:58 +0800 | [diff] [blame^] | 44 | static void destroy(cs_struct *handle) |
| 45 | { |
| 46 | Mips_free_cache(); |
| 47 | } |
| 48 | |
Nguyen Anh Quynh | 13a7d95 | 2013-12-21 12:19:44 +0800 | [diff] [blame] | 49 | static void __attribute__ ((constructor)) __init_mips__() |
| 50 | { |
Nguyen Anh Quynh | d345839 | 2013-12-22 11:10:56 +0800 | [diff] [blame] | 51 | arch_init[CS_ARCH_MIPS] = init; |
| 52 | arch_option[CS_ARCH_MIPS] = option; |
Nguyen Anh Quynh | b265406 | 2014-01-03 17:08:58 +0800 | [diff] [blame^] | 53 | arch_destroy[CS_ARCH_MIPS] = destroy; |
Nguyen Anh Quynh | f954f87 | 2013-12-22 18:49:22 +0800 | [diff] [blame] | 54 | |
| 55 | // support this arch |
| 56 | all_arch |= (1 << CS_ARCH_MIPS); |
Nguyen Anh Quynh | 13a7d95 | 2013-12-21 12:19:44 +0800 | [diff] [blame] | 57 | } |