1 /* Copyright 2001, 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Alexandre Oliva <aoliva@redhat.com>.
4 Based on ../i386/sysdep.h.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 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 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #ifndef _LINUX_AM33_SYSDEP_H
22 #define _LINUX_AM33_SYSDEP_H 1
24 /* There is some commonality. */
25 #include "../../../am33/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. */
32 #define SYS_ify(syscall_name) __NR_##syscall_name
34 /* ELF-like local names start with `.L'. */
36 #define L(name) .L##name
40 /* Linux uses a negative return value to indicate syscall errors,
41 unlike most Unices, which use the condition codes' carry flag.
43 Since version 2.1 the return value of a system call might be
44 negative even if the call succeeded. E.g., the `lseek' system call
45 might return a large offset. Therefore we must not anymore test
46 for < 0, but test for a real error by making sure the value in %eax
47 is a real error number. Linus said he will make sure the no syscall
48 returns a value in -1 .. -4095 as a valid result so we can savely
51 /* We don't want the label for the error handle to be global when we define
54 # define SYSCALL_ERROR_LABEL 0f
56 # define SYSCALL_ERROR_LABEL syscall_error
60 #define PSEUDO(name, syscall_name, args) \
63 DO_CALL (syscall_name, args); \
66 jmp SYSCALL_ERROR_LABEL; \
71 #define PSEUDO_END(name) \
72 SYSCALL_ERROR_HANDLER \
76 #define PSEUDO_NOERRNO(name, syscall_name, args) \
79 DO_CALL (syscall_name, args)
81 #undef PSEUDO_END_NOERRNO
82 #define PSEUDO_END_NOERRNO(name) \
85 #define ret_NOERRNO ret
87 /* The function has to return the error code. */
89 #define PSEUDO_ERRVAL(name, syscall_name, args) \
92 DO_CALL (syscall_name, args); \
96 #undef PSEUDO_END_ERRVAL
97 #define PSEUDO_END_ERRVAL(name) \
100 #define ret_ERRVAL ret
103 #define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
105 /* Store (- d0) into errno through the GOT. */
106 #ifdef _LIBC_REENTRANT
107 #define SYSCALL_ERROR_HANDLER \
108 0:movm [d2,a2],(sp); \
111 add _GLOBAL_OFFSET_TABLE_-(1b-.),a2; \
114 call __errno_location@PLT,[],0; \
121 /* A quick note: it is assumed that the call to `__errno_location' does
122 not modify the stack! */
124 #define SYSCALL_ERROR_HANDLER \
126 add _GLOBAL_OFFSET_TABLE_-(0b-.),a0; \
129 mov (errno@GOT,a0),a1; \
134 #endif /* _LIBC_REENTRANT */
137 /* Linux takes system call arguments in registers:
139 syscall number d0 call-clobbered
140 arg 1 a0 call-clobbered
141 arg 2 d1 call-clobbered
147 The stack layout upon entering the function is:
157 (Of course a function with say 3 arguments does not have entries for
158 arguments 4, 5 and 6.) */
161 #define DO_CALL(syscall_name, args) \
164 mov SYS_ify (syscall_name),d0; \
168 #define PUSHARGS_0 /* No arguments to push. */
169 #define _DOARGS_0(N) /* No arguments to frob. */
170 #define DOARGS_0 /* No arguments to frob. */
171 #define POPARGS_0 /* No arguments to pop. */
173 #define PUSHARGS_1 /* No arguments to push. */
174 #define _DOARGS_1(N) _DOARGS_0 (N-4) mov d0,a0;
175 #define DOARGS_1 _DOARGS_1 (4)
176 #define POPARGS_1 /* No arguments to pop. */
178 #define PUSHARGS_2 /* No arguments to push. */
179 #define _DOARGS_2(N) _DOARGS_1 (N-4) /* Argument already in d1. */
180 #define DOARGS_2 _DOARGS_2 (8)
181 #define POPARGS_2 /* No arguments to pop. */
183 #define PUSHARGS_3 movm [a3],(sp);
184 #define _DOARGS_3(N) _DOARGS_2 (N-4) mov (N,sp),a3;
185 #define DOARGS_3 _DOARGS_3 (16)
186 #define POPARGS_3 ; movm (sp),[a3]
188 #define PUSHARGS_4 movm [a2,a3],(sp);
189 #define _DOARGS_4(N) _DOARGS_3 (N-4) mov (N,sp),a2;
190 #define DOARGS_4 _DOARGS_4 (24)
191 #define POPARGS_4 ; movm (sp),[a2,a3]
193 #define PUSHARGS_5 movm [d3,a2,a3],(sp);
194 #define _DOARGS_5(N) _DOARGS_4 (N-4) mov (N,sp),d3;
195 #define DOARGS_5 _DOARGS_5 (32)
196 #define POPARGS_5 ; movm (sp),[d3,a2,a3]
198 #define PUSHARGS_6 movm [d2,d3,a2,a3],(sp);
199 #define _DOARGS_6(N) _DOARGS_5 (N-4) mov (N,sp),d2;
200 #define DOARGS_6 _DOARGS_6 (40)
201 #define POPARGS_6 ; movm (sp),[d2,d3,a2,a3]
203 #else /* !__ASSEMBLER__ */
205 /* Define a macro which expands inline into the wrapper code for a system
207 #undef INLINE_SYSCALL
208 #define INLINE_SYSCALL(name, nr, args...) \
210 unsigned int resultvar = INTERNAL_SYSCALL (name, , nr, args); \
211 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
213 __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
214 resultvar = 0xffffffff; \
218 #define INTERNAL_SYSCALL(name, err, nr, args...) \
220 register long __sc0 asm ("d0") = __NR_##name; \
221 inline_syscall##nr(name, ## args); \
225 #undef INTERNAL_SYSCALL_DECL
226 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
228 #undef INTERNAL_SYSCALL_ERROR_P
229 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
230 ((unsigned int) (val) >= (unsigned long)-125)
232 #undef INTERNAL_SYSCALL_ERRNO
233 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
235 #define inline_syscall0(name,dummy...) \
236 __asm__ __volatile__ ("syscall 0" \
240 #define inline_syscall1(name,arg1) \
241 register long __sc1 asm ("a0") = (long) (arg1); \
242 inline_syscall0 (name); \
243 __asm__ __volatile__ ("" : : "r" (__sc1))
245 #define inline_syscall2(name,arg1,arg2) \
246 register long __sc2 asm ("d1") = (long) (arg2); \
247 inline_syscall1 (name,(arg1)); \
248 __asm__ __volatile__ ("" : : "r" (__sc2))
250 /* We can't tell whether a3 is going to be eliminated in the enclosing
251 function, so we have to assume it isn't. We first load the value
252 of any arguments into their registers, except for a3 itself, that
253 may be needed to load the value of the other arguments. Then, we
254 save a3's value in some other register, and load the argument value
255 into a3. We have to force both a3 and its copy to be live in
256 different registers at the same time, to avoid having the copy
257 spilled and the value reloaded into the same register, in which
258 case we'd be unable to get the value of a3 back, should the stack
259 slot reference be (offset,a3). */
260 #define inline_syscall3(name,arg1,arg2,arg3) \
261 long __sc3v = (long) (arg3); \
262 register long __sc1 asm ("a0") = (long) (arg1); \
263 register long __sc2 asm ("d1") = (long) (arg2); \
264 register long __sc3 asm ("a3") = __sc3; \
265 register long __sc3c; \
266 __asm__ __volatile__ ("mov %1,%0" : "=&r" (__sc3c) : "r" (__sc3)); \
268 __asm__ __volatile__ ("" : : "r" (__sc3c), "r" (__sc3)); \
269 inline_syscall0 (name); \
271 __asm__ __volatile__ ("" : : "r" (__sc3), "r" (__sc2), "r" (__sc1))
274 /* Since a2 is the PIC register, it requires similar handling as a3
275 when we're generating PIC, as a2's value may be needed to load
276 arguments whose values live in global variables. The difference is
277 that we don't need to require its value to be live in a register;
278 it may well be in a stack slot, as long as we save it before
279 clobbering a3 and restore it after restoring a3. */
280 #define inline_syscall4(name,arg1,arg2,arg3,arg4) \
281 long __sc4v = (long) (arg4); \
282 long __sc3v = (long) (arg3); \
283 register long __sc1 asm ("a0") = (long) (arg1); \
284 register long __sc2 asm ("d1") = (long) (arg2); \
285 register long __sc3 asm ("a3") = __sc3; \
286 register long __sc3c; \
287 register long __sc4 asm ("a2") = __sc4; \
288 long __sc4c = __sc4; \
290 __asm__ __volatile__ ("mov %1,%0" : "=&r" (__sc3c) : "r" (__sc3)); \
292 __asm__ __volatile__ ("" : : "r" (__sc3c), "r" (__sc3), "r" (__sc4)); \
293 inline_syscall0 (name); \
296 __asm__ __volatile__ ("" : : "r" (__sc4), "r" (__sc3), \
297 "r" (__sc2), "r" (__sc1))
299 #define inline_syscall4(name,arg1,arg2,arg3,arg4) \
300 register long __sc4 asm ("a2") = (long) (arg4); \
301 inline_syscall3 (name,(arg1),(arg2),(arg3)); \
302 __asm__ __volatile__ ("" : : "r" (__sc4))
305 #define inline_syscall5(name,arg1,arg2,arg3,arg4,arg5) \
306 register long __sc5 asm ("d3") = (long) (arg5); \
307 inline_syscall4 (name,(arg1),(arg2),(arg3),(arg4)); \
308 __asm__ __volatile__ ("" : : "r" (__sc5))
310 #define inline_syscall6(name,arg1,arg2,arg3,arg4,arg5,arg6) \
311 register long __sc6 asm ("d2") = (long) (arg6); \
312 inline_syscall5 (name,(arg1),(arg2),(arg3),(arg4),(arg5)); \
313 __asm__ __volatile__ ("" : : "r" (__sc6))
315 #endif /* __ASSEMBLER__ */
317 #endif /* linux/am33/sysdep.h */