08c3a6
commit 738ee53f0ce5e39b9b7a6777f5d3057afbaac498
08c3a6
Author: John David Anglin <danglin@gcc.gnu.org>
08c3a6
Date:   Tue Mar 15 23:12:37 2022 +0000
08c3a6
08c3a6
    hppa: Implement swapcontext in assembler (bug 28960)
08c3a6
    
08c3a6
    When swapcontext.c is compiled without -g, the following error occurs:
08c3a6
    Error: CFI instruction used without previous .cfi_startproc
08c3a6
    
08c3a6
    Fix by converting swapcontext routine to assembler.
08c3a6
08c3a6
diff --git a/sysdeps/unix/sysv/linux/hppa/swapcontext.S b/sysdeps/unix/sysv/linux/hppa/swapcontext.S
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..94b164dc6375563e
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/unix/sysv/linux/hppa/swapcontext.S
08c3a6
@@ -0,0 +1,72 @@
08c3a6
+/* Swap to new context.
08c3a6
+   Copyright (C) 2008-2022 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library.  If not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+#include <sysdep.h>
08c3a6
+#include "ucontext_i.h"
08c3a6
+
08c3a6
+	.text
08c3a6
+ENTRY(__swapcontext)
08c3a6
+
08c3a6
+	/* Copy rp to ret0 (r28).  */
08c3a6
+	copy %rp,%ret0
08c3a6
+
08c3a6
+	/* Create a frame.  */
08c3a6
+	ldo 64(%sp),%sp
08c3a6
+	.cfi_def_cfa_offset -64
08c3a6
+
08c3a6
+	/* Save the current machine context to oucp.  */
08c3a6
+	bl __getcontext,%rp
08c3a6
+
08c3a6
+	/* Copy oucp to register ret1 (r29).  __getcontext saves and
08c3a6
+	   restores it on a normal return.  It is restored from oR29
08c3a6
+	   on reactivation.  */
08c3a6
+	copy %r26,%ret1
08c3a6
+
08c3a6
+	/* Pop frame.  */
08c3a6
+	ldo -64(%sp),%sp
08c3a6
+	.cfi_def_cfa_offset 0
08c3a6
+
08c3a6
+	/* Load return pointer from oR28.  */
08c3a6
+	ldw oR28(%ret1),%rp
08c3a6
+
08c3a6
+	/* Return if error.  */
08c3a6
+	or,= %r0,%ret0,%r0
08c3a6
+	bv,n %r0(%rp)
08c3a6
+
08c3a6
+	/* Load sc_sar flag.  */
08c3a6
+	ldb oSAR(%ret1),%r20
08c3a6
+
08c3a6
+	/* Return if oucp context has been reactivated.  */
08c3a6
+	or,= %r0,%r20,%r0
08c3a6
+	bv,n %r0(%rp)
08c3a6
+
08c3a6
+	/* Mark sc_sar flag.  */
08c3a6
+	ldi 1,%r20
08c3a6
+	stb %r20,oSAR(%ret1)
08c3a6
+
08c3a6
+	/* Activate the machine context in ucp.  */
08c3a6
+	bl __setcontext,%rp
08c3a6
+	ldw oR25(%ret1),%r26
08c3a6
+
08c3a6
+	/* Load return pointer.  */
08c3a6
+	ldw oR28(%ret1),%rp
08c3a6
+	bv,n %r0(%rp)
08c3a6
+
08c3a6
+PSEUDO_END(__swapcontext)
08c3a6
+
08c3a6
+weak_alias (__swapcontext, swapcontext)
08c3a6
diff --git a/sysdeps/unix/sysv/linux/hppa/swapcontext.c b/sysdeps/unix/sysv/linux/hppa/swapcontext.c
08c3a6
deleted file mode 100644
08c3a6
index 1664f68c7b9982e8..0000000000000000
08c3a6
--- a/sysdeps/unix/sysv/linux/hppa/swapcontext.c
08c3a6
+++ /dev/null
08c3a6
@@ -1,83 +0,0 @@
08c3a6
-/* Swap to new context.
08c3a6
-   Copyright (C) 2008-2021 Free Software Foundation, Inc.
08c3a6
-   This file is part of the GNU C Library.
08c3a6
-   Contributed by Helge Deller <deller@gmx.de>, 2008.
08c3a6
-
08c3a6
-   The GNU C Library is free software; you can redistribute it and/or
08c3a6
-   modify it under the terms of the GNU Lesser General Public
08c3a6
-   License as published by the Free Software Foundation; either
08c3a6
-   version 2.1 of the License, or (at your option) any later version.
08c3a6
-
08c3a6
-   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
08c3a6
-   Lesser General Public License for more details.
08c3a6
-
08c3a6
-   You should have received a copy of the GNU Lesser General Public
08c3a6
-   License along with the GNU C Library.  If not, see
08c3a6
-   <https://www.gnu.org/licenses/>.  */
08c3a6
-
08c3a6
-#include <ucontext.h>
08c3a6
-#include "ucontext_i.h"
08c3a6
-
08c3a6
-extern int __getcontext (ucontext_t *ucp);
08c3a6
-extern int __setcontext (const ucontext_t *ucp);
08c3a6
-
08c3a6
-int
08c3a6
-__swapcontext (ucontext_t *oucp, const ucontext_t *ucp)
08c3a6
-{
08c3a6
-  /* Save rp for debugger.  */
08c3a6
-  asm ("stw %rp,-20(%sp)");
08c3a6
-  asm (".cfi_offset 2, -20");
08c3a6
-
08c3a6
-  /* Copy rp to ret0 (r28).  */
08c3a6
-  asm ("copy %rp,%ret0");
08c3a6
-
08c3a6
-  /* Create a frame.  */
08c3a6
-  asm ("ldo 64(%sp),%sp");
08c3a6
-  asm (".cfi_def_cfa_offset -64");
08c3a6
-
08c3a6
-  /* Save the current machine context to oucp.  */
08c3a6
-  asm ("bl __getcontext,%rp");
08c3a6
-
08c3a6
-  /* Copy oucp to register ret1 (r29).  __getcontext saves and restores it
08c3a6
-     on a normal return.  It is restored from oR29 on reactivation.  */
08c3a6
-  asm ("copy %r26,%ret1");
08c3a6
-
08c3a6
-  /* Pop frame.  */
08c3a6
-  asm ("ldo -64(%sp),%sp");
08c3a6
-  asm (".cfi_def_cfa_offset 0");
08c3a6
-
08c3a6
-  /* Load return pointer from oR28.  */
08c3a6
-  asm ("ldw %0(%%ret1),%%rp" : : "i" (oR28));
08c3a6
-
08c3a6
-  /* Return if error.  */
08c3a6
-  asm ("or,= %r0,%ret0,%r0");
08c3a6
-  asm ("bv,n %r0(%rp)");
08c3a6
-
08c3a6
-  /* Load sc_sar flag.  */
08c3a6
-  asm ("ldb %0(%%ret1),%%r20" : : "i" (oSAR));
08c3a6
-
08c3a6
-  /* Return if oucp context has been reactivated.  */
08c3a6
-  asm ("or,= %r0,%r20,%r0");
08c3a6
-  asm ("bv,n %r0(%rp)");
08c3a6
-
08c3a6
-  /* Mark sc_sar flag.  */
08c3a6
-  asm ("1: ldi 1,%r20");
08c3a6
-  asm ("stb %%r20,%0(%%ret1)" : : "i" (oSAR));
08c3a6
-
08c3a6
-  /* Activate the machine context in ucp.  */
08c3a6
-  asm ("bl __setcontext,%rp");
08c3a6
-  asm ("ldw %0(%%ret1),%%r26" : : "i" (oR25));
08c3a6
-
08c3a6
-  /* Load return pointer.  */
08c3a6
-  asm ("ldw %0(%%ret1),%%rp" : : "i" (oR28));
08c3a6
-
08c3a6
-  /* A successful call to setcontext does not return.  */
08c3a6
-  asm ("bv,n %r0(%rp)");
08c3a6
-
08c3a6
-  /* Make gcc happy.  */
08c3a6
-  return 0;
08c3a6
-}
08c3a6
-
08c3a6
-weak_alias (__swapcontext, swapcontext)