1
/* Copyright (C) 2005-2007, 2009-2012
2
Free Software Foundation, Inc.
4
This file is part of the GNU C Library.
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 License as
8
published by the Free Software Foundation; either version 2.1 of the
9
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
<http://www.gnu.org/licenses/>. */
20
#ifndef _LINUX_AARCH64_SYSDEP_H
21
#define _LINUX_AARCH64_SYSDEP_H 1
23
#include <sysdeps/unix/sysdep.h>
24
#include <sysdeps/aarch64/sysdep.h>
26
/* Don't use stime, even if the kernel headers define it. We have
27
settimeofday. Similarly use setitimer to implement alarm. */
35
#undef __NR_socketcall
38
/* Defines RTLD_PRIVATE_ERRNO and USE_DL_SYSINFO. */
39
#include <dl-sysdep.h>
43
/* In order to get __set_errno() definition in INLINE_SYSCALL. */
48
/* For Linux we can use the system call table in the header file
49
/usr/include/asm/unistd.h
50
of the kernel. But these symbols do not follow the SYS_* syntax
51
so we have to redefine the `SYS_ify' macro here. */
53
#define SYS_ify(syscall_name) (__NR_##syscall_name)
57
/* Linux uses a negative return value to indicate syscall errors,
58
unlike most Unices, which use the condition codes' carry flag.
60
Since version 2.1 the return value of a system call might be
61
negative even if the call succeeded. E.g., the `lseek' system call
62
might return a large offset. Therefore we must not anymore test
63
for < 0, but test for a real error by making sure the value in R0
64
is a real error number. Linus said he will make sure the no syscall
65
returns a value in -1 .. -4095 as a valid result so we can safely
69
#define PSEUDO(name, syscall_name, args) \
72
DO_CALL (syscall_name, args); \
75
/* Notice the use of 'RET' instead of 'ret' the assembler is case
76
insensitive and eglibc already uses the preprocessor symbol 'ret'
77
so we use the upper case 'RET' to force through a ret instruction
83
b PLTJMP(SYSCALL_ERROR)
85
#define ret PSEUDO_RET
88
#define PSEUDO_END(name) \
89
SYSCALL_ERROR_HANDLER \
93
#define PSEUDO_NOERRNO(name, syscall_name, args) \
96
DO_CALL (syscall_name, args);
98
/* Notice the use of 'RET' instead of 'ret' the assembler is case
99
insensitive and eglibc already uses the preprocessor symbol 'ret'
100
so we use the upper case 'RET' to force through a ret instruction
102
#define PSEUDO_RET_NOERRNO \
106
#define ret_NOERRNO PSEUDO_RET_NOERRNO
108
#undef PSEUDO_END_NOERRNO
109
#define PSEUDO_END_NOERRNO(name) \
112
/* The function has to return the error code. */
114
#define PSEUDO_ERRVAL(name, syscall_name, args) \
117
DO_CALL (syscall_name, args); \
120
#undef PSEUDO_END_ERRVAL
121
#define PSEUDO_END_ERRVAL(name) \
124
#define ret_ERRVAL PSEUDO_RET_NOERRNO
127
# define SYSCALL_ERROR __local_syscall_error
128
# if RTLD_PRIVATE_ERRNO
129
# define SYSCALL_ERROR_HANDLER \
130
__local_syscall_error: \
131
adrp x1, C_SYMBOL_NAME(rtld_errno); \
132
add x1, x1, #:lo12:C_SYMBOL_NAME(rtld_errno); \
139
# define SYSCALL_ERROR_HANDLER \
140
__local_syscall_error: \
141
stp x29, x30, [sp, -32]!; \
142
cfi_adjust_cfa_offset (32); \
143
cfi_rel_offset (x29, 0); \
144
cfi_rel_offset (x30, 8); \
148
bl PLTJMP(C_SYMBOL_NAME(__errno_location)); \
152
ldp x29, x30, [sp], 32; \
153
cfi_adjust_cfa_offset (-32); \
159
# define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
160
# define SYSCALL_ERROR __syscall_error
163
/* Linux takes system call args in registers:
164
syscall number in the SVC instruction
173
The compiler is going to form a call by coming here, through PSEUDO, with
175
syscall number in the DO_CALL macro
184
We need to shuffle values between R4..R6 and the stack so that the
185
caller's v1..v3 and stack frame are not corrupted, and the kernel
186
sees the right arguments.
191
#define DO_CALL(syscall_name, args) \
193
mov x8, SYS_ify (syscall_name); \
197
#define DOARGS_0 /* nothing */
198
#define DOARGS_1 /* nothing */
199
#define DOARGS_2 /* nothing */
200
#define DOARGS_3 /* nothing */
201
#define DOARGS_4 /* nothing */
202
#define DOARGS_5 /* nothing */
203
#define DOARGS_6 /* nothing */
204
#define DOARGS_7 /* nothing */
206
#define UNDOARGS_0 /* nothing */
207
#define UNDOARGS_1 /* nothing */
208
#define UNDOARGS_2 /* nothing */
209
#define UNDOARGS_3 /* nothing */
210
#define UNDOARGS_4 /* nothing */
211
#define UNDOARGS_5 /* nothing */
212
#define UNDOARGS_6 /* nothing */
213
#define UNDOARGS_7 /* nothing */
215
#else /* not __ASSEMBLER__ */
218
# define INLINE_VSYSCALL(name, nr, args...) \
224
INTERNAL_SYSCALL_DECL (sc_err); \
226
if (__vdso_##name != NULL) \
228
register long _x0 asm ("x0"); \
229
sc_ret = INTERNAL_VSYSCALL_NCS (__vdso_##name, sc_err, nr, ##args); \
230
if (!INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
232
if (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err) != ENOSYS) \
236
sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, ##args); \
237
if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
240
__set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \
247
# define INLINE_VSYSCALL(name, nr, args...) \
248
INLINE_SYSCALL (name, nr, ##args)
252
# define INTERNAL_VSYSCALL(name, err, nr, args...) \
257
if (__vdso_##name != NULL) \
259
register long _x0 asm ("x0"); \
260
v_ret = INTERNAL_VSYSCALL_NCS (__vdso_##name, err, nr, ##args); \
261
if (!INTERNAL_SYSCALL_ERROR_P (v_ret, err) \
262
|| INTERNAL_SYSCALL_ERRNO (v_ret, err) != ENOSYS) \
265
v_ret = INTERNAL_SYSCALL (name, err, nr, ##args); \
270
# define INTERNAL_VSYSCALL(name, err, nr, args...) \
271
INTERNAL_SYSCALL (name, err, nr, ##args)
274
/* List of system calls which are supported as vsyscalls. */
275
#define HAVE_CLOCK_GETRES_VSYSCALL 1
276
#define HAVE_CLOCK_GETTIME_VSYSCALL 1
278
#define INTERNAL_VSYSCALL_NCS(funcptr, err, nr, args...) \
280
LOAD_ARGS_##nr (args) \
281
asm volatile ("blr %1" \
283
: "r" (funcptr), ASM_ARGS_##nr \
284
: "x30", "memory"); \
289
/* Define a macro which expands into the inline wrapper code for a system
291
#undef INLINE_SYSCALL
292
#define INLINE_SYSCALL(name, nr, args...) \
293
({ unsigned long _sys_result = INTERNAL_SYSCALL (name, , nr, args); \
294
if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0))\
296
__set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, )); \
297
_sys_result = (unsigned long) -1; \
299
(long) _sys_result; })
301
#undef INTERNAL_SYSCALL_DECL
302
#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
304
#undef INTERNAL_SYSCALL_RAW
305
#define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \
306
({ unsigned long _sys_result; \
308
LOAD_ARGS_##nr (args) \
309
register long _x8 asm ("x8") = (name); \
310
asm volatile ("svc 0 // syscall " # name \
311
: "+r" (_x0), "+r" (_x8) \
313
: "memory", CLOBBER_ARGS_##nr); \
316
(long) _sys_result; })
318
#undef INTERNAL_SYSCALL
319
#define INTERNAL_SYSCALL(name, err, nr, args...) \
320
INTERNAL_SYSCALL_RAW(SYS_ify(name), err, nr, args)
322
#undef INTERNAL_SYSCALL_AARCH64
323
#define INTERNAL_SYSCALL_AARCH64(name, err, nr, args...) \
324
INTERNAL_SYSCALL_RAW(__ARM_NR_##name, err, nr, args)
326
#undef INTERNAL_SYSCALL_ERROR_P
327
#define INTERNAL_SYSCALL_ERROR_P(val, err) \
328
((unsigned long) (val) >= (unsigned long) -4095)
330
#undef INTERNAL_SYSCALL_ERRNO
331
#define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
333
#define CLOBBER_ARGS_0 CLOBBER_ARGS_1
334
#define CLOBBER_ARGS_1 "x1", CLOBBER_ARGS_2
335
#define CLOBBER_ARGS_2 "x2", CLOBBER_ARGS_3
336
#define CLOBBER_ARGS_3 "x3", CLOBBER_ARGS_4
337
#define CLOBBER_ARGS_4 "x4", CLOBBER_ARGS_5
338
#define CLOBBER_ARGS_5 "x5", CLOBBER_ARGS_6
339
#define CLOBBER_ARGS_6 "x6", CLOBBER_ARGS_7
340
#define CLOBBER_ARGS_7 \
341
"x7", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18"
343
#define LOAD_ARGS_0() \
344
register long _x0 asm ("x0");
347
#define LOAD_ARGS_1(x0) \
348
long _x0tmp = (long) (x0); \
351
#define ASM_ARGS_1 "r" (_x0)
352
#define LOAD_ARGS_2(x0, x1) \
353
long _x1tmp = (long) (x1); \
355
register long _x1 asm ("x1") = _x1tmp;
356
#define ASM_ARGS_2 ASM_ARGS_1, "r" (_x1)
357
#define LOAD_ARGS_3(x0, x1, x2) \
358
long _x2tmp = (long) (x2); \
359
LOAD_ARGS_2 (x0, x1) \
360
register long _x2 asm ("x2") = _x2tmp;
361
#define ASM_ARGS_3 ASM_ARGS_2, "r" (_x2)
362
#define LOAD_ARGS_4(x0, x1, x2, x3) \
363
long _x3tmp = (long) (x3); \
364
LOAD_ARGS_3 (x0, x1, x2) \
365
register long _x3 asm ("x3") = _x3tmp;
366
#define ASM_ARGS_4 ASM_ARGS_3, "r" (_x3)
367
#define LOAD_ARGS_5(x0, x1, x2, x3, x4) \
368
long _x4tmp = (long) (x4); \
369
LOAD_ARGS_4 (x0, x1, x2, x3) \
370
register long _x4 asm ("x4") = _x4tmp;
371
#define ASM_ARGS_5 ASM_ARGS_4, "r" (_x4)
372
#define LOAD_ARGS_6(x0, x1, x2, x3, x4, x5) \
373
long _x5tmp = (long) (x5); \
374
LOAD_ARGS_5 (x0, x1, x2, x3, x4) \
375
register long _x5 asm ("x5") = _x5tmp;
376
#define ASM_ARGS_6 ASM_ARGS_5, "r" (_x5)
377
#define LOAD_ARGS_7(x0, x1, x2, x3, x4, x5, x6) \
378
long _x6tmp = (long) (x6); \
379
LOAD_ARGS_6 (x0, x1, x2, x3, x4, x5) \
380
register long _x6 asm ("x6") = _x6tmp;
381
#define ASM_ARGS_7 ASM_ARGS_6, "r" (_x6)
383
#undef INTERNAL_SYSCALL_NCS
384
#define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
385
INTERNAL_SYSCALL_RAW (number, err, nr, args)
387
#endif /* __ASSEMBLER__ */
389
/* Pointer mangling is not yet supported for AArch64. */
390
#define PTR_MANGLE(var) (void) (var)
391
#define PTR_DEMANGLE(var) (void) (var)
393
#if !defined __NR_pread && defined __NR_pread64
394
# define __NR_pread __NR_pread64
397
#if !defined __NR_pwrite && defined __NR_pwrite64
398
# define __NR_pwrite __NR_pwrite64
401
#endif /* linux/aarch64/sysdep.h */