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