]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h
1 /* Assembler macros for 64 bit S/390.
2 Copyright (C) 2001-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
19 #ifndef _LINUX_S390_SYSDEP_H
20 #define _LINUX_S390_SYSDEP_H
22 #include <sysdeps/s390/s390-64/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. */
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
37 #define SYS_ify(syscall_name) __NR_##syscall_name
41 /* Linux uses a negative return value to indicate syscall errors, unlike
42 most Unices, which use the condition codes' carry flag.
44 Since version 2.1 the return value of a system call might be negative
45 even if the call succeeded. E.g., the `lseek' system call might return
46 a large offset. Therefore we must not anymore test for < 0, but test
47 for a real error by making sure the value in gpr2 is a real error
48 number. Linus said he will make sure that no syscall returns a value
49 in -1 .. -4095 as a valid result so we can savely test with -4095. */
52 #define PSEUDO(name, syscall_name, args) \
55 DO_CALL (syscall_name, args); \
58 jgnl SYSCALL_ERROR_LABEL
61 #define PSEUDO_END(name) \
62 SYSCALL_ERROR_HANDLER; \
66 #define PSEUDO_NOERRNO(name, syscall_name, args) \
69 DO_CALL (syscall_name, args)
71 #undef PSEUDO_END_NOERRNO
72 #define PSEUDO_END_NOERRNO(name) \
73 SYSCALL_ERROR_HANDLER; \
77 #define PSEUDO_ERRVAL(name, syscall_name, args) \
80 DO_CALL (syscall_name, args); \
83 #undef PSEUDO_END_ERRVAL
84 #define PSEUDO_END_ERRVAL(name) \
85 SYSCALL_ERROR_HANDLER; \
88 #undef SYSCALL_ERROR_LABEL
90 # undef SYSCALL_ERROR_LABEL
91 # define SYSCALL_ERROR_LABEL syscall_error
92 # define SYSCALL_ERROR_HANDLER
94 # if RTLD_PRIVATE_ERRNO
95 # undef SYSCALL_ERROR_LABEL
96 # define SYSCALL_ERROR_LABEL 0f
97 # define SYSCALL_ERROR_HANDLER \
98 0: larl %r1,rtld_errno; \
103 # elif defined _LIBC_REENTRANT
105 # define SYSCALL_ERROR_ERRNO __libc_errno
107 # define SYSCALL_ERROR_ERRNO errno
109 # undef SYSCALL_ERROR_LABEL
110 # define SYSCALL_ERROR_LABEL 0f
111 # define SYSCALL_ERROR_HANDLER \
113 larl %r1,SYSCALL_ERROR_ERRNO@indntpoff; \
122 # undef SYSCALL_ERROR_LABEL
123 # define SYSCALL_ERROR_LABEL 0f
124 # define SYSCALL_ERROR_HANDLER \
125 0: larl %r1,_GLOBAL_OFFSET_TABLE_; \
126 lg %r1,errno@GOT(%r1); \
131 # endif /* _LIBC_REENTRANT */
134 /* Linux takes system call arguments in registers:
136 syscall number 1 call-clobbered
137 arg 1 2 call-clobbered
138 arg 2 3 call-clobbered
139 arg 3 4 call-clobbered
140 arg 4 5 call-clobbered
144 (Of course a function with say 3 arguments does not have entries for
146 For system calls with 6 parameters a stack operation is required
147 to load the 6th parameter to register 7. Call saved register 7 is
148 moved to register 0 and back to avoid an additional stack frame.
151 #define DO_CALL(syscall, args) \
156 .if SYS_ify (syscall) < 256; \
157 svc SYS_ify (syscall); \
159 lghi %r1,SYS_ify (syscall); \
169 #define ret_NOERRNO \
177 # undef HAVE_INTERNAL_BRK_ADDR_SYMBOL
178 # define HAVE_INTERNAL_BRK_ADDR_SYMBOL 1
180 #endif /* __ASSEMBLER__ */
182 /* Pointer mangling support. */
184 /* We cannot use the thread descriptor because in ld.so we use setjmp
185 earlier than the descriptor is initialized. */
187 /* For the time being just use stack_guard rather than a separate
189 # ifdef __ASSEMBLER__
190 # define PTR_MANGLE(reg, tmpreg) \
192 sllg tmpreg,tmpreg,32; \
194 xg reg,STACK_GUARD(tmpreg)
195 # define PTR_MANGLE2(reg, tmpreg) \
196 xg reg,STACK_GUARD(tmpreg)
197 # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
199 # define PTR_MANGLE(var) \
200 (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
201 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
205 #endif /* _LINUX_S390_SYSDEP_H */