1 /* Copyright (C) 1992, 93, 1995-2000, 2002, 2003, 2005, 2006, 2009
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>, August 1995.
5 ARM changes by Philip Blundell, <pjb27@cam.ac.uk>, May 1997.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 #ifndef _LINUX_ARM_SYSDEP_H
23 #define _LINUX_ARM_SYSDEP_H 1
25 /* There is some commonality. */
26 #include <sysdeps/unix/arm/sysdep.h>
28 /* Defines RTLD_PRIVATE_ERRNO and USE_DL_SYSINFO. */
29 #include <dl-sysdep.h>
33 /* In order to get __set_errno() definition in INLINE_SYSCALL. */
38 /* For Linux we can use the system call table in the header file
39 /usr/include/asm/unistd.h
40 of the kernel. But these symbols do not follow the SYS_* syntax
41 so we have to redefine the `SYS_ify' macro here. */
43 #define SWI_BASE (0x900000)
44 #define SYS_ify(syscall_name) (__NR_##syscall_name)
47 /* The following must match the kernel's <asm/procinfo.h>. */
48 #define HWCAP_ARM_SWP 1
49 #define HWCAP_ARM_HALF 2
50 #define HWCAP_ARM_THUMB 4
51 #define HWCAP_ARM_26BIT 8
52 #define HWCAP_ARM_FAST_MULT 16
53 #define HWCAP_ARM_FPA 32
54 #define HWCAP_ARM_VFP 64
55 #define HWCAP_ARM_EDSP 128
56 #define HWCAP_ARM_JAVA 256
57 #define HWCAP_ARM_IWMMXT 512
61 /* Linux uses a negative return value to indicate syscall errors,
62 unlike most Unices, which use the condition codes' carry flag.
64 Since version 2.1 the return value of a system call might be
65 negative even if the call succeeded. E.g., the `lseek' system call
66 might return a large offset. Therefore we must not anymore test
67 for < 0, but test for a real error by making sure the value in R0
68 is a real error number. Linus said he will make sure the no syscall
69 returns a value in -1 .. -4095 as a valid result so we can safely
73 #define PSEUDO(name, syscall_name, args) \
76 DO_CALL (syscall_name, args); \
81 b PLTJMP(SYSCALL_ERROR)
83 #define ret PSEUDO_RET
86 #define PSEUDO_END(name) \
87 SYSCALL_ERROR_HANDLER; \
91 #define PSEUDO_NOERRNO(name, syscall_name, args) \
94 DO_CALL (syscall_name, args);
96 #define PSEUDO_RET_NOERRNO \
100 #define ret_NOERRNO PSEUDO_RET_NOERRNO
102 #undef PSEUDO_END_NOERRNO
103 #define PSEUDO_END_NOERRNO(name) \
106 /* The function has to return the error code. */
108 #define PSEUDO_ERRVAL(name, syscall_name, args) \
111 DO_CALL (syscall_name, args); \
114 #undef PSEUDO_END_ERRVAL
115 #define PSEUDO_END_ERRVAL(name) \
118 #define ret_ERRVAL PSEUDO_RET_NOERRNO
121 # define SYSCALL_ERROR __local_syscall_error
122 # if RTLD_PRIVATE_ERRNO
123 # define SYSCALL_ERROR_HANDLER \
124 __local_syscall_error: \
127 0: str r0, [pc, r1]; \
130 1: .word C_SYMBOL_NAME(rtld_errno) - 0b - 8;
132 # if defined(__ARM_ARCH_4T__) && defined(__THUMB_INTERWORK__)
135 cfi_adjust_cfa_offset (-4); \
142 # define SYSCALL_ERROR_HANDLER \
143 __local_syscall_error: \
144 str lr, [sp, #-4]!; \
145 cfi_adjust_cfa_offset (4); \
146 cfi_rel_offset (lr, 0); \
147 str r0, [sp, #-4]!; \
148 cfi_adjust_cfa_offset (4); \
149 bl PLTJMP(C_SYMBOL_NAME(__errno_location)); \
151 cfi_adjust_cfa_offset (-4); \
158 # define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
159 # define SYSCALL_ERROR __syscall_error
162 /* Linux takes system call args in registers:
163 syscall number in the SWI instruction
168 arg 5 r4 (this is different from the APCS convention)
172 The compiler is going to form a call by coming here, through PSEUDO, with
174 syscall number in the DO_CALL macro
183 We need to shuffle values between R4..R6 and the stack so that the
184 caller's v1..v3 and stack frame are not corrupted, and the kernel
185 sees the right arguments.
190 #define DO_CALL(syscall_name, args) \
192 swi SYS_ify (syscall_name); \
195 #define DOARGS_0 /* nothing */
196 #define DOARGS_1 /* nothing */
197 #define DOARGS_2 /* nothing */
198 #define DOARGS_3 /* nothing */
199 #define DOARGS_4 /* nothing */
201 str r4, [sp, $-4]!; \
202 cfi_adjust_cfa_offset (4); \
203 cfi_rel_offset (r4, 0); \
207 stmfd sp!, {r4, r5}; \
208 cfi_adjust_cfa_offset (8); \
209 cfi_rel_offset (r4, 0); \
210 cfi_rel_offset (r5, 4); \
214 stmfd sp!, {r4, r5, r6}; \
215 cfi_adjust_cfa_offset (12); \
216 cfi_rel_offset (r4, 0); \
217 cfi_rel_offset (r5, 4); \
218 cfi_rel_offset (r6, 8); \
219 ldmia ip, {r4, r5, r6}
221 #define UNDOARGS_0 /* nothing */
222 #define UNDOARGS_1 /* nothing */
223 #define UNDOARGS_2 /* nothing */
224 #define UNDOARGS_3 /* nothing */
225 #define UNDOARGS_4 /* nothing */
228 cfi_adjust_cfa_offset (-4); \
231 ldmfd sp!, {r4, r5}; \
232 cfi_adjust_cfa_offset (-8); \
236 ldmfd sp!, {r4, r5, r6}; \
237 cfi_adjust_cfa_offset (-12); \
242 #else /* not __ASSEMBLER__ */
244 /* Define a macro which expands into the inline wrapper code for a system
246 #undef INLINE_SYSCALL
247 #define INLINE_SYSCALL(name, nr, args...) \
248 ({ unsigned int _sys_result = INTERNAL_SYSCALL (name, , nr, args); \
249 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0)) \
251 __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, )); \
252 _sys_result = (unsigned int) -1; \
254 (int) _sys_result; })
256 #undef INTERNAL_SYSCALL_DECL
257 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
259 #undef INTERNAL_SYSCALL_RAW
260 #define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
261 ({ unsigned int _sys_result; \
263 register int _a1 asm ("a1"); \
264 LOAD_ARGS_##nr (args) \
265 asm volatile ("swi %1 @ syscall " #name \
267 : "i" (name) ASM_ARGS_##nr \
271 (int) _sys_result; })
273 #undef INTERNAL_SYSCALL
274 #define INTERNAL_SYSCALL(name, err, nr, args...) \
275 INTERNAL_SYSCALL_RAW(SYS_ify(name), err, nr, args)
277 #undef INTERNAL_SYSCALL_ARM
278 #define INTERNAL_SYSCALL_ARM(name, err, nr, args...) \
279 INTERNAL_SYSCALL_RAW(__ARM_NR_##name, err, nr, args)
281 #undef INTERNAL_SYSCALL_ERROR_P
282 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
283 ((unsigned int) (val) >= 0xfffff001u)
285 #undef INTERNAL_SYSCALL_ERRNO
286 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
288 #define LOAD_ARGS_0()
290 #define LOAD_ARGS_1(a1) \
291 int _a1tmp = (int) (a1); \
294 #define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
295 #define LOAD_ARGS_2(a1, a2) \
296 int _a2tmp = (int) (a2); \
298 register int _a2 asm ("a2") = _a2tmp;
299 #define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2)
300 #define LOAD_ARGS_3(a1, a2, a3) \
301 int _a3tmp = (int) (a3); \
302 LOAD_ARGS_2 (a1, a2) \
303 register int _a3 asm ("a3") = _a3tmp;
304 #define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3)
305 #define LOAD_ARGS_4(a1, a2, a3, a4) \
306 int _a4tmp = (int) (a4); \
307 LOAD_ARGS_3 (a1, a2, a3) \
308 register int _a4 asm ("a4") = _a4tmp;
309 #define ASM_ARGS_4 ASM_ARGS_3, "r" (_a4)
310 #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
311 int _v1tmp = (int) (a5); \
312 LOAD_ARGS_4 (a1, a2, a3, a4) \
313 register int _v1 asm ("v1") = _v1tmp;
314 #define ASM_ARGS_5 ASM_ARGS_4, "r" (_v1)
315 #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
316 int _v2tmp = (int) (a6); \
317 LOAD_ARGS_5 (a1, a2, a3, a4, a5) \
318 register int _v2 asm ("v2") = _v2tmp;
319 #define ASM_ARGS_6 ASM_ARGS_5, "r" (_v2)
320 #define LOAD_ARGS_7(a1, a2, a3, a4, a5, a6, a7) \
321 int _v3tmp = (int) (a7); \
322 LOAD_ARGS_6 (a1, a2, a3, a4, a5, a6) \
323 register int _v3 asm ("v3") = _v3tmp;
324 #define ASM_ARGS_7 ASM_ARGS_6, "r" (_v3)
326 /* We can't implement non-constant syscalls directly since the syscall
327 number is normally encoded in the instruction. So use SYS_syscall. */
328 #define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
329 INTERNAL_SYSCALL_NCS_##nr (number, err, args)
331 #define INTERNAL_SYSCALL_NCS_0(number, err, args...) \
332 INTERNAL_SYSCALL (syscall, err, 1, number, args)
333 #define INTERNAL_SYSCALL_NCS_1(number, err, args...) \
334 INTERNAL_SYSCALL (syscall, err, 2, number, args)
335 #define INTERNAL_SYSCALL_NCS_2(number, err, args...) \
336 INTERNAL_SYSCALL (syscall, err, 3, number, args)
337 #define INTERNAL_SYSCALL_NCS_3(number, err, args...) \
338 INTERNAL_SYSCALL (syscall, err, 4, number, args)
339 #define INTERNAL_SYSCALL_NCS_4(number, err, args...) \
340 INTERNAL_SYSCALL (syscall, err, 5, number, args)
341 #define INTERNAL_SYSCALL_NCS_5(number, err, args...) \
342 INTERNAL_SYSCALL (syscall, err, 6, number, args)
344 #endif /* __ASSEMBLER__ */
346 /* Pointer mangling is not yet supported for ARM. */
347 #define PTR_MANGLE(var) (void) (var)
348 #define PTR_DEMANGLE(var) (void) (var)
350 #endif /* linux/arm/sysdep.h */