machdep.c revision 1.3 1 /* $NetBSD: machdep.c,v 1.3 2001/05/12 22:35:30 chs Exp $ */
2 /*
3 * Copyright (c) 1998 Darrin Jewell
4 * Copyright (c) 1994 Rolf Grossmann
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Rolf Grossmann.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include <sys/types.h>
34
35 #include <stand.h>
36 #include <next68k/next68k/nextrom.h>
37
38 char *mg;
39
40 #define MON(type, off) (*(type *)((u_int) (mg) + off))
41
42 extern int entry_point;
43
44 #ifdef DEBUG
45 int debug = 1;
46 #else
47 int debug = 0;
48 #endif
49
50 #ifdef DEBUG
51 #define DPRINTF(x) printf x
52 #else
53 #define DPRINTF(x)
54 #endif
55
56 void
57 machdep_start(char *entry, int howto, char *loadaddr, char *ssym, char *esym)
58 {
59 DPRINTF(("machdep_start(entry=%p,howto=0x%x,loadaddr=%p,ssym=%p,esym=%p\n",
60 entry, howto, loadaddr, ssym, esym));
61 MON(int,MG_boot_how) = howto;
62 entry_point = (int)entry + (int)loadaddr;
63 DPRINTF(("start=0x%lx\n", (u_long)entry_point));
64
65 /* @@@ hack to pass esym to kernel */
66 *((u_int *)loadaddr) = (u_int)esym;
67
68 /* return to exec, so that main can return entry point */
69 }
70
71 typedef int (*getcptr)(void);
72 typedef int (*putcptr)(int);
73
74 int
75 getchar(void)
76 {
77 return(MON(getcptr,MG_getc)());
78 }
79
80 void
81 putchar(int c)
82 {
83 MON(putcptr,MG_putc)(c);
84 }
85
86 __dead void
87 _rtt(void)
88 {
89 extern __dead void _halt __P((void)) __attribute__((noreturn));
90
91 printf("Press any key to halt.\n");
92 getchar();
93 _halt();
94 /* NOTREACHED */
95 }
96
97 struct trapframe {
98 int dregs[8];
99 int aregs[8];
100 short sr;
101 int pc;
102 short frame;
103 char info[0];
104 };
105
106 int trap __P((struct trapframe *fp));
107
108 int
109 trap(struct trapframe *fp)
110 {
111 static int intrap = 0;
112
113 if (intrap)
114 return 0;
115 intrap = 1;
116 printf("Got unexpected trap: format=%x vector=%x sr=%x pc=%x\n",
117 (fp->frame>>12)&0xF, fp->frame&0xFFF, fp->sr, fp->pc);
118 printf("dregs: %x %x %x %x %x %x %x %x\n",
119 fp->dregs[0], fp->dregs[1], fp->dregs[2], fp->dregs[3],
120 fp->dregs[4], fp->dregs[5], fp->dregs[6], fp->dregs[7]);
121 printf("aregs: %x %x %x %x %x %x %x %x\n",
122 fp->aregs[0], fp->aregs[1], fp->aregs[2], fp->aregs[3],
123 fp->aregs[4], fp->aregs[5], fp->aregs[6], fp->aregs[7]);
124 intrap = 0;
125 printf("Halting.\n");
126 return 0;
127 }
128