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