• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===------ inline implementation of Darwin arm64 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_DARWIN_ARM_SYSCALL_H
10 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_DARWIN_ARM_SYSCALL_H
11 
12 #include "src/__support/common.h"
13 
14 #define REGISTER_DECL_0                                                        \
15   register long x16 __asm__("x16") = number;                                   \
16   register long x0 __asm__("x0");
17 #define REGISTER_DECL_1                                                        \
18   register long x16 __asm__("x16") = number;                                   \
19   register long x0 __asm__("x0") = arg1;
20 #define REGISTER_DECL_2                                                        \
21   REGISTER_DECL_1                                                              \
22   register long x1 __asm__("x1") = arg2;
23 #define REGISTER_DECL_3                                                        \
24   REGISTER_DECL_2                                                              \
25   register long x2 __asm__("x2") = arg3;
26 #define REGISTER_DECL_4                                                        \
27   REGISTER_DECL_3                                                              \
28   register long x3 __asm__("x3") = arg4;
29 #define REGISTER_DECL_5                                                        \
30   REGISTER_DECL_4                                                              \
31   register long x4 __asm__("x4") = arg5;
32 #define REGISTER_DECL_6                                                        \
33   REGISTER_DECL_5                                                              \
34   register long x5 __asm__("x5") = arg6;
35 
36 #define REGISTER_CONSTRAINT_0 "r"(x16)
37 #define REGISTER_CONSTRAINT_1 REGISTER_CONSTRAINT_0, "r"(x0)
38 #define REGISTER_CONSTRAINT_2 REGISTER_CONSTRAINT_1, "r"(x1)
39 #define REGISTER_CONSTRAINT_3 REGISTER_CONSTRAINT_2, "r"(x2)
40 #define REGISTER_CONSTRAINT_4 REGISTER_CONSTRAINT_3, "r"(x3)
41 #define REGISTER_CONSTRAINT_5 REGISTER_CONSTRAINT_4, "r"(x4)
42 #define REGISTER_CONSTRAINT_6 REGISTER_CONSTRAINT_5, "r"(x5)
43 
44 #define SYSCALL_INSTR(input_constraint)                                        \
45   LIBC_INLINE_ASM("svc 0x80" : "=r"(x0) : input_constraint : "memory", "cc")
46 
47 namespace LIBC_NAMESPACE {
48 
syscall_impl(long number)49 LIBC_INLINE long syscall_impl(long number) {
50   REGISTER_DECL_0;
51   SYSCALL_INSTR(REGISTER_CONSTRAINT_0);
52   return x0;
53 }
54 
syscall_impl(long number,long arg1)55 LIBC_INLINE long syscall_impl(long number, long arg1) {
56   REGISTER_DECL_1;
57   SYSCALL_INSTR(REGISTER_CONSTRAINT_1);
58   return x0;
59 }
60 
syscall_impl(long number,long arg1,long arg2)61 LIBC_INLINE long syscall_impl(long number, long arg1, long arg2) {
62   REGISTER_DECL_2;
63   SYSCALL_INSTR(REGISTER_CONSTRAINT_2);
64   return x0;
65 }
66 
syscall_impl(long number,long arg1,long arg2,long arg3)67 LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3) {
68   REGISTER_DECL_3;
69   SYSCALL_INSTR(REGISTER_CONSTRAINT_3);
70   return x0;
71 }
72 
syscall_impl(long number,long arg1,long arg2,long arg3,long arg4)73 LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3,
74                               long arg4) {
75   REGISTER_DECL_4;
76   SYSCALL_INSTR(REGISTER_CONSTRAINT_4);
77   return x0;
78 }
79 
syscall_impl(long number,long arg1,long arg2,long arg3,long arg4,long arg5)80 LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3,
81                               long arg4, long arg5) {
82   REGISTER_DECL_5;
83   SYSCALL_INSTR(REGISTER_CONSTRAINT_5);
84   return x0;
85 }
86 
syscall_impl(long number,long arg1,long arg2,long arg3,long arg4,long arg5,long arg6)87 LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3,
88                               long arg4, long arg5, long arg6) {
89   REGISTER_DECL_6;
90   SYSCALL_INSTR(REGISTER_CONSTRAINT_6);
91   return x0;
92 }
93 
94 } // namespace LIBC_NAMESPACE
95 
96 #undef REGISTER_DECL_0
97 #undef REGISTER_DECL_1
98 #undef REGISTER_DECL_2
99 #undef REGISTER_DECL_3
100 #undef REGISTER_DECL_4
101 #undef REGISTER_DECL_5
102 #undef REGISTER_DECL_6
103 
104 #undef REGISTER_CONSTRAINT_0
105 #undef REGISTER_CONSTRAINT_1
106 #undef REGISTER_CONSTRAINT_2
107 #undef REGISTER_CONSTRAINT_3
108 #undef REGISTER_CONSTRAINT_4
109 #undef REGISTER_CONSTRAINT_5
110 #undef REGISTER_CONSTRAINT_6
111 
112 #endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_DARWIN_ARM_SYSCALL_H
113