1 /* $NetBSD: core_machdep.c,v 1.3 2009/11/23 00:11:44 rmind Exp $ */ 2 3 /* 4 * Copyright (c) 1982, 1986, 1990, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * the Systems Programming Group of the University of Utah Computer 9 * Science Department. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * from: Utah $Hdr: vm_machdep.c 1.21 91/04/06$ 36 * 37 * @(#)vm_machdep.c 8.6 (Berkeley) 1/12/94 38 */ 39 /* 40 * Copyright (c) 1988 University of Utah. 41 * 42 * This code is derived from software contributed to Berkeley by 43 * the Systems Programming Group of the University of Utah Computer 44 * Science Department. 45 * 46 * Redistribution and use in source and binary forms, with or without 47 * modification, are permitted provided that the following conditions 48 * are met: 49 * 1. Redistributions of source code must retain the above copyright 50 * notice, this list of conditions and the following disclaimer. 51 * 2. Redistributions in binary form must reproduce the above copyright 52 * notice, this list of conditions and the following disclaimer in the 53 * documentation and/or other materials provided with the distribution. 54 * 3. All advertising materials mentioning features or use of this software 55 * must display the following acknowledgement: 56 * This product includes software developed by the University of 57 * California, Berkeley and its contributors. 58 * 4. Neither the name of the University nor the names of its contributors 59 * may be used to endorse or promote products derived from this software 60 * without specific prior written permission. 61 * 62 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 63 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 64 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 65 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 66 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 72 * SUCH DAMAGE. 73 * 74 * from: Utah $Hdr: vm_machdep.c 1.21 91/04/06$ 75 * 76 * @(#)vm_machdep.c 8.6 (Berkeley) 1/12/94 77 */ 78 79 #include <sys/cdefs.h> 80 __KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.3 2009/11/23 00:11:44 rmind Exp $"); 81 82 #include <sys/param.h> 83 #include <sys/systm.h> 84 #include <sys/proc.h> 85 #include <sys/malloc.h> 86 #include <sys/buf.h> 87 #include <sys/vnode.h> 88 #include <sys/core.h> 89 #include <sys/exec.h> 90 91 #include <sys/exec_aout.h> 92 93 #include <machine/frame.h> 94 #include <machine/cpu.h> 95 #include <machine/pte.h> 96 #include <machine/reg.h> 97 98 #include <uvm/uvm_extern.h> 99 100 /* 101 * Dump the machine specific header information at the start of a core dump. 102 */ 103 struct md_core { 104 struct reg intreg; 105 struct fpreg freg; 106 }; 107 108 int 109 cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr) 110 { 111 struct md_core md_core; 112 struct coreseg cseg; 113 int error; 114 115 if (iocookie == NULL) { 116 CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0); 117 chdr->c_hdrsize = ALIGN(sizeof(*chdr)); 118 chdr->c_seghdrsize = ALIGN(sizeof(cseg)); 119 chdr->c_cpusize = sizeof(md_core); 120 chdr->c_nseg++; 121 return 0; 122 } 123 124 /* Save integer registers. */ 125 error = process_read_regs(l, &md_core.intreg); 126 if (error) 127 return error; 128 129 if (fputype) { 130 /* Save floating point registers. */ 131 error = process_read_fpregs(l, &md_core.freg); 132 if (error) 133 return error; 134 } else { 135 /* Make sure these are clear. */ 136 memset((void *)&md_core.freg, 0, sizeof(md_core.freg)); 137 } 138 139 CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU); 140 cseg.c_addr = 0; 141 cseg.c_size = chdr->c_cpusize; 142 143 error = coredump_write(iocookie, UIO_SYSSPACE, &cseg, 144 chdr->c_seghdrsize); 145 if (error) 146 return error; 147 148 return coredump_write(iocookie, UIO_SYSSPACE, &md_core, 149 sizeof(md_core)); 150 } 151