Advertisement
Guest User

DragonFly BSD support for sbcl

a guest
Apr 9th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 27.61 KB | None | 0 0
  1. diff --git a/TODO b/TODO
  2. index 6c8d83b..d60252c 100644
  3. --- a/TODO
  4. +++ b/TODO
  5. @@ -104,6 +104,9 @@ DARWIN
  6.    Needs love, particularly threads and exceptions/signals. slam.sh is
  7.    also broken there.
  8.  
  9. +DRAGONFLY
  10. +  Fix multithreading support on x86-64, add it on x86.
  11. +
  12.  FUNCTION NAMES
  13.  
  14.    We'd like to be able to (SETF %FUNCTION-NAME) on a closure.
  15. diff --git a/base-target-features.lisp-expr b/base-target-features.lisp-expr
  16. index 74bf083..c262c1c 100644
  17. --- a/base-target-features.lisp-expr
  18. +++ b/base-target-features.lisp-expr
  19. @@ -434,23 +434,24 @@
  20.   ;;     implemented for this platform.
  21.   ;;
  22.   ;; operating system features:
  23. - ;;   :unix    = We're intended to run under some Unix-like OS. (This is not
  24. - ;;              exclusive with the features which indicate which particular
  25. - ;;              Unix-like OS we're intended to run under.)
  26. - ;;   :linux   = We're intended to run under some version of Linux.
  27. - ;;   :bsd     = We're intended to run under some version of BSD Unix. (This
  28. - ;;              is not exclusive with the features which indicate which
  29. - ;;              particular version of BSD we're intended to run under.)
  30. - ;;   :freebsd = We're intended to run under FreeBSD.
  31. - ;;   :openbsd = We're intended to run under OpenBSD.
  32. - ;;   :netbsd  = We're intended to run under NetBSD.
  33. - ;;   :darwin  = We're intended to run under Darwin (including MacOS X).
  34. - ;;   :sunos   = We're intended to run under Solaris user environment
  35. - ;;              with the SunOS kernel.
  36. - ;;   :hpux    = We're intended to run under HP-UX 11.11 or later
  37. - ;;   :osf1    = We're intended to run under Tru64 (aka Digital Unix
  38. - ;;              aka OSF/1).
  39. - ;;   :win32   = We're intended to under some version of Microsoft Windows.
  40. + ;;   :unix       = We're intended to run under some Unix-like OS. (This is not
  41. + ;;                 exclusive with the features which indicate which particular
  42. + ;;                 Unix-like OS we're intended to run under.)
  43. + ;;   :linux      = We're intended to run under some version of Linux.
  44. + ;;   :bsd        = We're intended to run under some version of BSD Unix. (This
  45. + ;;                 is not exclusive with the features which indicate which
  46. + ;;                 particular version of BSD we're intended to run under.)
  47. + ;;   :freebsd    = We're intended to run under FreeBSD.
  48. + ;;   :openbsd    = We're intended to run under OpenBSD.
  49. + ;;   :netbsd     = We're intended to run under NetBSD.
  50. + ;;   :dragonfly  = We're intended to run under DragonFly.
  51. + ;;   :darwin     = We're intended to run under Darwin (including MacOS X).
  52. + ;;   :sunos      = We're intended to run under Solaris user environment
  53. + ;;                 with the SunOS kernel.
  54. + ;;   :hpux       = We're intended to run under HP-UX 11.11 or later
  55. + ;;   :osf1       = We're intended to run under Tru64 (aka Digital Unix
  56. + ;;                 aka OSF/1).
  57. + ;;   :win32      = We're intended to under some version of Microsoft Windows.
  58.   ;; (No others are supported by SBCL as of 1.0.8, but :hpux or :irix
  59.   ;; support could be ported from CMU CL if anyone is sufficiently
  60.   ;; motivated to do so.)
  61. diff --git a/contrib/asdf/asdf.lisp b/contrib/asdf/asdf.lisp
  62. index ce7a1db..6274595 100644
  63. --- a/contrib/asdf/asdf.lisp
  64. +++ b/contrib/asdf/asdf.lisp
  65. @@ -3237,7 +3237,7 @@ located."
  66.     '(:cygwin (:win :windows :mswindows :win32 :mingw32) ;; try cygwin first!
  67.       (:linux :linux :linux-target) ;; for GCL at least, must appear before :bsd
  68.       (:macosx :macosx :darwin :darwin-target :apple) ; also before :bsd
  69. -     (:solaris :solaris :sunos) (:bsd :bsd :freebsd :netbsd :openbsd) :unix
  70. +     (:solaris :solaris :sunos) (:bsd :bsd :freebsd :dragonfly :netbsd :openbsd) :unix
  71.       :genera)))
  72.  
  73.  (defun architecture ()
  74. diff --git a/contrib/sb-bsd-sockets/constants.lisp b/contrib/sb-bsd-sockets/constants.lisp
  75. index eeabd11..b874b17 100644
  76. --- a/contrib/sb-bsd-sockets/constants.lisp
  77. +++ b/contrib/sb-bsd-sockets/constants.lisp
  78. @@ -316,7 +316,7 @@
  79.   (:integer EAI-BADFLAGS "EAI_BADFLAGS")
  80.   (:integer EAI-NONAME "EAI_NONAME")
  81.   (:integer EAI-SERVICE "EAI_SERVICE")
  82. - #-freebsd
  83. + #-(or freebsd dragonfly)
  84.   (:integer EAI-ADDRFAMILY "EAI_ADDRFAMILY")
  85.   (:integer EAI-MEMORY "EAI_MEMORY")
  86.   (:integer EAI-FAIL "EAI_FAIL")
  87. diff --git a/contrib/sb-bsd-sockets/tests.lisp b/contrib/sb-bsd-sockets/tests.lisp
  88. index 776878c..f9e8c1b 100644
  89. --- a/contrib/sb-bsd-sockets/tests.lisp
  90. +++ b/contrib/sb-bsd-sockets/tests.lisp
  91. @@ -30,6 +30,7 @@
  92.  ;;; Apparently getprotobyname_r on FreeBSD says -1 and EINTR
  93.  ;;; for unknown protocols...
  94.  #-(and freebsd sb-thread)
  95. +#-(and dragonfly sb-thread)
  96.  (deftest get-protocol-by-name/error
  97.    (handler-case (get-protocol-by-name "nonexistent-protocol")
  98.      (unknown-protocol ()
  99. diff --git a/make-config.sh b/make-config.sh
  100. index 6b720e0..04a2dda 100644
  101. --- a/make-config.sh
  102. +++ b/make-config.sh
  103. @@ -277,6 +277,9 @@ case `uname` in
  104.                  ;;
  105.          esac
  106.          ;;
  107. +    DragonFly)
  108. +   sbcl_os="dragonfly"
  109. +   ;;
  110.      Darwin)
  111.          sbcl_os="darwin"
  112.          ;;
  113. @@ -385,7 +388,8 @@ then
  114.      # If --fancy, enable threads on platforms where they can be built.
  115.      case $sbcl_arch in
  116.          x86|x86-64|ppc)
  117. -       if [ "$sbcl_os" = "sunos" ] && [ "$sbcl_arch" = "x86-64" ]
  118. +       if ([ "$sbcl_os" = "sunos" ] && [ "$sbcl_arch" = "x86-64" ]) || \
  119. +               ([ "$sbcl_os" = "dragonfly" ] && [ "$sbcl_arch" = "x86" ])
  120.         then
  121.         echo "No threads on this platform."
  122.         else
  123. @@ -502,6 +506,16 @@ case "$sbcl_os" in
  124.                  ;;
  125.          esac
  126.          ;;
  127. +    dragonfly)
  128. +        printf ' :unix' >> $ltf
  129. +        printf ' :bsd' >> $ltf
  130. +        printf ' :elf' >> $ltf
  131. +        printf ' :dragonfly' >> $ltf
  132. +        printf ' :sb-qshow' >> $ltf
  133. +        link_or_copy $sbcl_arch-bsd-os.h target-arch-os.h
  134. +        link_or_copy bsd-os.h target-os.h
  135. +        link_or_copy Config.$sbcl_arch-dragonfly Config
  136. +        ;;
  137.      darwin)
  138.          printf ' :unix' >> $ltf
  139.          printf ' :mach-o' >> $ltf
  140. @@ -587,7 +601,7 @@ if [ "$sbcl_arch" = "x86" ]; then
  141.      printf ' :alien-callbacks :cycle-counter :inline-constants ' >> $ltf
  142.      printf ' :memory-barrier-vops :multiply-high-vops' >> $ltf
  143.      case "$sbcl_os" in
  144. -    linux | freebsd | netbsd | openbsd | sunos | darwin | win32)
  145. +    linux | freebsd | netbsd | openbsd | sunos | darwin | win32 | dragonfly)
  146.          printf ' :linkage-table' >> $ltf
  147.      esac
  148.      if [ "$sbcl_os" = "win32" ]; then
  149. diff --git a/src/code/unix.lisp b/src/code/unix.lisp
  150. index 9572a22..de330ae 100644
  151. --- a/src/code/unix.lisp
  152. +++ b/src/code/unix.lisp
  153. @@ -414,14 +414,14 @@ corresponds to NAME, or NIL if there is none."
  154.    ;; comma not inside a backquote. This error has absolutely nothing
  155.    ;; to do with the actual meaning of the error (and little to do with
  156.    ;; its location, either).
  157. -  #!-(or linux openbsd freebsd netbsd sunos osf1 darwin hpux win32) (,stub,)
  158. -  #!+(or linux openbsd freebsd netbsd sunos osf1 darwin hpux win32)
  159. +  #!-(or linux openbsd freebsd netbsd sunos osf1 darwin hpux win32 dragonfly) (,stub,)
  160. +  #!+(or linux openbsd freebsd netbsd sunos osf1 darwin hpux win32 dragonfly)
  161.    (or (newcharstar-string (alien-funcall (extern-alien "getcwd"
  162.                                                         (function (* char)
  163.                                                                   (* char)
  164.                                                                   size-t))
  165.                                           nil
  166. -                                         #!+(or linux openbsd freebsd netbsd darwin win32) 0
  167. +                                         #!+(or linux openbsd freebsd netbsd dragonfly darwin win32) 0
  168.                                           #!+(or sunos osf1 hpux) 1025))
  169.        (simple-perror "getcwd")))
  170.  
  171. diff --git a/src/compiler/x86/parms.lisp b/src/compiler/x86/parms.lisp
  172. index 5502afd..163ffd7 100644
  173. --- a/src/compiler/x86/parms.lisp
  174. +++ b/src/compiler/x86/parms.lisp
  175. @@ -187,13 +187,14 @@
  176.  ;;; NetBSD configuration used to have this comment regarding the linkage
  177.  ;;; table: "In CMUCL: 0xB0000000->0xB1000000"
  178.  
  179. -#!+win32   (!gencgc-space-setup #x22000000 nil nil #x10000)
  180. -#!+linux   (!gencgc-space-setup #x01000000 #x09000000)
  181. -#!+sunos   (!gencgc-space-setup #x20000000 #x48000000)
  182. -#!+freebsd (!gencgc-space-setup #x01000000 #x58000000)
  183. -#!+openbsd (!gencgc-space-setup #x1b000000 #x40000000)
  184. -#!+netbsd  (!gencgc-space-setup #x20000000 #x60000000)
  185. -#!+darwin  (!gencgc-space-setup #x04000000 #x10000000)
  186. +#!+win32     (!gencgc-space-setup #x22000000 nil nil #x10000)
  187. +#!+linux     (!gencgc-space-setup #x01000000 #x09000000)
  188. +#!+sunos     (!gencgc-space-setup #x20000000 #x48000000)
  189. +#!+freebsd   (!gencgc-space-setup #x01000000 #x58000000)
  190. +#!+dragonfly (!gencgc-space-setup #x01000000 #x58000000)
  191. +#!+openbsd   (!gencgc-space-setup #x1b000000 #x40000000)
  192. +#!+netbsd    (!gencgc-space-setup #x20000000 #x60000000)
  193. +#!+darwin    (!gencgc-space-setup #x04000000 #x10000000)
  194.  
  195.  ;;; Size of one linkage-table entry in bytes.
  196.  (def!constant linkage-table-entry-size 8)
  197. diff --git a/src/runtime/Config.x86-64-dragonfly b/src/runtime/Config.x86-64-dragonfly
  198. new file mode 100644
  199. index 0000000..f00b739
  200. --- /dev/null
  201. +++ b/src/runtime/Config.x86-64-dragonfly
  202. @@ -0,0 +1,26 @@
  203. +# -*- makefile -*- for the C-level run-time support for SBCL
  204. +
  205. +# This software is part of the SBCL system. See the README file for
  206. +# more information.
  207. +#
  208. +# This software is derived from the CMU CL system, which was
  209. +# written at Carnegie Mellon University and released into the
  210. +# public domain. The software is in the public domain and is
  211. +# provided with absolutely no warranty. See the COPYING and CREDITS
  212. +# files for more information.
  213. +
  214. +include Config.x86-64-bsd
  215. +
  216. +ASSEM_SRC += ldso-stubs.S
  217. +
  218. +# Until sbcl-0.6.7.3, we used "LINKFLAGS+=-static" here, which
  219. +# worked fine for most things, but LOAD-FOREIGN & friends require
  220. +# dlopen() etc., which in turn depend on dynamic linking of the
  221. +# runtime.
  222. +LINKFLAGS += -dynamic -export-dynamic
  223. +
  224. +# use 1:1 threading.
  225. +# FIXME: DragonFly's lpthread must be what we need.
  226. +ifdef LISP_FEATURE_SB_THREAD
  227. +  OS_LIBS += -lpthread
  228. +endif
  229. diff --git a/src/runtime/Config.x86-dragonfly b/src/runtime/Config.x86-dragonfly
  230. new file mode 100644
  231. index 0000000..ab834fb
  232. --- /dev/null
  233. +++ b/src/runtime/Config.x86-dragonfly
  234. @@ -0,0 +1,26 @@
  235. +# -*- makefile -*- for the C-level run-time support for SBCL
  236. +
  237. +# This software is part of the SBCL system. See the README file for
  238. +# more information.
  239. +#
  240. +# This software is derived from the CMU CL system, which was
  241. +# written at Carnegie Mellon University and released into the
  242. +# public domain. The software is in the public domain and is
  243. +# provided with absolutely no warranty. See the COPYING and CREDITS
  244. +# files for more information.
  245. +
  246. +include Config.x86-bsd
  247. +
  248. +ASSEM_SRC += ldso-stubs.S
  249. +
  250. +# Until sbcl-0.6.7.3, we used "LINKFLAGS+=-static" here, which
  251. +# worked fine for most things, but LOAD-FOREIGN & friends require
  252. +# dlopen() etc., which in turn depend on dynamic linking of the
  253. +# runtime.
  254. +LINKFLAGS += -dynamic -export-dynamic
  255. +
  256. +ifdef LISP_FEATURE_SB_THREAD
  257. +  OS_LIBS += -lpthread
  258. +endif
  259. +
  260. +CFLAGS += -fno-omit-frame-pointer
  261. diff --git a/src/runtime/bsd-os.c b/src/runtime/bsd-os.c
  262. index 4c08b97..d308d9b 100644
  263. --- a/src/runtime/bsd-os.c
  264. +++ b/src/runtime/bsd-os.c
  265. @@ -72,6 +72,12 @@ static void netbsd_init();
  266.  static void freebsd_init();
  267.  #endif /* __FreeBSD__ */
  268.  
  269. +#ifdef __DragonFly__
  270. +#include <sys/sysctl.h>
  271. +
  272. +static void dragonfly_init();
  273. +#endif /* __DragonFly__ */
  274. +
  275.  #ifdef __OpenBSD__
  276.  #include <sys/types.h>
  277.  #include <sys/resource.h>
  278. @@ -98,6 +104,8 @@ os_init(char *argv[], char *envp[])
  279.      openbsd_init();
  280.  #elif defined(LISP_FEATURE_DARWIN)
  281.      darwin_init();
  282. +#elif defined(__DragonFly__)
  283. +    dragonfly_init();
  284.  #endif
  285.  }
  286.  
  287. @@ -107,7 +115,7 @@ os_context_sigmask_addr(os_context_t *context)
  288.      /* (Unlike most of the other context fields that we access, the
  289.       * signal mask field is a field of the basic, outermost context
  290.       * struct itself both in FreeBSD 4.0 and in OpenBSD 2.6.) */
  291. -#if defined(__FreeBSD__)  || defined(__NetBSD__) || defined(LISP_FEATURE_DARWIN)
  292. +#if defined(__FreeBSD__)  || defined(__NetBSD__) || defined(LISP_FEATURE_DARWIN) || defined(__DragonFly__)
  293.      return &context->uc_sigmask;
  294.  #elif defined (__OpenBSD__)
  295.      return &context->sc_mask;
  296. @@ -444,6 +452,58 @@ futex_wake(int *lock_word, int n)
  297.  #endif
  298.  #endif /* __FreeBSD__ */
  299.  
  300. +#ifdef __DragonFly__
  301. +static void dragonfly_init()
  302. +{
  303. +#ifdef LISP_FEATURE_X86
  304. +    size_t len;
  305. +    int instruction_sse;
  306. +    
  307. +    len = sizeof(instruction_sse);
  308. +    if (sysctlbyname("hw.instruction_sse", &instruction_sse, &len,
  309. +                     NULL, 0) == 0 && instruction_sse != 0) {
  310. +        /* Use the SSE detector */
  311. +        fast_bzero_pointer = fast_bzero_detect;
  312. +    }
  313. +#endif /* LISP_FEATURE_X86 */
  314. +}
  315. +
  316. +
  317. +#if defined(LISP_FEATURE_SB_THREAD) && defined(LISP_FEATURE_SB_FUTEX) \
  318. +    && !defined(LISP_FEATURE_SB_PTHREAD_FUTEX)
  319. +int
  320. +futex_wait(int *lock_word, long oldval, long sec, unsigned long usec)
  321. +{
  322. +    int ret;
  323. +
  324. +    if (sec < 0)
  325. +        ret = umtx_sleep(lock_word, oldval, 0);
  326. +    else {
  327. +        int count = usec + 1000000 * sec;
  328. +        ret = umtx_sleep(lock_word, oldval, count);
  329. +    }
  330. +
  331. +    if (ret == 0) return 0;
  332. +    else {
  333. +        switch (errno) {
  334. +        case EWOULDBLOCK: // Operation timed out
  335. +            return 1;
  336. +        case EINTR:
  337. +            return 2;
  338. +        default: // Such as EINVAL or EBUSY
  339. +            return -1;
  340. +        }
  341. +    }
  342. +}
  343. +
  344. +int
  345. +futex_wake(int *lock_word, int n)
  346. +{
  347. +    return umtx_wakeup(lock_word, n);
  348. +}
  349. +#endif
  350. +#endif /* __DragonFly__ */
  351. +
  352.  #ifdef LISP_FEATURE_DARWIN
  353.  /* defined in ppc-darwin-os.c instead */
  354.  #elif defined(LISP_FEATURE_FREEBSD)
  355. @@ -478,6 +538,20 @@ os_get_runtime_executable_path(int external)
  356.          return NULL;
  357.      return copied_string(path);
  358.  }
  359. +#elif defined(LISP_FEATURE_DRAGONFLY)
  360. +char *
  361. +os_get_runtime_executable_path(int external)
  362. +{
  363. +    char path[PATH_MAX + 1];
  364. +    int size = readlink("/proc/curproc/file", path, sizeof(path) - 1);
  365. +    if (size < 0)
  366. +        return NULL;
  367. +    path[size] = '\0';
  368. +
  369. +    if (strcmp(path, "unknown") == 0)
  370. +        return NULL;
  371. +    return copied_string(path);
  372. +}
  373.  #elif defined(LISP_FEATURE_NETBSD) || defined(LISP_FEATURE_OPENBSD)
  374.  char *
  375.  os_get_runtime_executable_path(int external)
  376. @@ -487,7 +561,7 @@ os_get_runtime_executable_path(int external)
  377.          return copied_string("/proc/curproc/file");
  378.      return NULL;
  379.  }
  380. -#else /* Not DARWIN or FREEBSD or NETBSD or OPENBSD */
  381. +#else /* Not DARWIN or FREEBSD or NETBSD or OPENBSD or DragonFly */
  382.  char *
  383.  os_get_runtime_executable_path(int external)
  384.  {
  385. diff --git a/src/runtime/bsd-os.h b/src/runtime/bsd-os.h
  386. index 880c5f7..61aaf0e 100644
  387. --- a/src/runtime/bsd-os.h
  388. +++ b/src/runtime/bsd-os.h
  389. @@ -9,7 +9,7 @@
  390.   * files for more information.
  391.   */
  392.  
  393. -#ifdef __FreeBSD__
  394. +#if defined(__FreeBSD__) || defined(__DragonFly__)
  395.  #include <osreldate.h>
  396.  #endif
  397.  
  398. @@ -61,6 +61,14 @@ extern int sig_memory_fault;
  399.  
  400.  #define SIG_STOP_FOR_GC (SIGUSR2)
  401.  
  402. +#elif defined __DragonFly__
  403. +
  404. +#include <sys/ucontext.h>
  405. +typedef ucontext_t os_context_t;
  406. +
  407. +#define SIG_MEMORY_FAULT (SIGSEGV)
  408. +#define SIG_STOP_FOR_GC (SIGUSR2)
  409. +
  410.  #elif defined __OpenBSD__
  411.  
  412.  typedef struct sigcontext os_context_t;
  413. diff --git a/src/runtime/pthread-futex.c b/src/runtime/pthread-futex.c
  414. index cddcda9..209480c 100644
  415. --- a/src/runtime/pthread-futex.c
  416. +++ b/src/runtime/pthread-futex.c
  417. @@ -279,7 +279,7 @@ again:
  418.           * emulate this behaviour. */
  419.          sigpending(&pendset);
  420.          for (i = 1; i < NSIG; i++) {
  421. -            if (sigismember(&pendset, i) && sigismember(&newset, i)) {
  422. +            if (sigismember(&pendset, i) && sigismember(&oldset, i)) {
  423.                  result = EINTR;
  424.                  goto done;
  425.              }
  426. diff --git a/src/runtime/thread.c b/src/runtime/thread.c
  427. index 26f6de6..dd89435 100644
  428. --- a/src/runtime/thread.c
  429. +++ b/src/runtime/thread.c
  430. @@ -58,7 +58,7 @@
  431.  #define LOCK_CREATE_THREAD
  432.  #endif
  433.  
  434. -#ifdef LISP_FEATURE_FREEBSD
  435. +#if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DRAGONFLY)
  436.  #define CREATE_CLEANUP_THREAD
  437.  #define LOCK_CREATE_THREAD
  438.  #endif
  439. diff --git a/src/runtime/undefineds.h b/src/runtime/undefineds.h
  440. index b1cb325..024b565 100644
  441. --- a/src/runtime/undefineds.h
  442. +++ b/src/runtime/undefineds.h
  443. @@ -39,7 +39,8 @@ F(brk)
  444.       || defined(SVR4) \
  445.       || defined(__FreeBSD__) \
  446.       || defined(__OpenBSD__) \
  447. -     || defined(__NetBSD__)
  448. +     || defined(__NetBSD__) \
  449. +     || defined(__DragonFly__)
  450.  F(cfgetospeed)
  451.  F(cfsetospeed)
  452.  F(cfgetispeed)
  453. @@ -154,7 +155,7 @@ F(sigreturn)
  454.  #if !defined(SVR4)
  455.  F(sigsetmask)
  456.  #endif
  457. -#if !defined(SVR4) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
  458. +#if !defined(SVR4) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__)
  459.  F(sigstack)
  460.  F(sigvec)
  461.  #endif
  462. @@ -180,6 +181,7 @@ F(readdir)
  463.       || defined(__FreeBSD__) \
  464.       || defined(__OpenBSD__) \
  465.       || defined(__NetBSD__) \
  466. +     || defined(__DragonFly__) \
  467.       || defined(__linux__)
  468.  F(tcgetattr)
  469.  F(tcsetattr)
  470. @@ -198,6 +200,7 @@ F(umask)
  471.       && !defined(SOLARIS) \
  472.       && !defined(__OpenBSD__) \
  473.       && !defined(__FreeBSD__) \
  474. +     && !defined(__DragonFly__) \
  475.       && !defined(__NetBSD__)
  476.  F(umount)
  477.  #endif
  478. @@ -208,7 +211,7 @@ F(utimes)
  479.  #ifndef irix
  480.  F(vfork)
  481.  #endif
  482. -#if !defined(osf1) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
  483. +#if !defined(osf1) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__)
  484.  F(vhangup)
  485.  #endif
  486.  F(wait)
  487. diff --git a/src/runtime/x86-64-arch.c b/src/runtime/x86-64-arch.c
  488. index 2e6ea23..f0831cf 100644
  489. --- a/src/runtime/x86-64-arch.c
  490. +++ b/src/runtime/x86-64-arch.c
  491. @@ -70,7 +70,7 @@ context_eflags_addr(os_context_t *context)
  492.       * we need to do this nasty absolute index magic number thing
  493.       * instead. */
  494.      return &context->uc_mcontext.gregs[17];
  495. -#elif defined __FreeBSD__
  496. +#elif defined(__FreeBSD__) || defined(__DragonFly__)
  497.      return &context->uc_mcontext.mc_rflags;
  498.  #elif defined LISP_FEATURE_DARWIN
  499.      return CONTEXT_ADDR_FROM_STEM(rflags);
  500. diff --git a/src/runtime/x86-64-assem.S b/src/runtime/x86-64-assem.S
  501. index b85639e..61924a5 100644
  502. --- a/src/runtime/x86-64-assem.S
  503. +++ b/src/runtime/x86-64-assem.S
  504. @@ -25,7 +25,7 @@
  505.  #include "genesis/thread.h"
  506.    
  507.  /* Minimize conditionalization for different OS naming schemes. */
  508. -#if defined __linux__  || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ || defined __sun || defined _WIN64
  509. +#if defined __linux__  || defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ || defined __sun || defined _WIN64 || defined __DragonFly__
  510.  #define GNAME(var) var
  511.  #else
  512.  #define GNAME(var) _##var
  513. @@ -33,7 +33,7 @@
  514.  
  515.  /* Get the right type of alignment. Linux, FreeBSD and OpenBSD
  516.   * want alignment in bytes. */
  517. -#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined __NetBSD__ || defined(__sun) || defined _WIN64
  518. +#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined __NetBSD__ || defined(__sun) || defined _WIN64 || defined(__DragonFly__)
  519.  #define align_4byte    4
  520.  #define align_8byte    8
  521.  #define align_16byte   16
  522. diff --git a/src/runtime/x86-64-bsd-os.c b/src/runtime/x86-64-bsd-os.c
  523. index 3d9a9c7..b394118 100644
  524. --- a/src/runtime/x86-64-bsd-os.c
  525. +++ b/src/runtime/x86-64-bsd-os.c
  526. @@ -12,6 +12,10 @@
  527.  #include <machine/fpu.h>
  528.  #endif
  529.  
  530. +#if defined(LISP_FEATURE_DRAGONFLY)
  531. +#include <machine/npx.h>
  532. +#endif
  533. +
  534.  /* KLUDGE: There is strong family resemblance in the signal context
  535.   * stuff in FreeBSD and OpenBSD, but in detail they're different in
  536.   * almost every line of code. It would be nice to find some way to
  537. @@ -23,7 +27,7 @@
  538.   * entails; unfortunately, currently the situation is worse, not
  539.   * better, than in the above paragraph. */
  540.  
  541. -#if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DARWIN) || defined(LISP_FEATURE_OPENBSD)
  542. +#if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DARWIN) || defined(LISP_FEATURE_OPENBSD) || defined(LISP_FEATURE_DRAGONFLY)
  543.  os_context_register_t *
  544.  os_context_register_addr(os_context_t *context, int offset)
  545.  {
  546. @@ -168,6 +172,19 @@ int arch_os_thread_cleanup(struct thread *thread) {
  547.      return 1;                  /* success */
  548.  }
  549.  
  550. +#if defined(LISP_FEATURE_DRAGONFLY)
  551. +void
  552. +os_restore_fp_control(os_context_t *context)
  553. +{
  554. +    struct envxmm *ex = (struct envxmm*)(&context->uc_mcontext.mc_fpregs);
  555. +    /* reset exception flags and restore control flags on SSE2 FPU */
  556. +    unsigned int temp = (ex->en_mxcsr) & ~0x3F;
  557. +    asm ("ldmxcsr %0" : : "m" (temp));
  558. +    /* same for x87 FPU. */
  559. +    asm ("fldcw %0" : : "m" (ex->en_cw));
  560. +}
  561. +#endif
  562. +
  563.  #if defined(LISP_FEATURE_FREEBSD)
  564.  void
  565.  os_restore_fp_control(os_context_t *context)
  566. diff --git a/src/runtime/x86-64-bsd-os.h b/src/runtime/x86-64-bsd-os.h
  567. index 9db3ae7..789748b 100644
  568. --- a/src/runtime/x86-64-bsd-os.h
  569. +++ b/src/runtime/x86-64-bsd-os.h
  570. @@ -5,6 +5,10 @@
  571.  #include <machine/fpu.h>
  572.  #endif
  573.  
  574. +#ifdef LISP_FEATURE_DRAGONFLY
  575. +#include <machine/npx.h>
  576. +#endif
  577. +
  578.  typedef register_t os_context_register_t;
  579.  
  580.  static inline os_context_t *arch_os_get_context(void **void_context)
  581. @@ -16,7 +20,7 @@ static inline os_context_t *arch_os_get_context(void **void_context)
  582.   * store signal context information, but at least they tend to use the
  583.   * same stems to name the structure fields, so by using this macro we
  584.   * can share a fair amount of code between different variants. */
  585. -#if defined __FreeBSD__
  586. +#if defined(__FreeBSD__) || defined(__DragonFly__)
  587.  #define CONTEXT_ADDR_FROM_STEM(stem) &context->uc_mcontext.mc_ ## stem
  588.  #elif defined(__OpenBSD__)
  589.  #define CONTEXT_ADDR_FROM_STEM(stem) &context->sc_ ## stem
  590. @@ -26,6 +30,20 @@ static inline os_context_t *arch_os_get_context(void **void_context)
  591.  #error unsupported BSD variant
  592.  #endif
  593.  
  594. +#if defined LISP_FEATURE_DRAGONFLY
  595. +#define RESTORE_FP_CONTROL_FROM_CONTEXT
  596. +void os_restore_fp_control(os_context_t *context);
  597. +
  598. +#define X86_64_SIGFPE_FIXUP
  599. +
  600. +static inline unsigned int *
  601. +arch_os_context_mxcsr_addr(os_context_t *context)
  602. +{
  603. +    struct envxmm *ex = (struct envxmm *)(&context->uc_mcontext.mc_fpregs);
  604. +    return &ex->en_mxcsr;
  605. +}
  606. +#endif
  607. +
  608.  #if defined LISP_FEATURE_FREEBSD
  609.  #define RESTORE_FP_CONTROL_FROM_CONTEXT
  610.  void os_restore_fp_control(os_context_t *context);
  611. diff --git a/src/runtime/x86-arch.c b/src/runtime/x86-arch.c
  612. index dfbf908..59ecf92 100644
  613. --- a/src/runtime/x86-arch.c
  614. +++ b/src/runtime/x86-arch.c
  615. @@ -68,7 +68,7 @@ context_eflags_addr(os_context_t *context)
  616.       * we need to do this nasty absolute index magic number thing
  617.       * instead. */
  618.      return &context->uc_mcontext.gregs[16];
  619. -#elif defined __FreeBSD__
  620. +#elif defined(__FreeBSD__) || defined(__DragonFly__)
  621.      return &context->uc_mcontext.mc_eflags;
  622.  #elif defined __OpenBSD__
  623.      return &context->sc_eflags;
  624. diff --git a/src/runtime/x86-assem.S b/src/runtime/x86-assem.S
  625. index fba970b..024e137 100644
  626. --- a/src/runtime/x86-assem.S
  627. +++ b/src/runtime/x86-assem.S
  628. @@ -32,7 +32,7 @@
  629.   *
  630.   * (Except Win32, which is unlikely ever to be ELF, sorry. -- AB 2005-12-08)
  631.   */
  632. -#if defined __linux__  || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ || defined __sun
  633. +#if defined __linux__  || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ || defined __sun || defined __DragonFly__
  634.  #define GNAME(var) var
  635.  #else
  636.  #define GNAME(var) _##var
  637. @@ -47,7 +47,7 @@
  638.   * matter any more, perhaps it's just clutter we could get
  639.   * rid of? -- WHN 2004-04-18)
  640.   */
  641. -#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun) || defined(LISP_FEATURE_WIN32)
  642. +#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun) || defined(LISP_FEATURE_WIN32) || defined(__Dragonfly__)
  643.  #define align_4byte    4
  644.  #define align_8byte    8
  645.  #define align_16byte   16
  646. @@ -131,7 +131,7 @@
  647.  # define LoadCurrentThreadSlot(offset,reg);     \
  648.     movl    SBCL_THREAD_BASE_EA, reg ;      \
  649.     movl    offset(reg), reg ;
  650. -#elif defined(LISP_FEATURE_LINUX) || defined(LISP_FEATURE_SUNOS) || defined(LISP_FEATURE_FREEBSD)
  651. +#elif defined(LISP_FEATURE_LINUX) || defined(LISP_FEATURE_SUNOS) || defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DRAGONFLY)
  652.    /* see comment in arch_os_thread_init */
  653.  # define SBCL_THREAD_BASE_EA %fs:THREAD_SELFPTR_OFFSET
  654.  # define MAYBE_FS(addr) addr
  655. diff --git a/src/runtime/x86-bsd-os.c b/src/runtime/x86-bsd-os.c
  656. index fe75566..4f985fe 100644
  657. --- a/src/runtime/x86-bsd-os.c
  658. +++ b/src/runtime/x86-bsd-os.c
  659. @@ -16,7 +16,7 @@
  660.  #endif /* LISP_FEATURE_DARWIN */
  661.  #endif
  662.  
  663. -#if defined(LISP_FEATURE_FREEBSD)
  664. +#if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DRAGONFLY)
  665.  #include "machine/npx.h"
  666.  #endif
  667.  
  668. @@ -40,7 +40,7 @@
  669.   * entails; unfortunately, currently the situation is worse, not
  670.   * better, than in the above paragraph. */
  671.  
  672. -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(LISP_FEATURE_DARWIN)
  673. +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(LISP_FEATURE_DARWIN) || defined(__DragonFly__)
  674.  int *
  675.  os_context_register_addr(os_context_t *context, int offset)
  676.  {
  677. @@ -72,7 +72,7 @@ os_context_sp_addr(os_context_t *context)
  678.      return (int *)CONTEXT_ADDR_FROM_STEM(esp);
  679.  }
  680.  
  681. -#endif /* __FreeBSD__ || __OpenBSD__ */
  682. +#endif /* __FreeBSD__ || __OpenBSD__ || __DragonFly__ */
  683.  
  684.  #ifdef __NetBSD__
  685.  int *
  686. @@ -112,7 +112,7 @@ os_context_sp_addr(os_context_t *context)
  687.  
  688.  int *os_context_pc_addr(os_context_t *context)
  689.  {
  690. -#if defined __FreeBSD__
  691. +#if defined(__FreeBSD__) || defined(__DragonFly__)
  692.      return CONTEXT_ADDR_FROM_STEM(eip);
  693.  #elif defined __OpenBSD__
  694.      return CONTEXT_ADDR_FROM_STEM(pc);
  695. @@ -264,6 +264,14 @@ os_restore_fp_control(os_context_t *context)
  696.  }
  697.  #endif
  698.  
  699. +#if defined(LISP_FEATURE_DRAGONFLY)
  700. +void os_restore_fp_control (os_context_t *context)
  701. +{
  702. +    struct envxmm *ex = (struct envxmm *)(context->uc_mcontext.mc_fpregs);
  703. +    __asm__ __volatile__ ("fldcw %0" : : "m" (ex->en_cw));
  704. +}
  705. +#endif /* LISP_FEATURE_DRAGONFLY */
  706. +
  707.  #if defined(LISP_FEATURE_OPENBSD)
  708.  void
  709.  os_restore_fp_control(os_context_t *context)
  710. diff --git a/src/runtime/x86-bsd-os.h b/src/runtime/x86-bsd-os.h
  711. index dc9d9f7..2ae7d61 100644
  712. --- a/src/runtime/x86-bsd-os.h
  713. +++ b/src/runtime/x86-bsd-os.h
  714. @@ -1,7 +1,7 @@
  715.  #ifndef _X86_BSD_OS_H
  716.  #define _X86_BSD_OS_H
  717.  
  718. -#ifdef LISP_FEATURE_FREEBSD
  719. +#if defined(LISP_FEATURE_FREEBSD) || defined(LISP_FEATURE_DRAGONFLY)
  720.  #include <machine/segments.h>
  721.  #include <machine/cpufunc.h>
  722.  #endif
  723. @@ -17,7 +17,7 @@ static inline os_context_t *arch_os_get_context(void **void_context)
  724.   * store signal context information, but at least they tend to use the
  725.   * same stems to name the structure fields, so by using this macro we
  726.   * can share a fair amount of code between different variants. */
  727. -#if defined __FreeBSD__
  728. +#if defined(__FreeBSD__) || defined(__DragonFly__)
  729.  #define CONTEXT_ADDR_FROM_STEM(stem) &context->uc_mcontext.mc_ ## stem
  730.  #elif defined(__OpenBSD__)
  731.  #define CONTEXT_ADDR_FROM_STEM(stem) &context->sc_ ## stem
  732. @@ -35,7 +35,7 @@ void os_restore_tls_segment_register(os_context_t *context);
  733.  void os_restore_fp_control(os_context_t *context);
  734.  #endif
  735.  
  736. -#if defined LISP_FEATURE_OPENBSD
  737. +#if defined(LISP_FEATURE_OPENBSD) || defined(LISP_FEATURE_DRAGONFLY)
  738.  #define RESTORE_FP_CONTROL_FROM_CONTEXT
  739.  void os_restore_fp_control(os_context_t *context);
  740.  #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement