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