Replace FSF snail mail address by URL.
[glibc.git] / sysdeps / unix / sysv / linux / arm / eabi / sysdep.h
blob408142c1af878ff5ac1b1e660f764a4aeb50a2d9
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>
27 #include <tls.h>
29 #if __NR_SYSCALL_BASE != 0
30 # error Kernel headers are too old
31 #endif
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. */
36 #undef __NR_stime
37 #undef __NR_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
44 may be invoked. */
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
51 pointer.
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. */
61 #undef LOAD_ARGS_7
62 #undef INTERNAL_SYSCALL_RAW
63 #define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
64 ({ \
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" \
70 : "=r" (_a1) \
71 : "r" (_name) ASM_ARGS_##nr \
72 : "memory", "lr"); \
73 _a1; })
74 #else /* ARM */
75 #undef INTERNAL_SYSCALL_RAW
76 #define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
77 ({ \
78 register int _a1 asm ("r0"), _nr asm ("r7"); \
79 LOAD_ARGS_##nr (args) \
80 _nr = name; \
81 asm volatile ("swi 0x0 @ syscall " #name \
82 : "=r" (_a1) \
83 : "r" (_nr) ASM_ARGS_##nr \
84 : "memory"); \
85 _a1; })
86 #endif
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
103 syscalls. */
105 #undef DO_CALL
106 #define DO_CALL(syscall_name, args) \
107 DOARGS_##args; \
108 ldr r7, =SYS_ify (syscall_name); \
109 swi 0x0; \
110 UNDOARGS_##args
112 #undef DOARGS_0
113 #define DOARGS_0 \
114 .fnstart; \
115 str r7, [sp, #-4]!; \
116 cfi_adjust_cfa_offset (4); \
117 cfi_rel_offset (r7, 0); \
118 .save { r7 }
119 #undef DOARGS_1
120 #define DOARGS_1 DOARGS_0
121 #undef DOARGS_2
122 #define DOARGS_2 DOARGS_0
123 #undef DOARGS_3
124 #define DOARGS_3 DOARGS_0
125 #undef DOARGS_4
126 #define DOARGS_4 DOARGS_0
127 #undef DOARGS_5
128 #define DOARGS_5 \
129 .fnstart; \
130 stmfd sp!, {r4, r7}; \
131 cfi_adjust_cfa_offset (8); \
132 cfi_rel_offset (r4, 0); \
133 cfi_rel_offset (r7, 4); \
134 .save { r4, r7 }; \
135 ldr r4, [sp, #8]
136 #undef DOARGS_6
137 #define DOARGS_6 \
138 .fnstart; \
139 mov ip, sp; \
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 }; \
146 ldmia ip, {r4, r5}
147 #undef DOARGS_7
148 #define DOARGS_7 \
149 .fnstart; \
150 mov ip, sp; \
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}
160 #undef UNDOARGS_0
161 #define UNDOARGS_0 \
162 ldr r7, [sp], #4; \
163 cfi_adjust_cfa_offset (-4); \
164 cfi_restore (r7); \
165 .fnend
166 #undef UNDOARGS_1
167 #define UNDOARGS_1 UNDOARGS_0
168 #undef UNDOARGS_2
169 #define UNDOARGS_2 UNDOARGS_0
170 #undef UNDOARGS_3
171 #define UNDOARGS_3 UNDOARGS_0
172 #undef UNDOARGS_4
173 #define UNDOARGS_4 UNDOARGS_0
174 #undef UNDOARGS_5
175 #define UNDOARGS_5 \
176 ldmfd sp!, {r4, r7}; \
177 cfi_adjust_cfa_offset (-8); \
178 cfi_restore (r4); \
179 cfi_restore (r7); \
180 .fnend
181 #undef UNDOARGS_6
182 #define UNDOARGS_6 \
183 ldmfd sp!, {r4, r5, r7}; \
184 cfi_adjust_cfa_offset (-12); \
185 cfi_restore (r4); \
186 cfi_restore (r5); \
187 cfi_restore (r7); \
188 .fnend
189 #undef UNDOARGS_7
190 #define UNDOARGS_7 \
191 ldmfd sp!, {r4, r5, r6, r7}; \
192 cfi_adjust_cfa_offset (-16); \
193 cfi_restore (r4); \
194 cfi_restore (r5); \
195 cfi_restore (r6); \
196 cfi_restore (r7); \
197 .fnend
199 #endif /* _LINUX_ARM_EABI_SYSDEP_H */