]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/arm/sysdep.h
e2985cffd71a1e667f52b01a69c70178f4a8f77c
1 /* Copyright (C) 1992-2020 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 /* For Linux we can use the system call table in the header file
33 /usr/include/asm/unistd.h
34 of the kernel. But these symbols do not follow the SYS_* syntax
35 so we have to redefine the `SYS_ify' macro here. */
37 #define SYS_ify(syscall_name) (__NR_##syscall_name)
39 #include <bits/hwcap.h>
43 #ifndef ARCH_HAS_HARD_TP
44 /* Internal macro calling the linux kernel kuser_get_tls helper.
45 Note that in thumb mode, a constant pool break is often out of range, so
46 we always expand the constant inline. */
48 # define GET_TLS_BODY \
53 # define GET_TLS_BODY \
54 mov r0, #0xffff0fff; /* Point to the high page. */ \
55 mov lr, pc; /* Save our return address. */ \
56 sub pc, r0, #31 /* Jump to the TLS entry. */
59 /* Helper to get the TLS base pointer. Save LR in TMP, return in R0,
60 and no other registers clobbered. TMP may be LR itself to indicate
61 that no save is necessary. */
63 # define GET_TLS(TMP) \
66 cfi_register (lr, TMP); \
73 #endif /* ARCH_HAS_HARD_TP */
75 /* Linux uses a negative return value to indicate syscall errors,
76 unlike most Unices, which use the condition codes' carry flag.
78 Since version 2.1 the return value of a system call might be
79 negative even if the call succeeded. E.g., the `lseek' system call
80 might return a large offset. Therefore we must not anymore test
81 for < 0, but test for a real error by making sure the value in R0
82 is a real error number. Linus said he will make sure the no syscall
83 returns a value in -1 .. -4095 as a valid result so we can safely
87 #define PSEUDO(name, syscall_name, args) \
90 DO_CALL (syscall_name, args); \
96 b PLTJMP(SYSCALL_ERROR)
98 #define ret PSEUDO_RET
101 #define PSEUDO_END(name) \
102 SYSCALL_ERROR_HANDLER; \
105 #undef PSEUDO_NOERRNO
106 #define PSEUDO_NOERRNO(name, syscall_name, args) \
109 DO_CALL (syscall_name, args);
111 #define PSEUDO_RET_NOERRNO \
115 #define ret_NOERRNO PSEUDO_RET_NOERRNO
117 #undef PSEUDO_END_NOERRNO
118 #define PSEUDO_END_NOERRNO(name) \
121 /* The function has to return the error code. */
123 #define PSEUDO_ERRVAL(name, syscall_name, args) \
126 DO_CALL (syscall_name, args); \
129 #undef PSEUDO_END_ERRVAL
130 #define PSEUDO_END_ERRVAL(name) \
133 #define ret_ERRVAL PSEUDO_RET_NOERRNO
136 # define SYSCALL_ERROR __local_syscall_error
137 # if RTLD_PRIVATE_ERRNO
138 # define SYSCALL_ERROR_HANDLER \
139 __local_syscall_error: \
141 LDST_PCREL(str, r0, r1, C_SYMBOL_NAME(rtld_errno)); \
145 # if defined(__ARM_ARCH_4T__) && defined(__THUMB_INTERWORK__)
148 cfi_adjust_cfa_offset (-4); \
152 # define POP_PC pop { pc }
154 # define SYSCALL_ERROR_HANDLER \
155 __local_syscall_error: \
157 cfi_adjust_cfa_offset (4); \
158 cfi_rel_offset (lr, 0); \
160 cfi_adjust_cfa_offset (4); \
161 bl PLTJMP(C_SYMBOL_NAME(__errno_location)); \
163 cfi_adjust_cfa_offset (-4); \
170 # define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
171 # define SYSCALL_ERROR __syscall_error
174 /* The ARM EABI user interface passes the syscall number in r7, instead
175 of in the swi. This is more efficient, because the kernel does not need
176 to fetch the swi from memory to find out the number; which can be painful
177 with separate I-cache and D-cache. Make sure to use 0 for the SWI
178 argument; otherwise the (optional) compatibility code for APCS binaries
181 /* Linux takes system call args in registers:
186 arg 5 r4 (this is different from the APCS convention)
190 The compiler is going to form a call by coming here, through PSEUDO, with
192 syscall number in the DO_CALL macro
201 We need to shuffle values between R4..R6 and the stack so that the
202 caller's v1..v3 and stack frame are not corrupted, and the kernel
203 sees the right arguments.
207 /* We must save and restore r7 (call-saved) for the syscall number.
208 We never make function calls from inside here (only potentially
209 signal handlers), so we do not bother with doubleword alignment.
211 Just like the APCS syscall convention, the EABI syscall convention uses
212 r0 through r6 for up to seven syscall arguments. None are ever passed to
213 the kernel on the stack, although incoming arguments are on the stack for
214 syscalls with five or more arguments.
216 The assembler will convert the literal pool load to a move for most
220 #define DO_CALL(syscall_name, args) \
222 ldr r7, =SYS_ify (syscall_name); \
230 cfi_adjust_cfa_offset (4); \
231 cfi_rel_offset (r7, 0); \
234 #define DOARGS_1 DOARGS_0
236 #define DOARGS_2 DOARGS_0
238 #define DOARGS_3 DOARGS_0
240 #define DOARGS_4 DOARGS_0
245 cfi_adjust_cfa_offset (8); \
246 cfi_rel_offset (r4, 0); \
247 cfi_rel_offset (r7, 4); \
255 cfi_adjust_cfa_offset (12); \
256 cfi_rel_offset (r4, 0); \
257 cfi_rel_offset (r5, 4); \
258 cfi_rel_offset (r7, 8); \
259 .save { r4, r5, r7 }; \
265 push {r4, r5, r6, r7}; \
266 cfi_adjust_cfa_offset (16); \
267 cfi_rel_offset (r4, 0); \
268 cfi_rel_offset (r5, 4); \
269 cfi_rel_offset (r6, 8); \
270 cfi_rel_offset (r7, 12); \
271 .save { r4, r5, r6, r7 }; \
272 ldmia ip, {r4, r5, r6}
277 cfi_adjust_cfa_offset (-4); \
281 #define UNDOARGS_1 UNDOARGS_0
283 #define UNDOARGS_2 UNDOARGS_0
285 #define UNDOARGS_3 UNDOARGS_0
287 #define UNDOARGS_4 UNDOARGS_0
291 cfi_adjust_cfa_offset (-8); \
298 cfi_adjust_cfa_offset (-12); \
305 pop {r4, r5, r6, r7}; \
306 cfi_adjust_cfa_offset (-16); \
313 #else /* not __ASSEMBLER__ */
315 #if defined(__thumb__)
316 /* We can not expose the use of r7 to the compiler. GCC (as
317 of 4.5) uses r7 as the hard frame pointer for Thumb - although
318 for Thumb-2 it isn't obviously a better choice than r11.
319 And GCC does not support asms that conflict with the frame
322 This would be easier if syscall numbers never exceeded 255,
323 but they do. For the moment the LOAD_ARGS_7 is sacrificed.
324 We can't use push/pop inside the asm because that breaks
325 unwinding (i.e. thread cancellation) for this frame. We can't
326 locally save and restore r7, because we do not know if this
327 function uses r7 or if it is our caller's r7; if it is our caller's,
328 then unwinding will fail higher up the stack. So we move the
329 syscall out of line and provide its own unwind information. */
330 # undef INTERNAL_SYSCALL_RAW
331 # define INTERNAL_SYSCALL_RAW(name, nr, args...) \
333 register int _a1 asm ("a1"); \
334 int _nametmp = name; \
335 LOAD_ARGS_##nr (args) \
336 register int _name asm ("ip") = _nametmp; \
337 asm volatile ("bl __libc_do_syscall" \
339 : "r" (_name) ASM_ARGS_##nr \
343 # undef INTERNAL_SYSCALL_RAW
344 # define INTERNAL_SYSCALL_RAW(name, nr, args...) \
346 register int _a1 asm ("r0"), _nr asm ("r7"); \
347 LOAD_ARGS_##nr (args) \
349 asm volatile ("swi 0x0 @ syscall " #name \
351 : "r" (_nr) ASM_ARGS_##nr \
356 #undef INTERNAL_SYSCALL
357 #define INTERNAL_SYSCALL(name, nr, args...) \
358 INTERNAL_SYSCALL_RAW(SYS_ify(name), nr, args)
360 #define VDSO_NAME "LINUX_2.6"
361 #define VDSO_HASH 61765110
363 /* List of system calls which are supported as vsyscalls. */
364 #define HAVE_CLOCK_GETTIME_VSYSCALL "__vdso_clock_gettime"
365 #define HAVE_CLOCK_GETTIME64_VSYSCALL "__vdso_clock_gettime64"
366 #define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_gettimeofday"
368 #define LOAD_ARGS_0()
370 #define LOAD_ARGS_1(a1) \
371 int _a1tmp = (int) (a1); \
374 #define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
375 #define LOAD_ARGS_2(a1, a2) \
376 int _a2tmp = (int) (a2); \
378 register int _a2 asm ("a2") = _a2tmp;
379 #define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2)
380 #define LOAD_ARGS_3(a1, a2, a3) \
381 int _a3tmp = (int) (a3); \
382 LOAD_ARGS_2 (a1, a2) \
383 register int _a3 asm ("a3") = _a3tmp;
384 #define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3)
385 #define LOAD_ARGS_4(a1, a2, a3, a4) \
386 int _a4tmp = (int) (a4); \
387 LOAD_ARGS_3 (a1, a2, a3) \
388 register int _a4 asm ("a4") = _a4tmp;
389 #define ASM_ARGS_4 ASM_ARGS_3, "r" (_a4)
390 #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
391 int _v1tmp = (int) (a5); \
392 LOAD_ARGS_4 (a1, a2, a3, a4) \
393 register int _v1 asm ("v1") = _v1tmp;
394 #define ASM_ARGS_5 ASM_ARGS_4, "r" (_v1)
395 #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
396 int _v2tmp = (int) (a6); \
397 LOAD_ARGS_5 (a1, a2, a3, a4, a5) \
398 register int _v2 asm ("v2") = _v2tmp;
399 #define ASM_ARGS_6 ASM_ARGS_5, "r" (_v2)
401 # define LOAD_ARGS_7(a1, a2, a3, a4, a5, a6, a7) \
402 int _v3tmp = (int) (a7); \
403 LOAD_ARGS_6 (a1, a2, a3, a4, a5, a6) \
404 register int _v3 asm ("v3") = _v3tmp;
405 # define ASM_ARGS_7 ASM_ARGS_6, "r" (_v3)
408 /* For EABI, non-constant syscalls are actually pretty easy... */
409 #undef INTERNAL_SYSCALL_NCS
410 #define INTERNAL_SYSCALL_NCS(number, nr, args...) \
411 INTERNAL_SYSCALL_RAW (number, nr, args)
413 #define SINGLE_THREAD_BY_GLOBAL 1
415 #endif /* __ASSEMBLER__ */
417 #endif /* linux/arm/sysdep.h */