Commit | Line | Data |
---|---|---|
5b564702 | 1 | /* init_main.c 4.5 %G% */ |
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" |
c4708522 BJ |
22 | |
23 | /* | |
24 | * Initialization code. | |
25 | * Called from cold start routine as | |
26 | * soon as a stack and segmentation | |
27 | * have been established. | |
28 | * Functions: | |
29 | * clear and free user core | |
30 | * turn on clock | |
31 | * hand craft 0th process | |
32 | * call all initialization routines | |
33 | * fork - process 0 to schedule | |
34 | * - process 2 to page out | |
35 | * - process 1 execute bootstrap | |
36 | * | |
37 | * loop at loc 13 (0xd) in user mode -- /etc/init | |
38 | * cannot be executed. | |
39 | */ | |
40 | main(firstaddr) | |
41 | { | |
73248996 | 42 | register int i; |
c4708522 | 43 | |
c4708522 BJ |
44 | #ifdef FASTVAX |
45 | rqinit(); | |
46 | #endif | |
47 | startup(firstaddr); | |
48 | if (lotsfree == 0) | |
49 | lotsfree = LOTSFREE; | |
50 | ||
51 | /* | |
52 | * set up system process 0 (swapper) | |
53 | */ | |
54 | ||
55 | proc[0].p_p0br = (struct pte *)mfpr(P0BR); | |
56 | proc[0].p_szpt = 1; | |
57 | proc[0].p_addr = uaddr(&proc[0]); | |
58 | proc[0].p_stat = SRUN; | |
59 | proc[0].p_flag |= SLOAD|SSYS; | |
60 | proc[0].p_nice = NZERO; | |
61 | u.u_procp = &proc[0]; | |
62 | u.u_cmask = CMASK; | |
73248996 | 63 | for (i = 1; i < sizeof(u.u_limit)/sizeof(u.u_limit[0]); i++) |
403556fe BJ |
64 | switch (i) { |
65 | ||
66 | case LIM_STACK: | |
67 | u.u_limit[i] = 512*1024; | |
68 | continue; | |
69 | case LIM_DATA: | |
70 | u.u_limit[i] = ctob(MAXDSIZ); | |
71 | continue; | |
72 | default: | |
73 | u.u_limit[i] = INFINITY; | |
74 | continue; | |
75 | } | |
c4708522 BJ |
76 | clkstart(); |
77 | ||
78 | /* | |
79 | * Initialize devices and | |
80 | * set up 'known' i-nodes | |
81 | */ | |
82 | ||
83 | ihinit(); | |
0d5a507c | 84 | bhinit(); |
c4708522 BJ |
85 | cinit(); |
86 | binit(); | |
87 | bswinit(); | |
88 | iinit(); | |
89 | rootdir = iget(rootdev, (ino_t)ROOTINO); | |
90 | rootdir->i_flag &= ~ILOCK; | |
91 | u.u_cdir = iget(rootdev, (ino_t)ROOTINO); | |
92 | u.u_cdir->i_flag &= ~ILOCK; | |
93 | u.u_rdir = NULL; | |
94 | u.u_dmap = zdmap; | |
95 | u.u_smap = zdmap; | |
96 | ||
97 | /* | |
98 | * make page-out daemon (process 2) | |
99 | * the daemon has ctopt(NSWBUF*CLSIZE*KLMAX) pages of page | |
100 | * table so that it can map dirty pages into | |
101 | * its address space during asychronous pushes. | |
102 | */ | |
103 | ||
104 | mpid = 1; | |
105 | proc[0].p_szpt = clrnd(ctopt(NSWBUF*CLSIZE*KLMAX + UPAGES)); | |
106 | proc[1].p_stat = SZOMB; /* force it to be in proc slot 2 */ | |
107 | if (newproc(0)) { | |
108 | proc[2].p_flag |= SLOAD|SSYS; | |
109 | proc[2].p_dsize = u.u_dsize = NSWBUF*CLSIZE*KLMAX; | |
110 | pageout(); | |
111 | } | |
112 | ||
113 | /* | |
114 | * make init process and | |
115 | * enter scheduling loop | |
116 | */ | |
117 | ||
118 | mpid = 0; | |
119 | proc[1].p_stat = 0; | |
120 | proc[0].p_szpt = CLSIZE; | |
121 | if (newproc(0)) { | |
122 | expand(clrnd((int)btoc(szicode)), P0BR); | |
934e4ecf | 123 | (void) swpexpand(u.u_dsize, 0, &u.u_dmap, &u.u_smap); |
81263dba | 124 | (void) copyout((caddr_t)icode, (caddr_t)0, (unsigned)szicode); |
c4708522 BJ |
125 | /* |
126 | * Return goes to loc. 0 of user init | |
127 | * code just copied out. | |
128 | */ | |
129 | return; | |
130 | } | |
131 | proc[0].p_szpt = 1; | |
132 | sched(); | |
133 | } | |
134 | ||
135 | /* | |
136 | * iinit is called once (from main) | |
137 | * very early in initialization. | |
138 | * It reads the root's super block | |
139 | * and initializes the current date | |
140 | * from the last modified date. | |
141 | * | |
142 | * panic: iinit -- cannot read the super | |
143 | * block. Usually because of an IO error. | |
144 | */ | |
145 | iinit() | |
146 | { | |
5b564702 | 147 | register struct buf *bp; |
c4708522 | 148 | register struct filsys *fp; |
c4708522 BJ |
149 | |
150 | (*bdevsw[major(rootdev)].d_open)(rootdev, 1); | |
151 | bp = bread(rootdev, SUPERB); | |
c4708522 BJ |
152 | if(u.u_error) |
153 | panic("iinit"); | |
63e97a1d | 154 | bp->b_flags |= B_LOCKED; /* block can never be re-used */ |
c4708522 | 155 | brelse(bp); |
c4708522 | 156 | mount[0].m_dev = rootdev; |
63e97a1d BJ |
157 | mount[0].m_bufp = bp; |
158 | fp = bp->b_un.b_filsys; | |
c4708522 BJ |
159 | fp->s_flock = 0; |
160 | fp->s_ilock = 0; | |
161 | fp->s_ronly = 0; | |
162 | fp->s_lasti = 1; | |
163 | fp->s_nbehind = 0; | |
403556fe | 164 | clkinit(fp->s_time); |
c4708522 BJ |
165 | bootime = time; |
166 | } | |
167 | ||
168 | /* | |
169 | * This is the set of buffers proper, whose heads | |
170 | * were declared in buf.h. There can exist buffer | |
171 | * headers not pointing here that are used purely | |
172 | * as arguments to the I/O routines to describe | |
173 | * I/O to be done-- e.g. swap headers swbuf[] for | |
174 | * swapping. | |
a53ab6ba BJ |
175 | * |
176 | * These are actually allocated kernel map slots and space is | |
177 | * allocated in locore.s for them. | |
c4708522 | 178 | */ |
143f81a8 | 179 | char buffers[NBUF][BSIZE]; |
c4708522 BJ |
180 | |
181 | /* | |
182 | * Initialize the buffer I/O system by freeing | |
183 | * all buffers and setting all device buffer lists to empty. | |
c4708522 BJ |
184 | */ |
185 | binit() | |
186 | { | |
187 | register struct buf *bp; | |
188 | register struct buf *dp; | |
189 | register int i; | |
190 | struct bdevsw *bdp; | |
41888f16 | 191 | struct swdevt *swp; |
c4708522 | 192 | |
63e97a1d BJ |
193 | for (dp = bfreelist; dp < &bfreelist[BQUEUES]; dp++) { |
194 | dp->b_forw = dp->b_back = dp->av_forw = dp->av_back = dp; | |
195 | dp->b_flags = B_HEAD; | |
196 | } | |
197 | dp--; /* dp = &bfreelist[BQUEUES-1]; */ | |
c4708522 BJ |
198 | for (i=0; i<NBUF; i++) { |
199 | bp = &buf[i]; | |
200 | bp->b_dev = NODEV; | |
201 | bp->b_un.b_addr = buffers[i]; | |
63e97a1d BJ |
202 | bp->b_back = dp; |
203 | bp->b_forw = dp->b_forw; | |
204 | dp->b_forw->b_back = bp; | |
205 | dp->b_forw = bp; | |
206 | bp->b_flags = B_BUSY|B_INVAL; | |
c4708522 BJ |
207 | brelse(bp); |
208 | } | |
5b564702 | 209 | for (bdp = bdevsw; bdp->d_open; bdp++) |
c4708522 | 210 | nblkdev++; |
41888f16 BJ |
211 | /* |
212 | * Count swap devices, and adjust total swap space available. | |
213 | * Some of this space will not be available until a vswapon() | |
214 | * system is issued, usually when the system goes multi-user. | |
215 | */ | |
216 | nswdev = 0; | |
217 | for (swp = swdevt; swp->sw_dev; swp++) | |
218 | nswdev++; | |
219 | if (nswdev == 0) | |
220 | panic("binit"); | |
221 | nswap *= nswdev; | |
222 | maxpgio *= nswdev; | |
223 | swfree(0); | |
c4708522 BJ |
224 | } |
225 | ||
226 | /* | |
227 | * Initialize linked list of free swap | |
228 | * headers. These do not actually point | |
229 | * to buffers, but rather to pages that | |
230 | * are being swapped in and out. | |
231 | */ | |
232 | bswinit() | |
233 | { | |
234 | register int i; | |
235 | ||
236 | bswlist.av_forw = &swbuf[0]; | |
237 | for (i=0; i<NSWBUF-1; i++) | |
238 | swbuf[i].av_forw = &swbuf[i+1]; | |
239 | swbuf[NSWBUF-1].av_forw = NULL; | |
240 | } |