1 /* $NetBSD: stubs.c,v 1.21 2009/03/15 22:20:10 cegger Exp $ */
4 * Copyright (c) 1994-1998 Mark Brinicombe.
5 * Copyright (c) 1994 Brini.
8 * This code is derived from software written for Brini by Mark Brinicombe
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
38 * Routines that are temporary or do not have a home yet.
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: stubs.c,v 1.21 2009/03/15 22:20:10 cegger Exp $");
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/errno.h>
51 #include <sys/msgbuf.h>
52 #include <uvm/uvm_extern.h>
53 #include <machine/cpu.h>
54 #include <machine/intr.h>
55 #include <machine/bootconfig.h>
56 #include <machine/pcb.h>
57 #include <arm/arm32/machdep.h>
58 #include <arm/kcore.h>
59 #include <sys/kcore.h>
61 #include <sys/exec_aout.h>
66 int cpu_dumpsize(void);
67 u_long
cpu_dump_mempagecnt(void);
70 * These variables are needed by /sbin/savecore
72 u_int32_t dumpmag
= 0x8fca0101; /* magic number */
73 int dumpsize
= 0; /* pages */
74 long dumplo
= 0; /* blocks */
79 * This is called by main to set dumplo and dumpsize.
80 * Dumps always skip the first PAGE_SIZE of disk space
81 * in case there might be a disk label stored there.
82 * If there is extra space, put dump at the end to
83 * reduce the chance that swapping trashes it.
89 const struct bdevsw
*bdev
;
90 int nblks
, dumpblks
; /* size of dump area */
94 bdev
= bdevsw_lookup(dumpdev
);
96 panic("dumpconf: bad dumpdev=0x%"PRIx64
"", dumpdev
);
97 if (bdev
->d_psize
== NULL
)
99 nblks
= (*bdev
->d_psize
)(dumpdev
);
100 if (nblks
<= ctod(1))
103 dumpblks
= cpu_dumpsize();
106 dumpblks
+= ctod(cpu_dump_mempagecnt());
108 /* If dump won't fit (incl. room for possible label), punt. */
109 if (dumpblks
> (nblks
- ctod(1)))
112 /* Put dump at end of partition */
113 dumplo
= nblks
- dumpblks
;
115 /* dumpsize is in page units, and doesn't include headers. */
116 dumpsize
= cpu_dump_mempagecnt();
124 * cpu_dump: dump the machine-dependent kernel core dump headers.
129 int (*dump
)(dev_t
, daddr_t
, void *, size_t);
132 cpu_kcore_hdr_t
*cpuhdrp
;
133 phys_ram_seg_t
*memsegp
;
134 const struct bdevsw
*bdev
;
137 bdev
= bdevsw_lookup(dumpdev
);
142 memset(bf
, 0, sizeof bf
);
143 segp
= (kcore_seg_t
*)bf
;
144 cpuhdrp
= (cpu_kcore_hdr_t
*)&bf
[ALIGN(sizeof(*segp
))];
145 memsegp
= (phys_ram_seg_t
*)&bf
[ ALIGN(sizeof(*segp
)) +
146 ALIGN(sizeof(*cpuhdrp
))];
149 * Generate a segment header.
151 CORE_SETMAGIC(*segp
, KCORE_MAGIC
, MID_MACHINE
, CORE_CPU
);
152 segp
->c_size
= dbtob(1) - ALIGN(sizeof(*segp
));
155 * Add the machine-dependent header info.
157 cpuhdrp
->version
= 1;
158 cpuhdrp
->PAKernelL1Table
= pmap_kernel_L1_addr();
159 cpuhdrp
->UserL1TableSize
= 0;
160 cpuhdrp
->nmemsegs
= bootconfig
.dramblocks
;
161 cpuhdrp
->omemsegs
= ALIGN(sizeof(*cpuhdrp
));
164 * Fill in the memory segment descriptors.
166 for (i
= 0; i
< bootconfig
.dramblocks
; i
++) {
167 memsegp
[i
].start
= bootconfig
.dram
[i
].address
;
168 memsegp
[i
].size
= bootconfig
.dram
[i
].pages
* PAGE_SIZE
;
171 return (dump(dumpdev
, dumplo
, bf
, dbtob(1)));
175 * cpu_dumpsize: calculate size of machine-dependent kernel core dump headers.
182 size
= ALIGN(sizeof(kcore_seg_t
)) + ALIGN(sizeof(cpu_kcore_hdr_t
)) +
183 ALIGN( bootconfig
.dramblocks
* sizeof(phys_ram_seg_t
));
184 if (roundup(size
, dbtob(1)) != dbtob(1))
192 * cpu_dump_mempagecnt: calculate the size of RAM (in pages) to be dumped.
195 cpu_dump_mempagecnt(void)
200 for (i
= 0; i
< bootconfig
.dramblocks
; i
++) {
201 n
+= bootconfig
.dram
[i
].pages
;
207 /* This should be moved to machdep.c */
209 extern vaddr_t memhook
; /* XXX */
212 * Doadump comes here after turning off memory management and
213 * getting on the dump stack, either when called above, or by
214 * the auto-restart code.
216 void dodumpsys(void);
221 const struct bdevsw
*bdev
;
230 /* flush everything out of caches */
231 cpu_dcache_wbinv_all();
233 if (dumpdev
== NODEV
)
238 if (dumplo
<= 0 || dumpsize
== 0) {
239 printf("\ndump to dev %u,%u not possible\n",
240 major(dumpdev
), minor(dumpdev
));
244 printf("\ndumping to dev %u,%u offset %ld\n",
245 major(dumpdev
), minor(dumpdev
), dumplo
);
248 bdev
= bdevsw_lookup(dumpdev
);
249 if (bdev
== NULL
|| bdev
->d_psize
== NULL
)
251 psize
= (*bdev
->d_psize
)(dumpdev
);
254 printf("area unavailable\n");
258 if ((error
= cpu_dump()) != 0)
261 blkno
= dumplo
+ cpu_dumpsize();
266 for (block
= 0; block
< bootconfig
.dramblocks
&& error
== 0; ++block
) {
267 addr
= bootconfig
.dram
[block
].address
;
268 for (;addr
< (bootconfig
.dram
[block
].address
269 + (bootconfig
.dram
[block
].pages
* PAGE_SIZE
));
271 if ((len
% (1024*1024)) == 0)
272 printf("%d ", len
/ (1024*1024));
274 pmap_kenter_pa(dumpspace
, addr
, VM_PROT_READ
, 0);
275 pmap_update(pmap_kernel());
276 error
= (*bdev
->d_dump
)(dumpdev
,
277 blkno
, (void *) dumpspace
, PAGE_SIZE
);
280 blkno
+= btodb(PAGE_SIZE
);
287 printf("device bad\n");
291 printf("device not ready\n");
295 printf("area improper\n");
299 printf("i/o error\n");
303 printf("aborted from console\n");
307 printf("succeeded\n");
311 printf("error %d\n", error
);