From aa9c2237859d9191f449cfc1345ccbb11310113e Mon Sep 17 00:00:00 2001
From: rswindells <rswindells>
Date: Sun, 26 Dec 2010 16:04:43 +0000
Subject: [PATCH] Add a test for whether the operating system supports use of
 the SSE2 registers. The test is a stub on everything except NetBSD for now.

---
 lisp/Darwin-os.c  | 10 +++++++++-
 lisp/FreeBSD-os.c | 11 ++++++++++-
 lisp/Linux-os.c   | 10 +++++++++-
 lisp/NetBSD-os.c  | 18 +++++++++++++++++-
 lisp/lisp.c       |  6 +++---
 lisp/os.h         |  6 +++++-
 lisp/solaris-os.c |  8 +++++++-
 lisp/x86-arch.c   |  4 ++--
 8 files changed, 62 insertions(+), 11 deletions(-)

diff --git a/lisp/Darwin-os.c b/lisp/Darwin-os.c
index e496fbcc0..17944c1ee 100644
--- a/lisp/Darwin-os.c
+++ b/lisp/Darwin-os.c
@@ -14,7 +14,7 @@
  * Frobbed for OpenBSD by Pierre R. Mai, 2001.
  * Frobbed for Darwin by Pierre R. Mai, 2003.
  *
- * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Darwin-os.c,v 1.30 2010/06/22 16:55:17 rtoy Rel $
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Darwin-os.c,v 1.31 2010/12/26 16:04:43 rswindells Exp $
  *
  */
 
@@ -523,3 +523,11 @@ os_dlsym(const char *sym_name, lispobj lib_list)
 
     return sym_addr;
 }
+
+#ifdef i386
+boolean
+os_support_sse2()
+{
+    return TRUE;
+}
+#endif
diff --git a/lisp/FreeBSD-os.c b/lisp/FreeBSD-os.c
index 292277ff1..1e91906f4 100644
--- a/lisp/FreeBSD-os.c
+++ b/lisp/FreeBSD-os.c
@@ -12,7 +12,7 @@
  * Much hacked by Paul Werkowski
  * GENCGC support by Douglas Crosher, 1996, 1997.
  *
- * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/FreeBSD-os.c,v 1.36 2010/09/08 03:28:08 agoncharov Rel $
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/FreeBSD-os.c,v 1.37 2010/12/26 16:04:43 rswindells Exp $
  *
  */
 
@@ -356,3 +356,12 @@ restore_fpu(ucontext_t *scp)
     }
 #endif
 }
+
+#ifdef i386
+boolean
+os_support_sse2()
+{
+    return TRUE;
+}
+#endif
+
diff --git a/lisp/Linux-os.c b/lisp/Linux-os.c
index 1d7deb13a..3e3df735e 100644
--- a/lisp/Linux-os.c
+++ b/lisp/Linux-os.c
@@ -15,7 +15,7 @@
  * GENCGC support by Douglas Crosher, 1996, 1997.
  * Alpha support by Julian Dolby, 1999.
  *
- * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Linux-os.c,v 1.50 2010/06/22 16:55:17 rtoy Rel $
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/Linux-os.c,v 1.51 2010/12/26 16:04:43 rswindells Exp $
  *
  */
 
@@ -537,3 +537,11 @@ restore_fpu(ucontext_t *context)
 #endif        
     }
 }
+
+#ifdef i386
+boolean
+os_support_sse2()
+{
+    return TRUE;
+}
+#endif
diff --git a/lisp/NetBSD-os.c b/lisp/NetBSD-os.c
index 6708d5369..df268cd03 100644
--- a/lisp/NetBSD-os.c
+++ b/lisp/NetBSD-os.c
@@ -15,7 +15,7 @@
  * Frobbed for OpenBSD by Pierre R. Mai, 2001.
  * Frobbed for NetBSD by Pierre R. Mai, 2002.
  *
- * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/NetBSD-os.c,v 1.18 2010/12/23 17:38:05 rtoy Exp $
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/NetBSD-os.c,v 1.19 2010/12/26 16:04:43 rswindells Exp $
  *
  */
 
@@ -36,6 +36,7 @@
 /* #include <sys/sysinfo.h> */
 #include <sys/proc.h>
 #include <dlfcn.h>
