dl-tlsdesc.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #include <tls.h>
  17. #include "tlsdesc.h"
  18. .text
  19. .align 4
  20. .hidden _dl_tlsdesc_return
  21. .global _dl_tlsdesc_return
  22. .type _dl_tlsdesc_return, @function
  23. _dl_tlsdesc_return:
  24. entry a1, 16
  25. rur.threadptr a3
  26. add a2, a2, a3
  27. retw
  28. .size _dl_tlsdesc_return, .-_dl_tlsdesc_return
  29. #ifdef SHARED
  30. /* This function is used for symbols that need dynamic TLS.
  31. The argument passed to this function points to the TLS descriptor.
  32. The assembly code that follows is a rendition of the following
  33. C code, hand-optimized a little bit.
  34. ptrdiff_t
  35. _dl_tlsdesc_dynamic(struct tlsdesc_dynamic_arg *td)
  36. {
  37. dtv_t *dtv = (dtv_t *)THREAD_DTV();
  38. if (td->gen_count <= dtv[0].counter
  39. && dtv[td->tlsinfo.ti_module].pointer.val
  40. != TLS_DTV_UNALLOCATED)
  41. return dtv[td->tlsinfo.ti_module].pointer.val
  42. + td->tlsinfo.ti_offset - __builtin_thread_pointer();
  43. return __tls_get_addr (&td->tlsinfo) - __builtin_thread_pointer();
  44. }
  45. */
  46. .align 4
  47. .hidden _dl_tlsdesc_dynamic
  48. .global _dl_tlsdesc_dynamic
  49. .type _dl_tlsdesc_dynamic, @function
  50. _dl_tlsdesc_dynamic:
  51. entry a1, 32
  52. /* dtv_t *dtv = (dtv_t *)THREAD_DTV(); */
  53. rur.threadptr a3
  54. l32i a4, a3, 0
  55. /* if (td->gen_count <= dtv[0].counter */
  56. l32i a6, a2, TLSDESC_GEN_COUNT
  57. l32i a7, a4, 0
  58. blt a7, a6, .Lslow
  59. /* && dtv[td->tlsinfo.ti_module].pointer.val != TLS_DTV_UNALLOCATED) */
  60. l32i a6, a2, TLSDESC_MODID
  61. addx8 a6, a3, a6
  62. l32i a6, a6, 0
  63. beqi a6, -1, .Lslow
  64. /* return dtv[td->tlsinfo.ti_module].pointer.val
  65. + td->tlsinfo.ti_offset - __builtin_thread_pointer(); */
  66. l32i a6, a2, TLSDESC_MODOFF
  67. sub a2, a6, a3
  68. retw
  69. /* return __tls_get_addr (&td->tlsinfo) - __builtin_thread_pointer(); */
  70. .Lslow:
  71. mov a10, a2
  72. movi a8, __tls_get_addr
  73. callx8 a8
  74. sub a2, a10, a3
  75. retw
  76. .size _dl_tlsdesc_dynamic, .-_dl_tlsdesc_dynamic
  77. #endif /* SHARED */