tls-macros-riscv.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Macros to support TLS testing in times of missing compiler support.
  2. Copyright (C) 2017-2020 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <sys/cdefs.h>
  16. #include <sys/asm.h>
  17. #define TLS_GD(x) \
  18. ({ void *__result; \
  19. asm ("la.tls.gd %0, " #x "\n\t" \
  20. : "=r" (__result)); \
  21. __tls_get_addr (__result); })
  22. #define TLS_LD(x) TLS_GD(x)
  23. #define TLS_IE(x) \
  24. ({ void *__result; \
  25. asm ("la.tls.ie %0, " #x "\n\t" \
  26. "add %0, %0, tp\n\t" \
  27. : "=r" (__result)); \
  28. __result; })
  29. #define TLS_LE(x) \
  30. ({ void *__result; \
  31. asm ("lui %0, %%tprel_hi(" #x ")\n\t" \
  32. "add %0, %0, tp, %%tprel_add(" #x ")\n\t" \
  33. "addi %0, %0, %%tprel_lo(" #x ")\n\t" \
  34. : "=r" (__result)); \
  35. __result; })