stubs.c revision 1.6 1 /* $NetBSD: stubs.c,v 1.6 2001/11/26 23:19:04 thorpej 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/intr.h>
52 #include <machine/bootconfig.h>
53 #include <machine/pcb.h>
54
55 extern dev_t dumpdev;
56 extern BootConfig bootconfig;
57
58 /*
59 * These variables are needed by /sbin/savecore
60 */
61 u_long dumpmag = 0x8fca0101; /* magic number */
62 int dumpsize = 0; /* pages */
63 long dumplo = 0; /* blocks */
64
65 struct pcb dumppcb;
66
67 /*
68 * This is called by main to set dumplo and dumpsize.
69 * Dumps always skip the first CLBYTES of disk space
70 * in case there might be a disk label stored there.
71 * If there is extra space, put dump at the end to
72 * reduce the chance that swapping trashes it.
73 */
74
75 void
76 cpu_dumpconf()
77 {
78 int nblks; /* size of dump area */
79 int maj;
80
81 if (dumpdev == NODEV)
82 return;
83 maj = major(dumpdev);
84 if (maj < 0 || maj >= nblkdev)
85 panic("dumpconf: bad dumpdev=0x%x", dumpdev);
86 if (bdevsw[maj].d_psize == NULL)
87 return;
88 nblks = (*bdevsw[maj].d_psize)(dumpdev);
89 if (nblks <= ctod(1))
90 return;
91
92 dumpsize = physmem;
93
94 /* Always skip the first CLBYTES, in case there is a label there. */
95 if (dumplo < ctod(1))
96 dumplo = ctod(1);
97
98 /* Put dump at end of partition, and make it fit. */
99 if (dumpsize > dtoc(nblks - dumplo))
100 dumpsize = dtoc(nblks - dumplo);
101 if (dumplo < nblks - ctod(dumpsize))
102 dumplo = nblks - ctod(dumpsize);
103 }
104
105 /* This should be moved to machdep.c */
106
107 extern pagehook_t page_hook0;
108
109 /*
110 * Doadump comes here after turning off memory management and
111 * getting on the dump stack, either when called above, or by
112 * the auto-restart code.
113 */
114
115 void
116 dumpsys()
117 {
118 daddr_t blkno;
119 int psize;
120 int error;
121 int addr;
122 int block;
123 int len;
124 vaddr_t dumpspace;
125
126 /* Save registers. */
127 savectx(&dumppcb);
128
129 if (dumpdev == NODEV)
130 return;
131 if (dumpsize == 0) {
132 cpu_dumpconf();
133 if (dumpsize == 0)
134 return;
135 }
136 if (dumplo <= 0) {
137 printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
138 minor(dumpdev));
139 return;
140 }
141 printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
142 minor(dumpdev), dumplo);
143
144 blkno = dumplo;
145 dumpspace = page_hook0.va;
146
147 psize = (*bdevsw[major(dumpdev)].d_psize)(dumpdev);
148 printf("dump ");
149 if (psize == -1) {
150 printf("area unavailable\n");
151 return;
152 }
153
154 error = 0;
155 len = 0;
156
157 for (block = 0; block < bootconfig.dramblocks && error == 0; ++block) {
158 addr = bootconfig.dram[block].address;
159 for (;addr < (bootconfig.dram[block].address
160 + (bootconfig.dram[block].pages * NBPG)); addr += NBPG) {
161 if ((len % (1024*1024)) == 0)
162 printf("%d ", len / (1024*1024));
163 pmap_map(dumpspace, addr, addr + NBPG, VM_PROT_READ);
164 error = (*bdevsw[major(dumpdev)].d_dump)(dumpdev,
165 blkno, (caddr_t) dumpspace, NBPG);
166 if (error) break;
167 blkno += btodb(NBPG);
168 len += NBPG;
169 }
170 }
171
172 switch (error) {
173 case ENXIO:
174 printf("device bad\n");
175 break;
176
177 case EFAULT:
178 printf("device not ready\n");
179 break;
180
181 case EINVAL:
182 printf("area improper\n");
183 break;
184
185 case EIO:
186 printf("i/o error\n");
187 break;
188
189 case EINTR:
190 printf("aborted from console\n");
191 break;
192
193 default:
194 printf("succeeded\n");
195 break;
196 }
197 printf("\n\n");
198 delay(1000000);
199 }
200
201 /* End of stubs.c */
202