From 9e7e5fda38471e00d1190479ea91d7b08ae3e304 Mon Sep 17 00:00:00 2001 From: John David Anglin Date: Tue, 22 Feb 2022 17:28:46 +0000 Subject: hppa: Revise gettext trampoline design The current getcontext return trampoline is overly complex and it unnecessarily clobbers several registers. By saving the context pointer (r26) in the context, __getcontext_ret can restore any registers not restored by setcontext. This allows getcontext to save and restore the entire register context present when getcontext is entered. We use the unused oR0 context slot for the return from __getcontext_ret. While this is not directly useful in C, it can be exploited in assembly code. Registers r20, r23, r24 and r25 are not clobbered in the call path to getcontext. This allows a small simplification of swapcontext. It also allows saving and restoring the 6-bit SAR register in the LSB of the oSAR context slot. The getcontext flag value can be stored in the MSB of the oSAR slot. --- sysdeps/unix/sysv/linux/hppa/setcontext.S | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'sysdeps/unix/sysv/linux/hppa/setcontext.S') diff --git a/sysdeps/unix/sysv/linux/hppa/setcontext.S b/sysdeps/unix/sysv/linux/hppa/setcontext.S index 5da01c2f35..dfa794ad5c 100644 --- a/sysdeps/unix/sysv/linux/hppa/setcontext.S +++ b/sysdeps/unix/sysv/linux/hppa/setcontext.S @@ -75,7 +75,7 @@ ENTRY(__setcontext) ldw oR18(%r3), %r18 ldw oR19(%r3), %r19 ldw oR20(%r3), %r20 - ldw oR21(%r3), %r21 + ldw oR21(%r3), %r21 /* maybe clobbered by dyncall */ /* ldw oR22(%r3), %r22 - dyncall arg. */ ldw oR23(%r3), %r23 ldw oR24(%r3), %r24 @@ -87,6 +87,10 @@ ENTRY(__setcontext) ldw oR30(%r3), %sp /* ldw oR31(%r3), %r31 - dyncall scratch register */ + /* Restore SAR register. */ + ldw oSAR(%r3), %r22 + mtsar %r22 + /* Restore floating-point registers. */ ldo oFPREGS31(%r3), %r22 fldds 0(%r22), %fr31 -- cgit 1.4.1