1/* $NetBSD: core_machdep.c,v 1.6 2011/06/13 21:32:42 matt Exp $ */ 2 3/* 4 * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University. 5 * All rights reserved. 6 * 7 * Author: Chris G. Demetriou 8 * 9 * Permission to use, copy, modify and distribute this software and 10 * its documentation is hereby granted, provided that both the copyright 11 * notice and this permission notice appear in all copies of the 12 * software, derivative works or modified versions, and any portions 13 * thereof, and that both notices appear in supporting documentation. 14 * 15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 18 * 19 * Carnegie Mellon requests users of this software to return to 20 * 21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 22 * School of Computer Science 23 * Carnegie Mellon University 24 * Pittsburgh PA 15213-3890 25 * 26 * any improvements or extensions that they make and grant Carnegie the 27 * rights to redistribute these changes. 28 */ 29 30#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 31 32__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.6 2011/06/13 21:32:42 matt Exp $"); 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/proc.h> 37#include <sys/malloc.h> 38#include <sys/buf.h> 39#include <sys/vnode.h> 40#include <sys/core.h> 41#include <sys/exec.h> 42 43#include <sys/exec_aout.h> 44 45#include <machine/cpu.h> 46#include <machine/alpha.h> 47#include <machine/pmap.h> 48#include <machine/reg.h> 49 50/* 51 * Dump the machine specific header information at the start of a core dump. 52 */ 53int 54cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr) 55{ 56 int error; 57 struct md_coredump cpustate; 58 struct coreseg cseg; 59 60 if (iocookie == NULL) { 61 CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0); 62 chdr->c_hdrsize = ALIGN(sizeof(*chdr)); 63 chdr->c_seghdrsize = ALIGN(sizeof(cseg)); 64 chdr->c_cpusize = sizeof(cpustate); 65 chdr->c_nseg++; 66 return 0; 67 } 68 69 pcu_save_all(l); 70 cpustate.md_tf = *l->l_md.md_tf; 71 cpustate.md_tf.tf_regs[FRAME_SP] = alpha_pal_rdusp(); /* XXX */ 72 if (fpu_used_p(l)) { 73 cpustate.md_fpstate = ((struct pcb *)lwp_getpcb(l))->pcb_fp; 74 } else 75 memset(&cpustate.md_fpstate, 0, sizeof(cpustate.md_fpstate)); 76 77 CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU); 78 cseg.c_addr = 0; 79 cseg.c_size = chdr->c_cpusize; 80 81 error = coredump_write(iocookie, UIO_SYSSPACE, &cseg, 82 chdr->c_seghdrsize); 83 if (error) 84 return error; 85 86 return coredump_write(iocookie, UIO_SYSSPACE, &cpustate, 87 sizeof(cpustate)); 88} 89