Home | History | Annotate | Line # | Download | only in sun3x
machdep.c revision 1.46
      1 /*	$NetBSD: machdep.c,v 1.46 1999/04/08 04:17:44 gwr 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_bufcache.h"
     45 #include "opt_ddb.h"
     46 #include "opt_sysv.h"
     47 
     48 #include <sys/param.h>
     49 #include <sys/systm.h>
     50 #include <sys/kernel.h>
     51 #include <sys/map.h>
     52 #include <sys/proc.h>
     53 #include <sys/buf.h>
     54 #include <sys/reboot.h>
     55 #include <sys/conf.h>
     56 #include <sys/file.h>
     57 #include <sys/clist.h>
     58 #include <sys/callout.h>
     59 #include <sys/device.h>
     60 #include <sys/malloc.h>
     61 #include <sys/mbuf.h>
     62 #include <sys/msgbuf.h>
     63 #include <sys/ioctl.h>
     64 #include <sys/tty.h>
     65 #include <sys/mount.h>
     66 #include <sys/user.h>
     67 #include <sys/exec.h>
     68 #include <sys/core.h>
     69 #include <sys/kcore.h>
     70 #include <sys/vnode.h>
     71 #include <sys/syscallargs.h>
     72 #ifdef SYSVMSG
     73 #include <sys/msg.h>
     74 #endif
     75 #ifdef SYSVSEM
     76 #include <sys/sem.h>
     77 #endif
     78 #ifdef SYSVSHM
     79 #include <sys/shm.h>
     80 #endif
     81 #ifdef	KGDB
     82 #include <sys/kgdb.h>
     83 #endif
     84 
     85 #include <vm/vm.h>
     86 #include <vm/vm_map.h>
     87 #include <vm/vm_kern.h>
     88 #include <vm/vm_page.h>
     89 
     90 #include <uvm/uvm_extern.h>
     91 
     92 #include <sys/sysctl.h>
     93 
     94 #include <dev/cons.h>
     95 
     96 #include <machine/cpu.h>
     97 #include <machine/dvma.h>
     98 #include <machine/idprom.h>
     99 #include <machine/kcore.h>
    100 #include <machine/reg.h>
    101 #include <machine/psl.h>
    102 #include <machine/pte.h>
    103 
    104 #if defined(DDB)
    105 #include <machine/db_machdep.h>
    106 #include <ddb/db_sym.h>
    107 #include <ddb/db_extern.h>
    108 #endif
    109 
    110 #include <sun3/sun3/machdep.h>
    111 
    112 /* Defined in locore.s */
    113 extern char kernel_text[];
    114 /* Defined by the linker */
    115 extern char etext[];
    116 
    117 vm_map_t exec_map = NULL;
    118 vm_map_t mb_map = NULL;
    119 vm_map_t phys_map = NULL;
    120 
    121 int	physmem;
    122 int	fputype;
    123 caddr_t	msgbufaddr;
    124 
    125 /* Virtual page frame for /dev/mem (see mem.c) */
    126 vm_offset_t vmmap;
    127 
    128 /*
    129  * safepri is a safe priority for sleep to set for a spin-wait
    130  * during autoconfiguration or after a panic.
    131  */
    132 int	safepri = PSL_LOWIPL;
    133 
    134 /*
    135  * Declare these as initialized data so we can patch them.
    136  */
    137 int	nswbuf = 0;
    138 #ifdef	NBUF
    139 int	nbuf = NBUF;
    140 #else
    141 int	nbuf = 0;
    142 #endif
    143 #ifdef	BUFPAGES
    144 int	bufpages = BUFPAGES;
    145 #else
    146 int	bufpages = 0;
    147 #endif
    148 
    149 u_char cpu_machine_id = 0;
    150 char *cpu_string = NULL;
    151 int cpu_has_vme = 0;
    152 int has_iocache = 0;
    153 
    154 static void identifycpu __P((void));
    155 static void initcpu __P((void));
    156 
    157 /*
    158  * Console initialization: called early on from main,
    159  * before vm init or cpu_startup.  This system is able
    160  * to use the console for output immediately (via PROM)
    161  * but can not use it for input until after this point.
    162  */
    163 void
    164 consinit()
    165 {
    166 
    167 	/*
    168 	 * Switch from the PROM console (output only)
    169 	 * to our own console driver.
    170 	 */
    171 	cninit();
    172 
    173 #ifdef DDB
    174 	db_machine_init();
    175 	{
    176 		extern int end[];
    177 		extern char *esym;
    178 
    179 		/* symsize, symstart, symend */
    180 		ddb_init(end[0], end + 1, (int*)esym);
    181 	}
    182 #endif DDB
    183 
    184 	/*
    185 	 * Now that the console can do input as well as
    186 	 * output, consider stopping for a debugger.
    187 	 */
    188 	if (boothowto & RB_KDB) {
    189 #ifdef KGDB
    190 		/* XXX - Ask on console for kgdb_dev? */
    191 		/* Note: this will just return if kgdb_dev==NODEV */
    192 		kgdb_connect(1);
    193 #else	/* KGDB */
    194 		/* Either DDB or no debugger (just PROM). */
    195 		Debugger();
    196 #endif	/* KGDB */
    197 	}
    198 }
    199 
    200 /*
    201  * allocsys() - Private routine used by cpu_startup() below.
    202  *
    203  * Allocate space for system data structures.  We are given
    204  * a starting virtual address and we return a final virtual
    205  * address; along the way we set each data structure pointer.
    206  *
    207  * We call allocsys() with 0 to find out how much space we want,
    208  * allocate that much and fill it with zeroes, and then call
    209  * allocsys() again with the correct base virtual address.
    210  */
    211 #define	valloc(name, type, num) \
    212 	v = (caddr_t)(((name) = (type *)v) + (num))
    213 static caddr_t allocsys __P((caddr_t));
    214 static caddr_t
    215 allocsys(v)
    216 	register caddr_t v;
    217 {
    218 
    219 #ifdef REAL_CLISTS
    220 	valloc(cfree, struct cblock, nclist);
    221 #endif
    222 	valloc(callout, struct callout, ncallout);
    223 #ifdef SYSVSHM
    224 	valloc(shmsegs, struct shmid_ds, shminfo.shmmni);
    225 #endif
    226 #ifdef SYSVSEM
    227 	valloc(sema, struct semid_ds, seminfo.semmni);
    228 	valloc(sem, struct sem, seminfo.semmns);
    229 	/* This is pretty disgusting! */
    230 	valloc(semu, int, (seminfo.semmnu * seminfo.semusz) / sizeof(int));
    231 #endif
    232 #ifdef SYSVMSG
    233 	valloc(msgpool, char, msginfo.msgmax);
    234 	valloc(msgmaps, struct msgmap, msginfo.msgseg);
    235 	valloc(msghdrs, struct msg, msginfo.msgtql);
    236 	valloc(msqids, struct msqid_ds, msginfo.msgmni);
    237 #endif
    238 
    239 	/*
    240 	 * Determine how many buffers to allocate. We allocate
    241 	 * the BSD standard of use 10% of memory for the first 2 Meg,
    242 	 * 5% of remaining. Insure a minimum of 16 buffers.
    243 	 * Allocate 1/2 as many swap buffer headers as file i/o buffers.
    244 	 */
    245 	if (bufpages == 0) {
    246 		/* We always have more than 2MB of memory. */
    247 		bufpages = ((btoc(2 * 1024 * 1024) + physmem) /
    248 		            (20 * CLSIZE));
    249 	}
    250 	if (nbuf == 0) {
    251 		nbuf = bufpages;
    252 		if (nbuf < 16)
    253 			nbuf = 16;
    254 	}
    255 	if (nswbuf == 0) {
    256 		nswbuf = (nbuf / 2) &~ 1;	/* force even */
    257 		if (nswbuf > 256)
    258 			nswbuf = 256;		/* sanity */
    259 	}
    260 	valloc(buf, struct buf, nbuf);
    261 	return v;
    262 }
    263 #undef	valloc
    264 
    265 /*
    266  * cpu_startup: allocate memory for variable-sized tables,
    267  * initialize cpu, and do autoconfiguration.
    268  *
    269  * This is called early in init_main.c:main(), after the
    270  * kernel memory allocator is ready for use, but before
    271  * the creation of processes 1,2, and mountroot, etc.
    272  */
    273 void
    274 cpu_startup()
    275 {
    276 	caddr_t v;
    277 	int sz, i;
    278 	vm_size_t size;
    279 	int base, residual;
    280 	vm_offset_t minaddr, maxaddr;
    281 
    282 	/*
    283 	 * Initialize message buffer (for kernel printf).
    284 	 * This is put in physical page zero so it will
    285 	 * always be in the same place after a reboot.
    286 	 * Its mapping was prepared in pmap_bootstrap().
    287 	 * Also, offset some to avoid PROM scribbles.
    288 	 */
    289 	v = (caddr_t) KERNBASE;
    290 	msgbufaddr = (caddr_t)(v + MSGBUFOFF);
    291 	initmsgbuf(msgbufaddr, MSGBUFSIZE);
    292 
    293 	/*
    294 	 * Good {morning,afternoon,evening,night}.
    295 	 */
    296 	printf(version);
    297 	identifycpu();
    298 	initfpu();	/* also prints FPU type */
    299 
    300 	size = ptoa(physmem);
    301 	printf("real  mem = %ldK (0x%lx)\n", (size >> 10), size);
    302 
    303 	/*
    304 	 * Find out how much space we need, allocate it,
    305 	 * and then give everything true virtual addresses.
    306 	 */
    307 	sz = (int)allocsys((caddr_t)0);
    308 	if ((v = (caddr_t)uvm_km_alloc(kernel_map, round_page(sz))) == 0)
    309 		panic("startup: no room for tables");
    310 	if (allocsys(v) - v != sz)
    311 		panic("startup: table size inconsistency");
    312 
    313 	/*
    314 	 * Now allocate buffers proper.  They are different than the above
    315 	 * in that they usually occupy more virtual memory than physical.
    316 	 */
    317 	size = MAXBSIZE * nbuf;
    318 	if (uvm_map(kernel_map, (vm_offset_t *) &buffers, round_page(size),
    319 		    NULL, UVM_UNKNOWN_OFFSET,
    320 		    UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
    321 				UVM_ADV_NORMAL, 0)) != KERN_SUCCESS)
    322 		panic("startup: cannot allocate VM for buffers");
    323 	minaddr = (vm_offset_t)buffers;
    324 	if ((bufpages / nbuf) >= btoc(MAXBSIZE)) {
    325 		/* don't want to alloc more physical mem than needed */
    326 		bufpages = btoc(MAXBSIZE) * nbuf;
    327 	}
    328 	base = bufpages / nbuf;
    329 	residual = bufpages % nbuf;
    330 	for (i = 0; i < nbuf; i++) {
    331 		vm_size_t curbufsize;
    332 		vm_offset_t curbuf;
    333 		struct vm_page *pg;
    334 
    335 		/*
    336 		 * Each buffer has MAXBSIZE bytes of VM space allocated.  Of
    337 		 * that MAXBSIZE space, we allocate and map (base+1) pages
    338 		 * for the first "residual" buffers, and then we allocate
    339 		 * "base" pages for the rest.
    340 		 */
    341 		curbuf = (vm_offset_t) buffers + (i * MAXBSIZE);
    342 		curbufsize = CLBYTES * ((i < residual) ? (base+1) : base);
    343 
    344 		while (curbufsize) {
    345 			pg = uvm_pagealloc(NULL, 0, NULL);
    346 			if (pg == NULL)
    347 				panic("cpu_startup: not enough memory for "
    348 				    "buffer cache");
    349 #if defined(PMAP_NEW)
    350 			pmap_kenter_pgs(curbuf, &pg, 1);
    351 #else
    352 			pmap_enter(kernel_map->pmap, curbuf,
    353 			    VM_PAGE_TO_PHYS(pg), VM_PROT_READ|VM_PROT_WRITE,
    354 			    TRUE, VM_PROT_READ|VM_PROT_WRITE);
    355 #endif
    356 			curbuf += PAGE_SIZE;
    357 			curbufsize -= PAGE_SIZE;
    358 		}
    359 	}
    360 
    361 	/*
    362 	 * Allocate a submap for exec arguments.  This map effectively
    363 	 * limits the number of processes exec'ing at any time.
    364 	 */
    365 	exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    366 				   16*NCARGS, TRUE, FALSE, NULL);
    367 
    368 	/*
    369 	 * We don't use a submap for physio, and use a separate map
    370 	 * for DVMA allocations.  Our vmapbuf just maps pages into
    371 	 * the kernel map (any kernel mapping is OK) and then the
    372 	 * device drivers clone the kernel mappings into DVMA space.
    373 	 */
    374 
    375 	/*
    376 	 * Finally, allocate mbuf cluster submap.
    377 	 */
    378 	mb_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    379 				 VM_MBUF_SIZE, FALSE, FALSE, NULL);
    380 
    381 	/*
    382 	 * Initialize callouts
    383 	 */
    384 	callfree = callout;
    385 	for (i = 1; i < ncallout; i++)
    386 		callout[i-1].c_next = &callout[i];
    387 	callout[i-1].c_next = NULL;
    388 
    389 	size = ptoa(uvmexp.free);
    390 	printf("avail mem = %ldK (0x%lx)\n", (size >> 10), size);
    391 	printf("using %d buffers containing %d bytes of memory\n",
    392 		   nbuf, bufpages * CLBYTES);
    393 
    394 	/*
    395 	 * Tell the VM system that writing to kernel text isn't allowed.
    396 	 * If we don't, we might end up COW'ing the text segment!
    397 	 */
    398 	if (uvm_map_protect(kernel_map, (vm_offset_t) kernel_text,
    399 	    m68k_trunc_page((vm_offset_t) etext),
    400 	    UVM_PROT_READ|UVM_PROT_EXEC, TRUE) != KERN_SUCCESS)
    401 		panic("can't protect kernel text");
    402 
    403 	/*
    404 	 * Allocate a virtual page (for use by /dev/mem)
    405 	 * This page is handed to pmap_enter() therefore
    406 	 * it has to be in the normal kernel VA range.
    407 	 */
    408 	vmmap = uvm_km_valloc_wait(kernel_map, NBPG);
    409 
    410 	/*
    411 	 * Create the DVMA maps.
    412 	 */
    413 	dvma_init();
    414 
    415 	/*
    416 	 * Set up CPU-specific registers, cache, etc.
    417 	 */
    418 	initcpu();
    419 
    420 	/*
    421 	 * Set up buffers, so they can be used to read disk labels.
    422 	 */
    423 	bufinit();
    424 }
    425 
    426 /*
    427  * Set registers on exec.
    428  */
    429 void
    430 setregs(p, pack, stack)
    431 	struct proc *p;
    432 	struct exec_package *pack;
    433 	u_long stack;
    434 {
    435 	struct trapframe *tf = (struct trapframe *)p->p_md.md_regs;
    436 
    437 	tf->tf_sr = PSL_USERSET;
    438 	tf->tf_pc = pack->ep_entry & ~1;
    439 	tf->tf_regs[D0] = 0;
    440 	tf->tf_regs[D1] = 0;
    441 	tf->tf_regs[D2] = 0;
    442 	tf->tf_regs[D3] = 0;
    443 	tf->tf_regs[D4] = 0;
    444 	tf->tf_regs[D5] = 0;
    445 	tf->tf_regs[D6] = 0;
    446 	tf->tf_regs[D7] = 0;
    447 	tf->tf_regs[A0] = 0;
    448 	tf->tf_regs[A1] = 0;
    449 	tf->tf_regs[A2] = (int)PS_STRINGS;
    450 	tf->tf_regs[A3] = 0;
    451 	tf->tf_regs[A4] = 0;
    452 	tf->tf_regs[A5] = 0;
    453 	tf->tf_regs[A6] = 0;
    454 	tf->tf_regs[SP] = stack;
    455 
    456 	/* restore a null state frame */
    457 	p->p_addr->u_pcb.pcb_fpregs.fpf_null = 0;
    458 	if (fputype)
    459 		m68881_restore(&p->p_addr->u_pcb.pcb_fpregs);
    460 
    461 	p->p_md.md_flags = 0;
    462 }
    463 
    464 /*
    465  * Info for CTL_HW
    466  */
    467 char	machine[16] = MACHINE;		/* from <machine/param.h> */
    468 char	kernel_arch[16] = "sun3x";	/* XXX needs a sysctl node */
    469 char	cpu_model[120];
    470 
    471 /*
    472  * XXX - Should empirically estimate the divisor...
    473  * Note that the value of delay_divisor is roughly
    474  * 2048 / cpuclock	(where cpuclock is in MHz).
    475  */
    476 int delay_divisor = 62;		/* assume the fastest (33 MHz) */
    477 
    478 void
    479 identifycpu()
    480 {
    481 	u_char machtype;
    482 
    483 	machtype = identity_prom.idp_machtype;
    484 	if ((machtype & IDM_ARCH_MASK) != IDM_ARCH_SUN3X) {
    485 		printf("Bad IDPROM arch!\n");
    486 		sunmon_abort();
    487 	}
    488 
    489 	cpu_machine_id = machtype;
    490 	switch (cpu_machine_id) {
    491 
    492 	case SUN3X_MACH_80:
    493 		cpu_string = "80";  	/* Hydra */
    494 		delay_divisor = 102;	/* 20 MHz */
    495 		cpu_has_vme = FALSE;
    496 		break;
    497 
    498 	case SUN3X_MACH_470:
    499 		cpu_string = "470"; 	/* Pegasus */
    500 		delay_divisor = 62; 	/* 33 MHz */
    501 		cpu_has_vme = TRUE;
    502 		break;
    503 
    504 	default:
    505 		printf("unknown sun3x model\n");
    506 		sunmon_abort();
    507 	}
    508 
    509 	/* Other stuff? (VAC, mc6888x version, etc.) */
    510 	/* Note: miniroot cares about the kernel_arch part. */
    511 	sprintf(cpu_model, "%s %s", kernel_arch, cpu_string);
    512 
    513 	printf("Model: %s\n", cpu_model);
    514 }
    515 
    516 /*
    517  * machine dependent system variables.
    518  */
    519 int
    520 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
    521 	int *name;
    522 	u_int namelen;
    523 	void *oldp;
    524 	size_t *oldlenp;
    525 	void *newp;
    526 	size_t newlen;
    527 	struct proc *p;
    528 {
    529 	int error;
    530 	dev_t consdev;
    531 
    532 	/* all sysctl names at this level are terminal */
    533 	if (namelen != 1)
    534 		return (ENOTDIR);		/* overloaded */
    535 
    536 	switch (name[0]) {
    537 	case CPU_CONSDEV:
    538 		if (cn_tab != NULL)
    539 			consdev = cn_tab->cn_dev;
    540 		else
    541 			consdev = NODEV;
    542 		error = sysctl_rdstruct(oldp, oldlenp, newp,
    543 		    &consdev, sizeof consdev);
    544 		break;
    545 
    546 #if 0	/* XXX - Not yet... */
    547 	case CPU_ROOT_DEVICE:
    548 		error = sysctl_rdstring(oldp, oldlenp, newp, root_device);
    549 		break;
    550 
    551 	case CPU_BOOTED_KERNEL:
    552 		error = sysctl_rdstring(oldp, oldlenp, newp, booted_kernel);
    553 		break;
    554 #endif
    555 
    556 	default:
    557 		error = EOPNOTSUPP;
    558 	}
    559 	return (error);
    560 }
    561 
    562 /* See: sig_machdep.c */
    563 
    564 /*
    565  * Do a sync in preparation for a reboot.
    566  * XXX - This could probably be common code.
    567  * XXX - And now, most of it is in vfs_shutdown()
    568  * XXX - Put waittime checks in there too?
    569  */
    570 int waittime = -1;	/* XXX - Who else looks at this? -gwr */
    571 static void
    572 reboot_sync __P((void))
    573 {
    574 
    575 	/* Check waittime here to localize its use to this function. */
    576 	if (waittime >= 0)
    577 		return;
    578 	waittime = 0;
    579 	vfs_shutdown();
    580 }
    581 
    582 /*
    583  * Common part of the BSD and SunOS reboot system calls.
    584  */
    585 __dead void
    586 cpu_reboot(howto, user_boot_string)
    587 	int howto;
    588 	char *user_boot_string;
    589 {
    590 	/* Note: this string MUST be static! */
    591 	static char bootstr[128];
    592 	char *p;
    593 
    594 	/* If system is cold, just halt. (early panic?) */
    595 	if (cold)
    596 		goto haltsys;
    597 
    598 	/* Un-blank the screen if appropriate. */
    599 	cnpollc(1);
    600 
    601 	if ((howto & RB_NOSYNC) == 0) {
    602 		reboot_sync();
    603 		/*
    604 		 * If we've been adjusting the clock, the todr
    605 		 * will be out of synch; adjust it now.
    606 		 *
    607 		 * XXX - However, if the kernel has been sitting in ddb,
    608 		 * the time will be way off, so don't set the HW clock!
    609 		 * XXX - Should do sanity check against HW clock. -gwr
    610 		 */
    611 		/* resettodr(); */
    612 	}
    613 
    614 	/* Disable interrupts. */
    615 	splhigh();
    616 
    617 	/* Write out a crash dump if asked. */
    618 	if (howto & RB_DUMP)
    619 		dumpsys();
    620 
    621 	/* run any shutdown hooks */
    622 	doshutdownhooks();
    623 
    624 	if (howto & RB_HALT) {
    625 	haltsys:
    626 		printf("Kernel halted.\n");
    627 #if 0
    628 		/*
    629 		 * This calls the PROM monitor "exit_to_mon" function
    630 		 * which appears to have problems...  SunOS uses the
    631 		 * "abort" function when you halt (bug work-around?)
    632 		 * so we might as well do the same.
    633 		 */
    634 		sunmon_halt(); /* provokes PROM monitor bug */
    635 #else
    636 		sunmon_abort();
    637 #endif
    638 	}
    639 
    640 	/*
    641 	 * Automatic reboot.
    642 	 */
    643 	if (user_boot_string)
    644 		strncpy(bootstr, user_boot_string, sizeof(bootstr));
    645 	else {
    646 		/*
    647 		 * Build our own boot string with an empty
    648 		 * boot device/file and (maybe) some flags.
    649 		 * The PROM will supply the device/file name.
    650 		 */
    651 		p = bootstr;
    652 		*p = '\0';
    653 		if (howto & (RB_KDB|RB_ASKNAME|RB_SINGLE)) {
    654 			/* Append the boot flags. */
    655 			*p++ = ' ';
    656 			*p++ = '-';
    657 			if (howto & RB_KDB)
    658 				*p++ = 'd';
    659 			if (howto & RB_ASKNAME)
    660 				*p++ = 'a';
    661 			if (howto & RB_SINGLE)
    662 				*p++ = 's';
    663 			*p = '\0';
    664 		}
    665 	}
    666 	printf("Kernel rebooting...\n");
    667 	sunmon_reboot(bootstr);
    668 	for (;;) ;
    669 	/*NOTREACHED*/
    670 }
    671 
    672 /*
    673  * These variables are needed by /sbin/savecore
    674  */
    675 u_long	dumpmag = 0x8fca0101;	/* magic number */
    676 int 	dumpsize = 0;		/* pages */
    677 long	dumplo = 0; 		/* blocks */
    678 
    679 /*
    680  * This is called by main to set dumplo, dumpsize.
    681  * Dumps always skip the first CLBYTES of disk space
    682  * in case there might be a disk label stored there.
    683  * If there is extra space, put dump at the end to
    684  * reduce the chance that swapping trashes it.
    685  */
    686 void
    687 cpu_dumpconf()
    688 {
    689 	int nblks;	/* size of dump area */
    690 	int maj;
    691 	int (*getsize)__P((dev_t));
    692 
    693 	/* Validate space in page zero for the kcore header. */
    694 	if (MSGBUFOFF < (sizeof(kcore_seg_t) + sizeof(cpu_kcore_hdr_t)))
    695 		panic("cpu_dumpconf: MSGBUFOFF too small");
    696 
    697 	if (dumpdev == NODEV)
    698 		return;
    699 
    700 	maj = major(dumpdev);
    701 	if (maj < 0 || maj >= nblkdev)
    702 		panic("dumpconf: bad dumpdev=0x%x", dumpdev);
    703 	getsize = bdevsw[maj].d_psize;
    704 	if (getsize == NULL)
    705 		return;
    706 	nblks = (*getsize)(dumpdev);
    707 	if (nblks <= ctod(1))
    708 		return;
    709 
    710 	/* Position dump image near end of space, page aligned. */
    711 	dumpsize = physmem; 	/* pages */
    712 	dumplo = nblks - ctod(dumpsize);
    713 	dumplo &= ~(ctod(1)-1);
    714 
    715 	/* If it does not fit, truncate it by moving dumplo. */
    716 	/* Note: Must force signed comparison. */
    717 	if (dumplo < ((long)ctod(1))) {
    718 		dumplo = ctod(1);
    719 		dumpsize = dtoc(nblks - dumplo);
    720 	}
    721 }
    722 
    723 /* Note: gdb looks for "dumppcb" in a kernel crash dump. */
    724 struct pcb dumppcb;
    725 
    726 /*
    727  * Write a crash dump.  The format while in swap is:
    728  *   kcore_seg_t cpu_hdr;
    729  *   cpu_kcore_hdr_t cpu_data;
    730  *   padding (NBPG-sizeof(kcore_seg_t))
    731  *   pagemap (2*NBPG)
    732  *   physical memory...
    733  */
    734 void
    735 dumpsys()
    736 {
    737 	struct bdevsw *dsw;
    738 	kcore_seg_t	*kseg_p;
    739 	cpu_kcore_hdr_t *chdr_p;
    740 	struct sun3x_kcore_hdr *sh;
    741 	phys_ram_seg_t *crs_p;
    742 	char *vaddr;
    743 	vm_offset_t paddr;
    744 	int psize, todo, seg, segsz;
    745 	daddr_t blkno;
    746 	int error = 0;
    747 
    748 	msgbufenabled = 0;
    749 	if (dumpdev == NODEV)
    750 		return;
    751 
    752 	/*
    753 	 * For dumps during autoconfiguration,
    754 	 * if dump device has already configured...
    755 	 */
    756 	if (dumpsize == 0)
    757 		cpu_dumpconf();
    758 	if (dumplo <= 0) {
    759 		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
    760 		    minor(dumpdev));
    761 		return;
    762 	}
    763 	savectx(&dumppcb);
    764 
    765 	dsw = &bdevsw[major(dumpdev)];
    766 	psize = (*(dsw->d_psize))(dumpdev);
    767 	if (psize == -1) {
    768 		printf("dump area unavailable\n");
    769 		return;
    770 	}
    771 
    772 	printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
    773 	    minor(dumpdev), dumplo);
    774 
    775 	/*
    776 	 * We put the dump header is in physical page zero,
    777 	 * so there is no extra work here to write it out.
    778 	 * All we do is initialize the header.
    779 	 */
    780 
    781 	/* Set pointers to all three parts. */
    782 	kseg_p = (kcore_seg_t *)KERNBASE;
    783 	chdr_p = (cpu_kcore_hdr_t *) (kseg_p + 1);
    784 	sh = &chdr_p->un._sun3x;
    785 
    786 	/* Fill in kcore_seg_t part. */
    787 	CORE_SETMAGIC(*kseg_p, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
    788 	kseg_p->c_size = sizeof(*chdr_p);
    789 
    790 	/* Fill in cpu_kcore_hdr_t part. */
    791 	strncpy(chdr_p->name, kernel_arch, sizeof(chdr_p->name));
    792 	chdr_p->page_size = NBPG;
    793 	chdr_p->kernbase = KERNBASE;
    794 
    795 	/* Fill in the sun3x_kcore_hdr part. */
    796 	pmap_kcore_hdr(sh);
    797 
    798 	/*
    799 	 * Now dump physical memory.  Note that physical memory
    800 	 * might NOT be congiguous, so do it by segments.
    801 	 */
    802 
    803 	blkno = dumplo;
    804 	todo = dumpsize;	/* pages */
    805 	vaddr = (char*)vmmap;	/* Borrow /dev/mem VA */
    806 
    807 	for (seg = 0; seg < SUN3X_NPHYS_RAM_SEGS; seg++) {
    808 		crs_p = &sh->ram_segs[seg];
    809 		paddr = crs_p->start;
    810 		segsz = crs_p->size;
    811 		/*
    812 		 * Our header lives in the first little bit of
    813 		 * physical memory (not written separately), so
    814 		 * we have to adjust the first ram segment size
    815 		 * and start address to reflect the stolen RAM.
    816 		 * (Nothing interesing in that RAM anyway 8^).
    817 		 */
    818 		if (seg == 0) {
    819 			int adj = sizeof(*kseg_p) + sizeof(*chdr_p);
    820 			crs_p->start += adj;
    821 			crs_p->size  -= adj;
    822 		}
    823 
    824 		while (todo && (segsz > 0)) {
    825 
    826 			/* Print pages left after every 16. */
    827 			if ((todo & 0xf) == 0)
    828 				printf("\r%4d", todo);
    829 
    830 			/* Make a temporary mapping for the page. */
    831 			pmap_enter(pmap_kernel(), vmmap, paddr | PMAP_NC,
    832 					   VM_PROT_READ, FALSE, 0);
    833 			error = (*dsw->d_dump)(dumpdev, blkno, vaddr, NBPG);
    834 			pmap_remove(pmap_kernel(), vmmap, vmmap + NBPG);
    835 			if (error)
    836 				goto fail;
    837 			paddr += NBPG;
    838 			segsz -= NBPG;
    839 			blkno += btodb(NBPG);
    840 			todo--;
    841 		}
    842 	}
    843 	printf("\rdump succeeded\n");
    844 	return;
    845 fail:
    846 	printf(" dump error=%d\n", error);
    847 }
    848 
    849 static void
    850 initcpu()
    851 {
    852 	/* XXX: Enable RAM parity/ECC checking? */
    853 	/* XXX: parityenable(); */
    854 
    855 #ifdef	HAVECACHE
    856 	cache_enable();
    857 #endif
    858 }
    859 
    860 /* straptrap() in trap.c */
    861 
    862 /* from hp300: badaddr() */
    863 /* peek_byte(), peek_word() moved to bus_subr.c */
    864 
    865 /* XXX: parityenable() ? */
    866 /* regdump() moved to regdump.c */
    867 
    868 /*
    869  * cpu_exec_aout_makecmds():
    870  *	cpu-dependent a.out format hook for execve().
    871  *
    872  * Determine if the given exec package refers to something which we
    873  * understand and, if so, set up the vmcmds for it.
    874  */
    875 int
    876 cpu_exec_aout_makecmds(p, epp)
    877 	struct proc *p;
    878 	struct exec_package *epp;
    879 {
    880 	return ENOEXEC;
    881 }
    882