1 #ifndef __MONO_MINI_X86_H__
2 #define __MONO_MINI_X86_H__
4 #include <mono/arch/x86/x86-codegen.h>
5 #include <mono/utils/mono-sigcontext.h>
6 #include <mono/utils/mono-context.h>
8 #ifdef __native_client_codegen__
9 #define kNaClAlignmentX86 32
10 #define kNaClAlignmentMaskX86 (kNaClAlignmentX86 - 1)
12 #define kNaClLengthOfCallImm kx86NaClLengthOfCallImm
17 /* use SIG* defines if possible */
22 typedef void (* MonoW32ExceptionHandler) (int _dummy, EXCEPTION_RECORD *info, void *context);
23 void win32_seh_init(void);
24 void win32_seh_cleanup(void);
25 void win32_seh_set_handler(int type, MonoW32ExceptionHandler handler);
39 LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep);
41 #endif /* HOST_WIN32 */
47 #endif /* __HAIKU__ */
49 #if defined( __linux__) || defined(__sun) || defined(__APPLE__) || defined(__NetBSD__) || \
50 defined(__FreeBSD__) || defined(__OpenBSD__)
51 #define MONO_ARCH_USE_SIGACTION
54 #if defined(__native_client__)
55 #undef MONO_ARCH_USE_SIGACTION
60 #ifdef HAVE_WORKING_SIGALTSTACK
62 * solaris doesn't have pthread_getattr_np () needed by the sigaltstack setup
66 #define MONO_ARCH_SIGSEGV_ON_ALTSTACK
68 /* Haiku doesn't have SA_SIGINFO */
70 #define MONO_ARCH_USE_SIGACTION
71 #endif /* __HAIKU__ */
73 #endif /* HAVE_WORKING_SIGALTSTACK */
74 #endif /* !HOST_WIN32 */
76 #define MONO_ARCH_SUPPORT_SIMD_INTRINSICS 1
77 #define MONO_ARCH_SUPPORT_TASKLETS 1
80 #define MONO_ARCH_SIMD_INTRINSICS 1
81 #define MONO_ARCH_NEED_SIMD_BANK 1
84 /* we should lower this size and make sure we don't call heavy stack users in the segv handler */
85 #define MONO_ARCH_SIGNAL_STACK_SIZE (16 * 1024)
86 #define MONO_ARCH_HAVE_RESTORE_STACK_SUPPORT 1
88 #define MONO_ARCH_CPU_SPEC x86_desc
90 #define MONO_MAX_IREGS 8
91 #define MONO_MAX_FREGS 8
92 #define MONO_MAX_XREGS 8
94 /* Parameters used by the register allocator */
95 #define MONO_ARCH_CALLEE_REGS X86_CALLEE_REGS
96 #define MONO_ARCH_CALLEE_SAVED_REGS X86_CALLER_REGS
98 #define MONO_ARCH_CALLEE_FREGS (0xff & ~(regmask (MONO_ARCH_FPSTACK_SIZE)))
99 #define MONO_ARCH_CALLEE_SAVED_FREGS 0
101 /* All registers are clobered by a call */
102 #define MONO_ARCH_CALLEE_XREGS (0xff & ~(regmask (MONO_MAX_XREGS)))
103 #define MONO_ARCH_CALLEE_SAVED_XREGS 0
105 #define MONO_ARCH_USE_FPSTACK TRUE
106 #define MONO_ARCH_FPSTACK_SIZE 6
108 #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)))))
110 #define MONO_ARCH_INST_FIXED_MASK(desc) ((desc == 'y') ? (X86_BYTE_REGS) : 0)
112 /* RDX is clobbered by the opcode implementation before accessing sreg2 */
114 * Originally this contained X86_EDX for div/rem opcodes, but that led to unsolvable
115 * situations since there are only 3 usable registers for local register allocation.
116 * Instead, we handle the sreg2==edx case in the opcodes.
118 #define MONO_ARCH_INST_SREG2_MASK(ins) 0
121 * L is a generic register pair, while l means eax:rdx
123 #define MONO_ARCH_INST_IS_REGPAIR(desc) (desc == 'l' || desc == 'L')
124 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hreg1) (desc == 'l' ? X86_EDX : -1)
126 /* must be at a power of 2 and >= 8 */
127 #define MONO_ARCH_FRAME_ALIGNMENT 16
129 /* fixme: align to 16byte instead of 32byte (we align to 32byte to get
130 * reproduceable results for benchmarks */
131 #define MONO_ARCH_CODE_ALIGNMENT 32
133 #define MONO_ARCH_RETREG1 X86_EAX
134 #define MONO_ARCH_RETREG2 X86_EDX
136 /*This is the max size of the locals area of a given frame. I think 1MB is a safe default for now*/
137 #define MONO_ARCH_MAX_FRAME_SIZE 0x100000
139 /*This is how much a try block must be extended when is is preceeded by a Monitor.Enter() call.
140 It's 4 bytes as this is how many bytes + 1 that 'add 0x10, %esp' takes. It is used to pop the arguments from
141 the monitor.enter call and must be already protected.*/
142 #define MONO_ARCH_MONITOR_ENTER_ADJUSTMENT 4
146 * If the lowest bit is set to 1, then this is a trampoline LMF frame.
147 * If the second lowest bit is set to 1, then this is a MonoLMFExt structure, and
148 * the other fields are not valid.
150 guint32 previous_lmf;
152 /* Only set in trampoline LMF frames */
154 /* Only set in trampoline LMF frames */
164 gboolean need_stack_frame_inited;
165 gboolean need_stack_frame;
168 #define MONO_CONTEXT_SET_LLVM_EXC_REG(ctx, exc) do { (ctx)->eax = (gsize)exc; } while (0)
172 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx, start_func) do { \
173 unsigned int stackptr; \
174 mono_arch_flush_register_windows (); \
176 __asm mov stackptr, ebp \
178 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
179 MONO_CONTEXT_SET_BP ((ctx), stackptr); \
180 MONO_CONTEXT_SET_SP ((ctx), stackptr); \
185 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do { \
186 mono_arch_flush_register_windows (); \
187 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
188 MONO_CONTEXT_SET_BP ((ctx), __builtin_frame_address (0)); \
189 MONO_CONTEXT_SET_SP ((ctx), __builtin_frame_address (0)); \
194 #define MONO_ARCH_INIT_TOP_LMF_ENTRY(lmf) do { (lmf)->ebp = -1; } while (0)
196 /* Enables OP_LSHL, OP_LSHL_IMM, OP_LSHR, OP_LSHR_IMM, OP_LSHR_UN, OP_LSHR_UN_IMM */
197 #define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS
199 #define MONO_ARCH_BIGMUL_INTRINS 1
200 #define MONO_ARCH_NEED_DIV_CHECK 1
201 #define MONO_ARCH_HAVE_IS_INT_OVERFLOW 1
202 #define MONO_ARCH_HAVE_INVALIDATE_METHOD 1
203 #define MONO_ARCH_NEED_GOT_VAR 1
204 #if !defined(__APPLE__)
205 #define MONO_ARCH_ENABLE_MONO_LMF_VAR 1
207 #define MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE 1
208 #define MONO_ARCH_HAVE_ATOMIC_ADD 1
209 #define MONO_ARCH_HAVE_ATOMIC_EXCHANGE 1
210 #define MONO_ARCH_HAVE_ATOMIC_CAS 1
211 #define MONO_ARCH_HAVE_IMT 1
212 #define MONO_ARCH_HAVE_TLS_GET (mono_x86_have_tls_get ())
213 #define MONO_ARCH_IMT_REG X86_EDX
214 #define MONO_ARCH_VTABLE_REG X86_EDX
215 #define MONO_ARCH_RGCTX_REG X86_EDX
216 #define MONO_ARCH_HAVE_GENERALIZED_IMT_THUNK 1
217 #define MONO_ARCH_HAVE_LIVERANGE_OPS 1
218 #define MONO_ARCH_HAVE_XP_UNWIND 1
219 #define MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX 1
220 #if defined(__linux__) || defined (__APPLE__)
221 #define MONO_ARCH_MONITOR_OBJECT_REG X86_EAX
223 #define MONO_ARCH_HAVE_STATIC_RGCTX_TRAMPOLINE 1
224 #if !defined (__APPLE__) || defined(__native_client_codegen__)
225 #define MONO_ARCH_HAVE_FULL_AOT_TRAMPOLINES 1
227 #define MONO_ARCH_GOT_REG X86_EBX
228 #define MONO_ARCH_HAVE_GET_TRAMPOLINES 1
230 #define MONO_ARCH_HAVE_CMOV_OPS 1
232 #ifdef MONO_ARCH_SIMD_INTRINSICS
233 #define MONO_ARCH_HAVE_DECOMPOSE_OPTS 1
236 #define MONO_ARCH_HAVE_DECOMPOSE_LONG_OPTS 1
238 #define MONO_ARCH_AOT_SUPPORTED 1
240 #define MONO_ARCH_ENABLE_MONITOR_IL_FASTPATH 1
242 #define MONO_ARCH_GSHARED_SUPPORTED 1
243 #define MONO_ARCH_HAVE_LLVM_IMT_TRAMPOLINE 1
244 #define MONO_ARCH_LLVM_SUPPORTED 1
245 #define MONO_ARCH_THIS_AS_FIRST_ARG 1
247 #if defined(MONO_ARCH_USE_SIGACTION) || defined(TARGET_WIN32)
248 #define MONO_ARCH_SOFT_DEBUG_SUPPORTED 1
251 #define MONO_ARCH_HAVE_EXCEPTIONS_INIT 1
252 #define MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD 1
254 #define MONO_ARCH_HAVE_CARD_TABLE_WBARRIER 1
255 #define MONO_ARCH_HAVE_SETUP_RESUME_FROM_SIGNAL_HANDLER_CTX 1
256 #define MONO_ARCH_GC_MAPS_SUPPORTED 1
259 mono_x86_tail_call_supported (MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig) MONO_INTERNAL;
261 #define MONO_ARCH_USE_OP_TAIL_CALL(caller_sig, callee_sig) mono_x86_tail_call_supported (caller_sig, callee_sig)
263 /* Used for optimization, not complete */
264 #define MONO_ARCH_IS_OP_MEMBASE(opcode) ((opcode) == OP_X86_PUSH_MEMBASE)
266 #define MONO_ARCH_EMIT_BOUNDS_CHECK(cfg, array_reg, offset, index_reg) do { \
268 MONO_INST_NEW ((cfg), inst, OP_X86_COMPARE_MEMBASE_REG); \
269 inst->inst_basereg = array_reg; \
270 inst->inst_offset = offset; \
271 inst->sreg2 = index_reg; \
272 MONO_ADD_INS ((cfg)->cbb, inst); \
273 MONO_EMIT_NEW_COND_EXC (cfg, LE_UN, "IndexOutOfRangeException"); \
279 } MonoBreakpointInfo;
281 extern MonoBreakpointInfo mono_breakpoint_info [MONO_BREAKPOINT_ARRAY_SIZE];
284 mono_x86_emit_tls_get (guint8* code, int dreg, int tls_offset) MONO_INTERNAL;
287 mono_x86_get_this_arg_offset (MonoGenericSharingContext *gsctx, MonoMethodSignature *sig) MONO_INTERNAL;
290 mono_x86_have_tls_get (void) MONO_INTERNAL;
293 mono_x86_throw_exception (mgreg_t *regs, MonoObject *exc,
294 mgreg_t eip, gboolean rethrow) MONO_INTERNAL;
297 mono_x86_throw_corlib_exception (mgreg_t *regs, guint32 ex_token_index,
298 mgreg_t eip, gint32 pc_offset) MONO_INTERNAL;
301 mono_x86_patch (unsigned char* code, gpointer target) MONO_INTERNAL;
303 #endif /* __MONO_MINI_X86_H__ */