xref: /netbsd/sys/arch/sh3/sh3/core_machdep.c (revision 6550d01e)
1 /*	$NetBSD: core_machdep.c,v 1.4 2011/01/27 00:19:27 uwe Exp $	*/
2 
3 /*-
4  * Copyright (c) 2002 The NetBSD Foundation, Inc. All rights reserved.
5  * Copyright (c) 1982, 1986 The Regents of the University of California.
6  * 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 William Jolitz.
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  *	@(#)vm_machdep.c	7.3 (Berkeley) 5/13/91
37  */
38 
39 /*-
40  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
41  * Copyright (c) 1989, 1990 William Jolitz
42  * All rights reserved.
43  *
44  * This code is derived from software contributed to Berkeley by
45  * the Systems Programming Group of the University of Utah Computer
46  * Science Department, and William Jolitz.
47  *
48  * Redistribution and use in source and binary forms, with or without
49  * modification, are permitted provided that the following conditions
50  * are met:
51  * 1. Redistributions of source code must retain the above copyright
52  *    notice, this list of conditions and the following disclaimer.
53  * 2. Redistributions in binary form must reproduce the above copyright
54  *    notice, this list of conditions and the following disclaimer in the
55  *    documentation and/or other materials provided with the distribution.
56  * 3. All advertising materials mentioning features or use of this software
57  *    must display the following acknowledgement:
58  *	This product includes software developed by the University of
59  *	California, Berkeley and its contributors.
60  * 4. Neither the name of the University nor the names of its contributors
61  *    may be used to endorse or promote products derived from this software
62  *    without specific prior written permission.
63  *
64  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
65  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
68  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74  * SUCH DAMAGE.
75  *
76  *	@(#)vm_machdep.c	7.3 (Berkeley) 5/13/91
77  */
78 
79 /*
80  *	Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$
81  */
82 
83 #include <sys/cdefs.h>
84 __KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.4 2011/01/27 00:19:27 uwe Exp $");
85 
86 #include <sys/param.h>
87 #include <sys/systm.h>
88 #include <sys/proc.h>
89 #include <sys/core.h>
90 #include <sys/exec.h>
91 #include <sys/ptrace.h>
92 
93 #include <sh3/reg.h>
94 
95 
96 /*
97  * Dump the machine specific segment at the start of a core dump.
98  */
99 struct md_core {
100 	struct reg intreg;
101 };
102 
103 int
104 cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
105 {
106 	struct md_core md_core;
107 	struct coreseg cseg;
108 	int error;
109 
110 	if (iocookie == NULL) {
111 		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
112 		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
113 		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
114 		chdr->c_cpusize = sizeof(md_core);
115 		chdr->c_nseg++;
116 		return 0;
117 	}
118 
119 	/* Save integer registers. */
120 	error = process_read_regs(l, &md_core.intreg);
121 	if (error)
122 		return error;
123 
124 	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
125 	cseg.c_addr = 0;
126 	cseg.c_size = chdr->c_cpusize;
127 
128 	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
129 	    chdr->c_seghdrsize);
130 	if (error)
131 		return error;
132 
133 	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
134 	    sizeof(md_core));
135 }
136