1 /* $NetBSD: machdep.c,v 1.147 2026/04/28 03:29:10 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1998 Darrin B. Jewell 5 * Copyright (c) 1988 University of Utah. 6 * Copyright (c) 1982, 1986, 1990, 1993 7 * The Regents of the University of California. All rights reserved. 8 * 9 * This code is derived from software contributed to Berkeley by 10 * the Systems Programming Group of the University of Utah Computer 11 * Science Department. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 3. Neither the name of the University nor the names of its contributors 22 * may be used to endorse or promote products derived from this software 23 * without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * 37 * from: Utah $Hdr: machdep.c 1.74 92/12/20$ 38 * 39 * @(#)machdep.c 8.10 (Berkeley) 4/20/94 40 */ 41 42 #include <sys/cdefs.h> 43 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.147 2026/04/28 03:29:10 thorpej Exp $"); 44 45 #include "opt_ddb.h" 46 #include "opt_kgdb.h" 47 #include "opt_modular.h" 48 49 #include <sys/param.h> 50 #include <sys/systm.h> 51 #include <sys/signalvar.h> 52 #include <sys/kernel.h> 53 #include <sys/proc.h> 54 #include <sys/buf.h> 55 #include <sys/reboot.h> 56 #include <sys/conf.h> 57 #include <sys/file.h> 58 #include <sys/device.h> 59 #include <sys/mbuf.h> 60 #include <sys/msgbuf.h> 61 #include <sys/ioctl.h> 62 #include <sys/tty.h> 63 #include <sys/mount.h> 64 #include <sys/exec.h> 65 #include <sys/core.h> 66 #include <sys/kcore.h> 67 #include <sys/vnode.h> 68 #include <sys/syscallargs.h> 69 #include <sys/ksyms.h> 70 #include <sys/module.h> 71 #ifdef KGDB 72 #include <sys/kgdb.h> 73 #endif 74 #include <sys/boot_flag.h> 75 #include <sys/cpu.h> 76 77 #include <uvm/uvm_extern.h> 78 79 #ifdef DDB 80 #include <machine/db_machdep.h> 81 #include <ddb/db_access.h> 82 #include <ddb/db_sym.h> 83 #include <ddb/db_extern.h> 84 #endif 85 86 #ifdef KGDB 87 /* Is zs configured in? */ 88 #include "zsc.h" 89 #if (NZSC > 0) 90 #include <next68k/dev/zs_cons.h> 91 #endif 92 #endif 93 94 #include <sys/sysctl.h> 95 96 #include <machine/cpu.h> 97 #include <machine/bus.h> 98 #include <machine/reg.h> 99 #include <machine/pcb.h> 100 #include <machine/psl.h> 101 #include <machine/pte.h> 102 #include <machine/vmparam.h> 103 #include <dev/cons.h> 104 105 #include <machine/kcore.h> /* XXX should be pulled in by sys/kcore.h */ 106 107 #include <next68k/dev/intiovar.h> 108 #include <next68k/next68k/isr.h> 109 #include <next68k/next68k/nextrom.h> 110 #include <next68k/next68k/rtc.h> 111 #include <m68k/seglist.h> 112 113 #include <dev/mm.h> 114 115 #include "ksyms.h" 116 117 int nsym; 118 char *ssym; 119 extern char *esym; 120 121 #define MAXMEM 64*1024 /* XXX - from cmap.h */ 122 123 extern u_int lowram; 124 125 /* functions called from locore.s */ 126 void machine_init(paddr_t); 127 128 /* 129 * Default to 33MHz 68040. 130 */ 131 int delay_divisor = delay_divisor_est40(33); 132 133 /****************************************************************/ 134 135 struct pmap_bootmap machine_bootmap[] = { 136 [PMBM_I_INTIO] = { .pmbm_vaddr_ptr = &intiobase, 137 .pmbm_paddr = INTIOBASE, 138 .pmbm_size = INTIOSIZE, 139 .pmbm_flags = PMBM_F_CI }, 140 141 [PMBM_I_FB] = { .pmbm_vaddr_ptr = &fbbase, 142 .pmbm_paddr = 0, /* filled in by... */ 143 .pmbm_size = 0, /* ...next68k_bootargs() */ 144 .pmbm_flags = PMBM_F_CWT }, 145 146 { .pmbm_vaddr = -1 }, 147 }; 148 149 /* 150 * Early initialization, before main() is called. 151 */ 152 void 153 machine_init(paddr_t nextpa) 154 { 155 machine_init_common(nextpa); 156 157 { 158 char *p = rom_boot_arg; 159 boothowto = 0; 160 if (*p++ == '-') { 161 for (;*p;p++) 162 BOOT_FLAG(*p, boothowto); 163 } 164 } 165 } 166 167 /* 168 * Console initialization: called early on from main, 169 * before vm init or startup. Do enough configuration 170 * to choose and initialize a console. 171 */ 172 void 173 consinit(void) 174 { 175 static int init = 0; 176 177 /* 178 * Generic console: sys/dev/cons.c 179 * Initializes either ite or ser as console. 180 * Can be called from locore.s and init_main.c. 181 */ 182 183 if (!init) { 184 cninit(); 185 #if defined(KGDB) && (NZSC > 0) 186 zs_kgdb_init(); 187 #endif 188 #if NKSYMS || defined(DDB) || defined(MODULAR) 189 /* Initialize kernel symbol table, if compiled in. */ 190 ksyms_addsyms_elf(nsym, ssym, esym); 191 #endif 192 if (boothowto & RB_KDB) { 193 #if defined(KGDB) 194 kgdb_connect(1); 195 #elif defined(DDB) 196 Debugger(); 197 #endif 198 } 199 200 init = 1; 201 } 202 } 203 204 void 205 machine_set_model(void) 206 { 207 extern int turbo; 208 const char *shape_str = "cube"; 209 const char *color_str = iscolor ? " Color" : ""; 210 const char *turbo_str = turbo ? " Turbo" : ""; 211 212 switch (rom_machine_type) { 213 case NeXT_WARP9: /* 68040 25MHz NeXTstation */ 214 case NeXT_WARP9C: /* 68040 25MHz NeXTstation Color */ 215 case NeXT_TURBO_MONO: /* 68040 33MHz NeXTstation */ 216 case NeXT_TURBO_COLOR: /* 68040 33MHz NeXTstation Color */ 217 shape_str = "station"; 218 /* FALLTHROUGH */ 219 case NeXT_CUBE: /* 68030 25MHz NeXTcube */ 220 case NeXT_X15: /* 68040 25MHz NeXTcubr */ 221 case NeXT_CUBE_TURBO: /* 68040 33MHz NeXTcube */ 222 cpu_setmodel("NeXT%s%s%s", shape_str, color_str, turbo_str); 223 break; 224 225 default: 226 cpu_setmodel("NeXT machine type %d", rom_machine_type); 227 break; 228 } 229 230 switch (cputype) { 231 case CPU_68040: 232 cpuspeed_khz = (turbo ? 33 : 25) * 1000; 233 delay_divisor = delay_divisor_est40(cpuspeed_khz / 1000); 234 break; 235 case CPU_68030: 236 cpuspeed_khz = 25*1000; 237 delay_divisor = delay_divisor_est(cpuspeed_khz / 1000); 238 break; 239 default: 240 printf("\nunknown cputype %d\n", cputype); 241 panic("startup"); 242 } 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 #if 0 258 sysctl_createv(clog, 0, NULL, NULL, 259 CTLFLAG_PERMANENT, 260 CTLTYPE_STRUCT, "console_device", NULL, 261 sysctl_consdev, 0, NULL, sizeof(dev_t), 262 CTL_MACHDEP, CPU_CONSDEV, CTL_EOL); 263 #endif 264 } 265 266 void 267 machine_powerdown(void) 268 { 269 poweroff(); 270 } 271 272 void 273 machine_halt(void) 274 { 275 monbootflag = 0x2d680000; /* "-h" halts instead of reboot */ 276 machine_reboot(RB_HALT, NULL); /* args are ignored */ 277 } 278 279 /* 280 * Level 7 interrupts can be caused by the keyboard or parity errors. 281 */ 282 int 283 nmihand(void *frame) 284 { 285 static int innmihand; /* simple mutex */ 286 287 /* Prevent unwanted recursion. */ 288 if (innmihand) 289 return 0; 290 innmihand = 1; 291 292 printf("Got a NMI"); 293 294 if (!INTR_OCCURRED(NEXT_I_NMI)) { 295 printf("But NMI isn't set in intrstat!\n"); 296 } 297 INTR_DISABLE(NEXT_I_NMI); 298 299 #if defined(DDB) 300 printf(": entering debugger\n"); 301 Debugger(); 302 printf("continuing after NMI\n"); 303 #elif defined(KGDB) 304 kgdb_connect(1); 305 #else 306 printf(": ignoring\n"); 307 #endif /* DDB */ 308 309 INTR_ENABLE(NEXT_I_NMI); 310 311 innmihand = 0; 312 313 return 0; 314 } 315