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>
52 extern struct dump_pa dump_map[DUMPSYS_MD_PA_NPAIRS];
57 dumpsys_map_chunk(vm_paddr_t pa, size_t chunk __unused, void **va)
60 *va = (void *)TLB_PHYS_TO_DIRECT(pa);
64 reg_write(struct dumperinfo *di, vm_paddr_t pa, vm_size_t size)
66 struct sparc64_dump_reg r;
72 return (dumpsys_buf_write(di, (char *)&r, sizeof(r)));
76 dumpsys(struct dumperinfo *di)
78 static struct kerneldumpheader kdh;
79 struct sparc64_dump_hdr hdr;
80 vm_size_t size, hdrsize;
83 /* Set up dump_map and calculate dump size. */
85 nreg = sparc64_nmemreg;
86 memset(dump_map, 0, sizeof(dump_map));
87 for (i = 0; i < nreg; i++) {
88 dump_map[i].pa_start = sparc64_memreg[i].mr_start;
89 size += dump_map[i].pa_size = sparc64_memreg[i].mr_size;
91 /* Account for the header size. */
92 hdrsize = roundup2(sizeof(hdr) + sizeof(struct sparc64_dump_reg) * nreg,
96 dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_SPARC64_VERSION,
99 printf("Dumping %lu MB (%d chunks)\n", (u_long)(size >> 20), nreg);
101 error = dump_start(di, &kdh);
105 /* Dump the private header. */
106 hdr.dh_hdr_size = hdrsize;
107 hdr.dh_tsb_pa = tsb_kernel_phys;
108 hdr.dh_tsb_size = tsb_kernel_size;
109 hdr.dh_tsb_mask = tsb_kernel_mask;
110 hdr.dh_nregions = nreg;
112 if (dumpsys_buf_write(di, (char *)&hdr, sizeof(hdr)) != 0)
116 /* Now, write out the region descriptors. */
117 for (i = 0; i < nreg; i++) {
118 error = reg_write(di, sparc64_memreg[i].mr_start,
119 sparc64_memreg[i].mr_size);
123 dumpsys_buf_flush(di);
125 /* Dump memory chunks. */
126 error = dumpsys_foreach_chunk(dumpsys_cb_dumpdata, di);
130 error = dump_finish(di, &kdh);
134 printf("\nDump complete\n");
141 /* XXX It should look more like VMS :-) */
142 printf("** DUMP FAILED (ERROR %d) **\n", error);