1st working version
authorSam Leffler <sam@ucbvax.Berkeley.EDU>
Mon, 6 Jan 1986 10:42:49 +0000 (02:42 -0800)
committerSam Leffler <sam@ucbvax.Berkeley.EDU>
Mon, 6 Jan 1986 10:42:49 +0000 (02:42 -0800)
SCCS-vsn: sys/tahoe/tahoe/Locore.c 1.2
SCCS-vsn: sys/tahoe/tahoe/autoconf.c 1.2
SCCS-vsn: sys/tahoe/tahoe/clock.c 1.2
SCCS-vsn: sys/tahoe/include/clock.h 1.2
SCCS-vsn: sys/tahoe/tahoe/conf.c 1.2
SCCS-vsn: sys/tahoe/tahoe/cons.c 1.2
SCCS-vsn: sys/tahoe/tahoe/in_cksum.c 1.2
SCCS-vsn: sys/tahoe/tahoe/locore.s 1.2
SCCS-vsn: sys/tahoe/tahoe/machdep.c 1.2
SCCS-vsn: sys/tahoe/tahoe/mem.c 1.2
SCCS-vsn: sys/tahoe/include/pcb.h 1.2
SCCS-vsn: sys/tahoe/include/psl.h 1.2
SCCS-vsn: sys/tahoe/include/pte.h 1.2
SCCS-vsn: sys/tahoe/tahoe/swapgeneric.c 1.2
SCCS-vsn: sys/tahoe/tahoe/trap.c 1.2
SCCS-vsn: sys/tahoe/tahoe/vm_machdep.c 1.2
SCCS-vsn: sys/tahoe/include/vmparam.h 1.2

17 files changed:
usr/src/sys/tahoe/include/clock.h
usr/src/sys/tahoe/include/pcb.h
usr/src/sys/tahoe/include/psl.h
usr/src/sys/tahoe/include/pte.h
usr/src/sys/tahoe/include/vmparam.h
usr/src/sys/tahoe/tahoe/Locore.c
usr/src/sys/tahoe/tahoe/autoconf.c
usr/src/sys/tahoe/tahoe/clock.c
usr/src/sys/tahoe/tahoe/conf.c
usr/src/sys/tahoe/tahoe/cons.c
usr/src/sys/tahoe/tahoe/in_cksum.c
usr/src/sys/tahoe/tahoe/locore.s
usr/src/sys/tahoe/tahoe/machdep.c
usr/src/sys/tahoe/tahoe/mem.c
usr/src/sys/tahoe/tahoe/swapgeneric.c
usr/src/sys/tahoe/tahoe/trap.c
usr/src/sys/tahoe/tahoe/vm_machdep.c

index f8ed0f7..81050fc 100644 (file)
@@ -1,4 +1,4 @@
-/*     clock.h 4.5     81/02/23        */
+/*     clock.h 1.2     86/01/05        */
 
 #define        SECDAY          ((unsigned)(24*60*60))          /* seconds per day */
 #define        SECYR           ((unsigned)(365*SECDAY))        /* per common year */
 
 #define        SECDAY          ((unsigned)(24*60*60))          /* seconds per day */
 #define        SECYR           ((unsigned)(365*SECDAY))        /* per common year */
@@ -9,4 +9,4 @@
 /*
  * Software clock is software interrupt level 8
  */
 /*
  * Software clock is software interrupt level 8
  */
-#define        setsoftclock()  mtpr(0x8, SIRR)
+#define        setsoftclock()  mtpr(SIRR, 0x8)
index a9418db..4099e11 100644 (file)
@@ -1,9 +1,9 @@
+/*     pcb.h   1.2     86/01/05        */
+
 /*
  * TAHOE process control block
  */
 /*
  * TAHOE process control block
  */
-
-struct pcb
-{
+struct pcb {
        int     pcb_ksp;        /* kernel stack pointer */
        int     pcb_usp;        /* user stack pointer */
        int     pcb_r0; 
        int     pcb_ksp;        /* kernel stack pointer */
        int     pcb_usp;        /* user stack pointer */
        int     pcb_r0; 
@@ -33,7 +33,7 @@ struct pcb
        int     pcb_acl;        /* accumulator - low order longword */
 #define ACH    pcb_ach
 #define ACL    pcb_acl
        int     pcb_acl;        /* accumulator - low order longword */
 #define ACH    pcb_ach
 #define ACL    pcb_acl
-       int     pcb_hfs;        /* f.p. status register.        */
+       int     pcb_hfs;        /* fp status register */
 /*
  * Software pcb (extension)
  */
 /*
  * Software pcb (extension)
  */
@@ -46,21 +46,19 @@ struct pcb
        int     pcb_szpt;       /* number of pages of user page table */
        int     pcb_cmap2;
        int     *pcb_sswap;
        int     pcb_szpt;       /* number of pages of user page table */
        int     pcb_cmap2;
        int     *pcb_sswap;
-       short   pcb_ckey;       /* cache code key (proc index if NPROC<255) */
-       short   pcb_dkey;       /* cache data key */
-       int     pcb_sigc[4];
+       long    pcb_sigc[5];    /* sigcode actually 19 bytes */
 };
 
 extern long    *user_psl;
 
 };
 
 extern long    *user_psl;
 
-#define        aston() \
-       { \
-               u.u_pcb.pcb_psl |= PSL_SFE; \
-               if ((int)user_psl != 0) *user_psl |= PSL_SFE; \
-       }
+#define        aston() \
+       u.u_pcb.pcb_psl |= PSL_SFE; \
+       if ((int)user_psl != 0) \
+               *user_psl |= PSL_SFE; \
+}
 
 
-#define        astoff() \
-       { \
-               u.u_pcb.pcb_psl &= ~ PSL_SFE; \
-               if ((int)user_psl != 0) *user_psl &= ~PSL_SFE; \
-       }
+#define        astoff() \
+       u.u_pcb.pcb_psl &= ~ PSL_SFE; \
+       if ((int)user_psl != 0) \
+               *user_psl &= ~PSL_SFE; \
+}
index 408998b..8e9bd3e 100644 (file)
@@ -1,10 +1,8 @@
-
-/*     psl.h   4.4     84/01/31        */
+/*     psl.h   1.2     86/01/05        */
 
 /*
 
 /*
- * TAHOE program status longword
+ * TAHOE processor status longword.
  */
  */
-
 #define        PSL_C           0x00000001      /* carry bit */
 #define        PSL_V           0x00000002      /* overflow bit */
 #define        PSL_Z           0x00000004      /* zero bit */
 #define        PSL_C           0x00000001      /* carry bit */
 #define        PSL_V           0x00000002      /* overflow bit */
 #define        PSL_Z           0x00000004      /* zero bit */
 #define PSL_DBL                0x00000080      /* f.p. prescision indicator    */
 #define        PSL_SFE         0x00000100      /* system-forced-exception */
 #define        PSL_IPL         0x001f0000      /* interrupt priority level */
 #define PSL_DBL                0x00000080      /* f.p. prescision indicator    */
 #define        PSL_SFE         0x00000100      /* system-forced-exception */
 #define        PSL_IPL         0x001f0000      /* interrupt priority level */
+#define        PSL_PRVMOD      0x00000000      /* previous mode (kernel mode) */
 #define        PSL_CURMOD      0x01000000      /* current mode (all on is user) */
 #define        PSL_IS          0x04000000      /* interrupt stack */
 #define        PSL_TP          0x40000000      /* trace pending */
 
 #define        PSL_CURMOD      0x01000000      /* current mode (all on is user) */
 #define        PSL_IS          0x04000000      /* interrupt stack */
 #define        PSL_TP          0x40000000      /* trace pending */
 
-#define        PSL_MBZ         0xbae0ffc0      /* must be zero bits */
+#define        PSL_MBZ         0xbae0fe00      /* must be zero bits */
 
 #define        PSL_USERSET     (PSL_CURMOD)
 
 #define        PSL_USERSET     (PSL_CURMOD)
-#define        PSL_USERCLR     (PSL_IS|PSL_IPL|PSL_MBZ)
+#define        PSL_USERCLR     (PSL_IS|PSL_IPL|PSL_MBZ|PSL_SFE|PSL_DBL|PSL_FU)
index 62aaf6d..20bdbb1 100644 (file)
@@ -1,5 +1,4 @@
-/*     pte.h   1.1     85/07/21        */
-/*     Tahoe version, November 1982    */
+/*     pte.h   1.2     86/01/05        */
 
 /*
  * Tahoe page table entry
 
 /*
  * Tahoe page table entry
@@ -18,12 +17,10 @@ unsigned int
                pg_v:1,                 /* valid bit */
                pg_prot:4,              /* access control */
                pg_fod:1,               /* is fill on demand (=0) */
                pg_v:1,                 /* valid bit */
                pg_prot:4,              /* access control */
                pg_fod:1,               /* is fill on demand (=0) */
-               pg_swapm:1,             /* must write back to swap */
+               :1,                     /* must write back to swap (unused) */
                pg_nc:1,                /* 'uncacheable page' bit */
                pg_m:1,                 /* hardware maintained modified bit */
                pg_nc:1,                /* 'uncacheable page' bit */
                pg_m:1,                 /* hardware maintained modified bit */
-       /*      pg_u:1,                 /* hardware maintained 'used' bit */
-                                       /* Not implemented in this version */
-               pg_vreadm:1,            /* modified since vread (ored with _m)*/
+               pg_u:1,                 /* hardware maintained 'used' bit */
                pg_pfnum:22;            /* core page frame number or 0 */
 };
 struct hpte
                pg_pfnum:22;            /* core page frame number or 0 */
 };
 struct hpte
@@ -39,8 +36,8 @@ unsigned int
                pg_prot:4,
                pg_fod:1,               /* is fill on demand (=1) */
                :1,
                pg_prot:4,
                pg_fod:1,               /* is fill on demand (=1) */
                :1,
-               pg_fileno:5,            /* file mapped from or TEXT or ZERO */
-               pg_blkno:20;            /* file system block number */
+               pg_fileno:1,            /* file mapped from or TEXT or ZERO */
+               pg_blkno:24;            /* file system block number */
 };
 #endif
 
 };
 #endif
 
@@ -50,12 +47,11 @@ unsigned int
 #define        PG_SWAPM        0x02000000
 #define PG_N           0x01000000 /* Non-cacheable */
 #define        PG_M            0x00800000
 #define        PG_SWAPM        0x02000000
 #define PG_N           0x01000000 /* Non-cacheable */
 #define        PG_M            0x00800000
-/*  #define PG_U       0x00400000 /* NOT implemented now !!! */
-#define PG_VREADM      0x00400000 /* Uses 'U' bit location !!! */
+#define PG_U           0x00400000 /* not currently used */
 #define        PG_PFNUM        0x003fffff
 
 #define        PG_PFNUM        0x003fffff
 
-#define        PG_FZERO        (NOFILE)
-#define        PG_FTEXT        (NOFILE+1)
+#define        PG_FZERO        0
+#define        PG_FTEXT        1
 #define        PG_FMAX         (PG_FTEXT)
 
 #define        PG_NOACC        0
 #define        PG_FMAX         (PG_FTEXT)
 
 #define        PG_NOACC        0
@@ -68,13 +64,10 @@ unsigned int
 /*
  * Pte related macros
  */
 /*
  * Pte related macros
  */
-#define        dirty(pte)      ((pte)->pg_fod == 0 && (pte)->pg_pfnum && \
-                           ((pte)->pg_m || (pte)->pg_swapm))
+#define        dirty(pte)      ((pte)->pg_fod == 0 && (pte)->pg_pfnum && (pte)->pg_m)
 
 #ifndef LOCORE
 #ifdef KERNEL
 
 #ifndef LOCORE
 #ifdef KERNEL
-struct pte *vtopte();
-
 /* utilities defined in locore.s */
 extern struct pte Sysmap[];
 extern struct pte Usrptmap[];
 /* utilities defined in locore.s */
 extern struct pte Sysmap[];
 extern struct pte Usrptmap[];
@@ -85,15 +78,13 @@ extern      struct pte Xswapmap[];
 extern struct pte Xswap2map[];
 extern struct pte Pushmap[];
 extern struct pte Vfmap[];
 extern struct pte Xswap2map[];
 extern struct pte Pushmap[];
 extern struct pte Vfmap[];
-/*
-extern struct pte IOmap[];
-*/
 extern struct pte VD0map[];
 extern struct pte VD1map[];
 extern struct pte VD2map[];
 extern struct pte VD3map[];
 extern struct pte UDmap[];
 extern struct pte VD0map[];
 extern struct pte VD1map[];
 extern struct pte VD2map[];
 extern struct pte VD3map[];
 extern struct pte UDmap[];
-extern struct pte CYmap[];
+extern struct pte CY0map[];
+extern struct pte CY1map[];
 extern struct pte XYmap[];
 extern struct pte mmap[];
 extern struct pte msgbufmap[];
 extern struct pte XYmap[];
 extern struct pte mmap[];
 extern struct pte msgbufmap[];
index b44a80a..041be7d 100644 (file)
@@ -1,5 +1,4 @@
-/*     vmparam.h       1.3     5/25/85 */
-/*     vmparam.h       6.1     83/07/29        */
+/*     vmparam.h       1.2     86/01/05        */
 
 /*
  * Machine dependent constants for TAHOE
 
 /*
  * Machine dependent constants for TAHOE
  * beginning of the text and from the beginning of the P2 region to the
  * beginning of the stack respectively.
  */
  * beginning of the text and from the beginning of the P2 region to the
  * beginning of the stack respectively.
  */
-                                       /* number of ptes per page */
 #define        USRTEXT         0
 #define        USRTEXT         0
-#define        USRSTACK        (0xC0000000-UPAGES*NBPG)
-                                       /* Start of user stack */
+#define        USRSTACK        (0xc0000000-UPAGES*NBPG) /* Start of user stack */
+#define        BTOPUSRSTACK    (0x300000 - UPAGES)      /* btop(USRSTACK) */
 #define        P2PAGES         0x100000        /* number of pages in P2 region */
 #define        LOWPAGES        0
 #define        HIGHPAGES       UPAGES
 
 /*
 #define        P2PAGES         0x100000        /* number of pages in P2 region */
 #define        LOWPAGES        0
 #define        HIGHPAGES       UPAGES
 
 /*
- * Virtual memory related constants
+ * Virtual memory related constants, all in clicks
  */
  */
-#define        SLOP    32
-#define        MAXTSIZ         (6*1024-SLOP)           /* max text size (clicks) */
-#define        MAXDSIZ         (19*2048-32-SLOP)       /* max data size (clicks) */
-#define        MAXSSIZ         (19*2048-32-SLOP)       /* max stack size (clicks) */
+#define        MAXTSIZ         (6*CLSIZE*1024)         /* max text size */
+#ifndef DFLDSIZ
+#define        DFLDSIZ         (6*1024*1024/NBPG)      /* initial data size limit */
+#endif
+#ifndef MAXDSIZ
+#define        MAXDSIZ         (19*1024*1024/NBPG)     /* max data size */
+#endif
+#ifndef        DFLSSIZ
+#define        DFLSSIZ         (512*1024/NBPG)         /* initial stack size limit */
+#endif
+#ifndef        MAXSSIZ
+#define        MAXSSIZ         MAXDSIZ                 /* max stack size */
+#endif
+
+/*
+ * Default sizes of swap allocation chunks (see dmap.h).
+ * The actual values may be changed in vminit() based on MAXDSIZ.
+ * With MAXDSIZ of 16Mb and NDMAP of 38, dmmax will be 1024.
+ */
+#define        DMMIN   32                      /* smallest swap allocation */
+#define        DMMAX   4096                    /* largest potential swap allocation */
+#define        DMTEXT  1024                    /* swap allocation for text */
 
 /*
  * Sizes of the system and user portions of the system page table.
  */
 /* SYSPTSIZE IS SILLY; IT SHOULD BE COMPUTED AT BOOT TIME */
 
 /*
  * Sizes of the system and user portions of the system page table.
  */
 /* SYSPTSIZE IS SILLY; IT SHOULD BE COMPUTED AT BOOT TIME */
-#define        SYSPTSIZE       ((30+MAXUSERS)*NPTEPG/4)
-#define        USRPTSIZE       (2*NPTEPG)
+#ifdef notdef
+#define        SYSPTSIZE       ((20+MAXUSERS)*NPTEPG)
+#define        USRPTSIZE       (32*NPTEPG)
+#else
+#define        SYSPTSIZE       ((128*NPTEPG/2)+(MAXUSERS*NPTEPG/16))
+#define        USRPTSIZE       (4*NPTEPG)
+#endif
 
 /*
  * The size of the clock loop.
 
 /*
  * The size of the clock loop.
@@ -63,7 +84,7 @@
  * that we don't consider it worthwhile and swap it out to disk which costs
  * $30/mb or about $0.75.
  */
  * that we don't consider it worthwhile and swap it out to disk which costs
  * $30/mb or about $0.75.
  */
-#define        SAFERSS         16              /* nominal ``small'' resident set size
+#define        SAFERSS         32              /* nominal ``small'' resident set size
                                           protected against replacement */
 
 /*
                                           protected against replacement */
 
 /*
 
 /*
  * Paging thresholds (see vm_sched.c).
 
 /*
  * Paging thresholds (see vm_sched.c).
- * Strategy of 4/22/81:
- *     lotsfree is 1/4 of memory free.
+ * Strategy of 1/19/85:
+ *     lotsfree is 512k bytes, but at most 1/4 of memory
  *     desfree is 200k bytes, but at most 1/8 of memory
  *     minfree is 64k bytes, but at most 1/2 of desfree
  */
  *     desfree is 200k bytes, but at most 1/8 of memory
  *     minfree is 64k bytes, but at most 1/2 of desfree
  */
+#define        LOTSFREE        (512 * 1024)
 #define        LOTSFREEFRACT   4
 #define        DESFREE         (200 * 1024)
 #define        DESFREEFRACT    8
 #define        MINFREE         (64 * 1024)
 #define        MINFREEFRACT    2
 
 #define        LOTSFREEFRACT   4
 #define        DESFREE         (200 * 1024)
 #define        DESFREEFRACT    8
 #define        MINFREE         (64 * 1024)
 #define        MINFREEFRACT    2
 
+/*
+ * There are two clock hands, initially separated by HANDSPREAD bytes
+ * (but at most all of user memory).  The amount of time to reclaim
+ * a page once the pageout process examines it increases with this
+ * distance and decreases as the scan rate rises.
+ */
+#define        HANDSPREAD      (2 * 1024 * 1024)
+
+/*
+ * The number of times per second to recompute the desired paging rate
+ * and poke the pagedaemon.
+ */
+#define        RATETOSCHEDPAGING       4
+
 /*
  * Believed threshold (in megabytes) for which interleaved
  * swapping area is desirable.
 /*
  * Believed threshold (in megabytes) for which interleaved
  * swapping area is desirable.
  * BEWARE THIS DEFINITION WORKS ONLY WITH COUNT OF 1
  */
 #define        mapin(pte, v, pfnum, count, prot) \
  * BEWARE THIS DEFINITION WORKS ONLY WITH COUNT OF 1
  */
 #define        mapin(pte, v, pfnum, count, prot) \
-       (*(int *)(pte) = (pfnum) | (prot), mtpr(ptob(v), TBIS))
+       (*(int *)(pte) = (pfnum) | (prot), mtpr(TBIS, ptob(v)))
+
+/*
+ * Invalidate a cluster (optimized here for standard CLSIZE).
+ */
+#if CLSIZE == 1
+#define        tbiscl(v)       mtpr(TBIS, ptob(v))
+#endif
 
 /* 
  * The following constant is used to initialize the map of the
 
 /* 
  * The following constant is used to initialize the map of the
  * It's value should be the highest i/o address used by all the 
  * controllers handled in the system as specified in ubminit 
  * structure in ioconf.c.
  * It's value should be the highest i/o address used by all the 
  * controllers handled in the system as specified in ubminit 
  * structure in ioconf.c.
-*/
-#define MAXIOADDR 0xffffee45   /* highest physical io address */
-
-/* Number of entries in the system page pable for i/o space */
-#define IOSIZE (( (MAXIOADDR - IOBASE+ NBPG -1) >> PGSHIFT )+1)
-#define TBUFSIZ        10              /* maximum tape buffer size */
-#define        ACEBPTE 32              /* ACC Ethernet (ACE) I/O window        */
+ */
+#define MAXIOADDR      0xffffee45
+/* number of entries in the system page pable for i/o space */
+#define IOSIZE         (((MAXIOADDR - (int)IOBASE+ NBPG-1) >> PGSHIFT)+1)
+#define TBUFSIZ                32              /* maximum tape buffer size */
+#define        ACEBPTE         32              /* ACC Ethernet (ACE) I/O window */
index f612050..9d2042a 100644 (file)
@@ -1,54 +1,56 @@
-/*     Locore.c        1.1     85/07/21        */
-
-#include "dz.h"
-#include "mba.h"
-#include "uba.h"
-
-#include "../machine/pte.h"
-
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/dir.h"
-#include "../h/user.h"
-#include "../h/vm.h"
-#include "../h/tty.h"
-#include "../h/proc.h"
-#include "../h/buf.h"
-#include "../h/msgbuf.h"
-#include "../h/mbuf.h"
-#include "../h/protosw.h"
-#include "../h/domain.h"
-
-#include "../vax/nexus.h"
-#include "../vaxuba/ubavar.h"
-#include "../vaxuba/ubareg.h"
+/*     Locore.c        1.2     86/01/05        */
+
+#include "../tahoe/mtpr.h"
+#include "../tahoe/trap.h"
+#include "../tahoe/psl.h"
+#include "../tahoe/pte.h"
+#include "../tahoe/cp.h"
+#include "../tahoe/mem.h"
+#include "../tahoemath/fp.h"
+
+#include "param.h"
+#include "systm.h"
+#include "dir.h"
+#include "user.h"
+#include "vm.h"
+#include "ioctl.h"
+#include "tty.h"
+#include "proc.h"
+#include "buf.h"
+#include "msgbuf.h"
+#include "mbuf.h"
+#include "protosw.h"
+#include "domain.h"
+#include "map.h"
 
 /*
  * Pseudo file for lint to show what is used/defined in locore.s.
  */
 
 struct scb scb;
 
 /*
  * Pseudo file for lint to show what is used/defined in locore.s.
  */
 
 struct scb scb;
-int    (*UNIvec[128])();
-#if NUBA > 1
-int    (*UNI1vec[128])();
-#endif
 struct rpb rpb;
 struct rpb rpb;
-int    intstack[3*128];
-
+int    dumpflag;
+int    intstack[3*NBPG];
 int    masterpaddr;            /* p_addr of current process on master cpu */
 int    masterpaddr;            /* p_addr of current process on master cpu */
-
 struct user u;
 struct user u;
+int    icode[8];
+int    szicode = sizeof (icode);
+/*
+ * Variables declared for savecore, or
+ * implicitly, such as by config or the loader.
+ */
+char   version[] = "4.2 BSD UNIX ....";
+int    etext;
 
 doadump() { dumpsys(); }
 
 
 doadump() { dumpsys(); }
 
-Xmba3int() { }
-Xmba2int() { }
-Xmba1int() { }
-Xmba0int() { }
-
 lowinit()
 {
 lowinit()
 {
+       caddr_t cp;
        extern int dumpmag;
        extern int dumpmag;
+       extern int rthashsize;
+       extern int arptab_size;
+       extern int dk_ndrive;
        extern struct domain unixdomain;
 #ifdef PUP
        extern struct domain pupdomain;
        extern struct domain unixdomain;
 #ifdef PUP
        extern struct domain pupdomain;
@@ -60,6 +62,12 @@ lowinit()
 #if NIMP > 0
        extern struct domain impdomain;
 #endif
 #if NIMP > 0
        extern struct domain impdomain;
 #endif
+#ifdef NS
+       extern struct domain nsdomain;
+#endif
+       extern int nport;
+       extern short *swsize;
+       extern int *swpf;
 
        /* cpp messes these up for lint so put them here */
        unixdomain.dom_next = domains;
 
        /* cpp messes these up for lint so put them here */
        unixdomain.dom_next = domains;
@@ -75,8 +83,15 @@ lowinit()
 #if NIMP > 0
        impdomain.dom_next = domains;
        domains = &impdomain;
 #if NIMP > 0
        impdomain.dom_next = domains;
        domains = &impdomain;
+#endif
+#ifdef NS
+       nsdomain.dom_next = domains;
+       domains = &nsdomain;
 #endif
        dumpmag = 0;                    /* used only by savecore */
 #endif
        dumpmag = 0;                    /* used only by savecore */
+       rthashsize = rthashsize;        /* used by netstat, etc. */
+       arptab_size = arptab_size;      /* used by arp command */
+       dk_ndrive = dk_ndrive;          /* used by vmstat, iostat, etc. */
 
        /*
         * Pseudo-uses of globals.
 
        /*
         * Pseudo-uses of globals.
@@ -87,63 +102,52 @@ lowinit()
        scb = scb;
        maxmem = physmem = freemem = 0;
        u = u;
        scb = scb;
        maxmem = physmem = freemem = 0;
        u = u;
-       fixctlrmask();
        main(0);
        main(0);
-       Xustray();
+       swsize = swsize;                /* XXX */
+       swpf = swpf;                    /* XXX */
+       nport = nport;                  /* XXX */
 
        /*
         * Routines called from interrupt vectors.
         */
 
        /*
         * Routines called from interrupt vectors.
         */
+       buserror((caddr_t)0);
        panic("Machine check");
        printf("Write timeout");
        panic("Machine check");
        printf("Write timeout");
-       (*UNIvec[0])();
-#if NUBA > 1
-       (*UNI1vec[0])();
+       rawintr();
+#ifdef INET
+       ipintr();
+#endif
+#ifdef NS
+       nsintr();
 #endif
 #endif
-       ubaerror(0, (struct uba_hd *)0, 0, 0, (struct uba_regs *)0);
        cnrint(0);
        cnxint(0);
        cnrint(0);
        cnxint(0);
-       consdin();
-       consdout();
-#if NDZ > 0
-       dzdma();
-#endif
-#if NMBA > 0
-       mbintr(0);
-#endif
        hardclock((caddr_t)0, 0);
        softclock((caddr_t)0, 0);
        hardclock((caddr_t)0, 0);
        softclock((caddr_t)0, 0);
-       trap(0, 0, (unsigned)0, 0, 0);
-       syscall(0, 0, (unsigned)0, 0, 0);
-       ipintr();
-       rawintr();
+       fpemulate(0, 0, 0, 0, 0, 0, 0, 0, 0);
+       trap(0, 0, 0, 0, 0, 0, (unsigned)0, 0, 0);
+       syscall(0, 0, 0, 0, 0, 0, (unsigned)0, 0, 0);
 
        if (vmemall((struct pte *)0, 0, (struct proc *)0, 0))
                return;         /* use value */
 
        if (vmemall((struct pte *)0, 0, (struct proc *)0, 0))
                return;         /* use value */
-       machinecheck((caddr_t)0);
-       memerr();
+       if (zmemall((int (*)())0, 0) == (caddr_t)0)
+               return;         /* use value */
        boothowto = 0;
        boothowto = 0;
-}
-
-consdin() { }
-consdout() { }
-#if NDZ > 0
-dzdma() { dzxint((struct tty *)0); }
+/* the following are not currently used but will soon */
+       if (rmget((struct map *)0, 0, 0) == 0)
+               return;
+       cp = calloc(0); cfreemem(cp, 0);
+/* end not currently used */
+       dumpflag = 0; dumpflag = dumpflag;
+#if !defined(GPROF)
+       cp = (caddr_t)&etext;
 #endif
 #endif
-
-int    catcher[256];
-int    cold = 1;
-
-Xustray() { }
+}
 
 struct pte Sysmap[6*NPTEPG];
 
 struct pte Sysmap[6*NPTEPG];
-char   Sysbase[6*NPTEPG*NBPG];
-int    umbabeg;
-struct pte Nexmap[16][16];
-struct nexus nexus[MAXNNEXUS];
-struct pte UMEMmap[MAXNUBA][512];
-char   umem[MAXNUBA][512*NBPG];
-int    umbaend;
+caddr_t        Sysbase;
+struct pte VMEMmap[1];
+int    vmembeg, vmemend;
 struct pte Usrptmap[USRPTSIZE];
 struct pte usrpt[USRPTSIZE*NPTEPG];
 struct pte Forkmap[UPAGES];
 struct pte Usrptmap[USRPTSIZE];
 struct pte usrpt[USRPTSIZE*NPTEPG];
 struct pte Forkmap[UPAGES];
@@ -158,38 +162,76 @@ struct    pte Pushmap[UPAGES];
 struct user pushutl;
 struct pte Vfmap[UPAGES];
 struct user vfutl;
 struct user pushutl;
 struct pte Vfmap[UPAGES];
 struct user vfutl;
-struct pte CMAP1;
-char   CADDR1[NBPG];
-struct pte CMAP2;
-char   CADDR2[NBPG];
+#include "fsd.h"
+#if NVD > 0
+struct pte VD0map[MAXBPTE+1];
+char   vd0utl[1];
+#endif
+#if NVD > 1
+struct pte VD1map[MAXBPTE+1];
+char   vd1utl[1];
+#endif
+#if NVD > 2
+struct pte VD2map[MAXBPTE+1];
+char   vd2utl[1];
+#endif
+#if NVD > 3
+struct pte VD3map[MAXBPTE+1];
+char   vd3utl[1];
+#endif
+#include "cy.h"
+#if NCY > 0
+struct pte CY0map[TBUFSIZ+1];
+char   cy0utl[1];
+#endif
+#if NCY > 1
+struct pte CY1map[TBUFSIZ+1];
+char   cy1utl[1];
+#endif
+#include "ace.h"
+#if NACE > 0
+struct pte ACE0map[1], ACE1map[1];
+char   ace0utl[1], ace1utl[1];
+#endif
+struct pte CMAP1[1], CMAP2[1];
+caddr_t        CADDR1, CADDR2;
 struct pte mmap[1];
 struct pte mmap[1];
-char   vmmap[NBPG];
+char   vmmap[1];
+struct pte msgbufmap[3*NBPG];
+struct msgbuf msgbuf;
+struct pte camap[16];
+int    cabase, calimit;
 struct pte Mbmap[NMBCLUSTERS/CLSIZE];
 struct mbuf mbutl[NMBCLUSTERS*CLBYTES/sizeof (struct mbuf)];
 struct pte Mbmap[NMBCLUSTERS/CLSIZE];
 struct mbuf mbutl[NMBCLUSTERS*CLBYTES/sizeof (struct mbuf)];
-struct pte msgbufmap[CLSIZE];
-struct msgbuf msgbuf;
-struct pte camap[32];
-int    cabase;
-#ifdef unneeded
-char   caspace[32*NBPG];
-#endif
-int    calimit;
 
 /*ARGSUSED*/
 badaddr(addr, len) caddr_t addr; int len; { return (0); }
 
 /*ARGSUSED*/
 badaddr(addr, len) caddr_t addr; int len; { return (0); }
-
+#if NCY > 0
 /*ARGSUSED*/
 /*ARGSUSED*/
-copyin(udaddr, kaddr, n) caddr_t udaddr, kaddr; unsigned n; { return (0); }
-
+badcyaddr(addr) caddr_t addr; { return (0); }
+#endif
 /*ARGSUSED*/
 /*ARGSUSED*/
