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