Updated to fedora-glibc-20060102T2114
[glibc.git] / sysdeps / unix / sysv / linux / s390 / s390-64 / sysdep.h
blobaadbf74c2b88a399002ac88ada32671ef15228dd
1 /* Assembler macros for 64 bit S/390.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005 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. */
27 #include <tls.h>
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 * Newer kernel versions redefined __NR_pread and __NR_pwrite to
38 * __NR_pread64 and __NR_pwrite64.
40 #ifndef __NR_pread
41 # define __NR_pread __NR_pread64
42 #endif
43 #ifndef __NR_pwrite
44 # define __NR_pwrite __NR_pwrite64
45 #endif
47 #undef SYS_ify
48 #define SYS_ify(syscall_name) __NR_##syscall_name
50 #ifdef __ASSEMBLER__
52 /* Linux uses a negative return value to indicate syscall errors, unlike
53 most Unices, which use the condition codes' carry flag.
55 Since version 2.1 the return value of a system call might be negative
56 even if the call succeeded. E.g., the `lseek' system call might return
57 a large offset. Therefore we must not anymore test for < 0, but test
58 for a real error by making sure the value in gpr2 is a real error
59 number. Linus said he will make sure the no syscall returns a value
60 in -1 .. -4095 as a valid result so we can savely test with -4095. */
62 #undef PSEUDO
63 #define PSEUDO(name, syscall_name, args) \
64 .text; \
65 ENTRY (name) \
66 DO_CALL (syscall_name, args); \
67 lghi %r4,-4095 ; \
68 clgr %r2,%r4 ; \
69 jgnl SYSCALL_ERROR_LABEL
71 #undef PSEUDO_END
72 #define PSEUDO_END(name) \
73 SYSCALL_ERROR_HANDLER; \
74 END (name)
76 #undef PSEUDO_NOERRNO
77 #define PSEUDO_NOERRNO(name, syscall_name, args) \
78 .text; \
79 ENTRY (name) \
80 DO_CALL (syscall_name, args)
82 #undef PSEUDO_END_NOERRNO
83 #define PSEUDO_END_NOERRNO(name) \
84 SYSCALL_ERROR_HANDLER; \
85 END (name)
87 #undef PSEUDO_ERRVAL
88 #define PSEUDO_ERRVAL(name, syscall_name, args) \
89 .text; \
90 ENTRY (name) \
91 DO_CALL (syscall_name, args); \
92 lcgr %r2,%r2
94 #undef PSEUDO_END_ERRVAL
95 #define PSEUDO_END_ERRVAL(name) \
96 SYSCALL_ERROR_HANDLER; \
97 END (name)
99 #ifndef PIC
100 # define SYSCALL_ERROR_LABEL syscall_error
101 # define SYSCALL_ERROR_HANDLER
102 #else
103 # if RTLD_PRIVATE_ERRNO
104 # define SYSCALL_ERROR_LABEL 0f
105 # define SYSCALL_ERROR_HANDLER \
106 0: larl %r1,rtld_errno; \
107 lcr %r2,%r2; \
108 st %r2,0(%r1); \
109 lghi %r2,-1; \
110 br %r14
111 # elif defined _LIBC_REENTRANT
112 # if USE___THREAD
113 # ifndef NOT_IN_libc
114 # define SYSCALL_ERROR_ERRNO __libc_errno
115 # else
116 # define SYSCALL_ERROR_ERRNO errno
117 # endif
118 # define SYSCALL_ERROR_LABEL 0f
119 # define SYSCALL_ERROR_HANDLER \
120 0: lcr %r0,%r2; \
121 larl %r1,SYSCALL_ERROR_ERRNO@indntpoff; \
122 lg %r1,0(%r1); \
123 ear %r2,%a0; \
124 sllg %r2,%r2,32; \
125 ear %r2,%a1; \
126 st %r0,0(%r1,%r2); \
127 lghi %r2,-1; \
128 br %r14
129 # else
130 # define SYSCALL_ERROR_LABEL syscall_error@plt
131 # define SYSCALL_ERROR_HANDLER
132 # endif
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 */
145 /* Linux takes system call arguments in registers:
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
154 (Of course a function with say 3 arguments does not have entries for
155 arguments 4 and 5.)
156 S390 does not need to do ANY stack operations to get its parameters
157 right.
160 #define DO_CALL(syscall, args) \
161 .if SYS_ify (syscall) < 256; \
162 svc SYS_ify (syscall); \
163 .else; \
164 lghi %r1,SYS_ify (syscall); \
165 svc 0; \
166 .endif
168 #define ret \
169 br 14
171 #define ret_NOERRNO \
172 br 14
174 #define ret_ERRVAL \
175 br 14
177 #endif /* __ASSEMBLER__ */
179 #undef INLINE_SYSCALL
180 #define INLINE_SYSCALL(name, nr, args...) \
181 ({ \
182 long _ret = INTERNAL_SYSCALL (name, , nr, args); \
183 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_ret, ), 0)) \
185 __set_errno (INTERNAL_SYSCALL_ERRNO (_ret, )); \
186 _ret = -1; \
188 _ret; })
190 #undef INTERNAL_SYSCALL_DECL
191 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
193 #undef INTERNAL_SYSCALL_DIRECT
194 #define INTERNAL_SYSCALL_DIRECT(name, err, nr, args...) \
195 ({ \
196 DECLARGS_##nr(args) \
197 register long _ret asm("2"); \
198 asm volatile ( \
199 "svc %b1\n\t" \
200 : "=d" (_ret) \
201 : "i" (__NR_##name) ASMFMT_##nr \
202 : "memory" ); \
203 _ret; })
205 #undef INTERNAL_SYSCALL_SVC0
206 #define INTERNAL_SYSCALL_SVC0(name, err, nr, args...) \
207 ({ \
208 DECLARGS_##nr(args) \
209 register unsigned long _nr asm("1") = (unsigned long)(__NR_##name); \
210 register long _ret asm("2"); \
211 asm volatile ( \
212 "svc 0\n\t" \
213 : "=d" (_ret) \
214 : "d" (_nr) ASMFMT_##nr \
215 : "memory" ); \
216 _ret; })
218 #undef INTERNAL_SYSCALL_NCS
219 #define INTERNAL_SYSCALL_NCS(no, err, nr, args...) \
220 ({ \
221 DECLARGS_##nr(args) \
222 register unsigned long _nr asm("1") = (unsigned long)(no); \
223 register long _ret asm("2"); \
224 asm volatile ( \
225 "svc 0\n\t" \
226 : "=d" (_ret) \
227 : "d" (_nr) ASMFMT_##nr \
228 : "memory" ); \
229 _ret; })
231 #undef INTERNAL_SYSCALL
232 #define INTERNAL_SYSCALL(name, err, nr, args...) \
233 (((__NR_##name) < 256) ? \
234 INTERNAL_SYSCALL_DIRECT(name, err, nr, args) : \
235 INTERNAL_SYSCALL_SVC0(name, err,nr, args))
237 #undef INTERNAL_SYSCALL_ERROR_P
238 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
239 ((unsigned long) (val) >= -4095UL)
241 #undef INTERNAL_SYSCALL_ERRNO
242 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
244 #define DECLARGS_0()
245 #define DECLARGS_1(arg1) \
246 register unsigned long gpr2 asm ("2") = (unsigned long)(arg1);
247 #define DECLARGS_2(arg1, arg2) \
248 DECLARGS_1(arg1) \
249 register unsigned long gpr3 asm ("3") = (unsigned long)(arg2);
250 #define DECLARGS_3(arg1, arg2, arg3) \
251 DECLARGS_2(arg1, arg2) \
252 register unsigned long gpr4 asm ("4") = (unsigned long)(arg3);
253 #define DECLARGS_4(arg1, arg2, arg3, arg4) \
254 DECLARGS_3(arg1, arg2, arg3) \
255 register unsigned long gpr5 asm ("5") = (unsigned long)(arg4);
256 #define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
257 DECLARGS_4(arg1, arg2, arg3, arg4) \
258 register unsigned long gpr6 asm ("6") = (unsigned long)(arg5);
260 #define ASMFMT_0
261 #define ASMFMT_1 , "0" (gpr2)
262 #define ASMFMT_2 , "0" (gpr2), "d" (gpr3)
263 #define ASMFMT_3 , "0" (gpr2), "d" (gpr3), "d" (gpr4)
264 #define ASMFMT_4 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5)
265 #define ASMFMT_5 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6)
267 /* Pointer mangling support. */
268 #if defined NOT_IN_libc && defined IS_IN_rtld
269 /* We cannot use the thread descriptor because in ld.so we use setjmp
270 earlier than the descriptor is initialized. */
271 #else
272 /* For the time being just use stack_guard rather than a separate
273 pointer_guard. */
274 # ifdef __ASSEMBLER__
275 # define PTR_MANGLE(reg, tmpreg) \
276 ear tmpreg,%a0; \
277 sllg tmpreg,tmpreg,32; \
278 ear tmpreg,%a1; \
279 xg reg,STACK_GUARD(tmpreg)
280 # define PTR_MANGLE2(reg, tmpreg) \
281 xg reg,STACK_GUARD(tmpreg)
282 # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
283 # else
284 # define PTR_MANGLE(var) \
285 (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
286 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
287 # endif
288 #endif
290 #endif /* _LINUX_S390_SYSDEP_H */