112 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AARCH64_SYSCALL_H10#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AARCH64_SYSCALL_H11 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 46namespace LIBC_NAMESPACE_DECL {47 48LIBC_INLINE long syscall_impl(long number) {49 REGISTER_DECL_0;50 SYSCALL_INSTR(REGISTER_CONSTRAINT_0);51 return x0;52}53 54LIBC_INLINE long syscall_impl(long number, long arg1) {55 REGISTER_DECL_1;56 SYSCALL_INSTR(REGISTER_CONSTRAINT_1);57 return x0;58}59 60LIBC_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 66LIBC_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 72LIBC_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 79LIBC_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 86LIBC_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_DECL94 95#undef REGISTER_DECL_096#undef REGISTER_DECL_197#undef REGISTER_DECL_298#undef REGISTER_DECL_399#undef REGISTER_DECL_4100#undef REGISTER_DECL_5101#undef REGISTER_DECL_6102 103#undef REGISTER_CONSTRAINT_0104#undef REGISTER_CONSTRAINT_1105#undef REGISTER_CONSTRAINT_2106#undef REGISTER_CONSTRAINT_3107#undef REGISTER_CONSTRAINT_4108#undef REGISTER_CONSTRAINT_5109#undef REGISTER_CONSTRAINT_6110 111#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AARCH64_SYSCALL_H112