blob: b5f7f8a5379059d5b50cdc9ee98574abece4fc78 [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 "X86Disassembler.h"
7#include "X86InstPrinter.h"
8#include "mapping.h"
9
Nguyen Anh Quynhec4ead22013-12-28 14:34:21 +080010static cs_err init(cs_struct *ud)
Nguyen Anh Quynh13a7d952013-12-21 12:19:44 +080011{
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 Quynhec4ead22013-12-28 14:34:21 +080020
21 return CS_ERR_OK;
Nguyen Anh Quynh13a7d952013-12-21 12:19:44 +080022}
23
Nguyen Anh Quynhd3458392013-12-22 11:10:56 +080024static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)
Nguyen Anh Quynh13a7d952013-12-21 12:19:44 +080025{
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
45static void __attribute__ ((constructor)) __init_x86__()
46{
Nguyen Anh Quynhd3458392013-12-22 11:10:56 +080047 arch_init[CS_ARCH_X86] = init;
48 arch_option[CS_ARCH_X86] = option;
Nguyen Anh Quynhf954f872013-12-22 18:49:22 +080049
50 // support this arch
51 all_arch |= (1 << CS_ARCH_X86);
Nguyen Anh Quynh13a7d952013-12-21 12:19:44 +080052}