From owner-freebsd-ppc@FreeBSD.ORG Fri Oct 10 15:11:19 2014 Return-Path: Delivered-To: freebsd-ppc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 772A897F for ; Fri, 10 Oct 2014 15:11:19 +0000 (UTC) Received: from asp.reflexion.net (outbound-241.asp.reflexion.net [69.84.129.241]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 221E96E2 for ; Fri, 10 Oct 2014 15:11:18 +0000 (UTC) Received: (qmail 14928 invoked from network); 10 Oct 2014 15:04:37 -0000 Received: from unknown (HELO rtc-sm-01.app.dca.reflexion.local) (10.81.150.1) by 0 (rfx-qmail) with SMTP; 10 Oct 2014 15:04:37 -0000 Received: by rtc-sm-01.app.dca.reflexion.local (Reflexion email security v7.30.7) with SMTP; Fri, 10 Oct 2014 11:04:37 -0400 (EDT) Received: (qmail 29205 invoked from network); 10 Oct 2014 15:04:37 -0000 Received: from unknown (HELO iron2.pdx.net) (69.64.224.71) by 0 (rfx-qmail) with (DHE-RSA-AES256-SHA encrypted) SMTP; 10 Oct 2014 15:04:37 -0000 X-No-Relay: not in my network X-No-Relay: not in my network X-No-Relay: not in my network Received: from [192.168.1.8] (c-98-246-178-138.hsd1.or.comcast.net [98.246.178.138]) by iron2.pdx.net (Postfix) with ESMTPSA id 26330B1E002; Fri, 10 Oct 2014 08:04:34 -0700 (PDT) From: Mark Millard Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: powerpc64/GENERIC64: s_trap vs. realtrap, why does realtrap possibly execute restore_kernsrs twice in a row overall? Date: Fri, 10 Oct 2014 08:04:35 -0700 Message-Id: <511C0B85-173F-4863-ACA5-0274C381E005@dsl-only.net> To: FreeBSD PowerPC ML Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) X-Mailer: Apple Mail (2.1878.6) Cc: Justin Hibbits X-BeenThere: freebsd-ppc@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Porting FreeBSD to the PowerPC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Oct 2014 15:11:19 -0000 Based on 10.1-RC1 sources but probably long true.. s_trap in /usr/src/sys/powerpc/aim/trap_subr64.S starts with the = following sequence of 8 lines of source immediately after the s_trap = label (ignoring the unused u_trap label line, not shown below): s_trap: bf 17,k_trap /* branch if PSL_PR is false */ GET_CPUINFO(%r1) ld %r1,PC_CURPCB(%r1) mr %r27,%r28 /* Save LR, r29 */ mtsprg2 %r29 bl restore_kernsrs /* enable kernel mapping */ mfsprg2 %r29 mr %r28,%r27 realtrap also has that exact instruction sequence starting a few = instructions down in its code --but immeadiately followed by a branch to = s_strap that ends up reexecuting that same instruction sequence (but = in/at s_trap), presuming that the original "bd 17,k_trap" in realtrap is = not taken: realtrap: /* Test whether we already had PR set */ mfsrr1 %r1 mtcr %r1 mfsprg1 %r1 /* restore SP (might have been overwritten) */ bf 17,k_trap /* branch if PSL_PR is false */ GET_CPUINFO(%r1) ld %r1,PC_CURPCB(%r1) mr %r27,%r28 /* Save LR, r29 */ mtsprg2 %r29 bl restore_kernsrs /* enable kernel mapping */ mfsprg2 %r29 mr %r28,%r27 ba s_trap Why would this code for possibly calling restore_kernsrs possibly be = executed twice back-to-back for realtrap's execution overall? Is this = deliberate for some reason? Could the realtrap code validly avoid the = doubled activity when it does not immediately jump to k_trap? Note that if it was possible for s_trap to take the "bf 17,k_trap" = branch after realtrap did its "ba s_trap" then %r1 for that s_trap use = would not have the stack pointer in it for k_trap's potential use (e.g., = in its use of FRAME_SETUP). restore_kernsrs does not touch %r1 and = k_trap takes %r1 as-is for use as a stack pointer in FRAME_SETUP. = Luckily it appears that s_trap would not take that branch in this = context. But if that last is true that means that s_trap's code definitely always = does call restore_kernsrs a second time when used from realtrap. = Wasteful? [And for realtrap it would seem that the "mfsrr1 %r1" definitely "might = have" overwritten %r1 (a.k.a. the Stack Pointer): The "might have" = comment seems a little odd. It is more like the SP would be needed in = the branch to k_trap case and so had to be put back in %r1 to cover = that.] =3D=3D=3D Mark Millard markmi at dsl-only.net