Update.
[glibc.git] / elf / tls-macros.h
blob1f9cf4448a8c479cf57b7b698c5cf96422b20bd7
1 /* Macros to support TLS testing in times of missing compiler support. */
3 #define COMMON_INT_DEF(x) \
4 asm (".tls_common " #x ",4,4")
5 /* XXX Until we get compiler support we don't need declarations. */
6 #define COMMON_INT_DECL(x)
8 /* XXX This definition will probably be machine specific, too. */
9 #define VAR_INT_DEF(x) \
10 asm (".section .tdata\n\t" \
11 ".globl " #x "\n" \
12 #x ":\t.long 0\n\t" \
13 ".size " #x ",4\n\t" \
14 ".previous")
15 /* XXX Until we get compiler support we don't need declarations. */
16 #define VAR_INT_DECL(x)
19 /* XXX Each architecture must have its own asm for now. */
20 #ifdef __i386__
21 # define TLS_LE(x) \
22 ({ int *__l; \
23 asm ("movl %%gs:0,%0\n\t" \
24 "subl $" #x "@tpoff,%0" \
25 : "=r" (__l)); \
26 __l; })
28 # ifdef PIC
29 # define TLS_IE(x) \
30 ({ int *__l; \
31 asm ("movl %%gs:0,%0\n\t" \
32 "subl " #x "@gottpoff(%%ebx),%0" \
33 : "=r" (__l)); \
34 __l; })
35 # else
36 # define TLS_IE(x) \
37 ({ int *__l, __b; \
38 asm ("call 1f\n\t" \
39 ".subsection 1\n" \
40 "1:\tmovl (%%esp), %%ebx\n\t" \
41 "ret\n\t" \
42 ".previous\n\t" \
43 "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t" \
44 "movl %%gs:0,%0\n\t" \
45 "subl " #x "@gottpoff(%%ebx),%0" \
46 : "=r" (__l), "=&b" (__b)); \
47 __l; })
48 # endif
50 # ifdef PIC
51 # define TLS_LD(x) \
52 ({ int *__l, __c, __d; \
53 asm ("leal " #x "@tlsldm(%%ebx),%%eax\n\t" \
54 "call ___tls_get_addr@plt\n\t" \
55 "leal " #x "@dtpoff(%%eax), %%eax" \
56 : "=a" (__l), "=&c" (__c), "=&d" (__d)); \
57 __l; })
58 # else
59 # define TLS_LD(x) \
60 ({ int *__l, __b, __c, __d; \
61 asm ("call 1f\n\t" \
62 ".subsection 1\n" \
63 "1:\tmovl (%%esp), %%ebx\n\t" \
64 "ret\n\t" \
65 ".previous\n\t" \
66 "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t" \
67 "leal " #x "@tlsldm(%%ebx),%%eax\n\t" \
68 "call ___tls_get_addr@plt\n\t" \
69 "leal " #x "@dtpoff(%%eax), %%eax" \
70 : "=a" (__l), "=&b" (__b), "=&c" (__c), "=&d" (__d)); \
71 __l; })
72 # endif
74 # ifdef PIC
75 # define TLS_GD(x) \
76 ({ int *__l, __c, __d; \
77 asm ("leal " #x "@tlsgd(%%ebx),%%eax\n\t" \
78 "call ___tls_get_addr@plt\n\t" \
79 "nop" \
80 : "=a" (__l), "=&c" (__c), "=&d" (__d)); \
81 __l; })
82 # else
83 # define TLS_GD(x) \
84 ({ int *__l, __b, __c, __d; \
85 asm ("call 1f\n\t" \
86 ".subsection 1\n" \
87 "1:\tmovl (%%esp), %%ebx\n\t" \
88 "ret\n\t" \
89 ".previous\n\t" \
90 "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t" \
91 "leal " #x "@tlsgd(%%ebx),%%eax\n\t" \
92 "call ___tls_get_addr@plt\n\t" \
93 "nop" \
94 : "=a" (__l), "=&b" (__b), "=&c" (__c), "=&d" (__d)); \
95 __l; })
96 # endif
98 #elif defined __x86_64__
100 # define TLS_LE(x) \
101 ({ int *__l; \
102 asm ("movq %%fs:0,%0\n\t" \
103 "leaq " #x "@tpoff(%0), %0" \
104 : "=r" (__l)); \
105 __l; })
107 # define TLS_IE(x) \
108 ({ int *__l; \
109 asm ("movq %%fs:0,%0\n\t" \
110 "addq " #x "@gottpoff(%%rip),%0" \
111 : "=r" (__l)); \
112 __l; })
114 # define TLS_LD(x) \
115 ({ int *__l, __c, __d; \
116 asm ("leaq " #x "@tlsld(%%rip),%%rdi\n\t" \
117 "call __tls_get_addr@plt\n\t" \
118 "leaq " #x "@dtpoff(%%rax), %%rax" \
119 : "=a" (__l), "=&c" (__c), "=&d" (__d) \
120 : : "rdi", "rsi", "r8", "r9", "r10", "r11"); \
121 __l; })
123 # define TLS_GD(x) \
124 ({ int *__l, __c, __d; \
125 asm (".long 0x66666666\n\t" \
126 "leaq " #x "@tlsgd(%%rip),%%rdi\n\t" \
127 "call __tls_get_addr@plt" \
128 : "=a" (__l), "=&c" (__c), "=&d" (__d) \
129 : : "rdi", "rsi", "r8", "r9", "r10", "r11"); \
130 __l; })
132 #elif defined __sh__
134 # define TLS_LE(x) \
135 ({ int *__l; void *__tp; \
136 asm ("stc gbr,%1\n\t" \
137 "mov.l 1f,%0\n\t" \
138 "bra 2f\n\t" \
139 " add %1,%0\n\t" \
140 ".align 2\n\t" \
141 "1: .long " #x "@tpoff\n\t" \
142 "2:" \
143 : "=r" (__l), "=r" (__tp)); \
144 __l; })
146 # define TLS_IE(x) \
147 ({ int *__l; void *__tp; \
148 asm ("mova 0f,r0\n\t" \
149 "mov.l 0f,r12\n\t" \
150 "add r0,r12\n\t" \
151 "mov.l 1f,r0\n\t" \
152 "stc gbr,%1\n\t" \
153 "mov.l @(r0,r12),%0\n\t" \
154 "bra 2f\n\t" \
155 " add %1,%0\n\t" \
156 ".align 2\n\t" \
157 "0: .long _GLOBAL_OFFSET_TABLE_\n\t" \
158 "1: .long " #x "@gottpoff\n\t" \
159 "2:" \
160 : "=r" (__l), "=r" (__tp) : : "r0", "r12"); \
161 __l; })
163 # define TLS_LD(x) \
164 ({ int *__l; \
165 asm ("mova 0f,r0\n\t" \
166 "mov.l 0f,r12\n\t" \
167 "add r0,r12\n\t" \
168 "mov.l 1f,r4\n\t" \
169 "mova 2f,r0\n\t" \
170 "mov.l 2f,r1\n\t" \
171 "add r0,r1\n\t" \
172 "jsr @r1\n\t" \
173 " add r12,r4\n\t" \
174 "mov.l 3f,%0\n\t" \
175 "bra 4f\n\t" \
176 " add r0,%0\n\t" \
177 ".align 2\n\t" \
178 "0: .long _GLOBAL_OFFSET_TABLE_\n\t" \
179 "1: .long " #x "@tlsldm\n\t" \
180 "2: .long __tls_get_addr@plt\n\t" \
181 "3: .long " #x "@dtpoff\n\t" \
182 "4:" \
183 : "=r" (__l) : : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
184 "r12", "pr", "t"); \
185 __l; })
187 # define TLS_GD(x) \
188 ({ int *__l; \
189 asm ("mova 0f,r0\n\t" \
190 "mov.l 0f,r12\n\t" \
191 "add r0,r12\n\t" \
192 "mov.l 1f,r4\n\t" \
193 "mova 2f,r0\n\t" \
194 "mov.l 2f,r1\n\t" \
195 "add r0,r1\n\t" \
196 "jsr @r1\n\t" \
197 " add r12,r4\n\t" \
198 "bra 3f\n\t" \
199 " mov r0,%0\n\t" \
200 ".align 2\n\t" \
201 "0: .long _GLOBAL_OFFSET_TABLE_\n\t" \
202 "1: .long " #x "@tlsgd\n\t" \
203 "2: .long __tls_get_addr@plt\n\t" \
204 "3:" \
205 : "=r" (__l) : : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
206 "r12", "pr", "t"); \
207 __l; })
209 #else
210 # error "No support for this architecture so far."
211 #endif