1
0

syscall_arch.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #define __SYSCALL_LL_E(x) (x)
  2. #define __SYSCALL_LL_O(x) (x)
  3. #define __asm_syscall(ret, ...) do { \
  4. __asm__ __volatile__ ("svc 0\n" \
  5. : ret : __VA_ARGS__ : "memory"); \
  6. return r2; \
  7. } while (0)
  8. static inline long __syscall0(long n)
  9. {
  10. register long r1 __asm__("r1") = n;
  11. register long r2 __asm__("r2");
  12. __asm_syscall("=r"(r2), "r"(r1));
  13. }
  14. static inline long __syscall1(long n, long a)
  15. {
  16. register long r1 __asm__("r1") = n;
  17. register long r2 __asm__("r2") = a;
  18. __asm_syscall("+r"(r2), "r"(r1));
  19. }
  20. static inline long __syscall2(long n, long a, long b)
  21. {
  22. register long r1 __asm__("r1") = n;
  23. register long r2 __asm__("r2") = a;
  24. register long r3 __asm__("r3") = b;
  25. __asm_syscall("+r"(r2), "r"(r1), "r"(r3));
  26. }
  27. static inline long __syscall3(long n, long a, long b, long c)
  28. {
  29. register long r1 __asm__("r1") = n;
  30. register long r2 __asm__("r2") = a;
  31. register long r3 __asm__("r3") = b;
  32. register long r4 __asm__("r4") = c;
  33. __asm_syscall("+r"(r2), "r"(r1), "r"(r3), "r"(r4));
  34. }
  35. static inline long __syscall4(long n, long a, long b, long c, long d)
  36. {
  37. register long r1 __asm__("r1") = n;
  38. register long r2 __asm__("r2") = a;
  39. register long r3 __asm__("r3") = b;
  40. register long r4 __asm__("r4") = c;
  41. register long r5 __asm__("r5") = d;
  42. __asm_syscall("+r"(r2), "r"(r1), "r"(r3), "r"(r4), "r"(r5));
  43. }
  44. static inline long __syscall5(long n, long a, long b, long c, long d, long e)
  45. {
  46. register long r1 __asm__("r1") = n;
  47. register long r2 __asm__("r2") = a;
  48. register long r3 __asm__("r3") = b;
  49. register long r4 __asm__("r4") = c;
  50. register long r5 __asm__("r5") = d;
  51. register long r6 __asm__("r6") = e;
  52. __asm_syscall("+r"(r2), "r"(r1), "r"(r3), "r"(r4), "r"(r5), "r"(r6));
  53. }
  54. static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
  55. {
  56. if (n == SYS_mmap) return __syscall1(n, (long)(long[]){a,b,c,d,e,f});
  57. register long r1 __asm__("r1") = n;
  58. register long r2 __asm__("r2") = a;
  59. register long r3 __asm__("r3") = b;
  60. register long r4 __asm__("r4") = c;
  61. register long r5 __asm__("r5") = d;
  62. register long r6 __asm__("r6") = e;
  63. register long r7 __asm__("r7") = f;
  64. __asm_syscall("+r"(r2), "r"(r1), "r"(r3), "r"(r4), "r"(r5), "r"(r6), "r"(r7));
  65. }