-copyout(kaddr, udaddr, n) caddr_t kaddr, udaddr; unsigned n; { return (0); }
-
+ovbcopy(from, to, len) caddr_t from, to; unsigned len; { }
+copyinstr(udaddr, kaddr, maxlength, lencopied)
+    caddr_t udaddr, kaddr; u_int maxlength, *lencopied;
+{ *kaddr = *udaddr; *lencopied = maxlength; return (0); }
+copyoutstr(kaddr, udaddr, maxlength, lencopied)
+    caddr_t kaddr, udaddr; u_int maxlength, *lencopied;
+{ *kaddr = *udaddr; *lencopied = maxlength; return (0); }
+copystr(kfaddr, kdaddr, maxlength, lencopied)
+    caddr_t kfaddr, kdaddr; u_int maxlength, *lencopied;
+{ *kdaddr = *kfaddr; *lencopied = maxlength; return (0); }
 /*ARGSUSED*/
 /*ARGSUSED*/
-setjmp(lp) label_t *lp; { return (0); }
+copyin(udaddr, kaddr, n) caddr_t udaddr, kaddr; u_int n; { return (0); }
+/*ARGSUSED*/
+copyout(kaddr, udaddr, n) caddr_t kaddr, udaddr; u_int n; { return (0); }
 
 /*ARGSUSED*/
 longjmp(lp) label_t *lp; { /*NOTREACHED*/ }
 
 
 /*ARGSUSED*/
 longjmp(lp) label_t *lp; { /*NOTREACHED*/ }
 
+/*ARGSUSED*/
+savectx(lp) label_t *lp; { return (0); }
+
 /*ARGSUSED*/
 setrq(p) struct proc *p; { }
 
 /*ARGSUSED*/
 setrq(p) struct proc *p; { }
 
@@ -203,83 +245,83 @@ resume(pcbpf) unsigned pcbpf; { }
 
 /*ARGSUSED*/
 fubyte(base) caddr_t base; { return (0); }
 
 /*ARGSUSED*/
 fubyte(base) caddr_t base; { return (0); }
-
 /*ARGSUSED*/
 subyte(base, i) caddr_t base; { return (0); }
 /*ARGSUSED*/
 subyte(base, i) caddr_t base; { return (0); }
-
 /*ARGSUSED*/
 /*ARGSUSED*/
-suibyte(base, i) caddr_t base; { return (0); }
+fuword(base) caddr_t base; { return (0); }
+/*ARGSUSED*/
+suword(base, i) caddr_t base; { return (0); }
 
 /*ARGSUSED*/
 
 /*ARGSUSED*/
-fuword(base) caddr_t base; { return (0); }
+copyseg(udaddr, pf)
+    caddr_t udaddr; unsigned pf;
+{ CMAP1[0] = CMAP1[0]; CADDR1[0] = CADDR1[0]; }
 
 /*ARGSUSED*/
 
 /*ARGSUSED*/
-fuiword(base) caddr_t base; { return (0); }
+clearseg(pf) unsigned pf; { CMAP2[0] = CMAP2[0]; CADDR2[0] = CADDR2[0]; }
 
 /*ARGSUSED*/
 
 /*ARGSUSED*/
-suword(base, i) caddr_t base; { return (0); }
+useracc(udaddr, bcnt, rw) caddr_t udaddr; unsigned bcnt; { return (0); }
 
 /*ARGSUSED*/
 
 /*ARGSUSED*/
-suiword(base, i) caddr_t base; { return (0); }
+kernacc(addr, bcnt, rw) caddr_t addr; unsigned bcnt; { return (0); }
 
 /*ARGSUSED*/
 
 /*ARGSUSED*/
-copyseg(udaddr, pf) caddr_t udaddr; unsigned pf; {
-    CMAP1 = CMAP1; CADDR1[0] = CADDR1[0];
-}
+addupc(pc, prof, counts) int pc; struct uprof *prof; int counts; { }
 
 /*ARGSUSED*/
 
 /*ARGSUSED*/
-clearseg(pf) unsigned pf; { CMAP2 = CMAP2; CADDR2[0] = CADDR2[0]; }
+scanc(size, cp, table, mask)
+    unsigned size; char *cp, table[]; int mask;
+{ return (0); }
 
 /*ARGSUSED*/
 
 /*ARGSUSED*/
-useracc(udaddr, bcnt, rw) caddr_t udaddr; unsigned bcnt; { return (0); }
+skpc(mask, size, cp) int mask; char *cp; unsigned size; { return (0); }
 
 
+#ifdef notdef
 /*ARGSUSED*/
 /*ARGSUSED*/
-kernacc(addr, bcnt, rw) caddr_t addr; unsigned bcnt; { return (0); }
+locc(mask, size, cp) int mask; char *cp; unsigned size; { return (0); }
+#endif
 
 /*
 
 /*
- * Routines handled by asm.sed script.
+ * Routines expanded by inline.
  */
  */
+#ifdef notdef
+fuibyte(base) caddr_t base; { return (fubyte(base)); }
+#endif
+fuiword(base) caddr_t base; { return (fuword(base)); }
+suibyte(base, i) caddr_t base; { return (subyte(base, i)); }
+suiword(base, i) caddr_t base; { return (suword(base, i)); }
 
 
-/*VARARGS1*/
 /*ARGSUSED*/
 /*ARGSUSED*/
-mtpr(reg, value) int reg, value; { }
+setjmp(lp) label_t *lp; { return (0); }
 
 /*ARGSUSED*/
 
 /*ARGSUSED*/
-mfpr(reg) int reg; { return (0); }
-
-
-spl0() { }
-spl4() { return (0); }
-spl5() { return (0); }
-spl6() { return (0); }
-spl7() { return (0); }
-
+_insque(p, q) caddr_t p, q; { }
 /*ARGSUSED*/
 /*ARGSUSED*/
-splx(s) int s; { }
+_remque(p) caddr_t p; { }
 
 /*ARGSUSED*/
 
 /*ARGSUSED*/
-bcopy(from, to, count) caddr_t from, to; unsigned count; { ; }
-
+bcopy(from, to, len) caddr_t from, to; unsigned len; { }
 /*ARGSUSED*/
 /*ARGSUSED*/
-bzero(base, count) caddr_t base; unsigned count; { ; }
-
+bzero(base, count) caddr_t base; unsigned count; { }
 /*ARGSUSED*/
 /*ARGSUSED*/
-bcmp(s1, s2, count) caddr_t s1, s2; unsigned count; { return (0); }
+blkclr(base, count) caddr_t base; unsigned count; { }
 
 /*ARGSUSED*/
 
 /*ARGSUSED*/
-scanc(size, cp, table, mask)
-unsigned size; caddr_t cp, table; int mask; { return (0); }
-
+/*VARARGS1*/
+mtpr(reg, v) int reg; { }
 /*ARGSUSED*/
 /*ARGSUSED*/
-ffs(i) { return (0); }
+mfpr(reg) int reg; { return (0); }
 
 
-ntohs(s) u_short s; { return ((int)s); }
+/*ARGSUSED*/
+_movow(dst, v) u_short *dst, v; { }
+/*ARGSUSED*/
+_movob(dst, v) u_char *dst, v; { }
 
 
-htons(s) u_short s; { return ((int)s); }
+/*ARGSUSED*/
+ffs(v) long v; { return (0); }
 
 
-/*
- * Variables declared for savecore, or
- * implicitly, such as by config or the loader.
- */
-char   version[] = "4.2 BSD UNIX ....";
-char   etext;
+imin(a, b) int a, b; { return (a < b ? a : b); }
+imax(a, b) int a, b; { return (a > b ? a : b); }
+unsigned min(a, b) u_int a, b; { return (a < b ? a : b); }
+unsigned max(a, b) u_int a, b; { return (a > b ? a : b); }
index 934b514..c1eef16 100644 (file)
@@ -1,4 +1,4 @@
-/*     autoconf.c      1.1     85/07/21        */
+/*     autoconf.c      1.2     86/01/05        */
 
 /*
  * Setup the system to run on the current machine.
 
 /*
  * Setup the system to run on the current machine.
@@ -9,19 +9,20 @@
  * and the drivers are initialized.
  *
  */
  * and the drivers are initialized.
  *
  */
+#include "../tahoe/pte.h"
+#include "../tahoe/mem.h"
+#include "../tahoe/mtpr.h"
 
 
-#include "../machine/pte.h"
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/map.h"
-#include "../h/buf.h"
-#include "../h/dk.h"
-#include "../h/vm.h"
-#include "../h/conf.h"
-#include "../h/dmap.h"
-#include "../machine/mem.h"
-#include "../machine/mtpr.h"
-#include "../vba/vbavar.h"
+#include "param.h"
+#include "systm.h"
+#include "map.h"
+#include "buf.h"
+#include "dk.h"
+#include "vm.h"
+#include "conf.h"
+#include "dmap.h"
+
+#include "../tahoevba/vbavar.h"
 
 /*
  * The following several variables are related to
 
 /*
  * The following several variables are related to
@@ -36,10 +37,10 @@ int dkn;            /* number of iostat dk numbers assigned so far */
 configure()
 {
        register int *ip;
 configure()
 {
        register int *ip;
-       extern char Sysbase[];
+       extern caddr_t Sysbase;
 
 
-       printf("vba%d at 0x%x\n", numvba, IOBASE);
-       vbafind((char *)vmem,(struct pte *)VMEMmap);
+       printf("vba%d at %x\n", numvba-1, IOBASE);
+       vbafind(numvba-1, (char *)vmem,(struct pte *)VMEMmap);
        /*
         * Write protect the scb.  It is strange
         * that this code is here, but this is as soon
        /*
         * Write protect the scb.  It is strange
         * that this code is here, but this is as soon
@@ -48,7 +49,7 @@ configure()
         * to which we will never return.
         */
        ip = (int *)&Sysmap[2]; *ip &= ~PG_PROT; *ip |= PG_KR;
         * to which we will never return.
         */
        ip = (int *)&Sysmap[2]; *ip &= ~PG_PROT; *ip |= PG_KR;
-       mtpr(Sysbase+0x800, TBIS);
+       mtpr(TBIS, Sysbase+2*NBPG);
 #if GENERIC
        setconf();
 #endif
 #if GENERIC
        setconf();
 #endif
@@ -60,19 +61,17 @@ configure()
  * Make the controllers accessible at physical address phys
  * by mapping kernel ptes starting at pte.
  */
  * Make the controllers accessible at physical address phys
  * by mapping kernel ptes starting at pte.
  */
-
-ioaccess(pte,iobase,iosize)
+ioaccess(pte, iobase, n)
        register struct pte *pte;
        register struct pte *pte;
-       register caddr_t iobase;
-       register int    iosize;
+       caddr_t iobase;
+       register int n;
 {
 {
-       register int i = iosize;        /* number of ptes to map */
        register unsigned v = btop(iobase);
        
        do
                *(int *)pte++ = PG_V|PG_KW|v++;
        register unsigned v = btop(iobase);
        
        do
                *(int *)pte++ = PG_V|PG_KW|v++;
-       while (--i > 0);
-       mtpr(0, TBIA);
+       while (--n > 0);
+       mtpr(TBIA, 0);
 }
 
 
 }
 
 
@@ -85,7 +84,8 @@ ioaccess(pte,iobase,iosize)
 
 int    iospace_mapped = 0;
 
 
 int    iospace_mapped = 0;
 
-vbafind(vumem, memmap)
+vbafind(vban, vumem, memmap)
+       int vban;
        char *vumem;
        struct pte *memmap;
 {
        char *vumem;
        struct pte *memmap;
 {
@@ -100,11 +100,10 @@ vbafind(vumem, memmap)
         * Make the controllers accessible at physical address phys
         * by mapping kernel ptes starting at pte.
         */
         * Make the controllers accessible at physical address phys
         * by mapping kernel ptes starting at pte.
         */
-       ioaccess(memmap,IOBASE,IOSIZE);
+       ioaccess(memmap, IOBASE, (int)IOSIZE);
        iospace_mapped = 1;
 #define        vbaddr(off)     (u_short *)((int)vumem + ((off) & 0x0fffff))
 
        iospace_mapped = 1;
 #define        vbaddr(off)     (u_short *)((int)vumem + ((off) & 0x0fffff))
 
-
        /*
         * Check each VERSAbus mass storage controller.
         * For each one which is potentially on this vba,
        /*
         * Check each VERSAbus mass storage controller.
         * For each one which is potentially on this vba,
@@ -112,28 +111,28 @@ vbafind(vumem, memmap)
         * then go looking for slaves.
         */
        for (um = vbminit; udp = um->um_driver; um++) {
         * then go looking for slaves.
         */
        for (um = vbminit; udp = um->um_driver; um++) {
-               if (um->um_vbanum != numvba && um->um_vbanum != '?')
+               if (um->um_vbanum != vban && um->um_vbanum != '?')
                        continue;
                addr = (long)um->um_addr;
                reg = vbaddr(addr);
                i = (*udp->ud_probe)(reg);
                if (i == 0)
                        continue;
                        continue;
                addr = (long)um->um_addr;
                reg = vbaddr(addr);
                i = (*udp->ud_probe)(reg);
                if (i == 0)
                        continue;
-               printf("%s%d at csr 0x%x\n",
-                   udp->ud_mname, um->um_ctlr, addr);
+               printf("%s%d at vba%d csr %x\n",
+                   udp->ud_mname, um->um_ctlr, vban, addr);
                um->um_alive = 1;
                um->um_alive = 1;
-               um->um_vbanum = numvba;
+               um->um_vbanum = vban;
                um->um_addr = (caddr_t)reg;
                udp->ud_minfo[um->um_ctlr] = um;
                for (ui = vbdinit; ui->ui_driver; ui++) {
                        if (ui->ui_driver != udp || ui->ui_alive ||
                            ui->ui_ctlr != um->um_ctlr && ui->ui_ctlr != '?' ||
                um->um_addr = (caddr_t)reg;
                udp->ud_minfo[um->um_ctlr] = um;
                for (ui = vbdinit; ui->ui_driver; ui++) {
                        if (ui->ui_driver != udp || ui->ui_alive ||
                            ui->ui_ctlr != um->um_ctlr && ui->ui_ctlr != '?' ||
-                           ui->ui_vbanum != numvba && ui->ui_vbanum != '?')
+                           ui->ui_vbanum != vban && ui->ui_vbanum != '?')
                                continue;
                        if ((*udp->ud_slave)(ui, reg)) {
                                ui->ui_alive = 1;
                                ui->ui_ctlr = um->um_ctlr;
                                continue;
                        if ((*udp->ud_slave)(ui, reg)) {
                                ui->ui_alive = 1;
                                ui->ui_ctlr = um->um_ctlr;
-                               ui->ui_vbanum = numvba;
+                               ui->ui_vbanum = vban;
                                ui->ui_addr = (caddr_t)reg;
                                ui->ui_physaddr = (caddr_t)IOBASE + (addr&0x0fffff);
                                if (ui->ui_dk && dkn < DK_NDRIVE)
                                ui->ui_addr = (caddr_t)reg;
                                ui->ui_physaddr = (caddr_t)IOBASE + (addr&0x0fffff);
                                if (ui->ui_dk && dkn < DK_NDRIVE)
@@ -155,7 +154,7 @@ vbafind(vumem, memmap)
         * Now look for non-mass storage peripherals.
         */
        for (ui = vbdinit; udp = ui->ui_driver; ui++) {
         * Now look for non-mass storage peripherals.
         */
        for (ui = vbdinit; udp = ui->ui_driver; ui++) {
-               if (ui->ui_vbanum != numvba && ui->ui_vbanum != '?' ||
+               if (ui->ui_vbanum != vban && ui->ui_vbanum != '?' ||
                    ui->ui_alive || ui->ui_slave != -1)
                        continue;
                addr = (long)ui->ui_addr;
                    ui->ui_alive || ui->ui_slave != -1)
                        continue;
                addr = (long)ui->ui_addr;
@@ -165,10 +164,10 @@ vbafind(vumem, memmap)
                i = (*udp->ud_probe)(reg);
                if (i == 0)
                        continue;
                i = (*udp->ud_probe)(reg);
                if (i == 0)
                        continue;
-               printf("%s%d at csr 0x%x\n",
-                   ui->ui_driver->ud_dname, ui->ui_unit, addr);
+               printf("%s%d at vba%d csr %x\n",
+                   ui->ui_driver->ud_dname, ui->ui_unit, vban, addr);
                ui->ui_alive = 1;
                ui->ui_alive = 1;
-               ui->ui_vbanum = numvba;
+               ui->ui_vbanum = vban;
                ui->ui_addr = (caddr_t)reg;
                ui->ui_physaddr = (caddr_t)IOBASE + (addr&0x0fffff);
                ui->ui_dk = -1;
                ui->ui_addr = (caddr_t)reg;
                ui->ui_physaddr = (caddr_t)IOBASE + (addr&0x0fffff);
                ui->ui_dk = -1;
@@ -179,10 +178,7 @@ vbafind(vumem, memmap)
 }
 
 
 }
 
 
-#define        DMMIN   32
-#define        DMMAX   1024
-#define        DMTEXT  1024
-#define        MAXDUMP (10*2048)
+#define        MAXDUMP (8*1024)
 /*
  * Configure swap space and related parameters.
  */
 /*
  * Configure swap space and related parameters.
  */
@@ -202,12 +198,4 @@ swapconf()
                dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) - MAXDUMP;
        if (dumplo < 0)
                dumplo = 0;
                dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) - MAXDUMP;
        if (dumplo < 0)
                dumplo = 0;
-       if (dmmin == 0)
-               dmmin = DMMIN;
-       if (dmmax == 0)
-               dmmax = DMMAX;
-       if (dmtext == 0)
-               dmtext = DMTEXT;
-       if (dmtext > dmmax)
-               dmtext = dmmax;
 }
 }
index 2175a2c..9023498 100644 (file)
@@ -1,4 +1,4 @@
-/*     clock.c 1.1     85/07/22        */
+/*     clock.c 1.2     86/01/05        */
 
 #include "../h/param.h"
 #include "../h/time.h"
 
 #include "../h/param.h"
 #include "../h/time.h"
index ced7818..24565e0 100644 (file)
@@ -1,12 +1,11 @@
-/*     conf.c  1.3     85/04/25        */
-/*     conf.c  6.1     83/07/29        */
+/*     conf.c  1.2     86/01/05        */
 
 
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/buf.h"
-#include "../h/ioctl.h"
-#include "../h/tty.h"
-#include "../h/conf.h"
+#include "param.h"
+#include "systm.h"
+#include "buf.h"
+#include "ioctl.h"
+#include "tty.h"
+#include "conf.h"
 
 int    nulldev();
 int    nodev();
 
 int    nulldev();
 int    nodev();
@@ -81,7 +80,7 @@ struct bdevsw bdevsw[] =
 int    nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]);
 
 int    cnopen(),cnclose(),cnread(),cnwrite(),cnioctl();
 int    nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]);
 
 int    cnopen(),cnclose(),cnread(),cnwrite(),cnioctl();
-struct tty cons[];
+extern struct tty cons;
 
 #include "vx.h"
 #if NVX == 0
 
 #include "vx.h"
 #if NVX == 0
@@ -180,12 +179,14 @@ int       efsopen(),efsfgen(),efsread(),efswrite(),efsioctl(),efsreset();
 #define efsreset nodev
 #endif
 
 #define efsreset nodev
 #endif
 
+int    logopen(),logclose(),logread(),logioctl(),logselect();
+
 int    ttselect(), seltrue();
 
 struct cdevsw  cdevsw[] =
 {
        cnopen,         cnclose,        cnread,         cnwrite,        /*0*/
 int    ttselect(), seltrue();
 
 struct cdevsw  cdevsw[] =
 {
        cnopen,         cnclose,        cnread,         cnwrite,        /*0*/
-       cnioctl,        nulldev,        nulldev,        cons,
+       cnioctl,        nulldev,        nulldev,        &cons,
        ttselect,       nodev,
        vxopen,         vxclose,        vxread,         vxwrite,        /*1*/
        vxioctl,        vxstop,         vxreset,        vx_tty,
        ttselect,       nodev,
        vxopen,         vxclose,        vxread,         vxwrite,        /*1*/
        vxioctl,        vxstop,         vxreset,        vx_tty,
@@ -229,9 +230,9 @@ struct cdevsw       cdevsw[] =
        iiopen,         iiclose,        nulldev,        nulldev,        /*14*/
        iiioctl,        nulldev,        nulldev,        0,
        seltrue,        nodev,
        iiopen,         iiclose,        nulldev,        nulldev,        /*14*/
        iiioctl,        nulldev,        nulldev,        0,
        seltrue,        nodev,
-       nodev,          nodev,          nulldev,        nulldev,        /*15*/
-       nodev,          nodev,          nulldev,        0,
-       nodev,          nodev,
+       logopen,        logclose,       logread,        nodev,          /*15*/
+       logioctl,       nodev,          nulldev,        0,
+       logselect,      nodev,
        nodev,          nodev,          nulldev,        nulldev,        /*16*/
        nodev,          nodev,          nulldev,        0,
        nodev,          nodev,
        nodev,          nodev,          nulldev,        nulldev,        /*16*/
        nodev,          nodev,          nulldev,        0,
        nodev,          nodev,
index 81cc1f0..2ea233b 100644 (file)
@@ -1,4 +1,4 @@
-/*     cons.c  1.1     85/07/21        */
+/*     cons.c  1.2     86/01/05        */
 /*     Minor device 0 is the CP itself.
 /*       No real read/writes can be done to him.
 /*     Minor 1 is the console terminal.
 /*     Minor device 0 is the CP itself.
 /*       No real read/writes can be done to him.
 /*     Minor 1 is the console terminal.
@@ -9,81 +9,77 @@
  * Tahoe console processor driver
  *
  */
  * Tahoe console processor driver
  *
  */
-#include "../h/param.h"
-#include "../h/conf.h"
-#include "../h/dir.h"
-#include "../h/ioctl.h"
-#include "../h/user.h"
-#include "../h/tty.h"
-#include "../h/uio.h"
-#include "../h/callout.h"
-#include "../h/systm.h"
-#include "../machine/cp.h"
-#include "../machine/mtpr.h"
+#include "param.h"
+#include "conf.h"
+#include "dir.h"
+#include "ioctl.h"
+#include "user.h"
+#include "proc.h"
+#include "tty.h"
+#include "uio.h"
+#include "callout.h"
+#include "systm.h"
 
 
-#define FALSE 0
-#define TRUE  1
+#include "../tahoe/cp.h"
+#include "../tahoe/mtpr.h"
 
 
-int    cnrestart() ;
-int    timeout() ;
+int    cnrestart();
+int    timeout();
 
 
-struct tty cons[3];    /* One for each unit on CP */
-struct cons_info {
-       char    last_one;       /* Last char sent - possibly repeat
-                                * If zero, timeout has nothing to do
-                                */
-       int     active_timeout; /* There is an active timeout for this line
-                                * Set by 'cnputc' when a timeout is initiated.
-                                * Reset by the routine  called at timeout.
-                                */
-       int     try_later;      /* If true, timeout has nothing to do.
-                                * Set by 'cnputc' every time a char is sent.
-                                * Reset by the timeout arrival. If next time
-                                * the timeout comes it's zero, then it may
-                                * have something to do.
-                                */
-       } cons_info[3];
+struct tty cons;
+struct tty CPtty;
+struct tty RLtty;
+struct tty *constty[3] = { &CPtty, &cons, &RLtty };
+struct consoftc {
+       char    cs_lastc;       /* last char sent */
+       int     cs_flags;
+#define        CSF_ACTIVE      0x1     /* timeout active */
+#define        CSF_RETRY       0x2     /* try again at a later time */
+} consoftc[3];
 struct cpdcb_o consout[3] = { 
 struct cpdcb_o consout[3] = { 
-                       /*      unit,           cmd,count, buf */
-                       {(char)(CPTAKE | CPDONE),0,   0 },
-                       {(char)(CPTAKE | CPDONE),0,   0 },
-                       {(char)(CPTAKE | CPDONE),0,   0 }
-                       };
+       /*      unit,           cmd,count, buf */
+       (char)(CPTAKE | CPDONE),0,   0 },
+       (char)(CPTAKE | CPDONE),0,   0 },
+       (char)(CPTAKE | CPDONE),0,   0 }
+};
 struct cpdcb_i consin[3] = {
 struct cpdcb_i consin[3] = {
-                       /*      unit,           cmd,count, buf */
-                       {(char)(CPTAKE | CPDONE),0,   0 },
-                       {(char)(CPTAKE | CPDONE),0,   0 },
-                       {(char)(CPTAKE | CPDONE),0,   0 }
-                       };
+       /*      unit,           cmd,count, buf */
+       (char)(CPTAKE | CPDONE),0,   0 },
+       (char)(CPTAKE | CPDONE),0,   0 },
+       (char)(CPTAKE | CPDONE),0,   0 }
+};
 struct cphdr *lasthdr;
 
 int    cnstart();
 int    ttrstrt();
 char   partab[];
 
 struct cphdr *lasthdr;
 
 int    cnstart();
 int    ttrstrt();
 char   partab[];
 
+/*ARGSUSED*/
 cnopen(dev, flag)
 cnopen(dev, flag)
-dev_t dev;
+       dev_t dev;
 {
        register struct cpdcb_i *cin;
        register struct tty *tp;
 {
        register struct cpdcb_i *cin;
        register struct tty *tp;
-       register int timo;
+       int unit = minor(dev);
 
 
-       if (minor(dev) > CPREMOT) 
-               return EEXIST;
-       tp = &cons[minor(dev)];
+       if (unit > CPREMOT) 
+               return (EEXIST);
+       tp = constty[unit];
        if (tp->t_state&TS_XCLUDE && u.u_uid != 0)
        if (tp->t_state&TS_XCLUDE && u.u_uid != 0)
-               return EBUSY;
+               return (EBUSY);
        if (lasthdr != (struct cphdr *)0) {
        if (lasthdr != (struct cphdr *)0) {
+               register int timo;
+
                timo = 10000;
                timo = 10000;
-               uncache((char *)&lasthdr->cp_unit);
-               while ((lasthdr->cp_unit & CPTAKE)==0 && --timo )
-                       uncache((char *)&lasthdr->cp_unit);
-       }       /* Here we give up waiting */
-       cin = &consin[minor(dev)];
-       cin->cp_hdr.cp_unit = (char)(minor(dev));
-       cin->cp_hdr.cp_comm = (char)CPREAD;
+               uncache(&lasthdr->cp_unit);
+               while ((lasthdr->cp_unit&CPTAKE) == 0 && --timo)
+                       uncache(&lasthdr->cp_unit);
+       }
+       cin = &consin[unit];
+       cin->cp_hdr.cp_unit = unit;
+       cin->cp_hdr.cp_comm = CPREAD;
        cin->cp_hdr.cp_count = 1;       /* Get ready for input */
        cin->cp_hdr.cp_count = 1;       /* Get ready for input */
-       mtpr (cin, CPMDCB);
+       mtpr(CPMDCB, cin);
        lasthdr = (struct cphdr *)cin;
        tp->t_oproc = cnstart;
        tp->t_dev = dev;
        lasthdr = (struct cphdr *)cin;
        tp->t_oproc = cnstart;
        tp->t_dev = dev;
@@ -92,13 +88,13 @@ dev_t dev;
                tp->t_state = TS_ISOPEN|TS_CARR_ON;
                tp->t_flags = EVENP|ECHO|XTABS|CRMOD;
        }
                tp->t_state = TS_ISOPEN|TS_CARR_ON;
                tp->t_flags = EVENP|ECHO|XTABS|CRMOD;
        }
-       (*linesw[tp->t_line].l_open)(dev, tp);
+       return ((*linesw[tp->t_line].l_open)(dev, tp));
 }
 
 cnclose(dev)
 }
 
 cnclose(dev)
-dev_t dev;
+       dev_t dev;
 {
 {
-       register struct tty *tp = &cons[minor(dev)];
+       register struct tty *tp = constty[minor(dev)];
 
        (*linesw[tp->t_line].l_close)(tp);
        ttyclose(tp);
 
        (*linesw[tp->t_line].l_close)(tp);
        ttyclose(tp);
@@ -109,7 +105,7 @@ cnread(dev, uio)
        dev_t dev;
        struct uio *uio;
 {
        dev_t dev;
        struct uio *uio;
 {
-       register struct tty *tp = &cons[minor(dev)];
+       struct tty *tp = constty[minor(dev)];
 
        return ((*linesw[tp->t_line].l_read)(tp, uio));
 }
 
        return ((*linesw[tp->t_line].l_read)(tp, uio));
 }
@@ -119,7 +115,7 @@ cnwrite(dev, uio)
        dev_t dev;
        struct uio *uio;
 {
        dev_t dev;
        struct uio *uio;
 {
-       register struct tty *tp = &cons[minor(dev)];
+       struct tty *tp = constty[minor(dev)];
 
        return ((*linesw[tp->t_line].l_write)(tp, uio));
 }
 
        return ((*linesw[tp->t_line].l_write)(tp, uio));
 }
@@ -130,40 +126,42 @@ cnwrite(dev, uio)
  * Catch the character, and see who it goes to.
  */
 cnrint(dev)
  * Catch the character, and see who it goes to.
  */
 cnrint(dev)
-dev_t dev;
+       dev_t dev;
 {
        register int c, timo;
        register struct tty *tp;
 {
        register int c, timo;
        register struct tty *tp;
+       int unit;
 
 
-       if (intenable == 0) return;
+       if (intenable == 0)
+               return;
+       unit = minor(dev);
        /* make sure we dont take it from cache */
        /* make sure we dont take it from cache */
-       uncache((char *)&consin[minor(dev)].cpi_buf[0]);
-       c = consin[minor(dev)].cpi_buf[0];
+       uncache(&consin[unit].cpi_buf[0]);
+       c = consin[unit].cpi_buf[0];
 /*
 /* Wait about 5 milli for last CPMDCB to be read by CP,
 /* otherwise give up
 /**/
        timo = 10000;
 /*
 /* Wait about 5 milli for last CPMDCB to be read by CP,
 /* otherwise give up
 /**/
        timo = 10000;
-       uncache((char *)&lasthdr->cp_unit);
-       while ((lasthdr->cp_unit & CPTAKE)==0  && --timo  )
-               uncache((char *)&lasthdr->cp_unit);
-       uncache((char *)&lasthdr->cp_unit);
-       if (lasthdr->cp_unit & CPTAKE)
-       {
-               consin[minor(dev)].cp_hdr.cp_unit = (char)(minor(dev));
+       uncache(&lasthdr->cp_unit);
+       while ((lasthdr->cp_unit&CPTAKE) == 0  && --timo)
+               uncache(&lasthdr->cp_unit);
+       uncache(&lasthdr->cp_unit);
+       if (lasthdr->cp_unit&CPTAKE) {
+               consin[unit].cp_hdr.cp_unit = unit;
                        /* This resets status bits */
                        /* This resets status bits */
-               mtpr (&consin[minor(dev)], CPMDCB); /* Ready for new character */
-               lasthdr = (struct cphdr *)&consin[minor(dev)];
-               tp = &cons[minor(dev)];
+               mtpr(CPMDCB, &consin[unit]); /* Ready for new character */
+               lasthdr = (struct cphdr *)&consin[unit];
+               tp = constty[unit];
                (*linesw[tp->t_line].l_rint)(c, tp);
        }
 }
 
 cnioctl(dev, cmd, addr, flag)
                (*linesw[tp->t_line].l_rint)(c, tp);
        }
 }
 
 cnioctl(dev, cmd, addr, flag)
-dev_t dev;
-caddr_t addr;
+       dev_t dev;
+       caddr_t addr;
 {
 {
-       register struct tty *tp = &cons[minor(dev)];
+       register struct tty *tp = constty[minor(dev)];
        register error;
  
        error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, addr);
        register error;
  
        error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, addr);
@@ -171,9 +169,9 @@ caddr_t addr;
                return error;
        if ((error = ttioctl(tp, cmd, addr, flag)) < 0)
                error = ENOTTY;
                return error;
        if ((error = ttioctl(tp, cmd, addr, flag)) < 0)
                error = ENOTTY;
-       else if(cmd==TIOCSETP || cmd==TIOCSETN)
+       else if (cmd == TIOCSETP || cmd == TIOCSETN)
                cnparams(tp);
                cnparams(tp);
-       return error;
+       return (error);
 }
 
 int    consintr = 1;
 }
 
 int    consintr = 1;
