Home | History | Annotate | Line # | Download | only in amiga
      1 /*	$NetBSD: machdep.c,v 1.281 2026/11/13 21:14:17 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1988 University of Utah.
      5  * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
      6  * All rights reserved.
      7  *
      8  * This code is derived from software contributed to Berkeley by
      9  * the Systems Programming Group of the University of Utah Computer
     10  * Science Department.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  * from: Utah $Hdr: machdep.c 1.63 91/04/24$
     37  *
     38  *	@(#)machdep.c	7.16 (Berkeley) 6/3/91
     39  */
     40 
     41 #include "opt_ddb.h"
     42 #include "opt_fpu_emulate.h"
     43 #include "opt_lev6_defer.h"
     44 #include "opt_m060sp.h"
     45 #include "opt_modular.h"
     46 #include "opt_panicbutton.h"
     47 #include "opt_m68k_arch.h"
     48 
     49 #include "empm.h"
     50 
     51 #include <sys/cdefs.h>
     52 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.281 2026/11/13 21:14:17 thorpej Exp $");
     53 
     54 #include <sys/param.h>
     55 #include <sys/systm.h>
     56 #include <sys/callout.h>
     57 #include <sys/signalvar.h>
     58 #include <sys/kernel.h>
     59 #include <sys/proc.h>
     60 #include <sys/buf.h>
     61 #include <sys/reboot.h>
     62 #include <sys/conf.h>
     63 #include <sys/file.h>
     64 #include <sys/mbuf.h>
     65 #include <sys/msgbuf.h>
     66 #include <sys/vnode.h>
     67 #include <sys/device.h>
     68 #include <sys/queue.h>
     69 #include <sys/mount.h>
     70 #include <sys/core.h>
     71 #include <sys/kcore.h>
     72 #include <sys/ksyms.h>
     73 #include <sys/module.h>
     74 #include <sys/cpu.h>
     75 #include <sys/exec.h>
     76 
     77 #if defined(DDB) && defined(__ELF__)
     78 #include <sys/exec_elf.h>
     79 #endif
     80 
     81 #undef PS	/* XXX netccitt/pk.h conflict with machine/reg.h? */
     82 
     83 #define	MAXMEM	64*1024	/* XXX - from cmap.h */
     84 #include <uvm/uvm_extern.h>
     85 
     86 #include <sys/sysctl.h>
     87 
     88 #include <machine/db_machdep.h>
     89 #include <ddb/db_sym.h>
     90 #include <ddb/db_extern.h>
     91 
     92 #include <machine/reg.h>
     93 #include <machine/pcb.h>
     94 #include <machine/psl.h>
     95 #include <machine/pte.h>
     96 #include <machine/kcore.h>
     97 #include <machine/vectors.h>
     98 #include <dev/cons.h>
     99 #include <dev/mm.h>
    100 #include <amiga/amiga/isr.h>
    101 #include <amiga/amiga/custom.h>
    102 #ifdef DRACO
    103 #include <amiga/amiga/drcustom.h>
    104 #include <m68k/include/asm_single.h>
    105 #endif
    106 #include <amiga/amiga/cia.h>
    107 #include <amiga/amiga/cc.h>
    108 #include <amiga/amiga/memlist.h>
    109 #include <amiga/amiga/device.h>
    110 #if NEMPM > 0
    111 #include <amiga/pci/empmvar.h>
    112 #endif /* NEMPM > 0 */
    113 
    114 #ifdef M68060
    115 #include <m68k/pcr.h>
    116 #endif
    117 
    118 #include "fd.h"
    119 #include "ser.h"
    120 #include "ksyms.h"
    121 
    122 /* prototypes */
    123 vm_offset_t reserve_dumppages(vm_offset_t);
    124 void dumpsys(void);
    125 void intrhand(int);
    126 #if NSER > 0
    127 void ser_outintr(void);
    128 #endif
    129 #if NFD > 0
    130 void fdintr(int);
    131 #endif
    132 
    133 int	machineid;
    134 int	maxmem;			/* max memory per process */
    135 
    136 extern  int   freebufspace;
    137 extern	u_int lowram;
    138 
    139 /*
    140  * current open serial device speed;  used by some SCSI drivers to reduce
    141  * DMA transfer lengths.
    142  */
    143 int	ser_open_speed;
    144 
    145 #ifdef DRACO
    146 vaddr_t DRCCADDR;
    147 
    148 volatile u_int8_t *draco_intena, *draco_intpen, *draco_intfrc;
    149 volatile u_int8_t *draco_misc;
    150 volatile struct drioct *draco_ioct;
    151 #endif
    152 
    153 struct pmap_bootmap machine_bootmap[] = {
    154 	/* XXX */
    155 	{ .pmbm_vaddr = -1 },
    156 };
    157 
    158  /*
    159  * Console initialization: called early on from main,
    160  * before vm init or startup.  Do enough configuration
    161  * to choose and initialize a console.
    162  */
    163 void
    164 consinit(void)
    165 {
    166 	/* initialize custom chip interface */
    167 #ifdef DRACO
    168 	if (is_draco()) {
    169 		/* XXX to be done */
    170 	} else
    171 #endif
    172 		custom_chips_init();
    173 
    174 	/* preconfigure graphics cards */
    175 	config_console();
    176 
    177 	/*
    178 	 * Initialize the console before we print anything out.
    179 	 */
    180 	cninit();
    181 
    182 #if NKSYMS || defined(DDB) || defined(MODULAR)
    183 	{
    184 		extern int end[];
    185 		extern int *esym;
    186 
    187 		ksyms_addsyms_elf((int)esym - (int)&end - sizeof(Elf32_Ehdr),
    188 		    (void *)&end, esym);
    189 	}
    190 #endif
    191 #ifdef DDB
    192 	if (boothowto & RB_KDB)
    193 		Debugger();
    194 #endif
    195 }
    196 
    197 /*
    198  * cpu_startup: allocate memory for variable-sized tables,
    199  * initialize CPU, and do autoconfiguration.
    200  */
    201 void
    202 cpu_startup(void)
    203 {
    204 	cpu_startup_common();
    205 
    206 	/*
    207 	 * display memory configuration passed from loadbsd
    208 	 */
    209 	if (memlist->m_nseg > 0 && memlist->m_nseg < 16) {
    210 		for (u_int i = 0; i < memlist->m_nseg; i++) {
    211 			printf("memory segment %d at %08x size %08x\n", i,
    212 			    memlist->m_seg[i].ms_start,
    213 			    memlist->m_seg[i].ms_size);
    214 		}
    215 	}
    216 }
    217 
    218 void
    219 machine_set_model(void)
    220 {
    221 	const char *mach;
    222 
    223 #ifdef DRACO
    224 	char machbuf[16];
    225 
    226 	if (is_draco()) {
    227 		snprintf(machbuf, sizeof(machbuf), "DraCo rev.%d", is_draco());
    228 		mach = machbuf;
    229 	} else
    230 #endif
    231 	if (is_a4000())
    232 		mach = "Amiga 4000";
    233 	else if (is_a3000())
    234 		mach = "Amiga 3000";
    235 	else if (is_a1200())
    236 		mach = "Amiga 1200";
    237 	else if (is_a600())
    238 		mach = "Amiga 600";
    239 	else
    240 		mach = "Amiga 500/2000";
    241 
    242 	cpu_setmodel("%s", mach);
    243 }
    244 
    245 /*
    246  * machine dependent system variables.
    247  */
    248 SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
    249 {
    250 
    251 	sysctl_createv(clog, 0, NULL, NULL,
    252 		       CTLFLAG_PERMANENT,
    253 		       CTLTYPE_NODE, "machdep", NULL,
    254 		       NULL, 0, NULL, 0,
    255 		       CTL_MACHDEP, CTL_EOL);
    256 
    257 	sysctl_createv(clog, 0, NULL, NULL,
    258 		       CTLFLAG_PERMANENT,
    259 		       CTLTYPE_STRUCT, "console_device", NULL,
    260 		       sysctl_consdev, 0, NULL, sizeof(dev_t),
    261 		       CTL_MACHDEP, CPU_CONSDEV, CTL_EOL);
    262 }
    263 
    264 void
    265 machine_powerdown(void)
    266 {
    267 #if NEMPM > 0
    268 	device_t empmdev = device_find_by_xname("empm0");
    269 	if (empmdev != NULL) {
    270 		empm_power_off(device_private(empmdev));
    271 	}
    272 #endif /* NEMPM > 0 */
    273 }
    274 
    275 u_int32_t dumpmag = 0x8fca0101;	/* magic number for savecore */
    276 int	dumpsize = 0;		/* also for savecore */
    277 long	dumplo = 0;
    278 cpu_kcore_hdr_t cpu_kcore_hdr;
    279 
    280 #define CHDRSIZE (ALIGN(sizeof(kcore_seg_t)) + ALIGN(sizeof(cpu_kcore_hdr_t)))
    281 #define MDHDRSIZE roundup(CHDRSIZE, dbtob(1))
    282 
    283 void
    284 cpu_dumpconf(void)
    285 {
    286 	cpu_kcore_hdr_t *h = &cpu_kcore_hdr;
    287 	struct m68k_kcore_hdr *m = &h->un._m68k;
    288 	int nblks;
    289 	int i;
    290 	extern int end[];
    291 
    292 	memset(&cpu_kcore_hdr, 0, sizeof(cpu_kcore_hdr));
    293 
    294 	/*
    295 	 * Intitialize the `dispatcher' portion of the header.
    296 	 */
    297 	strcpy(h->name, machine);
    298 	h->page_size = PAGE_SIZE;
    299 	h->kernbase = KERNBASE;
    300 
    301 	/*
    302 	 * Fill in information about our MMU configuration.
    303 	 */
    304 	m->mmutype	= mmutype;
    305 	m->sg_v		= SG_V;
    306 	m->sg_frame	= SG_FRAME;
    307 	m->sg_ishift	= SG_ISHIFT;
    308 	m->sg_pmask	= SG_PMASK;
    309 	m->sg40_shift1	= SG4_SHIFT1;
    310 	m->sg40_mask2	= SG4_MASK2;
    311 	m->sg40_shift2	= SG4_SHIFT2;
    312 	m->sg40_mask3	= SG4_MASK3;
    313 	m->sg40_shift3	= SG4_SHIFT3;
    314 	m->sg40_addr1	= SG4_ADDR1;
    315 	m->sg40_addr2	= SG4_ADDR2;
    316 	m->pg_v		= PG_V;
    317 	m->pg_frame	= PG_FRAME;
    318 
    319 	/*
    320 	 * Initialize the pointer to the kernel segment table.
    321 	 */
    322 	m->sysseg_pa = (paddr_t)pmap_kernel()->pm_stpa;
    323 
    324 	/*
    325 	 * Initialize relocation value such that:
    326 	 *
    327 	 *	pa = (va - KERNBASE) + reloc
    328 	 */
    329 	m->reloc = lowram;
    330 
    331 	/*
    332 	 * Define the end of the relocatable range.
    333 	 */
    334 	m->relocend = (u_int32_t)&end;
    335 
    336 	/* XXX new corefile format, single segment + chipmem */
    337 	dumpsize = physmem;
    338 	m->ram_segs[0].start = lowram;
    339 	m->ram_segs[0].size  = ctob(physmem);
    340 	for (i = 0; i < memlist->m_nseg; i++) {
    341 		if ((memlist->m_seg[i].ms_attrib & MEMF_CHIP) == 0)
    342 			continue;
    343 		dumpsize += btoc(memlist->m_seg[i].ms_size);
    344 		m->ram_segs[1].start = 0;
    345 		m->ram_segs[1].size  = memlist->m_seg[i].ms_size;
    346 		break;
    347 	}
    348 	if (bdevsw_lookup(dumpdev) == NULL) {
    349 		dumpdev = NODEV;
    350 		return;
    351 	}
    352 	nblks = bdev_size(dumpdev);
    353 	if (nblks > 0) {
    354 		if (dumpsize > btoc(dbtob(nblks - dumplo)))
    355 			dumpsize = btoc(dbtob(nblks - dumplo));
    356 		else if (dumplo == 0)
    357 			dumplo = nblks - btodb(ctob(dumpsize));
    358 	}
    359 	dumplo -= ctod(btoc(MDHDRSIZE));
    360 	/*
    361 	 * Don't dump on the first PAGE_SIZE (why PAGE_SIZE?)
    362 	 * in case the dump device includes a disk label.
    363 	 */
    364 	if (dumplo < btodb(PAGE_SIZE))
    365 		dumplo = btodb(PAGE_SIZE);
    366 }
    367 
    368 /*
    369  * Doadump comes here after turning off memory management and
    370  * getting on the dump stack, either when called above, or by
    371  * the auto-restart code.
    372  */
    373 static vm_offset_t dumpspace;
    374 
    375 vm_offset_t
    376 reserve_dumppages(vm_offset_t p)
    377 {
    378 	dumpspace = p;
    379 	return (p + PAGE_SIZE);
    380 }
    381 
    382 void
    383 dumpsys(void)
    384 {
    385 	unsigned bytes, i, n, seg;
    386 	int     maddr, psize;
    387 	daddr_t blkno;
    388 	int     (*dump)(dev_t, daddr_t, void *, size_t);
    389 	int     error = 0;
    390 	kcore_seg_t *kseg_p;
    391 	cpu_kcore_hdr_t *chdr_p;
    392 	char	dump_hdr[MDHDRSIZE];
    393 	const struct bdevsw *bdev;
    394 
    395 	if (dumpdev == NODEV)
    396 		return;
    397 	bdev = bdevsw_lookup(dumpdev);
    398 	if (bdev == NULL || bdev->d_psize == NULL)
    399 		return;
    400 	/*
    401 	 * For dumps during autoconfiguration,
    402 	 * if dump device has already configured...
    403 	 */
    404 	if (dumpsize == 0)
    405 		cpu_dumpconf();
    406 	if (dumplo <= 0) {
    407 		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
    408 		    minor(dumpdev));
    409 		return;
    410 	}
    411 	printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
    412 	    minor(dumpdev), dumplo);
    413 
    414 	psize = bdev_size(dumpdev);
    415 	printf("dump ");
    416 	if (psize == -1) {
    417 		printf("area unavailable.\n");
    418 		return;
    419 	}
    420 	kseg_p = (kcore_seg_t *)dump_hdr;
    421 	chdr_p = (cpu_kcore_hdr_t *)&dump_hdr[ALIGN(sizeof(*kseg_p))];
    422 	memset(dump_hdr, 0, sizeof(dump_hdr));
    423 
    424 	/*
    425 	 * Generate a segment header
    426 	 */
    427 	CORE_SETMAGIC(*kseg_p, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
    428 	kseg_p->c_size = MDHDRSIZE - ALIGN(sizeof(*kseg_p));
    429 
    430 	/*
    431 	 * Add the md header
    432 	 */
    433 
    434 	*chdr_p = cpu_kcore_hdr;
    435 
    436 	bytes = ctob(dumpsize);
    437 	maddr = cpu_kcore_hdr.un._m68k.ram_segs[0].start;
    438 	seg = 0;
    439 	blkno = dumplo;
    440 	dump = bdev->d_dump;
    441 	error = (*dump) (dumpdev, blkno, (void *)dump_hdr, sizeof(dump_hdr));
    442 	blkno += btodb(sizeof(dump_hdr));
    443 	for (i = 0; i < bytes && error == 0; i += n) {
    444 		/* Print out how many MBs we have to go. */
    445 		n = bytes - i;
    446 		if (n && (n % (1024 * 1024)) == 0)
    447 			printf_nolog("%d ", n / (1024 * 1024));
    448 
    449 		/* Limit size for next transfer. */
    450 		if (n > PAGE_SIZE)
    451 			n = PAGE_SIZE;
    452 
    453 		if (maddr == 0) {	/* XXX kvtop chokes on this */
    454 			maddr += PAGE_SIZE;
    455 			n -= PAGE_SIZE;
    456 			i += PAGE_SIZE;
    457 			++blkno;	/* XXX skip physical page 0 */
    458 		}
    459 		pmap_enter(pmap_kernel(), dumpspace, maddr,
    460 		    VM_PROT_READ, VM_PROT_READ|PMAP_WIRED);
    461 		pmap_update(pmap_kernel());
    462 		error = (*dump) (dumpdev, blkno, (void *) dumpspace, n);
    463 		if (error)
    464 			break;
    465 		maddr += n;
    466 		blkno += btodb(n);	/* XXX? */
    467 		if (maddr >= (cpu_kcore_hdr.un._m68k.ram_segs[seg].start +
    468 		    cpu_kcore_hdr.un._m68k.ram_segs[seg].size)) {
    469 			++seg;
    470 			maddr = cpu_kcore_hdr.un._m68k.ram_segs[seg].start;
    471 			if (cpu_kcore_hdr.un._m68k.ram_segs[seg].size == 0)
    472 				break;
    473 		}
    474 	}
    475 
    476 	switch (error) {
    477 
    478 	case ENXIO:
    479 		printf("device bad\n");
    480 		break;
    481 
    482 	case EFAULT:
    483 		printf("device not ready\n");
    484 		break;
    485 
    486 	case EINVAL:
    487 		printf("area improper\n");
    488 		break;
    489 
    490 	case EIO:
    491 		printf("i/o error\n");
    492 		break;
    493 
    494 	default:
    495 		printf("succeeded\n");
    496 		break;
    497 	}
    498 	printf("\n\n");
    499 	delay(5000000);		/* 5 seconds */
    500 }
    501 
    502 struct isr *isr_ports;
    503 #ifdef DRACO
    504 struct isr *isr_slot3;
    505 struct isr *isr_supio;
    506 #endif
    507 struct isr *isr_exter;
    508 
    509 void
    510 add_isr(struct isr *isr)
    511 {
    512 	struct isr **p, *q;
    513 
    514 #ifdef DRACO
    515 	switch (isr->isr_ipl) {
    516 	case 2:
    517 		p = &isr_ports;
    518 		break;
    519 	case 3:
    520 		p = &isr_slot3;
    521 		break;
    522 	case 5:
    523 		p = &isr_supio;
    524 		break;
    525 	default:	/* was case 6:; make gcc -Wall quiet */
    526 		p = &isr_exter;
    527 		break;
    528 	}
    529 #else
    530 	p = isr->isr_ipl == 2 ? &isr_ports : &isr_exter;
    531 #endif
    532 	while ((q = *p) != NULL)
    533 		p = &q->isr_forw;
    534 	isr->isr_forw = NULL;
    535 	*p = isr;
    536 	/* enable interrupt */
    537 #ifdef DRACO
    538 	if (is_draco())
    539 		switch(isr->isr_ipl) {
    540 			case 6:
    541 				single_inst_bset_b(*draco_intena, DRIRQ_INT6);
    542 				break;
    543 			case 2:
    544 				single_inst_bset_b(*draco_intena, DRIRQ_INT2);
    545 				break;
    546 			default:
    547 				break;
    548 		}
    549 	else
    550 #endif
    551 		custom.intena = isr->isr_ipl == 2 ?
    552 		    INTF_SETCLR | INTF_PORTS :
    553 		    INTF_SETCLR | INTF_EXTER;
    554 }
    555 
    556 void
    557 remove_isr(struct isr *isr)
    558 {
    559 	struct isr **p, *q;
    560 
    561 #ifdef DRACO
    562 	switch (isr->isr_ipl) {
    563 	case 2:
    564 		p = &isr_ports;
    565 		break;
    566 	case 3:
    567 		p = &isr_slot3;
    568 		break;
    569 	case 5:
    570 		p = &isr_supio;
    571 		break;
    572 	default:	/* XXX to make gcc -Wall quiet, was 6: */
    573 		p = &isr_exter;
    574 		break;
    575 	}
    576 #else
    577 	p = isr->isr_ipl == 6 ? &isr_exter : &isr_ports;
    578 #endif
    579 
    580 	while ((q = *p) != NULL && q != isr)
    581 		p = &q->isr_forw;
    582 	if (q)
    583 		*p = q->isr_forw;
    584 	else
    585 		panic("remove_isr: handler not registered");
    586 	/* disable interrupt if no more handlers */
    587 #ifdef DRACO
    588 	switch (isr->isr_ipl) {
    589 	case 2:
    590 		p = &isr_ports;
    591 		break;
    592 	case 3:
    593 		p = &isr_slot3;
    594 		break;
    595 	case 5:
    596 		p = &isr_supio;
    597 		break;
    598 	case 6:
    599 		p = &isr_exter;
    600 		break;
    601 	}
    602 #else
    603 	p = isr->isr_ipl == 6 ? &isr_exter : &isr_ports;
    604 #endif
    605 	if (*p == NULL) {
    606 #ifdef DRACO
    607 		if (is_draco()) {
    608 			switch(isr->isr_ipl) {
    609 				case 2:
    610 					single_inst_bclr_b(*draco_intena,
    611 					    DRIRQ_INT2);
    612 					break;
    613 				case 6:
    614 					single_inst_bclr_b(*draco_intena,
    615 					    DRIRQ_INT6);
    616 					break;
    617 				default:
    618 					break;
    619 			}
    620 		} else
    621 #endif
    622 			custom.intena = isr->isr_ipl == 6 ?
    623 			    INTF_EXTER : INTF_PORTS;
    624 	}
    625 }
    626 
    627 void
    628 intrhand(int sr)
    629 {
    630 	register unsigned int ipl;
    631 	register unsigned short ireq;
    632 	register struct isr **p, *q;
    633 
    634 	ipl = (sr >> 8) & 7;
    635 #ifdef REALLYDEBUG
    636 	printf("intrhand: got int. %d\n", ipl);
    637 #endif
    638 #ifdef DRACO
    639 	if (is_draco())
    640 		ireq = ((ipl == 1)  && (*draco_intfrc & DRIRQ_SOFT) ?
    641 		    INTF_SOFTINT : 0);
    642 	else
    643 #endif
    644 		ireq = custom.intreqr;
    645 
    646 	switch (ipl) {
    647 	case 1:
    648 #ifdef DRACO
    649 		if (is_draco() && (draco_ioct->io_status & DRSTAT_KBDRECV))
    650 			drkbdintr();
    651 #endif
    652 		if (ireq & INTF_TBE) {
    653 #if NSER > 0
    654 			ser_outintr();
    655 #else
    656 			custom.intreq = INTF_TBE;
    657 #endif
    658 		}
    659 
    660 		if (ireq & INTF_DSKBLK) {
    661 #if NFD > 0
    662 			fdintr(0);
    663 #endif
    664 			custom.intreq = INTF_DSKBLK;
    665 		}
    666 		if (ireq & INTF_SOFTINT) {
    667 			/* sicallback handling removed */
    668 #ifdef DEBUG
    669 			printf("intrhand: SOFTINT ignored\n");
    670 #endif
    671 			custom.intreq = INTF_SOFTINT;
    672 		}
    673 		break;
    674 
    675 	case 2:
    676 		p = &isr_ports;
    677 		while ((q = *p) != NULL) {
    678 			if ((q->isr_intr)(q->isr_arg))
    679 				break;
    680 			p = &q->isr_forw;
    681 		}
    682 		if (q == NULL)
    683 			ciaa_intr ();
    684 #ifdef DRACO
    685 		if (is_draco())
    686 			single_inst_bclr_b(*draco_intpen, DRIRQ_INT2);
    687 		else
    688 #endif
    689 			custom.intreq = INTF_PORTS;
    690 
    691 		break;
    692 
    693 #ifdef DRACO
    694 	/* only handled here for DraCo */
    695 	case 6:
    696 		p = &isr_exter;
    697 		while ((q = *p) != NULL) {
    698 			if ((q->isr_intr)(q->isr_arg))
    699 				break;
    700 			p = &q->isr_forw;
    701 		}
    702 		single_inst_bclr_b(*draco_intpen, DRIRQ_INT6);
    703 		break;
    704 #endif
    705 
    706 	case 3:
    707 	/* VBL */
    708 		if (ireq & INTF_BLIT)
    709 			blitter_handler();
    710 		if (ireq & INTF_COPER)
    711 			copper_handler();
    712 		if (ireq & INTF_VERTB)
    713 			vbl_handler();
    714 		break;
    715 #ifdef DRACO
    716 	case 5:
    717 		p = &isr_supio;
    718 		while ((q = *p) != NULL) {
    719 			if ((q->isr_intr)(q->isr_arg))
    720 				break;
    721 			p = &q->isr_forw;
    722 		}
    723 		break;
    724 #endif
    725 #if 0
    726 /* now dealt with in locore.s for speed reasons */
    727 	case 5:
    728 		/* check RS232 RBF */
    729 		serintr (0);
    730 
    731 		custom.intreq = INTF_DSKSYNC;
    732 		break;
    733 #endif
    734 
    735 	case 4:
    736 #ifdef DRACO
    737 #include "drsc.h"
    738 		if (is_draco())
    739 #if NDRSC > 0
    740 			drsc_handler();
    741 #else
    742 			single_inst_bclr_b(*draco_intpen, DRIRQ_SCSI);
    743 #endif
    744 		else
    745 #endif
    746 		audio_handler();
    747 		break;
    748 	default:
    749 		printf("intrhand: unexpected sr 0x%x, intreq = 0x%x\n",
    750 		    sr, ireq);
    751 		break;
    752 	}
    753 #ifdef REALLYDEBUG
    754 	printf("intrhand: leaving.\n");
    755 #endif
    756 }
    757 
    758 #if defined(DEBUG) && !defined(PANICBUTTON)
    759 #define PANICBUTTON
    760 #endif
    761 
    762 #ifdef PANICBUTTON
    763 int panicbutton = 1;	/* non-zero if panic buttons are enabled */
    764 int crashandburn = 0;
    765 int candbdelay = 50;	/* give em half a second */
    766 void candbtimer(void);
    767 callout_t candbtimer_ch;
    768 
    769 void
    770 candbtimer(void)
    771 {
    772 	crashandburn = 0;
    773 }
    774 #endif
    775 
    776 #if 0
    777 /*
    778  * Level 7 interrupts can be caused by the keyboard or parity errors.
    779  */
    780 nmihand(struct frame frame)
    781 {
    782 	if (kbdnmi()) {
    783 #ifdef PANICBUTTON
    784 		static int innmihand = 0;
    785 
    786 		/*
    787 		 * Attempt to reduce the window of vulnerability for recursive
    788 		 * NMIs (e.g. someone holding down the keyboard reset button).
    789 		 */
    790 		if (innmihand == 0) {
    791 			innmihand = 1;
    792 			printf("Got a keyboard NMI\n");
    793 			innmihand = 0;
    794 		}
    795 		if (panicbutton) {
    796 			if (crashandburn) {
    797 				crashandburn = 0;
    798 				panic(panicstr ?
    799 				      "forced crash, nosync" : "forced crash");
    800 			}
    801 			crashandburn++;
    802 			callout_reset(&candbtimer_ch, candbdelay,
    803 			    candbtimer, NULL);
    804 		}
    805 #endif
    806 		return;
    807 	}
    808 	if (parityerror(&frame))
    809 		return;
    810 	/* panic?? */
    811 	printf("unexpected level 7 interrupt ignored\n");
    812 }
    813 #endif
    814 
    815 #ifdef MODULAR
    816 int _spllkm6(void);
    817 int _spllkm7(void);
    818 
    819 #ifdef LEV6_DEFER
    820 int _spllkm6(void) {
    821 	return spl4();
    822 };
    823 
    824 int _spllkm7(void) {
    825 	return spl4();
    826 };
    827 
    828 #else
    829 
    830 int _spllkm6(void) {
    831 	return spl6();
    832 };
    833 
    834 int _spllkm7(void) {
    835 	return spl7();
    836 };
    837 
    838 #endif
    839 
    840 #endif
    841 
    842 int ipl2spl_table[_NIPL] = {
    843 	[IPL_NONE] = PSL_IPL0|PSL_S,
    844 	[IPL_SOFTCLOCK] = PSL_IPL1|PSL_S,
    845 	[IPL_VM] = PSL_IPL4|PSL_S,
    846 #if defined(LEV6_DEFER)
    847 	[IPL_SCHED] = PSL_IPL4|PSL_S,
    848 	[IPL_HIGH] = PSL_IPL4|PSL_S,
    849 #else /* defined(LEV6_DEFER) */
    850 	[IPL_SCHED] = PSL_IPL6|PSL_S,
    851 	[IPL_HIGH] = PSL_IPL7|PSL_S,
    852 #endif /* defined(LEV6_DEFER) */
    853 };
    854 
    855 int
    856 mm_md_physacc(paddr_t pa, vm_prot_t prot)
    857 {
    858 
    859 	return (pa >= 0xfffffffc || pa < lowram) ? EFAULT : 0;
    860 }
    861