]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h
0d683a5bcbe819448c13361d62c14966ee812779
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / s390 / s390-32 / sysdep.h
1 /* Copyright (C) 2000-2018 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 <http://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/sysdep.h>
25 #include <dl-sysdep.h> /* For RTLD_PRIVATE_ERRNO. */
26 #include <tls.h>
27
28 /* Define __set_errno() for INLINE_SYSCALL macro below. */
29 #ifndef __ASSEMBLER__
30 #include <errno.h>
31 #endif
32
33 /* For Linux we can use the system call table in the header file
34 /usr/include/asm/unistd.h
35 of the kernel. But these symbols do not follow the SYS_* syntax
36 so we have to redefine the `SYS_ify' macro here. */
37 /* in newer 2.1 kernels __NR_syscall is missing so we define it here */
38 #define __NR_syscall 0
39
40 #undef SYS_ify
41 #define SYS_ify(syscall_name) __NR_##syscall_name
42
43 #ifdef __ASSEMBLER__
44
45 /* Linux uses a negative return value to indicate syscall errors, unlike
46 most Unices, which use the condition codes' carry flag.
47
48 Since version 2.1 the return value of a system call might be negative
49 even if the call succeeded. E.g., the `lseek' system call might return
50 a large offset. Therefore we must not anymore test for < 0, but test
51 for a real error by making sure the value in gpr2 is a real error
52 number. Linus said he will make sure that no syscall returns a value
53 in -1 .. -4095 as a valid result so we can savely test with -4095. */
54
55 #undef PSEUDO
56 #define PSEUDO(name, syscall_name, args) \
57 .text; \
58 ENTRY (name) \
59 DO_CALL (syscall_name, args); \
60 lhi %r4,-4095 ; \
61 clr %r2,%r4 ; \
62 jnl SYSCALL_ERROR_LABEL
63
64 #undef PSEUDO_END
65 #define PSEUDO_END(name) \
66 SYSCALL_ERROR_HANDLER; \
67 END (name)
68
69 #undef PSEUDO_NOERRNO
70 #define PSEUDO_NOERRNO(name, syscall_name, args) \
71 .text; \
72 ENTRY (name) \
73 DO_CALL (syscall_name, args)
74
75 #undef PSEUDO_END_NOERRNO
76 #define PSEUDO_END_NOERRNO(name) \
77 END (name)
78
79 #undef PSEUDO_ERRVAL
80 #define PSEUDO_ERRVAL(name, syscall_name, args) \
81 .text; \
82 ENTRY (name) \
83 DO_CALL (syscall_name, args); \
84 lcr %r2,%r2
85
86 #undef PSEUDO_END_ERRVAL
87 #define PSEUDO_END_ERRVAL(name) \
88 END (name)
89
90 #ifndef PIC
91 # define SYSCALL_ERROR_LABEL 0f
92 # define SYSCALL_ERROR_HANDLER \
93 0: basr %r1,0; \
94 1: l %r1,2f-1b(%r1); \
95 br %r1; \
96 2: .long syscall_error
97 #else
98 # if RTLD_PRIVATE_ERRNO
99 # define SYSCALL_ERROR_LABEL 0f
100 # define SYSCALL_ERROR_HANDLER \
101 0: basr %r1,0; \
102 1: al %r1,2f-1b(%r1); \
103 lcr %r2,%r2; \
104 st %r2,0(%r1); \
105 lhi %r2,-1; \
106 br %r14; \
107 2: .long rtld_errno-1b
108 # elif defined _LIBC_REENTRANT
109 # if IS_IN (libc)
110 # define SYSCALL_ERROR_ERRNO __libc_errno
111 # else
112 # define SYSCALL_ERROR_ERRNO errno
113 # endif
114 # define SYSCALL_ERROR_LABEL 0f
115 # define SYSCALL_ERROR_HANDLER \
116 0: lcr %r0,%r2; \
117 basr %r1,0; \
118 1: al %r1,2f-1b(%r1); \
119 l %r1,SYSCALL_ERROR_ERRNO@gotntpoff(%r1); \
120 ear %r2,%a0; \
121 st %r0,0(%r1,%r2); \
122 lhi %r2,-1; \
123 br %r14; \
124 2: .long _GLOBAL_OFFSET_TABLE_-1b
125 # else
126 # define SYSCALL_ERROR_LABEL 0f
127 # define SYSCALL_ERROR_HANDLER \
128 0: basr %r1,0; \
129 1: al %r1,2f-1b(%r1); \
130 l %r1,errno@GOT(%r1); \
131 lcr %r2,%r2; \
132 st %r2,0(%r1); \
133 lhi %r2,-1; \
134 br %r14; \
135 2: .long _GLOBAL_OFFSET_TABLE_-1b
136 # endif /* _LIBC_REENTRANT */
137 #endif /* PIC */
138
139 /* Linux takes system call arguments in registers:
140
141 syscall number 1 call-clobbered
142 arg 1 2 call-clobbered
143 arg 2 3 call-clobbered
144 arg 3 4 call-clobbered
145 arg 4 5 call-clobbered
146 arg 5 6 call-saved
147 arg 6 7 call-saved
148
149 (Of course a function with say 3 arguments does not have entries for
150 arguments 4 and 5.)
151 For system calls with 6 parameters a stack operation is required
152 to load the 6th parameter to register 7. Call saved register 7 is
153 moved to register 0 and back to avoid an additional stack frame.
154 */
155
156 #define DO_CALL(syscall, args) \
157 .if args > 5; \
158 lr %r0,%r7; \
159 l %r7,96(%r15); \
160 .endif; \
161 .if SYS_ify (syscall) < 256; \
162 svc SYS_ify (syscall); \
163 .else; \
164 lhi %r1,SYS_ify (syscall); \
165 svc 0; \
166 .endif; \
167 .if args > 5; \
168 lr %r7,%r0; \
169 .endif
170
171 #define ret \
172 br 14
173
174 #define ret_NOERRNO \
175 br 14
176
177 #define ret_ERRVAL \
178 br 14
179
180 #endif /* __ASSEMBLER__ */
181
182 #undef INLINE_SYSCALL
183 #define INLINE_SYSCALL(name, nr, args...) \
184 ({ \
185 unsigned int _ret = INTERNAL_SYSCALL (name, , nr, args); \
186 if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (_ret, ))) \
187 { \
188 __set_errno (INTERNAL_SYSCALL_ERRNO (_ret, )); \
189 _ret = 0xffffffff; \
190 } \
191 (int) _ret; })
192
193 #undef INTERNAL_SYSCALL_DECL
194 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
195
196 #undef INTERNAL_SYSCALL_DIRECT
197 #define INTERNAL_SYSCALL_DIRECT(name, err, nr, args...) \
198 ({ \
199 DECLARGS_##nr(args) \
200 register int _ret __asm__("2"); \
201 __asm__ __volatile__ ( \
202 "svc %b1\n\t" \
203 : "=d" (_ret) \
204 : "i" (__NR_##name) ASMFMT_##nr \
205 : "memory" ); \
206 _ret; })
207
208 #undef INTERNAL_SYSCALL_SVC0
209 #define INTERNAL_SYSCALL_SVC0(name, err, nr, args...) \
210 ({ \
211 DECLARGS_##nr(args) \
212 register unsigned long _nr __asm__("1") = (unsigned long)(__NR_##name); \
213 register int _ret __asm__("2"); \
214 __asm__ __volatile__ ( \
215 "svc 0\n\t" \
216 : "=d" (_ret) \
217 : "d" (_nr) ASMFMT_##nr \
218 : "memory" ); \
219 _ret; })
220
221 #undef INTERNAL_SYSCALL_NCS
222 #define INTERNAL_SYSCALL_NCS(no, err, nr, args...) \
223 ({ \
224 DECLARGS_##nr(args) \
225 register unsigned long _nr __asm__("1") = (unsigned long)(no); \
226 register int _ret __asm__("2"); \
227 __asm__ __volatile__ ( \
228 "svc 0\n\t" \
229 : "=d" (_ret) \
230 : "d" (_nr) ASMFMT_##nr \
231 : "memory" ); \
232 _ret; })
233
234 #undef INTERNAL_SYSCALL
235 #define INTERNAL_SYSCALL(name, err, nr, args...) \
236 (((__NR_##name) < 256) ? \
237 INTERNAL_SYSCALL_DIRECT(name, err, nr, args) : \
238 INTERNAL_SYSCALL_SVC0(name, err,nr, args))
239
240 #undef INTERNAL_SYSCALL_ERROR_P
241 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
242 ((unsigned int) (val) >= 0xfffff001u)
243
244 #undef INTERNAL_SYSCALL_ERRNO
245 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
246
247 #define DECLARGS_0()
248 #define DECLARGS_1(arg1) \
249 register unsigned long gpr2 __asm__ ("2") = (unsigned long)(arg1);
250 #define DECLARGS_2(arg1, arg2) \
251 DECLARGS_1(arg1) \
252 register unsigned long gpr3 __asm__ ("3") = (unsigned long)(arg2);
253 #define DECLARGS_3(arg1, arg2, arg3) \
254 DECLARGS_2(arg1, arg2) \
255 register unsigned long gpr4 __asm__ ("4") = (unsigned long)(arg3);
256 #define DECLARGS_4(arg1, arg2, arg3, arg4) \
257 DECLARGS_3(arg1, arg2, arg3) \
258 register unsigned long gpr5 __asm__ ("5") = (unsigned long)(arg4);
259 #define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
260 DECLARGS_4(arg1, arg2, arg3, arg4) \
261 register unsigned long gpr6 __asm__ ("6") = (unsigned long)(arg5);
262 #define DECLARGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
263 DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
264 register unsigned long gpr7 __asm__ ("7") = (unsigned long)(arg6);
265
266 #define ASMFMT_0
267 #define ASMFMT_1 , "0" (gpr2)
268 #define ASMFMT_2 , "0" (gpr2), "d" (gpr3)
269 #define ASMFMT_3 , "0" (gpr2), "d" (gpr3), "d" (gpr4)
270 #define ASMFMT_4 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5)
271 #define ASMFMT_5 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6)
272 #define ASMFMT_6 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6), "d" (gpr7)
273
274 /* List of system calls which are supported as vsyscalls. */
275 #define HAVE_CLOCK_GETRES_VSYSCALL 1
276 #define HAVE_CLOCK_GETTIME_VSYSCALL 1
277 #define HAVE_GETTIMEOFDAY_VSYSCALL 1
278 #define HAVE_GETCPU_VSYSCALL 1
279
280 /* Pointer mangling support. */
281 #if IS_IN (rtld)
282 /* We cannot use the thread descriptor because in ld.so we use setjmp
283 earlier than the descriptor is initialized. */
284 #else
285 /* For the time being just use stack_guard rather than a separate
286 pointer_guard. */
287 # ifdef __ASSEMBLER__
288 # define PTR_MANGLE(reg, tmpreg) \
289 ear tmpreg,%a0; \
290 x reg,STACK_GUARD(tmpreg)
291 # define PTR_MANGLE2(reg, tmpreg) \
292 x reg,STACK_GUARD(tmpreg)
293 # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
294 # else
295 # define PTR_MANGLE(var) \
296 (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
297 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
298 # endif
299 #endif
300
301 #endif /* _LINUX_S390_SYSDEP_H */