summaryrefslogtreecommitdiffstats
path: root/libc/config/linux/x86_64/syscall.h.inc
blob: 944ac99e51a875db113e8c9c9a2c6f5a9459c54f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//===------------ inline implementation of x86_64 syscalls --------------*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

%%begin()

#include "src/__support/common.h"

#define SYSCALL_CLOBBER_LIST "rcx", "r11", "memory"

namespace __llvm_libc {

inline long syscall(long __number) {
  long retcode;
  LIBC_INLINE_ASM("syscall" :
             "=a"(retcode) :
             "a"(__number) :
             SYSCALL_CLOBBER_LIST);
  return retcode;
}

inline long syscall(long __number, long __arg1) {
  long retcode;
  LIBC_INLINE_ASM("syscall" :
             "=a"(retcode) :
             "a"(__number), "D"(__arg1) :
             SYSCALL_CLOBBER_LIST);
  return retcode;
}

inline long syscall(long __number, long __arg1, long __arg2) {
  long retcode;
  LIBC_INLINE_ASM("syscall" :
             "=a"(retcode) :
             "a"(__number), "D"(__arg1), "S"(__arg2) :
             SYSCALL_CLOBBER_LIST);
  return retcode;
}

inline long syscall(long __number, long __arg1, long __arg2, long __arg3) {
  long retcode;
  LIBC_INLINE_ASM("syscall" :
             "=a"(retcode) :
             "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3) :
             SYSCALL_CLOBBER_LIST);
  return retcode;
}

inline long syscall(
    long __number, long __arg1, long __arg2, long __arg3, long __arg4) {
  long retcode;
  register long r10 __asm__("r10") = __arg4;
  LIBC_INLINE_ASM("syscall" :
             "=a"(retcode) :
             "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3), "r"(r10) :
             SYSCALL_CLOBBER_LIST);
  return retcode;
}

inline long syscall(long __number, long __arg1, long __arg2, long __arg3,
                    long __arg4, long __arg5) {
  long retcode;
  register long r10 __asm__("r10") = __arg4;
  register long r8 __asm__("r8") = __arg5;
  LIBC_INLINE_ASM(
      "syscall" :
      "=a"(retcode) :
      "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3), "r"(r10), "r"(r8) :
      SYSCALL_CLOBBER_LIST);
  return retcode;
}

inline long syscall(long __number, long __arg1, long __arg2, long __arg3,
                    long __arg4, long __arg5, long __arg6) {
  long retcode;
  register long r10 __asm__("r10") = __arg4;
  register long r8 __asm__("r8") = __arg5;
  register long r9 __asm__("r9") = __arg6;
  LIBC_INLINE_ASM(
      "syscall" :
      "=a"(retcode) :
      "a"(__number), "D"(__arg1), "S"(__arg2), "d"(__arg3), "r"(r10), "r"(r8), "r"(r9) :
      SYSCALL_CLOBBER_LIST);
  return retcode;
}

#undef SYSCALL_CLOBBER_LIST

} // namespace __llvm_libc
OpenPOWER on IntegriCloud