syscalls.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. register unsigned long __res __asm__("r28"); \
  38. K_LOAD_ARGS_##nr(args) \
  39. /* FIXME: HACK stw/ldw r19 around syscall */ \
  40. __asm__ __volatile__( \
  41. K_STW_ASM_PIC \
  42. " ble 0x100(%%sr2, %%r0)\n" \
  43. " ldi %1, %%r20\n" \
  44. K_LDW_ASM_PIC \
  45. : "=r" (__res) \
  46. : "i" (name) K_ASM_ARGS_##nr \
  47. : "memory", K_CALL_CLOB_REGS K_CLOB_ARGS_##nr \
  48. ); \
  49. __res; \
  50. })
  51. #define K_LOAD_ARGS_0()
  52. #define K_LOAD_ARGS_1(r26) \
  53. register unsigned long __r26 __asm__("r26") = (unsigned long)(r26); \
  54. K_LOAD_ARGS_0()
  55. #define K_LOAD_ARGS_2(r26,r25) \
  56. register unsigned long __r25 __asm__("r25") = (unsigned long)(r25); \
  57. K_LOAD_ARGS_1(r26)
  58. #define K_LOAD_ARGS_3(r26,r25,r24) \
  59. register unsigned long __r24 __asm__("r24") = (unsigned long)(r24); \
  60. K_LOAD_ARGS_2(r26,r25)
  61. #define K_LOAD_ARGS_4(r26,r25,r24,r23) \
  62. register unsigned long __r23 __asm__("r23") = (unsigned long)(r23); \
  63. K_LOAD_ARGS_3(r26,r25,r24)
  64. #define K_LOAD_ARGS_5(r26,r25,r24,r23,r22) \
  65. register unsigned long __r22 __asm__("r22") = (unsigned long)(r22); \
  66. K_LOAD_ARGS_4(r26,r25,r24,r23)
  67. #define K_LOAD_ARGS_6(r26,r25,r24,r23,r22,r21) \
  68. register unsigned long __r21 __asm__("r21") = (unsigned long)(r21); \
  69. K_LOAD_ARGS_5(r26,r25,r24,r23,r22)
  70. /* Even with zero args we use r20 for the syscall number */
  71. #define K_ASM_ARGS_0
  72. #define K_ASM_ARGS_1 K_ASM_ARGS_0, "r" (__r26)
  73. #define K_ASM_ARGS_2 K_ASM_ARGS_1, "r" (__r25)
  74. #define K_ASM_ARGS_3 K_ASM_ARGS_2, "r" (__r24)
  75. #define K_ASM_ARGS_4 K_ASM_ARGS_3, "r" (__r23)
  76. #define K_ASM_ARGS_5 K_ASM_ARGS_4, "r" (__r22)
  77. #define K_ASM_ARGS_6 K_ASM_ARGS_5, "r" (__r21)
  78. /* The registers not listed as inputs but clobbered */
  79. #define K_CLOB_ARGS_6
  80. #define K_CLOB_ARGS_5 K_CLOB_ARGS_6, "%r21"
  81. #define K_CLOB_ARGS_4 K_CLOB_ARGS_5, "%r22"
  82. #define K_CLOB_ARGS_3 K_CLOB_ARGS_4, "%r23"
  83. #define K_CLOB_ARGS_2 K_CLOB_ARGS_3, "%r24"
  84. #define K_CLOB_ARGS_1 K_CLOB_ARGS_2, "%r25"
  85. #define K_CLOB_ARGS_0 K_CLOB_ARGS_1, "%r26"
  86. #endif /* __ASSEMBLER__ */
  87. #endif /* _BITS_SYSCALLS_H */