dl-tlsdesc.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* Thread-local storage handling in the ELF dynamic linker. Xtensa version.
  2. Copyright (C) 2012-2013 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library. If not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <sysdep.h>
  16. #if defined __UCLIBC_HAS_TLS__
  17. #include <tls.h>
  18. #include "tlsdesc.h"
  19. .text
  20. HIDDEN_ENTRY (_dl_tlsdesc_return)
  21. #ifdef __FDPIC__
  22. l32i a2, a2, 4
  23. #endif
  24. rur.threadptr a3
  25. add a2, a2, a3
  26. abi_ret
  27. END (_dl_tlsdesc_return)
  28. #ifdef SHARED
  29. /* This function is used for symbols that need dynamic TLS.
  30. The argument passed to this function points to the TLS descriptor.
  31. The assembly code that follows is a rendition of the following
  32. C code, hand-optimized a little bit.
  33. void *
  34. _dl_tlsdesc_dynamic(struct tlsdesc_dynamic_arg *td)
  35. {
  36. dtv_t *dtv = (dtv_t *)THREAD_DTV();
  37. if (td->gen_count <= dtv[0].counter
  38. && dtv[td->tlsinfo.ti_module].pointer.val
  39. != TLS_DTV_UNALLOCATED)
  40. return dtv[td->tlsinfo.ti_module].pointer.val
  41. + td->tlsinfo.ti_offset;
  42. return __tls_get_addr (&td->tlsinfo);
  43. }
  44. */
  45. HIDDEN_ENTRY (_dl_tlsdesc_dynamic)
  46. #ifdef __FDPIC__
  47. l32i a2, a2, 4
  48. #endif
  49. /* dtv_t *dtv = (dtv_t *)THREAD_DTV(); */
  50. rur.threadptr a3
  51. l32i a4, a3, 0
  52. /* if (td->gen_count <= dtv[0].counter */
  53. l32i a6, a2, TLSDESC_GEN_COUNT
  54. l32i a7, a4, 0
  55. blt a7, a6, .Lslow
  56. /* && dtv[td->tlsinfo.ti_module].pointer.val != TLS_DTV_UNALLOCATED) */
  57. l32i a6, a2, TLSDESC_MODID
  58. addx8 a6, a6, a4
  59. l32i a6, a6, 0
  60. beqi a6, -1, .Lslow
  61. /* return dtv[td->tlsinfo.ti_module].pointer.val
  62. + td->tlsinfo.ti_offset; */
  63. l32i a5, a2, TLSDESC_MODOFF
  64. add a2, a6, a5
  65. abi_ret
  66. /* return __tls_get_addr (&td->tlsinfo); */
  67. .Lslow:
  68. #if defined(__XTENSA_WINDOWED_ABI__)
  69. mov a6, a2
  70. movi a4, __tls_get_addr
  71. callx4 a4
  72. mov a2, a6
  73. retw
  74. #elif defined(__XTENSA_CALL0_ABI__)
  75. addi a1, a1, -16
  76. s32i a0, a1, 0
  77. movi a0, JUMPTARGET(__tls_get_addr)
  78. FDPIC_LOAD_JUMPTARGET(a0, a11, a0)
  79. callx0 a0
  80. l32i a0, a1, 0
  81. addi a1, a1, 16
  82. ret
  83. #else
  84. #error Unsupported Xtensa ABI
  85. #endif
  86. END (_dl_tlsdesc_dynamic)
  87. #endif /* SHARED */
  88. #endif