pmap_bootstrap.c revision 1.57 1 1.57 mhitch /* $NetBSD: pmap_bootstrap.c,v 1.57 2012/02/10 06:28:39 mhitch 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.57 mhitch __KERNEL_RCSID(0, "$NetBSD: pmap_bootstrap.c,v 1.57 2012/02/10 06:28:39 mhitch Exp $");
40 1.1 mycroft
41 1.1 mycroft #include <sys/param.h>
42 1.50 tsutsui #include <uvm/uvm_extern.h>
43 1.11 scottr
44 1.11 scottr #include <machine/cpu.h>
45 1.12 thorpej #include <machine/hp300spu.h>
46 1.50 tsutsui #include <machine/pte.h>
47 1.11 scottr #include <machine/vmparam.h>
48 1.11 scottr
49 1.1 mycroft #include <hp300/hp300/clockreg.h>
50 1.1 mycroft
51 1.36 tsutsui #define RELOC(v, t) *((t*)((uintptr_t)&(v) + firstpa))
52 1.1 mycroft
53 1.1 mycroft extern char *etext;
54 1.15 kleink extern vaddr_t CLKbase, MMUbase;
55 1.1 mycroft
56 1.1 mycroft extern int maxmem, physmem;
57 1.15 kleink extern paddr_t avail_start, avail_end;
58 1.1 mycroft
59 1.1 mycroft /*
60 1.1 mycroft * Special purpose kernel virtual addresses, used for mapping
61 1.1 mycroft * physical pages for a variety of temporary or permanent purposes:
62 1.1 mycroft *
63 1.1 mycroft * CADDR1, CADDR2: pmap zero/copy operations
64 1.1 mycroft * vmmap: /dev/mem, crash dumps, parity error checking
65 1.50 tsutsui * msgbufaddr: kernel message buffer
66 1.1 mycroft */
67 1.50 tsutsui void *CADDR1, *CADDR2;
68 1.29 tsutsui char *vmmap;
69 1.30 tsutsui void *msgbufaddr;
70 1.50 tsutsui
71 1.50 tsutsui void pmap_bootstrap(paddr_t, paddr_t);
72 1.1 mycroft
73 1.1 mycroft /*
74 1.1 mycroft * Bootstrap the VM system.
75 1.1 mycroft *
76 1.1 mycroft * Called with MMU off so we must relocate all global references by `firstpa'
77 1.1 mycroft * (don't call any functions here!) `nextpa' is the first available physical
78 1.1 mycroft * memory address. Returns an updated first PA reflecting the memory we
79 1.1 mycroft * have allocated. MMU is still off when we return.
80 1.1 mycroft *
81 1.3 mycroft * XXX assumes sizeof(u_int) == sizeof(pt_entry_t)
82 1.1 mycroft * XXX a PIC compiler would make this much easier.
83 1.1 mycroft */
84 1.1 mycroft void
85 1.25 thorpej pmap_bootstrap(paddr_t nextpa, paddr_t firstpa)
86 1.1 mycroft {
87 1.50 tsutsui paddr_t lwp0upa, kstpa, kptmpa, kptpa;
88 1.50 tsutsui paddr_t lkptpa;
89 1.1 mycroft u_int nptpages, kstsize;
90 1.43 tsutsui st_entry_t protoste, *ste, *este;
91 1.11 scottr pt_entry_t protopte, *pte, *epte;
92 1.44 tsutsui u_int stfree = 0; /* XXX: gcc -Wuninitialized */
93 1.1 mycroft
94 1.1 mycroft /*
95 1.1 mycroft * Calculate important physical addresses:
96 1.1 mycroft *
97 1.50 tsutsui * lwp0upa lwp0 u-area UPAGES pages
98 1.42 tsutsui *
99 1.1 mycroft * kstpa kernel segment table 1 page (!040)
100 1.1 mycroft * N pages (040)
101 1.1 mycroft *
102 1.42 tsutsui * kptmpa kernel PT map 1 page
103 1.42 tsutsui *
104 1.42 tsutsui * lkptpa last kernel PT page 1 page
105 1.42 tsutsui *
106 1.1 mycroft * kptpa statically allocated
107 1.1 mycroft * kernel PT pages Sysptsize+ pages
108 1.1 mycroft *
109 1.50 tsutsui * [ Sysptsize is the number of pages of PT, and IIOMAPSIZE and
110 1.1 mycroft * EIOMAPSIZE are the number of PTEs, hence we need to round
111 1.1 mycroft * the total to a page boundary with IO maps at the end. ]
112 1.1 mycroft *
113 1.1 mycroft * The KVA corresponding to any of these PAs is:
114 1.1 mycroft * (PA - firstpa + KERNBASE).
115 1.1 mycroft */
116 1.42 tsutsui lwp0upa = nextpa;
117 1.42 tsutsui nextpa += USPACE;
118 1.1 mycroft if (RELOC(mmutype, int) == MMU_68040)
119 1.1 mycroft kstsize = MAXKL2SIZE / (NPTEPG/SG4_LEV2SIZE);
120 1.1 mycroft else
121 1.1 mycroft kstsize = 1;
122 1.1 mycroft kstpa = nextpa;
123 1.22 thorpej nextpa += kstsize * PAGE_SIZE;
124 1.1 mycroft kptmpa = nextpa;
125 1.22 thorpej nextpa += PAGE_SIZE;
126 1.1 mycroft lkptpa = nextpa;
127 1.22 thorpej nextpa += PAGE_SIZE;
128 1.26 yamt kptpa = nextpa;
129 1.57 mhitch nptpages = RELOC(Sysptsize, int) + howmany(RELOC(physmem, int), NPTEPG) +
130 1.26 yamt (IIOMAPSIZE + EIOMAPSIZE + NPTEPG - 1) / NPTEPG;
131 1.26 yamt nextpa += nptpages * PAGE_SIZE;
132 1.1 mycroft
133 1.1 mycroft /*
134 1.1 mycroft * Initialize segment table and kernel page table map.
135 1.1 mycroft *
136 1.1 mycroft * On 68030s and earlier MMUs the two are identical except for
137 1.1 mycroft * the valid bits so both are initialized with essentially the
138 1.1 mycroft * same values. On the 68040, which has a mandatory 3-level
139 1.1 mycroft * structure, the segment table holds the level 1 table and part
140 1.1 mycroft * (or all) of the level 2 table and hence is considerably
141 1.1 mycroft * different. Here the first level consists of 128 descriptors
142 1.1 mycroft * (512 bytes) each mapping 32mb of address space. Each of these
143 1.1 mycroft * points to blocks of 128 second level descriptors (512 bytes)
144 1.1 mycroft * each mapping 256kb. Note that there may be additional "segment
145 1.1 mycroft * table" pages depending on how large MAXKL2SIZE is.
146 1.1 mycroft *
147 1.35 tsutsui * Portions of the last two segment of KVA space (0xFF800000 -
148 1.35 tsutsui * 0xFFFFFFFF) are mapped for a couple of purposes.
149 1.35 tsutsui * The first segment (0xFF800000 - 0xFFBFFFFF) is mapped
150 1.35 tsutsui * for the kernel page tables.
151 1.35 tsutsui * The very last page (0xFFFFF000) in the second segment is mapped
152 1.1 mycroft * to the last physical page of RAM to give us a region in which
153 1.1 mycroft * PA == VA. We use the first part of this page for enabling
154 1.1 mycroft * and disabling mapping. The last part of this page also contains
155 1.1 mycroft * info left by the boot ROM.
156 1.1 mycroft *
157 1.1 mycroft * XXX cramming two levels of mapping into the single "segment"
158 1.1 mycroft * table on the 68040 is intended as a temporary hack to get things
159 1.1 mycroft * working. The 224mb of address space that this allows will most
160 1.1 mycroft * likely be insufficient in the future (at least for the kernel).
161 1.1 mycroft */
162 1.1 mycroft if (RELOC(mmutype, int) == MMU_68040) {
163 1.44 tsutsui int nl1desc, nl2desc, i;
164 1.1 mycroft
165 1.1 mycroft /*
166 1.1 mycroft * First invalidate the entire "segment table" pages
167 1.1 mycroft * (levels 1 and 2 have the same "invalid" value).
168 1.1 mycroft */
169 1.43 tsutsui ste = (st_entry_t *)kstpa;
170 1.43 tsutsui este = &ste[kstsize * NPTEPG];
171 1.43 tsutsui while (ste < este)
172 1.43 tsutsui *ste++ = SG_NV;
173 1.1 mycroft /*
174 1.1 mycroft * Initialize level 2 descriptors (which immediately
175 1.1 mycroft * follow the level 1 table). We need:
176 1.1 mycroft * NPTEPG / SG4_LEV3SIZE
177 1.26 yamt * level 2 descriptors to map each of the nptpages
178 1.1 mycroft * pages of PTEs. Note that we set the "used" bit
179 1.1 mycroft * now to save the HW the expense of doing it.
180 1.1 mycroft */
181 1.44 tsutsui nl2desc = nptpages * (NPTEPG / SG4_LEV3SIZE);
182 1.43 tsutsui ste = (st_entry_t *)kstpa;
183 1.43 tsutsui ste = &ste[SG4_LEV1SIZE];
184 1.44 tsutsui este = &ste[nl2desc];
185 1.1 mycroft protoste = kptpa | SG_U | SG_RW | SG_V;
186 1.43 tsutsui while (ste < este) {
187 1.43 tsutsui *ste++ = protoste;
188 1.3 mycroft protoste += (SG4_LEV3SIZE * sizeof(st_entry_t));
189 1.1 mycroft }
190 1.1 mycroft /*
191 1.1 mycroft * Initialize level 1 descriptors. We need:
192 1.44 tsutsui * howmany(nl2desc, SG4_LEV2SIZE)
193 1.44 tsutsui * level 1 descriptors to map the `nl2desc' level 2's.
194 1.1 mycroft */
195 1.44 tsutsui nl1desc = howmany(nl2desc, SG4_LEV2SIZE);
196 1.43 tsutsui ste = (st_entry_t *)kstpa;
197 1.44 tsutsui este = &ste[nl1desc];
198 1.43 tsutsui protoste = (paddr_t)&ste[SG4_LEV1SIZE] | SG_U | SG_RW | SG_V;
199 1.43 tsutsui while (ste < este) {
200 1.43 tsutsui *ste++ = protoste;
201 1.3 mycroft protoste += (SG4_LEV2SIZE * sizeof(st_entry_t));
202 1.1 mycroft }
203 1.1 mycroft /*
204 1.44 tsutsui * Initialize the final level 1 descriptor to map the next
205 1.44 tsutsui * block of level 2 descriptors for Sysptmap.
206 1.1 mycroft */
207 1.43 tsutsui ste = (st_entry_t *)kstpa;
208 1.43 tsutsui ste = &ste[SG4_LEV1SIZE - 1];
209 1.44 tsutsui *ste = protoste;
210 1.1 mycroft /*
211 1.1 mycroft * Now initialize the final portion of that block of
212 1.50 tsutsui * descriptors to map Sysmap and the "last PT page".
213 1.1 mycroft */
214 1.44 tsutsui i = SG4_LEV1SIZE + (nl1desc * SG4_LEV2SIZE);
215 1.43 tsutsui ste = (st_entry_t *)kstpa;
216 1.44 tsutsui ste = &ste[i + SG4_LEV2SIZE - (NPTEPG / SG4_LEV3SIZE) * 2];
217 1.43 tsutsui este = &ste[NPTEPG / SG4_LEV3SIZE];
218 1.26 yamt protoste = kptmpa | SG_U | SG_RW | SG_V;
219 1.43 tsutsui while (ste < este) {
220 1.43 tsutsui *ste++ = protoste;
221 1.26 yamt protoste += (SG4_LEV3SIZE * sizeof(st_entry_t));
222 1.26 yamt }
223 1.43 tsutsui este = &ste[NPTEPG / SG4_LEV3SIZE];
224 1.1 mycroft protoste = lkptpa | SG_U | SG_RW | SG_V;
225 1.43 tsutsui while (ste < este) {
226 1.43 tsutsui *ste++ = protoste;
227 1.3 mycroft protoste += (SG4_LEV3SIZE * sizeof(st_entry_t));
228 1.1 mycroft }
229 1.1 mycroft /*
230 1.44 tsutsui * Calculate the free level 2 descriptor mask
231 1.44 tsutsui * noting that we have used:
232 1.44 tsutsui * 0: level 1 table
233 1.44 tsutsui * 1 to nl1desc: map page tables
234 1.44 tsutsui * nl1desc + 1: maps kptmpa and last-page page table
235 1.44 tsutsui */
236 1.44 tsutsui /* mark an entry for level 1 table */
237 1.44 tsutsui stfree = ~l2tobm(0);
238 1.44 tsutsui /* mark entries for map page tables */
239 1.44 tsutsui for (i = 1; i <= nl1desc; i++)
240 1.44 tsutsui stfree &= ~l2tobm(i);
241 1.44 tsutsui /* mark an entry for kptmpa and lkptpa */
242 1.44 tsutsui stfree &= ~l2tobm(i);
243 1.44 tsutsui /* mark entries not available */
244 1.44 tsutsui for (i = MAXKL2SIZE; i < sizeof(stfree) * NBBY; i++)
245 1.44 tsutsui stfree &= ~l2tobm(i);
246 1.44 tsutsui
247 1.44 tsutsui /*
248 1.1 mycroft * Initialize Sysptmap
249 1.1 mycroft */
250 1.43 tsutsui pte = (pt_entry_t *)kptmpa;
251 1.26 yamt epte = &pte[nptpages];
252 1.1 mycroft protopte = kptpa | PG_RW | PG_CI | PG_V;
253 1.1 mycroft while (pte < epte) {
254 1.1 mycroft *pte++ = protopte;
255 1.22 thorpej protopte += PAGE_SIZE;
256 1.1 mycroft }
257 1.7 thorpej /*
258 1.44 tsutsui * Invalidate all remaining entries.
259 1.7 thorpej */
260 1.43 tsutsui epte = (pt_entry_t *)kptmpa;
261 1.46 tsutsui epte = &epte[TIB_SIZE];
262 1.7 thorpej while (pte < epte) {
263 1.7 thorpej *pte++ = PG_NV;
264 1.7 thorpej }
265 1.10 thorpej /*
266 1.50 tsutsui * Initialize the last ones to point to Sysptmap and the page
267 1.7 thorpej * table page allocated earlier.
268 1.7 thorpej */
269 1.44 tsutsui pte = (pt_entry_t *)kptmpa;
270 1.46 tsutsui pte = &pte[SYSMAP_VA >> SEGSHIFT];
271 1.26 yamt *pte = kptmpa | PG_RW | PG_CI | PG_V;
272 1.46 tsutsui pte = (pt_entry_t *)kptmpa;
273 1.46 tsutsui pte = &pte[MAXADDR >> SEGSHIFT];
274 1.1 mycroft *pte = lkptpa | PG_RW | PG_CI | PG_V;
275 1.1 mycroft } else {
276 1.1 mycroft /*
277 1.1 mycroft * Map the page table pages in both the HW segment table
278 1.26 yamt * and the software Sysptmap.
279 1.1 mycroft */
280 1.43 tsutsui ste = (st_entry_t *)kstpa;
281 1.43 tsutsui pte = (pt_entry_t *)kptmpa;
282 1.26 yamt epte = &pte[nptpages];
283 1.1 mycroft protoste = kptpa | SG_RW | SG_V;
284 1.1 mycroft protopte = kptpa | PG_RW | PG_CI | PG_V;
285 1.1 mycroft while (pte < epte) {
286 1.1 mycroft *ste++ = protoste;
287 1.1 mycroft *pte++ = protopte;
288 1.22 thorpej protoste += PAGE_SIZE;
289 1.22 thorpej protopte += PAGE_SIZE;
290 1.1 mycroft }
291 1.1 mycroft /*
292 1.44 tsutsui * Invalidate all remaining entries in both.
293 1.1 mycroft */
294 1.44 tsutsui este = (st_entry_t *)kstpa;
295 1.47 tsutsui este = &este[TIA_SIZE];
296 1.44 tsutsui while (ste < este)
297 1.44 tsutsui *ste++ = SG_NV;
298 1.43 tsutsui epte = (pt_entry_t *)kptmpa;
299 1.46 tsutsui epte = &epte[TIB_SIZE];
300 1.44 tsutsui while (pte < epte)
301 1.1 mycroft *pte++ = PG_NV;
302 1.1 mycroft /*
303 1.50 tsutsui * Initialize the last ones to point to Sysptmap and the page
304 1.1 mycroft * table page allocated earlier.
305 1.1 mycroft */
306 1.44 tsutsui ste = (st_entry_t *)kstpa;
307 1.46 tsutsui ste = &ste[SYSMAP_VA >> SEGSHIFT];
308 1.44 tsutsui pte = (pt_entry_t *)kptmpa;
309 1.46 tsutsui pte = &pte[SYSMAP_VA >> SEGSHIFT];
310 1.26 yamt *ste = kptmpa | SG_RW | SG_V;
311 1.26 yamt *pte = kptmpa | PG_RW | PG_CI | PG_V;
312 1.46 tsutsui ste = (st_entry_t *)kstpa;
313 1.46 tsutsui ste = &ste[MAXADDR >> SEGSHIFT];
314 1.46 tsutsui pte = (pt_entry_t *)kptmpa;
315 1.46 tsutsui pte = &pte[MAXADDR >> SEGSHIFT];
316 1.1 mycroft *ste = lkptpa | SG_RW | SG_V;
317 1.1 mycroft *pte = lkptpa | PG_RW | PG_CI | PG_V;
318 1.1 mycroft }
319 1.50 tsutsui
320 1.1 mycroft /*
321 1.43 tsutsui * Invalidate all but the final entry in the last kernel PT page.
322 1.43 tsutsui * The final entry maps the last page of physical memory to
323 1.43 tsutsui * prepare a page that is PA == VA to turn on the MMU.
324 1.1 mycroft */
325 1.43 tsutsui pte = (pt_entry_t *)lkptpa;
326 1.43 tsutsui epte = &pte[NPTEPG - 1];
327 1.1 mycroft while (pte < epte)
328 1.1 mycroft *pte++ = PG_NV;
329 1.1 mycroft *pte = MAXADDR | PG_RW | PG_CI | PG_V;
330 1.1 mycroft /*
331 1.1 mycroft * Initialize kernel page table.
332 1.1 mycroft * Start by invalidating the `nptpages' that we have allocated.
333 1.1 mycroft */
334 1.43 tsutsui pte = (pt_entry_t *)kptpa;
335 1.1 mycroft epte = &pte[nptpages * NPTEPG];
336 1.1 mycroft while (pte < epte)
337 1.1 mycroft *pte++ = PG_NV;
338 1.10 thorpej /*
339 1.50 tsutsui * Validate PTEs for kernel text (RO).
340 1.50 tsutsui * The first page of kernel text remains invalid; see locore.s
341 1.10 thorpej */
342 1.43 tsutsui pte = (pt_entry_t *)kptpa;
343 1.43 tsutsui pte = &pte[m68k_btop(KERNBASE + PAGE_SIZE)];
344 1.13 veego epte = &pte[m68k_btop(m68k_trunc_page(&etext))];
345 1.22 thorpej protopte = (firstpa + PAGE_SIZE) | PG_RO | PG_V;
346 1.1 mycroft while (pte < epte) {
347 1.1 mycroft *pte++ = protopte;
348 1.22 thorpej protopte += PAGE_SIZE;
349 1.1 mycroft }
350 1.1 mycroft /*
351 1.1 mycroft * Validate PTEs for kernel data/bss, dynamic data allocated
352 1.48 tsutsui * by us so far (kstpa - firstpa bytes), and pages for lwp0
353 1.1 mycroft * u-area and page table allocated below (RW).
354 1.1 mycroft */
355 1.43 tsutsui epte = (pt_entry_t *)kptpa;
356 1.48 tsutsui epte = &epte[m68k_btop(kstpa - firstpa)];
357 1.1 mycroft protopte = (protopte & ~PG_PROT) | PG_RW;
358 1.1 mycroft /*
359 1.1 mycroft * Enable copy-back caching of data pages
360 1.1 mycroft */
361 1.1 mycroft if (RELOC(mmutype, int) == MMU_68040)
362 1.1 mycroft protopte |= PG_CCB;
363 1.1 mycroft while (pte < epte) {
364 1.1 mycroft *pte++ = protopte;
365 1.22 thorpej protopte += PAGE_SIZE;
366 1.1 mycroft }
367 1.1 mycroft /*
368 1.51 tsutsui * Map the kernel segment table cache invalidated for 68040/68060.
369 1.51 tsutsui * (for the 68040 not strictly necessary, but recommended by Motorola;
370 1.51 tsutsui * for the 68060 mandatory)
371 1.48 tsutsui */
372 1.48 tsutsui epte = (pt_entry_t *)kptpa;
373 1.48 tsutsui epte = &epte[m68k_btop(nextpa - firstpa)];
374 1.48 tsutsui protopte = (protopte & ~PG_PROT) | PG_RW;
375 1.48 tsutsui if (RELOC(mmutype, int) == MMU_68040) {
376 1.48 tsutsui protopte &= ~PG_CCB;
377 1.48 tsutsui protopte |= PG_CIN;
378 1.48 tsutsui }
379 1.48 tsutsui while (pte < epte) {
380 1.48 tsutsui *pte++ = protopte;
381 1.48 tsutsui protopte += PAGE_SIZE;
382 1.48 tsutsui }
383 1.48 tsutsui
384 1.48 tsutsui /*
385 1.1 mycroft * Finally, validate the internal IO space PTEs (RW+CI).
386 1.1 mycroft * We do this here since the 320/350 MMU registers (also
387 1.1 mycroft * used, but to a lesser extent, on other models) are mapped
388 1.1 mycroft * in this range and it would be nice to be able to access
389 1.1 mycroft * them after the MMU is turned on.
390 1.1 mycroft */
391 1.26 yamt
392 1.26 yamt #define PTE2VA(pte) m68k_ptob(pte - ((pt_entry_t *)kptpa))
393 1.26 yamt
394 1.1 mycroft protopte = INTIOBASE | PG_RW | PG_CI | PG_V;
395 1.26 yamt epte = &pte[IIOMAPSIZE];
396 1.43 tsutsui RELOC(intiobase, uint8_t *) = (uint8_t *)PTE2VA(pte);
397 1.43 tsutsui RELOC(intiolimit, uint8_t *) = (uint8_t *)PTE2VA(epte);
398 1.1 mycroft while (pte < epte) {
399 1.1 mycroft *pte++ = protopte;
400 1.22 thorpej protopte += PAGE_SIZE;
401 1.1 mycroft }
402 1.43 tsutsui RELOC(extiobase, uint8_t *) = (uint8_t *)PTE2VA(pte);
403 1.26 yamt pte += EIOMAPSIZE;
404 1.26 yamt RELOC(virtual_avail, vaddr_t) = PTE2VA(pte);
405 1.1 mycroft
406 1.1 mycroft /*
407 1.45 tsutsui * Calculate important exported kernel addresses and related values.
408 1.1 mycroft */
409 1.1 mycroft /*
410 1.1 mycroft * Sysseg: base of kernel segment table
411 1.1 mycroft */
412 1.43 tsutsui RELOC(Sysseg, st_entry_t *) = (st_entry_t *)(kstpa - firstpa);
413 1.45 tsutsui RELOC(Sysseg_pa, paddr_t) = kstpa;
414 1.45 tsutsui if (RELOC(mmutype, int) == MMU_68040)
415 1.45 tsutsui RELOC(protostfree, u_int) = stfree;
416 1.1 mycroft /*
417 1.1 mycroft * Sysptmap: base of kernel page table map
418 1.1 mycroft */
419 1.43 tsutsui RELOC(Sysptmap, pt_entry_t *) = (pt_entry_t *)(kptmpa - firstpa);
420 1.1 mycroft /*
421 1.1 mycroft * Sysmap: kernel page table (as mapped through Sysptmap)
422 1.31 tsutsui * Allocated at the end of KVA space.
423 1.1 mycroft */
424 1.46 tsutsui RELOC(Sysmap, pt_entry_t *) = (pt_entry_t *)SYSMAP_VA;
425 1.1 mycroft /*
426 1.1 mycroft * CLKbase, MMUbase: important registers in internal IO space
427 1.1 mycroft * accessed from assembly language.
428 1.1 mycroft */
429 1.15 kleink RELOC(CLKbase, vaddr_t) =
430 1.15 kleink (vaddr_t)RELOC(intiobase, char *) + CLKBASE;
431 1.15 kleink RELOC(MMUbase, vaddr_t) =
432 1.15 kleink (vaddr_t)RELOC(intiobase, char *) + MMUBASE;
433 1.1 mycroft
434 1.1 mycroft /*
435 1.40 tsutsui * Remember the u-area address so it can be loaded in the lwp0
436 1.40 tsutsui * via uvm_lwp_setuarea() later in pmap_bootstrap_finalize().
437 1.1 mycroft */
438 1.40 tsutsui RELOC(lwp0uarea, vaddr_t) = lwp0upa - firstpa;
439 1.1 mycroft
440 1.1 mycroft /*
441 1.1 mycroft * VM data structures are now initialized, set up data for
442 1.1 mycroft * the pmap module.
443 1.8 thorpej *
444 1.8 thorpej * Note about avail_end: msgbuf is initialized just after
445 1.50 tsutsui * avail_end in machdep.c.
446 1.50 tsutsui * Since the last page is used for rebooting the system
447 1.50 tsutsui * (code is copied there and excution continues from copied code
448 1.50 tsutsui * before the MMU is disabled), the msgbuf will get trounced
449 1.50 tsutsui * between reboots if it's placed in the last physical page.
450 1.8 thorpej * To work around this, we move avail_end back one more
451 1.8 thorpej * page so the msgbuf can be preserved.
452 1.1 mycroft */
453 1.15 kleink RELOC(avail_start, paddr_t) = nextpa;
454 1.15 kleink RELOC(avail_end, paddr_t) = m68k_ptob(RELOC(maxmem, int)) -
455 1.14 leo (m68k_round_page(MSGBUFSIZE) + m68k_ptob(1));
456 1.15 kleink RELOC(mem_size, vsize_t) = m68k_ptob(RELOC(physmem, int));
457 1.50 tsutsui
458 1.15 kleink RELOC(virtual_end, vaddr_t) = VM_MAX_KERNEL_ADDRESS;
459 1.1 mycroft
460 1.1 mycroft /*
461 1.1 mycroft * Allocate some fixed, special purpose kernel virtual addresses
462 1.1 mycroft */
463 1.1 mycroft {
464 1.15 kleink vaddr_t va = RELOC(virtual_avail, vaddr_t);
465 1.1 mycroft
466 1.28 christos RELOC(CADDR1, void *) = (void *)va;
467 1.22 thorpej va += PAGE_SIZE;
468 1.28 christos RELOC(CADDR2, void *) = (void *)va;
469 1.22 thorpej va += PAGE_SIZE;
470 1.28 christos RELOC(vmmap, void *) = (void *)va;
471 1.22 thorpej va += PAGE_SIZE;
472 1.28 christos RELOC(msgbufaddr, void *) = (void *)va;
473 1.14 leo va += m68k_round_page(MSGBUFSIZE);
474 1.15 kleink RELOC(virtual_avail, vaddr_t) = va;
475 1.1 mycroft }
476 1.21 chs }
477