]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/arm/sysdep.h
Update.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / arm / sysdep.h
1 /* Copyright (C) 1992, 93, 1995-2000, 2002, 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>, August 1995.
4 ARM changes by Philip Blundell, <pjb27@cam.ac.uk>, May 1997.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21 #ifndef _LINUX_ARM_SYSDEP_H
22 #define _LINUX_ARM_SYSDEP_H 1
23
24 /* There is some commonality. */
25 #include <sysdeps/unix/arm/sysdep.h>
26
27 /* For Linux we can use the system call table in the header file
28 /usr/include/asm/unistd.h
29 of the kernel. But these symbols do not follow the SYS_* syntax
30 so we have to redefine the `SYS_ify' macro here. */
31 #undef SYS_ify
32 #define SWI_BASE (0x900000)
33 #define SYS_ify(syscall_name) (__NR_##syscall_name)
34
35
36 #ifdef __ASSEMBLER__
37
38 /* Linux uses a negative return value to indicate syscall errors,
39 unlike most Unices, which use the condition codes' carry flag.
40
41 Since version 2.1 the return value of a system call might be
42 negative even if the call succeeded. E.g., the `lseek' system call
43 might return a large offset. Therefore we must not anymore test
44 for < 0, but test for a real error by making sure the value in R0
45 is a real error number. Linus said he will make sure the no syscall
46 returns a value in -1 .. -4095 as a valid result so we can savely
47 test with -4095. */
48
49 #undef PSEUDO
50 #define PSEUDO(name, syscall_name, args) \
51 .text; \
52 ENTRY (name); \
53 DO_CALL (syscall_name, args); \
54 cmn r0, $4096;
55
56 #define PSEUDO_RET \
57 RETINSTR(movcc, pc, lr); \
58 b PLTJMP(SYSCALL_ERROR)
59 #undef ret
60 #define ret PSEUDO_RET
61
62 #undef PSEUDO_END
63 #define PSEUDO_END(name) \
64 SYSCALL_ERROR_HANDLER \
65 END (name)
66
67 #if NOT_IN_libc
68 # define SYSCALL_ERROR __local_syscall_error
69 # define SYSCALL_ERROR_HANDLER \
70 __local_syscall_error: \
71 str lr, [sp, #-4]!; \
72 str r0, [sp, #-4]!; \
73 bl PLTJMP(C_SYMBOL_NAME(__errno_location)); \
74 ldr r1, [sp], #4; \
75 rsb r1, r1, #0; \
76 str r1, [r0]; \
77 mvn r0, #0; \
78 ldr pc, [sp], #4;
79 #else
80 # define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
81 # define SYSCALL_ERROR __syscall_error
82 #endif
83
84 /* Linux takes system call args in registers:
85 syscall number in the SWI instruction
86 arg 1 r0
87 arg 2 r1
88 arg 3 r2
89 arg 4 r3
90 arg 5 r4 (this is different from the APCS convention)
91 arg 6 r5
92 arg 7 r6
93
94 The compiler is going to form a call by coming here, through PSEUDO, with
95 arguments
96 syscall number in the DO_CALL macro
97 arg 1 r0
98 arg 2 r1
99 arg 3 r2
100 arg 4 r3
101 arg 5 [sp]
102 arg 6 [sp+4]
103 arg 7 [sp+8]
104
105 We need to shuffle values between R4..R6 and the stack so that the
106 caller's v1..v3 and stack frame are not corrupted, and the kernel
107 sees the right arguments.
108
109 */
110
111 #undef DO_CALL
112 #define DO_CALL(syscall_name, args) \
113 DOARGS_##args \
114 swi SYS_ify (syscall_name); \
115 UNDOARGS_##args
116
117 #define DOARGS_0 /* nothing */
118 #define DOARGS_1 /* nothing */
119 #define DOARGS_2 /* nothing */
120 #define DOARGS_3 /* nothing */
121 #define DOARGS_4 /* nothing */
122 #define DOARGS_5 str r4, [sp, $-4]!; ldr r4, [sp, $4];
123 #define DOARGS_6 mov ip, sp; stmfd sp!, {r4, r5}; ldmia ip, {r4, r5};
124 #define DOARGS_7 mov ip, sp; stmfd sp!, {r4, r5, r6}; ldmia ip, {r4, r5, r6};
125
126 #define UNDOARGS_0 /* nothing */
127 #define UNDOARGS_1 /* nothing */
128 #define UNDOARGS_2 /* nothing */
129 #define UNDOARGS_3 /* nothing */
130 #define UNDOARGS_4 /* nothing */
131 #define UNDOARGS_5 ldr r4, [sp], $4;
132 #define UNDOARGS_6 ldmfd sp!, {r4, r5};
133 #define UNDOARGS_7 ldmfd sp!, {r4, r5, r6};
134
135 #else /* not __ASSEMBLER__ */
136
137 /* Define a macro which expands into the inline wrapper code for a system
138 call. */
139 #undef INLINE_SYSCALL
140 #define INLINE_SYSCALL(name, nr, args...) \
141 ({ unsigned int _sys_result = INTERNAL_SYSCALL (name, , nr, args); \
142 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0)) \
143 { \
144 __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, )); \
145 _sys_result = (unsigned int) -1; \
146 } \
147 (int) _sys_result; })
148
149 #undef INTERNAL_SYSCALL_DECL
150 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
151
152 #undef INTERNAL_SYSCALL
153 #define INTERNAL_SYSCALL(name, err, nr, args...) \
154 ({ unsigned int _sys_result; \
155 { \
156 register int _a1 asm ("a1"); \
157 LOAD_ARGS_##nr (args) \
158 asm volatile ("swi %1 @ syscall " #name \
159 : "=r" (_a1) \
160 : "i" (SYS_ify(name)) ASM_ARGS_##nr \
161 : "a1", "memory"); \
162 _sys_result = _a1; \
163 } \
164 (int) _sys_result; })
165
166 #undef INTERNAL_SYSCALL_ERROR_P
167 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
168 ((unsigned int) (val) >= 0xfffff001u)
169
170 #undef INTERNAL_SYSCALL_ERRNO
171 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
172
173 #define LOAD_ARGS_0()
174 #define ASM_ARGS_0
175 #define LOAD_ARGS_1(a1) \
176 _a1 = (int) (a1); \
177 LOAD_ARGS_0 ()
178 #define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
179 #define LOAD_ARGS_2(a1, a2) \
180 register int _a2 asm ("a2") = (int) (a2); \
181 LOAD_ARGS_1 (a1)
182 #define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2)
183 #define LOAD_ARGS_3(a1, a2, a3) \
184 register int _a3 asm ("a3") = (int) (a3); \
185 LOAD_ARGS_2 (a1, a2)
186 #define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3)
187 #define LOAD_ARGS_4(a1, a2, a3, a4) \
188 register int _a4 asm ("a4") = (int) (a4); \
189 LOAD_ARGS_3 (a1, a2, a3)
190 #define ASM_ARGS_4 ASM_ARGS_3, "r" (_a4)
191 #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
192 register int _v1 asm ("v1") = (int) (a5); \
193 LOAD_ARGS_4 (a1, a2, a3, a4)
194 #define ASM_ARGS_5 ASM_ARGS_4, "r" (_v1)
195 #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
196 register int _v2 asm ("v2") = (int) (a6); \
197 LOAD_ARGS_5 (a1, a2, a3, a4, a5)
198 #define ASM_ARGS_6 ASM_ARGS_5, "r" (_v2)
199 #define LOAD_ARGS_7(a1, a2, a3, a4, a5, a6, a7) \
200 register int _v3 asm ("v3") = (int) (a7); \
201 LOAD_ARGS_6 (a1, a2, a3, a4, a5, a6)
202 #define ASM_ARGS_7 ASM_ARGS_6, "r" (_v3)
203
204 #endif /* __ASSEMBLER__ */
205
206 #endif /* linux/arm/sysdep.h */