2 * Copyright (c) 2002 Marcel Moolenaar
3 * Copyright (c) 2002 Thomas Moestl
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/kerneldump.h>
39 #include <vm/vm_param.h>
42 #include <machine/dump.h>
43 #include <machine/md_var.h>
44 #include <machine/metadata.h>
45 #include <machine/kerneldump.h>
46 #include <machine/ofw_mem.h>
47 #include <machine/tsb.h>
48 #include <machine/tlb.h>
53 extern struct dump_pa dump_map[DUMPSYS_MD_PA_NPAIRS];
58 dumpsys_map_chunk(vm_paddr_t pa, size_t chunk __unused, void **va)
61 *va = (void *)TLB_PHYS_TO_DIRECT(pa);
65 reg_write(struct dumperinfo *di, vm_paddr_t pa, vm_size_t size)
67 struct sparc64_dump_reg r;
73 return (dumpsys_buf_write(di, (char *)&r, sizeof(r)));
77 dumpsys(struct dumperinfo *di)
79 static struct kerneldumpheader kdh;
80 struct sparc64_dump_hdr hdr;
81 vm_size_t size, totsize, hdrsize;
84 /* Set up dump_map and calculate dump size. */
86 nreg = sparc64_nmemreg;
87 memset(dump_map, 0, sizeof(dump_map));
88 for (i = 0; i < nreg; i++) {
89 dump_map[i].pa_start = sparc64_memreg[i].mr_start;
90 size += dump_map[i].pa_size = sparc64_memreg[i].mr_size;
92 /* Account for the header size. */
93 hdrsize = roundup2(sizeof(hdr) + sizeof(struct sparc64_dump_reg) * nreg,
97 totsize = size + 2 * sizeof(kdh);
98 if (totsize > di->mediasize) {
99 printf("Insufficient space on device (need %ld, have %ld), "
100 "refusing to dump.\n", (long)totsize,
101 (long)di->mediasize);
106 /* Determine dump offset on device. */
107 dumplo = di->mediaoffset + di->mediasize - totsize;
109 mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_SPARC64_VERSION, size,
112 printf("Dumping %lu MB (%d chunks)\n", (u_long)(size >> 20), nreg);
115 error = dump_write(di, &kdh, 0, dumplo, sizeof(kdh));
118 dumplo += sizeof(kdh);
120 /* Dump the private header. */
121 hdr.dh_hdr_size = hdrsize;
122 hdr.dh_tsb_pa = tsb_kernel_phys;
123 hdr.dh_tsb_size = tsb_kernel_size;
124 hdr.dh_tsb_mask = tsb_kernel_mask;
125 hdr.dh_nregions = nreg;
127 if (dumpsys_buf_write(di, (char *)&hdr, sizeof(hdr)) != 0)
131 /* Now, write out the region descriptors. */
132 for (i = 0; i < nreg; i++) {
133 error = reg_write(di, sparc64_memreg[i].mr_start,
134 sparc64_memreg[i].mr_size);
138 dumpsys_buf_flush(di);
140 /* Dump memory chunks. */
141 error = dumpsys_foreach_chunk(dumpsys_cb_dumpdata, di);
146 error = dump_write(di, &kdh, 0, dumplo, sizeof(kdh));
150 /* Signal completion, signoff and exit stage left. */
151 dump_write(di, NULL, 0, 0, 0);
152 printf("\nDump complete\n");
159 /* XXX It should look more like VMS :-) */
160 printf("** DUMP FAILED (ERROR %d) **\n", error);