+#include <sys/sysctl.h>
 #include "validate.h"
 size_t os_vm_page_size;
 
@@ -409,3 +410,18 @@ restore_fpu(ucontext_t *scp)
 	__asm__ __volatile__ ("ldmxcsr %0"::"m"(*&mxcsr));
     }
 }
+
+#ifdef i386
+boolean
+os_support_sse2()
+{
+    int support_sse2;
+    size_t len;
+
+    if (sysctlbyname("machdep.sse2", &support_sse2, &len,
+		     NULL, 0) == 0 && support_sse2 != 0)
+	return TRUE;
+    else
+	return FALSE;
+}
+#endif
diff --git a/lisp/lisp.c b/lisp/lisp.c
index 7c6f56add..a808f48ae 100644
--- a/lisp/lisp.c
+++ b/lisp/lisp.c
@@ -1,7 +1,7 @@
 /*
  * main() entry point for a stand alone lisp image.
  *
- * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/lisp.c,v 1.80 2010/12/23 03:20:27 rtoy Exp $
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/lisp.c,v 1.81 2010/12/26 16:04:43 rswindells Exp $
  *
  */
 
@@ -715,8 +715,8 @@ main(int argc, const char *argv[], const char *envp[])
     }
 
 #ifdef i386
-    if ((fpu_type == SSE2) && !arch_support_sse2()) {
-	fprintf(stderr, "Core uses SSE2, but CPU doesn't support SSE2.  Exiting\n");
+    if ((fpu_type == SSE2) && (!arch_support_sse2() || !os_support_sse2())) {
+	fprintf(stderr, "Core uses SSE2, but CPU/OS doesn't support SSE2.  Exiting\n");
 	exit(1);
     }
     fpu_mode = fpu_type;
diff --git a/lisp/os.h b/lisp/os.h
index 6a63808ca..9a2a8fd46 100644
--- a/lisp/os.h
+++ b/lisp/os.h
@@ -1,5 +1,5 @@
 /*
- * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/os.h,v 1.26 2010/02/01 17:38:48 rtoy Rel $
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/os.h,v 1.27 2010/12/26 16:04:43 rswindells Exp $
  *
  * Common interface for os-dependent functions.
  *
@@ -115,6 +115,10 @@ unsigned long *os_sigcontext_pc(ucontext_t *);
 unsigned char *os_sigcontext_fpu_reg(ucontext_t *, int);
 unsigned int os_sigcontext_fpu_modes(ucontext_t *);
 
+#ifdef i386
+extern boolean os_support_sse2(void);
+#endif
+
 char* convert_lisp_string(char* c_string, void* lisp_string, int len);
 
 #endif /* _OS_H_ */
diff --git a/lisp/solaris-os.c b/lisp/solaris-os.c
index a639875bc..140e5db54 100644
--- a/lisp/solaris-os.c
+++ b/lisp/solaris-os.c
@@ -1,5 +1,5 @@
 /*
- * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/solaris-os.c,v 1.28 2010/12/23 23:02:58 rtoy Exp $
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/solaris-os.c,v 1.29 2010/12/26 16:04:43 rswindells Exp $
  *
  * OS-dependent routines.  This file (along with os.h) exports an
  * OS-independent interface to the operating system VM facilities.
@@ -609,4 +609,10 @@ os_sigcontext_fpu_modes(ucontext_t *scp)
     modes ^= (0x3f << 7);
     return modes;
 }
+
+boolean
+os_support_sse2()
+{
+    return TRUE;
+}
 #endif
diff --git a/lisp/x86-arch.c b/lisp/x86-arch.c
index 2d99467cb..474fb875b 100644
--- a/lisp/x86-arch.c
+++ b/lisp/x86-arch.c
@@ -1,6 +1,6 @@
 /* x86-arch.c -*- Mode: C; comment-column: 40 -*-
  *
- * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-arch.c,v 1.42 2010/12/23 22:55:31 rtoy Exp $ 
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-arch.c,v 1.43 2010/12/26 16:04:43 rswindells Exp $ 
  *
  */
 
@@ -105,7 +105,7 @@ arch_init(fpu_mode_t mode)
 {
     int have_sse2;
 
-    have_sse2 = arch_support_sse2();
+    have_sse2 = arch_support_sse2() && os_support_sse2();
     
     switch (mode) {
       case AUTO:
-- 
GitLab