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" \
13 ".size " #x ",4\n\t" \
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. */
23 asm ("movl %%gs:0,%0\n\t" \
24 "subl $" #x "@tpoff,%0" \
31 asm ("movl %%gs:0,%0\n\t" \
32 "subl " #x "@gottpoff(%%ebx),%0" \
40 "1:\tmovl (%%esp), %%ebx\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)); \
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)); \
60 ({ int *__l, __b, __c, __d; \
63 "1:\tmovl (%%esp), %%ebx\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)); \
76 ({ int *__l, __c, __d; \
77 asm ("leal " #x "@tlsgd(%%ebx),%%eax\n\t" \
78 "call ___tls_get_addr@plt\n\t" \
80 : "=a" (__l), "=&c" (__c), "=&d" (__d)); \
84 ({ int *__l, __b, __c, __d; \
87 "1:\tmovl (%%esp), %%ebx\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" \
94 : "=a" (__l), "=&b" (__b), "=&c" (__c), "=&d" (__d)); \
98 #elif defined __x86_64__
102 asm ("movq %%fs:0,%0\n\t" \
103 "leaq " #x "@tpoff(%0), %0" \
109 asm ("movq %%fs:0,%0\n\t" \
110 "addq " #x "@gottpoff(%%rip),%0" \
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"); \
124 ({ int *__l, __c, __d; \
125 asm (".byte 0x66\n\t" \
126 "leaq " #x "@tlsgd(%%rip),%%rdi\n\t" \
129 "call __tls_get_addr@plt" \
130 : "=a" (__l), "=&c" (__c), "=&d" (__d) \
131 : : "rdi", "rsi", "r8", "r9", "r10", "r11"); \
137 ({ int *__l; void *__tp; \
138 asm ("stc gbr,%1\n\t" \
143 "1: .long " #x "@tpoff\n\t" \
145 : "=r" (__l), "=r" (__tp)); \
150 ({ int *__l; void *__tp; \
151 register void *__gp __asm__("r12"); \
152 asm ("mov.l 1f,r0\n\t" \
154 "mov.l @(r0,r12),%0\n\t" \
158 "1: .long " #x "@gottpoff\n\t" \
160 : "=r" (__l), "=r" (__tp) : "r" (__gp) : "r0"); \
164 ({ int *__l; void *__tp; \
165 asm ("mov.l r12,@-r15\n\t" \
171 "mov.l @(r0,r12),%0\n\t" \
175 "1: .long " #x "@gottpoff\n\t" \
176 "0: .long _GLOBAL_OFFSET_TABLE_\n\t" \
177 "2: mov.l @r15+,r12" \
178 : "=r" (__l), "=r" (__tp) : : "r0"); \
185 register void *__gp __asm__("r12"); \
186 asm ("mov.l 1f,r4\n\t" \
195 "1: .long " #x "@tlsldm\n\t" \
196 "2: .long __tls_get_addr@plt\n\t" \
197 "4: mov.l 3f,%0\n\t" \
201 "3: .long " #x "@dtpoff\n\t" \
203 : "=r" (__l) : "r" (__gp) : "r0", "r1", "r2", "r3", "r4", "r5", \
204 "r6", "r7", "pr", "t"); \
209 asm ("mov.l r12,@-r15\n\t" \
222 "1: .long " #x "@tlsldm\n\t" \
223 "2: .long __tls_get_addr@plt\n\t" \
224 "0: .long _GLOBAL_OFFSET_TABLE_\n\t" \
225 "4: mov.l 3f,%0\n\t" \
229 "3: .long " #x "@dtpoff\n\t" \
230 "5: mov.l @r15+,r12" \
231 : "=r" (__l) : : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
239 register void *__gp __asm__("r12"); \
240 asm ("mov.l 1f,r4\n\t" \
249 "1: .long " #x "@tlsgd\n\t" \
250 "2: .long __tls_get_addr@plt\n\t" \
252 : "=r" (__l) : "r" (__gp) : "r0", "r1", "r2", "r3", "r4", "r5", \
253 "r6", "r7", "pr", "t"); \
258 asm ("mov.l r12,@-r15\n\t" \
271 "1: .long " #x "@tlsgd\n\t" \
272 "2: .long __tls_get_addr@plt\n\t" \
273 "0: .long _GLOBAL_OFFSET_TABLE_\n\t" \
274 "3: mov.l @r15+,r12" \
275 : "=r" (__l) : : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
280 #elif defined __alpha__
282 register void *__gp __asm__("$29");
286 asm ("call_pal 158\n\tlda $0," #x "($0)\t\t!tprel" : "=v"(__l)); \
290 ({ char *__tp; unsigned long __o; \
291 asm ("call_pal 158\n\tldq %1," #x "($gp)\t\t!gottprel" \
292 : "=v"(__tp), "=r"(__o) : "r"(__gp)); \
293 (int *)(__tp + __o); })
296 ({ extern void *__tls_get_addr(void *); int *__l; void *__i; \
297 asm ("lda %0," #x "($gp)\t\t!tlsldm" : "=r" (__i) : "r"(__gp)); \
298 __i = __tls_get_addr(__i); \
299 asm ("lda %0, " #x "(%1)\t\t!dtprel" : "=r"(__l) : "r"(__i)); \
303 ({ extern void *__tls_get_addr(void *); void *__i; \
304 asm ("lda %0," #x "($gp)\t\t!tlsgd" : "=r" (__i) : "r"(__gp)); \
305 (int *) __tls_get_addr(__i); })
308 #elif defined __ia64__
312 asm ("mov r2=r13\n\t" \
314 "addl %0=@tprel(" #x "),r2\n\t" \
315 : "=r" (__l) : : "r2" ); __l; })
320 "addl r16=@ltoff(@tprel(" #x ")),gp\n\t" \
322 "ld8 r17=[r16]\n\t" \
324 "add %0=r13,r17\n\t" \
325 : "=r" (__l) : : "r16", "r17" ); __l; })
327 # define __TLS_CALL_CLOBBERS \
328 "r2", "r3", "r8", "r9", "r10", "r11", "r14", "r15", "r16", "r17", \
329 "r18", "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", \
330 "r27", "r28", "r29", "r30", "r31", \
331 "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", \
332 "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
334 "out0", "out1", "out2", "out3", "out4", "out5", "out6", "out7"
340 "addl r16=@ltoff(@dtpmod(" #x ")),gp\n\t" \
341 "addl out1=@dtprel(" #x "),r0\n\t" \
343 "ld8 out0=[r16]\n\t" \
344 "br.call.sptk.many b0=__tls_get_addr" \
348 : "=r" (__l) : : "loc0", __TLS_CALL_CLOBBERS); \
355 "addl r16=@ltoff(@dtpmod(" #x ")),gp\n\t" \
356 "addl r17=@ltoff(@dtprel(" #x ")),gp\n\t" \
358 "ld8 out0=[r16]\n\t" \
359 "ld8 out1=[r17]\n\t" \
360 "br.call.sptk.many b0=__tls_get_addr" \
364 : "=r" (__l) : : "loc0", __TLS_CALL_CLOBBERS); \
367 #elif defined __sparc__ && !defined __arch64__
371 asm ("sethi %%tle_hix22(" #x "), %0" : "=r" (__l)); \
372 asm ("xor %1, %%tle_lox10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
373 asm ("add %%g7, %1, %0" : "=r" (__l) : "r" (__l)); \
377 # define TLS_LOAD_PIC \
378 ({ register long pc __asm__ ("%o7"); \
380 asm ("sethi %%hi(_GLOBAL_OFFSET_TABLE_-4), %1\n\t" \
382 "add %1, %%lo(_GLOBAL_OFFSET_TABLE_+4), %1\n\t" \
383 "add %1, %0, %1\n\t" \
384 : "=r" (pc), "=r" (got)); \
387 # define TLS_LOAD_PIC \
389 asm (".hidden _GLOBAL_OFFSET_TABLE_\n\t" \
390 "sethi %%hi(_GLOBAL_OFFSET_TABLE_), %0\n\t" \
391 "or %0, %%lo(_GLOBAL_OFFSET_TABLE_), %0" \
398 asm ("sethi %%tie_hi22(" #x "), %0" : "=r" (__l)); \
399 asm ("add %1, %%tie_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
400 asm ("ld [%1 + %2], %0, %%tie_ld(" #x ")" \
401 : "=r" (__l) : "r" (TLS_LOAD_PIC), "r" (__l)); \
402 asm ("add %%g7, %1, %0, %%tie_add(" #x ")" : "=r" (__l) : "r" (__l)); \
406 ({ int *__l; register void *__o0 asm ("%o0"); \
408 asm ("sethi %%tldm_hi22(" #x "), %0" : "=r" (__l)); \
409 asm ("add %1, %%tldm_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
410 asm ("add %1, %2, %0, %%tldm_add(" #x ")" \
411 : "=r" (__o0) : "r" (TLS_LOAD_PIC), "r" (__l)); \
412 asm ("call __tls_get_addr, %%tgd_call(" #x ")\n\t" \
414 : "=r" (__o0) : "0" (__o0) \
415 : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
417 asm ("sethi %%tldo_hix22(" #x "), %0" : "=r" (__o)); \
418 asm ("xor %1, %%tldo_lox10(" #x "), %0" : "=r" (__o) : "r" (__o)); \
419 asm ("add %1, %2, %0, %%tldo_add(" #x ")" : "=r" (__l) \
420 : "r" (__o0), "r" (__o)); \
424 ({ int *__l; register void *__o0 asm ("%o0"); \
425 asm ("sethi %%tgd_hi22(" #x "), %0" : "=r" (__l)); \
426 asm ("add %1, %%tgd_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
427 asm ("add %1, %2, %0, %%tgd_add(" #x ")" \
428 : "=r" (__o0) : "r" (TLS_LOAD_PIC), "r" (__l)); \
429 asm ("call __tls_get_addr, %%tgd_call(" #x ")\n\t" \
431 : "=r" (__o0) : "0" (__o0) \
432 : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
436 #elif defined __s390x__
439 ({ unsigned long __offset; \
440 asm ("bras %0,1f\n" \
441 "0:\t.quad " #x "@ntpoff\n" \
443 : "=a" (__offset) : : "cc" ); \
444 (int *) (__builtin_thread_pointer() + __offset); })
448 ({ unsigned long __offset; \
449 asm ("bras %0,1f\n" \
450 "0:\t.quad " #x "@gotntpoff\n" \
451 "1:\tlg %0,0(%0)\n\t" \
452 "lg %0,0(%0,%%r12):tls_load:" #x \
453 : "=&a" (__offset) : : "cc" ); \
454 (int *) (__builtin_thread_pointer() + __offset); })
457 ({ unsigned long __offset; \
458 asm ("bras %0,1f\n" \
459 "0:\t.quad " #x "@indntpoff\n" \
460 "1:\t lg %0,0(%0)\n\t" \
461 "lg %0,0(%0):tls_load:" #x \
462 : "=&a" (__offset) : : "cc" ); \
463 (int *) (__builtin_thread_pointer() + __offset); })
468 ({ unsigned long __offset, __save12; \
469 asm ("bras %0,1f\n" \
470 "0:\t.quad " #x "@tlsldm\n\t" \
471 ".quad " #x "@dtpoff\n" \
472 "1:\tlgr %1,%%r12\n\t" \
473 "larl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
474 "lg %%r2,0(%0)\n\t" \
475 "brasl %%r14,__tls_get_offset@plt:tls_ldcall:" #x "\n\t" \
479 : "=&a" (__offset), "=&a" (__save12) \
480 : : "cc", "0", "1", "2", "3", "4", "5" ); \
481 (int *) (__builtin_thread_pointer() + __offset); })
484 ({ unsigned long __offset; \
485 asm ("bras %0,1f\n" \
486 "0:\t.quad " #x "@tlsldm\n\t" \
487 ".quad " #x "@dtpoff\n" \
488 "1:\tlarl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
489 "lg %%r2,0(%0)\n\t" \
490 "brasl %%r14,__tls_get_offset@plt:tls_ldcall:" #x "\n\t" \
493 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
494 (int *) (__builtin_thread_pointer() + __offset); })
499 ({ unsigned long __offset, __save12; \
500 asm ("bras %0,1f\n" \
501 "0:\t.quad " #x "@tlsgd\n" \
502 "1:\tlgr %1,%%r12\n\t" \
503 "larl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
504 "lg %%r2,0(%0)\n\t" \
505 "brasl %%r14,__tls_get_offset@plt:tls_gdcall:" #x "\n\t" \
508 : "=&a" (__offset), "=&a" (__save12) \
509 : : "cc", "0", "1", "2", "3", "4", "5" ); \
510 (int *) (__builtin_thread_pointer() + __offset); })
513 ({ unsigned long __offset; \
514 asm ("bras %0,1f\n" \
515 "0:\t.quad " #x "@tlsgd\n" \
516 "1:\tlarl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
517 "lg %%r2,0(%0)\n\t" \
518 "brasl %%r14,__tls_get_offset@plt:tls_gdcall:" #x "\n\t" \
520 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
521 (int *) (__builtin_thread_pointer() + __offset); })
524 #elif defined __s390__
527 ({ unsigned long __offset; \
528 asm ("bras %0,1f\n" \
529 "0:\t.long " #x "@ntpoff\n" \
531 : "=a" (__offset) : : "cc" ); \
532 (int *) (__builtin_thread_pointer() + __offset); })
536 ({ unsigned long __offset; \
537 asm ("bras %0,1f\n" \
538 "0:\t.long " #x "@gotntpoff\n" \
539 "1:\tl %0,0(%0)\n\t" \
540 "l %0,0(%0,%%r12):tls_load:" #x \
541 : "=&a" (__offset) : : "cc" ); \
542 (int *) (__builtin_thread_pointer() + __offset); })
545 ({ unsigned long __offset; \
546 asm ("bras %0,1f\n" \
547 "0:\t.long " #x "@indntpoff\n" \
548 "1:\t l %0,0(%0)\n\t" \
549 "l %0,0(%0):tls_load:" #x \
550 : "=&a" (__offset) : : "cc" ); \
551 (int *) (__builtin_thread_pointer() + __offset); })
556 ({ unsigned long __offset, __save12; \
557 asm ("bras %0,1f\n" \
558 "0:\t.long _GLOBAL_OFFSET_TABLE_-0b\n\t" \
559 ".long __tls_get_offset@plt-0b\n\t" \
560 ".long " #x "@tlsldm\n\t" \
561 ".long " #x "@dtpoff\n" \
562 "1:\tlr %1,%%r12\n\t" \
563 "l %%r12,0(%0)\n\t" \
564 "la %%r12,0(%%r12,%0)\n\t" \
567 "bas %%r14,0(%%r1,%0):tls_ldcall:" #x "\n\t" \
571 : "=&a" (__offset), "=&a" (__save12) \
572 : : "cc", "0", "1", "2", "3", "4", "5" ); \
573 (int *) (__builtin_thread_pointer() + __offset); })
576 ({ unsigned long __offset; \
577 asm ("bras %0,1f\n" \
578 "0:\t.long _GLOBAL_OFFSET_TABLE_\n\t" \
579 ".long __tls_get_offset@plt\n\t" \
580 ".long " #x "@tlsldm\n\t" \
581 ".long " #x "@dtpoff\n" \
582 "1:\tl %%r12,0(%0)\n\t" \
585 "bas %%r14,0(%%r1):tls_ldcall:" #x "\n\t" \
588 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
589 (int *) (__builtin_thread_pointer() + __offset); })
594 ({ unsigned long __offset, __save12; \
595 asm ("bras %0,1f\n" \
596 "0:\t.long _GLOBAL_OFFSET_TABLE_-0b\n\t" \
597 ".long __tls_get_offset@plt-0b\n\t" \
598 ".long " #x "@tlsgd\n" \
599 "1:\tlr %1,%%r12\n\t" \
600 "l %%r12,0(%0)\n\t" \
601 "la %%r12,0(%%r12,%0)\n\t" \
604 "bas %%r14,0(%%r1,%0):tls_gdcall:" #x "\n\t" \
607 : "=&a" (__offset), "=&a" (__save12) \
608 : : "cc", "0", "1", "2", "3", "4", "5" ); \
609 (int *) (__builtin_thread_pointer() + __offset); })
612 ({ unsigned long __offset; \
613 asm ("bras %0,1f\n" \
614 "0:\t.long _GLOBAL_OFFSET_TABLE_\n\t" \
615 ".long __tls_get_offset@plt\n\t" \
616 ".long " #x "@tlsgd\n" \
617 "1:\tl %%r12,0(%0)\n\t" \
620 "bas %%r14,0(%%r1):tls_gdcall:" #x "\n\t" \
622 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
623 (int *) (__builtin_thread_pointer() + __offset); })
626 #elif defined __powerpc__ && defined __powerpc64__
628 /* PowerPC64 Local Exec TLS access. */
632 " addis %0,13," #x "@tprel@ha\n" \
633 " addi %0,%0," #x "@tprel@l\n" \
634 : "=b" (__result) ); \
637 /* PowerPC64 Initial Exec TLS access. */
641 " ld %0," #x "@got@tprel(2)\n" \
642 " add %0,%0," #x "@tls\n" \
643 : "=b" (__result) ); \
646 /* PowerPC64 Local Dynamic TLS access. */
650 " addi 3,2," #x "@got@tlsld\n" \
651 " bl .__tls_get_addr\n" \
653 " addis %0,3," #x "@dtprel@ha\n" \
654 " addi %0,%0," #x "@dtprel@l\n" \
655 : "=b" (__result) : \
656 : "0", "3", "4", "5", "6", "7", \
657 "8", "9", "10", "11", "12", \
659 "cr0", "cr1", "cr5", "cr6", "cr7"); \
662 /* PowerPC64 General Dynamic TLS access. */
666 " addi 3,2," #x "@got@tlsgd\n" \
667 " bl .__tls_get_addr\n" \
670 : "=b" (__result) : \
671 : "0", "3", "4", "5", "6", "7", \
672 "8", "9", "10", "11", "12", \
674 "cr0", "cr1", "cr5", "cr6", "cr7"); \
679 # error "No support for this architecture so far."