01850 #include "../h/param.h" 01851 #include "../h/systm.h" 01852 #include "../h/dir.h" 01853 #include "../h/user.h" 01854 #include "../h/filsys.h" 01855 #include "../h/mount.h" 01856 #include "../h/map.h" 01857 #include "../h/proc.h" 01858 #include "../h/inode.h" 01859 #include "../h/seg.h" 01860 #include "../h/conf.h" 01861 #include "../h/buf.h" 01862 01863 /* 01864 * Initialization code. 01865 * Called from cold start routine as 01866 * soon as a stack and segmentation 01867 * have been established. 01868 * Functions: 01869 * clear and free user core 01870 * turn on clock 01871 * hand craft 0th process 01872 * call all initialization routines 01873 * fork - process 0 to schedule 01874 * - process 1 execute bootstrap 01875 * 01876 * loop at low address in user mode -- /etc/init 01877 * cannot be executed. 01878 */ 01879 main() 01880 { 01881 01882 startup(); 01883 /* 01884 * set up system process 01885 */ 01886 01887 proc[0].p_addr = ka6->r[0]; 01888 proc[0].p_size = USIZE; 01889 proc[0].p_stat = SRUN; 01890 proc[0].p_flag |= SLOAD|SSYS; 01891 proc[0].p_nice = NZERO; 01892 u.u_procp = &proc[0]; 01893 u.u_cmask = CMASK; 01894 01895 /* 01896 * Initialize devices and 01897 * set up 'known' i-nodes 01898 */ 01899 01900 clkstart(); 01901 cinit(); 01902 binit(); 01903 iinit(); 01904 rootdir = iget(rootdev, (ino_t)ROOTINO); 01905 rootdir->i_flag &= ~ILOCK; 01906 u.u_cdir = iget(rootdev, (ino_t)ROOTINO); 01907 u.u_cdir->i_flag &= ~ILOCK; 01908 u.u_rdir = NULL; 01909 01910 /* 01911 * make init process 01912 * enter scheduling loop 01913 * with system process 01914 */ 01915 01916 if(newproc()) { 01917 expand(USIZE + (int)btoc(szicode)); 01918 estabur((unsigned)0, btoc(szicode), (unsigned)0, 0, RO); 01919 copyout((caddr_t)icode, (caddr_t)0, szicode); 01920 /* 01921 * Return goes to loc. 0 of user init 01922 * code just copied out. 01923 */ 01924 return; 01925 } 01926 sched(); 01927 } 01928 01929 /* 01930 * iinit is called once (from main) 01931 * very early in initialization. 01932 * It reads the root's super block 01933 * and initializes the current date 01934 * from the last modified date. 01935 * 01936 * panic: iinit -- cannot read the super 01937 * block. Usually because of an IO error. 01938 */ 01939 iinit() 01940 { 01941 register struct buf *cp, *bp; 01942 register struct filsys *fp; 01943 01944 (*bdevsw[major(rootdev)].d_open)(rootdev, 1); 01945 bp = bread(rootdev, SUPERB); 01946 cp = geteblk(); 01947 if(u.u_error) 01948 panic("iinit"); 01949 bcopy(bp->b_un.b_addr, cp->b_un.b_addr, sizeof(struct filsys)); 01950 brelse(bp); 01951 mount[0].m_bufp = cp; 01952 mount[0].m_dev = rootdev; 01953 fp = cp->b_un.b_filsys; 01954 fp->s_flock = 0; 01955 fp->s_ilock = 0; 01956 fp->s_ronly = 0; 01957 time = fp->s_time; 01958 } 01959 01960 /* 01961 * This is the set of buffers proper, whose heads 01962 * were declared in buf.h. There can exist buffer 01963 * headers not pointing here that are used purely 01964 * as arguments to the I/O routines to describe 01965 * I/O to be done-- e.g. swbuf for 01966 * swapping. 01967 */ 01968 char buffers[NBUF][BSIZE+BSLOP]; 01969 01970 /* 01971 * Initialize the buffer I/O system by freeing 01972 * all buffers and setting all device buffer lists to empty. 01973 */ 01974 binit() 01975 { 01976 register struct buf *bp; 01977 register struct buf *dp; 01978 register int i; 01979 struct bdevsw *bdp; 01980 01981 bfreelist.b_forw = bfreelist.b_back = 01982 bfreelist.av_forw = bfreelist.av_back = &bfreelist; 01983 for (i=0; i01984 bp = &buf[i]; 01985 bp->b_dev = NODEV; 01986 bp->b_un.b_addr = buffers[i]; 01987 bp->b_back = &bfreelist; 01988 bp->b_forw = bfreelist.b_forw; 01989 bfreelist.b_forw->b_back = bp; 01990 bfreelist.b_forw = bp; 01991 bp->b_flags = B_BUSY; 01992 brelse(bp); 01993 } 01994 for (bdp = bdevsw; bdp->d_open; bdp++) { 01995 dp = bdp->d_tab; 01996 if(dp) { 01997 dp->b_forw = dp; 01998 dp->b_back = dp; 01999 } 02000 nblkdev++; 02001 } 02002 } 02003 02004 02005 02006 02007 02008 02009 02010 02011 02012 02013 02014 02015 02016 02017 02018 02019 02020 02021 02022 02023 02024 02025 02026 02027 02028 02029 02030 02031 02032 02033 02034 02035 02036 02037 02038 02039 02040 02041 02042 02043 02044 02045 02046 02047 02048 02049