Add CFI statements to ARM's assembly code.
[glibc.git] / sysdeps / unix / sysv / linux / arm / eabi / sysdep.h
blob9d90f3e35fba505541e4217e6cc09e622706bf8e
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, write to the Free
20 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 02111-1307 USA. */
23 #ifndef _LINUX_ARM_EABI_SYSDEP_H
24 #define _LINUX_ARM_EABI_SYSDEP_H 1
26 #include <arm/sysdep.h>
28 #include <tls.h>
30 #if __NR_SYSCALL_BASE != 0
31 # error Kernel headers are too old
32 #endif
34 /* Don't use stime, even if the kernel headers define it. We have
35 settimeofday, and some EABI kernels have removed stime. Similarly
36 use setitimer to implement alarm. */
37 #undef __NR_stime
38 #undef __NR_alarm
40 /* The ARM EABI user interface passes the syscall number in r7, instead
41 of in the swi. This is more efficient, because the kernel does not need
42 to fetch the swi from memory to find out the number; which can be painful
43 with separate I-cache and D-cache. Make sure to use 0 for the SWI
44 argument; otherwise the (optional) compatibility code for APCS binaries
45 may be invoked. */
47 #ifdef __thumb__
48 /* Hide the use of r7 from the compiler, this would be a lot
49 easier but for the fact that the syscalls can exceed 255.
50 For the moment the LOAD_ARGS_7 is sacrificed.
51 We can't use push/pop inside the asm because that breaks
52 unwinding (ie. thread cancellation). */
53 /* FIXME: the str / ldr of r7 are not covered by CFI information. */
54 #undef LOAD_ARGS_7
55 #undef INTERNAL_SYSCALL_RAW
56 #define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
57 ({ \
58 int _sys_buf[2]; \
59 register int _a1 asm ("a1"); \
60 register int *_r6 asm ("r6") = _sys_buf; \
61 *_r6 = name; \
62 LOAD_ARGS_##nr (args) \
63 asm volatile ("str r7, [r6, #4]\n\t" \
64 "ldr r7, [r6]\n\t" \
65 "swi 0 @ syscall " #name "\n\t" \
66 "ldr r7, [r6, #4]" \
67 : "=r" (_a1) \
68 : "r" (_r6) ASM_ARGS_##nr \
69 : "memory"); \
70 _a1; })
71 #else /* ARM */
72 #undef INTERNAL_SYSCALL_RAW
73 #define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
74 ({ \
75 register int _a1 asm ("r0"), _nr asm ("r7"); \
76 LOAD_ARGS_##nr (args) \
77 _nr = name; \
78 asm volatile ("swi 0x0 @ syscall " #name \
79 : "=r" (_a1) \
80 : "r" (_nr) ASM_ARGS_##nr \
81 : "memory"); \
82 _a1; })
83 #endif
85 /* For EABI, non-constant syscalls are actually pretty easy... */
86 #undef INTERNAL_SYSCALL_NCS
87 #define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
88 INTERNAL_SYSCALL_RAW (number, err, nr, args)
90 /* We must save and restore r7 (call-saved) for the syscall number.
91 We never make function calls from inside here (only potentially
92 signal handlers), so we do not bother with doubleword alignment.
94 Just like the APCS syscall convention, the EABI syscall convention uses
95 r0 through r6 for up to seven syscall arguments. None are ever passed to
96 the kernel on the stack, although incoming arguments are on the stack for
97 syscalls with five or more arguments.
99 The assembler will convert the literal pool load to a move for most
100 syscalls. */
102 #undef DO_CALL
103 #define DO_CALL(syscall_name, args) \
104 DOARGS_##args; \
105 mov ip, r7; \
106 cfi_register (r7, ip); \
107 ldr r7, =SYS_ify (syscall_name); \
108 swi 0x0; \
109 mov r7, ip; \
110 cfi_restore (r7); \
111 UNDOARGS_##args
113 #endif /* _LINUX_ARM_EABI_SYSDEP_H */