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