From owner-svn-src-all@FreeBSD.ORG Fri Feb 27 12:08:25 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6D24A10656EE; Fri, 27 Feb 2009 12:08:25 +0000 (UTC) (envelope-from raj@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 570C18FC1A; Fri, 27 Feb 2009 12:08:25 +0000 (UTC) (envelope-from raj@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n1RC8Poe069906; Fri, 27 Feb 2009 12:08:25 GMT (envelope-from raj@svn.freebsd.org) Received: (from raj@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n1RC8OnP069899; Fri, 27 Feb 2009 12:08:24 GMT (envelope-from raj@svn.freebsd.org) Message-Id: <200902271208.n1RC8OnP069899@svn.freebsd.org> From: Rafal Jaworowski Date: Fri, 27 Feb 2009 12:08:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r189100 - in head/sys/powerpc: booke include powerpc X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Feb 2009 12:08:30 -0000 Author: raj Date: Fri Feb 27 12:08:24 2009 New Revision: 189100 URL: http://svn.freebsd.org/changeset/base/189100 Log: Make Book-E debug register state part of the PCB context. Previously, DBCR0 flags were set "globally", but this leads to problems because Book-E fine grained debug settings work only in conjuction with the debug master enable bit in MSR: in scenarios when the DBCR0 was set with intention to debug one process, but another one with MSR[DE] set got scheduled, the latter would immediately cause debug exceptions to occur upon execution of its own code instructions (and not the one intended for debugging). To avoid such problems and properly handle debugging context, DBCR0 state should be managed individually per process. Submitted by: Grzegorz Bernacki gjb ! semihalf dot com Reviewed by: marcel Modified: head/sys/powerpc/booke/machdep.c head/sys/powerpc/booke/swtch.S head/sys/powerpc/booke/trap.c head/sys/powerpc/booke/trap_subr.S head/sys/powerpc/include/frame.h head/sys/powerpc/include/pcb.h head/sys/powerpc/powerpc/genassym.c Modified: head/sys/powerpc/booke/machdep.c ============================================================================== --- head/sys/powerpc/booke/machdep.c Fri Feb 27 06:01:42 2009 (r189099) +++ head/sys/powerpc/booke/machdep.c Fri Feb 27 12:08:24 2009 (r189100) @@ -806,14 +806,10 @@ int ptrace_single_step(struct thread *td) { struct trapframe *tf; - u_int reg; - - reg = mfspr(SPR_DBCR0); - reg |= DBCR0_IC | DBCR0_IDM; - mtspr(SPR_DBCR0, reg); tf = td->td_frame; tf->srr1 |= PSL_DE; + tf->cpu.booke.dbcr0 |= (DBCR0_IDM | DBCR0_IC); return (0); } @@ -824,6 +820,7 @@ ptrace_clear_single_step(struct thread * tf = td->td_frame; tf->srr1 &= ~PSL_DE; + tf->cpu.booke.dbcr0 &= ~(DBCR0_IDM | DBCR0_IC); return (0); } Modified: head/sys/powerpc/booke/swtch.S ============================================================================== --- head/sys/powerpc/booke/swtch.S Fri Feb 27 06:01:42 2009 (r189099) +++ head/sys/powerpc/booke/swtch.S Fri Feb 27 12:08:24 2009 (r189100) @@ -66,6 +66,7 @@ #include #include #include +#include /* * void cpu_switch(struct thread *old, struct thread *new) @@ -87,6 +88,8 @@ ENTRY(cpu_switch) stw %r16, PCB_BOOKE_CTR(%r5) mfxer %r16 stw %r16, PCB_BOOKE_XER(%r5) + mfspr %r16, SPR_DBCR0 + stw %r16, PCB_BOOKE_DBCR0(%r5) stw %r1, PCB_SP(%r5) /* Save the stack pointer */ @@ -114,6 +117,8 @@ ENTRY(cpu_switch) mtctr %r5 lwz %r5, PCB_BOOKE_XER(%r3) mtxer %r5 + lwz %r5, PCB_BOOKE_DBCR0(%r3) + mtspr SPR_DBCR0, %r5 lwz %r1, PCB_SP(%r3) /* Load the stack pointer */ blr Modified: head/sys/powerpc/booke/trap.c ============================================================================== --- head/sys/powerpc/booke/trap.c Fri Feb 27 06:01:42 2009 (r189099) +++ head/sys/powerpc/booke/trap.c Fri Feb 27 12:08:24 2009 (r189100) @@ -187,6 +187,7 @@ trap(struct trapframe *frame) case EXC_DEBUG: /* Single stepping */ mtspr(SPR_DBSR, mfspr(SPR_DBSR)); frame->srr1 &= ~PSL_DE; + frame->cpu.booke.dbcr0 &= ~(DBCR0_IDM || DBCR0_IC); sig = SIGTRAP; break; Modified: head/sys/powerpc/booke/trap_subr.S ============================================================================== --- head/sys/powerpc/booke/trap_subr.S Fri Feb 27 06:01:42 2009 (r189099) +++ head/sys/powerpc/booke/trap_subr.S Fri Feb 27 12:08:24 2009 (r189100) @@ -207,6 +207,9 @@ stw %r4, FRAME_CTR+8(1); \ li %r5, exc; \ stw %r5, FRAME_EXC+8(1); \ + /* save DBCR0 */ \ + mfspr %r3, SPR_DBCR0; \ + stw %r3, FRAME_BOOKE_DBCR0+8(1); \ /* save xSSR0-1 */ \ lwz %r30, (savearea+CPUSAVE_SRR0)(%r2); \ lwz %r31, (savearea+CPUSAVE_SRR1)(%r2); \ @@ -231,6 +234,9 @@ mtxer %r5; \ mtlr %r6; \ mtcr %r7; \ + /* restore DBCR0 */ \ + lwz %r4, FRAME_BOOKE_DBCR0+8(%r1); \ + mtspr SPR_DBCR0, %r4; \ /* restore xSRR0-1 */ \ lwz %r30, FRAME_SRR0+8(%r1); \ lwz %r31, FRAME_SRR1+8(%r1); \ Modified: head/sys/powerpc/include/frame.h ============================================================================== --- head/sys/powerpc/include/frame.h Fri Feb 27 06:01:42 2009 (r189099) +++ head/sys/powerpc/include/frame.h Fri Feb 27 12:08:24 2009 (r189100) @@ -65,6 +65,7 @@ struct trapframe { struct { register_t dear; register_t esr; + register_t dbcr0; } booke; } cpu; }; Modified: head/sys/powerpc/include/pcb.h ============================================================================== --- head/sys/powerpc/include/pcb.h Fri Feb 27 06:01:42 2009 (r189099) +++ head/sys/powerpc/include/pcb.h Fri Feb 27 12:08:24 2009 (r189100) @@ -70,6 +70,7 @@ struct pcb { struct { register_t ctr; register_t xer; + register_t dbcr0; } booke; } pcb_cpu; }; Modified: head/sys/powerpc/powerpc/genassym.c ============================================================================== --- head/sys/powerpc/powerpc/genassym.c Fri Feb 27 06:01:42 2009 (r189099) +++ head/sys/powerpc/powerpc/genassym.c Fri Feb 27 12:08:24 2009 (r189100) @@ -158,6 +158,7 @@ ASSYM(FRAME_AIM_DAR, offsetof(struct tra ASSYM(FRAME_AIM_DSISR, offsetof(struct trapframe, cpu.aim.dsisr)); ASSYM(FRAME_BOOKE_DEAR, offsetof(struct trapframe, cpu.booke.dear)); ASSYM(FRAME_BOOKE_ESR, offsetof(struct trapframe, cpu.booke.esr)); +ASSYM(FRAME_BOOKE_DBCR0, offsetof(struct trapframe, cpu.booke.dbcr0)); ASSYM(CF_FUNC, offsetof(struct callframe, cf_func)); ASSYM(CF_ARG0, offsetof(struct callframe, cf_arg0)); @@ -176,6 +177,7 @@ ASSYM(PCB_VEC, PCB_VEC); ASSYM(PCB_AIM_USR, offsetof(struct pcb, pcb_cpu.aim.usr)); ASSYM(PCB_BOOKE_CTR, offsetof(struct pcb, pcb_cpu.booke.ctr)); ASSYM(PCB_BOOKE_XER, offsetof(struct pcb, pcb_cpu.booke.xer)); +ASSYM(PCB_BOOKE_DBCR0, offsetof(struct pcb, pcb_cpu.booke.dbcr0)); ASSYM(TD_LOCK, offsetof(struct thread, td_lock)); ASSYM(TD_PROC, offsetof(struct thread, td_proc));