Define F_DUPFD_CLOEXEC.
[glibc-ports.git] / sysdeps / unix / sysv / linux / arm / sysdep.h
blob2952067b976b5e112c7a3a282c2f29dd00b98799
1 /* Copyright (C) 1992, 93, 1995-2000, 2002, 2003, 2005, 2006
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 /* For Linux we can use the system call table in the header file
32 /usr/include/asm/unistd.h
33 of the kernel. But these symbols do not follow the SYS_* syntax
34 so we have to redefine the `SYS_ify' macro here. */
35 #undef SYS_ify
36 #define SWI_BASE (0x900000)
37 #define SYS_ify(syscall_name) (__NR_##syscall_name)
40 /* The following must match the kernel's <asm/procinfo.h>. */
41 #define HWCAP_ARM_SWP 1
42 #define HWCAP_ARM_HALF 2
43 #define HWCAP_ARM_THUMB 4
44 #define HWCAP_ARM_26BIT 8
45 #define HWCAP_ARM_FAST_MULT 16
46 #define HWCAP_ARM_FPA 32
47 #define HWCAP_ARM_VFP 64
48 #define HWCAP_ARM_EDSP 128
49 #define HWCAP_ARM_JAVA 256
50 #define HWCAP_ARM_IWMMXT 512
52 #ifdef __ASSEMBLER__
54 /* Linux uses a negative return value to indicate syscall errors,
55 unlike most Unices, which use the condition codes' carry flag.
57 Since version 2.1 the return value of a system call might be
58 negative even if the call succeeded. E.g., the `lseek' system call
59 might return a large offset. Therefore we must not anymore test
60 for < 0, but test for a real error by making sure the value in R0
61 is a real error number. Linus said he will make sure the no syscall
62 returns a value in -1 .. -4095 as a valid result so we can safely
63 test with -4095. */
65 #undef PSEUDO
66 #define PSEUDO(name, syscall_name, args) \
67 .text; \
68 ENTRY (name); \
69 DO_CALL (syscall_name, args); \
70 cmn r0, $4096;
72 #define PSEUDO_RET \
73 RETINSTR(cc, lr); \
74 b PLTJMP(SYSCALL_ERROR)
75 #undef ret
76 #define ret PSEUDO_RET
78 #undef PSEUDO_END
79 #define PSEUDO_END(name) \
80 SYSCALL_ERROR_HANDLER \
81 END (name)
83 #undef PSEUDO_NOERRNO
84 #define PSEUDO_NOERRNO(name, syscall_name, args) \
85 .text; \
86 ENTRY (name); \
87 DO_CALL (syscall_name, args);
89 #define PSEUDO_RET_NOERRNO \
90 DO_RET (lr);
92 #undef ret_NOERRNO
93 #define ret_NOERRNO PSEUDO_RET_NOERRNO
95 #undef PSEUDO_END_NOERRNO
96 #define PSEUDO_END_NOERRNO(name) \
97 END (name)
99 /* The function has to return the error code. */
100 #undef PSEUDO_ERRVAL
101 #define PSEUDO_ERRVAL(name, syscall_name, args) \
102 .text; \
103 ENTRY (name) \
104 DO_CALL (syscall_name, args); \
105 rsb r0, r0, #0
107 #undef PSEUDO_END_ERRVAL
108 #define PSEUDO_END_ERRVAL(name) \
109 END (name)
111 #define ret_ERRVAL PSEUDO_RET_NOERRNO
113 #if NOT_IN_libc
114 # define SYSCALL_ERROR __local_syscall_error
115 # if RTLD_PRIVATE_ERRNO
116 # define SYSCALL_ERROR_HANDLER \
117 __local_syscall_error: \
118 ldr r1, 1f; \
119 rsb r0, r0, #0; \
120 0: str r0, [pc, r1]; \
121 mvn r0, #0; \
122 DO_RET(lr); \
123 1: .word C_SYMBOL_NAME(rtld_errno) - 0b - 8;
124 # else
125 # define SYSCALL_ERROR_HANDLER \
126 __local_syscall_error: \
127 str lr, [sp, #-4]!; \
128 str r0, [sp, #-4]!; \
129 bl PLTJMP(C_SYMBOL_NAME(__errno_location)); \
130 ldr r1, [sp], #4; \
131 rsb r1, r1, #0; \
132 str r1, [r0]; \
133 mvn r0, #0; \
134 ldr pc, [sp], #4;
135 # endif
136 #else
137 # define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
138 # define SYSCALL_ERROR __syscall_error
139 #endif
141 /* Linux takes system call args in registers:
142 syscall number in the SWI instruction
143 arg 1 r0
144 arg 2 r1
145 arg 3 r2
146 arg 4 r3
147 arg 5 r4 (this is different from the APCS convention)
148 arg 6 r5
149 arg 7 r6
151 The compiler is going to form a call by coming here, through PSEUDO, with
152 arguments
153 syscall number in the DO_CALL macro
154 arg 1 r0
155 arg 2 r1
156 arg 3 r2
157 arg 4 r3
158 arg 5 [sp]
159 arg 6 [sp+4]
160 arg 7 [sp+8]
162 We need to shuffle values between R4..R6 and the stack so that the
163 caller's v1..v3 and stack frame are not corrupted, and the kernel
164 sees the right arguments.
168 #undef DO_CALL
169 #define DO_CALL(syscall_name, args) \
170 DOARGS_##args \
171 swi SYS_ify (syscall_name); \
172 UNDOARGS_##args
174 #define DOARGS_0 /* nothing */
175 #define DOARGS_1 /* nothing */
176 #define DOARGS_2 /* nothing */
177 #define DOARGS_3 /* nothing */
178 #define DOARGS_4 /* nothing */
179 #define DOARGS_5 str r4, [sp, $-4]!; ldr r4, [sp, $4];
180 #define DOARGS_6 mov ip, sp; stmfd sp!, {r4, r5}; ldmia ip, {r4, r5};
181 #define DOARGS_7 mov ip, sp; stmfd sp!, {r4, r5, r6}; ldmia ip, {r4, r5, r6};
183 #define UNDOARGS_0 /* nothing */
184 #define UNDOARGS_1 /* nothing */
185 #define UNDOARGS_2 /* nothing */
186 #define UNDOARGS_3 /* nothing */
187 #define UNDOARGS_4 /* nothing */
188 #define UNDOARGS_5 ldr r4, [sp], $4;
189 #define UNDOARGS_6 ldmfd sp!, {r4, r5};
190 #define UNDOARGS_7 ldmfd sp!, {r4, r5, r6};
192 #else /* not __ASSEMBLER__ */
194 /* Define a macro which expands into the inline wrapper code for a system
195 call. */
196 #undef INLINE_SYSCALL
197 #define INLINE_SYSCALL(name, nr, args...) \
198 ({ unsigned int _sys_result = INTERNAL_SYSCALL (name, , nr, args); \
199 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0)) \
201 __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, )); \
202 _sys_result = (unsigned int) -1; \
204 (int) _sys_result; })
206 #undef INTERNAL_SYSCALL_DECL
207 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
209 #undef INTERNAL_SYSCALL_RAW
210 #define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
211 ({ unsigned int _sys_result; \
213 register int _a1 asm ("a1"); \
214 LOAD_ARGS_##nr (args) \
215 asm volatile ("swi %1 @ syscall " #name \
216 : "=r" (_a1) \
217 : "i" (name) ASM_ARGS_##nr \
218 : "memory"); \
219 _sys_result = _a1; \
221 (int) _sys_result; })
223 #undef INTERNAL_SYSCALL
224 #define INTERNAL_SYSCALL(name, err, nr, args...) \
225 INTERNAL_SYSCALL_RAW(SYS_ify(name), err, nr, args)
227 #undef INTERNAL_SYSCALL_ARM
228 #define INTERNAL_SYSCALL_ARM(name, err, nr, args...) \
229 INTERNAL_SYSCALL_RAW(__ARM_NR_##name, err, nr, args)
231 #undef INTERNAL_SYSCALL_ERROR_P
232 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
233 ((unsigned int) (val) >= 0xfffff001u)
235 #undef INTERNAL_SYSCALL_ERRNO
236 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
238 #define LOAD_ARGS_0()
239 #define ASM_ARGS_0
240 #define LOAD_ARGS_1(a1) \
241 _a1 = (int) (a1); \
242 LOAD_ARGS_0 ()
243 #define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
244 #define LOAD_ARGS_2(a1, a2) \
245 register int _a2 asm ("a2") = (int) (a2); \
246 LOAD_ARGS_1 (a1)
247 #define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2)
248 #define LOAD_ARGS_3(a1, a2, a3) \
249 register int _a3 asm ("a3") = (int) (a3); \
250 LOAD_ARGS_2 (a1, a2)
251 #define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3)
252 #define LOAD_ARGS_4(a1, a2, a3, a4) \
253 register int _a4 asm ("a4") = (int) (a4); \
254 LOAD_ARGS_3 (a1, a2, a3)
255 #define ASM_ARGS_4 ASM_ARGS_3, "r" (_a4)
256 #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
257 register int _v1 asm ("v1") = (int) (a5); \
258 LOAD_ARGS_4 (a1, a2, a3, a4)
259 #define ASM_ARGS_5 ASM_ARGS_4, "r" (_v1)
260 #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
261 register int _v2 asm ("v2") = (int) (a6); \
262 LOAD_ARGS_5 (a1, a2, a3, a4, a5)
263 #define ASM_ARGS_6 ASM_ARGS_5, "r" (_v2)
264 #define LOAD_ARGS_7(a1, a2, a3, a4, a5, a6, a7) \
265 register int _v3 asm ("v3") = (int) (a7); \
266 LOAD_ARGS_6 (a1, a2, a3, a4, a5, a6)
267 #define ASM_ARGS_7 ASM_ARGS_6, "r" (_v3)
269 /* We can't implement non-constant syscalls directly since the syscall
270 number is normally encoded in the instruction. So use SYS_syscall. */
271 #define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
272 INTERNAL_SYSCALL_NCS_##nr (number, err, args)
274 #define INTERNAL_SYSCALL_NCS_0(number, err, args...) \
275 INTERNAL_SYSCALL (syscall, err, 1, number, args)
276 #define INTERNAL_SYSCALL_NCS_1(number, err, args...) \
277 INTERNAL_SYSCALL (syscall, err, 2, number, args)
278 #define INTERNAL_SYSCALL_NCS_2(number, err, args...) \
279 INTERNAL_SYSCALL (syscall, err, 3, number, args)
280 #define INTERNAL_SYSCALL_NCS_3(number, err, args...) \
281 INTERNAL_SYSCALL (syscall, err, 4, number, args)
282 #define INTERNAL_SYSCALL_NCS_4(number, err, args...) \
283 INTERNAL_SYSCALL (syscall, err, 5, number, args)
284 #define INTERNAL_SYSCALL_NCS_5(number, err, args...) \
285 INTERNAL_SYSCALL (syscall, err, 6, number, args)
287 #endif /* __ASSEMBLER__ */
289 /* Pointer mangling is not yet supported for ARM. */
290 #define PTR_MANGLE(var) (void) (var)
291 #define PTR_DEMANGLE(var) (void) (var)
293 #endif /* linux/arm/sysdep.h */