2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2002 Marcel Moolenaar
5 * Copyright (c) 2002 Thomas Moestl
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/kerneldump.h>
41 #include <vm/vm_param.h>
44 #include <machine/dump.h>
45 #include <machine/md_var.h>
46 #include <machine/metadata.h>
47 #include <machine/kerneldump.h>
48 #include <machine/ofw_mem.h>
49 #include <machine/tsb.h>
50 #include <machine/tlb.h>
54 extern struct dump_pa dump_map[DUMPSYS_MD_PA_NPAIRS];
59 dumpsys_map_chunk(vm_paddr_t pa, size_t chunk __unused, void **va)
62 *va = (void *)TLB_PHYS_TO_DIRECT(pa);
66 reg_write(struct dumperinfo *di, vm_paddr_t pa, vm_size_t size)
68 struct sparc64_dump_reg r;
74 return (dumpsys_buf_write(di, (char *)&r, sizeof(r)));
78 dumpsys(struct dumperinfo *di)
80 static struct kerneldumpheader kdh;
81 struct sparc64_dump_hdr hdr;
82 vm_size_t size, hdrsize;
85 /* Set up dump_map and calculate dump size. */
87 nreg = sparc64_nmemreg;
88 memset(dump_map, 0, sizeof(dump_map));
89 for (i = 0; i < nreg; i++) {
90 dump_map[i].pa_start = sparc64_memreg[i].mr_start;
91 size += dump_map[i].pa_size = sparc64_memreg[i].mr_size;
93 /* Account for the header size. */
94 hdrsize = roundup2(sizeof(hdr) + sizeof(struct sparc64_dump_reg) * nreg,
98 dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_SPARC64_VERSION,
101 printf("Dumping %lu MB (%d chunks)\n", (u_long)(size >> 20), nreg);
103 error = dump_start(di, &kdh);
107 /* Dump the private header. */
108 hdr.dh_hdr_size = hdrsize;
109 hdr.dh_tsb_pa = tsb_kernel_phys;
110 hdr.dh_tsb_size = tsb_kernel_size;
111 hdr.dh_tsb_mask = tsb_kernel_mask;
112 hdr.dh_nregions = nreg;
114 if (dumpsys_buf_write(di, (char *)&hdr, sizeof(hdr)) != 0)
118 /* Now, write out the region descriptors. */
119 for (i = 0; i < nreg; i++) {
120 error = reg_write(di, sparc64_memreg[i].mr_start,
121 sparc64_memreg[i].mr_size);
125 dumpsys_buf_flush(di);
127 /* Dump memory chunks. */
128 error = dumpsys_foreach_chunk(dumpsys_cb_dumpdata, di);
132 error = dump_finish(di, &kdh);
136 printf("\nDump complete\n");
143 /* XXX It should look more like VMS :-) */
144 printf("** DUMP FAILED (ERROR %d) **\n", error);