tls-macros-riscv.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. asm ("la.tls.gd %0, " #x "\n\t" \
  17. : "=r" (__result)); \
  18. __tls_get_addr (__result); })
  19. #define TLS_LD(x) TLS_GD(x)
  20. #define TLS_IE(x) \
  21. ({ void *__result; \
  22. asm ("la.tls.ie %0, " #x "\n\t" \
  23. "add %0, %0, tp\n\t" \
  24. : "=r" (__result)); \
  25. __result; })
  26. #define TLS_LE(x) \
  27. ({ void *__result; \
  28. asm ("lui %0, %%tprel_hi(" #x ")\n\t" \
  29. "add %0, %0, tp, %%tprel_add(" #x ")\n\t" \
  30. "addi %0, %0, %%tprel_lo(" #x ")\n\t" \
  31. : "=r" (__result)); \
  32. __result; })