xref: /netbsd-src/sys/arch/mac68k/mac68k/pmap_bootstrap.c (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: pmap_bootstrap.c,v 1.60 2003/08/07 16:28:22 agc Exp $	*/
2 
3 /*
4  * Copyright (c) 1991, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * the Systems Programming Group of the University of Utah Computer
9  * Science Department.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *	@(#)pmap_bootstrap.c	8.1 (Berkeley) 6/10/93
36  */
37 
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: pmap_bootstrap.c,v 1.60 2003/08/07 16:28:22 agc Exp $");
40 
41 #include "opt_ddb.h"
42 #include "opt_kgdb.h"
43 #include "zsc.h"
44 
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/reboot.h>
48 
49 #include <uvm/uvm_extern.h>
50 
51 #include <machine/pte.h>
52 #include <mac68k/mac68k/clockreg.h>
53 #include <machine/vmparam.h>
54 #include <machine/cpu.h>
55 #include <machine/pmap.h>
56 #include <machine/autoconf.h>
57 
58 #include <ufs/mfs/mfs_extern.h>
59 
60 #include <mac68k/mac68k/macrom.h>
61 
62 #define PA2VA(v, t)	(t)((u_int)(v) - firstpa)
63 
64 extern char *etext;
65 extern int Sysptsize;
66 extern char *extiobase, *proc0paddr;
67 extern st_entry_t *Sysseg;
68 extern pt_entry_t *Sysptmap, *Sysmap;
69 
70 extern int physmem;
71 extern paddr_t avail_start;
72 extern paddr_t avail_end;
73 extern vaddr_t virtual_avail, virtual_end;
74 extern vsize_t mem_size;
75 extern int protection_codes[];
76 
77 #if NZSC > 0
78 extern	int	zsinited;
79 #endif
80 
81 /*
82  * These are used to map the RAM:
83  */
84 int	numranges;	/* = 0 == don't use the ranges */
85 u_long	low[8];
86 u_long	high[8];
87 u_long	maxaddr;	/* PA of the last physical page */
88 int	vidlen;
89 #define VIDMAPSIZE	btoc(vidlen)
90 extern u_int32_t	mac68k_vidphys;
91 extern u_int32_t	videoaddr;
92 extern u_int32_t	videorowbytes;
93 extern u_int32_t	videosize;
94 static u_int32_t	newvideoaddr;
95 
96 extern caddr_t	ROMBase;
97 
98 /*
99  * Special purpose kernel virtual addresses, used for mapping
100  * physical pages for a variety of temporary or permanent purposes:
101  *
102  *	CADDR1, CADDR2:	pmap zero/copy operations
103  *	vmmap:		/dev/mem, crash dumps, parity error checking
104  *	msgbufaddr:	kernel message buffer
105  */
106 caddr_t		CADDR1, CADDR2, vmmap;
107 extern caddr_t	msgbufaddr;
108 
109 void	pmap_bootstrap __P((paddr_t, paddr_t));
110 void	bootstrap_mac68k __P((int));
111 
112 /*
113  * Bootstrap the VM system.
114  *
115  * This is called with the MMU either on or off.  If it's on, we assume
116  * that it's mapped with the same PA <=> LA mapping that we eventually
117  * want.  The page sizes and the protections will be wrong, anyway.
118  *
119  * nextpa is the first address following the loaded kernel.  On a IIsi
120  * on 12 May 1996, that was 0xf9000 beyond firstpa.
121  */
122 void
123 pmap_bootstrap(nextpa, firstpa)
124 	paddr_t nextpa;
125 	paddr_t firstpa;
126 {
127 	paddr_t kstpa, kptpa, vidpa, iiopa, rompa, kptmpa, lkptpa, p0upa;
128 	u_int nptpages, kstsize;
129 	paddr_t avail_next;
130 	int avail_remaining;
131 	int avail_range;
132 	int i;
133 	st_entry_t protoste, *ste;
134 	pt_entry_t protopte, *pte, *epte;
135 
136 	vidlen = m68k_round_page(((videosize >> 16) & 0xffff) * videorowbytes +
137 	    m68k_page_offset(mac68k_vidphys));
138 
139 	/*
140 	 * Calculate important physical addresses:
141 	 *
142 	 *	kstpa		kernel segment table	1 page (!040)
143 	 *						N pages (040)
144 	 *
145 	 *	kptpa		statically allocated
146 	 *			kernel PT pages		Sysptsize+ pages
147 	 *
148 	 *	vidpa		internal video space for some machines
149 	 *			PT pages		VIDMAPSIZE pages
150 	 *
151 	 *	rompa 		ROM space
152 	 *			PT pages		ROMMAPSIZE pages
153 	 *
154 	 *	iiopa		internal IO space
155 	 *			PT pages		IIOMAPSIZE pages
156 	 *
157 	 * [ Sysptsize is the number of pages of PT, IIOMAPSIZE and
158 	 *   NBMAPSIZE are the number of PTEs, hence we need to round
159 	 *   the total to a page boundary with IO maps at the end. ]
160 	 *
161 	 *	kptmpa		kernel PT map		1 page
162 	 *
163 	 *	lkptpa		last kernel PT page	1 page
164 	 *
165 	 *	p0upa		proc 0 u-area		UPAGES pages
166 	 *
167 	 */
168 	if (mmutype == MMU_68040)
169 		kstsize = MAXKL2SIZE / (NPTEPG/SG4_LEV2SIZE);
170 	else
171 		kstsize = 1;
172 	kstpa = nextpa;
173 	nextpa += kstsize * PAGE_SIZE;
174 	kptpa = nextpa;
175 	nptpages = Sysptsize +
176 		(IIOMAPSIZE + ROMMAPSIZE + VIDMAPSIZE + NPTEPG - 1) / NPTEPG;
177 	nextpa += nptpages * PAGE_SIZE;
178 	vidpa = nextpa - VIDMAPSIZE * sizeof(pt_entry_t);
179 	rompa = vidpa  - ROMMAPSIZE * sizeof(pt_entry_t);
180 	iiopa = rompa  - IIOMAPSIZE * sizeof(pt_entry_t);
181 	kptmpa = nextpa;
182 	nextpa += PAGE_SIZE;
183 	lkptpa = nextpa;
184 	nextpa += PAGE_SIZE;
185 	p0upa = nextpa;
186 	nextpa += USPACE;
187 
188 
189 	for (i = 0; i < numranges; i++)
190 		if (low[i] <= firstpa && firstpa < high[i])
191 			break;
192 	if (i >= numranges || nextpa > high[i]) {
193 		if (mac68k_machine.do_graybars) {
194 			printf("Failure in NetBSD boot; ");
195 			if (i < numranges)
196 				printf("nextpa=0x%lx, high[%d]=0x%lx.\n",
197 				    nextpa, i, high[i]);
198 			else
199 				printf("can't find kernel RAM segment.\n");
200 			printf("You're hosed!  Try booting with 32-bit ");
201 			printf("addressing enabled in the memory control ");
202 			printf("panel.\n");
203 			printf("Older machines may need Mode32 to get that ");
204 			printf("option.\n");
205 		}
206 		panic("Cannot work with the current memory mappings.");
207 	}
208 
209 	/*
210 	 * Initialize segment table and kernel page table map.
211 	 *
212 	 * On 68030s and earlier MMUs the two are identical except for
213 	 * the valid bits so both are initialized with essentially the
214 	 * same values.  On the 68040, which has a mandatory 3-level
215 	 * structure, the segment table holds the level 1 table and part
216 	 * (or all) of the level 2 table and hence is considerably
217 	 * different.  Here the first level consists of 128 descriptors
218 	 * (512 bytes) each mapping 32mb of address space.  Each of these
219 	 * points to blocks of 128 second level descriptors (512 bytes)
220 	 * each mapping 256kb.  Note that there may be additional "segment
221 	 * table" pages depending on how large MAXKL2SIZE is.
222 	 *
223 	 * XXX cramming two levels of mapping into the single "segment"
224 	 * table on the 68040 is intended as a temporary hack to get things
225 	 * working.  The 224mb of address space that this allows will most
226 	 * likely be insufficient in the future (at least for the kernel).
227 	 */
228 	if (mmutype == MMU_68040) {
229 		int num;
230 
231 		/*
232 		 * First invalidate the entire "segment table" pages
233 		 * (levels 1 and 2 have the same "invalid" value).
234 		 */
235 		pte = PA2VA(kstpa, u_int *);
236 		epte = &pte[kstsize * NPTEPG];
237 		while (pte < epte)
238 			*pte++ = SG_NV;
239 		/*
240 		 * Initialize level 2 descriptors (which immediately
241 		 * follow the level 1 table).  We need:
242 		 *	NPTEPG / SG4_LEV3SIZE
243 		 * level 2 descriptors to map each of the nptpages+1
244 		 * pages of PTEs.  Note that we set the "used" bit
245 		 * now to save the HW the expense of doing it.
246 		 */
247 		num = (nptpages + 1) * (NPTEPG / SG4_LEV3SIZE);
248 		pte = &(PA2VA(kstpa, u_int *))[SG4_LEV1SIZE];
249 		epte = &pte[num];
250 		protoste = kptpa | SG_U | SG_RW | SG_V;
251 		while (pte < epte) {
252 			*pte++ = protoste;
253 			protoste += (SG4_LEV3SIZE * sizeof(st_entry_t));
254 		}
255 		/*
256 		 * Initialize level 1 descriptors.  We need:
257 		 *	roundup(num, SG4_LEV2SIZE) / SG4_LEV2SIZE
258 		 * level 1 descriptors to map the `num' level 2's.
259 		 */
260 		pte = PA2VA(kstpa, u_int *);
261 		epte = &pte[roundup(num, SG4_LEV2SIZE) / SG4_LEV2SIZE];
262 		protoste = (u_int)&pte[SG4_LEV1SIZE] | SG_U | SG_RW | SG_V;
263 		while (pte < epte) {
264 			*pte++ = protoste;
265 			protoste += (SG4_LEV2SIZE * sizeof(st_entry_t));
266 		}
267 		/*
268 		 * Initialize the final level 1 descriptor to map the last
269 		 * block of level 2 descriptors.
270 		 */
271 		ste = &(PA2VA(kstpa, u_int*))[SG4_LEV1SIZE-1];
272 		pte = &(PA2VA(kstpa, u_int*))[kstsize*NPTEPG - SG4_LEV2SIZE];
273 		*ste = (u_int)pte | SG_U | SG_RW | SG_V;
274 		/*
275 		 * Now initialize the final portion of that block of
276 		 * descriptors to map the "last PT page".
277 		 */
278 		pte = &(PA2VA(kstpa, u_int*))
279 				[kstsize*NPTEPG - NPTEPG/SG4_LEV3SIZE];
280 		epte = &pte[NPTEPG/SG4_LEV3SIZE];
281 		protoste = lkptpa | SG_U | SG_RW | SG_V;
282 		while (pte < epte) {
283 			*pte++ = protoste;
284 			protoste += (SG4_LEV3SIZE * sizeof(st_entry_t));
285 		}
286 		/*
287 		 * Initialize Sysptmap
288 		 */
289 		pte = PA2VA(kptmpa, u_int *);
290 		epte = &pte[nptpages+1];
291 		protopte = kptpa | PG_RW | PG_CI | PG_V;
292 		while (pte < epte) {
293 			*pte++ = protopte;
294 			protopte += PAGE_SIZE;
295 		}
296 		/*
297 		 * Invalidate all but the last remaining entries in both.
298 		 */
299 		epte = &(PA2VA(kptmpa, u_int *))[NPTEPG-1];
300 		while (pte < epte) {
301 			*pte++ = PG_NV;
302 		}
303 		/*
304 		 * Initialize the last to point to the page
305 		 * table page allocated earlier.
306 		 */
307 		*pte = lkptpa | PG_RW | PG_CI | PG_V;
308 	} else {
309 		/*
310 		 * Map the page table pages in both the HW segment table
311 		 * and the software Sysptmap.  Note that Sysptmap is also
312 		 * considered a PT page hence the +1.
313 		 */
314 		ste = PA2VA(kstpa, u_int*);
315 		pte = PA2VA(kptmpa, u_int*);
316 		epte = &pte[nptpages+1];
317 		protoste = kptpa | SG_RW | SG_V;
318 		protopte = kptpa | PG_RW | PG_CI | PG_V;
319 		while (pte < epte) {
320 			*ste++ = protoste;
321 			*pte++ = protopte;
322 			protoste += PAGE_SIZE;
323 			protopte += PAGE_SIZE;
324 		}
325 		/*
326 		 * Invalidate all but the last remaining entries in both.
327 		 */
328 		epte = &(PA2VA(kptmpa, u_int *))[NPTEPG-1];
329 		while (pte < epte) {
330 			*ste++ = SG_NV;
331 			*pte++ = PG_NV;
332 		}
333 		/*
334 		 * Initialize the last to point to point to the page
335 		 * table page allocated earlier.
336 		 */
337 		*ste = lkptpa | SG_RW | SG_V;
338 		*pte = lkptpa | PG_RW | PG_CI | PG_V;
339 	}
340 	/*
341 	 * Invalidate all entries in the last kernel PT page
342 	 * (u-area PTEs will be validated later).
343 	 */
344 	pte = PA2VA(lkptpa, u_int *);
345 	epte = &pte[NPTEPG];
346 	while (pte < epte)
347 		*pte++ = PG_NV;
348 
349 	/*
350 	 * Initialize kernel page table.
351 	 * Start by invalidating the `nptpages' that we have allocated.
352 	 */
353 	pte = PA2VA(kptpa, u_int *);
354 	epte = &pte[nptpages * NPTEPG];
355 	while (pte < epte)
356 		*pte++ = PG_NV;
357 
358 	/*
359 	 * Validate PTEs for kernel text (RO)
360 	 */
361 	pte = &(PA2VA(kptpa, u_int *))[m68k_btop(KERNBASE)];
362 	epte = &pte[m68k_btop(m68k_trunc_page(&etext))];
363 #if defined(KGDB) || defined(DDB)
364 	protopte = firstpa | PG_RW | PG_V;	/* XXX RW for now */
365 #else
366 	protopte = firstpa | PG_RO | PG_V;
367 #endif
368 	while (pte < epte) {
369 		*pte++ = protopte;
370 		protopte += PAGE_SIZE;
371 	}
372 	/*
373 	 * Validate PTEs for kernel data/bss, dynamic data allocated
374 	 * by us so far (nextpa - firstpa bytes), and pages for proc0
375 	 * u-area and page table allocated below (RW).
376 	 */
377 	epte = &(PA2VA(kptpa, u_int *))[m68k_btop(nextpa - firstpa)];
378 	protopte = (protopte & ~PG_PROT) | PG_RW;
379 	/*
380 	 * Enable copy-back caching of data pages
381 	 */
382 	if (mmutype == MMU_68040)
383 		protopte |= PG_CCB;
384 	while (pte < epte) {
385 		*pte++ = protopte;
386 		protopte += PAGE_SIZE;
387 	}
388 	/*
389 	 * Finally, validate the internal IO space, ROM space, and
390 	 * framebuffer PTEs (RW+CI).
391 	 */
392 	pte = PA2VA(iiopa, u_int *);
393 	epte = PA2VA(rompa, u_int *);
394 	protopte = IOBase | PG_RW | PG_CI | PG_V;
395 	while (pte < epte) {
396 		*pte++ = protopte;
397 		protopte += PAGE_SIZE;
398 	}
399 
400 	pte = PA2VA(rompa, u_int *);
401 	epte = PA2VA(vidpa, u_int *);
402 	protopte = ((u_int) ROMBase) | PG_RO | PG_V;
403 	while (pte < epte) {
404 		*pte++ = protopte;
405 		protopte += PAGE_SIZE;
406 	}
407 
408 	if (vidlen) {
409 		pte = PA2VA(vidpa, u_int *);
410 		epte = pte + VIDMAPSIZE;
411 		protopte = m68k_trunc_page(mac68k_vidphys) |
412 		    PG_RW | PG_V | PG_CI;
413 		while (pte < epte) {
414 			*pte++ = protopte;
415 			protopte += PAGE_SIZE;
416 		}
417 	}
418 
419 	/*
420 	 * Calculate important exported kernel virtual addresses
421 	 */
422 	/*
423 	 * Sysseg: base of kernel segment table
424 	 */
425 	Sysseg = PA2VA(kstpa, st_entry_t *);
426 	/*
427 	 * Sysptmap: base of kernel page table map
428 	 */
429 	Sysptmap = PA2VA(kptmpa, pt_entry_t *);
430 	/*
431 	 * Sysmap: kernel page table (as mapped through Sysptmap)
432 	 * Immediately follows `nptpages' of static kernel page table.
433 	 */
434 	Sysmap = (pt_entry_t *)m68k_ptob(nptpages * NPTEPG);
435 
436 	IOBase = (u_long)m68k_ptob(nptpages * NPTEPG -
437 	    (IIOMAPSIZE + ROMMAPSIZE + VIDMAPSIZE));
438 
439 	ROMBase = (char *)m68k_ptob(nptpages * NPTEPG -
440 	    (ROMMAPSIZE + VIDMAPSIZE));
441 
442 	if (vidlen) {
443 		newvideoaddr = (u_int32_t)m68k_ptob(nptpages * NPTEPG -
444 		    VIDMAPSIZE) + m68k_page_offset(mac68k_vidphys);
445 	}
446 
447 	/*
448 	 * Setup u-area for process 0.
449 	 */
450 	/*
451 	 * Zero the u-area.
452 	 * NOTE: `pte' and `epte' aren't PTEs here.
453 	 */
454 	pte = PA2VA(p0upa, u_int *);
455 	epte = (u_int *)(PA2VA(p0upa, u_int) + USPACE);
456 	while (pte < epte)
457 		*pte++ = 0;
458 	/*
459 	 * Remember the u-area address so it can be loaded in the
460 	 * proc struct p_addr field later.
461 	 */
462 	proc0paddr = PA2VA(p0upa, char *);
463 
464 	/*
465 	 * VM data structures are now initialized, set up data for
466 	 * the pmap module.
467 	 *
468 	 * Note about avail_end: msgbuf is initialized just after
469 	 * avail_end in machdep.c.  Since the last page is used
470 	 * for rebooting the system (code is copied there and
471 	 * excution continues from copied code before the MMU
472 	 * is disabled), the msgbuf will get trounced between
473 	 * reboots if it's placed in the last physical page.
474 	 * To work around this, we move avail_end back one more
475 	 * page so the msgbuf can be preserved.
476 	 */
477 	avail_next = avail_start = m68k_round_page(nextpa);
478 	avail_remaining = 0;
479 	avail_range = -1;
480 	for (i = 0; i < numranges; i++) {
481 		if (low[i] <= avail_next && avail_next < high[i]) {
482 			avail_range = i;
483 			avail_remaining = high[i] - avail_next;
484 		} else if (avail_range != -1) {
485 			avail_remaining += (high[i] - low[i]);
486 		}
487 	}
488 	physmem = m68k_btop(avail_remaining + nextpa - firstpa);
489 
490 	maxaddr = high[numranges - 1] - m68k_ptob(1);
491 	high[numranges - 1] -= (m68k_round_page(MSGBUFSIZE) + m68k_ptob(1));
492 	avail_end = high[numranges - 1];
493 	mem_size = m68k_ptob(physmem);
494 	virtual_avail = VM_MIN_KERNEL_ADDRESS + (nextpa - firstpa);
495 	virtual_end = VM_MAX_KERNEL_ADDRESS;
496 
497 	/*
498 	 * Initialize protection array.
499 	 * XXX don't use a switch statement, it might produce an
500 	 * absolute "jmp" table.
501 	 */
502 	{
503 		int *kp;
504 
505 		kp = (int *)&protection_codes;
506 		kp[VM_PROT_NONE|VM_PROT_NONE|VM_PROT_NONE] = 0;
507 		kp[VM_PROT_READ|VM_PROT_NONE|VM_PROT_NONE] = PG_RO;
508 		kp[VM_PROT_READ|VM_PROT_NONE|VM_PROT_EXECUTE] = PG_RO;
509 		kp[VM_PROT_NONE|VM_PROT_NONE|VM_PROT_EXECUTE] = PG_RO;
510 		kp[VM_PROT_NONE|VM_PROT_WRITE|VM_PROT_NONE] = PG_RW;
511 		kp[VM_PROT_NONE|VM_PROT_WRITE|VM_PROT_EXECUTE] = PG_RW;
512 		kp[VM_PROT_READ|VM_PROT_WRITE|VM_PROT_NONE] = PG_RW;
513 		kp[VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE] = PG_RW;
514 	}
515 
516 	/*
517 	 * Kernel page/segment table allocated in locore,
518 	 * just initialize pointers.
519 	 */
520 	{
521 		struct pmap *kpm = (struct pmap *)&kernel_pmap_store;
522 
523 		kpm->pm_stab = Sysseg;
524 		kpm->pm_ptab = Sysmap;
525 		simple_lock_init(&kpm->pm_lock);
526 		kpm->pm_count = 1;
527 		kpm->pm_stpa = (st_entry_t *)kstpa;
528 		/*
529 		 * For the 040 we also initialize the free level 2
530 		 * descriptor mask noting that we have used:
531 		 *	0:		level 1 table
532 		 *	1 to `num':	map page tables
533 		 *	MAXKL2SIZE-1:	maps last-page page table
534 		 */
535 		if (mmutype == MMU_68040) {
536 			int num;
537 
538 			kpm->pm_stfree = ~l2tobm(0);
539 			num = roundup((nptpages + 1) * (NPTEPG / SG4_LEV3SIZE),
540 				      SG4_LEV2SIZE) / SG4_LEV2SIZE;
541 			while (num)
542 				kpm->pm_stfree &= ~l2tobm(num--);
543 			kpm->pm_stfree &= ~l2tobm(MAXKL2SIZE-1);
544 			for (num = MAXKL2SIZE;
545 			     num < sizeof(kpm->pm_stfree)*NBBY;
546 			     num++)
547 				kpm->pm_stfree &= ~l2tobm(num);
548 		}
549 	}
550 
551 	/*
552 	 * Allocate some fixed, special purpose kernel virtual addresses
553 	 */
554 	{
555 		vaddr_t va = virtual_avail;
556 
557 		CADDR1 = (caddr_t)va;
558 		va += PAGE_SIZE;
559 		CADDR2 = (caddr_t)va;
560 		va += PAGE_SIZE;
561 		vmmap = (caddr_t)va;
562 		va += PAGE_SIZE;
563 		msgbufaddr = (caddr_t)va;
564 		va += m68k_round_page(MSGBUFSIZE);
565 		virtual_avail = va;
566 	}
567 }
568 
569 void
570 bootstrap_mac68k(tc)
571 	int	tc;
572 {
573 #if NZSC > 0
574 	extern void zs_init __P((void));
575 #endif
576 	extern int *esym;
577 	paddr_t nextpa;
578 	caddr_t oldROMBase;
579 
580 	if (mac68k_machine.do_graybars)
581 		printf("Bootstrapping NetBSD/mac68k.\n");
582 
583 	oldROMBase = ROMBase;
584 	mac68k_vidphys = videoaddr;
585 
586 	if (((tc & 0x80000000) && (mmutype == MMU_68030)) ||
587 	    ((tc & 0x8000) && (mmutype == MMU_68040))) {
588 		if (mac68k_machine.do_graybars)
589 			printf("Getting mapping from MMU.\n");
590 		(void) get_mapping();
591 		if (mac68k_machine.do_graybars)
592 			printf("Done.\n");
593 	} else {
594 		/* MMU not enabled.  Fake up ranges. */
595 		numranges = 1;
596 		low[0] = 0;
597 		high[0] = mac68k_machine.mach_memsize * (1024 * 1024);
598 		if (mac68k_machine.do_graybars)
599 			printf("Faked range to byte 0x%lx.\n", high[0]);
600 	}
601 	nextpa = load_addr + m68k_round_page(esym);
602 
603 	if (mac68k_machine.do_graybars)
604 		printf("Bootstrapping the pmap system.\n");
605 
606 	pmap_bootstrap(nextpa, load_addr);
607 
608 	if (mac68k_machine.do_graybars)
609 		printf("Pmap bootstrapped.\n");
610 
611 	if (!vidlen)
612 		panic("Don't know how to relocate video!");
613 
614 	if (mac68k_machine.do_graybars)
615 		printf("Moving ROMBase from %p to %p.\n", oldROMBase, ROMBase);
616 
617 	mrg_fixupROMBase(oldROMBase, ROMBase);
618 
619 	if (mac68k_machine.do_graybars)
620 		printf("Video address 0x%lx -> 0x%lx.\n",
621 		    (unsigned long)videoaddr, (unsigned long)newvideoaddr);
622 
623 	mac68k_set_io_offsets(IOBase);
624 
625 	/*
626 	 * If the serial ports are going (for console or 'echo'), then
627 	 * we need to make sure the IO change gets propagated properly.
628 	 * This resets the base addresses for the 8530 (serial) driver.
629 	 *
630 	 * WARNING!!! No printfs() (etc) BETWEEN zs_init() and the end
631 	 * of this function (where we start using the MMU, so the new
632 	 * address is correct.
633 	 */
634 #if NZSC > 0
635 	if (zsinited != 0)
636 		zs_init();
637 #endif
638 
639 	videoaddr = newvideoaddr;
640 }
641 
642 void
643 pmap_init_md(void)
644 {
645 	vaddr_t addr;
646 
647 	addr = (vaddr_t)IOBase;
648 	if (uvm_map(kernel_map, &addr,
649 		    m68k_ptob(IIOMAPSIZE + ROMMAPSIZE + VIDMAPSIZE),
650 		    NULL, UVM_UNKNOWN_OFFSET, 0,
651 		    UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE,
652 				UVM_INH_NONE, UVM_ADV_RANDOM,
653 				UVM_FLAG_FIXED)) != 0)
654 		panic("pmap_init_md: uvm_map failed");
655 }
656