sysdep.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 LOC(name) .L##name
  68. #undef PSEUDO
  69. #define PSEUDO(name, syscall_name, args) \
  70. .text; \
  71. ENTRY(name); \
  72. LOADSYSCALL(syscall_name); \
  73. ta 0x6d; \
  74. bcc,pt %xcc, 1f; \
  75. nop; \
  76. SYSCALL_ERROR_HANDLER \
  77. 1:
  78. #undef PSEUDO_NOERRNO
  79. #define PSEUDO_NOERRNO(name, syscall_name, args)\
  80. .text; \
  81. ENTRY(name); \
  82. LOADSYSCALL(syscall_name); \
  83. ta 0x6d;
  84. #undef PSEUDO_ERRVAL
  85. #define PSEUDO_ERRVAL(name, syscall_name, args) \
  86. .text; \
  87. ENTRY(name); \
  88. LOADSYSCALL(syscall_name); \
  89. ta 0x6d;
  90. #undef PSEUDO_END
  91. #define PSEUDO_END(name) \
  92. END(name)
  93. #ifndef __PIC__
  94. # define SYSCALL_ERROR_HANDLER \
  95. mov %o7, %g1; \
  96. call __syscall_error; \
  97. mov %g1, %o7;
  98. #else
  99. # define SYSCALL_ERROR_HANDLER \
  100. 0: SETUP_PIC_REG_LEAF(o2,g1) \
  101. sethi %gdop_hix22(errno), %g1;\
  102. xor %g1, %gdop_lox10(errno), %g1;\
  103. ldx [%o2 + %g1], %g1, %gdop(errno);\
  104. st %o0, [%g1]; \
  105. jmp %o7 + 8; \
  106. mov -1, %o0;
  107. #endif /* PIC */
  108. #endif /* __ASSEMBLER__ */
  109. /* This is the offset from the %sp to the backing store above the
  110. register windows. So if you poke stack memory directly you add this. */
  111. #define STACK_BIAS 2047
  112. #endif