Commit | Line | Data |
---|---|---|
dc8751f9 | 1 | /* init_main.c 4.18 81/08/24 */ |
c4708522 BJ |
2 | |
3 | #include "../h/param.h" | |
4 | #include "../h/systm.h" | |
5 | #include "../h/dir.h" | |
6 | #include "../h/user.h" | |
7 | #include "../h/filsys.h" | |
8 | #include "../h/mount.h" | |
9 | #include "../h/map.h" | |
10 | #include "../h/proc.h" | |
11 | #include "../h/inode.h" | |
12 | #include "../h/seg.h" | |
13 | #include "../h/conf.h" | |
14 | #include "../h/buf.h" | |
15 | #include "../h/mtpr.h" | |
16 | #include "../h/pte.h" | |
17 | #include "../h/clock.h" | |
18 | #include "../h/vm.h" | |
19 | #include "../h/cmap.h" | |
831e498e | 20 | #include "../h/text.h" |
00ea40c7 | 21 | #include "../h/vlimit.h" |
0a34b6fd | 22 | #include "../h/clist.h" |
c4708522 BJ |
23 | |
24 | /* | |
25 | * Initialization code. | |
26 | * Called from cold start routine as | |
27 | * soon as a stack and segmentation | |
28 | * have been established. | |
29 | * Functions: | |
30 | * clear and free user core | |
31 | * turn on clock | |
32 | * hand craft 0th process | |
33 | * call all initialization routines | |
34 | * fork - process 0 to schedule | |
35 | * - process 2 to page out | |
36 | * - process 1 execute bootstrap | |
37 | * | |
38 | * loop at loc 13 (0xd) in user mode -- /etc/init | |
39 | * cannot be executed. | |
40 | */ | |
41 | main(firstaddr) | |
42 | { | |
73248996 | 43 | register int i; |
dd4b582c | 44 | register struct proc *p; |
c4708522 | 45 | |
c4708522 | 46 | rqinit(); |
c4708522 | 47 | startup(firstaddr); |
c4708522 BJ |
48 | |
49 | /* | |
50 | * set up system process 0 (swapper) | |
51 | */ | |
dd4b582c BJ |
52 | p = &proc[0]; |
53 | p->p_p0br = (struct pte *)mfpr(P0BR); | |
54 | p->p_szpt = 1; | |
55 | p->p_addr = uaddr(p); | |
56 | p->p_stat = SRUN; | |
57 | p->p_flag |= SLOAD|SSYS; | |
58 | p->p_nice = NZERO; | |
59 | setredzone(p->p_addr, (caddr_t)&u); | |
60 | u.u_procp = p; | |
c4708522 | 61 | u.u_cmask = CMASK; |
73248996 | 62 | for (i = 1; i < sizeof(u.u_limit)/sizeof(u.u_limit[0]); i++) |
403556fe BJ |
63 | switch (i) { |
64 | ||
65 | case LIM_STACK: | |
66 | u.u_limit[i] = 512*1024; | |
67 | continue; | |
68 | case LIM_DATA: | |
69 | u.u_limit[i] = ctob(MAXDSIZ); | |
70 | continue; | |
71 | default: | |
72 | u.u_limit[i] = INFINITY; | |
73 | continue; | |
74 | } | |
af54b85d | 75 | p->p_maxrss = INFINITY/NBPG; |
c4708522 BJ |
76 | clkstart(); |
77 | ||
78 | /* | |
79 | * Initialize devices and | |
80 | * set up 'known' i-nodes | |
81 | */ | |
82 | ||
83 | ihinit(); | |
0d5a507c | 84 | bhinit(); |
c4708522 BJ |
85 | cinit(); |
86 | binit(); | |
87 | bswinit(); | |
88 | iinit(); | |
4abdf21f | 89 | ptinit(); |
c4708522 BJ |
90 | rootdir = iget(rootdev, (ino_t)ROOTINO); |
91 | rootdir->i_flag &= ~ILOCK; | |
92 | u.u_cdir = iget(rootdev, (ino_t)ROOTINO); | |
93 | u.u_cdir->i_flag &= ~ILOCK; | |
94 | u.u_rdir = NULL; | |
95 | u.u_dmap = zdmap; | |
96 | u.u_smap = zdmap; | |
97 | ||
c1988f85 BJ |
98 | /* |
99 | * Set the scan rate and other parameters of the paging subsystem. | |
100 | */ | |
101 | setupclock(); | |
102 | ||
c4708522 BJ |
103 | /* |
104 | * make page-out daemon (process 2) | |
c34926db | 105 | * the daemon has ctopt(nswbuf*CLSIZE*KLMAX) pages of page |
c4708522 BJ |
106 | * table so that it can map dirty pages into |
107 | * its address space during asychronous pushes. | |
108 | */ | |
c4708522 | 109 | mpid = 1; |
c34926db | 110 | proc[0].p_szpt = clrnd(ctopt(nswbuf*CLSIZE*KLMAX + UPAGES)); |
c4708522 BJ |
111 | proc[1].p_stat = SZOMB; /* force it to be in proc slot 2 */ |
112 | if (newproc(0)) { | |
113 | proc[2].p_flag |= SLOAD|SSYS; | |
c34926db | 114 | proc[2].p_dsize = u.u_dsize = nswbuf*CLSIZE*KLMAX; |
c4708522 BJ |
115 | pageout(); |
116 | } | |
117 | ||
118 | /* | |
119 | * make init process and | |
120 | * enter scheduling loop | |
121 | */ | |
122 | ||
123 | mpid = 0; | |
124 | proc[1].p_stat = 0; | |
125 | proc[0].p_szpt = CLSIZE; | |
126 | if (newproc(0)) { | |
127 | expand(clrnd((int)btoc(szicode)), P0BR); | |
934e4ecf | 128 | (void) swpexpand(u.u_dsize, 0, &u.u_dmap, &u.u_smap); |
81263dba | 129 | (void) copyout((caddr_t)icode, (caddr_t)0, (unsigned)szicode); |
c4708522 BJ |
130 | /* |
131 | * Return goes to loc. 0 of user init | |
132 | * code just copied out. | |
133 | */ | |
134 | return; | |
135 | } | |
fc814008 BJ |
136 | |
137 | #ifdef BBNNET | |
138 | /* | |
139 | * Initialize bbn network. | |
140 | */ | |
dc8751f9 | 141 | netmain(); |
fc814008 | 142 | #endif BBNNET |
c4708522 BJ |
143 | proc[0].p_szpt = 1; |
144 | sched(); | |
145 | } | |
146 | ||
147 | /* | |
148 | * iinit is called once (from main) | |
149 | * very early in initialization. | |
150 | * It reads the root's super block | |
151 | * and initializes the current date | |
152 | * from the last modified date. | |
153 | * | |
154 | * panic: iinit -- cannot read the super | |
155 | * block. Usually because of an IO error. | |
156 | */ | |
157 | iinit() | |
158 | { | |
5b564702 | 159 | register struct buf *bp; |
c4708522 | 160 | register struct filsys *fp; |
dc0c4971 | 161 | register int i; |
c4708522 BJ |
162 | |
163 | (*bdevsw[major(rootdev)].d_open)(rootdev, 1); | |
164 | bp = bread(rootdev, SUPERB); | |
c4708522 BJ |
165 | if(u.u_error) |
166 | panic("iinit"); | |
63e97a1d | 167 | bp->b_flags |= B_LOCKED; /* block can never be re-used */ |
c4708522 | 168 | brelse(bp); |
c4708522 | 169 | mount[0].m_dev = rootdev; |
63e97a1d BJ |
170 | mount[0].m_bufp = bp; |
171 | fp = bp->b_un.b_filsys; | |
c4708522 BJ |
172 | fp->s_flock = 0; |
173 | fp->s_ilock = 0; | |
174 | fp->s_ronly = 0; | |
175 | fp->s_lasti = 1; | |
176 | fp->s_nbehind = 0; | |
dc0c4971 BJ |
177 | fp->s_fsmnt[0] = '/'; |
178 | for (i = 1; i < sizeof(fp->s_fsmnt); i++) | |
179 | fp->s_fsmnt[i] = 0; | |
403556fe | 180 | clkinit(fp->s_time); |
c4708522 BJ |
181 | bootime = time; |
182 | } | |
183 | ||
c4708522 BJ |
184 | /* |
185 | * Initialize the buffer I/O system by freeing | |
186 | * all buffers and setting all device buffer lists to empty. | |
c4708522 BJ |
187 | */ |
188 | binit() | |
189 | { | |
190 | register struct buf *bp; | |
191 | register struct buf *dp; | |
192 | register int i; | |
193 | struct bdevsw *bdp; | |
41888f16 | 194 | struct swdevt *swp; |
c4708522 | 195 | |
63e97a1d BJ |
196 | for (dp = bfreelist; dp < &bfreelist[BQUEUES]; dp++) { |
197 | dp->b_forw = dp->b_back = dp->av_forw = dp->av_back = dp; | |
198 | dp->b_flags = B_HEAD; | |
199 | } | |
200 | dp--; /* dp = &bfreelist[BQUEUES-1]; */ | |
0a34b6fd | 201 | for (i=0; i<nbuf; i++) { |
c4708522 BJ |
202 | bp = &buf[i]; |
203 | bp->b_dev = NODEV; | |
0a34b6fd | 204 | bp->b_un.b_addr = buffers + i * BSIZE; |
63e97a1d BJ |
205 | bp->b_back = dp; |
206 | bp->b_forw = dp->b_forw; | |
207 | dp->b_forw->b_back = bp; | |
208 | dp->b_forw = bp; | |
209 | bp->b_flags = B_BUSY|B_INVAL; | |
c4708522 BJ |
210 | brelse(bp); |
211 | } | |
5b564702 | 212 | for (bdp = bdevsw; bdp->d_open; bdp++) |
c4708522 | 213 | nblkdev++; |
41888f16 BJ |
214 | /* |
215 | * Count swap devices, and adjust total swap space available. | |
216 | * Some of this space will not be available until a vswapon() | |
217 | * system is issued, usually when the system goes multi-user. | |
218 | */ | |
219 | nswdev = 0; | |
220 | for (swp = swdevt; swp->sw_dev; swp++) | |
221 | nswdev++; | |
222 | if (nswdev == 0) | |
223 | panic("binit"); | |
b2fdd14d EC |
224 | if (nswdev > 1) |
225 | nswap = (nswap/DMMAX)*DMMAX; | |
41888f16 BJ |
226 | nswap *= nswdev; |
227 | maxpgio *= nswdev; | |
228 | swfree(0); | |
c4708522 BJ |
229 | } |
230 | ||
231 | /* | |
232 | * Initialize linked list of free swap | |
233 | * headers. These do not actually point | |
234 | * to buffers, but rather to pages that | |
235 | * are being swapped in and out. | |
236 | */ | |
237 | bswinit() | |
238 | { | |
239 | register int i; | |
0a34b6fd | 240 | register struct buf *sp = swbuf; |
c4708522 | 241 | |
c34926db | 242 | bswlist.av_forw = sp; |
0a34b6fd | 243 | for (i=0; i<nswbuf-1; i++, sp++) |
c34926db BJ |
244 | sp->av_forw = sp+1; |
245 | sp->av_forw = NULL; | |
c4708522 | 246 | } |
e7c7d88e BJ |
247 | |
248 | /* | |
249 | * Initialize clist by freeing all character blocks, then count | |
250 | * number of character devices. (Once-only routine) | |
251 | */ | |
252 | cinit() | |
253 | { | |
254 | register int ccp; | |
255 | register struct cblock *cp; | |
256 | register struct cdevsw *cdp; | |
257 | ||
258 | ccp = (int)cfree; | |
259 | ccp = (ccp+CROUND) & ~CROUND; | |
260 | for(cp=(struct cblock *)ccp; cp < &cfree[nclist-1]; cp++) { | |
261 | cp->c_next = cfreelist; | |
262 | cfreelist = cp; | |
263 | cfreecount += CBSIZE; | |
264 | } | |
265 | ccp = 0; | |
266 | for(cdp = cdevsw; cdp->d_open; cdp++) | |
267 | ccp++; | |
268 | nchrdev = ccp; | |
269 | } |