1 /* Copyright (C) 2000,01,02,03 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
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>
26 /* For Linux we can use the system call table in the header file
27 /usr/include/asm/unistd.h
28 of the kernel. But these symbols do not follow the SYS_* syntax
29 so we have to redefine the `SYS_ify' macro here. */
30 /* in newer 2.1 kernels __NR_syscall is missing so we define it here */
31 #define __NR_syscall 0
34 #define SYS_ify(syscall_name) __NR_##syscall_name
38 /* Linux uses a negative return value to indicate syscall errors, unlike
39 most Unices, which use the condition codes' carry flag.
41 Since version 2.1 the return value of a system call might be negative
42 even if the call succeeded. E.g., the `lseek' system call might return
43 a large offset. Therefore we must not anymore test for < 0, but test
44 for a real error by making sure the value in gpr2 is a real error
45 number. Linus said he will make sure the no syscall returns a value
46 in -1 .. -4095 as a valid result so we can savely test with -4095. */
48 #define SYSCALL_ERROR_LABEL 0f
51 #define PSEUDO(name, syscall_name, args) \
54 DO_CALL (syscall_name, args); \
57 jnl SYSCALL_ERROR_LABEL ; \
61 #define PSEUDO_END(name) \
62 SYSCALL_ERROR_HANDLER; \
65 #ifndef _LIBC_REENTRANT
67 #define SYSCALL_ERROR_HANDLER \
76 #define SYSCALL_ERROR_HANDLER \
78 1: al %r1,2f-1b(%r1) ; \
79 l %r1,errno@GOT12(%r1) ; \
84 2: .long _GLOBAL_OFFSET_TABLE_-1b
87 #define SYSCALL_ERROR_HANDLER \
89 1: al %r1,2f-1b(%r1) ; \
91 2: .long __syscall_error@PLT-1b
92 #endif /* _LIBC_REENTRANT */
94 /* Linux takes system call arguments in registers:
96 syscall number 1 call-clobbered
97 arg 1 2 call-clobbered
98 arg 2 3 call-clobbered
99 arg 3 4 call-clobbered
100 arg 4 5 call-clobbered
103 (Of course a function with say 3 arguments does not have entries for
105 S390 does not need to do ANY stack operations to get its parameters
109 #define DO_CALL(syscall, args) \
110 svc SYS_ify (syscall)
115 #endif /* __ASSEMBLER__ */
117 #undef INLINE_SYSCALL
118 #define INLINE_SYSCALL(name, nr, args...) \
120 unsigned int _ret = INTERNAL_SYSCALL (name, , nr, args); \
121 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_ret, ), 0)) \
123 __set_errno (INTERNAL_SYSCALL_ERRNO (_ret, )); \
128 #undef INTERNAL_SYSCALL_DECL
129 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
131 #undef INTERNAL_SYSCALL
132 #define INTERNAL_SYSCALL(name, err, nr, args...) \
134 DECLARGS_##nr(args) \
141 : "I" (__NR_##name) ASMFMT_##nr \
142 : "memory", "cc", "2", "3", "4", "5", "6"); \
145 #undef INTERNAL_SYSCALL_ERROR_P
146 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
147 ((unsigned int) (val) >= 0xfffff001u)
149 #undef INTERNAL_SYSCALL_ERRNO
150 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
153 #define DECLARGS_1(arg1) \
154 unsigned int gpr2 = (unsigned int) (arg1);
155 #define DECLARGS_2(arg1, arg2) \
157 unsigned int gpr3 = (unsigned int) (arg2);
158 #define DECLARGS_3(arg1, arg2, arg3) \
159 DECLARGS_2(arg1, arg2) \
160 unsigned int gpr4 = (unsigned int) (arg3);
161 #define DECLARGS_4(arg1, arg2, arg3, arg4) \
162 DECLARGS_3(arg1, arg2, arg3) \
163 unsigned int gpr5 = (unsigned int) (arg4);
164 #define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
165 DECLARGS_4(arg1, arg2, arg3, arg4) \
166 unsigned int gpr6 = (unsigned int) (arg5);
169 #define LOADARGS_1 "L 2,%2\n\t"
170 #define LOADARGS_2 LOADARGS_1 "L 3,%3\n\t"
171 #define LOADARGS_3 LOADARGS_2 "L 4,%4\n\t"
172 #define LOADARGS_4 LOADARGS_3 "L 5,%5\n\t"
173 #define LOADARGS_5 LOADARGS_4 "L 6,%6\n\t"
176 #define ASMFMT_1 , "m" (gpr2)
177 #define ASMFMT_2 , "m" (gpr2), "m" (gpr3)
178 #define ASMFMT_3 , "m" (gpr2), "m" (gpr3), "m" (gpr4)
179 #define ASMFMT_4 , "m" (gpr2), "m" (gpr3), "m" (gpr4), "m" (gpr5)
180 #define ASMFMT_5 , "m" (gpr2), "m" (gpr3), "m" (gpr4), "m" (gpr5), "m" (gpr6)
183 #undef INLINE_SYSCALL
184 #define INLINE_SYSCALL(name, nr, args...) \
186 DECLARGS_##nr(args) \
190 : "I" (__NR_##name) ASMFMT_##nr : "memory", "cc"); \
191 if (gpr2 >= 0xfffff001) \
193 __set_errno(-gpr2); \
198 #define DECLARGS_0() \
199 register unsigned int gpr2 asm("2");
200 #define DECLARGS_1(arg1) \
201 register unsigned int gpr2 asm("2") = (unsigned int) (arg1);
202 #define DECLARGS_2(arg1, arg2) \
204 register unsigned int gpr3 asm("3") = (unsigned int) (arg2);
205 #define DECLARGS_3(arg1, arg2, arg3) \
206 DECLARGS_2(arg1, arg2) \
207 register unsigned int gpr4 asm("4") = (unsigned int) (arg3);
208 #define DECLARGS_4(arg1, arg2, arg3, arg4) \
209 DECLARGS_3(arg1, arg2, arg3) \
210 register unsigned int gpr5 asm("5") = (unsigned int) (arg4);
211 #define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
212 DECLARGS_4(arg1, arg2, arg3, arg4) \
213 register unsigned int gpr6 asm("6") = (unsigned int) (arg5);
217 #define ASMFMT_2 , "d" (gpr3)
218 #define ASMFMT_3 , "d" (gpr3), "d" (gpr4)
219 #define ASMFMT_4 , "d" (gpr3), "d" (gpr4), "d" (gpr5)
220 #define ASMFMT_5 , "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6)
224 #endif /* _LINUX_S390_SYSDEP_H */