* mini-s390[x].c (is_regsize_var): Support PTR/FNPTR too.
[mono.git] / mono / mini / mini-x86.h
blob994899a79c359fd3686c68b1440793615faeaaa0
1 #ifndef __MONO_MINI_X86_H__
2 #define __MONO_MINI_X86_H__
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
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;
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);
30 #ifndef SIGFPE
31 #define SIGFPE 4
32 #endif
34 #ifndef SIGILL
35 #define SIGILL 8
36 #endif
38 #ifndef SIGSEGV
39 #define SIGSEGV 11
40 #endif
42 LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep);
44 #endif /* PLATFORM_WIN32 */
46 #if defined( __linux__) || defined(__sun) || defined(__APPLE__)
47 #define MONO_ARCH_USE_SIGACTION
48 #endif
50 #ifndef PLATFORM_WIN32
52 #ifdef HAVE_WORKING_SIGALTSTACK
53 #define MONO_ARCH_SIGSEGV_ON_ALTSTACK
54 #define MONO_ARCH_USE_SIGACTION
56 #endif /* HAVE_WORKING_SIGALTSTACK */
57 #endif /* !PLATFORM_WIN32 */
59 #define MONO_ARCH_SIGNAL_STACK_SIZE (64 * 1024)
61 /* Enables OP_LSHL, OP_LSHL_IMM, OP_LSHR, OP_LSHR_IMM, OP_LSHR_UN, OP_LSHR_UN_IMM */
62 #define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS
64 #define MONO_MAX_IREGS 8
65 #define MONO_MAX_FREGS 6
67 /* Parameters used by the register allocator */
68 #define MONO_ARCH_HAS_XP_LOCAL_REGALLOC
70 #define MONO_ARCH_CALLEE_REGS X86_CALLEE_REGS
71 #define MONO_ARCH_CALLEE_SAVED_REGS X86_CALLER_REGS
73 #define MONO_ARCH_CALLEE_FREGS 0
74 #define MONO_ARCH_CALLEE_SAVED_FREGS 0
76 #define MONO_ARCH_USE_FPSTACK TRUE
77 #define MONO_ARCH_FPSTACK_SIZE 6
79 #define MONO_ARCH_INST_FIXED_REG(desc) (((desc == ' ') || (desc == 'i')) ? -1 : ((desc == 's') ? X86_ECX : ((desc == 'a') ? X86_EAX : ((desc == 'd') ? X86_EDX : ((desc == 'l') ? X86_EAX : -1)))))
81 #define MONO_ARCH_INST_FIXED_MASK(desc) ((desc == 'y') ? (X86_BYTE_REGS) : 0)
83 /* RDX is clobbered by the opcode implementation before accessing sreg2 */
84 #define MONO_ARCH_INST_SREG2_MASK(ins) (((ins [MONO_INST_CLOB] == 'a') || (ins [MONO_INST_CLOB] == 'd')) ? (1 << X86_EDX) : 0)
87 * L is a generic register pair, while l means eax:rdx
89 #define MONO_ARCH_INST_IS_REGPAIR(desc) (desc == 'l' || desc == 'L')
90 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hreg1) (desc == 'l' ? X86_EDX : -1)
92 #if defined(__APPLE__)
93 #define MONO_ARCH_FRAME_ALIGNMENT 16
94 #else
95 #define MONO_ARCH_FRAME_ALIGNMENT 4
96 #endif
98 /* fixme: align to 16byte instead of 32byte (we align to 32byte to get
99 * reproduceable results for benchmarks */
100 #define MONO_ARCH_CODE_ALIGNMENT 32
102 #define MONO_ARCH_BASEREG X86_EBP
103 #define MONO_ARCH_RETREG1 X86_EAX
104 #define MONO_ARCH_RETREG2 X86_EDX
106 #define MONO_ARCH_AOT_PLT_OFFSET_REG X86_EAX
108 #define MONO_ARCH_ENCODE_LREG(r1,r2) (r1 | (r2<<3))
110 #define inst_dreg_low dreg&7
111 #define inst_dreg_high dreg>>3
112 #define inst_sreg1_low sreg1&7
113 #define inst_sreg1_high sreg1>>3
114 #define inst_sreg2_low sreg2&7
115 #define inst_sreg2_high sreg2>>3
117 struct MonoLMF {
118 gpointer previous_lmf;
119 gpointer lmf_addr;
120 MonoMethod *method;
121 guint32 ebx;
122 guint32 edi;
123 guint32 esi;
124 guint32 ebp;
125 guint32 eip;
128 typedef void* MonoCompileArch;
130 #if defined(__FreeBSD__) || defined(__APPLE__)
131 #include <ucontext.h>
132 #endif
134 #if defined(__FreeBSD__)
135 #define UCONTEXT_REG_EAX(ctx) ((ctx)->uc_mcontext.mc_eax)
136 #define UCONTEXT_REG_EBX(ctx) ((ctx)->uc_mcontext.mc_ebx)
137 #define UCONTEXT_REG_ECX(ctx) ((ctx)->uc_mcontext.mc_ecx)
138 #define UCONTEXT_REG_EDX(ctx) ((ctx)->uc_mcontext.mc_edx)
139 #define UCONTEXT_REG_EBP(ctx) ((ctx)->uc_mcontext.mc_ebp)
140 #define UCONTEXT_REG_ESP(ctx) ((ctx)->uc_mcontext.mc_esp)
141 #define UCONTEXT_REG_ESI(ctx) ((ctx)->uc_mcontext.mc_esi)
142 #define UCONTEXT_REG_EDI(ctx) ((ctx)->uc_mcontext.mc_edi)
143 #define UCONTEXT_REG_EIP(ctx) ((ctx)->uc_mcontext.mc_eip)
144 #elif defined(__APPLE__)
145 #define UCONTEXT_REG_EAX(ctx) ((ctx)->uc_mcontext->ss.eax)
146 #define UCONTEXT_REG_EBX(ctx) ((ctx)->uc_mcontext->ss.ebx)
147 #define UCONTEXT_REG_ECX(ctx) ((ctx)->uc_mcontext->ss.ecx)
148 #define UCONTEXT_REG_EDX(ctx) ((ctx)->uc_mcontext->ss.edx)
149 #define UCONTEXT_REG_EBP(ctx) ((ctx)->uc_mcontext->ss.ebp)
150 #define UCONTEXT_REG_ESP(ctx) ((ctx)->uc_mcontext->ss.esp)
151 #define UCONTEXT_REG_ESI(ctx) ((ctx)->uc_mcontext->ss.esi)
152 #define UCONTEXT_REG_EDI(ctx) ((ctx)->uc_mcontext->ss.edi)
153 #define UCONTEXT_REG_EIP(ctx) ((ctx)->uc_mcontext->ss.eip)
154 #else
155 #define UCONTEXT_REG_EAX(ctx) ((ctx)->uc_mcontext.gregs [REG_EAX])
156 #define UCONTEXT_REG_EBX(ctx) ((ctx)->uc_mcontext.gregs [REG_EBX])
157 #define UCONTEXT_REG_ECX(ctx) ((ctx)->uc_mcontext.gregs [REG_ECX])
158 #define UCONTEXT_REG_EDX(ctx) ((ctx)->uc_mcontext.gregs [REG_EDX])
159 #define UCONTEXT_REG_EBP(ctx) ((ctx)->uc_mcontext.gregs [REG_EBP])
160 #define UCONTEXT_REG_ESP(ctx) ((ctx)->uc_mcontext.gregs [REG_ESP])
161 #define UCONTEXT_REG_ESI(ctx) ((ctx)->uc_mcontext.gregs [REG_ESI])
162 #define UCONTEXT_REG_EDI(ctx) ((ctx)->uc_mcontext.gregs [REG_EDI])
163 #define UCONTEXT_REG_EIP(ctx) ((ctx)->uc_mcontext.gregs [REG_EIP])
164 #endif
166 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
167 # define SC_EAX sc_eax
168 # define SC_EBX sc_ebx
169 # define SC_ECX sc_ecx
170 # define SC_EDX sc_edx
171 # define SC_EBP sc_ebp
172 # define SC_EIP sc_eip
173 # define SC_ESP sc_esp
174 # define SC_EDI sc_edi
175 # define SC_ESI sc_esi
176 #else
177 # define SC_EAX eax
178 # define SC_EBX ebx
179 # define SC_ECX ecx
180 # define SC_EDX edx
181 # define SC_EBP ebp
182 # define SC_EIP eip
183 # define SC_ESP esp
184 # define SC_EDI edi
185 # define SC_ESI esi
186 #endif
188 typedef struct {
189 guint32 eax;
190 guint32 ebx;
191 guint32 ecx;
192 guint32 edx;
193 guint32 ebp;
194 guint32 esp;
195 guint32 esi;
196 guint32 edi;
197 guint32 eip;
198 } MonoContext;
200 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->eip = (long)(ip); } while (0);
201 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->ebp = (long)(bp); } while (0);
202 #define MONO_CONTEXT_SET_SP(ctx,sp) do { (ctx)->esp = (long)(sp); } while (0);
204 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->eip))
205 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->ebp))
206 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->esp))
208 #ifdef _MSC_VER
210 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx, start_func) do { \
211 unsigned int stackptr; \
212 mono_arch_flush_register_windows (); \
214 __asm mov stackptr, ebp \
216 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
217 MONO_CONTEXT_SET_BP ((ctx), stackptr); \
218 } while (0)
220 #else
222 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do { \
223 mono_arch_flush_register_windows (); \
224 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
225 MONO_CONTEXT_SET_BP ((ctx), __builtin_frame_address (0)); \
226 } while (0)
228 #endif
230 #define MONO_ARCH_BIGMUL_INTRINS 1
231 #define MONO_ARCH_NEED_DIV_CHECK 1
232 #define MONO_ARCH_HAVE_IS_INT_OVERFLOW 1
233 #define MONO_ARCH_HAVE_INVALIDATE_METHOD 1
234 #define MONO_ARCH_HAVE_PIC_AOT 1
235 #define MONO_ARCH_NEED_GOT_VAR 1
236 #define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION 1
237 #define MONO_ARCH_ENABLE_EMIT_STATE_OPT 1
238 #define MONO_ARCH_ENABLE_MONO_LMF_VAR 1
239 #define MONO_ARCH_HAVE_CREATE_TRAMPOLINE_FROM_TOKEN 1
240 #define MONO_ARCH_HAVE_CREATE_SPECIFIC_TRAMPOLINE 1
241 #define MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE 1
242 #define MONO_ARCH_HAVE_CREATE_VARS 1
244 #endif /* __MONO_MINI_X86_H__ */