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