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.
30 #include <sys/param.h>
31 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/kerneldump.h>
38 #include <vm/vm_param.h>
41 #include <machine/metadata.h>
42 #include <machine/kerneldump.h>
43 #include <machine/ofw_mem.h>
44 #include <machine/tte.h>
45 #include <machine/tsb.h>
48 CTASSERT(sizeof(struct kerneldumpheader) == DEV_BSIZE);
50 static struct kerneldumpheader kdh;
51 static off_t dumplo, dumppos;
53 /* Handle buffered writes. */
54 static char buffer[DEV_BSIZE];
55 static vm_size_t fragsz;
57 #define MAXDUMPSZ (MAXDUMPPGS << PAGE_SHIFT)
60 buf_write(struct dumperinfo *di, char *ptr, size_t sz)
66 len = DEV_BSIZE - fragsz;
69 bcopy(ptr, buffer + fragsz, len);
73 if (fragsz == DEV_BSIZE) {
74 error = dump_write(di, buffer, 0, dumplo,
87 buf_flush(struct dumperinfo *di)
94 error = dump_write(di, buffer, 0, dumplo, DEV_BSIZE);
100 reg_write(struct dumperinfo *di, vm_paddr_t pa, vm_size_t size)
102 struct sparc64_dump_reg r;
108 return (buf_write(di, (char *)&r, sizeof(r)));
112 blk_dump(struct dumperinfo *di, vm_paddr_t pa, vm_size_t size)
116 int c, counter, error, twiddle;
118 printf(" chunk at %#lx: %ld bytes ", (u_long)pa, (long)size);
121 error = counter = twiddle = 0;
122 for (pos = 0; pos < size; pos += MAXDUMPSZ, counter++) {
123 if (counter % 128 == 0)
124 printf("%c\b", "|/-\\"[twiddle++ & 3]);
126 rsz = (rsz > MAXDUMPSZ) ? MAXDUMPSZ : rsz;
128 va = TLB_PHYS_TO_DIRECT(pa + pos);
130 error = dump_write(di, (void *)va, 0, dumplo, rsz);
135 /* Check for user abort. */
140 printf("(CTRL-C to abort) ");
142 printf("... %s\n", (error) ? "fail" : "ok");
147 dumpsys(struct dumperinfo *di)
149 struct sparc64_dump_hdr hdr;
150 vm_size_t size, totsize, hdrsize;
153 /* Calculate dump size. */
155 nreg = sparc64_nmemreg;
156 for (i = 0; i < sparc64_nmemreg; i++)
157 size += sparc64_memreg[i].mr_size;
158 /* Account for the header size. */
159 hdrsize = roundup2(sizeof(hdr) + sizeof(struct sparc64_dump_reg) * nreg,
163 totsize = size + 2 * sizeof(kdh);
164 if (totsize > di->mediasize) {
165 printf("Insufficient space on device (need %ld, have %ld), "
166 "refusing to dump.\n", (long)totsize,
167 (long)di->mediasize);
172 /* Determine dump offset on device. */
173 dumplo = di->mediaoffset + di->mediasize - totsize;
175 mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_SPARC64_VERSION, size, di->blocksize);
177 printf("Dumping %lu MB (%d chunks)\n", (u_long)(size >> 20), nreg);
180 error = dump_write(di, &kdh, 0, dumplo, sizeof(kdh));
183 dumplo += sizeof(kdh);
185 /* Dump the private header. */
186 hdr.dh_hdr_size = hdrsize;
188 /* XXX SUN4V_FIXME */
189 hdr.dh_tsb_pa = tsb_kernel_phys;
190 hdr.dh_tsb_size = tsb_kernel_size;
192 hdr.dh_nregions = nreg;
194 if (buf_write(di, (char *)&hdr, sizeof(hdr)) != 0)
198 /* Now, write out the region descriptors. */
199 for (i = 0; i < sparc64_nmemreg; i++) {
200 error = reg_write(di, sparc64_memreg[i].mr_start,
201 sparc64_memreg[i].mr_size);
207 /* Dump memory chunks. */
208 for (i = 0; i < sparc64_nmemreg; i++) {
209 error = blk_dump(di, sparc64_memreg[i].mr_start,
210 sparc64_memreg[i].mr_size);
216 error = dump_write(di, &kdh, 0, dumplo, sizeof(kdh));
220 /* Signal completion, signoff and exit stage left. */
221 dump_write(di, NULL, 0, 0, 0);
222 printf("\nDump complete\n");
226 /* XXX It should look more like VMS :-) */
227 printf("** DUMP FAILED (ERROR %d) **\n", error);