#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: core_machdep.c,v 1.11 2021/07/04 22:42:35 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/buf.h>
#include <sys/vnode.h>
#include <sys/core.h>
#include <sys/exec.h>
#include <sys/compat_stub.h>
#include <sys/exec_aout.h>
#include <machine/cpu.h>
#include <machine/alpha.h>
#include <machine/pmap.h>
#include <machine/reg.h>
int
cpu_coredump(struct lwp *l, struct coredump_iostate *iocookie,
struct core *chdr)
{
int error;
struct md_coredump cpustate;
struct coreseg cseg;
if (iocookie == NULL) {
CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0);
chdr->c_hdrsize = ALIGN(sizeof(*chdr));
chdr->c_seghdrsize = ALIGN(sizeof(cseg));
chdr->c_cpusize = sizeof(cpustate);
chdr->c_nseg++;
return 0;
}
pcu_save_all(l);
cpustate.md_tf = *l->l_md.md_tf;
cpustate.md_tf.tf_regs[FRAME_SP] = alpha_pal_rdusp();
if (fpu_valid_p(l)) {
cpustate.md_fpstate = ((struct pcb *)lwp_getpcb(l))->pcb_fp;
} else
memset(&cpustate.md_fpstate, 0, sizeof(cpustate.md_fpstate));
CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
cseg.c_addr = 0;
cseg.c_size = chdr->c_cpusize;
MODULE_HOOK_CALL(coredump_write_hook, (iocookie, UIO_SYSSPACE, &cseg,
chdr->c_seghdrsize), ENOSYS, error);
if (error)
return error;
MODULE_HOOK_CALL(coredump_write_hook, (iocookie, UIO_SYSSPACE,
&cpustate, sizeof(cpustate)), ENOSYS, error);
return error;
}