[BZ #681]
[glibc.git] / elf / tls-macros.h
blobbed2e148994af8990e9e38c88a01bfbdbb92964b
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 ".balign 4\n" \
13 #x ":\t.long 0\n\t" \
14 ".size " #x ",4\n\t" \
15 ".previous")
16 /* XXX Until we get compiler support we don't need declarations. */
17 #define VAR_INT_DECL(x)
20 /* XXX Each architecture must have its own asm for now. */
21 #ifdef __i386__
22 # define TLS_LE(x) \
23 ({ int *__l; \
24 asm ("movl %%gs:0,%0\n\t" \
25 "subl $" #x "@tpoff,%0" \
26 : "=r" (__l)); \
27 __l; })
29 # ifdef PIC
30 # define TLS_IE(x) \
31 ({ int *__l; \
32 asm ("movl %%gs:0,%0\n\t" \
33 "subl " #x "@gottpoff(%%ebx),%0" \
34 : "=r" (__l)); \
35 __l; })
36 # else
37 # define TLS_IE(x) \
38 ({ int *__l, __b; \
39 asm ("call 1f\n\t" \
40 ".subsection 1\n" \
41 "1:\tmovl (%%esp), %%ebx\n\t" \
42 "ret\n\t" \
43 ".previous\n\t" \
44 "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t" \
45 "movl %%gs:0,%0\n\t" \
46 "subl " #x "@gottpoff(%%ebx),%0" \
47 : "=r" (__l), "=&b" (__b)); \
48 __l; })
49 # endif
51 # ifdef PIC
52 # define TLS_LD(x) \
53 ({ int *__l, __c, __d; \
54 asm ("leal " #x "@tlsldm(%%ebx),%%eax\n\t" \
55 "call ___tls_get_addr@plt\n\t" \
56 "leal " #x "@dtpoff(%%eax), %%eax" \
57 : "=a" (__l), "=&c" (__c), "=&d" (__d)); \
58 __l; })
59 # else
60 # define TLS_LD(x) \
61 ({ int *__l, __b, __c, __d; \
62 asm ("call 1f\n\t" \
63 ".subsection 1\n" \
64 "1:\tmovl (%%esp), %%ebx\n\t" \
65 "ret\n\t" \
66 ".previous\n\t" \
67 "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t" \
68 "leal " #x "@tlsldm(%%ebx),%%eax\n\t" \
69 "call ___tls_get_addr@plt\n\t" \
70 "leal " #x "@dtpoff(%%eax), %%eax" \
71 : "=a" (__l), "=&b" (__b), "=&c" (__c), "=&d" (__d)); \
72 __l; })
73 # endif
75 # ifdef PIC
76 # define TLS_GD(x) \
77 ({ int *__l, __c, __d; \
78 asm ("leal " #x "@tlsgd(%%ebx),%%eax\n\t" \
79 "call ___tls_get_addr@plt\n\t" \
80 "nop" \
81 : "=a" (__l), "=&c" (__c), "=&d" (__d)); \
82 __l; })
83 # else
84 # define TLS_GD(x) \
85 ({ int *__l, __b, __c, __d; \
86 asm ("call 1f\n\t" \
87 ".subsection 1\n" \
88 "1:\tmovl (%%esp), %%ebx\n\t" \
89 "ret\n\t" \
90 ".previous\n\t" \
91 "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t" \
92 "leal " #x "@tlsgd(%%ebx),%%eax\n\t" \
93 "call ___tls_get_addr@plt\n\t" \
94 "nop" \
95 : "=a" (__l), "=&b" (__b), "=&c" (__c), "=&d" (__d)); \
96 __l; })
97 # endif
99 #elif defined __x86_64__
101 # define TLS_LE(x) \
102 ({ int *__l; \
103 asm ("movq %%fs:0,%0\n\t" \
104 "leaq " #x "@tpoff(%0), %0" \
105 : "=r" (__l)); \
106 __l; })
108 # define TLS_IE(x) \
109 ({ int *__l; \
110 asm ("movq %%fs:0,%0\n\t" \
111 "addq " #x "@gottpoff(%%rip),%0" \
112 : "=r" (__l)); \
113 __l; })
115 # define TLS_LD(x) \
116 ({ int *__l, __c, __d; \
117 asm ("leaq " #x "@tlsld(%%rip),%%rdi\n\t" \
118 "call __tls_get_addr@plt\n\t" \
119 "leaq " #x "@dtpoff(%%rax), %%rax" \
120 : "=a" (__l), "=&c" (__c), "=&d" (__d) \
121 : : "rdi", "rsi", "r8", "r9", "r10", "r11"); \
122 __l; })
124 # define TLS_GD(x) \
125 ({ int *__l, __c, __d; \
126 asm (".byte 0x66\n\t" \
127 "leaq " #x "@tlsgd(%%rip),%%rdi\n\t" \
128 ".word 0x6666\n\t" \
129 "rex64\n\t" \
130 "call __tls_get_addr@plt" \
131 : "=a" (__l), "=&c" (__c), "=&d" (__d) \
132 : : "rdi", "rsi", "r8", "r9", "r10", "r11"); \
133 __l; })
135 #elif defined __sh__
137 # define TLS_LE(x) \
138 ({ int *__l; void *__tp; \
139 asm ("stc gbr,%1\n\t" \
140 "mov.l 1f,%0\n\t" \
141 "bra 2f\n\t" \
142 " add %1,%0\n\t" \
143 ".align 2\n\t" \
144 "1: .long " #x "@tpoff\n\t" \
145 "2:" \
146 : "=r" (__l), "=r" (__tp)); \
147 __l; })
149 # ifdef PIC
150 # define TLS_IE(x) \
151 ({ int *__l; void *__tp; \
152 register void *__gp __asm__("r12"); \
153 asm ("mov.l 1f,r0\n\t" \
154 "stc gbr,%1\n\t" \
155 "mov.l @(r0,r12),%0\n\t" \
156 "bra 2f\n\t" \
157 " add %1,%0\n\t" \
158 ".align 2\n\t" \
159 "1: .long " #x "@gottpoff\n\t" \
160 "2:" \
161 : "=r" (__l), "=r" (__tp) : "r" (__gp) : "r0"); \
162 __l; })
163 # else
164 # define TLS_IE(x) \
165 ({ int *__l; void *__tp; \
166 asm ("mov.l r12,@-r15\n\t" \
167 "mova 0f,r0\n\t" \
168 "mov.l 0f,r12\n\t" \
169 "add r0,r12\n\t" \
170 "mov.l 1f,r0\n\t" \
171 "stc gbr,%1\n\t" \
172 "mov.l @(r0,r12),%0\n\t" \
173 "bra 2f\n\t" \
174 " add %1,%0\n\t" \
175 ".align 2\n\t" \
176 "1: .long " #x "@gottpoff\n\t" \
177 "0: .long _GLOBAL_OFFSET_TABLE_\n\t" \
178 "2: mov.l @r15+,r12" \
179 : "=r" (__l), "=r" (__tp) : : "r0"); \
180 __l; })
181 #endif
183 # ifdef PIC
184 # define TLS_LD(x) \
185 ({ int *__l; \
186 register void *__gp __asm__("r12"); \
187 asm ("mov.l 1f,r4\n\t" \
188 "mova 2f,r0\n\t" \
189 "mov.l 2f,r1\n\t" \
190 "add r0,r1\n\t" \
191 "jsr @r1\n\t" \
192 " add r12,r4\n\t" \
193 "bra 4f\n\t" \
194 " nop\n\t" \
195 ".align 2\n\t" \
196 "1: .long " #x "@tlsldm\n\t" \
197 "2: .long __tls_get_addr@plt\n\t" \
198 "4: mov.l 3f,%0\n\t" \
199 "bra 5f\n\t" \
200 " add r0,%0\n\t" \
201 ".align 2\n\t" \
202 "3: .long " #x "@dtpoff\n\t" \
203 "5:" \
204 : "=r" (__l) : "r" (__gp) : "r0", "r1", "r2", "r3", "r4", "r5", \
205 "r6", "r7", "pr", "t"); \
206 __l; })
207 # else
208 # define TLS_LD(x) \
209 ({ int *__l; \
210 asm ("mov.l r12,@-r15\n\t" \
211 "mova 0f,r0\n\t" \
212 "mov.l 0f,r12\n\t" \
213 "add r0,r12\n\t" \
214 "mov.l 1f,r4\n\t" \
215 "mova 2f,r0\n\t" \
216 "mov.l 2f,r1\n\t" \
217 "add r0,r1\n\t" \
218 "jsr @r1\n\t" \
219 " add r12,r4\n\t" \
220 "bra 4f\n\t" \
221 " nop\n\t" \
222 ".align 2\n\t" \
223 "1: .long " #x "@tlsldm\n\t" \
224 "2: .long __tls_get_addr@plt\n\t" \
225 "0: .long _GLOBAL_OFFSET_TABLE_\n\t" \
226 "4: mov.l 3f,%0\n\t" \
227 "bra 5f\n\t" \
228 " add r0,%0\n\t" \
229 ".align 2\n\t" \
230 "3: .long " #x "@dtpoff\n\t" \
231 "5: mov.l @r15+,r12" \
232 : "=r" (__l) : : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
233 "pr", "t"); \
234 __l; })
235 #endif
237 # ifdef PIC
238 # define TLS_GD(x) \
239 ({ int *__l; \
240 register void *__gp __asm__("r12"); \
241 asm ("mov.l 1f,r4\n\t" \
242 "mova 2f,r0\n\t" \
243 "mov.l 2f,r1\n\t" \
244 "add r0,r1\n\t" \
245 "jsr @r1\n\t" \
246 " add r12,r4\n\t" \
247 "bra 3f\n\t" \
248 " mov r0,%0\n\t" \
249 ".align 2\n\t" \
250 "1: .long " #x "@tlsgd\n\t" \
251 "2: .long __tls_get_addr@plt\n\t" \
252 "3:" \
253 : "=r" (__l) : "r" (__gp) : "r0", "r1", "r2", "r3", "r4", "r5", \
254 "r6", "r7", "pr", "t"); \
255 __l; })
256 # else
257 # define TLS_GD(x) \
258 ({ int *__l; \
259 asm ("mov.l r12,@-r15\n\t" \
260 "mova 0f,r0\n\t" \
261 "mov.l 0f,r12\n\t" \
262 "add r0,r12\n\t" \
263 "mov.l 1f,r4\n\t" \
264 "mova 2f,r0\n\t" \
265 "mov.l 2f,r1\n\t" \
266 "add r0,r1\n\t" \
267 "jsr @r1\n\t" \
268 " add r12,r4\n\t" \
269 "bra 3f\n\t" \
270 " mov r0,%0\n\t" \
271 ".align 2\n\t" \
272 "1: .long " #x "@tlsgd\n\t" \
273 "2: .long __tls_get_addr@plt\n\t" \
274 "0: .long _GLOBAL_OFFSET_TABLE_\n\t" \
275 "3: mov.l @r15+,r12" \
276 : "=r" (__l) : : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
277 "pr", "t"); \
278 __l; })
279 #endif
281 #elif defined __alpha__
283 register void *__gp __asm__("$29");
285 # define TLS_LE(x) \
286 ({ int *__l; \
287 asm ("call_pal 158\n\tlda $0," #x "($0)\t\t!tprel" : "=v"(__l)); \
288 __l; })
290 # define TLS_IE(x) \
291 ({ char *__tp; unsigned long __o; \
292 asm ("call_pal 158\n\tldq %1," #x "($gp)\t\t!gottprel" \
293 : "=v"(__tp), "=r"(__o) : "r"(__gp)); \
294 (int *)(__tp + __o); })
296 # define TLS_LD(x) \
297 ({ extern void *__tls_get_addr(void *); int *__l; void *__i; \
298 asm ("lda %0," #x "($gp)\t\t!tlsldm" : "=r" (__i) : "r"(__gp)); \
299 __i = __tls_get_addr(__i); \
300 asm ("lda %0, " #x "(%1)\t\t!dtprel" : "=r"(__l) : "r"(__i)); \
301 __l; })
303 # define TLS_GD(x) \
304 ({ extern void *__tls_get_addr(void *); void *__i; \
305 asm ("lda %0," #x "($gp)\t\t!tlsgd" : "=r" (__i) : "r"(__gp)); \
306 (int *) __tls_get_addr(__i); })
309 #elif defined __ia64__
311 # define TLS_LE(x) \
312 ({ void *__l; \
313 asm ("mov r2=r13\n\t" \
314 ";;\n\t" \
315 "addl %0=@tprel(" #x "),r2\n\t" \
316 : "=r" (__l) : : "r2" ); __l; })
318 # define TLS_IE(x) \
319 ({ void *__l; \
320 register long __gp asm ("gp"); \
321 asm (";;\n\t" \
322 "addl r16=@ltoff(@tprel(" #x ")),gp\n\t" \
323 ";;\n\t" \
324 "ld8 r17=[r16]\n\t" \
325 ";;\n\t" \
326 "add %0=r13,r17\n\t" \
327 ";;\n\t" \
328 : "=r" (__l) : "r" (__gp) : "r16", "r17" ); __l; })
330 # define __TLS_CALL_CLOBBERS \
331 "r2", "r3", "r8", "r9", "r10", "r11", "r14", "r15", "r16", "r17", \
332 "r18", "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", \
333 "r27", "r28", "r29", "r30", "r31", \
334 "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", \
335 "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
336 "b6", "b7", \
337 "out0", "out1", "out2", "out3", "out4", "out5", "out6", "out7"
339 # define TLS_LD(x) \
340 ({ void *__l; \
341 register long __gp asm ("gp"); \
342 asm (";;\n\t" \
343 "mov loc0=gp\n\t" \
344 "addl r16=@ltoff(@dtpmod(" #x ")),gp\n\t" \
345 "addl out1=@dtprel(" #x "),r0\n\t" \
346 ";;\n\t" \
347 "ld8 out0=[r16]\n\t" \
348 "br.call.sptk.many b0=__tls_get_addr" \
349 ";;\n\t" \
350 "mov gp=loc0\n\t" \
351 "mov %0=r8\n\t" \
352 ";;\n\t" \
353 : "=r" (__l) : "r" (__gp) : "loc0", __TLS_CALL_CLOBBERS); \
354 __l; })
356 # define TLS_GD(x) \
357 ({ void *__l; \
358 register long __gp asm ("gp"); \
359 asm (";;\n\t" \
360 "mov loc0=gp\n\t" \
361 "addl r16=@ltoff(@dtpmod(" #x ")),gp\n\t" \
362 "addl r17=@ltoff(@dtprel(" #x ")),gp\n\t" \
363 ";;\n\t" \
364 "ld8 out0=[r16]\n\t" \
365 "ld8 out1=[r17]\n\t" \
366 "br.call.sptk.many b0=__tls_get_addr" \
367 ";;\n\t" \
368 "mov gp=loc0\n\t" \
369 "mov %0=r8\n\t" \
370 ";;\n\t" \
371 : "=r" (__l) : "r" (__gp) : "loc0", __TLS_CALL_CLOBBERS); \
372 __l; })
374 #elif defined __sparc__ && !defined __arch64__
376 # define TLS_LE(x) \
377 ({ int *__l; \
378 asm ("sethi %%tle_hix22(" #x "), %0" : "=r" (__l)); \
379 asm ("xor %1, %%tle_lox10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
380 asm ("add %%g7, %1, %0" : "=r" (__l) : "r" (__l)); \
381 __l; })
383 # ifdef __PIC__
384 # define TLS_LOAD_PIC \
385 ({ register long pc __asm__ ("%o7"); \
386 long got; \
387 asm ("sethi %%hi(_GLOBAL_OFFSET_TABLE_-4), %1\n\t" \
388 "call .+8\n\t" \
389 "add %1, %%lo(_GLOBAL_OFFSET_TABLE_+4), %1\n\t" \
390 "add %1, %0, %1\n\t" \
391 : "=r" (pc), "=r" (got)); \
392 got; })
393 # else
394 # define TLS_LOAD_PIC \
395 ({ long got; \
396 asm (".hidden _GLOBAL_OFFSET_TABLE_\n\t" \
397 "sethi %%hi(_GLOBAL_OFFSET_TABLE_), %0\n\t" \
398 "or %0, %%lo(_GLOBAL_OFFSET_TABLE_), %0" \
399 : "=r" (got)); \
400 got; })
401 # endif
403 # define TLS_IE(x) \
404 ({ int *__l; \
405 asm ("sethi %%tie_hi22(" #x "), %0" : "=r" (__l)); \
406 asm ("add %1, %%tie_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
407 asm ("ld [%1 + %2], %0, %%tie_ld(" #x ")" \
408 : "=r" (__l) : "r" (TLS_LOAD_PIC), "r" (__l)); \
409 asm ("add %%g7, %1, %0, %%tie_add(" #x ")" : "=r" (__l) : "r" (__l)); \
410 __l; })
412 # define TLS_LD(x) \
413 ({ int *__l; register void *__o0 asm ("%o0"); \
414 long __o; \
415 asm ("sethi %%tldm_hi22(" #x "), %0" : "=r" (__l)); \
416 asm ("add %1, %%tldm_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
417 asm ("add %1, %2, %0, %%tldm_add(" #x ")" \
418 : "=r" (__o0) : "r" (TLS_LOAD_PIC), "r" (__l)); \
419 asm ("call __tls_get_addr, %%tgd_call(" #x ")\n\t" \
420 " nop" \
421 : "=r" (__o0) : "0" (__o0) \
422 : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
423 "o5", "o7", "cc"); \
424 asm ("sethi %%tldo_hix22(" #x "), %0" : "=r" (__o)); \
425 asm ("xor %1, %%tldo_lox10(" #x "), %0" : "=r" (__o) : "r" (__o)); \
426 asm ("add %1, %2, %0, %%tldo_add(" #x ")" : "=r" (__l) \
427 : "r" (__o0), "r" (__o)); \
428 __l; })
430 # define TLS_GD(x) \
431 ({ int *__l; register void *__o0 asm ("%o0"); \
432 asm ("sethi %%tgd_hi22(" #x "), %0" : "=r" (__l)); \
433 asm ("add %1, %%tgd_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
434 asm ("add %1, %2, %0, %%tgd_add(" #x ")" \
435 : "=r" (__o0) : "r" (TLS_LOAD_PIC), "r" (__l)); \
436 asm ("call __tls_get_addr, %%tgd_call(" #x ")\n\t" \
437 " nop" \
438 : "=r" (__o0) : "0" (__o0) \
439 : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
440 "o5", "o7", "cc"); \
441 __o0; })
443 #elif defined __s390x__
445 # define TLS_LE(x) \
446 ({ unsigned long __offset; \
447 asm ("bras %0,1f\n" \
448 "0:\t.quad " #x "@ntpoff\n" \
449 "1:\tlg %0,0(%0)" \
450 : "=a" (__offset) : : "cc" ); \
451 (int *) (__builtin_thread_pointer() + __offset); })
453 # ifdef PIC
454 # define TLS_IE(x) \
455 ({ unsigned long __offset; \
456 asm ("bras %0,1f\n" \
457 "0:\t.quad " #x "@gotntpoff\n" \
458 "1:\tlg %0,0(%0)\n\t" \
459 "lg %0,0(%0,%%r12):tls_load:" #x \
460 : "=&a" (__offset) : : "cc" ); \
461 (int *) (__builtin_thread_pointer() + __offset); })
462 # else
463 # define TLS_IE(x) \
464 ({ unsigned long __offset; \
465 asm ("bras %0,1f\n" \
466 "0:\t.quad " #x "@indntpoff\n" \
467 "1:\t lg %0,0(%0)\n\t" \
468 "lg %0,0(%0):tls_load:" #x \
469 : "=&a" (__offset) : : "cc" ); \
470 (int *) (__builtin_thread_pointer() + __offset); })
471 # endif
473 # ifdef PIC
474 # define TLS_LD(x) \
475 ({ unsigned long __offset, __save12; \
476 asm ("bras %0,1f\n" \
477 "0:\t.quad " #x "@tlsldm\n\t" \
478 ".quad " #x "@dtpoff\n" \
479 "1:\tlgr %1,%%r12\n\t" \
480 "larl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
481 "lg %%r2,0(%0)\n\t" \
482 "brasl %%r14,__tls_get_offset@plt:tls_ldcall:" #x "\n\t" \
483 "lg %0,8(%0)\n\t" \
484 "algr %0,%%r2\n\t" \
485 "lgr %%r12,%1" \
486 : "=&a" (__offset), "=&a" (__save12) \
487 : : "cc", "0", "1", "2", "3", "4", "5", "14" ); \
488 (int *) (__builtin_thread_pointer() + __offset); })
489 # else
490 # define TLS_LD(x) \
491 ({ unsigned long __offset; \
492 asm ("bras %0,1f\n" \
493 "0:\t.quad " #x "@tlsldm\n\t" \
494 ".quad " #x "@dtpoff\n" \
495 "1:\tlarl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
496 "lg %%r2,0(%0)\n\t" \
497 "brasl %%r14,__tls_get_offset@plt:tls_ldcall:" #x "\n\t" \
498 "lg %0,8(%0)\n\t" \
499 "algr %0,%%r2" \
500 : "=&a" (__offset) \
501 : : "cc", "0", "1", "2", "3", "4", "5", "12", "14" ); \
502 (int *) (__builtin_thread_pointer() + __offset); })
503 # endif
505 # ifdef PIC
506 # define TLS_GD(x) \
507 ({ unsigned long __offset, __save12; \
508 asm ("bras %0,1f\n" \
509 "0:\t.quad " #x "@tlsgd\n" \
510 "1:\tlgr %1,%%r12\n\t" \
511 "larl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
512 "lg %%r2,0(%0)\n\t" \
513 "brasl %%r14,__tls_get_offset@plt:tls_gdcall:" #x "\n\t" \
514 "lgr %0,%%r2\n\t" \
515 "lgr %%r12,%1" \
516 : "=&a" (__offset), "=&a" (__save12) \
517 : : "cc", "0", "1", "2", "3", "4", "5", "14" ); \
518 (int *) (__builtin_thread_pointer() + __offset); })
519 # else
520 # define TLS_GD(x) \
521 ({ unsigned long __offset; \
522 asm ("bras %0,1f\n" \
523 "0:\t.quad " #x "@tlsgd\n" \
524 "1:\tlarl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
525 "lg %%r2,0(%0)\n\t" \
526 "brasl %%r14,__tls_get_offset@plt:tls_gdcall:" #x "\n\t" \
527 "lgr %0,%%r2" \
528 : "=&a" (__offset) \
529 : : "cc", "0", "1", "2", "3", "4", "5", "12", "14" ); \
530 (int *) (__builtin_thread_pointer() + __offset); })
531 # endif
533 #elif defined __s390__
535 # define TLS_LE(x) \
536 ({ unsigned long __offset; \
537 asm ("bras %0,1f\n" \
538 "0:\t.long " #x "@ntpoff\n" \
539 "1:\tl %0,0(%0)" \
540 : "=a" (__offset) : : "cc" ); \
541 (int *) (__builtin_thread_pointer() + __offset); })
543 # ifdef PIC
544 # define TLS_IE(x) \
545 ({ unsigned long __offset; \
546 asm ("bras %0,1f\n" \
547 "0:\t.long " #x "@gotntpoff\n" \
548 "1:\tl %0,0(%0)\n\t" \
549 "l %0,0(%0,%%r12):tls_load:" #x \
550 : "=&a" (__offset) : : "cc" ); \
551 (int *) (__builtin_thread_pointer() + __offset); })
552 # else
553 # define TLS_IE(x) \
554 ({ unsigned long __offset; \
555 asm ("bras %0,1f\n" \
556 "0:\t.long " #x "@indntpoff\n" \
557 "1:\t l %0,0(%0)\n\t" \
558 "l %0,0(%0):tls_load:" #x \
559 : "=&a" (__offset) : : "cc" ); \
560 (int *) (__builtin_thread_pointer() + __offset); })
561 # endif
563 # ifdef PIC
564 # define TLS_LD(x) \
565 ({ unsigned long __offset, __save12; \
566 asm ("bras %0,1f\n" \
567 "0:\t.long _GLOBAL_OFFSET_TABLE_-0b\n\t" \
568 ".long __tls_get_offset@plt-0b\n\t" \
569 ".long " #x "@tlsldm\n\t" \
570 ".long " #x "@dtpoff\n" \
571 "1:\tlr %1,%%r12\n\t" \
572 "l %%r12,0(%0)\n\t" \
573 "la %%r12,0(%%r12,%0)\n\t" \
574 "l %%r1,4(%0)\n\t" \
575 "l %%r2,8(%0)\n\t" \
576 "bas %%r14,0(%%r1,%0):tls_ldcall:" #x "\n\t" \
577 "l %0,12(%0)\n\t" \
578 "alr %0,%%r2\n\t" \
579 "lr %%r12,%1" \
580 : "=&a" (__offset), "=&a" (__save12) \
581 : : "cc", "0", "1", "2", "3", "4", "5" ); \
582 (int *) (__builtin_thread_pointer() + __offset); })
583 # else
584 # define TLS_LD(x) \
585 ({ unsigned long __offset; \
586 asm ("bras %0,1f\n" \
587 "0:\t.long _GLOBAL_OFFSET_TABLE_\n\t" \
588 ".long __tls_get_offset@plt\n\t" \
589 ".long " #x "@tlsldm\n\t" \
590 ".long " #x "@dtpoff\n" \
591 "1:\tl %%r12,0(%0)\n\t" \
592 "l %%r1,4(%0)\n\t" \
593 "l %%r2,8(%0)\n\t" \
594 "bas %%r14,0(%%r1):tls_ldcall:" #x "\n\t" \
595 "l %0,12(%0)\n\t" \
596 "alr %0,%%r2" \
597 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
598 (int *) (__builtin_thread_pointer() + __offset); })
599 # endif
601 # ifdef PIC
602 # define TLS_GD(x) \
603 ({ unsigned long __offset, __save12; \
604 asm ("bras %0,1f\n" \
605 "0:\t.long _GLOBAL_OFFSET_TABLE_-0b\n\t" \
606 ".long __tls_get_offset@plt-0b\n\t" \
607 ".long " #x "@tlsgd\n" \
608 "1:\tlr %1,%%r12\n\t" \
609 "l %%r12,0(%0)\n\t" \
610 "la %%r12,0(%%r12,%0)\n\t" \
611 "l %%r1,4(%0)\n\t" \
612 "l %%r2,8(%0)\n\t" \
613 "bas %%r14,0(%%r1,%0):tls_gdcall:" #x "\n\t" \
614 "lr %0,%%r2\n\t" \
615 "lr %%r12,%1" \
616 : "=&a" (__offset), "=&a" (__save12) \
617 : : "cc", "0", "1", "2", "3", "4", "5" ); \
618 (int *) (__builtin_thread_pointer() + __offset); })
619 # else
620 # define TLS_GD(x) \
621 ({ unsigned long __offset; \
622 asm ("bras %0,1f\n" \
623 "0:\t.long _GLOBAL_OFFSET_TABLE_\n\t" \
624 ".long __tls_get_offset@plt\n\t" \
625 ".long " #x "@tlsgd\n" \
626 "1:\tl %%r12,0(%0)\n\t" \
627 "l %%r1,4(%0)\n\t" \
628 "l %%r2,8(%0)\n\t" \
629 "bas %%r14,0(%%r1):tls_gdcall:" #x "\n\t" \
630 "lr %0,%%r2" \
631 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
632 (int *) (__builtin_thread_pointer() + __offset); })
633 # endif
635 #elif defined __powerpc__ && !defined __powerpc64__
637 # define __TLS_CALL_CLOBBERS \
638 "0", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", \
639 "lr", "ctr", "cr0", "cr1", "cr5", "cr6", "cr7"
641 /* PowerPC32 Local Exec TLS access. */
642 # define TLS_LE(x) \
643 ({ int *__result; \
644 asm ("addi %0,2," #x "@tprel" \
645 : "=r" (__result)); \
646 __result; })
648 /* PowerPC32 Initial Exec TLS access. */
649 # define TLS_IE(x) \
650 ({ int *__result; \
651 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
652 "mflr %0\n\t" \
653 "lwz %0," #x "@got@tprel(%0)\n\t" \
654 "add %0,%0," #x "@tls" \
655 : "=b" (__result) : \
656 : "lr"); \
657 __result; })
659 /* PowerPC32 Local Dynamic TLS access. */
660 # define TLS_LD(x) \
661 ({ int *__result; \
662 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
663 "mflr 3\n\t" \
664 "addi 3,3," #x "@got@tlsld\n\t" \
665 "bl __tls_get_addr@plt\n\t" \
666 "addi %0,3," #x "@dtprel" \
667 : "=r" (__result) : \
668 : __TLS_CALL_CLOBBERS); \
669 __result; })
671 /* PowerPC32 General Dynamic TLS access. */
672 # define TLS_GD(x) \
673 ({ register int *__result __asm__ ("r3"); \
674 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
675 "mflr 3\n\t" \
676 "addi 3,3," #x "@got@tlsgd\n\t" \
677 "bl __tls_get_addr@plt" \
678 : : \
679 : __TLS_CALL_CLOBBERS); \
680 __result; })
682 #elif defined __powerpc__ && defined __powerpc64__
684 /* PowerPC64 Local Exec TLS access. */
685 # define TLS_LE(x) \
686 ({ int * __result; \
687 asm ( \
688 " addis %0,13," #x "@tprel@ha\n" \
689 " addi %0,%0," #x "@tprel@l\n" \
690 : "=b" (__result) ); \
691 __result; \
693 /* PowerPC64 Initial Exec TLS access. */
694 # define TLS_IE(x) \
695 ({ int * __result; \
696 asm ( \
697 " ld %0," #x "@got@tprel(2)\n" \
698 " add %0,%0," #x "@tls\n" \
699 : "=b" (__result) ); \
700 __result; \
702 /* PowerPC64 Local Dynamic TLS access. */
703 # define TLS_LD(x) \
704 ({ int * __result; \
705 asm ( \
706 " addi 3,2," #x "@got@tlsld\n" \
707 " bl .__tls_get_addr\n" \
708 " nop \n" \
709 " addis %0,3," #x "@dtprel@ha\n" \
710 " addi %0,%0," #x "@dtprel@l\n" \
711 : "=b" (__result) : \
712 : "0", "3", "4", "5", "6", "7", \
713 "8", "9", "10", "11", "12", \
714 "lr", "ctr", \
715 "cr0", "cr1", "cr5", "cr6", "cr7"); \
716 __result; \
718 /* PowerPC64 General Dynamic TLS access. */
719 # define TLS_GD(x) \
720 ({ int * __result; \
721 asm ( \
722 " addi 3,2," #x "@got@tlsgd\n" \
723 " bl .__tls_get_addr\n" \
724 " nop \n" \
725 " mr %0,3\n" \
726 : "=b" (__result) : \
727 : "0", "3", "4", "5", "6", "7", \
728 "8", "9", "10", "11", "12", \
729 "lr", "ctr", \
730 "cr0", "cr1", "cr5", "cr6", "cr7"); \
731 __result; \
734 #else
735 # error "No support for this architecture so far."
736 #endif