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