syscall.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2016,2017,2018 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/syscall.h>
  22. int errno;
  23. int
  24. __sys_call (int sys_call)
  25. {
  26. asm("RD_A7 RS1_FP !-8 LD");
  27. asm("ECALL");}
  28. int
  29. __sys_call1 (int sys_call, int one)
  30. {
  31. asm("RD_A7 RS1_FP !-8 LD");
  32. asm("RD_A0 RS1_FP !-16 LD");
  33. asm("ECALL");
  34. }
  35. int
  36. __sys_call2 (int sys_call, int one, int two)
  37. {
  38. asm("RD_A7 RS1_FP !-8 LD");
  39. asm("RD_A0 RS1_FP !-16 LD");
  40. asm("RD_A1 RS1_FP !-24 LD");
  41. asm("ECALL");
  42. }
  43. int
  44. __sys_call3 (int sys_call, int one, int two, int three)
  45. {
  46. asm("RD_A7 RS1_FP !-8 LD");
  47. asm("RD_A0 RS1_FP !-16 LD");
  48. asm("RD_A1 RS1_FP !-24 LD");
  49. asm("RD_A2 RS1_FP !-32 LD");
  50. asm("ECALL");
  51. }
  52. int
  53. __sys_call4 (int sys_call, int one, int two, int three, int four)
  54. {
  55. asm("RD_A7 RS1_FP !-8 LD");
  56. asm("RD_A0 RS1_FP !-16 LD");
  57. asm("RD_A1 RS1_FP !-24 LD");
  58. asm("RD_A2 RS1_FP !-32 LD");
  59. asm("RD_A3 RS1_FP !-40 LD");
  60. asm("ECALL");
  61. }
  62. int
  63. _sys_call (int sys_call)
  64. {
  65. int r = __sys_call (sys_call);
  66. if (r < 0)
  67. {
  68. errno = -r;
  69. r = -1;
  70. }
  71. else
  72. errno = 0;
  73. return r;
  74. }
  75. int
  76. _sys_call1 (int sys_call, int one)
  77. {
  78. int r = __sys_call1 (sys_call, one);
  79. if (r < 0)
  80. {
  81. errno = -r;
  82. r = -1;
  83. }
  84. else
  85. errno = 0;
  86. return r;
  87. }
  88. int
  89. _sys_call2 (int sys_call, int one, int two)
  90. {
  91. int r = __sys_call2 (sys_call, one, two);
  92. if (r < 0)
  93. {
  94. errno = -r;
  95. r = -1;
  96. }
  97. else
  98. errno = 0;
  99. return r;
  100. }
  101. int
  102. _sys_call3 (int sys_call, int one, int two, int three)
  103. {
  104. int r = __sys_call3 (sys_call, one, two, three);
  105. if (r < 0)
  106. {
  107. errno = -r;
  108. r = -1;
  109. }
  110. else
  111. errno = 0;
  112. return r;
  113. }
  114. int
  115. _sys_call4 (int sys_call, int one, int two, int three, int four)
  116. {
  117. int r = __sys_call4 (sys_call, one, two, three, four);
  118. if (r < 0)
  119. {
  120. errno = -r;
  121. r = -1;
  122. }
  123. else
  124. errno = 0;
  125. return r;
  126. }