1 //===--------- inline implementation of arm 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_ARM_SYSCALL_H
10 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_ARM_SYSCALL_H
12 #include "src/__support/common.h"
15 #error "The arm syscall implementation does not yet support thumb flavor."
18 #define REGISTER_DECL_0 \
19 register long r7 __asm__("r7") = number; \
20 register long r0 __asm__("r0");
21 #define REGISTER_DECL_1 \
22 register long r7 __asm__("r7") = number; \
23 register long r0 __asm__("r0") = arg1;
24 #define REGISTER_DECL_2 \
26 register long r1 __asm__("r1") = arg2;
27 #define REGISTER_DECL_3 \
29 register long r2 __asm__("r2") = arg3;
30 #define REGISTER_DECL_4 \
32 register long r3 __asm__("r3") = arg4;
33 #define REGISTER_DECL_5 \
35 register long r4 __asm__("r4") = arg5;
36 #define REGISTER_DECL_6 \
38 register long r5 __asm__("r5") = arg6;
40 #define REGISTER_CONSTRAINT_0 "r"(r7)
41 #define REGISTER_CONSTRAINT_1 REGISTER_CONSTRAINT_0, "r"(r0)
42 #define REGISTER_CONSTRAINT_2 REGISTER_CONSTRAINT_1, "r"(r1)
43 #define REGISTER_CONSTRAINT_3 REGISTER_CONSTRAINT_2, "r"(r2)
44 #define REGISTER_CONSTRAINT_4 REGISTER_CONSTRAINT_3, "r"(r3)
45 #define REGISTER_CONSTRAINT_5 REGISTER_CONSTRAINT_4, "r"(r4)
46 #define REGISTER_CONSTRAINT_6 REGISTER_CONSTRAINT_5, "r"(r5)
48 #define SYSCALL_INSTR(input_constraint) \
49 LIBC_INLINE_ASM("svc 0" : "=r"(r0) : input_constraint : "memory", "cc")
51 namespace LIBC_NAMESPACE
{
53 LIBC_INLINE
long syscall_impl(long number
) {
55 SYSCALL_INSTR(REGISTER_CONSTRAINT_0
);
59 LIBC_INLINE
long syscall_impl(long number
, long arg1
) {
61 SYSCALL_INSTR(REGISTER_CONSTRAINT_1
);
65 LIBC_INLINE
long syscall_impl(long number
, long arg1
, long arg2
) {
67 SYSCALL_INSTR(REGISTER_CONSTRAINT_2
);
71 LIBC_INLINE
long syscall_impl(long number
, long arg1
, long arg2
, long arg3
) {
73 SYSCALL_INSTR(REGISTER_CONSTRAINT_3
);
77 LIBC_INLINE
long syscall_impl(long number
, long arg1
, long arg2
, long arg3
,
80 SYSCALL_INSTR(REGISTER_CONSTRAINT_4
);
84 LIBC_INLINE
long syscall_impl(long number
, long arg1
, long arg2
, long arg3
,
85 long arg4
, long arg5
) {
87 SYSCALL_INSTR(REGISTER_CONSTRAINT_5
);
91 LIBC_INLINE
long syscall_impl(long number
, long arg1
, long arg2
, long arg3
,
92 long arg4
, long arg5
, long arg6
) {
94 SYSCALL_INSTR(REGISTER_CONSTRAINT_6
);
98 } // namespace LIBC_NAMESPACE
100 #undef REGISTER_DECL_0
101 #undef REGISTER_DECL_1
102 #undef REGISTER_DECL_2
103 #undef REGISTER_DECL_3
104 #undef REGISTER_DECL_4
105 #undef REGISTER_DECL_5
106 #undef REGISTER_DECL_6
108 #undef REGISTER_CONSTRAINT_0
109 #undef REGISTER_CONSTRAINT_1
110 #undef REGISTER_CONSTRAINT_2
111 #undef REGISTER_CONSTRAINT_3
112 #undef REGISTER_CONSTRAINT_4
113 #undef REGISTER_CONSTRAINT_5
114 #undef REGISTER_CONSTRAINT_6
116 #endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_ARM_SYSCALL_H