1 /* Macros to support TLS testing in times of missing compiler support. */
6 #define __STRING2(X) __STRING(X)
7 #define ADDU __STRING2(PTR_ADDU)
8 #define ADDIU __STRING2(PTR_ADDIU)
9 #define LW __STRING2(PTR_L)
11 /* Load the GOT pointer, which may not be in $28 in a non-PIC
12 (abicalls pic0) function. */
14 # if _MIPS_SIM != _ABI64
16 # define LOAD_GP "move %[tmp], $28\n\tla $28, __gnu_local_gp\n\t"
19 "li %[tmp], %%hi(__gnu_local_gp)\n\t" \
20 "sll %[tmp], 16\n\t" \
21 "addiu %[tmp], %%lo(__gnu_local_gp)\n\t"
24 # define LOAD_GP "move %[tmp], $28\n\tdla $28, __gnu_local_gp\n\t"
26 # define UNLOAD_GP "\n\tmove $28, %[tmp]"
28 /* MIPS16 (re)creates the GP value using PC-relative instructions. */
31 "li %[tmp], %%hi(_gp_disp)\n\t" \
32 "addiu %0, $pc, %%lo(_gp_disp)\n\t" \
33 "sll %[tmp], 16\n\t" \
43 ({ void *__result, *__tmp; \
44 extern void *__tls_get_addr (void *); \
45 asm (LOAD_GP ADDIU " %0, $28, %%tlsgd(" #x ")" \
47 : "=r" (__result), [tmp] "=&r" (__tmp)); \
48 (int *)__tls_get_addr (__result); })
50 ({ void *__result, *__tmp; \
51 extern void *__tls_get_addr (void *); \
52 asm (LOAD_GP ADDIU " %0, $28, %%tlsldm(" #x ")" \
54 : "=r" (__result), [tmp] "=&r" (__tmp)); \
55 __result = __tls_get_addr (__result); \
56 asm ("lui $3,%%dtprel_hi(" #x ")\n\t" \
57 "addiu $3,$3,%%dtprel_lo(" #x ")\n\t" \
59 : "+r" (__result) : : "$3"); \
62 ({ void *__result, *__tmp; \
63 asm (".set push\n\t.set mips32r2\n\t" \
64 "rdhwr\t%0,$29\n\t.set pop" \
66 asm (LOAD_GP LW " $3,%%gottprel(" #x ")($28)\n\t" \
69 : "+r" (__result), [tmp] "=&r" (__tmp) \
74 asm (".set push\n\t.set mips32r2\n\t" \
75 "rdhwr\t%0,$29\n\t.set pop" \
77 asm ("lui $3,%%tprel_hi(" #x ")\n\t" \
78 "addiu $3,$3,%%tprel_lo(" #x ")\n\t" \
80 : "+r" (__result) : : "$3"); \
86 ({ void *__result, *__tmp; \
87 extern void *__tls_get_addr (void *); \
88 asm (LOAD_GP ADDIU " %1, %%tlsgd(" #x ")" \
90 : "=d" (__result), [tmp] "=&d" (__tmp)); \
91 (int *) __tls_get_addr (__result); })
93 ({ void *__result, *__tmp; \
94 extern void *__tls_get_addr (void *); \
95 asm (LOAD_GP ADDIU " %1, %%tlsldm(" #x ")" \
97 : "=d" (__result), [tmp] "=&d" (__tmp)); \
98 __result = __tls_get_addr (__result); \
99 asm ("li $3,%%dtprel_hi(" #x ")\n\t" \
101 "addiu $3,%%dtprel_lo(" #x ")\n\t" \
103 : "+d" (__result) : : "$3"); \
106 ({ void *__result, *__tmp, *__tp; \
107 __tp = __builtin_thread_pointer (); \
108 asm (LOAD_GP LW " $3,%%gottprel(" #x ")(%1)\n\t" \
109 ADDU " %0,%[tp],$3" \
110 : "=&d" (__result), [tmp] "=&d" (__tmp) \
111 : [tp] "d" (__tp) : "$3"); \
114 ({ void *__result, *__tp; \
115 __tp = __builtin_thread_pointer (); \
116 asm ("li $3,%%tprel_hi(" #x ")\n\t" \
118 "addiu $3,%%tprel_lo(" #x ")\n\t" \
119 ADDU " %0,%[tp],$3" \
120 : "=d" (__result) : [tp] "d" (__tp) : "$3"); \
123 #endif /* __mips16 */