initial commit
[glibc.git] / sysdeps / s390 / s390-32 / __longjmp.c
1 /* Copyright (C) 2000-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18 #include <errno.h>
19 #include <sysdep.h>
20 #include <setjmp.h>
21 #include <bits/setjmp.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <stap-probe.h>
25
26 /* Jump to the position specified by ENV, causing the
27 setjmp call there to return VAL, or 1 if VAL is 0. */
28 void
29 __longjmp (__jmp_buf env, int val)
30 {
31 #ifdef PTR_DEMANGLE
32 uintptr_t guard = THREAD_GET_POINTER_GUARD ();
33 # ifdef CHECK_SP
34 CHECK_SP (env, guard);
35 # endif
36 #elif defined CHECK_SP
37 CHECK_SP (env, 0);
38 #endif
39 register int r2 __asm__ ("%r2") = val == 0 ? 1 : val;
40 #ifdef PTR_DEMANGLE
41 register uintptr_t r3 __asm__ ("%r3") = guard;
42 register void *r1 __asm__ ("%r1") = (void *) env;
43 #endif
44 /* Restore registers and jump back. */
45 __asm__ __volatile__ (
46 /* longjmp probe expects longjmp first argument, second
47 argument and target address. */
48 #ifdef PTR_DEMANGLE
49 "lm %%r4,%%r5,32(%1)\n\t"
50 "xr %%r4,%2\n\t"
51 "xr %%r5,%2\n\t"
52 LIBC_PROBE_ASM (longjmp, 4@%1 -4@%0 4@%%r4)
53 #else
54 LIBC_PROBE_ASM (longjmp, 4@%1 -4@%0 4@%%r14)
55 #endif
56
57 /* restore fpregs */
58 "ld %%f6,48(%1)\n\t"
59 "ld %%f4,40(%1)\n\t"
60
61 /* restore gregs and return to jmp_buf target */
62 #ifdef PTR_DEMANGLE
63 "lm %%r6,%%r13,0(%1)\n\t"
64 "lr %%r15,%%r5\n\t"
65 LIBC_PROBE_ASM (longjmp_target, 4@%1 -4@%0 4@%%r4)
66 "br %%r4"
67 #else
68 "lm %%r6,%%r15,0(%1)\n\t"
69 LIBC_PROBE_ASM (longjmp_target, 4@%1 -4@%0 4@%%r14)
70 "br %%r14"
71 #endif
72 : : "r" (r2),
73 #ifdef PTR_DEMANGLE
74 "r" (r1), "r" (r3)
75 #else
76 "a" (env)
77 #endif
78 );
79
80 /* Avoid `volatile function does return' warnings. */
81 for (;;);
82 }