1 /* Macros to support TLS testing in times of missing compiler support. */
7 #define __STRING2(X) __STRING(X)
8 #define ADDU __STRING2(PTR_ADDU)
9 #define ADDIU __STRING2(PTR_ADDIU)
10 #define LW __STRING2(PTR_L)
12 /* Load the GOT pointer, which may not be in $28 in a non-PIC
13 (abicalls pic0) function. */
15 # if _MIPS_SIM != _ABI64
17 # define LOAD_GP "move %[tmp], $28\n\tla $28, __gnu_local_gp\n\t"
20 "li %[tmp], %%hi(__gnu_local_gp)\n\t" \
21 "sll %[tmp], 16\n\t" \
22 "addiu %[tmp], %%lo(__gnu_local_gp)\n\t"
25 # define LOAD_GP "move %[tmp], $28\n\tdla $28, __gnu_local_gp\n\t"
27 # define UNLOAD_GP "\n\tmove $28, %[tmp]"
29 /* MIPS16 (re)creates the GP value using PC-relative instructions. */
32 "li %[tmp], %%hi(_gp_disp)\n\t" \
33 "addiu %0, $pc, %%lo(_gp_disp)\n\t" \
34 "sll %[tmp], 16\n\t" \
42 # if __mips_isa_rev >= 2
43 # define TLS_RDHWR "rdhwr\t%0,$29"
46 ".set push\n\t.set mips32r2\n\t" \
47 "rdhwr\t%0,$29\n\t.set pop"
52 ({ void *__result, *__tmp; \
53 extern void *__tls_get_addr (void *); \
54 asm (LOAD_GP ADDIU " %0, $28, %%tlsgd(" #x ")" \
56 : "=r" (__result), [tmp] "=&r" (__tmp)); \
57 (int *)__tls_get_addr (__result); })
59 ({ void *__result, *__tmp; \
60 extern void *__tls_get_addr (void *); \
61 asm (LOAD_GP ADDIU " %0, $28, %%tlsldm(" #x ")" \
63 : "=r" (__result), [tmp] "=&r" (__tmp)); \
64 __result = __tls_get_addr (__result); \
65 asm ("lui $3,%%dtprel_hi(" #x ")\n\t" \
66 "addiu $3,$3,%%dtprel_lo(" #x ")\n\t" \
68 : "+r" (__result) : : "$3"); \
71 ({ void *__result, *__tmp; \
74 asm (LOAD_GP LW " $3,%%gottprel(" #x ")($28)\n\t" \
77 : "+r" (__result), [tmp] "=&r" (__tmp) \
84 asm ("lui $3,%%tprel_hi(" #x ")\n\t" \
85 "addiu $3,$3,%%tprel_lo(" #x ")\n\t" \
87 : "+r" (__result) : : "$3"); \
93 ({ void *__result, *__tmp; \
94 extern void *__tls_get_addr (void *); \
95 asm (LOAD_GP ADDIU " %1, %%tlsgd(" #x ")" \
97 : "=d" (__result), [tmp] "=&d" (__tmp)); \
98 (int *) __tls_get_addr (__result); })
100 ({ void *__result, *__tmp; \
101 extern void *__tls_get_addr (void *); \
102 asm (LOAD_GP ADDIU " %1, %%tlsldm(" #x ")" \
104 : "=d" (__result), [tmp] "=&d" (__tmp)); \
105 __result = __tls_get_addr (__result); \
106 asm ("li $3,%%dtprel_hi(" #x ")\n\t" \
108 "addiu $3,%%dtprel_lo(" #x ")\n\t" \
110 : "+d" (__result) : : "$3"); \
113 ({ void *__result, *__tmp, *__tp; \
114 __tp = __builtin_thread_pointer (); \
115 asm (LOAD_GP LW " $3,%%gottprel(" #x ")(%1)\n\t" \
116 ADDU " %0,%[tp],$3" \
117 : "=&d" (__result), [tmp] "=&d" (__tmp) \
118 : [tp] "d" (__tp) : "$3"); \
121 ({ void *__result, *__tp; \
122 __tp = __builtin_thread_pointer (); \
123 asm ("li $3,%%tprel_hi(" #x ")\n\t" \
125 "addiu $3,%%tprel_lo(" #x ")\n\t" \
126 ADDU " %0,%[tp],$3" \
127 : "=d" (__result) : [tp] "d" (__tp) : "$3"); \
130 #endif /* __mips16 */