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 * di->blocksize +
98 kerneldumpcrypto_dumpkeysize(di->kdc);
99 if (totsize > di->mediasize) {
100 printf("Insufficient space on device (need %ld, have %ld), "
101 "refusing to dump.\n", (long)totsize,
102 (long)di->mediasize);
107 /* Determine dump offset on device. */
108 dumplo = di->mediaoffset + di->mediasize - totsize;
110 /* Initialize kernel dump crypto. */
111 error = kerneldumpcrypto_init(di->kdc);
115 mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_SPARC64_VERSION, size,
116 kerneldumpcrypto_dumpkeysize(di->kdc), di->blocksize);
118 printf("Dumping %lu MB (%d chunks)\n", (u_long)(size >> 20), nreg);
121 error = dump_write_header(di, &kdh, 0, dumplo);
124 dumplo += di->blocksize;
127 error = dump_write_key(di, 0, dumplo);
130 dumplo += kerneldumpcrypto_dumpkeysize(di->kdc);
132 /* Dump the private header. */
133 hdr.dh_hdr_size = hdrsize;
134 hdr.dh_tsb_pa = tsb_kernel_phys;
135 hdr.dh_tsb_size = tsb_kernel_size;
136 hdr.dh_tsb_mask = tsb_kernel_mask;
137 hdr.dh_nregions = nreg;
139 if (dumpsys_buf_write(di, (char *)&hdr, sizeof(hdr)) != 0)
143 /* Now, write out the region descriptors. */
144 for (i = 0; i < nreg; i++) {
145 error = reg_write(di, sparc64_memreg[i].mr_start,
146 sparc64_memreg[i].mr_size);
150 dumpsys_buf_flush(di);
152 /* Dump memory chunks. */
153 error = dumpsys_foreach_chunk(dumpsys_cb_dumpdata, di);
158 error = dump_write_header(di, &kdh, 0, dumplo);
161 dumplo += di->blocksize;
163 /* Signal completion, signoff and exit stage left. */
164 dump_write(di, NULL, 0, 0, 0);
165 printf("\nDump complete\n");
172 /* XXX It should look more like VMS :-) */
173 printf("** DUMP FAILED (ERROR %d) **\n", error);