syscalls.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #ifndef __ASSEMBLER__
  7. /* Assume all syscalls are done from PIC code just to be
  8. * safe. The worst case scenario is that you lose a register
  9. * and save/restore r19 across the syscall. */
  10. #define PIC
  11. /* Definition taken from glibc 2.3.3
  12. * sysdeps/unix/sysv/linux/hppa/sysdep.h
  13. */
  14. #ifdef PIC
  15. /* WARNING: CANNOT BE USED IN A NOP! */
  16. # define K_STW_ASM_PIC " copy %%r19, %%r4\n"
  17. # define K_LDW_ASM_PIC " copy %%r4, %%r19\n"
  18. # define K_USING_GR4 "%r4",
  19. #else
  20. # define K_STW_ASM_PIC " \n"
  21. # define K_LDW_ASM_PIC " \n"
  22. # define K_USING_GR4
  23. #endif
  24. /* GCC has to be warned that a syscall may clobber all the ABI
  25. registers listed as "caller-saves", see page 8, Table 2
  26. in section 2.2.6 of the PA-RISC RUN-TIME architecture
  27. document. However! r28 is the result and will conflict with
  28. the clobber list so it is left out. Also the input arguments
  29. registers r20 -> r26 will conflict with the list so they
  30. are treated specially. Although r19 is clobbered by the syscall
  31. we cannot say this because it would violate ABI, thus we say
  32. r4 is clobbered and use that register to save/restore r19
  33. across the syscall. */
  34. #define K_CALL_CLOB_REGS "%r1", "%r2", K_USING_GR4 \
  35. "%r20", "%r29", "%r31"
  36. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  37. (__extension__ \
  38. ({ \
  39. register unsigned long __res __asm__("r28"); \
  40. K_LOAD_ARGS_##nr(args) \
  41. /* FIXME: HACK stw/ldw r19 around syscall */ \
  42. __asm__ __volatile__( \
  43. K_STW_ASM_PIC \
  44. " ble 0x100(%%sr2, %%r0)\n" \
  45. " ldi %1, %%r20\n" \
  46. K_LDW_ASM_PIC \
  47. : "=r" (__res) \
  48. : "i" (name) K_ASM_ARGS_##nr \
  49. : "memory", K_CALL_CLOB_REGS K_CLOB_ARGS_##nr \
  50. ); \
  51. __res; \
  52. }) \
  53. )
  54. #define K_LOAD_ARGS_0()
  55. #define K_LOAD_ARGS_1(r26) \
  56. register unsigned long __r26 __asm__("r26") = (unsigned long)(r26); \
  57. K_LOAD_ARGS_0()
  58. #define K_LOAD_ARGS_2(r26,r25) \
  59. register unsigned long __r25 __asm__("r25") = (unsigned long)(r25); \
  60. K_LOAD_ARGS_1(r26)
  61. #define K_LOAD_ARGS_3(r26,r25,r24) \
  62. register unsigned long __r24 __asm__("r24") = (unsigned long)(r24); \
  63. K_LOAD_ARGS_2(r26,r25)
  64. #define K_LOAD_ARGS_4(r26,r25,r24,r23) \
  65. register unsigned long __r23 __asm__("r23") = (unsigned long)(r23); \
  66. K_LOAD_ARGS_3(r26,r25,r24)
  67. #define K_LOAD_ARGS_5(r26,r25,r24,r23,r22) \
  68. register unsigned long __r22 __asm__("r22") = (unsigned long)(r22); \
  69. K_LOAD_ARGS_4(r26,r25,r24,r23)
  70. #define K_LOAD_ARGS_6(r26,r25,r24,r23,r22,r21) \
  71. register unsigned long __r21 __asm__("r21") = (unsigned long)(r21); \
  72. K_LOAD_ARGS_5(r26,r25,r24,r23,r22)
  73. /* Even with zero args we use r20 for the syscall number */
  74. #define K_ASM_ARGS_0
  75. #define K_ASM_ARGS_1 K_ASM_ARGS_0, "r" (__r26)
  76. #define K_ASM_ARGS_2 K_ASM_ARGS_1, "r" (__r25)
  77. #define K_ASM_ARGS_3 K_ASM_ARGS_2, "r" (__r24)
  78. #define K_ASM_ARGS_4 K_ASM_ARGS_3, "r" (__r23)
  79. #define K_ASM_ARGS_5 K_ASM_ARGS_4, "r" (__r22)
  80. #define K_ASM_ARGS_6 K_ASM_ARGS_5, "r" (__r21)
  81. /* The registers not listed as inputs but clobbered */
  82. #define K_CLOB_ARGS_6
  83. #define K_CLOB_ARGS_5 K_CLOB_ARGS_6, "%r21"
  84. #define K_CLOB_ARGS_4 K_CLOB_ARGS_5, "%r22"
  85. #define K_CLOB_ARGS_3 K_CLOB_ARGS_4, "%r23"
  86. #define K_CLOB_ARGS_2 K_CLOB_ARGS_3, "%r24"
  87. #define K_CLOB_ARGS_1 K_CLOB_ARGS_2, "%r25"
  88. #define K_CLOB_ARGS_0 K_CLOB_ARGS_1, "%r26"
  89. #endif /* __ASSEMBLER__ */
  90. #endif /* _BITS_SYSCALLS_H */