sysdep.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* Copyright (C) 1997-2017 Free Software Foundation, Inc.
  2. Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #ifndef _LINUX_SPARC64_SYSDEP_H
  15. #define _LINUX_SPARC64_SYSDEP_H 1
  16. #include <common/sysdep.h>
  17. #undef SYS_ify
  18. #define SYS_ify(syscall_name) __NR_##syscall_name
  19. #ifdef __ASSEMBLER__
  20. #define SPARC_PIC_THUNK(reg) \
  21. .ifndef __sparc_get_pc_thunk.reg; \
  22. .section .text.__sparc_get_pc_thunk.reg,"axG",@progbits,__sparc_get_pc_thunk.reg,comdat; \
  23. .align 32; \
  24. .weak __sparc_get_pc_thunk.reg; \
  25. .hidden __sparc_get_pc_thunk.reg; \
  26. .type __sparc_get_pc_thunk.reg, #function; \
  27. __sparc_get_pc_thunk.reg: \
  28. jmp %o7 + 8; \
  29. add %o7, %reg, %##reg; \
  30. .previous; \
  31. .endif;
  32. /* The "-4" and "+4" offsets against _GLOBAL_OFFSET_TABLE_ are
  33. critical since they represent the offset from the thunk call to the
  34. instruction containing the _GLOBAL_OFFSET_TABLE_ reference.
  35. Therefore these instructions cannot be moved around without
  36. appropriate adjustments to those offsets.
  37. Furthermore, these expressions are special in another regard. When
  38. the assembler sees a reference to _GLOBAL_OFFSET_TABLE_ inside of
  39. a %hi() or %lo(), it emits a PC-relative relocation. This causes
  40. R_SPARC_HI22 to turn into R_SPARC_PC22, and R_SPARC_LO10 to turn into
  41. R_SPARC_PC10, respectively.
  42. Even when v9 we use a call sequence instead of using "rd %pc" because
  43. RDPC is extremely expensive and incurs a full pipeline flush. */
  44. #define SPARC_PIC_THUNK_CALL(reg) \
  45. sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %##reg; \
  46. call __sparc_get_pc_thunk.reg; \
  47. or %##reg, %lo(_GLOBAL_OFFSET_TABLE_+4), %##reg;
  48. #define SETUP_PIC_REG(reg) \
  49. SPARC_PIC_THUNK(reg) \
  50. SPARC_PIC_THUNK_CALL(reg)
  51. #define SETUP_PIC_REG_LEAF(reg, tmp) \
  52. SPARC_PIC_THUNK(reg) \
  53. mov %o7, %##tmp; \
  54. SPARC_PIC_THUNK_CALL(reg); \
  55. mov %##tmp, %o7;
  56. #define LOADSYSCALL(x) mov __NR_##x, %g1
  57. #define ENTRY(name) \
  58. .align 4; \
  59. .global C_SYMBOL_NAME(name); \
  60. .type name, @function; \
  61. C_LABEL(name) \
  62. cfi_startproc;
  63. #undef END
  64. #define END(name) \
  65. cfi_endproc; \
  66. .size name, . - name
  67. #define ENTRY_NOCFI(name) \
  68. .align 4; \
  69. .global C_SYMBOL_NAME(name); \
  70. .type name, @function; \
  71. C_LABEL(name)
  72. #define END_NOCFI(name) \
  73. .size name, . - name
  74. #define LOC(name) .L##name
  75. #undef PSEUDO
  76. #define PSEUDO(name, syscall_name, args) \
  77. .text; \
  78. ENTRY(name); \
  79. LOADSYSCALL(syscall_name); \
  80. ta 0x6d; \
  81. bcc,pt %xcc, 1f; \
  82. nop; \
  83. SYSCALL_ERROR_HANDLER \
  84. 1:
  85. #undef PSEUDO_NOERRNO
  86. #define PSEUDO_NOERRNO(name, syscall_name, args)\
  87. .text; \
  88. ENTRY(name); \
  89. LOADSYSCALL(syscall_name); \
  90. ta 0x6d;
  91. #undef PSEUDO_ERRVAL
  92. #define PSEUDO_ERRVAL(name, syscall_name, args) \
  93. .text; \
  94. ENTRY(name); \
  95. LOADSYSCALL(syscall_name); \
  96. ta 0x6d;
  97. #undef PSEUDO_END
  98. #define PSEUDO_END(name) \
  99. END(name)
  100. #ifndef __PIC__
  101. # define SYSCALL_ERROR_HANDLER \
  102. mov %o7, %g1; \
  103. call __syscall_error; \
  104. mov %g1, %o7;
  105. #else
  106. # define SYSCALL_ERROR_HANDLER \
  107. 0: SETUP_PIC_REG_LEAF(o2,g1) \
  108. sethi %gdop_hix22(errno), %g1;\
  109. xor %g1, %gdop_lox10(errno), %g1;\
  110. ldx [%o2 + %g1], %g1, %gdop(errno);\
  111. st %o0, [%g1]; \
  112. jmp %o7 + 8; \
  113. mov -1, %o0;
  114. #endif /* PIC */
  115. #endif /* __ASSEMBLER__ */
  116. /* This is the offset from the %sp to the backing store above the
  117. register windows. So if you poke stack memory directly you add this. */
  118. #define STACK_BIAS 2047
  119. #endif