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