]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sparc64/sparc64/dump_machdep.c
These are no longer a thing, remove them.
[FreeBSD/FreeBSD.git] / sys / sparc64 / sparc64 / dump_machdep.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2002 Marcel Moolenaar
5  * Copyright (c) 2002 Thomas Moestl
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
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.
17  *
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.
28  */
29
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/conf.h>
36 #include <sys/cons.h>
37 #include <sys/kernel.h>
38 #include <sys/kerneldump.h>
39
40 #include <vm/vm.h>
41 #include <vm/vm_param.h>
42 #include <vm/pmap.h>
43
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>
51
52 static off_t fileofs;
53
54 extern struct dump_pa dump_map[DUMPSYS_MD_PA_NPAIRS];
55
56 int do_minidump = 0;
57
58 void
59 dumpsys_map_chunk(vm_paddr_t pa, size_t chunk __unused, void **va)
60 {
61
62         *va = (void *)TLB_PHYS_TO_DIRECT(pa);
63 }
64
65 static int
66 reg_write(struct dumperinfo *di, vm_paddr_t pa, vm_size_t size)
67 {
68         struct sparc64_dump_reg r;
69
70         r.dr_pa = pa;
71         r.dr_size = size;
72         r.dr_offs = fileofs;
73         fileofs += size;
74         return (dumpsys_buf_write(di, (char *)&r, sizeof(r)));
75 }
76
77 int
78 dumpsys(struct dumperinfo *di)
79 {
80         static struct kerneldumpheader kdh;
81         struct sparc64_dump_hdr hdr;
82         vm_size_t size, hdrsize;
83         int error, i, nreg;
84
85         /* Set up dump_map and calculate dump size. */
86         size = 0;
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;
92         }
93         /* Account for the header size. */
94         hdrsize = roundup2(sizeof(hdr) + sizeof(struct sparc64_dump_reg) * nreg,
95             DEV_BSIZE);
96         size += hdrsize;
97
98         dump_init_header(di, &kdh, KERNELDUMPMAGIC, KERNELDUMP_SPARC64_VERSION,
99             size);
100
101         error = dump_start(di, &kdh);
102         if (error != 0)
103                 goto fail;
104
105         printf("Dumping %lu MB (%d chunks)\n", (u_long)(size >> 20), nreg);
106
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;
113
114         if (dumpsys_buf_write(di, (char *)&hdr, sizeof(hdr)) != 0)
115                 goto fail;
116
117         fileofs = hdrsize;
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);
122                 if (error != 0)
123                         goto fail;
124         }
125         dumpsys_buf_flush(di);
126
127         /* Dump memory chunks. */
128         error = dumpsys_foreach_chunk(dumpsys_cb_dumpdata, di);
129         if (error < 0)
130                 goto fail;
131
132         error = dump_finish(di, &kdh);
133         if (error != 0)
134                 goto fail;
135
136         printf("\nDump complete\n");
137         return (0);
138
139  fail:
140         if (error < 0)
141                 error = -error;
142
143         /* XXX It should look more like VMS :-) */
144         printf("** DUMP FAILED (ERROR %d) **\n", error);
145         return (error);
146 }