Home | History | Annotate | Line # | Download | only in sparc
      1 /*	$NetBSD: core_machdep.c,v 1.9 2023/12/20 05:33:19 thorpej Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1996
      5  *	The President and Fellows of Harvard College. All rights reserved.
      6  * Copyright (c) 1992, 1993
      7  *	The Regents of the University of California.  All rights reserved.
      8  *
      9  * This software was developed by the Computer Systems Engineering group
     10  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     11  * contributed to Berkeley.
     12  *
     13  * All advertising materials mentioning features or use of this software
     14  * must display the following acknowledgement:
     15  *	This product includes software developed by the University of
     16  *	California, Lawrence Berkeley Laboratory.
     17  *	This product includes software developed by Harvard University.
     18  *
     19  * Redistribution and use in source and binary forms, with or without
     20  * modification, are permitted provided that the following conditions
     21  * are met:
     22  * 1. Redistributions of source code must retain the above copyright
     23  *    notice, this list of conditions and the following disclaimer.
     24  * 2. Redistributions in binary form must reproduce the above copyright
     25  *    notice, this list of conditions and the following disclaimer in the
     26  *    documentation and/or other materials provided with the distribution.
     27  * 3. All advertising materials mentioning features or use of this software
     28  *    must display the following acknowledgement:
     29  *	This product includes software developed by Harvard University.
     30  *	This product includes software developed by the University of
     31  *	California, Berkeley and its contributors.
     32  * 4. Neither the name of the University nor the names of its contributors
     33  *    may be used to endorse or promote products derived from this software
     34  *    without specific prior written permission.
     35  *
     36  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     37  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     38  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     39  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     40  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     41  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     42  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     43  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     44  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     45  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     46  * SUCH DAMAGE.
     47  *
     48  *	@(#)vm_machdep.c	8.2 (Berkeley) 9/23/93
     49  */
     50 
     51 #include <sys/cdefs.h>
     52 __KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.9 2023/12/20 05:33:19 thorpej Exp $");
     53 
     54 #include <sys/param.h>
     55 #include <sys/systm.h>
     56 #include <sys/proc.h>
     57 #include <sys/core.h>
     58 #include <sys/buf.h>
     59 #include <sys/exec.h>
     60 #include <sys/vnode.h>
     61 #include <sys/compat_stub.h>
     62 
     63 #include <sys/exec_aout.h>
     64 
     65 #include <uvm/uvm_extern.h>
     66 
     67 #include <machine/cpu.h>
     68 #include <machine/frame.h>
     69 #include <machine/pcb.h>
     70 #include <machine/trap.h>
     71 
     72 #include <sparc/sparc/cpuvar.h>
     73 
     74 /*
     75  * cpu_coredump is called to write a core dump header.
     76  */
     77 int
     78 cpu_coredump(struct lwp *l, struct coredump_iostate *iocookie,
     79     struct core *chdr)
     80 {
     81 	int error;
     82 	struct md_coredump md_core;
     83 	struct coreseg cseg;
     84 
     85 	if (iocookie == NULL) {
     86 		CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
     87 		chdr->c_hdrsize = ALIGN(sizeof(*chdr));
     88 		chdr->c_seghdrsize = ALIGN(sizeof(cseg));
     89 		chdr->c_cpusize = sizeof(md_core);
     90 		chdr->c_nseg++;
     91 		return 0;
     92 	}
     93 
     94 	md_core.md_tf = *l->l_md.md_tf;
     95 	if (l->l_md.md_fpstate) {
     96 		if (l == cpuinfo.fplwp)
     97 			savefpstate(l->l_md.md_fpstate);
     98 		md_core.md_fpstate = *l->l_md.md_fpstate;
     99 	} else
    100 		memset((void *)&md_core.md_fpstate, 0, sizeof(struct fpstate));
    101 
    102 	CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
    103 	cseg.c_addr = 0;
    104 	cseg.c_size = chdr->c_cpusize;
    105 
    106 	MODULE_HOOK_CALL(coredump_write_hook, (iocookie, UIO_SYSSPACE, &cseg,
    107 	    chdr->c_seghdrsize), ENOSYS, error);
    108 	if (error)
    109 		return error;
    110 
    111 	MODULE_HOOK_CALL(coredump_write_hook, (iocookie, UIO_SYSSPACE, &md_core,
    112 	    sizeof(md_core)), ENOSYS, error);
    113 
    114 	return error;
    115 }
    116