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