tls-macros-xtensa.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #if defined(__XTENSA_WINDOWED_ABI__)
  2. #define TLS_GD(x) \
  3. ({ int *__l; \
  4. __asm__ ("movi a8, " #x "@TLSFUNC\n\t" \
  5. "movi a10, " #x "@TLSARG\n\t" \
  6. "callx8.tls a8, " #x "@TLSCALL\n\t" \
  7. "mov %0, a10\n\t" \
  8. : "=r" (__l) \
  9. : \
  10. : "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15"); \
  11. __l; })
  12. #define TLS_LD(x) \
  13. ({ int *__l; \
  14. __asm__ ("movi a8, _TLS_MODULE_BASE_@TLSFUNC\n\t" \
  15. "movi a10, _TLS_MODULE_BASE_@TLSARG\n\t" \
  16. "callx8.tls a8, _TLS_MODULE_BASE_@TLSCALL\n\t" \
  17. "movi %0, " #x "@DTPOFF\n\t" \
  18. "add %0, %0, a10\n\t" \
  19. : "=r" (__l) \
  20. : \
  21. : "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15"); \
  22. __l; })
  23. #elif defined(__XTENSA_CALL0_ABI__)
  24. #ifdef __FDPIC__
  25. #define TLS_GD(x) \
  26. ({ int *__l; \
  27. int __t; \
  28. extern unsigned long _GLOBAL_OFFSET_TABLE_[]; \
  29. __asm__ ("movi %[tmp], " #x "@GOTTLSDESC\n\t" \
  30. ".reloc ., R_XTENSA_TLS_ARG, " #x "\n\t" \
  31. "add a2, %[tmp], %[got]\n\t" \
  32. ".reloc ., R_XTENSA_TLS_FUNCDESC, " #x "\n\t" \
  33. "l32i %[tmp], a2, 0\n\t" \
  34. "mov a12, a11\n\t" \
  35. ".reloc ., R_XTENSA_TLS_GOT, " #x "\n\t" \
  36. "l32i a11, %[tmp], 4\n\t" \
  37. ".reloc ., R_XTENSA_TLS_FUNC, " #x "\n\t" \
  38. "_l32i %[tmp], %[tmp], 0\n\t" \
  39. ".reloc ., R_XTENSA_TLS_CALL, " #x "\n\t" \
  40. "callx0 %[tmp]\n\t" \
  41. "mov a11, a12\n\t" \
  42. "mov %[res], a2\n\t" \
  43. : [res] "=r" (__l), [tmp] "=&r" (__t) \
  44. : [got] "r" (_GLOBAL_OFFSET_TABLE_) \
  45. : "a0", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a12");\
  46. __l; })
  47. #define TLS_LD(x) \
  48. ({ int *__l; \
  49. int __t; \
  50. extern unsigned long _GLOBAL_OFFSET_TABLE_[]; \
  51. __asm__ ("movi %[tmp], _TLS_MODULE_BASE_@GOTTLSDESC\n\t" \
  52. ".reloc ., R_XTENSA_TLS_ARG, _TLS_MODULE_BASE_\n\t" \
  53. "add a2, %[tmp], %[got]\n\t" \
  54. ".reloc ., R_XTENSA_TLS_FUNCDESC, _TLS_MODULE_BASE_\n\t"\
  55. "l32i %[tmp], a2, 0\n\t" \
  56. "mov a12, a11\n\t" \
  57. ".reloc ., R_XTENSA_TLS_GOT, _TLS_MODULE_BASE_\n\t" \
  58. "l32i a11, %[tmp], 4\n\t" \
  59. ".reloc ., R_XTENSA_TLS_FUNC, _TLS_MODULE_BASE_\n\t" \
  60. "_l32i %[tmp], %[tmp], 0\n\t" \
  61. ".reloc ., R_XTENSA_TLS_CALL, _TLS_MODULE_BASE_\n\t" \
  62. "callx0 %[tmp]\n\t" \
  63. "mov a11, a12\n\t" \
  64. "movi %[res], " #x "@DTPOFF\n\t" \
  65. "add %[res], %[res], a2\n\t" \
  66. : [res] "=r" (__l), [tmp] "=&r" (__t) \
  67. : [got] "r" (_GLOBAL_OFFSET_TABLE_) \
  68. : "a0", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a12");\
  69. __l; })
  70. #define TLS_IE(x) \
  71. ({ int *__l; \
  72. int __t; \
  73. extern unsigned long _GLOBAL_OFFSET_TABLE_[]; \
  74. __asm__ ("movi %[tmp], " #x "@GOTTPOFF\n\t" \
  75. ".reloc ., R_XTENSA_TLS_TPOFF_PTR, " #x "\n\t" \
  76. "add %[tmp], %[tmp], %[got]\n\t" \
  77. ".reloc ., R_XTENSA_TLS_TPOFF_LOAD, " #x "\n\t" \
  78. "l32i %[tmp], %[tmp], 0\n\t" \
  79. "rur %[res], threadptr\n\t" \
  80. "add %[res], %[res], %[tmp]\n\t" \
  81. : [res] "=r" (__l), [tmp] "=&r" (__t) \
  82. : [got] "r" (_GLOBAL_OFFSET_TABLE_)); \
  83. __l; })
  84. #define TLS_LE(x) \
  85. ({ int *__l; \
  86. int __t; \
  87. __asm__ ("rur %0, threadptr\n\t" \
  88. "movi %1, " #x "@TPOFF\n\t" \
  89. "add %0, %0, %1\n\t" \
  90. : "=r" (__l), "=r" (__t) ); \
  91. __l; })
  92. #else
  93. #define TLS_GD(x) \
  94. ({ int *__l; \
  95. __asm__ ("movi a0, " #x "@TLSFUNC\n\t" \
  96. "movi a2, " #x "@TLSARG\n\t" \
  97. "callx0.tls a0, " #x "@TLSCALL\n\t" \
  98. "mov %0, a2\n\t" \
  99. : "=r" (__l) \
  100. : \
  101. : "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11");\
  102. __l; })
  103. #define TLS_LD(x) \
  104. ({ int *__l; \
  105. __asm__ ("movi a0, _TLS_MODULE_BASE_@TLSFUNC\n\t" \
  106. "movi a2, _TLS_MODULE_BASE_@TLSARG\n\t" \
  107. "callx0.tls a0, _TLS_MODULE_BASE_@TLSCALL\n\t" \
  108. "movi %0, " #x "@DTPOFF\n\t" \
  109. "add %0, %0, a2\n\t" \
  110. : "=r" (__l) \
  111. : \
  112. : "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11");\
  113. __l; })
  114. #endif
  115. #else
  116. #error Unsupported Xtensa ABI
  117. #endif
  118. #ifndef __FDPIC__
  119. #define TLS_IE(x) TLS_LE(x)
  120. #define TLS_LE(x) \
  121. ({ int *__l; \
  122. int __t; \
  123. __asm__ ("rur %0, threadptr\n\t" \
  124. "movi %1, " #x "@TPOFF\n\t" \
  125. "add %0, %0, %1\n\t" \
  126. : "=r" (__l), "=r" (__t) ); \
  127. __l; })
  128. #endif