xref: /netbsd-src/sys/arch/mips/mips/core_machdep.c (revision aec6f0cf2ee0e8ce1a23f9d46109cdee745ca66f)
1 /*	$NetBSD: core_machdep.c,v 1.10 2022/09/29 07:00:46 skrll Exp $	*/
2 
3 /*
4  * Copyright (c) 1988 University of Utah.
5  * Copyright (c) 1992, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * the Systems Programming Group of the University of Utah Computer
10  * Science Department and Ralph Campbell.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  * from: Utah Hdr: vm_machdep.c 1.21 91/04/06
37  *
38  *	@(#)vm_machdep.c	8.3 (Berkeley) 1/4/94
39  */
40 
41 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
42 __KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.10 2022/09/29 07:00:46 skrll Exp $");
43 
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/proc.h>
47 #include <sys/buf.h>
48 #include <sys/vnode.h>
49 #include <sys/core.h>
50 #include <sys/exec.h>
51 #include <sys/cpu.h>
52 #include <sys/compat_stub.h>
53 
54 #include <uvm/uvm_extern.h>
55 
56 #include <mips/locore.h>
57 #include <mips/pcb.h>
58 #include <mips/cache.h>
59 #include <mips/regnum.h>
60 #include <mips/pte.h>
61 #include <mips/psl.h>
62 
63 /*
64  * Dump the machine specific segment at the start of a core dump.
65  */
66 int
cpu_coredump(struct lwp * l,struct coredump_iostate * iocookie,struct core * chdr)67 cpu_coredump(struct lwp *l, struct coredump_iostate *iocookie,
68     struct core *chdr)
69 {
70 	int error;
71 	struct coreseg cseg;
72 	struct cpustate {
73 		struct trapframe tf;
74 		struct fpreg fpregs;
75 	} cpustate;
76 
77 	if (iocookie == NULL) {
78 		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
79 		chdr->c_hdrsize = ALIGN(sizeof(struct core));
80 		chdr->c_seghdrsize = ALIGN(sizeof(struct coreseg));
81 		chdr->c_cpusize = sizeof(struct cpustate);
82 		chdr->c_nseg++;
83 		return 0;
84 	}
85 
86 	pcu_save_all(l);
87 	cpustate.tf = *l->l_md.md_utf;
88 	cpustate.fpregs = ((struct pcb *)lwp_getpcb(l))->pcb_fpregs;
89 
90 	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
91 	cseg.c_addr = 0;
92 	cseg.c_size = chdr->c_cpusize;
93 
94 	MODULE_HOOK_CALL(coredump_write_hook, (iocookie, UIO_SYSSPACE, &cseg,
95 	    chdr->c_seghdrsize), ENOSYS, error);
96 	if (error)
97 		return error;
98 
99 	MODULE_HOOK_CALL(coredump_write_hook, (iocookie, UIO_SYSSPACE,
100 	    &cpustate, chdr->c_cpusize), ENOSYS, error);
101 
102 	return error;
103 }
104