xref: /netbsd/sys/arch/sun3/sun3/machdep.c (revision c4a72b64)
1 /*	$NetBSD: machdep.c,v 1.160 2002/10/20 02:37:35 chs Exp $	*/
2 
3 /*
4  * Copyright (c) 1994, 1995 Gordon W. Ross
5  * Copyright (c) 1993 Adam Glass
6  * Copyright (c) 1988 University of Utah.
7  * Copyright (c) 1982, 1986, 1990, 1993
8  *	The Regents of the University of California.  All rights reserved.
9  *
10  * This code is derived from software contributed to Berkeley by
11  * the Systems Programming Group of the University of Utah Computer
12  * Science Department.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  * 3. All advertising materials mentioning features or use of this software
23  *    must display the following acknowledgement:
24  *	This product includes software developed by the University of
25  *	California, Berkeley and its contributors.
26  * 4. Neither the name of the University nor the names of its contributors
27  *    may be used to endorse or promote products derived from this software
28  *    without specific prior written permission.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40  * SUCH DAMAGE.
41  *
42  *	from: Utah Hdr: machdep.c 1.74 92/12/20
43  *	from: @(#)machdep.c	8.10 (Berkeley) 4/20/94
44  */
45 
46 #include "opt_ddb.h"
47 #include "opt_kgdb.h"
48 
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
52 #include <sys/proc.h>
53 #include <sys/buf.h>
54 #include <sys/reboot.h>
55 #include <sys/conf.h>
56 #include <sys/file.h>
57 #include <sys/device.h>
58 #include <sys/malloc.h>
59 #include <sys/mbuf.h>
60 #include <sys/msgbuf.h>
61 #include <sys/ioctl.h>
62 #include <sys/tty.h>
63 #include <sys/mount.h>
64 #include <sys/user.h>
65 #include <sys/exec.h>
66 #include <sys/core.h>
67 #include <sys/kcore.h>
68 #include <sys/vnode.h>
69 #include <sys/syscallargs.h>
70 #ifdef	KGDB
71 #include <sys/kgdb.h>
72 #endif
73 
74 #include <uvm/uvm.h> /* XXX: not _extern ... need vm_map_create */
75 
76 #include <sys/sysctl.h>
77 
78 #include <dev/cons.h>
79 
80 #include <machine/cpu.h>
81 #include <machine/dvma.h>
82 #include <machine/idprom.h>
83 #include <machine/kcore.h>
84 #include <machine/reg.h>
85 #include <machine/psl.h>
86 #include <machine/pte.h>
87 
88 #if defined(DDB)
89 #include <machine/db_machdep.h>
90 #include <ddb/db_sym.h>
91 #include <ddb/db_extern.h>
92 #endif
93 
94 #include <sun3/sun3/machdep.h>
95 
96 /* Defined in locore.s */
97 extern char kernel_text[];
98 /* Defined by the linker */
99 extern char etext[];
100 
101 /* Our exported CPU info; we can have only one. */
102 struct cpu_info cpu_info_store;
103 
104 struct vm_map *exec_map = NULL;
105 struct vm_map *mb_map = NULL;
106 struct vm_map *phys_map = NULL;
107 
108 int	physmem;
109 int	fputype;
110 caddr_t	msgbufaddr;
111 
112 /* Virtual page frame for /dev/mem (see mem.c) */
113 vaddr_t vmmap;
114 
115 union sun3sir sun3sir;
116 
117 /*
118  * safepri is a safe priority for sleep to set for a spin-wait
119  * during autoconfiguration or after a panic.
120  */
121 int	safepri = PSL_LOWIPL;
122 
123 /* Our private scratch page for dumping the MMU. */
124 static vaddr_t dumppage;
125 
126 static void identifycpu __P((void));
127 static void initcpu __P((void));
128 
129 /*
130  * Console initialization: called early on from main,
131  * before vm init or cpu_startup.  This system is able
132  * to use the console for output immediately (via PROM)
133  * but can not use it for input until after this point.
134  */
135 void
136 consinit()
137 {
138 
139 	/*
140 	 * Switch from the PROM console (output only)
141 	 * to our own console driver.
142 	 */
143 	cninit();
144 
145 #ifdef DDB
146 	{
147 		extern int nsym;
148 		extern char *ssym, *esym;
149 
150 		ddb_init(nsym, ssym, esym);
151 	}
152 #endif /* DDB */
153 
154 	/*
155 	 * Now that the console can do input as well as
156 	 * output, consider stopping for a debugger.
157 	 */
158 	if (boothowto & RB_KDB) {
159 #ifdef KGDB
160 		/* XXX - Ask on console for kgdb_dev? */
161 		/* Note: this will just return if kgdb_dev==NODEV */
162 		kgdb_connect(1);
163 #else	/* KGDB */
164 		/* Either DDB or no debugger (just PROM). */
165 		Debugger();
166 #endif	/* KGDB */
167 	}
168 }
169 
170 /*
171  * cpu_startup: allocate memory for variable-sized tables,
172  * initialize cpu, and do autoconfiguration.
173  *
174  * This is called early in init_main.c:main(), after the
175  * kernel memory allocator is ready for use, but before
176  * the creation of processes 1,2, and mountroot, etc.
177  */
178 void
179 cpu_startup()
180 {
181 	caddr_t v;
182 	vsize_t size;
183 	int i, sz, base, residual;
184 	vaddr_t minaddr, maxaddr;
185 	char pbuf[9];
186 
187 	/*
188 	 * Initialize message buffer (for kernel printf).
189 	 * This is put in physical page zero so it will
190 	 * always be in the same place after a reboot.
191 	 * Its mapping was prepared in pmap_bootstrap().
192 	 * Also, offset some to avoid PROM scribbles.
193 	 */
194 	v = (caddr_t) KERNBASE;
195 	msgbufaddr = (caddr_t)(v + MSGBUFOFF);
196 	initmsgbuf(msgbufaddr, MSGBUFSIZE);
197 
198 	/*
199 	 * Good {morning,afternoon,evening,night}.
200 	 */
201 	printf(version);
202 	identifycpu();
203 	initfpu();	/* also prints FPU type */
204 
205 	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
206 	printf("total memory = %s\n", pbuf);
207 
208 	/*
209 	 * Get scratch page for dumpsys().
210 	 */
211 	if ((dumppage = uvm_km_alloc(kernel_map, NBPG)) == 0)
212 		panic("startup: alloc dumppage");
213 
214 	/*
215 	 * Find out how much space we need, allocate it,
216 	 * and then give everything true virtual addresses.
217 	 */
218 	sz = (u_int)allocsys(NULL, NULL);
219 	if ((v = (caddr_t)uvm_km_alloc(kernel_map, round_page(sz))) == 0)
220 		panic("startup: no room for tables");
221 	if (allocsys(v, NULL) - v != sz)
222 		panic("startup: table size inconsistency");
223 
224 	/*
225 	 * Now allocate buffers proper.  They are different than the above
226 	 * in that they usually occupy more virtual memory than physical.
227 	 */
228 	size = MAXBSIZE * nbuf;
229 	if (uvm_map(kernel_map, (vaddr_t *) &buffers, round_page(size),
230 		    NULL, UVM_UNKNOWN_OFFSET, 0,
231 		    UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
232 				UVM_ADV_NORMAL, 0)) != 0)
233 		panic("startup: cannot allocate VM for buffers");
234 	minaddr = (vaddr_t)buffers;
235 	if ((bufpages / nbuf) >= btoc(MAXBSIZE)) {
236 		/* don't want to alloc more physical mem than needed */
237 		bufpages = btoc(MAXBSIZE) * nbuf;
238 	}
239 	base = bufpages / nbuf;
240 	residual = bufpages % nbuf;
241 	for (i = 0; i < nbuf; i++) {
242 		vsize_t curbufsize;
243 		vaddr_t curbuf;
244 		struct vm_page *pg;
245 
246 		/*
247 		 * Each buffer has MAXBSIZE bytes of VM space allocated.  Of
248 		 * that MAXBSIZE space, we allocate and map (base+1) pages
249 		 * for the first "residual" buffers, and then we allocate
250 		 * "base" pages for the rest.
251 		 */
252 		curbuf = (vaddr_t) buffers + (i * MAXBSIZE);
253 		curbufsize = NBPG * ((i < residual) ? (base+1) : base);
254 
255 		while (curbufsize) {
256 			pg = uvm_pagealloc(NULL, 0, NULL, 0);
257 			if (pg == NULL)
258 				panic("cpu_startup: not enough memory for "
259 				    "buffer cache");
260 			pmap_kenter_pa(curbuf, VM_PAGE_TO_PHYS(pg),
261 				       VM_PROT_READ|VM_PROT_WRITE);
262 			curbuf += PAGE_SIZE;
263 			curbufsize -= PAGE_SIZE;
264 		}
265 	}
266 	pmap_update(pmap_kernel());
267 
268 	/*
269 	 * Allocate a submap for exec arguments.  This map effectively
270 	 * limits the number of processes exec'ing at any time.
271 	 */
272 	exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
273 				   16*NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
274 
275 	/*
276 	 * Allocate a submap for physio
277 	 */
278 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
279 				   VM_PHYS_SIZE, 0, FALSE, NULL);
280 
281 	/*
282 	 * Finally, allocate mbuf cluster submap.
283 	 */
284 	mb_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
285 				 nmbclusters * mclbytes, VM_MAP_INTRSAFE,
286 				 FALSE, NULL);
287 
288 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
289 	printf("avail memory = %s\n", pbuf);
290 	format_bytes(pbuf, sizeof(pbuf), bufpages * NBPG);
291 	printf("using %u buffers containing %s of memory\n", nbuf, pbuf);
292 
293 	/*
294 	 * Allocate a virtual page (for use by /dev/mem)
295 	 * This page is handed to pmap_enter() therefore
296 	 * it has to be in the normal kernel VA range.
297 	 */
298 	vmmap = uvm_km_valloc_wait(kernel_map, NBPG);
299 
300 	/*
301 	 * Create the DVMA maps.
302 	 */
303 	dvma_init();
304 
305 	/*
306 	 * Set up CPU-specific registers, cache, etc.
307 	 */
308 	initcpu();
309 
310 	/*
311 	 * Set up buffers, so they can be used to read disk labels.
312 	 */
313 	bufinit();
314 }
315 
316 /*
317  * Set registers on exec.
318  */
319 void
320 setregs(p, pack, stack)
321 	struct proc *p;
322 	struct exec_package *pack;
323 	u_long stack;
324 {
325 	struct trapframe *tf = (struct trapframe *)p->p_md.md_regs;
326 
327 	tf->tf_sr = PSL_USERSET;
328 	tf->tf_pc = pack->ep_entry & ~1;
329 	tf->tf_regs[D0] = 0;
330 	tf->tf_regs[D1] = 0;
331 	tf->tf_regs[D2] = 0;
332 	tf->tf_regs[D3] = 0;
333 	tf->tf_regs[D4] = 0;
334 	tf->tf_regs[D5] = 0;
335 	tf->tf_regs[D6] = 0;
336 	tf->tf_regs[D7] = 0;
337 	tf->tf_regs[A0] = 0;
338 	tf->tf_regs[A1] = 0;
339 	tf->tf_regs[A2] = (int)p->p_psstr;
340 	tf->tf_regs[A3] = 0;
341 	tf->tf_regs[A4] = 0;
342 	tf->tf_regs[A5] = 0;
343 	tf->tf_regs[A6] = 0;
344 	tf->tf_regs[SP] = stack;
345 
346 	/* restore a null state frame */
347 	p->p_addr->u_pcb.pcb_fpregs.fpf_null = 0;
348 	if (fputype)
349 		m68881_restore(&p->p_addr->u_pcb.pcb_fpregs);
350 
351 	p->p_md.md_flags = 0;
352 }
353 
354 /*
355  * Info for CTL_HW
356  */
357 char	machine[16] = MACHINE;		/* from <machine/param.h> */
358 char	kernel_arch[16] = "sun3";	/* XXX needs a sysctl node */
359 char	cpu_model[120];
360 
361 /*
362  * Determine which Sun3 model we are running on.
363  * We have to do this very early on the Sun3 because
364  * pmap_bootstrap() needs to know if it should avoid
365  * the video memory on the Sun3/50.  Therefore, this
366  * function just prints out what we already know.
367  */
368 void
369 identifycpu()
370 {
371 	extern char *cpu_string;	/* XXX */
372 
373 	/* Other stuff? (VAC, mc6888x version, etc.) */
374 	/* Note: miniroot cares about the kernel_arch part. */
375 	sprintf(cpu_model, "%s %s", kernel_arch, cpu_string);
376 
377 	printf("Model: %s\n", cpu_model);
378 }
379 
380 /*
381  * machine dependent system variables.
382  */
383 int
384 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
385 	int *name;
386 	u_int namelen;
387 	void *oldp;
388 	size_t *oldlenp;
389 	void *newp;
390 	size_t newlen;
391 	struct proc *p;
392 {
393 	int error;
394 	dev_t consdev;
395 
396 	/* all sysctl names at this level are terminal */
397 	if (namelen != 1)
398 		return (ENOTDIR);		/* overloaded */
399 
400 	switch (name[0]) {
401 	case CPU_CONSDEV:
402 		if (cn_tab != NULL)
403 			consdev = cn_tab->cn_dev;
404 		else
405 			consdev = NODEV;
406 		error = sysctl_rdstruct(oldp, oldlenp, newp,
407 		    &consdev, sizeof consdev);
408 		break;
409 
410 #if 0	/* XXX - Not yet... */
411 	case CPU_ROOT_DEVICE:
412 		error = sysctl_rdstring(oldp, oldlenp, newp, root_device);
413 		break;
414 
415 	case CPU_BOOTED_KERNEL:
416 		error = sysctl_rdstring(oldp, oldlenp, newp, booted_kernel);
417 		break;
418 #endif
419 
420 	default:
421 		error = EOPNOTSUPP;
422 	}
423 	return (error);
424 }
425 
426 /* See: sig_machdep.c */
427 
428 /*
429  * Do a sync in preparation for a reboot.
430  * XXX - This could probably be common code.
431  * XXX - And now, most of it is in vfs_shutdown()
432  * XXX - Put waittime checks in there too?
433  */
434 int waittime = -1;	/* XXX - Who else looks at this? -gwr */
435 static void
436 reboot_sync __P((void))
437 {
438 
439 	/* Check waittime here to localize its use to this function. */
440 	if (waittime >= 0)
441 		return;
442 	waittime = 0;
443 	vfs_shutdown();
444 }
445 
446 /*
447  * Common part of the BSD and SunOS reboot system calls.
448  */
449 __dead void
450 cpu_reboot(howto, user_boot_string)
451 	int howto;
452 	char *user_boot_string;
453 {
454 	char *bs, *p;
455 	char default_boot_string[8];
456 
457 	/* If system is cold, just halt. (early panic?) */
458 	if (cold)
459 		goto haltsys;
460 
461 	/* Un-blank the screen if appropriate. */
462 	cnpollc(1);
463 
464 	if ((howto & RB_NOSYNC) == 0) {
465 		reboot_sync();
466 		/*
467 		 * If we've been adjusting the clock, the todr
468 		 * will be out of synch; adjust it now.
469 		 *
470 		 * XXX - However, if the kernel has been sitting in ddb,
471 		 * the time will be way off, so don't set the HW clock!
472 		 * XXX - Should do sanity check against HW clock. -gwr
473 		 */
474 		/* resettodr(); */
475 	}
476 
477 	/* Disable interrupts. */
478 	splhigh();
479 
480 	/* Write out a crash dump if asked. */
481 	if (howto & RB_DUMP)
482 		dumpsys();
483 
484 	/* run any shutdown hooks */
485 	doshutdownhooks();
486 
487 	if (howto & RB_HALT) {
488 	haltsys:
489 		printf("halted.\n");
490 		sunmon_halt();
491 	}
492 
493 	/*
494 	 * Automatic reboot.
495 	 */
496 	bs = user_boot_string;
497 	if (bs == NULL) {
498 		/*
499 		 * Build our own boot string with an empty
500 		 * boot device/file and (maybe) some flags.
501 		 * The PROM will supply the device/file name.
502 		 */
503 		bs = default_boot_string;
504 		*bs = '\0';
505 		if (howto & (RB_KDB|RB_ASKNAME|RB_SINGLE)) {
506 			/* Append the boot flags. */
507 			p = bs;
508 			*p++ = ' ';
509 			*p++ = '-';
510 			if (howto & RB_KDB)
511 				*p++ = 'd';
512 			if (howto & RB_ASKNAME)
513 				*p++ = 'a';
514 			if (howto & RB_SINGLE)
515 				*p++ = 's';
516 			*p = '\0';
517 		}
518 	}
519 	printf("rebooting...\n");
520 	sunmon_reboot(bs);
521 	for (;;) ;
522 	/*NOTREACHED*/
523 }
524 
525 /*
526  * These variables are needed by /sbin/savecore
527  */
528 u_int32_t dumpmag = 0x8fca0101;	/* magic number */
529 int 	dumpsize = 0;		/* pages */
530 long	dumplo = 0; 		/* blocks */
531 
532 #define	DUMP_EXTRA 	3	/* CPU-dependent extra pages */
533 
534 /*
535  * This is called by main to set dumplo, dumpsize.
536  * Dumps always skip the first NBPG of disk space
537  * in case there might be a disk label stored there.
538  * If there is extra space, put dump at the end to
539  * reduce the chance that swapping trashes it.
540  */
541 void
542 cpu_dumpconf()
543 {
544 	const struct bdevsw *bdev;
545 	int devblks;	/* size of dump device in blocks */
546 	int dumpblks;	/* size of dump image in blocks */
547 	int (*getsize)__P((dev_t));
548 
549 	if (dumpdev == NODEV)
550 		return;
551 
552 	bdev = bdevsw_lookup(dumpdev);
553 	if (bdev == NULL)
554 		panic("dumpconf: bad dumpdev=0x%x", dumpdev);
555 	getsize = bdev->d_psize;
556 	if (getsize == NULL)
557 		return;
558 	devblks = (*getsize)(dumpdev);
559 	if (devblks <= ctod(1))
560 		return;
561 	devblks &= ~(ctod(1)-1);
562 
563 	/*
564 	 * Note: savecore expects dumpsize to be the
565 	 * number of pages AFTER the dump header.
566 	 */
567 	dumpsize = physmem;
568 
569 	/* Position dump image near end of space, page aligned. */
570 	dumpblks = ctod(physmem + DUMP_EXTRA);
571 	dumplo = devblks - dumpblks;
572 
573 	/* If it does not fit, truncate it by moving dumplo. */
574 	/* Note: Must force signed comparison. */
575 	if (dumplo < ((long)ctod(1))) {
576 		dumplo = ctod(1);
577 		dumpsize = dtoc(devblks - dumplo) - DUMP_EXTRA;
578 	}
579 }
580 
581 /* Note: gdb looks for "dumppcb" in a kernel crash dump. */
582 struct pcb dumppcb;
583 extern paddr_t avail_start;
584 
585 /*
586  * Write a crash dump.  The format while in swap is:
587  *   kcore_seg_t cpu_hdr;
588  *   cpu_kcore_hdr_t cpu_data;
589  *   padding (NBPG-sizeof(kcore_seg_t))
590  *   pagemap (2*NBPG)
591  *   physical memory...
592  */
593 void
594 dumpsys()
595 {
596 	const struct bdevsw *dsw;
597 	kcore_seg_t	*kseg_p;
598 	cpu_kcore_hdr_t *chdr_p;
599 	struct sun3_kcore_hdr *sh;
600 	char *vaddr;
601 	paddr_t paddr;
602 	int psize, todo, chunk;
603 	daddr_t blkno;
604 	int error = 0;
605 
606 	if (dumpdev == NODEV)
607 		return;
608 	if (dumppage == 0)
609 		return;
610 	dsw = bdevsw_lookup(dumpdev);
611 	if (dsw == NULL || dsw->d_psize == NULL)
612 		return;
613 
614 	/*
615 	 * For dumps during autoconfiguration,
616 	 * if dump device has already configured...
617 	 */
618 	if (dumpsize == 0)
619 		cpu_dumpconf();
620 	if (dumplo <= 0) {
621 		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
622 		    minor(dumpdev));
623 		return;
624 	}
625 	savectx(&dumppcb);
626 
627 	psize = (*(dsw->d_psize))(dumpdev);
628 	if (psize == -1) {
629 		printf("dump area unavailable\n");
630 		return;
631 	}
632 
633 	printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
634 	    minor(dumpdev), dumplo);
635 
636 	/*
637 	 * Prepare the dump header, including MMU state.
638 	 */
639 	blkno = dumplo;
640 	todo = dumpsize;	/* pages */
641 	vaddr = (char*)dumppage;
642 	memset(vaddr, 0, NBPG);
643 
644 	/* Set pointers to all three parts. */
645 	kseg_p = (kcore_seg_t *)vaddr;
646 	chdr_p = (cpu_kcore_hdr_t *) (kseg_p + 1);
647 	sh = &chdr_p->un._sun3;
648 
649 	/* Fill in kcore_seg_t part. */
650 	CORE_SETMAGIC(*kseg_p, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
651 	kseg_p->c_size = (ctob(DUMP_EXTRA) - sizeof(*kseg_p));
652 
653 	/* Fill in cpu_kcore_hdr_t part. */
654 	strncpy(chdr_p->name, kernel_arch, sizeof(chdr_p->name));
655 	chdr_p->page_size = NBPG;
656 	chdr_p->kernbase = KERNBASE;
657 
658 	/* Fill in the sun3_kcore_hdr part (MMU state). */
659 	pmap_kcore_hdr(sh);
660 
661 	/* Write out the dump header. */
662 	error = (*dsw->d_dump)(dumpdev, blkno, vaddr, NBPG);
663 	if (error)
664 		goto fail;
665 	blkno += btodb(NBPG);
666 
667 	/* translation RAM (page zero) */
668 	pmap_get_pagemap((int*)vaddr, 0);
669 	error = (*dsw->d_dump)(dumpdev, blkno, vaddr, NBPG);
670 	if (error)
671 		goto fail;
672 	blkno += btodb(NBPG);
673 
674 	/* translation RAM (page one) */
675 	pmap_get_pagemap((int*)vaddr, NBPG);
676 	error = (*dsw->d_dump)(dumpdev, blkno, vaddr, NBPG);
677 	if (error)
678 		goto fail;
679 	blkno += btodb(NBPG);
680 
681 	/*
682 	 * Now dump physical memory.  Have to do it in two chunks.
683 	 * The first chunk is "unmanaged" (by the VM code) and its
684 	 * range of physical addresses is not allow in pmap_enter.
685 	 * However, that segment is mapped linearly, so we can just
686 	 * use the virtual mappings already in place.  The second
687 	 * chunk is done the normal way, using pmap_enter.
688 	 *
689 	 * Note that vaddr==(paddr+KERNBASE) for paddr=0 through etext.
690 	 */
691 
692 	/* Do the first chunk (0 <= PA < avail_start) */
693 	paddr = 0;
694 	chunk = btoc(avail_start);
695 	if (chunk > todo)
696 		chunk = todo;
697 	do {
698 		if ((todo & 0xf) == 0)
699 			printf("\r%4d", todo);
700 		vaddr = (char*)(paddr + KERNBASE);
701 		error = (*dsw->d_dump)(dumpdev, blkno, vaddr, NBPG);
702 		if (error)
703 			goto fail;
704 		paddr += NBPG;
705 		blkno += btodb(NBPG);
706 		--todo;
707 	} while (--chunk > 0);
708 
709 	/* Do the second chunk (avail_start <= PA < dumpsize) */
710 	vaddr = (char*)vmmap;	/* Borrow /dev/mem VA */
711 	do {
712 		if ((todo & 0xf) == 0)
713 			printf("\r%4d", todo);
714 		pmap_kenter_pa(vmmap, paddr | PMAP_NC, VM_PROT_READ);
715 		pmap_update(pmap_kernel());
716 		error = (*dsw->d_dump)(dumpdev, blkno, vaddr, NBPG);
717 		pmap_kremove(vmmap, NBPG);
718 		pmap_update(pmap_kernel());
719 		if (error)
720 			goto fail;
721 		paddr += NBPG;
722 		blkno += btodb(NBPG);
723 	} while (--todo > 0);
724 
725 	printf("\rdump succeeded\n");
726 	return;
727 fail:
728 	printf(" dump error=%d\n", error);
729 }
730 
731 static void
732 initcpu()
733 {
734 	/* XXX: Enable RAM parity/ECC checking? */
735 	/* XXX: parityenable(); */
736 
737 #ifdef	HAVECACHE
738 	cache_enable();
739 #endif
740 }
741 
742 /* straptrap() in trap.c */
743 
744 /* from hp300: badaddr() */
745 /* peek_byte(), peek_word() moved to bus_subr.c */
746 
747 /* XXX: parityenable() ? */
748 /* regdump() moved to regdump.c */
749 
750 /*
751  * cpu_exec_aout_makecmds():
752  *	cpu-dependent a.out format hook for execve().
753  *
754  * Determine if the given exec package refers to something which we
755  * understand and, if so, set up the vmcmds for it.
756  */
757 int
758 cpu_exec_aout_makecmds(p, epp)
759 	struct proc *p;
760 	struct exec_package *epp;
761 {
762 	return ENOEXEC;
763 }
764