stubs.c revision 1.1.2.2 1 /* $NetBSD: stubs.c,v 1.1.2.2 2001/08/03 04:10:59 lukem Exp $ */
2
3 /*
4 * Copyright (c) 1994-1998 Mark Brinicombe.
5 * Copyright (c) 1994 Brini.
6 * All rights reserved.
7 *
8 * This code is derived from software written for Brini by Mark Brinicombe
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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by Mark Brinicombe
21 * for the NetBSD Project.
22 * 4. The name of the company nor the name of the author may be used to
23 * endorse or promote products derived from this software without specific
24 * prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * Routines that are temporary or do not have a home yet.
39 *
40 * Created : 17/09/94
41 */
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/errno.h>
46 #include <sys/proc.h>
47 #include <sys/conf.h>
48 #include <sys/msgbuf.h>
49 #include <uvm/uvm_extern.h>
50 #include <machine/cpu.h>
51 #include <machine/irqhandler.h>
52 #include <machine/bootconfig.h>
53 #include <machine/pcb.h>
54
55 extern dev_t dumpdev;
56 extern BootConfig bootconfig;
57
58 /* These queue functions are candiates for arm32/machdep.c */
59 struct queue {
60 struct queue *q_next, *q_prev;
61 };
62
63 /*
64 * insert an element into a queue
65 */
66
67 void
68 _insque(v1, v2)
69 void *v1;
70 void *v2;
71 {
72 struct queue *elem = v1, *head = v2;
73 struct queue *next;
74
75 next = head->q_next;
76 elem->q_next = next;
77 head->q_next = elem;
78 elem->q_prev = head;
79 next->q_prev = elem;
80 }
81
82 /*
83 * remove an element from a queue
84 */
85
86 void
87 _remque(v)
88 void *v;
89 {
90 struct queue *elem = v;
91 struct queue *next, *prev;
92
93 next = elem->q_next;
94 prev = elem->q_prev;
95 next->q_prev = prev;
96 prev->q_next = next;
97 elem->q_prev = 0;
98 }
99
100
101 /*
102 * These variables are needed by /sbin/savecore
103 */
104 u_long dumpmag = 0x8fca0101; /* magic number */
105 int dumpsize = 0; /* pages */
106 long dumplo = 0; /* blocks */
107
108 struct pcb dumppcb;
109
110 /*
111 * This is called by main to set dumplo and dumpsize.
112 * Dumps always skip the first CLBYTES of disk space
113 * in case there might be a disk label stored there.
114 * If there is extra space, put dump at the end to
115 * reduce the chance that swapping trashes it.
116 */
117
118 void
119 cpu_dumpconf()
120 {
121 int nblks; /* size of dump area */
122 int maj;
123
124 if (dumpdev == NODEV)
125 return;
126 maj = major(dumpdev);
127 if (maj < 0 || maj >= nblkdev)
128 panic("dumpconf: bad dumpdev=0x%x", dumpdev);
129 if (bdevsw[maj].d_psize == NULL)
130 return;
131 nblks = (*bdevsw[maj].d_psize)(dumpdev);
132 if (nblks <= ctod(1))
133 return;
134
135 dumpsize = physmem;
136
137 /* Always skip the first CLBYTES, in case there is a label there. */
138 if (dumplo < ctod(1))
139 dumplo = ctod(1);
140
141 /* Put dump at end of partition, and make it fit. */
142 if (dumpsize > dtoc(nblks - dumplo))
143 dumpsize = dtoc(nblks - dumplo);
144 if (dumplo < nblks - ctod(dumpsize))
145 dumplo = nblks - ctod(dumpsize);
146 }
147
148 /* This should be moved to machdep.c */
149
150 extern pagehook_t page_hook0;
151
152 /*
153 * Doadump comes here after turning off memory management and
154 * getting on the dump stack, either when called above, or by
155 * the auto-restart code.
156 */
157
158 void
159 dumpsys()
160 {
161 daddr_t blkno;
162 int psize;
163 int error;
164 int addr;
165 int block;
166 int len;
167 vaddr_t dumpspace;
168
169 /* Save registers. */
170 savectx(&dumppcb);
171
172 if (dumpdev == NODEV)
173 return;
174 if (dumpsize == 0) {
175 cpu_dumpconf();
176 if (dumpsize == 0)
177 return;
178 }
179 if (dumplo <= 0) {
180 printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
181 minor(dumpdev));
182 return;
183 }
184 printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
185 minor(dumpdev), dumplo);
186
187 blkno = dumplo;
188 dumpspace = page_hook0.va;
189
190 psize = (*bdevsw[major(dumpdev)].d_psize)(dumpdev);
191 printf("dump ");
192 if (psize == -1) {
193 printf("area unavailable\n");
194 return;
195 }
196
197 error = 0;
198 len = 0;
199
200 for (block = 0; block < bootconfig.dramblocks && error == 0; ++block) {
201 addr = bootconfig.dram[block].address;
202 for (;addr < (bootconfig.dram[block].address
203 + (bootconfig.dram[block].pages * NBPG)); addr += NBPG) {
204 if ((len % (1024*1024)) == 0)
205 printf("%d ", len / (1024*1024));
206 pmap_map(dumpspace, addr, addr + NBPG, VM_PROT_READ);
207 error = (*bdevsw[major(dumpdev)].d_dump)(dumpdev,
208 blkno, (caddr_t) dumpspace, NBPG);
209 if (error) break;
210 blkno += btodb(NBPG);
211 len += NBPG;
212 }
213 }
214
215 switch (error) {
216 case ENXIO:
217 printf("device bad\n");
218 break;
219
220 case EFAULT:
221 printf("device not ready\n");
222 break;
223
224 case EINVAL:
225 printf("area improper\n");
226 break;
227
228 case EIO:
229 printf("i/o error\n");
230 break;
231
232 case EINTR:
233 printf("aborted from console\n");
234 break;
235
236 default:
237 printf("succeeded\n");
238 break;
239 }
240 printf("\n\n");
241 delay(1000000);
242 }
243
244 /* This is interrupt / SPL related */
245
246 int current_spl_level = _SPL_HIGH;
247 u_int spl_masks[_SPL_LEVELS + 1];
248 u_int spl_smasks[_SPL_LEVELS];
249 int safepri = _SPL_0;
250
251 void
252 set_spl_masks()
253 {
254 int loop;
255
256 for (loop = 0; loop < _SPL_LEVELS; ++loop) {
257 spl_masks[loop] = 0xffffffff;
258 spl_smasks[loop] = 0;
259 }
260
261 spl_masks[_SPL_BIO] = irqmasks[IPL_BIO];
262 spl_masks[_SPL_NET] = irqmasks[IPL_NET];
263 spl_masks[_SPL_SOFTSERIAL] = irqmasks[IPL_TTY];
264 spl_masks[_SPL_TTY] = irqmasks[IPL_TTY];
265 spl_masks[_SPL_IMP] = irqmasks[IPL_IMP];
266 spl_masks[_SPL_AUDIO] = irqmasks[IPL_AUDIO];
267 spl_masks[_SPL_CLOCK] = irqmasks[IPL_CLOCK];
268 spl_masks[_SPL_HIGH] = irqmasks[IPL_HIGH];
269 spl_masks[_SPL_SERIAL] = irqmasks[IPL_SERIAL];
270 spl_masks[_SPL_LEVELS] = 0;
271
272 spl_smasks[_SPL_0] = 0xffffffff;
273 for (loop = 0; loop < _SPL_SOFTSERIAL; ++loop)
274 spl_smasks[loop] |= SOFTIRQ_BIT(SOFTIRQ_SERIAL);
275 for (loop = 0; loop < _SPL_SOFTNET; ++loop)
276 spl_smasks[loop] |= SOFTIRQ_BIT(SOFTIRQ_NET);
277 for (loop = 0; loop < _SPL_SOFTCLOCK; ++loop)
278 spl_smasks[loop] |= SOFTIRQ_BIT(SOFTIRQ_CLOCK);
279 }
280
281 #ifdef DIAGNOSTIC
282 void
283 dump_spl_masks()
284 {
285 int loop;
286
287 for (loop = 0; loop < _SPL_LEVELS; ++loop) {
288 printf("spl_mask[%d]=%08x splsmask[%d]=%08x\n", loop,
289 spl_masks[loop], loop, spl_smasks[loop]);
290 }
291 }
292 #endif
293
294 /* End of stubs.c */
295