Warning: That file was not part of the compilation database. It may have many parsing errors.

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.
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, see
18 <http://www.gnu.org/licenses/>. */
19
20#ifndef _LINUX_ARM_SYSDEP_H
21#define _LINUX_ARM_SYSDEP_H 1
22
23/* Always enable vsyscalls on arm */
24#define ALWAYS_USE_VSYSCALL 1
25
26/* There is some commonality. */
27#include <sysdeps/unix/sysv/linux/sysdep.h>
28#include <sysdeps/unix/arm/sysdep.h>
29
30/* Defines RTLD_PRIVATE_ERRNO and USE_DL_SYSINFO. */
31#include <dl-sysdep.h>
32
33#include <tls.h>
34
35/* In order to get __set_errno() definition in INLINE_SYSCALL. */
36#ifndef __ASSEMBLER__
37#include <errno.h>
38#endif
39
40/* For Linux we can use the system call table in the header file
41 /usr/include/asm/unistd.h
42 of the kernel. But these symbols do not follow the SYS_* syntax
43 so we have to redefine the `SYS_ify' macro here. */
44#undef SYS_ify
45#define SYS_ify(syscall_name) (__NR_##syscall_name)
46
47#include <bits/hwcap.h>
48
49#ifdef __ASSEMBLER__
50
51#ifndef ARCH_HAS_HARD_TP
52/* Internal macro calling the linux kernel kuser_get_tls helper.
53 Note that in thumb mode, a constant pool break is often out of range, so
54 we always expand the constant inline. */
55# ifdef __thumb2__
56# define GET_TLS_BODY \
57 movw r0, #0x0fe0; \
58 movt r0, #0xffff; \
59 blx r0
60# else
61# define GET_TLS_BODY \
62 mov r0, #0xffff0fff; /* Point to the high page. */ \
63 mov lr, pc; /* Save our return address. */ \
64 sub pc, r0, #31 /* Jump to the TLS entry. */
65# endif
66
67/* Helper to get the TLS base pointer. Save LR in TMP, return in R0,
68 and no other registers clobbered. TMP may be LR itself to indicate
69 that no save is necessary. */
70# undef GET_TLS
71# define GET_TLS(TMP) \
72 .ifnc TMP, lr; \
73 mov TMP, lr; \
74 cfi_register (lr, TMP); \
75 GET_TLS_BODY; \
76 mov lr, TMP; \
77 cfi_restore (lr); \
78 .else; \
79 GET_TLS_BODY; \
80 .endif
81#endif /* ARCH_HAS_HARD_TP */
82
83/* Linux uses a negative return value to indicate syscall errors,
84 unlike most Unices, which use the condition codes' carry flag.
85
86 Since version 2.1 the return value of a system call might be
87 negative even if the call succeeded. E.g., the `lseek' system call
88 might return a large offset. Therefore we must not anymore test
89 for < 0, but test for a real error by making sure the value in R0
90 is a real error number. Linus said he will make sure the no syscall
91 returns a value in -1 .. -4095 as a valid result so we can safely
92 test with -4095. */
93
94#undef PSEUDO
95#define PSEUDO(name, syscall_name, args) \
96 .text; \
97 ENTRY (name); \
98 DO_CALL (syscall_name, args); \
99 cmn r0, $4096;
100
101#define PSEUDO_RET \
102 it cc; \
103 RETINSTR(cc, lr); \
104 b PLTJMP(SYSCALL_ERROR)
105#undef ret
106#define ret PSEUDO_RET
107
108#undef PSEUDO_END
109#define PSEUDO_END(name) \
110 SYSCALL_ERROR_HANDLER; \
111 END (name)
112
113#undef PSEUDO_NOERRNO
114#define PSEUDO_NOERRNO(name, syscall_name, args) \
115 .text; \
116 ENTRY (name); \
117 DO_CALL (syscall_name, args);
118
119#define PSEUDO_RET_NOERRNO \
120 DO_RET (lr);
121
122#undef ret_NOERRNO
123#define ret_NOERRNO PSEUDO_RET_NOERRNO
124
125#undef PSEUDO_END_NOERRNO
126#define PSEUDO_END_NOERRNO(name) \
127 END (name)
128
129/* The function has to return the error code. */
130#undef PSEUDO_ERRVAL
131#define PSEUDO_ERRVAL(name, syscall_name, args) \
132 .text; \
133 ENTRY (name) \
134 DO_CALL (syscall_name, args); \
135 rsb r0, r0, #0
136
137#undef PSEUDO_END_ERRVAL
138#define PSEUDO_END_ERRVAL(name) \
139 END (name)
140
141#define ret_ERRVAL PSEUDO_RET_NOERRNO
142
143#if !IS_IN (libc)
144# define SYSCALL_ERROR __local_syscall_error
145# if RTLD_PRIVATE_ERRNO
146# define SYSCALL_ERROR_HANDLER \
147__local_syscall_error: \
148 rsb r0, r0, #0; \
149 LDST_PCREL(str, r0, r1, C_SYMBOL_NAME(rtld_errno)); \
150 mvn r0, #0; \
151 DO_RET(lr)
152# else
153# if defined(__ARM_ARCH_4T__) && defined(__THUMB_INTERWORK__)
154# define POP_PC \
155 pop { lr }; \
156 cfi_adjust_cfa_offset (-4); \
157 cfi_restore (lr); \
158 bx lr
159# else
160# define POP_PC pop { pc }
161# endif
162# define SYSCALL_ERROR_HANDLER \
163__local_syscall_error: \
164 push { lr }; \
165 cfi_adjust_cfa_offset (4); \
166 cfi_rel_offset (lr, 0); \
167 push { r0 }; \
168 cfi_adjust_cfa_offset (4); \
169 bl PLTJMP(C_SYMBOL_NAME(__errno_location)); \
170 pop { r1 }; \
171 cfi_adjust_cfa_offset (-4); \
172 rsb r1, r1, #0; \
173 str r1, [r0]; \
174 mvn r0, #0; \
175 POP_PC;
176# endif
177#else
178# define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
179# define SYSCALL_ERROR __syscall_error
180#endif
181
182/* The ARM EABI user interface passes the syscall number in r7, instead
183 of in the swi. This is more efficient, because the kernel does not need
184 to fetch the swi from memory to find out the number; which can be painful
185 with separate I-cache and D-cache. Make sure to use 0 for the SWI
186 argument; otherwise the (optional) compatibility code for APCS binaries
187 may be invoked. */
188
189/* Linux takes system call args in registers:
190 arg 1 r0
191 arg 2 r1
192 arg 3 r2
193 arg 4 r3
194 arg 5 r4 (this is different from the APCS convention)
195 arg 6 r5
196 arg 7 r6
197
198 The compiler is going to form a call by coming here, through PSEUDO, with
199 arguments
200 syscall number in the DO_CALL macro
201 arg 1 r0
202 arg 2 r1
203 arg 3 r2
204 arg 4 r3
205 arg 5 [sp]
206 arg 6 [sp+4]
207 arg 7 [sp+8]
208
209 We need to shuffle values between R4..R6 and the stack so that the
210 caller's v1..v3 and stack frame are not corrupted, and the kernel
211 sees the right arguments.
212
213*/
214
215/* We must save and restore r7 (call-saved) for the syscall number.
216 We never make function calls from inside here (only potentially
217 signal handlers), so we do not bother with doubleword alignment.
218
219 Just like the APCS syscall convention, the EABI syscall convention uses
220 r0 through r6 for up to seven syscall arguments. None are ever passed to
221 the kernel on the stack, although incoming arguments are on the stack for
222 syscalls with five or more arguments.
223
224 The assembler will convert the literal pool load to a move for most
225 syscalls. */
226
227#undef DO_CALL
228#define DO_CALL(syscall_name, args) \
229 DOARGS_##args; \
230 ldr r7, =SYS_ify (syscall_name); \
231 swi 0x0; \
232 UNDOARGS_##args
233
234#undef DOARGS_0
235#define DOARGS_0 \
236 .fnstart; \
237 push { r7 }; \
238 cfi_adjust_cfa_offset (4); \
239 cfi_rel_offset (r7, 0); \
240 .save { r7 }
241#undef DOARGS_1
242#define DOARGS_1 DOARGS_0
243#undef DOARGS_2
244#define DOARGS_2 DOARGS_0
245#undef DOARGS_3
246#define DOARGS_3 DOARGS_0
247#undef DOARGS_4
248#define DOARGS_4 DOARGS_0
249#undef DOARGS_5
250#define DOARGS_5 \
251 .fnstart; \
252 push {r4, r7}; \
253 cfi_adjust_cfa_offset (8); \
254 cfi_rel_offset (r4, 0); \
255 cfi_rel_offset (r7, 4); \
256 .save { r4, r7 }; \
257 ldr r4, [sp, #8]
258#undef DOARGS_6
259#define DOARGS_6 \
260 .fnstart; \
261 mov ip, sp; \
262 push {r4, r5, r7}; \
263 cfi_adjust_cfa_offset (12); \
264 cfi_rel_offset (r4, 0); \
265 cfi_rel_offset (r5, 4); \
266 cfi_rel_offset (r7, 8); \
267 .save { r4, r5, r7 }; \
268 ldmia ip, {r4, r5}
269#undef DOARGS_7
270#define DOARGS_7 \
271 .fnstart; \
272 mov ip, sp; \
273 push {r4, r5, r6, r7}; \
274 cfi_adjust_cfa_offset (16); \
275 cfi_rel_offset (r4, 0); \
276 cfi_rel_offset (r5, 4); \
277 cfi_rel_offset (r6, 8); \
278 cfi_rel_offset (r7, 12); \
279 .save { r4, r5, r6, r7 }; \
280 ldmia ip, {r4, r5, r6}
281
282#undef UNDOARGS_0
283#define UNDOARGS_0 \
284 pop {r7}; \
285 cfi_adjust_cfa_offset (-4); \
286 cfi_restore (r7); \
287 .fnend
288#undef UNDOARGS_1
289#define UNDOARGS_1 UNDOARGS_0
290#undef UNDOARGS_2
291#define UNDOARGS_2 UNDOARGS_0
292#undef UNDOARGS_3
293#define UNDOARGS_3 UNDOARGS_0
294#undef UNDOARGS_4
295#define UNDOARGS_4 UNDOARGS_0
296#undef UNDOARGS_5
297#define UNDOARGS_5 \
298 pop {r4, r7}; \
299 cfi_adjust_cfa_offset (-8); \
300 cfi_restore (r4); \
301 cfi_restore (r7); \
302 .fnend
303#undef UNDOARGS_6
304#define UNDOARGS_6 \
305 pop {r4, r5, r7}; \
306 cfi_adjust_cfa_offset (-12); \
307 cfi_restore (r4); \
308 cfi_restore (r5); \
309 cfi_restore (r7); \
310 .fnend
311#undef UNDOARGS_7
312#define UNDOARGS_7 \
313 pop {r4, r5, r6, r7}; \
314 cfi_adjust_cfa_offset (-16); \
315 cfi_restore (r4); \
316 cfi_restore (r5); \
317 cfi_restore (r6); \
318 cfi_restore (r7); \
319 .fnend
320
321#else /* not __ASSEMBLER__ */
322
323/* Define a macro which expands into the inline wrapper code for a system
324 call. */
325#undef INLINE_SYSCALL
326#define INLINE_SYSCALL(name, nr, args...) \
327 ({ unsigned int _sys_result = INTERNAL_SYSCALL (name, , nr, args); \
328 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0)) \
329 { \
330 __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, )); \
331 _sys_result = (unsigned int) -1; \
332 } \
333 (int) _sys_result; })
334
335#undef INTERNAL_SYSCALL_DECL
336#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
337
338#if defined(__thumb__)
339/* We can not expose the use of r7 to the compiler. GCC (as
340 of 4.5) uses r7 as the hard frame pointer for Thumb - although
341 for Thumb-2 it isn't obviously a better choice than r11.
342 And GCC does not support asms that conflict with the frame
343 pointer.
344
345 This would be easier if syscall numbers never exceeded 255,
346 but they do. For the moment the LOAD_ARGS_7 is sacrificed.
347 We can't use push/pop inside the asm because that breaks
348 unwinding (i.e. thread cancellation) for this frame. We can't
349 locally save and restore r7, because we do not know if this
350 function uses r7 or if it is our caller's r7; if it is our caller's,
351 then unwinding will fail higher up the stack. So we move the
352 syscall out of line and provide its own unwind information. */
353# undef INTERNAL_SYSCALL_RAW
354# define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
355 ({ \
356 register int _a1 asm ("a1"); \
357 int _nametmp = name; \
358 LOAD_ARGS_##nr (args) \
359 register int _name asm ("ip") = _nametmp; \
360 asm volatile ("bl __libc_do_syscall" \
361 : "=r" (_a1) \
362 : "r" (_name) ASM_ARGS_##nr \
363 : "memory", "lr"); \
364 _a1; })
365#else /* ARM */
366# undef INTERNAL_SYSCALL_RAW
367# define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
368 ({ \
369 register int _a1 asm ("r0"), _nr asm ("r7"); \
370 LOAD_ARGS_##nr (args) \
371 _nr = name; \
372 asm volatile ("swi 0x0 @ syscall " #name \
373 : "=r" (_a1) \
374 : "r" (_nr) ASM_ARGS_##nr \
375 : "memory"); \
376 _a1; })
377#endif
378
379#undef INTERNAL_SYSCALL
380#define INTERNAL_SYSCALL(name, err, nr, args...) \
381 INTERNAL_SYSCALL_RAW(SYS_ify(name), err, nr, args)
382
383#undef INTERNAL_SYSCALL_ARM
384#define INTERNAL_SYSCALL_ARM(name, err, nr, args...) \
385 INTERNAL_SYSCALL_RAW(__ARM_NR_##name, err, nr, args)
386
387#undef INTERNAL_SYSCALL_ERROR_P
388#define INTERNAL_SYSCALL_ERROR_P(val, err) \
389 ((unsigned int) (val) >= 0xfffff001u)
390
391#undef INTERNAL_SYSCALL_ERRNO
392#define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
393
394/* List of system calls which are supported as vsyscalls. */
395#define HAVE_CLOCK_GETTIME_VSYSCALL 1
396#define HAVE_GETTIMEOFDAY_VSYSCALL 1
397
398#define LOAD_ARGS_0()
399#define ASM_ARGS_0
400#define LOAD_ARGS_1(a1) \
401 int _a1tmp = (int) (a1); \
402 LOAD_ARGS_0 () \
403 _a1 = _a1tmp;
404#define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
405#define LOAD_ARGS_2(a1, a2) \
406 int _a2tmp = (int) (a2); \
407 LOAD_ARGS_1 (a1) \
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)
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) \
434 register int _v3 asm ("v3") = _v3tmp;
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)
442
443#define SINGLE_THREAD_BY_GLOBAL 1
444
445#endif /* __ASSEMBLER__ */
446
447#endif /* linux/arm/sysdep.h */
448

Warning: That file was not part of the compilation database. It may have many parsing errors.