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