dl-tlsdesc.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. rur.threadptr a3
  22. add a2, a2, a3
  23. abi_ret
  24. END (_dl_tlsdesc_return)
  25. #ifdef SHARED
  26. /* This function is used for symbols that need dynamic TLS.
  27. The argument passed to this function points to the TLS descriptor.
  28. The assembly code that follows is a rendition of the following
  29. C code, hand-optimized a little bit.
  30. void *
  31. _dl_tlsdesc_dynamic(struct tlsdesc_dynamic_arg *td)
  32. {
  33. dtv_t *dtv = (dtv_t *)THREAD_DTV();
  34. if (td->gen_count <= dtv[0].counter
  35. && dtv[td->tlsinfo.ti_module].pointer.val
  36. != TLS_DTV_UNALLOCATED)
  37. return dtv[td->tlsinfo.ti_module].pointer.val
  38. + td->tlsinfo.ti_offset;
  39. return __tls_get_addr (&td->tlsinfo);
  40. }
  41. */
  42. HIDDEN_ENTRY (_dl_tlsdesc_dynamic)
  43. /* dtv_t *dtv = (dtv_t *)THREAD_DTV(); */
  44. rur.threadptr a3
  45. l32i a4, a3, 0
  46. /* if (td->gen_count <= dtv[0].counter */
  47. l32i a6, a2, TLSDESC_GEN_COUNT
  48. l32i a7, a4, 0
  49. blt a7, a6, .Lslow
  50. /* && dtv[td->tlsinfo.ti_module].pointer.val != TLS_DTV_UNALLOCATED) */
  51. l32i a6, a2, TLSDESC_MODID
  52. addx8 a6, a6, a4
  53. l32i a6, a6, 0
  54. beqi a6, -1, .Lslow
  55. /* return dtv[td->tlsinfo.ti_module].pointer.val
  56. + td->tlsinfo.ti_offset; */
  57. l32i a5, a2, TLSDESC_MODOFF
  58. add a2, a6, a5
  59. abi_ret
  60. /* return __tls_get_addr (&td->tlsinfo); */
  61. .Lslow:
  62. #if defined(__XTENSA_WINDOWED_ABI__)
  63. mov a6, a2
  64. movi a4, __tls_get_addr
  65. callx4 a4
  66. mov a2, a6
  67. retw
  68. #elif defined(__XTENSA_CALL0_ABI__)
  69. addi a1, a1, -16
  70. s32i a0, a1, 0
  71. movi a0, __tls_get_addr
  72. callx0 a0
  73. l32i a0, a1, 0
  74. addi a1, a1, 16
  75. ret
  76. #else
  77. #error Unsupported Xtensa ABI
  78. #endif
  79. END (_dl_tlsdesc_dynamic)
  80. #endif /* SHARED */
  81. #endif