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/tsb.h>
45 #include <machine/tlb.h>
47 CTASSERT(sizeof(struct kerneldumpheader) == DEV_BSIZE);
49 static struct kerneldumpheader kdh;
50 static off_t dumplo, dumppos;
52 /* Handle buffered writes. */
53 static char buffer[DEV_BSIZE];
54 static vm_size_t fragsz;
56 #define MAXDUMPSZ (MAXDUMPPGS << PAGE_SHIFT)
59 buf_write(struct dumperinfo *di, char *ptr, size_t sz)
65 len = DEV_BSIZE - fragsz;
68 bcopy(ptr, buffer + fragsz, len);
72 if (fragsz == DEV_BSIZE) {
73 error = dump_write(di, buffer, 0, dumplo,
86 buf_flush(struct dumperinfo *di)
93 error = dump_write(di, buffer, 0, dumplo, DEV_BSIZE);
99 reg_write(struct dumperinfo *di, vm_paddr_t pa, vm_size_t size)
101 struct sparc64_dump_reg r;
107 return (buf_write(di, (char *)&r, sizeof(r)));
111 blk_dump(struct dumperinfo *di, vm_paddr_t pa, vm_size_t size)
115 int c, counter, error, twiddle;
117 printf(" chunk at %#lx: %ld bytes ", (u_long)pa, (long)size);
120 error = counter = twiddle = 0;
121 for (pos = 0; pos < size; pos += MAXDUMPSZ, counter++) {
122 if (counter % 128 == 0)
123 printf("%c\b", "|/-\\"[twiddle++ & 3]);
125 rsz = (rsz > MAXDUMPSZ) ? MAXDUMPSZ : rsz;
126 va = TLB_PHYS_TO_DIRECT(pa + pos);
127 error = dump_write(di, (void *)va, 0, dumplo, rsz);
132 /* Check for user abort. */
137 printf("(CTRL-C to abort) ");
139 printf("... %s\n", (error) ? "fail" : "ok");
144 dumpsys(struct dumperinfo *di)
146 struct sparc64_dump_hdr hdr;
147 vm_size_t size, totsize, hdrsize;
150 /* Calculate dump size. */
152 nreg = sparc64_nmemreg;
153 for (i = 0; i < sparc64_nmemreg; i++)
154 size += sparc64_memreg[i].mr_size;
155 /* Account for the header size. */
156 hdrsize = roundup2(sizeof(hdr) + sizeof(struct sparc64_dump_reg) * nreg,
160 totsize = size + 2 * sizeof(kdh);
161 if (totsize > di->mediasize) {
162 printf("Insufficient space on device (need %ld, have %ld), "
163 "refusing to dump.\n", (long)totsize,
164 (long)di->mediasize);
169 /* Determine dump offset on device. */
170 dumplo = di->mediaoffset + di->mediasize - totsize;
172 mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_SPARC64_VERSION, size, di->blocksize);
174 printf("Dumping %lu MB (%d chunks)\n", (u_long)(size >> 20), nreg);
177 error = dump_write(di, &kdh, 0, dumplo, sizeof(kdh));
180 dumplo += sizeof(kdh);
182 /* Dump the private header. */
183 hdr.dh_hdr_size = hdrsize;
184 hdr.dh_tsb_pa = tsb_kernel_phys;
185 hdr.dh_tsb_size = tsb_kernel_size;
186 hdr.dh_tsb_mask = tsb_kernel_mask;
187 hdr.dh_nregions = nreg;
189 if (buf_write(di, (char *)&hdr, sizeof(hdr)) != 0)
193 /* Now, write out the region descriptors. */
194 for (i = 0; i < sparc64_nmemreg; i++) {
195 error = reg_write(di, sparc64_memreg[i].mr_start,
196 sparc64_memreg[i].mr_size);
202 /* Dump memory chunks. */
203 for (i = 0; i < sparc64_nmemreg; i++) {
204 error = blk_dump(di, sparc64_memreg[i].mr_start,
205 sparc64_memreg[i].mr_size);
211 error = dump_write(di, &kdh, 0, dumplo, sizeof(kdh));
215 /* Signal completion, signoff and exit stage left. */
216 dump_write(di, NULL, 0, 0, 0);
217 printf("\nDump complete\n");
221 /* XXX It should look more like VMS :-) */
222 printf("** DUMP FAILED (ERROR %d) **\n", error);