2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This software was developed by the Computer Systems Engineering group
6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7 * contributed to Berkeley.
9 * Redistribution and use in source and binary forms, with or without
10 * 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.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 static char sccsid[] = "@(#)md-sparc.c 8.1 (Berkeley) 6/6/93";
42 #include <sys/param.h>
48 #include <sys/sysctl.h>
49 #include <machine/vmparam.h>
58 #define offsetof(s, f) ((int)&((s *)0)->f)
62 shift_page(fd, off, ssize)
69 (void)lseek(fd, (off_t)-NBPG, SEEK_END);
70 for (; ssize > 0; ssize -= NBPG) {
71 (void)read(fd, buffer, NBPG);
72 (void)write(fd, buffer, NBPG);
73 (void)lseek(fd, (off_t)-2 * NBPG, SEEK_CUR);
78 * Fix up the core image for the sparc. We need to flush any register
79 * windows that are cached in the pcb out to the user stack.
80 * Also, we need to get the trap frame and possible floating point state
81 * from the top of the kernel stack and store it in the pcb.
87 struct kinfo_proc *ki;
89 register struct rwindow *rw;
90 register int nsaved, cc, ssize;
91 register off_t off, s;
97 * Before anything else read the trapframe. Synchronizing here
98 * is impossible if the process is running.
100 cc = kvm_read(kd, (u_long)ki->kp_proc.p_md.md_tf,
102 (void *)&tf, sizeof(tf));
104 err(1, "kvm_read: %s (reading kernel trapframe)",
106 if (cc != sizeof(tf))
107 err(1, "cannot read kernel trapframe");
110 * Write out the real trap frame.
112 off = offsetof(struct user, u_md);
113 off += offsetof(struct md_coredump, md_tf);
114 if (lseek(fd, off, SEEK_SET) == -1)
115 err(1, "lseek: %s", strerror(errno));
116 (void)write(fd, &tf, sizeof(tf));
118 if (ki->kp_proc.p_md.md_fpstate != 0) {
120 * If floating point state is present, write it out too.
121 * It comes right after the trapframe so we don't need to seek.
124 cc = kvm_read(kd, (u_long)ki->kp_proc.p_md.md_fpstate,
125 (void *)&fs, sizeof(fs));
127 err(1, "kvm_read: %s (fpu state)", kvm_geterr(kd));
128 if (cc != sizeof(fs))
129 err(1, "cannot read fpu state");
130 (void)write(fd, (char *)&fs, sizeof(fs));
135 if (lseek(fd, (off_t)offsetof(struct user, u_pcb), SEEK_SET) == -1)
136 err(1, "lseek: %s", strerror(errno));
137 cc = read(fd, (char *)&pcb, sizeof(pcb));
138 if (cc != sizeof(pcb)) {
140 err(1, "read: %s", strerror(errno));
141 err(1, "couldn't read pcb from core file");
145 * Write any unsaved windows to the appropriate stack locations.
147 nsaved = pcb.pcb_nsaved;
152 off = ctob(UPAGES + ki->kp_eproc.e_vm.vm_dsize);
153 ssize = ctob(ki->kp_eproc.e_vm.vm_ssize);
155 for (; --nsaved >= 0; ++rw) {
157 * Copy register window into appropriate stack location.
159 s = ssize - (USRSTACK - sp);
162 err(1, "cannot copy pcb windows to stack");
164 * It's possible to be missing the bottomost
165 * page because a stack page hasn't been allocated
166 * for the register save area. Shift over
167 * the stack segment by a page, and update
168 * the u-area to reflect the new stack size. YECH!
170 shift_page(fd, off, ssize);
173 ++ki->kp_eproc.e_vm.vm_ssize;
175 (off_t)offsetof(struct user, u_kproc.kp_eproc.e_vm),
178 &ki->kp_eproc.e_vm, sizeof(ki->kp_eproc.e_vm));
180 if (lseek(fd, off + s, SEEK_SET) == -1)
181 err(1, "cannot copy pcb windows to stack");
183 (void)write(fd, rw, sizeof(*rw));