From 4ea11535ee62950e5305928c61bda869367c1b5e Mon Sep 17 00:00:00 2001
From: pmai <pmai>
Date: Mon, 28 Jan 2002 20:17:12 +0000
Subject: [PATCH] Added specialised port to NetBSD (1.5.2) on x86.  Since the
 code-base was already cleaned up with the OpenBSD port, this doesn't require
 massive changes.

Since current NetBSD is ELF-based by default, we don't make use of the
ELF feature, or in other words:  The presence of the NetBSD feature
implies ELF, since there is no support for non-ELF NetBSD.
---
 code/bsd-os.lisp                  |  6 +++--
 code/foreign.lisp                 | 16 +++++++------
 code/x86-vm.lisp                  | 32 ++++++++++++++++++++++++--
 compiler/generic/new-genesis.lisp |  7 +++---
 lisp/Config.NetBSD                | 19 ++++++++++++++++
 lisp/Config.NetBSD_gencgc         | 19 ++++++++++++++++
 lisp/NetBSD-os.h                  | 37 +++++++++++++++++++++++++++++++
 lisp/lisp.h                       |  4 ++--
 lisp/os.h                         |  6 ++++-
 lisp/undefineds.h                 | 14 ++++++------
 lisp/x86-arch.c                   |  6 ++---
 lisp/x86-assem.S                  |  4 ++--
 lisp/x86-validate.h               |  6 ++---
 motif/server/Config.NetBSD        |  7 ++++++
 14 files changed, 151 insertions(+), 32 deletions(-)
 create mode 100644 lisp/Config.NetBSD
 create mode 100644 lisp/Config.NetBSD_gencgc
 create mode 100644 lisp/NetBSD-os.h
 create mode 100644 motif/server/Config.NetBSD

