aarch64: add system call definitions
authorJens Axboe <axboe@kernel.dk>
Mon, 21 Feb 2022 16:41:53 +0000 (09:41 -0700)
committerJens Axboe <axboe@kernel.dk>
Mon, 21 Feb 2022 16:41:53 +0000 (09:41 -0700)
Avoid a libc function call, just define our own syscall wrappers for
this architecture. Lifted from liburing.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
arch/arch-aarch64.h

index 94571709eb2756d41a921f981b669ae27ee7b1ae..951d1718cfabfbe59469c3421b67d4bc8fb5e103 100644 (file)
@@ -44,4 +44,81 @@ static inline int arch_init(char *envp[])
        return 0;
 }
 
+#define __do_syscallN(...) ({                                          \
+       __asm__ volatile (                                              \
+               "svc 0"                                                 \
+               : "=r"(x0)                                              \
+               : __VA_ARGS__                                           \
+               : "memory", "cc");                                      \
+       (long) x0;                                                      \
+})
+
+#define __do_syscall0(__n) ({                                          \
+       register long x8 __asm__("x8") = __n;                           \
+       register long x0 __asm__("x0");                                 \
+                                                                       \
+       __do_syscallN("r" (x8));                                        \
+})
+
+#define __do_syscall1(__n, __a) ({                                     \
+       register long x8 __asm__("x8") = __n;                           \
+       register __typeof__(__a) x0 __asm__("x0") = __a;                \
+                                                                       \
+       __do_syscallN("r" (x8), "0" (x0));                              \
+})
+
+#define __do_syscall2(__n, __a, __b) ({                                        \
+       register long x8 __asm__("x8") = __n;                           \
+       register __typeof__(__a) x0 __asm__("x0") = __a;                \
+       register __typeof__(__b) x1 __asm__("x1") = __b;                \
+                                                                       \
+       __do_syscallN("r" (x8), "0" (x0), "r" (x1));                    \
+})
+
+#define __do_syscall3(__n, __a, __b, __c) ({                           \
+       register long x8 __asm__("x8") = __n;                           \
+       register __typeof__(__a) x0 __asm__("x0") = __a;                \
+       register __typeof__(__b) x1 __asm__("x1") = __b;                \
+       register __typeof__(__c) x2 __asm__("x2") = __c;                \
+                                                                       \
+       __do_syscallN("r" (x8), "0" (x0), "r" (x1), "r" (x2));          \
+})
+
+#define __do_syscall4(__n, __a, __b, __c, __d) ({                      \
+       register long x8 __asm__("x8") = __n;                           \
+       register __typeof__(__a) x0 __asm__("x0") = __a;                \
+       register __typeof__(__b) x1 __asm__("x1") = __b;                \
+       register __typeof__(__c) x2 __asm__("x2") = __c;                \
+       register __typeof__(__d) x3 __asm__("x3") = __d;                \
+                                                                       \
+       __do_syscallN("r" (x8), "0" (x0), "r" (x1), "r" (x2), "r" (x3));\
+})
+
+#define __do_syscall5(__n, __a, __b, __c, __d, __e) ({                 \
+       register long x8 __asm__("x8") = __n;                           \
+       register __typeof__(__a) x0 __asm__("x0") = __a;                \
+       register __typeof__(__b) x1 __asm__("x1") = __b;                \
+       register __typeof__(__c) x2 __asm__("x2") = __c;                \
+       register __typeof__(__d) x3 __asm__("x3") = __d;                \
+       register __typeof__(__e) x4 __asm__("x4") = __e;                \
+                                                                       \
+       __do_syscallN("r" (x8), "0" (x0), "r" (x1), "r" (x2), "r" (x3), \
+                       "r"(x4));                                       \
+})
+
+#define __do_syscall6(__n, __a, __b, __c, __d, __e, __f) ({            \
+       register long x8 __asm__("x8") = __n;                           \
+       register __typeof__(__a) x0 __asm__("x0") = __a;                \
+       register __typeof__(__b) x1 __asm__("x1") = __b;                \
+       register __typeof__(__c) x2 __asm__("x2") = __c;                \
+       register __typeof__(__d) x3 __asm__("x3") = __d;                \
+       register __typeof__(__e) x4 __asm__("x4") = __e;                \
+       register __typeof__(__f) x5 __asm__("x5") = __f;                \
+                                                                       \
+       __do_syscallN("r" (x8), "0" (x0), "r" (x1), "r" (x2), "r" (x3), \
+                       "r" (x4), "r"(x5));                             \
+})
+
+#define FIO_ARCH_HAS_SYSCALL
+
 #endif