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