• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===--------- inline implementation of arm 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_LINUX_ARM_SYSCALL_H
10 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_ARM_SYSCALL_H
11 
12 #include "src/__support/common.h"
13 
14 #ifdef __thumb__
15 #error "The arm syscall implementation does not yet support thumb flavor."
16 #endif // __thumb__
17 
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                                                        \
25   REGISTER_DECL_1                                                              \
26   register long r1 __asm__("r1") = arg2;
27 #define REGISTER_DECL_3                                                        \
28   REGISTER_DECL_2                                                              \
29   register long r2 __asm__("r2") = arg3;
30 #define REGISTER_DECL_4                                                        \
31   REGISTER_DECL_3                                                              \
32   register long r3 __asm__("r3") = arg4;
33 #define REGISTER_DECL_5                                                        \
34   REGISTER_DECL_4                                                              \
35   register long r4 __asm__("r4") = arg5;
36 #define REGISTER_DECL_6                                                        \
37   REGISTER_DECL_5                                                              \
38   register long r5 __asm__("r5") = arg6;
39 
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)
47 
48 #define SYSCALL_INSTR(input_constraint)                                        \
49   LIBC_INLINE_ASM("svc 0" : "=r"(r0) : input_constraint : "memory", "cc")
50 
51 namespace LIBC_NAMESPACE {
52 
syscall_impl(long number)53 LIBC_INLINE long syscall_impl(long number) {
54   REGISTER_DECL_0;
55   SYSCALL_INSTR(REGISTER_CONSTRAINT_0);
56   return r0;
57 }
58 
syscall_impl(long number,long arg1)59 LIBC_INLINE long syscall_impl(long number, long arg1) {
60   REGISTER_DECL_1;
61   SYSCALL_INSTR(REGISTER_CONSTRAINT_1);
62   return r0;
63 }
64 
syscall_impl(long number,long arg1,long arg2)65 LIBC_INLINE long syscall_impl(long number, long arg1, long arg2) {
66   REGISTER_DECL_2;
67   SYSCALL_INSTR(REGISTER_CONSTRAINT_2);
68   return r0;
69 }
70 
syscall_impl(long number,long arg1,long arg2,long arg3)71 LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3) {
72   REGISTER_DECL_3;
73   SYSCALL_INSTR(REGISTER_CONSTRAINT_3);
74   return r0;
75 }
76 
syscall_impl(long number,long arg1,long arg2,long arg3,long arg4)77 LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3,
78                               long arg4) {
79   REGISTER_DECL_4;
80   SYSCALL_INSTR(REGISTER_CONSTRAINT_4);
81   return r0;
82 }
83 
syscall_impl(long number,long arg1,long arg2,long arg3,long arg4,long arg5)84 LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3,
85                               long arg4, long arg5) {
86   REGISTER_DECL_5;
87   SYSCALL_INSTR(REGISTER_CONSTRAINT_5);
88   return r0;
89 }
90 
syscall_impl(long number,long arg1,long arg2,long arg3,long arg4,long arg5,long arg6)91 LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3,
92                               long arg4, long arg5, long arg6) {
93   REGISTER_DECL_6;
94   SYSCALL_INSTR(REGISTER_CONSTRAINT_6);
95   return r0;
96 }
97 
98 } // namespace LIBC_NAMESPACE
99 
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
107 
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
115 
116 #endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_ARM_SYSCALL_H
117