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