1 /* Copyright (C) 1992, 93, 1995-2000, 2002, 2003, 2005 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>, August 1995.
4 ARM changes by Philip Blundell, <pjb27@cam.ac.uk>, May 1997.
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_ARM_SYSDEP_H
22 #define _LINUX_ARM_SYSDEP_H 1
24 /* There is some commonality. */
25 #include <ports/sysdeps/unix/arm/sysdep.h>
27 /* Defines RTLD_PRIVATE_ERRNO and USE_DL_SYSINFO. */
28 #include <dl-sysdep.h>
30 /* For Linux we can use the system call table in the header file
31 /usr/include/asm/unistd.h
32 of the kernel. But these symbols do not follow the SYS_* syntax
33 so we have to redefine the `SYS_ify' macro here. */
35 #define SWI_BASE (0x900000)
36 #define SYS_ify(syscall_name) (__NR_##syscall_name)
41 /* Linux uses a negative return value to indicate syscall errors,
42 unlike most Unices, which use the condition codes' carry flag.
44 Since version 2.1 the return value of a system call might be
45 negative even if the call succeeded. E.g., the `lseek' system call
46 might return a large offset. Therefore we must not anymore test
47 for < 0, but test for a real error by making sure the value in R0
48 is a real error number. Linus said he will make sure the no syscall
49 returns a value in -1 .. -4095 as a valid result so we can safely
53 #define PSEUDO(name, syscall_name, args) \
56 DO_CALL (syscall_name, args); \
61 b PLTJMP(SYSCALL_ERROR)
63 #define ret PSEUDO_RET
66 #define PSEUDO_END(name) \
67 SYSCALL_ERROR_HANDLER \
71 #define PSEUDO_NOERRNO(name, syscall_name, args) \
74 DO_CALL (syscall_name, args);
76 #define PSEUDO_RET_NOERRNO \
80 #define ret_NOERRNO PSEUDO_RET_NOERRNO
82 #undef PSEUDO_END_NOERRNO
83 #define PSEUDO_END_NOERRNO(name) \
86 /* The function has to return the error code. */
88 #define PSEUDO_ERRVAL(name, syscall_name, args) \
91 DO_CALL (syscall_name, args); \
94 #undef PSEUDO_END_ERRVAL
95 #define PSEUDO_END_ERRVAL(name) \
98 #define ret_ERRVAL PSEUDO_RET_NOERRNO
101 # define SYSCALL_ERROR __local_syscall_error
102 # if RTLD_PRIVATE_ERRNO
103 # define SYSCALL_ERROR_HANDLER \
104 __local_syscall_error: \
107 0: str r0, [pc, r1]; \
110 1: .word C_SYMBOL_NAME(rtld_errno) - 0b - 8;
112 # define SYSCALL_ERROR_HANDLER \
113 __local_syscall_error: \
114 str lr, [sp, #-4]!; \
115 str r0, [sp, #-4]!; \
116 bl PLTJMP(C_SYMBOL_NAME(__errno_location)); \
124 # define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
125 # define SYSCALL_ERROR __syscall_error
128 /* Linux takes system call args in registers:
129 syscall number in the SWI instruction
134 arg 5 r4 (this is different from the APCS convention)
138 The compiler is going to form a call by coming here, through PSEUDO, with
140 syscall number in the DO_CALL macro
149 We need to shuffle values between R4..R6 and the stack so that the
150 caller's v1..v3 and stack frame are not corrupted, and the kernel
151 sees the right arguments.
156 #define DO_CALL(syscall_name, args) \
158 swi SYS_ify (syscall_name); \
161 #define DOARGS_0 /* nothing */
162 #define DOARGS_1 /* nothing */
163 #define DOARGS_2 /* nothing */
164 #define DOARGS_3 /* nothing */
165 #define DOARGS_4 /* nothing */
166 #define DOARGS_5 str r4, [sp, $-4]!; ldr r4, [sp, $4];
167 #define DOARGS_6 mov ip, sp; stmfd sp!, {r4, r5}; ldmia ip, {r4, r5};
168 #define DOARGS_7 mov ip, sp; stmfd sp!, {r4, r5, r6}; ldmia ip, {r4, r5, r6};
170 #define UNDOARGS_0 /* nothing */
171 #define UNDOARGS_1 /* nothing */
172 #define UNDOARGS_2 /* nothing */
173 #define UNDOARGS_3 /* nothing */
174 #define UNDOARGS_4 /* nothing */
175 #define UNDOARGS_5 ldr r4, [sp], $4;
176 #define UNDOARGS_6 ldmfd sp!, {r4, r5};
177 #define UNDOARGS_7 ldmfd sp!, {r4, r5, r6};
179 #else /* not __ASSEMBLER__ */
181 /* Define a macro which expands into the inline wrapper code for a system
183 #undef INLINE_SYSCALL
184 #define INLINE_SYSCALL(name, nr, args...) \
185 ({ unsigned int _sys_result = INTERNAL_SYSCALL (name, , nr, args); \
186 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0)) \
188 __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, )); \
189 _sys_result = (unsigned int) -1; \
191 (int) _sys_result; })
193 #undef INTERNAL_SYSCALL_DECL
194 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
196 #undef INTERNAL_SYSCALL_RAW
197 #define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
198 ({ unsigned int _sys_result; \
200 register int _a1 asm ("a1"); \
201 LOAD_ARGS_##nr (args) \
202 asm volatile ("swi %1 @ syscall " #name \
204 : "i" (name) ASM_ARGS_##nr \
208 (int) _sys_result; })
210 #undef INTERNAL_SYSCALL
211 #define INTERNAL_SYSCALL(name, err, nr, args...) \
212 INTERNAL_SYSCALL_RAW(SYS_ify(name), err, nr, args)
214 #undef INTERNAL_SYSCALL_ARM
215 #define INTERNAL_SYSCALL_ARM(name, err, nr, args...) \
216 INTERNAL_SYSCALL_RAW(__ARM_NR_##name, err, nr, args)
218 #undef INTERNAL_SYSCALL_ERROR_P
219 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
220 ((unsigned int) (val) >= 0xfffff001u)
222 #undef INTERNAL_SYSCALL_ERRNO
223 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
225 #define LOAD_ARGS_0()
227 #define LOAD_ARGS_1(a1) \
230 #define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
231 #define LOAD_ARGS_2(a1, a2) \
232 register int _a2 asm ("a2") = (int) (a2); \
234 #define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2)
235 #define LOAD_ARGS_3(a1, a2, a3) \
236 register int _a3 asm ("a3") = (int) (a3); \
238 #define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3)
239 #define LOAD_ARGS_4(a1, a2, a3, a4) \
240 register int _a4 asm ("a4") = (int) (a4); \
241 LOAD_ARGS_3 (a1, a2, a3)
242 #define ASM_ARGS_4 ASM_ARGS_3, "r" (_a4)
243 #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
244 register int _v1 asm ("v1") = (int) (a5); \
245 LOAD_ARGS_4 (a1, a2, a3, a4)
246 #define ASM_ARGS_5 ASM_ARGS_4, "r" (_v1)
247 #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
248 register int _v2 asm ("v2") = (int) (a6); \
249 LOAD_ARGS_5 (a1, a2, a3, a4, a5)
250 #define ASM_ARGS_6 ASM_ARGS_5, "r" (_v2)
251 #define LOAD_ARGS_7(a1, a2, a3, a4, a5, a6, a7) \
252 register int _v3 asm ("v3") = (int) (a7); \
253 LOAD_ARGS_6 (a1, a2, a3, a4, a5, a6)
254 #define ASM_ARGS_7 ASM_ARGS_6, "r" (_v3)
256 /* We can't implement non-constant syscalls directly since the syscall
257 number is normally encoded in the instruction. So use SYS_syscall. */
258 #define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
259 INTERNAL_SYSCALL_NCS_##nr (number, err, args)
261 #define INTERNAL_SYSCALL_NCS_0(number, err, args...) \
262 INTERNAL_SYSCALL (syscall, err, 1, number, args)
263 #define INTERNAL_SYSCALL_NCS_1(number, err, args...) \
264 INTERNAL_SYSCALL (syscall, err, 2, number, args)
265 #define INTERNAL_SYSCALL_NCS_2(number, err, args...) \
266 INTERNAL_SYSCALL (syscall, err, 3, number, args)
267 #define INTERNAL_SYSCALL_NCS_3(number, err, args...) \
268 INTERNAL_SYSCALL (syscall, err, 4, number, args)
269 #define INTERNAL_SYSCALL_NCS_4(number, err, args...) \
270 INTERNAL_SYSCALL (syscall, err, 5, number, args)
271 #define INTERNAL_SYSCALL_NCS_5(number, err, args...) \
272 INTERNAL_SYSCALL (syscall, err, 6, number, args)
274 #endif /* __ASSEMBLER__ */
276 #endif /* linux/arm/sysdep.h */