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