xref: /netbsd/sys/arch/powerpc/powerpc/core_machdep.c (revision 6550d01e)
1 /*	$NetBSD: core_machdep.c,v 1.5 2011/01/18 01:02:55 matt Exp $	*/
2 
3 /*
4  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5  * Copyright (C) 1995, 1996 TooLs GmbH.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by TooLs GmbH.
19  * 4. The name of TooLs GmbH may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.5 2011/01/18 01:02:55 matt Exp $");
36 
37 #ifdef _KERNEL_OPT
38 #include "opt_altivec.h"
39 #include "opt_ppcarch.h"
40 #endif
41 
42 #include <sys/param.h>
43 #include <sys/core.h>
44 #include <sys/exec.h>
45 #include <sys/proc.h>
46 #include <sys/systm.h>
47 #include <sys/vnode.h>
48 
49 #include <sys/exec_aout.h>
50 
51 #include <uvm/uvm_extern.h>
52 
53 #if defined(ALTIVEC) || defined(PPC_HAVE_SPE)
54 #include <powerpc/altivec.h>
55 #endif
56 #include <machine/fpu.h>
57 #include <machine/pcb.h>
58 
59 /*
60  * Write the machine-dependent part of a core dump.
61  */
62 int
63 cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
64 {
65 	struct coreseg cseg;
66 	struct md_coredump md_core;
67 	struct pcb * const pcb = lwp_getpcb(l);
68 	int error;
69 
70 	if (iocookie == NULL) {
71 		CORE_SETMAGIC(*chdr, COREMAGIC, MID_POWERPC, 0);
72 		chdr->c_hdrsize = ALIGN(sizeof *chdr);
73 		chdr->c_seghdrsize = ALIGN(sizeof cseg);
74 		chdr->c_cpusize = sizeof md_core;
75 		chdr->c_nseg++;
76 		return 0;
77 	}
78 
79 	md_core.frame = *trapframe(l);
80 	if (l->l_md.md_flags & MDLWP_OWNFPU) {
81 #ifdef PPC_HAVE_FPU
82 		fpu_save_lwp(l, FPU_SAVE);
83 #endif
84 		md_core.fpstate = pcb->pcb_fpu;
85 	} else
86 		memset(&md_core.fpstate, 0, sizeof(md_core.fpstate));
87 
88 #if defined(ALTIVEC) || defined(PPC_HAVE_SPE)
89 	if (l->l_md.md_flags & MDLWP_OWNVEC) {
90 		vec_save_lwp(l, VEC_SAVE);
91 		md_core.vstate = pcb->pcb_vr;
92 	} else
93 #endif
94 		memset(&md_core.vstate, 0, sizeof(md_core.vstate));
95 
96 	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
97 	cseg.c_addr = 0;
98 	cseg.c_size = chdr->c_cpusize;
99 
100 	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
101 		    chdr->c_seghdrsize);
102 	if (error)
103 		return error;
104 
105 	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
106 	    sizeof(md_core));
107 }
108