tls-macros-mips.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Macros to support TLS testing in times of missing compiler support. */
  2. #include <sys/cdefs.h>
  3. #include <sys/asm.h>
  4. #define __STRING2(X) __STRING(X)
  5. #define ADDU __STRING2(PTR_ADDU)
  6. #define ADDIU __STRING2(PTR_ADDIU)
  7. #define LW __STRING2(PTR_L)
  8. /* Load the GOT pointer, which may not be in $28 in a non-PIC
  9. (abicalls pic0) function. */
  10. #ifndef __PIC__
  11. # if _MIPS_SIM != _ABI64
  12. # define LOAD_GP "move %[tmp], $28\n\tla $28, __gnu_local_gp\n\t"
  13. # else
  14. # define LOAD_GP "move %[tmp], $28\n\tdla $28, __gnu_local_gp\n\t"
  15. # endif
  16. # define UNLOAD_GP "\n\tmove $28, %[tmp]"
  17. #else
  18. # define LOAD_GP
  19. # define UNLOAD_GP
  20. #endif
  21. # define TLS_GD(x) \
  22. ({ void *__result, *__tmp; \
  23. extern void *__tls_get_addr (void *); \
  24. __asm__ (LOAD_GP ADDIU " %0, $28, %%tlsgd(" #x ")" \
  25. UNLOAD_GP \
  26. : "=r" (__result), [tmp] "=&r" (__tmp)); \
  27. (int *)__tls_get_addr (__result); })
  28. # define TLS_LD(x) \
  29. ({ void *__result, *__tmp; \
  30. extern void *__tls_get_addr (void *); \
  31. __asm__ (LOAD_GP ADDIU " %0, $28, %%tlsldm(" #x ")" \
  32. UNLOAD_GP \
  33. : "=r" (__result), [tmp] "=&r" (__tmp)); \
  34. __result = __tls_get_addr (__result); \
  35. __asm__ ("lui $3,%%dtprel_hi(" #x ")\n\t" \
  36. "addiu $3,$3,%%dtprel_lo(" #x ")\n\t" \
  37. ADDU " %0,%0,$3" \
  38. : "+r" (__result) : : "$3"); \
  39. __result; })
  40. # define TLS_IE(x) \
  41. ({ void *__result, *__tmp; \
  42. __asm__ (".set push\n\t.set mips32r2\n\t" \
  43. "rdhwr\t%0,$29\n\t.set pop" \
  44. : "=v" (__result)); \
  45. __asm__ (LOAD_GP LW " $3,%%gottprel(" #x ")($28)\n\t" \
  46. ADDU " %0,%0,$3" \
  47. UNLOAD_GP \
  48. : "+r" (__result), [tmp] "=&r" (__tmp) \
  49. : : "$3"); \
  50. __result; })
  51. # define TLS_LE(x) \
  52. ({ void *__result; \
  53. __asm__ (".set push\n\t.set mips32r2\n\t" \
  54. "rdhwr\t%0,$29\n\t.set pop" \
  55. : "=v" (__result)); \
  56. __asm__ ("lui $3,%%tprel_hi(" #x ")\n\t" \
  57. "addiu $3,$3,%%tprel_lo(" #x ")\n\t" \
  58. ADDU " %0,%0,$3" \
  59. : "+r" (__result) : : "$3"); \
  60. __result; })