@@ -182,20 +180,20 @@ int       consintr = 1;
  * the console processor wants another character.
  */
 cnxint(dev)
  * the console processor wants another character.
  */
 cnxint(dev)
-dev_t dev;
+       dev_t dev;
 {
        register struct tty *tp;
 {
        register struct tty *tp;
-       register int line_no;
+       register int unit;
 
 
-       if (intenable == 0 || consintr == 0) return;
-#ifdef CPPERF
-       if (minor(dev)==CPCONS) scope_in(1);
-       else scope_in(2);
+       if (intenable == 0 || consintr == 0)
+               return;
+       unit = minor(dev);
+#ifdef CPPERF
+       scope_in(unit == CPCONS ? 1 : 2);
 #endif
 #endif
-       line_no = minor(dev);
-       tp = &cons[line_no];
+       tp = constty[unit];
        tp->t_state &= ~TS_BUSY;
        tp->t_state &= ~TS_BUSY;
-       cons_info[line_no].last_one = (char)0;
+       consoftc[unit].cs_lastc = (char)0;
        if (tp->t_line)
                (*linesw[tp->t_line].l_start)(tp);
        else
        if (tp->t_line)
                (*linesw[tp->t_line].l_start)(tp);
        else
@@ -203,14 +201,12 @@ dev_t dev;
 }
 
 cnstart(tp)
 }
 
 cnstart(tp)
-register struct tty *tp;
+       register struct tty *tp;
 {
 {
-       register c;
-       register s;
+       register c, s;
 
 #ifdef CPPERF
 
 #ifdef CPPERF
-       if (minor(tp->t_dev)==CPCONS) scope_in(3);
-       else scope_in(4);
+       scope_in(minor(tp->t_dev) == CPCONS ? 3 : 4);
 #endif
        s = spl8();
        if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
 #endif
        s = spl8();
        if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
@@ -230,40 +226,48 @@ register struct tty *tp;
                goto out;
        c = getc(&tp->t_outq) & 0xff;
        if (tp->t_flags&(RAW|LITOUT))
                goto out;
        c = getc(&tp->t_outq) & 0xff;
        if (tp->t_flags&(RAW|LITOUT))
-               cnputc(c,tp);
-       else if (c<=0177)
-               cnputc ((c | (partab[c]&0200))&0xff,tp);
+               cnputchar(c, tp);
+       else if (c <= 0177)
+               cnputchar((c | (partab[c]&0200))&0xff, tp);
        else {
                timeout(ttrstrt, (caddr_t)tp, (c&0177));
                tp->t_state |= TS_TIMEOUT;
                goto out;
        }
        tp->t_state |= TS_BUSY;
        else {
                timeout(ttrstrt, (caddr_t)tp, (c&0177));
                tp->t_state |= TS_TIMEOUT;
                goto out;
        }
        tp->t_state |= TS_BUSY;
-    out:
+out:
        splx(s);
 }
 
        splx(s);
 }
 
+cnputc(c)
+       char c;
+{
+
+       if (c == '\n')
+               cnputchar('\r', (struct tty *)0);
+       cnputchar(c, (struct tty *)0);
+}
+
 /*
  * Print a character on console.
  */
 /*
  * Print a character on console.
  */
-cnputc(c,tp)
-register char c;
-register struct tty *tp;
+cnputchar(c,tp)
+       register char c;
+       register struct tty *tp;
 {
 {
-       register timo , line_no, s;
+       register timo, unit;
        register struct cpdcb_o *current;
 
        /* tp == 0 only in system error messages */
        if (tp == 0) {
                current = &consout[CPCONS];
        register struct cpdcb_o *current;
 
        /* tp == 0 only in system error messages */
        if (tp == 0) {
                current = &consout[CPCONS];
-               line_no = CPCONS;
-               if(lasthdr == 0)        /* not done anythig yet */
+               unit = CPCONS;
+               if (lasthdr == 0)       /* not done anythig yet */
                        lasthdr = (struct cphdr *)current;
                c |= partab[c&0177]&0200;
                        lasthdr = (struct cphdr *)current;
                c |= partab[c&0177]&0200;
-       }
-       else {
+       } else {
                current = &consout[minor(tp->t_dev)];
                current = &consout[minor(tp->t_dev)];
-               line_no = minor(tp->t_dev);
+               unit = minor(tp->t_dev);
        }
        timo = 30000;
        /*
        }
        timo = 30000;
        /*
@@ -271,66 +275,63 @@ register struct tty *tp;
         * otherwise give up after a reasonable time.
         * make sure we dont test this bit in cache!
         */
         * otherwise give up after a reasonable time.
         * make sure we dont test this bit in cache!
         */
-       uncache((char *)&current->cp_hdr.cp_unit);
-       while ((current->cp_hdr.cp_unit & CPDONE) == 0 && --timo )
-               uncache((char *)&current->cp_hdr.cp_unit);
-       current->cp_hdr.cp_comm = (char)CPWRITE;
+       uncache(&current->cp_hdr.cp_unit);
+       while ((current->cp_hdr.cp_unit&CPDONE) == 0 && --timo)
+               uncache(&current->cp_hdr.cp_unit);
+       current->cp_hdr.cp_comm = CPWRITE;
        current->cp_hdr.cp_count = 1;
        current->cp_hdr.cp_count = 1;
-       current->cp_buf[0] = (char)(c & 0xff);
+       current->cp_buf[0] = c & 0xff;
        timo = 10000;
        /*
         * Try waiting for the console tty to come ready,
         * otherwise give up after a reasonable time.
         */
        timo = 10000;
        /*
         * Try waiting for the console tty to come ready,
         * otherwise give up after a reasonable time.
         */
-       uncache((char *)&lasthdr->cp_unit);
-       while ((lasthdr->cp_unit & CPTAKE)==0 && --timo )
-               uncache((char *)&lasthdr->cp_unit);
+       uncache(&lasthdr->cp_unit);
+       while ((lasthdr->cp_unit&CPTAKE) == 0 && --timo)
+               uncache(&lasthdr->cp_unit);
        /* Reset done bit */
        /* Reset done bit */
-       current->cp_hdr.cp_unit = (char)line_no; 
+       current->cp_hdr.cp_unit = (char)unit;
        lasthdr = (struct cphdr *)current;
 #ifdef CPPERF
        lasthdr = (struct cphdr *)current;
 #ifdef CPPERF
-       if (intenable != 0) scope_in(5);
+       if (intenable != 0)
+               scope_in(5);
 #endif
 #endif
-       cons_info[line_no].last_one = c;
-       if ( !cons_info[line_no].active_timeout && clk_enable) {
-               cons_info[line_no].active_timeout = TRUE;
-               timeout (cnrestart, (caddr_t)tp, 10);
+       consoftc[unit].cs_lastc = c;
+       if ((consoftc[unit].cs_flags&CSF_ACTIVE) == 0 && clk_enable) {
+               consoftc[unit].cs_flags |= CSF_ACTIVE;
+               timeout(cnrestart, (caddr_t)tp, 10);
        }
        }
-       cons_info[line_no].try_later = TRUE; /* For timeout-means wait some more */
-       mtpr (current, CPMDCB);
+       consoftc[unit].cs_flags |= CSF_RETRY;   /* wait some more */
+       mtpr(CPMDCB, current);
 }
 
 /*
  * Restart (if necessary) transfer to CP line.
  * This way, lost 'transmit' interrupts don't break the chain.
  */
 }
 
 /*
  * Restart (if necessary) transfer to CP line.
  * This way, lost 'transmit' interrupts don't break the chain.
  */
-cnrestart (tp)
-struct tty *tp;
+cnrestart(tp)
+       struct tty *tp;
 {
 {
-       register line_no, s;
+       register struct consoftc *cs;
 
 
-       if (tp == 0) {
-               line_no = CPCONS;
-       } else
-               line_no = minor(tp->t_dev);
-       if (cons_info[line_no].try_later) {
-               cons_info[line_no].try_later = FALSE;
-               timeout (cnrestart, (caddr_t)tp, 10);
-       }
-       else {
-               cons_info[line_no].active_timeout = FALSE;
-               if (cons_info[line_no].last_one != (char)0)
-                       cnputc (cons_info[line_no].last_one, tp);
+       cs = &consoftc[tp == 0 ? CPCONS : minor(tp->t_dev)];
+       if (cs->cs_flags&CSF_RETRY) {
+               cs->cs_flags &= ~CSF_RETRY;
+               timeout(cnrestart, (caddr_t)tp, 10);
+               return;
        }
        }
+       cs->cs_flags &= ~CSF_ACTIVE;
+       if (cs->cs_lastc != (char)0)
+               cnputchar(cs->cs_lastc, tp);
 }
 
 /*
  * Set line parameters
  */
 cnparams(tp)
 }
 
 /*
  * Set line parameters
  */
 cnparams(tp)
-register struct tty *tp;
+       register struct tty *tp;
 {
 {
-       register timo ;
+       register timo;
        register struct cpdcb_o *current;
        register struct cpdcb_i *cin;
 
        register struct cpdcb_o *current;
        register struct cpdcb_i *cin;
 
@@ -341,38 +342,37 @@ register struct tty *tp;
         * otherwise give up after a reasonable time.
         * make sure we dont test this bit in cache!
         */
         * otherwise give up after a reasonable time.
         * make sure we dont test this bit in cache!
         */
-       uncache((char *)&current->cp_hdr.cp_unit);
-       while ((current->cp_hdr.cp_unit & CPDONE) == 0 && --timo )
-               uncache((char *)&current->cp_hdr.cp_unit);
-       current->cp_hdr.cp_comm = (char)CPSTTY;
+       uncache(&current->cp_hdr.cp_unit);
+       while ((current->cp_hdr.cp_unit&CPDONE) == 0 && --timo)
+               uncache(&current->cp_hdr.cp_unit);
+       current->cp_hdr.cp_comm = CPSTTY;
        current->cp_hdr.cp_count = 4;
        current->cp_buf[0] = tp->t_ispeed;
        /* the rest are defaults */
        current->cp_buf[1] = 0; /* no parity */
        current->cp_hdr.cp_count = 4;
        current->cp_buf[0] = tp->t_ispeed;
        /* the rest are defaults */
        current->cp_buf[1] = 0; /* no parity */
-       current->cp_buf[2] = 0; /* stop bits */
-       current->cp_buf[3] = 8; /* data bits */
+       current->cp_buf[2] = 0; /* stop bits */
+       current->cp_buf[3] = 8; /* data bits */
        timo = 10000;
        /*
         * Try waiting for the console tty to come ready,
         * otherwise give up after a reasonable time.
         */
        timo = 10000;
        /*
         * Try waiting for the console tty to come ready,
         * otherwise give up after a reasonable time.
         */
-       uncache((char *)&lasthdr->cp_unit);
-       while ((lasthdr->cp_unit & CPTAKE)==0 && --timo )
-               uncache((char *)&lasthdr->cp_unit);
+       uncache(&lasthdr->cp_unit);
+       while ((lasthdr->cp_unit&CPTAKE) == 0 && --timo)
+               uncache(&lasthdr->cp_unit);
        /* Reset done bit */
        current->cp_hdr.cp_unit = (char)minor(tp->t_dev); 
        lasthdr = (struct cphdr *)current;
        /* Reset done bit */
        current->cp_hdr.cp_unit = (char)minor(tp->t_dev); 
        lasthdr = (struct cphdr *)current;
-       mtpr (current, CPMDCB);
+       mtpr(CPMDCB, current);
 
        timo = 10000;
 
        timo = 10000;
-       uncache((char *)&lasthdr->cp_unit);
-       while ((lasthdr->cp_unit & CPTAKE)==0 && --timo )
-               uncache((char *)&lasthdr->cp_unit);
+       uncache(&lasthdr->cp_unit);
+       while ((lasthdr->cp_unit&CPTAKE) == 0 && --timo)
+               uncache(&lasthdr->cp_unit);
        cin = &consin[minor(tp->t_dev)];
        cin = &consin[minor(tp->t_dev)];
-       cin->cp_hdr.cp_unit = (char)(minor(tp->t_dev));
-       cin->cp_hdr.cp_comm = (char)CPREAD;
+       cin->cp_hdr.cp_unit = minor(tp->t_dev);
+       cin->cp_hdr.cp_comm = CPREAD;
        cin->cp_hdr.cp_count = 1;       /* Get ready for input */
        cin->cp_hdr.cp_count = 1;       /* Get ready for input */
-       mtpr (cin, CPMDCB);
+       mtpr(CPMDCB, cin);
        lasthdr = (struct cphdr *)cin;
        lasthdr = (struct cphdr *)cin;
-
 }
 }
index aad9899..34acb5a 100644 (file)
@@ -1,11 +1,10 @@
-/*     in_cksum.c      6.1     83/07/29        */
+/*     in_cksum.c      1.2     86/01/05        */
 
 #include "../h/types.h"
 #include "../h/mbuf.h"
 #include "../netinet/in.h"
 #include "../netinet/in_systm.h"
 
 
 #include "../h/types.h"
 #include "../h/mbuf.h"
 #include "../netinet/in.h"
 #include "../netinet/in_systm.h"
 
-#if defined(tahoe)
 /*
  * Checksum routine for Internet Protocol family headers.
  *
 /*
  * Checksum routine for Internet Protocol family headers.
  *
@@ -35,11 +34,8 @@ in_cksum(m, len)
        register int mlen = 0;
 
        for (;m && len; m = m->m_next) {
        register int mlen = 0;
 
        for (;m && len; m = m->m_next) {
-
-               if (m->m_len == 0) {
+               if (m->m_len == 0)
                        continue;
                        continue;
-               }
-
                w = mtod(m, u_short *);
                if (mlen == -1) {
                        /*
                w = mtod(m, u_short *);
                if (mlen == -1) {
                        /*
@@ -54,7 +50,6 @@ in_cksum(m, len)
                        u.c[1] = *(u_char *)w;
                        sum += u.s;
                        ADDCARRY(sum);
                        u.c[1] = *(u_char *)w;
                        sum += u.s;
                        ADDCARRY(sum);
-
                        w = (u_short *)((char *)w + 1);
                        mlen = m->m_len - 1;
                        len--;
                        w = (u_short *)((char *)w + 1);
                        mlen = m->m_len - 1;
                        len--;
@@ -69,20 +64,17 @@ in_cksum(m, len)
                 * add by words.
                 */
                while ((mlen -= 2) >= 0) {
                 * add by words.
                 */
                while ((mlen -= 2) >= 0) {
-                       
                        if ((int)w & 0x1) {
                                /* word is not aligned */
                                u.c[0] = *(char *)w;
                                u.c[1] = *((char *)w+1);
                                sum += u.s;
                                w++;
                        if ((int)w & 0x1) {
                                /* word is not aligned */
                                u.c[0] = *(char *)w;
                                u.c[1] = *((char *)w+1);
                                sum += u.s;
                                w++;
-                       }
-                       else {
+                       } else
                                sum += *w++;
                                sum += *w++;
-                       }
                        ADDCARRY(sum);
                }
                        ADDCARRY(sum);
                }
-               if (mlen == -1) {
+               if (mlen == -1)
                        /*
                         * This mbuf has odd number of bytes. 
                         * There could be a word split betwen
                        /*
                         * This mbuf has odd number of bytes. 
                         * There could be a word split betwen
@@ -90,7 +82,6 @@ in_cksum(m, len)
                         * Save the last byte (to prepend to next mbuf).
                         */
                        u.c[0] = *(u_char *)w;
                         * Save the last byte (to prepend to next mbuf).
                         */
                        u.c[0] = *(u_char *)w;
-               }
        }
        if (len)
                printf("cksum: out of data\n");
        }
        if (len)
                printf("cksum: out of data\n");
@@ -101,134 +92,5 @@ in_cksum(m, len)
                sum += u.s;
                ADDCARRY(sum);
        }
                sum += u.s;
                ADDCARRY(sum);
        }
-done:
        return (~sum & 0xffff);
 }
        return (~sum & 0xffff);
 }
-#endif
-
-#if defined(vax)
-
-/*
- * Checksum routine for Internet Protocol family headers (VAX Version).
- *
- * This routine is very heavily used in the network
- * code and should be modified for each CPU to be as fast as possible.
- */
-
-in_cksum(m, len)
-       register struct mbuf *m;
-       register int len;
-{
-       register u_short *w;            /* on Tahoe, known to be r10 */
-       register int sum = 0;           /* on Tahoe, known to be r9 */
-       register int mlen = 0;
-
-       for (;;) {
-               /*
-                * Each trip around loop adds in
-                * word from one mbuf segment.
-                */
-               w = mtod(m, u_short *);
-               if (mlen == -1) {
-                       /*
-                        * There is a byte left from the last segment;
-                        * add it into the checksum.  Don't have to worry
-                        * about a carry-out here because we make sure
-                        * that high part of (32 bit) sum is small below.
-                        */
-                       sum += *(u_char *)w << 8;
-                       w = (u_short *)((char *)w + 1);
-                       mlen = m->m_len - 1;
-                       len--;
-               } else
-                       mlen = m->m_len;
-               m = m->m_next;
-               if (len < mlen)
-                       mlen = len;
-               len -= mlen;
-               /*
-                * Force to long boundary so we do longword aligned
-                * memory operations.  
-                */
-               if (((int)w&0x1) && mlen >= 1) {
-                       sum += *(u_char *)w++;
-                       mlen -= 1;
-               }
-               if (((int)w&0x2) && mlen >= 2) {
-                       sum += *w++;
-                       mlen -= 2;
-               }
-               /*
-                * Do as much of the checksum as possible 32 bits at at time.
-                * In fact, this loop is unrolled to make overhead from
-                * branches &c small.
-                *
-                * We can do a 16 bit ones complement sum 32 bits at a time
-                * because the 32 bit register is acting as two 16 bit
-                * registers for adding, with carries from the low added
-                * into the high (by normal carry-chaining) and carries
-                * from the high carried into the low on the next word
-                * by use of the adwc instruction.  This lets us run
-                * this loop at almost memory speed.
-                *
-                * Here there is the danger of high order carry out, and
-                * we carefully use adwc.
-                */
-               while ((mlen -= 32) >= 0) {
-#undef ADD
-                       asm("clrl r0");         /* clears carry */
-#define ADD            asm("adwc (r10),r9;addl2 $4,r10; ");
-                       ADD; ADD; ADD; ADD; ADD; ADD; ADD; ADD;
-                       asm("adwc $0,r9");
-               }
-               mlen += 32;
-               while ((mlen -= 8) >= 0) {
-                       asm("clrl r0");
-                       ADD; ADD;
-                       asm("adwc $0,r9");
-               }
-               mlen += 8;
-               /*
-                * Now eliminate the possibility of carry-out's by
-                * folding back to a 16 bit number (adding high and
-                * low parts together.)  Then mop up trailing words
-                * and maybe an odd byte.
-                */
-               { asm("shal $-16,r9,r0; addw2 r0,r9");
-                 asm("adwc $0,r9; movzwl r9,r9"); }
-               while ((mlen -= 2) >= 0) {
-                       asm("movzwl (r10),r0;addl2 $4,r10;  addl2 r0,r9");
-               }
-               if (mlen == -1) {
-                       sum += *(u_char *)w;
-               }
-               if (len == 0)
-                       break;
-               /*
-                * Locate the next block with some data.
-                * If there is a word split across a boundary we
-                * will wrap to the top with mlen == -1 and
-                * then add it in shifted appropriately.
-                */
-               for (;;) {
-                       if (m == 0) {
-                               printf("cksum: out of data\n");
-                               goto done;
-                       }
-                       if (m->m_len)
-                               break;
-                       m = m->m_next;
-               }
-       }
-done:
-       /*
-        * Add together high and low parts of sum
-        * and carry to get cksum.
-        * Have to be careful to not drop the last
-        * carry here.
-        */
-       { asm("shal $-16,r9,r0; addw2 r0,r9; adwc $0,r9");
-         asm("mcoml r9,r9; movzwl r9,r9"); }
-       return (sum);
-}
-#endif
index f3c9d2e..dab45df 100644 (file)
@@ -1,4 +1,4 @@
-/*     locore.s        1.7     85/05/15        */
+/*     locore.s        1.2     86/01/05        */
 
 #include "../tahoe/mtpr.h"
 #include "../tahoe/trap.h"
 
 #include "../tahoe/mtpr.h"
 #include "../tahoe/trap.h"
@@ -6,17 +6,16 @@
 #include "../tahoe/pte.h"
 #include "../tahoe/cp.h"
 #include "../tahoe/mem.h"
 #include "../tahoe/pte.h"
 #include "../tahoe/cp.h"
 #include "../tahoe/mem.h"
-#include "../tahoe/fp.h"
+#include "../tahoe/SYS.h"
+#include "../tahoemath/fp.h"
 
 
-#include "../h/errno.h"
+#include "errno.h"
+#include "syscall.h"
+#include "cmap.h"
 
        .set    HIGH,0x1f       # mask for total disable
        .set    BERVEC,0x80     # offset into scb of the bus error vector 
        .set    RESTVEC,0x8     # offset into scb of the restart vector 
 
        .set    HIGH,0x1f       # mask for total disable
        .set    BERVEC,0x80     # offset into scb of the bus error vector 
        .set    RESTVEC,0x8     # offset into scb of the restart vector 
-       .set    MAXPHYSMEM,8*1024*1024-1 # max physical memory 
-                                       # while we work on CMD/32M !
-                                       # look at vmsched.c to see why.
-       .set    MEMUNIT,64*1024 # minimum memory increment
 
        .set    NISP,3          # number of interrupt stack pages
        .set    SYSTEM,0xC0000000 # virtual address of system start
 
        .set    NISP,3          # number of interrupt stack pages
        .set    SYSTEM,0xC0000000 # virtual address of system start
        cmpl    _index,_limit; \
        bgeq    _displ
 
        cmpl    _index,_limit; \
        bgeq    _displ
 
-#define        MOVC3(_len,_srcaddr,_dstaddr) \
+#define        MOVC3(_srcaddr,_dstaddr,_len) \
        movl    _srcaddr,r0; \
        movl    _dstaddr,r1; \
        movl    _len,r2; \
        movblk
 
        movl    _srcaddr,r0; \
        movl    _dstaddr,r1; \
        movl    _len,r2; \
        movblk
 
-/* Keep address of psl if coming from user mode */
+/* keep address of psl if coming from user mode */
 #define CHECK_SFE(_delta) \
        bitl    $PSL_CURMOD,_delta(sp); \
        jeql    1f; \
 #define CHECK_SFE(_delta) \
        bitl    $PSL_CURMOD,_delta(sp); \
        jeql    1f; \
  * Takes a core-dump and then halts.
  */ 
        .globl  _rsstk
  * Takes a core-dump and then halts.
  */ 
        .globl  _rsstk
-
-_rsstk:        .space  1024-8
        .globl  pwfl_stk        
        .globl  pwfl_stk        
-pwfl_stk:      .space  4
-dumpflag:      .space  4
+_rsstk:
+       .space  1024-8
+pwfl_stk:
+       .space  4
+dumpflag:
+       .space  4
 
        .globl  _intstack
 _intstack:
        .space  NISP*NBPG
 eintstack:
 
 
        .globl  _intstack
 _intstack:
        .space  NISP*NBPG
 eintstack:
 
+/*
+ * Power failure storage block and
+ * macros for saving and restoring.
+ */
+#define        POWERFAIL(id,longs) \
+       .globl  pwfl_/**/id \
+pwfl_/**/id: .space longs*4
        .data
        .data
-       .globl  pwfl_r0
-pwfl_r0:       .space  14*4            # Enough for r0 - r13
-       .globl  pwfl_sp
-pwfl_sp:       .long   0x12345678      # r14
-       .globl  pwfl_SCBB
-pwfl_SCBB:     .long   0x12345678
-       .globl  pwfl_SBR
-pwfl_SBR:      .long   0x12345678
-       .globl  pwfl_SLR
-pwfl_SLR:      .long   0x12345678
-       .globl  pwfl_P0BR
-pwfl_P0BR:     .long   0x12345678
-       .globl  pwfl_P0LR
-pwfl_P0LR:     .long   0x12345678
-       .globl  pwfl_P1BR
-pwfl_P1BR:     .long   0x12345678
-       .globl  pwfl_P1LR
-pwfl_P1LR:     .long   0x12345678
-       .globl  pwfl_P2BR
-pwfl_P2BR:     .long   0x12345678
-       .globl  pwfl_P2LR
-pwfl_P2LR:     .long   0x12345678
-       .globl  pwfl_IPL
-pwfl_IPL:      .long   0x12345678
-       .globl  pwfl_DCK
-pwfl_DCK:      .long   0x12345678
-       .globl  pwfl_CCK
-pwfl_CCK:      .long   0x12345678
-       .globl  pwfl_PCBB
-pwfl_PCBB:     .long   0x12345678
-       .globl  pwfl_ISP
-pwfl_ISP:      .long   0x12345678
-       .globl  pwfl_KSP
-pwfl_KSP:      .long   0x12345678
-       .globl  pwfl_USP
-pwfl_USP:      .long   0x12345678
-       .globl  pwfl_MME
-pwfl_MME:      .long   0x12345678
-       .globl  pwfl_PSL
-pwfl_PSL:      .long   0x12345678
+       POWERFAIL(r0,   14)             # r0-r13
+       POWERFAIL(sp,   1)              # r14
+       POWERFAIL(SCBB, 1)              # system control block base
+       POWERFAIL(SBR,  1)              # system pte base
+       POWERFAIL(SLR,  1)              # system pte length
+       POWERFAIL(P0BR, 1)              # p0 pte base
+       POWERFAIL(P0LR, 1)              # p0 pte length
+       POWERFAIL(P1BR, 1)              # p1 pte base
+       POWERFAIL(P1LR, 1)              # p1 pte length
+       POWERFAIL(P2BR, 1)              # p2 pte base
+       POWERFAIL(P2LR, 1)              # p2 pte length
+       POWERFAIL(IPL,  1)              # interrupt priority level
+       POWERFAIL(DCK,  1)              # data cache key
+       POWERFAIL(CCK,  1)              # code cache key
+       POWERFAIL(PCBB, 1)              # process control block base
+       POWERFAIL(ISP,  1)              # interrupt stack pointer
+       POWERFAIL(KSP,  1)              # kernel mode stack pointer
+       POWERFAIL(USP,  1)              # user mode stack pointer
+       POWERFAIL(MME,  1)              # memory management enable
+       POWERFAIL(PSL,  1)              # processor status longword
+
+/*
+ * Save current state in power fail storage block.
+ */
+#define        SAVEpwfl() \
+       movpsl  pwfl_PSL        # Keeps all flags, etc. \
+       storer  $0x3fff,pwfl_r0 # Saves r0-r13 \
+       moval   0(sp),pwfl_sp   # Saves sp (=r14) \
+       mfpr    $SBR,pwfl_SBR   # Save all re_loadable registers \
+       mfpr    $SLR,pwfl_SLR \
+       mfpr    $P0BR,pwfl_P0BR \
+       mfpr    $P0LR,pwfl_P0LR \
+       mfpr    $P1BR,pwfl_P1BR \
+       mfpr    $P1LR,pwfl_P1LR \
+       mfpr    $P2BR,pwfl_P2BR \
+       mfpr    $P2LR,pwfl_P2LR \
+       mfpr    $IPL,pwfl_IPL \
+       mfpr    $MME,pwfl_MME \
+       mfpr    $DCK,pwfl_DCK \
+       mfpr    $CCK,pwfl_CCK \
+       mfpr    $PCBB,pwfl_PCBB \
+       mfpr    $ISP,pwfl_ISP \
+       mfpr    $SCBB,pwfl_SCBB \
+       mfpr    $KSP,pwfl_KSP \
+       mfpr    $USP,pwfl_USP
+
+/*
+ * Restore state saved in power fail block and
+ * jmp to location specified after (possibly)
+ * enabling memory management.
+ */
+#define        RESTOREpwfl(loc) \
+       loadr   $0x3fff,pwfl_r0 # Restore r0-r13 \
+       movl    pwfl_sp,sp      # Restore sp (=r14) \
+       mtpr    pwfl_SCBB,$SCBB \
+       mtpr    pwfl_SBR,$SBR   # Restore all re_loadable registers \
+       mtpr    pwfl_SLR,$SLR \
+       mtpr    pwfl_P0BR,$P0BR \
+       mtpr    pwfl_P0LR,$P0LR \
+       mtpr    pwfl_P1BR,$P1BR \
+       mtpr    pwfl_P1LR,$P1LR \
+       mtpr    pwfl_P2BR,$P2BR \
+       mtpr    pwfl_P2LR,$P2LR \
+       mtpr    pwfl_IPL,$IPL \
+       mtpr    pwfl_DCK,$DCK \
+       mtpr    pwfl_CCK,$CCK \
+       mtpr    pwfl_PCBB,$PCBB \
+       mtpr    pwfl_ISP,$ISP \
+       mtpr    pwfl_KSP,$KSP \
+       mtpr    pwfl_USP,$USP \
+\
+       bicpsw  $0xff           # Restore PSW. \
+       bispsw  pwfl_PSL+2      # Set original bits back (just in case..) \
+# now go to mapped mode \
+# Have to change PC to system addresses \
+       mtpr    $1,$PACC        # Thoroughly clean up caches. \
+       mtpr    $1,$PADC \
+       mtpr    $1,$TBIA \
+       mtpr    pwfl_MME,$MME   # Restore MME. Last thing to be done. \
+       jmp     loc
 
 /*
  * Do a dump.
 
 /*
  * Do a dump.
@@ -120,42 +168,13 @@ pwfl_PSL: .long   0x12345678
        .text
        .globl  _Xdoadump
        .globl  _doadump
        .text
        .globl  _Xdoadump
        .globl  _doadump
-_Xdoadump:                     # CP brings Tahoe here on power recovery
-       loadr   $0x3fff,pwfl_r0 # Restore r0 - r13
-       movl    pwfl_sp,sp      # Restore sp ( = r14 )
-       mtpr    pwfl_SCBB,$SCBB
-       mtpr    pwfl_SBR,$SBR   # Restore all re_loadable registers
-       mtpr    pwfl_SLR,$SLR
-       mtpr    pwfl_P0BR,$P0BR
-       mtpr    pwfl_P0LR,$P0LR
-       mtpr    pwfl_P1BR,$P1BR
-       mtpr    pwfl_P1LR,$P1LR
-       mtpr    pwfl_P2BR,$P2BR
-       mtpr    pwfl_P2LR,$P2LR
-       mtpr    pwfl_IPL,$IPL
-       mtpr    pwfl_DCK,$DCK
-       mtpr    pwfl_CCK,$CCK
-       mtpr    pwfl_PCBB,$PCBB
-       mtpr    pwfl_ISP,$ISP
-       mtpr    pwfl_KSP,$KSP
-       mtpr    pwfl_USP,$USP
-
-       bicpsw  $0xff           # Restore PSW.
-       bispsw  pwfl_PSL+2      # Set original bits back (just in case..)
-/* now go to mapped mode */
-/* Have to change PC to system addresses */
-       mtpr    $1,$PACC        # Thoroughly clean up caches.
-       mtpr    $1,$PADC
-       mtpr    $1,$TBIA
-       mtpr    pwfl_MME,$MME   # Restore MME. Last thing to be done.
-       jmp     *$0f
+_Xdoadump:                                     # CP comes here after power fail
+       RESTOREpwfl(*0f)                        # restore state
 _doadump:
        .word 0
 _doadump:
        .word 0
