dl-tlsdesc.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Thread-local storage handling in the ELF dynamic linker. NDS32 version.
  2. Copyright (C) 2006-2013 Free Software Foundation, Inc.
  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. #include <sysdep.h>
  15. #if defined __UCLIBC_HAS_TLS__
  16. #include <tls.h>
  17. #include "tlsdesc.h"
  18. .text
  19. .hidden _dl_tlsdesc_return
  20. .global _dl_tlsdesc_return
  21. .type _dl_tlsdesc_return,#function
  22. cfi_startproc
  23. .align 2
  24. _dl_tlsdesc_return:
  25. lwi $r0, [$r0 + 4]
  26. add $r0, $r0, $r25
  27. ret
  28. cfi_endproc
  29. .size _dl_tlsdesc_return, .-_dl_tlsdesc_return
  30. #ifdef SHARED
  31. .hidden _dl_tlsdesc_dynamic
  32. .global _dl_tlsdesc_dynamic
  33. .type _dl_tlsdesc_dynamic,#function
  34. cfi_startproc
  35. .pic
  36. /*
  37. The assembly code that follows is a rendition of the following
  38. C code, hand-optimized a little bit.
  39. ptrdiff_t
  40. _dl_tlsdesc_dynamic(struct tlsdesc *tdp)
  41. {
  42. struct tlsdesc_dynamic_arg *td = tdp->argument.pointer;
  43. dtv_t *dtv = (dtv_t *)THREAD_DTV();
  44. if (__builtin_expect (td->gen_count <= dtv[0].counter
  45. && dtv[td->tlsinfo.ti_module].pointer.val
  46. != TLS_DTV_UNALLOCATED,
  47. 1))
  48. return dtv[td->tlsinfo.ti_module].pointer.val +
  49. td->tlsinfo.ti_offset - __builtin_thread_pointer();
  50. return __tls_get_addr (&td->tlsinfo) - __builtin_thread_pointer();
  51. }
  52. */
  53. .align 2
  54. _dl_tlsdesc_dynamic:
  55. lwi $r0, [$r0 + 4]
  56. lwi $r1, [$r0 + #TLSDESC_GEN_COUNT] /* $r0=td $r1=td->gen_count*/
  57. lwi $r2, [$r25 + #DTV_OFFSET] /* $r2=&dtv[0]*/
  58. lwi $r3, [$r2]
  59. sub $r1, $r1, $r3
  60. bgtz $r1, 2f
  61. lwi $r3, [$r0 + #TLSDESC_MODID] /* r3=module id */
  62. slli $r3, $r3, #3 /* r3=module offset=module id*8(byte) */
  63. lw $r3, [$r2 + $r3] /* r3=&dtc[module ID]=&dtv[0]+ module offset*/
  64. movi $r1, #-1
  65. beq $r3, $r1, 2f
  66. lwi $r1, [$r0 + #TLSDESC_MODOFF]
  67. add $r0, $r3, $r1
  68. 1:
  69. ret
  70. 2:
  71. smw.adm $sp,[$sp],$sp,#0x6
  72. cfi_adjust_cfa_offset(8)
  73. cfi_rel_offset(gp, 0)
  74. cfi_rel_offset(lp, 4)
  75. mfusr $r15, $PC;
  76. sethi $gp, hi20(_GLOBAL_OFFSET_TABLE_ + 4);
  77. ori $gp, $gp, lo12(_GLOBAL_OFFSET_TABLE_ + 8);
  78. add $gp, $r15, $gp;
  79. sethi $r15, hi20(__tls_get_addr@PLT);
  80. ori $r15, $r15, lo12(__tls_get_addr@PLT);
  81. add $r15, $r15, $gp
  82. jral $r15
  83. lmw.bim $sp,[$sp],$sp,#0x6
  84. cfi_adjust_cfa_offset(-8)
  85. cfi_restore(gp)
  86. cfi_restore(lp)
  87. j 1b
  88. cfi_endproc
  89. .size _dl_tlsdesc_dynamic, .-_dl_tlsdesc_dynamic
  90. #endif
  91. #endif // __UCLIBC_HAS_TLS__