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" \
14 ".size " #x ",4\n\t" \
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. */
24 asm ("movl %%gs:0,%0\n\t" \
25 "subl $" #x "@tpoff,%0" \
32 asm ("movl %%gs:0,%0\n\t" \
33 "subl " #x "@gottpoff(%%ebx),%0" \
41 "1:\tmovl (%%esp), %%ebx\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)); \
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)); \
61 ({ int *__l, __b, __c, __d; \
64 "1:\tmovl (%%esp), %%ebx\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)); \
77 ({ int *__l, __c, __d; \
78 asm ("leal " #x "@tlsgd(%%ebx),%%eax\n\t" \
79 "call ___tls_get_addr@plt\n\t" \
81 : "=a" (__l), "=&c" (__c), "=&d" (__d)); \
85 ({ int *__l, __b, __c, __d; \
88 "1:\tmovl (%%esp), %%ebx\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" \
95 : "=a" (__l), "=&b" (__b), "=&c" (__c), "=&d" (__d)); \
99 #elif defined __x86_64__
103 asm ("movq %%fs:0,%0\n\t" \
104 "leaq " #x "@tpoff(%0), %0" \
110 asm ("movq %%fs:0,%0\n\t" \
111 "addq " #x "@gottpoff(%%rip),%0" \
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"); \
125 ({ int *__l, __c, __d; \
126 asm (".byte 0x66\n\t" \
127 "leaq " #x "@tlsgd(%%rip),%%rdi\n\t" \
130 "call __tls_get_addr@plt" \
131 : "=a" (__l), "=&c" (__c), "=&d" (__d) \
132 : : "rdi", "rsi", "r8", "r9", "r10", "r11"); \
138 ({ int *__l; void *__tp; \
139 asm ("stc gbr,%1\n\t" \
144 "1: .long " #x "@tpoff\n\t" \
146 : "=r" (__l), "=r" (__tp)); \
151 ({ int *__l; void *__tp; \
152 register void *__gp __asm__("r12"); \
153 asm ("mov.l 1f,r0\n\t" \
155 "mov.l @(r0,r12),%0\n\t" \
159 "1: .long " #x "@gottpoff\n\t" \
161 : "=r" (__l), "=r" (__tp) : "r" (__gp) : "r0"); \
165 ({ int *__l; void *__tp; \
166 asm ("mov.l r12,@-r15\n\t" \
172 "mov.l @(r0,r12),%0\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"); \
186 register void *__gp __asm__("r12"); \
187 asm ("mov.l 1f,r4\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" \
202 "3: .long " #x "@dtpoff\n\t" \
204 : "=r" (__l) : "r" (__gp) : "r0", "r1", "r2", "r3", "r4", "r5", \
205 "r6", "r7", "pr", "t"); \
210 asm ("mov.l r12,@-r15\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" \
230 "3: .long " #x "@dtpoff\n\t" \
231 "5: mov.l @r15+,r12" \
232 : "=r" (__l) : : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
240 register void *__gp __asm__("r12"); \
241 asm ("mov.l 1f,r4\n\t" \
250 "1: .long " #x "@tlsgd\n\t" \
251 "2: .long __tls_get_addr@plt\n\t" \
253 : "=r" (__l) : "r" (__gp) : "r0", "r1", "r2", "r3", "r4", "r5", \
254 "r6", "r7", "pr", "t"); \
259 asm ("mov.l r12,@-r15\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", \
281 #elif defined __alpha__
283 register void *__gp
__asm__("$29");
287 asm ("call_pal 158\n\tlda $0," #x "($0)\t\t!tprel" : "=v"(__l)); \
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); })
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)); \
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__
313 asm ("mov r2=r13\n\t" \
315 "addl %0=@tprel(" #x "),r2\n\t" \
316 : "=r" (__l) : : "r2" ); __l; })
320 register long __gp asm ("gp"); \
322 "addl r16=@ltoff(@tprel(" #x ")),gp\n\t" \
324 "ld8 r17=[r16]\n\t" \
326 "add %0=r13,r17\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", \
337 "out0", "out1", "out2", "out3", "out4", "out5", "out6", "out7"
341 register long __gp asm ("gp"); \
344 "addl r16=@ltoff(@dtpmod(" #x ")),gp\n\t" \
345 "addl out1=@dtprel(" #x "),r0\n\t" \
347 "ld8 out0=[r16]\n\t" \
348 "br.call.sptk.many b0=__tls_get_addr" \
353 : "=r" (__l) : "r" (__gp) : "loc0", __TLS_CALL_CLOBBERS); \
358 register long __gp asm ("gp"); \
361 "addl r16=@ltoff(@dtpmod(" #x ")),gp\n\t" \
362 "addl r17=@ltoff(@dtprel(" #x ")),gp\n\t" \
364 "ld8 out0=[r16]\n\t" \
365 "ld8 out1=[r17]\n\t" \
366 "br.call.sptk.many b0=__tls_get_addr" \
371 : "=r" (__l) : "r" (__gp) : "loc0", __TLS_CALL_CLOBBERS); \
374 #elif defined __sparc__ && !defined __arch64__
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)); \
384 # define TLS_LOAD_PIC \
385 ({ register long pc __asm__ ("%o7"); \
387 asm ("sethi %%hi(_GLOBAL_OFFSET_TABLE_-4), %1\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)); \
394 # define TLS_LOAD_PIC \
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" \
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)); \
413 ({ int *__l; register void *__o0 asm ("%o0"); \
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" \
421 : "=r" (__o0) : "0" (__o0) \
422 : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
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)); \
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" \
438 : "=r" (__o0) : "0" (__o0) \
439 : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
443 #elif defined __s390x__
446 ({ unsigned long __offset; \
447 asm ("bras %0,1f\n" \
448 "0:\t.quad " #x "@ntpoff\n" \
450 : "=a" (__offset) : : "cc" ); \
451 (int *) (__builtin_thread_pointer() + __offset); })
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); })
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); })
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" \
486 : "=&a" (__offset), "=&a" (__save12) \
487 : : "cc", "0", "1", "2", "3", "4", "5", "14" ); \
488 (int *) (__builtin_thread_pointer() + __offset); })
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" \
501 : : "cc", "0", "1", "2", "3", "4", "5", "12", "14" ); \
502 (int *) (__builtin_thread_pointer() + __offset); })
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" \
516 : "=&a" (__offset), "=&a" (__save12) \
517 : : "cc", "0", "1", "2", "3", "4", "5", "14" ); \
518 (int *) (__builtin_thread_pointer() + __offset); })
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" \
529 : : "cc", "0", "1", "2", "3", "4", "5", "12", "14" ); \
530 (int *) (__builtin_thread_pointer() + __offset); })
533 #elif defined __s390__
536 ({ unsigned long __offset; \
537 asm ("bras %0,1f\n" \
538 "0:\t.long " #x "@ntpoff\n" \
540 : "=a" (__offset) : : "cc" ); \
541 (int *) (__builtin_thread_pointer() + __offset); })
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); })
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); })
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" \
576 "bas %%r14,0(%%r1,%0):tls_ldcall:" #x "\n\t" \
580 : "=&a" (__offset), "=&a" (__save12) \
581 : : "cc", "0", "1", "2", "3", "4", "5" ); \
582 (int *) (__builtin_thread_pointer() + __offset); })
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" \
594 "bas %%r14,0(%%r1):tls_ldcall:" #x "\n\t" \
597 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
598 (int *) (__builtin_thread_pointer() + __offset); })
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" \
613 "bas %%r14,0(%%r1,%0):tls_gdcall:" #x "\n\t" \
616 : "=&a" (__offset), "=&a" (__save12) \
617 : : "cc", "0", "1", "2", "3", "4", "5" ); \
618 (int *) (__builtin_thread_pointer() + __offset); })
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" \
629 "bas %%r14,0(%%r1):tls_gdcall:" #x "\n\t" \
631 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
632 (int *) (__builtin_thread_pointer() + __offset); })
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. */
644 asm ("addi %0,2," #x "@tprel" \
645 : "=r" (__result)); \
648 /* PowerPC32 Initial Exec TLS access. */
651 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
653 "lwz %0," #x "@got@tprel(%0)\n\t" \
654 "add %0,%0," #x "@tls" \
655 : "=b" (__result) : \
659 /* PowerPC32 Local Dynamic TLS access. */
662 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\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); \
671 /* PowerPC32 General Dynamic TLS access. */
673 ({ register int *__result __asm__ ("r3"); \
674 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
676 "addi 3,3," #x "@got@tlsgd\n\t" \
677 "bl __tls_get_addr@plt" \
679 : __TLS_CALL_CLOBBERS); \
682 #elif defined __powerpc__ && defined __powerpc64__
684 /* PowerPC64 Local Exec TLS access. */
688 " addis %0,13," #x "@tprel@ha\n" \
689 " addi %0,%0," #x "@tprel@l\n" \
690 : "=b" (__result) ); \
693 /* PowerPC64 Initial Exec TLS access. */
697 " ld %0," #x "@got@tprel(2)\n" \
698 " add %0,%0," #x "@tls\n" \
699 : "=b" (__result) ); \
702 /* PowerPC64 Local Dynamic TLS access. */
706 " addi 3,2," #x "@got@tlsld\n" \
707 " bl .__tls_get_addr\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", \
715 "cr0", "cr1", "cr5", "cr6", "cr7"); \
718 /* PowerPC64 General Dynamic TLS access. */
722 " addi 3,2," #x "@got@tlsgd\n" \
723 " bl .__tls_get_addr\n" \
726 : "=b" (__result) : \
727 : "0", "3", "4", "5", "6", "7", \
728 "8", "9", "10", "11", "12", \
730 "cr0", "cr1", "cr5", "cr6", "cr7"); \
735 # error "No support for this architecture so far."