syscalls.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef _BITS_SYSCALLS_H
  2. #define _BITS_SYSCALLS_H
  3. #ifndef _SYSCALL_H
  4. # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
  5. #endif
  6. /* m68k headers does stupid stuff with __NR_iopl / __NR_vm86:
  7. * #define __NR_iopl not supported
  8. * #define __NR_vm86 not supported
  9. */
  10. #undef __NR_iopl
  11. #undef __NR_vm86
  12. #ifndef __ASSEMBLER__
  13. /* Linux takes system call arguments in registers:
  14. syscall number %d0 call-clobbered
  15. arg 1 %d1 call-clobbered
  16. arg 2 %d2 call-saved
  17. arg 3 %d3 call-saved
  18. arg 4 %d4 call-saved
  19. arg 5 %d5 call-saved
  20. arg 6 %a0 call-clobbered
  21. The stack layout upon entering the function is:
  22. 24(%sp) Arg# 6
  23. 20(%sp) Arg# 5
  24. 16(%sp) Arg# 4
  25. 12(%sp) Arg# 3
  26. 8(%sp) Arg# 2
  27. 4(%sp) Arg# 1
  28. (%sp) Return address
  29. (Of course a function with say 3 arguments does not have entries for
  30. arguments 4 and 5.)
  31. Separate move's are faster than movem, but need more space. Since
  32. speed is more important, we don't use movem. Since %a0 and %a1 are
  33. scratch registers, we can use them for saving as well. */
  34. /* Define a macro which expands inline into the wrapper code for a system
  35. call. This use is for internal calls that do not need to handle errors
  36. normally. It will never touch errno. This returns just what the kernel
  37. gave back. */
  38. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  39. (__extension__ \
  40. ({ unsigned int _sys_result; \
  41. { \
  42. /* Load argument values in temporary variables
  43. to perform side effects like function calls
  44. before the call used registers are set. */ \
  45. LOAD_ARGS_##nr (args) \
  46. LOAD_REGS_##nr \
  47. register int _d0 __asm__ ("%d0") = name; \
  48. __asm__ __volatile__ ("trap #0" \
  49. : "=d" (_d0) \
  50. : "0" (_d0) ASM_ARGS_##nr \
  51. : "memory"); \
  52. _sys_result = _d0; \
  53. } \
  54. (int) _sys_result; \
  55. }) \
  56. )
  57. #define LOAD_ARGS_0()
  58. #define LOAD_REGS_0
  59. #define ASM_ARGS_0
  60. #define LOAD_ARGS_1(a1) \
  61. LOAD_ARGS_0 () \
  62. int __arg1 = (int) (a1);
  63. #define LOAD_REGS_1 \
  64. register int _d1 __asm__ ("d1") = __arg1; \
  65. LOAD_REGS_0
  66. #define ASM_ARGS_1 ASM_ARGS_0, "d" (_d1)
  67. #define LOAD_ARGS_2(a1, a2) \
  68. LOAD_ARGS_1 (a1) \
  69. int __arg2 = (int) (a2);
  70. #define LOAD_REGS_2 \
  71. register int _d2 __asm__ ("d2") = __arg2; \
  72. LOAD_REGS_1
  73. #define ASM_ARGS_2 ASM_ARGS_1, "d" (_d2)
  74. #define LOAD_ARGS_3(a1, a2, a3) \
  75. LOAD_ARGS_2 (a1, a2) \
  76. int __arg3 = (int) (a3);
  77. #define LOAD_REGS_3 \
  78. register int _d3 __asm__ ("d3") = __arg3; \
  79. LOAD_REGS_2
  80. #define ASM_ARGS_3 ASM_ARGS_2, "d" (_d3)
  81. #define LOAD_ARGS_4(a1, a2, a3, a4) \
  82. LOAD_ARGS_3 (a1, a2, a3) \
  83. int __arg4 = (int) (a4);
  84. #define LOAD_REGS_4 \
  85. register int _d4 __asm__ ("d4") = __arg4; \
  86. LOAD_REGS_3
  87. #define ASM_ARGS_4 ASM_ARGS_3, "d" (_d4)
  88. #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
  89. LOAD_ARGS_4 (a1, a2, a3, a4) \
  90. int __arg5 = (int) (a5);
  91. #define LOAD_REGS_5 \
  92. register int _d5 __asm__ ("d5") = __arg5; \
  93. LOAD_REGS_4
  94. #define ASM_ARGS_5 ASM_ARGS_4, "d" (_d5)
  95. #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
  96. LOAD_ARGS_5 (a1, a2, a3, a4, a5) \
  97. int __arg6 = (int) (a6);
  98. #define LOAD_REGS_6 \
  99. register int _a0 __asm__ ("a0") = __arg6; \
  100. LOAD_REGS_5
  101. #define ASM_ARGS_6 ASM_ARGS_5, "a" (_a0)
  102. #endif /* __ASSEMBLER__ */
  103. #endif /* _BITS_SYSCALLS_H */