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