]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/arm/sysdep.h
Fix vDSO initialization on arm and mips
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / arm / sysdep.h
CommitLineData
04277e02 1/* Copyright (C) 1992-2019 Free Software Foundation, Inc.
c751295f
UD
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.
8d2485ed 5
c751295f 6 The GNU C Library is free software; you can redistribute it and/or
3214b89b
AJ
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.
8d2485ed 10
c751295f
UD
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
3214b89b 14 Lesser General Public License for more details.
8d2485ed 15
3214b89b 16 You should have received a copy of the GNU Lesser General Public
ab84e3ff 17 License along with the GNU C Library. If not, see
5a82c748 18 <https://www.gnu.org/licenses/>. */
8d2485ed
UD
19
20#ifndef _LINUX_ARM_SYSDEP_H
21#define _LINUX_ARM_SYSDEP_H 1
22
23/* There is some commonality. */
fb1cf108 24#include <sysdeps/unix/sysv/linux/sysdep.h>
16c82ad7 25#include <sysdeps/unix/arm/sysdep.h>
8d2485ed 26
02a9f771
DJ
27/* Defines RTLD_PRIVATE_ERRNO and USE_DL_SYSINFO. */
28#include <dl-sysdep.h>
29
a68f927f
DJ
30#include <tls.h>
31
26ed7fb1
JM
32/* In order to get __set_errno() definition in INLINE_SYSCALL. */
33#ifndef __ASSEMBLER__
34#include <errno.h>
35#endif
36
8d2485ed
UD
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. */
41#undef SYS_ify
d2099b0d 42#define SYS_ify(syscall_name) (__NR_##syscall_name)
8d2485ed 43
c0ddea5a 44#include <bits/hwcap.h>
4b860fb9 45
e0ebc3b2 46#ifdef __ASSEMBLER__
8d2485ed 47
79fd8731 48#ifndef ARCH_HAS_HARD_TP
5232b909
RH
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. */
79fd8731
RH
52# ifdef __thumb2__
53# define GET_TLS_BODY \
5232b909
RH
54 movw r0, #0x0fe0; \
55 movt r0, #0xffff; \
56 blx r0
79fd8731
RH
57# else
58# define GET_TLS_BODY \
5232b909
RH
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. */
79fd8731 62# endif
5232b909
RH
63
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. */
79fd8731
RH
67# undef GET_TLS
68# define GET_TLS(TMP) \
5232b909
RH
69 .ifnc TMP, lr; \
70 mov TMP, lr; \
71 cfi_register (lr, TMP); \
72 GET_TLS_BODY; \
73 mov lr, TMP; \
74 cfi_restore (lr); \
75 .else; \
76 GET_TLS_BODY; \
77 .endif
79fd8731 78#endif /* ARCH_HAS_HARD_TP */
5232b909 79
8d2485ed
UD
80/* Linux uses a negative return value to indicate syscall errors,
81 unlike most Unices, which use the condition codes' carry flag.
82
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
0f2a261a 86 for < 0, but test for a real error by making sure the value in R0
8d2485ed 87 is a real error number. Linus said he will make sure the no syscall
02a9f771 88 returns a value in -1 .. -4095 as a valid result so we can safely
8d2485ed 89 test with -4095. */
ff550b1f 90
8d2485ed 91#undef PSEUDO
63cc0e75
RH
92#define PSEUDO(name, syscall_name, args) \
93 .text; \
94 ENTRY (name); \
95 DO_CALL (syscall_name, args); \
96 cmn r0, $4096;
97
98#define PSEUDO_RET \
6ccd0107 99 it cc; \
63cc0e75
RH
100 RETINSTR(cc, lr); \
101 b PLTJMP(SYSCALL_ERROR)
63ac74aa
UD
102#undef ret
103#define ret PSEUDO_RET
8d2485ed
UD
104
105#undef PSEUDO_END
63cc0e75
RH
106#define PSEUDO_END(name) \
107 SYSCALL_ERROR_HANDLER; \
8d2485ed
UD
108 END (name)
109
98f7320f 110#undef PSEUDO_NOERRNO
63cc0e75
RH
111#define PSEUDO_NOERRNO(name, syscall_name, args) \
112 .text; \
113 ENTRY (name); \
114 DO_CALL (syscall_name, args);
98f7320f 115
63cc0e75
RH
116#define PSEUDO_RET_NOERRNO \
117 DO_RET (lr);
44acff5d 118
98f7320f
UD
119#undef ret_NOERRNO
120#define ret_NOERRNO PSEUDO_RET_NOERRNO
121
122#undef PSEUDO_END_NOERRNO
63cc0e75 123#define PSEUDO_END_NOERRNO(name) \
98f7320f
UD
124 END (name)
125
ae53e7a7
UD
126/* The function has to return the error code. */
127#undef PSEUDO_ERRVAL
63cc0e75
RH
128#define PSEUDO_ERRVAL(name, syscall_name, args) \
129 .text; \
130 ENTRY (name) \
131 DO_CALL (syscall_name, args); \
132 rsb r0, r0, #0
ae53e7a7
UD
133
134#undef PSEUDO_END_ERRVAL
63cc0e75 135#define PSEUDO_END_ERRVAL(name) \
ae53e7a7
UD
136 END (name)
137
138#define ret_ERRVAL PSEUDO_RET_NOERRNO
139
4f41c682 140#if !IS_IN (libc)
2f0910ca 141# define SYSCALL_ERROR __local_syscall_error
02a9f771
DJ
142# if RTLD_PRIVATE_ERRNO
143# define SYSCALL_ERROR_HANDLER \
144__local_syscall_error: \
cd24e113
RH
145 rsb r0, r0, #0; \
146 LDST_PCREL(str, r0, r1, C_SYMBOL_NAME(rtld_errno)); \
147 mvn r0, #0; \
148 DO_RET(lr)
02a9f771 149# else
01b32e73
TS
150# if defined(__ARM_ARCH_4T__) && defined(__THUMB_INTERWORK__)
151# define POP_PC \
55668624 152 pop { lr }; \
01b32e73
TS
153 cfi_adjust_cfa_offset (-4); \
154 cfi_restore (lr); \
155 bx lr
156# else
55668624 157# define POP_PC pop { pc }
01b32e73 158# endif
02a9f771 159# define SYSCALL_ERROR_HANDLER \
2f0910ca 160__local_syscall_error: \
55668624 161 push { lr }; \
01b32e73
TS
162 cfi_adjust_cfa_offset (4); \
163 cfi_rel_offset (lr, 0); \
55668624 164 push { r0 }; \
01b32e73 165 cfi_adjust_cfa_offset (4); \
2f0910ca 166 bl PLTJMP(C_SYMBOL_NAME(__errno_location)); \
55668624 167 pop { r1 }; \
01b32e73 168 cfi_adjust_cfa_offset (-4); \
2f0910ca
UD
169 rsb r1, r1, #0; \
170 str r1, [r0]; \
171 mvn r0, #0; \
b2b2415f 172 POP_PC;
02a9f771 173# endif
2f0910ca
UD
174#else
175# define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
176# define SYSCALL_ERROR __syscall_error
177#endif
ff550b1f 178
25593dca
JM
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
184 may be invoked. */
185
ff550b1f 186/* Linux takes system call args in registers:
ff550b1f
UD
187 arg 1 r0
188 arg 2 r1
189 arg 3 r2
190 arg 4 r3
191 arg 5 r4 (this is different from the APCS convention)
62749187
UD
192 arg 6 r5
193 arg 7 r6
ff550b1f
UD
194
195 The compiler is going to form a call by coming here, through PSEUDO, with
196 arguments
4ac049e1
JM
197 syscall number in the DO_CALL macro
198 arg 1 r0
199 arg 2 r1
200 arg 3 r2
201 arg 4 r3
202 arg 5 [sp]
62749187
UD
203 arg 6 [sp+4]
204 arg 7 [sp+8]
ff550b1f 205
62749187
UD
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.
ff550b1f
UD
209
210*/
8d2485ed 211
25593dca
JM
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.
215
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.
220
221 The assembler will convert the literal pool load to a move for most
222 syscalls. */
223
8d2485ed 224#undef DO_CALL
63cc0e75
RH
225#define DO_CALL(syscall_name, args) \
226 DOARGS_##args; \
227 ldr r7, =SYS_ify (syscall_name); \
228 swi 0x0; \
229 UNDOARGS_##args
ff550b1f 230
25593dca 231#undef DOARGS_0
63cc0e75
RH
232#define DOARGS_0 \
233 .fnstart; \
55668624 234 push { r7 }; \
63cc0e75
RH
235 cfi_adjust_cfa_offset (4); \
236 cfi_rel_offset (r7, 0); \
237 .save { r7 }
25593dca
JM
238#undef DOARGS_1
239#define DOARGS_1 DOARGS_0
240#undef DOARGS_2
241#define DOARGS_2 DOARGS_0
242#undef DOARGS_3
243#define DOARGS_3 DOARGS_0
244#undef DOARGS_4
245#define DOARGS_4 DOARGS_0
246#undef DOARGS_5
63cc0e75
RH
247#define DOARGS_5 \
248 .fnstart; \
55668624 249 push {r4, r7}; \
63cc0e75
RH
250 cfi_adjust_cfa_offset (8); \
251 cfi_rel_offset (r4, 0); \
252 cfi_rel_offset (r7, 4); \
253 .save { r4, r7 }; \
254 ldr r4, [sp, #8]
25593dca 255#undef DOARGS_6
63cc0e75
RH
256#define DOARGS_6 \
257 .fnstart; \
258 mov ip, sp; \
55668624 259 push {r4, r5, r7}; \
63cc0e75
RH
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 }; \
265 ldmia ip, {r4, r5}
25593dca 266#undef DOARGS_7
63cc0e75
RH
267#define DOARGS_7 \
268 .fnstart; \
269 mov ip, sp; \
55668624 270 push {r4, r5, r6, r7}; \
63cc0e75
RH
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}
ff550b1f 278
25593dca 279#undef UNDOARGS_0
63cc0e75 280#define UNDOARGS_0 \
55668624 281 pop {r7}; \
63cc0e75
RH
282 cfi_adjust_cfa_offset (-4); \
283 cfi_restore (r7); \
284 .fnend
25593dca
JM
285#undef UNDOARGS_1
286#define UNDOARGS_1 UNDOARGS_0
287#undef UNDOARGS_2
288#define UNDOARGS_2 UNDOARGS_0
289#undef UNDOARGS_3
290#define UNDOARGS_3 UNDOARGS_0
291#undef UNDOARGS_4
292#define UNDOARGS_4 UNDOARGS_0
293#undef UNDOARGS_5
63cc0e75 294#define UNDOARGS_5 \
55668624 295 pop {r4, r7}; \
63cc0e75
RH
296 cfi_adjust_cfa_offset (-8); \
297 cfi_restore (r4); \
298 cfi_restore (r7); \
299 .fnend
25593dca 300#undef UNDOARGS_6
63cc0e75 301#define UNDOARGS_6 \
55668624 302 pop {r4, r5, r7}; \
63cc0e75
RH
303 cfi_adjust_cfa_offset (-12); \
304 cfi_restore (r4); \
305 cfi_restore (r5); \
306 cfi_restore (r7); \
307 .fnend
25593dca 308#undef UNDOARGS_7
63cc0e75 309#define UNDOARGS_7 \
55668624 310 pop {r4, r5, r6, r7}; \
63cc0e75
RH
311 cfi_adjust_cfa_offset (-16); \
312 cfi_restore (r4); \
313 cfi_restore (r5); \
314 cfi_restore (r6); \
315 cfi_restore (r7); \
316 .fnend
8d2485ed 317
ba023f01
UD
318#else /* not __ASSEMBLER__ */
319
320/* Define a macro which expands into the inline wrapper code for a system
321 call. */
322#undef INLINE_SYSCALL
2f0910ca 323#define INLINE_SYSCALL(name, nr, args...) \
114e7d50
UD
324 ({ unsigned int _sys_result = INTERNAL_SYSCALL (name, , nr, args); \
325 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0)) \
2f0910ca 326 { \
114e7d50 327 __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, )); \
2f0910ca
UD
328 _sys_result = (unsigned int) -1; \
329 } \
330 (int) _sys_result; })
331
aeeec7fb
UD
332#undef INTERNAL_SYSCALL_DECL
333#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
334
25593dca
JM
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
340 pointer.
341
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...) \
352 ({ \
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" \
358 : "=r" (_a1) \
359 : "r" (_name) ASM_ARGS_##nr \
360 : "memory", "lr"); \
361 _a1; })
362#else /* ARM */
363# undef INTERNAL_SYSCALL_RAW
364# define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
365 ({ \
366 register int _a1 asm ("r0"), _nr asm ("r7"); \
ba023f01 367 LOAD_ARGS_##nr (args) \
25593dca
JM
368 _nr = name; \
369 asm volatile ("swi 0x0 @ syscall " #name \
ba023f01 370 : "=r" (_a1) \
25593dca 371 : "r" (_nr) ASM_ARGS_##nr \
cf666e4b 372 : "memory"); \
25593dca
JM
373 _a1; })
374#endif
ba023f01 375
485a9bb9
DJ
376#undef INTERNAL_SYSCALL
377#define INTERNAL_SYSCALL(name, err, nr, args...) \
378 INTERNAL_SYSCALL_RAW(SYS_ify(name), err, nr, args)
379
380#undef INTERNAL_SYSCALL_ARM
381#define INTERNAL_SYSCALL_ARM(name, err, nr, args...) \
382 INTERNAL_SYSCALL_RAW(__ARM_NR_##name, err, nr, args)
383
2f0910ca 384#undef INTERNAL_SYSCALL_ERROR_P
aeeec7fb
UD
385#define INTERNAL_SYSCALL_ERROR_P(val, err) \
386 ((unsigned int) (val) >= 0xfffff001u)
2f0910ca
UD
387
388#undef INTERNAL_SYSCALL_ERRNO
aeeec7fb 389#define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
2f0910ca 390
b8386c28
AZ
391#define VDSO_NAME "LINUX_2.6"
392#define VDSO_HASH 61765110
393
b65d3e5f 394/* List of system calls which are supported as vsyscalls. */
eb502f72
AS
395#define HAVE_CLOCK_GETTIME_VSYSCALL "__vdso_clock_gettime"
396#define HAVE_GETTIMEOFDAY_VSYSCALL "__vdso_gettimeofday"
b65d3e5f 397
ba023f01
UD
398#define LOAD_ARGS_0()
399#define ASM_ARGS_0
400#define LOAD_ARGS_1(a1) \
9806fbba
JM
401 int _a1tmp = (int) (a1); \
402 LOAD_ARGS_0 () \
403 _a1 = _a1tmp;
ba023f01
UD
404#define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
405#define LOAD_ARGS_2(a1, a2) \
9806fbba
JM
406 int _a2tmp = (int) (a2); \
407 LOAD_ARGS_1 (a1) \
408 register int _a2 asm ("a2") = _a2tmp;
ba023f01
UD
409#define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2)
410#define LOAD_ARGS_3(a1, a2, a3) \
9806fbba
JM
411 int _a3tmp = (int) (a3); \
412 LOAD_ARGS_2 (a1, a2) \
413 register int _a3 asm ("a3") = _a3tmp;
ba023f01
UD
414#define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3)
415#define LOAD_ARGS_4(a1, a2, a3, a4) \
9806fbba
JM
416 int _a4tmp = (int) (a4); \
417 LOAD_ARGS_3 (a1, a2, a3) \
418 register int _a4 asm ("a4") = _a4tmp;
ba023f01
UD
419#define ASM_ARGS_4 ASM_ARGS_3, "r" (_a4)
420#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
9806fbba
JM
421 int _v1tmp = (int) (a5); \
422 LOAD_ARGS_4 (a1, a2, a3, a4) \
423 register int _v1 asm ("v1") = _v1tmp;
ba023f01 424#define ASM_ARGS_5 ASM_ARGS_4, "r" (_v1)
62749187 425#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
9806fbba
JM
426 int _v2tmp = (int) (a6); \
427 LOAD_ARGS_5 (a1, a2, a3, a4, a5) \
428 register int _v2 asm ("v2") = _v2tmp;
62749187 429#define ASM_ARGS_6 ASM_ARGS_5, "r" (_v2)
25593dca
JM
430#ifndef __thumb__
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) \
9806fbba 434 register int _v3 asm ("v3") = _v3tmp;
25593dca
JM
435# define ASM_ARGS_7 ASM_ARGS_6, "r" (_v3)
436#endif
437
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)
02a9f771 442
09c76a74
AZ
443#define SINGLE_THREAD_BY_GLOBAL 1
444
e0ebc3b2 445#endif /* __ASSEMBLER__ */
8d2485ed
UD
446
447#endif /* linux/arm/sysdep.h */