1 #ifndef __MONO_MINI_X86_H__
2 #define __MONO_MINI_X86_H__
4 #include <mono/arch/x86/x86-codegen.h>
7 /* use SIG* defines if possible */
12 /* sigcontext surrogate */
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);
42 LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep);
44 #endif /* PLATFORM_WIN32 */
46 #if defined( __linux__) || defined(__sun)
47 #define MONO_ARCH_USE_SIGACTION
50 #ifndef PLATFORM_WIN32
52 #ifdef HAVE_WORKING_SIGALTSTACK
53 #define MONO_ARCH_SIGSEGV_ON_ALTSTACK
54 #define MONO_ARCH_USE_SIGACTION
56 /* FreeBSD and NetBSD need SA_STACK and MAP_ANON re-definitions */
57 # if defined(__FreeBSD__) || defined(__NetBSD__)
59 # define SA_STACK SA_ONSTACK
61 # ifndef MAP_ANONYMOUS
62 # define MAP_ANONYMOUS MAP_ANON
66 #endif /* HAVE_WORKING_SIGALTSTACK */
67 #endif /* !PLATFORM_WIN32 */
69 #define MONO_ARCH_SIGNAL_STACK_SIZE (64 * 1024)
71 /* Enables OP_LSHL, OP_LSHL_IMM, OP_LSHR, OP_LSHR_IMM, OP_LSHR_UN, OP_LSHR_UN_IMM */
72 #define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS
74 #define MONO_MAX_IREGS 8
75 #define MONO_MAX_FREGS 6
77 /* Parameters used by the register allocator */
78 #define MONO_ARCH_HAS_XP_LOCAL_REGALLOC
80 #define MONO_ARCH_CALLEE_REGS X86_CALLEE_REGS
81 #define MONO_ARCH_CALLEE_SAVED_REGS X86_CALLER_REGS
83 #define MONO_ARCH_CALLEE_FREGS 0
84 #define MONO_ARCH_CALLEE_SAVED_FREGS 0
86 #define MONO_ARCH_USE_FPSTACK TRUE
87 #define MONO_ARCH_FPSTACK_SIZE 6
89 /* FIXME: Don't constrain byte regs to eax */
90 #define MONO_ARCH_INST_FIXED_REG(desc) ((desc == 's') ? X86_ECX : ((desc == 'a') ? X86_EAX : ((desc == 'd') ? X86_EDX : ((desc == 'y') ? X86_EAX : ((desc == 'l') ? X86_EAX : -1)))))
92 /* RDX is clobbered by the opcode implementation before accessing sreg2 */
93 #define MONO_ARCH_INST_SREG2_MASK(ins) (((ins [MONO_INST_CLOB] == 'a') || (ins [MONO_INST_CLOB] == 'd')) ? (1 << X86_EDX) : 0)
96 * L is a generic register pair, while l means eax:rdx
98 #define MONO_ARCH_INST_IS_REGPAIR(desc) (desc == 'l' || desc == 'L')
99 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hreg1) (desc == 'l' ? X86_EDX : -1)
101 #define MONO_ARCH_FRAME_ALIGNMENT 4
103 /* fixme: align to 16byte instead of 32byte (we align to 32byte to get
104 * reproduceable results for benchmarks */
105 #define MONO_ARCH_CODE_ALIGNMENT 32
107 #define MONO_ARCH_BASEREG X86_EBP
108 #define MONO_ARCH_RETREG1 X86_EAX
109 #define MONO_ARCH_RETREG2 X86_EDX
111 #define MONO_ARCH_ENCODE_LREG(r1,r2) (r1 | (r2<<3))
113 #define inst_dreg_low dreg&7
114 #define inst_dreg_high dreg>>3
115 #define inst_sreg1_low sreg1&7
116 #define inst_sreg1_high sreg1>>3
117 #define inst_sreg2_low sreg2&7
118 #define inst_sreg2_high sreg2>>3
121 gpointer previous_lmf;
131 typedef void* MonoCompileArch;
133 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
134 # define SC_EAX sc_eax
135 # define SC_EBX sc_ebx
136 # define SC_ECX sc_ecx
137 # define SC_EDX sc_edx
138 # define SC_EBP sc_ebp
139 # define SC_EIP sc_eip
140 # define SC_ESP sc_esp
141 # define SC_EDI sc_edi
142 # define SC_ESI sc_esi
167 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->eip = (long)(ip); } while (0);
168 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->ebp = (long)(bp); } while (0);
169 #define MONO_CONTEXT_SET_SP(ctx,sp) do { (ctx)->esp = (long)(sp); } while (0);
171 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->eip))
172 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->ebp))
173 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->esp))
177 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx, start_func) do { \
178 unsigned int stackptr; \
179 mono_arch_flush_register_windows (); \
181 __asm mov stackptr, ebp \
183 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
184 MONO_CONTEXT_SET_BP ((ctx), stackptr); \
187 #define MONO_INIT_CONTEXT_FROM_CALLER(ctx) do { \
188 unsigned int stackptr, retaddr; \
190 __asm mov stackptr, ebp \
191 __asm mov eax, DWORD PTR [ebp + 4] \
192 __asm mov retaddr, eax \
194 MONO_CONTEXT_SET_IP ((ctx), retaddr); \
195 /* FIXME: NOT WORKING -- THIS IS __builtin_frame_address (0) NOT (1) */ \
196 MONO_CONTEXT_SET_BP ((ctx), stackptr); \
201 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do { \
202 mono_arch_flush_register_windows (); \
203 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
204 MONO_CONTEXT_SET_BP ((ctx), __builtin_frame_address (0)); \
209 #define MONO_ARCH_BIGMUL_INTRINS 1
210 #define MONO_ARCH_NEED_DIV_CHECK 1
211 #define MONO_ARCH_HAVE_IS_INT_OVERFLOW 1
212 #define MONO_ARCH_HAVE_INVALIDATE_METHOD 1
213 #define MONO_ARCH_HAVE_PIC_AOT 1
214 #define MONO_ARCH_NEED_GOT_VAR 1
215 #define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION 1
216 #define MONO_ARCH_ENABLE_EMIT_STATE_OPT 1
217 #define MONO_ARCH_HAVE_CREATE_TRAMPOLINE_FROM_TOKEN 1
218 #define MONO_ARCH_HAVE_CREATE_SPECIFIC_TRAMPOLINE 1
219 #define MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE 1
220 #define MONO_ARCH_HAVE_CREATE_VARS 1
222 #endif /* __MONO_MINI_X86_H__ */