-#define        _rsstkmap       _Sysmap+12                      
-                       # Tahoe storage, scb, rsstk, interrupt stack
-0:
-       mtpr    $HIGH,$IPL
-       andl2   $0!PG_PROT,_rsstkmap
+0:     mtpr    $HIGH,$IPL
+#define        _rsstkmap _Sysmap+12    # powerfail storage, scb, rsstk, int stack
+       andl2   $~PG_PROT,_rsstkmap
        orl2    $PG_KW,_rsstkmap                # Make dump stack r/w
        tstl    dumpflag                        # dump only once!
        bneq    1f
        orl2    $PG_KW,_rsstkmap                # Make dump stack r/w
        tstl    dumpflag                        # dump only once!
        bneq    1f
@@ -170,109 +189,131 @@ _doadump:
  * Interrupt vector routines
  */ 
        .globl  _waittime
  * Interrupt vector routines
  */ 
        .globl  _waittime
-
 #define        SCBVEC(name) \
        .align 2; \
        .globl _X/**/name; \
 _X/**/name
 #define        SCBVEC(name) \
        .align 2; \
        .globl _X/**/name; \
 _X/**/name
-#define        PANIC(msg)      clrl _waittime; pushab 1f; \
-                       callf $8,_panic; 1: .asciz msg
-#define        PRINTF(n,msg)   pushab 1f; callf $(n+2)*4,_printf; MSG(msg)
-#define        MSG(msg)        .data; 1: .asciz msg; .text
-
-                       # these registers are not restored by the C-compiler.
-#define        PUSHR           pushl r0; pushl r1;
-#define        POPR            movl (sp)+, r1; movl (sp)+, r0;
-                       # mask for error code on stack.
-
-#define SAVE_FPSTAT(_delta)    bitl    $PSL_DBL,_delta(sp); \
-                               beql    1f; \
-                               pushl   $1; \
-                               pushd; \
-                               jmp     2f; \
-                       1:      pushl   $0; \
-                               pushl   $0; \
-                               stf     -(sp); \
-                       2:      tstl    _u+PCB_SAVACC; \
-                               bneq    3f; \
-                               moval   0(sp),_u+PCB_SAVACC; \
-                               orl2    $2,8(sp);\
-                       3:      pushl   $0;
-
-#define REST_FPSTAT            tstl    (sp)+; \
-                               bitl    $2,8(sp);\
-                               beql    1f;\
-                               movl    $0,_u+PCB_SAVACC; \
-                       1:      bitl    $1,8(sp); \
-                               beql    2f; \
-                               ldd     (sp); \
-                               jmp     3f; \
-                       2:      ldf     (sp); \
-                       3:      moval   12(sp),sp;
-
-#define REST_ACC               tstl    _u+PCB_SAVACC; \
-                               beql    2f; \
-                               movl    _u+PCB_SAVACC,r1; \
-                               andl3   $(EXPMASK|SIGNBIT),(r1),-(sp); \
-                               cmpl    $0x80000000,(sp)+; \
-                               bneq    3f; \
-                               clrl    (r1); \
-                       3:      bitl    $1,8(r1); \
-                               beql    1f; \
-                               ldd     (r1); \
-                               jmp     2f; \
-                       1:      ldf     (r1); \
-                       2:      ;
-
-#define PUSHBPAR       pushab  6*4(sp) /* Push address of buserr paramters */
-#define BPAR1          28              /* Offset to first hardware parameter */
+#define        PANIC(msg) \
+       clrl _waittime; pushab 1f; callf $8,_panic; 1: .asciz msg
+#define        PRINTF(n,msg) \
+       pushab 1f; callf $(n+2)*4,_printf; MSG(msg)
+#define        MSG(msg) .data; 1: .asciz msg; .text
+/*
+ * r0-r2 are saved across all faults and interrupts.
+ * Routines below and those hidden in ubglue.s (device
+ * interrupts) invoke the PUSHR/POPR macros to execute
+ * this.  Also, certain stack frame offset calculations
+ * (such as in hardclock) understand this, using the
+ * REGSPC definition (and FPSPC defined below).
+ * Finally, many routines, including those expanded
+ * inline depend on this!  Should probably save all
+ * live C compiler temp registers to eliminate potentially
+ * grievous problems caused by incorrect register save masks.
+ */
+#define        REGSPC  (3*4)
+#define        PUSHR   pushl r0; pushl r1; pushl r2;
+#define        POPR    movl (sp)+,r2; movl (sp)+,r1; movl (sp)+,r0;
+
+/*
+ * Floating point state is saved across faults and
+ * interrupts.  The state occupies 4 longwords on
+ * the stack:
+ *     precision indicator (single = 0/double = 1)
+ *     double representation of accumulator
+ *     save accumulator status flag (pcb_savacc)
+ */
+#define        FPSPC   (4*4)
+
+#define SAVE_FPSTAT(_delta) \
+       bitl    $PSL_DBL,_delta(sp); \
+       beql    1f; \
+       pushl   $1; \
+       pushd; \
+       jmp     2f; \
+1:     pushl   $0; \
+       pushl   $0; \
+       stf     -(sp); \
+2:     tstl    _u+PCB_SAVACC; \
+       bneq    3f; \
+       moval   0(sp),_u+PCB_SAVACC; \
+       orl2    $2,8(sp);\
+3:     pushl   $0;
+
+#define REST_FPSTAT \
+       tstl    (sp)+; \
+       bitl    $2,8(sp);\
+       beql    1f;\
+       movl    $0,_u+PCB_SAVACC; \
+1:     bitl    $1,8(sp); \
+       beql    2f; \
+       ldd     (sp); \
+       jmp     3f; \
+2:     ldf     (sp); \
+3:     moval   12(sp),sp;
+
+#define REST_ACC \
+       tstl    _u+PCB_SAVACC; \
+       beql    2f; \
+       movl    _u+PCB_SAVACC,r1; \
+       andl3   $(EXPMASK|SIGNBIT),(r1),-(sp); \
+       cmpl    $0x80000000,(sp)+; \
+       bneq    3f; \
+       clrl    (r1); \
+3:     bitl    $1,8(r1); \
+       beql    1f; \
+       ldd     (r1); \
+       jmp     2f; \
+1:     ldf     (r1); \
+2:     ;
+
+       .data
+nofault: .space        4                       # bus error non-local goto label
 
 
+       .text
 SCBVEC(buserr):
        CHECK_SFE(12)
 SCBVEC(buserr):
        CHECK_SFE(12)
-       SAVE_FPSTAT(12);
-       PUSHR
-       andl3   BPAR1(sp),$ERRCD,r0
-       jeql    go_on
-       cmpl    r0,$APE
+       SAVE_FPSTAT(12)
+       pushl   r0                      # must save
+       andl3   24(sp),$ERRCD,r0        # grab pushed MER value
+       cmpl    r0,$APE                 # address parity error?
        jneq    1f
        jneq    1f
-       halt            # Address parity error !!!
-1:     cmpl    r0,$VBE
-       jneq    go_on
-       halt            # Versabus error !!!
-go_on:
-       PUSHBPAR        # Pointer to parameters
+       halt    
+1:     cmpl    r0,$VBE                 # versabus error?
+       jneq    2f
+       halt
+2:
+       movl    (sp)+,r0                # restore r0 and...
+       bitl    $PSL_CURMOD,4*4+3*4(sp) # check if happened in user mode?
+       jeql    3f                      # yes, then shift stack up for trap...
+       movl    12(sp),16(sp)           # sorry, no space for which-buss...
+       movl    8(sp),12(sp)
+       movl    4(sp),8(sp)
+       movl    0(sp),4(sp)
+       movl    $T_BUSERR,0(sp)         # push trap type code and...
+       jbr     alltraps                # ...merge with all other traps
+3:                                     # kernel mode, check to see if...
+       tstl    nofault                 # ...doing peek/poke?
+       jeql    4f                      # nofault set? if so, jump to it...
+       movl    nofault,4*4+2*4(sp)     # ...setup for non-local goto
+       clrl    nofault
+       jbr     5f
+4:
+       PUSHR
+       pushab  7*4(sp)                 # address of bus error parameters
        callf   $8,_buserror
        POPR
        callf   $8,_buserror
        POPR
-       REST_FPSTAT;
-       movab   8(sp),sp        # Remove hardware parameters
+5:
+       REST_FPSTAT
+       movab   8(sp),sp                # remove bus error parameters
        rei
 
        rei
 
-SCBVEC(powfail):               # We should be on interrupt stack now.
-       movpsl  pwfl_PSL        # Keeps all flags, etc.
-       storer  $0x3fff,pwfl_r0 # Saves r0 - r13
-       moval   0(sp),pwfl_sp   # Saves sp ( = r14 )
-       mfpr    $SBR,pwfl_SBR   # Save all re_loadable registers
-       mfpr    $SLR,pwfl_SLR
-       mfpr    $P0BR,pwfl_P0BR
-       mfpr    $P0LR,pwfl_P0LR
-       mfpr    $P1BR,pwfl_P1BR
-       mfpr    $P1LR,pwfl_P1LR
-       mfpr    $P2BR,pwfl_P2BR
-       mfpr    $P2LR,pwfl_P2LR
-       mfpr    $IPL,pwfl_IPL
-       mfpr    $MME,pwfl_MME  
-       mfpr    $DCK,pwfl_DCK
-       mfpr    $CCK,pwfl_CCK
-       mfpr    $PCBB,pwfl_PCBB
-       mfpr    $ISP,pwfl_ISP
-       mfpr    $SCBB,pwfl_SCBB
-       mfpr    $KSP,pwfl_KSP
-       mfpr    $USP,pwfl_USP
+SCBVEC(powfail):                       # We should be on interrupt stack now.
+       SAVEpwfl()                      # save machine state
        moval   _Xdoadump-SYSTEM,_scb+RESTVEC
        halt
 
 SCBVEC(stray):
        moval   _Xdoadump-SYSTEM,_scb+RESTVEC
        halt
 
 SCBVEC(stray):
-       PUSHR; PRINTF(0, "******* Undefined interrupt *******\n"); POPR;
+       PUSHR; PRINTF(0, "stray interrupt\n"); POPR;
        rei
 
 #include "../net/netisr.h"
        rei
 
 #include "../net/netisr.h"
@@ -281,21 +322,20 @@ SCBVEC(netintr):
        CHECK_SFE(4)
        SAVE_FPSTAT(4)
        PUSHR
        CHECK_SFE(4)
        SAVE_FPSTAT(4)
        PUSHR
-
        bbc     $NETISR_RAW,_netisr,1f
        bbc     $NETISR_RAW,_netisr,1f
-       andl2   $(0!(1<<NETISR_RAW)),_netisr    
+       andl2   $~(1<<NETISR_RAW),_netisr       
        callf   $4,_rawintr     
 1:
 #ifdef INET
 #include "../netinet/in_systm.h"
        bbc     $NETISR_IP,_netisr,1f   
        callf   $4,_rawintr     
 1:
 #ifdef INET
 #include "../netinet/in_systm.h"
        bbc     $NETISR_IP,_netisr,1f   
-       andl2   $(0!(1<<NETISR_IP)),_netisr
+       andl2   $~(1<<NETISR_IP),_netisr
        callf   $4,_ipintr      
 1:
 #endif
 #ifdef NS
        bbc     $NETISR_NS,_netisr,1f   
        callf   $4,_ipintr      
 1:
 #endif
 #ifdef NS
        bbc     $NETISR_NS,_netisr,1f   
-       andl2   $(0!(1<<NETISR_NS)),_netisr
+       andl2   $~(1<<NETISR_NS),_netisr
        callf   $4,_nsintr      
 1:
 #endif
        callf   $4,_nsintr      
 1:
 #endif
@@ -319,9 +359,7 @@ SCBVEC(soft3):
 SCBVEC(soft2):
 SCBVEC(soft1):
 #endif
 SCBVEC(soft2):
 SCBVEC(soft1):
 #endif
-       PUSHR
-       PRINTF(0, "******* Undefined software interrupt *******\n")
-       POPR;
+       PUSHR; PRINTF(0, "stray software interrupt\n"); POPR;
        rei
 
 #ifdef SIMIO
        rei
 
 #ifdef SIMIO
@@ -329,51 +367,55 @@ SCBVEC(soft2):
 #endif
 SCBVEC(cnrint):
        CHECK_SFE(4)
 #endif
 SCBVEC(cnrint):
        CHECK_SFE(4)
-       SAVE_FPSTAT(4);PUSHR; 
-       pushl $CPCONS; callf $8,_cnrint; POPR; incl _cnt+V_INTR;
-       REST_FPSTAT; rei
+       SAVE_FPSTAT(4); PUSHR; 
+       pushl $CPCONS; callf $8,_cnrint; incl _cnt+V_INTR
+       POPR; REST_FPSTAT;
+       rei
 #ifdef SIMIO
 SCBVEC(soft3):
 #endif
 SCBVEC(cnxint):
        CHECK_SFE(4)
 #ifdef SIMIO
 SCBVEC(soft3):
 #endif
 SCBVEC(cnxint):
        CHECK_SFE(4)
-       SAVE_FPSTAT(4);PUSHR; 
-       pushl $CPCONS; callf $8,_cnxint; POPR; REST_FPSTAT;
-       incl _cnt+V_INTR; rei
+       SAVE_FPSTAT(4); PUSHR; 
+       pushl $CPCONS; callf $8,_cnxint; incl _cnt+V_INTR
+       POPR; REST_FPSTAT;
+       rei
 SCBVEC(rmtrint):
        CHECK_SFE(4)
        SAVE_FPSTAT(4); PUSHR; 
 SCBVEC(rmtrint):
        CHECK_SFE(4)
        SAVE_FPSTAT(4); PUSHR; 
-       pushl $CPREMOT; callf $8,_cnrint; POPR; REST_FPSTAT;
-       incl _cnt+V_INTR; rei
+       pushl $CPREMOT; callf $8,_cnrint; incl _cnt+V_INTR
+       POPR; REST_FPSTAT;
+       rei
 SCBVEC(rmtxint):
        CHECK_SFE(4)
        SAVE_FPSTAT(4); PUSHR; 
 SCBVEC(rmtxint):
        CHECK_SFE(4)
        SAVE_FPSTAT(4); PUSHR; 
-       pushl $CPREMOT; callf $8,_cnxint; POPR; REST_FPSTAT;
-       incl _cnt+V_INTR; rei
+       pushl $CPREMOT; callf $8,_cnxint; incl _cnt+V_INTR
+       POPR; REST_FPSTAT;
+       rei
 #ifdef SIMIO
 SCBVEC(soft9):
 #endif
 
 #ifdef SIMIO
 SCBVEC(soft9):
 #endif
 
-#define PUSHPCPSL      pushl 5*4+2*4(sp); pushl 5*4+2*4(sp);
+#define PUSHPCPSL      pushl 4+FPSPC+REGSPC(sp); pushl 4+FPSPC+REGSPC(sp);
 
 SCBVEC(hardclock):
 
 SCBVEC(hardclock):
+       tstl    _clk_enable
+       bneq    1f
+       rei
+1:
        CHECK_SFE(4)
        CHECK_SFE(4)
-       SAVE_FPSTAT(4)
-       PUSHR
-       PUSHPCPSL                               # push pc and psl
-       callf $12,_hardclock                    # hardclock(pc,psl)
-       POPR;
-       REST_FPSTAT
+       SAVE_FPSTAT(4); PUSHR
+       PUSHPCPSL                       # push pc and psl
+       callf   $12,_hardclock          # hardclock(pc,psl)
        incl    _cnt+V_INTR             ## temp so not to break vmstat -= HZ
        incl    _cnt+V_INTR             ## temp so not to break vmstat -= HZ
+       POPR; REST_FPSTAT
        rei
 SCBVEC(softclock):
        CHECK_SFE(4)
        rei
 SCBVEC(softclock):
        CHECK_SFE(4)
-       SAVE_FPSTAT(4)
-       PUSHR
+       SAVE_FPSTAT(4); PUSHR;
        PUSHPCPSL                               # push pc and psl
        PUSHPCPSL                               # push pc and psl
-       callf $12,_softclock                    # softclock(pc,psl)
-       POPR; 
-       REST_FPSTAT
+       callf   $12,_softclock                  # softclock(pc,psl)
+       POPR; REST_FPSTAT
        rei
 
 /*
        rei
 
 /*
@@ -385,15 +427,13 @@ SCBVEC(softclock):
  * Ast delivery (profiling and/or reschedule)
  */
 /*
  * Ast delivery (profiling and/or reschedule)
  */
 /*
- * When we want to reschedule we will force a memory fault by setting the m.s.b
- *  of P0LR. Then , on memory fault if m.s.b of P0LR is on we will clear it and
- *  TRAP(astflt).
- *
+ * When we want to reschedule we will force a
+ * memory fault by setting the ASTBIT of P0LR.
+ * Then, on memory fault if the ASTBIT of the
+ * p0lr is set we will clear it and TRAP(astflt).
  */
  */
-                                       # if this bit is on it is an ast.
-#define        ASTBIT  0x00100000      
-#define                P0MASK  0xc0000000
+#define ASTBIT 0x00100000      
+#define        P0MASK  0xc0000000
 
 SCBVEC(kspnotval):
        CHECK_SFE(4)
 
 SCBVEC(kspnotval):
        CHECK_SFE(4)
@@ -445,8 +485,7 @@ segflt:
        SAVE_FPSTAT(8)
        TRAP(SEGFLT)
 
        SAVE_FPSTAT(8)
        TRAP(SEGFLT)
 
-SCBVEC(fpm):                   # Floating Point eMulation
-       .globl  _fpemulate
+SCBVEC(fpm):                   # Floating Point Emulation
        CHECK_SFE(16)
        SAVE_FPSTAT(16)
        callf   $4,_fpemulate
        CHECK_SFE(16)
        SAVE_FPSTAT(16)
        callf   $4,_fpemulate
@@ -478,9 +517,10 @@ tableflt:
 
 alltraps:
        mfpr    $USP,-(sp); 
 
 alltraps:
        mfpr    $USP,-(sp); 
-       callf $4,_trap; mtpr (sp)+,$USP
+       callf   $4,_trap;
+       mtpr    (sp)+,$USP
        incl    _cnt+V_TRAP
        incl    _cnt+V_TRAP
-       REST_STACK                      # pop type, code, an fp stuff
+       REST_STACK                      # pop type, code, and fp stuff
        mtpr    $HIGH,$IPL              ## dont go to a higher IPL (GROT)
        rei
 
        mtpr    $HIGH,$IPL              ## dont go to a higher IPL (GROT)
        rei
 
@@ -488,9 +528,11 @@ SCBVEC(syscall):
        CHECK_SFE(8)
        SAVE_FPSTAT(8)
        pushl   $T_SYSCALL
        CHECK_SFE(8)
        SAVE_FPSTAT(8)
        pushl   $T_SYSCALL
-       mfpr    $USP,-(sp); callf $4,_syscall; mtpr (sp)+,$USP
+       mfpr    $USP,-(sp);
+       callf   $4,_syscall;
+       mtpr    (sp)+,$USP
        incl    _cnt+V_SYSCALL
        incl    _cnt+V_SYSCALL
-       REST_STACK                      # pop type, code, an fp stuff
+       REST_STACK                      # pop type, code, and fp stuff
        mtpr    $HIGH,$IPL              ## dont go to a higher IPL (GROT)
        rei
 
        mtpr    $HIGH,$IPL              ## dont go to a higher IPL (GROT)
        rei
 
@@ -523,7 +565,8 @@ _/**/mname: .globl  _/**/mname;             \
        SYSMAP(VD1map   ,vd1utl         ,(MAXBPTE+1)    )
        SYSMAP(VD2map   ,vd2utl         ,(MAXBPTE+1)    )
        SYSMAP(VD3map   ,vd3utl         ,(MAXBPTE+1)    )
        SYSMAP(VD1map   ,vd1utl         ,(MAXBPTE+1)    )
        SYSMAP(VD2map   ,vd2utl         ,(MAXBPTE+1)    )
        SYSMAP(VD3map   ,vd3utl         ,(MAXBPTE+1)    )
-       SYSMAP(CYmap    ,cyutl          ,(TBUFSIZ+1)    )
+       SYSMAP(CY0map   ,cy0utl         ,(TBUFSIZ+1)    )
+       SYSMAP(CY1map   ,cy1utl         ,(TBUFSIZ+1)    )
        SYSMAP(CMAP1    ,CADDR1         ,1              )
        SYSMAP(CMAP2    ,CADDR2         ,1              )
        SYSMAP(mmap     ,vmmap          ,1              )
        SYSMAP(CMAP1    ,CADDR1         ,1              )
        SYSMAP(CMAP2    ,CADDR2         ,1              )
        SYSMAP(mmap     ,vmmap          ,1              )
@@ -540,148 +583,111 @@ eSysmap:
  * Initialization
  *
  * IPL 0x1f; MME 0; scbb, pcbb, sbr, slr, isp, ksp not set
  * Initialization
  *
  * IPL 0x1f; MME 0; scbb, pcbb, sbr, slr, isp, ksp not set
- *
  */
  */
-
        .align  2
        .globl  start
 start:
        .word   0
        .align  2
        .globl  start
 start:
        .word   0
-
 /* set system control block base and system page table params */
 /* set system control block base and system page table params */
-
        mtpr    $_scb-SYSTEM,$SCBB
        mtpr    $_Sysmap-SYSTEM,$SBR
        mtpr    $_Syssize,$SLR
        mtpr    $_scb-SYSTEM,$SCBB
        mtpr    $_Sysmap-SYSTEM,$SBR
        mtpr    $_Syssize,$SLR
-
 /* double map the kernel into the virtual user addresses of phys mem */
 /* double map the kernel into the virtual user addresses of phys mem */
-/* (to be on the safe side.This is supposed to run in system sace. )  */
        mtpr    $_Sysmap,$P0BR
        mtpr    $_Syssize,$P0LR
        mtpr    $_Sysmap,$P0BR
        mtpr    $_Syssize,$P0LR
-
-       mtpr    $_Sysmap,$P1BR          # Against Murphy
+       mtpr    $_Sysmap,$P1BR                  # against Murphy
        mtpr    $_Syssize,$P1LR
        mtpr    $_Syssize,$P1LR
-
 /* set ISP */
 /* set ISP */
-       movl    $_intstack-SYSTEM+NISP*NBPG,sp  # Still physical !
+       movl    $_intstack-SYSTEM+NISP*NBPG,sp  # still physical
        mtpr    $_intstack+NISP*NBPG,$ISP
        mtpr    $_intstack+NISP*NBPG,$ISP
-
 /* count up memory */
 /* count up memory */
-
        clrl    r7
 1:     pushl   $1; pushl r7; callf $12,_badaddr; tstl r0; bneq 9f
        clrl    r7
 1:     pushl   $1; pushl r7; callf $12,_badaddr; tstl r0; bneq 9f
-       addl2   $MEMUNIT,r7
-       cmpl    r7,$MAXPHYSMEM
-       bleq    1b
+       ACBL($MAXMEM*1024-1,$64*1024,r7,1b)
 9:
 /* clear memory from kernel bss and pages for proc 0 u. and page table */
        movab   _edata,r6
        movab   _end,r5
 9:
 /* clear memory from kernel bss and pages for proc 0 u. and page table */
        movab   _edata,r6
        movab   _end,r5
-       andl2   $0!SYSTEM,r6
-       andl2   $0!SYSTEM,r5
+       andl2   $~SYSTEM,r6
+       andl2   $~SYSTEM,r5
        addl2   $(UPAGES*NBPG)+NBPG+NBPG,r5
        addl2   $(UPAGES*NBPG)+NBPG+NBPG,r5
-1:     clrl    (r6); ACBL( r5,$4,r6,1b)
-
-/* trap() and syscall() save r0-r13 in the entry mask (per ../h/reg.h) */
-/* For floating point emulation, we do same for 'fpemulate' */
+1:     clrl    (r6); ACBL(r5,$4,r6,1b)
+/* trap(), syscall(), and fpemulate() save r0-r12 in the entry mask */
        orw2    $0x01fff,_trap
        orw2    $0x01fff,_syscall
        orw2    $0x01fff,_fpemulate
        orw2    $0x01fff,_trap
        orw2    $0x01fff,_syscall
        orw2    $0x01fff,_fpemulate
-
+       orw2    $0x01ffc,_panic                 # for debugging (no r0|r1)
 /* initialize system page table: scb and int stack writeable */
        clrl    r2
        movab   eintstack,r1 
 /* initialize system page table: scb and int stack writeable */
        clrl    r2
        movab   eintstack,r1 
-       andl2   $0!SYSTEM,r1
-       shrl    $PGSHIFT,r1,r1          # r1-page number of eintstack.
-
-/* Start by making the processor storage read/only */
-
+       andl2   $~SYSTEM,r1
+       shrl    $PGSHIFT,r1,r1                  # r1-page number of eintstack
+/* make processor storage read/only */
        orl3    $PG_V|PG_KR,r2,_Sysmap[r2]; incl r2;
        orl3    $PG_V|PG_KR,r2,_Sysmap[r2]; incl r2;
        orl3    $PG_V|PG_KR,r2,_Sysmap[r2]; incl r2;
        orl3    $PG_V|PG_KR,r2,_Sysmap[r2]; incl r2;
-
-/* Other parts of the system are read/write for kernel */
-
-1:     orl3    $PG_V|PG_KW,r2,_Sysmap[r2]; # data:kernel write + phys=virtual
+/* other parts of the system are read/write for kernel */
+1:     orl3    $PG_V|PG_KW,r2,_Sysmap[r2];     # data:kernel write+phys=virtual
        aoblss r1,r2,1b
        aoblss r1,r2,1b
-
 /* make rsstk read-only as red zone for interrupt stack */
 /* make rsstk read-only as red zone for interrupt stack */
-       andl2   $0!PG_PROT,_rsstkmap
-       orl2    $PG_V|PG_KR,_rsstkmap           # Make dump stack r/w
-
+       andl2   $~PG_PROT,_rsstkmap
+       orl2    $PG_V|PG_KR,_rsstkmap
 /* make kernel text space read-only */
 /* make kernel text space read-only */
-/*
- * HAVE TO CHECK ALL THE MAGIC CONSTANTS USED HERE : $xxxxxx */
-
        movab   _etext+NBPG-1,r1
        movab   _etext+NBPG-1,r1
-       andl2   $0!SYSTEM,r1
+       andl2   $~SYSTEM,r1
        shrl    $PGSHIFT,r1,r1
 1:     orl3    $PG_V|PG_KR,r2,_Sysmap[r2]
        aoblss r1,r2,1b
        shrl    $PGSHIFT,r1,r1
 1:     orl3    $PG_V|PG_KR,r2,_Sysmap[r2]
        aoblss r1,r2,1b
-
 /* make kernel data, bss, read-write */
        movab   _end+NBPG-1,r1
 /* make kernel data, bss, read-write */
        movab   _end+NBPG-1,r1
-       andl2   $0!SYSTEM,r1
+       andl2   $~SYSTEM,r1
        shrl    $PGSHIFT,r1,r1
 1:     orl3    $PG_V|PG_KW,r2,_Sysmap[r2]
        aoblss r1,r2,1b
        shrl    $PGSHIFT,r1,r1
 1:     orl3    $PG_V|PG_KW,r2,_Sysmap[r2]
        aoblss r1,r2,1b
-
-/* now go to mapped mode */
-/* Have to change both PC and SP to system addresses */
+/* go to mapped mode, have to change both pc and sp to system addresses */
        mtpr    $1,$TBIA
        mtpr    $1,$TBIA
-       mtpr    $1,$PADC        /* needed by HW parity & ECC logic */
-       mtpr    $1,$PACC        /* just in case */
+       mtpr    $1,$PADC                        # needed by HW parity&ECC logic
+       mtpr    $1,$PACC                        # just in case
        mtpr    $1,$MME
        movab   SYSTEM(sp),sp
        mtpr    $1,$MME
        movab   SYSTEM(sp),sp
-       .globl  go_virt
-go_virt:       
        jmp     *$0f
 0:
        jmp     *$0f
 0:
-
 /* disable any interrupts */
        movl    $0,_intenable
 /* init mem sizes */
        shrl    $PGSHIFT,r7,_maxmem
        movl    _maxmem,_physmem
        movl    _maxmem,_freemem
 /* disable any interrupts */
        movl    $0,_intenable
 /* init mem sizes */
        shrl    $PGSHIFT,r7,_maxmem
        movl    _maxmem,_physmem
        movl    _maxmem,_freemem
-
-/* setup context for proc[0] == Scheduler */
+/* setup context for proc[0] == scheduler */
        movab   _end-SYSTEM+NBPG-1,r6
        movab   _end-SYSTEM+NBPG-1,r6
-       andl2   $0!(NBPG-1),r6          # make page boundary
-
+       andl2   $~(NBPG-1),r6                   # make page boundary
 /* setup page table for proc[0] */
        shrl    $PGSHIFT,r6,r3                  # r3 = btoc(r6)
        orl3    $PG_V|PG_KW,r3,_Usrptmap        # init first upt entry
        incl    r3                              # r3 - next page
        movab   _usrpt,r0                       # r0 - first user page
        mtpr    r0,$TBIS
 /* setup page table for proc[0] */
        shrl    $PGSHIFT,r6,r3                  # r3 = btoc(r6)
        orl3    $PG_V|PG_KW,r3,_Usrptmap        # init first upt entry
        incl    r3                              # r3 - next page
        movab   _usrpt,r0                       # r0 - first user page
        mtpr    r0,$TBIS
-
 /* init p0br, p0lr */
 /* init p0br, p0lr */
-       mtpr    r0,$P0BR        # No P0 for proc[0]
+       mtpr    r0,$P0BR                        # no p0 for proc[0]
        mtpr    $0,$P0LR
        mtpr    $0,$P0LR
-
-       mtpr    r0,$P1BR        # No P1 either
+       mtpr    r0,$P1BR                        # no p1 either
        mtpr    $0,$P1LR
        mtpr    $0,$P1LR
-
-
 /* init p2br, p2lr */
        movab   NBPG(r0),r0
        movl    $PPAGES-UPAGES,r1
        mtpr    r1,$P2LR
        moval   -4*PPAGES(r0),r2
        mtpr    r2,$P2BR
 /* init p2br, p2lr */
        movab   NBPG(r0),r0
        movl    $PPAGES-UPAGES,r1
        mtpr    r1,$P2LR
        moval   -4*PPAGES(r0),r2
        mtpr    r2,$P2BR
-
 /* setup mapping for UPAGES of _u */
 /* setup mapping for UPAGES of _u */
-       clrl    r2
+       clrl    r2
        movl    $SYSTEM,r1
        addl2   $UPAGES,r3
        jbr 2f
 1:     decl    r3
        movl    $SYSTEM,r1
        addl2   $UPAGES,r3
        jbr 2f
 1:     decl    r3
-       moval   -NBPG(r1),r1;   # r1 = virtual add of next (downward) _u page
+       moval   -NBPG(r1),r1    # r1 = virtual add of next (downward) _u page
        subl2   $4,r0           # r0 = pte address
        orl3    $PG_V|PG_URKW,r3,(r0)
        mtpr    r1,$TBIS
 2:     aobleq  $UPAGES,r2,1b
        subl2   $4,r0           # r0 = pte address
        orl3    $PG_V|PG_URKW,r3,(r0)
        mtpr    r1,$TBIS
 2:     aobleq  $UPAGES,r2,1b
-
 /* initialize (slightly) the pcb */
        movab   UPAGES*NBPG(r1),PCB_KSP(r1)     # KSP starts at end of _u
        movl    r1,PCB_USP(r1)                  # USP starts just below _u
 /* initialize (slightly) the pcb */
        movab   UPAGES*NBPG(r1),PCB_KSP(r1)     # KSP starts at end of _u
        movl    r1,PCB_USP(r1)                  # USP starts just below _u
