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