tls-macros-csky.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* Macros for accessing thread-local storage. C-SKY ABIV2 version.
  2. Copyright (C) 2018-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_LE(x) \
  15. ({ int *__result; \
  16. __asm__ ("lrw %0, " #x "@TPOFF\n\t" \
  17. "add %0, tls, %0" \
  18. : "=&r" (__result)); \
  19. __result; })
  20. # define TLS_IE(x) \
  21. ({ int *__result; \
  22. __asm__ ("grs a1, 1f\n" \
  23. "1:\tlrw %0, " #x "@GOTTPOFF\n\t" \
  24. "ldr.w %0, (a1, %0 << 0)\n\t" \
  25. "add %0, tls, %0" \
  26. : "=&r" (__result): : "a1"); \
  27. __result; })
  28. # define TLS_LD(x) \
  29. ({ char *__result; \
  30. int __offset; \
  31. extern void *__tls_get_addr (void *); \
  32. __asm__ ("grs a1, 1f\n" \
  33. "1:\tlrw %0, " #x "@TLSLDM32;\n\t" \
  34. "add %0, a1, %0" \
  35. : "=r" (__result) : : "a1"); \
  36. __result = (char *)__tls_get_addr (__result); \
  37. __asm__ ("lrw %0, " #x "@TLSLDO32" \
  38. : "=r" (__offset)); \
  39. (int *) (__result + __offset); })
  40. # define TLS_GD(x) \
  41. ({ int *__result; \
  42. extern void *__tls_get_addr (void *); \
  43. __asm__ ("grs a1, 1f\n" \
  44. "1:\tlrw %0, " #x "@TLSGD32\n\t" \
  45. "add %0, a1, %0" \
  46. : "=r" (__result) : : "a1"); \
  47. (int *)__tls_get_addr (__result); })