|
|
1.1 ! root 1: #include "sys/param.h" ! 2: #include "sys/systm.h" ! 3: #include "sys/user.h" ! 4: #include "sys/filsys.h" ! 5: #include "sys/mtpr.h" ! 6: #include "sys/pte.h" ! 7: #include "sys/proc.h" ! 8: #include "sys/inode.h" ! 9: #include "sys/conf.h" ! 10: #include "sys/buf.h" ! 11: #include "sys/clock.h" ! 12: #include "sys/vm.h" ! 13: #include "sys/text.h" ! 14: #include "sys/vlimit.h" ! 15: #include "sys/file.h" ! 16: ! 17: /* ! 18: * Initialization code. ! 19: * Called from cold start routine as ! 20: * soon as a stack and segmentation ! 21: * have been established. ! 22: * Functions: ! 23: * clear and free user core ! 24: * turn on clock ! 25: * hand craft 0th process ! 26: * call all initialization routines ! 27: * fork - process 0 to schedule ! 28: * - process 2 to page out ! 29: * - process 1 execute bootstrap ! 30: * ! 31: * loop at low addr in user mode -- /etc/init ! 32: * cannot be executed. ! 33: */ ! 34: struct proc *procNPROC; ! 35: struct text *textNTEXT; ! 36: struct file *fileNFILE; ! 37: struct inode *inodeNINODE; ! 38: time_t bootime; /* should probably go away */ ! 39: ! 40: main() ! 41: { ! 42: register int i; ! 43: register struct proc *p; ! 44: extern char sigcode[]; ! 45: extern int szsigcode; ! 46: extern char icode[]; ! 47: extern int szicode; ! 48: extern int swbufcnt; ! 49: ! 50: rqinit(); ! 51: procNPROC = &proc[SYSPIDS]; ! 52: textNTEXT = &text[textcnt]; ! 53: fileNFILE = &file[filecnt]; ! 54: inodeNINODE = &inode[inodecnt]; ! 55: startup(); ! 56: ! 57: /* ! 58: * set up system process 0 (swapper) ! 59: */ ! 60: p = &proc[SWAPPID]; ! 61: p->p_stat = SRUN; ! 62: p->p_flag |= SLOAD|SSYS; ! 63: p->p_nice = NZERO; ! 64: u.u_procp = p; ! 65: bcopy((caddr_t)sigcode, (caddr_t)u.u_pcb.pcb_sigc, szsigcode); ! 66: u.u_cmask = CMASK; ! 67: for (i = 0; i < NGROUPS; i++) ! 68: u.u_groups[i] = NOGROUP; /* null access group for init */ ! 69: for (i = 1; i < sizeof(u.u_limit)/sizeof(u.u_limit[0]); i++) ! 70: u.u_limit[i] = INFINITY; ! 71: u.u_limit[LIM_STACK] = ctob(maxssize); ! 72: u.u_limit[LIM_DATA] = ctob(maxdsize); ! 73: u.u_limit[LIM_TEXT] = ctob(maxtsize); ! 74: p->p_maxrss = INFINITY/NBPG; ! 75: callinit(); ! 76: clkstart(); ! 77: ! 78: /* ! 79: * Initialize devices and ! 80: * set up 'known' i-nodes ! 81: */ ! 82: ! 83: ihinit(); ! 84: bhinit(); ! 85: binit(); ! 86: qinit(); ! 87: bswinit(); ! 88: iinit(); ! 89: bootime = time; ! 90: u.u_dmap = zdmap; ! 91: u.u_smap = zdmap; ! 92: ! 93: /* ! 94: * Set the scan rate and other parameters of the paging subsystem. ! 95: */ ! 96: setupclock(); ! 97: ! 98: /* ! 99: * make page-out daemon (process 2) ! 100: * the daemon has ctopt(swbufcnt*CLSIZE*KLMAX) pages of page ! 101: * table so that it can map dirty pages into ! 102: * its address space during asychronous pushes. ! 103: * this stuff should be shoved out to a vm init routine. ! 104: */ ! 105: ! 106: p->p_szpt = clrnd(ctopt(swbufcnt*CLSIZE*KLMAX + UPAGES)); ! 107: if (newproc(&proc[PAGEPID], PAGEPID)) { ! 108: proc[PAGEPID].p_flag |= SLOAD|SSYS; ! 109: proc[PAGEPID].p_dsize = u.u_dsize = swbufcnt*CLSIZE*KLMAX; ! 110: pageout(); ! 111: } ! 112: /* ! 113: * make init process and ! 114: * enter scheduling loop ! 115: */ ! 116: p->p_szpt = CLSIZE; ! 117: if (newproc(&proc[INITPID], INITPID)) { ! 118: expand(clrnd((int)btoc(szicode)), P0BR); ! 119: (void) swpexpand(u.u_dsize, 0, &u.u_dmap, &u.u_smap); ! 120: (void) copyout((caddr_t)icode, (caddr_t)0, (unsigned)szicode); ! 121: /* ! 122: * Return goes to loc. 0 of user init ! 123: * code just copied out. ! 124: */ ! 125: return; ! 126: } ! 127: p->p_szpt = 1; ! 128: sched(); ! 129: } ! 130: ! 131: /* ! 132: * iinit is called once (from main) ! 133: * very early in initialization. ! 134: * It reads the root's super block ! 135: * it mounts the root filesystem. ! 136: * there is a small amount of magic: ! 137: * an inode is invented to hold the special file ! 138: * for the root device, so it is known that ! 139: * a special file in that filesystem is involved; ! 140: * the filesystem is mounted on the special file, ! 141: * then patched so that the root is also the mount point. ! 142: * some of this magic should be removed. ! 143: * ! 144: * some filesystem types init the date, again through magic ! 145: */ ! 146: ! 147: static struct inode rootspcl; ! 148: ! 149: iinit() ! 150: { ! 151: register struct inode *ip; ! 152: extern int rootfstyp; ! 153: ! 154: bdevopen(rootdev); ! 155: if (u.u_error) ! 156: panic("iinit root"); ! 157: bdevopen(swapdev); ! 158: if (u.u_error) ! 159: panic("iinit swap"); ! 160: rootspcl.i_dev = NODEV; ! 161: rootspcl.i_fstyp = rootfstyp; ! 162: rootspcl.i_mode = IFBLK; ! 163: rootspcl.i_un.i_rdev = rootdev; ! 164: rootspcl.i_count = 1; ! 165: /* rootspcl.i_un.i_bufp == NULL; does it matter? */ ! 166: if (fstypsw[rootfstyp] == NULL) ! 167: panic("iinit fstyp"); ! 168: (*fstypsw[rootfstyp]->t_mount)(&rootspcl, &rootspcl, 0, 1, rootfstyp); ! 169: if (u.u_error) ! 170: panic("iinit mount"); ! 171: ip = rootspcl.i_mroot; ! 172: ip->i_mpoint = ip; ! 173: ip->i_mroot = NULL; /* own mount point, but not mounted on self */ ! 174: rootdir = ip; ! 175: u.u_cdir = ip; ! 176: ip->i_count += 2; /* needed? */ ! 177: u.u_rdir = NULL; ! 178: } ! 179: ! 180: /* ! 181: * open a block device, with no more than dev ! 182: */ ! 183: ! 184: bdevopen(dev) ! 185: dev_t dev; ! 186: { ! 187: register unsigned maj; ! 188: ! 189: maj = major(dev); ! 190: if (maj >= nblkdev || bdevsw[maj] == NULL) { ! 191: u.u_error = ENODEV; ! 192: return; ! 193: } ! 194: (*bdevsw[maj]->d_open)(dev, FREAD|FWRITE); ! 195: } ! 196: ! 197: /* ! 198: * Initialize the buffer I/O system by freeing ! 199: * all buffers and setting all device buffer lists to empty. ! 200: */ ! 201: binit() ! 202: { ! 203: register struct buf *bp; ! 204: register struct buf *dp; ! 205: register int i; ! 206: ! 207: for (dp = bfreelist; dp < &bfreelist[BQUEUES]; dp++) { ! 208: dp->b_forw = dp->b_back = dp->av_forw = dp->av_back = dp; ! 209: dp->b_flags = B_HEAD; ! 210: } ! 211: dp--; /* dp = &bfreelist[BQUEUES-1]; */ ! 212: for (i=0; i<nbuf; i++) { ! 213: bp = &buf[i]; ! 214: bp->b_dev = NODEV; ! 215: bp->b_un.b_addr = buffers + i * BUFSIZE; ! 216: bp->b_back = dp; ! 217: bp->b_forw = dp->b_forw; ! 218: dp->b_forw->b_back = bp; ! 219: dp->b_forw = bp; ! 220: bp->b_flags = B_BUSY|B_INVAL; ! 221: brelse(bp); ! 222: } ! 223: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.