]> sourceware.org Git - glibc.git/blob - sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h
Update.
[glibc.git] / sysdeps / unix / sysv / linux / s390 / s390-64 / sysdep.h
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.
5
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.
10
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.
15
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. */
20
21 #ifndef _LINUX_S390_SYSDEP_H
22 #define _LINUX_S390_SYSDEP_H
23
24 #include <sysdeps/s390/s390-64/sysdep.h>
25 #include <sysdeps/unix/sysdep.h>
26
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
33
34 #undef SYS_ify
35 #define SYS_ify(syscall_name) __NR_##syscall_name
36
37 #ifdef __ASSEMBLER__
38
39 /* Linux uses a negative return value to indicate syscall errors, unlike
40 most Unices, which use the condition codes' carry flag.
41
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. */
48
49 #undef PSEUDO
50 #define PSEUDO(name, syscall_name, args) \
51 .text; \
52 ENTRY (name) \
53 DO_CALL (syscall_name, args); \
54 lghi %r4,-4095 ; \
55 clgr %r2,%r4 ; \
56 jgnl SYSCALL_ERROR_LABEL
57
58 #undef PSEUDO_END
59 #define PSEUDO_END(name) \
60 SYSCALL_ERROR_HANDLER; \
61 END (name)
62
63 #ifndef PIC
64 # define SYSCALL_ERROR_LABEL syscall_error
65 # define SYSCALL_ERROR_HANDLER
66 #else
67 # if RTLD_PRIVATE_ERRNO
68 # define SYSCALL_ERROR_LABEL 0f
69 # define SYSCALL_ERROR_HANDLER \
70 0: larl %r1,errno; \
71 lcr %r2,%r2; \
72 st %r2,0(%r1); \
73 lghi %r2,-1; \
74 br %r14
75 # elif defined _LIBC_REENTRANT
76 # if USE___THREAD
77 # ifndef NOT_IN_libc
78 # define SYSCALL_ERROR_ERRNO __libc_errno
79 # else
80 # define SYSCALL_ERROR_ERRNO errno
81 # endif
82 # define SYSCALL_ERROR_LABEL 0f
83 # define SYSCALL_ERROR_HANDLER \
84 0: lcr %r0,%r2; \
85 larl %r1,SYSCALL_ERROR_ERRNO@indntpoff; \
86 lg %r1,0(%r1); \
87 ear %r2,%a0; \
88 sllg %r2,%r2,32; \
89 ear %r2,%a1; \
90 st %r0,0(%r1,%r2); \
91 lghi %r2,-1; \
92 br %r14
93 # else
94 # define SYSCALL_ERROR_LABEL syscall_error@plt
95 # define SYSCALL_ERROR_HANDLER
96 # endif
97 # else
98 # define SYSCALL_ERROR_LABEL 0f
99 # define SYSCALL_ERROR_HANDLER \
100 0: larl %r1,_GLOBAL_OFFSET_TABLE_; \
101 lg %r1,errno@GOT(%r1); \
102 lcr %r2,%r2; \
103 st %r2,0(%r1); \
104 lghi %r2,-1; \
105 br %r14
106 # endif /* _LIBC_REENTRANT */
107 #endif /* PIC */
108
109 /* Linux takes system call arguments in registers:
110
111 syscall number 1 call-clobbered
112 arg 1 2 call-clobbered
113 arg 2 3 call-clobbered
114 arg 3 4 call-clobbered
115 arg 4 5 call-clobbered
116 arg 5 6 call-saved
117
118 (Of course a function with say 3 arguments does not have entries for
119 arguments 4 and 5.)
120 S390 does not need to do ANY stack operations to get its parameters
121 right.
122 */
123
124 #define DO_CALL(syscall, args) \
125 .if SYS_ify (syscall) < 256; \
126 svc SYS_ify (syscall); \
127 .else; \
128 lghi %r1,SYS_ify (syscall); \
129 svc 0; \
130 .endif
131
132 #define ret \
133 br 14
134
135 #endif /* __ASSEMBLER__ */
136
137 #undef INLINE_SYSCALL
138 #define INLINE_SYSCALL(name, nr, args...) \
139 ({ \
140 unsigned int _ret = INTERNAL_SYSCALL (name, , nr, args); \
141 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_ret, ), 0)) \
142 { \
143 __set_errno (INTERNAL_SYSCALL_ERRNO (_ret, )); \
144 _ret = -1; \
145 } \
146 (int) _ret; })
147
148 #undef INTERNAL_SYSCALL_DECL
149 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
150
151 #undef INTERNAL_SYSCALL_DIRECT
152 #define INTERNAL_SYSCALL_DIRECT(name, err, nr, args...) \
153 ({ \
154 DECLARGS_##nr(args) \
155 register int _ret asm("2"); \
156 asm volatile ( \
157 "svc %b1\n\t" \
158 : "=d" (_ret) \
159 : "i" (__NR_##name) ASMFMT_##nr \
160 : "memory" ); \
161 _ret; })
162
163 #undef INTERNAL_SYSCALL_SVC0
164 #define INTERNAL_SYSCALL_SVC0(name, err, nr, args...) \
165 ({ \
166 DECLARGS_##nr(args) \
167 register unsigned long _nr asm("1") = (unsigned long)(__NR_##name); \
168 register int _ret asm("2"); \
169 asm volatile ( \
170 "svc 0\n\t" \
171 : "=d" (_ret) \
172 : "d" (_nr), "i" (__NR_##name) ASMFMT_##nr \
173 : "memory" ); \
174 _ret; })
175
176 #undef INTERNAL_SYSCALL
177 #define INTERNAL_SYSCALL(name, err, nr, args...) \
178 (((__NR_##name) < 256) ? \
179 INTERNAL_SYSCALL_DIRECT(name, err, nr, args) : \
180 INTERNAL_SYSCALL_SVC0(name, err,nr, args))
181
182 #undef INTERNAL_SYSCALL_ERROR_P
183 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
184 ((unsigned int) (val) >= 0xfffff001u)
185
186 #undef INTERNAL_SYSCALL_ERRNO
187 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
188
189 #define DECLARGS_0()
190 #define DECLARGS_1(arg1) \
191 register unsigned long gpr2 asm ("2") = (unsigned long)(arg1);
192 #define DECLARGS_2(arg1, arg2) \
193 DECLARGS_1(arg1) \
194 register unsigned long gpr3 asm ("3") = (unsigned long)(arg2);
195 #define DECLARGS_3(arg1, arg2, arg3) \
196 DECLARGS_2(arg1, arg2) \
197 register unsigned long gpr4 asm ("4") = (unsigned long)(arg3);
198 #define DECLARGS_4(arg1, arg2, arg3, arg4) \
199 DECLARGS_3(arg1, arg2, arg3) \
200 register unsigned long gpr5 asm ("5") = (unsigned long)(arg4);
201 #define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
202 DECLARGS_4(arg1, arg2, arg3, arg4) \
203 register unsigned long gpr6 asm ("6") = (unsigned long)(arg5);
204
205 #define ASMFMT_0
206 #define ASMFMT_1 , "0" (gpr2)
207 #define ASMFMT_2 , "0" (gpr2), "d" (gpr3)
208 #define ASMFMT_3 , "0" (gpr2), "d" (gpr3), "d" (gpr4)
209 #define ASMFMT_4 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5)
210 #define ASMFMT_5 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6)
211
212 #endif /* _LINUX_S390_SYSDEP_H */
This page took 0.047128 seconds and 5 git commands to generate.