@@ -695,79 +701,70 @@ go_virt:
        movl    r11,PCB_R11(r1)                 # r11 obtained from CP on boot
        movab   1f,PCB_PC(r1)                   # initial pc
        clrl    PCB_PSL(r1)                     # kernel mode, ipl=0
        movl    r11,PCB_R11(r1)                 # r11 obtained from CP on boot
        movab   1f,PCB_PC(r1)                   # initial pc
        clrl    PCB_PSL(r1)                     # kernel mode, ipl=0
-       movw    $0xff,PCB_CKEY(r1)      # give him a code key
-       movw    $0xff,PCB_DKEY(r1)      # give him a data key
        shll    $PGSHIFT,r3,r3
        shll    $PGSHIFT,r3,r3
-       mtpr    r3,$PCBB                        # first pcbb (physical ! )
-
-/* Go to a 'normal' process mode (kernel) */
-
+       mtpr    r3,$PCBB                        # first pcbb (physical)
+/* go to kernel mode */
        ldpctx
        ldpctx
-       rei             # Actually 'returns' to the next instruction:
-
+       rei                                     # Actually next instruction:
 /* put signal trampoline code in u. area */
 /* put signal trampoline code in u. area */
-1:     movab   _u,r0
-       movl    sigcode+0,PCB_SIGC+0(r0)
-       movl    sigcode+4,PCB_SIGC+4(r0)
-       movl    sigcode+8,PCB_SIGC+8(r0)
-       movl    sigcode+12,PCB_SIGC+12(r0)
-
+1:     movab   sigcode,r0
+       movab   _u+PCB_SIGC,r1
+       movl    $19,r2
+       movblk
 /* save reboot flags in global _boothowto */
        movl    r11,_boothowto
 /* save reboot flags in global _boothowto */
        movl    r11,_boothowto
-
 /* calculate firstaddr, and call main() */
        movab   _end-SYSTEM+NBPG-1,r0
        shrl    $PGSHIFT,r0,-(sp)
 /* calculate firstaddr, and call main() */
        movab   _end-SYSTEM+NBPG-1,r0
        shrl    $PGSHIFT,r0,-(sp)
-       addl2   $UPAGES+1,(sp)          # First physical unused page number
+       addl2   $UPAGES+1,(sp)                  # first physical unused page
        callf   $8,_main
        callf   $8,_main
-
 /* proc[1] == /etc/init now running here in kernel mode; run icode */
 /* proc[1] == /etc/init now running here in kernel mode; run icode */
-       pushl   $PSL_CURMOD             # User mode PSL
-       pushl $0                        # PC = 0 (virtual now)
+       pushl   $PSL_CURMOD                     # User mode PSL
+       pushl $0                                # PC = 0 (virtual now)
        rei
 
        rei
 
-/* signal trampoline code: it is known that this code takes up to 16    */
-/* bytes in pcb.h and in the code above                                */
-/*  The following user stack layout was set up by machdep.c/sendsig    */
-/*     routine:                                                        */
-/*                                                                     */
-/*     +---------------+                                               */
-/*     |  Last PSL     |\                                              */
-/*     +---------------+ > for rei                                     */
-/*  :-->|  Last PC     |/                                              */
-/*  |  +---------------+                                               */
-/*  :___|__*   SP      |\                                              */
-/*     +---------------+ |                                             */
-/*     |  sigmask      | |                                             */
-/*     +---------------+  > cleaned by kcall $139 (sigcleanup)         */
-/*  :-->|  u.u_onstack | |                                             */
-/*  |  +---------------+ |                                             */
-/*  :___|_* copy of SCP        |/                                              */
-/*  |  +---------------+                                               */
-/*  |  |  Process' r0  |                                               */
-/*  |  +---------------+                                               */
-/*  |  |  Process' r1  |                                               */
-/*  |  +---------------+                                               */
-/*  |  | Handler addr. |\                                              */
-/*  |  +---------------+ |                                             */
-/*  :___|_*   SCP      | |                                             */
-/*     +---------------+  > cleaned by ret from calls                  */
-/*     |  u.u_code     | |                                             */
-/*     +---------------+ |                                             */
-/*     |  signal number|/                                              */
-/*     +---------------+                                               */
-/*                                                                     */
-/*   * Stack when entering sigcode; setup by sendsig();                        */
-/*                                                                     */
+/*
+ * Mask for saving/restoring registers on entry to
+ * a user signal handler.  Space for the registers
+ * is reserved in sendsig, so beware if you want
+ * to change the mask.
+ */
+#define        SIGREGS (R0|R1|R2|R3|R4|R5)
+       .align  2
+       .globl  sigcode
+sigcode:
+       storer  $SIGREGS,16(sp) # save volatile registers
+       calls   $4*3+4,*12(sp)  # params pushed by sendsig for handler
+       loadr   $SIGREGS,4(sp)  # restore volatile registers
+       movab   24(sp),fp       # use parameter list set up in sendsig
+       kcall   $SYS_sigreturn  # cleanup mask and onsigstack
+       halt                    # sigreturn does not return!
+
+       .globl  _icode
+       .globl  _initflags
+       .globl  _szicode
+/*
+ * Icode is copied out to process 1 to exec /etc/init.
+ * If the exec fails, process 1 exits.
+ */
        .align  2
        .align  2
-sigcode:                       # When the process executes this code
-                               #  (located in its u. structure), it
-                               #  is in user mode !
-       calls   $4*4+4,*12(sp)  # 4 words popped from stack when this call returns
-       movl    (sp)+,r1
-       movl    (sp)+,r0
-       kcall   $139            # Signal cleanup
-       rei                     # From user mode to user mode !
+_icode:
+       pushab  b`argv-l0(pc)
+l0:    pushab  b`init-l1(pc)
+l1:    pushl   $2
+       movab   (sp),fp
+       kcall   $SYS_execv
+       kcall   $SYS_exit
+
+init:  .asciz  "/etc/init"
+       .align  2
+_initflags:
+       .long   0
+argv:  .long   init+5-_icode
+       .long   _initflags-_icode
+       .long   0
+_szicode:
+       .long   _szicode-_icode
 
 /*
  * Primitives
 
 /*
  * Primitives
@@ -779,9 +776,7 @@ sigcode:                    # When the process executes this code
  *     len is length of access (1=byte, 2=short, 4=long)
  *     r0 = 0 means good(exists); r0 =1 means does not exist.
  */
  *     len is length of access (1=byte, 2=short, 4=long)
  *     r0 = 0 means good(exists); r0 =1 means does not exist.
  */
-       .globl  _badaddr
-_badaddr:
-       .word   0x1c    # Keep r4,r3,r2
+ENTRY(badaddr, R3|R4)
        mfpr    $IPL,r1
        mtpr    $HIGH,$IPL
        movl    _scb+BERVEC,r2
        mfpr    $IPL,r1
        mtpr    $HIGH,$IPL
        movl    _scb+BERVEC,r2
@@ -791,17 +786,17 @@ _badaddr:
        bbc     $0,r4,1f; tstb  (r3)
 1:     bbc     $1,r4,1f; tstw  (r3)
 1:     bbc     $2,r4,1f; tstl  (r3)
        bbc     $0,r4,1f; tstb  (r3)
 1:     bbc     $1,r4,1f; tstw  (r3)
 1:     bbc     $2,r4,1f; tstl  (r3)
-1:     clrl    r0                      # made it w/o machine checks
+1:     clrl    r0
 2:     movl    r2,_scb+BERVEC
        mtpr    r1,$IPL
        ret
 
        .align  2
 2:     movl    r2,_scb+BERVEC
        mtpr    r1,$IPL
        ret
 
        .align  2
-9:                     # Here we catch buss error (if it comes)
+9:                             # catch buss error (if it comes)
        andl3   4(sp),$ERRCD,r0
        cmpl    r0,$APE
        jneq    1f
        andl3   4(sp),$ERRCD,r0
        cmpl    r0,$APE
        jneq    1f
-       halt                    # Address parity error !!!
+       halt                    # address parity error
 1:     cmpl    r0,$VBE
        jneq    1f
        halt                    # Versabus error
 1:     cmpl    r0,$VBE
        jneq    1f
        halt                    # Versabus error
@@ -811,69 +806,83 @@ _badaddr:
        movab   2b,(sp)         # new program counter on stack.
        rei
 
        movab   2b,(sp)         # new program counter on stack.
        rei
 
-
 /*
  * badcyaddr(addr)
  *     see if access tape master controller addr causes a bus error
  *     r0 = 0: no error; r0 = 1: timeout error.
  */
 /*
  * badcyaddr(addr)
  *     see if access tape master controller addr causes a bus error
  *     r0 = 0: no error; r0 = 1: timeout error.
  */
-       .globl  _badcyaddr
-_badcyaddr:
-       .word   0x0c    # Keep r3,r2
+ENTRY(badcyaddr, 0)
        mfpr    $IPL,r1
        mtpr    $HIGH,$IPL
        mfpr    $IPL,r1
        mtpr    $HIGH,$IPL
-       movl    _scb+BERVEC,r2
-       clrl    r3
-       movab   9f,_scb+BERVEC
+       clrl    r2
+       movab   2f,nofault
        movob   $-1, *4(fp)
        movob   $-1, *4(fp)
-1:     aobleq  $1000, r3, 1b
-       clrl    r0                      # made it w/o machine checks
-2:     movl    r2,_scb+BERVEC
-       mtpr    r1,$IPL
+1:     aobleq  $1000, r2, 1b
+       clrl    nofault                 # made it w/o bus error
+       clrl    r0
+       jbr     3f
+2:     movl    $1,r0
+3:     mtpr    r1,$IPL
        ret
 
        ret
 
-       .align  2
-9:                     # Here we catch buss error (if it comes)
-       andl3   4(sp),$ERRCD,r0
-       cmpl    r0,$APE
-       jneq    1f
-       halt                    # Address parity error !!!
-1:     cmpl    r0,$VBE
-       jneq    1f
-       halt                    # Versabus error
-1:
-       movl    $1,r0           # Anything else = timeout
-       movab   8(sp),sp        # discard buss error trash
-       movab   2b,(sp)         # new program counter on stack.
-       rei
+/*
+ * peek(addr)
+ *     fetch word and catch any bus error
+ */
+ENTRY(peek, 0)
+       mfpr    $IPL,r1
+       mtpr    $0x18,$IPL      # not reentrant
+       movl    4(fp),r2
+       movab   1f,nofault
+       movw    (r2),r0
+       clrl    nofault
+       andl2   $0xffff,r0
+       jbr     2f
+1:     movl    $-1,r0          # bus error
+2:     mtpr    r1,$IPL
+       ret
 
 
-_bcopy:        .globl  _bcopy
-       .word   0x4             # save r2
-                               # Called by ovbcopy(from,dst,len)
-       movl    4(fp),r0
-       movl    8(fp),r1
-       movl    12(fp),r2
-       movblk
+/*
+ * poke(addr, val)
+ *     write word and catch any bus error
+ */
+ENTRY(poke, R3)
+       mfpr    $IPL,r1
+       mtpr    $0x18,$IPL      # not reentrant
+       movl    4(fp),r2
+       movl    8(fp),r3
+       clrl    r0
+       movab   1f,nofault
+       movw    r3,(r2)
+       clrl    nofault
+       jbr     2f
+1:     movl    $-1,r0          # bus error
+2:     mtpr    r1,$IPL
        ret
 
        ret
 
-_ovbcopy:      .globl  _ovbcopy
-       .word   0x001c
+/*
+ * Copy a potentially overlapping block of memory.
+ *
+ * ovbcopy(src, dst, count)
+ *     caddr_t src, dst; unsigned count;
+ */
+ENTRY(ovbcopy, R3|R4)
        movl    4(fp),r0
        movl    8(fp),r1
        movl    12(fp),r2
        cmpl    r0,r1
        movl    4(fp),r0
        movl    8(fp),r1
        movl    12(fp),r2
        cmpl    r0,r1
-       bgtru   1f              # normal forward case
-       beql    2f              # equal, nothing to do
-       addl2   r2,r0           # may be overlapping
+       bgtru   1f                      # normal forward case
+       beql    2f                      # equal, nothing to do
+       addl2   r2,r0                   # may be overlapping
        cmpl    r0,r1
        bgtru   3f
        cmpl    r0,r1
        bgtru   3f
-       subl2   r2,r0           # normal forward case
+       subl2   r2,r0                   # normal forward case
 1:
        movblk
 2:
        ret
 3:
 1:
        movblk
 2:
        ret
 3:
-       addl2   r2,r1           # overlapping, must do backwards
+       addl2   r2,r1                   # overlapping, must do backwards
        subl3   r0,r1,r3
        movl    r2,r4
        jbr     5f
        subl3   r0,r1,r3
        movl    r2,r4
        jbr     5f
@@ -895,104 +904,230 @@ _ovbcopy:       .globl  _ovbcopy
        ret
 
 /*
        ret
 
 /*
- * bzero (base, count)
- * zero out a block starting at 'base', size 'count'.
+ * Copy a null terminated string from the user address space into
+ * the kernel address space.
+ *
+ * copyinstr(fromaddr, toaddr, maxlength, &lencopied)
  */
  */
-_bzero:        
-       .globl  _bzero
-       .word   0x4
-       movl    $1f,r0                          # r0 = null source string
-       movl    4(fp),r1                        # r1 = destination address
-       movl    8(fp),r2                        # r2 = count
-       movs3
+ENTRY(copyinstr, R3|R4|R5)
+       movl    12(fp),r5               # r5 = max length
+       jlss    8f
+       movl    4(fp),r0                # r0 = user address
+       movl    r0,r3                   # r3 = copy of src for null byte test
+       andl3   $(NBPG*CLSIZE-1),r0,r2  # r2 = bytes on first page
+       subl3   r2,$(NBPG*CLSIZE),r2
+       movl    8(fp),r1                # r1 = kernel address
+1:
+       cmpl    r5,r2                   # r2 = min(bytes on page, length left);
+       jgeq    2f
+       movl    r5,r2
+2:
+       prober  $1,(r0),r2              # bytes accessible?
+       jeql    8f
+       subl2   r2,r5                   # update bytes left count
+       addl2   r2,r3                   # calculate src+count
+       movs3                           # copy in next piece
+       subl3   r0,r3,r2                # null byte found?
+       jneq    3f
+       movl    $(NBPG*CLSIZE),r2       # check next page
+       tstl    r5                      # run out of space?
+       jneq    1b
+       movl    $ENOENT,r0              # set error code and return
+       jbr     9f
+3:
+       tstl    16(fp)                  # return length?
+       beql    4f
+       subl3   r5,12(fp),r5            # actual len = maxlen - unused pages
+       subl2   r2,r5                   #       - unused on this page
+       addl3   $1,r5,*16(fp)           #       + the null byte
+4:
+       clrl    r0
        ret
        ret
+8:
+       movl    $EFAULT,r0
+9:
+       tstl    16(fp)
+       beql    1f
+       subl3   r5,12(fp),*16(fp)
+1:
+       ret
+
+/*
+ * Copy a null terminated string from the kernel
+ * address space to the user address space.
+ *
+ * copyoutstr(fromaddr, toaddr, maxlength, &lencopied)
+ */
+ENTRY(copyoutstr, R3|R4|R5)
+       movl    12(fp),r5               # r5 = max length
+       jlss    8b
+       movl    4(fp),r0                # r0 = kernel address
+       movl    r0,r3                   # r3 = copy of src for null byte test
+       movl    8(fp),r1                # r1 = user address
+       andl3   $(NBPG*CLSIZE-1),r1,r2  # r2 = bytes on first page
+       subl3   r2,$(NBPG*CLSIZE),r2
 1:
 1:
-       .byte 0
+       cmpl    r5,r2                   # r2 = min(bytes on page, length left);
+       jgeq    2f
+       movl    r5,r2
+2:
+       probew  $1,(r1),r2              # bytes accessible?
+       jeql    8b
+       subl2   r2,r5                   # update bytes left count
+       addl2   r2,r3                   # calculate src+count
+#ifdef notdef
+       movs3                           # copy out next piece
+#else
+       tstl    r2
+       beql    6f
+4:
+       movb    (r0),(r1)
+       beql    5f
+       incl    r0
+       incl    r1
+       decl    r2
+       bneq    4b
+       jbr     6f
+5:
+       incl    r1
+       decl    r2
+6:
+#endif
+       subl3   r0,r3,r2                # null byte found?
+       jneq    3b
+       movl    $(NBPG*CLSIZE),r2       # check next page
+       tstl    r5                      # run out of space?
+       jneq    1b
+       movl    $ENOENT,r0              # set error code and return
+       jbr     9b
 
 
+/*
+ * Copy a null terminated string from one point to another in
+ * the kernel address space.
+ *
+ * copystr(fromaddr, toaddr, maxlength, &lencopied)
+ */
+ENTRY(copystr, R3|R4|R5)
+       movl    12(fp),r5               # r5 = max length
+       jlss    8b
+       movl    4(fp),r0                # r0 = src address
+       movl    r0,r3                   # r3 = copy of src for null byte test
+       movl    8(fp),r1                # r1 = dest address
+1:
+       movzwl  $65535,r2               # r2 = bytes in first chunk
+       cmpl    r5,r2                   # r2 = min(bytes in chunk, length left);
+       jgeq    2f
+       movl    r5,r2
+2:
+       subl2   r2,r5                   # update bytes left count
+       addl2   r2,r3                   # calculate src+count
+       movs3                           # copy next piece
+       subl3   r0,r3,r2                # null byte found?
+       jneq    3b
+       tstl    r5                      # run out of space?
+       jneq    1b
+       movl    $ENOENT,r0              # set error code and return
+       jbr     9b
 
 
-_copyin:       .globl  _copyin         # the _Copyin subroutine in VAX
-                                       # became _copyin procedure for TAHOE
-       .word   0x0004
+/*
+ * Copy a block of data from the user address space into
+ * the kernel address space.
+ *
+ * copyin(fromaddr, toaddr, count)
+ */
+ENTRY(copyin, 0)
        movl    12(fp),r0               # copy length
        movl    12(fp),r0               # copy length
-       blss    ersb
+       blss    9f
        movl    4(fp),r1                # copy user address
        movl    4(fp),r1                # copy user address
-       cmpl    $NBPG,r0                # probing one page or less ?
-       bgeq    cishort                 # yes
-ciloop:
-       prober  $1,(r1),$NBPG           # bytes accessible ?
-       beql    ersb                    # no
-       addl2   $NBPG,r1                # incr user address ptr
-       _ACBL   ($NBPG+1,$-NBPG,r0,ciloop)      # reduce count and loop
-cishort:
+       cmpl    $(CLSIZE*NBPG),r0       # probing one page or less ?
+       bgeq    2f                      # yes
+1:
+       prober  $1,(r1),$(CLSIZE*NBPG)  # bytes accessible ?
+       beql    9f                      # no
+       addl2   $(CLSIZE*NBPG),r1       # incr user address ptr
+       _ACBL($(CLSIZE*NBPG+1),$(-CLSIZE*NBPG),r0,1b)   # reduce count and loop
+2:
        prober  $1,(r1),r0              # bytes accessible ?
        prober  $1,(r1),r0              # bytes accessible ?
-       beql    ersb                    # no
-       MOVC3   (12(fp),4(fp),8(fp))
+       beql    9f                      # no
+       MOVC3(4(fp),8(fp),12(fp))
        clrl    r0
        ret
        clrl    r0
        ret
-
-ersb:
+9:
        movl    $EFAULT,r0
        ret
 
        movl    $EFAULT,r0
        ret
 
-_copyout:      .globl  _copyout        # the _Copyout subroutine in VAX
-                                       # became _copyout procedure for TAHOE
-       .word   0x04
+/*
+ * Copy a block of data from the kernel 
+ * address space to the user address space.
+ *
+ * copyout(fromaddr, toaddr, count)
+ */
+ENTRY(copyout, 0)
        movl    12(fp),r0               # get count
        movl    12(fp),r0               # get count
-       blss    ersb
+       blss    9b
        movl    8(fp),r1                # get user address
        movl    8(fp),r1                # get user address
-       cmpl    $NBPG,r0                # can do in one probew?
-       bgeq    coshort                 # yes
-coloop:
-       probew  $1,(r1),$NBPG           # bytes accessible?
-       beql    ersb                    # no 
-       addl2   $NBPG,r1                # increment user address
-       _ACBL   ($NBPG+1,$-NBPG,r0,coloop)      # reduce count and loop
-coshort:
+       cmpl    $(CLSIZE*NBPG),r0       # can do in one probew?
+       bgeq    2f                      # yes
+1:
+       probew  $1,(r1),$(CLSIZE*NBPG)  # bytes accessible?
+       beql    9b                      # no 
+       addl2   $(CLSIZE*NBPG),r1       # increment user address
+       _ACBL($(CLSIZE*NBPG+1),$(-CLSIZE*NBPG),r0,1b)   # reduce count and loop
+2:
        probew  $1,(r1),r0              # bytes accessible?
        probew  $1,(r1),r0              # bytes accessible?
-       beql    ersb                    # no
-       MOVC3   (12(fp),4(fp),8(fp))
+       beql    9b                      # no
+       MOVC3(4(fp),8(fp),12(fp))
        clrl    r0
        ret
 
 /*
  * non-local goto's
  */
        clrl    r0
        ret
 
 /*
  * non-local goto's
  */
-       .globl  _setjmp                 # the _Setjmp subroutine in VAX
-                                       # became _setjmp procedure for TAHOE
-_setjmp:
-       .word   0x0
-       movl    4(fp),r2
-       storer  $0x1ff8,(r2)
-       addl2   $40,r2
-       movl    (fp),(r2)
-       addl2   $4,r2
-       movab   8(fp),(r2)
-       addl2   $4,r2
-       movl    -8(fp),(r2)
+#ifdef notdef
+ENTRY(setjmp, 0)
+       movl    4(fp),r0
+       movl    (fp),(r0); addl2 $4,r0          # save fp
+       movl    -8(fp),(r0)                     # save pc
        clrl    r0
        ret
        clrl    r0
        ret
+#endif
 
 
-       .globl  _longjmp                # the _Longjmp subroutine in VAX
-                                       # became _longjmp procedure for TAHOE
-_longjmp:
-       .word   0x0000
-       movl    4(fp),r2
-_Longjmp:                      # called from swtch
-       loadr   $0x3ff8,(r2)
-       addl2   $44,r2
-       movl    (r2),r1
-       addl2   $4,r2
-       movab   (sp),r0
-       cmpl    r1,r0                           # must be a pop
-       bgequ   lj2
-       pushab  lj1
+ENTRY(longjmp, 0)
+       movl    4(fp),r0
+       movl    (r0),newfp; addl2 $4,r0         # must save parameters in memory
+       movl    (r0),newpc                      # as all regs may be clobbered.
+1:
+       cmpl    fp,newfp                        # are we there yet?
+       bgequ   2f                              # yes
+       moval   1b,-8(fp)                       # redirect return pc to us!
+       ret                                     # pop next frame
+2:
+       beql    3f                              # did we miss our frame?
+       pushab  4f                              # yep ?!?
        callf   $8,_panic
        callf   $8,_panic
-lj2:
-       movl    r1,sp
-       jmp     *(r2)
+3:
+       movl    newpc,r0                        # all done, just return
+       jmp     (r0)                            # to setjmp `ret'
 
 
-lj1:   .asciz  "longjmp"
+       .data
+newpc: .space  4
+newfp: .space  4
+4:     .asciz  "longjmp"
 
 
+/*
+ * setjmp that saves all registers as the call frame may not
+ * be available to recover them in the usual manner by longjmp.
+ * Called before swapping out the u. area, restored by resume()
+ * below.
+ */
+ENTRY(savectx, 0)
+       movl    4(fp),r2
+       storer  $0x1ff8,(r2); addl2 $40,r2      # r3-r12
+       movl    (fp),(r2); addl2 $4,r2          # fp
+       movab   8(fp),(r2); addl2 $4,r2         # sp
+       movl    -8(fp),(r2)                     # pc
+       clrl    r0
+       ret
 
        .globl  _whichqs
        .globl  _qs
 
        .globl  _whichqs
        .globl  _qs
@@ -1002,7 +1137,6 @@ lj1:      .asciz  "longjmp"
        .comm   _noproc,4
        .globl  _runrun
        .comm   _runrun,4
        .comm   _noproc,4
        .globl  _runrun
        .comm   _runrun,4
-
 /*
  * The following primitives use the fancy TAHOE instructions.
  * _whichqs tells which of the 32 queues _qs
 /*
  * The following primitives use the fancy TAHOE instructions.
  * _whichqs tells which of the 32 queues _qs
@@ -1018,9 +1152,7 @@ lj1:      .asciz  "longjmp"
  *
  * Call should be made at spl8(), and p->p_stat should be SRUN
  */
  *
  * Call should be made at spl8(), and p->p_stat should be SRUN
  */
-       .globl  _setrq
-_setrq:
-       .word   0x4
+ENTRY(setrq, 0)
        movl    4(fp),r0
        tstl    P_RLINK(r0)             ## firewall: p->p_rlink must be 0
        beql    set1                    ##
        movl    4(fp),r0
        tstl    P_RLINK(r0)             ## firewall: p->p_rlink must be 0
        beql    set1                    ##
@@ -1043,9 +1175,7 @@ set3:     .asciz  "setrq"
  *
  * Call should be made at spl8().
  */
  *
  * Call should be made at spl8().
  */
-       .globl  _remrq
-_remrq:
-       .word   0x0
+ENTRY(remrq, 0)
        movl    4(fp),r0
        movzbl  P_PRI(r0),r1
        shar    $2,r1,r1
        movl    4(fp),r0
        movzbl  P_PRI(r0),r1
        shar    $2,r1,r1
@@ -1064,19 +1194,6 @@ rem2:
 
 rem3:  .asciz  "remrq"
 
 
 rem3:  .asciz  "remrq"
 
-       .globl __insque
-__insque:
-       .word 0
-       insque  *4(fp), *8(fp)
-       ret
-
-
-       .globl __remque
-__remque:
-       .word 0
-       remque  *4(fp)
-       ret
-
 /*
  * Masterpaddr is the p->p_addr of the running process on the master
  * processor.  When a multiprocessor system, the slave processors will have
 /*
  * Masterpaddr is the p->p_addr of the running process on the master
  * processor.  When a multiprocessor system, the slave processors will have
@@ -1084,17 +1201,14 @@ __remque:
  */
        .globl  _masterpaddr
        .data
  */
        .globl  _masterpaddr
        .data
-_masterpaddr:
-       .long   0
+_masterpaddr: .long    0
 
        .text
 sw0:   .asciz  "swtch"
 /*
 
        .text
 sw0:   .asciz  "swtch"
 /*
- * swtch(), using fancy TAHOE instructions
+ * swtch(), using fancy tahoe instructions
  */
  */
-       .globl  _swtch
-_swtch:
-       .word   0x0
+ENTRY(swtch, 0)
        movl    (fp),fp                 # prepare for rei
        movl    (sp),4(sp)              # saved pc
        tstl    (sp)+
        movl    (fp),fp                 # prepare for rei
        movl    (sp),4(sp)              # saved pc
        tstl    (sp)+
@@ -1129,39 +1243,29 @@ sw3:
        movl    *P_ADDR(r2),r0
        movl    r0,_masterpaddr
        shal    $PGSHIFT,r0,r0          # r0 = pcbb(p)
        movl    *P_ADDR(r2),r0
        movl    r0,_masterpaddr
        shal    $PGSHIFT,r0,r0          # r0 = pcbb(p)
-/*     mfpr    $PCBB,r1                # resume of current proc is easy
- *     cmpl    r0,r1
- */    beql    res0
+#ifdef notdef
+       mfpr    $PCBB,r1                # resume of current proc is easy
+       cmpl    r0,r1
+       beql    res0
+#endif
        incl    _cnt+V_SWTCH
        brb     swresume
        incl    _cnt+V_SWTCH
        brb     swresume
-/* fall into... */
+       /* fall into... */
 
 
-/*
- * global cache key used if cant use proc index as key
- * (e.g. NPROC>=255)
- * otherwise used for temporary storage of key
- */
-       .data
-       .globl  _globkey
-_globkey:
-       .long   0
        .globl  _prevpcb
        .globl  _prevpcb
-_prevpcb:
-       .long   0
+_prevpcb: .long        0
        .text
 /*
  * resume(pf)
  */
        .text
 /*
  * resume(pf)
  */
-       .globl  _resume
-_resume:
-       .word   0x0
-       shal    $PGSHIFT,4(fp),r0       # r0 = pcbb(p)
+ENTRY(resume, 0)
+       shal    $PGSHIFT,4(fp),r0       # r0 = pcbb(pf)
        movl    (fp),fp                 # prepare for rei
        movl    (sp)+,4(sp)             # saved pc
        tstl    (sp)+
        movpsl  4(sp)
 swresume:
        movl    (fp),fp                 # prepare for rei
        movl    (sp)+,4(sp)             # saved pc
        tstl    (sp)+
        movpsl  4(sp)
 swresume:
-       mtpr    $0x18,$IPL                      # no interrupts, please
+       mtpr    $0x18,$IPL              # no interrupts, please
        movl    _CMAP2,_u+PCB_CMAP2     # yech
        REST_ACC                        # restore original accumulator
        svpctx
        movl    _CMAP2,_u+PCB_CMAP2     # yech
        REST_ACC                        # restore original accumulator
        svpctx
@@ -1170,38 +1274,46 @@ swresume:
        movl    _u+PCB_CMAP2,_CMAP2     # yech
        mtpr    $_CADDR2,$TBIS
 res0:
        movl    _u+PCB_CMAP2,_CMAP2     # yech
        mtpr    $_CADDR2,$TBIS
 res0:
+       PUSHR;
+       movl    _u+U_PROCP,r2           # r2 = u.u_procp
+       tstl    P_CKEY(r2)              # does proc have code key?
+       bneq    1f
+       callf   $4,_getcodekey          # no, give him one
+       movl    r0,P_CKEY(r2)
+1:
+       movl    _u+U_PROCP,r2           # r2 = u.u_procp
+       tstl    P_DKEY(r2)              # does proc have data key?
+       bneq    1f
+       callf   $4,_getdatakey          # no, give him one
+       movl    r0,P_DKEY(r2)
+1:
+       mtpr    P_CKEY(r2),$CCK         # set code cache key
+       mtpr    P_DKEY(r2),$DCK         # set data cache key
+       POPR
        tstl    _u+PCB_SSWAP
        tstl    _u+PCB_SSWAP
-       beql    res1
+       bneq    res1
+       rei
+res1:                                  # longjmp to saved context
        movl    _u+PCB_SSWAP,r2
        clrl    _u+PCB_SSWAP
        movl    _u+PCB_SSWAP,r2
        clrl    _u+PCB_SSWAP
-       movab   _Longjmp,(sp)
-       clrl    4(sp)                   # PSL = kernel mode, IPL=0
-res1:
-#ifdef GLOBKEY
-       aoblss  $256,_globkey,res2      # define new cache key
-       mtpr    $0,$PACC                # out of keys, purge all
-       mtpr    $0,$PADC
-       movl    $1,_globkey
-res2:
-       mtpr    _globkey,$CCK
-#else
-res3:
-       movzwl  _u+PCB_CKEY,_globkey
-       mtpr    _globkey,$CCK
-res4:
-       movzwl  _u+PCB_DKEY,_globkey
-#endif
-       mtpr    _globkey,$DCK
+       loadr   $0x3ff8,(r2); addl2 $44,r2      # restore r3-r13 (r13=fp)
+       movl    (r2),r1; addl2 $4,r2    # fetch previous sp ...
+       movab   (sp),r0                 # ... and current sp and
+       cmpl    r1,r0                   # check for credibility,
+       bgequ   1f                      # if further up stack ...
+       pushab 2f; callf $8,_panic      # ... panic
+       /*NOTREACHED*/
+1:                                     # sp ok, complete return
+       movl    r1,sp                   # restore sp
+       movl    (r2),(sp)               # return address
+       movl    $PSL_PRVMOD,4(sp)       # kernel mode, ipl 0
        rei
        rei
