4.2 distribution
[unix-history] / usr / src / sys / kern / init_main.c
index 73dfff7..b244654 100644 (file)
@@ -1,4 +1,6 @@
-/*     init_main.c     4.40    82/10/17        */
+/*     init_main.c     6.1     83/07/29        */
+
+#include "../machine/pte.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -13,7 +15,6 @@
 #include "../h/seg.h"
 #include "../h/conf.h"
 #include "../h/buf.h"
 #include "../h/seg.h"
 #include "../h/conf.h"
 #include "../h/buf.h"
-#include "../h/pte.h"
 #include "../h/vm.h"
 #include "../h/cmap.h"
 #include "../h/text.h"
 #include "../h/vm.h"
 #include "../h/cmap.h"
 #include "../h/text.h"
@@ -22,6 +23,8 @@
 #include "../h/protosw.h"
 #endif
 #include "../h/quota.h"
 #include "../h/protosw.h"
 #endif
 #include "../h/quota.h"
+#include "../machine/reg.h"
+#include "../machine/cpu.h"
 
 extern struct user u;          /* have to declare it somewhere! */
 /*
 
 extern struct user u;          /* have to declare it somewhere! */
 /*
@@ -42,10 +45,12 @@ extern      struct user u;          /* have to declare it somewhere! */
  *     cannot be executed.
  */
 main(firstaddr)
  *     cannot be executed.
  */
 main(firstaddr)
+       int firstaddr;
 {
        register int i;
        register struct proc *p;
        struct fs *fs;
 {
        register int i;
        register struct proc *p;
        struct fs *fs;
+       int s;
 
        rqinit();
 #include "loop.h"
 
        rqinit();
 #include "loop.h"
@@ -65,7 +70,7 @@ main(firstaddr)
        u.u_procp = p;
        u.u_cmask = CMASK;
        for (i = 1; i < NGROUPS; i++)
        u.u_procp = p;
        u.u_cmask = CMASK;
        for (i = 1; i < NGROUPS; i++)
-               u.u_groups[i] = -1;
+               u.u_groups[i] = NOGROUP;
        for (i = 0; i < sizeof(u.u_rlimit)/sizeof(u.u_rlimit[0]); i++)
                u.u_rlimit[i].rlim_cur = u.u_rlimit[i].rlim_max = 
                    RLIM_INFINITY;
        for (i = 0; i < sizeof(u.u_rlimit)/sizeof(u.u_rlimit[0]); i++)
                u.u_rlimit[i].rlim_cur = u.u_rlimit[i].rlim_max = 
                    RLIM_INFINITY;
@@ -78,7 +83,11 @@ main(firstaddr)
        qtinit();
        p->p_quota = u.u_quota = getquota(0, 0, Q_NDQ);
 #endif
        qtinit();
        p->p_quota = u.u_quota = getquota(0, 0, Q_NDQ);
 #endif
-       clockstart();
+       startrtclock();
+#include "kg.h"
+#if NKG > 0
+       startkgclock();
+#endif
 
        /*
         * Initialize tables, protocols, and set up well-known inodes.
 
        /*
         * Initialize tables, protocols, and set up well-known inodes.
@@ -89,8 +98,16 @@ main(firstaddr)
 #if NLOOP > 0
        loattach();                     /* XXX */
 #endif
 #if NLOOP > 0
        loattach();                     /* XXX */
 #endif
+       /*
+        * Block reception of incoming packets
+        * until protocols have been initialized.
+        */
+       s = splimp();
        ifinit();
        ifinit();
-       pfinit();                       /* must follow interfaces */
+#endif
+       domaininit();
+#ifdef INET
+       splx(s);
 #endif
        ihinit();
        bhinit();
 #endif
        ihinit();
        bhinit();
@@ -105,8 +122,7 @@ main(firstaddr)
                panic("iinit");
        bcopy("/", fs->fs_fsmnt, 2);
 
                panic("iinit");
        bcopy("/", fs->fs_fsmnt, 2);
 
-/* initialize wall clock */
-       clockinit(fs->fs_time);
+       inittodr(fs->fs_time);
        boottime = time;
 
 /* kick off timeout driven events by calling first time */
        boottime = time;
 
 /* kick off timeout driven events by calling first time */
@@ -142,6 +158,7 @@ main(firstaddr)
                proc[2].p_flag |= SLOAD|SSYS;
                proc[2].p_dsize = u.u_dsize = nswbuf*CLSIZE*KLMAX; 
                pageout();
                proc[2].p_flag |= SLOAD|SSYS;
                proc[2].p_dsize = u.u_dsize = nswbuf*CLSIZE*KLMAX; 
                pageout();
+               /*NOTREACHED*/
        }
 
        /*
        }
 
        /*
@@ -162,22 +179,6 @@ main(firstaddr)
                 */
                return;
        }
                 */
                return;
        }
