syscall.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2016,2017,2018,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. *
  5. * This file is part of GNU Mes.
  6. *
  7. * GNU Mes is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * GNU Mes is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <errno.h>
  21. #include <linux/x86_64/syscall.h>
  22. long
  23. __sys_call (long sys_call)
  24. {
  25. #if 0 // !MES_CCAMD64
  26. asm ("mov____0x8(%rbp),%rdi !0x10");
  27. #else
  28. asm ("mov____0x8(%rbp),%rax !0x10");
  29. #endif
  30. asm ("syscall");
  31. }
  32. long
  33. __sys_call1 (long sys_call, long one)
  34. {
  35. #if 0 // !MES_CCAMD64
  36. asm ("mov____0x8(%rbp),%rdi !0x10");
  37. asm ("mov____0x8(%rbp),%rsi !0x18");
  38. #else
  39. asm ("mov____0x8(%rbp),%rax !0x10");
  40. asm ("mov____0x8(%rbp),%rdi !0x18");
  41. #endif
  42. asm ("syscall");
  43. }
  44. long
  45. __sys_call2 (long sys_call, long one, long two)
  46. {
  47. #if 0 // !MES_CCAMD64
  48. asm ("mov____0x8(%rbp),%rdi !0x10");
  49. asm ("mov____0x8(%rbp),%rsi !0x18");
  50. asm ("mov____0x8(%rbp),%rdx !0x20");
  51. #else
  52. asm ("mov____0x8(%rbp),%rax !0x10");
  53. asm ("mov____0x8(%rbp),%rdi !0x18");
  54. asm ("mov____0x8(%rbp),%rsi !0x20");
  55. #endif
  56. asm ("syscall");
  57. }
  58. long
  59. __sys_call3 (long sys_call, long one, long two, long three)
  60. {
  61. #if 0 // !MES_CCAMD64
  62. asm ("mov____0x8(%rbp),%rdi !0x10");
  63. asm ("mov____0x8(%rbp),%rsi !0x18");
  64. asm ("mov____0x8(%rbp),%rdx !0x20");
  65. asm ("mov____0x8(%rbp),%rdx !0x28");
  66. #else
  67. asm ("mov____0x8(%rbp),%rax !0x10");
  68. asm ("mov____0x8(%rbp),%rdi !0x18");
  69. asm ("mov____0x8(%rbp),%rsi !0x20");
  70. asm ("mov____0x8(%rbp),%rdx !0x28");
  71. #endif
  72. asm ("syscall");
  73. }
  74. long
  75. __sys_call4 (long sys_call, long one, long two, long three, long four)
  76. {
  77. #if 0 // !MES_CCAMD64
  78. asm ("mov____0x8(%rbp),%rdi !0x10");
  79. asm ("mov____0x8(%rbp),%rsi !0x18");
  80. asm ("mov____0x8(%rbp),%rdx !0x20");
  81. asm ("mov____0x8(%rbp),%rdx !0x28");
  82. asm ("mov____0x8(%rbp),%r10 !0x30");
  83. #else
  84. asm ("mov____0x8(%rbp),%rax !0x10");
  85. asm ("mov____0x8(%rbp),%rdi !0x18");
  86. asm ("mov____0x8(%rbp),%rsi !0x20");
  87. asm ("mov____0x8(%rbp),%rdx !0x28");
  88. asm ("mov____0x8(%rbp),%r10 !0x30");
  89. #endif
  90. asm ("syscall");
  91. }
  92. long
  93. _sys_call (long sys_call)
  94. {
  95. long r = __sys_call (sys_call);
  96. if (r < 0)
  97. {
  98. errno = -r;
  99. r = -1;
  100. }
  101. else
  102. errno = 0;
  103. return r;
  104. }
  105. long
  106. _sys_call1 (long sys_call, long one)
  107. {
  108. long r = __sys_call1 (sys_call, one);
  109. if (r < 0)
  110. {
  111. errno = -r;
  112. r = -1;
  113. }
  114. else
  115. errno = 0;
  116. return r;
  117. }
  118. long
  119. _sys_call2 (long sys_call, long one, long two)
  120. {
  121. long r = __sys_call2 (sys_call, one, two);
  122. if (r < 0)
  123. {
  124. errno = -r;
  125. r = -1;
  126. }
  127. else
  128. errno = 0;
  129. return r;
  130. }
  131. long
  132. _sys_call3 (long sys_call, long one, long two, long three)
  133. {
  134. long r = __sys_call3 (sys_call, one, two, three);
  135. if (r < 0)
  136. {
  137. errno = -r;
  138. r = -1;
  139. }
  140. else
  141. errno = 0;
  142. return r;
  143. }
  144. long
  145. _sys_call4 (long sys_call, long one, long two, long three, long four)
  146. {
  147. long r = __sys_call4 (sys_call, one, two, three, four);
  148. if (r < 0)
  149. {
  150. errno = -r;
  151. r = -1;
  152. }
  153. else
  154. errno = 0;
  155. return r;
  156. }