+2:     .asciz  "ldctx"
 
 /*
  * {fu,su},{byte,word}
  */
 
 /*
  * {fu,su},{byte,word}
  */
-       .globl  _fuiword
-       .globl  _fuword
-_fuiword:
-_fuword:
-       .word   0x0
+ENTRY(fuword, 0)
        movl    4(fp), r1
        prober  $1,(r1),$4              # check access
        beql    fserr                   # page unreadable
        movl    4(fp), r1
        prober  $1,(r1),$4              # check access
        beql    fserr                   # page unreadable
@@ -1230,21 +1342,13 @@ fserr:
        mnegl   $1,r0
        ret
 
        mnegl   $1,r0
        ret
 
-       .globl  _fuibyte
-       .globl  _fubyte
-_fuibyte:
-_fubyte:
-       .word   0x0
+ENTRY(fubyte, 0)
        prober  $1,*4(fp),$1
        beql    fserr
        movzbl  *4(fp),r0
        ret
 
        prober  $1,*4(fp),$1
        beql    fserr
        movzbl  *4(fp),r0
        ret
 
-       .globl  _suiword
-       .globl  _suword
-_suiword:
-_suword:
-       .word   0x0
+ENTRY(suword, 0)
        movl    4(fp), r0
        probew  $1,(r0),$4              # check access
        beql    fserr                   # page unwritable
        movl    4(fp), r0
        probew  $1,(r0),$4              # check access
        beql    fserr                   # page unwritable
@@ -1267,11 +1371,7 @@ _suword:
        clrl    r0
        ret
 
        clrl    r0
        ret
 
-       .globl  _suibyte
-       .globl  _subyte
-_suibyte:
-_subyte:
-       .word   0x0
+ENTRY(subyte, 0)
        probew  $1,*4(fp),$1
        beql    fserr
        movb    11(fp),*4(fp)
        probew  $1,*4(fp),$1
        beql    fserr
        movb    11(fp),*4(fp)
@@ -1282,22 +1382,18 @@ _subyte:
  * Copy 1 relocation unit (NBPG bytes)
  * from user virtual address to physical address
  */
  * Copy 1 relocation unit (NBPG bytes)
  * from user virtual address to physical address
  */
-_copyseg:      .globl  _copyseg
-       .word   0x4
+ENTRY(copyseg, 0)
        orl3    $PG_V|PG_KW,8(fp),_CMAP2
        mtpr    $_CADDR2,$TBIS  # invalidate entry for copy 
        orl3    $PG_V|PG_KW,8(fp),_CMAP2
        mtpr    $_CADDR2,$TBIS  # invalidate entry for copy 
-       MOVC3   ($NBPG,4(fp),$_CADDR2)
+       MOVC3(4(fp),$_CADDR2,$NBPG)
        ret
 
 /*
        ret
 
 /*
- * clearseg(physical_page_number);
+ * Clear a page of memory.  The page frame is specified.
  *
  *
- * zero out physical memory
- * specified in relocation units (NBPG bytes)
- * This routine was optimized for speed on Tahoe.
+ * clearseg(pf);
  */
  */
-_clearseg:     .globl  _clearseg
-       .word   0
+ENTRY(clearseg, 0)
        orl3    $PG_V|PG_KW,4(fp),_CMAP1        # Maps to virtual addr CADDR1
        mtpr    $_CADDR1,$TBIS
        movl    $255,r0                         # r0 = limit
        orl3    $PG_V|PG_KW,4(fp),_CMAP1        # Maps to virtual addr CADDR1
        mtpr    $_CADDR1,$TBIS
        movl    $255,r0                         # r0 = limit
@@ -1308,42 +1404,40 @@ _clearseg:      .globl  _clearseg
        ret
 
 /*
        ret
 
 /*
- * if ( useracc(address, count, mode) ) ....
- * Check address.
- * Given virtual address, byte count, and rw flag
- * returns 0 on no access.
- * Note : it is assumed that on all calls to this routine,
- *  mode=0 means write access, mode=1 means read access.
+ * Check user mode read/write access.
+ *
+ * useracc(addr, count, mode)
+ *     caddr_t addr; int count, mode;
+ * mode = 0    write access
+ * mode = 1    read access
  */
  */
-_useracc:      .globl  _useracc
-       .word   0x4
+ENTRY(useracc, 0)
        movl    $1,r2                   # r2 = 'user mode' for probew/probew
 probes:
        movl    4(fp),r0                # get va
        movl    8(fp),r1                # count
        tstl    12(fp)                  # test for read access ?
        bneq    userar                  # yes
        movl    $1,r2                   # r2 = 'user mode' for probew/probew
 probes:
        movl    4(fp),r0                # get va
        movl    8(fp),r1                # count
        tstl    12(fp)                  # test for read access ?
        bneq    userar                  # yes
-       cmpl    $NBPG,r1                        # can we do it in one probe ?
+       cmpl    $(CLSIZE*NBPG),r1       # can we do it in one probe ?
        bgeq    uaw2                    # yes
 uaw1:
        bgeq    uaw2                    # yes
 uaw1:
-       probew  r2,(r0),$NBPG
+       probew  r2,(r0),$(CLSIZE*NBPG)
        beql    uaerr                   # no access
        beql    uaerr                   # no access
-       addl2   $NBPG,r0
-       _ACBL($NBPG+1,$-NBPG,r1,uaw1)
+       addl2   $(CLSIZE*NBPG),r0
+       _ACBL($(CLSIZE*NBPG+1),$(-CLSIZE*NBPG),r1,uaw1)
 uaw2:
        probew  r2,(r0),r1
        beql    uaerr
        movl    $1,r0
        ret
 uaw2:
        probew  r2,(r0),r1
        beql    uaerr
        movl    $1,r0
        ret
-
 userar:
 userar:
-       cmpl    $NBPG,r1
+       cmpl    $(CLSIZE*NBPG),r1
        bgeq    uar2
 uar1:
        bgeq    uar2
 uar1:
-       prober  r2,(r0),$NBPG
+       prober  r2,(r0),$(CLSIZE*NBPG)
        beql    uaerr
        beql    uaerr
-       addl2   $NBPG,r0
-       _ACBL($NBPG+1,$-NBPG,r1,uar1)
+       addl2   $(CLSIZE*NBPG),r0
+       _ACBL($(CLSIZE*NBPG+1),$(-CLSIZE*NBPG),r1,uar1)
 uar2:
        prober  r2,(r0),r1
        beql    uaerr
 uar2:
        prober  r2,(r0),r1
        beql    uaerr
@@ -1354,15 +1448,14 @@ uaerr:
        ret
 
 /*
        ret
 
 /*
- * if ( kernacc(address, count, mode) ) ....
- * Check address.
- * Given virtual address, byte count, and rw flag
- * returns 0 on no access.
- * Same as useracc routine but checks for kernel access rights.
+ * Check kernel mode read/write access.
+ *
+ * kernacc(addr, count, mode)
+ *     caddr_t addr; int count, mode;
+ * mode = 0    write access
+ * mode = 1    read access
  */
  */
-
-_kernacc:      .globl  _kernacc
-       .word   0x4
+ENTRY(kernacc, 0)
        clrl    r2              # r2 = 0 means kernel mode probe.
        jbr     probes          # Dijkstra would get gastric distress here.
 
        clrl    r2              # r2 = 0 means kernel mode probe.
        jbr     probes          # Dijkstra would get gastric distress here.
 
@@ -1370,9 +1463,8 @@ _kernacc: .globl  _kernacc
  * addupc - increment some histogram counter
  *     in the profiling buffer
  *
  * addupc - increment some histogram counter
  *     in the profiling buffer
  *
- * addupc(pc, prof, counts)
- * long        pc , counts;    Only least significant word of 'counts' is added.
- * struct      uprof *prof;
+ * addupc(pc, prof, delta)
+ *     long pc; short delta; struct uprof *prof;
  * 
  * struct uprof {              # profile arguments 
  *     short   *r_base;        # buffer base 
  * 
  * struct uprof {              # profile arguments 
  *     short   *r_base;        # buffer base 
@@ -1381,22 +1473,72 @@ _kernacc:       .globl  _kernacc
  *     unsigned pr_scale;      # pc scaling 
  * }
  */
  *     unsigned pr_scale;      # pc scaling 
  * }
  */
-       .globl  _addupc
-_addupc:
-       .word   4
-       movl    8(fp),r2        # r2 points to structure
-       subl3   8(r2),4(fp),r0  # r0 = PC - lowpc
-       jlss    9f              # PC < lowpc , out of range !
-       shrl    $1,r0,r0        # the unit is words
-       shrl    $1,12(r2),r1    # ditto for scale
+ENTRY(addupc, 0)
+       movl    8(fp),r2                # r2 points to structure
+       subl3   8(r2),4(fp),r0          # r0 = PC - lowpc
+       jlss    9f                      # PC < lowpc , out of range !
+       shrl    $1,r0,r0                # the unit is words
+       shrl    $1,12(r2),r1            # ditto for scale
        emul    r1,r0,$0,r0
        shrq    $14,r0,r0
        emul    r1,r0,$0,r0
        shrq    $14,r0,r0
-       tstl    r0              # too big
+       tstl    r0                      # too big
        jneq    9f
        jneq    9f
-       cmpl    r1,4(r2)        # Check buffer overflow
+       cmpl    r1,4(r2)                # Check buffer overflow
        jgequ   9f
        probew  $1,*0(r2)[r1],$2        # counter accessible?
        jeql    9f
        jgequ   9f
        probew  $1,*0(r2)[r1],$2        # counter accessible?
        jeql    9f
-       shrl    $1,r1,r1        # make r1 word index
+       shrl    $1,r1,r1                # make r1 word index
        addw2   14(fp),*0(r2)[r1]
 9:     ret
        addw2   14(fp),*0(r2)[r1]
 9:     ret
+
+/*
+ * scanc(size, cp, table, mask)
+ */
+ENTRY(scanc, R3|R4)
+       movl    8(fp),r0                # r0 = cp
+       addl3   4(fp),r0,r2             # end = &cp[size]
+       movl    12(fp),r1               # r1 = table
+       movb    19(fp),r4               # r4 = mask
+       decl    r0                      # --cp
+       jbr     0f                      # just like Fortran...
+1:                                     # do {
+       movzbl  (r0),r3 
+       bitb    r4,(r1)[r3]             #       if (table[*cp] & mask)
+       jneq    2f                      #               break;
+0:     aoblss  r2,r0,1b                # } while (++cp < end);
+2:
+       subl3   r0,r2,r0; ret           # return (end - cp);
+
+/*
+ * skpc(mask, size, cp)
+ */
+ENTRY(skpc, 0)
+       movl    12(fp),r0               # r0 = cp
+       addl3   8(fp),r0,r1             # r1 = end = &cp[size];
+       movb    7(fp),r2                # r2 = mask
+       decl    r0                      # --cp;
+       jbr     0f
+1:                                     # do
+       cmpb    (r0),r2                 #       if (*cp != mask)
+       jneq    2f                      #               break;
+0:     aoblss  r1,r0,1b                # while (++cp < end);
+2:
+       subl3   r0,r1,r0; ret           # return (end - cp);
+
+#ifdef notdef
+/*
+ * locc(mask, size, cp)
+ */
+ENTRY(locc, 0)
+       movl    12(fp),r0               # r0 = cp
+       addl3   8(fp),r0,r1             # r1 = end = &cp[size]
+       movb    7(fp),r2                # r2 = mask
+       decl    r0                      # --cp;
+       jbr     0f
+1:                                     # do
+       cmpb    (r0),r2                 #       if (*cp == mask)
+       jeql    2f                      #               break;
+0:     aoblss  r1,r0,1b                # while (++cp < end);
+2:
+       subl3   r0,r1,r0; ret           # return (end - cp);
+#endif
index bab6414..aab0673 100644 (file)
@@ -1,55 +1,49 @@
-/*     machdep.c       1.4     85/05/15        */
-
-#include "../machine/reg.h"
-#include "../machine/pte.h"
-#include "../machine/psl.h"
-
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/dir.h"
-#include "../h/user.h"
-#include "../h/nami.h"
-#include "../h/kernel.h"
-#include "../h/map.h"
-#include "../h/vm.h"
-#include "../h/proc.h"
-#include "../h/buf.h"
-#include "../h/reboot.h"
-#include "../h/conf.h"
-#include "../h/inode.h"
-#include "../h/file.h"
-#include "../h/text.h"
-#include "../h/clist.h"
-#include "../h/callout.h"
-#include "../h/cmap.h"
-#include "../h/mbuf.h"
-#include "../h/msgbuf.h"
-#include "../h/quota.h"
+/*     machdep.c       1.2     86/01/05        */
+
+#include "../tahoe/reg.h"
+#include "../tahoe/pte.h"
+#include "../tahoe/psl.h"
+
+#include "param.h"
+#include "systm.h"
+#include "dir.h"
+#include "user.h"
+#include "kernel.h"
+#include "map.h"
+#include "vm.h"
+#include "proc.h"
+#include "buf.h"
+#include "reboot.h"
+#include "conf.h"
+#include "inode.h"
+#include "file.h"
+#include "text.h"
+#include "clist.h"
+#include "callout.h"
+#include "cmap.h"
+#include "mbuf.h"
+#include "msgbuf.h"
+#include "quota.h"
+
 #include "../tahoe/mem.h"
 #include "../tahoe/mtpr.h"
 #include "../tahoe/cp.h"
 #include "../tahoe/mem.h"
 #include "../tahoe/mtpr.h"
 #include "../tahoe/cp.h"
-#include "../vba/vbavar.h"
-
-int    icode[] = {
-       0xf9af19f9,     /*      pushab  argp */
-       0xaf09dd02,     /*      pushab  file */
-       0xe96e5dcf,     /*      pushl   $2 */
-       0x0b11fe2f,     /*      movab   (sp),fp */
-       0x6574632f,     /*      kcall   $exec */
-       0x696e6974,     /* here:brb     here */
-       0x00000000,     /*.file:.ascii  "/etc/" */
-       0x00000014,     /* args:.ascii  "init\0" */
-       0x00000000,     /*      .align  2 */
-                       /* argp:.long   args, 0 */
-};
-int    szicode = sizeof(icode);
+#include "../tahoevba/vbavar.h"
+
 /*
  * Declare these as initialized data so we can patch them.
  */
 /*
  * Declare these as initialized data so we can patch them.
  */
-int    nbuf = 0;
 int    nswbuf = 0;
 int    nswbuf = 0;
+#ifdef NBUF
+int    nbuf = NBUF;
+#else
+int    nbuf = 0;
+#endif
+#ifdef BUFPAGES
+int    bufpages = BUFPAGES;
+#else
 int    bufpages = 0;
 int    bufpages = 0;
+#endif
 
 /*
  * Machine-dependent startup code
 
 /*
  * Machine-dependent startup code
@@ -60,9 +54,9 @@ startup(firstaddr)
        register int unixsize;
        register unsigned i;
        register struct pte *pte;
        register int unixsize;
        register unsigned i;
        register struct pte *pte;
-       register int mapaddr, j;
+       int mapaddr, j;
        register caddr_t v;
        register caddr_t v;
-       register int maxbufs, base, residual;
+       int maxbufs, base, residual;
        extern char etext;
 
        /*
        extern char etext;
 
        /*
@@ -72,74 +66,29 @@ startup(firstaddr)
        pte = msgbufmap;
        for (i = 0; i < btoc(sizeof (struct msgbuf)); i++)
                *(int *)pte++ = PG_V | PG_KW | (maxmem + i);
        pte = msgbufmap;
        for (i = 0; i < btoc(sizeof (struct msgbuf)); i++)
                *(int *)pte++ = PG_V | PG_KW | (maxmem + i);
-       mtpr(1,TBIA);
+       mtpr(TBIA, 1);
 
        /*
         * Good {morning,afternoon,evening,night}.
         */
        printf(version);
 
        /*
         * Good {morning,afternoon,evening,night}.
         */
        printf(version);
-       printf("real mem  = %d\n", ctob(maxmem));
-       
-       /*
-        * Determine how many buffers to allocate.
-        * Use 10% of memory, with min of 16.
-        * We allocate 1/2 as many swap buffer headers as file i/o buffers.
-        */
-       maxbufs = ((SYSPTSIZE * NBPG) - (5 * (int)(&etext - 0xc0000000))) /
-           MAXBSIZE;
-       if (bufpages == 0)
-               bufpages = (physmem * NBPG) / 10 / CLBYTES;
-       if (nbuf == 0) {
-               nbuf = bufpages / 2;
-               if (nbuf < 16)
-                       nbuf = 16;
-               if (nbuf > maxbufs)
-                       nbuf = maxbufs;
-       }
-       if (bufpages > nbuf * (MAXBSIZE / CLBYTES))
-               bufpages = nbuf * (MAXBSIZE / CLBYTES);
-       if (nswbuf == 0) {
-               nswbuf = (nbuf / 2) &~ 1;       /* force even */
-               if (nswbuf > 256)
-                       nswbuf = 256;           /* sanity */
-       }
+       printf("real mem  = %d\n", ctob(physmem));
 
        /*
         * Allocate space for system data structures.
         * The first available real memory address is in "firstaddr".
 
        /*
         * Allocate space for system data structures.
         * The first available real memory address is in "firstaddr".
-        * As pages of memory are allocated, "firstaddr" is incremented.
         * The first available kernel virtual address is in "v".
         * As pages of kernel virtual memory are allocated, "v" is incremented.
         * The first available kernel virtual address is in "v".
         * As pages of kernel virtual memory are allocated, "v" is incremented.
+        * As pages of memory are allocated and cleared,
+        * "firstaddr" is incremented.
         * An index into the kernel page table corresponding to the
         * virtual memory address maintained in "v" is kept in "mapaddr".
         */
         * An index into the kernel page table corresponding to the
         * virtual memory address maintained in "v" is kept in "mapaddr".
         */
-       mapaddr = firstaddr;
        v = (caddr_t)(0xc0000000 | (firstaddr * NBPG));
 #define        valloc(name, type, num) \
        v = (caddr_t)(0xc0000000 | (firstaddr * NBPG));
 #define        valloc(name, type, num) \
-           (name) = (type *)(v); (v) = (caddr_t)((name)+(num))
+           (name) = (type *)v; v = (caddr_t)((name)+(num))
 #define        valloclim(name, type, num, lim) \
 #define        valloclim(name, type, num, lim) \
-           (name) = (type *)(v); (v) = (caddr_t)((lim) = ((name)+(num)))
-       valloc(buffers, char, MAXBSIZE * nbuf);
-       base = bufpages / nbuf;
-       residual = bufpages % nbuf;
-       for (i = 0; i < residual; i++) {
-               for (j = 0; j < (base + 1) * CLSIZE; j++) {
-                       *(int *)(&Sysmap[mapaddr+j]) = PG_V | PG_KW | firstaddr;
-                       clearseg((unsigned)firstaddr);
-                       firstaddr++;
-               }
-               mapaddr += MAXBSIZE / NBPG;
-       }
-       for (i = residual; i < nbuf; i++) {
-               for (j = 0; j < base * CLSIZE; j++) {
-                       *(int *)(&Sysmap[mapaddr+j]) = PG_V | PG_KW | firstaddr;
-                       clearseg((unsigned)firstaddr);
-                       firstaddr++;
-               }
-               mapaddr += MAXBSIZE / NBPG;
-       }
-       valloc(buf, struct buf, nbuf);
-       valloc(swbuf, struct buf, nswbuf);
+           (name) = (type *)v; v = (caddr_t)((lim) = ((name)+(num)))
        valloclim(inode, struct inode, ninode, inodeNINODE);
        valloclim(file, struct file, nfile, fileNFILE);
        valloclim(proc, struct proc, nproc, procNPROC);
        valloclim(inode, struct inode, ninode, inodeNINODE);
        valloclim(file, struct file, nfile, fileNFILE);
        valloclim(proc, struct proc, nproc, procNPROC);
@@ -155,34 +104,104 @@ startup(firstaddr)
        valloclim(quota, struct quota, nquota, quotaNQUOTA);
        valloclim(dquot, struct dquot, ndquot, dquotNDQUOT);
 #endif
        valloclim(quota, struct quota, nquota, quotaNQUOTA);
        valloclim(dquot, struct dquot, ndquot, dquotNDQUOT);
 #endif
+       
+       /*
+        * Determine how many buffers to allocate.
+        * Use 10% of memory for the first 2 Meg, 5% of the remaining
+        * memory. Insure a minimum of 16 buffers.
+        * We allocate 1/2 as many swap buffer headers as file i/o buffers.
+        */
+       if (bufpages == 0)
+               if (physmem < (2 * 1024 * 1024))
+                       bufpages = physmem / 10 / CLSIZE;
+               else
+                       bufpages =
+                           ((2 * 1024 * 1024) / 5 + physmem / 5) / CLSIZE;
+       if (nbuf == 0) {
+               nbuf = bufpages / 2;
+               if (nbuf < 16)
+                       nbuf = 16;
+       }
+       if (nswbuf == 0) {
+               nswbuf = (nbuf / 2) &~ 1;       /* force even */
+               if (nswbuf > 256)
+                       nswbuf = 256;           /* sanity */
+       }
+       valloc(swbuf, struct buf, nswbuf);
+
        /*
        /*
-        * Now allocate space for core map
+        * Now the amount of virtual memory remaining for buffers
+        * can be calculated, estimating needs for the cmap.
+        */
+       ncmap = (maxmem*NBPG - ((int)v &~ 0xc0000000)) /
+               (CLBYTES + sizeof(struct cmap)) + 2;
+       maxbufs = ((SYSPTSIZE * NBPG) -
+           ((int)(v + ncmap * sizeof(struct cmap)) - 0xc0000000)) /
+               (MAXBSIZE + sizeof(struct buf));
+       if (maxbufs < 16)
+               panic("sys pt too small");
+       if (nbuf > maxbufs) {
+               printf("SYSPTSIZE limits number of buffers to %d\n", maxbufs);
+               nbuf = maxbufs;
+       }
+       if (bufpages > nbuf * (MAXBSIZE / CLBYTES))
+               bufpages = nbuf * (MAXBSIZE / CLBYTES);
+       valloc(buf, struct buf, nbuf);
+
+       /*
+        * Allocate space for core map.
         * Allow space for all of phsical memory minus the amount 
         * dedicated to the system. The amount of physical memory
         * dedicated to the system is the total virtual memory of
         * Allow space for all of phsical memory minus the amount 
         * dedicated to the system. The amount of physical memory
         * dedicated to the system is the total virtual memory of
-        * the system minus the space in the buffers which is not
-        * allocated real memory.
+        * the system thus far, plus core map, buffer pages,
+        * and buffer headers not yet allocated.
+        * Add 2: 1 because the 0th entry is unused, 1 for rounding.
         */
         */
-       ncmap = (physmem*NBPG - ((int)v &~ 0xc0000000) +
-               (nbuf * MAXBSIZE - bufpages * CLBYTES)) /
-                   (NBPG*CLSIZE + sizeof (struct cmap));
+       ncmap = (maxmem*NBPG - ((int)(v + bufpages*CLBYTES) &~ 0xc0000000)) /
+               (CLBYTES + sizeof(struct cmap)) + 2;
        valloclim(cmap, struct cmap, ncmap, ecmap);
        valloclim(cmap, struct cmap, ncmap, ecmap);
-       if ((((int)(ecmap+1))&~0xc0000000) > SYSPTSIZE*NBPG)
-               panic("sys pt too small");
 
        /*
 
        /*
-        * Clear allocated space, and make r/w entries
+        * Clear space allocated thus far, and make r/w entries
         * for the space in the kernel map.
         */
         * for the space in the kernel map.
         */
-       unixsize = btoc((int)(ecmap+1) &~ 0xc0000000);
-       for (i = mapaddr; i < unixsize; i++) {
-               *(int *)(&Sysmap[i]) = PG_V | PG_KW | firstaddr;
+       unixsize = btoc((int)v &~ 0xc0000000);
+       while (firstaddr < unixsize) {
+               *(int *)(&Sysmap[firstaddr]) = PG_V | PG_KW | firstaddr;
                clearseg((unsigned)firstaddr);
                firstaddr++;
        }
                clearseg((unsigned)firstaddr);
                firstaddr++;
        }
+
+       /*
+        * Now allocate buffers proper.  They are different than the above
+        * in that they usually occupy more virtual memory than physical.
+        */
+       v = (caddr_t) ((int)(v + PGOFSET) &~ PGOFSET);
+       valloc(buffers, char, MAXBSIZE * nbuf);
+       base = bufpages / nbuf;
+       residual = bufpages % nbuf;
+       mapaddr = firstaddr;
+       for (i = 0; i < residual; i++) {
+               for (j = 0; j < (base + 1) * CLSIZE; j++) {
+                       *(int *)(&Sysmap[mapaddr+j]) = PG_V | PG_KW | firstaddr;
+                       clearseg((unsigned)firstaddr);
+                       firstaddr++;
+               }
+               mapaddr += MAXBSIZE / NBPG;
+       }
+       for (i = residual; i < nbuf; i++) {
+               for (j = 0; j < base * CLSIZE; j++) {
+                       *(int *)(&Sysmap[mapaddr+j]) = PG_V | PG_KW | firstaddr;
+                       clearseg((unsigned)firstaddr);
+                       firstaddr++;
+               }
+               mapaddr += MAXBSIZE / NBPG;
+       }
+
+       unixsize = btoc((int)v &~ 0xc0000000);
        if (firstaddr >= physmem - 8*UPAGES)
                panic("no memory");
        if (firstaddr >= physmem - 8*UPAGES)
                panic("no memory");
-       mtpr(1,TBIA);
+       mtpr(TBIA, 1);                  /* After we just cleared it all! */
 
        /*
         * Initialize callouts
 
        /*
         * Initialize callouts
@@ -208,6 +227,7 @@ startup(firstaddr)
        rminit(mbmap, (long)((nmbclusters - 1) * CLSIZE), (long)CLSIZE,
            "mbclusters", nmbclusters/4);
        intenable = 1;          /* Enable interrupts from now on */
        rminit(mbmap, (long)((nmbclusters - 1) * CLSIZE), (long)CLSIZE,
            "mbclusters", nmbclusters/4);
        intenable = 1;          /* Enable interrupts from now on */
+
        /*
         * Configure the system.
         */
        /*
         * Configure the system.
         */
@@ -223,10 +243,12 @@ startup(firstaddr)
  * which has not been serviced due to high
  * ipl, return error code.
  */
  * which has not been serviced due to high
  * ipl, return error code.
  */
+/*ARGSUSED*/
 vmtime(otime, olbolt, oicr)
        register int otime, olbolt, oicr;
 {
 vmtime(otime, olbolt, oicr)
        register int otime, olbolt, oicr;
 {
-       return(((time.tv_sec-otime)*60 + lbolt-olbolt)*16667);
+
+       return (((time.tv_sec-otime)*60 + lbolt-olbolt)*16667);
 }
 #endif
 
 }
 #endif
 
@@ -234,64 +256,60 @@ vmtime(otime, olbolt, oicr)
  * Send an interrupt to process.
  *
  * Stack is set up to allow sigcode stored
  * Send an interrupt to process.
  *
  * Stack is set up to allow sigcode stored
