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