diff --git a/code/bsd-os.lisp b/code/bsd-os.lisp
index e549101ec..a7a7546f7 100644
--- a/code/bsd-os.lisp
+++ b/code/bsd-os.lisp
@@ -5,7 +5,7 @@
 ;;; Carnegie Mellon University, and has been placed in the public domain.
 ;;;
 (ext:file-comment
-  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/bsd-os.lisp,v 1.4 2001/12/06 19:15:40 pmai Exp $")
+  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/bsd-os.lisp,v 1.5 2002/01/28 20:17:08 pmai Exp $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -16,6 +16,7 @@
 ;;;
 ;;; Hacked into (Free)bsd-os.lisp by Paul Werkowski.
 ;;; Generalized a bit for OpenBSD by Pierre R. Mai.
+;;; Support for NetBSD by Pierre R. Mai.
 
 (in-package "SYSTEM")
 (use-package "EXTENSIONS")
@@ -24,8 +25,9 @@
 (pushnew :bsd *features*)
 
 (setq *software-type* #+OpenBSD "OpenBSD"
+                      #+NetBSD "NetBSD"
                       #+FreeBSD "FreeBSD"
-		      #-(or FreeBSD OpenBSD) "BSD")
+		      #-(or FreeBSD NetBSD OpenBSD) "BSD")
 
 (defvar *software-version* nil "Version string for supporting software")
 
diff --git a/code/foreign.lisp b/code/foreign.lisp
index da348e77c..71c3927ae 100644
--- a/code/foreign.lisp
+++ b/code/foreign.lisp
@@ -5,7 +5,7 @@
 ;;; Carnegie Mellon University, and has been placed in the public domain.
 ;;;
 (ext:file-comment
-  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/foreign.lisp,v 1.35 2001/12/06 19:15:41 pmai Exp $")
+  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/foreign.lisp,v 1.36 2002/01/28 20:17:09 pmai Exp $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -89,7 +89,7 @@
 ;;; The following definitions are taken from
 ;;; /usr/include/sys/elf_common.h and /usr/include/sys/elf32.h.
 ;;;
-#+(and FreeBSD elf)
+#+(or NetBSD (and FreeBSD elf))
 (progn
 (alien:def-alien-type elf-address      (alien:unsigned 32))
 (alien:def-alien-type elf-half-word    (alien:unsigned 16))
@@ -183,10 +183,12 @@
 	  (unless (elf-p (alien:slot header 'elf-ident))
 	      (error (format nil "~A is not an ELF file." name)))
 
-	  (let ((brand (elf-brand (alien:slot header 'elf-ident))))
-	    (unless (string= brand "FreeBSD" :end1 6 :end2 6)
-	      (error (format nil "~A is not a FreeBSD executable. Brand: ~A"
-			     name brand))))
+	  #-NetBSD
+	  (let ((brand (elf-brand (alien:slot header 'elf-ident)))
+		(correct-brand #+NetBSD "NetBSD" #+FreeBSD "FreeBSD"))
+	    (unless (string= brand correct-brand :end1 (length correct-brand))
+	      (error (format nil "~A is not a ~A executable. Brand: ~A"
+			     name correct-brand brand))))
 
 	  (unless (elf-executable-p (alien:slot header 'elf-type))
 	    (error (format nil "~A is not executable." name)))
@@ -436,7 +438,7 @@ to skip undefined symbols which don't have an address."
             ))
       (unix:unix-close fd))))
 
-#-(or linux solaris irix (and FreeBSD elf))
+#-(or linux solaris irix NetBSD (and FreeBSD elf))
 (defun parse-symbol-table (name)
   (format t ";;; Parsing symbol table...~%")
   (let ((symbol-table (make-hash-table :test #'equal)))
diff --git a/code/x86-vm.lisp b/code/x86-vm.lisp
index 6c0a9c1f4..81dd39204 100644
--- a/code/x86-vm.lisp
+++ b/code/x86-vm.lisp
@@ -7,7 +7,7 @@
 ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
 ;;;
 (ext:file-comment
-  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/x86-vm.lisp,v 1.17 2001/12/06 19:15:41 pmai Exp $")
+  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/x86-vm.lisp,v 1.18 2002/01/28 20:17:09 pmai Exp $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -103,7 +103,7 @@
 	(sc-sp      unsigned-int)	
 	(sc-ss	    unsigned-int)))
 
-;;; OpenBSD also has a sigcontext that looks more like Linux.
+;;; OpenBSD/NetBSD also have sigcontext structs that look more like Linux.
 #+openbsd
 (def-alien-type sigcontext
     (struct nil
@@ -129,6 +129,34 @@
 	(sc-err     unsigned-int)
 	))
 
+#+netbsd
+(def-alien-type sigcontext
+    (struct nil
+	(sc-gs      unsigned-int)
+	(sc-fs      unsigned-int)
+	(sc-es	    unsigned-int)
+	(sc-ds	    unsigned-int)
+	(sc-edi	    unsigned-int)
+	(sc-esi	    unsigned-int)
+	(sc-fp	    unsigned-int) ;; ebp
+	(sc-ebx	    unsigned-int)
+	(sc-edx	    unsigned-int)
+	(sc-ecx	    unsigned-int)
+	(sc-eax	    unsigned-int)
+	(sc-pc      unsigned-int)
+	(sc-cs	    unsigned-int)
+	(sc-efl     unsigned-int)		; sc_ps
+	(sc-sp      unsigned-int)	
+	(sc-ss	    unsigned-int)
+	(sc-onstack unsigned-int)
+	;; Old NetBSD 1.3 signal mask
+	(sc-oldmask unsigned-int)
+	(sc-trapno  unsigned-int)
+	(sc-err     unsigned-int)
+	;; New signal mask (post NetBSD 1.3)
+	(sc-mask    (array unsigned-int 4))
+	))
+
 ;; For Linux...
 #+linux
 (def-alien-type sigcontext
diff --git a/compiler/generic/new-genesis.lisp b/compiler/generic/new-genesis.lisp
index 1de8b6f4c..217631db5 100644
--- a/compiler/generic/new-genesis.lisp
+++ b/compiler/generic/new-genesis.lisp
@@ -4,7 +4,7 @@
 ;;; Carnegie Mellon University, and has been placed in the public domain.
 ;;;
 (ext:file-comment
-  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/generic/new-genesis.lisp,v 1.42 2001/12/06 19:15:42 pmai Exp $")
+  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/generic/new-genesis.lisp,v 1.43 2002/01/28 20:17:09 pmai Exp $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -1861,9 +1861,10 @@
 		       "_"))
 		  (#.c:x86-fasl-file-implementation
 		   (if (and (c:backend-featurep :bsd)
-			    (not (c:backend-featurep :elf)))
+			    (not (c:backend-featurep :elf))
+			    (not (c:backend-featurep :netbsd)))
 		       "_" ; older FreeBSD, OpenBSD
-		       "")) ; Linux and FreeBSD V3+
+		       "")) ; Linux and ELF FreeBSD V3+, NetBSD
 		  )
 		name)))
 
diff --git a/lisp/Config.NetBSD b/lisp/Config.NetBSD
new file mode 100644
index 000000000..74cb5eced
--- /dev/null
+++ b/lisp/Config.NetBSD
@@ -0,0 +1,19 @@
+PATH1 = ../../src/lisp
+PATH2 = ../../p86/lisp
+vpath %.h $(PATH2):$(PATH1)
+vpath %.c $(PATH2):$(PATH1)
+vpath %.S $(PATH2):$(PATH1)
+CPPFLAGS = -I. -I$(PATH2) -I$(PATH1) -I- -I/usr/X11R6/include
+CC = gcc
+LD = ld
+CPP = cpp
+CFLAGS = -Wstrict-prototypes -Wall -O2 -g -DWANT_CGC -Di386
+ASFLAGS = -g -DWANT_CGC -Di386
+NM = nm -gp
+UNDEFSYMPATTERN = -Xlinker -u -Xlinker &
+ASSEM_SRC = x86-assem.S
+ARCH_SRC = x86-arch.c
+OS_SRC = NetBSD-os.c os-common.c undefineds.c
+OS_LINK_FLAGS = -static
+OS_LIBS =
+GC_SRC = cgc.c
diff --git a/lisp/Config.NetBSD_gencgc b/lisp/Config.NetBSD_gencgc
new file mode 100644
index 000000000..f6bf462ec
--- /dev/null
+++ b/lisp/Config.NetBSD_gencgc
@@ -0,0 +1,19 @@
+PATH1 = ../../src/lisp
+PATH2 = ../../p86/lisp
+vpath %.h $(PATH2):$(PATH1)
+vpath %.c $(PATH2):$(PATH1)
+vpath %.S $(PATH2):$(PATH1)
+CPPFLAGS = -I. -I$(PATH2) -I$(PATH1) -I- -I/usr/X11R6/include
+CC = gcc
+LD = ld
+CPP = cpp
+CFLAGS = -Wstrict-prototypes -Wall -O2 -g -DGENCGC -Di386
+ASFLAGS = -g -DGENCGC -Di386
+NM = nm -gp
+UNDEFSYMPATTERN = -Xlinker -u -Xlinker &
+ASSEM_SRC = x86-assem.S
+ARCH_SRC = x86-arch.c
+OS_SRC = NetBSD-os.c os-common.c undefineds.c
+OS_LINK_FLAGS = -static
+OS_LIBS =
+GC_SRC = gencgc.c
diff --git a/lisp/NetBSD-os.h b/lisp/NetBSD-os.h
new file mode 100644
index 000000000..5bc341bb4
--- /dev/null
+++ b/lisp/NetBSD-os.h
@@ -0,0 +1,37 @@
+/*
+
+ $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/NetBSD-os.h,v 1.1 2002/01/28 20:17:11 pmai 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.
+
+*/
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/signal.h>
+
+#define MAP_ANONYMOUS MAP_ANON
+#define MAP_VARIABLE 0
+
+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_VM_PROT_READ PROT_READ
+#define OS_VM_PROT_WRITE PROT_WRITE
+#define OS_VM_PROT_EXECUTE PROT_EXEC
+
+#define OS_VM_DEFAULT_PAGESIZE	4096
+
+#define POSIX_SIGS
+/* NetBSD 1.5.2 doesn't have this yet */
+#define USE_SA_SIGINFO 0
+
+#ifndef sa_sigaction
+#define sa_sigaction    sa_handler
+#endif
+
+#define uc_sigmask sc_mask
+int sc_reg(struct sigcontext*,int);
diff --git a/lisp/lisp.h b/lisp/lisp.h
index 5145ec9cc..7a335bdb8 100644
--- a/lisp/lisp.h
+++ b/lisp/lisp.h
@@ -1,4 +1,4 @@
-/* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/lisp.h,v 1.7 2001/12/06 19:15:45 pmai Exp $ */
+/* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/lisp.h,v 1.8 2002/01/28 20:17:11 pmai Exp $ */
 
 #ifndef _LISP_H_
 #define _LISP_H_
@@ -21,7 +21,7 @@
 #if !defined alpha
 typedef unsigned long lispobj;
 
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__)
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__linux__)
 typedef unsigned int u32;
 typedef signed int s32;
 #endif
diff --git a/lisp/os.h b/lisp/os.h
index 800ab331a..8c14ed6ab 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.8 2001/12/06 19:15:45 pmai Exp $
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/os.h,v 1.9 2002/01/28 20:17:11 pmai Exp $
  *
  * Common interface for os-dependent functions.
  *
@@ -32,6 +32,9 @@
 #ifdef __OpenBSD__
 #include "OpenBSD-os.h"
 #else
+#ifdef __NetBSD__
+#include "NetBSD-os.h"
+#else
 #ifdef __linux__
 #include "Linux-os.h"
 #endif
@@ -42,6 +45,7 @@
 #endif
 #endif
 #endif
+#endif
 
 #ifndef HANDLER_ARGS
 #define HANDLER_ARGS int signal, int code, struct sigcontext *context
diff --git a/lisp/undefineds.h b/lisp/undefineds.h
index ff5b9199b..46a43dfbd 100644
--- a/lisp/undefineds.h
+++ b/lisp/undefineds.h
@@ -1,5 +1,5 @@
 /* Routines that must be linked into the core for lisp to work. */
-/* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/undefineds.h,v 1.24 2001/12/06 19:15:45 pmai Exp $ */
+/* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/undefineds.h,v 1.25 2002/01/28 20:17:11 pmai Exp $ */
 
 /* Pick up all the syscalls. */
 F(accept)
@@ -10,7 +10,7 @@ F(adjtime)
 #endif
 F(bind)
 F(brk)
-#if defined(hpux) || defined(SVR4) || defined(__FreeBSD__) || defined(__OpenBSD__)
+#if defined(hpux) || defined(SVR4) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 F(cfgetospeed)
 F(cfsetospeed)
 F(cfgetispeed)
@@ -116,7 +116,7 @@ F(setpgrp)
 #if !defined(SVR4) ||  defined(SOLARIS25)
 F(setpriority)
 #endif
-#if !defined(mach) && !defined(SOLARIS) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(SUNOS) && !defined(osf1) && !defined(irix) && !defined(hpux) && !(defined(linux) && defined(alpha))
+#if !defined(mach) && !defined(SOLARIS) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(SUNOS) && !defined(osf1) && !defined(irix) && !defined(hpux) && !(defined(linux) && defined(alpha))
 F(setquota)
 #endif
 #if !defined(hpux) && !defined(SVR4) ||  defined(SOLARIS25)
@@ -134,7 +134,7 @@ F(sigpause)
 #if !defined(ibmrt) && !defined(hpux) && !defined(SVR4) && !defined(i386)
 F(sigreturn)
 #endif
-#if !defined(SVR4) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
+#if !defined(SVR4) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
 F(sigsetmask)
 F(sigstack)
 F(sigvec)
@@ -153,7 +153,7 @@ F(closedir)
 F(opendir)
 F(readdir)
 #endif
-#if defined(hpux) || defined(SVR4) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__linux__)
+#if defined(hpux) || defined(SVR4) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__linux__)
 F(tcgetattr)
 F(tcsetattr)
 F(tcsendbreak)
@@ -167,7 +167,7 @@ F(times)
 F(truncate)
 F(umask)
 #if !defined(SUNOS) && !defined(parisc) && !defined(SOLARIS) \
-  && !defined(__FreeBSD__) && !defined(__OpenBSD__)
+  && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
 F(umount)
 #endif
 F(unlink)
@@ -177,7 +177,7 @@ F(utimes)
 #ifndef irix
 F(vfork)
 #endif
-#if !defined(osf1) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
+#if !defined(osf1) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
 F(vhangup)
 #endif
 F(wait)
diff --git a/lisp/x86-arch.c b/lisp/x86-arch.c
index 00fc02624..5bff6125d 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.15 2001/12/06 19:15:46 pmai Exp $ 
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-arch.c,v 1.16 2002/01/28 20:17:12 pmai Exp $ 
  *
  */
 
@@ -238,14 +238,14 @@ void  sigtrap_handler(HANDLER_ARGS)
       
     case trap_Halt:
       {
-#if defined(__FreeBSD__) || defined(__OpenBSD__)
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 	int fpu_state[27];
 	fpu_save(fpu_state);
 #endif
 	fake_foreign_function_call(context);
 	lose("%%primitive halt called; the party is over.\n");
 	undo_fake_foreign_function_call(context);
-#if defined(__FreeBSD__) || defined(__OpenBSD__)
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
 	fpu_restore(fpu_state);
 #endif
 	arch_skip_instruction(context);
diff --git a/lisp/x86-assem.S b/lisp/x86-assem.S
index abc8e03c4..8833b4ece 100644
--- a/lisp/x86-assem.S
+++ b/lisp/x86-assem.S
@@ -1,6 +1,6 @@
 ### x86-assem.S -*- Mode: Asm; -*-
 /**
- * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-assem.S,v 1.19 2000/09/05 08:51:52 dtc Exp $
+ * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-assem.S,v 1.20 2002/01/28 20:17:12 pmai Exp $
  *
  * Authors:	Paul F. Werkowski <pw@snoopy.mv.com>
  *		Douglas T. Crosher
@@ -22,7 +22,7 @@
 #endif
 
 /* Minimize conditionalization for different OS naming schemes */
-#if defined (__linux__) || (__FreeBSD_version >= 300000)
+#if defined (__linux__) || (__FreeBSD_version >= 300000) || defined (__NetBSD__)
 #define GNAME(var) var
 #else
 #define GNAME(var) _##var
diff --git a/lisp/x86-validate.h b/lisp/x86-validate.h
index c71ec8be5..8277a406b 100644
--- a/lisp/x86-validate.h
+++ b/lisp/x86-validate.h
@@ -3,7 +3,7 @@
  * This code was written as part of the CMU Common Lisp project at
  * Carnegie Mellon University, and has been placed in the public domain.
  *
- *  $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-validate.h,v 1.13 2001/12/06 19:15:46 pmai Exp $
+ *  $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-validate.h,v 1.14 2002/01/28 20:17:12 pmai Exp $
  *
  */
 
@@ -21,7 +21,7 @@
  *	0x48000000->0xC8000000 2GB  Dynamic Space.
  *	0xE0000000->           256M C stack - Alien stack.
  *
- *  OpenBSD:
+ *  OpenBSD and NetBSD:
  *	0x00000000->0x0E000000 224M C program and memory allocation.
  *	0x0E000000->0x10000000  32M Foreign segment.
  *	0x10000000->0x20000000 256M Read-Only Space.
@@ -67,7 +67,7 @@
 #endif
 
 
-#ifdef __OpenBSD__
+#if defined(__OpenBSD__) || defined(__NetBSD__)
 #define READ_ONLY_SPACE_START   (0x10000000)
 #define READ_ONLY_SPACE_SIZE    (0x0ffff000) /* 256MB - 1 page */
 
diff --git a/motif/server/Config.NetBSD b/motif/server/Config.NetBSD
new file mode 100644
index 000000000..b72d6f383
--- /dev/null
+++ b/motif/server/Config.NetBSD
@@ -0,0 +1,7 @@
+CFLAGS = -O2 -I/usr/local/include -I/usr/X11R6/include -I. -I$(VPATH)
+LDFLAGS = -L/usr/X11R6/lib -L/usr/local/lib
+LIBS = -lXm -lXt -lXext -lX11 -lSM -lICE -lXp
+# This def assumes you are building in the same or parallel
+# tree to the CVS souce layout. Sites may need to customize
+# this path.
+VPATH = ../../../src/motif/server/
-- 
GitLab