-/*
- * Initialize clist by freeing all character blocks, then count
- * number of character devices. (Once-only routine)
- */
-cinit()
-{
- register int ccp;
- register struct cblock *cp;
- register struct cdevsw *cdp;
-
- ccp = (int)cfree;
- ccp = (ccp+CROUND) & ~CROUND;
- for(cp=(struct cblock *)ccp; cp < &cfree[nclist-1]; cp++) {
- cp->c_next = cfreelist;
- cfreelist = cp;
- cfreecount += CBSIZE;
+ /*
+ * Set up the root file system and vnode.
+ */
+ if ((*mountroot)())
+ panic("cannot mount root");
+ /*
+ * Get vnode for '/'.
+ * Setup rootdir and fdp->fd_fd.fd_cdir to point to it.
+ */
+ if (VFS_ROOT(rootfs, &rootdir))
+ panic("cannot find root vnode");
+ fdp->fd_fd.fd_cdir = rootdir;
+ VREF(fdp->fd_fd.fd_cdir);
+ VOP_UNLOCK(rootdir);
+ fdp->fd_fd.fd_rdir = NULL;
+ swapinit();
+
+ /*
+ * Now can look at time, having had a chance
+ * to verify the time from the file system.
+ */
+ boottime = p->p_stats->p_start = time;
+
+ /*
+ * make init process
+ */
+ siginit(p);
+ if (fork(p, (void *) NULL, rval))
+ panic("fork init");
+ if (rval[1]) {
+ static char initflags[] = "-sf";
+ char *ip = initflags + 1;
+ vm_offset_t addr = 0;
+ extern int icode[]; /* user init code */
+ extern int szicode; /* size of icode */
+
+ /*
+ * Now in process 1. Set init flags into icode,
+ * get a minimal address space, copy out "icode",
+ * and return to it to do an exec of init.
+ */
+ p = curproc;
+ initproc = p;
+ if (boothowto&RB_SINGLE)
+ *ip++ = 's';
+#ifdef notyet
+ if (boothowto&RB_FASTBOOT)
+ *ip++ = 'f';
+#endif
+ *ip++ = '\0';
+
+ if (vm_allocate(&p->p_vmspace->vm_map, &addr,
+ round_page(szicode + sizeof(initflags)), FALSE) != 0 ||
+ addr != 0)
+ panic("init: couldn't allocate at zero");
+
+ /* need just enough stack to exec from */
+ addr = trunc_page(USRSTACK - PAGE_SIZE);
+ if (vm_allocate(&p->p_vmspace->vm_map, &addr,
+ PAGE_SIZE, FALSE) != KERN_SUCCESS)
+ panic("vm_allocate init stack");
+ p->p_vmspace->vm_maxsaddr = (caddr_t)addr;
+ (void) copyout((caddr_t)icode, (caddr_t)0, (unsigned)szicode);
+ (void) copyout(initflags, (caddr_t)szicode, sizeof(initflags));
+ return; /* returns to icode */