Move MonoContext to mono-context for mips
[mono.git] / mono / mini / mini-x86.h
index feaade49a92a7abda7b4bf3f89ef0bc837bd45cb..6ee04ab2c1592b78fc07b6817398659193734449 100644 (file)
@@ -3,27 +3,24 @@
 
 #include <mono/arch/x86/x86-codegen.h>
 #include <mono/utils/mono-sigcontext.h>
-#ifdef PLATFORM_WIN32
+#include <mono/utils/mono-context.h>
+
+#ifdef __native_client_codegen__
+#define kNaClAlignmentX86 32
+#define kNaClAlignmentMaskX86 (kNaClAlignmentX86 - 1)
+
+#define kNaClLengthOfCallImm kx86NaClLengthOfCallImm
+#endif
+
+#ifdef HOST_WIN32
 #include <windows.h>
 /* use SIG* defines if possible */
 #ifdef HAVE_SIGNAL_H
 #include <signal.h>
 #endif
 
-/* sigcontext surrogate */
-struct sigcontext {
-       unsigned int eax;
-       unsigned int ebx;
-       unsigned int ecx;
-       unsigned int edx;
-       unsigned int ebp;
-       unsigned int esp;
-       unsigned int esi;
-       unsigned int edi;
-       unsigned int eip;
-};
+typedef void (* MonoW32ExceptionHandler) (int _dummy, EXCEPTION_POINTERS *info, void *context);
 
-typedef void (* MonoW32ExceptionHandler) (int);
 void win32_seh_init(void);
 void win32_seh_cleanup(void);
 void win32_seh_set_handler(int type, MonoW32ExceptionHandler handler);
@@ -42,13 +39,24 @@ void win32_seh_set_handler(int type, MonoW32ExceptionHandler handler);
 
 LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep);
 
-#endif /* PLATFORM_WIN32 */
+#endif /* HOST_WIN32 */
 
-#if defined( __linux__) || defined(__sun) || defined(__APPLE__) || defined(__NetBSD__) || defined(__FreeBSD__)
+#ifdef __HAIKU__
+struct sigcontext {
+       vregs regs;
+};
+#endif /* __HAIKU__ */
+
+#if defined( __linux__) || defined(__sun) || defined(__APPLE__) || defined(__NetBSD__) || \
+       defined(__FreeBSD__) || defined(__OpenBSD__)
 #define MONO_ARCH_USE_SIGACTION
 #endif
 
-#ifndef PLATFORM_WIN32
+#if defined(__native_client__)
+#undef MONO_ARCH_USE_SIGACTION
+#endif
+
+#ifndef HOST_WIN32
 
 #ifdef HAVE_WORKING_SIGALTSTACK
 /* 
@@ -58,10 +66,13 @@ LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep);
 #ifndef __sun
 #define MONO_ARCH_SIGSEGV_ON_ALTSTACK
 #endif
+/* Haiku doesn't have SA_SIGINFO */
+#ifndef __HAIKU__
 #define MONO_ARCH_USE_SIGACTION
+#endif /* __HAIKU__ */
 
 #endif /* HAVE_WORKING_SIGALTSTACK */
-#endif /* !PLATFORM_WIN32 */
+#endif /* !HOST_WIN32 */
 
 #define MONO_ARCH_SUPPORT_SIMD_INTRINSICS 1
 #define MONO_ARCH_SUPPORT_TASKLETS 1
@@ -123,6 +134,14 @@ LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep);
 #define MONO_ARCH_RETREG1 X86_EAX
 #define MONO_ARCH_RETREG2 X86_EDX
 
