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