- * in u. to call routine, followed by chmk
- * to sigcleanup routine below.  After sigcleanup
- * resets the signal mask and the stack, it
- * returns to user who then unwinds with the
- * rei at the bottom of sigcode.
+ * in u. to call routine, followed by kcall
+ * to sigreturn routine below.  After sigreturn
+ * resets the signal mask, the stack, and the
+ * frame pointer, it returns to the user
+ * specified pc, psl.
  */
 sendsig(p, sig, mask)
        int (*p)(), sig, mask;
 {
  */
 sendsig(p, sig, mask)
        int (*p)(), sig, mask;
 {
-       register struct sigcontext *scp;        /* know to be r12 */
+       register struct sigcontext *scp;
        register int *regs;
        register struct sigframe {
                int     sf_signum;
                int     sf_code;
                struct  sigcontext *sf_scp;
                int     (*sf_handler)();
        register int *regs;
        register struct sigframe {
                int     sf_signum;
                int     sf_code;
                struct  sigcontext *sf_scp;
                int     (*sf_handler)();
-               int     r1;
-               int     r0;
+               int     sf_regs[6];             /* r0-r5 */
                struct  sigcontext *sf_scpcopy;
                struct  sigcontext *sf_scpcopy;
-       } *fp;                                  /* known to be r10 */
+       } *fp;
        int oonstack;
 
        regs = u.u_ar0;
        oonstack = u.u_onstack;
        int oonstack;
 
        regs = u.u_ar0;
        oonstack = u.u_onstack;
-       scp = (struct sigcontext *)regs[SP] - 1;
+       /*
+        * Allocate and validate space for the signal handler
+        * context. Note that if the stack is in P0 space, the
+        * call to grow() is a nop, and the useracc() check
+        * will fail if the process has not already allocated
+        * the space with a `brk'.
+        */
        if (!u.u_onstack && (u.u_sigonstack & sigmask(sig))) {
        if (!u.u_onstack && (u.u_sigonstack & sigmask(sig))) {
-               fp = (struct sigframe *)u.u_sigsp - 1;
+               scp = (struct sigcontext *)u.u_sigsp - 1;
                u.u_onstack = 1;
        } else
                u.u_onstack = 1;
        } else
-               fp = (struct sigframe *)scp - 1;
-       /*
-        * Must build signal handler context on stack to be returned to
-        * so that rei instruction in sigcode will pop ps and pc
-        * off correct stack.  The remainder of the signal state
-        * used in calling the handler must be placed on the stack
-        * on which the handler is to operate so that the calls
-        * in sigcode will save the registers and such correctly.
-        */
-       if (!oonstack && (int)fp <= USRSTACK - ctob(u.u_ssize)) 
+               scp = (struct sigcontext *)regs[SP] - 1;
+       fp = (struct sigframe *)scp - 1;
+       if ((int)fp <= USRSTACK - ctob(u.u_ssize)) 
                grow((unsigned)fp);
                grow((unsigned)fp);
-       ;
-#ifndef lint
-       asm("probew $1,(r10),$7*4");
-       asm("jeql bad");
-#else
-       if (useracc((caddr_t)fp, sizeof (struct sigframe), 1))
-               goto bad;
-#endif
-       if (!u.u_onstack && (int)scp <= USRSTACK - ctob(u.u_ssize))
-               grow((unsigned)scp);
-       ;                       /* Avoid asm() label botch */
-#ifndef lint
-       asm("probew $1,(r12),$5*4");
-       asm("beql bad");
-#else
-       if (useracc((caddr_t)scp, sizeof (struct sigcontext), 1))
-               goto bad;
-#endif
+       if (useracc((caddr_t)fp, sizeof (*fp) + sizeof (*scp), 1) == 0) {
+               /*
+                * Process has trashed its stack; give it an illegal
+                * instruction to halt it in its tracks.
+                */
+               u.u_signal[SIGILL] = SIG_DFL;
+               sig = sigmask(SIGILL);
+               u.u_procp->p_sigignore &= ~sig;
+               u.u_procp->p_sigcatch &= ~sig;
+               u.u_procp->p_sigmask &= ~sig;
+               psignal(u.u_procp, SIGILL);
+               return;
+       }
+       /* 
+        * Build the argument list for the signal handler.
+        */
        fp->sf_signum = sig;
        if (sig == SIGILL || sig == SIGFPE) {
                fp->sf_code = u.u_code;
        fp->sf_signum = sig;
        if (sig == SIGILL || sig == SIGFPE) {
                fp->sf_code = u.u_code;
@@ -300,96 +318,106 @@ sendsig(p, sig, mask)
                fp->sf_code = 0;
        fp->sf_scp = scp;
        fp->sf_handler = p;
                fp->sf_code = 0;
        fp->sf_scp = scp;
        fp->sf_handler = p;
-       fp->r1 = regs[R1];      /* These are not saved by the C compiler */
-       fp->r0 = regs[R0];
        /*
        /*
-        * Duplicate the pointer to the sigcontext structure.
-        * This one doesn't get popped by the ret, and is used 
-        * by sigcleanup to reset the signal state on inward return.
+        * Build the callf argument frame to be used to call sigreturn.
         */
        fp->sf_scpcopy = scp;
         */
        fp->sf_scpcopy = scp;
-       /* sigcontext goes on previous stack */
+       /*
+        * Build the signal context to be used by sigreturn.
+        */
        scp->sc_onstack = oonstack;
        scp->sc_mask = mask;
        scp->sc_onstack = oonstack;
        scp->sc_mask = mask;
-       /* setup rei */
-       scp->sc_sp = (int)&scp->sc_pc;
+       scp->sc_sp = regs[SP];
+       scp->sc_fp = regs[FP];
        scp->sc_pc = regs[PC];
        scp->sc_ps = regs[PS];
        regs[SP] = (int)fp;
        regs[PC] = (int)u.u_pcb.pcb_sigc;
        scp->sc_pc = regs[PC];
        scp->sc_ps = regs[PS];
        regs[SP] = (int)fp;
        regs[PC] = (int)u.u_pcb.pcb_sigc;
-       return;
-
-asm("bad:");
-bad:
-       /*
-        * Process has trashed its stack; give it an illegal
-        * instruction to halt it in its tracks.
-        */
-       u.u_signal[SIGILL] = SIG_DFL;
-       sig = sigmask(SIGILL);
-       u.u_procp->p_sigignore &= ~sig;
-       u.u_procp->p_sigcatch &= ~sig;
-       u.u_procp->p_sigmask &= ~sig;
-       psignal(u.u_procp, SIGILL);
 }
 
 /*
 }
 
 /*
- * Routine to cleanup state after a signal
+ * System call to cleanup state after a signal
  * has been taken.  Reset signal mask and
  * stack state from context left by sendsig (above).
  * has been taken.  Reset signal mask and
  * stack state from context left by sendsig (above).
- * Pop these values in preparation for rei which
- * follows return from this routine.
+ * Return to previous pc and psl as specified by
+ * context left by sendsig. Check carefully to
+ * make sure that the user has not modified the
+ * psl to gain improper priviledges or to cause
+ * a machine fault.
  */
  */
-sigcleanup()
+sigreturn()
 {
 {
-       register struct sigcontext *scp;        /* known as R12 */
+       struct a {
+               struct sigcontext *sigcntxp;
+       };
+       register struct sigcontext *scp;
+       register int *regs = u.u_ar0;
+
+       scp = ((struct a *)(u.u_ap))->sigcntxp;
+       if (useracc((caddr_t)scp, sizeof (*scp), 0) == 0) {
+               u.u_error = EINVAL;
+               return;
+       }
+       if ((scp->sc_ps & (PSL_MBZ|PSL_IPL|PSL_IS)) != 0 ||
+           (scp->sc_ps & (PSL_PRVMOD|PSL_CURMOD)) != (PSL_PRVMOD|PSL_CURMOD)) {
+               u.u_error = EINVAL;
+               return;
+       }
+       u.u_eosys = JUSTRETURN;
+       u.u_onstack = scp->sc_onstack & 01;
+       u.u_procp->p_sigmask = scp->sc_mask &~
+           (sigmask(SIGKILL)|sigmask(SIGCONT)|sigmask(SIGSTOP));
+       regs[FP] = scp->sc_fp;
+       regs[SP] = scp->sc_sp;
+       regs[PC] = scp->sc_pc;
+       regs[PS] = scp->sc_ps;
+}
 
 
-       scp = (struct sigcontext *)fuword((caddr_t)u.u_ar0[SP]);
+/* XXX - BEGIN 4.2 COMPATIBILITY */
+/*
+ * Compatibility with 4.2 kcall $139 used by longjmp()
+ */
+osigcleanup()
+{
+       register struct sigcontext *scp;
+       register int *regs = u.u_ar0;
+
+       scp = (struct sigcontext *)fuword((caddr_t)regs[SP]);
        if ((int)scp == -1)
                return;
        if ((int)scp == -1)
                return;
-#ifndef lint
-       ;                       /* Avoid asm() label botch */
-       /* only probe 12 here because that's all we need */
-       asm("prober $1,(r12),$12");
-       asm("bnequ 1f; ret; 1:");
-#else
-       if (useracc((caddr_t)scp, sizeof (*scp), 0))
+       if (useracc((caddr_t)scp, 3 * sizeof (int), 0) == 0)
                return;
                return;
-#endif
        u.u_onstack = scp->sc_onstack & 01;
        u.u_onstack = scp->sc_onstack & 01;
-       u.u_procp->p_sigmask =
-          scp->sc_mask &~ (sigmask(SIGKILL)|sigmask(SIGCONT)|sigmask(SIGSTOP));
-       u.u_ar0[SP] = scp->sc_sp;
+       u.u_procp->p_sigmask = scp->sc_mask &~
+           (sigmask(SIGKILL)|sigmask(SIGCONT)|sigmask(SIGSTOP));
+       regs[SP] = scp->sc_sp;
 }
 }
+/* XXX - END 4.2 COMPATIBILITY */
 
 int    waittime = -1;
 
 boot(paniced, arghowto)
        int paniced, arghowto;
 {
 
 int    waittime = -1;
 
 boot(paniced, arghowto)
        int paniced, arghowto;
 {
-       register long dummy;
+       register long dummy;            /* r12 is reserved */
        register int howto;             /* r11 == how to boot */
        register int devtype;           /* r10 == major of root dev */
 
 #ifdef lint
        register int howto;             /* r11 == how to boot */
        register int devtype;           /* r10 == major of root dev */
 
 #ifdef lint
-       howto = 0; devtype = 0;
+       howto = 0; devtype = 0; dummy = 0; dummy = dummy;
        printf("howto %d, devtype %d\n", arghowto, devtype);
 #endif
        (void) spl1();
        howto = arghowto;
        printf("howto %d, devtype %d\n", arghowto, devtype);
 #endif
        (void) spl1();
        howto = arghowto;
-       if ((howto&RB_NOSYNC)==0 && waittime < 0 && bfreelist[0].b_forw) {
+       if ((howto&RB_NOSYNC) == 0 && waittime < 0 && bfreelist[0].b_forw) {
                waittime = 0;
                update();
                printf("syncing disks... ");
                waittime = 0;
                update();
                printf("syncing disks... ");
-#ifdef notdef
-               DELAY(10000000);
-#else
                { register struct buf *bp;
                  int iter, nbusy, oldnbusy;
 
                { register struct buf *bp;
                  int iter, nbusy, oldnbusy;
 
-                 printf ("\tBlocks to sync : ");
                  oldnbusy = 0;
                  oldnbusy = 0;
-                 for (iter = 0; /* iter < 20 */; iter++) {
+                 for (iter = 0; iter < 1000; iter++) {
                        DELAY(1000);
                        nbusy = 0;
                        for (bp = &buf[nbuf]; --bp >= buf; )
                        DELAY(1000);
                        nbusy = 0;
                        for (bp = &buf[nbuf]; --bp >= buf; )
@@ -401,21 +429,17 @@ boot(paniced, arghowto)
                                printf("%d ", nbusy);
                                oldnbusy = nbusy;
                        }
                                printf("%d ", nbusy);
                                oldnbusy = nbusy;
                        }
-                       if (iter >= 100) {
-                               printf (" - disk I/O stopped (?), giving up\n");
-                               DELAY(10000);
-                               break;
-                       }
                  }
                  }
+                 if (iter >= 1000 && nbusy)
+                       printf("- i/o timeout, giving up...");
                }
                }
-#endif
-               printf("done\n\n");
+               printf("done\n");
        }
        }
-       splx(0x1f);                     /* extreme priority */
+       mtpr(IPL, 0x1f);                        /* extreme priority */
        devtype = major(rootdev);
        if (howto&RB_HALT) {
                printf("halting (in tight loop); hit ~h\n\n");
        devtype = major(rootdev);
        if (howto&RB_HALT) {
                printf("halting (in tight loop); hit ~h\n\n");
-               mtpr(0x1f,IPL);
+               mtpr(IPL, 0x1f);
                for (;;)
                        ;
        } else {
                for (;;)
                        ;
        } else {
@@ -430,39 +454,34 @@ boot(paniced, arghowto)
        /*NOTREACHED*/
 }
 
        /*NOTREACHED*/
 }
 
-
+struct cphdr *lasthdr;         /* defined in cons.c */
+struct cpdcb_o cpcontrol;
 
 /*
  * Send the given comand ('c') to the console processor.
  * Assumed to be one of the last things the OS does before
  *  halting or rebooting.
  */
 
 /*
  * Send the given comand ('c') to the console processor.
  * Assumed to be one of the last things the OS does before
  *  halting or rebooting.
  */
-
-struct cphdr *lasthdr; /* Available in "dev/cons.c" */
-
-struct cpdcb_o cpcontrol;
-
-tocons(command)
-int command;
+tocons(c)
 {
 {
-
        int timeout;
 
        cpcontrol.cp_hdr.cp_unit = CPUNIT;
        int timeout;
 
        cpcontrol.cp_hdr.cp_unit = CPUNIT;
-       cpcontrol.cp_hdr.cp_comm =  (char) command;
-       if (command != CPBOOT) 
+       cpcontrol.cp_hdr.cp_comm =  (char)c;
+       if (c != CPBOOT) 
                cpcontrol.cp_hdr.cp_count = 1;  /* Just for sanity */
        else {
                cpcontrol.cp_hdr.cp_count = 4;
                *(int *)cpcontrol.cp_buf = 0;   /* r11 value for reboot */
        }
        timeout = 100000;                               /* Delay loop */
                cpcontrol.cp_hdr.cp_count = 1;  /* Just for sanity */
        else {
                cpcontrol.cp_hdr.cp_count = 4;
                *(int *)cpcontrol.cp_buf = 0;   /* r11 value for reboot */
        }
        timeout = 100000;                               /* Delay loop */
-       while (timeout-- && !(lasthdr->cp_unit & CPDONE))
+       while (timeout-- && (lasthdr->cp_unit&CPDONE) == 0)
                uncache(&lasthdr->cp_unit);
                uncache(&lasthdr->cp_unit);
-                                       /* Give up, force it to listen */
-       mtpr ( vtoph(0, &cpcontrol), CPMDCB);
+       /* give up, force it to listen */
+       mtpr(CPMDCB, vtoph((struct proc *)0, (unsigned)&cpcontrol));
 }
 
 }
 
+#if CLSIZE != 1
 /*
  * Invalidate single all pte's in a cluster
  */
 /*
  * Invalidate single all pte's in a cluster
  */
@@ -474,10 +493,11 @@ tbiscl(v)
 
        addr = ptob(v);
        for (i = 0; i < CLSIZE; i++) {
 
        addr = ptob(v);
        for (i = 0; i < CLSIZE; i++) {
-               mtpr(addr, TBIS);
+               mtpr(TBIS, addr);
                addr += NBPG;
        }
 }
                addr += NBPG;
        }
 }
+#endif
 
 int    dumpmag = 0x8fca0101;   /* magic number for savecore */
 int    dumpsize = 0;           /* also for savecore */
 
 int    dumpmag = 0x8fca0101;   /* magic number for savecore */
 int    dumpsize = 0;           /* also for savecore */
@@ -518,16 +538,15 @@ dumpsys()
                printf("succeeded\n");
                break;
        }
                printf("succeeded\n");
                break;
        }
-       printf("Rebooting the system ...\n\n");
+       printf("\n\n");
+       DELAY(1000);
        tocons(CPBOOT);
 }
 
        tocons(CPBOOT);
 }
 
-
 /*
  * Bus error 'recovery' code.
  * Print out the buss frame and then give up.
  * (More information from special registers can be printed here.)
 /*
  * Bus error 'recovery' code.
  * Print out the buss frame and then give up.
  * (More information from special registers can be printed here.)
- * 
  */
 
 /*
  */
 
 /*
@@ -540,50 +559,40 @@ struct buserframe {
        int     trp_psl;                /* trapped psl */
 };
 
        int     trp_psl;                /* trapped psl */
 };
 
-buserror(busef)
-       caddr_t busef;
-{
-       register struct buserframe *frameptr;
-       register long   hardreg;
-
+char   *mem_errcd[8] = {
+       "Unknown error code 0",
+       "Address parity error",         /* APE */
+       "Data parity error",            /* DPE */
+       "Data check error",             /* DCE */
+       "Versabus timeout",             /* VTO */
+       "Versabus error",               /* VBE */
+       "Non-existent memory",          /* NEM */
+       "Unknown error code 7",
+};
 
 
-       frameptr = (struct buserframe *)busef;
-       printf("bus error at address %x, psl = %x\n",
-               frameptr->trp_pc,frameptr->trp_psl);
-       hardreg =  frameptr->memerreg;
-       printf("\tMEAR = %x\n",((hardreg&MEAR)>>16)&0xffff);
-       switch (hardreg & ERRCD){
-               case (APE):     printf("\tAdress parity error.Should not reach this point!! \n");
-                               break;
-               case (DPE):     printf("\tData parity error.\n");
-                               break;
-               case (DCE):     printf("\tData check error.\n");
-                               break;
-               case (VTO):     printf("\tVersabus timeout.\n");
-                               break;
-               case (VBE):     printf("\tVersabus error.Should not reach this point!! \n");
-                               break;
-               case (NEM):     printf("\tNon existent memory.\n");
-                               break;
-               default:        printf("\tUnknown error code: %x\n",
-                                       hardreg&ERRCD);
-       }
-       if (hardreg&AXE) printf("\tAdapter external error\n");
-       printf ("\tError master : ");
-       if (hardreg&ERM) printf("Versabus\n");
-       else printf ("Tahoe\n");
-       if (hardreg&IVV)
-               printf("\tIllegal interrupt vector, from ipl %d\n",
-                   (hardreg >> 2) & 7);
-
-       hardreg = frameptr->which_bus;
-       printf("\tMCBR = %x\n", ((hardreg&MCBR)>>16)&0xffff);
-       printf("\tVersabus type : %x\n", hardreg&0xffc3);
-       if (frameptr->memerreg&IVV) return;
-       panic("buserror");
+buserror(v)
+       caddr_t v;
+{
+       register struct buserframe *busef = (struct buserframe *)v;
+       register long reg;
+
+       printf("bus error, address %x, psl %x\n",
+           busef->trp_pc, busef->trp_psl);
+       reg =  busef->memerreg;
+       printf("mear %x %s\n",
+           ((reg&MEAR)>>16)&0xffff, mem_errcd[reg & ERRCD]);
+       if (reg&AXE)
+               printf("adapter external error\n");
+       printf("error master: %s\n", reg&ERM ? "versabus" : "tahoe");
+       if (reg&IVV)
+               printf("illegal interrupt vector from ipl %d\n", (reg>>2)&7);
+       reg = busef->which_bus;
+       printf("mcbr %x versabus type %x\n",
+           ((reg&MCBR)>>16)&0xffff, reg & 0xffc3);
+       if ((busef->memerreg&IVV) == 0)
+               panic("buserror");
 }
 
 }
 
-
 physstrat(bp, strat, prio)
        struct buf *bp;
        int (*strat)(), prio;
 physstrat(bp, strat, prio)
        struct buf *bp;
        int (*strat)(), prio;
@@ -600,20 +609,18 @@ physstrat(bp, strat, prio)
        splx(s);
 }
 
        splx(s);
 }
 
-
-/*ARGSUSED*/
-mtpr (value, regno)
+/*
+ * Clear registers on exec
+ */
+setregs(entry)
+       u_long entry;
 {
 {
-       asm("mtpr 4(fp), 8(fp)");
-}
 
 
-/*ARGSUSED*/
-int
-mfpr (regno)
-{
-       asm("mfpr 4(fp),r0");
-#ifdef lint
-       return(0);
+#ifdef notdef
+       /* should pass args to init on the stack */
+       for (rp = &u.u_ar0[0]; rp < &u.u_ar0[16];)
+               *rp++ = 0;
 #endif
 #endif
+       u.u_ar0[FP] = 0;        /* bottom of the fp chain */
+       u.u_ar0[PC] = entry + 2;
 }
 }
-
index 23c93f7..74a177c 100644 (file)
@@ -1,4 +1,4 @@
-/*     mem.c   1.1     85/07/21        */
+/*     mem.c   1.2     86/01/05        */
 
 /*
  * Memory special file
 
 /*
  * Memory special file
@@ -16,7 +16,7 @@
 #include "../h/cmap.h"
 #include "../h/uio.h"
 
 #include "../h/cmap.h"
 #include "../h/uio.h"
 
-#include "../machine/mtpr.h"
+#include "../tahoe/mtpr.h"
 
 mmread(dev, uio)
        dev_t dev;
 
 mmread(dev, uio)
        dev_t dev;
@@ -64,7 +64,7 @@ mmrw(dev, uio, rw)
                                goto fault;
                        *(int *)mmap = v | PG_V |
                                (rw == UIO_READ ? PG_KR : PG_KW);
                                goto fault;
                        *(int *)mmap = v | PG_V |
                                (rw == UIO_READ ? PG_KR : PG_KW);
-                       mtpr(vmmap, TBIS);
+                       mtpr(TBIS, vmmap);
                        o = (int)uio->uio_offset & PGOFSET;
                        c = min((u_int)(NBPG - o), (u_int)iov->iov_len);
                        c = min(c, (u_int)(NBPG - ((int)iov->iov_base&PGOFSET)));
                        o = (int)uio->uio_offset & PGOFSET;
                        c = min((u_int)(NBPG - o), (u_int)iov->iov_len);
                        c = min(c, (u_int)(NBPG - ((int)iov->iov_base&PGOFSET)));
index 893090c..c45f8cd 100644 (file)
@@ -1,17 +1,17 @@
-/*     swapgeneric.c   1.1     85/07/21        */
+/*     swapgeneric.c   1.2     86/01/05        */
 
 #include "../machine/pte.h"
 
 
 #include "../machine/pte.h"
 
-#include "../h/param.h"
-#include "../h/conf.h"
-#include "../h/buf.h"
-#include "../h/vm.h"
-#include "../h/systm.h"
-#include "../h/reboot.h"
+#include "param.h"
+#include "conf.h"
+#include "buf.h"
+#include "vm.h"
+#include "systm.h"
+#include "reboot.h"
 
 
-#include "../machine/cp.h"
-#include "../machine/mtpr.h"
-#include "../vba/vbavar.h"
+#include "../tahoe/cp.h"
+#include "../tahoe/mtpr.h"
+#include "../tahoevba/vbavar.h"
 
 /*
  * Generic configuration;  all in one
 
 /*
  * Generic configuration;  all in one
@@ -35,6 +35,7 @@ struct        genericconf {
        { (caddr_t)&vddriver,   "fsd",  makedev(1, 0),  },
        { (caddr_t)&vddriver,   "smd",  makedev(1, 0),  },
        { (caddr_t)&vddriver,   "xfd",  makedev(1, 0),  },
        { (caddr_t)&vddriver,   "fsd",  makedev(1, 0),  },
        { (caddr_t)&vddriver,   "smd",  makedev(1, 0),  },
        { (caddr_t)&vddriver,   "xfd",  makedev(1, 0),  },
+       { (caddr_t)&vddriver,   "xsd",  makedev(1, 0),  },
        { 0 },
 };
 
        { 0 },
 };
 
@@ -66,7 +67,7 @@ gotit:
                }
                printf("bad/missing unit number\n");
 bad:
                }
                printf("bad/missing unit number\n");
 bad:
-               printf("use fsd%%d, smd%%d, or xfd%%d\n");
+               printf("use fsd%%d, smd%%d, xfd%%d, or xsd%%d\n");
                goto retry;
        }
        unit = 0;
                goto retry;
        }
        unit = 0;
@@ -96,23 +97,23 @@ found:
 
 getchar()
 {
 
 getchar()
 {
-       char    c;
+       char c;
        int timo;
        int timo;
-       extern struct   cpdcb_i consin[];
-       extern struct   cphdr *lasthdr;
+       extern struct cpdcb_i consin[];
+       extern struct cphdr *lasthdr;
 #define cpin consin[CPCONS]
 
        timo = 10000;
        uncache((char *)&lasthdr->cp_unit);
 #define cpin consin[CPCONS]
 
        timo = 10000;
        uncache((char *)&lasthdr->cp_unit);
-       while ((lasthdr->cp_unit & CPTAKE)==0 && --timo )
-               uncache((char *)&lasthdr->cp_unit);
+       while ((lasthdr->cp_unit&CPTAKE) == 0 && --timo)
+               uncache(&lasthdr->cp_unit);
        cpin.cp_hdr.cp_unit = CPCONS;   /* Resets done bit */
        cpin.cp_hdr.cp_comm = CPREAD;
        cpin.cp_hdr.cp_count = 1;
        cpin.cp_hdr.cp_unit = CPCONS;   /* Resets done bit */
        cpin.cp_hdr.cp_comm = CPREAD;
        cpin.cp_hdr.cp_count = 1;
-       mtpr(&cpin, CPMDCB);
+       mtpr(CPMDCB, &cpin);
        while ((cpin.cp_hdr.cp_unit & CPDONE) == 0) 
        while ((cpin.cp_hdr.cp_unit & CPDONE) == 0) 
-               uncache (&cpin.cp_hdr.cp_unit);
-       uncache (&cpin.cpi_buf[0]);
+               uncache(&cpin.cp_hdr.cp_unit);
+       uncache(&cpin.cpi_buf[0]);
        c = cpin.cpi_buf[0] & 0x7f;
        lasthdr = (struct cphdr *)&cpin;
        if (c == '\r')
        c = cpin.cpi_buf[0] & 0x7f;
        lasthdr = (struct cphdr *)&cpin;
        if (c == '\r')
index 0e6bb24..3f75f98 100644 (file)
@@ -1,50 +1,67 @@
-/*     trap.c  4.10    84/02/09        */
-
-#include "../machine/psl.h"
-#include "../machine/reg.h"
-#include "../machine/pte.h"
-
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/dir.h"
-#include "../h/user.h"
-#include "../h/proc.h"
-#include "../h/seg.h"
-#include "../machine/trap.h"
-#include "../h/acct.h"
-#include "../h/kernel.h"
-#include "../machine/mtpr.h"
+/*     trap.c  1.2     86/01/05        */
+
+#include "../tahoe/psl.h"
+#include "../tahoe/reg.h"
+#include "../tahoe/pte.h"
+#include "../tahoe/mtpr.h"
+
+#include "param.h"
+#include "systm.h"
+#include "dir.h"
+#include "user.h"
+#include "proc.h"
+#include "seg.h"
+#include "acct.h"
+#include "kernel.h"
+#define        SYSCALLTRACE
 #ifdef SYSCALLTRACE
 #include "../sys/syscalls.c"
 #endif
 #ifdef SYSCALLTRACE
 #include "../sys/syscalls.c"
 #endif
-#include "../machine/fp_in_krnl.h"
+
+#include "../tahoe/trap.h"
 
 #define        USER    040             /* user-mode flag added to type */
 
 
 #define        USER    040             /* user-mode flag added to type */
 
-struct sysent  sysent[];
-int nsysent;
+struct sysent sysent[];
+int    nsysent;
+
+char   *trap_type[] = {
+       "Reserved addressing mode",             /* T_RESADFLT */
+       "Privileged instruction",               /* T_PRIVINFLT */
+       "Reserved operand",                     /* T_RESOPFLT */
+       "Breakpoint",                           /* T_BPTFLT */
+       0,
+       "Kernel call",                          /* T_SYSCALL */
+       "Arithmetic trap",                      /* T_ARITHTRAP */
+       "System forced exception",              /* T_ASTFLT */
+       "Segmentation fault",                   /* T_SEGFLT */
+       "Protection fault",                     /* T_PROTFLT */
+       "Trace trap",                           /* T_TRCTRAP */
+       0,
+       "Page fault",                           /* T_PAGEFLT */
+       "Page table fault",                     /* T_TABLEFLT */
+       "Alignment fault",                      /* T_ALIGNFLT */
+       "Kernel stack not valid",               /* T_KSPNOTVAL */
+       "Bus error",                            /* T_BUSERR */
+};
+#define        TRAP_TYPES      (sizeof (trap_type) / sizeof (trap_type[0]))
 
 /*
  * Called from the trap handler when a processor trap occurs.
  */
 
 /*
  * Called from the trap handler when a processor trap occurs.
  */
+/*ARGSUSED*/
 trap(sp, type, hfs, accmst, acclst, dbl, code, pc, psl)
 trap(sp, type, hfs, accmst, acclst, dbl, code, pc, psl)
