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
36 /* ELF-like local names start with `.L'. */
38 #define L(name) .L##name
42 /* Linux uses a negative return value to indicate syscall errors, unlike
43 most Unices, which use the condition codes' carry flag.
45 Since version 2.1 the return value of a system call might be negative
46 even if the call succeeded. E.g., the `lseek' system call might return
47 a large offset. Therefore we must not anymore test for < 0, but test
48 for a real error by making sure the value in gpr2 is a real error
49 number. Linus said he will make sure the no syscall returns a value
50 in -1 .. -4095 as a valid result so we can savely test with -4095. */
52 #define SYSCALL_ERROR_LABEL 0f
55 #define PSEUDO(name, syscall_name, args) \
58 DO_CALL (syscall_name, args); \
61 jnl SYSCALL_ERROR_LABEL ; \
65 #define PSEUDO_END(name) \
66 SYSCALL_ERROR_HANDLER; \
69 #ifndef _LIBC_REENTRANT
71 #define SYSCALL_ERROR_HANDLER \
80 #define SYSCALL_ERROR_HANDLER \
82 1: al %r1,2f-1b(%r1) ; \
83 l %r1,errno@GOT12(%r1) ; \
88 2: .long _GLOBAL_OFFSET_TABLE_-1b
91 #define SYSCALL_ERROR_HANDLER \
93 1: al %r1,2f-1b(%r1) ; \
95 2: .long __syscall_error@PLT-1b
96 #endif /* _LIBC_REENTRANT */
98 /* Linux takes system call arguments in registers:
100 syscall number 1 call-clobbered
101 arg 1 2 call-clobbered
102 arg 2 3 call-clobbered
103 arg 3 4 call-clobbered
104 arg 4 5 call-clobbered
107 (Of course a function with say 3 arguments does not have entries for
109 S390 does not need to do ANY stack operations to get its parameters
113 #define DO_CALL(syscall, args) \
114 svc SYS_ify (syscall)
119 #endif /* __ASSEMBLER__ */
121 #undef INLINE_SYSCALL
122 #define INLINE_SYSCALL(name, nr, args...) \
124 unsigned int _ret = INTERNAL_SYSCALL (name, , nr, args); \
125 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_ret, ), 0)) \
127 __set_errno (INTERNAL_SYSCALL_ERRNO (_ret, )); \
132 #undef INTERNAL_SYSCALL_DECL
133 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
135 #undef INTERNAL_SYSCALL
136 #define INTERNAL_SYSCALL(name, err, nr, args...) \
138 DECLARGS_##nr(args) \
145 : "I" (__NR_##name) ASMFMT_##nr \
146 : "memory", "cc", "2", "3", "4", "5", "6"); \
149 #undef INTERNAL_SYSCALL_ERROR_P
150 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
151 ((unsigned int) (val) >= 0xfffff001u)
153 #undef INTERNAL_SYSCALL_ERRNO
154 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
157 #define DECLARGS_1(arg1) \
158 unsigned int gpr2 = (unsigned int) (arg1);
159 #define DECLARGS_2(arg1, arg2) \
161 unsigned int gpr3 = (unsigned int) (arg2);
162 #define DECLARGS_3(arg1, arg2, arg3) \
163 DECLARGS_2(arg1, arg2) \
164 unsigned int gpr4 = (unsigned int) (arg3);
165 #define DECLARGS_4(arg1, arg2, arg3, arg4) \
166 DECLARGS_3(arg1, arg2, arg3) \
167 unsigned int gpr5 = (unsigned int) (arg4);
168 #define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
169 DECLARGS_4(arg1, arg2, arg3, arg4) \
170 unsigned int gpr6 = (unsigned int) (arg5);
173 #define LOADARGS_1 "L 2,%2\n\t"
174 #define LOADARGS_2 LOADARGS_1 "L 3,%3\n\t"
175 #define LOADARGS_3 LOADARGS_2 "L 4,%4\n\t"
176 #define LOADARGS_4 LOADARGS_3 "L 5,%5\n\t"
177 #define LOADARGS_5 LOADARGS_4 "L 6,%6\n\t"
180 #define ASMFMT_1 , "m" (gpr2)
181 #define ASMFMT_2 , "m" (gpr2), "m" (gpr3)
182 #define ASMFMT_3 , "m" (gpr2), "m" (gpr3), "m" (gpr4)
183 #define ASMFMT_4 , "m" (gpr2), "m" (gpr3), "m" (gpr4), "m" (gpr5)
184 #define ASMFMT_5 , "m" (gpr2), "m" (gpr3), "m" (gpr4), "m" (gpr5), "m" (gpr6)
187 #undef INLINE_SYSCALL
188 #define INLINE_SYSCALL(name, nr, args...) \
190 DECLARGS_##nr(args) \
194 : "I" (__NR_##name) ASMFMT_##nr : "memory", "cc"); \
195 if (gpr2 >= 0xfffff001) \
197 __set_errno(-gpr2); \
202 #define DECLARGS_0() \
203 register unsigned int gpr2 asm("2");
204 #define DECLARGS_1(arg1) \
205 register unsigned int gpr2 asm("2") = (unsigned int) (arg1);
206 #define DECLARGS_2(arg1, arg2) \
208 register unsigned int gpr3 asm("3") = (unsigned int) (arg2);
209 #define DECLARGS_3(arg1, arg2, arg3) \
210 DECLARGS_2(arg1, arg2) \
211 register unsigned int gpr4 asm("4") = (unsigned int) (arg3);
212 #define DECLARGS_4(arg1, arg2, arg3, arg4) \
213 DECLARGS_3(arg1, arg2, arg3) \
214 register unsigned int gpr5 asm("5") = (unsigned int) (arg4);
215 #define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
216 DECLARGS_4(arg1, arg2, arg3, arg4) \
217 register unsigned int gpr6 asm("6") = (unsigned int) (arg5);
221 #define ASMFMT_2 , "d" (gpr3)
222 #define ASMFMT_3 , "d" (gpr3), "d" (gpr4)
223 #define ASMFMT_4 , "d" (gpr3), "d" (gpr4), "d" (gpr5)
224 #define ASMFMT_5 , "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6)
228 #endif /* _LINUX_S390_SYSDEP_H */