diff --git a/TODO b/TODO index 6c8d83b..d60252c 100644 --- a/TODO +++ b/TODO @@ -104,6 +104,9 @@ DARWIN Needs love, particularly threads and exceptions/signals. slam.sh is also broken there. +DRAGONFLY + Fix multithreading support on x86-64, add it on x86. + FUNCTION NAMES We'd like to be able to (SETF %FUNCTION-NAME) on a closure. diff --git a/base-target-features.lisp-expr b/base-target-features.lisp-expr index 74bf083..c262c1c 100644 --- a/base-target-features.lisp-expr +++ b/base-target-features.lisp-expr @@ -434,23 +434,24 @@ ;; implemented for this platform. ;; ;; operating system features: - ;; :unix = We're intended to run under some Unix-like OS. (This is not - ;; exclusive with the features which indicate which particular - ;; Unix-like OS we're intended to run under.) - ;; :linux = We're intended to run under some version of Linux. - ;; :bsd = We're intended to run under some version of BSD Unix. (This - ;; is not exclusive with the features which indicate which - ;; particular version of BSD we're intended to run under.) - ;; :freebsd = We're intended to run under FreeBSD. - ;; :openbsd = We're intended to run under OpenBSD. - ;; :netbsd = We're intended to run under NetBSD. - ;; :darwin = We're intended to run under Darwin (including MacOS X). - ;; :sunos = We're intended to run under Solaris user environment - ;; with the SunOS kernel. - ;; :hpux = We're intended to run under HP-UX 11.11 or later - ;; :osf1 = We're intended to run under Tru64 (aka Digital Unix - ;; aka OSF/1). - ;; :win32 = We're intended to under some version of Microsoft Windows. + ;; :unix = We're intended to run under some Unix-like OS. (This is not + ;; exclusive with the features which indicate which particular + ;; Unix-like OS we're intended to run under.) + ;; :linux = We're intended to run under some version of Linux. + ;; :bsd = We're intended to run under some version of BSD Unix. (This + ;; is not exclusive with the features which indicate which + ;; particular version of BSD we're intended to run under.) + ;; :freebsd = We're intended to run under FreeBSD. + ;; :openbsd = We're intended to run under OpenBSD. + ;; :netbsd = We're intended to run under NetBSD. + ;; :dragonfly = We're intended to run under DragonFly. + ;; :darwin = We're intended to run under Darwin (including MacOS X). + ;; :sunos = We're intended to run under Solaris user environment + ;; with the SunOS kernel. + ;; :hpux = We're intended to run under HP-UX 11.11 or later + ;; :osf1 = We're intended to run under Tru64 (aka Digital Unix + ;; aka OSF/1). + ;; :win32 = We're intended to under some version of Microsoft Windows. ;; (No others are supported by SBCL as of 1.0.8, but :hpux or :irix ;; support could be ported from CMU CL if anyone is sufficiently ;; motivated to do so.) diff --git a/contrib/asdf/asdf.lisp b/contrib/asdf/asdf.lisp index ce7a1db..6274595 100644 --- a/contrib/asdf/asdf.lisp +++ b/contrib/asdf/asdf.lisp @@ -3237,7 +3237,7 @@ located." '(:cygwin (:win :windows :mswindows :win32 :mingw32) ;; try cygwin first! (:linux :linux :linux-target) ;; for GCL at least, must appear before :bsd (:macosx :macosx :darwin :darwin-target :apple) ; also before :bsd - (:solaris :solaris :sunos) (:bsd :bsd :freebsd :netbsd :openbsd) :unix + (:solaris :solaris :sunos) (:bsd :bsd :freebsd :dragonfly :netbsd :openbsd) :unix :genera))) (defun architecture () diff --git a/contrib/sb-bsd-sockets/constants.lisp b/contrib/sb-bsd-sockets/constants.lisp index eeabd11..b874b17 100644 --- a/contrib/sb-bsd-sockets/constants.lisp +++ b/contrib/sb-bsd-sockets/constants.lisp @@ -316,7 +316,7 @@ (:integer EAI-BADFLAGS "EAI_BADFLAGS") (:integer EAI-NONAME "EAI_NONAME") (:integer EAI-SERVICE "EAI_SERVICE") - #-freebsd + #-(or freebsd dragonfly) (:integer EAI-ADDRFAMILY "EAI_ADDRFAMILY") (:integer EAI-MEMORY "EAI_MEMORY") (:integer EAI-FAIL "EAI_FAIL") diff --git a/contrib/sb-bsd-sockets/tests.lisp b/contrib/sb-bsd-sockets/tests.lisp index 776878c..f9e8c1b 100644 --- a/contrib/sb-bsd-sockets/tests.lisp +++ b/contrib/sb-bsd-sockets/tests.lisp @@ -30,6 +30,7 @@ ;;; Apparently getprotobyname_r on FreeBSD says -1 and EINTR ;;; for unknown protocols... #-(and freebsd sb-thread) +#-(and dragonfly sb-thread) (deftest get-protocol-by-name/error (handler-case (get-protocol-by-name "nonexistent-protocol") (unknown-protocol () diff --git a/make-config.sh b/make-config.sh index 6b720e0..04a2dda 100644 --- a/make-config.sh +++ b/make-config.sh @@ -277,6 +277,9 @@ case `uname` in ;; esac ;; + DragonFly) + sbcl_os="dragonfly" + ;; Darwin) sbcl_os="darwin" ;; @@ -385,7 +388,8 @@ then # If --fancy, enable threads on platforms where they can be built. case $sbcl_arch in x86|x86-64|ppc) - if [ "$sbcl_os" = "sunos" ] && [ "$sbcl_arch" = "x86-64" ] + if ([ "$sbcl_os" = "sunos" ] && [ "$sbcl_arch" = "x86-64" ]) || \ + ([ "$sbcl_os" = "dragonfly" ] && [ "$sbcl_arch" = "x86" ]) then echo "No threads on this platform." else @@ -502,6 +506,16 @@ case "$sbcl_os" in ;; esac ;; + dragonfly) + printf ' :unix' >> $ltf + printf ' :bsd' >> $ltf + printf ' :elf' >> $ltf + printf ' :dragonfly' >> $ltf + printf ' :sb-qshow' >> $ltf + link_or_copy $sbcl_arch-bsd-os.h target-arch-os.h + link_or_copy bsd-os.h target-os.h + link_or_copy Config.$sbcl_arch-dragonfly Config + ;; darwin) printf ' :unix' >> $ltf printf ' :mach-o' >> $ltf @@ -587,7 +601,7 @@ if [ "$sbcl_arch" = "x86" ]; then printf ' :alien-callbacks :cycle-counter :inline-constants ' >> $ltf printf ' :memory-barrier-vops :multiply-high-vops' >> $ltf case "$sbcl_os" in - linux | freebsd | netbsd | openbsd | sunos | darwin | win32) + linux | freebsd | netbsd | openbsd | sunos | darwin | win32 | dragonfly) printf ' :linkage-table' >> $ltf esac if [ "$sbcl_os" = "win32" ]; then diff --git a/src/code/unix.lisp b/src/code/unix.lisp index 9572a22..de330ae 100644 --- a/src/code/unix.lisp +++ b/src/code/unix.lisp @@ -414,14 +414,14 @@ corresponds to NAME, or NIL if there is none." ;; comma not inside a backquote. This error has absolutely nothing ;; to do with the actual meaning of the error (and little to do with ;; its location, either). - #!-(or linux openbsd freebsd netbsd sunos osf1 darwin hpux win32) (,stub,) - #!+(or linux openbsd freebsd netbsd sunos osf1 darwin hpux win32) + #!-(or linux openbsd freebsd netbsd sunos osf1 darwin hpux win32 dragonfly) (,stub,) + #!+(or linux openbsd freebsd netbsd sunos osf1 darwin hpux win32 dragonfly) (or (newcharstar-string (alien-funcall (extern-alien "getcwd" (function (* char) (* char) size-t)) nil - #!+(or linux openbsd freebsd netbsd darwin win32) 0 + #!+(or linux openbsd freebsd netbsd dragonfly darwin win32) 0 #!+(or sunos osf1 hpux) 1025)) (simple-perror "getcwd"))) diff --git a/src/compiler/x86/parms.lisp b/src/compiler/x86/parms.lisp index 5502afd..163ffd7 100644 --- a/src/compiler/x86/parms.lisp +++ b/src/compiler/x86/parms.lisp @@ -187,13 +187,14 @@ ;;; NetBSD configuration used to have this comment regarding the linkage ;;; table: "In CMUCL: 0xB0000000->0xB1000000" -#!+win32 (!gencgc-space-setup #x22000000 nil nil #x10000) -#!+linux (!gencgc-space-setup #x01000000 #x09000000) -#!+sunos (!gencgc-space-setup #x20000000 #x48000000) -#!+freebsd (!gencgc-space-setup #x01000000 #x58000000) -#!+openbsd (!gencgc-space-setup #x1b000000 #x40000000) -#!+netbsd (!gencgc-space-setup #x20000000 #x60000000) -#!+darwin (!gencgc-space-setup #x04000000 #x10000000) +#!+win32 (!gencgc-space-setup #x22000000 nil nil #x10000) +#!+linux (!gencgc-space-setup #x01000000 #x09000000) +#!+sunos (!gencgc-space-setup #x20000000 #x48000000) +#!+freebsd (!gencgc-space-setup #x01000000 #x58000000) +#!+dragonfly (!gencgc-space-setup #x01000000 #x58000000) +#!+openbsd (!gencgc-space-setup #x1b000000 #x40000000) +#!+netbsd (!gencgc-space-setup #x20000000 #x60000000) +#!+darwin (!gencgc-space-setup #x04000000 #x10000000) ;;; Size of one linkage-table entry in bytes. (def!constant linkage-table-entry-size 8) diff --git a/src/runtime/Config.x86-64-dragonfly b/src/runtime/Config.x86-64-dragonfly new file mode 100644 index 0000000..f00b739 --- /dev/null +++ b/src/runtime/Config.x86-64-dragonfly @@ -0,0 +1,26 @@ +# -*- makefile -*- for the C-level run-time support for SBCL + +# This software is part of the SBCL system. See the README file for +# more information. +# +# This software is derived from the CMU CL system, which was +# written at Carnegie Mellon University and released into the +# public domain. The software is in the public domain and is +# provided with absolutely no warranty. See the COPYING and CREDITS +# files for more information. + +include Config.x86-64-bsd + +ASSEM_SRC += ldso-stubs.S + +# Until sbcl-0.6.7.3, we used "LINKFLAGS+=-static" here, which +# worked fine for most things, but LOAD-FOREIGN & friends require +# dlopen() etc., which in turn depend on dynamic linking of the +# runtime. +LINKFLAGS += -dynamic -export-dynamic + +# use 1:1 threading. +# FIXME: DragonFly's lpthread must be what we need. +ifdef LISP_FEATURE_SB_THREAD + OS_LIBS += -lpthread +endif diff --git a/src/runtime/Config.x86-dragonfly b/src/runtime/Config.x86-dragonfly new file mode 100644 index 0000000..ab834fb --- /dev/null +++ b/src/runtime/Config.x86-dragonfly @@ -0,0 +1,26 @@ +# -*- makefile -*- for the C-level run-time support for SBCL + +# This software is part of the SBCL system. See the README file for +# more information. +# +# This software is derived from the CMU CL system, which was +# written at Carnegie Mellon University and released into the +# public domain. The software is in the public domain and is +# provided with absolutely no warranty. See the COPYING and CREDITS +# files for more information. + +include Config.x86-bsd + +ASSEM_SRC += ldso-stubs.S + +# Until sbcl-0.6.7.3, we used "LINKFLAGS+=-static" here, which +# worked fine for most things, but LOAD-FOREIGN & friends require +# dlopen() etc., which in turn depend on dynamic linking of the +# runtime. +LINKFLAGS += -dynamic -export-dynamic + +ifdef LISP_FEATURE_SB_THREAD + OS_LIBS += -lpthread +endif + +CFLAGS += -fno-omit-frame-pointer diff --git a/src/runtime/bsd-os.c b/src/runtime/bsd-os.c index 4c08b97..d308d9b 100644 --- a/src/runtime/bsd-os.c +++ b/src/runtime/bsd-os.c @@ -72,6 +72,12 @@ static void netbsd_init(); static void freebsd_init(); #endif /* __FreeBSD__ */ +#ifdef __DragonFly__ +#include + +static void dragonfly_init(); +#endif /* __DragonFly__ */ + #ifdef __OpenBSD__ #include #include @@ -98,6 +104,8 @@ os_init(char *argv[], char *envp[]) openbsd_init(); #elif defined(LISP_FEATURE_DARWIN) darwin_init(); +#elif defined(__DragonFly__) + dragonfly_init(); #endif } @@ -107,7 +115,7 @@ os_context_sigmask_addr(os_context_t *context) /* (Unlike most of the other context fields that we access, the * signal mask field is a field of the basic, outermost context * struct itself both in FreeBSD 4.0 and in OpenBSD 2.6.) */ -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(LISP_FEATURE_DARWIN) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(LISP_FEATURE_DARWIN) || defined(__DragonFly__) return &context->uc_sigmask; #elif defined (__OpenBSD__) return &context->sc_mask; @@ -444,6 +452,58 @@ futex_wake(int *lock_word, int n) #endif #endif /* __FreeBSD__ */ +#ifdef __DragonFly__ +static void dragonfly_init() +{ +#ifdef LISP_FEATURE_X86 + size_t len; + int instruction_sse; + + len = sizeof(instruction_sse); + if (sysctlbyname("hw.instruction_sse", &instruction_sse, &len, + NULL, 0) == 0 && instruction_sse != 0) { + /* Use the SSE detector */ + fast_bzero_pointer = fast_bzero_detect; + } +#endif /* LISP_FEATURE_X86 */ +} + + +#if defined(LISP_FEATURE_SB_THREAD) && defined(LISP_FEATURE_SB_FUTEX) \ + && !defined(LISP_FEATURE_SB_PTHREAD_FUTEX) +int +futex_wait(int *lock_word, long oldval, long sec, unsigned long usec) +{ + int ret; + + if (sec < 0) + ret = umtx_sleep(lock_word, oldval, 0); + else { + int count = usec + 1000000 * sec; + ret = umtx_sleep(lock_word, oldval, count); + } + + if (ret == 0) return 0; + else { + switch (errno) { + case EWOULDBLOCK: // Operation timed out + return 1; + case EINTR: + return 2; + default: // Such as EINVAL or EBUSY + return -1; + } + } +} + +int +futex_wake(int *lock_word, int n) +{ + return umtx_wakeup(lock_word, n); +} +#endif +#endif /* __DragonFly__ */ + #ifdef LISP_FEATURE_DARWIN /* defined in ppc-darwin-os.c instead */ #elif defined(LISP_FEATURE_FREEBSD) @@ -478,6 +538,20 @@ os_get_runtime_executable_path(int external) return NULL; return copied_string(path); } +#elif defined(LISP_FEATURE_DRAGONFLY) +char * +os_get_runtime_executable_path(int external) +{ + char path[PATH_MAX + 1]; + int size = readlink("/proc/curproc/file", path, sizeof(path) - 1); + if (size < 0) + return NULL; + path[size] = '\0'; + + if (strcmp(path, "unknown") == 0) + return NULL; + return copied_string(path); +} #elif defined(LISP_FEATURE_NETBSD) || defined(LISP_FEATURE_OPENBSD) char * os_get_runtime_executable_path(int external) @@ -487,7 +561,7 @@ os_get_runtime_executable_path(int external) return copied_string("/proc/curproc/file"); return NULL; } -#else /* Not DARWIN or FREEBSD or NETBSD or OPENBSD */ +#else /* Not DARWIN or FREEBSD or NETBSD or OPENBSD or DragonFly */ char * os_get_runtime_executable_path(int external) { diff --git a/src/runtime/bsd-os.h b/src/runtime/bsd-os.h index 880c5f7..61aaf0e 100644 --- a/src/runtime/bsd-os.h +++ b/src/runtime/bsd-os.h @@ -9,7 +9,7 @@ * files for more information. */ -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__DragonFly__) #include #endif @@ -61,6 +61,14 @@ extern int sig_memory_fault; #define SIG_STOP_FOR_GC (SIGUSR2) +#elif defined __DragonFly__ + +#include +typedef ucontext_t os_context_t; + +#define SIG_MEMORY_FAULT (SIGSEGV) +#define SIG_STOP_FOR_GC (SIGUSR2) + #elif defined __OpenBSD__ typedef struct sigcontext os_context_t; diff --git a/src/runtime/pthread-futex.c b/src/runtime/pthread-futex.c index cddcda9..209480c 100644 --- a/src/runtime/pthread-futex.c +++ b/src/runtime/pthread-futex.c @@ -279,7 +279,7 @@ again: * emulate this behaviour. */ sigpending(&pendset); for (i = 1; i < NSIG; i++) { - if (sigismember(&pendset, i) && sigismember(&newset, i)) { + if (sigismember(&pendset, i) && sigismember(&oldset, i)) { result = EINTR; goto done; } diff --git a/src/runtime/thread.c b/src/runtime/thread.c index 26f6de6..dd89435 100644 --- a/src/runtime/thread.c +++ b/src/runtime/thread.c @@ -58,7 +58,7 @@ #define LOCK_CREATE_THREAD #endif -#ifdef LISP_FEATURE_FREEBSD +#if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DRAGONFLY) #define CREATE_CLEANUP_THREAD #define LOCK_CREATE_THREAD #endif diff --git a/src/runtime/undefineds.h b/src/runtime/undefineds.h index b1cb325..024b565 100644 --- a/src/runtime/undefineds.h +++ b/src/runtime/undefineds.h @@ -39,7 +39,8 @@ F(brk) || defined(SVR4) \ || defined(__FreeBSD__) \ || defined(__OpenBSD__) \ - || defined(__NetBSD__) + || defined(__NetBSD__) \ + || defined(__DragonFly__) F(cfgetospeed) F(cfsetospeed) F(cfgetispeed) @@ -154,7 +155,7 @@ F(sigreturn) #if !defined(SVR4) F(sigsetmask) #endif -#if !defined(SVR4) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) +#if !defined(SVR4) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__) F(sigstack) F(sigvec) #endif @@ -180,6 +181,7 @@ F(readdir) || defined(__FreeBSD__) \ || defined(__OpenBSD__) \ || defined(__NetBSD__) \ + || defined(__DragonFly__) \ || defined(__linux__) F(tcgetattr) F(tcsetattr) @@ -198,6 +200,7 @@ F(umask) && !defined(SOLARIS) \ && !defined(__OpenBSD__) \ && !defined(__FreeBSD__) \ + && !defined(__DragonFly__) \ && !defined(__NetBSD__) F(umount) #endif @@ -208,7 +211,7 @@ F(utimes) #ifndef irix F(vfork) #endif -#if !defined(osf1) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) +#if !defined(osf1) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__) F(vhangup) #endif F(wait) diff --git a/src/runtime/x86-64-arch.c b/src/runtime/x86-64-arch.c index 2e6ea23..f0831cf 100644 --- a/src/runtime/x86-64-arch.c +++ b/src/runtime/x86-64-arch.c @@ -70,7 +70,7 @@ context_eflags_addr(os_context_t *context) * we need to do this nasty absolute index magic number thing * instead. */ return &context->uc_mcontext.gregs[17]; -#elif defined __FreeBSD__ +#elif defined(__FreeBSD__) || defined(__DragonFly__) return &context->uc_mcontext.mc_rflags; #elif defined LISP_FEATURE_DARWIN return CONTEXT_ADDR_FROM_STEM(rflags); diff --git a/src/runtime/x86-64-assem.S b/src/runtime/x86-64-assem.S index b85639e..61924a5 100644 --- a/src/runtime/x86-64-assem.S +++ b/src/runtime/x86-64-assem.S @@ -25,7 +25,7 @@ #include "genesis/thread.h" /* Minimize conditionalization for different OS naming schemes. */ -#if defined __linux__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ || defined __sun || defined _WIN64 +#if defined __linux__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ || defined __sun || defined _WIN64 || defined __DragonFly__ #define GNAME(var) var #else #define GNAME(var) _##var @@ -33,7 +33,7 @@ /* Get the right type of alignment. Linux, FreeBSD and OpenBSD * want alignment in bytes. */ -#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined __NetBSD__ || defined(__sun) || defined _WIN64 +#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined __NetBSD__ || defined(__sun) || defined _WIN64 || defined(__DragonFly__) #define align_4byte 4 #define align_8byte 8 #define align_16byte 16 diff --git a/src/runtime/x86-64-bsd-os.c b/src/runtime/x86-64-bsd-os.c index 3d9a9c7..b394118 100644 --- a/src/runtime/x86-64-bsd-os.c +++ b/src/runtime/x86-64-bsd-os.c @@ -12,6 +12,10 @@ #include #endif +#if defined(LISP_FEATURE_DRAGONFLY) +#include +#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 @@ -23,7 +27,7 @@ * entails; unfortunately, currently the situation is worse, not * better, than in the above paragraph. */ -#if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DARWIN) || defined(LISP_FEATURE_OPENBSD) +#if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DARWIN) || defined(LISP_FEATURE_OPENBSD) || defined(LISP_FEATURE_DRAGONFLY) os_context_register_t * os_context_register_addr(os_context_t *context, int offset) { @@ -168,6 +172,19 @@ int arch_os_thread_cleanup(struct thread *thread) { return 1; /* success */ } +#if defined(LISP_FEATURE_DRAGONFLY) +void +os_restore_fp_control(os_context_t *context) +{ + struct envxmm *ex = (struct envxmm*)(&context->uc_mcontext.mc_fpregs); + /* reset exception flags and restore control flags on SSE2 FPU */ + unsigned int temp = (ex->en_mxcsr) & ~0x3F; + asm ("ldmxcsr %0" : : "m" (temp)); + /* same for x87 FPU. */ + asm ("fldcw %0" : : "m" (ex->en_cw)); +} +#endif + #if defined(LISP_FEATURE_FREEBSD) void os_restore_fp_control(os_context_t *context) diff --git a/src/runtime/x86-64-bsd-os.h b/src/runtime/x86-64-bsd-os.h index 9db3ae7..789748b 100644 --- a/src/runtime/x86-64-bsd-os.h +++ b/src/runtime/x86-64-bsd-os.h @@ -5,6 +5,10 @@ #include #endif +#ifdef LISP_FEATURE_DRAGONFLY +#include +#endif + typedef register_t os_context_register_t; static inline os_context_t *arch_os_get_context(void **void_context) @@ -16,7 +20,7 @@ static inline os_context_t *arch_os_get_context(void **void_context) * store signal context information, but at least they tend to use the * same stems to name the structure fields, so by using this macro we * can share a fair amount of code between different variants. */ -#if defined __FreeBSD__ +#if defined(__FreeBSD__) || defined(__DragonFly__) #define CONTEXT_ADDR_FROM_STEM(stem) &context->uc_mcontext.mc_ ## stem #elif defined(__OpenBSD__) #define CONTEXT_ADDR_FROM_STEM(stem) &context->sc_ ## stem @@ -26,6 +30,20 @@ static inline os_context_t *arch_os_get_context(void **void_context) #error unsupported BSD variant #endif +#if defined LISP_FEATURE_DRAGONFLY +#define RESTORE_FP_CONTROL_FROM_CONTEXT +void os_restore_fp_control(os_context_t *context); + +#define X86_64_SIGFPE_FIXUP + +static inline unsigned int * +arch_os_context_mxcsr_addr(os_context_t *context) +{ + struct envxmm *ex = (struct envxmm *)(&context->uc_mcontext.mc_fpregs); + return &ex->en_mxcsr; +} +#endif + #if defined LISP_FEATURE_FREEBSD #define RESTORE_FP_CONTROL_FROM_CONTEXT void os_restore_fp_control(os_context_t *context); diff --git a/src/runtime/x86-arch.c b/src/runtime/x86-arch.c index dfbf908..59ecf92 100644 --- a/src/runtime/x86-arch.c +++ b/src/runtime/x86-arch.c @@ -68,7 +68,7 @@ context_eflags_addr(os_context_t *context) * we need to do this nasty absolute index magic number thing * instead. */ return &context->uc_mcontext.gregs[16]; -#elif defined __FreeBSD__ +#elif defined(__FreeBSD__) || defined(__DragonFly__) return &context->uc_mcontext.mc_eflags; #elif defined __OpenBSD__ return &context->sc_eflags; diff --git a/src/runtime/x86-assem.S b/src/runtime/x86-assem.S index fba970b..024e137 100644 --- a/src/runtime/x86-assem.S +++ b/src/runtime/x86-assem.S @@ -32,7 +32,7 @@ * * (Except Win32, which is unlikely ever to be ELF, sorry. -- AB 2005-12-08) */ -#if defined __linux__ || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ || defined __sun +#if defined __linux__ || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ || defined __sun || defined __DragonFly__ #define GNAME(var) var #else #define GNAME(var) _##var @@ -47,7 +47,7 @@ * matter any more, perhaps it's just clutter we could get * rid of? -- WHN 2004-04-18) */ -#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun) || defined(LISP_FEATURE_WIN32) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun) || defined(LISP_FEATURE_WIN32) || defined(__Dragonfly__) #define align_4byte 4 #define align_8byte 8 #define align_16byte 16 @@ -131,7 +131,7 @@ # define LoadCurrentThreadSlot(offset,reg); \ movl SBCL_THREAD_BASE_EA, reg ; \ movl offset(reg), reg ; -#elif defined(LISP_FEATURE_LINUX) || defined(LISP_FEATURE_SUNOS) || defined(LISP_FEATURE_FREEBSD) +#elif defined(LISP_FEATURE_LINUX) || defined(LISP_FEATURE_SUNOS) || defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DRAGONFLY) /* see comment in arch_os_thread_init */ # define SBCL_THREAD_BASE_EA %fs:THREAD_SELFPTR_OFFSET # define MAYBE_FS(addr) addr diff --git a/src/runtime/x86-bsd-os.c b/src/runtime/x86-bsd-os.c index fe75566..4f985fe 100644 --- a/src/runtime/x86-bsd-os.c +++ b/src/runtime/x86-bsd-os.c @@ -16,7 +16,7 @@ #endif /* LISP_FEATURE_DARWIN */ #endif -#if defined(LISP_FEATURE_FREEBSD) +#if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DRAGONFLY) #include "machine/npx.h" #endif @@ -40,7 +40,7 @@ * entails; unfortunately, currently the situation is worse, not * better, than in the above paragraph. */ -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(LISP_FEATURE_DARWIN) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(LISP_FEATURE_DARWIN) || defined(__DragonFly__) int * os_context_register_addr(os_context_t *context, int offset) { @@ -72,7 +72,7 @@ os_context_sp_addr(os_context_t *context) return (int *)CONTEXT_ADDR_FROM_STEM(esp); } -#endif /* __FreeBSD__ || __OpenBSD__ */ +#endif /* __FreeBSD__ || __OpenBSD__ || __DragonFly__ */ #ifdef __NetBSD__ int * @@ -112,7 +112,7 @@ os_context_sp_addr(os_context_t *context) int *os_context_pc_addr(os_context_t *context) { -#if defined __FreeBSD__ +#if defined(__FreeBSD__) || defined(__DragonFly__) return CONTEXT_ADDR_FROM_STEM(eip); #elif defined __OpenBSD__ return CONTEXT_ADDR_FROM_STEM(pc); @@ -264,6 +264,14 @@ os_restore_fp_control(os_context_t *context) } #endif +#if defined(LISP_FEATURE_DRAGONFLY) +void os_restore_fp_control (os_context_t *context) +{ + struct envxmm *ex = (struct envxmm *)(context->uc_mcontext.mc_fpregs); + __asm__ __volatile__ ("fldcw %0" : : "m" (ex->en_cw)); +} +#endif /* LISP_FEATURE_DRAGONFLY */ + #if defined(LISP_FEATURE_OPENBSD) void os_restore_fp_control(os_context_t *context) diff --git a/src/runtime/x86-bsd-os.h b/src/runtime/x86-bsd-os.h index dc9d9f7..2ae7d61 100644 --- a/src/runtime/x86-bsd-os.h +++ b/src/runtime/x86-bsd-os.h @@ -1,7 +1,7 @@ #ifndef _X86_BSD_OS_H #define _X86_BSD_OS_H -#ifdef LISP_FEATURE_FREEBSD +#if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DRAGONFLY) #include #include #endif @@ -17,7 +17,7 @@ static inline os_context_t *arch_os_get_context(void **void_context) * store signal context information, but at least they tend to use the * same stems to name the structure fields, so by using this macro we * can share a fair amount of code between different variants. */ -#if defined __FreeBSD__ +#if defined(__FreeBSD__) || defined(__DragonFly__) #define CONTEXT_ADDR_FROM_STEM(stem) &context->uc_mcontext.mc_ ## stem #elif defined(__OpenBSD__) #define CONTEXT_ADDR_FROM_STEM(stem) &context->sc_ ## stem @@ -35,7 +35,7 @@ void os_restore_tls_segment_register(os_context_t *context); void os_restore_fp_control(os_context_t *context); #endif -#if defined LISP_FEATURE_OPENBSD +#if defined(LISP_FEATURE_OPENBSD) || defined(LISP_FEATURE_DRAGONFLY) #define RESTORE_FP_CONTROL_FROM_CONTEXT void os_restore_fp_control(os_context_t *context); #endif