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