Commit | Line | Data |
---|---|---|
da7c5cc6 KM |
1 | /* |
2 | * Copyright (c) 1982 Regents of the University of California. | |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | * | |
539068fe | 6 | * @(#)init_main.c 6.11 (Berkeley) %G% |
da7c5cc6 | 7 | */ |
961945a8 SL |
8 | |
9 | #include "../machine/pte.h" | |
c4708522 | 10 | |
94368568 JB |
11 | #include "param.h" |
12 | #include "systm.h" | |
13 | #include "dir.h" | |
14 | #include "user.h" | |
15 | #include "kernel.h" | |
16 | #include "fs.h" | |
17 | #include "mount.h" | |
18 | #include "map.h" | |
19 | #include "proc.h" | |
20 | #include "inode.h" | |
21 | #include "seg.h" | |
22 | #include "conf.h" | |
23 | #include "buf.h" | |
24 | #include "vm.h" | |
25 | #include "cmap.h" | |
26 | #include "text.h" | |
27 | #include "clist.h" | |
d872f034 | 28 | #ifdef INET |
94368568 | 29 | #include "protosw.h" |
d872f034 | 30 | #endif |
94368568 | 31 | #include "quota.h" |
9f803800 SL |
32 | #include "../machine/reg.h" |
33 | #include "../machine/cpu.h" | |
961945a8 | 34 | |
28c7a4c5 | 35 | int cmask = CMASK; |
c4708522 BJ |
36 | /* |
37 | * Initialization code. | |
38 | * Called from cold start routine as | |
39 | * soon as a stack and segmentation | |
40 | * have been established. | |
41 | * Functions: | |
42 | * clear and free user core | |
43 | * turn on clock | |
44 | * hand craft 0th process | |
45 | * call all initialization routines | |
46 | * fork - process 0 to schedule | |
c4708522 | 47 | * - process 1 execute bootstrap |
a5829200 | 48 | * - process 2 to page out |
c4708522 BJ |
49 | */ |
50 | main(firstaddr) | |
b7892118 | 51 | int firstaddr; |
c4708522 | 52 | { |
73248996 | 53 | register int i; |
dd4b582c | 54 | register struct proc *p; |
9d6d37ce | 55 | struct fs *fs; |
4f083fd7 | 56 | int s; |
c4708522 | 57 | |
c4708522 | 58 | rqinit(); |
fbf9a431 | 59 | #include "loop.h" |
c4708522 | 60 | startup(firstaddr); |
c4708522 BJ |
61 | |
62 | /* | |
63 | * set up system process 0 (swapper) | |
64 | */ | |
dd4b582c | 65 | p = &proc[0]; |
206ecc72 | 66 | p->p_p0br = u.u_pcb.pcb_p0br; |
dd4b582c BJ |
67 | p->p_szpt = 1; |
68 | p->p_addr = uaddr(p); | |
69 | p->p_stat = SRUN; | |
70 | p->p_flag |= SLOAD|SSYS; | |
71 | p->p_nice = NZERO; | |
72 | setredzone(p->p_addr, (caddr_t)&u); | |
73 | u.u_procp = p; | |
14fda239 KM |
74 | #ifdef vax |
75 | /* | |
4898b838 KM |
76 | * These assume that the u. area is always mapped |
77 | * to the same virtual address. Otherwise must be | |
14fda239 KM |
78 | * handled when copying the u. area in newproc(). |
79 | */ | |
80 | u.u_nd.ni_iov = &u.u_nd.ni_iovec; | |
4898b838 | 81 | u.u_ap = u.u_arg; |
14fda239 KM |
82 | #endif |
83 | u.u_nd.ni_iovcnt = 1; | |
28c7a4c5 | 84 | u.u_cmask = cmask; |
a5829200 | 85 | u.u_lastfile = -1; |
197da11b | 86 | for (i = 1; i < NGROUPS; i++) |
f926daf9 | 87 | u.u_groups[i] = NOGROUP; |
d3003a84 BJ |
88 | for (i = 0; i < sizeof(u.u_rlimit)/sizeof(u.u_rlimit[0]); i++) |
89 | u.u_rlimit[i].rlim_cur = u.u_rlimit[i].rlim_max = | |
90 | RLIM_INFINITY; | |
4898b838 KM |
91 | /* |
92 | * Virtual memory limits get set in vminit(). | |
93 | */ | |
94 | vminit(); | |
1d348849 | 95 | #if defined(QUOTA) |
859bd1be RE |
96 | qtinit(); |
97 | p->p_quota = u.u_quota = getquota(0, 0, Q_NDQ); | |
98 | #endif | |
c70d0a8b | 99 | startrtclock(); |
f882447b SL |
100 | #include "kg.h" |
101 | #if NKG > 0 | |
d0ab60b1 KM |
102 | startkgclock(); |
103 | #endif | |
c4708522 BJ |
104 | |
105 | /* | |
d872f034 | 106 | * Initialize tables, protocols, and set up well-known inodes. |
c4708522 | 107 | */ |
d872f034 | 108 | mbinit(); |
a5829200 | 109 | cinit(); |
d872f034 | 110 | #ifdef INET |
4f4caf05 BJ |
111 | #if NLOOP > 0 |
112 | loattach(); /* XXX */ | |
113 | #endif | |
4f083fd7 SL |
114 | /* |
115 | * Block reception of incoming packets | |
116 | * until protocols have been initialized. | |
117 | */ | |
118 | s = splimp(); | |
fbf9a431 | 119 | ifinit(); |
d872f034 | 120 | #endif |
b7892118 | 121 | domaininit(); |
4f083fd7 SL |
122 | #ifdef INET |
123 | splx(s); | |
124 | #endif | |
1d348849 | 125 | pqinit(); |
c4708522 | 126 | ihinit(); |
0d5a507c | 127 | bhinit(); |
c4708522 BJ |
128 | binit(); |
129 | bswinit(); | |
f93197fc | 130 | nchinit(); |
e6254ffb BJ |
131 | #ifdef GPROF |
132 | kmstartup(); | |
133 | #endif | |
9d6d37ce | 134 | |
55b76399 | 135 | fs = mountfs(rootdev, 0, (struct inode *)0); |
9d6d37ce BJ |
136 | if (fs == 0) |
137 | panic("iinit"); | |
138 | bcopy("/", fs->fs_fsmnt, 2); | |
27b91f59 | 139 | |
c70d0a8b | 140 | inittodr(fs->fs_time); |
d3003a84 | 141 | boottime = time; |
9d6d37ce | 142 | |
27b91f59 BJ |
143 | /* kick off timeout driven events by calling first time */ |
144 | roundrobin(); | |
145 | schedcpu(); | |
146 | schedpaging(); | |
147 | ||
148 | /* set up the root file system */ | |
9d6d37ce BJ |
149 | rootdir = iget(rootdev, fs, (ino_t)ROOTINO); |
150 | iunlock(rootdir); | |
151 | u.u_cdir = iget(rootdev, fs, (ino_t)ROOTINO); | |
152 | iunlock(u.u_cdir); | |
c4708522 | 153 | u.u_rdir = NULL; |
27b91f59 | 154 | |
c4708522 BJ |
155 | u.u_dmap = zdmap; |
156 | u.u_smap = zdmap; | |
157 | ||
28c7a4c5 MK |
158 | /* |
159 | * make init process | |
160 | */ | |
161 | ||
162 | proc[0].p_szpt = CLSIZE; | |
163 | if (newproc(0)) { | |
164 | expand(clrnd((int)btoc(szicode)), 0); | |
165 | (void) swpexpand(u.u_dsize, 0, &u.u_dmap, &u.u_smap); | |
166 | (void) copyout((caddr_t)icode, (caddr_t)0, (unsigned)szicode); | |
167 | /* | |
168 | * Return goes to loc. 0 of user init | |
169 | * code just copied out. | |
170 | */ | |
171 | return; | |
172 | } | |
c4708522 BJ |
173 | /* |
174 | * make page-out daemon (process 2) | |
c34926db | 175 | * the daemon has ctopt(nswbuf*CLSIZE*KLMAX) pages of page |
c4708522 BJ |
176 | * table so that it can map dirty pages into |
177 | * its address space during asychronous pushes. | |
178 | */ | |
c34926db | 179 | proc[0].p_szpt = clrnd(ctopt(nswbuf*CLSIZE*KLMAX + UPAGES)); |
c4708522 BJ |
180 | if (newproc(0)) { |
181 | proc[2].p_flag |= SLOAD|SSYS; | |
c34926db | 182 | proc[2].p_dsize = u.u_dsize = nswbuf*CLSIZE*KLMAX; |
c4708522 | 183 | pageout(); |
b7892118 | 184 | /*NOTREACHED*/ |
c4708522 BJ |
185 | } |
186 | ||
187 | /* | |
c4708522 BJ |
188 | * enter scheduling loop |
189 | */ | |
c4708522 BJ |
190 | proc[0].p_szpt = 1; |
191 | sched(); | |
192 | } | |
193 | ||
94d38c1e KM |
194 | /* |
195 | * Initialize hash links for buffers. | |
196 | */ | |
197 | bhinit() | |
198 | { | |
199 | register int i; | |
200 | register struct bufhd *bp; | |
201 | ||
202 | for (bp = bufhash, i = 0; i < BUFHSZ; i++, bp++) | |
203 | bp->b_forw = bp->b_back = (struct buf *)bp; | |
c4708522 BJ |
204 | } |
205 | ||
c4708522 BJ |
206 | /* |
207 | * Initialize the buffer I/O system by freeing | |
208 | * all buffers and setting all device buffer lists to empty. | |
c4708522 BJ |
209 | */ |
210 | binit() | |
211 | { | |
21c39d9c | 212 | register struct buf *bp, *dp; |
c4708522 | 213 | register int i; |
41888f16 | 214 | struct swdevt *swp; |
af371633 | 215 | int base, residual; |
c4708522 | 216 | |
63e97a1d BJ |
217 | for (dp = bfreelist; dp < &bfreelist[BQUEUES]; dp++) { |
218 | dp->b_forw = dp->b_back = dp->av_forw = dp->av_back = dp; | |
219 | dp->b_flags = B_HEAD; | |
220 | } | |
af371633 KM |
221 | base = bufpages / nbuf; |
222 | residual = bufpages % nbuf; | |
6459ebe0 | 223 | for (i = 0; i < nbuf; i++) { |
c4708522 BJ |
224 | bp = &buf[i]; |
225 | bp->b_dev = NODEV; | |
4f083fd7 | 226 | bp->b_bcount = 0; |
6459ebe0 | 227 | bp->b_un.b_addr = buffers + i * MAXBSIZE; |
af371633 KM |
228 | if (i < residual) |
229 | bp->b_bufsize = (base + 1) * CLBYTES; | |
230 | else | |
231 | bp->b_bufsize = base * CLBYTES; | |
961945a8 | 232 | binshash(bp, &bfreelist[BQ_AGE]); |
63e97a1d | 233 | bp->b_flags = B_BUSY|B_INVAL; |
c4708522 BJ |
234 | brelse(bp); |
235 | } | |
41888f16 BJ |
236 | /* |
237 | * Count swap devices, and adjust total swap space available. | |
238 | * Some of this space will not be available until a vswapon() | |
239 | * system is issued, usually when the system goes multi-user. | |
240 | */ | |
241 | nswdev = 0; | |
d668d9ba SL |
242 | nswap = 0; |
243 | for (swp = swdevt; swp->sw_dev; swp++) { | |
41888f16 | 244 | nswdev++; |
d668d9ba SL |
245 | if (swp->sw_nblks > nswap) |
246 | nswap = swp->sw_nblks; | |
247 | } | |
41888f16 BJ |
248 | if (nswdev == 0) |
249 | panic("binit"); | |
b2fdd14d | 250 | if (nswdev > 1) |
d668d9ba | 251 | nswap = ((nswap + dmmax - 1) / dmmax) * dmmax; |
41888f16 BJ |
252 | nswap *= nswdev; |
253 | maxpgio *= nswdev; | |
254 | swfree(0); | |
c4708522 BJ |
255 | } |
256 | ||
257 | /* | |
258 | * Initialize linked list of free swap | |
259 | * headers. These do not actually point | |
260 | * to buffers, but rather to pages that | |
261 | * are being swapped in and out. | |
262 | */ | |
263 | bswinit() | |
264 | { | |
265 | register int i; | |
0a34b6fd | 266 | register struct buf *sp = swbuf; |
c4708522 | 267 | |
c34926db | 268 | bswlist.av_forw = sp; |
0a34b6fd | 269 | for (i=0; i<nswbuf-1; i++, sp++) |
c34926db BJ |
270 | sp->av_forw = sp+1; |
271 | sp->av_forw = NULL; | |
c4708522 | 272 | } |
e7c7d88e BJ |
273 | |
274 | /* | |
275 | * Initialize clist by freeing all character blocks, then count | |
276 | * number of character devices. (Once-only routine) | |
277 | */ | |
278 | cinit() | |
279 | { | |
280 | register int ccp; | |
281 | register struct cblock *cp; | |
e7c7d88e BJ |
282 | |
283 | ccp = (int)cfree; | |
284 | ccp = (ccp+CROUND) & ~CROUND; | |
285 | for(cp=(struct cblock *)ccp; cp < &cfree[nclist-1]; cp++) { | |
286 | cp->c_next = cfreelist; | |
287 | cfreelist = cp; | |
288 | cfreecount += CBSIZE; | |
289 | } | |
e7c7d88e | 290 | } |