X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Fx86-bsd-os.c;h=8b62584e361607ca4a56f4ac44b6941b1547bf0f;hb=3a340441c36832861f53fc16478607ea8ab5cb2e;hp=490c7cf3b571a5f8541ee9445c396306ebf14926;hpb=402958f92506b9d3de852601b8c1ccb99b5ee558;p=sbcl.git diff --git a/src/runtime/x86-bsd-os.c b/src/runtime/x86-bsd-os.c index 490c7cf..8b62584 100644 --- a/src/runtime/x86-bsd-os.c +++ b/src/runtime/x86-bsd-os.c @@ -1,4 +1,5 @@ #include +#include #include "sbcl.h" #include "runtime.h" #include "thread.h" @@ -19,6 +20,15 @@ #include "machine/npx.h" #endif +#if defined(LISP_FEATURE_OPENBSD) +#include +#include +#include "openbsd-sigcontext.h" +#ifdef OS_OPENBSD_FPSTATE_IN_SIGFRAME +# include +#endif +#endif + /* KLUDGE: There is strong family resemblance in the signal context * stuff in FreeBSD and OpenBSD, but in detail they're different in * almost every line of code. It would be nice to find some way to @@ -36,21 +46,21 @@ os_context_register_addr(os_context_t *context, int offset) { switch(offset) { case 0: - return CONTEXT_ADDR_FROM_STEM(eax); + return (int *)CONTEXT_ADDR_FROM_STEM(eax); case 2: - return CONTEXT_ADDR_FROM_STEM(ecx); + return (int *)CONTEXT_ADDR_FROM_STEM(ecx); case 4: - return CONTEXT_ADDR_FROM_STEM(edx); + return (int *)CONTEXT_ADDR_FROM_STEM(edx); case 6: - return CONTEXT_ADDR_FROM_STEM(ebx); + return (int *)CONTEXT_ADDR_FROM_STEM(ebx); case 8: - return CONTEXT_ADDR_FROM_STEM(esp); + return (int *)CONTEXT_ADDR_FROM_STEM(esp); case 10: - return CONTEXT_ADDR_FROM_STEM(ebp); + return (int *)CONTEXT_ADDR_FROM_STEM(ebp); case 12: - return CONTEXT_ADDR_FROM_STEM(esi); + return (int *)CONTEXT_ADDR_FROM_STEM(esi); case 14: - return CONTEXT_ADDR_FROM_STEM(edi); + return (int *)CONTEXT_ADDR_FROM_STEM(edi); default: return 0; } @@ -59,7 +69,7 @@ os_context_register_addr(os_context_t *context, int offset) int * os_context_sp_addr(os_context_t *context) { - return CONTEXT_ADDR_FROM_STEM(esp); + return (int *)CONTEXT_ADDR_FROM_STEM(esp); } #endif /* __FreeBSD__ || __OpenBSD__ */ @@ -100,6 +110,22 @@ os_context_sp_addr(os_context_t *context) #endif /* __NetBSD__ */ +int *os_context_pc_addr(os_context_t *context) +{ +#if defined __FreeBSD__ + return CONTEXT_ADDR_FROM_STEM(eip); +#elif defined __OpenBSD__ + return CONTEXT_ADDR_FROM_STEM(pc); +#elif defined __NetBSD__ + return CONTEXT_ADDR_FROM_STEM(EIP); +#elif defined(LISP_FEATURE_DARWIN) && defined(LISP_FEATURE_X86) + return (int *)CONTEXT_ADDR_FROM_STEM(eip); +#elif defined LISP_FEATURE_DARWIN + return &context->uc_mcontext->ss.srr0; +#else +#error unsupported BSD variant +#endif +} /* FIXME: If this can be a no-op on BSD/x86, then it * deserves a more precise name. @@ -140,7 +166,7 @@ int arch_os_thread_init(struct thread *thread) { struct segment_descriptor ldt_entry = { 0, 0, SDT_MEMRW, SEL_UPL, 1, 0, 0, 1, 0, 0 }; - set_data_desc_addr(&ldt_entry, (unsigned long) thread); + set_data_desc_addr(&ldt_entry, thread); set_data_desc_size(&ldt_entry, dynamic_values_bytes); n = i386_set_ldt(LDT_AUTO_ALLOC, (union descriptor*) &ldt_entry, 1); @@ -150,11 +176,19 @@ int arch_os_thread_init(struct thread *thread) { } FSHOW_SIGNAL((stderr, "/ TLS: Allocated LDT %x\n", n)); sel = LSEL(n, SEL_UPL); - __asm__ __volatile__ ("mov %0, %%fs" : : "r"(sel)); + load_fs(sel); thread->tls_cookie=n; +#ifdef LISP_FEATURE_GCC_TLS + current_thread = thread; +#else pthread_setspecific(specials,thread); #endif +#endif + +#ifdef LISP_FEATURE_SB_SAFEPOINT + thread->selfptr = thread; +#endif #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK stack_t sigstack; @@ -176,8 +210,8 @@ int arch_os_thread_cleanup(struct thread *thread) { #if defined(LISP_FEATURE_SB_THREAD) int n = thread->tls_cookie; - /* Set the %%fs register back to 0 and free the the ldt - * by setting it to NULL. + /* Set the %%fs register back to 0 and free the ldt by setting it + * to NULL. */ FSHOW_SIGNAL((stderr, "/ TLS: Freeing LDT %x\n", n)); @@ -191,10 +225,48 @@ int arch_os_thread_cleanup(struct thread *thread) { #endif /* !LISP_FEATURE_DARWIN */ #if defined(LISP_FEATURE_FREEBSD) +#if defined(LISP_FEATURE_RESTORE_TLS_SEGMENT_REGISTER_FROM_CONTEXT) +void +os_restore_tls_segment_register(os_context_t *context) +{ + load_fs(context->uc_mcontext.mc_fs); +} +#endif + void os_restore_fp_control(os_context_t *context) { - struct envxmm *ex = (struct envxmm*)(&context->uc_mcontext.mc_fpstate); - asm ("fldcw %0" : : "m" (ex->en_cw)); + /* FPU state is saved per context on post-KSE systems. + * On earlier systems, it is shared in a whole process. + */ +#if defined(__FreeBSD_version) && __FreeBSD_version >= 500040 + struct envxmm *ex = (struct envxmm *)(context->uc_mcontext.mc_fpstate); + __asm__ __volatile__ ("fldcw %0" : : "m" (ex->en_cw)); +#endif +#if defined(LISP_FEATURE_RESTORE_TLS_SEGMENT_REGISTER_FROM_CONTEXT) + /* Calling this function here may not be good idea. Or rename + * function name os_restore_fp_control to os_restore_context or + * so, to match the behavior? */ + os_restore_tls_segment_register(context); +#endif +} +#endif + +#if defined(LISP_FEATURE_OPENBSD) +void +os_restore_fp_control(os_context_t *context) +{ +#ifdef OS_OPENBSD_FPSTATE_IN_SIGFRAME + struct sigframe *frame = (struct sigframe *)((char*)context - + offsetof(struct sigframe, sf_sc)); + union savefpu *fpu = frame->sf_fpstate; +#elif defined(OS_OPENBSD_FPSTATE_IN_SIGCONTEXT) + union savefpu *fpu = context->sc_fpstate; +#endif + + if (openbsd_use_fxsave) + __asm__ __volatile__ ("fldcw %0" : : "m" (fpu->sv_xmm.sv_env.en_cw)); + else + __asm__ __volatile__ ("fldcw %0" : : "m" (fpu->sv_87.sv_env.en_cw)); } #endif