Home | History | Annotate | Line # | Download | only in luna68k
machdep.c revision 1.75
      1 /* $NetBSD: machdep.c,v 1.75 2010/06/06 04:50:06 mrg 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.75 2010/06/06 04:50:06 mrg 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 #include "opt_m68k_arch.h"
     42 
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/kernel.h>
     46 #include <sys/proc.h>
     47 #include <sys/buf.h>
     48 #include <sys/reboot.h>
     49 #include <sys/conf.h>
     50 #include <sys/file.h>
     51 #include <sys/device.h>
     52 #include <sys/malloc.h>
     53 #include <sys/mbuf.h>
     54 #include <sys/msgbuf.h>
     55 #include <sys/ioctl.h>
     56 #include <sys/tty.h>
     57 #include <sys/mount.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 *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(void)
    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(void)
    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 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
    268 	printf("avail memory = %s\n", pbuf);
    269 
    270 	/*
    271 	 * Say "Hi" to the world
    272 	 */
    273 	greeting();
    274 }
    275 
    276 /*
    277  * Set registers on exec.
    278  */
    279 void
    280 setregs(struct lwp *l, struct exec_package *pack, vaddr_t stack)
    281 {
    282 	struct frame *frame = (struct frame *)l->l_md.md_regs;
    283 	struct pcb *pcb = lwp_getpcb(l);
    284 	extern int fputype;
    285 
    286 	frame->f_sr = PSL_USERSET;
    287 	frame->f_pc = pack->ep_entry & ~1;
    288 	frame->f_regs[D0] = 0;
    289 	frame->f_regs[D1] = 0;
    290 	frame->f_regs[D2] = 0;
    291 	frame->f_regs[D3] = 0;
    292 	frame->f_regs[D4] = 0;
    293 	frame->f_regs[D5] = 0;
    294 	frame->f_regs[D6] = 0;
    295 	frame->f_regs[D7] = 0;
    296 	frame->f_regs[A0] = 0;
    297 	frame->f_regs[A1] = 0;
    298 	frame->f_regs[A2] = (int)l->l_proc->p_psstr;
    299 	frame->f_regs[A3] = 0;
    300 	frame->f_regs[A4] = 0;
    301 	frame->f_regs[A5] = 0;
    302 	frame->f_regs[A6] = 0;
    303 	frame->f_regs[SP] = stack;
    304 
    305 	/* restore a null state frame */
    306 	pcb->pcb_fpregs.fpf_null = 0;
    307 	if (fputype)
    308 		m68881_restore(&pcb->pcb_fpregs);
    309 }
    310 
    311 void
    312 identifycpu(void)
    313 {
    314 	extern int cputype;
    315 	const char *cpu;
    316 
    317 	memset(cpu_model, 0, sizeof(cpu_model));
    318 	switch (cputype) {
    319 	case CPU_68030:
    320 		cpu = "MC68030 CPU+MMU, MC68882 FPU";
    321 		machtype = LUNA_I;
    322 		cpuspeed = 20; delay_divisor = 102;	/* 20MHz 68030 */
    323 		hz = 60;
    324 		break;
    325 #if defined(M68040)
    326 	case CPU_68040:
    327 		cpu = "MC68040 CPU+MMU+FPU, 4k on-chip physical I/D caches";
    328 		machtype = LUNA_II;
    329 		cpuspeed = 25; delay_divisor = 300;	/* 25MHz 68040 */
    330 		break;
    331 #endif
    332 	default:
    333 		panic("unknown CPU type");
    334 	}
    335 	strcpy(cpu_model, cpu);
    336 	printf("%s\n", cpu_model);
    337 }
    338 
    339 /*
    340  * machine dependent system variables.
    341  */
    342 SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
    343 {
    344 
    345 	sysctl_createv(clog, 0, NULL, NULL,
    346 		       CTLFLAG_PERMANENT,
    347 		       CTLTYPE_NODE, "machdep", NULL,
    348 		       NULL, 0, NULL, 0,
    349 		       CTL_MACHDEP, CTL_EOL);
    350 
    351 	sysctl_createv(clog, 0, NULL, NULL,
    352 		       CTLFLAG_PERMANENT,
    353 		       CTLTYPE_STRUCT, "console_device", NULL,
    354 		       sysctl_consdev, 0, NULL, sizeof(dev_t),
    355 		       CTL_MACHDEP, CPU_CONSDEV, CTL_EOL);
    356 }
    357 
    358 int	waittime = -1;
    359 
    360 void
    361 cpu_reboot(volatile int howto, char *bootstr)
    362 	/* howto:  XXX to shutup GCC XXX */
    363 {
    364 	struct pcb *pcb = lwp_getpcb(curlwp);
    365 	extern void doboot(void);
    366 
    367 	/* take a snap shot before clobbering any registers */
    368 	if (pcb != NULL)
    369 		savectx(pcb);
    370 
    371 	/* If system is hold, just halt. */
    372 	if (cold) {
    373 		howto |= RB_HALT;
    374 		goto haltsys;
    375 	}
    376 
    377 	boothowto = howto;
    378 	if ((howto & RB_NOSYNC) == 0 && waittime < 0) {
    379 		waittime = 0;
    380 		vfs_shutdown();
    381 		/*
    382 		 * If we've been adjusting the clock, the todr
    383 		 * will be out of synch; adjust it now.
    384 		 */
    385 		resettodr();
    386 	}
    387 
    388 	/* Disable interrupts. */
    389 	splhigh();
    390 
    391 	/* If rebooting and a dump is requested, do it. */
    392 	if (howto & RB_DUMP)
    393 		dumpsys();
    394 
    395 haltsys:
    396 	/* Run any shutdown hooks. */
    397 	doshutdownhooks();
    398 
    399 	pmf_system_shutdown(boothowto);
    400 
    401 	/* Finally, halt/reboot the system. */
    402 	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
    403 		u_int8_t *pio = (void *)0x4d000000;
    404 
    405 		printf("power is going down.\n");
    406 		DELAY(100000);
    407 		pio[3] = 0x94;
    408 		pio[2] = 0 << 4;
    409 		for (;;) /* NOP */;
    410 	}
    411 	if (howto & RB_HALT) {
    412 		printf("System halted.	Hit any key to reboot.\n\n");
    413 		(void)cngetc();
    414 	}
    415 
    416 	printf("rebooting...\n");
    417 	DELAY(100000);
    418 	doboot();
    419 	/*NOTREACHED*/
    420 	while (1) ;
    421 }
    422 
    423 /*
    424  * Initialize the kernel crash dump header.
    425  */
    426 void
    427 cpu_init_kcore_hdr(void)
    428 {
    429 	cpu_kcore_hdr_t *h = &cpu_kcore_hdr;
    430 	struct m68k_kcore_hdr *m = &h->un._m68k;
    431 	extern char end[];
    432 
    433 	memset(&cpu_kcore_hdr, 0, sizeof(cpu_kcore_hdr));
    434 
    435 	/*
    436 	 * Initialize the `dispatcher' portion of the header.
    437 	 */
    438 	strcpy(h->name, machine);
    439 	h->page_size = PAGE_SIZE;
    440 	h->kernbase = KERNBASE;
    441 
    442 	/*
    443 	 * Fill in information about our MMU configuration.
    444 	 */
    445 	m->mmutype	= mmutype;
    446 	m->sg_v		= SG_V;
    447 	m->sg_frame	= SG_FRAME;
    448 	m->sg_ishift	= SG_ISHIFT;
    449 	m->sg_pmask	= SG_PMASK;
    450 	m->sg40_shift1	= SG4_SHIFT1;
    451 	m->sg40_mask2	= SG4_MASK2;
    452 	m->sg40_shift2	= SG4_SHIFT2;
    453 	m->sg40_mask3	= SG4_MASK3;
    454 	m->sg40_shift3	= SG4_SHIFT3;
    455 	m->sg40_addr1	= SG4_ADDR1;
    456 	m->sg40_addr2	= SG4_ADDR2;
    457 	m->pg_v		= PG_V;
    458 	m->pg_frame	= PG_FRAME;
    459 
    460 	/*
    461 	 * Initialize pointer to kernel segment table.
    462 	 */
    463 	m->sysseg_pa = (u_int32_t)(pmap_kernel()->pm_stpa);
    464 
    465 	/*
    466 	 * Initialize relocation value such that:
    467 	 *
    468 	 *	pa = (va - KERNBASE) + reloc
    469 	 *
    470 	 * Since we're linked and loaded at the same place,
    471 	 * and the kernel is mapped va == pa, this is 0.
    472 	 */
    473 	m->reloc = 0;
    474 
    475 	/*
    476 	 * Define the end of the relocatable range.
    477 	 */
    478 	m->relocend = (u_int32_t)end;
    479 
    480 	/*
    481 	 * The luna68k has one contiguous memory segment.
    482 	 */
    483 	m->ram_segs[0].start = 0 /* lowram */;
    484 	m->ram_segs[0].size  = ctob(physmem);
    485 }
    486 
    487 /*
    488  * Compute the size of the machine-dependent crash dump header.
    489  * Returns size in disk blocks.
    490  */
    491 
    492 #define CHDRSIZE (ALIGN(sizeof(kcore_seg_t)) + ALIGN(sizeof(cpu_kcore_hdr_t)))
    493 #define MDHDRSIZE roundup(CHDRSIZE, dbtob(1))
    494 
    495 int
    496 cpu_dumpsize(void)
    497 {
    498 
    499 	return btodb(MDHDRSIZE);
    500 }
    501 
    502 /*
    503  * Called by dumpsys() to dump the machine-dependent header.
    504  */
    505 int
    506 cpu_dump(dump, blknop)
    507 	int (*dump)(dev_t, daddr_t, void *, size_t);
    508 	daddr_t *blknop;
    509 {
    510 	int buf[MDHDRSIZE / sizeof(int)];
    511 	cpu_kcore_hdr_t *chdr;
    512 	kcore_seg_t *kseg;
    513 	int error;
    514 
    515 	kseg = (kcore_seg_t *)buf;
    516 	chdr = (cpu_kcore_hdr_t *)&buf[ALIGN(sizeof(kcore_seg_t)) /
    517 	    sizeof(int)];
    518 
    519 	/* Create the segment header. */
    520 	CORE_SETMAGIC(*kseg, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
    521 	kseg->c_size = MDHDRSIZE - ALIGN(sizeof(kcore_seg_t));
    522 
    523 	memcpy(chdr, &cpu_kcore_hdr, sizeof(cpu_kcore_hdr_t));
    524 	error = (*dump)(dumpdev, *blknop, (void *)buf, sizeof(buf));
    525 	*blknop += btodb(sizeof(buf));
    526 	return (error);
    527 }
    528 
    529 /*
    530  * These variables are needed by /sbin/savecore
    531  */
    532 u_int32_t dumpmag = 0x8fca0101;	/* magic number */
    533 int	dumpsize = 0;		/* pages */
    534 long	dumplo = 0;		/* blocks */
    535 
    536 /*
    537  * This is called by main to set dumplo and dumpsize.
    538  * Dumps always skip the first PAGE_SIZE of disk space
    539  * in case there might be a disk label stored there.
    540  * If there is extra space, put dump at the end to
    541  * reduce the chance that swapping trashes it.
    542  */
    543 void
    544 cpu_dumpconf(void)
    545 {
    546 	const struct bdevsw *bdev;
    547 	int chdrsize;	/* size of dump header */
    548 	int nblks;	/* size of dump area */
    549 
    550 	if (dumpdev == NODEV)
    551 		return;
    552 	bdev = bdevsw_lookup(dumpdev);
    553 	if (bdev == NULL) {
    554 		dumpdev = NODEV;
    555 		return;
    556 	}
    557 	if (bdev->d_psize == NULL)
    558 		return;
    559 	nblks = (*bdev->d_psize)(dumpdev);
    560 	chdrsize = cpu_dumpsize();
    561 
    562 	dumpsize = btoc(cpu_kcore_hdr.un._m68k.ram_segs[0].size);
    563 
    564 	/*
    565 	 * Check do see if we will fit.  Note we always skip the
    566 	 * first PAGE_SIZE in case there is a disk label there.
    567 	 */
    568 	if (nblks < (ctod(dumpsize) + chdrsize + ctod(1))) {
    569 		dumpsize = 0;
    570 		dumplo = -1;
    571 		return;
    572 	}
    573 
    574 	/*
    575 	 * Put dump at the end of the partition.
    576 	 */
    577 	dumplo = (nblks - 1) - ctod(dumpsize) - chdrsize;
    578 }
    579 
    580 /*
    581  * Dump physical memory onto the dump device.  Called by cpu_reboot().
    582  */
    583 void
    584 dumpsys(void)
    585 {
    586 	const struct bdevsw *bdev;
    587 	daddr_t blkno;		/* current block to write */
    588 				/* dump routine */
    589 	int (*dump)(dev_t, daddr_t, void *, size_t);
    590 	int pg;			/* page being dumped */
    591 	paddr_t maddr;		/* PA being dumped */
    592 	int error;		/* error code from (*dump)() */
    593 
    594 	/* XXX initialized here because of gcc lossage */
    595 	maddr = 0 /* lowram */;
    596 	pg = 0;
    597 
    598 	/* Make sure dump device is valid. */
    599 	if (dumpdev == NODEV)
    600 		return;
    601 	bdev = bdevsw_lookup(dumpdev);
    602 	if (bdev == NULL)
    603 		return;
    604 	if (dumpsize == 0) {
    605 		cpu_dumpconf();
    606 		if (dumpsize == 0)
    607 			return;
    608 	}
    609 	if (dumplo <= 0) {
    610 		printf("\ndump to dev %u,%u  not possible\n",
    611 		    major(dumpdev), minor(dumpdev));
    612 		return;
    613 	}
    614 	dump = bdev->d_dump;
    615 	blkno = dumplo;
    616 
    617 	printf("\ndumping to dev %u,%u offset %ld\n",
    618 	    major(dumpdev), minor(dumpdev), dumplo);
    619 
    620 	printf("dump ");
    621 
    622 	/* Write the dump header. */
    623 	error = cpu_dump(dump, &blkno);
    624 	if (error)
    625 		goto bad;
    626 
    627 	for (pg = 0; pg < dumpsize; pg++) {
    628 #define NPGMB	(1024*1024/PAGE_SIZE)
    629 		/* print out how many MBs we have dumped */
    630 		if (pg && (pg % NPGMB) == 0)
    631 			printf("%d ", pg / NPGMB);
    632 #undef NPGMB
    633 		pmap_enter(pmap_kernel(), (vaddr_t)vmmap, maddr,
    634 		    VM_PROT_READ, VM_PROT_READ|PMAP_WIRED);
    635 
    636 		pmap_update(pmap_kernel());
    637 		error = (*dump)(dumpdev, blkno, vmmap, PAGE_SIZE);
    638  bad:
    639 		switch (error) {
    640 		case 0:
    641 			maddr += PAGE_SIZE;
    642 			blkno += btodb(PAGE_SIZE);
    643 			break;
    644 
    645 		case ENXIO:
    646 			printf("device bad\n");
    647 			return;
    648 
    649 		case EFAULT:
    650 			printf("device not ready\n");
    651 			return;
    652 
    653 		case EINVAL:
    654 			printf("area improper\n");
    655 			return;
    656 
    657 		case EIO:
    658 			printf("i/o error\n");
    659 			return;
    660 
    661 		case EINTR:
    662 			printf("aborted from console\n");
    663 			return;
    664 
    665 		default:
    666 			printf("error %d\n", error);
    667 			return;
    668 		}
    669 	}
    670 	printf("succeeded\n");
    671 }
    672 
    673 void
    674 straytrap(int pc, u_short evec)
    675 {
    676 	printf("unexpected trap (vector offset %x) from %x\n",
    677 	       evec & 0xFFF, pc);
    678 }
    679 
    680 int	*nofault;
    681 
    682 int
    683 badaddr(register void *addr, int nbytes)
    684 {
    685 	register int i;
    686 	label_t faultbuf;
    687 
    688 #ifdef lint
    689 	i = *addr; if (i) return (0);
    690 #endif
    691 
    692 	nofault = (int *) &faultbuf;
    693 	if (setjmp((label_t *)nofault)) {
    694 		nofault = (int *) 0;
    695 		return(1);
    696 	}
    697 
    698 	switch (nbytes) {
    699 	case 1:
    700 		i = *(volatile char *)addr;
    701 		break;
    702 
    703 	case 2:
    704 		i = *(volatile short *)addr;
    705 		break;
    706 
    707 	case 4:
    708 		i = *(volatile int *)addr;
    709 		break;
    710 
    711 	default:
    712 		panic("badaddr: bad request");
    713 	}
    714 	nofault = (int *) 0;
    715 	return (0);
    716 }
    717 
    718 void luna68k_abort(const char *);
    719 
    720 static int innmihand;	/* simple mutex */
    721 
    722 /*
    723  * Level 7 interrupts are caused by e.g. the ABORT switch.
    724  *
    725  * If we have DDB, then break into DDB on ABORT.  In a production
    726  * environment, bumping the ABORT switch would be bad, so we enable
    727  * panic'ing on ABORT with the kernel option "PANICBUTTON".
    728  */
    729 void
    730 nmihand(struct frame frame)
    731 {
    732 	/* Prevent unwanted recursion */
    733 	if (innmihand)
    734 		return;
    735 	innmihand = 1;
    736 
    737 	luna68k_abort("ABORT SWITCH");
    738 }
    739 
    740 /*
    741  * Common code for handling ABORT signals from buttons, switches,
    742  * serial lines, etc.
    743  */
    744 void
    745 luna68k_abort(const char *cp)
    746 {
    747 #ifdef DDB
    748 	printf("%s\n", cp);
    749 	cpu_Debugger();
    750 #else
    751 #ifdef PANICBUTTON
    752 	panic(cp);
    753 #else
    754 	printf("%s ignored\n", cp);
    755 #endif /* PANICBUTTON */
    756 #endif /* DDB */
    757 }
    758 
    759 /*
    760  * cpu_exec_aout_makecmds():
    761  *	CPU-dependent a.out format hook for execve().
    762  *
    763  * Determine of the given exec package refers to something which we
    764  * understand and, if so, set up the vmcmds for it.
    765  */
    766 int
    767 cpu_exec_aout_makecmds(struct lwp *l, struct exec_package *epp)
    768 {
    769 	int error = ENOEXEC;
    770 #ifdef COMPAT_SUNOS
    771 	extern sunos_exec_aout_makecmds
    772 (struct proc *, struct exec_package *);
    773 	if ((error = sunos_exec_aout_makecmds(l->l_proc, epp)) == 0)
    774 		return 0;
    775 #endif
    776 	return error;
    777 }
    778 
    779 #if 1
    780 
    781 struct consdev *cn_tab = &syscons;
    782 
    783 #else
    784 
    785 /*
    786  * romcons is useful until m68k TC register is initialized.
    787  */
    788 int  romcngetc(dev_t);
    789 void romcnputc(dev_t, int);
    790 
    791 struct consdev romcons = {
    792 	NULL,
    793 	NULL,
    794 	romcngetc,
    795 	romcnputc,
    796 	nullcnpollc,
    797 	makedev(7, 0), /* XXX */
    798 	CN_DEAD,
    799 };
    800 struct consdev *cn_tab = &romcons;
    801 
    802 #define __		((int **)0x41000000)
    803 #define GETC()		(*(int (*)())__[6])()
    804 #define PUTC(x)		(*(void (*)())__[7])(x)
    805 
    806 #define ROMPUTC(x) \
    807 ({					\
    808 	register _r;			\
    809 	__asm volatile ("			\
    810 		movc	%%vbr,%0	; \
    811 		movel	%0,%%sp@-	; \
    812 		clrl	%0		; \
    813 		movc	%0,%%vbr"	\
    814 		: "=r" (_r));		\
    815 	PUTC(x);			\
    816 	__asm volatile ("			\
    817 		movel	%%sp@+,%0	; \
    818 		movc	%0,%%vbr"	\
    819 		: "=r" (_r));		\
    820 })
    821 
    822 #define ROMGETC() \
    823 ({					\
    824 	register _r, _c;		\
    825 	__asm volatile ("			\
    826 		movc	%%vbr,%0	; \
    827 		movel	%0,%%sp@-	; \
    828 		clrl	%0		; \
    829 		movc	%0,%%vbr"	\
    830 		: "=r" (_r));		\
    831 	_c = GETC();			\
    832 	__asm volatile ("			\
    833 		movel	%%sp@+,%0	; \
    834 		movc	%0,%%vbr"	\
    835 		: "=r" (_r));		\
    836 	_c;				\
    837 })
    838 
    839 void
    840 romcnputc(dev_t dev, int c)
    841 {
    842 	int s;
    843 
    844 	s = splhigh();
    845 	ROMPUTC(c);
    846 	splx(s);
    847 }
    848 
    849 int
    850 romcngetc(dev_t dev)
    851 {
    852 	int s, c;
    853 
    854 	do {
    855 		s = splhigh();
    856 		c = ROMGETC();
    857 		splx(s);
    858 	} while (c == -1);
    859 	return c;
    860 }
    861 #endif
    862