tls-macros-nios2.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #define TLS_LE(x) \
  2. ({ int *__result; \
  3. asm ("addi %0, r23, %%tls_le(" #x ")" \
  4. : "=r" (__result)); \
  5. __result; })
  6. #define TLS_IE(x) \
  7. ({ int *__result; \
  8. int __tmp; \
  9. asm ("nextpc %0 ; " \
  10. "1: movhi %1, %%hiadj(_gp_got - 1b) ; " \
  11. "addi %1, %1, %%lo(_gp_got - 1b) ; " \
  12. "add %0, %0, %1 ; " \
  13. "ldw %1, %%tls_ie(" #x ")(%0) ; " \
  14. "add %1, r23, %1" \
  15. : "=&r" (__tmp), "=&r" (__result)); \
  16. __result; })
  17. #define TLS_LD(x) \
  18. ({ char *__result; \
  19. char *__result2; \
  20. int *__result3; \
  21. int __tmp; \
  22. extern void *__tls_get_addr (void *); \
  23. asm ("nextpc %0 ; " \
  24. "1: movhi %1, %%hiadj(_gp_got - 1b) ; " \
  25. "addi %1, %1, %%lo(_gp_got - 1b) ; " \
  26. "add %0, %0, %1 ; " \
  27. "addi %0, %0, %%tls_ldm(" #x ")" \
  28. : "=r" (__result), "=r" (__tmp)); \
  29. __result2 = (char *)__tls_get_addr (__result); \
  30. asm ("addi %0, %1, %%tls_ldo(" #x ")" \
  31. : "=r" (__result3) : "r" (__result2)); \
  32. __result3; })
  33. #define TLS_GD(x) \
  34. ({ int *__result; \
  35. int __tmp; \
  36. extern void *__tls_get_addr (void *); \
  37. asm ("nextpc %0 ; " \
  38. "1: movhi %1, %%hiadj(_gp_got - 1b) ; " \
  39. "addi %1, %1, %%lo(_gp_got - 1b) ; " \
  40. "add %0, %0, %1 ; " \
  41. "addi %0, %0, %%tls_gd(" #x ")" \
  42. : "=r" (__result), "=r" (__tmp)); \
  43. (int *)__tls_get_addr (__result); })