From cf47b9b0c7003eec0a4c38861a986e1e85a697b9 Mon Sep 17 00:00:00 2001 From: skrll Date: Sat, 12 Jan 2008 20:50:23 +0000 Subject: [PATCH] Push a switchframe in dumpsys and cpu_switchto, but as dumpsys calls other funcs a switchframe needs to be a multiple of 8 bytes. Stash sp as well in the switchframe to bump it to 24bytes. Setup the switchframe appropriately in cpu_lwp_fork. Remove savectx - nothing uses it. All of this make gdb's life much easier when dealing with crash dumps and live kernels. Reviewd by chris. --- sys/arch/arm/arm32/cpuswitch.S | 34 ++++++------------------------ sys/arch/arm/arm32/locore.S | 13 ++++-------- sys/arch/arm/arm32/vm_machdep.c | 5 +++-- sys/arch/arm/include/arm32/frame.h | 7 ++++-- 4 files changed, 18 insertions(+), 41 deletions(-) diff --git a/sys/arch/arm/arm32/cpuswitch.S b/sys/arch/arm/arm32/cpuswitch.S index 011641b5e718..e67c78cb9dcc 100644 --- a/sys/arch/arm/arm32/cpuswitch.S +++ b/sys/arch/arm/arm32/cpuswitch.S @@ -1,4 +1,4 @@ -/* $NetBSD: cpuswitch.S,v 1.50 2007/10/17 19:53:30 garbled Exp $ */ +/* $NetBSD: cpuswitch.S,v 1.51 2008/01/12 20:50:23 skrll Exp $ */ /* * Copyright 2003 Wasabi Systems, Inc. @@ -171,7 +171,8 @@ _C_LABEL(curpcb): * r1 'struct lwp *' of the LWP to switch to */ ENTRY(cpu_switchto) - stmfd sp!, {r4-r7, lr} + mov ip, sp + stmfd sp!, {r4-r7, ip, lr} mov r6, r1 /* save new lwp */ mov r4, r0 /* save old lwp, it's the return value */ @@ -347,10 +348,10 @@ ENTRY(cpu_switchto) mov r1, r6 /* - * Pull the registers that got pushed when either savectx() or - * cpu_switchto() was called and return. + * Pull the registers that got pushed when cpu_switchto() was called, + * and return. */ - ldmfd sp!, {r4-r7, pc} + ldmfd sp, {r4-r7, sp, pc} .Lswitch_do_ras: ldr r1, [r1, #(TF_PC)] /* second ras_lookup() arg */ @@ -361,29 +362,6 @@ ENTRY(cpu_switchto) strne r0, [r1, #(TF_PC)] b .Lswitch_return - -/* LINTSTUB: Func: void savectx(struct pcb *pcb) */ -ENTRY(savectx) - /* - * r0 = pcb - */ - - /* Push registers.*/ - stmfd sp!, {r4-r7, lr} - - /* Store all the registers in the process's pcb */ -#ifndef __XSCALE__ - add r2, r0, #(PCB_R8) - stmia r2, {r8-r13} -#else - strd r8, [r0, #(PCB_R8)] - strd r10, [r0, #(PCB_R10)] - strd r12, [r0, #(PCB_R12)] -#endif - - /* Pull the regs of the stack */ - ldmfd sp!, {r4-r7, pc} - ENTRY(lwp_trampoline) bl _C_LABEL(lwp_startup) diff --git a/sys/arch/arm/arm32/locore.S b/sys/arch/arm/arm32/locore.S index e89722c1561e..b45fb703c974 100644 --- a/sys/arch/arm/arm32/locore.S +++ b/sys/arch/arm/arm32/locore.S @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.19 2008/01/01 14:06:42 chris Exp $ */ +/* $NetBSD: locore.S,v 1.20 2008/01/12 20:50:24 skrll Exp $ */ /* * Copyright (C) 1994-1997 Mark Brinicombe @@ -218,11 +218,8 @@ ENTRY_NP(abort) */ ENTRY(dumpsys) /* push registers onto stack */ - stmfd sp!, {r0-r7, lr} - - /* push the status bits onto the stack */ - mrs r0, cpsr_all - stmfd sp!, {r0} + mov ip, sp + stmfd sp!, {r4-r7, ip, lr} /* fill in dumppcb */ ldr r0, .Ldumppcb @@ -239,9 +236,7 @@ ENTRY(dumpsys) bl _C_LABEL(dodumpsys) /* unwind the stack */ - ldmfd sp!, {r0} - nop - ldmfd sp!, {r0-r7, pc} + ldmfd sp, {r4-r7, sp, pc} .Ldumppcb: .word _C_LABEL(dumppcb) diff --git a/sys/arch/arm/arm32/vm_machdep.c b/sys/arch/arm/arm32/vm_machdep.c index 2cb078415a1d..542ab0d740eb 100644 --- a/sys/arch/arm/arm32/vm_machdep.c +++ b/sys/arch/arm/arm32/vm_machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: vm_machdep.c,v 1.40 2007/10/17 19:53:31 garbled Exp $ */ +/* $NetBSD: vm_machdep.c,v 1.41 2008/01/12 20:50:24 skrll Exp $ */ /* * Copyright (c) 1994-1998 Mark Brinicombe. @@ -44,7 +44,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.40 2007/10/17 19:53:31 garbled Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.41 2008/01/12 20:50:24 skrll Exp $"); #include "opt_armfpe.h" #include "opt_pmap_debug.h" @@ -190,6 +190,7 @@ cpu_lwp_fork(struct lwp *l1, struct lwp *l2, void *stack, size_t stacksize, sf = (struct switchframe *)tf - 1; sf->sf_r4 = (u_int)func; sf->sf_r5 = (u_int)arg; + sf->sf_sp = (u_int)tf; sf->sf_pc = (u_int)lwp_trampoline; pcb->pcb_un.un_32.pcb32_sp = (u_int)sf; } diff --git a/sys/arch/arm/include/arm32/frame.h b/sys/arch/arm/include/arm32/frame.h index 8593a720a21d..2ebeeb758c92 100644 --- a/sys/arch/arm/include/arm32/frame.h +++ b/sys/arch/arm/include/arm32/frame.h @@ -1,4 +1,4 @@ -/* $NetBSD: frame.h,v 1.15 2007/03/09 19:21:58 thorpej Exp $ */ +/* $NetBSD: frame.h,v 1.16 2008/01/12 20:50:24 skrll Exp $ */ /* * Copyright (c) 1994-1997 Mark Brinicombe. @@ -81,7 +81,9 @@ struct clockframe { }; /* - * Switch frame + * Switch frame. + * + * Should be a multiple of 8 bytes for dumpsys. */ struct switchframe { @@ -89,6 +91,7 @@ struct switchframe { u_int sf_r5; u_int sf_r6; u_int sf_r7; + u_int sf_sp; u_int sf_pc; };