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"
9 extern 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 */
18 static DISASM_REPORTER __x86_reporter_func = NULL;
19 static void * __x86_reporter_arg = NULL;
20 
x86_init(enum x86_options options,DISASM_REPORTER reporter,void * arg)21 int 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 
x86_set_reporter(DISASM_REPORTER reporter,void * arg)30 void x86_set_reporter( DISASM_REPORTER reporter, void * arg ) {
31         __x86_reporter_func = reporter;
32 	__x86_reporter_arg = arg;
33 }
34 
x86_set_options(enum x86_options options)35 void x86_set_options( enum x86_options options ){
36         ia32_settings.options = options;
37 }
38 
x86_get_options(void)39 enum x86_options x86_get_options( void ) {
40         return ia32_settings.options;
41 }
42 
x86_cleanup(void)43 int x86_cleanup( void )
44 {
45         return 1;
46 }
47 
48 /* =========================================================== ERRORS */
x86_report_error(enum x86_report_codes code,void * data)49 void 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 */
x86_endian(void)57 unsigned int x86_endian(void)        { return ia32_settings.endian;  }
x86_addr_size(void)58 unsigned int x86_addr_size(void)     { return ia32_settings.sz_addr; }
x86_op_size(void)59 unsigned int x86_op_size(void)       { return ia32_settings.sz_oper; }
x86_word_size(void)60 unsigned int x86_word_size(void)     { return ia32_settings.sz_word; }
x86_max_insn_size(void)61 unsigned int x86_max_insn_size(void) { return ia32_settings.max_insn; }
x86_sp_reg(void)62 unsigned int x86_sp_reg(void)        { return ia32_settings.id_sp_reg;      }
x86_fp_reg(void)63 unsigned int x86_fp_reg(void)        { return ia32_settings.id_fp_reg;      }
x86_ip_reg(void)64 unsigned int x86_ip_reg(void)        { return ia32_settings.id_ip_reg;      }
x86_flag_reg(void)65 unsigned int x86_flag_reg(void)        { return ia32_settings.id_flag_reg;  }
66 
67 /* wrapper function to hide the IA32 register fn */
x86_reg_from_id(unsigned int id,x86_reg_t * reg)68 void x86_reg_from_id( unsigned int id, x86_reg_t * reg ) {
69 	ia32_handle_register( reg, id );
70 	return;
71 }
72