]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/arm/sysdep.h
1 /* Copyright (C) 1992-2019 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.
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.
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.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library. If not, see
18 <https://www.gnu.org/licenses/>. */
20 #ifndef _LINUX_ARM_SYSDEP_H
21 #define _LINUX_ARM_SYSDEP_H 1
23 /* There is some commonality. */
24 #include <sysdeps/unix/sysv/linux/sysdep.h>
25 #include <sysdeps/unix/arm/sysdep.h>
27 /* Defines RTLD_PRIVATE_ERRNO and USE_DL_SYSINFO. */
28 #include <dl-sysdep.h>
32 /* In order to get __set_errno() definition in INLINE_SYSCALL. */
37 /* For Linux we can use the system call table in the header file
38 /usr/include/asm/unistd.h
39 of the kernel. But these symbols do not follow the SYS_* syntax
40 so we have to redefine the `SYS_ify' macro here. */
42 #define SYS_ify(syscall_name) (__NR_##syscall_name)
44 #include <bits/hwcap.h>
48 #ifndef ARCH_HAS_HARD_TP
49 /* Internal macro calling the linux kernel kuser_get_tls helper.
50 Note that in thumb mode, a constant pool break is often out of range, so
51 we always expand the constant inline. */
53 # define GET_TLS_BODY \
58 # define GET_TLS_BODY \
59 mov r0, #0xffff0fff; /* Point to the high page. */ \
60 mov lr, pc; /* Save our return address. */ \
61 sub pc, r0, #31 /* Jump to the TLS entry. */
64 /* Helper to get the TLS base pointer. Save LR in TMP, return in R0,
65 and no other registers clobbered. TMP may be LR itself to indicate
66 that no save is necessary. */
68 # define GET_TLS(TMP) \
71 cfi_register (lr, TMP); \
78 #endif /* ARCH_HAS_HARD_TP */
80 /* Linux uses a negative return value to indicate syscall errors,
81 unlike most Unices, which use the condition codes' carry flag.
83 Since version 2.1 the return value of a system call might be
84 negative even if the call succeeded. E.g., the `lseek' system call
85 might return a large offset. Therefore we must not anymore test
86 for < 0, but test for a real error by making sure the value in R0
87 is a real error number. Linus said he will make sure the no syscall
88 returns a value in -1 .. -4095 as a valid result so we can safely
92 #define PSEUDO(name, syscall_name, args) \
95 DO_CALL (syscall_name, args); \
101 b PLTJMP(SYSCALL_ERROR)
103 #define ret PSEUDO_RET
106 #define PSEUDO_END(name) \
107 SYSCALL_ERROR_HANDLER; \
110 #undef PSEUDO_NOERRNO
111 #define PSEUDO_NOERRNO(name, syscall_name, args) \
114 DO_CALL (syscall_name, args);
116 #define PSEUDO_RET_NOERRNO \
120 #define ret_NOERRNO PSEUDO_RET_NOERRNO
122 #undef PSEUDO_END_NOERRNO
123 #define PSEUDO_END_NOERRNO(name) \
126 /* The function has to return the error code. */
128 #define PSEUDO_ERRVAL(name, syscall_name, args) \
131 DO_CALL (syscall_name, args); \
134 #undef PSEUDO_END_ERRVAL
135 #define PSEUDO_END_ERRVAL(name) \
138 #define ret_ERRVAL PSEUDO_RET_NOERRNO
141 # define SYSCALL_ERROR __local_syscall_error
142 # if RTLD_PRIVATE_ERRNO
143 # define SYSCALL_ERROR_HANDLER \
144 __local_syscall_error: \
146 LDST_PCREL(str, r0, r1, C_SYMBOL_NAME(rtld_errno)); \
150 # if defined(__ARM_ARCH_4T__) && defined(__THUMB_INTERWORK__)
153 cfi_adjust_cfa_offset (-4); \
157 # define POP_PC pop { pc }
159 # define SYSCALL_ERROR_HANDLER \
160 __local_syscall_error: \
162 cfi_adjust_cfa_offset (4); \
163 cfi_rel_offset (lr, 0); \
165 cfi_adjust_cfa_offset (4); \
166 bl PLTJMP(C_SYMBOL_NAME(__errno_location)); \
168 cfi_adjust_cfa_offset (-4); \
175 # define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
176 # define SYSCALL_ERROR __syscall_error
179 /* The ARM EABI user interface passes the syscall number in r7, instead
180 of in the swi. This is more efficient, because the kernel does not need
181 to fetch the swi from memory to find out the number; which can be painful
182 with separate I-cache and D-cache. Make sure to use 0 for the SWI
183 argument; otherwise the (optional) compatibility code for APCS binaries
186 /* Linux takes system call args in registers:
191 arg 5 r4 (this is different from the APCS convention)
195 The compiler is going to form a call by coming here, through PSEUDO, with
197 syscall number in the DO_CALL macro
206 We need to shuffle values between R4..R6 and the stack so that the
207 caller's v1..v3 and stack frame are not corrupted, and the kernel
208 sees the right arguments.
212 /* We must save and restore r7 (call-saved) for the syscall number.
213 We never make function calls from inside here (only potentially
214 signal handlers), so we do not bother with doubleword alignment.
216 Just like the APCS syscall convention, the EABI syscall convention uses
217 r0 through r6 for up to seven syscall arguments. None are ever passed to
218 the kernel on the stack, although incoming arguments are on the stack for
219 syscalls with five or more arguments.
221 The assembler will convert the literal pool load to a move for most
225 #define DO_CALL(syscall_name, args) \
227 ldr r7, =SYS_ify (syscall_name); \
235 cfi_adjust_cfa_offset (4); \
236 cfi_rel_offset (r7, 0); \
239 #define DOARGS_1 DOARGS_0
241 #define DOARGS_2 DOARGS_0
243 #define DOARGS_3 DOARGS_0
245 #define DOARGS_4 DOARGS_0
250 cfi_adjust_cfa_offset (8); \
251 cfi_rel_offset (r4, 0); \
252 cfi_rel_offset (r7, 4); \
260 cfi_adjust_cfa_offset (12); \
261 cfi_rel_offset (r4, 0); \
262 cfi_rel_offset (r5, 4); \
263 cfi_rel_offset (r7, 8); \
264 .save { r4, r5, r7 }; \
270 push {r4, r5, r6, r7}; \
271 cfi_adjust_cfa_offset (16); \
272 cfi_rel_offset (r4, 0); \
273 cfi_rel_offset (r5, 4); \
274 cfi_rel_offset (r6, 8); \
275 cfi_rel_offset (r7, 12); \
276 .save { r4, r5, r6, r7 }; \
277 ldmia ip, {r4, r5, r6}
282 cfi_adjust_cfa_offset (-4); \
286 #define UNDOARGS_1 UNDOARGS_0
288 #define UNDOARGS_2 UNDOARGS_0
290 #define UNDOARGS_3 UNDOARGS_0
292 #define UNDOARGS_4 UNDOARGS_0
296 cfi_adjust_cfa_offset (-8); \
303 cfi_adjust_cfa_offset (-12); \
310 pop {r4, r5, r6, r7}; \
311 cfi_adjust_cfa_offset (-16); \
318 #else /* not __ASSEMBLER__ */
320 /* Define a macro which expands into the inline wrapper code for a system
322 #undef INLINE_SYSCALL
323 #define INLINE_SYSCALL(name, nr, args...) \
324 ({ unsigned int _sys_result = INTERNAL_SYSCALL (name, , nr, args); \
325 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0)) \
327 __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, )); \
328 _sys_result = (unsigned int) -1; \
330 (int) _sys_result; })
332 #undef INTERNAL_SYSCALL_DECL
333 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
335 #if defined(__thumb__)
336 /* We can not expose the use of r7 to the compiler. GCC (as
337 of 4.5) uses r7 as the hard frame pointer for Thumb - although
338 for Thumb-2 it isn't obviously a better choice than r11.
339 And GCC does not support asms that conflict with the frame
342 This would be easier if syscall numbers never exceeded 255,
343 but they do. For the moment the LOAD_ARGS_7 is sacrificed.
344 We can't use push/pop inside the asm because that breaks
345 unwinding (i.e. thread cancellation) for this frame. We can't
346 locally save and restore r7, because we do not know if this
347 function uses r7 or if it is our caller's r7; if it is our caller's,
348 then unwinding will fail higher up the stack. So we move the
349 syscall out of line and provide its own unwind information. */
350 # undef INTERNAL_SYSCALL_RAW
351 # define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
353 register int _a1 asm ("a1"); \
354 int _nametmp = name; \
355 LOAD_ARGS_##nr (args) \
356 register int _name asm ("ip") = _nametmp; \
357 asm volatile ("bl __libc_do_syscall" \
359 : "r" (_name) ASM_ARGS_##nr \
363 # undef INTERNAL_SYSCALL_RAW
364 # define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
366 register int _a1 asm ("r0"), _nr asm ("r7"); \
367 LOAD_ARGS_##nr (args) \
369 asm volatile ("swi 0x0 @ syscall " #name \
371 : "r" (_nr) ASM_ARGS_##nr \
376 #undef INTERNAL_SYSCALL
377 #define INTERNAL_SYSCALL(name, err, nr, args...) \
378 INTERNAL_SYSCALL_RAW(SYS_ify(name), err, nr, args)
380 #undef INTERNAL_SYSCALL_ARM
381 #define INTERNAL_SYSCALL_ARM(name, err, nr, args...) \
382 INTERNAL_SYSCALL_RAW(__ARM_NR_##name, err, nr, args)
384 #undef INTERNAL_SYSCALL_ERROR_P
385 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
386 ((unsigned int) (val) >= 0xfffff001u)
388 #undef INTERNAL_SYSCALL_ERRNO
389 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
391 #define VDSO_NAME "LINUX_2.6"
392 #define VDSO_HASH 61765110
394 /* List of system calls which are supported as vsyscalls. */
395 #define HAVE_CLOCK_GETTIME_VSYSCALL 1
396 #define HAVE_GETTIMEOFDAY_VSYSCALL 1
398 #define LOAD_ARGS_0()
400 #define LOAD_ARGS_1(a1) \
401 int _a1tmp = (int) (a1); \
404 #define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
405 #define LOAD_ARGS_2(a1, a2) \
406 int _a2tmp = (int) (a2); \
408 register int _a2 asm ("a2") = _a2tmp;
409 #define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2)
410 #define LOAD_ARGS_3(a1, a2, a3) \
411 int _a3tmp = (int) (a3); \
412 LOAD_ARGS_2 (a1, a2) \
413 register int _a3 asm ("a3") = _a3tmp;
414 #define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3)
415 #define LOAD_ARGS_4(a1, a2, a3, a4) \
416 int _a4tmp = (int) (a4); \
417 LOAD_ARGS_3 (a1, a2, a3) \
418 register int _a4 asm ("a4") = _a4tmp;
419 #define ASM_ARGS_4 ASM_ARGS_3, "r" (_a4)
420 #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
421 int _v1tmp = (int) (a5); \
422 LOAD_ARGS_4 (a1, a2, a3, a4) \
423 register int _v1 asm ("v1") = _v1tmp;
424 #define ASM_ARGS_5 ASM_ARGS_4, "r" (_v1)
425 #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
426 int _v2tmp = (int) (a6); \
427 LOAD_ARGS_5 (a1, a2, a3, a4, a5) \
428 register int _v2 asm ("v2") = _v2tmp;
429 #define ASM_ARGS_6 ASM_ARGS_5, "r" (_v2)
431 # define LOAD_ARGS_7(a1, a2, a3, a4, a5, a6, a7) \
432 int _v3tmp = (int) (a7); \
433 LOAD_ARGS_6 (a1, a2, a3, a4, a5, a6) \
434 register int _v3 asm ("v3") = _v3tmp;
435 # define ASM_ARGS_7 ASM_ARGS_6, "r" (_v3)
438 /* For EABI, non-constant syscalls are actually pretty easy... */
439 #undef INTERNAL_SYSCALL_NCS
440 #define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
441 INTERNAL_SYSCALL_RAW (number, err, nr, args)
443 #define SINGLE_THREAD_BY_GLOBAL 1
445 #endif /* __ASSEMBLER__ */
447 #endif /* linux/arm/sysdep.h */