X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fmini-x86.h;h=bfd8d282a7fc786c3d9d8c00ebe22f5ce5961195;hb=4bd1f7ba7252579e97d480e3008b3a3f9fc52817;hp=579c9144e6b555df36c72e996823f8bec7a696e6;hpb=c55e9a08204be58437a8d0c01c4ed67508b84a0d;p=mono.git diff --git a/mono/mini/mini-x86.h b/mono/mini/mini-x86.h index 579c9144e6b..bfd8d282a7f 100644 --- a/mono/mini/mini-x86.h +++ b/mono/mini/mini-x86.h @@ -2,7 +2,8 @@ #define __MONO_MINI_X86_H__ #include -#ifdef PLATFORM_WIN32 +#include +#ifdef HOST_WIN32 #include /* use SIG* defines if possible */ #ifdef HAVE_SIGNAL_H @@ -22,7 +23,7 @@ struct sigcontext { unsigned int eip; }; -typedef void (* MonoW32ExceptionHandler) (int); +typedef void (* MonoW32ExceptionHandler) (int _dummy, EXCEPTION_RECORD *info, void *context); void win32_seh_init(void); void win32_seh_cleanup(void); void win32_seh_set_handler(int type, MonoW32ExceptionHandler handler); @@ -41,13 +42,13 @@ 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__) +#if defined( __linux__) || defined(__sun) || defined(__APPLE__) || defined(__NetBSD__) || defined(__FreeBSD__) #define MONO_ARCH_USE_SIGACTION #endif -#ifndef PLATFORM_WIN32 +#ifndef HOST_WIN32 #ifdef HAVE_WORKING_SIGALTSTACK /* @@ -60,26 +61,37 @@ LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep); #define MONO_ARCH_USE_SIGACTION #endif /* HAVE_WORKING_SIGALTSTACK */ -#endif /* !PLATFORM_WIN32 */ +#endif /* !HOST_WIN32 */ + +#define MONO_ARCH_SUPPORT_SIMD_INTRINSICS 1 +#define MONO_ARCH_SUPPORT_TASKLETS 1 + +#ifndef DISABLE_SIMD +#define MONO_ARCH_SIMD_INTRINSICS 1 +#define MONO_ARCH_NEED_SIMD_BANK 1 +#endif /* we should lower this size and make sure we don't call heavy stack users in the segv handler */ #define MONO_ARCH_SIGNAL_STACK_SIZE (16 * 1024) - -/* 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 +#define MONO_ARCH_HAVE_RESTORE_STACK_SUPPORT 1 #define MONO_ARCH_CPU_SPEC x86_desc #define MONO_MAX_IREGS 8 -#define MONO_MAX_FREGS 6 +#define MONO_MAX_FREGS 8 +#define MONO_MAX_XREGS 8 /* Parameters used by the register allocator */ #define MONO_ARCH_CALLEE_REGS X86_CALLEE_REGS #define MONO_ARCH_CALLEE_SAVED_REGS X86_CALLER_REGS -#define MONO_ARCH_CALLEE_FREGS 0 +#define MONO_ARCH_CALLEE_FREGS (0xff & ~(regmask (MONO_ARCH_FPSTACK_SIZE))) #define MONO_ARCH_CALLEE_SAVED_FREGS 0 +/* All registers are clobered by a call */ +#define MONO_ARCH_CALLEE_XREGS (0xff & ~(regmask (MONO_MAX_XREGS))) +#define MONO_ARCH_CALLEE_SAVED_XREGS 0 + #define MONO_ARCH_USE_FPSTACK TRUE #define MONO_ARCH_FPSTACK_SIZE 6 @@ -88,7 +100,12 @@ LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep); #define MONO_ARCH_INST_FIXED_MASK(desc) ((desc == 'y') ? (X86_BYTE_REGS) : 0) /* RDX is clobbered by the opcode implementation before accessing sreg2 */ -#define MONO_ARCH_INST_SREG2_MASK(ins) (((ins [MONO_INST_CLOB] == 'a') || (ins [MONO_INST_CLOB] == 'd')) ? (1 << X86_EDX) : 0) +/* + * Originally this contained X86_EDX for div/rem opcodes, but that led to unsolvable + * situations since there are only 3 usable registers for local register allocation. + * Instead, we handle the sreg2==edx case in the opcodes. + */ +#define MONO_ARCH_INST_SREG2_MASK(ins) 0 /* * L is a generic register pair, while l means eax:rdx @@ -96,33 +113,25 @@ LONG CALLBACK seh_handler(EXCEPTION_POINTERS* ep); #define MONO_ARCH_INST_IS_REGPAIR(desc) (desc == 'l' || desc == 'L') #define MONO_ARCH_INST_REGPAIR_REG2(desc,hreg1) (desc == 'l' ? X86_EDX : -1) -#if defined(__APPLE__) +/* must be at a power of 2 and >= 8 */ #define MONO_ARCH_FRAME_ALIGNMENT 16 -#else -#define MONO_ARCH_FRAME_ALIGNMENT 4 -#endif /* fixme: align to 16byte instead of 32byte (we align to 32byte to get * reproduceable results for benchmarks */ #define MONO_ARCH_CODE_ALIGNMENT 32 -#define MONO_ARCH_BASEREG X86_EBP #define MONO_ARCH_RETREG1 X86_EAX #define MONO_ARCH_RETREG2 X86_EDX -#define MONO_ARCH_AOT_PLT_OFFSET_REG X86_EAX - -#define MONO_ARCH_ENCODE_LREG(r1,r2) (r1 | (r2<<3)) - -#define inst_dreg_low dreg&7 -#define inst_dreg_high dreg>>3 -#define inst_sreg1_low sreg1&7 -#define inst_sreg1_high sreg1>>3 -#define inst_sreg2_low sreg2&7 -#define inst_sreg2_high sreg2>>3 +/*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 struct MonoLMF { - /* Offset by 1 if this is a trampoline LMF frame */ + /* + * If the lowest bit is set to 1, then this is a trampoline LMF frame. + * If the second lowest bit is set to 1, then this is a MonoLMFExt structure, and + * the other fields are not valid. + */ guint32 previous_lmf; gpointer lmf_addr; /* Only set in trampoline LMF frames */ @@ -136,53 +145,10 @@ struct MonoLMF { guint32 eip; }; -typedef void* MonoCompileArch; - -#if defined(__FreeBSD__) || defined(__APPLE__) -#include -#endif - -#if defined(__FreeBSD__) - #define UCONTEXT_REG_EAX(ctx) ((ctx)->uc_mcontext.mc_eax) - #define UCONTEXT_REG_EBX(ctx) ((ctx)->uc_mcontext.mc_ebx) - #define UCONTEXT_REG_ECX(ctx) ((ctx)->uc_mcontext.mc_ecx) - #define UCONTEXT_REG_EDX(ctx) ((ctx)->uc_mcontext.mc_edx) - #define UCONTEXT_REG_EBP(ctx) ((ctx)->uc_mcontext.mc_ebp) - #define UCONTEXT_REG_ESP(ctx) ((ctx)->uc_mcontext.mc_esp) - #define UCONTEXT_REG_ESI(ctx) ((ctx)->uc_mcontext.mc_esi) - #define UCONTEXT_REG_EDI(ctx) ((ctx)->uc_mcontext.mc_edi) - #define UCONTEXT_REG_EIP(ctx) ((ctx)->uc_mcontext.mc_eip) -#elif defined(__APPLE__) - #define UCONTEXT_REG_EAX(ctx) ((ctx)->uc_mcontext->ss.eax) - #define UCONTEXT_REG_EBX(ctx) ((ctx)->uc_mcontext->ss.ebx) - #define UCONTEXT_REG_ECX(ctx) ((ctx)->uc_mcontext->ss.ecx) - #define UCONTEXT_REG_EDX(ctx) ((ctx)->uc_mcontext->ss.edx) - #define UCONTEXT_REG_EBP(ctx) ((ctx)->uc_mcontext->ss.ebp) - #define UCONTEXT_REG_ESP(ctx) ((ctx)->uc_mcontext->ss.esp) - #define UCONTEXT_REG_ESI(ctx) ((ctx)->uc_mcontext->ss.esi) - #define UCONTEXT_REG_EDI(ctx) ((ctx)->uc_mcontext->ss.edi) - #define UCONTEXT_REG_EIP(ctx) ((ctx)->uc_mcontext->ss.eip) -#elif defined(__NetBSD__) - #define UCONTEXT_REG_EAX(ctx) ((ctx)->uc_mcontext.__gregs [_REG_EAX]) - #define UCONTEXT_REG_EBX(ctx) ((ctx)->uc_mcontext.__gregs [_REG_EBX]) - #define UCONTEXT_REG_ECX(ctx) ((ctx)->uc_mcontext.__gregs [_REG_ECX]) - #define UCONTEXT_REG_EDX(ctx) ((ctx)->uc_mcontext.__gregs [_REG_EDX]) - #define UCONTEXT_REG_EBP(ctx) ((ctx)->uc_mcontext.__gregs [_REG_EBP]) - #define UCONTEXT_REG_ESP(ctx) ((ctx)->uc_mcontext.__gregs [_REG_ESP]) - #define UCONTEXT_REG_ESI(ctx) ((ctx)->uc_mcontext.__gregs [_REG_ESI]) - #define UCONTEXT_REG_EDI(ctx) ((ctx)->uc_mcontext.__gregs [_REG_EDI]) - #define UCONTEXT_REG_EIP(ctx) ((ctx)->uc_mcontext.__gregs [_REG_EIP]) -#else - #define UCONTEXT_REG_EAX(ctx) ((ctx)->uc_mcontext.gregs [REG_EAX]) - #define UCONTEXT_REG_EBX(ctx) ((ctx)->uc_mcontext.gregs [REG_EBX]) - #define UCONTEXT_REG_ECX(ctx) ((ctx)->uc_mcontext.gregs [REG_ECX]) - #define UCONTEXT_REG_EDX(ctx) ((ctx)->uc_mcontext.gregs [REG_EDX]) - #define UCONTEXT_REG_EBP(ctx) ((ctx)->uc_mcontext.gregs [REG_EBP]) - #define UCONTEXT_REG_ESP(ctx) ((ctx)->uc_mcontext.gregs [REG_ESP]) - #define UCONTEXT_REG_ESI(ctx) ((ctx)->uc_mcontext.gregs [REG_ESI]) - #define UCONTEXT_REG_EDI(ctx) ((ctx)->uc_mcontext.gregs [REG_EDI]) - #define UCONTEXT_REG_EIP(ctx) ((ctx)->uc_mcontext.gregs [REG_EIP]) -#endif +typedef struct { + gboolean need_stack_frame_inited; + gboolean need_stack_frame; +} MonoCompileArch; #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) # define SC_EAX sc_eax @@ -226,6 +192,8 @@ typedef struct { #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 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx, start_func) do { \ @@ -250,23 +218,91 @@ 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; + +/* 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 + #define MONO_ARCH_BIGMUL_INTRINS 1 #define MONO_ARCH_NEED_DIV_CHECK 1 #define MONO_ARCH_HAVE_IS_INT_OVERFLOW 1 #define MONO_ARCH_HAVE_INVALIDATE_METHOD 1 -#define MONO_ARCH_HAVE_PIC_AOT 1 #define MONO_ARCH_NEED_GOT_VAR 1 #define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION 1 -#define MONO_ARCH_ENABLE_EMIT_STATE_OPT 1 #define MONO_ARCH_ENABLE_MONO_LMF_VAR 1 -#define MONO_ARCH_HAVE_CREATE_TRAMPOLINE_FROM_TOKEN 1 -#define MONO_ARCH_HAVE_CREATE_SPECIFIC_TRAMPOLINE 1 #define MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE 1 -#define MONO_ARCH_HAVE_CREATE_VARS 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_IMT_REG X86_EDX +#define MONO_ARCH_VTABLE_REG X86_EDX +#define MONO_ARCH_RGCTX_REG X86_EDX +#define MONO_ARCH_HAVE_GENERALIZED_IMT_THUNK 1 +#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) +#define MONO_ARCH_MONITOR_OBJECT_REG X86_EAX +#endif +#define MONO_ARCH_HAVE_STATIC_RGCTX_TRAMPOLINE 1 +#define MONO_ARCH_HAVE_CMOV_OPS 1 + +#ifdef MONO_ARCH_SIMD_INTRINSICS +#define MONO_ARCH_HAVE_DECOMPOSE_OPTS 1 +#endif + +#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_SOFT_DEBUG_SUPPORTED 1 +#define MONO_ARCH_HAVE_FIND_JIT_INFO_EXT 1 +#define MONO_ARCH_HAVE_EXCEPTIONS_INIT 1 + +/* Used for optimization, not complete */ +#define MONO_ARCH_IS_OP_MEMBASE(opcode) ((opcode) == OP_X86_PUSH_MEMBASE) + +#define MONO_ARCH_EMIT_BOUNDS_CHECK(cfg, array_reg, offset, index_reg) do { \ + MonoInst *inst; \ + MONO_INST_NEW ((cfg), inst, OP_X86_COMPARE_MEMBASE_REG); \ + inst->inst_basereg = array_reg; \ + inst->inst_offset = offset; \ + inst->sreg2 = index_reg; \ + MONO_ADD_INS ((cfg)->cbb, inst); \ + MONO_EMIT_NEW_COND_EXC (cfg, LE_UN, "IndexOutOfRangeException"); \ + } while (0) + +typedef struct { + guint8 *address; + guint8 saved_byte; +} MonoBreakpointInfo; + +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; #endif /* __MONO_MINI_X86_H__ */