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