1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5#include "libdis.h"
6#include "ia32_insn.h"
7#include "ia32_reg.h" /* for ia32_reg wrapper */
8#include "ia32_settings.h"
9extern ia32_settings_t ia32_settings;
10
11#ifdef _MSC_VER
12 #define snprintf _snprintf
13 #define inline __inline
14#endif
15
16
17/* =========================================================== INIT/TERM */
18static DISASM_REPORTER __x86_reporter_func = NULL;
19static void * __x86_reporter_arg = NULL;
20
21int x86_init( enum x86_options options, DISASM_REPORTER reporter, void * arg )
22{
23 ia32_settings.options = options;
24 __x86_reporter_func = reporter;
25 __x86_reporter_arg = arg;
26
27 return 1;
28}
29
30void x86_set_reporter( DISASM_REPORTER reporter, void * arg ) {
31 __x86_reporter_func = reporter;
32 __x86_reporter_arg = arg;
33}
34
35void x86_set_options( enum x86_options options ){
36 ia32_settings.options = options;
37}
38
39enum x86_options x86_get_options( void ) {
40 return ia32_settings.options;
41}
42
43int x86_cleanup( void )
44{
45 return 1;
46}
47
48/* =========================================================== ERRORS */
49void x86_report_error( enum x86_report_codes code, void *data ) {
50 if ( __x86_reporter_func ) {
51 (*__x86_reporter_func)(code, data, __x86_reporter_arg);
52 }
53}
54
55
56/* =========================================================== MISC */
57unsigned int x86_endian(void) { return ia32_settings.endian; }
58unsigned int x86_addr_size(void) { return ia32_settings.sz_addr; }
59unsigned int x86_op_size(void) { return ia32_settings.sz_oper; }
60unsigned int x86_word_size(void) { return ia32_settings.sz_word; }
61unsigned int x86_max_insn_size(void) { return ia32_settings.max_insn; }
62unsigned int x86_sp_reg(void) { return ia32_settings.id_sp_reg; }
63unsigned int x86_fp_reg(void) { return ia32_settings.id_fp_reg; }
64unsigned int x86_ip_reg(void) { return ia32_settings.id_ip_reg; }
65unsigned int x86_flag_reg(void) { return ia32_settings.id_flag_reg; }
66
67/* wrapper function to hide the IA32 register fn */
68void x86_reg_from_id( unsigned int id, x86_reg_t * reg ) {
69 ia32_handle_register( reg, id );
70 return;
71}
72