-unsigned code;
+       unsigned type, code;
 {
 {
-       /* Next 2 dummy variables MUST BE the first local */
-       /* variables; leaving place for registers 0 and 1 */
-       /* which are not preserved by the 'cct' */
-
-       int     dumm1;          /* register 1 */
-       int     dumm0;          /* register 0 */
-       register dumm3;         /* register 12 is the 1'st register variable */
-                               /* in TAHOE  (register 11 in VAX) */
-
+       int r0, r1;             /* must reserve space */
        register int *locr0 = ((int *)&psl)-PS;
        register int i;
        register struct proc *p;
        struct timeval syst;
        register int *locr0 = ((int *)&psl)-PS;
        register int i;
        register struct proc *p;
        struct timeval syst;
-       char    *typename;
 
 
+#ifdef lint
+       r0 = 0; r0 = r0; r1 = 0; r1 = r1;
+#endif
        syst = u.u_ru.ru_stime;
        if (USERMODE(locr0[PS])) {
                type |= USER;
        syst = u.u_ru.ru_stime;
        if (USERMODE(locr0[PS])) {
                type |= USER;
@@ -52,53 +69,28 @@ unsigned code;
        }
        switch (type) {
 
        }
        switch (type) {
 
-       default: switch (type) {
-               case T_RESADFLT:
-                       typename = "reserved addressing mode";break;
-               case T_PRIVINFLT:
-                       typename = "illegal opcode";break;
-               case T_RESOPFLT:
-                       typename = "reserved operand";break;
-               case T_BPTFLT:
-                       typename = "breakpoint";break;
-               case T_SYSCALL:
-                       typename = "kernel call";break;
-               case T_ARITHTRAP:
-                       typename = "arithmetic exception";break;
-               case T_ASTFLT:
-                       typename = "system forced exception";break;
-               case T_SEGFLT:
-                       typename = "limit fault";break;
-               case T_PROTFLT:
-                       typename = "illegal access type";break;
-               case T_TRCTRAP:
-                       typename = "trace trap";break;
-               case T_PAGEFLT:
-                       typename = "page fault";break;
-               case T_TABLEFLT:
-                       typename = "page table fault";break;
-               case T_ALIGNFLT:
-                       typename = "alignment fault";break;
-               case T_KSPNOTVAL:
-                       typename = "kernel stack not valid";break;
-               }
-               printf("System trap (%s), code = %x, pc = %x\n", 
-                               typename, code, pc);
-               panic("trap");
+       default:
+               printf("trap type %d, code = %x, pc = %x\n", type, code, pc);
+               type &= ~USER;
+               if (type < TRAP_TYPES && trap_type[type])
+                       panic(trap_type[type]);
+               else
+                       panic("trap");
+               /*NOTREACHED*/
 
 
-       case T_PROTFLT + USER:  /* protection fault */
+       case T_PROTFLT + USER:          /* protection fault */
                i = SIGBUS;
                break;
 
        case T_PRIVINFLT + USER:        /* privileged instruction fault */
                i = SIGBUS;
                break;
 
        case T_PRIVINFLT + USER:        /* privileged instruction fault */
-       case T_RESADFLT + USER: /* reserved addressing fault */
-       case T_RESOPFLT + USER: /* resereved operand fault */
-       case T_ALIGNFLT + USER: /* unaligned data fault */
+       case T_RESADFLT + USER:         /* reserved addressing fault */
+       case T_RESOPFLT + USER:         /* resereved operand fault */
+       case T_ALIGNFLT + USER:         /* unaligned data fault */
                u.u_code = type &~ USER;
                i = SIGILL;
                break;
 
                u.u_code = type &~ USER;
                i = SIGILL;
                break;
 
-       case T_ASTFLT + USER:   /* Allow process switch */
+       case T_ASTFLT + USER:           /* Allow process switch */
        case T_ASTFLT:
                astoff();
                if ((u.u_procp->p_flag & SOWEUPC) && u.u_prof.pr_scale) {
        case T_ASTFLT:
                astoff();
                if ((u.u_procp->p_flag & SOWEUPC) && u.u_prof.pr_scale) {
@@ -122,25 +114,25 @@ unsigned code;
                i = SIGSEGV;
                break;
 
                i = SIGSEGV;
                break;
 
-       case T_TABLEFLT:                /* allow page table faults in kernel mode */
-       case T_TABLEFLT + USER:   /* page table fault */
+       case T_TABLEFLT:                /* allow page table faults in kernel */
+       case T_TABLEFLT + USER:         /* page table fault */
                panic("ptable fault");
 
                panic("ptable fault");
 
-       case T_PAGEFLT:         /* allow page faults in kernel mode */
-       case T_PAGEFLT + USER:  /* page fault */
+       case T_PAGEFLT:                 /* allow page faults in kernel mode */
+       case T_PAGEFLT + USER:          /* page fault */
                i = u.u_error;
                i = u.u_error;
-               if(fastreclaim(code) == 0)
-                       pagein(code, 0);
+               pagein(code, 0);
                u.u_error = i;
                if (type == T_PAGEFLT)
                        return;
                goto out;
 
                u.u_error = i;
                if (type == T_PAGEFLT)
                        return;
                goto out;
 
-       case T_BPTFLT + USER:   /* bpt instruction fault */
-       case T_TRCTRAP + USER:  /* trace trap */
+       case T_BPTFLT + USER:           /* bpt instruction fault */
+       case T_TRCTRAP + USER:          /* trace trap */
                locr0[PS] &= ~PSL_T;
                i = SIGTRAP;
                break;
                locr0[PS] &= ~PSL_T;
                i = SIGTRAP;
                break;
+
        case T_KSPNOTVAL:
        case T_KSPNOTVAL + USER:
                i = SIGKILL;    /* There is nothing to do but to kill the 
        case T_KSPNOTVAL:
        case T_KSPNOTVAL + USER:
                i = SIGKILL;    /* There is nothing to do but to kill the 
@@ -148,6 +140,10 @@ unsigned code;
                printf("KSP NOT VALID.\n");
                break;
 
                printf("KSP NOT VALID.\n");
                break;
 
+       case T_BUSERR + USER:
+               i = SIGBUS;
+               u.u_code = code;
+               break;
        }
        psignal(u.u_procp, i);
 out:
        }
        psignal(u.u_procp, i);
 out:
@@ -182,77 +178,72 @@ out:
 }
 
 #ifdef SYSCALLTRACE
 }
 
 #ifdef SYSCALLTRACE
-int syscalltrace = 0;
+int    syscalltrace = 0;
 #endif
 
 /*
 #endif
 
 /*
- * Called from the trap handler when a system call occurs
+ * Called from locore when a system call occurs
  */
  */
+/*ARGSUSED*/
 syscall(sp, type, hfs, accmst, acclst, dbl, code, pc, psl)
 syscall(sp, type, hfs, accmst, acclst, dbl, code, pc, psl)
-unsigned code;
+       unsigned code;
 {
 {
-       /* Next 2 dummy variables MUST BE the first local */
-       /* variables; leaving place for registers 0 and 1 */
-       /* which are not preserved by the 'cct' */
-
-       int     dumm1;          /* register 1 */
-       int     dumm0;          /* register 0 */
-       register dumm3;         /* register 12 is the 1'st register variable */
-                               /* in TAHOE  (register 11 in VAX) */
-
+       int r0, r1;                     /* must reserve space */
        register int *locr0 = ((int *)&psl)-PS;
        register int *locr0 = ((int *)&psl)-PS;
-       register caddr_t params;                /* known to be r10 below */
-       register int i;                         /* known to be r9 below */
+       register caddr_t params;
+       register int i;
        register struct sysent *callp;
        register struct proc *p;
        register struct sysent *callp;
        register struct proc *p;
-       struct  timeval syst;
+       struct timeval syst;
        int opc;
 
        int opc;
 
+#ifdef lint
+       r0 = 0; r0 = r0; r1 = 0; r1 = r1;
+#endif
        syst = u.u_ru.ru_stime;
        if (!USERMODE(locr0[PS]))
                panic("syscall");
        u.u_ar0 = locr0;
        syst = u.u_ru.ru_stime;
        if (!USERMODE(locr0[PS]))
                panic("syscall");
        u.u_ar0 = locr0;
-       if (code == 139) {                      /* XXX */
-               sigcleanup();                   /* XXX */
-               goto done;                      /* XXX */
+       if (code == 139) {                      /* 4.2 COMPATIBILTY XXX */
+               osigcleanup();                  /* 4.2 COMPATIBILTY XXX */
+               goto done;                      /* 4.2 COMPATIBILTY XXX */
        }
        params = (caddr_t)locr0[FP] + NBPW;
        u.u_error = 0;
        }
        params = (caddr_t)locr0[FP] + NBPW;
        u.u_error = 0;
-       /*------ DIRTY CODE !!!!!!!!!---------*/
-       /* try to reconstruct pc, assuming code is an immediate constant */
+/* BEGIN GROT */
+       /*
+        * Try to reconstruct pc, assuming code
+        * is an immediate constant
+        */
        opc = pc - 2;           /* short literal */
        if (code > 0x3f) {
        opc = pc - 2;           /* short literal */
        if (code > 0x3f) {
-               opc--;  /* byte immediate */
+               opc--;                          /* byte immediate */
                if (code > 0x7f) {
                if (code > 0x7f) {
-                       opc--;  /* word immediate */
+                       opc--;                  /* word immediate */
                        if (code > 0x7fff)
                                opc -= 2;       /* long immediate */
                }
        }
                        if (code > 0x7fff)
                                opc -= 2;       /* long immediate */
                }
        }
-       /*------------------------------------*/
+/* END GROT */
        callp = (code >= nsysent) ? &sysent[63] : &sysent[code];
        if (callp == sysent) {
                i = fuword(params);
                params += NBPW;
        callp = (code >= nsysent) ? &sysent[63] : &sysent[code];
        if (callp == sysent) {
                i = fuword(params);
                params += NBPW;
-       callp = (code >= nsysent) ? &sysent[63] : &sysent[code];
+               callp = (code >= nsysent) ? &sysent[63] : &sysent[code];
        }
        }
-       if (i = callp->sy_narg * sizeof (int)) {
-               asm("prober $1,(r10),r9");              /* GROT */
-               asm("bnequ ok");                        /* GROT */
-               u.u_error = EFAULT;                     /* GROT */
-               goto bad;                               /* GROT */
-asm("ok:");                                            /* GROT */
-               bcopy(params,u.u_arg,i);
+       if ((i = callp->sy_narg * sizeof (int)) &&
+           (u.u_error = copyin(params, (caddr_t)u.u_arg, (u_int)i)) != 0) {
+               locr0[R0] = u.u_error;
+               locr0[PS] |= PSL_C;     /* carry bit */
+               goto done;
        }
        }
-       u.u_ap = u.u_arg;
-       u.u_dirp = (caddr_t)u.u_arg[0];
        u.u_r.r_val1 = 0;
        u.u_r.r_val1 = 0;
-       u.u_r.r_val2 = locr0[R1]; /*------------ CHECK again */
+       u.u_r.r_val2 = locr0[R1];
        if (setjmp(&u.u_qsave)) {
        if (setjmp(&u.u_qsave)) {
-               if (u.u_error == 0 && u.u_eosys == JUSTRETURN)
+               if (u.u_error == 0 && u.u_eosys != RESTARTSYS)
                        u.u_error = EINTR;
        } else {
                        u.u_error = EINTR;
        } else {
-               u.u_eosys = JUSTRETURN;
+               u.u_eosys = NORMALRETURN;
 #ifdef SYSCALLTRACE
                if (syscalltrace) {
                        register int i;
 #ifdef SYSCALLTRACE
                if (syscalltrace) {
                        register int i;
@@ -272,20 +263,21 @@ asm("ok:");                                               /* GROT */
                        putchar('\n', 0);
                }
 #endif
                        putchar('\n', 0);
                }
 #endif
-
-               (*(callp->sy_call))();
+               (*callp->sy_call)();
        }
        }
-       if (u.u_eosys == RESTARTSYS)
+       if (u.u_eosys == NORMALRETURN) {
+               if (u.u_error) {
+                       locr0[R0] = u.u_error;
+                       locr0[PS] |= PSL_C;     /* carry bit */
+               } else {
+                       locr0[PS] &= ~PSL_C;    /* clear carry bit */
+                       locr0[R0] = u.u_r.r_val1;
+                       locr0[R1] = u.u_r.r_val2;
+               }
+       } else if (u.u_eosys == RESTARTSYS)
                pc = opc;
                pc = opc;
-       else if (u.u_error) {
-bad:
-               locr0[R0] = u.u_error;
-               locr0[PS] |= PSL_C;     /* carry bit */
-       } else {
-               locr0[PS] &= ~PSL_C;    /* clear carry bit */
-               locr0[R0] = u.u_r.r_val1;
-               locr0[R1] = u.u_r.r_val2;
-       }
+       /* else if (u.u_eosys == JUSTRETURN) */
+               /* nothing to do */
 done:
        p = u.u_procp;
        if (p->p_cursig || ISSIG(p))
 done:
        p = u.u_procp;
        if (p->p_cursig || ISSIG(p))
@@ -324,11 +316,13 @@ done:
  */
 nosys()
 {
  */
 nosys()
 {
+
        if (u.u_signal[SIGSYS] == SIG_IGN || u.u_signal[SIGSYS] == SIG_HOLD)
                u.u_error = EINVAL;
        psignal(u.u_procp, SIGSYS);
 }
 
        if (u.u_signal[SIGSYS] == SIG_IGN || u.u_signal[SIGSYS] == SIG_HOLD)
                u.u_error = EINVAL;
        psignal(u.u_procp, SIGSYS);
 }
 
+#ifdef notdef
 /*
  * Ignored system call
  */
 /*
  * Ignored system call
  */
@@ -336,140 +330,4 @@ nullsys()
 {
 
 }
 {
 
 }
-
-fpemulate(hfsreg,acc_most,acc_least,dbl,op_most,op_least,opcode,pc,psl)
-{
-/*
- * Emulate the F.P. 'opcode'. Update psl flags as necessary.
- * If all OK, set 'opcode' to 0, else to the F.P. exception #.
- * Not all parameter longwords are relevant - depends on opcode.
- *
- * The entry mask is set so ALL registers are saved - courtesy of
- *  locore.s. This enables F.P. opcodes to change 'user' registers
- *  before return.
- */
-
- /* WARNING!!!! THIS CODE MUST NOT PRODUCE ANY FLOATING POINT EXCEPTIONS. */
-
-       /* Next 2 dummy variables MUST BE the first local */
-       /* variables; leaving place for registers 0 and 1 */
-       /* which are not preserved by the 'cct' */
-
-       int     dumm1;          /* register 1 */
-       int     dumm0;          /* register 0 */
-       register dumm3;         /* register 12 is the 1'st register variable */
-                               /* in TAHOE  (register 11 in VAX) */
-
-       register int *locr0 = ((int *)&psl)-PS; /* R11 */
-       int hfs = 0;                    /* returned data about exceptions */
-       float (*f_proc)();              /* fp procedure to be called.   */
-       double (*d_proc)();             /* fp procedure to be called.   */
-       int dest_type;                  /* float or double.     */
-       union{
-               float ff;                       /* float result.        */
-               int fi;
-       }f_res;
-       union{
-               double  dd;                     /* double result.       */
-               int     di[2] ;
-       }d_res;
-       extern float    Kcvtlf(), Kaddf(), Ksubf(), Kmulf(), Kdivf();
-       extern double   Kcvtld(), Kaddd(), Ksubd(), Kmuld(), Kdivd();
-       extern float    Ksinf(), Kcosf(), Katanf(), Klogf(), Ksqrtf(), Kexpf();
-       
-       
-
-       switch(opcode & 0x0FF){
-
-       case CVLF:      f_proc = Kcvtlf; dest_type = FLOAT; 
-                       locr0[PS] &= ~PSL_DBL;break;    /* clear double bit */
-       case CVLD:      d_proc = Kcvtld; dest_type = DOUBLE; 
-                       locr0[PS] |= PSL_DBL; break;    /* turn on double bit */
-       case ADDF:      f_proc = Kaddf; dest_type = FLOAT;
-                       break;
-       case ADDD:      d_proc = Kaddd; dest_type = DOUBLE;
-                       break;
-       case SUBF:      f_proc = Ksubf; dest_type = FLOAT;
-                       break;
-       case SUBD:      d_proc = Ksubd; dest_type = DOUBLE;
-                       break;
-       case MULF:      f_proc = Kmulf; dest_type = FLOAT;
-                       break;
-       case MULD:      d_proc = Kmuld; dest_type = DOUBLE;
-                       break;
-       case DIVF:      f_proc = Kdivf; dest_type = FLOAT;
-                       break;
-       case DIVD:      d_proc = Kdivd; dest_type = DOUBLE;
-                       break;
-       case SINF:      f_proc = Ksinf; dest_type = FLOAT;
-                       break;
-       case COSF:      f_proc = Kcosf; dest_type = FLOAT;
-                       break;
-       case ATANF:     f_proc = Katanf; dest_type = FLOAT;
-                       break;
-       case LOGF:      f_proc = Klogf; dest_type = FLOAT;
-                       break;
-       case SQRTF:     f_proc = Ksqrtf; dest_type = FLOAT;
-                       break;
-       case EXPF:      f_proc = Kexpf; dest_type = FLOAT;
-                       break;
-       }
-
-       switch(dest_type){
-
-       case FLOAT: 
-               f_res.ff = (*f_proc)(acc_most,acc_least,op_most,op_least,&hfs);
-
-               if (f_res.fi == 0 ) locr0[PS] |= PSL_Z;
-               if (f_res.fi < 0 ) locr0[PS] |= PSL_N;
-               break;
-       case DOUBLE:
-               d_res.dd = (*d_proc)(acc_most,acc_least,op_most,op_least,&hfs);
-               if ((d_res.di[0] == 0) && (d_res.di[1] == 0))
-                                               locr0[PS] |= PSL_Z;
-               if (d_res.di[0] < 0 ) locr0[PS] |= PSL_N;
-               break;
-       }
-
-       if (hfs & HFS_OVF){
-               locr0[PS] |= PSL_V;     /* turn on overflow bit */
-               /* if (locr0[PS] & PSL_IV)   {  /* overflow elabled?    */
-                       opcode = OVF_EXC;
-                       u.u_error = (hfs & HFS_DOM) ? EDOM : ERANGE;
-                       return;
-               /*}*/
-       }
-       else if (hfs & HFS_UNDF){
-               if (locr0[PS] & PSL_FU){  /* underflow elabled? */
-                       opcode = UNDF_EXC;
-                       u.u_error = (hfs & HFS_DOM) ? EDOM : ERANGE;
-                       return;
-               } 
-       }
-       else if (hfs & HFS_DIVZ){
-               opcode = DIV0_EXC;
-               return;
-       }
-       else if (hfs & HFS_DOM)
-               u.u_error = EDOM;
-       else if (hfs & HFS_RANGE)
-               u.u_error = ERANGE;
-
-       switch(dest_type){
-       case FLOAT:
-               if ((hfs & HFS_OVF) || (hfs & HFS_UNDF)) {
-                       f_res.ff = 0.0;
-                       locr0[PS] |= PSL_Z;
-               }
-               mvtofacc(f_res.ff, &acc_most);
-               break;
-       case DOUBLE:
-               if ((hfs & HFS_OVF) || (hfs & HFS_UNDF)) {
-                       d_res.dd = 0.0;
-                       locr0[PS] |= PSL_Z;
-               }
-               mvtodacc(d_res.di[0], d_res.di[1], &acc_most);
-               break;
-       }
-       opcode=0;
-}
+#endif
index 54af69b..46cf997 100644 (file)
@@ -1,18 +1,19 @@
-/*     vm_machdep.c    1.1     85/07/21        */
+/*     vm_machdep.c    1.2     86/01/05        */
 
 #include "../machine/pte.h"
 
 
 #include "../machine/pte.h"
 
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/dir.h"
-#include "../h/user.h"
-#include "../h/proc.h"
-#include "../h/cmap.h"
-#include "../h/mount.h"
-#include "../h/vm.h"
-#include "../h/text.h"
+#include "param.h"
+#include "systm.h"
+#include "dir.h"
+#include "user.h"
+#include "proc.h"
+#include "cmap.h"
+#include "mount.h"
+#include "vm.h"
+#include "text.h"
+#include "kernel.h"
 
 
-#include "../machine/mtpr.h"
+#include "../tahoe/mtpr.h"
 
 /*
  * Set a red zone in the kernel stack after the u. area.
 
 /*
  * Set a red zone in the kernel stack after the u. area.
@@ -26,7 +27,7 @@ setredzone(pte, vaddr)
        *(int *)pte &= ~PG_PROT;
        *(int *)pte |= PG_URKR;
        if (vaddr)
        *(int *)pte &= ~PG_PROT;
        *(int *)pte |= PG_URKR;
        if (vaddr)
-               mtpr(vaddr + sizeof (struct user) + NBPG - 1, TBIS);
+               mtpr(TBIS, vaddr + sizeof (struct user) + NBPG - 1);
 }
 
 #ifndef mapin
 }
 
 #ifndef mapin
@@ -38,7 +39,7 @@ mapin(pte, v, pfnum, count, prot)
 
        while (count > 0) {
                *(int *)pte++ = pfnum | prot;
 
        while (count > 0) {
                *(int *)pte++ = pfnum | prot;
-               mtpr(ptob(v), TBIS);
+               mtpr(TBIS, ptob(v));
                v++;
                pfnum++;
                count--;
                v++;
                pfnum++;
                count--;
@@ -60,38 +61,15 @@ mapout(pte, size)
 /*
  * Check for valid program size
  */
 /*
  * Check for valid program size
  */
-chksize(ts, ds, ss)
-       register unsigned ts, ds, ss;
+chksize(ts, ids, uds, ss)
+       register unsigned ts, ids, uds, ss;
 {
 {
-       static int maxdmap = 0;
 
 
-       if (ts > MAXTSIZ || ds > MAXDSIZ || ss > MAXSSIZ) {
-               u.u_error = ENOMEM;
-               return (1);
-       }
-       /* check for swap map overflow */
-       if (maxdmap == 0) {
-               register int i, blk;
-
-               blk = dmmin;
-               for (i = 0; i < NDMAP; i++) {
-                       maxdmap += blk;
-                       if (blk < dmmax)
-                               blk *= 2;
-               }
-       }
-       if (ctod(ts) > NXDAD * dmtext ||
-           ctod(ds) > maxdmap || ctod(ss) > maxdmap) {
-               u.u_error = ENOMEM;
-               return (1);
-       }
-       /*
-        * Make sure the process isn't bigger than our
-        * virtual memory limit.
-        *
-        * THERE SHOULD BE A CONSTANT FOR THIS.
-        */
-       if (ts + ds + ss + LOWPAGES + HIGHPAGES > btoc(USRSTACK)) {
+       if (ts > maxtsize ||
+           ctob(ids) > u.u_rlimit[RLIMIT_DATA].rlim_cur ||
+           ctob(uds) > u.u_rlimit[RLIMIT_DATA].rlim_cur ||
+           ctob(ids + uds) > u.u_rlimit[RLIMIT_DATA].rlim_cur ||
+           ctob(ss) > u.u_rlimit[RLIMIT_STACK].rlim_cur) {
                u.u_error = ENOMEM;
                return (1);
        }
                u.u_error = ENOMEM;
                return (1);
        }
@@ -110,11 +88,11 @@ newptes(pte, v, size)
        pte = pte;
 #endif
        if (size >= 8) {
        pte = pte;
 #endif
        if (size >= 8) {
-               mtpr(0, TBIA);
+               mtpr(TBIA, 0);
                return;
        }
        while (size > 0) {
                return;
        }
        while (size > 0) {
-               mtpr(a, TBIS);
+               mtpr(TBIS, a);
                a += NBPG;
                size--;
        }
                a += NBPG;
                size--;
        }
@@ -164,13 +142,13 @@ settprot(tprot)
                ptaddr[i] &= ~PG_PROT;
                ptaddr[i] |= tprot;
        }
                ptaddr[i] &= ~PG_PROT;
                ptaddr[i] |= tprot;
        }
-       mtpr(0, TBIA);
+       mtpr(TBIA, 0);
 }
 
 }
 
+#ifdef notdef
 /*
  * Rest are machine-dependent
  */
 /*
  * Rest are machine-dependent
  */
-
 getmemc(addr)
        caddr_t addr;
 {
 getmemc(addr)
        caddr_t addr;
 {
@@ -179,11 +157,11 @@ getmemc(addr)
 
        savemap = mmap[0];
        *(int *)mmap = PG_V | PG_KR | btop(addr);
 
        savemap = mmap[0];
        *(int *)mmap = PG_V | PG_KR | btop(addr);
-       mtpr(vmmap, TBIS);
-       uncache (&vmmap[(int)addr & PGOFSET]);
+       mtpr(TBIS, vmmap);
+       uncache(&vmmap[(int)addr & PGOFSET]);
        c = *(char *)&vmmap[(int)addr & PGOFSET];
        mmap[0] = savemap;
        c = *(char *)&vmmap[(int)addr & PGOFSET];
        mmap[0] = savemap;
-       mtpr(vmmap, TBIS);
+       mtpr(TBIS, vmmap);
        return (c & 0377);
 }
 
        return (c & 0377);
 }
 
@@ -194,15 +172,16 @@ putmemc(addr, val)
 
        savemap = mmap[0];
        *(int *)mmap = PG_V | PG_KW | btop(addr);
 
        savemap = mmap[0];
        *(int *)mmap = PG_V | PG_KW | btop(addr);
-       mtpr(vmmap, TBIS);
+       mtpr(TBIS, vmmap);
        *(char *)&vmmap[(int)addr & PGOFSET] = val;
 
        *(char *)&vmmap[(int)addr & PGOFSET] = val;
 
-       mtpr (0, PADC);
-       mtpr (0, PACC);
+       mtpr(PADC, 0);
+       mtpr(PACC, 0);
 
        mmap[0] = savemap;
 
        mmap[0] = savemap;
-       mtpr(vmmap, TBIS);
+       mtpr(TBIS, vmmap);
 }
 }
+#endif
 
 /*
  * Move pages from one kernel virtual address to another.
 
 /*
  * Move pages from one kernel virtual address to another.
@@ -222,114 +201,275 @@ pagemove(from, to, size)
        while (size > 0) {
                *tpte++ = *fpte;
                *(int *)fpte++ = 0;
        while (size > 0) {
                *tpte++ = *fpte;
                *(int *)fpte++ = 0;
-               mtpr(from, TBIS);
-               mtpr(to, TBIS);
-               mtpr(to, P1DC);         /* purge !! */
+               mtpr(TBIS, from);
+               mtpr(TBIS, to);
+               mtpr(P1DC, to);         /* purge !! */
                from += NBPG;
                to += NBPG;
                size -= NBPG;
        }
 }
 
                from += NBPG;
                to += NBPG;
                size -= NBPG;
        }
 }
 
-#ifndef GLOBKEY
-ckeyrelease(key)
-/* 
- * release code key
+#ifndef vtopte
+/*
+ * Convert a virtual page 
+ * number to a pte address.
  */
  */
+/*VARARGS1*/
+struct pte *
+vtopte(p, v)
+       register struct proc *p;
 {
 {
-       register int ipl,i,j ;
-       ipl = spl8();
-       if (--ckey_cnt[key-1] < 0 ) {
+
+       if ((v & 0x300000) == 0x300000)
+               return (struct pte *)(mfpr(SBR) + 0xc0000000 + (v&0xfffff)*4);
+       if (p == 0)
+               panic("vtopte (no proc)");
+       if (v < p->p_tsize + p->p_dsize)
+               return (p->p_p0br + v);
+       return (p->p_p0br + (p->p_szpt*NPTEPG + v - (BTOPUSRSTACK + UPAGES)));
+}
+#endif
+
 /*
 /*
-               panic ("Code key release");
-*/
-               printf("Ckey release, key=%d\n", key);
-               ckey_cnt[key-1] = 0;
-               splx(ipl);
+ * Code and data key management routines.
+ *
+ * The arrays ckey_cnt and ckey_cache are allways kept in such a way
+ * that the following invariant holds:
+ *     ckey_cnt > 0    =>'s    ckey_cache == 1
+ * meaning as long as a code key is used by at least one process, it's
+ * marked as being 'in the cache'. Of course, the following invariant
+ * also holds:
+ *     ckey_cache == 0 =>'s    ckey_cnt == 0
+ * which is just the reciprocal of the 1'st invariant.
+ * Equivalent invariants hold for the data key arrays.
+ */
+
+/* 
+ * Release a code key.
+ */
+ckeyrelease(key)
+       int key;
+{
+       register int s;
+
+       s = spl8();
+       if (--ckey_cnt[key] < 0) {
+               printf("ckeyrelease: key = %d\n", key);
+               ckey_cnt[key] = 0;
        }
        }
-       splx(ipl);
+       splx(s);
 }
 
 }
 
-
-dkeyrelease(key)
 /* 
 /* 
- * release data key
+ * Release a data key.
  */
  */
+dkeyrelease(key)
+       int key;
 {
 {
-       if (--dkey_cnt[key-1] != 0 ) panic ("Data key release");
+       register int s;
+
+       s = spl8();
+       if (--dkey_cnt[key] != 0) {
+               printf("dkeyrelease: key = %d\n", key);
+               dkey_cnt[key] = 0;
+       }
+       splx(s);        
 }
 
 }
 
+struct keystats {
+       long    ks_allocs;      /* number of keys allocated */
+       long    ks_free;        /* key allocated from free slot */
+       long    ks_norefs;      /* key marked in use, but refcnt 0 */
+       long    ks_taken;       /* key taken from single process */
+       long    ks_shared;      /* key taken from multiple processes */
+};
+struct keystats ckeystats;
+struct keystats dkeystats;
 
 
-int
-getcodekey()
 /* 
 /* 
- * Get a code key
+ * Get a code key.
  */
  */
+getcodekey()
 {
 {
-       register int i, ipl, first;
-
-       first = 1;
-       ipl = spl8();
-retry:
-       for (i=0; i<255; i++) {
-               if ( (int)ckey_cache[i] == 0) {
-                       ckey_cache[i] = 1;
-                       ckey_cnt[i] = 1;
-                       splx(ipl);
-                       return (i+1);
-               };
+       register int i, s, freekey, sharedkey;
+       register struct proc *p;
+
+       ckeystats.ks_allocs++;
+       s = spl8();
+       freekey = 0;
+       for (i = 1; i <= MAXCKEY; i++) {
+               if ((int)ckey_cache[i] == 0) {  /* free key, take it */
+                       ckey_cache[i] = 1, ckey_cnt[i] = 1;
+                       splx(s);
+                       ckeystats.ks_free++;
+                       return (i);
+               }
+               if (ckey_cnt[i] == 0) {         /* save for potential use */
+                       if (freekey == 0)
+                               freekey = i;
+               } else if (ckey_cnt[i] > 1 && i != MAXCKEY)
+                       sharedkey = i;
+       }
+       /*
+        * All code keys were marked as being in cache.
+        * Moreover, we are assured that sharedkey has a meaningful value,
+        * since we know that the init process and the shell are around
+        * and they have shared text!
+        */
+       /*
+        * If a key was in the cache, but not in use, grab it.
+        */
+       if (freekey != 0) {
+               /*
+                * If we've run out of bonified free keys,
+                * try and free up some other keys to avoid
+                * future cache purges.
+                */
+               for (i = 1; i <= MAXCKEY; i++)
+                       if (ckey_cnt[i] == 0)
+                               ckey_cache[i] = 0;
+               ckey_cnt[freekey] = 1, ckey_cache[freekey] = 1;
+               mtpr(PACC, 0);
+               splx(s);
+               ckeystats.ks_norefs++;
+               return (freekey);
        }
        }
-       if ( !first) {
-               splx(ipl);
-               panic ("Not enough code keys\n");
+
+       /*
+        * All keys are marked as in the cache and in use.
+        *
+        * Strip some process of their code key. First time,
+        * 1) Try hard not to do that to kernel processes !!
+        * 2) Try hard NOT to strip shared text processes of
+        *    their (shared) key, because then they'll run
+        *    with different keys from now on, i.e. less efficient
+        *    cache utilization.
+        */
+       for (p = proc; p < procNPROC; p++)
+               /*
+                * Look for a meaningful key but not
+                * used and not shared text.
+                */
+               if (p->p_ckey && p->p_ckey != MAXCKEY &&
+                   ckey_cnt[p->p_ckey] < 2) {
+                       i = p->p_ckey;
+                       p->p_ckey = 0;
+                       ckey_cnt[i] = 1, ckey_cache[i] = 1;
+                       mtpr(PACC, 0);
+                       splx(s);
+                       ckeystats.ks_taken++;
+                       return (i);
+               }
+
+       /*
+        * Second time around!
+        * Highly unlikely situation. It means that all keys are
+        * allocated AND shared (i.e. we have at least 510 active
+        * processes).
+        * Strip some of them. We pick some key (known to be shared
+        * by several processes) and strip the poor process group.
+        * At least 2 processes will loose but we gain one key to be reused.
+        * The way 'shared_key' was produced (above) virtually assures
+        * us that this key isn't the 'init' group key (1) nor the
+        * 'shell' group key (2 or 3). It's probably something like 254.
+        * Could be more straightforward to strip all processes, but it's
+        * better to invest in one more loop here and keep the cache
+        * utilization to a maximum.
+        */
+       for (p = proc; p < procNPROC; p++)
+               if (p->p_ckey == sharedkey) {
+                       p->p_ckey = 0;
+                       ckey_cnt[sharedkey]--;
+               }
+       if (ckey_cnt[sharedkey] != 0) {
+               printf("getcodekey: key = %d cnt = %d\n",
+                   sharedkey, ckey_cnt[sharedkey]);
+               panic("getcodekey");
        }
        }
-       mtpr (0, PACC);
-       first = 0;
-       for (i=0; i<255; i++)
-               if ( ckey_cnt[i] > 0 ) ckey_cache[i] = 1;
-               else ckey_cache[i] = 0;
-       goto retry;
+       ckey_cnt[sharedkey] = 1, ckey_cache[sharedkey] = 1;
+       mtpr(PACC, 0);
+       splx(s);
+       ckeystats.ks_shared++;
+       return (sharedkey);
 }
 
 }
 
-int
-getdatakey()
 /* 
 /* 
- * Get a data key
+ * Get a data key.
+ *
+ * General strategy:
+ * 1) Try to find a data key that isn't in the cache. Allocate it.
+ * 2) If all data keys are in the cache, find one which isn't
+ *    allocated. Clear all status and allocate this one.
+ * 3) If all of them are allocated, pick some process, strip him
+ *    of the data key and allocate it. We (cold-bloodedly) pick
+ *    one process to be the poor looser because that's the
+ *    easiest way to do it and because this extreme situation
+ *    ( >255 active processes ) is expected to be temporary,
+ *    after which 1) or 2) above should be the usual case.
+ * The poor looser is the first process which has a data key.
+ * However, we try to spare known kernel processes and daemons
+ * (fired at bootstrap time), by searching from proc[LOOSER] and on.
  */
  */
+getdatakey()
 {
 {
-       register int i, ipl, first;
-       
-       first = 1;
-       ipl = spl8();
-retry:
-       for (i=0; i<255; i++)
-               if ( (int)dkey_cache[i] == 0) {
-                       dkey_cache[i] = 1;
-                       dkey_cnt[i] = 1;
-                       splx(ipl);
-                       return (i+1);
-               };
-       if ( !first) {
-               splx(ipl);
-               panic("Not enough data keys\n");
+       register int i, s, freekey;
+       register struct proc *p;
+
+       dkeystats.ks_allocs++;
+       s = spl8();
+       freekey = 0;
+       for (i = 1; i <= MAXDKEY; i++) {
+               if ((int)dkey_cache[i] == 0) {  /* free key, take it */
+                       dkey_cache[i] = 1, dkey_cnt[i] = 1;
+                       splx(s);
+                       dkeystats.ks_free++;
+                       return (i);
+               }
+               if (dkey_cnt[i] == 0 && freekey == 0)
+                       freekey = i;
+       }
+       if (freekey) {
+               /*
+                * Try and free up some more keys to avoid
+                * future allocations causing a cache purge.
+                */
+               for (i = 1; i < MAXDKEY; i++)
+                       if (dkey_cnt[i] == 0)
+                               dkey_cache[i] = 0;
+               dkey_cnt[freekey] = 1, dkey_cache[freekey] = 1;
+               mtpr(PADC, 0);
+               splx(s);
+               dkeystats.ks_norefs++;
+               return (freekey);
        }
        }
-       mtpr (0, PADC);
-       first = 0;
-       for (i=0; i<255; i++)
-               if ( dkey_cnt[i] > 0 ) dkey_cache[i] = 1;
-               else dkey_cache[i] = 0;
-       goto retry;
+
+       /*
+        * Now, we have to take a code from someone.
+        */
+#define LOOSER 20
+       for (p = &proc[LOOSER]; p < procNPROC; p++)
+               if (p->p_dkey != 0) {
+                       i = p->p_dkey;
+                       p->p_dkey = 0;
+                       dkey_cnt[i] = 1;
+                       dkey_cache[i] = 1;
+                       mtpr(PADC, 0);
+                       splx(s);
+                       dkeystats.ks_taken++;
+                       return (i);
+               }
+       panic("getdatakey");
+       /*NOTREACHED*/
 }
 }
-#endif
 
 
-/* General (includes system) virtual address to physical */
+/*VARGARGS1*/
 vtoph(p, v)
 vtoph(p, v)
-register struct proc *p;
-register unsigned v;
+       register struct proc *p;
+       register unsigned v;
 {
 {
-       register struct pte *thispte;
+       register struct pte *pte;
 
 
-       thispte = vtopte (p, btop(v));
-       return ( (thispte->pg_pfnum << PGSHIFT) + (v & PGOFSET));
+       pte = vtopte(p, btop(v));
+       return ((pte->pg_pfnum << PGSHIFT) + (v & PGOFSET));
 }
 }
-