1 /* $NetBSD: core_machdep.c,v 1.11 2021/07/04 22:42:35 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
31
32 __KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.11 2021/07/04 22:42:35 thorpej Exp $");
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/proc.h>
37 #include <sys/buf.h>
38 #include <sys/vnode.h>
39 #include <sys/core.h>
40 #include <sys/exec.h>
41 #include <sys/compat_stub.h>
42
43 #include <sys/exec_aout.h>
44
45 #include <machine/cpu.h>
46 #include <machine/alpha.h>
47 #include <machine/pmap.h>
48 #include <machine/reg.h>
49
50 /*
51 * Dump the machine specific header information at the start of a core dump.
52 */
53 int
cpu_coredump(struct lwp * l,struct coredump_iostate * iocookie,struct core * chdr)54 cpu_coredump(struct lwp *l, struct coredump_iostate *iocookie,
55 struct core *chdr)
56 {
57 int error;
58 struct md_coredump cpustate;
59 struct coreseg cseg;
60
61 if (iocookie == NULL) {
62 CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
63 chdr->c_hdrsize = ALIGN(sizeof(*chdr));
64 chdr->c_seghdrsize = ALIGN(sizeof(cseg));
65 chdr->c_cpusize = sizeof(cpustate);
66 chdr->c_nseg++;
67 return 0;
68 }
69
70 pcu_save_all(l);
71 cpustate.md_tf = *l->l_md.md_tf;
72 cpustate.md_tf.tf_regs[FRAME_SP] = alpha_pal_rdusp(); /* XXX */
73 if (fpu_valid_p(l)) {
74 cpustate.md_fpstate = ((struct pcb *)lwp_getpcb(l))->pcb_fp;
75 } else
76 memset(&cpustate.md_fpstate, 0, sizeof(cpustate.md_fpstate));
77
78 CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
79 cseg.c_addr = 0;
80 cseg.c_size = chdr->c_cpusize;
81
82 MODULE_HOOK_CALL(coredump_write_hook, (iocookie, UIO_SYSSPACE, &cseg,
83 chdr->c_seghdrsize), ENOSYS, error);
84 if (error)
85 return error;
86
87 MODULE_HOOK_CALL(coredump_write_hook, (iocookie, UIO_SYSSPACE,
88 &cpustate, sizeof(cpustate)), ENOSYS, error);
89
90 return error;
91 }
92