tls-macros-mips.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Macros to support TLS testing in times of missing compiler support. */
  2. #if _MIPS_SIM != _ABI64
  3. /* These versions are for o32 and n32. */
  4. # define TLS_GD(x) \
  5. ({ void *__result; \
  6. extern void *__tls_get_addr (void *); \
  7. __asm__ ("addiu %0, $28, %%tlsgd(" #x ")" \
  8. : "=r" (__result)); \
  9. (int *)__tls_get_addr (__result); })
  10. #else
  11. # define TLS_GD(x) \
  12. ({ void *__result; \
  13. extern void *__tls_get_addr (void *); \
  14. __asm__ ("daddiu %0, $28, %%tlsgd(" #x ")" \
  15. : "=r" (__result)); \
  16. (int *)__tls_get_addr (__result); })
  17. #endif
  18. #if _MIPS_SIM != _ABI64
  19. # define TLS_LD(x) \
  20. ({ void *__result; \
  21. extern void *__tls_get_addr (void *); \
  22. __asm__ ("addiu %0, $28, %%tlsldm(" #x ")" \
  23. : "=r" (__result)); \
  24. __result = __tls_get_addr (__result); \
  25. __asm__ ("lui $3,%%dtprel_hi(" #x ")\n\t" \
  26. "addiu $3,$3,%%dtprel_lo(" #x ")\n\t" \
  27. "addu %0,%0,$3" \
  28. : "+r" (__result) : : "$3"); \
  29. __result; })
  30. # define TLS_IE(x) \
  31. ({ void *__result; \
  32. __asm__ (".set push\n\t.set mips32r2\n\t" \
  33. "rdhwr\t%0,$29\n\t.set pop" \
  34. : "=v" (__result)); \
  35. __asm__ ("lw $3,%%gottprel(" #x ")($28)\n\t" \
  36. "addu %0,%0,$3" \
  37. : "+r" (__result) : : "$3"); \
  38. __result; })
  39. # define TLS_LE(x) \
  40. ({ void *__result; \
  41. __asm__ (".set push\n\t.set mips32r2\n\t" \
  42. "rdhwr\t%0,$29\n\t.set pop" \
  43. : "=v" (__result)); \
  44. __asm__ ("lui $3,%%tprel_hi(" #x ")\n\t" \
  45. "addiu $3,$3,%%tprel_lo(" #x ")\n\t" \
  46. "addu %0,%0,$3" \
  47. : "+r" (__result) : : "$3"); \
  48. __result; })
  49. #else
  50. /* These versions are for n64. */
  51. # define TLS_LD(x) \
  52. ({ void *__result; \
  53. extern void *__tls_get_addr (void *); \
  54. __asm__ ("daddiu %0, $28, %%tlsldm(" #x ")" \
  55. : "=r" (__result)); \
  56. __result = __tls_get_addr (__result); \
  57. __asm__ ("lui $3,%%dtprel_hi(" #x ")\n\t" \
  58. "daddiu $3,$3,%%dtprel_lo(" #x ")\n\t" \
  59. "daddu %0,%0,$3" \
  60. : "+r" (__result) : : "$3"); \
  61. __result; })
  62. # define TLS_IE(x) \
  63. ({ void *__result; \
  64. __asm__ (".set push\n\t.set mips32r2\n\t" \
  65. "rdhwr\t%0,$29\n\t.set pop" \
  66. : "=v" (__result)); \
  67. __asm__ ("ld $3,%%gottprel(" #x ")($28)\n\t" \
  68. "daddu %0,%0,$3" \
  69. : "+r" (__result) : : "$3"); \
  70. __result; })
  71. # define TLS_LE(x) \
  72. ({ void *__result; \
  73. __asm__ (".set push\n\t.set mips32r2\n\t" \
  74. "rdhwr\t%0,$29\n\t.set pop" \
  75. : "=v" (__result)); \
  76. __asm__ ("lui $3,%%tprel_hi(" #x ")\n\t" \
  77. "daddiu $3,$3,%%tprel_lo(" #x ")\n\t" \
  78. "daddu %0,%0,$3" \
  79. : "+r" (__result) : : "$3"); \
  80. __result; })
  81. #endif