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