1: /*
   2:  *	SCCS id	@(#)main.c	2.1 (Berkeley)	8/29/83
   3:  */
   4: 
   5: #include "param.h"
   6: #include <sys/systm.h>
   7: #include <sys/dir.h>
   8: #include <sys/user.h>
   9: #include <sys/filsys.h>
  10: #include <sys/mount.h>
  11: #include <sys/map.h>
  12: #include <sys/proc.h>
  13: #include <sys/inode.h>
  14: #include <sys/seg.h>
  15: #include <sys/conf.h>
  16: #include <sys/buf.h>
  17: 
  18: 
  19: #ifdef  UCB_FRCSWAP
  20: /*
  21:  *	If set, allow incore forks and expands.
  22:  *	Set before idle(), cleared in clock.c.
  23:  *	Set to 1 here because the init creation
  24:  *	must not cause a swap.
  25:  */
  26: int idleflg = 1;
  27: #endif
  28: 
  29: /*
  30:  * Initialization code.
  31:  * Called from cold start routine as
  32:  * soon as a stack and segmentation
  33:  * have been established.
  34:  * Functions:
  35:  *	clear and free user core
  36:  *	turn on clock
  37:  *	hand craft 0th process
  38:  *	call all initialization routines
  39:  *	fork - process 0 to schedule
  40:  *	     - process 1 execute bootstrap
  41:  */
  42: main()
  43: {
  44:     extern char version[];
  45: 
  46:     printf("\n%s", version);
  47:     startup();
  48: 
  49:     /*
  50: 	 * set up system process
  51: 	 */
  52:     proc[0].p_addr = *ka6;
  53: #ifndef VIRUS_VFORK
  54:     proc[0].p_size = USIZE;
  55: #endif
  56:     proc[0].p_stat = SRUN;
  57:     proc[0].p_flag |= SLOAD|SSYS;
  58:     proc[0].p_nice = NZERO;
  59:     u.u_procp = &proc[0];
  60:     u.u_cmask = CMASK;
  61: 
  62:     /*
  63: 	 * Initialize devices and
  64: 	 * set up 'known' i-nodes
  65: 	 */
  66: 
  67: #ifdef  UCB_IHASH
  68:     ihinit();
  69: #endif
  70:     cinit();
  71:     binit();
  72: #ifdef  UNIBUS_MAP
  73:     (void) ubinit();
  74: #endif	UNIBUS_MAP
  75: #ifdef  UCB_NET
  76:     netinit();
  77: #endif
  78:     clkstart();
  79:     iinit();
  80:     rootdir = iget(rootdev, (ino_t)ROOTINO);
  81:     rootdir->i_flag &= ~ILOCK;
  82:     u.u_cdir = iget(rootdev, (ino_t)ROOTINO);
  83:     u.u_cdir->i_flag &= ~ILOCK;
  84: 
  85:     /*
  86: 	 * make init process
  87: 	 * enter scheduling loop
  88: 	 * with system process
  89: 	 */
  90: #ifdef  VIRUS_VFORK
  91:     if(newproc(0))
  92: #else
  93:     if(newproc())
  94: #endif
  95:         {
  96: #ifdef  VIRUS_VFORK
  97:         expand((int)btoc(szicode),S_DATA);
  98: #else
  99:         expand(USIZE + (int)btoc(szicode));
 100: #endif
 101:         estabur((unsigned)0, btoc(szicode), (unsigned)0, 0, RO);
 102:         copyout((caddr_t)icode, (caddr_t)0, szicode);
 103:         /*
 104: 		 * Return goes to loc. 0 of user init
 105: 		 * code just copied out.
 106: 		 */
 107:         return;
 108:     }
 109:     else
 110:         sched();
 111: }
 112: 
 113: /*
 114:  * Iinit is called once (from main)
 115:  * very early in initialization.
 116:  * It reads the root's super block
 117:  * and initializes the current date
 118:  * from the last modified date.
 119:  *
 120:  * panic: iinit -- cannot read the super
 121:  * block (usually because of an IO error).
 122:  */
 123: iinit()
 124: {
 125:     register struct buf *cp, *bp;
 126:     register struct filsys *fp;
 127:     register i;
 128: 
 129:     (*bdevsw[major(rootdev)].d_open)(rootdev, B_READ);
 130:     (*bdevsw[major(swapdev)].d_open)(swapdev, B_READ);
 131:     bp = bread(rootdev, SUPERB);
 132:     if(u.u_error)
 133:         panic("iinit");
 134:     fp = &mount[0].m_filsys;
 135:     bcopy(mapin(bp), (caddr_t)fp, sizeof(struct filsys));
 136:     mapout(bp);
 137:     mount[0].m_inodp = (struct inode *) 1;
 138:     brelse(bp);
 139:     mount[0].m_dev = rootdev;
 140:     fp->s_flock = 0;
 141:     fp->s_ilock = 0;
 142:     fp->s_ronly = 0;
 143: #ifdef  UCB_IHASH
 144:     fp->s_lasti = 1;
 145:     fp->s_nbehind = 0;
 146: #endif
 147:     fp->s_fsmnt[0] = '/';
 148:     for (i = 1; i < sizeof(fp->s_fsmnt); i++)
 149:         fp->s_fsmnt[i] = 0;
 150:     time = fp->s_time;
 151:     bootime = time;
 152: }
 153: 
 154: memaddr bpaddr;     /* physical click-address of buffers */
 155: 
 156: /*
 157:  * Initialize the buffer I/O system by freeing
 158:  * all buffers and setting all device buffer lists to empty.
 159:  */
 160: binit()
 161: {
 162:     register struct buf *bp;
 163:     register struct buf *dp;
 164:     register int i;
 165:     struct bdevsw *bdp;
 166:     long paddr;
 167: 
 168:     bfreelist.b_forw = bfreelist.b_back =
 169:         bfreelist.av_forw = bfreelist.av_back = &bfreelist;
 170:     paddr = ((long) bpaddr) << 6;
 171:     for (i=0; i<nbuf; i++) {
 172:         bp = &buf[i];
 173:         bp->b_dev = NODEV;
 174:         bp->b_un.b_addr = loint(paddr);
 175:         bp->b_xmem = hiint(paddr);
 176:         paddr += bsize;
 177:         bp->b_back = &bfreelist;
 178:         bp->b_forw = bfreelist.b_forw;
 179:         bfreelist.b_forw->b_back = bp;
 180:         bfreelist.b_forw = bp;
 181:         bp->b_flags = B_BUSY;
 182:         brelse(bp);
 183:     }
 184:     for (bdp = bdevsw; bdp < bdevsw + nblkdev; bdp++) {
 185:         dp = bdp->d_tab;
 186:         if(dp) {
 187:             dp->b_forw = dp;
 188:             dp->b_back = dp;
 189:         }
 190:         (void) (*bdp->d_root)();
 191:     }
 192: }

Defined functions

binit defined in line 160; used 1 times
  • in line 71
iinit defined in line 123; used 1 times
  • in line 79
main defined in line 42; never used

Defined variables

bpaddr defined in line 154; used 7 times
idleflg defined in line 26; used 6 times
Last modified: 1983-08-30
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 823
Valid CSS Valid XHTML 1.0 Strict