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