/* * Dump the machine specific header information at the start of a core dump. * First put all regs in PCB for debugging purposes. This is not an good * way to do this, but good for my purposes so far. */ int cpu_coredump(struct lwp *l, struct coredump_iostate *iocookie, struct core *chdr) { struct md_coredump md_core; struct coreseg cseg; int error; if (iocookie == NULL) { CORE_SETMAGIC(*chdr, COREMAGIC, MID_MACHINE, 0); chdr->c_hdrsize = sizeof(struct core); chdr->c_seghdrsize = sizeof(struct coreseg); chdr->c_cpusize = sizeof(struct md_coredump); chdr->c_nseg++; return 0; } md_core.md_tf = *l->l_md.md_utf; /*XXX*/ CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU); cseg.c_addr = 0; cseg.c_size = chdr->c_cpusize; error = coredump_write(iocookie, UIO_SYSSPACE, &cseg, chdr->c_seghdrsize); if (error) return error; return coredump_write(iocookie, UIO_SYSSPACE, &md_core, sizeof(md_core)); }
static int CORENAME(coredump_writesegs_netbsd)(struct proc *p, void *iocookie, struct uvm_coredump_state *us) { struct coredump_state *cs = us->cookie; struct CORENAME(coreseg) cseg; int flag, error; if (us->start == us->realend) return (0); if (us->flags & UVM_COREDUMP_STACK) flag = CORE_STACK; else flag = CORE_DATA; /* * Set up a new core file segment. */ CORE_SETMAGIC(cseg, CORESEGMAGIC, CORE_GETMID(cs->core), flag); cseg.c_addr = us->start; cseg.c_size = us->end - us->start; error = coredump_write(iocookie, UIO_SYSSPACE, &cseg, cs->core.c_seghdrsize); if (error) return (error); return coredump_write(iocookie, UIO_USERSPACE, (void *)(vaddr_t)us->start, cseg.c_size); }
/* * 32-bit version of cpu_coredump. */ int cpu_coredump32(struct lwp *l, struct coredump_iostate *iocookie, struct core32 *chdr) { int i, error; struct md_coredump32 md_core; struct coreseg32 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(md_core); chdr->c_nseg++; return 0; } /* Fake a v8 trapframe */ md_core.md_tf.tf_psr = TSTATECCR_TO_PSR(l->l_md.md_tf->tf_tstate); md_core.md_tf.tf_pc = l->l_md.md_tf->tf_pc; md_core.md_tf.tf_npc = l->l_md.md_tf->tf_npc; md_core.md_tf.tf_y = l->l_md.md_tf->tf_y; for (i=0; i<8; i++) { md_core.md_tf.tf_global[i] = l->l_md.md_tf->tf_global[i]; md_core.md_tf.tf_out[i] = l->l_md.md_tf->tf_out[i]; } if (l->l_md.md_fpstate) { fpusave_lwp(l, true); /* Copy individual fields */ for (i=0; i<32; i++) md_core.md_fpstate.fs_regs[i] = l->l_md.md_fpstate->fs_regs[i]; md_core.md_fpstate.fs_fsr = l->l_md.md_fpstate->fs_fsr; i = md_core.md_fpstate.fs_qsize = l->l_md.md_fpstate->fs_qsize; /* Should always be zero */ while (i--) md_core.md_fpstate.fs_queue[i] = l->l_md.md_fpstate->fs_queue[i]; } else memset(&md_core.md_fpstate, 0, sizeof(md_core.md_fpstate)); CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU); cseg.c_addr = 0; cseg.c_size = chdr->c_cpusize; error = coredump_write(iocookie, UIO_SYSSPACE, &cseg, chdr->c_seghdrsize); if (error) return error; return coredump_write(iocookie, UIO_SYSSPACE, &md_core, sizeof(md_core)); }
int cpu_coredump(struct lwp *l, struct coredump_iostate *iocookie, struct core *chdr) { struct md_core md_core; struct coreseg cseg; int error; 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(md_core); chdr->c_nseg++; return 0; } /* Save integer registers. */ error = process_read_regs(l, &md_core.intreg); if (error) return error; if (fputype) { /* Save floating point registers. */ error = process_read_fpregs(l, &md_core.freg, NULL); if (error) return error; } else { /* Make sure these are clear. */ memset((void *)&md_core.freg, 0, sizeof(md_core.freg)); } CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU); cseg.c_addr = 0; cseg.c_size = chdr->c_cpusize; error = coredump_write(iocookie, UIO_SYSSPACE, &cseg, chdr->c_seghdrsize); if (error) return error; return coredump_write(iocookie, UIO_SYSSPACE, &md_core, sizeof(md_core)); }
/* * Dump the machine specific segment at the start of a core dump. */ int cpu_coredump(struct lwp *l, struct coredump_iostate *iocookie, struct core *chdr) { int error; struct { struct reg regs; struct fpreg fpregs; } 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; } /* Save integer registers. */ error = process_read_regs(l, &cpustate.regs); if (error) return error; /* Save floating point registers. */ error = process_read_fpregs(l, &cpustate.fpregs, NULL); if (error) return error; CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU); cseg.c_addr = 0; cseg.c_size = chdr->c_cpusize; error = coredump_write(iocookie, UIO_SYSSPACE, &cseg, chdr->c_seghdrsize); if (error) return error; return coredump_write(iocookie, UIO_SYSSPACE, &cpustate, sizeof(cpustate)); }
int cpu_coredump32(struct lwp *l, struct coredump_iostate *iocookie, struct core32 *chdr) { struct md_core32 md_core; struct coreseg cseg; int error; if (iocookie == NULL) { CORE_SETMAGIC(*chdr, COREMAGIC, MID_I386, 0); chdr->c_hdrsize = ALIGN32(sizeof(*chdr)); chdr->c_seghdrsize = ALIGN32(sizeof(cseg)); chdr->c_cpusize = sizeof(md_core); chdr->c_nseg++; return 0; } /* Save integer registers. */ error = netbsd32_process_read_regs(l, &md_core.intreg); if (error) return error; /* Save floating point registers. */ error = netbsd32_process_read_fpregs(l, &md_core.freg, NULL); if (error) return error; CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_I386, CORE_CPU); cseg.c_addr = 0; cseg.c_size = chdr->c_cpusize; error = coredump_write(iocookie, UIO_SYSSPACE, &cseg, chdr->c_seghdrsize); if (error) return error; return coredump_write(iocookie, UIO_SYSSPACE, &md_core, sizeof(md_core)); }
/* * Dump the machine specific header information at the start of a core dump. */ int cpu_coredump(struct lwp *l, void *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; } cpustate.md_tf = *l->l_md.md_tf; cpustate.md_tf.tf_regs[FRAME_SP] = alpha_pal_rdusp(); /* XXX */ if (l->l_md.md_flags & MDP_FPUSED) { if (l->l_addr->u_pcb.pcb_fpcpu != NULL) fpusave_proc(l, 1); cpustate.md_fpstate = l->l_addr->u_pcb.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; error = coredump_write(iocookie, UIO_SYSSPACE, &cseg, chdr->c_seghdrsize); if (error) return error; return coredump_write(iocookie, UIO_SYSSPACE, &cpustate, sizeof(cpustate)); }
int CORENAME(coredump_netbsd)(struct lwp *l, void *iocookie) { struct coredump_state cs; struct proc *p = l->l_proc; struct vmspace *vm = p->p_vmspace; int error; cs.core.c_midmag = 0; strncpy(cs.core.c_name, p->p_comm, MAXCOMLEN); cs.core.c_nseg = 0; cs.core.c_signo = p->p_sigctx.ps_signo; cs.core.c_ucode = p->p_sigctx.ps_code; cs.core.c_cpusize = 0; cs.core.c_tsize = (u_long)ctob(vm->vm_tsize); cs.core.c_dsize = (u_long)ctob(vm->vm_dsize); cs.core.c_ssize = (u_long)round_page(ctob(vm->vm_ssize)); error = CORENAME(cpu_coredump)(l, NULL, &cs.core); if (error) return (error); error = uvm_coredump_walkmap(p, NULL, CORENAME(coredump_countsegs_netbsd), &cs); if (error) return (error); /* First write out the core header. */ error = coredump_write(iocookie, UIO_SYSSPACE, &cs.core, cs.core.c_hdrsize); if (error) return (error); /* Then the CPU specific stuff */ error = CORENAME(cpu_coredump)(l, iocookie, &cs.core); if (error) return (error); /* Finally, the address space dump */ return uvm_coredump_walkmap(p, iocookie, CORENAME(coredump_writesegs_netbsd), &cs); }
/* * cpu_coredump is called to write a core dump header. */ int cpu_coredump(struct lwp *l, void *iocookie, struct core *chdr) { int error; struct md_coredump md_core; 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(md_core); chdr->c_nseg++; return 0; } /* Copy important fields over. */ md_core.md_tf.tf_tstate = l->l_md.md_tf->tf_tstate; md_core.md_tf.tf_pc = l->l_md.md_tf->tf_pc; md_core.md_tf.tf_npc = l->l_md.md_tf->tf_npc; md_core.md_tf.tf_y = l->l_md.md_tf->tf_y; md_core.md_tf.tf_tt = l->l_md.md_tf->tf_tt; md_core.md_tf.tf_pil = l->l_md.md_tf->tf_pil; md_core.md_tf.tf_oldpil = l->l_md.md_tf->tf_oldpil; md_core.md_tf.tf_global[0] = l->l_md.md_tf->tf_global[0]; md_core.md_tf.tf_global[1] = l->l_md.md_tf->tf_global[1]; md_core.md_tf.tf_global[2] = l->l_md.md_tf->tf_global[2]; md_core.md_tf.tf_global[3] = l->l_md.md_tf->tf_global[3]; md_core.md_tf.tf_global[4] = l->l_md.md_tf->tf_global[4]; md_core.md_tf.tf_global[5] = l->l_md.md_tf->tf_global[5]; md_core.md_tf.tf_global[6] = l->l_md.md_tf->tf_global[6]; md_core.md_tf.tf_global[7] = l->l_md.md_tf->tf_global[7]; md_core.md_tf.tf_out[0] = l->l_md.md_tf->tf_out[0]; md_core.md_tf.tf_out[1] = l->l_md.md_tf->tf_out[1]; md_core.md_tf.tf_out[2] = l->l_md.md_tf->tf_out[2]; md_core.md_tf.tf_out[3] = l->l_md.md_tf->tf_out[3]; md_core.md_tf.tf_out[4] = l->l_md.md_tf->tf_out[4]; md_core.md_tf.tf_out[5] = l->l_md.md_tf->tf_out[5]; md_core.md_tf.tf_out[6] = l->l_md.md_tf->tf_out[6]; md_core.md_tf.tf_out[7] = l->l_md.md_tf->tf_out[7]; #ifdef DEBUG md_core.md_tf.tf_local[0] = l->l_md.md_tf->tf_local[0]; md_core.md_tf.tf_local[1] = l->l_md.md_tf->tf_local[1]; md_core.md_tf.tf_local[2] = l->l_md.md_tf->tf_local[2]; md_core.md_tf.tf_local[3] = l->l_md.md_tf->tf_local[3]; md_core.md_tf.tf_local[4] = l->l_md.md_tf->tf_local[4]; md_core.md_tf.tf_local[5] = l->l_md.md_tf->tf_local[5]; md_core.md_tf.tf_local[6] = l->l_md.md_tf->tf_local[6]; md_core.md_tf.tf_local[7] = l->l_md.md_tf->tf_local[7]; md_core.md_tf.tf_in[0] = l->l_md.md_tf->tf_in[0]; md_core.md_tf.tf_in[1] = l->l_md.md_tf->tf_in[1]; md_core.md_tf.tf_in[2] = l->l_md.md_tf->tf_in[2]; md_core.md_tf.tf_in[3] = l->l_md.md_tf->tf_in[3]; md_core.md_tf.tf_in[4] = l->l_md.md_tf->tf_in[4]; md_core.md_tf.tf_in[5] = l->l_md.md_tf->tf_in[5]; md_core.md_tf.tf_in[6] = l->l_md.md_tf->tf_in[6]; md_core.md_tf.tf_in[7] = l->l_md.md_tf->tf_in[7]; #endif if (l->l_md.md_fpstate) { fpusave_lwp(l, true); md_core.md_fpstate = *l->l_md.md_fpstate; } else memset(&md_core.md_fpstate, 0, sizeof(md_core.md_fpstate)); CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU); cseg.c_addr = 0; cseg.c_size = chdr->c_cpusize; error = coredump_write(iocookie, UIO_SYSSPACE, &cseg, chdr->c_seghdrsize); if (error) return error; return coredump_write(iocookie, UIO_SYSSPACE, &md_core, sizeof(md_core)); }