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