Fix s390{,x} build. grouplist fixes from Ulrich.
[glibc.git] / sysdeps / unix / sysv / linux / s390 / s390-64 / sysdep.h
blob154bc068039deee558589aff74abeef2a29a9cf5
1 /* Assembler macros for 64 bit S/390.
2 Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
4 This file is part of the GNU C Library.
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.
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.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #ifndef _LINUX_S390_SYSDEP_H
22 #define _LINUX_S390_SYSDEP_H
24 #include <sysdeps/s390/s390-64/sysdep.h>
25 #include <sysdeps/unix/sysdep.h>
26 #include <dl-sysdep.h> /* For RTLD_PRIVATE_ERRNO. */
28 /* For Linux we can use the system call table in the header file
29 /usr/include/asm/unistd.h
30 of the kernel. But these symbols do not follow the SYS_* syntax
31 so we have to redefine the `SYS_ify' macro here. */
32 /* In newer 2.1 kernels __NR_syscall is missing so we define it here. */
33 #define __NR_syscall 0
36 * Newer kernel versions redefined __NR_pread and __NR_pwrite to
37 * __NR_pread64 and __NR_pwrite64.
39 #ifndef __NR_pread
40 # define __NR_pread __NR_pread64
41 #endif
42 #ifndef __NR_pwrite
43 # define __NR_pwrite __NR_pwrite64
44 #endif
46 #undef SYS_ify
47 #define SYS_ify(syscall_name) __NR_##syscall_name
49 #ifdef __ASSEMBLER__
51 /* Linux uses a negative return value to indicate syscall errors, unlike
52 most Unices, which use the condition codes' carry flag.
54 Since version 2.1 the return value of a system call might be negative
55 even if the call succeeded. E.g., the `lseek' system call might return
56 a large offset. Therefore we must not anymore test for < 0, but test
57 for a real error by making sure the value in gpr2 is a real error
58 number. Linus said he will make sure the no syscall returns a value
59 in -1 .. -4095 as a valid result so we can savely test with -4095. */
61 #undef PSEUDO
62 #define PSEUDO(name, syscall_name, args) \
63 .text; \
64 ENTRY (name) \
65 DO_CALL (syscall_name, args); \
66 lghi %r4,-4095 ; \
67 clgr %r2,%r4 ; \
68 jgnl SYSCALL_ERROR_LABEL
70 #undef PSEUDO_END
71 #define PSEUDO_END(name) \
72 SYSCALL_ERROR_HANDLER; \
73 END (name)
75 #undef PSEUDO_NOERRNO
76 #define PSEUDO_NOERRNO(name, syscall_name, args) \
77 .text; \
78 ENTRY (name) \
79 DO_CALL (syscall_name, args)
81 #undef PSEUDO_END_NOERRNO
82 #define PSEUDO_END_NOERRNO(name) \
83 SYSCALL_ERROR_HANDLER; \
84 END (name)
86 #undef PSEUDO_ERRVAL
87 #define PSEUDO_ERRVAL(name, syscall_name, args) \
88 .text; \
89 ENTRY (name) \
90 DO_CALL (syscall_name, args); \
91 lcgr %r2,%r2
93 #undef PSEUDO_END_ERRVAL
94 #define PSEUDO_END_ERRVAL(name) \
95 SYSCALL_ERROR_HANDLER; \
96 END (name)
98 #ifndef PIC
99 # define SYSCALL_ERROR_LABEL syscall_error
100 # define SYSCALL_ERROR_HANDLER
101 #else
102 # if RTLD_PRIVATE_ERRNO
103 # define SYSCALL_ERROR_LABEL 0f
104 # define SYSCALL_ERROR_HANDLER \
105 0: larl %r1,rtld_errno; \
106 lcr %r2,%r2; \
107 st %r2,0(%r1); \
108 lghi %r2,-1; \
109 br %r14
110 # elif defined _LIBC_REENTRANT
111 # if USE___THREAD
112 # ifndef NOT_IN_libc
113 # define SYSCALL_ERROR_ERRNO __libc_errno
114 # else
115 # define SYSCALL_ERROR_ERRNO errno
116 # endif
117 # define SYSCALL_ERROR_LABEL 0f
118 # define SYSCALL_ERROR_HANDLER \
119 0: lcr %r0,%r2; \
120 larl %r1,SYSCALL_ERROR_ERRNO@indntpoff; \
121 lg %r1,0(%r1); \
122 ear %r2,%a0; \
123 sllg %r2,%r2,32; \
124 ear %r2,%a1; \
125 st %r0,0(%r1,%r2); \
126 lghi %r2,-1; \
127 br %r14
128 # else
129 # define SYSCALL_ERROR_LABEL syscall_error@plt
130 # define SYSCALL_ERROR_HANDLER
131 # endif
132 # else
133 # define SYSCALL_ERROR_LABEL 0f
134 # define SYSCALL_ERROR_HANDLER \
135 0: larl %r1,_GLOBAL_OFFSET_TABLE_; \
136 lg %r1,errno@GOT(%r1); \
137 lcr %r2,%r2; \
138 st %r2,0(%r1); \
139 lghi %r2,-1; \
140 br %r14
141 # endif /* _LIBC_REENTRANT */
142 #endif /* PIC */
144 /* Linux takes system call arguments in registers:
146 syscall number 1 call-clobbered
147 arg 1 2 call-clobbered
148 arg 2 3 call-clobbered
149 arg 3 4 call-clobbered
150 arg 4 5 call-clobbered
151 arg 5 6 call-saved
153 (Of course a function with say 3 arguments does not have entries for
154 arguments 4 and 5.)
155 S390 does not need to do ANY stack operations to get its parameters
156 right.
159 #define DO_CALL(syscall, args) \
160 .if SYS_ify (syscall) < 256; \
161 svc SYS_ify (syscall); \
162 .else; \
163 lghi %r1,SYS_ify (syscall); \
164 svc 0; \
165 .endif
167 #define ret \
168 br 14
170 #define ret_NOERRNO \
171 br 14
173 #define ret_ERRVAL \
174 br 14
176 #endif /* __ASSEMBLER__ */
178 #undef INLINE_SYSCALL
179 #define INLINE_SYSCALL(name, nr, args...) \
180 ({ \
181 long _ret = INTERNAL_SYSCALL (name, , nr, args); \
182 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_ret, ), 0)) \
184 __set_errno (INTERNAL_SYSCALL_ERRNO (_ret, )); \
185 _ret = -1; \
187 _ret; })
189 #undef INTERNAL_SYSCALL_DECL
190 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
192 #undef INTERNAL_SYSCALL_DIRECT
193 #define INTERNAL_SYSCALL_DIRECT(name, err, nr, args...) \
194 ({ \
195 DECLARGS_##nr(args) \
196 register long _ret asm("2"); \
197 asm volatile ( \
198 "svc %b1\n\t" \
199 : "=d" (_ret) \
200 : "i" (__NR_##name) ASMFMT_##nr \
201 : "memory" ); \
202 _ret; })
204 #undef INTERNAL_SYSCALL_SVC0
205 #define INTERNAL_SYSCALL_SVC0(name, err, nr, args...) \
206 ({ \
207 DECLARGS_##nr(args) \
208 register unsigned long _nr asm("1") = (unsigned long)(__NR_##name); \
209 register long _ret asm("2"); \
210 asm volatile ( \
211 "svc 0\n\t" \
212 : "=d" (_ret) \
213 : "d" (_nr) ASMFMT_##nr \
214 : "memory" ); \
215 _ret; })
217 #undef INTERNAL_SYSCALL_NCS
218 #define INTERNAL_SYSCALL_NCS(no, err, nr, args...) \
219 ({ \
220 DECLARGS_##nr(args) \
221 register unsigned long _nr asm("1") = (unsigned long)(no); \
222 register long _ret asm("2"); \
223 asm volatile ( \
224 "svc 0\n\t" \
225 : "=d" (_ret) \
226 : "d" (_nr) ASMFMT_##nr \
227 : "memory" ); \
228 _ret; })
230 #undef INTERNAL_SYSCALL
231 #define INTERNAL_SYSCALL(name, err, nr, args...) \
232 (((__NR_##name) < 256) ? \
233 INTERNAL_SYSCALL_DIRECT(name, err, nr, args) : \
234 INTERNAL_SYSCALL_SVC0(name, err,nr, args))
236 #undef INTERNAL_SYSCALL_ERROR_P
237 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
238 ((unsigned long) (val) >= -4095UL)
240 #undef INTERNAL_SYSCALL_ERRNO
241 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
243 #define DECLARGS_0()
244 #define DECLARGS_1(arg1) \
245 register unsigned long gpr2 asm ("2") = (unsigned long)(arg1);
246 #define DECLARGS_2(arg1, arg2) \
247 DECLARGS_1(arg1) \
248 register unsigned long gpr3 asm ("3") = (unsigned long)(arg2);
249 #define DECLARGS_3(arg1, arg2, arg3) \
250 DECLARGS_2(arg1, arg2) \
251 register unsigned long gpr4 asm ("4") = (unsigned long)(arg3);
252 #define DECLARGS_4(arg1, arg2, arg3, arg4) \
253 DECLARGS_3(arg1, arg2, arg3) \
254 register unsigned long gpr5 asm ("5") = (unsigned long)(arg4);
255 #define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
256 DECLARGS_4(arg1, arg2, arg3, arg4) \
257 register unsigned long gpr6 asm ("6") = (unsigned long)(arg5);
259 #define ASMFMT_0
260 #define ASMFMT_1 , "0" (gpr2)
261 #define ASMFMT_2 , "0" (gpr2), "d" (gpr3)
262 #define ASMFMT_3 , "0" (gpr2), "d" (gpr3), "d" (gpr4)
263 #define ASMFMT_4 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5)
264 #define ASMFMT_5 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6)
266 #endif /* _LINUX_S390_SYSDEP_H */