pmap_bootstrap.c revision 1.15 1 1.15 kleink /* $NetBSD: pmap_bootstrap.c,v 1.15 1998/08/20 08:33:45 kleink Exp $ */
2 1.4 cgd
3 1.1 mycroft /*
4 1.1 mycroft * Copyright (c) 1991, 1993
5 1.1 mycroft * The Regents of the University of California. All rights reserved.
6 1.1 mycroft *
7 1.1 mycroft * This code is derived from software contributed to Berkeley by
8 1.1 mycroft * the Systems Programming Group of the University of Utah Computer
9 1.1 mycroft * Science Department.
10 1.1 mycroft *
11 1.1 mycroft * Redistribution and use in source and binary forms, with or without
12 1.1 mycroft * modification, are permitted provided that the following conditions
13 1.1 mycroft * are met:
14 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
15 1.1 mycroft * notice, this list of conditions and the following disclaimer.
16 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
18 1.1 mycroft * documentation and/or other materials provided with the distribution.
19 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
20 1.1 mycroft * must display the following acknowledgement:
21 1.1 mycroft * This product includes software developed by the University of
22 1.1 mycroft * California, Berkeley and its contributors.
23 1.1 mycroft * 4. Neither the name of the University nor the names of its contributors
24 1.1 mycroft * may be used to endorse or promote products derived from this software
25 1.1 mycroft * without specific prior written permission.
26 1.1 mycroft *
27 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 1.1 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 1.1 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 1.1 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 1.1 mycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 1.1 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 1.1 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 1.1 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 1.1 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 1.1 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 1.1 mycroft * SUCH DAMAGE.
38 1.1 mycroft *
39 1.4 cgd * @(#)pmap_bootstrap.c 8.1 (Berkeley) 6/10/93
40 1.1 mycroft */
41 1.1 mycroft
42 1.1 mycroft #include <sys/param.h>
43 1.11 scottr #include <sys/proc.h>
44 1.11 scottr
45 1.11 scottr #include <machine/frame.h>
46 1.11 scottr #include <machine/cpu.h>
47 1.12 thorpej #include <machine/hp300spu.h>
48 1.11 scottr #include <machine/vmparam.h>
49 1.1 mycroft #include <machine/pte.h>
50 1.11 scottr
51 1.1 mycroft #include <hp300/hp300/clockreg.h>
52 1.1 mycroft
53 1.1 mycroft #include <vm/vm.h>
54 1.11 scottr #include <vm/pmap.h>
55 1.1 mycroft
56 1.1 mycroft #define RELOC(v, t) *((t*)((u_int)&(v) + firstpa))
57 1.1 mycroft
58 1.1 mycroft extern char *etext;
59 1.1 mycroft extern int Sysptsize;
60 1.1 mycroft extern char *extiobase, *proc0paddr;
61 1.3 mycroft extern st_entry_t *Sysseg;
62 1.3 mycroft extern pt_entry_t *Sysptmap, *Sysmap;
63 1.15 kleink extern vaddr_t CLKbase, MMUbase;
64 1.15 kleink extern paddr_t pagezero;
65 1.1 mycroft
66 1.1 mycroft extern int maxmem, physmem;
67 1.15 kleink extern paddr_t avail_start, avail_end;
68 1.15 kleink extern vaddr_t virtual_avail, virtual_end;
69 1.15 kleink extern vsize_t mem_size;
70 1.1 mycroft extern int protection_codes[];
71 1.9 thorpej #ifdef M68K_MMU_HP
72 1.1 mycroft extern int pmap_aliasmask;
73 1.1 mycroft #endif
74 1.1 mycroft
75 1.15 kleink void pmap_bootstrap __P((paddr_t, paddr_t));
76 1.11 scottr
77 1.1 mycroft /*
78 1.1 mycroft * Special purpose kernel virtual addresses, used for mapping
79 1.1 mycroft * physical pages for a variety of temporary or permanent purposes:
80 1.1 mycroft *
81 1.1 mycroft * CADDR1, CADDR2: pmap zero/copy operations
82 1.1 mycroft * vmmap: /dev/mem, crash dumps, parity error checking
83 1.1 mycroft * ledbase: SPU LEDs
84 1.14 leo * msgbufaddr: kernel message buffer
85 1.1 mycroft */
86 1.1 mycroft caddr_t CADDR1, CADDR2, vmmap, ledbase;
87 1.14 leo extern caddr_t msgbufaddr;
88 1.1 mycroft
89 1.1 mycroft /*
90 1.1 mycroft * Bootstrap the VM system.
91 1.1 mycroft *
92 1.1 mycroft * Called with MMU off so we must relocate all global references by `firstpa'
93 1.1 mycroft * (don't call any functions here!) `nextpa' is the first available physical
94 1.1 mycroft * memory address. Returns an updated first PA reflecting the memory we
95 1.1 mycroft * have allocated. MMU is still off when we return.
96 1.1 mycroft *
97 1.3 mycroft * XXX assumes sizeof(u_int) == sizeof(pt_entry_t)
98 1.1 mycroft * XXX a PIC compiler would make this much easier.
99 1.1 mycroft */
100 1.1 mycroft void
101 1.1 mycroft pmap_bootstrap(nextpa, firstpa)
102 1.15 kleink paddr_t nextpa;
103 1.15 kleink paddr_t firstpa;
104 1.1 mycroft {
105 1.15 kleink paddr_t kstpa, kptpa, iiopa, eiopa, kptmpa, lkptpa, p0upa;
106 1.1 mycroft u_int nptpages, kstsize;
107 1.11 scottr st_entry_t protoste, *ste;
108 1.11 scottr pt_entry_t protopte, *pte, *epte;
109 1.1 mycroft
110 1.1 mycroft /*
111 1.1 mycroft * Calculate important physical addresses:
112 1.1 mycroft *
113 1.1 mycroft * kstpa kernel segment table 1 page (!040)
114 1.1 mycroft * N pages (040)
115 1.1 mycroft *
116 1.1 mycroft * kptpa statically allocated
117 1.1 mycroft * kernel PT pages Sysptsize+ pages
118 1.1 mycroft *
119 1.1 mycroft * iiopa internal IO space
120 1.1 mycroft * PT pages IIOMAPSIZE pages
121 1.1 mycroft *
122 1.1 mycroft * eiopa external IO space
123 1.1 mycroft * PT pages EIOMAPSIZE pages
124 1.1 mycroft *
125 1.1 mycroft * [ Sysptsize is the number of pages of PT, IIOMAPSIZE and
126 1.1 mycroft * EIOMAPSIZE are the number of PTEs, hence we need to round
127 1.1 mycroft * the total to a page boundary with IO maps at the end. ]
128 1.1 mycroft *
129 1.1 mycroft * kptmpa kernel PT map 1 page
130 1.1 mycroft *
131 1.1 mycroft * lkptpa last kernel PT page 1 page
132 1.1 mycroft *
133 1.1 mycroft * p0upa proc 0 u-area UPAGES pages
134 1.1 mycroft *
135 1.1 mycroft * The KVA corresponding to any of these PAs is:
136 1.1 mycroft * (PA - firstpa + KERNBASE).
137 1.1 mycroft */
138 1.1 mycroft if (RELOC(mmutype, int) == MMU_68040)
139 1.1 mycroft kstsize = MAXKL2SIZE / (NPTEPG/SG4_LEV2SIZE);
140 1.1 mycroft else
141 1.1 mycroft kstsize = 1;
142 1.1 mycroft kstpa = nextpa;
143 1.1 mycroft nextpa += kstsize * NBPG;
144 1.1 mycroft kptpa = nextpa;
145 1.1 mycroft nptpages = RELOC(Sysptsize, int) +
146 1.1 mycroft (IIOMAPSIZE + EIOMAPSIZE + NPTEPG - 1) / NPTEPG;
147 1.1 mycroft nextpa += nptpages * NBPG;
148 1.3 mycroft eiopa = nextpa - EIOMAPSIZE * sizeof(pt_entry_t);
149 1.3 mycroft iiopa = eiopa - IIOMAPSIZE * sizeof(pt_entry_t);
150 1.1 mycroft kptmpa = nextpa;
151 1.1 mycroft nextpa += NBPG;
152 1.1 mycroft lkptpa = nextpa;
153 1.1 mycroft nextpa += NBPG;
154 1.1 mycroft p0upa = nextpa;
155 1.5 mycroft nextpa += USPACE;
156 1.1 mycroft
157 1.1 mycroft /*
158 1.1 mycroft * Initialize segment table and kernel page table map.
159 1.1 mycroft *
160 1.1 mycroft * On 68030s and earlier MMUs the two are identical except for
161 1.1 mycroft * the valid bits so both are initialized with essentially the
162 1.1 mycroft * same values. On the 68040, which has a mandatory 3-level
163 1.1 mycroft * structure, the segment table holds the level 1 table and part
164 1.1 mycroft * (or all) of the level 2 table and hence is considerably
165 1.1 mycroft * different. Here the first level consists of 128 descriptors
166 1.1 mycroft * (512 bytes) each mapping 32mb of address space. Each of these
167 1.1 mycroft * points to blocks of 128 second level descriptors (512 bytes)
168 1.1 mycroft * each mapping 256kb. Note that there may be additional "segment
169 1.1 mycroft * table" pages depending on how large MAXKL2SIZE is.
170 1.1 mycroft *
171 1.1 mycroft * Portions of the last segment of KVA space (0xFFF00000 -
172 1.1 mycroft * 0xFFFFFFFF) are mapped for a couple of purposes. 0xFFF00000
173 1.1 mycroft * for UPAGES is used for mapping the current process u-area
174 1.1 mycroft * (u + kernel stack). The very last page (0xFFFFF000) is mapped
175 1.1 mycroft * to the last physical page of RAM to give us a region in which
176 1.1 mycroft * PA == VA. We use the first part of this page for enabling
177 1.1 mycroft * and disabling mapping. The last part of this page also contains
178 1.1 mycroft * info left by the boot ROM.
179 1.1 mycroft *
180 1.1 mycroft * XXX cramming two levels of mapping into the single "segment"
181 1.1 mycroft * table on the 68040 is intended as a temporary hack to get things
182 1.1 mycroft * working. The 224mb of address space that this allows will most
183 1.1 mycroft * likely be insufficient in the future (at least for the kernel).
184 1.1 mycroft */
185 1.1 mycroft if (RELOC(mmutype, int) == MMU_68040) {
186 1.11 scottr int num;
187 1.1 mycroft
188 1.1 mycroft /*
189 1.1 mycroft * First invalidate the entire "segment table" pages
190 1.1 mycroft * (levels 1 and 2 have the same "invalid" value).
191 1.1 mycroft */
192 1.1 mycroft pte = (u_int *)kstpa;
193 1.1 mycroft epte = &pte[kstsize * NPTEPG];
194 1.1 mycroft while (pte < epte)
195 1.1 mycroft *pte++ = SG_NV;
196 1.1 mycroft /*
197 1.1 mycroft * Initialize level 2 descriptors (which immediately
198 1.1 mycroft * follow the level 1 table). We need:
199 1.1 mycroft * NPTEPG / SG4_LEV3SIZE
200 1.1 mycroft * level 2 descriptors to map each of the nptpages+1
201 1.1 mycroft * pages of PTEs. Note that we set the "used" bit
202 1.1 mycroft * now to save the HW the expense of doing it.
203 1.1 mycroft */
204 1.1 mycroft num = (nptpages + 1) * (NPTEPG / SG4_LEV3SIZE);
205 1.1 mycroft pte = &((u_int *)kstpa)[SG4_LEV1SIZE];
206 1.1 mycroft epte = &pte[num];
207 1.1 mycroft protoste = kptpa | SG_U | SG_RW | SG_V;
208 1.1 mycroft while (pte < epte) {
209 1.1 mycroft *pte++ = protoste;
210 1.3 mycroft protoste += (SG4_LEV3SIZE * sizeof(st_entry_t));
211 1.1 mycroft }
212 1.1 mycroft /*
213 1.1 mycroft * Initialize level 1 descriptors. We need:
214 1.1 mycroft * roundup(num, SG4_LEV2SIZE) / SG4_LEV2SIZE
215 1.1 mycroft * level 1 descriptors to map the `num' level 2's.
216 1.1 mycroft */
217 1.1 mycroft pte = (u_int *)kstpa;
218 1.1 mycroft epte = &pte[roundup(num, SG4_LEV2SIZE) / SG4_LEV2SIZE];
219 1.1 mycroft protoste = (u_int)&pte[SG4_LEV1SIZE] | SG_U | SG_RW | SG_V;
220 1.1 mycroft while (pte < epte) {
221 1.1 mycroft *pte++ = protoste;
222 1.3 mycroft protoste += (SG4_LEV2SIZE * sizeof(st_entry_t));
223 1.1 mycroft }
224 1.1 mycroft /*
225 1.1 mycroft * Initialize the final level 1 descriptor to map the last
226 1.1 mycroft * block of level 2 descriptors.
227 1.1 mycroft */
228 1.1 mycroft ste = &((u_int *)kstpa)[SG4_LEV1SIZE-1];
229 1.1 mycroft pte = &((u_int *)kstpa)[kstsize*NPTEPG - SG4_LEV2SIZE];
230 1.1 mycroft *ste = (u_int)pte | SG_U | SG_RW | SG_V;
231 1.1 mycroft /*
232 1.1 mycroft * Now initialize the final portion of that block of
233 1.1 mycroft * descriptors to map the "last PT page".
234 1.1 mycroft */
235 1.1 mycroft pte = &((u_int *)kstpa)[kstsize*NPTEPG - NPTEPG/SG4_LEV3SIZE];
236 1.1 mycroft epte = &pte[NPTEPG/SG4_LEV3SIZE];
237 1.1 mycroft protoste = lkptpa | SG_U | SG_RW | SG_V;
238 1.1 mycroft while (pte < epte) {
239 1.1 mycroft *pte++ = protoste;
240 1.3 mycroft protoste += (SG4_LEV3SIZE * sizeof(st_entry_t));
241 1.1 mycroft }
242 1.1 mycroft /*
243 1.1 mycroft * Initialize Sysptmap
244 1.1 mycroft */
245 1.1 mycroft pte = (u_int *)kptmpa;
246 1.1 mycroft epte = &pte[nptpages+1];
247 1.1 mycroft protopte = kptpa | PG_RW | PG_CI | PG_V;
248 1.1 mycroft while (pte < epte) {
249 1.1 mycroft *pte++ = protopte;
250 1.1 mycroft protopte += NBPG;
251 1.1 mycroft }
252 1.7 thorpej /*
253 1.7 thorpej * Invalidate all but the last remaining entry.
254 1.7 thorpej */
255 1.7 thorpej epte = &((u_int *)kptmpa)[NPTEPG-1];
256 1.7 thorpej while (pte < epte) {
257 1.7 thorpej *pte++ = PG_NV;
258 1.7 thorpej }
259 1.10 thorpej /*
260 1.10 thorpej * Initialize the last to point to the page
261 1.7 thorpej * table page allocated earlier.
262 1.7 thorpej */
263 1.1 mycroft *pte = lkptpa | PG_RW | PG_CI | PG_V;
264 1.1 mycroft } else {
265 1.1 mycroft /*
266 1.1 mycroft * Map the page table pages in both the HW segment table
267 1.1 mycroft * and the software Sysptmap. Note that Sysptmap is also
268 1.1 mycroft * considered a PT page hence the +1.
269 1.1 mycroft */
270 1.1 mycroft ste = (u_int *)kstpa;
271 1.1 mycroft pte = (u_int *)kptmpa;
272 1.1 mycroft epte = &pte[nptpages+1];
273 1.1 mycroft protoste = kptpa | SG_RW | SG_V;
274 1.1 mycroft protopte = kptpa | PG_RW | PG_CI | PG_V;
275 1.1 mycroft while (pte < epte) {
276 1.1 mycroft *ste++ = protoste;
277 1.1 mycroft *pte++ = protopte;
278 1.1 mycroft protoste += NBPG;
279 1.1 mycroft protopte += NBPG;
280 1.1 mycroft }
281 1.1 mycroft /*
282 1.1 mycroft * Invalidate all but the last remaining entries in both.
283 1.1 mycroft */
284 1.1 mycroft epte = &((u_int *)kptmpa)[NPTEPG-1];
285 1.1 mycroft while (pte < epte) {
286 1.1 mycroft *ste++ = SG_NV;
287 1.1 mycroft *pte++ = PG_NV;
288 1.1 mycroft }
289 1.1 mycroft /*
290 1.1 mycroft * Initialize the last to point to point to the page
291 1.1 mycroft * table page allocated earlier.
292 1.1 mycroft */
293 1.1 mycroft *ste = lkptpa | SG_RW | SG_V;
294 1.1 mycroft *pte = lkptpa | PG_RW | PG_CI | PG_V;
295 1.1 mycroft }
296 1.1 mycroft /*
297 1.1 mycroft * Invalidate all but the final entry in the last kernel PT page
298 1.1 mycroft * (u-area PTEs will be validated later). The final entry maps
299 1.1 mycroft * the last page of physical memory.
300 1.1 mycroft */
301 1.1 mycroft pte = (u_int *)lkptpa;
302 1.1 mycroft epte = &pte[NPTEPG-1];
303 1.1 mycroft while (pte < epte)
304 1.1 mycroft *pte++ = PG_NV;
305 1.1 mycroft *pte = MAXADDR | PG_RW | PG_CI | PG_V;
306 1.1 mycroft /*
307 1.1 mycroft * Initialize kernel page table.
308 1.1 mycroft * Start by invalidating the `nptpages' that we have allocated.
309 1.1 mycroft */
310 1.1 mycroft pte = (u_int *)kptpa;
311 1.1 mycroft epte = &pte[nptpages * NPTEPG];
312 1.1 mycroft while (pte < epte)
313 1.1 mycroft *pte++ = PG_NV;
314 1.10 thorpej
315 1.1 mycroft /*
316 1.10 thorpej * Save the physical address of `page zero'. This is
317 1.10 thorpej * a page of memory at the beginning of kernel text
318 1.10 thorpej * not mapped at VA 0. But, we might want to use it
319 1.10 thorpej * for something later.
320 1.1 mycroft */
321 1.15 kleink RELOC(pagezero, paddr_t) = firstpa;
322 1.10 thorpej
323 1.10 thorpej /*
324 1.10 thorpej * Validate PTEs for kernel text (RO). The first page
325 1.10 thorpej * of kernel text remains invalid; see locore.s
326 1.10 thorpej */
327 1.13 veego pte = &((u_int *)kptpa)[m68k_btop(KERNBASE + NBPG)];
328 1.13 veego epte = &pte[m68k_btop(m68k_trunc_page(&etext))];
329 1.10 thorpej protopte = (firstpa + NBPG) | PG_RO | PG_V;
330 1.1 mycroft while (pte < epte) {
331 1.1 mycroft *pte++ = protopte;
332 1.1 mycroft protopte += NBPG;
333 1.1 mycroft }
334 1.1 mycroft /*
335 1.1 mycroft * Validate PTEs for kernel data/bss, dynamic data allocated
336 1.1 mycroft * by us so far (nextpa - firstpa bytes), and pages for proc0
337 1.1 mycroft * u-area and page table allocated below (RW).
338 1.1 mycroft */
339 1.13 veego epte = &((u_int *)kptpa)[m68k_btop(nextpa - firstpa)];
340 1.1 mycroft protopte = (protopte & ~PG_PROT) | PG_RW;
341 1.1 mycroft /*
342 1.1 mycroft * Enable copy-back caching of data pages
343 1.1 mycroft */
344 1.1 mycroft if (RELOC(mmutype, int) == MMU_68040)
345 1.1 mycroft protopte |= PG_CCB;
346 1.1 mycroft while (pte < epte) {
347 1.1 mycroft *pte++ = protopte;
348 1.1 mycroft protopte += NBPG;
349 1.1 mycroft }
350 1.1 mycroft /*
351 1.1 mycroft * Finally, validate the internal IO space PTEs (RW+CI).
352 1.1 mycroft * We do this here since the 320/350 MMU registers (also
353 1.1 mycroft * used, but to a lesser extent, on other models) are mapped
354 1.1 mycroft * in this range and it would be nice to be able to access
355 1.1 mycroft * them after the MMU is turned on.
356 1.1 mycroft */
357 1.1 mycroft pte = (u_int *)iiopa;
358 1.1 mycroft epte = (u_int *)eiopa;
359 1.1 mycroft protopte = INTIOBASE | PG_RW | PG_CI | PG_V;
360 1.1 mycroft while (pte < epte) {
361 1.1 mycroft *pte++ = protopte;
362 1.1 mycroft protopte += NBPG;
363 1.1 mycroft }
364 1.1 mycroft
365 1.1 mycroft /*
366 1.1 mycroft * Calculate important exported kernel virtual addresses
367 1.1 mycroft */
368 1.1 mycroft /*
369 1.1 mycroft * Sysseg: base of kernel segment table
370 1.1 mycroft */
371 1.3 mycroft RELOC(Sysseg, st_entry_t *) =
372 1.3 mycroft (st_entry_t *)(kstpa - firstpa);
373 1.1 mycroft /*
374 1.1 mycroft * Sysptmap: base of kernel page table map
375 1.1 mycroft */
376 1.3 mycroft RELOC(Sysptmap, pt_entry_t *) =
377 1.3 mycroft (pt_entry_t *)(kptmpa - firstpa);
378 1.1 mycroft /*
379 1.1 mycroft * Sysmap: kernel page table (as mapped through Sysptmap)
380 1.1 mycroft * Immediately follows `nptpages' of static kernel page table.
381 1.1 mycroft */
382 1.3 mycroft RELOC(Sysmap, pt_entry_t *) =
383 1.13 veego (pt_entry_t *)m68k_ptob(nptpages * NPTEPG);
384 1.1 mycroft /*
385 1.1 mycroft * intiobase, intiolimit: base and end of internal (DIO) IO space.
386 1.1 mycroft * IIOMAPSIZE pages prior to external IO space at end of static
387 1.1 mycroft * kernel page table.
388 1.1 mycroft */
389 1.1 mycroft RELOC(intiobase, char *) =
390 1.13 veego (char *)m68k_ptob(nptpages*NPTEPG - (IIOMAPSIZE+EIOMAPSIZE));
391 1.1 mycroft RELOC(intiolimit, char *) =
392 1.13 veego (char *)m68k_ptob(nptpages*NPTEPG - EIOMAPSIZE);
393 1.1 mycroft /*
394 1.1 mycroft * extiobase: base of external (DIO-II) IO space.
395 1.1 mycroft * EIOMAPSIZE pages at the end of the static kernel page table.
396 1.1 mycroft */
397 1.1 mycroft RELOC(extiobase, char *) =
398 1.13 veego (char *)m68k_ptob(nptpages*NPTEPG - EIOMAPSIZE);
399 1.1 mycroft /*
400 1.1 mycroft * CLKbase, MMUbase: important registers in internal IO space
401 1.1 mycroft * accessed from assembly language.
402 1.1 mycroft */
403 1.15 kleink RELOC(CLKbase, vaddr_t) =
404 1.15 kleink (vaddr_t)RELOC(intiobase, char *) + CLKBASE;
405 1.15 kleink RELOC(MMUbase, vaddr_t) =
406 1.15 kleink (vaddr_t)RELOC(intiobase, char *) + MMUBASE;
407 1.1 mycroft
408 1.1 mycroft /*
409 1.1 mycroft * Setup u-area for process 0.
410 1.1 mycroft */
411 1.1 mycroft /*
412 1.1 mycroft * Zero the u-area.
413 1.1 mycroft * NOTE: `pte' and `epte' aren't PTEs here.
414 1.1 mycroft */
415 1.1 mycroft pte = (u_int *)p0upa;
416 1.5 mycroft epte = (u_int *)(p0upa + USPACE);
417 1.1 mycroft while (pte < epte)
418 1.1 mycroft *pte++ = 0;
419 1.1 mycroft /*
420 1.1 mycroft * Remember the u-area address so it can be loaded in the
421 1.1 mycroft * proc struct p_addr field later.
422 1.1 mycroft */
423 1.1 mycroft RELOC(proc0paddr, char *) = (char *)(p0upa - firstpa);
424 1.1 mycroft
425 1.1 mycroft /*
426 1.1 mycroft * VM data structures are now initialized, set up data for
427 1.1 mycroft * the pmap module.
428 1.8 thorpej *
429 1.8 thorpej * Note about avail_end: msgbuf is initialized just after
430 1.8 thorpej * avail_end in machdep.c. Since the last page is used
431 1.8 thorpej * for rebooting the system (code is copied there and
432 1.8 thorpej * excution continues from copied code before the MMU
433 1.8 thorpej * is disabled), the msgbuf will get trounced between
434 1.8 thorpej * reboots if it's placed in the last physical page.
435 1.8 thorpej * To work around this, we move avail_end back one more
436 1.8 thorpej * page so the msgbuf can be preserved.
437 1.1 mycroft */
438 1.15 kleink RELOC(avail_start, paddr_t) = nextpa;
439 1.15 kleink RELOC(avail_end, paddr_t) = m68k_ptob(RELOC(maxmem, int)) -
440 1.14 leo (m68k_round_page(MSGBUFSIZE) + m68k_ptob(1));
441 1.15 kleink RELOC(mem_size, vsize_t) = m68k_ptob(RELOC(physmem, int));
442 1.15 kleink RELOC(virtual_avail, vaddr_t) =
443 1.1 mycroft VM_MIN_KERNEL_ADDRESS + (nextpa - firstpa);
444 1.15 kleink RELOC(virtual_end, vaddr_t) = VM_MAX_KERNEL_ADDRESS;
445 1.1 mycroft
446 1.9 thorpej #ifdef M68K_MMU_HP
447 1.1 mycroft /*
448 1.1 mycroft * Determine VA aliasing distance if any
449 1.1 mycroft */
450 1.1 mycroft if (RELOC(ectype, int) == EC_VIRT)
451 1.1 mycroft if (RELOC(machineid, int) == HP_320)
452 1.1 mycroft RELOC(pmap_aliasmask, int) = 0x3fff; /* 16k */
453 1.1 mycroft else if (RELOC(machineid, int) == HP_350)
454 1.1 mycroft RELOC(pmap_aliasmask, int) = 0x7fff; /* 32k */
455 1.1 mycroft #endif
456 1.1 mycroft
457 1.1 mycroft /*
458 1.1 mycroft * Initialize protection array.
459 1.1 mycroft * XXX don't use a switch statement, it might produce an
460 1.1 mycroft * absolute "jmp" table.
461 1.1 mycroft */
462 1.1 mycroft {
463 1.11 scottr int *kp;
464 1.1 mycroft
465 1.1 mycroft kp = &RELOC(protection_codes, int);
466 1.1 mycroft kp[VM_PROT_NONE|VM_PROT_NONE|VM_PROT_NONE] = 0;
467 1.1 mycroft kp[VM_PROT_READ|VM_PROT_NONE|VM_PROT_NONE] = PG_RO;
468 1.1 mycroft kp[VM_PROT_READ|VM_PROT_NONE|VM_PROT_EXECUTE] = PG_RO;
469 1.1 mycroft kp[VM_PROT_NONE|VM_PROT_NONE|VM_PROT_EXECUTE] = PG_RO;
470 1.1 mycroft kp[VM_PROT_NONE|VM_PROT_WRITE|VM_PROT_NONE] = PG_RW;
471 1.1 mycroft kp[VM_PROT_NONE|VM_PROT_WRITE|VM_PROT_EXECUTE] = PG_RW;
472 1.1 mycroft kp[VM_PROT_READ|VM_PROT_WRITE|VM_PROT_NONE] = PG_RW;
473 1.1 mycroft kp[VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE] = PG_RW;
474 1.1 mycroft }
475 1.1 mycroft
476 1.1 mycroft /*
477 1.1 mycroft * Kernel page/segment table allocated in locore,
478 1.1 mycroft * just initialize pointers.
479 1.1 mycroft */
480 1.1 mycroft {
481 1.1 mycroft struct pmap *kpm = &RELOC(kernel_pmap_store, struct pmap);
482 1.1 mycroft
483 1.3 mycroft kpm->pm_stab = RELOC(Sysseg, st_entry_t *);
484 1.3 mycroft kpm->pm_ptab = RELOC(Sysmap, pt_entry_t *);
485 1.1 mycroft simple_lock_init(&kpm->pm_lock);
486 1.1 mycroft kpm->pm_count = 1;
487 1.3 mycroft kpm->pm_stpa = (st_entry_t *)kstpa;
488 1.1 mycroft /*
489 1.1 mycroft * For the 040 we also initialize the free level 2
490 1.1 mycroft * descriptor mask noting that we have used:
491 1.1 mycroft * 0: level 1 table
492 1.1 mycroft * 1 to `num': map page tables
493 1.1 mycroft * MAXKL2SIZE-1: maps last-page page table
494 1.1 mycroft */
495 1.1 mycroft if (RELOC(mmutype, int) == MMU_68040) {
496 1.11 scottr int num;
497 1.1 mycroft
498 1.1 mycroft kpm->pm_stfree = ~l2tobm(0);
499 1.1 mycroft num = roundup((nptpages + 1) * (NPTEPG / SG4_LEV3SIZE),
500 1.1 mycroft SG4_LEV2SIZE) / SG4_LEV2SIZE;
501 1.1 mycroft while (num)
502 1.1 mycroft kpm->pm_stfree &= ~l2tobm(num--);
503 1.1 mycroft kpm->pm_stfree &= ~l2tobm(MAXKL2SIZE-1);
504 1.1 mycroft for (num = MAXKL2SIZE;
505 1.1 mycroft num < sizeof(kpm->pm_stfree)*NBBY;
506 1.1 mycroft num++)
507 1.1 mycroft kpm->pm_stfree &= ~l2tobm(num);
508 1.1 mycroft }
509 1.1 mycroft }
510 1.1 mycroft
511 1.1 mycroft /*
512 1.1 mycroft * Allocate some fixed, special purpose kernel virtual addresses
513 1.1 mycroft */
514 1.1 mycroft {
515 1.15 kleink vaddr_t va = RELOC(virtual_avail, vaddr_t);
516 1.1 mycroft
517 1.1 mycroft RELOC(CADDR1, caddr_t) = (caddr_t)va;
518 1.3 mycroft va += NBPG;
519 1.1 mycroft RELOC(CADDR2, caddr_t) = (caddr_t)va;
520 1.3 mycroft va += NBPG;
521 1.1 mycroft RELOC(vmmap, caddr_t) = (caddr_t)va;
522 1.3 mycroft va += NBPG;
523 1.1 mycroft RELOC(ledbase, caddr_t) = (caddr_t)va;
524 1.3 mycroft va += NBPG;
525 1.14 leo RELOC(msgbufaddr, caddr_t) = (caddr_t)va;
526 1.14 leo va += m68k_round_page(MSGBUFSIZE);
527 1.15 kleink RELOC(virtual_avail, vaddr_t) = va;
528 1.1 mycroft }
529 1.1 mycroft }
530