From 8e69ce0726eacc9d39d7fc4519b23892a5440443 Mon Sep 17 00:00:00 2001 From: yamt Date: Fri, 25 May 2007 15:09:50 +0000 Subject: [PATCH] dumpsys: build a fake switchframe for postmortem debugging. reviewed by Frank van der Linden. --- sys/arch/amd64/amd64/locore.S | 22 +++++++++++++++++++++- sys/arch/amd64/amd64/machdep.c | 10 ++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/sys/arch/amd64/amd64/locore.S b/sys/arch/amd64/amd64/locore.S index 2409371f68f0..3d84ee1a2d36 100644 --- a/sys/arch/amd64/amd64/locore.S +++ b/sys/arch/amd64/amd64/locore.S @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.24 2007/05/21 08:10:38 fvdl Exp $ */ +/* $NetBSD: locore.S,v 1.25 2007/05/25 15:09:50 yamt Exp $ */ /* * Copyright-o-rama! @@ -709,6 +709,26 @@ ENTRY(longjmp) movl $1,%eax ret +ENTRY(dumpsys) + # mimic cpu_switchto() for postmortem debugging. + + # build a fake switch frame. + pushq %rbx + pushq %r12 + pushq %r13 + pushq %r14 + pushq %r15 + + # save a context. + movq $dumppcb, %rax + movq %rsp, PCB_RSP(%rax) + movq %rbp, PCB_RBP(%rax) + + call _C_LABEL(dodumpsys) + + addq $(5*8), %rsp # sizeof(switchframe) - sizeof(%rip) + ret + /* * struct lwp *cpu_switchto(struct lwp *, struct lwp *) * diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index b174c704de1a..128485ad3d82 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.58 2007/05/21 08:10:38 fvdl Exp $ */ +/* $NetBSD: machdep.c,v 1.59 2007/05/25 15:09:50 yamt Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007 @@ -73,7 +73,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.58 2007/05/21 08:10:38 fvdl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.59 2007/05/25 15:09:50 yamt Exp $"); #include "opt_user_ldt.h" #include "opt_ddb.h" @@ -230,6 +230,7 @@ int cpu_dump(void); int cpu_dumpsize(void); u_long cpu_dump_mempagecnt(void); void dumpsys(void); +void dodumpsys(void); void init_x86_64(paddr_t); /* @@ -724,7 +725,7 @@ reserve_dumppages(vaddr_t p) } void -dumpsys(void) +dodumpsys(void) { const struct bdevsw *bdev; u_long totalbytesleft, bytes, i, n, memseg; @@ -734,9 +735,6 @@ dumpsys(void) int (*dump)(dev_t, daddr_t, void *, size_t); int error; - /* Save registers. */ - savectx(&dumppcb); - if (dumpdev == NODEV) return; bdev = bdevsw_lookup(dumpdev);