1 //===--------- inline implementation of aarch64 syscalls ----------* C++ *-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AARCH64_SYSCALL_H 10 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AARCH64_SYSCALL_H 11 12 #include "src/__support/common.h" 13 #include "src/__support/macros/config.h" 14 15 #define REGISTER_DECL_0 \ 16 register long x8 __asm__("x8") = number; \ 17 register long x0 __asm__("x0"); 18 #define REGISTER_DECL_1 \ 19 register long x8 __asm__("x8") = number; \ 20 register long x0 __asm__("x0") = arg1; 21 #define REGISTER_DECL_2 REGISTER_DECL_1 register long x1 __asm__("x1") = arg2; 22 #define REGISTER_DECL_3 \ 23 REGISTER_DECL_2 \ 24 register long x2 __asm__("x2") = arg3; 25 #define REGISTER_DECL_4 \ 26 REGISTER_DECL_3 \ 27 register long x3 __asm__("x3") = arg4; 28 #define REGISTER_DECL_5 \ 29 REGISTER_DECL_4 \ 30 register long x4 __asm__("x4") = arg5; 31 #define REGISTER_DECL_6 \ 32 REGISTER_DECL_5 \ 33 register long x5 __asm__("x5") = arg6; 34 35 #define REGISTER_CONSTRAINT_0 "r"(x8) 36 #define REGISTER_CONSTRAINT_1 REGISTER_CONSTRAINT_0, "r"(x0) 37 #define REGISTER_CONSTRAINT_2 REGISTER_CONSTRAINT_1, "r"(x1) 38 #define REGISTER_CONSTRAINT_3 REGISTER_CONSTRAINT_2, "r"(x2) 39 #define REGISTER_CONSTRAINT_4 REGISTER_CONSTRAINT_3, "r"(x3) 40 #define REGISTER_CONSTRAINT_5 REGISTER_CONSTRAINT_4, "r"(x4) 41 #define REGISTER_CONSTRAINT_6 REGISTER_CONSTRAINT_5, "r"(x5) 42 43 #define SYSCALL_INSTR(input_constraint) \ 44 LIBC_INLINE_ASM("svc 0" : "=r"(x0) : input_constraint : "memory", "cc") 45 46 namespace LIBC_NAMESPACE_DECL { 47 48 LIBC_INLINE long syscall_impl(long number) { 49 REGISTER_DECL_0; 50 SYSCALL_INSTR(REGISTER_CONSTRAINT_0); 51 return x0; 52 } 53 54 LIBC_INLINE long syscall_impl(long number, long arg1) { 55 REGISTER_DECL_1; 56 SYSCALL_INSTR(REGISTER_CONSTRAINT_1); 57 return x0; 58 } 59 60 LIBC_INLINE long syscall_impl(long number, long arg1, long arg2) { 61 REGISTER_DECL_2; 62 SYSCALL_INSTR(REGISTER_CONSTRAINT_2); 63 return x0; 64 } 65 66 LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3) { 67 REGISTER_DECL_3; 68 SYSCALL_INSTR(REGISTER_CONSTRAINT_3); 69 return x0; 70 } 71 72 LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3, 73 long arg4) { 74 REGISTER_DECL_4; 75 SYSCALL_INSTR(REGISTER_CONSTRAINT_4); 76 return x0; 77 } 78 79 LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3, 80 long arg4, long arg5) { 81 REGISTER_DECL_5; 82 SYSCALL_INSTR(REGISTER_CONSTRAINT_5); 83 return x0; 84 } 85 86 LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3, 87 long arg4, long arg5, long arg6) { 88 REGISTER_DECL_6; 89 SYSCALL_INSTR(REGISTER_CONSTRAINT_6); 90 return x0; 91 } 92 93 } // namespace LIBC_NAMESPACE_DECL 94 95 #undef REGISTER_DECL_0 96 #undef REGISTER_DECL_1 97 #undef REGISTER_DECL_2 98 #undef REGISTER_DECL_3 99 #undef REGISTER_DECL_4 100 #undef REGISTER_DECL_5 101 #undef REGISTER_DECL_6 102 103 #undef REGISTER_CONSTRAINT_0 104 #undef REGISTER_CONSTRAINT_1 105 #undef REGISTER_CONSTRAINT_2 106 #undef REGISTER_CONSTRAINT_3 107 #undef REGISTER_CONSTRAINT_4 108 #undef REGISTER_CONSTRAINT_5 109 #undef REGISTER_CONSTRAINT_6 110 111 #endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AARCH64_SYSCALL_H 112