sysdep.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* Copyright (C) 2011-2018 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
  4. License as published by the Free Software Foundation; either
  5. version 2.1 of the 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. #include <common/sysdep.h>
  14. #include <bits/wordsize.h>
  15. #include <arch/abi.h>
  16. #undef SYS_ify
  17. #define SYS_ify(syscall_name) __NR_##syscall_name
  18. #if defined __ASSEMBLER__
  19. /* Make use of .size directive. */
  20. #define ASM_SIZE_DIRECTIVE(name) .size name,.-name;
  21. /* Define an entry point visible from C. */
  22. #define ENTRY(name) \
  23. .globl C_SYMBOL_NAME(name); \
  24. .type C_SYMBOL_NAME(name),@function; \
  25. .align 8; \
  26. C_LABEL(name) \
  27. cfi_startproc; \
  28. #undef END
  29. #define END(name) \
  30. cfi_endproc; \
  31. ASM_SIZE_DIRECTIVE(name)
  32. /* Since C identifiers are not normally prefixed with an underscore
  33. on this system, the asm identifier `syscall_error' intrudes on the
  34. C name space. Make sure we use an innocuous name. */
  35. #define syscall_error __syscall_error
  36. /* Local label name for asm code. */
  37. #define L(name) .L##name
  38. /* Specify the size in bytes of a machine register. */
  39. #define REGSIZE 8
  40. /* Provide "pointer-oriented" instruction variants. These differ not
  41. just for tilepro vs tilegx, but also for tilegx -m64 vs -m32. */
  42. #if __WORDSIZE == 32
  43. #define ADD_PTR addx
  44. #define ADDI_PTR addxi
  45. #define ADDLI_PTR addxli
  46. #define LD_PTR ld4s
  47. #define ST_PTR st4
  48. #define SHL_PTR_ADD shl2add
  49. #else
  50. #define ADD_PTR add
  51. #define ADDI_PTR addi
  52. #define ADDLI_PTR addli
  53. #define LD_PTR LD
  54. #define ST_PTR ST
  55. #define SHL_PTR_ADD shl3add
  56. #endif
  57. /* The actual implementation of doing a syscall. */
  58. #define DO_CALL(syscall_name, args) \
  59. moveli TREG_SYSCALL_NR_NAME, SYS_ify(syscall_name); \
  60. swint1
  61. /* TILE Linux returns the result in r0 (or a negative errno).
  62. The kernel "owns" the code to decide if a given value is an error,
  63. and puts errno in r1 if so, or otherwise zero. */
  64. #define PSEUDO(name, syscall_name, args) \
  65. ENTRY (name); \
  66. DO_CALL(syscall_name, args); \
  67. BNEZ r1, 0f
  68. #define ret jrp lr
  69. #ifndef SHARED
  70. /* For static code, on error jump to __syscall_error directly. */
  71. # define SYSCALL_ERROR_NAME __syscall_error
  72. #elif IS_IN_libc || IS_IN_libpthread
  73. /* Use the internal name for libc/libpthread shared objects. */
  74. # define SYSCALL_ERROR_NAME __GI___syscall_error
  75. #else
  76. /* Otherwise, on error do a full PLT jump. */
  77. # define SYSCALL_ERROR_NAME plt(__syscall_error)
  78. #endif
  79. #undef PSEUDO_END
  80. #define PSEUDO_END(name) \
  81. 0: \
  82. j SYSCALL_ERROR_NAME; \
  83. END (name)
  84. #undef PSEUDO_NOERRNO
  85. #define PSEUDO_NOERRNO(name, syscall_name, args) \
  86. ENTRY (name); \
  87. DO_CALL(syscall_name, args)
  88. #define ret_NOERRNO jrp lr
  89. #undef PSEUDO_END_NOERRNO
  90. #define PSEUDO_END_NOERRNO(name) \
  91. END (name)
  92. /* Convenience wrappers. */
  93. #define SYSCALL__(name, args) PSEUDO (__##name, name, args)
  94. #define SYSCALL(name, args) PSEUDO (name, name, args)
  95. #endif /* __ASSEMBLER__ */