1 //===------ inline implementation of Darwin arm64 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_DARWIN_ARM_SYSCALL_H
10 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_DARWIN_ARM_SYSCALL_H
12 #include "src/__support/common.h"
13 #include "src/__support/macros/config.h"
15 #define REGISTER_DECL_0 \
16 register long x16 __asm__("x16") = number; \
17 register long x0 __asm__("x0");
18 #define REGISTER_DECL_1 \
19 register long x16 __asm__("x16") = number; \
20 register long x0 __asm__("x0") = arg1;
21 #define REGISTER_DECL_2 \
23 register long x1 __asm__("x1") = arg2;
24 #define REGISTER_DECL_3 \
26 register long x2 __asm__("x2") = arg3;
27 #define REGISTER_DECL_4 \
29 register long x3 __asm__("x3") = arg4;
30 #define REGISTER_DECL_5 \
32 register long x4 __asm__("x4") = arg5;
33 #define REGISTER_DECL_6 \
35 register long x5 __asm__("x5") = arg6;
37 #define REGISTER_CONSTRAINT_0 "r"(x16)
38 #define REGISTER_CONSTRAINT_1 REGISTER_CONSTRAINT_0, "r"(x0)
39 #define REGISTER_CONSTRAINT_2 REGISTER_CONSTRAINT_1, "r"(x1)
40 #define REGISTER_CONSTRAINT_3 REGISTER_CONSTRAINT_2, "r"(x2)
41 #define REGISTER_CONSTRAINT_4 REGISTER_CONSTRAINT_3, "r"(x3)
42 #define REGISTER_CONSTRAINT_5 REGISTER_CONSTRAINT_4, "r"(x4)
43 #define REGISTER_CONSTRAINT_6 REGISTER_CONSTRAINT_5, "r"(x5)
45 #define SYSCALL_INSTR(input_constraint) \
46 LIBC_INLINE_ASM("svc 0x80" : "=r"(x0) : input_constraint : "memory", "cc")
48 namespace LIBC_NAMESPACE_DECL
{
50 LIBC_INLINE
long syscall_impl(long number
) {
52 SYSCALL_INSTR(REGISTER_CONSTRAINT_0
);
56 LIBC_INLINE
long syscall_impl(long number
, long arg1
) {
58 SYSCALL_INSTR(REGISTER_CONSTRAINT_1
);
62 LIBC_INLINE
long syscall_impl(long number
, long arg1
, long arg2
) {
64 SYSCALL_INSTR(REGISTER_CONSTRAINT_2
);
68 LIBC_INLINE
long syscall_impl(long number
, long arg1
, long arg2
, long arg3
) {
70 SYSCALL_INSTR(REGISTER_CONSTRAINT_3
);
74 LIBC_INLINE
long syscall_impl(long number
, long arg1
, long arg2
, long arg3
,
77 SYSCALL_INSTR(REGISTER_CONSTRAINT_4
);
81 LIBC_INLINE
long syscall_impl(long number
, long arg1
, long arg2
, long arg3
,
82 long arg4
, long arg5
) {
84 SYSCALL_INSTR(REGISTER_CONSTRAINT_5
);
88 LIBC_INLINE
long syscall_impl(long number
, long arg1
, long arg2
, long arg3
,
89 long arg4
, long arg5
, long arg6
) {
91 SYSCALL_INSTR(REGISTER_CONSTRAINT_6
);
95 } // namespace LIBC_NAMESPACE_DECL
97 #undef REGISTER_DECL_0
98 #undef REGISTER_DECL_1
99 #undef REGISTER_DECL_2
100 #undef REGISTER_DECL_3
101 #undef REGISTER_DECL_4
102 #undef REGISTER_DECL_5
103 #undef REGISTER_DECL_6
105 #undef REGISTER_CONSTRAINT_0
106 #undef REGISTER_CONSTRAINT_1
107 #undef REGISTER_CONSTRAINT_2
108 #undef REGISTER_CONSTRAINT_3
109 #undef REGISTER_CONSTRAINT_4
110 #undef REGISTER_CONSTRAINT_5
111 #undef REGISTER_CONSTRAINT_6
113 #endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_DARWIN_ARM_SYSCALL_H