Home | History | Annotate | Line # | Download | only in luna68k
machdep.c revision 1.41
      1 /* $NetBSD: machdep.c,v 1.41 2005/06/05 09:08:48 he Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Tohru Nishimura.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     40 
     41 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.41 2005/06/05 09:08:48 he Exp $");
     42 
     43 #include "opt_ddb.h"
     44 #include "opt_kgdb.h"
     45 #include "opt_compat_sunos.h"
     46 #include "opt_panicbutton.h"
     47 
     48 #include <sys/param.h>
     49 #include <sys/systm.h>
     50 #include <sys/kernel.h>
     51 #include <sys/proc.h>
     52 #include <sys/buf.h>
     53 #include <sys/reboot.h>
     54 #include <sys/conf.h>
     55 #include <sys/file.h>
     56 #include <sys/device.h>
     57 #include <sys/malloc.h>
     58 #include <sys/mbuf.h>
     59 #include <sys/msgbuf.h>
     60 #include <sys/ioctl.h>
     61 #include <sys/tty.h>
     62 #include <sys/mount.h>
     63 #include <sys/user.h>
     64 #include <sys/exec.h>
     65 #include <sys/core.h>
     66 #include <sys/kcore.h>
     67 #include <sys/vnode.h>
     68 #include <sys/sa.h>
     69 #include <sys/syscallargs.h>
     70 #include <sys/ksyms.h>
     71 #ifdef	KGDB
     72 #include <sys/kgdb.h>
     73 #endif
     74 #include <sys/boot_flag.h>
     75 
     76 #include <uvm/uvm_extern.h>
     77 
     78 #include <sys/sysctl.h>
     79 
     80 #include <machine/cpu.h>
     81 #include <machine/reg.h>
     82 #include <machine/psl.h>
     83 #include <machine/pte.h>
     84 #include <machine/kcore.h>	/* XXX should be pulled in by sys/kcore.h */
     85 
     86 #include <dev/cons.h>
     87 
     88 #if defined(DDB)
     89 #include <machine/db_machdep.h>
     90 #include <ddb/db_sym.h>
     91 #include <ddb/db_extern.h>
     92 #endif
     93 
     94 #include "ksyms.h"
     95 
     96 /*
     97  * Info for CTL_HW
     98  */
     99 char	machine[] = MACHINE;
    100 char	cpu_model[60];
    101 
    102 /* Our exported CPU info; we can have only one. */
    103 struct cpu_info cpu_info_store;
    104 
    105 struct vm_map *exec_map = NULL;
    106 struct vm_map *mb_map = NULL;
    107 struct vm_map *phys_map = NULL;
    108 
    109 caddr_t	msgbufaddr;
    110 int	maxmem;			/* max memory per process */
    111 int	physmem;		/* set by locore */
    112 /*
    113  * safepri is a safe priority for sleep to set for a spin-wait
    114  * during autoconfiguration or after a panic.
    115  */
    116 int	safepri = PSL_LOWIPL;
    117 
    118 void luna68k_init __P((void));
    119 void identifycpu __P((void));
    120 void dumpsys __P((void));
    121 
    122 void straytrap __P((int, u_short));
    123 void nmihand __P((struct frame));
    124 
    125 int  cpu_dumpsize __P((void));
    126 int  cpu_dump __P((int (*)(dev_t, daddr_t, caddr_t, size_t), daddr_t *));
    127 void cpu_init_kcore_hdr __P((void));
    128 
    129 /*
    130  * Machine-independent crash dump header info.
    131  */
    132 cpu_kcore_hdr_t cpu_kcore_hdr;
    133 
    134 int	machtype;	/* model: 1 for LUNA-1, 2 for LUNA-2 */
    135 int	sysconsole;	/* console: 0 for ttya, 1 for video */
    136 
    137 extern struct consdev syscons;
    138 extern void omfb_cnattach __P((void));
    139 extern void ws_cnattach __P((void));
    140 extern void syscnattach __P((int));
    141 
    142 /*
    143  * On the 68020/68030, the value of delay_divisor is roughly
    144  * 2048 / cpuspeed (where cpuspeed is in MHz).
    145  *
    146  * On the 68040/68060(?), the value of delay_divisor is roughly
    147  * 759 / cpuspeed (where cpuspeed is in MHz).
    148  * XXX -- is the above formula correct?
    149  */
    150 int	cpuspeed = 25;		/* only used for printing later */
    151 int	delay_divisor = 300;	/* for delay() loop count */
    152 
    153 /*
    154  * Early initialization, before main() is called.
    155  */
    156 void
    157 luna68k_init()
    158 {
    159 	volatile unsigned char *pio0 = (void *)0x49000000;
    160 	int sw1, i;
    161 	char *cp;
    162 	extern char bootarg[64];
    163 
    164 	extern paddr_t avail_start, avail_end;
    165 
    166 	/*
    167 	 * Tell the VM system about available physical memory.  The
    168 	 * luna68k only has one segment.
    169 	 */
    170 	uvm_page_physload(atop(avail_start), atop(avail_end),
    171 	    atop(avail_start), atop(avail_end), VM_FREELIST_DEFAULT);
    172 
    173 	/*
    174 	 * Initialize error message buffer (at end of core).
    175 	 * avail_end was pre-decremented in pmap_bootstrap to compensate.
    176 	 */
    177 	for (i = 0; i < btoc(MSGBUFSIZE); i++)
    178 		pmap_enter(pmap_kernel(), (vaddr_t)msgbufaddr + i * PAGE_SIZE,
    179 		    avail_end + i * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE,
    180 		    VM_PROT_READ|VM_PROT_WRITE|PMAP_WIRED);
    181 	pmap_update(pmap_kernel());
    182 	initmsgbuf(msgbufaddr, m68k_round_page(MSGBUFSIZE));
    183 
    184 
    185 	pio0[3] = 0xb6;
    186 	pio0[2] = 1 << 6;		/* enable parity check */
    187 	pio0[3] = 0xb6;
    188 	sw1 = pio0[0];			/* dipssw1 value */
    189 	sw1 ^= 0xff;
    190 	sysconsole = !(sw1 & 0x2);	/* console selection */
    191 
    192 	boothowto = 0;
    193 	i = 0;
    194 	/*
    195 	 * 'bootarg' has;
    196 	 *   "<args of x command> ENADDR=<addr> HOST=<host> SERVER=<name>"
    197 	 * where <addr> is MAC address of which network loader used (not
    198 	 * necessarily same as one at 0x4101.FFE0), <host> and <name>
    199 	 * are the values of HOST and SERVER environment variables,
    200 	 *
    201 	 * NetBSD/luna68k cares only the first argment; any of "sda".
    202 	 */
    203 	for (cp = bootarg; *cp != ' '; cp++) {
    204 		BOOT_FLAG(*cp, boothowto);
    205 		if (i++ >= sizeof(bootarg))
    206 			break;
    207 	}
    208 #if 0 /* overload 1:sw1, which now means 'go ROM monitor' after poweron */
    209 	if (boothowto == 0)
    210 		boothowto = (sw1 & 0x1) ? RB_SINGLE : 0;
    211 #endif
    212 }
    213 
    214 /*
    215  * Console initialization: called early on from main,
    216  */
    217 void
    218 consinit()
    219 {
    220 	if (sysconsole == 0)
    221 		syscnattach(0);
    222 	else {
    223 		omfb_cnattach();
    224 		ws_cnattach();
    225 	}
    226 
    227 #if NKSYMS || defined(DDB) || defined(LKM)
    228 	{
    229 		extern int end;
    230 		extern int *esym;
    231 
    232 		ksyms_init(*(int *)&end, ((int *)&end) + 1, esym);
    233 	}
    234 #endif
    235 #ifdef DDB
    236 	if (boothowto & RB_KDB)
    237 		cpu_Debugger();
    238 #endif
    239 }
    240 
    241 /*
    242  * cpu_startup: allocate memory for variable-sized tables.
    243  */
    244 void
    245 cpu_startup()
    246 {
    247 	vaddr_t minaddr, maxaddr;
    248 	char pbuf[9];
    249 	extern void greeting __P((void));
    250 
    251 	if (fputype != FPU_NONE)
    252 		m68k_make_fpu_idle_frame();
    253 
    254 	/*
    255 	 * Initialize the kernel crash dump header.
    256 	 */
    257 	cpu_init_kcore_hdr();
    258 
    259 	/*
    260 	 * Good {morning,afternoon,evening,night}.
    261 	 */
    262 	printf("%s%s", copyright, version);
    263 	identifycpu();
    264 
    265 	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
    266 	printf("total memory = %s\n", pbuf);
    267 
    268 	minaddr = 0;
    269 	/*
    270 	 * Allocate a submap for exec arguments.  This map effectively
    271 	 * limits the number of processes exec'ing at any time.
    272 	 */
    273 	exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    274 				   16*NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
    275 
    276 	/*
    277 	 * Allocate a submap for physio
    278 	 */
    279 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    280 				   VM_PHYS_SIZE, 0, FALSE, NULL);
    281 
    282 	/*
    283 	 * Finally, allocate mbuf cluster submap.
    284 	 */
    285 	mb_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    286 				 nmbclusters * mclbytes, VM_MAP_INTRSAFE,
    287 				 FALSE, NULL);
    288 
    289 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
    290 	printf("avail memory = %s\n", pbuf);
    291 
    292 	/*
    293 	 * Say "Hi" to the world
    294 	 */
    295 	greeting();
    296 }
    297 
    298 /*
    299  * Set registers on exec.
    300  */
    301 void
    302 setregs(l, pack, stack)
    303 	struct lwp *l;
    304 	struct exec_package *pack;
    305 	u_long stack;
    306 {
    307 	struct frame *frame = (struct frame *)l->l_md.md_regs;
    308 	extern int fputype;
    309 
    310 	frame->f_sr = PSL_USERSET;
    311 	frame->f_pc = pack->ep_entry & ~1;
    312 	frame->f_regs[D0] = 0;
    313 	frame->f_regs[D1] = 0;
    314 	frame->f_regs[D2] = 0;
    315 	frame->f_regs[D3] = 0;
    316 	frame->f_regs[D4] = 0;
    317 	frame->f_regs[D5] = 0;
    318 	frame->f_regs[D6] = 0;
    319 	frame->f_regs[D7] = 0;
    320 	frame->f_regs[A0] = 0;
    321 	frame->f_regs[A1] = 0;
    322 	frame->f_regs[A2] = (int)l->l_proc->p_psstr;
    323 	frame->f_regs[A3] = 0;
    324 	frame->f_regs[A4] = 0;
    325 	frame->f_regs[A5] = 0;
    326 	frame->f_regs[A6] = 0;
    327 	frame->f_regs[SP] = stack;
    328 
    329 	/* restore a null state frame */
    330 	l->l_addr->u_pcb.pcb_fpregs.fpf_null = 0;
    331 	if (fputype)
    332 		m68881_restore(&l->l_addr->u_pcb.pcb_fpregs);
    333 }
    334 
    335 void
    336 identifycpu()
    337 {
    338 	extern int cputype;
    339 	const char *cpu;
    340 
    341 	bzero(cpu_model, sizeof(cpu_model));
    342 	switch (cputype) {
    343 	case CPU_68030:
    344 		cpu = "MC68030 CPU+MMU, MC68882 FPU";
    345 		machtype = LUNA_I;
    346 		cpuspeed = 20; delay_divisor = 102;	/* 20MHz 68030 */
    347 		hz = 60;
    348 		break;
    349 #if defined(M68040)
    350 	case CPU_68040:
    351 		cpu = "MC68040 CPU+MMU+FPU, 4k on-chip physical I/D caches";
    352 		machtype = LUNA_II;
    353 		cpuspeed = 25; delay_divisor = 300;	/* 25MHz 68040 */
    354 		break;
    355 #endif
    356 	default:
    357 		panic("unknown CPU type");
    358 	}
    359 	strcpy(cpu_model, cpu);
    360 	printf("%s\n", cpu_model);
    361 }
    362 
    363 /*
    364  * machine dependent system variables.
    365  */
    366 SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
    367 {
    368 
    369 	sysctl_createv(clog, 0, NULL, NULL,
    370 		       CTLFLAG_PERMANENT,
    371 		       CTLTYPE_NODE, "machdep", NULL,
    372 		       NULL, 0, NULL, 0,
    373 		       CTL_MACHDEP, CTL_EOL);
    374 
    375 	sysctl_createv(clog, 0, NULL, NULL,
    376 		       CTLFLAG_PERMANENT,
    377 		       CTLTYPE_STRUCT, "console_device", NULL,
    378 		       sysctl_consdev, 0, NULL, sizeof(dev_t),
    379 		       CTL_MACHDEP, CPU_CONSDEV, CTL_EOL);
    380 }
    381 
    382 int	waittime = -1;
    383 
    384 void
    385 cpu_reboot(howto, bootstr)
    386 	volatile int howto; /* XXX to shutup GCC XXX */
    387 	char *bootstr;
    388 {
    389 	extern void doboot __P((void));
    390 
    391 	/* take a snap shot before clobbering any registers */
    392 	if (curlwp && curlwp->l_addr)
    393 		savectx(&curlwp->l_addr->u_pcb);
    394 
    395 	/* If system is hold, just halt. */
    396 	if (cold) {
    397 		howto |= RB_HALT;
    398 		goto haltsys;
    399 	}
    400 
    401 	boothowto = howto;
    402 	if ((howto & RB_NOSYNC) == 0 && waittime < 0) {
    403 		waittime = 0;
    404 		vfs_shutdown();
    405 		/*
    406 		 * If we've been adjusting the clock, the todr
    407 		 * will be out of synch; adjust it now.
    408 		 */
    409 		resettodr();
    410 	}
    411 
    412 	/* Disable interrupts. */
    413 	splhigh();
    414 
    415 	/* If rebooting and a dump is requested, do it. */
    416 	if (howto & RB_DUMP)
    417 		dumpsys();
    418 
    419 haltsys:
    420 	/* Run any shutdown hooks. */
    421 	doshutdownhooks();
    422 
    423 	/* Finally, halt/reboot the system. */
    424 	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
    425 		u_int8_t *pio = (void *)0x4d000000;
    426 
    427 		printf("power is going down.\n");
    428 		DELAY(100000);
    429 		pio[3] = 0x94;
    430 		pio[2] = 0 << 4;
    431 		for (;;) /* NOP */;
    432 	}
    433 	if (howto & RB_HALT) {
    434 		printf("System halted.	Hit any key to reboot.\n\n");
    435 		(void)cngetc();
    436 	}
    437 
    438 	printf("rebooting...\n");
    439 	DELAY(100000);
    440 	doboot();
    441 	/*NOTREACHED*/
    442 	while (1) ;
    443 }
    444 
    445 /*
    446  * Initialize the kernel crash dump header.
    447  */
    448 void
    449 cpu_init_kcore_hdr()
    450 {
    451 	cpu_kcore_hdr_t *h = &cpu_kcore_hdr;
    452 	struct m68k_kcore_hdr *m = &h->un._m68k;
    453 	extern char end[];
    454 
    455 	bzero(&cpu_kcore_hdr, sizeof(cpu_kcore_hdr));
    456 
    457 	/*
    458 	 * Initialize the `dispatcher' portion of the header.
    459 	 */
    460 	strcpy(h->name, machine);
    461 	h->page_size = PAGE_SIZE;
    462 	h->kernbase = KERNBASE;
    463 
    464 	/*
    465 	 * Fill in information about our MMU configuration.
    466 	 */
    467 	m->mmutype	= mmutype;
    468 	m->sg_v		= SG_V;
    469 	m->sg_frame	= SG_FRAME;
    470 	m->sg_ishift	= SG_ISHIFT;
    471 	m->sg_pmask	= SG_PMASK;
    472 	m->sg40_shift1	= SG4_SHIFT1;
    473 	m->sg40_mask2	= SG4_MASK2;
    474 	m->sg40_shift2	= SG4_SHIFT2;
    475 	m->sg40_mask3	= SG4_MASK3;
    476 	m->sg40_shift3	= SG4_SHIFT3;
    477 	m->sg40_addr1	= SG4_ADDR1;
    478 	m->sg40_addr2	= SG4_ADDR2;
    479 	m->pg_v		= PG_V;
    480 	m->pg_frame	= PG_FRAME;
    481 
    482 	/*
    483 	 * Initialize pointer to kernel segment table.
    484 	 */
    485 	m->sysseg_pa = (u_int32_t)(pmap_kernel()->pm_stpa);
    486 
    487 	/*
    488 	 * Initialize relocation value such that:
    489 	 *
    490 	 *	pa = (va - KERNBASE) + reloc
    491 	 *
    492 	 * Since we're linked and loaded at the same place,
    493 	 * and the kernel is mapped va == pa, this is 0.
    494 	 */
    495 	m->reloc = 0;
    496 
    497 	/*
    498 	 * Define the end of the relocatable range.
    499 	 */
    500 	m->relocend = (u_int32_t)end;
    501 
    502 	/*
    503 	 * The luna68k has one contiguous memory segment.
    504 	 */
    505 	m->ram_segs[0].start = 0 /* lowram */;
    506 	m->ram_segs[0].size  = ctob(physmem);
    507 }
    508 
    509 /*
    510  * Compute the size of the machine-dependent crash dump header.
    511  * Returns size in disk blocks.
    512  */
    513 int
    514 cpu_dumpsize()
    515 {
    516 	int size;
    517 
    518 	size = ALIGN(sizeof(kcore_seg_t)) + ALIGN(sizeof(cpu_kcore_hdr_t));
    519 	return (btodb(roundup(size, dbtob(1))));
    520 }
    521 
    522 /*
    523  * Called by dumpsys() to dump the machine-dependent header.
    524  */
    525 int
    526 cpu_dump(dump, blknop)
    527 	int (*dump) __P((dev_t, daddr_t, caddr_t, size_t));
    528 	daddr_t *blknop;
    529 {
    530 	int buf[dbtob(1) / sizeof(int)];
    531 	cpu_kcore_hdr_t *chdr;
    532 	kcore_seg_t *kseg;
    533 	int error;
    534 
    535 	kseg = (kcore_seg_t *)buf;
    536 	chdr = (cpu_kcore_hdr_t *)&buf[ALIGN(sizeof(kcore_seg_t)) /
    537 	    sizeof(int)];
    538 
    539 	/* Create the segment header. */
    540 	CORE_SETMAGIC(*kseg, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
    541 	kseg->c_size = dbtob(1) - ALIGN(sizeof(kcore_seg_t));
    542 
    543 	bcopy(&cpu_kcore_hdr, chdr, sizeof(cpu_kcore_hdr_t));
    544 	error = (*dump)(dumpdev, *blknop, (caddr_t)buf, sizeof(buf));
    545 	*blknop += btodb(sizeof(buf));
    546 	return (error);
    547 }
    548 
    549 /*
    550  * These variables are needed by /sbin/savecore
    551  */
    552 u_int32_t dumpmag = 0x8fca0101;	/* magic number */
    553 int	dumpsize = 0;		/* pages */
    554 long	dumplo = 0;		/* blocks */
    555 
    556 /*
    557  * This is called by main to set dumplo and dumpsize.
    558  * Dumps always skip the first PAGE_SIZE of disk space
    559  * in case there might be a disk label stored there.
    560  * If there is extra space, put dump at the end to
    561  * reduce the chance that swapping trashes it.
    562  */
    563 void
    564 cpu_dumpconf()
    565 {
    566 	const struct bdevsw *bdev;
    567 	int chdrsize;	/* size of dump header */
    568 	int nblks;	/* size of dump area */
    569 
    570 	if (dumpdev == NODEV)
    571 		return;
    572 	bdev = bdevsw_lookup(dumpdev);
    573 	if (bdev == NULL)
    574 		panic("dumpconf: bad dumpdev=0x%x", dumpdev);
    575 	if (bdev->d_psize == NULL)
    576 		return;
    577 	nblks = (*bdev->d_psize)(dumpdev);
    578 	chdrsize = cpu_dumpsize();
    579 
    580 	dumpsize = btoc(cpu_kcore_hdr.un._m68k.ram_segs[0].size);
    581 
    582 	/*
    583 	 * Check do see if we will fit.  Note we always skip the
    584 	 * first PAGE_SIZE in case there is a disk label there.
    585 	 */
    586 	if (nblks < (ctod(dumpsize) + chdrsize + ctod(1))) {
    587 		dumpsize = 0;
    588 		dumplo = -1;
    589 		return;
    590 	}
    591 
    592 	/*
    593 	 * Put dump at the end of the partition.
    594 	 */
    595 	dumplo = (nblks - 1) - ctod(dumpsize) - chdrsize;
    596 }
    597 
    598 /*
    599  * Dump physical memory onto the dump device.  Called by cpu_reboot().
    600  */
    601 void
    602 dumpsys()
    603 {
    604 	const struct bdevsw *bdev;
    605 	daddr_t blkno;		/* current block to write */
    606 				/* dump routine */
    607 	int (*dump) __P((dev_t, daddr_t, caddr_t, size_t));
    608 	int pg;			/* page being dumped */
    609 	paddr_t maddr;		/* PA being dumped */
    610 	int error;		/* error code from (*dump)() */
    611 
    612 	/* XXX initialized here because of gcc lossage */
    613 	maddr = 0 /* lowram */;
    614 	pg = 0;
    615 
    616 	/* Make sure dump device is valid. */
    617 	if (dumpdev == NODEV)
    618 		return;
    619 	bdev = bdevsw_lookup(dumpdev);
    620 	if (bdev == NULL)
    621 		return;
    622 	if (dumpsize == 0) {
    623 		cpu_dumpconf();
    624 		if (dumpsize == 0)
    625 			return;
    626 	}
    627 	if (dumplo <= 0) {
    628 		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
    629 		    minor(dumpdev));
    630 		return;
    631 	}
    632 	dump = bdev->d_dump;
    633 	blkno = dumplo;
    634 
    635 	printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
    636 	    minor(dumpdev), dumplo);
    637 
    638 	printf("dump ");
    639 
    640 	/* Write the dump header. */
    641 	error = cpu_dump(dump, &blkno);
    642 	if (error)
    643 		goto bad;
    644 
    645 	for (pg = 0; pg < dumpsize; pg++) {
    646 #define NPGMB	(1024*1024/PAGE_SIZE)
    647 		/* print out how many MBs we have dumped */
    648 		if (pg && (pg % NPGMB) == 0)
    649 			printf("%d ", pg / NPGMB);
    650 #undef NPGMB
    651 		pmap_enter(pmap_kernel(), (vaddr_t)vmmap, maddr,
    652 		    VM_PROT_READ, VM_PROT_READ|PMAP_WIRED);
    653 
    654 		pmap_update(pmap_kernel());
    655 		error = (*dump)(dumpdev, blkno, vmmap, PAGE_SIZE);
    656  bad:
    657 		switch (error) {
    658 		case 0:
    659 			maddr += PAGE_SIZE;
    660 			blkno += btodb(PAGE_SIZE);
    661 			break;
    662 
    663 		case ENXIO:
    664 			printf("device bad\n");
    665 			return;
    666 
    667 		case EFAULT:
    668 			printf("device not ready\n");
    669 			return;
    670 
    671 		case EINVAL:
    672 			printf("area improper\n");
    673 			return;
    674 
    675 		case EIO:
    676 			printf("i/o error\n");
    677 			return;
    678 
    679 		case EINTR:
    680 			printf("aborted from console\n");
    681 			return;
    682 
    683 		default:
    684 			printf("error %d\n", error);
    685 			return;
    686 		}
    687 	}
    688 	printf("succeeded\n");
    689 }
    690 
    691 void
    692 straytrap(pc, evec)
    693 	int pc;
    694 	u_short evec;
    695 {
    696 	printf("unexpected trap (vector offset %x) from %x\n",
    697 	       evec & 0xFFF, pc);
    698 }
    699 
    700 int	*nofault;
    701 
    702 int
    703 badaddr(addr, nbytes)
    704 	register caddr_t addr;
    705 	int nbytes;
    706 {
    707 	register int i;
    708 	label_t faultbuf;
    709 
    710 #ifdef lint
    711 	i = *addr; if (i) return (0);
    712 #endif
    713 
    714 	nofault = (int *) &faultbuf;
    715 	if (setjmp((label_t *)nofault)) {
    716 		nofault = (int *) 0;
    717 		return(1);
    718 	}
    719 
    720 	switch (nbytes) {
    721 	case 1:
    722 		i = *(volatile char *)addr;
    723 		break;
    724 
    725 	case 2:
    726 		i = *(volatile short *)addr;
    727 		break;
    728 
    729 	case 4:
    730 		i = *(volatile int *)addr;
    731 		break;
    732 
    733 	default:
    734 		panic("badaddr: bad request");
    735 	}
    736 	nofault = (int *) 0;
    737 	return (0);
    738 }
    739 
    740 void luna68k_abort __P((const char *));
    741 
    742 static int innmihand;	/* simple mutex */
    743 
    744 /*
    745  * Level 7 interrupts are caused by e.g. the ABORT switch.
    746  *
    747  * If we have DDB, then break into DDB on ABORT.  In a production
    748  * environment, bumping the ABORT switch would be bad, so we enable
    749  * panic'ing on ABORT with the kernel option "PANICBUTTON".
    750  */
    751 void
    752 nmihand(frame)
    753 	struct frame frame;
    754 {
    755 	/* Prevent unwanted recursion */
    756 	if (innmihand)
    757 		return;
    758 	innmihand = 1;
    759 
    760 	luna68k_abort("ABORT SWITCH");
    761 }
    762 
    763 /*
    764  * Common code for handling ABORT signals from buttons, switches,
    765  * serial lines, etc.
    766  */
    767 void
    768 luna68k_abort(cp)
    769 	const char *cp;
    770 {
    771 #ifdef DDB
    772 	printf("%s\n", cp);
    773 	cpu_Debugger();
    774 #else
    775 #ifdef PANICBUTTON
    776 	panic(cp);
    777 #else
    778 	printf("%s ignored\n", cp);
    779 #endif /* PANICBUTTON */
    780 #endif /* DDB */
    781 }
    782 
    783 /*
    784  * cpu_exec_aout_makecmds():
    785  *	CPU-dependent a.out format hook for execve().
    786  *
    787  * Determine of the given exec package refers to something which we
    788  * understand and, if so, set up the vmcmds for it.
    789  */
    790 int
    791 cpu_exec_aout_makecmds(p, epp)
    792 	struct proc *p;
    793 	struct exec_package *epp;
    794 {
    795 	int error = ENOEXEC;
    796 #ifdef COMPAT_SUNOS
    797 	extern sunos_exec_aout_makecmds
    798 	__P((struct proc *, struct exec_package *));
    799 	if ((error = sunos_exec_aout_makecmds(p, epp)) == 0)
    800 		return 0;
    801 #endif
    802 	return error;
    803 }
    804 
    805 /*
    806  * Return the best possible estimate of the time in the timeval
    807  * to which tvp points.	 Unfortunately, we can't read the hardware registers.
    808  * We guarantee that the time will be greater than the value obtained by a
    809  * previous call.
    810  */
    811 void
    812 microtime(tvp)
    813 	register struct timeval *tvp;
    814 {
    815 	int s = splclock();
    816 	static struct timeval lasttime;
    817 
    818 	*tvp = time;
    819 #ifdef notdef
    820 	tvp->tv_usec += clkread();
    821 	while (tvp->tv_usec >= 1000000) {
    822 		tvp->tv_sec++;
    823 		tvp->tv_usec -= 1000000;
    824 	}
    825 #endif
    826 	if (tvp->tv_sec == lasttime.tv_sec &&
    827 	    tvp->tv_usec <= lasttime.tv_usec &&
    828 	    (tvp->tv_usec = lasttime.tv_usec + 1) >= 1000000) {
    829 		tvp->tv_sec++;
    830 		tvp->tv_usec -= 1000000;
    831 	}
    832 	lasttime = *tvp;
    833 	splx(s);
    834 }
    835 
    836 #if 1
    837 
    838 struct consdev *cn_tab = &syscons;
    839 
    840 #else
    841 
    842 /*
    843  * romcons is useful until m68k TC register is initialized.
    844  */
    845 int  romcngetc __P((dev_t));
    846 void romcnputc __P((dev_t, int));
    847 
    848 struct consdev romcons = {
    849 	NULL,
    850 	NULL,
    851 	romcngetc,
    852 	romcnputc,
    853 	nullcnpollc,
    854 	makedev(7, 0), /* XXX */
    855 	CN_DEAD,
    856 };
    857 struct consdev *cn_tab = &romcons;
    858 
    859 #define __		((int **)0x41000000)
    860 #define GETC()		(*(int (*)())__[6])()
    861 #define PUTC(x)		(*(void (*)())__[7])(x)
    862 
    863 #define ROMPUTC(x) \
    864 ({					\
    865 	register _r;			\
    866 	asm volatile ("			\
    867 		movc	%%vbr,%0	; \
    868 		movel	%0,%%sp@-	; \
    869 		clrl	%0		; \
    870 		movc	%0,%%vbr"	\
    871 		: "=r" (_r));		\
    872 	PUTC(x);			\
    873 	asm volatile ("			\
    874 		movel	%%sp@+,%0	; \
    875 		movc	%0,%%vbr"	\
    876 		: "=r" (_r));		\
    877 })
    878 
    879 #define ROMGETC() \
    880 ({					\
    881 	register _r, _c;		\
    882 	asm volatile ("			\
    883 		movc	%%vbr,%0	; \
    884 		movel	%0,%%sp@-	; \
    885 		clrl	%0		; \
    886 		movc	%0,%%vbr"	\
    887 		: "=r" (_r));		\
    888 	_c = GETC();			\
    889 	asm volatile ("			\
    890 		movel	%%sp@+,%0	; \
    891 		movc	%0,%%vbr"	\
    892 		: "=r" (_r));		\
    893 	_c;				\
    894 })
    895 
    896 void
    897 romcnputc(dev, c)
    898 	dev_t dev;
    899 	int c;
    900 {
    901 	int s;
    902 
    903 	s = splhigh();
    904 	ROMPUTC(c);
    905 	splx(s);
    906 }
    907 
    908 int
    909 romcngetc(dev)
    910 	dev_t dev;
    911 {
    912 	int s, c;
    913 
    914 	do {
    915 		s = splhigh();
    916 		c = ROMGETC();
    917 		splx(s);
    918 	} while (c == -1);
    919 	return c;
    920 }
    921 #endif
    922