X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Futils%2Fmono-context.h;h=bac2fb331a1633ee4e143999f7b101870529e748;hb=161c807083bf5d889079a64604a176073eea8e1f;hp=3a6f44636c88a90af290d063274291f3fb432cd0;hpb=6025544e01621474c7c7e1acb08bcfa66704e8db;p=mono.git diff --git a/mono/utils/mono-context.h b/mono/utils/mono-context.h index 3a6f44636c8..bac2fb331a1 100644 --- a/mono/utils/mono-context.h +++ b/mono/utils/mono-context.h @@ -1,5 +1,6 @@ -/* - * mono-context.h: plat independent machine state definitions +/** + * \file + * plat independent machine state definitions * * * Copyright (c) 2011 Novell, Inc (http://www.novell.com) @@ -21,8 +22,16 @@ #define MONO_CONTEXT_OFFSET(field, index, field_type) \ "i" (offsetof (MonoContext, field) + (index) * sizeof (field_type)) +#if defined(TARGET_X86) +#if defined(__APPLE__) +typedef struct __darwin_xmm_reg MonoContextSimdReg; +#endif +#elif defined(TARGET_AMD64) #if defined(__APPLE__) typedef struct __darwin_xmm_reg MonoContextSimdReg; +#elif defined(__linux__) +typedef struct _libc_xmmreg MonoContextSimdReg; +#endif #endif /* @@ -33,7 +42,25 @@ typedef struct __darwin_xmm_reg MonoContextSimdReg; * MONO_CONTEXT_GET_CURRENT captures the current context as close as possible. One reg might be clobbered * to hold the address of the target MonoContext. It will be a caller save one, so should not be a problem. */ -#if (defined(__i386__) && !defined(MONO_CROSS_COMPILE)) || (defined(TARGET_X86)) +#if defined (TARGET_WASM) + +typedef struct { + mgreg_t wasm_sp; + mgreg_t wasm_bp; + mgreg_t llvm_exc_reg; + mgreg_t wasm_ip; + mgreg_t wasm_pc; +} MonoContext; + +#define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->wasm_ip = (mgreg_t)(ip); } while (0); +#define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->wasm_bp = (mgreg_t)(bp); } while (0); +#define MONO_CONTEXT_SET_SP(ctx,sp) do { (ctx)->wasm_sp = (mgreg_t)(sp); } while (0); + +#define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->wasm_ip)) +#define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->wasm_bp)) +#define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->wasm_sp)) + +#elif (defined(__i386__) && !defined(MONO_CROSS_COMPILE)) || (defined(TARGET_X86)) /*HACK, move this to an eventual mono-signal.c*/ #if defined( __linux__) || defined(__sun) || defined(__APPLE__) || defined(__NetBSD__) || \ @@ -43,8 +70,11 @@ typedef struct __darwin_xmm_reg MonoContextSimdReg; #endif #endif -#if defined(__native_client__) -#undef MONO_SIGNAL_USE_UCONTEXT_T +#ifdef __HAIKU__ +/* sigcontext surrogate */ +struct sigcontext { + vregs regs; +}; #endif #ifdef HOST_WIN32 @@ -74,14 +104,14 @@ struct sigcontext { # define SC_ESI sc_esi #elif defined(__HAIKU__) # define SC_EAX regs.eax -# define SC_EBX regs._reserved_2[2] +# define SC_EBX regs.ebx # define SC_ECX regs.ecx # define SC_EDX regs.edx # define SC_EBP regs.ebp # define SC_EIP regs.eip # define SC_ESP regs.esp -# define SC_EDI regs._reserved_2[0] -# define SC_ESI regs._reserved_2[1] +# define SC_EDI regs.edi +# define SC_ESI regs.esi #else # define SC_EAX eax # define SC_EBX ebx @@ -185,7 +215,7 @@ typedef struct { [xmm4] MONO_CONTEXT_OFFSET (fregs, X86_XMM4, MonoContextSimdReg), \ [xmm5] MONO_CONTEXT_OFFSET (fregs, X86_XMM5, MonoContextSimdReg), \ [xmm6] MONO_CONTEXT_OFFSET (fregs, X86_XMM6, MonoContextSimdReg), \ - [xmm7] MONO_CONTEXT_OFFSET (fregs, X86_XMM7, MonoContextSimdReg), \ + [xmm7] MONO_CONTEXT_OFFSET (fregs, X86_XMM7, MonoContextSimdReg)); \ } while (0) #else #define MONO_CONTEXT_GET_CURRENT_FREGS(ctx) @@ -205,7 +235,7 @@ typedef struct { #include -#if !defined( HOST_WIN32 ) && !defined(__native_client__) && !defined(__native_client_codegen__) +#if !defined( HOST_WIN32 ) #if defined(HAVE_SIGACTION) || defined(__APPLE__) // the __APPLE__ check is required for the tvos simulator, which has ucontext_t but not sigaction #define MONO_SIGNAL_USE_UCONTEXT_T 1 @@ -215,7 +245,7 @@ typedef struct { typedef struct { mgreg_t gregs [AMD64_NREG]; -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__linux__) MonoContextSimdReg fregs [AMD64_XMM_NREG]; #else double fregs [AMD64_XMM_NREG]; @@ -235,30 +265,6 @@ typedef struct { extern void mono_context_get_current (void *); #define MONO_CONTEXT_GET_CURRENT(ctx) do { mono_context_get_current((void*)&(ctx)); } while (0) -#elif defined(__native_client__) -#define MONO_CONTEXT_GET_CURRENT(ctx) \ - __asm__ __volatile__( \ - "movq $0x0, %%nacl:0x00(%%r15, %0, 1)\n" \ - "movq %%rcx, %%nacl:0x08(%%r15, %0, 1)\n" \ - "movq %%rdx, %%nacl:0x10(%%r15, %0, 1)\n" \ - "movq %%rbx, %%nacl:0x18(%%r15, %0, 1)\n" \ - "movq %%rsp, %%nacl:0x20(%%r15, %0, 1)\n" \ - "movq %%rbp, %%nacl:0x28(%%r15, %0, 1)\n" \ - "movq %%rsi, %%nacl:0x30(%%r15, %0, 1)\n" \ - "movq %%rdi, %%nacl:0x38(%%r15, %0, 1)\n" \ - "movq %%r8, %%nacl:0x40(%%r15, %0, 1)\n" \ - "movq %%r9, %%nacl:0x48(%%r15, %0, 1)\n" \ - "movq %%r10, %%nacl:0x50(%%r15, %0, 1)\n" \ - "movq %%r11, %%nacl:0x58(%%r15, %0, 1)\n" \ - "movq %%r12, %%nacl:0x60(%%r15, %0, 1)\n" \ - "movq %%r13, %%nacl:0x68(%%r15, %0, 1)\n" \ - "movq %%r14, %%nacl:0x70(%%r15, %0, 1)\n" \ - "movq %%r15, %%nacl:0x78(%%r15, %0, 1)\n" \ - "leaq (%%rip), %%rdx\n" \ - "movq %%rdx, %%nacl:0x80(%%r15, %0, 1)\n" \ - : \ - : "a" ((int64_t)&(ctx)) \ - : "rdx", "memory") #else #define MONO_CONTEXT_GET_CURRENT_GREGS(ctx) \ @@ -763,89 +769,7 @@ typedef struct MonoContext { #define MONO_ARCH_HAS_MONO_CONTEXT 1 -#elif defined(__ia64__) /*defined(__sparc__) || defined(sparc) */ - -#ifndef UNW_LOCAL_ONLY - -#define UNW_LOCAL_ONLY -#include - -#endif - -typedef struct MonoContext { - unw_cursor_t cursor; - /* Whenever the ip in 'cursor' points to the ip where the exception happened */ - /* This is true for the initial context for exceptions thrown from signal handlers */ - gboolean precise_ip; -} MonoContext; - -/*XXX SET_BP is missing*/ -#define MONO_CONTEXT_SET_IP(ctx,eip) do { int err = unw_set_reg (&(ctx)->cursor, UNW_IA64_IP, (unw_word_t)(eip)); g_assert (err == 0); } while (0) -#define MONO_CONTEXT_SET_SP(ctx,esp) do { int err = unw_set_reg (&(ctx)->cursor, UNW_IA64_SP, (unw_word_t)(esp)); g_assert (err == 0); } while (0) - -#define MONO_CONTEXT_GET_IP(ctx) ((gpointer)(mono_ia64_context_get_ip ((ctx)))) -#define MONO_CONTEXT_GET_BP(ctx) ((gpointer)(mono_ia64_context_get_fp ((ctx)))) -#define MONO_CONTEXT_GET_SP(ctx) ((gpointer)(mono_ia64_context_get_sp ((ctx)))) - -static inline unw_word_t -mono_ia64_context_get_ip (MonoContext *ctx) -{ - unw_word_t ip; - int err; - - err = unw_get_reg (&ctx->cursor, UNW_IA64_IP, &ip); - g_assert (err == 0); - - if (ctx->precise_ip) { - return ip; - } else { - /* Subtrack 1 so ip points into the actual instruction */ - return ip - 1; - } -} - -static inline unw_word_t -mono_ia64_context_get_sp (MonoContext *ctx) -{ - unw_word_t sp; - int err; - - err = unw_get_reg (&ctx->cursor, UNW_IA64_SP, &sp); - g_assert (err == 0); - - return sp; -} - -static inline unw_word_t -mono_ia64_context_get_fp (MonoContext *ctx) -{ - unw_cursor_t new_cursor; - unw_word_t fp; - int err; - - { - unw_word_t ip, sp; - - err = unw_get_reg (&ctx->cursor, UNW_IA64_SP, &sp); - g_assert (err == 0); - - err = unw_get_reg (&ctx->cursor, UNW_IA64_IP, &ip); - g_assert (err == 0); - } - - /* fp is the SP of the parent frame */ - new_cursor = ctx->cursor; - - err = unw_step (&new_cursor); - g_assert (err >= 0); - - err = unw_get_reg (&new_cursor, UNW_IA64_SP, &fp); - g_assert (err == 0); - - return fp; -} - -#elif ((defined(__mips__) && !defined(MONO_CROSS_COMPILE)) || (defined(TARGET_MIPS))) && SIZEOF_REGISTER == 4 /* defined(__ia64__) */ +#elif ((defined(__mips__) && !defined(MONO_CROSS_COMPILE)) || (defined(TARGET_MIPS))) && SIZEOF_REGISTER == 4 #define MONO_ARCH_HAS_MONO_CONTEXT 1