2005-12-05 Roland McGrath <roland@redhat.com>
[glibc.git] / sysdeps / mips / tls-macros.h
blob2d0516b3e4921d6b68883a6429d4a328599d25dd
1 /* Macros to support TLS testing in times of missing compiler support. */
3 #if _MIPS_SIM != _ABI64
5 /* These versions are for o32 and n32. */
7 # define TLS_GD(x) \
8 ({ void *__result; \
9 extern void *__tls_get_addr (void *); \
10 asm ("addiu %0, $28, %%tlsgd(" #x ")" \
11 : "=r" (__result)); \
12 (int *)__tls_get_addr (__result); })
13 #else
14 # define TLS_GD(x) \
15 ({ void *__result; \
16 extern void *__tls_get_addr (void *); \
17 asm ("daddiu %0, $28, %%tlsgd(" #x ")" \
18 : "=r" (__result)); \
19 (int *)__tls_get_addr (__result); })
20 #endif
22 #if _MIPS_SIM != _ABI64
23 # define TLS_LD(x) \
24 ({ void *__result; \
25 extern void *__tls_get_addr (void *); \
26 asm ("addiu %0, $28, %%tlsldm(" #x ")" \
27 : "=r" (__result)); \
28 __result = __tls_get_addr (__result); \
29 asm ("lui $3,%%dtprel_hi(" #x ")\n\t" \
30 "addiu $3,$3,%%dtprel_lo(" #x ")\n\t" \
31 "addu %0,%0,$3" \
32 : "+r" (__result) : : "$3"); \
33 __result; })
34 # define TLS_IE(x) \
35 ({ void *__result; \
36 asm (".set push\n\t.set mips32r2\n\t" \
37 "rdhwr\t%0,$29\n\t.set pop" \
38 : "=v" (__result)); \
39 asm ("lw $3,%%gottprel(" #x ")($28)\n\t" \
40 "addu %0,%0,$3" \
41 : "+r" (__result) : : "$3"); \
42 __result; })
43 # define TLS_LE(x) \
44 ({ void *__result; \
45 asm (".set push\n\t.set mips32r2\n\t" \
46 "rdhwr\t%0,$29\n\t.set pop" \
47 : "=v" (__result)); \
48 asm ("lui $3,%%tprel_hi(" #x ")\n\t" \
49 "addiu $3,$3,%%tprel_lo(" #x ")\n\t" \
50 "addu %0,%0,$3" \
51 : "+r" (__result) : : "$3"); \
52 __result; })
54 #else
56 /* These versions are for n64. */
58 # define TLS_LD(x) \
59 ({ void *__result; \
60 extern void *__tls_get_addr (void *); \
61 asm ("daddiu %0, $28, %%tlsldm(" #x ")" \
62 : "=r" (__result)); \
63 __result = __tls_get_addr (__result); \
64 asm ("lui $3,%%dtprel_hi(" #x ")\n\t" \
65 "daddiu $3,$3,%%dtprel_lo(" #x ")\n\t" \
66 "daddu %0,%0,$3" \
67 : "+r" (__result) : : "$3"); \
68 __result; })
69 # define TLS_IE(x) \
70 ({ void *__result; \
71 asm (".set push\n\t.set mips32r2\n\t" \
72 "rdhwr\t%0,$29\n\t.set pop" \
73 : "=v" (__result)); \
74 asm ("ld $3,%%gottprel(" #x ")($28)\n\t" \
75 "daddu %0,%0,$3" \
76 : "+r" (__result) : : "$3"); \
77 __result; })
78 # define TLS_LE(x) \
79 ({ void *__result; \
80 asm (".set push\n\t.set mips32r2\n\t" \
81 "rdhwr\t%0,$29\n\t.set pop" \
82 : "=v" (__result)); \
83 asm ("lui $3,%%tprel_hi(" #x ")\n\t" \
84 "daddiu $3,$3,%%tprel_lo(" #x ")\n\t" \
85 "daddu %0,%0,$3" \
86 : "+r" (__result) : : "$3"); \
87 __result; })
88 #endif