xref: /netbsd-src/sys/arch/hppa/hppa/core_machdep.c (revision ec6aa33e7a2f3f2be898b76a82d820ece4871c14)
1 /*	$NetBSD: core_machdep.c,v 1.8 2022/09/29 06:39:59 skrll Exp $	*/
2 
3 /*	$OpenBSD: vm_machdep.c,v 1.25 2001/09/19 20:50:56 mickey Exp $	*/
4 
5 /*
6  * Copyright (c) 1999-2004 Michael Shalayeff
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
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 OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.8 2022/09/29 06:39:59 skrll Exp $");
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/proc.h>
37 #include <sys/signalvar.h>
38 #include <sys/buf.h>
39 #include <sys/vnode.h>
40 #include <sys/ptrace.h>
41 #include <sys/exec.h>
42 #include <sys/core.h>
43 #include <sys/compat_stub.h>
44 
45 #include <sys/exec_aout.h>
46 
47 #include <machine/cpufunc.h>
48 #include <machine/pmap.h>
49 #include <machine/pcb.h>
50 
51 #include <uvm/uvm.h>
52 
53 #include <hppa/hppa/machdep.h>
54 
55 /*
56  * Dump the machine specific header information at the start of a core dump.
57  */
58 int
cpu_coredump(struct lwp * l,struct coredump_iostate * iocookie,struct core * core)59 cpu_coredump(struct lwp *l, struct coredump_iostate *iocookie,
60     struct core *core)
61 {
62 	struct md_coredump md_core;
63 	struct coreseg cseg;
64 	int error;
65 
66 	if (iocookie == NULL) {
67 		CORE_SETMAGIC(*core, COREMAGIC, MID_MACHINE, 0);
68 		core->c_hdrsize = ALIGN(sizeof(*core));
69 		core->c_seghdrsize = ALIGN(sizeof(cseg));
70 		core->c_cpusize = sizeof(md_core);
71 		core->c_nseg++;
72 		return 0;
73 	}
74 
75 	error = process_read_regs(l, &md_core.md_reg);
76 	if (error)
77 		return error;
78 
79 	/* Save floating point registers. */
80 	error = process_read_fpregs(l, &md_core.md_fpreg, NULL);
81 	if (error)
82 		return error;
83 
84 	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
85 	cseg.c_addr = 0;
86 	cseg.c_size = core->c_cpusize;
87 
88 	MODULE_HOOK_CALL(coredump_write_hook, (iocookie, UIO_SYSSPACE, &cseg,
89 	    core->c_seghdrsize), ENOSYS, error);
90 	if (error)
91 		return error;
92 
93 	MODULE_HOOK_CALL(coredump_write_hook, (iocookie, UIO_SYSSPACE, &md_core,
94 	    sizeof(md_core)), ENOSYS, error);
95 
96 	return error;
97 }
98