tls-macros-riscv.h 1.9 KB

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