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