machdep.c revision 1.1 1 /* $NetBSD: machdep.c,v 1.1 2013/01/05 17:44:24 tsutsui Exp $ */
2
3 /*
4 * Copyright (c) 1992 OMRON Corporation.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * OMRON Corporation.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * @(#)machdep.c 8.1 (Berkeley) 6/10/93
38 */
39 /*
40 * Copyright (c) 1992, 1993
41 * The Regents of the University of California. All rights reserved.
42 *
43 * This code is derived from software contributed to Berkeley by
44 * OMRON Corporation.
45 *
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
48 * are met:
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. Neither the name of the University nor the names of its contributors
55 * may be used to endorse or promote products derived from this software
56 * without specific prior written permission.
57 *
58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE.
69 *
70 * @(#)machdep.c 8.1 (Berkeley) 6/10/93
71 */
72
73 #include <sys/param.h>
74 #include <luna68k/include/reg.h>
75 #include <luna68k/stand/boot/samachdep.h>
76
77 static void dumpmem(int *, int, int);
78
79 void
80 straytrap(int addr)
81 {
82 printf("stray trap, addr 0x%x\n", addr);
83 }
84
85 int *nofault = 0;
86
87 int
88 badaddr(volatile void *addr)
89 {
90 int i;
91 label_t faultbuf;
92
93 #ifdef lint
94 i = *addr; if (i) return(0);
95 #endif
96 nofault = (int *) &faultbuf;
97 if (setjmp((label_t *)nofault)) {
98 nofault = (int *) 0;
99 return(1);
100 }
101 i = *(volatile short *)addr;
102 nofault = (int *) 0;
103 return(0);
104 }
105
106 void
107 regdump(int *rp /* must not be register */, int sbytes)
108 {
109 static int doingdump = 0;
110 int i;
111 int s;
112
113 if (doingdump)
114 return;
115 s = splhigh();
116 doingdump = 1;
117 /* printf("pid = %d, pc = %s, ", u.u_procp->p_pid, hexstr(rp[PC], 8)); */
118 printf("pc = %s, ", hexstr(rp[PC], 8));
119 printf("ps = %s, ", hexstr(rp[PS], 4));
120 printf("sfc = %s, ", hexstr(getsfc(), 4));
121 printf("dfc = %s\n", hexstr(getdfc(), 4));
122 /*
123 printf("p0 = %x@%s, ",
124 u.u_pcb.pcb_p0lr, hexstr((int)u.u_pcb.pcb_p0br, 8));
125 printf("p1 = %x@%s\n\n",
126 u.u_pcb.pcb_p1lr, hexstr((int)u.u_pcb.pcb_p1br, 8));
127 */
128 printf("Registers:\n ");
129 for (i = 0; i < 8; i++)
130 printf(" %d", i);
131 printf("\ndreg:");
132 for (i = 0; i < 8; i++)
133 printf(" %s", hexstr(rp[i], 8));
134 printf("\nareg:");
135 for (i = 0; i < 8; i++)
136 printf(" %s", hexstr(rp[i+8], 8));
137 if (sbytes > 0) {
138 /* if (rp[PS] & PSL_S) { */
139 printf("\n\nKernel stack (%s):",
140 hexstr((int)(((int *)&rp)-1), 8));
141 dumpmem(((int *)&rp)-1, sbytes, 0);
142 /*
143 } else {
144 printf("\n\nUser stack (%s):", hexstr(rp[SP], 8));
145 dumpmem((int *)rp[SP], sbytes, 1);
146 }
147 */
148 }
149 doingdump = 0;
150 splx(s);
151 }
152
153 /* #define KSADDR ((int *)&(((char *)&u)[(UPAGES-1)*NBPG])) */
154
155 void
156 dumpmem(int *ptr, int sz, int ustack)
157 {
158 int i, val;
159
160 for (i = 0; i < sz; i++) {
161 if ((i & 7) == 0)
162 printf("\n%s: ", hexstr((int)ptr, 6));
163 else
164 printf(" ");
165 /*
166 if (ustack == 1) {
167 if ((val = fuword(ptr++)) == -1)
168 break;
169 } else {
170 if (ustack == 0 && (ptr < KSADDR || ptr > KSADDR+(NBPG/4-1)))
171 break;
172 */
173 val = *ptr++;
174 /* } */
175 printf("%s", hexstr(val, 8));
176 }
177 printf("\n");
178 }
179
180 char *
181 hexstr(int val, int len)
182 {
183 static char nbuf[9];
184 int x, i;
185
186 if (len > 8)
187 return("");
188 nbuf[len] = '\0';
189 for (i = len-1; i >= 0; --i) {
190 x = val & 0xF;
191 if (x > 9)
192 nbuf[i] = x - 10 + 'A';
193 else
194 nbuf[i] = x + '0';
195 val >>= 4;
196 }
197 return(nbuf);
198 }
199