tls-macros-riscv.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* Macros to support TLS testing in times of missing compiler support.
  2. Copyright (C) 2017-2020 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. <https://www.gnu.org/licenses/>. */
  14. #define TLS_GD(x) \
  15. ({ void *__result; \
  16. extern void *__tls_get_addr (void *); \
  17. asm ("la.tls.gd %0, " #x "\n\t" \
  18. : "=r" (__result)); \
  19. __tls_get_addr (__result); })
  20. #define TLS_LD(x) TLS_GD(x)
  21. #define TLS_IE(x) \
  22. ({ void *__result; \
  23. asm ("la.tls.ie %0, " #x "\n\t" \
  24. "add %0, %0, tp\n\t" \
  25. : "=r" (__result)); \
  26. __result; })
  27. #define TLS_LE(x) \
  28. ({ void *__result; \
  29. asm ("lui %0, %%tprel_hi(" #x ")\n\t" \
  30. "add %0, %0, tp, %%tprel_add(" #x ")\n\t" \
  31. "addi %0, %0, %%tprel_lo(" #x ")\n\t" \
  32. : "=r" (__result)); \
  33. __result; })