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