xref: /netbsd/sys/arch/vax/vax/core_machdep.c (revision 6550d01e)
1 /*	$NetBSD: core_machdep.c,v 1.4 2010/12/14 23:44:49 matt Exp $	     */
2 
3 /*
4  * Copyright (c) 1994 Ludd, University of Lule}, Sweden.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *     This product includes software developed at Ludd, University of Lule}.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.4 2010/12/14 23:44:49 matt Exp $");
35 
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/proc.h>
39 #include <sys/exec.h>
40 #include <sys/core.h>
41 
42 #include <sys/exec_aout.h>
43 
44 #include <machine/pcb.h>
45 #include <machine/frame.h>
46 
47 /*
48  * Dump the machine specific header information at the start of a core dump.
49  * First put all regs in PCB for debugging purposes. This is not an good
50  * way to do this, but good for my purposes so far.
51  */
52 int
53 cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
54 {
55 	struct md_coredump md_core;
56 	struct coreseg cseg;
57 	struct pcb *pcb;
58 	int error;
59 
60 	if (iocookie == NULL) {
61 		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
62 		chdr->c_hdrsize = sizeof(struct core);
63 		chdr->c_seghdrsize = sizeof(struct coreseg);
64 		chdr->c_cpusize = sizeof(struct md_coredump);
65 		chdr->c_nseg++;
66 		return 0;
67 	}
68 
69 	pcb = lwp_getpcb(l);
70 	md_core.md_tf = *(struct trapframe *)pcb->framep; /*XXX*/
71 
72 	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
73 	cseg.c_addr = 0;
74 	cseg.c_size = chdr->c_cpusize;
75 
76 	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
77 	    chdr->c_seghdrsize);
78 	if (error)
79 		return error;
80 
81 	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
82 	    sizeof(md_core));
83 }
84