#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.147 2026/04/28 03:29:10 thorpej Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
#include "opt_modular.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/signalvar.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/buf.h>
#include <sys/reboot.h>
#include <sys/conf.h>
#include <sys/file.h>
#include <sys/device.h>
#include <sys/mbuf.h>
#include <sys/msgbuf.h>
#include <sys/ioctl.h>
#include <sys/tty.h>
#include <sys/mount.h>
#include <sys/exec.h>
#include <sys/core.h>
#include <sys/kcore.h>
#include <sys/vnode.h>
#include <sys/syscallargs.h>
#include <sys/ksyms.h>
#include <sys/module.h>
#ifdef KGDB
#include <sys/kgdb.h>
#endif
#include <sys/boot_flag.h>
#include <sys/cpu.h>
#include <uvm/uvm_extern.h>
#ifdef DDB
#include <machine/db_machdep.h>
#include <ddb/db_access.h>
#include <ddb/db_sym.h>
#include <ddb/db_extern.h>
#endif
#ifdef KGDB
#include "zsc.h"
#if (NZSC > 0)
#include <next68k/dev/zs_cons.h>
#endif
#endif
#include <sys/sysctl.h>
#include <machine/cpu.h>
#include <machine/bus.h>
#include <machine/reg.h>
#include <machine/pcb.h>
#include <machine/psl.h>
#include <machine/pte.h>
#include <machine/vmparam.h>
#include <dev/cons.h>
#include <machine/kcore.h>
#include <next68k/dev/intiovar.h>
#include <next68k/next68k/isr.h>
#include <next68k/next68k/nextrom.h>
#include <next68k/next68k/rtc.h>
#include <m68k/seglist.h>
#include <dev/mm.h>
#include "ksyms.h"
int nsym;
char *ssym;
extern char *esym;
#define MAXMEM 64*1024
extern u_int lowram;
void machine_init(paddr_t);
int delay_divisor = delay_divisor_est40(33);
struct pmap_bootmap machine_bootmap[] = {
[PMBM_I_INTIO] = { .pmbm_vaddr_ptr = &intiobase,
.pmbm_paddr = INTIOBASE,
.pmbm_size = INTIOSIZE,
.pmbm_flags = PMBM_F_CI },
[PMBM_I_FB] = { .pmbm_vaddr_ptr = &fbbase,
.pmbm_paddr = 0,
.pmbm_size = 0,
.pmbm_flags = PMBM_F_CWT },
{ .pmbm_vaddr = -1 },
};
void
machine_init(paddr_t nextpa)
{
machine_init_common(nextpa);
{
char *p = rom_boot_arg;
boothowto = 0;
if (*p++ == '-') {
for (;*p;p++)
BOOT_FLAG(*p, boothowto);
}
}
}
void
consinit(void)
{
static int init = 0;
if (!init) {
cninit();
#if defined(KGDB) && (NZSC > 0)
zs_kgdb_init();
#endif
#if NKSYMS || defined(DDB) || defined(MODULAR)
ksyms_addsyms_elf(nsym, ssym, esym);
#endif
if (boothowto & RB_KDB) {
#if defined(KGDB)
kgdb_connect(1);
#elif defined(DDB)
Debugger();
#endif
}
init = 1;
}
}
void
machine_set_model(void)
{
extern int turbo;
const char *shape_str = "cube";
const char *color_str = iscolor ? " Color" : "";
const char *turbo_str = turbo ? " Turbo" : "";
switch (rom_machine_type) {
case NeXT_WARP9:
case NeXT_WARP9C:
case NeXT_TURBO_MONO:
case NeXT_TURBO_COLOR:
shape_str = "station";
case NeXT_CUBE:
case NeXT_X15:
case NeXT_CUBE_TURBO:
cpu_setmodel("NeXT%s%s%s", shape_str, color_str, turbo_str);
break;
default:
cpu_setmodel("NeXT machine type %d", rom_machine_type);
break;
}
switch (cputype) {
case CPU_68040:
cpuspeed_khz = (turbo ? 33 : 25) * 1000;
delay_divisor = delay_divisor_est40(cpuspeed_khz / 1000);
break;
case CPU_68030:
cpuspeed_khz = 25*1000;
delay_divisor = delay_divisor_est(cpuspeed_khz / 1000);
break;
default:
printf("\nunknown cputype %d\n", cputype);
panic("startup");
}
}
SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
{
sysctl_createv(clog, 0, NULL, NULL,
CTLFLAG_PERMANENT,
CTLTYPE_NODE, "machdep", NULL,
NULL, 0, NULL, 0,
CTL_MACHDEP, CTL_EOL);
#if 0
sysctl_createv(clog, 0, NULL, NULL,
CTLFLAG_PERMANENT,
CTLTYPE_STRUCT, "console_device", NULL,
sysctl_consdev, 0, NULL, sizeof(dev_t),
CTL_MACHDEP, CPU_CONSDEV, CTL_EOL);
#endif
}
void
machine_powerdown(void)
{
poweroff();
}
void
machine_halt(void)
{
monbootflag = 0x2d680000;
machine_reboot(RB_HALT, NULL);
}
int
nmihand(void *frame)
{
static int innmihand;
if (innmihand)
return 0;
innmihand = 1;
printf("Got a NMI");
if (!INTR_OCCURRED(NEXT_I_NMI)) {
printf("But NMI isn't set in intrstat!\n");
}
INTR_DISABLE(NEXT_I_NMI);
#if defined(DDB)
printf(": entering debugger\n");
Debugger();
printf("continuing after NMI\n");
#elif defined(KGDB)
kgdb_connect(1);
#else
printf(": ignoring\n");
#endif
INTR_ENABLE(NEXT_I_NMI);
innmihand = 0;
return 0;
}