+/*This is the max size of the locals area of a given frame. I think 1MB is a safe default for now*/
+#define MONO_ARCH_MAX_FRAME_SIZE 0x100000
+
+/*This is how much a try block must be extended when is is preceeded by a Monitor.Enter() call.
+It's 4 bytes as this is how many bytes + 1 that 'add 0x10, %esp' takes. It is used to pop the arguments from
+the monitor.enter call and must be already protected.*/
+#define MONO_ARCH_MONITOR_ENTER_ADJUSTMENT 4
+
 struct MonoLMF {
        /* 
         * If the lowest bit is set to 1, then this is a trampoline LMF frame.
@@ -147,47 +166,7 @@ typedef struct {
        gboolean need_stack_frame;
 } MonoCompileArch;
 
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
-# define SC_EAX sc_eax
-# define SC_EBX sc_ebx
-# define SC_ECX sc_ecx
-# define SC_EDX sc_edx
-# define SC_EBP sc_ebp
-# define SC_EIP sc_eip
-# define SC_ESP sc_esp
-# define SC_EDI sc_edi
-# define SC_ESI sc_esi
-#else
-# define SC_EAX eax
-# define SC_EBX ebx
-# define SC_ECX ecx
-# define SC_EDX edx
-# define SC_EBP ebp
-# define SC_EIP eip
-# define SC_ESP esp
-# define SC_EDI edi
-# define SC_ESI esi
-#endif
-
-typedef struct {
-       guint32 eax;
-       guint32 ebx;
-       guint32 ecx;
-       guint32 edx;
-       guint32 ebp;
-       guint32 esp;
-    guint32 esi;
-       guint32 edi;
-       guint32 eip;
-} MonoContext;
-
-#define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->eip = (long)(ip); } while (0); 
-#define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->ebp = (long)(bp); } while (0); 
-#define MONO_CONTEXT_SET_SP(ctx,sp) do { (ctx)->esp = (long)(sp); } while (0); 
-
-#define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->eip))
-#define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->ebp))
-#define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->esp))
+#define MONO_CONTEXT_SET_LLVM_EXC_REG(ctx, exc) do { (ctx)->eax = (gsize)exc; } while (0)
 
 #ifdef _MSC_VER
 
@@ -213,14 +192,7 @@ typedef struct {
 
 #endif
 
-/*
- * This structure is an extension of MonoLMF and contains extra information.
- */
-typedef struct {
-       struct MonoLMF lmf;
-       gboolean debugger_invoke;
-       MonoContext ctx; /* if debugger_invoke is TRUE */
-} MonoLMFExt;
+#define MONO_ARCH_INIT_TOP_LMF_ENTRY(lmf) do { (lmf)->ebp = -1; } while (0)
 
 /* Enables OP_LSHL, OP_LSHL_IMM, OP_LSHR, OP_LSHR_IMM, OP_LSHR_UN, OP_LSHR_UN_IMM */
 #define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS
@@ -230,14 +202,15 @@ typedef struct {
 #define MONO_ARCH_HAVE_IS_INT_OVERFLOW 1
 #define MONO_ARCH_HAVE_INVALIDATE_METHOD 1
 #define MONO_ARCH_NEED_GOT_VAR 1
-#define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION 1
+#if !defined(__APPLE__)
 #define MONO_ARCH_ENABLE_MONO_LMF_VAR 1
+#endif
 #define MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE 1
 #define MONO_ARCH_HAVE_ATOMIC_ADD 1
 #define MONO_ARCH_HAVE_ATOMIC_EXCHANGE 1
 #define MONO_ARCH_HAVE_ATOMIC_CAS 1
 #define MONO_ARCH_HAVE_IMT 1
-#define MONO_ARCH_HAVE_TLS_GET 1
+#define MONO_ARCH_HAVE_TLS_GET (mono_x86_have_tls_get ())
 #define MONO_ARCH_IMT_REG X86_EDX
 #define MONO_ARCH_VTABLE_REG X86_EDX
 #define MONO_ARCH_RGCTX_REG X86_EDX
@@ -245,10 +218,15 @@ typedef struct {
 #define MONO_ARCH_HAVE_LIVERANGE_OPS 1
 #define MONO_ARCH_HAVE_XP_UNWIND 1
 #define MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX 1
-#if defined(__linux__) && !defined(HAVE_MOVING_COLLECTOR)
+#if defined(__linux__) || defined (__APPLE__)
 #define MONO_ARCH_MONITOR_OBJECT_REG X86_EAX
 #endif
 #define MONO_ARCH_HAVE_STATIC_RGCTX_TRAMPOLINE 1
+#if !defined (__APPLE__) || defined(__native_client_codegen__)
+#define MONO_ARCH_HAVE_FULL_AOT_TRAMPOLINES 1
+#endif
+#define MONO_ARCH_GOT_REG X86_EBX
+#define MONO_ARCH_HAVE_GET_TRAMPOLINES 1
 
 #define MONO_ARCH_HAVE_CMOV_OPS 1
 
@@ -258,18 +236,30 @@ typedef struct {
 
 #define MONO_ARCH_HAVE_DECOMPOSE_LONG_OPTS 1
 
-#if !defined(__APPLE__)
 #define MONO_ARCH_AOT_SUPPORTED 1
-#endif
 
-#if defined(__linux__) || defined(__sun)
 #define MONO_ARCH_ENABLE_MONITOR_IL_FASTPATH 1
-#endif
 
 #define MONO_ARCH_GSHARED_SUPPORTED 1
 #define MONO_ARCH_HAVE_LLVM_IMT_TRAMPOLINE 1
+#define MONO_ARCH_LLVM_SUPPORTED 1
+#define MONO_ARCH_THIS_AS_FIRST_ARG 1
+
+#if defined(MONO_ARCH_USE_SIGACTION) || defined(TARGET_WIN32)
 #define MONO_ARCH_SOFT_DEBUG_SUPPORTED 1
-#define MONO_ARCH_HAVE_FIND_JIT_INFO_EXT 1
+#endif
+
+#define MONO_ARCH_HAVE_EXCEPTIONS_INIT 1
+#define MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD 1
+
+#define MONO_ARCH_HAVE_CARD_TABLE_WBARRIER 1
+#define MONO_ARCH_HAVE_SETUP_RESUME_FROM_SIGNAL_HANDLER_CTX 1
+#define MONO_ARCH_GC_MAPS_SUPPORTED 1
+
+gboolean
+mono_x86_tail_call_supported (MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig) MONO_INTERNAL;
+
+#define MONO_ARCH_USE_OP_TAIL_CALL(caller_sig, callee_sig) mono_x86_tail_call_supported (caller_sig, callee_sig)
 
 /* Used for optimization, not complete */
 #define MONO_ARCH_IS_OP_MEMBASE(opcode) ((opcode) == OP_X86_PUSH_MEMBASE)
@@ -294,5 +284,22 @@ extern MonoBreakpointInfo mono_breakpoint_info [MONO_BREAKPOINT_ARRAY_SIZE];
 guint8*
 mono_x86_emit_tls_get (guint8* code, int dreg, int tls_offset) MONO_INTERNAL;
 
+guint32
+mono_x86_get_this_arg_offset (MonoGenericSharingContext *gsctx, MonoMethodSignature *sig) MONO_INTERNAL;
+
+gboolean
+mono_x86_have_tls_get (void) MONO_INTERNAL;
+
+void
+mono_x86_throw_exception (mgreg_t *regs, MonoObject *exc, 
+                                                 mgreg_t eip, gboolean rethrow) MONO_INTERNAL;
+
+void
+mono_x86_throw_corlib_exception (mgreg_t *regs, guint32 ex_token_index, 
+                                                                mgreg_t eip, gint32 pc_offset) MONO_INTERNAL;
+
+void 
+mono_x86_patch (unsigned char* code, gpointer target) MONO_INTERNAL;
+
 #endif /* __MONO_MINI_X86_H__ */