summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/aarch64/sysdep.h
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@uclibc-ng.org>2016-10-04 06:51:35 +0200
committerWaldemar Brodkorb <wbx@openadk.org>2017-02-01 17:48:38 +0100
commitdba942c80dc2cfa5768a856fff98e22a755fdd27 (patch)
tree371e775cb6dfec085945f6834aeb9d3b6de36fbe /libc/sysdeps/linux/aarch64/sysdep.h
parent9b457baf8d46329f7d7ee2aa084022bb0df88551 (diff)
add experimental aarch64 support
Ported over from GNU C Library and runtime tested in Qemu.
Diffstat (limited to 'libc/sysdeps/linux/aarch64/sysdep.h')
-rw-r--r--libc/sysdeps/linux/aarch64/sysdep.h150
1 files changed, 150 insertions, 0 deletions
diff --git a/libc/sysdeps/linux/aarch64/sysdep.h b/libc/sysdeps/linux/aarch64/sysdep.h
new file mode 100644
index 000000000..82790be6d
--- /dev/null
+++ b/libc/sysdeps/linux/aarch64/sysdep.h
@@ -0,0 +1,150 @@
+/* Copyright (C) 2005-2016 Free Software Foundation, Inc.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with the GNU C Library; if not, see
+<http://www.gnu.org/licenses/>. */
+
+#ifndef _LINUX_AARCH64_SYSDEP_H
+#define _LINUX_AARCH64_SYSDEP_H 1
+
+#include <common/sysdep.h>
+#include <sys/syscall.h>
+
+/* In order to get __set_errno() definition in INLINE_SYSCALL. */
+#ifndef __ASSEMBLER__
+#include <errno.h>
+#endif
+
+/* For Linux we can use the system call table in the header file
+/usr/include/asm/unistd.h
+of the kernel. But these symbols do not follow the SYS_* syntax
+so we have to redefine the `SYS_ify' macro here. */
+#undef SYS_ify
+#define SYS_ify(syscall_name) (__NR_##syscall_name)
+
+#ifdef __ASSEMBLER__
+
+#define ASM_SIZE_DIRECTIVE(name) .size name,.-name
+
+/* Local label name for asm code. */
+#ifndef L
+# define L(name) .L##name
+#endif
+
+/* Define an entry point visible from C. */
+#define ENTRY(name) \
+ .globl C_SYMBOL_NAME(name); \
+ .type C_SYMBOL_NAME(name),%function; \
+ .align 4; \
+ C_LABEL(name) \
+ cfi_startproc;
+
+/* Define an entry point visible from C. */
+#define ENTRY_ALIGN(name, align) \
+ .globl C_SYMBOL_NAME(name); \
+ .type C_SYMBOL_NAME(name),%function; \
+ .p2align align; \
+ C_LABEL(name) \
+ cfi_startproc;
+
+#undef END
+#define END(name) \
+ cfi_endproc; \
+ ASM_SIZE_DIRECTIVE(name)
+
+/* Linux uses a negative return value to indicate syscall errors,
+unlike most Unices, which use the condition codes' carry flag.
+
+Since version 2.1 the return value of a system call might be
+negative even if the call succeeded. E.g., the `lseek' system call
+might return a large offset. Therefore we must not anymore test
+for < 0, but test for a real error by making sure the value in R0
+is a real error number. Linus said he will make sure the no syscall
+returns a value in -1 .. -4095 as a valid result so we can safely
+test with -4095. */
+
+# undef PSEUDO
+# define PSEUDO(name, syscall_name, args) \
+.text; \
+ENTRY (name); \
+DO_CALL (syscall_name, args); \
+cmn x0, #4095; \
+b.cs .Lsyscall_error;
+
+# undef PSEUDO_END
+# define PSEUDO_END(name) \
+SYSCALL_ERROR_HANDLER \
+END (name)
+
+# undef PSEUDO_NOERRNO
+# define PSEUDO_NOERRNO(name, syscall_name, args) \
+.text; \
+ENTRY (name); \
+DO_CALL (syscall_name, args);
+
+# undef PSEUDO_END_NOERRNO
+# define PSEUDO_END_NOERRNO(name) \
+END (name)
+
+# define ret_NOERRNO ret
+
+/* The function has to return the error code. */
+# undef PSEUDO_ERRVAL
+# define PSEUDO_ERRVAL(name, syscall_name, args) \
+.text; \
+ENTRY (name) \
+DO_CALL (syscall_name, args); \
+neg x0, x0
+
+# undef PSEUDO_END_ERRVAL
+# define PSEUDO_END_ERRVAL(name) \
+END (name)
+
+# define ret_ERRVAL ret
+
+#if defined _LIBC_REENTRANT
+# if defined USE___THREAD
+# ifndef NOT_IN_libc
+# define SYSCALL_ERROR_ERRNO __libc_errno
+# else
+# define SYSCALL_ERROR_ERRNO errno
+# endif
+# endif
+#endif
+
+#if defined USE___THREAD
+# define SYSCALL_ERROR .Lsyscall_error
+# define SYSCALL_ERROR_HANDLER \
+.Lsyscall_error: \
+ adrp x1, :gottprel:SYSCALL_ERROR_ERRNO; \
+ neg w2, w0; \
+ ldr x1, [x1, :gottprel_lo12:SYSCALL_ERROR_ERRNO]; \
+ mrs x3, tpidr_el0; \
+ mov x0, -1; \
+ str w2, [x1, x3]; \
+ ret;
+#else
+# define SYSCALL_ERROR __syscall_error
+# define SYSCALL_ERROR_HANDLER \
+.Lsyscall_error: \
+ b __syscall_error;
+#endif
+
+# undef DO_CALL
+# define DO_CALL(syscall_name, args) \
+mov x8, SYS_ify (syscall_name); \
+svc 0
+
+#endif /* __ASSEMBLER__ */
+
+#endif /* linux/aarch64/sysdep.h */