-#ifdef MUSH
-       /*
-        * start MUSH daemon
-        *                      pid == 3
-        */
-       if (newproc(0)) {
-               expand(clrnd((int)btoc(szmcode)), 0);
-               (void) swpexpand(u.u_dsize, 0, &u.u_dmap, &u.u_smap);
-               (void) copyout((caddr_t)mcode, (caddr_t)0, (unsigned)szmcode);
-               /*
-                * Return goes to loc. 0 of user mush
-                * code just copied out.
-                */
-               return;
-       }
-#endif
        proc[0].p_szpt = 1;
        sched();
 }
        proc[0].p_szpt = 1;
        sched();
 }
@@ -203,21 +204,24 @@ binit()
        register struct buf *bp, *dp;
        register int i;
        struct swdevt *swp;
        register struct buf *bp, *dp;
        register int i;
        struct swdevt *swp;
+       int base, residual;
 
        for (dp = bfreelist; dp < &bfreelist[BQUEUES]; dp++) {
                dp->b_forw = dp->b_back = dp->av_forw = dp->av_back = dp;
                dp->b_flags = B_HEAD;
        }
 
        for (dp = bfreelist; dp < &bfreelist[BQUEUES]; dp++) {
                dp->b_forw = dp->b_back = dp->av_forw = dp->av_back = dp;
                dp->b_flags = B_HEAD;
        }
-       dp--;                           /* dp = &bfreelist[BQUEUES-1]; */
+       base = bufpages / nbuf;
+       residual = bufpages % nbuf;
        for (i = 0; i < nbuf; i++) {
                bp = &buf[i];
                bp->b_dev = NODEV;
        for (i = 0; i < nbuf; i++) {
                bp = &buf[i];
                bp->b_dev = NODEV;
+               bp->b_bcount = 0;
                bp->b_un.b_addr = buffers + i * MAXBSIZE;
                bp->b_un.b_addr = buffers + i * MAXBSIZE;
-               bp->b_bcount = MAXBSIZE;
-               bp->b_back = dp;
-               bp->b_forw = dp->b_forw;
-               dp->b_forw->b_back = bp;
-               dp->b_forw = bp;
+               if (i < residual)
+                       bp->b_bufsize = (base + 1) * CLBYTES;
+               else
+                       bp->b_bufsize = base * CLBYTES;
+               binshash(bp, &bfreelist[BQ_AGE]);
                bp->b_flags = B_BUSY|B_INVAL;
                brelse(bp);
        }
                bp->b_flags = B_BUSY|B_INVAL;
                brelse(bp);
        }
@@ -227,12 +231,16 @@ binit()
         * system is issued, usually when the system goes multi-user.
         */
        nswdev = 0;
         * system is issued, usually when the system goes multi-user.
         */
        nswdev = 0;
-       for (swp = swdevt; swp->sw_dev; swp++)
+       nswap = 0;
+       for (swp = swdevt; swp->sw_dev; swp++) {
                nswdev++;
                nswdev++;
+               if (swp->sw_nblks > nswap)
+                       nswap = swp->sw_nblks;
+       }
        if (nswdev == 0)
                panic("binit");
        if (nswdev > 1)
        if (nswdev == 0)
                panic("binit");
        if (nswdev > 1)
-               nswap = (nswap/DMMAX)*DMMAX;
+               nswap = ((nswap + dmmax - 1) / dmmax) * dmmax;
        nswap *= nswdev;
        maxpgio *= nswdev;
        swfree(0);
        nswap *= nswdev;
        maxpgio *= nswdev;
        swfree(0);