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