Add CFI statements to ARM's assembly code.
[glibc-ports.git] / sysdeps / unix / sysv / linux / arm / sysdep.h
blobbd5b2ce3e452406b02989c9d235e9282e4ea5385
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
20 02111-1307 USA. */
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>
31 #include <tls.h>
33 /* In order to get __set_errno() definition in INLINE_SYSCALL. */
34 #ifndef __ASSEMBLER__
35 #include <errno.h>
36 #endif
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. */
42 #undef SYS_ify
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
59 #ifdef __ASSEMBLER__
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
70 test with -4095. */
72 #undef PSEUDO
73 #define PSEUDO(name, syscall_name, args) \
74 .text; \
75 ENTRY (name); \
76 DO_CALL (syscall_name, args); \
77 cmn r0, $4096;
79 #define PSEUDO_RET \
80 RETINSTR(cc, lr); \
81 b PLTJMP(SYSCALL_ERROR)
82 #undef ret
83 #define ret PSEUDO_RET
85 #undef PSEUDO_END
86 #define PSEUDO_END(name) \
87 SYSCALL_ERROR_HANDLER; \
88 END (name)
90 #undef PSEUDO_NOERRNO
91 #define PSEUDO_NOERRNO(name, syscall_name, args) \
92 .text; \
93 ENTRY (name); \
94 DO_CALL (syscall_name, args);
96 #define PSEUDO_RET_NOERRNO \
97 DO_RET (lr);
99 #undef ret_NOERRNO
100 #define ret_NOERRNO PSEUDO_RET_NOERRNO
102 #undef PSEUDO_END_NOERRNO
103 #define PSEUDO_END_NOERRNO(name) \
104 END (name)
106 /* The function has to return the error code. */
107 #undef PSEUDO_ERRVAL
108 #define PSEUDO_ERRVAL(name, syscall_name, args) \
109 .text; \
110 ENTRY (name) \
111 DO_CALL (syscall_name, args); \
112 rsb r0, r0, #0
114 #undef PSEUDO_END_ERRVAL
115 #define PSEUDO_END_ERRVAL(name) \
116 END (name)
118 #define ret_ERRVAL PSEUDO_RET_NOERRNO
120 #if NOT_IN_libc
121 # define SYSCALL_ERROR __local_syscall_error
122 # if RTLD_PRIVATE_ERRNO
123 # define SYSCALL_ERROR_HANDLER \
124 __local_syscall_error: \
125 ldr r1, 1f; \
126 rsb r0, r0, #0; \
127 0: str r0, [pc, r1]; \
128 mvn r0, #0; \
129 DO_RET(lr); \
130 1: .word C_SYMBOL_NAME(rtld_errno) - 0b - 8;
131 # else
132 # if defined(__ARM_ARCH_4T__) && defined(__THUMB_INTERWORK__)
133 # define POP_PC \
134 ldr lr, [sp], #4; \
135 cfi_adjust_cfa_offset (-4); \
136 cfi_restore (lr); \
137 bx lr
138 # else
139 # define POP_PC \
140 ldr pc, [sp], #4
141 # endif
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)); \
150 ldr r1, [sp], #4; \
151 cfi_adjust_cfa_offset (-4); \
152 rsb r1, r1, #0; \
153 str r1, [r0]; \
154 mvn r0, #0; \
155 POP_PC;
156 # endif
157 #else
158 # define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
159 # define SYSCALL_ERROR __syscall_error
160 #endif
162 /* Linux takes system call args in registers:
163 syscall number in the SWI instruction
164 arg 1 r0
165 arg 2 r1
166 arg 3 r2
167 arg 4 r3
168 arg 5 r4 (this is different from the APCS convention)
169 arg 6 r5
170 arg 7 r6
172 The compiler is going to form a call by coming here, through PSEUDO, with
173 arguments
174 syscall number in the DO_CALL macro
175 arg 1 r0
176 arg 2 r1
177 arg 3 r2
178 arg 4 r3
179 arg 5 [sp]
180 arg 6 [sp+4]
181 arg 7 [sp+8]
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.
189 #undef DO_CALL
190 #define DO_CALL(syscall_name, args) \
191 DOARGS_##args; \
192 swi SYS_ify (syscall_name); \
193 UNDOARGS_##args
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 */
200 #define DOARGS_5 \
201 str r4, [sp, $-4]!; \
202 cfi_adjust_cfa_offset (4); \
203 cfi_rel_offset (r4, 0); \
204 ldr r4, [sp, $4]
205 #define DOARGS_6 \
206 mov ip, sp; \
207 stmfd sp!, {r4, r5}; \
208 cfi_adjust_cfa_offset (8); \
209 cfi_rel_offset (r4, 0); \
210 cfi_rel_offset (r5, 4); \
211 ldmia ip, {r4, r5}
212 #define DOARGS_7 \
213 mov ip, sp; \
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 */
226 #define UNDOARGS_5 \
227 ldr r4, [sp], $4; \
228 cfi_adjust_cfa_offset (-4); \
229 cfi_restore (r4)
230 #define UNDOARGS_6 \
231 ldmfd sp!, {r4, r5}; \
232 cfi_adjust_cfa_offset (-8); \
233 cfi_restore (r4); \
234 cfi_restore (r5)
235 #define UNDOARGS_7 \
236 ldmfd sp!, {r4, r5, r6}; \
237 cfi_adjust_cfa_offset (-12); \
238 cfi_restore (r4); \
239 cfi_restore (r5); \
240 cfi_restore (r6)
242 #else /* not __ASSEMBLER__ */
244 /* Define a macro which expands into the inline wrapper code for a system
245 call. */
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 \
266 : "=r" (_a1) \
267 : "i" (name) ASM_ARGS_##nr \
268 : "memory"); \
269 _sys_result = _a1; \
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()
289 #define ASM_ARGS_0
290 #define LOAD_ARGS_1(a1) \
291 int _a1tmp = (int) (a1); \
292 LOAD_ARGS_0 () \
293 _a1 = _a1tmp;
294 #define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
295 #define LOAD_ARGS_2(a1, a2) \
296 int _a2tmp = (int) (a2); \
297 LOAD_ARGS_1 (a1) \
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 */