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 */
52int
53cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr)
54{
55	struct md_coredump md_core;
56	struct coreseg cseg;
57	int error;
58
59	if (iocookie == NULL) {
60		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
61		chdr->c_hdrsize = sizeof(struct core);
62		chdr->c_seghdrsize = sizeof(struct coreseg);
63		chdr->c_cpusize = sizeof(struct md_coredump);
64		chdr->c_nseg++;
65		return 0;
66	}
67
68	md_core.md_tf = *l->l_md.md_utf;	/*XXX*/
69
70	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
71	cseg.c_addr = 0;
72	cseg.c_size = chdr->c_cpusize;
73
74	error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
75	    chdr->c_seghdrsize);
76	if (error)
77		return error;
78
79	return coredump_write(iocookie, UIO_SYSSPACE, &md_core,
80	    sizeof(md_core));
81}
82