1 /* Assembler macros for 64 bit S/390.
2 Copyright (C) 2001,02 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
21 #ifndef _LINUX_S390_SYSDEP_H
22 #define _LINUX_S390_SYSEDP_H
24 #include <sysdeps/s390/s390-64/sysdep.h>
25 #include <sysdeps/unix/sysdep.h>
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
35 #define SYS_ify(syscall_name) __NR_##syscall_name
37 /* ELF-like local names start with `.L'. */
39 #define L(name) .L##name
43 /* Linux uses a negative return value to indicate syscall errors, unlike
44 most Unices, which use the condition codes' carry flag.
46 Since version 2.1 the return value of a system call might be negative
47 even if the call succeeded. E.g., the `lseek' system call might return
48 a large offset. Therefore we must not anymore test for < 0, but test
49 for a real error by making sure the value in gpr2 is a real error
50 number. Linus said he will make sure the no syscall returns a value
51 in -1 .. -4095 as a valid result so we can savely test with -4095. */
53 #define SYSCALL_ERROR_LABEL 0f
56 #define PSEUDO(name, syscall_name, args) \
59 DO_CALL (syscall_name, args); \
62 jnl SYSCALL_ERROR_LABEL ; \
66 #define PSEUDO_END(name) \
67 SYSCALL_ERROR_HANDLER; \
70 #ifndef _LIBC_REENTRANT
72 #define SYSCALL_ERROR_HANDLER \
79 #define SYSCALL_ERROR_HANDLER \
80 0: larl %r1,_GLOBAL_OFFSET_TABLE_ ; \
81 lg %r1,errno@GOT(%r1) ; \
88 #define SYSCALL_ERROR_HANDLER \
89 0: jg __syscall_error@PLT
90 #endif /* _LIBC_REENTRANT */
92 /* Linux takes system call arguments in registers:
94 syscall number 1 call-clobbered
95 arg 1 2 call-clobbered
96 arg 2 3 call-clobbered
97 arg 3 4 call-clobbered
98 arg 4 5 call-clobbered
101 (Of course a function with say 3 arguments does not have entries for
103 S390 does not need to do ANY stack operations to get its parameters
107 #define DO_CALL(syscall, args) \
108 svc SYS_ify (syscall)
113 #endif /* __ASSEMBLER__ */
115 #undef INLINE_SYSCALL
116 #define INLINE_SYSCALL(name, nr, args...) \
118 unsigned int _ret = INTERNAL_SYSCALL (name, , nr, args); \
119 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_ret, ), 0)) \
121 __set_errno (INTERNAL_SYSCALL_ERRNO (_ret, )); \
126 #undef INTERNAL_SYSCALL_DECL
127 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
129 #undef INTERNAL_SYSCALL
130 #define INTERNAL_SYSCALL(name, err, nr, args...) \
132 DECLARGS_##nr(args) \
139 : "I" (__NR_##name) ASMFMT_##nr \
140 : "memory", "cc", "2", "3", "4", "5", "6"); \
143 #undef INTERNAL_SYSCALL_ERROR_P
144 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
145 ((unsigned int) (val) >= 0xfffff001u)
147 #undef INTERNAL_SYSCALL_ERRNO
148 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
151 #define DECLARGS_1(arg1) \
152 unsigned long gpr2 = (unsigned long) (arg1);
153 #define DECLARGS_2(arg1, arg2) \
155 unsigned long gpr3 = (unsigned long) (arg2);
156 #define DECLARGS_3(arg1, arg2, arg3) \
157 DECLARGS_2(arg1, arg2) \
158 unsigned long gpr4 = (unsigned long) (arg3);
159 #define DECLARGS_4(arg1, arg2, arg3, arg4) \
160 DECLARGS_3(arg1, arg2, arg3) \
161 unsigned long gpr5 = (unsigned long) (arg4);
162 #define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
163 DECLARGS_4(arg1, arg2, arg3, arg4) \
164 unsigned long gpr6 = (unsigned long) (arg5);
167 #define LOADARGS_1 "LG 2,%2\n\t"
168 #define LOADARGS_2 LOADARGS_1 "LG 3,%3\n\t"
169 #define LOADARGS_3 LOADARGS_2 "LG 4,%4\n\t"
170 #define LOADARGS_4 LOADARGS_3 "LG 5,%5\n\t"
171 #define LOADARGS_5 LOADARGS_4 "LG 6,%6\n\t"
174 #define ASMFMT_1 , "m" (gpr2)
175 #define ASMFMT_2 , "m" (gpr2), "m" (gpr3)
176 #define ASMFMT_3 , "m" (gpr2), "m" (gpr3), "m" (gpr4)
177 #define ASMFMT_4 , "m" (gpr2), "m" (gpr3), "m" (gpr4), "m" (gpr5)
178 #define ASMFMT_5 , "m" (gpr2), "m" (gpr3), "m" (gpr4), "m" (gpr5), "m" (gpr6)
180 #endif /* _LINUX_S390_SYSDEP_H */