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