Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [day] [month] [year] [list]
Date: Sat, 30 Apr 2016 16:39:25 -0500
From: Bobby Bingham <koorogi@...rogi.info>
To: musl@...ts.openwall.com
Subject: [PATCH] ppc: simplify __clone by saving fn/arg to child stack

Previously, the parent spilled r30-r31 to its stack so that
the fn/arg could be stored in those registers, where they
would be available to the child process.

If instead, we save fn/arg to the child stack, we can avoid
spilling/restoring any registers in the parent.
---
 src/thread/powerpc/clone.s | 34 ++++++++++------------------------
 1 file changed, 10 insertions(+), 24 deletions(-)

diff --git a/src/thread/powerpc/clone.s b/src/thread/powerpc/clone.s
index a57dbcc..92ebe76 100644
--- a/src/thread/powerpc/clone.s
+++ b/src/thread/powerpc/clone.s
@@ -13,20 +13,15 @@ __clone:
 # SYS_clone = 120
 # SYS_exit = 1
 
-# store non-volatile regs r30, r31 on stack in order to put our
-# start func and its arg there
-stwu 30, -16(1)
-stw 31, 4(1)
-
-# save r3 (func) into r30, and r6(arg) into r31
-mr 30, 3
-mr 31, 6
-
 # create initial stack frame for new thread
 clrrwi 4, 4, 4
 li 0, 0
 stwu 0, -16(4)
 
+# save fn and arg to child stack
+stw 3, 4(4)
+stw 6, 8(4)
+
 #move c into first arg
 mr 3, 5
 #mr 4, 4
@@ -47,26 +42,17 @@ neg 3, 3 #negate the result (errno)
 # compare sc result with 0
 cmpwi cr7, 3, 0
 
-# if not 0, jump to end
-bne cr7, 2f
+# if not 0, return
+bnelr cr7
 
 #else: we're the child
 #call funcptr: move arg (d) into r3
-mr 3, 31
-#move r30 (funcptr) into CTR reg
-mtctr 30
+lwz 3, 8(1)
+#load funcptr (a) into CTR
+lwz 0, 4(1)
+mtctr 0
 # call CTR reg
 bctrl
 # mov SYS_exit into r0 (the exit param is already in r3)
 li 0, 1
 sc
-
-2:
-
-# restore stack
-lwz 30, 0(1)
-lwz 31, 4(1)
-addi 1, 1, 16
-
-blr
-
-- 
2.8.1

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.