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