X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Fx86-bsd-os.c;h=fe7556691f58f492323a6a57e8f44bad11f10103;hb=c8617f57d0413beb2890e94dabe227cef9c5ddad;hp=c44c7db4af7eb75538f1558cb1ea2029146bf7ef;hpb=26e8f33d8639e4de75e59e3aa30bbd7478d51a69;p=sbcl.git diff --git a/src/runtime/x86-bsd-os.c b/src/runtime/x86-bsd-os.c index c44c7db..fe75566 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 @@ -147,11 +157,24 @@ void set_data_desc_addr(struct segment_descriptor* desc, void* addr) #endif +#ifdef LISP_FEATURE_SB_THREAD +void +arch_os_load_ldt(struct thread *thread) +{ + int sel = LSEL(thread->tls_cookie, SEL_UPL); + unsigned int fs = rfs(); + + /* Load FS only if it's necessary. Modifying a selector + * causes privilege checking and it takes long time. */ + if (fs != sel) + load_fs(sel); +} +#endif + int arch_os_thread_init(struct thread *thread) { #ifdef LISP_FEATURE_SB_THREAD int n; - int sel; struct segment_descriptor ldt_entry = { 0, 0, SDT_MEMRW, SEL_UPL, 1, 0, 0, 1, 0, 0 }; @@ -165,10 +188,9 @@ int arch_os_thread_init(struct thread *thread) { lose("unexpected i386_set_ldt(..) failure\n"); } FSHOW_SIGNAL((stderr, "/ TLS: Allocated LDT %x\n", n)); - sel = LSEL(n, SEL_UPL); - load_fs(sel); - thread->tls_cookie=n; + arch_os_load_ldt(thread); + #ifdef LISP_FEATURE_GCC_TLS current_thread = thread; #else @@ -176,6 +198,10 @@ int arch_os_thread_init(struct thread *thread) { #endif #endif +#ifdef LISP_FEATURE_SB_SAFEPOINT + thread->selfptr = thread; +#endif + #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK stack_t sigstack; @@ -237,3 +263,22 @@ os_restore_fp_control(os_context_t *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