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