(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / unix / sysv / linux / s390 / s390-32 / sysdep.h
blob43b1b951d580b9774eb2042444ad72ab22b1d832
1 /* Copyright (C) 2000,01,02,03,04 Free Software Foundation, Inc.
2 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _LINUX_S390_SYSDEP_H
21 #define _LINUX_S390_SYSDEP_H
23 #include <sysdeps/s390/s390-32/sysdep.h>
24 #include <sysdeps/unix/sysdep.h>
25 #include <dl-sysdep.h> /* For RTLD_PRIVATE_ERRNO. */
27 /* For Linux we can use the system call table in the header file
28 /usr/include/asm/unistd.h
29 of the kernel. But these symbols do not follow the SYS_* syntax
30 so we have to redefine the `SYS_ify' macro here. */
31 /* in newer 2.1 kernels __NR_syscall is missing so we define it here */
32 #define __NR_syscall 0
34 #undef SYS_ify
35 #define SYS_ify(syscall_name) __NR_##syscall_name
37 #ifdef __ASSEMBLER__
39 /* Linux uses a negative return value to indicate syscall errors, unlike
40 most Unices, which use the condition codes' carry flag.
42 Since version 2.1 the return value of a system call might be negative
43 even if the call succeeded. E.g., the `lseek' system call might return
44 a large offset. Therefore we must not anymore test for < 0, but test
45 for a real error by making sure the value in gpr2 is a real error
46 number. Linus said he will make sure the no syscall returns a value
47 in -1 .. -4095 as a valid result so we can savely test with -4095. */
49 #undef PSEUDO
50 #define PSEUDO(name, syscall_name, args) \
51 .text; \
52 ENTRY (name) \
53 DO_CALL (syscall_name, args); \
54 lhi %r4,-4095 ; \
55 clr %r2,%r4 ; \
56 jnl SYSCALL_ERROR_LABEL
58 #undef PSEUDO_END
59 #define PSEUDO_END(name) \
60 SYSCALL_ERROR_HANDLER; \
61 END (name)
63 #undef PSEUDO_NOERRNO
64 #define PSEUDO_NOERRNO(name, syscall_name, args) \
65 .text; \
66 ENTRY (name) \
67 DO_CALL (syscall_name, args)
69 #undef PSEUDO_END_NOERRNO
70 #define PSEUDO_END_NOERRNO(name) \
71 END (name)
73 #undef PSEUDO_ERRVAL
74 #define PSEUDO_ERRVAL(name, syscall_name, args) \
75 .text; \
76 ENTRY (name) \
77 DO_CALL (syscall_name, args); \
78 lcr %r2,%r2
80 #undef PSEUDO_END_ERRVAL
81 #define PSEUDO_END_ERRVAL(name) \
82 END (name)
84 #ifndef PIC
85 # define SYSCALL_ERROR_LABEL 0f
86 # define SYSCALL_ERROR_HANDLER \
87 0: basr %r1,0; \
88 1: l %r1,2f-1b(%r1); \
89 br %r1; \
90 2: .long syscall_error
91 #else
92 # if RTLD_PRIVATE_ERRNO
93 # define SYSCALL_ERROR_LABEL 0f
94 # define SYSCALL_ERROR_HANDLER \
95 0: basr %r1,0; \
96 1: al %r1,2f-1b(%r1); \
97 lcr %r2,%r2; \
98 st %r2,0(%r1); \
99 lhi %r2,-1; \
100 br %r14; \
101 2: .long rtld_errno-1b
102 # elif defined _LIBC_REENTRANT
103 # if USE___THREAD
104 # ifndef NOT_IN_libc
105 # define SYSCALL_ERROR_ERRNO __libc_errno
106 # else
107 # define SYSCALL_ERROR_ERRNO errno
108 # endif
109 # define SYSCALL_ERROR_LABEL 0f
110 # define SYSCALL_ERROR_HANDLER \
111 0: lcr %r0,%r2; \
112 basr %r1,0; \
113 1: al %r1,2f-1b(%r1); \
114 l %r1,SYSCALL_ERROR_ERRNO@gotntpoff(%r1) \
115 ear %r2,%a0 \
116 st %r0,0(%r1,%r2); \
117 lhi %r2,-1; \
118 br %r14; \
119 2: .long _GLOBAL_OFFSET_TABLE_-1b
120 # else
121 # define SYSCALL_ERROR_LABEL 0f
122 # define SYSCALL_ERROR_HANDLER \
123 0: basr %r1,0; \
124 1: al %r1,2f-1b(%r1); \
125 br %r1; \
126 2: .long syscall_error@plt-1b
127 # endif
128 # else
129 # define SYSCALL_ERROR_LABEL 0f
130 # define SYSCALL_ERROR_HANDLER \
131 0: basr %r1,0; \
132 1: al %r1,2f-1b(%r1); \
133 l %r1,errno@GOT(%r1); \
134 lcr %r2,%r2; \
135 st %r2,0(%r1); \
136 lhi %r2,-1; \
137 br %r14; \
138 2: .long _GLOBAL_OFFSET_TABLE_-1b
139 # endif /* _LIBC_REENTRANT */
140 #endif /* PIC */
142 /* Linux takes system call arguments in registers:
144 syscall number 1 call-clobbered
145 arg 1 2 call-clobbered
146 arg 2 3 call-clobbered
147 arg 3 4 call-clobbered
148 arg 4 5 call-clobbered
149 arg 5 6 call-saved
151 (Of course a function with say 3 arguments does not have entries for
152 arguments 4 and 5.)
153 S390 does not need to do ANY stack operations to get its parameters
154 right.
157 #define DO_CALL(syscall, args) \
158 .if SYS_ify (syscall) < 256; \
159 svc SYS_ify (syscall); \
160 .else; \
161 lhi %r1,SYS_ify (syscall); \
162 svc 0; \
163 .endif
165 #define ret \
166 br 14
168 #define ret_NOERRNO \
169 br 14
171 #define ret_ERRVAL \
172 br 14
174 #endif /* __ASSEMBLER__ */
176 #undef INLINE_SYSCALL
177 #define INLINE_SYSCALL(name, nr, args...) \
178 ({ \
179 unsigned int _ret = INTERNAL_SYSCALL (name, , nr, args); \
180 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_ret, ), 0)) \
182 __set_errno (INTERNAL_SYSCALL_ERRNO (_ret, )); \
183 _ret = 0xffffffff; \
185 (int) _ret; })
187 #undef INTERNAL_SYSCALL_DECL
188 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
190 #undef INTERNAL_SYSCALL_DIRECT
191 #define INTERNAL_SYSCALL_DIRECT(name, err, nr, args...) \
192 ({ \
193 DECLARGS_##nr(args) \
194 register int _ret asm("2"); \
195 asm volatile ( \
196 "svc %b1\n\t" \
197 : "=d" (_ret) \
198 : "i" (__NR_##name) ASMFMT_##nr \
199 : "memory" ); \
200 _ret; })
202 #undef INTERNAL_SYSCALL_SVC0
203 #define INTERNAL_SYSCALL_SVC0(name, err, nr, args...) \
204 ({ \
205 DECLARGS_##nr(args) \
206 register unsigned long _nr asm("1") = (unsigned long)(__NR_##name); \
207 register int _ret asm("2"); \
208 asm volatile ( \
209 "svc 0\n\t" \
210 : "=d" (_ret) \
211 : "d" (_nr) ASMFMT_##nr \
212 : "memory" ); \
213 _ret; })
215 #undef INTERNAL_SYSCALL_NCS
216 #define INTERNAL_SYSCALL_NCS(no, err, nr, args...) \
217 ({ \
218 DECLARGS_##nr(args) \
219 register unsigned long _nr asm("1") = (unsigned long)(no); \
220 register int _ret asm("2"); \
221 asm volatile ( \
222 "svc 0\n\t" \
223 : "=d" (_ret) \
224 : "d" (_nr) ASMFMT_##nr \
225 : "memory" ); \
226 _ret; })
228 #undef INTERNAL_SYSCALL
229 #define INTERNAL_SYSCALL(name, err, nr, args...) \
230 (((__NR_##name) < 256) ? \
231 INTERNAL_SYSCALL_DIRECT(name, err, nr, args) : \
232 INTERNAL_SYSCALL_SVC0(name, err,nr, args))
234 #undef INTERNAL_SYSCALL_ERROR_P
235 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
236 ((unsigned int) (val) >= 0xfffff001u)
238 #undef INTERNAL_SYSCALL_ERRNO
239 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
241 #define DECLARGS_0()
242 #define DECLARGS_1(arg1) \
243 register unsigned long gpr2 asm ("2") = (unsigned long)(arg1);
244 #define DECLARGS_2(arg1, arg2) \
245 DECLARGS_1(arg1) \
246 register unsigned long gpr3 asm ("3") = (unsigned long)(arg2);
247 #define DECLARGS_3(arg1, arg2, arg3) \
248 DECLARGS_2(arg1, arg2) \
249 register unsigned long gpr4 asm ("4") = (unsigned long)(arg3);
250 #define DECLARGS_4(arg1, arg2, arg3, arg4) \
251 DECLARGS_3(arg1, arg2, arg3) \
252 register unsigned long gpr5 asm ("5") = (unsigned long)(arg4);
253 #define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
254 DECLARGS_4(arg1, arg2, arg3, arg4) \
255 register unsigned long gpr6 asm ("6") = (unsigned long)(arg5);
257 #define ASMFMT_0
258 #define ASMFMT_1 , "0" (gpr2)
259 #define ASMFMT_2 , "0" (gpr2), "d" (gpr3)
260 #define ASMFMT_3 , "0" (gpr2), "d" (gpr3), "d" (gpr4)
261 #define ASMFMT_4 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5)
262 #define ASMFMT_5 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6)
264 #endif /* _LINUX_S390_SYSDEP_H */