From daa432a5e6de0abafe55a565bf53ddfb0f9215be Mon Sep 17 00:00:00 2001
From: rswindells <rswindells>
Date: Fri, 16 May 2008 13:30:22 +0000
Subject: [PATCH] Make it build again for NetBSD.

---
 lisp/NetBSD-os.c | 54 +++++++++++++++++++++++++++---------------------
 lisp/NetBSD-os.h | 13 ++++++++----
 lisp/elf.h       |  4 ++--
 3 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/lisp/NetBSD-os.c b/lisp/NetBSD-os.c
index f26155701..07546ee5f 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.8 2007/11/16 06:31:54 cshapiro Exp $
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/NetBSD-os.c,v 1.9 2008/05/16 13:30:21 rswindells Exp $
  *
  */
 
@@ -52,30 +52,38 @@ os_init(void)
     os_vm_page_size = OS_VM_DEFAULT_PAGESIZE;
 }
 
-int *
-sc_reg(os_context_t * c, int offset)
+unsigned long *
+os_sigcontext_reg(ucontext_t *scp, int index)
 {
 #ifdef i386
-    switch (offset) {
-      case 0:
-	  return &c->uc_mcontext.__gregs[_REG_EAX];
-      case 2:
-	  return &c->uc_mcontext.__gregs[_REG_ECX];
-      case 4:
-	  return &c->uc_mcontext.__gregs[_REG_EDX];
-      case 6:
-	  return &c->uc_mcontext.__gregs[_REG_EBX];
-      case 8:
-	  return &c->uc_mcontext.__gregs[_REG_ESP];
-      case 10:
-	  return &c->uc_mcontext.__gregs[_REG_EBP];
-      case 12:
-	  return &c->uc_mcontext.__gregs[_REG_ESI];
-      case 14:
-	  return &c->uc_mcontext.__gregs[_REG_EDI];
+    switch (index) {
+    case 0:
+	return (unsigned long *) &scp->uc_mcontext.__gregs[_REG_EAX];
+    case 2:
+	return (unsigned long *) &scp->uc_mcontext.__gregs[_REG_ECX];
+    case 4:
+	return (unsigned long *) &scp->uc_mcontext.__gregs[_REG_EDX];
+    case 6:
+	return (unsigned long *) &scp->uc_mcontext.__gregs[_REG_EBX];
+    case 8:
+	return (unsigned long *) &scp->uc_mcontext.__gregs[_REG_ESP];
+    case 10:
+	return (unsigned long *) &scp->uc_mcontext.__gregs[_REG_EBP];
+    case 12:
+	return (unsigned long *) &scp->uc_mcontext.__gregs[_REG_ESI];
+    case 14:
+	return (unsigned long *) &scp->uc_mcontext.__gregs[_REG_EDI];
     }
 #endif
-    return (int *) 0;
+    return NULL;
+}
+
+unsigned long *
+os_sigcontext_pc(ucontext_t *scp)
+{
+#ifdef i386
+    return (unsigned long *) &scp->uc_mcontext.__gregs[_REG_EIP];
+#endif
 }
 
 os_vm_address_t
@@ -85,9 +93,7 @@ os_validate(os_vm_address_t addr, os_vm_size_t len)
 
     /*
      * NetBSD 1.5.2 seems to insist on each mmap being less than 128MB.
-     * So we mmap in 64MB steps.  This is probably inefficient, but the
-     * missing CR2 reporting in signal handlers already ensures that
-     * NetBSD/x86 is not a suitable platform for CMU CL as it stands.
+     * So we mmap in 64MB steps.
      */
 
     if (addr)
diff --git a/lisp/NetBSD-os.h b/lisp/NetBSD-os.h
index 562289b94..ed0e454ad 100644
--- a/lisp/NetBSD-os.h
+++ b/lisp/NetBSD-os.h
@@ -1,6 +1,6 @@
 /*
 
- $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/NetBSD-os.h,v 1.7 2007/06/12 03:21:46 cshapiro Exp $
+ $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/NetBSD-os.h,v 1.8 2008/05/16 13:30:22 rswindells Exp $
 
  This code was written as part of the CMU Common Lisp project at
  Carnegie Mellon University, and has been placed in the public domain.
@@ -10,27 +10,32 @@
 #ifndef _NETBSD_OS_H_
 #define _NETBSD_OS_H_
 
+#include <sys/param.h>
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <sys/signal.h>
 #include <ucontext.h>
+#include <string.h>
+#include <unistd.h>
 
 typedef caddr_t os_vm_address_t;
 typedef size_t os_vm_size_t;
 typedef off_t os_vm_offset_t;
 typedef int os_vm_prot_t;
+#define os_context_t ucontext_t
 
 #define OS_VM_PROT_READ PROT_READ
 #define OS_VM_PROT_WRITE PROT_WRITE
 #define OS_VM_PROT_EXECUTE PROT_EXEC
 
+#if defined(sparc)
+#define OS_VM_DEFAULT_PAGESIZE	8192
+#else
 #define OS_VM_DEFAULT_PAGESIZE	4096
+#endif
 
 #define HANDLER_ARGS int signal, siginfo_t *code, ucontext_t *context
 #define CODE(code)  ((code) ? code->si_code : 0)
-#define os_context_t ucontext_t
-
-int *sc_reg(ucontext_t *, int);
 
 #define PROTECTION_VIOLATION_SIGNAL SIGSEGV
 
diff --git a/lisp/elf.h b/lisp/elf.h
index 937a5da1b..b34acd2f4 100644
--- a/lisp/elf.h
+++ b/lisp/elf.h
@@ -1,4 +1,4 @@
-/* $Id: elf.h,v 1.8 2007/08/14 15:57:47 rtoy Exp $ */
+/* $Id: elf.h,v 1.9 2008/05/16 13:30:22 rswindells Exp $ */
 
 /* This code was written by Fred Gilham and has been placed in the public domain.  It is
    provided "AS-IS" and without warranty of any kind.
@@ -33,7 +33,7 @@ int elf_run_linker(long, char *);
 
 void map_core_sections(char *);
 
-#if defined(SOLARIS) || defined(linux)
+#if defined(SOLARIS) || defined(linux) || defined(__NetBSD__)
 typedef Elf32_Ehdr Elf_Ehdr;
 typedef Elf32_Shdr Elf_Shdr;
 typedef Elf32_Word Elf_Word;
-- 
GitLab