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>
8 /* use SIG* defines if possible */
13 /* sigcontext surrogate */
26 typedef void (* MonoW32ExceptionHandler
) (int _dummy
, EXCEPTION_RECORD
*info
, void *context
);
27 void win32_seh_init(void);
28 void win32_seh_cleanup(void);
29 void win32_seh_set_handler(int type
, MonoW32ExceptionHandler handler
);
43 LONG CALLBACK
seh_handler(EXCEPTION_POINTERS
* ep
);
45 #endif /* PLATFORM_WIN32 */
47 #if defined( __linux__) || defined(__sun) || defined(__APPLE__) || defined(__NetBSD__) || defined(__FreeBSD__)
48 #define MONO_ARCH_USE_SIGACTION
51 #ifndef PLATFORM_WIN32
53 #ifdef HAVE_WORKING_SIGALTSTACK
55 * solaris doesn't have pthread_getattr_np () needed by the sigaltstack setup
59 #define MONO_ARCH_SIGSEGV_ON_ALTSTACK
61 #define MONO_ARCH_USE_SIGACTION
63 #endif /* HAVE_WORKING_SIGALTSTACK */
64 #endif /* !PLATFORM_WIN32 */
66 #define MONO_ARCH_SUPPORT_SIMD_INTRINSICS 1
67 #define MONO_ARCH_SUPPORT_TASKLETS 1
70 #define MONO_ARCH_SIMD_INTRINSICS 1
71 #define MONO_ARCH_NEED_SIMD_BANK 1
74 /* we should lower this size and make sure we don't call heavy stack users in the segv handler */
75 #define MONO_ARCH_SIGNAL_STACK_SIZE (16 * 1024)
76 #define MONO_ARCH_HAVE_RESTORE_STACK_SUPPORT 1
78 #define MONO_ARCH_CPU_SPEC x86_desc
80 #define MONO_MAX_IREGS 8
81 #define MONO_MAX_FREGS 8
82 #define MONO_MAX_XREGS 8
84 /* Parameters used by the register allocator */
85 #define MONO_ARCH_CALLEE_REGS X86_CALLEE_REGS
86 #define MONO_ARCH_CALLEE_SAVED_REGS X86_CALLER_REGS
88 #define MONO_ARCH_CALLEE_FREGS (0xff & ~(regmask (MONO_ARCH_FPSTACK_SIZE)))
89 #define MONO_ARCH_CALLEE_SAVED_FREGS 0
91 /* All registers are clobered by a call */
92 #define MONO_ARCH_CALLEE_XREGS (0xff & ~(regmask (MONO_MAX_XREGS)))
93 #define MONO_ARCH_CALLEE_SAVED_XREGS 0
95 #define MONO_ARCH_USE_FPSTACK TRUE
96 #define MONO_ARCH_FPSTACK_SIZE 6
98 #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)))))
100 #define MONO_ARCH_INST_FIXED_MASK(desc) ((desc == 'y') ? (X86_BYTE_REGS) : 0)
102 /* RDX is clobbered by the opcode implementation before accessing sreg2 */
104 * Originally this contained X86_EDX for div/rem opcodes, but that led to unsolvable
105 * situations since there are only 3 usable registers for local register allocation.
106 * Instead, we handle the sreg2==edx case in the opcodes.
108 #define MONO_ARCH_INST_SREG2_MASK(ins) 0
111 * L is a generic register pair, while l means eax:rdx
113 #define MONO_ARCH_INST_IS_REGPAIR(desc) (desc == 'l' || desc == 'L')
114 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hreg1) (desc == 'l' ? X86_EDX : -1)
116 /* must be at a power of 2 and >= 8 */
117 #define MONO_ARCH_FRAME_ALIGNMENT 16
119 /* fixme: align to 16byte instead of 32byte (we align to 32byte to get
120 * reproduceable results for benchmarks */
121 #define MONO_ARCH_CODE_ALIGNMENT 32
123 #define MONO_ARCH_RETREG1 X86_EAX
124 #define MONO_ARCH_RETREG2 X86_EDX
128 * If the lowest bit is set to 1, then this is a trampoline LMF frame.
129 * If the second lowest bit is set to 1, then this is a MonoLMFExt structure, and
130 * the other fields are not valid.
132 guint32 previous_lmf
;
134 /* Only set in trampoline LMF frames */
136 /* Only set in trampoline LMF frames */
146 gboolean need_stack_frame_inited
;
147 gboolean need_stack_frame
;
150 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
151 # define SC_EAX sc_eax
152 # define SC_EBX sc_ebx
153 # define SC_ECX sc_ecx
154 # define SC_EDX sc_edx
155 # define SC_EBP sc_ebp
156 # define SC_EIP sc_eip
157 # define SC_ESP sc_esp
158 # define SC_EDI sc_edi
159 # define SC_ESI sc_esi
184 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->eip = (long)(ip); } while (0);
185 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->ebp = (long)(bp); } while (0);
186 #define MONO_CONTEXT_SET_SP(ctx,sp) do { (ctx)->esp = (long)(sp); } while (0);
188 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->eip))
189 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->ebp))
190 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->esp))
194 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx, start_func) do { \
195 unsigned int stackptr; \
196 mono_arch_flush_register_windows (); \
198 __asm mov stackptr, ebp \
200 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
201 MONO_CONTEXT_SET_BP ((ctx), stackptr); \
202 MONO_CONTEXT_SET_SP ((ctx), stackptr); \
207 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do { \
208 mono_arch_flush_register_windows (); \
209 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
210 MONO_CONTEXT_SET_BP ((ctx), __builtin_frame_address (0)); \
211 MONO_CONTEXT_SET_SP ((ctx), __builtin_frame_address (0)); \
217 * This structure is an extension of MonoLMF and contains extra information.
221 gboolean debugger_invoke
;
222 MonoContext ctx
; /* if debugger_invoke is TRUE */
225 /* Enables OP_LSHL, OP_LSHL_IMM, OP_LSHR, OP_LSHR_IMM, OP_LSHR_UN, OP_LSHR_UN_IMM */
226 #define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS
228 #define MONO_ARCH_BIGMUL_INTRINS 1
229 #define MONO_ARCH_NEED_DIV_CHECK 1
230 #define MONO_ARCH_HAVE_IS_INT_OVERFLOW 1
231 #define MONO_ARCH_HAVE_INVALIDATE_METHOD 1
232 #define MONO_ARCH_NEED_GOT_VAR 1
233 #define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION 1
234 #define MONO_ARCH_ENABLE_MONO_LMF_VAR 1
235 #define MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE 1
236 #define MONO_ARCH_HAVE_ATOMIC_ADD 1
237 #define MONO_ARCH_HAVE_ATOMIC_EXCHANGE 1
238 #define MONO_ARCH_HAVE_ATOMIC_CAS 1
239 #define MONO_ARCH_HAVE_IMT 1
240 #define MONO_ARCH_HAVE_TLS_GET 1
241 #define MONO_ARCH_IMT_REG X86_EDX
242 #define MONO_ARCH_VTABLE_REG X86_EDX
243 #define MONO_ARCH_RGCTX_REG X86_EDX
244 #define MONO_ARCH_HAVE_GENERALIZED_IMT_THUNK 1
245 #define MONO_ARCH_HAVE_LIVERANGE_OPS 1
246 #define MONO_ARCH_HAVE_XP_UNWIND 1
247 #define MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX 1
248 #if defined(__linux__) && !defined(HAVE_MOVING_COLLECTOR)
249 #define MONO_ARCH_MONITOR_OBJECT_REG X86_EAX
251 #define MONO_ARCH_HAVE_STATIC_RGCTX_TRAMPOLINE 1
253 #define MONO_ARCH_HAVE_CMOV_OPS 1
255 #ifdef MONO_ARCH_SIMD_INTRINSICS
256 #define MONO_ARCH_HAVE_DECOMPOSE_OPTS 1
259 #define MONO_ARCH_HAVE_DECOMPOSE_LONG_OPTS 1
261 #if !defined(__APPLE__)
262 #define MONO_ARCH_AOT_SUPPORTED 1
265 #if defined(__linux__) || defined(__sun)
266 #define MONO_ARCH_ENABLE_MONITOR_IL_FASTPATH 1
269 #define MONO_ARCH_GSHARED_SUPPORTED 1
270 //#define MONO_ARCH_HAVE_LLVM_IMT_TRAMPOLINE 1
271 #ifndef PLATFORM_WIN32
272 #define MONO_ARCH_SOFT_DEBUG_SUPPORTED 1
274 #define DISABLE_DEBUGGER_AGENT 1
276 #define MONO_ARCH_HAVE_FIND_JIT_INFO_EXT 1
278 /* Used for optimization, not complete */
279 #define MONO_ARCH_IS_OP_MEMBASE(opcode) ((opcode) == OP_X86_PUSH_MEMBASE)
281 #define MONO_ARCH_EMIT_BOUNDS_CHECK(cfg, array_reg, offset, index_reg) do { \
283 MONO_INST_NEW ((cfg), inst, OP_X86_COMPARE_MEMBASE_REG); \
284 inst->inst_basereg = array_reg; \
285 inst->inst_offset = offset; \
286 inst->sreg2 = index_reg; \
287 MONO_ADD_INS ((cfg)->cbb, inst); \
288 MONO_EMIT_NEW_COND_EXC (cfg, LE_UN, "IndexOutOfRangeException"); \
294 } MonoBreakpointInfo
;
296 extern MonoBreakpointInfo mono_breakpoint_info
[MONO_BREAKPOINT_ARRAY_SIZE
];
299 mono_x86_emit_tls_get (guint8
* code
, int dreg
, int tls_offset
) MONO_INTERNAL
;
301 #endif /* __MONO_MINI_X86_H__ */