brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.1 KiB · dc98c07 Raw
114 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_DARWIN_ARM_SYSCALL_H10#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_DARWIN_ARM_SYSCALL_H11 12#include "src/__support/common.h"13#include "src/__support/macros/config.h"14 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                                                        \22  REGISTER_DECL_1                                                              \23  register long x1 __asm__("x1") = arg2;24#define REGISTER_DECL_3                                                        \25  REGISTER_DECL_2                                                              \26  register long x2 __asm__("x2") = arg3;27#define REGISTER_DECL_4                                                        \28  REGISTER_DECL_3                                                              \29  register long x3 __asm__("x3") = arg4;30#define REGISTER_DECL_5                                                        \31  REGISTER_DECL_4                                                              \32  register long x4 __asm__("x4") = arg5;33#define REGISTER_DECL_6                                                        \34  REGISTER_DECL_5                                                              \35  register long x5 __asm__("x5") = arg6;36 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)44 45#define SYSCALL_INSTR(input_constraint)                                        \46  LIBC_INLINE_ASM("svc 0x80" : "=r"(x0) : input_constraint : "memory", "cc")47 48namespace LIBC_NAMESPACE_DECL {49 50LIBC_INLINE long syscall_impl(long number) {51  REGISTER_DECL_0;52  SYSCALL_INSTR(REGISTER_CONSTRAINT_0);53  return x0;54}55 56LIBC_INLINE long syscall_impl(long number, long arg1) {57  REGISTER_DECL_1;58  SYSCALL_INSTR(REGISTER_CONSTRAINT_1);59  return x0;60}61 62LIBC_INLINE long syscall_impl(long number, long arg1, long arg2) {63  REGISTER_DECL_2;64  SYSCALL_INSTR(REGISTER_CONSTRAINT_2);65  return x0;66}67 68LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3) {69  REGISTER_DECL_3;70  SYSCALL_INSTR(REGISTER_CONSTRAINT_3);71  return x0;72}73 74LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3,75                              long arg4) {76  REGISTER_DECL_4;77  SYSCALL_INSTR(REGISTER_CONSTRAINT_4);78  return x0;79}80 81LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3,82                              long arg4, long arg5) {83  REGISTER_DECL_5;84  SYSCALL_INSTR(REGISTER_CONSTRAINT_5);85  return x0;86}87 88LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3,89                              long arg4, long arg5, long arg6) {90  REGISTER_DECL_6;91  SYSCALL_INSTR(REGISTER_CONSTRAINT_6);92  return x0;93}94 95} // namespace LIBC_NAMESPACE_DECL96 97#undef REGISTER_DECL_098#undef REGISTER_DECL_199#undef REGISTER_DECL_2100#undef REGISTER_DECL_3101#undef REGISTER_DECL_4102#undef REGISTER_DECL_5103#undef REGISTER_DECL_6104 105#undef REGISTER_CONSTRAINT_0106#undef REGISTER_CONSTRAINT_1107#undef REGISTER_CONSTRAINT_2108#undef REGISTER_CONSTRAINT_3109#undef REGISTER_CONSTRAINT_4110#undef REGISTER_CONSTRAINT_5111#undef REGISTER_CONSTRAINT_6112 113#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_DARWIN_ARM_SYSCALL_H114