machdep.c revision 1.52 1 /* $NetBSD: machdep.c,v 1.52 2007/05/21 15:22:22 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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
40
41 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.52 2007/05/21 15:22:22 tsutsui Exp $");
42
43 #include "opt_ddb.h"
44 #include "opt_kgdb.h"
45 #include "opt_compat_sunos.h"
46 #include "opt_panicbutton.h"
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/kernel.h>
51 #include <sys/proc.h>
52 #include <sys/buf.h>
53 #include <sys/reboot.h>
54 #include <sys/conf.h>
55 #include <sys/file.h>
56 #include <sys/device.h>
57 #include <sys/malloc.h>
58 #include <sys/mbuf.h>
59 #include <sys/msgbuf.h>
60 #include <sys/ioctl.h>
61 #include <sys/tty.h>
62 #include <sys/mount.h>
63 #include <sys/user.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 #ifdef KGDB
71 #include <sys/kgdb.h>
72 #endif
73 #include <sys/boot_flag.h>
74
75 #include <uvm/uvm_extern.h>
76
77 #include <sys/sysctl.h>
78
79 #include <machine/cpu.h>
80 #include <machine/reg.h>
81 #include <machine/psl.h>
82 #include <machine/pte.h>
83 #include <machine/kcore.h> /* XXX should be pulled in by sys/kcore.h */
84
85 #include <dev/cons.h>
86
87 #if defined(DDB)
88 #include <machine/db_machdep.h>
89 #include <ddb/db_sym.h>
90 #include <ddb/db_extern.h>
91 #endif
92
93 #include "ksyms.h"
94
95 /*
96 * Info for CTL_HW
97 */
98 char machine[] = MACHINE;
99 char cpu_model[60];
100
101 /* Our exported CPU info; we can have only one. */
102 struct cpu_info cpu_info_store;
103
104 struct vm_map *exec_map = NULL;
105 struct vm_map *mb_map = NULL;
106 struct vm_map *phys_map = NULL;
107
108 int maxmem; /* max memory per process */
109 int physmem; /* set by locore */
110 /*
111 * safepri is a safe priority for sleep to set for a spin-wait
112 * during autoconfiguration or after a panic.
113 */
114 int safepri = PSL_LOWIPL;
115
116 void luna68k_init __P((void));
117 void identifycpu __P((void));
118 void dumpsys __P((void));
119
120 void straytrap __P((int, u_short));
121 void nmihand __P((struct frame));
122
123 int cpu_dumpsize __P((void));
124 int cpu_dump __P((int (*)(dev_t, daddr_t, void *, size_t), daddr_t *));
125 void cpu_init_kcore_hdr __P((void));
126
127 /*
128 * Machine-independent crash dump header info.
129 */
130 cpu_kcore_hdr_t cpu_kcore_hdr;
131
132 int machtype; /* model: 1 for LUNA-1, 2 for LUNA-2 */
133 int sysconsole; /* console: 0 for ttya, 1 for video */
134
135 extern struct consdev syscons;
136 extern void omfb_cnattach __P((void));
137 extern void ws_cnattach __P((void));
138 extern void syscnattach __P((int));
139
140 /*
141 * On the 68020/68030, the value of delay_divisor is roughly
142 * 2048 / cpuspeed (where cpuspeed is in MHz).
143 *
144 * On the 68040/68060(?), the value of delay_divisor is roughly
145 * 759 / cpuspeed (where cpuspeed is in MHz).
146 * XXX -- is the above formula correct?
147 */
148 int cpuspeed = 25; /* only used for printing later */
149 int delay_divisor = 300; /* for delay() loop count */
150
151 /*
152 * Early initialization, before main() is called.
153 */
154 void
155 luna68k_init()
156 {
157 volatile unsigned char *pio0 = (void *)0x49000000;
158 int sw1, i;
159 char *cp;
160 extern char bootarg[64];
161
162 extern paddr_t avail_start, avail_end;
163
164 /*
165 * Tell the VM system about available physical memory. The
166 * luna68k only has one segment.
167 */
168 uvm_page_physload(atop(avail_start), atop(avail_end),
169 atop(avail_start), atop(avail_end), VM_FREELIST_DEFAULT);
170
171 /*
172 * Initialize error message buffer (at end of core).
173 * avail_end was pre-decremented in pmap_bootstrap to compensate.
174 */
175 for (i = 0; i < btoc(MSGBUFSIZE); i++)
176 pmap_enter(pmap_kernel(), (vaddr_t)msgbufaddr + i * PAGE_SIZE,
177 avail_end + i * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE,
178 VM_PROT_READ|VM_PROT_WRITE|PMAP_WIRED);
179 pmap_update(pmap_kernel());
180 initmsgbuf(msgbufaddr, m68k_round_page(MSGBUFSIZE));
181
182
183 pio0[3] = 0xb6;
184 pio0[2] = 1 << 6; /* enable parity check */
185 pio0[3] = 0xb6;
186 sw1 = pio0[0]; /* dipssw1 value */
187 sw1 ^= 0xff;
188 sysconsole = !(sw1 & 0x2); /* console selection */
189
190 boothowto = 0;
191 i = 0;
192 /*
193 * 'bootarg' has;
194 * "<args of x command> ENADDR=<addr> HOST=<host> SERVER=<name>"
195 * where <addr> is MAC address of which network loader used (not
196 * necessarily same as one at 0x4101.FFE0), <host> and <name>
197 * are the values of HOST and SERVER environment variables,
198 *
199 * NetBSD/luna68k cares only the first argment; any of "sda".
200 */
201 for (cp = bootarg; *cp != ' '; cp++) {
202 BOOT_FLAG(*cp, boothowto);
203 if (i++ >= sizeof(bootarg))
204 break;
205 }
206 #if 0 /* overload 1:sw1, which now means 'go ROM monitor' after poweron */
207 if (boothowto == 0)
208 boothowto = (sw1 & 0x1) ? RB_SINGLE : 0;
209 #endif
210 }
211
212 /*
213 * Console initialization: called early on from main,
214 */
215 void
216 consinit()
217 {
218 if (sysconsole == 0)
219 syscnattach(0);
220 else {
221 omfb_cnattach();
222 ws_cnattach();
223 }
224
225 #if NKSYMS || defined(DDB) || defined(LKM)
226 {
227 extern char end[];
228 extern int *esym;
229
230 ksyms_init(*(int *)&end, ((int *)&end) + 1, esym);
231 }
232 #endif
233 #ifdef DDB
234 if (boothowto & RB_KDB)
235 cpu_Debugger();
236 #endif
237 }
238
239 /*
240 * cpu_startup: allocate memory for variable-sized tables.
241 */
242 void
243 cpu_startup()
244 {
245 vaddr_t minaddr, maxaddr;
246 char pbuf[9];
247 extern void greeting __P((void));
248
249 if (fputype != FPU_NONE)
250 m68k_make_fpu_idle_frame();
251
252 /*
253 * Initialize the kernel crash dump header.
254 */
255 cpu_init_kcore_hdr();
256
257 /*
258 * Good {morning,afternoon,evening,night}.
259 */
260 printf("%s%s", copyright, version);
261 identifycpu();
262
263 format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
264 printf("total memory = %s\n", pbuf);
265
266 minaddr = 0;
267 /*
268 * Allocate a submap for exec arguments. This map effectively
269 * limits the number of processes exec'ing at any time.
270 */
271 exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
272 16*NCARGS, VM_MAP_PAGEABLE, false, NULL);
273
274 /*
275 * Allocate a submap for physio
276 */
277 phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
278 VM_PHYS_SIZE, 0, false, NULL);
279
280 /*
281 * Finally, allocate mbuf cluster submap.
282 */
283 mb_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
284 nmbclusters * mclbytes, VM_MAP_INTRSAFE,
285 false, NULL);
286
287 format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
288 printf("avail memory = %s\n", pbuf);
289
290 /*
291 * Say "Hi" to the world
292 */
293 greeting();
294 }
295
296 /*
297 * Set registers on exec.
298 */
299 void
300 setregs(l, pack, stack)
301 struct lwp *l;
302 struct exec_package *pack;
303 u_long stack;
304 {
305 struct frame *frame = (struct frame *)l->l_md.md_regs;
306 extern int fputype;
307
308 frame->f_sr = PSL_USERSET;
309 frame->f_pc = pack->ep_entry & ~1;
310 frame->f_regs[D0] = 0;
311 frame->f_regs[D1] = 0;
312 frame->f_regs[D2] = 0;
313 frame->f_regs[D3] = 0;
314 frame->f_regs[D4] = 0;
315 frame->f_regs[D5] = 0;
316 frame->f_regs[D6] = 0;
317 frame->f_regs[D7] = 0;
318 frame->f_regs[A0] = 0;
319 frame->f_regs[A1] = 0;
320 frame->f_regs[A2] = (int)l->l_proc->p_psstr;
321 frame->f_regs[A3] = 0;
322 frame->f_regs[A4] = 0;
323 frame->f_regs[A5] = 0;
324 frame->f_regs[A6] = 0;
325 frame->f_regs[SP] = stack;
326
327 /* restore a null state frame */
328 l->l_addr->u_pcb.pcb_fpregs.fpf_null = 0;
329 if (fputype)
330 m68881_restore(&l->l_addr->u_pcb.pcb_fpregs);
331 }
332
333 void
334 identifycpu()
335 {
336 extern int cputype;
337 const char *cpu;
338
339 bzero(cpu_model, sizeof(cpu_model));
340 switch (cputype) {
341 case CPU_68030:
342 cpu = "MC68030 CPU+MMU, MC68882 FPU";
343 machtype = LUNA_I;
344 cpuspeed = 20; delay_divisor = 102; /* 20MHz 68030 */
345 hz = 60;
346 break;
347 #if defined(M68040)
348 case CPU_68040:
349 cpu = "MC68040 CPU+MMU+FPU, 4k on-chip physical I/D caches";
350 machtype = LUNA_II;
351 cpuspeed = 25; delay_divisor = 300; /* 25MHz 68040 */
352 break;
353 #endif
354 default:
355 panic("unknown CPU type");
356 }
357 strcpy(cpu_model, cpu);
358 printf("%s\n", cpu_model);
359 }
360
361 /*
362 * machine dependent system variables.
363 */
364 SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
365 {
366
367 sysctl_createv(clog, 0, NULL, NULL,
368 CTLFLAG_PERMANENT,
369 CTLTYPE_NODE, "machdep", NULL,
370 NULL, 0, NULL, 0,
371 CTL_MACHDEP, CTL_EOL);
372
373 sysctl_createv(clog, 0, NULL, NULL,
374 CTLFLAG_PERMANENT,
375 CTLTYPE_STRUCT, "console_device", NULL,
376 sysctl_consdev, 0, NULL, sizeof(dev_t),
377 CTL_MACHDEP, CPU_CONSDEV, CTL_EOL);
378 }
379
380 int waittime = -1;
381
382 void
383 cpu_reboot(howto, bootstr)
384 volatile int howto; /* XXX to shutup GCC XXX */
385 char *bootstr;
386 {
387 extern void doboot __P((void));
388
389 /* take a snap shot before clobbering any registers */
390 if (curlwp->l_addr)
391 savectx(&curlwp->l_addr->u_pcb);
392
393 /* If system is hold, just halt. */
394 if (cold) {
395 howto |= RB_HALT;
396 goto haltsys;
397 }
398
399 boothowto = howto;
400 if ((howto & RB_NOSYNC) == 0 && waittime < 0) {
401 waittime = 0;
402 vfs_shutdown();
403 /*
404 * If we've been adjusting the clock, the todr
405 * will be out of synch; adjust it now.
406 */
407 resettodr();
408 }
409
410 /* Disable interrupts. */
411 splhigh();
412
413 /* If rebooting and a dump is requested, do it. */
414 if (howto & RB_DUMP)
415 dumpsys();
416
417 haltsys:
418 /* Run any shutdown hooks. */
419 doshutdownhooks();
420
421 /* Finally, halt/reboot the system. */
422 if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
423 u_int8_t *pio = (void *)0x4d000000;
424
425 printf("power is going down.\n");
426 DELAY(100000);
427 pio[3] = 0x94;
428 pio[2] = 0 << 4;
429 for (;;) /* NOP */;
430 }
431 if (howto & RB_HALT) {
432 printf("System halted. Hit any key to reboot.\n\n");
433 (void)cngetc();
434 }
435
436 printf("rebooting...\n");
437 DELAY(100000);
438 doboot();
439 /*NOTREACHED*/
440 while (1) ;
441 }
442
443 /*
444 * Initialize the kernel crash dump header.
445 */
446 void
447 cpu_init_kcore_hdr()
448 {
449 cpu_kcore_hdr_t *h = &cpu_kcore_hdr;
450 struct m68k_kcore_hdr *m = &h->un._m68k;
451 extern char end[];
452
453 bzero(&cpu_kcore_hdr, sizeof(cpu_kcore_hdr));
454
455 /*
456 * Initialize the `dispatcher' portion of the header.
457 */
458 strcpy(h->name, machine);
459 h->page_size = PAGE_SIZE;
460 h->kernbase = KERNBASE;
461
462 /*
463 * Fill in information about our MMU configuration.
464 */
465 m->mmutype = mmutype;
466 m->sg_v = SG_V;
467 m->sg_frame = SG_FRAME;
468 m->sg_ishift = SG_ISHIFT;
469 m->sg_pmask = SG_PMASK;
470 m->sg40_shift1 = SG4_SHIFT1;
471 m->sg40_mask2 = SG4_MASK2;
472 m->sg40_shift2 = SG4_SHIFT2;
473 m->sg40_mask3 = SG4_MASK3;
474 m->sg40_shift3 = SG4_SHIFT3;
475 m->sg40_addr1 = SG4_ADDR1;
476 m->sg40_addr2 = SG4_ADDR2;
477 m->pg_v = PG_V;
478 m->pg_frame = PG_FRAME;
479
480 /*
481 * Initialize pointer to kernel segment table.
482 */
483 m->sysseg_pa = (u_int32_t)(pmap_kernel()->pm_stpa);
484
485 /*
486 * Initialize relocation value such that:
487 *
488 * pa = (va - KERNBASE) + reloc
489 *
490 * Since we're linked and loaded at the same place,
491 * and the kernel is mapped va == pa, this is 0.
492 */
493 m->reloc = 0;
494
495 /*
496 * Define the end of the relocatable range.
497 */
498 m->relocend = (u_int32_t)end;
499
500 /*
501 * The luna68k has one contiguous memory segment.
502 */
503 m->ram_segs[0].start = 0 /* lowram */;
504 m->ram_segs[0].size = ctob(physmem);
505 }
506
507 /*
508 * Compute the size of the machine-dependent crash dump header.
509 * Returns size in disk blocks.
510 */
511
512 #define CHDRSIZE (ALIGN(sizeof(kcore_seg_t)) + ALIGN(sizeof(cpu_kcore_hdr_t)))
513 #define MDHDRSIZE roundup(CHDRSIZE, dbtob(1))
514
515 int
516 cpu_dumpsize()
517 {
518
519 return btodb(MDHDRSIZE);
520 }
521
522 /*
523 * Called by dumpsys() to dump the machine-dependent header.
524 */
525 int
526 cpu_dump(dump, blknop)
527 int (*dump) __P((dev_t, daddr_t, void *, size_t));
528 daddr_t *blknop;
529 {
530 int buf[MDHDRSIZE / sizeof(int)];
531 cpu_kcore_hdr_t *chdr;
532 kcore_seg_t *kseg;
533 int error;
534
535 kseg = (kcore_seg_t *)buf;
536 chdr = (cpu_kcore_hdr_t *)&buf[ALIGN(sizeof(kcore_seg_t)) /
537 sizeof(int)];
538
539 /* Create the segment header. */
540 CORE_SETMAGIC(*kseg, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
541 kseg->c_size = MDHDRSIZE - ALIGN(sizeof(kcore_seg_t));
542
543 bcopy(&cpu_kcore_hdr, chdr, sizeof(cpu_kcore_hdr_t));
544 error = (*dump)(dumpdev, *blknop, (void *)buf, sizeof(buf));
545 *blknop += btodb(sizeof(buf));
546 return (error);
547 }
548
549 /*
550 * These variables are needed by /sbin/savecore
551 */
552 u_int32_t dumpmag = 0x8fca0101; /* magic number */
553 int dumpsize = 0; /* pages */
554 long dumplo = 0; /* blocks */
555
556 /*
557 * This is called by main to set dumplo and dumpsize.
558 * Dumps always skip the first PAGE_SIZE of disk space
559 * in case there might be a disk label stored there.
560 * If there is extra space, put dump at the end to
561 * reduce the chance that swapping trashes it.
562 */
563 void
564 cpu_dumpconf()
565 {
566 const struct bdevsw *bdev;
567 int chdrsize; /* size of dump header */
568 int nblks; /* size of dump area */
569
570 if (dumpdev == NODEV)
571 return;
572 bdev = bdevsw_lookup(dumpdev);
573 if (bdev == NULL) {
574 dumpdev = NODEV;
575 return;
576 }
577 if (bdev->d_psize == NULL)
578 return;
579 nblks = (*bdev->d_psize)(dumpdev);
580 chdrsize = cpu_dumpsize();
581
582 dumpsize = btoc(cpu_kcore_hdr.un._m68k.ram_segs[0].size);
583
584 /*
585 * Check do see if we will fit. Note we always skip the
586 * first PAGE_SIZE in case there is a disk label there.
587 */
588 if (nblks < (ctod(dumpsize) + chdrsize + ctod(1))) {
589 dumpsize = 0;
590 dumplo = -1;
591 return;
592 }
593
594 /*
595 * Put dump at the end of the partition.
596 */
597 dumplo = (nblks - 1) - ctod(dumpsize) - chdrsize;
598 }
599
600 /*
601 * Dump physical memory onto the dump device. Called by cpu_reboot().
602 */
603 void
604 dumpsys()
605 {
606 const struct bdevsw *bdev;
607 daddr_t blkno; /* current block to write */
608 /* dump routine */
609 int (*dump) __P((dev_t, daddr_t, void *, size_t));
610 int pg; /* page being dumped */
611 paddr_t maddr; /* PA being dumped */
612 int error; /* error code from (*dump)() */
613
614 /* XXX initialized here because of gcc lossage */
615 maddr = 0 /* lowram */;
616 pg = 0;
617
618 /* Make sure dump device is valid. */
619 if (dumpdev == NODEV)
620 return;
621 bdev = bdevsw_lookup(dumpdev);
622 if (bdev == NULL)
623 return;
624 if (dumpsize == 0) {
625 cpu_dumpconf();
626 if (dumpsize == 0)
627 return;
628 }
629 if (dumplo <= 0) {
630 printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
631 minor(dumpdev));
632 return;
633 }
634 dump = bdev->d_dump;
635 blkno = dumplo;
636
637 printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
638 minor(dumpdev), dumplo);
639
640 printf("dump ");
641
642 /* Write the dump header. */
643 error = cpu_dump(dump, &blkno);
644 if (error)
645 goto bad;
646
647 for (pg = 0; pg < dumpsize; pg++) {
648 #define NPGMB (1024*1024/PAGE_SIZE)
649 /* print out how many MBs we have dumped */
650 if (pg && (pg % NPGMB) == 0)
651 printf("%d ", pg / NPGMB);
652 #undef NPGMB
653 pmap_enter(pmap_kernel(), (vaddr_t)vmmap, maddr,
654 VM_PROT_READ, VM_PROT_READ|PMAP_WIRED);
655
656 pmap_update(pmap_kernel());
657 error = (*dump)(dumpdev, blkno, vmmap, PAGE_SIZE);
658 bad:
659 switch (error) {
660 case 0:
661 maddr += PAGE_SIZE;
662 blkno += btodb(PAGE_SIZE);
663 break;
664
665 case ENXIO:
666 printf("device bad\n");
667 return;
668
669 case EFAULT:
670 printf("device not ready\n");
671 return;
672
673 case EINVAL:
674 printf("area improper\n");
675 return;
676
677 case EIO:
678 printf("i/o error\n");
679 return;
680
681 case EINTR:
682 printf("aborted from console\n");
683 return;
684
685 default:
686 printf("error %d\n", error);
687 return;
688 }
689 }
690 printf("succeeded\n");
691 }
692
693 void
694 straytrap(pc, evec)
695 int pc;
696 u_short evec;
697 {
698 printf("unexpected trap (vector offset %x) from %x\n",
699 evec & 0xFFF, pc);
700 }
701
702 int *nofault;
703
704 int
705 badaddr(addr, nbytes)
706 register void *addr;
707 int nbytes;
708 {
709 register int i;
710 label_t faultbuf;
711
712 #ifdef lint
713 i = *addr; if (i) return (0);
714 #endif
715
716 nofault = (int *) &faultbuf;
717 if (setjmp((label_t *)nofault)) {
718 nofault = (int *) 0;
719 return(1);
720 }
721
722 switch (nbytes) {
723 case 1:
724 i = *(volatile char *)addr;
725 break;
726
727 case 2:
728 i = *(volatile short *)addr;
729 break;
730
731 case 4:
732 i = *(volatile int *)addr;
733 break;
734
735 default:
736 panic("badaddr: bad request");
737 }
738 nofault = (int *) 0;
739 return (0);
740 }
741
742 void luna68k_abort __P((const char *));
743
744 static int innmihand; /* simple mutex */
745
746 /*
747 * Level 7 interrupts are caused by e.g. the ABORT switch.
748 *
749 * If we have DDB, then break into DDB on ABORT. In a production
750 * environment, bumping the ABORT switch would be bad, so we enable
751 * panic'ing on ABORT with the kernel option "PANICBUTTON".
752 */
753 void
754 nmihand(frame)
755 struct frame frame;
756 {
757 /* Prevent unwanted recursion */
758 if (innmihand)
759 return;
760 innmihand = 1;
761
762 luna68k_abort("ABORT SWITCH");
763 }
764
765 /*
766 * Common code for handling ABORT signals from buttons, switches,
767 * serial lines, etc.
768 */
769 void
770 luna68k_abort(cp)
771 const char *cp;
772 {
773 #ifdef DDB
774 printf("%s\n", cp);
775 cpu_Debugger();
776 #else
777 #ifdef PANICBUTTON
778 panic(cp);
779 #else
780 printf("%s ignored\n", cp);
781 #endif /* PANICBUTTON */
782 #endif /* DDB */
783 }
784
785 /*
786 * cpu_exec_aout_makecmds():
787 * CPU-dependent a.out format hook for execve().
788 *
789 * Determine of the given exec package refers to something which we
790 * understand and, if so, set up the vmcmds for it.
791 */
792 int
793 cpu_exec_aout_makecmds(l, epp)
794 struct lwp *l;
795 struct exec_package *epp;
796 {
797 int error = ENOEXEC;
798 #ifdef COMPAT_SUNOS
799 extern sunos_exec_aout_makecmds
800 __P((struct proc *, struct exec_package *));
801 if ((error = sunos_exec_aout_makecmds(l->l_proc, epp)) == 0)
802 return 0;
803 #endif
804 return error;
805 }
806
807 #if 1
808
809 struct consdev *cn_tab = &syscons;
810
811 #else
812
813 /*
814 * romcons is useful until m68k TC register is initialized.
815 */
816 int romcngetc __P((dev_t));
817 void romcnputc __P((dev_t, int));
818
819 struct consdev romcons = {
820 NULL,
821 NULL,
822 romcngetc,
823 romcnputc,
824 nullcnpollc,
825 makedev(7, 0), /* XXX */
826 CN_DEAD,
827 };
828 struct consdev *cn_tab = &romcons;
829
830 #define __ ((int **)0x41000000)
831 #define GETC() (*(int (*)())__[6])()
832 #define PUTC(x) (*(void (*)())__[7])(x)
833
834 #define ROMPUTC(x) \
835 ({ \
836 register _r; \
837 __asm volatile (" \
838 movc %%vbr,%0 ; \
839 movel %0,%%sp@- ; \
840 clrl %0 ; \
841 movc %0,%%vbr" \
842 : "=r" (_r)); \
843 PUTC(x); \
844 __asm volatile (" \
845 movel %%sp@+,%0 ; \
846 movc %0,%%vbr" \
847 : "=r" (_r)); \
848 })
849
850 #define ROMGETC() \
851 ({ \
852 register _r, _c; \
853 __asm volatile (" \
854 movc %%vbr,%0 ; \
855 movel %0,%%sp@- ; \
856 clrl %0 ; \
857 movc %0,%%vbr" \
858 : "=r" (_r)); \
859 _c = GETC(); \
860 __asm volatile (" \
861 movel %%sp@+,%0 ; \
862 movc %0,%%vbr" \
863 : "=r" (_r)); \
864 _c; \
865 })
866
867 void
868 romcnputc(dev, c)
869 dev_t dev;
870 int c;
871 {
872 int s;
873
874 s = splhigh();
875 ROMPUTC(c);
876 splx(s);
877 }
878
879 int
880 romcngetc(dev)
881 dev_t dev;
882 {
883 int s, c;
884
885 do {
886 s = splhigh();
887 c = ROMGETC();
888 splx(s);
889 } while (c == -1);
890 return c;
891 }
892 #endif
893