sysdep.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* Copyright (C) 2005-2016 Free Software Foundation, Inc.
  2. The GNU C Library is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU Lesser General Public License as
  4. published by the Free Software Foundation; either version 2.1 of the
  5. License, or (at your option) any later version.
  6. The GNU C Library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Lesser General Public License for more details.
  10. You should have received a copy of the GNU Lesser General Public
  11. License along with the GNU C Library; if not, see
  12. <http://www.gnu.org/licenses/>. */
  13. #ifndef _LINUX_AARCH64_SYSDEP_H
  14. #define _LINUX_AARCH64_SYSDEP_H 1
  15. #include <common/sysdep.h>
  16. #include <sys/syscall.h>
  17. /* In order to get __set_errno() definition in INLINE_SYSCALL. */
  18. #ifndef __ASSEMBLER__
  19. #include <errno.h>
  20. #endif
  21. /* For Linux we can use the system call table in the header file
  22. /usr/include/asm/unistd.h
  23. of the kernel. But these symbols do not follow the SYS_* syntax
  24. so we have to redefine the `SYS_ify' macro here. */
  25. #undef SYS_ify
  26. #define SYS_ify(syscall_name) (__NR_##syscall_name)
  27. #ifdef __ASSEMBLER__
  28. #define ASM_SIZE_DIRECTIVE(name) .size name,.-name
  29. /* Local label name for asm code. */
  30. #ifndef L
  31. # define L(name) .L##name
  32. #endif
  33. /* Define an entry point visible from C. */
  34. #define ENTRY(name) \
  35. .globl C_SYMBOL_NAME(name); \
  36. .type C_SYMBOL_NAME(name),%function; \
  37. .align 4; \
  38. C_LABEL(name) \
  39. cfi_startproc;
  40. /* Define an entry point visible from C. */
  41. #define ENTRY_ALIGN(name, align) \
  42. .globl C_SYMBOL_NAME(name); \
  43. .type C_SYMBOL_NAME(name),%function; \
  44. .p2align align; \
  45. C_LABEL(name) \
  46. cfi_startproc;
  47. #undef END
  48. #define END(name) \
  49. cfi_endproc; \
  50. ASM_SIZE_DIRECTIVE(name)
  51. /* Linux uses a negative return value to indicate syscall errors,
  52. unlike most Unices, which use the condition codes' carry flag.
  53. Since version 2.1 the return value of a system call might be
  54. negative even if the call succeeded. E.g., the `lseek' system call
  55. might return a large offset. Therefore we must not anymore test
  56. for < 0, but test for a real error by making sure the value in R0
  57. is a real error number. Linus said he will make sure the no syscall
  58. returns a value in -1 .. -4095 as a valid result so we can safely
  59. test with -4095. */
  60. # undef PSEUDO
  61. # define PSEUDO(name, syscall_name, args) \
  62. .text; \
  63. ENTRY (name); \
  64. DO_CALL (syscall_name, args); \
  65. cmn x0, #4095; \
  66. b.cs .Lsyscall_error;
  67. # undef PSEUDO_END
  68. # define PSEUDO_END(name) \
  69. SYSCALL_ERROR_HANDLER \
  70. END (name)
  71. # undef PSEUDO_NOERRNO
  72. # define PSEUDO_NOERRNO(name, syscall_name, args) \
  73. .text; \
  74. ENTRY (name); \
  75. DO_CALL (syscall_name, args);
  76. # undef PSEUDO_END_NOERRNO
  77. # define PSEUDO_END_NOERRNO(name) \
  78. END (name)
  79. # define ret_NOERRNO ret
  80. /* The function has to return the error code. */
  81. # undef PSEUDO_ERRVAL
  82. # define PSEUDO_ERRVAL(name, syscall_name, args) \
  83. .text; \
  84. ENTRY (name) \
  85. DO_CALL (syscall_name, args); \
  86. neg x0, x0
  87. # undef PSEUDO_END_ERRVAL
  88. # define PSEUDO_END_ERRVAL(name) \
  89. END (name)
  90. # define ret_ERRVAL ret
  91. #if defined _LIBC_REENTRANT
  92. # if defined USE___THREAD
  93. # define SYSCALL_ERROR_ERRNO errno
  94. # endif
  95. #endif
  96. #if defined USE___THREAD
  97. # define SYSCALL_ERROR .Lsyscall_error
  98. # define SYSCALL_ERROR_HANDLER \
  99. .Lsyscall_error: \
  100. adrp x1, :gottprel:SYSCALL_ERROR_ERRNO; \
  101. neg w2, w0; \
  102. ldr x1, [x1, :gottprel_lo12:SYSCALL_ERROR_ERRNO]; \
  103. mrs x3, tpidr_el0; \
  104. mov x0, -1; \
  105. str w2, [x1, x3]; \
  106. ret;
  107. #else
  108. # define SYSCALL_ERROR __syscall_error
  109. # define SYSCALL_ERROR_HANDLER \
  110. .Lsyscall_error: \
  111. b __syscall_error;
  112. #endif
  113. # undef DO_CALL
  114. # define DO_CALL(syscall_name, args) \
  115. mov x8, SYS_ify (syscall_name); \
  116. svc 0
  117. #endif /* __ASSEMBLER__ */
  118. #endif /* linux/aarch64/sysdep.h */