*** empty log message ***
[glibc.git] / elf / tls-macros.h
blobbb243d819d1aa2b85f1f7c2ad3655fc10506cb76
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 #x ":\t.long 0\n\t" \
13 ".size " #x ",4\n\t" \
14 ".previous")
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. */
20 #ifdef __i386__
21 # define TLS_LE(x) \
22 ({ int *__l; \
23 asm ("movl %%gs:0,%0\n\t" \
24 "subl $" #x "@tpoff,%0" \
25 : "=r" (__l)); \
26 __l; })
28 # ifdef PIC
29 # define TLS_IE(x) \
30 ({ int *__l; \
31 asm ("movl %%gs:0,%0\n\t" \
32 "subl " #x "@gottpoff(%%ebx),%0" \
33 : "=r" (__l)); \
34 __l; })
35 # else
36 # define TLS_IE(x) \
37 ({ int *__l, __b; \
38 asm ("call 1f\n\t" \
39 ".subsection 1\n" \
40 "1:\tmovl (%%esp), %%ebx\n\t" \
41 "ret\n\t" \
42 ".previous\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)); \
47 __l; })
48 # endif
50 # ifdef PIC
51 # define TLS_LD(x) \
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)); \
57 __l; })
58 # else
59 # define TLS_LD(x) \
60 ({ int *__l, __b, __c, __d; \
61 asm ("call 1f\n\t" \
62 ".subsection 1\n" \
63 "1:\tmovl (%%esp), %%ebx\n\t" \
64 "ret\n\t" \
65 ".previous\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)); \
71 __l; })
72 # endif
74 # ifdef PIC
75 # define TLS_GD(x) \
76 ({ int *__l, __c, __d; \
77 asm ("leal " #x "@tlsgd(%%ebx),%%eax\n\t" \
78 "call ___tls_get_addr@plt\n\t" \
79 "nop" \
80 : "=a" (__l), "=&c" (__c), "=&d" (__d)); \
81 __l; })
82 # else
83 # define TLS_GD(x) \
84 ({ int *__l, __b, __c, __d; \
85 asm ("call 1f\n\t" \
86 ".subsection 1\n" \
87 "1:\tmovl (%%esp), %%ebx\n\t" \
88 "ret\n\t" \
89 ".previous\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" \
93 "nop" \
94 : "=a" (__l), "=&b" (__b), "=&c" (__c), "=&d" (__d)); \
95 __l; })
96 # endif
98 #elif defined __x86_64__
100 # define TLS_LE(x) \
101 ({ int *__l; \
102 asm ("movq %%fs:0,%0\n\t" \
103 "leaq " #x "@tpoff(%0), %0" \
104 : "=r" (__l)); \
105 __l; })
107 # define TLS_IE(x) \
108 ({ int *__l; \
109 asm ("movq %%fs:0,%0\n\t" \
110 "addq " #x "@gottpoff(%%rip),%0" \
111 : "=r" (__l)); \
112 __l; })
114 # define TLS_LD(x) \
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"); \
121 __l; })
123 # define TLS_GD(x) \
124 ({ int *__l, __c, __d; \
125 asm (".byte 0x66\n\t" \
126 "leaq " #x "@tlsgd(%%rip),%%rdi\n\t" \
127 ".word 0x6666\n\t" \
128 "rex64\n\t" \
129 "call __tls_get_addr@plt" \
130 : "=a" (__l), "=&c" (__c), "=&d" (__d) \
131 : : "rdi", "rsi", "r8", "r9", "r10", "r11"); \
132 __l; })
134 #elif defined __sh__
136 # define TLS_LE(x) \
137 ({ int *__l; void *__tp; \
138 asm ("stc gbr,%1\n\t" \
139 "mov.l 1f,%0\n\t" \
140 "bra 2f\n\t" \
141 " add %1,%0\n\t" \
142 ".align 2\n\t" \
143 "1: .long " #x "@tpoff\n\t" \
144 "2:" \
145 : "=r" (__l), "=r" (__tp)); \
146 __l; })
148 # ifdef PIC
149 # define TLS_IE(x) \
150 ({ int *__l; void *__tp; \
151 register void *__gp __asm__("r12"); \
152 asm ("mov.l 1f,r0\n\t" \
153 "stc gbr,%1\n\t" \
154 "mov.l @(r0,r12),%0\n\t" \
155 "bra 2f\n\t" \
156 " add %1,%0\n\t" \
157 ".align 2\n\t" \
158 "1: .long " #x "@gottpoff\n\t" \
159 "2:" \
160 : "=r" (__l), "=r" (__tp) : "r" (__gp) : "r0"); \
161 __l; })
162 # else
163 # define TLS_IE(x) \
164 ({ int *__l; void *__tp; \
165 asm ("mov.l r12,@-r15\n\t" \
166 "mova 0f,r0\n\t" \
167 "mov.l 0f,r12\n\t" \
168 "add r0,r12\n\t" \
169 "mov.l 1f,r0\n\t" \
170 "stc gbr,%1\n\t" \
171 "mov.l @(r0,r12),%0\n\t" \
172 "bra 2f\n\t" \
173 " add %1,%0\n\t" \
174 ".align 2\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"); \
179 __l; })
180 #endif
182 # ifdef PIC
183 # define TLS_LD(x) \
184 ({ int *__l; \
185 register void *__gp __asm__("r12"); \
186 asm ("mov.l 1f,r4\n\t" \
187 "mova 2f,r0\n\t" \
188 "mov.l 2f,r1\n\t" \
189 "add r0,r1\n\t" \
190 "jsr @r1\n\t" \
191 " add r12,r4\n\t" \
192 "bra 4f\n\t" \
193 " nop\n\t" \
194 ".align 2\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" \
198 "bra 5f\n\t" \
199 " add r0,%0\n\t" \
200 ".align 2\n\t" \
201 "3: .long " #x "@dtpoff\n\t" \
202 "5:" \
203 : "=r" (__l) : "r" (__gp) : "r0", "r1", "r2", "r3", "r4", "r5", \
204 "r6", "r7", "pr", "t"); \
205 __l; })
206 # else
207 # define TLS_LD(x) \
208 ({ int *__l; \
209 asm ("mov.l r12,@-r15\n\t" \
210 "mova 0f,r0\n\t" \
211 "mov.l 0f,r12\n\t" \
212 "add r0,r12\n\t" \
213 "mov.l 1f,r4\n\t" \
214 "mova 2f,r0\n\t" \
215 "mov.l 2f,r1\n\t" \
216 "add r0,r1\n\t" \
217 "jsr @r1\n\t" \
218 " add r12,r4\n\t" \
219 "bra 4f\n\t" \
220 " nop\n\t" \
221 ".align 2\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" \
226 "bra 5f\n\t" \
227 " add r0,%0\n\t" \
228 ".align 2\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", \
232 "pr", "t"); \
233 __l; })
234 #endif
236 # ifdef PIC
237 # define TLS_GD(x) \
238 ({ int *__l; \
239 register void *__gp __asm__("r12"); \
240 asm ("mov.l 1f,r4\n\t" \
241 "mova 2f,r0\n\t" \
242 "mov.l 2f,r1\n\t" \
243 "add r0,r1\n\t" \
244 "jsr @r1\n\t" \
245 " add r12,r4\n\t" \
246 "bra 3f\n\t" \
247 " mov r0,%0\n\t" \
248 ".align 2\n\t" \
249 "1: .long " #x "@tlsgd\n\t" \
250 "2: .long __tls_get_addr@plt\n\t" \
251 "3:" \
252 : "=r" (__l) : "r" (__gp) : "r0", "r1", "r2", "r3", "r4", "r5", \
253 "r6", "r7", "pr", "t"); \
254 __l; })
255 # else
256 # define TLS_GD(x) \
257 ({ int *__l; \
258 asm ("mov.l r12,@-r15\n\t" \
259 "mova 0f,r0\n\t" \
260 "mov.l 0f,r12\n\t" \
261 "add r0,r12\n\t" \
262 "mov.l 1f,r4\n\t" \
263 "mova 2f,r0\n\t" \
264 "mov.l 2f,r1\n\t" \
265 "add r0,r1\n\t" \
266 "jsr @r1\n\t" \
267 " add r12,r4\n\t" \
268 "bra 3f\n\t" \
269 " mov r0,%0\n\t" \
270 ".align 2\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", \
276 "pr", "t"); \
277 __l; })
278 #endif
280 #elif defined __alpha__
282 register void *__gp __asm__("$29");
284 # define TLS_LE(x) \
285 ({ int *__l; \
286 asm ("call_pal 158\n\tlda $0," #x "($0)\t\t!tprel" : "=v"(__l)); \
287 __l; })
289 # define TLS_IE(x) \
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); })
295 # define TLS_LD(x) \
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)); \
300 __l; })
302 # define TLS_GD(x) \
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__
310 # define TLS_LE(x) \
311 ({ void *__l; \
312 asm ("mov r2=r13\n\t" \
313 ";;\n\t" \
314 "addl %0=@tprel(" #x "),r2\n\t" \
315 : "=r" (__l) : : "r2" ); __l; })
317 # define TLS_IE(x) \
318 ({ void *__l; \
319 register long __gp asm ("gp"); \
320 asm (";;\n\t" \
321 "addl r16=@ltoff(@tprel(" #x ")),gp\n\t" \
322 ";;\n\t" \
323 "ld8 r17=[r16]\n\t" \
324 ";;\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", \
334 "b6", "b7", \
335 "out0", "out1", "out2", "out3", "out4", "out5", "out6", "out7"
337 # define TLS_LD(x) \
338 ({ void *__l; \
339 register long __gp asm ("gp"); \
340 asm (";;\n\t" \
341 "mov loc0=gp\n\t" \
342 "addl r16=@ltoff(@dtpmod(" #x ")),gp\n\t" \
343 "addl out1=@dtprel(" #x "),r0\n\t" \
344 ";;\n\t" \
345 "ld8 out0=[r16]\n\t" \
346 "br.call.sptk.many b0=__tls_get_addr" \
347 ";;\n\t" \
348 "mov gp=loc0\n\t" \
349 "mov %0=r8\n\t" \
350 : "=r" (__l) : "r" (__gp) : "loc0", __TLS_CALL_CLOBBERS); \
351 __l; })
353 # define TLS_GD(x) \
354 ({ void *__l; \
355 register long __gp asm ("gp"); \
356 asm (";;\n\t" \
357 "mov loc0=gp\n\t" \
358 "addl r16=@ltoff(@dtpmod(" #x ")),gp\n\t" \
359 "addl r17=@ltoff(@dtprel(" #x ")),gp\n\t" \
360 ";;\n\t" \
361 "ld8 out0=[r16]\n\t" \
362 "ld8 out1=[r17]\n\t" \
363 "br.call.sptk.many b0=__tls_get_addr" \
364 ";;\n\t" \
365 "mov gp=loc0\n\t" \
366 "mov %0=r8\n\t" \
367 : "=r" (__l) : "r" (__gp) : "loc0", __TLS_CALL_CLOBBERS); \
368 __l; })
370 #elif defined __sparc__ && !defined __arch64__
372 # define TLS_LE(x) \
373 ({ int *__l; \
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)); \
377 __l; })
379 # ifdef __PIC__
380 # define TLS_LOAD_PIC \
381 ({ register long pc __asm__ ("%o7"); \
382 long got; \
383 asm ("sethi %%hi(_GLOBAL_OFFSET_TABLE_-4), %1\n\t" \
384 "call .+8\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)); \
388 got; })
389 # else
390 # define TLS_LOAD_PIC \
391 ({ long got; \
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" \
395 : "=r" (got)); \
396 got; })
397 # endif
399 # define TLS_IE(x) \
400 ({ int *__l; \
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)); \
406 __l; })
408 # define TLS_LD(x) \
409 ({ int *__l; register void *__o0 asm ("%o0"); \
410 long __o; \
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" \
416 " nop" \
417 : "=r" (__o0) : "0" (__o0) \
418 : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
419 "o5", "o7", "cc"); \
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)); \
424 __l; })
426 # define TLS_GD(x) \
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" \
433 " nop" \
434 : "=r" (__o0) : "0" (__o0) \
435 : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
436 "o5", "o7", "cc"); \
437 __o0; })
439 #elif defined __s390x__
441 # define TLS_LE(x) \
442 ({ unsigned long __offset; \
443 asm ("bras %0,1f\n" \
444 "0:\t.quad " #x "@ntpoff\n" \
445 "1:\tlg %0,0(%0)" \
446 : "=a" (__offset) : : "cc" ); \
447 (int *) (__builtin_thread_pointer() + __offset); })
449 # ifdef PIC
450 # define TLS_IE(x) \
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); })
458 # else
459 # define TLS_IE(x) \
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); })
467 # endif
469 # ifdef PIC
470 # define TLS_LD(x) \
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" \
479 "lg %0,8(%0)\n\t" \
480 "algr %0,%%r2\n\t" \
481 "lgr %%r12,%1" \
482 : "=&a" (__offset), "=&a" (__save12) \
483 : : "cc", "0", "1", "2", "3", "4", "5" ); \
484 (int *) (__builtin_thread_pointer() + __offset); })
485 # else
486 # define TLS_LD(x) \
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" \
494 "lg %0,8(%0)\n\t" \
495 "algr %0,%%r2" \
496 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
497 (int *) (__builtin_thread_pointer() + __offset); })
498 # endif
500 # ifdef PIC
501 # define TLS_GD(x) \
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" \
509 "lgr %0,%%r2\n\t" \
510 "lgr %%r12,%1" \
511 : "=&a" (__offset), "=&a" (__save12) \
512 : : "cc", "0", "1", "2", "3", "4", "5" ); \
513 (int *) (__builtin_thread_pointer() + __offset); })
514 # else
515 # define TLS_GD(x) \
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" \
522 "lgr %0,%%r2" \
523 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
524 (int *) (__builtin_thread_pointer() + __offset); })
525 # endif
527 #elif defined __s390__
529 # define TLS_LE(x) \
530 ({ unsigned long __offset; \
531 asm ("bras %0,1f\n" \
532 "0:\t.long " #x "@ntpoff\n" \
533 "1:\tl %0,0(%0)" \
534 : "=a" (__offset) : : "cc" ); \
535 (int *) (__builtin_thread_pointer() + __offset); })
537 # ifdef PIC
538 # define TLS_IE(x) \
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); })
546 # else
547 # define TLS_IE(x) \
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); })
555 # endif
557 # ifdef PIC
558 # define TLS_LD(x) \
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" \
568 "l %%r1,4(%0)\n\t" \
569 "l %%r2,8(%0)\n\t" \
570 "bas %%r14,0(%%r1,%0):tls_ldcall:" #x "\n\t" \
571 "l %0,12(%0)\n\t" \
572 "alr %0,%%r2\n\t" \
573 "lr %%r12,%1" \
574 : "=&a" (__offset), "=&a" (__save12) \
575 : : "cc", "0", "1", "2", "3", "4", "5" ); \
576 (int *) (__builtin_thread_pointer() + __offset); })
577 # else
578 # define TLS_LD(x) \
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" \
586 "l %%r1,4(%0)\n\t" \
587 "l %%r2,8(%0)\n\t" \
588 "bas %%r14,0(%%r1):tls_ldcall:" #x "\n\t" \
589 "l %0,12(%0)\n\t" \
590 "alr %0,%%r2" \
591 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
592 (int *) (__builtin_thread_pointer() + __offset); })
593 # endif
595 # ifdef PIC
596 # define TLS_GD(x) \
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" \
605 "l %%r1,4(%0)\n\t" \
606 "l %%r2,8(%0)\n\t" \
607 "bas %%r14,0(%%r1,%0):tls_gdcall:" #x "\n\t" \
608 "lr %0,%%r2\n\t" \
609 "lr %%r12,%1" \
610 : "=&a" (__offset), "=&a" (__save12) \
611 : : "cc", "0", "1", "2", "3", "4", "5" ); \
612 (int *) (__builtin_thread_pointer() + __offset); })
613 # else
614 # define TLS_GD(x) \
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" \
621 "l %%r1,4(%0)\n\t" \
622 "l %%r2,8(%0)\n\t" \
623 "bas %%r14,0(%%r1):tls_gdcall:" #x "\n\t" \
624 "lr %0,%%r2" \
625 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
626 (int *) (__builtin_thread_pointer() + __offset); })
627 # endif
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. */
636 # define TLS_LE(x) \
637 ({ int *__result; \
638 asm ("addi %0,2," #x "@tprel" \
639 : "=r" (__result)); \
640 __result; })
642 /* PowerPC32 Initial Exec TLS access. */
643 # define TLS_IE(x) \
644 ({ int *__result; \
645 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
646 "mflr %0\n\t" \
647 "lwz %0," #x "@got@tprel(%0)\n\t" \
648 "add %0,%0," #x "@tls" \
649 : "=b" (__result) : \
650 : "lr"); \
651 __result; })
653 /* PowerPC32 Local Dynamic TLS access. */
654 # define TLS_LD(x) \
655 ({ int *__result; \
656 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
657 "mflr 3\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); \
663 __result; })
665 /* PowerPC32 General Dynamic TLS access. */
666 # define TLS_GD(x) \
667 ({ register int *__result __asm__ ("r3"); \
668 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
669 "mflr 3\n\t" \
670 "addi 3,3," #x "@got@tlsgd\n\t" \
671 "bl __tls_get_addr@plt" \
672 : : \
673 : __TLS_CALL_CLOBBERS); \
674 __result; })
676 #elif defined __powerpc__ && defined __powerpc64__
678 /* PowerPC64 Local Exec TLS access. */
679 # define TLS_LE(x) \
680 ({ int * __result; \
681 asm ( \
682 " addis %0,13," #x "@tprel@ha\n" \
683 " addi %0,%0," #x "@tprel@l\n" \
684 : "=b" (__result) ); \
685 __result; \
687 /* PowerPC64 Initial Exec TLS access. */
688 # define TLS_IE(x) \
689 ({ int * __result; \
690 asm ( \
691 " ld %0," #x "@got@tprel(2)\n" \
692 " add %0,%0," #x "@tls\n" \
693 : "=b" (__result) ); \
694 __result; \
696 /* PowerPC64 Local Dynamic TLS access. */
697 # define TLS_LD(x) \
698 ({ int * __result; \
699 asm ( \
700 " addi 3,2," #x "@got@tlsld\n" \
701 " bl .__tls_get_addr\n" \
702 " nop \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", \
708 "lr", "ctr", \
709 "cr0", "cr1", "cr5", "cr6", "cr7"); \
710 __result; \
712 /* PowerPC64 General Dynamic TLS access. */
713 # define TLS_GD(x) \
714 ({ int * __result; \
715 asm ( \
716 " addi 3,2," #x "@got@tlsgd\n" \
717 " bl .__tls_get_addr\n" \
718 " nop \n" \
719 " mr %0,3\n" \
720 : "=b" (__result) : \
721 : "0", "3", "4", "5", "6", "7", \
722 "8", "9", "10", "11", "12", \
723 "lr", "ctr", \
724 "cr0", "cr1", "cr5", "cr6", "cr7"); \
725 __result; \
728 #else
729 # error "No support for this architecture so far."
730 #endif