Fix features.h for -Wundef (bug 19212).
[glibc.git] / sysdeps / mips / tls-macros.h
bloba6fdfbc0ad29255c5253bd83bf087284af3665dc
1 /* Macros to support TLS testing in times of missing compiler support. */
3 #include <sys/cdefs.h>
4 #include <sys/asm.h>
5 #include <sysdep.h>
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. */
14 #ifndef __PIC__
15 # if _MIPS_SIM != _ABI64
16 # ifndef __mips16
17 # define LOAD_GP "move %[tmp], $28\n\tla $28, __gnu_local_gp\n\t"
18 # else
19 # define LOAD_GP \
20 "li %[tmp], %%hi(__gnu_local_gp)\n\t" \
21 "sll %[tmp], 16\n\t" \
22 "addiu %[tmp], %%lo(__gnu_local_gp)\n\t"
23 # endif
24 # else
25 # define LOAD_GP "move %[tmp], $28\n\tdla $28, __gnu_local_gp\n\t"
26 # endif
27 # define UNLOAD_GP "\n\tmove $28, %[tmp]"
28 #else
29 /* MIPS16 (re)creates the GP value using PC-relative instructions. */
30 # ifdef __mips16
31 # define LOAD_GP \
32 "li %[tmp], %%hi(_gp_disp)\n\t" \
33 "addiu %0, $pc, %%lo(_gp_disp)\n\t" \
34 "sll %[tmp], 16\n\t" \
35 "addu %[tmp], %0\n\t"
36 # else
37 # define LOAD_GP
38 # endif
39 # define UNLOAD_GP
40 #endif
42 # if __mips_isa_rev >= 2
43 # define TLS_RDHWR "rdhwr\t%0,$29"
44 # else
45 # define TLS_RDHWR \
46 ".set push\n\t.set mips32r2\n\t" \
47 "rdhwr\t%0,$29\n\t.set pop"
48 #endif
50 #ifndef __mips16
51 # define TLS_GD(x) \
52 ({ void *__result, *__tmp; \
53 extern void *__tls_get_addr (void *); \
54 asm (LOAD_GP ADDIU " %0, $28, %%tlsgd(" #x ")" \
55 UNLOAD_GP \
56 : "=r" (__result), [tmp] "=&r" (__tmp)); \
57 (int *)__tls_get_addr (__result); })
58 # define TLS_LD(x) \
59 ({ void *__result, *__tmp; \
60 extern void *__tls_get_addr (void *); \
61 asm (LOAD_GP ADDIU " %0, $28, %%tlsldm(" #x ")" \
62 UNLOAD_GP \
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" \
67 ADDU " %0,%0,$3" \
68 : "+r" (__result) : : "$3"); \
69 __result; })
70 # define TLS_IE(x) \
71 ({ void *__result, *__tmp; \
72 asm (TLS_RDHWR \
73 : "=v" (__result)); \
74 asm (LOAD_GP LW " $3,%%gottprel(" #x ")($28)\n\t" \
75 ADDU " %0,%0,$3" \
76 UNLOAD_GP \
77 : "+r" (__result), [tmp] "=&r" (__tmp) \
78 : : "$3"); \
79 __result; })
80 # define TLS_LE(x) \
81 ({ void *__result; \
82 asm (TLS_RDHWR \
83 : "=v" (__result)); \
84 asm ("lui $3,%%tprel_hi(" #x ")\n\t" \
85 "addiu $3,$3,%%tprel_lo(" #x ")\n\t" \
86 ADDU " %0,%0,$3" \
87 : "+r" (__result) : : "$3"); \
88 __result; })
90 #else /* __mips16 */
91 /* MIPS16 version. */
92 # define TLS_GD(x) \
93 ({ void *__result, *__tmp; \
94 extern void *__tls_get_addr (void *); \
95 asm (LOAD_GP ADDIU " %1, %%tlsgd(" #x ")" \
96 "\n\tmove %0, %1" \
97 : "=d" (__result), [tmp] "=&d" (__tmp)); \
98 (int *) __tls_get_addr (__result); })
99 # define TLS_LD(x) \
100 ({ void *__result, *__tmp; \
101 extern void *__tls_get_addr (void *); \
102 asm (LOAD_GP ADDIU " %1, %%tlsldm(" #x ")" \
103 "\n\tmove %0, %1" \
104 : "=d" (__result), [tmp] "=&d" (__tmp)); \
105 __result = __tls_get_addr (__result); \
106 asm ("li $3,%%dtprel_hi(" #x ")\n\t" \
107 "sll $3,16\n\t" \
108 "addiu $3,%%dtprel_lo(" #x ")\n\t" \
109 ADDU " %0,%0,$3" \
110 : "+d" (__result) : : "$3"); \
111 __result; })
112 # define TLS_IE(x) \
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"); \
119 __result; })
120 # define TLS_LE(x) \
121 ({ void *__result, *__tp; \
122 __tp = __builtin_thread_pointer (); \
123 asm ("li $3,%%tprel_hi(" #x ")\n\t" \
124 "sll $3,16\n\t" \
125 "addiu $3,%%tprel_lo(" #x ")\n\t" \
126 ADDU " %0,%[tp],$3" \
127 : "=d" (__result) : [tp] "d" (__tp) : "$3"); \
128 __result; })
130 #endif /* __mips16 */