]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h
26836620f28c976009a62a2fd4048595ebda9335
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / s390 / s390-32 / sysdep.h
1 /* Copyright (C) 2000-2020 Free Software Foundation, Inc.
2 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #ifndef _LINUX_S390_SYSDEP_H
20 #define _LINUX_S390_SYSDEP_H
21
22 #include <sysdeps/s390/s390-32/sysdep.h>
23 #include <sysdeps/unix/sysdep.h>
24 #include <sysdeps/unix/sysv/linux/s390/sysdep.h>
25 #include <sysdeps/unix/sysv/linux/sysdep.h>
26 #include <dl-sysdep.h> /* For RTLD_PRIVATE_ERRNO. */
27 #include <tls.h>
28
29 /* For Linux we can use the system call table in the header file
30 /usr/include/asm/unistd.h
31 of the kernel. But these symbols do not follow the SYS_* syntax
32 so we have to redefine the `SYS_ify' macro here. */
33 /* in newer 2.1 kernels __NR_syscall is missing so we define it here */
34 #define __NR_syscall 0
35
36 #ifdef __ASSEMBLER__
37
38 /* Linux uses a negative return value to indicate syscall errors, unlike
39 most Unices, which use the condition codes' carry flag.
40
41 Since version 2.1 the return value of a system call might be negative
42 even if the call succeeded. E.g., the `lseek' system call might return
43 a large offset. Therefore we must not anymore test for < 0, but test
44 for a real error by making sure the value in gpr2 is a real error
45 number. Linus said he will make sure that no syscall returns a value
46 in -1 .. -4095 as a valid result so we can savely test with -4095. */
47
48 #undef PSEUDO
49 #define PSEUDO(name, syscall_name, args) \
50 .text; \
51 ENTRY (name) \
52 DO_CALL (syscall_name, args); \
53 lhi %r4,-4095 ; \
54 clr %r2,%r4 ; \
55 jnl SYSCALL_ERROR_LABEL
56
57 #undef PSEUDO_END
58 #define PSEUDO_END(name) \
59 SYSCALL_ERROR_HANDLER; \
60 END (name)
61
62 #undef PSEUDO_NOERRNO
63 #define PSEUDO_NOERRNO(name, syscall_name, args) \
64 .text; \
65 ENTRY (name) \
66 DO_CALL (syscall_name, args)
67
68 #undef PSEUDO_END_NOERRNO
69 #define PSEUDO_END_NOERRNO(name) \
70 END (name)
71
72 #undef PSEUDO_ERRVAL
73 #define PSEUDO_ERRVAL(name, syscall_name, args) \
74 .text; \
75 ENTRY (name) \
76 DO_CALL (syscall_name, args); \
77 lcr %r2,%r2
78
79 #undef PSEUDO_END_ERRVAL
80 #define PSEUDO_END_ERRVAL(name) \
81 END (name)
82
83 #undef SYSCALL_ERROR_LABEL
84 #ifndef PIC
85 # undef SYSCALL_ERROR_LABEL
86 # define SYSCALL_ERROR_LABEL 0f
87 # define SYSCALL_ERROR_HANDLER \
88 0: basr %r1,0; \
89 1: l %r1,2f-1b(%r1); \
90 br %r1; \
91 2: .long syscall_error
92 #else
93 # if RTLD_PRIVATE_ERRNO
94 # undef SYSCALL_ERROR_LABEL
95 # define SYSCALL_ERROR_LABEL 0f
96 # define SYSCALL_ERROR_HANDLER \
97 0: basr %r1,0; \
98 1: al %r1,2f-1b(%r1); \
99 lcr %r2,%r2; \
100 st %r2,0(%r1); \
101 lhi %r2,-1; \
102 br %r14; \
103 2: .long rtld_errno-1b
104 # elif defined _LIBC_REENTRANT
105 # if IS_IN (libc)
106 # define SYSCALL_ERROR_ERRNO __libc_errno
107 # else
108 # define SYSCALL_ERROR_ERRNO errno
109 # endif
110 # undef SYSCALL_ERROR_LABEL
111 # define SYSCALL_ERROR_LABEL 0f
112 # define SYSCALL_ERROR_HANDLER \
113 0: lcr %r0,%r2; \
114 basr %r1,0; \
115 1: al %r1,2f-1b(%r1); \
116 l %r1,SYSCALL_ERROR_ERRNO@gotntpoff(%r1); \
117 ear %r2,%a0; \
118 st %r0,0(%r1,%r2); \
119 lhi %r2,-1; \
120 br %r14; \
121 2: .long _GLOBAL_OFFSET_TABLE_-1b
122 # else
123 # undef SYSCALL_ERROR_LABEL
124 # define SYSCALL_ERROR_LABEL 0f
125 # define SYSCALL_ERROR_HANDLER \
126 0: basr %r1,0; \
127 1: al %r1,2f-1b(%r1); \
128 l %r1,errno@GOT(%r1); \
129 lcr %r2,%r2; \
130 st %r2,0(%r1); \
131 lhi %r2,-1; \
132 br %r14; \
133 2: .long _GLOBAL_OFFSET_TABLE_-1b
134 # endif /* _LIBC_REENTRANT */
135 #endif /* PIC */
136
137 /* Linux takes system call arguments in registers:
138
139 syscall number 1 call-clobbered
140 arg 1 2 call-clobbered
141 arg 2 3 call-clobbered
142 arg 3 4 call-clobbered
143 arg 4 5 call-clobbered
144 arg 5 6 call-saved
145 arg 6 7 call-saved
146
147 (Of course a function with say 3 arguments does not have entries for
148 arguments 4 and 5.)
149 For system calls with 6 parameters a stack operation is required
150 to load the 6th parameter to register 7. Call saved register 7 is
151 moved to register 0 and back to avoid an additional stack frame.
152 */
153
154 #define DO_CALL(syscall, args) \
155 .if args > 5; \
156 lr %r0,%r7; \
157 l %r7,96(%r15); \
158 .endif; \
159 .if SYS_ify (syscall) < 256; \
160 svc SYS_ify (syscall); \
161 .else; \
162 lhi %r1,SYS_ify (syscall); \
163 svc 0; \
164 .endif; \
165 .if args > 5; \
166 lr %r7,%r0; \
167 .endif
168
169 #define ret \
170 br 14
171
172 #define ret_NOERRNO \
173 br 14
174
175 #define ret_ERRVAL \
176 br 14
177
178 #else
179
180 # undef HAVE_INTERNAL_BRK_ADDR_SYMBOL
181 # define HAVE_INTERNAL_BRK_ADDR_SYMBOL 1
182
183 #endif /* __ASSEMBLER__ */
184
185 /* Pointer mangling support. */
186 #if IS_IN (rtld)
187 /* We cannot use the thread descriptor because in ld.so we use setjmp
188 earlier than the descriptor is initialized. */
189 #else
190 /* For the time being just use stack_guard rather than a separate
191 pointer_guard. */
192 # ifdef __ASSEMBLER__
193 # define PTR_MANGLE(reg, tmpreg) \
194 ear tmpreg,%a0; \
195 x reg,STACK_GUARD(tmpreg)
196 # define PTR_MANGLE2(reg, tmpreg) \
197 x reg,STACK_GUARD(tmpreg)
198 # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
199 # else
200 # define PTR_MANGLE(var) \
201 (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
202 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
203 # endif
204 #endif
205
206 #endif /* _LINUX_S390_SYSDEP_H */