1 //===--------- inline implementation of aarch64 syscalls ----------* C++ *-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AARCH64_SYSCALL_H
10 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AARCH64_SYSCALL_H
12 #include "src/__support/common.h"
14 #define REGISTER_DECL_0 \
15 register long x8 __asm__("x8") = number; \
16 register long x0 __asm__("x0");
17 #define REGISTER_DECL_1 \
18 register long x8 __asm__("x8") = number; \
19 register long x0 __asm__("x0") = arg1;
20 #define REGISTER_DECL_2 REGISTER_DECL_1 register long x1 __asm__("x1") = arg2;
21 #define REGISTER_DECL_3 \
23 register long x2 __asm__("x2") = arg3;
24 #define REGISTER_DECL_4 \
26 register long x3 __asm__("x3") = arg4;
27 #define REGISTER_DECL_5 \
29 register long x4 __asm__("x4") = arg5;
30 #define REGISTER_DECL_6 \
32 register long x5 __asm__("x5") = arg6;
34 #define REGISTER_CONSTRAINT_0 "r"(x8)
35 #define REGISTER_CONSTRAINT_1 REGISTER_CONSTRAINT_0, "r"(x0)
36 #define REGISTER_CONSTRAINT_2 REGISTER_CONSTRAINT_1, "r"(x1)
37 #define REGISTER_CONSTRAINT_3 REGISTER_CONSTRAINT_2, "r"(x2)
38 #define REGISTER_CONSTRAINT_4 REGISTER_CONSTRAINT_3, "r"(x3)
39 #define REGISTER_CONSTRAINT_5 REGISTER_CONSTRAINT_4, "r"(x4)
40 #define REGISTER_CONSTRAINT_6 REGISTER_CONSTRAINT_5, "r"(x5)
42 #define SYSCALL_INSTR(input_constraint) \
43 LIBC_INLINE_ASM("svc 0" : "=r"(x0) : input_constraint : "memory", "cc")
45 namespace LIBC_NAMESPACE
{
47 LIBC_INLINE
long syscall_impl(long number
) {
49 SYSCALL_INSTR(REGISTER_CONSTRAINT_0
);
53 LIBC_INLINE
long syscall_impl(long number
, long arg1
) {
55 SYSCALL_INSTR(REGISTER_CONSTRAINT_1
);
59 LIBC_INLINE
long syscall_impl(long number
, long arg1
, long arg2
) {
61 SYSCALL_INSTR(REGISTER_CONSTRAINT_2
);
65 LIBC_INLINE
long syscall_impl(long number
, long arg1
, long arg2
, long arg3
) {
67 SYSCALL_INSTR(REGISTER_CONSTRAINT_3
);
71 LIBC_INLINE
long syscall_impl(long number
, long arg1
, long arg2
, long arg3
,
74 SYSCALL_INSTR(REGISTER_CONSTRAINT_4
);
78 LIBC_INLINE
long syscall_impl(long number
, long arg1
, long arg2
, long arg3
,
79 long arg4
, long arg5
) {
81 SYSCALL_INSTR(REGISTER_CONSTRAINT_5
);
85 LIBC_INLINE
long syscall_impl(long number
, long arg1
, long arg2
, long arg3
,
86 long arg4
, long arg5
, long arg6
) {
88 SYSCALL_INSTR(REGISTER_CONSTRAINT_6
);
92 } // namespace LIBC_NAMESPACE
94 #undef REGISTER_DECL_0
95 #undef REGISTER_DECL_1
96 #undef REGISTER_DECL_2
97 #undef REGISTER_DECL_3
98 #undef REGISTER_DECL_4
99 #undef REGISTER_DECL_5
100 #undef REGISTER_DECL_6
102 #undef REGISTER_CONSTRAINT_0
103 #undef REGISTER_CONSTRAINT_1
104 #undef REGISTER_CONSTRAINT_2
105 #undef REGISTER_CONSTRAINT_3
106 #undef REGISTER_CONSTRAINT_4
107 #undef REGISTER_CONSTRAINT_5
108 #undef REGISTER_CONSTRAINT_6
110 #endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AARCH64_SYSCALL_H