1 /* Copyright (C) 2005, 2006, 2007, 2009
2 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 Contributed by Daniel Jacobowitz <dan@codesourcery.com>, Oct 2005.
8 The GNU C Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 The GNU C Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with the GNU C Library. If not, see
20 <http://www.gnu.org/licenses/>. */
22 #ifndef _LINUX_ARM_EABI_SYSDEP_H
23 #define _LINUX_ARM_EABI_SYSDEP_H 1
25 #include <arm/sysdep.h>
29 #if __NR_SYSCALL_BASE != 0
30 # error Kernel headers are too old
33 /* Don't use stime, even if the kernel headers define it. We have
34 settimeofday, and some EABI kernels have removed stime. Similarly
35 use setitimer to implement alarm. */
39 /* The ARM EABI user interface passes the syscall number in r7, instead
40 of in the swi. This is more efficient, because the kernel does not need
41 to fetch the swi from memory to find out the number; which can be painful
42 with separate I-cache and D-cache. Make sure to use 0 for the SWI
43 argument; otherwise the (optional) compatibility code for APCS binaries
46 #if defined(__thumb__)
47 /* We can not expose the use of r7 to the compiler. GCC (as
48 of 4.5) uses r7 as the hard frame pointer for Thumb - although
49 for Thumb-2 it isn't obviously a better choice than r11.
50 And GCC does not support asms that conflict with the frame
53 This would be easier if syscall numbers never exceeded 255,
54 but they do. For the moment the LOAD_ARGS_7 is sacrificed.
55 We can't use push/pop inside the asm because that breaks
56 unwinding (i.e. thread cancellation) for this frame. We can't
57 locally save and restore r7, because we do not know if this
58 function uses r7 or if it is our caller's r7; if it is our caller's,
59 then unwinding will fail higher up the stack. So we move the
60 syscall out of line and provide its own unwind information. */
62 #undef INTERNAL_SYSCALL_RAW
63 #define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
65 register int _a1 asm ("a1"); \
66 int _nametmp = name; \
67 LOAD_ARGS_##nr (args) \
68 register int _name asm ("ip") = _nametmp; \
69 asm volatile ("bl __libc_do_syscall" \
71 : "r" (_name) ASM_ARGS_##nr \
75 #undef INTERNAL_SYSCALL_RAW
76 #define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
78 register int _a1 asm ("r0"), _nr asm ("r7"); \
79 LOAD_ARGS_##nr (args) \
81 asm volatile ("swi 0x0 @ syscall " #name \
83 : "r" (_nr) ASM_ARGS_##nr \
88 /* For EABI, non-constant syscalls are actually pretty easy... */
89 #undef INTERNAL_SYSCALL_NCS
90 #define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
91 INTERNAL_SYSCALL_RAW (number, err, nr, args)
93 /* We must save and restore r7 (call-saved) for the syscall number.
94 We never make function calls from inside here (only potentially
95 signal handlers), so we do not bother with doubleword alignment.
97 Just like the APCS syscall convention, the EABI syscall convention uses
98 r0 through r6 for up to seven syscall arguments. None are ever passed to
99 the kernel on the stack, although incoming arguments are on the stack for
100 syscalls with five or more arguments.
102 The assembler will convert the literal pool load to a move for most
106 #define DO_CALL(syscall_name, args) \
108 ldr r7, =SYS_ify (syscall_name); \
115 str r7, [sp, #-4]!; \
116 cfi_adjust_cfa_offset (4); \
117 cfi_rel_offset (r7, 0); \
120 #define DOARGS_1 DOARGS_0
122 #define DOARGS_2 DOARGS_0
124 #define DOARGS_3 DOARGS_0
126 #define DOARGS_4 DOARGS_0
130 stmfd sp!, {r4, r7}; \
131 cfi_adjust_cfa_offset (8); \
132 cfi_rel_offset (r4, 0); \
133 cfi_rel_offset (r7, 4); \
140 stmfd sp!, {r4, r5, r7}; \
141 cfi_adjust_cfa_offset (12); \
142 cfi_rel_offset (r4, 0); \
143 cfi_rel_offset (r5, 4); \
144 cfi_rel_offset (r7, 8); \
145 .save { r4, r5, r7 }; \
151 stmfd sp!, {r4, r5, r6, r7}; \
152 cfi_adjust_cfa_offset (16); \
153 cfi_rel_offset (r4, 0); \
154 cfi_rel_offset (r5, 4); \
155 cfi_rel_offset (r6, 8); \
156 cfi_rel_offset (r7, 12); \
157 .save { r4, r5, r6, r7 }; \
158 ldmia ip, {r4, r5, r6}
163 cfi_adjust_cfa_offset (-4); \
167 #define UNDOARGS_1 UNDOARGS_0
169 #define UNDOARGS_2 UNDOARGS_0
171 #define UNDOARGS_3 UNDOARGS_0
173 #define UNDOARGS_4 UNDOARGS_0
176 ldmfd sp!, {r4, r7}; \
177 cfi_adjust_cfa_offset (-8); \
183 ldmfd sp!, {r4, r5, r7}; \
184 cfi_adjust_cfa_offset (-12); \
191 ldmfd sp!, {r4, r5, r6, r7}; \
192 cfi_adjust_cfa_offset (-16); \
199 #endif /* _LINUX_ARM_EABI_SYSDEP_H */