2005-01-05 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / mini / mini-x86.h
1 #ifndef __MONO_MINI_X86_H__
2 #define __MONO_MINI_X86_H__
3
4 #include <mono/arch/x86/x86-codegen.h>
5 #ifdef PLATFORM_WIN32
6 #include <windows.h>
7 /* use SIG* defines if possible */
8 #ifdef HAVE_SIGNAL_H
9 #include <signal.h>
10 #endif
11
12 /* sigcontext surrogate */
13 struct sigcontext {
14         unsigned int eax;
15         unsigned int ebx;
16         unsigned int ecx;
17         unsigned int edx;
18         unsigned int ebp;
19         unsigned int esp;
20         unsigned int esi;
21         unsigned int edi;
22         unsigned int eip;
23 };
24
25 typedef void (* MonoW32ExceptionHandler) (int);
26 void win32_seh_init(void);
27 void win32_seh_cleanup(void);
28 void win32_seh_set_handler(int type, MonoW32ExceptionHandler handler);
29
30 #ifndef SIGFPE
31 #define SIGFPE 4
32 #endif
33
34 #ifndef SIGILL
35 #define SIGILL 8
36 #endif
37
38 #ifndef SIGSEGV
39 #define SIGSEGV 11
40 #endif
41
42 LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep);
43
44 #endif /* PLATFORM_WIN32 */
45
46 #ifdef sun    // Solaris x86
47 #  undef SIGSEGV_ON_ALTSTACK
48 #  define MONO_ARCH_USE_SIGACTION 1
49 struct sigcontext {
50         unsigned short gs, __gsh;
51         unsigned short fs, __fsh;
52         unsigned short es, __esh;
53         unsigned short ds, __dsh;
54         unsigned long edi;
55         unsigned long esi;
56         unsigned long ebp;
57         unsigned long esp;
58         unsigned long ebx;
59         unsigned long edx;
60         unsigned long ecx;
61         unsigned long eax;
62         unsigned long trapno;
63         unsigned long err;
64         unsigned long eip;
65         unsigned short cs, __csh;
66         unsigned long eflags;
67         unsigned long esp_at_signal;
68         unsigned short ss, __ssh;
69         unsigned long fpstate[95];
70       unsigned long filler[5];
71 };
72 #endif  // sun, Solaris x86
73
74 /* Enables OP_LSHL, OP_LSHL_IMM, OP_LSHR, OP_LSHR_IMM, OP_LSHR_UN, OP_LSHR_UN_IMM */
75 #define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS
76
77 #define MONO_MAX_IREGS 8
78 #define MONO_MAX_FREGS 6
79
80 #define MONO_ARCH_FRAME_ALIGNMENT 4
81
82 /* fixme: align to 16byte instead of 32byte (we align to 32byte to get 
83  * reproduceable results for benchmarks */
84 #define MONO_ARCH_CODE_ALIGNMENT 32
85
86 #define MONO_ARCH_BASEREG X86_EBP
87 #define MONO_ARCH_RETREG1 X86_EAX
88 #define MONO_ARCH_RETREG2 X86_EDX
89
90 #define MONO_ARCH_ENCODE_LREG(r1,r2) (r1 | (r2<<3))
91
92 #define inst_dreg_low dreg&7 
93 #define inst_dreg_high dreg>>3
94 #define inst_sreg1_low sreg1&7 
95 #define inst_sreg1_high sreg1>>3
96 #define inst_sreg2_low sreg2&7 
97 #define inst_sreg2_high sreg2>>3
98
99 struct MonoLMF {
100         gpointer    previous_lmf;
101         gpointer    lmf_addr;
102         MonoMethod *method;
103         guint32     ebx;
104         guint32     edi;
105         guint32     esi;
106         guint32     ebp;
107         guint32     eip;
108 };
109
110 typedef struct MonoCompileArch {
111 } MonoCompileArch;
112
113 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
114 # define SC_EAX sc_eax
115 # define SC_EBX sc_ebx
116 # define SC_ECX sc_ecx
117 # define SC_EDX sc_edx
118 # define SC_EBP sc_ebp
119 # define SC_EIP sc_eip
120 # define SC_ESP sc_esp
121 # define SC_EDI sc_edi
122 # define SC_ESI sc_esi
123 #else
124 # define SC_EAX eax
125 # define SC_EBX ebx
126 # define SC_ECX ecx
127 # define SC_EDX edx
128 # define SC_EBP ebp
129 # define SC_EIP eip
130 # define SC_ESP esp
131 # define SC_EDI edi
132 # define SC_ESI esi
133 #endif
134
135 typedef struct sigcontext MonoContext;
136
137 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->SC_EIP = (long)(ip); } while (0); 
138 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->SC_EBP = (long)(bp); } while (0); 
139 #define MONO_CONTEXT_SET_SP(ctx,esp) do { (ctx)->SC_ESP = (long)(esp); } while (0); 
140
141 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->SC_EIP))
142 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->SC_EBP))
143 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->SC_ESP))
144
145 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do {        \
146                 mono_arch_flush_register_windows ();    \
147                 MONO_CONTEXT_SET_IP ((ctx), (start_func));      \
148                 MONO_CONTEXT_SET_BP ((ctx), __builtin_frame_address (0));       \
149         } while (0)
150
151 #ifndef PLATFORM_WIN32
152 #ifdef HAVE_WORKING_SIGALTSTACK
153 #define MONO_ARCH_SIGSEGV_ON_ALTSTACK
154 /* NetBSD doesn't define SA_STACK */
155 #ifndef SA_STACK
156 #define SA_STACK SA_ONSTACK
157 #endif
158 #endif
159
160 #endif
161
162 #define MONO_ARCH_BIGMUL_INTRINS 1
163 #define MONO_ARCH_NEED_DIV_CHECK 1
164 #define MONO_ARCH_HAVE_IS_INT_OVERFLOW 1
165 #define MONO_ARCH_HAVE_INVALIDATE_METHOD 1
166 #define MONO_ARCH_HAVE_PIC_AOT 1
167 #define MONO_ARCH_NEED_GOT_VAR 1
168 #define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION 1
169 #define MONO_ARCH_ENABLE_EMIT_STATE_OPT 1
170 #define MONO_ARCH_HAVE_OUT_OF_LINE_BBLOCKS 1
171
172 #endif /* __MONO_MINI_X86_H__ */  
173