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; })
319 register long __gp asm ("gp"); \
321 "addl r16=@ltoff(@tprel(" #x ")),gp\n\t" \
323 "ld8 r17=[r16]\n\t" \
325 "add %0=r13,r17\n\t" \
326 : "=r" (__l) : "r" (__gp) : "r16", "r17" ); __l; })
328 # define __TLS_CALL_CLOBBERS \
329 "r2", "r3", "r8", "r9", "r10", "r11", "r14", "r15", "r16", "r17", \
330 "r18", "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", \
331 "r27", "r28", "r29", "r30", "r31", \
332 "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", \
333 "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
335 "out0", "out1", "out2", "out3", "out4", "out5", "out6", "out7"
339 register long __gp asm ("gp"); \
342 "addl r16=@ltoff(@dtpmod(" #x ")),gp\n\t" \
343 "addl out1=@dtprel(" #x "),r0\n\t" \
345 "ld8 out0=[r16]\n\t" \
346 "br.call.sptk.many b0=__tls_get_addr" \
350 : "=r" (__l) : "r" (__gp) : "loc0", __TLS_CALL_CLOBBERS); \
355 register long __gp asm ("gp"); \
358 "addl r16=@ltoff(@dtpmod(" #x ")),gp\n\t" \
359 "addl r17=@ltoff(@dtprel(" #x ")),gp\n\t" \
361 "ld8 out0=[r16]\n\t" \
362 "ld8 out1=[r17]\n\t" \
363 "br.call.sptk.many b0=__tls_get_addr" \
367 : "=r" (__l) : "r" (__gp) : "loc0", __TLS_CALL_CLOBBERS); \
370 #elif defined __sparc__ && !defined __arch64__
374 asm ("sethi %%tle_hix22(" #x "), %0" : "=r" (__l)); \
375 asm ("xor %1, %%tle_lox10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
376 asm ("add %%g7, %1, %0" : "=r" (__l) : "r" (__l)); \
380 # define TLS_LOAD_PIC \
381 ({ register long pc __asm__ ("%o7"); \
383 asm ("sethi %%hi(_GLOBAL_OFFSET_TABLE_-4), %1\n\t" \
385 "add %1, %%lo(_GLOBAL_OFFSET_TABLE_+4), %1\n\t" \
386 "add %1, %0, %1\n\t" \
387 : "=r" (pc), "=r" (got)); \
390 # define TLS_LOAD_PIC \
392 asm (".hidden _GLOBAL_OFFSET_TABLE_\n\t" \
393 "sethi %%hi(_GLOBAL_OFFSET_TABLE_), %0\n\t" \
394 "or %0, %%lo(_GLOBAL_OFFSET_TABLE_), %0" \
401 asm ("sethi %%tie_hi22(" #x "), %0" : "=r" (__l)); \
402 asm ("add %1, %%tie_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
403 asm ("ld [%1 + %2], %0, %%tie_ld(" #x ")" \
404 : "=r" (__l) : "r" (TLS_LOAD_PIC), "r" (__l)); \
405 asm ("add %%g7, %1, %0, %%tie_add(" #x ")" : "=r" (__l) : "r" (__l)); \
409 ({ int *__l; register void *__o0 asm ("%o0"); \
411 asm ("sethi %%tldm_hi22(" #x "), %0" : "=r" (__l)); \
412 asm ("add %1, %%tldm_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
413 asm ("add %1, %2, %0, %%tldm_add(" #x ")" \
414 : "=r" (__o0) : "r" (TLS_LOAD_PIC), "r" (__l)); \
415 asm ("call __tls_get_addr, %%tgd_call(" #x ")\n\t" \
417 : "=r" (__o0) : "0" (__o0) \
418 : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
420 asm ("sethi %%tldo_hix22(" #x "), %0" : "=r" (__o)); \
421 asm ("xor %1, %%tldo_lox10(" #x "), %0" : "=r" (__o) : "r" (__o)); \
422 asm ("add %1, %2, %0, %%tldo_add(" #x ")" : "=r" (__l) \
423 : "r" (__o0), "r" (__o)); \
427 ({ int *__l; register void *__o0 asm ("%o0"); \
428 asm ("sethi %%tgd_hi22(" #x "), %0" : "=r" (__l)); \
429 asm ("add %1, %%tgd_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
430 asm ("add %1, %2, %0, %%tgd_add(" #x ")" \
431 : "=r" (__o0) : "r" (TLS_LOAD_PIC), "r" (__l)); \
432 asm ("call __tls_get_addr, %%tgd_call(" #x ")\n\t" \
434 : "=r" (__o0) : "0" (__o0) \
435 : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
439 #elif defined __s390x__
442 ({ unsigned long __offset; \
443 asm ("bras %0,1f\n" \
444 "0:\t.quad " #x "@ntpoff\n" \
446 : "=a" (__offset) : : "cc" ); \
447 (int *) (__builtin_thread_pointer() + __offset); })
451 ({ unsigned long __offset; \
452 asm ("bras %0,1f\n" \
453 "0:\t.quad " #x "@gotntpoff\n" \
454 "1:\tlg %0,0(%0)\n\t" \
455 "lg %0,0(%0,%%r12):tls_load:" #x \
456 : "=&a" (__offset) : : "cc" ); \
457 (int *) (__builtin_thread_pointer() + __offset); })
460 ({ unsigned long __offset; \
461 asm ("bras %0,1f\n" \
462 "0:\t.quad " #x "@indntpoff\n" \
463 "1:\t lg %0,0(%0)\n\t" \
464 "lg %0,0(%0):tls_load:" #x \
465 : "=&a" (__offset) : : "cc" ); \
466 (int *) (__builtin_thread_pointer() + __offset); })
471 ({ unsigned long __offset, __save12; \
472 asm ("bras %0,1f\n" \
473 "0:\t.quad " #x "@tlsldm\n\t" \
474 ".quad " #x "@dtpoff\n" \
475 "1:\tlgr %1,%%r12\n\t" \
476 "larl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
477 "lg %%r2,0(%0)\n\t" \
478 "brasl %%r14,__tls_get_offset@plt:tls_ldcall:" #x "\n\t" \
482 : "=&a" (__offset), "=&a" (__save12) \
483 : : "cc", "0", "1", "2", "3", "4", "5" ); \
484 (int *) (__builtin_thread_pointer() + __offset); })
487 ({ unsigned long __offset; \
488 asm ("bras %0,1f\n" \
489 "0:\t.quad " #x "@tlsldm\n\t" \
490 ".quad " #x "@dtpoff\n" \
491 "1:\tlarl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
492 "lg %%r2,0(%0)\n\t" \
493 "brasl %%r14,__tls_get_offset@plt:tls_ldcall:" #x "\n\t" \
496 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
497 (int *) (__builtin_thread_pointer() + __offset); })
502 ({ unsigned long __offset, __save12; \
503 asm ("bras %0,1f\n" \
504 "0:\t.quad " #x "@tlsgd\n" \
505 "1:\tlgr %1,%%r12\n\t" \
506 "larl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
507 "lg %%r2,0(%0)\n\t" \
508 "brasl %%r14,__tls_get_offset@plt:tls_gdcall:" #x "\n\t" \
511 : "=&a" (__offset), "=&a" (__save12) \
512 : : "cc", "0", "1", "2", "3", "4", "5" ); \
513 (int *) (__builtin_thread_pointer() + __offset); })
516 ({ unsigned long __offset; \
517 asm ("bras %0,1f\n" \
518 "0:\t.quad " #x "@tlsgd\n" \
519 "1:\tlarl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
520 "lg %%r2,0(%0)\n\t" \
521 "brasl %%r14,__tls_get_offset@plt:tls_gdcall:" #x "\n\t" \
523 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
524 (int *) (__builtin_thread_pointer() + __offset); })
527 #elif defined __s390__
530 ({ unsigned long __offset; \
531 asm ("bras %0,1f\n" \
532 "0:\t.long " #x "@ntpoff\n" \
534 : "=a" (__offset) : : "cc" ); \
535 (int *) (__builtin_thread_pointer() + __offset); })
539 ({ unsigned long __offset; \
540 asm ("bras %0,1f\n" \
541 "0:\t.long " #x "@gotntpoff\n" \
542 "1:\tl %0,0(%0)\n\t" \
543 "l %0,0(%0,%%r12):tls_load:" #x \
544 : "=&a" (__offset) : : "cc" ); \
545 (int *) (__builtin_thread_pointer() + __offset); })
548 ({ unsigned long __offset; \
549 asm ("bras %0,1f\n" \
550 "0:\t.long " #x "@indntpoff\n" \
551 "1:\t l %0,0(%0)\n\t" \
552 "l %0,0(%0):tls_load:" #x \
553 : "=&a" (__offset) : : "cc" ); \
554 (int *) (__builtin_thread_pointer() + __offset); })
559 ({ unsigned long __offset, __save12; \
560 asm ("bras %0,1f\n" \
561 "0:\t.long _GLOBAL_OFFSET_TABLE_-0b\n\t" \
562 ".long __tls_get_offset@plt-0b\n\t" \
563 ".long " #x "@tlsldm\n\t" \
564 ".long " #x "@dtpoff\n" \
565 "1:\tlr %1,%%r12\n\t" \
566 "l %%r12,0(%0)\n\t" \
567 "la %%r12,0(%%r12,%0)\n\t" \
570 "bas %%r14,0(%%r1,%0):tls_ldcall:" #x "\n\t" \
574 : "=&a" (__offset), "=&a" (__save12) \
575 : : "cc", "0", "1", "2", "3", "4", "5" ); \
576 (int *) (__builtin_thread_pointer() + __offset); })
579 ({ unsigned long __offset; \
580 asm ("bras %0,1f\n" \
581 "0:\t.long _GLOBAL_OFFSET_TABLE_\n\t" \
582 ".long __tls_get_offset@plt\n\t" \
583 ".long " #x "@tlsldm\n\t" \
584 ".long " #x "@dtpoff\n" \
585 "1:\tl %%r12,0(%0)\n\t" \
588 "bas %%r14,0(%%r1):tls_ldcall:" #x "\n\t" \
591 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
592 (int *) (__builtin_thread_pointer() + __offset); })
597 ({ unsigned long __offset, __save12; \
598 asm ("bras %0,1f\n" \
599 "0:\t.long _GLOBAL_OFFSET_TABLE_-0b\n\t" \
600 ".long __tls_get_offset@plt-0b\n\t" \
601 ".long " #x "@tlsgd\n" \
602 "1:\tlr %1,%%r12\n\t" \
603 "l %%r12,0(%0)\n\t" \
604 "la %%r12,0(%%r12,%0)\n\t" \
607 "bas %%r14,0(%%r1,%0):tls_gdcall:" #x "\n\t" \
610 : "=&a" (__offset), "=&a" (__save12) \
611 : : "cc", "0", "1", "2", "3", "4", "5" ); \
612 (int *) (__builtin_thread_pointer() + __offset); })
615 ({ unsigned long __offset; \
616 asm ("bras %0,1f\n" \
617 "0:\t.long _GLOBAL_OFFSET_TABLE_\n\t" \
618 ".long __tls_get_offset@plt\n\t" \
619 ".long " #x "@tlsgd\n" \
620 "1:\tl %%r12,0(%0)\n\t" \
623 "bas %%r14,0(%%r1):tls_gdcall:" #x "\n\t" \
625 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
626 (int *) (__builtin_thread_pointer() + __offset); })
629 #elif defined __powerpc__ && !defined __powerpc64__
631 # define __TLS_CALL_CLOBBERS \
632 "0", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", \
633 "lr", "ctr", "cr0", "cr1", "cr5", "cr6", "cr7"
635 /* PowerPC32 Local Exec TLS access. */
638 asm ("addi %0,2," #x "@tprel" \
639 : "=r" (__result)); \
642 /* PowerPC32 Initial Exec TLS access. */
645 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
647 "lwz %0," #x "@got@tprel(%0)\n\t" \
648 "add %0,%0," #x "@tls" \
649 : "=b" (__result) : \
653 /* PowerPC32 Local Dynamic TLS access. */
656 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
658 "addi 3,3," #x "@got@tlsld\n\t" \
659 "bl __tls_get_addr@plt\n\t" \
660 "addi %0,3," #x "@dtprel" \
661 : "=r" (__result) : \
662 : __TLS_CALL_CLOBBERS); \
665 /* PowerPC32 General Dynamic TLS access. */
667 ({ register int *__result __asm__ ("r3"); \
668 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
670 "addi 3,3," #x "@got@tlsgd\n\t" \
671 "bl __tls_get_addr@plt" \
673 : __TLS_CALL_CLOBBERS); \
676 #elif defined __powerpc__ && defined __powerpc64__
678 /* PowerPC64 Local Exec TLS access. */
682 " addis %0,13," #x "@tprel@ha\n" \
683 " addi %0,%0," #x "@tprel@l\n" \
684 : "=b" (__result) ); \
687 /* PowerPC64 Initial Exec TLS access. */
691 " ld %0," #x "@got@tprel(2)\n" \
692 " add %0,%0," #x "@tls\n" \
693 : "=b" (__result) ); \
696 /* PowerPC64 Local Dynamic TLS access. */
700 " addi 3,2," #x "@got@tlsld\n" \
701 " bl .__tls_get_addr\n" \
703 " addis %0,3," #x "@dtprel@ha\n" \
704 " addi %0,%0," #x "@dtprel@l\n" \
705 : "=b" (__result) : \
706 : "0", "3", "4", "5", "6", "7", \
707 "8", "9", "10", "11", "12", \
709 "cr0", "cr1", "cr5", "cr6", "cr7"); \
712 /* PowerPC64 General Dynamic TLS access. */
716 " addi 3,2," #x "@got@tlsgd\n" \
717 " bl .__tls_get_addr\n" \
720 : "=b" (__result) : \
721 : "0", "3", "4", "5", "6", "7", \
722 "8", "9", "10", "11", "12", \
724 "cr0", "cr1", "cr5", "cr6", "cr7"); \
729 # error "No support for this architecture so far."