syscall.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef __SYSCALL_H__
  2. #define __SYSCALL_H__
  3. #include "bits/syscall.h"
  4. #include "bits/errno.h"
  5. inline static long syscall0(int nr)
  6. {
  7. register long x8 asm("x8") = nr;
  8. register long x0 asm("x0");
  9. asm volatile ("svc 0"
  10. : "=r"(x0)
  11. : "r"(x8)
  12. : "memory");
  13. return x0;
  14. }
  15. inline static long syscall1(int nr, long a1)
  16. {
  17. register long x8 asm("x8") = nr;
  18. register long x0 asm("x0") = a1;
  19. asm volatile ("svc 0"
  20. : "=r"(x0)
  21. : "r"(x8), "r"(x0)
  22. : "memory");
  23. return x0;
  24. }
  25. inline static long syscall2(int nr, long a1, long a2)
  26. {
  27. register long x8 asm("x8") = nr;
  28. register long x0 asm("x0") = a1;
  29. register long x1 asm("x1") = a2;
  30. asm volatile ("svc 0"
  31. : "=r"(x0)
  32. : "r"(x8), "r"(x0), "r"(x1)
  33. : "memory");
  34. return x0;
  35. }
  36. inline static long syscall3(int nr, long a1, long a2, long a3)
  37. {
  38. register long x8 asm("x8") = nr;
  39. register long x0 asm("x0") = a1;
  40. register long x1 asm("x1") = a2;
  41. register long x2 asm("x2") = a3;
  42. asm volatile ("svc 0"
  43. : "=r"(x0)
  44. : "r"(x8), "r"(x0), "r"(x1), "r"(x2)
  45. : "memory");
  46. return x0;
  47. }
  48. inline static long syscall4(int nr, long a1, long a2, long a3, long a4)
  49. {
  50. register long x8 asm("x8") = nr;
  51. register long x0 asm("x0") = a1;
  52. register long x1 asm("x1") = a2;
  53. register long x2 asm("x2") = a3;
  54. register long x3 asm("x3") = a4;
  55. asm volatile ("svc 0"
  56. : "=r"(x0)
  57. : "r"(x8), "r"(x0), "r"(x1), "r"(x2), "r"(x3)
  58. : "memory");
  59. return x0;
  60. }
  61. inline static long syscall5(int nr, long a1, long a2, long a3, long a4, long a5)
  62. {
  63. register long x8 asm("x8") = nr;
  64. register long x0 asm("x0") = x0;
  65. register long x1 asm("x1") = x1;
  66. register long x2 asm("x2") = x2;
  67. register long x3 asm("x3") = x3;
  68. register long x4 asm("x4") = x4;
  69. asm volatile ("svc 0"
  70. : "=r"(x0)
  71. : "r"(x8), "r"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4)
  72. : "memory");
  73. return x0;
  74. }
  75. inline static long syscall6(int nr, long a1, long a2, long a3, long a4,
  76. long a5, long a6)
  77. {
  78. register long x8 asm("r7") = nr;
  79. register long x0 asm("r0") = a1;
  80. register long x1 asm("r1") = a2;
  81. register long x2 asm("r2") = a3;
  82. register long x3 asm("r3") = a4;
  83. register long x4 asm("r4") = a5;
  84. register long x5 asm("r5") = a6;
  85. asm volatile ("svc 0"
  86. : "=r"(x0)
  87. : "r"(x8), "r"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4), "r"(x5)
  88. : "memory");
  89. return x0;
  90. }
  91. #endif