Commit | Line | Data |
---|---|---|
55b76399 | 1 | /* init_main.c 4.34 82/08/22 */ |
c4708522 BJ |
2 | |
3 | #include "../h/param.h" | |
4 | #include "../h/systm.h" | |
5 | #include "../h/dir.h" | |
6 | #include "../h/user.h" | |
6459ebe0 | 7 | #include "../h/fs.h" |
c4708522 BJ |
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" |
d872f034 | 23 | #ifdef INET |
d872f034 BJ |
24 | #include "../h/protosw.h" |
25 | #endif | |
859bd1be | 26 | #include "../h/quota.h" |
c4708522 BJ |
27 | |
28 | /* | |
29 | * Initialization code. | |
30 | * Called from cold start routine as | |
31 | * soon as a stack and segmentation | |
32 | * have been established. | |
33 | * Functions: | |
34 | * clear and free user core | |
35 | * turn on clock | |
36 | * hand craft 0th process | |
37 | * call all initialization routines | |
38 | * fork - process 0 to schedule | |
39 | * - process 2 to page out | |
40 | * - process 1 execute bootstrap | |
41 | * | |
42 | * loop at loc 13 (0xd) in user mode -- /etc/init | |
43 | * cannot be executed. | |
44 | */ | |
45 | main(firstaddr) | |
46 | { | |
73248996 | 47 | register int i; |
dd4b582c | 48 | register struct proc *p; |
9d6d37ce | 49 | struct fs *fs; |
c4708522 | 50 | |
c4708522 | 51 | rqinit(); |
fbf9a431 | 52 | #include "loop.h" |
c4708522 | 53 | startup(firstaddr); |
c4708522 BJ |
54 | |
55 | /* | |
56 | * set up system process 0 (swapper) | |
57 | */ | |
dd4b582c BJ |
58 | p = &proc[0]; |
59 | p->p_p0br = (struct pte *)mfpr(P0BR); | |
60 | p->p_szpt = 1; | |
61 | p->p_addr = uaddr(p); | |
62 | p->p_stat = SRUN; | |
63 | p->p_flag |= SLOAD|SSYS; | |
64 | p->p_nice = NZERO; | |
65 | setredzone(p->p_addr, (caddr_t)&u); | |
66 | u.u_procp = p; | |
c4708522 | 67 | u.u_cmask = CMASK; |
73248996 | 68 | for (i = 1; i < sizeof(u.u_limit)/sizeof(u.u_limit[0]); i++) |
403556fe BJ |
69 | switch (i) { |
70 | ||
71 | case LIM_STACK: | |
72 | u.u_limit[i] = 512*1024; | |
73 | continue; | |
74 | case LIM_DATA: | |
75 | u.u_limit[i] = ctob(MAXDSIZ); | |
76 | continue; | |
77 | default: | |
78 | u.u_limit[i] = INFINITY; | |
79 | continue; | |
80 | } | |
af54b85d | 81 | p->p_maxrss = INFINITY/NBPG; |
859bd1be RE |
82 | #ifdef QUOTA |
83 | qtinit(); | |
84 | p->p_quota = u.u_quota = getquota(0, 0, Q_NDQ); | |
85 | #endif | |
c4708522 BJ |
86 | clkstart(); |
87 | ||
88 | /* | |
d872f034 | 89 | * Initialize tables, protocols, and set up well-known inodes. |
c4708522 | 90 | */ |
d872f034 | 91 | mbinit(); |
3f660399 | 92 | cinit(); /* needed by dmc-11 driver */ |
d872f034 | 93 | #ifdef INET |
4f4caf05 BJ |
94 | #if NLOOP > 0 |
95 | loattach(); /* XXX */ | |
96 | #endif | |
fbf9a431 | 97 | ifinit(); |
b115f297 | 98 | pfinit(); /* must follow interfaces */ |
d872f034 | 99 | #endif |
c4708522 | 100 | ihinit(); |
0d5a507c | 101 | bhinit(); |
c4708522 BJ |
102 | binit(); |
103 | bswinit(); | |
e6254ffb BJ |
104 | #ifdef GPROF |
105 | kmstartup(); | |
106 | #endif | |
9d6d37ce | 107 | |
55b76399 | 108 | fs = mountfs(rootdev, 0, (struct inode *)0); |
9d6d37ce BJ |
109 | if (fs == 0) |
110 | panic("iinit"); | |
111 | bcopy("/", fs->fs_fsmnt, 2); | |
112 | clkinit(fs->fs_time); | |
113 | bootime = time; | |
114 | ||
115 | rootdir = iget(rootdev, fs, (ino_t)ROOTINO); | |
116 | iunlock(rootdir); | |
117 | u.u_cdir = iget(rootdev, fs, (ino_t)ROOTINO); | |
118 | iunlock(u.u_cdir); | |
119 | ||
c4708522 BJ |
120 | u.u_rdir = NULL; |
121 | u.u_dmap = zdmap; | |
122 | u.u_smap = zdmap; | |
123 | ||
c1988f85 BJ |
124 | /* |
125 | * Set the scan rate and other parameters of the paging subsystem. | |
126 | */ | |
127 | setupclock(); | |
128 | ||
c4708522 BJ |
129 | /* |
130 | * make page-out daemon (process 2) | |
c34926db | 131 | * the daemon has ctopt(nswbuf*CLSIZE*KLMAX) pages of page |
c4708522 BJ |
132 | * table so that it can map dirty pages into |
133 | * its address space during asychronous pushes. | |
134 | */ | |
c4708522 | 135 | mpid = 1; |
c34926db | 136 | proc[0].p_szpt = clrnd(ctopt(nswbuf*CLSIZE*KLMAX + UPAGES)); |
c4708522 BJ |
137 | proc[1].p_stat = SZOMB; /* force it to be in proc slot 2 */ |
138 | if (newproc(0)) { | |
139 | proc[2].p_flag |= SLOAD|SSYS; | |
c34926db | 140 | proc[2].p_dsize = u.u_dsize = nswbuf*CLSIZE*KLMAX; |
c4708522 BJ |
141 | pageout(); |
142 | } | |
143 | ||
144 | /* | |
145 | * make init process and | |
146 | * enter scheduling loop | |
147 | */ | |
148 | ||
149 | mpid = 0; | |
150 | proc[1].p_stat = 0; | |
151 | proc[0].p_szpt = CLSIZE; | |
152 | if (newproc(0)) { | |
153 | expand(clrnd((int)btoc(szicode)), P0BR); | |
934e4ecf | 154 | (void) swpexpand(u.u_dsize, 0, &u.u_dmap, &u.u_smap); |
81263dba | 155 | (void) copyout((caddr_t)icode, (caddr_t)0, (unsigned)szicode); |
c4708522 BJ |
156 | /* |
157 | * Return goes to loc. 0 of user init | |
158 | * code just copied out. | |
159 | */ | |
160 | return; | |
161 | } | |
859bd1be RE |
162 | #ifdef MUSH |
163 | /* | |
164 | * start MUSH daemon | |
165 | * pid == 3 | |
166 | */ | |
167 | if (newproc(0)) { | |
168 | expand(clrnd((int)btoc(szmcode)), P0BR); | |
169 | (void) swpexpand(u.u_dsize, 0, &u.u_dmap, &u.u_smap); | |
170 | (void) copyout((caddr_t)mcode, (caddr_t)0, (unsigned)szmcode); | |
171 | /* | |
172 | * Return goes to loc. 0 of user mush | |
173 | * code just copied out. | |
174 | */ | |
175 | return; | |
176 | } | |
177 | #endif | |
c4708522 BJ |
178 | proc[0].p_szpt = 1; |
179 | sched(); | |
180 | } | |
181 | ||
94d38c1e KM |
182 | /* |
183 | * Initialize hash links for buffers. | |
184 | */ | |
185 | bhinit() | |
186 | { | |
187 | register int i; | |
188 | register struct bufhd *bp; | |
189 | ||
190 | for (bp = bufhash, i = 0; i < BUFHSZ; i++, bp++) | |
191 | bp->b_forw = bp->b_back = (struct buf *)bp; | |
c4708522 BJ |
192 | } |
193 | ||
c4708522 BJ |
194 | /* |
195 | * Initialize the buffer I/O system by freeing | |
196 | * all buffers and setting all device buffer lists to empty. | |
c4708522 BJ |
197 | */ |
198 | binit() | |
199 | { | |
200 | register struct buf *bp; | |
201 | register struct buf *dp; | |
202 | register int i; | |
203 | struct bdevsw *bdp; | |
41888f16 | 204 | struct swdevt *swp; |
c4708522 | 205 | |
63e97a1d BJ |
206 | for (dp = bfreelist; dp < &bfreelist[BQUEUES]; dp++) { |
207 | dp->b_forw = dp->b_back = dp->av_forw = dp->av_back = dp; | |
208 | dp->b_flags = B_HEAD; | |
209 | } | |
210 | dp--; /* dp = &bfreelist[BQUEUES-1]; */ | |
6459ebe0 | 211 | for (i = 0; i < nbuf; i++) { |
c4708522 BJ |
212 | bp = &buf[i]; |
213 | bp->b_dev = NODEV; | |
6459ebe0 KM |
214 | bp->b_un.b_addr = buffers + i * MAXBSIZE; |
215 | bp->b_bcount = MAXBSIZE; | |
63e97a1d BJ |
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; | |
c4708522 BJ |
221 | brelse(bp); |
222 | } | |
5b564702 | 223 | for (bdp = bdevsw; bdp->d_open; bdp++) |
c4708522 | 224 | nblkdev++; |
41888f16 BJ |
225 | /* |
226 | * Count swap devices, and adjust total swap space available. | |
227 | * Some of this space will not be available until a vswapon() | |
228 | * system is issued, usually when the system goes multi-user. | |
229 | */ | |
230 | nswdev = 0; | |
231 | for (swp = swdevt; swp->sw_dev; swp++) | |
232 | nswdev++; | |
233 | if (nswdev == 0) | |
234 | panic("binit"); | |
b2fdd14d EC |
235 | if (nswdev > 1) |
236 | nswap = (nswap/DMMAX)*DMMAX; | |
41888f16 BJ |
237 | nswap *= nswdev; |
238 | maxpgio *= nswdev; | |
239 | swfree(0); | |
c4708522 BJ |
240 | } |
241 | ||
242 | /* | |
243 | * Initialize linked list of free swap | |
244 | * headers. These do not actually point | |
245 | * to buffers, but rather to pages that | |
246 | * are being swapped in and out. | |
247 | */ | |
248 | bswinit() | |
249 | { | |
250 | register int i; | |
0a34b6fd | 251 | register struct buf *sp = swbuf; |
c4708522 | 252 | |
c34926db | 253 | bswlist.av_forw = sp; |
0a34b6fd | 254 | for (i=0; i<nswbuf-1; i++, sp++) |
c34926db BJ |
255 | sp->av_forw = sp+1; |
256 | sp->av_forw = NULL; | |
c4708522 | 257 | } |
e7c7d88e BJ |
258 | |
259 | /* | |
260 | * Initialize clist by freeing all character blocks, then count | |
261 | * number of character devices. (Once-only routine) | |
262 | */ | |
263 | cinit() | |
264 | { | |
265 | register int ccp; | |
266 | register struct cblock *cp; | |
267 | register struct cdevsw *cdp; | |
268 | ||
269 | ccp = (int)cfree; | |
270 | ccp = (ccp+CROUND) & ~CROUND; | |
271 | for(cp=(struct cblock *)ccp; cp < &cfree[nclist-1]; cp++) { | |
272 | cp->c_next = cfreelist; | |
273 | cfreelist = cp; | |
274 | cfreecount += CBSIZE; | |
275 | } | |
276 | ccp = 0; | |
277 | for(cdp = cdevsw; cdp->d_open; cdp++) | |
278 | ccp++; | |
279 | nchrdev = ccp; | |
280 | } |