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 "X86Disassembler.h" |
| 7 | #include "X86InstPrinter.h" |
| 8 | #include "mapping.h" |
| 9 | |
Nguyen Anh Quynh | ec4ead2 | 2013-12-28 14:34:21 +0800 | [diff] [blame] | 10 | static cs_err init(cs_struct *ud) |
Nguyen Anh Quynh | 13a7d95 | 2013-12-21 12:19:44 +0800 | [diff] [blame] | 11 | { |
| 12 | // by default, we use Intel syntax |
| 13 | ud->printer = X86_Intel_printInst; |
| 14 | ud->printer_info = NULL; |
| 15 | ud->disasm = X86_getInstruction; |
| 16 | ud->reg_name = X86_reg_name; |
| 17 | ud->insn_id = X86_get_insn_id; |
| 18 | ud->insn_name = X86_insn_name; |
| 19 | ud->post_printer = X86_post_printer; |
Nguyen Anh Quynh | ec4ead2 | 2013-12-28 14:34:21 +0800 | [diff] [blame] | 20 | |
| 21 | return CS_ERR_OK; |
Nguyen Anh Quynh | 13a7d95 | 2013-12-21 12:19:44 +0800 | [diff] [blame] | 22 | } |
| 23 | |
Nguyen Anh Quynh | d345839 | 2013-12-22 11:10:56 +0800 | [diff] [blame] | 24 | 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] | 25 | { |
| 26 | if (type == CS_OPT_SYNTAX) { |
| 27 | switch(value) { |
| 28 | default: |
| 29 | // wrong syntax value |
| 30 | handle->errnum = CS_ERR_OPTION; |
| 31 | return CS_ERR_OPTION; |
| 32 | |
| 33 | case CS_OPT_SYNTAX_INTEL: |
| 34 | handle->printer = X86_Intel_printInst; |
| 35 | break; |
| 36 | |
| 37 | case CS_OPT_SYNTAX_ATT: |
| 38 | handle->printer = X86_ATT_printInst; |
| 39 | break; |
| 40 | } |
| 41 | } |
| 42 | return CS_ERR_OK; |
| 43 | } |
| 44 | |
| 45 | static void __attribute__ ((constructor)) __init_x86__() |
| 46 | { |
Nguyen Anh Quynh | d345839 | 2013-12-22 11:10:56 +0800 | [diff] [blame] | 47 | arch_init[CS_ARCH_X86] = init; |
| 48 | arch_option[CS_ARCH_X86] = option; |
Nguyen Anh Quynh | f954f87 | 2013-12-22 18:49:22 +0800 | [diff] [blame] | 49 | |
| 50 | // support this arch |
| 51 | all_arch |= (1 << CS_ARCH_X86); |
Nguyen Anh Quynh | 13a7d95 | 2013-12-21 12:19:44 +0800 | [diff] [blame] | 52 | } |