syscall.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 ("mov____0x8(%ebp),%eax !-4");
  27. asm ("int____$0x80");
  28. }
  29. int
  30. __sys_call1 (int sys_call, int one)
  31. {
  32. asm ("mov____0x8(%ebp),%eax !-4");
  33. asm ("mov____0x8(%ebp),%ebx !-8");
  34. asm ("int____$0x80");
  35. }
  36. int
  37. __sys_call2 (int sys_call, int one, int two)
  38. {
  39. asm ("mov____0x8(%ebp),%eax !-4");
  40. asm ("mov____0x8(%ebp),%ebx !-8");
  41. asm ("mov____0x8(%ebp),%ecx !-12");
  42. asm ("int____$0x80");
  43. }
  44. int
  45. __sys_call3 (int sys_call, int one, int two, int three)
  46. {
  47. asm ("mov____0x8(%ebp),%eax !-4");
  48. asm ("mov____0x8(%ebp),%ebx !-8");
  49. asm ("mov____0x8(%ebp),%ecx !-12");
  50. asm ("mov____0x8(%ebp),%edx !-16");
  51. asm ("int____$0x80");
  52. }
  53. int
  54. __sys_call4 (int sys_call, int one, int two, int three, int four)
  55. {
  56. asm ("mov____0x8(%ebp),%eax !-4");
  57. asm ("mov____0x8(%ebp),%ebx !-8");
  58. asm ("mov____0x8(%ebp),%ecx !-12");
  59. asm ("mov____0x8(%ebp),%edx !-16");
  60. asm ("mov____0x8(%ebp),%esi !-24");
  61. asm ("int____$0x80");
  62. }
  63. int
  64. _sys_call (int sys_call)
  65. {
  66. int r = __sys_call (sys_call);
  67. if (r < 0)
  68. {
  69. errno = -r;
  70. r = -1;
  71. }
  72. else
  73. errno = 0;
  74. return r;
  75. }
  76. int
  77. _sys_call1 (int sys_call, int one)
  78. {
  79. int r = __sys_call1 (sys_call, one);
  80. if (r < 0)
  81. {
  82. errno = -r;
  83. r = -1;
  84. }
  85. else
  86. errno = 0;
  87. return r;
  88. }
  89. int
  90. _sys_call2 (int sys_call, int one, int two)
  91. {
  92. int r = __sys_call2 (sys_call, one, two);
  93. if (r < 0)
  94. {
  95. errno = -r;
  96. r = -1;
  97. }
  98. else
  99. errno = 0;
  100. return r;
  101. }
  102. int
  103. _sys_call3 (int sys_call, int one, int two, int three)
  104. {
  105. int r = __sys_call3 (sys_call, one, two, three);
  106. if (r < 0)
  107. {
  108. errno = -r;
  109. r = -1;
  110. }
  111. else
  112. errno = 0;
  113. return r;
  114. }
  115. int
  116. _sys_call4 (int sys_call, int one, int two, int three, int four)
  117. {
  118. int r = __sys_call4 (sys_call, one, two, three, four);
  119. if (r < 0)
  120. {
  121. errno = -r;
  122. r = -1;
  123. }
  124. else
  125. errno = 0;
  126. return r;
  127. }