Support Intel processor model 6 and model 0x2.
[glibc.git] / elf / tls-macros.h
blob781256db1e21a9b28897300adec941faa70ca352
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 __sparc__ && defined __arch64__
446 # define TLS_LE(x) \
447 ({ int *__l; \
448 asm ("sethi %%tle_hix22(" #x "), %0" : "=r" (__l)); \
449 asm ("xor %1, %%tle_lox10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
450 asm ("add %%g7, %1, %0" : "=r" (__l) : "r" (__l)); \
451 __l; })
453 # ifdef __PIC__
454 # define TLS_LOAD_PIC \
455 ({ long pc, got; \
456 asm ("sethi %%hi(_GLOBAL_OFFSET_TABLE_-4), %1\n\t" \
457 "rd %%pc, %0\n\t" \
458 "add %1, %%lo(_GLOBAL_OFFSET_TABLE_+4), %1\n\t" \
459 "add %1, %0, %1\n\t" \
460 : "=r" (pc), "=r" (got)); \
461 got; })
462 # else
463 # define TLS_LOAD_PIC \
464 ({ long got; \
465 asm (".hidden _GLOBAL_OFFSET_TABLE_\n\t" \
466 "sethi %%hi(_GLOBAL_OFFSET_TABLE_), %0\n\t" \
467 "or %0, %%lo(_GLOBAL_OFFSET_TABLE_), %0" \
468 : "=r" (got)); \
469 got; })
470 # endif
472 # define TLS_IE(x) \
473 ({ int *__l; \
474 asm ("sethi %%tie_hi22(" #x "), %0" : "=r" (__l)); \
475 asm ("add %1, %%tie_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
476 asm ("ldx [%1 + %2], %0, %%tie_ldx(" #x ")" \
477 : "=r" (__l) : "r" (TLS_LOAD_PIC), "r" (__l)); \
478 asm ("add %%g7, %1, %0, %%tie_add(" #x ")" : "=r" (__l) : "r" (__l)); \
479 __l; })
481 # define TLS_LD(x) \
482 ({ int *__l; register void *__o0 asm ("%o0"); \
483 long __o; \
484 asm ("sethi %%tldm_hi22(" #x "), %0" : "=r" (__l)); \
485 asm ("add %1, %%tldm_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
486 asm ("add %1, %2, %0, %%tldm_add(" #x ")" \
487 : "=r" (__o0) : "r" (TLS_LOAD_PIC), "r" (__l)); \
488 asm ("call __tls_get_addr, %%tgd_call(" #x ")\n\t" \
489 " nop" \
490 : "=r" (__o0) : "0" (__o0) \
491 : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
492 "o5", "o7", "cc"); \
493 asm ("sethi %%tldo_hix22(" #x "), %0" : "=r" (__o)); \
494 asm ("xor %1, %%tldo_lox10(" #x "), %0" : "=r" (__o) : "r" (__o)); \
495 asm ("add %1, %2, %0, %%tldo_add(" #x ")" : "=r" (__l) \
496 : "r" (__o0), "r" (__o)); \
497 __l; })
499 # define TLS_GD(x) \
500 ({ int *__l; register void *__o0 asm ("%o0"); \
501 asm ("sethi %%tgd_hi22(" #x "), %0" : "=r" (__l)); \
502 asm ("add %1, %%tgd_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
503 asm ("add %1, %2, %0, %%tgd_add(" #x ")" \
504 : "=r" (__o0) : "r" (TLS_LOAD_PIC), "r" (__l)); \
505 asm ("call __tls_get_addr, %%tgd_call(" #x ")\n\t" \
506 " nop" \
507 : "=r" (__o0) : "0" (__o0) \
508 : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
509 "o5", "o7", "cc"); \
510 __o0; })
512 #elif defined __s390x__
514 # define TLS_LE(x) \
515 ({ unsigned long __offset; \
516 asm ("bras %0,1f\n" \
517 "0:\t.quad " #x "@ntpoff\n" \
518 "1:\tlg %0,0(%0)" \
519 : "=a" (__offset) : : "cc" ); \
520 (int *) (__builtin_thread_pointer() + __offset); })
522 # ifdef PIC
523 # define TLS_IE(x) \
524 ({ unsigned long __offset; \
525 asm ("bras %0,1f\n" \
526 "0:\t.quad " #x "@gotntpoff\n" \
527 "1:\tlg %0,0(%0)\n\t" \
528 "lg %0,0(%0,%%r12):tls_load:" #x \
529 : "=&a" (__offset) : : "cc" ); \
530 (int *) (__builtin_thread_pointer() + __offset); })
531 # else
532 # define TLS_IE(x) \
533 ({ unsigned long __offset; \
534 asm ("bras %0,1f\n" \
535 "0:\t.quad " #x "@indntpoff\n" \
536 "1:\t lg %0,0(%0)\n\t" \
537 "lg %0,0(%0):tls_load:" #x \
538 : "=&a" (__offset) : : "cc" ); \
539 (int *) (__builtin_thread_pointer() + __offset); })
540 # endif
542 # ifdef PIC
543 # define TLS_LD(x) \
544 ({ unsigned long __offset, __save12; \
545 asm ("bras %0,1f\n" \
546 "0:\t.quad " #x "@tlsldm\n\t" \
547 ".quad " #x "@dtpoff\n" \
548 "1:\tlgr %1,%%r12\n\t" \
549 "larl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
550 "lg %%r2,0(%0)\n\t" \
551 "brasl %%r14,__tls_get_offset@plt:tls_ldcall:" #x "\n\t" \
552 "lg %0,8(%0)\n\t" \
553 "algr %0,%%r2\n\t" \
554 "lgr %%r12,%1" \
555 : "=&a" (__offset), "=&a" (__save12) \
556 : : "cc", "0", "1", "2", "3", "4", "5", "14" ); \
557 (int *) (__builtin_thread_pointer() + __offset); })
558 # else
559 # define TLS_LD(x) \
560 ({ unsigned long __offset; \
561 asm ("bras %0,1f\n" \
562 "0:\t.quad " #x "@tlsldm\n\t" \
563 ".quad " #x "@dtpoff\n" \
564 "1:\tlarl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
565 "lg %%r2,0(%0)\n\t" \
566 "brasl %%r14,__tls_get_offset@plt:tls_ldcall:" #x "\n\t" \
567 "lg %0,8(%0)\n\t" \
568 "algr %0,%%r2" \
569 : "=&a" (__offset) \
570 : : "cc", "0", "1", "2", "3", "4", "5", "12", "14" ); \
571 (int *) (__builtin_thread_pointer() + __offset); })
572 # endif
574 # ifdef PIC
575 # define TLS_GD(x) \
576 ({ unsigned long __offset, __save12; \
577 asm ("bras %0,1f\n" \
578 "0:\t.quad " #x "@tlsgd\n" \
579 "1:\tlgr %1,%%r12\n\t" \
580 "larl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
581 "lg %%r2,0(%0)\n\t" \
582 "brasl %%r14,__tls_get_offset@plt:tls_gdcall:" #x "\n\t" \
583 "lgr %0,%%r2\n\t" \
584 "lgr %%r12,%1" \
585 : "=&a" (__offset), "=&a" (__save12) \
586 : : "cc", "0", "1", "2", "3", "4", "5", "14" ); \
587 (int *) (__builtin_thread_pointer() + __offset); })
588 # else
589 # define TLS_GD(x) \
590 ({ unsigned long __offset; \
591 asm ("bras %0,1f\n" \
592 "0:\t.quad " #x "@tlsgd\n" \
593 "1:\tlarl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
594 "lg %%r2,0(%0)\n\t" \
595 "brasl %%r14,__tls_get_offset@plt:tls_gdcall:" #x "\n\t" \
596 "lgr %0,%%r2" \
597 : "=&a" (__offset) \
598 : : "cc", "0", "1", "2", "3", "4", "5", "12", "14" ); \
599 (int *) (__builtin_thread_pointer() + __offset); })
600 # endif
602 #elif defined __s390__
604 # define TLS_LE(x) \
605 ({ unsigned long __offset; \
606 asm ("bras %0,1f\n" \
607 "0:\t.long " #x "@ntpoff\n" \
608 "1:\tl %0,0(%0)" \
609 : "=a" (__offset) : : "cc" ); \
610 (int *) (__builtin_thread_pointer() + __offset); })
612 # ifdef PIC
613 # define TLS_IE(x) \
614 ({ unsigned long __offset; \
615 asm ("bras %0,1f\n" \
616 "0:\t.long " #x "@gotntpoff\n" \
617 "1:\tl %0,0(%0)\n\t" \
618 "l %0,0(%0,%%r12):tls_load:" #x \
619 : "=&a" (__offset) : : "cc" ); \
620 (int *) (__builtin_thread_pointer() + __offset); })
621 # else
622 # define TLS_IE(x) \
623 ({ unsigned long __offset; \
624 asm ("bras %0,1f\n" \
625 "0:\t.long " #x "@indntpoff\n" \
626 "1:\t l %0,0(%0)\n\t" \
627 "l %0,0(%0):tls_load:" #x \
628 : "=&a" (__offset) : : "cc" ); \
629 (int *) (__builtin_thread_pointer() + __offset); })
630 # endif
632 # ifdef PIC
633 # define TLS_LD(x) \
634 ({ unsigned long __offset, __save12; \
635 asm ("bras %0,1f\n" \
636 "0:\t.long _GLOBAL_OFFSET_TABLE_-0b\n\t" \
637 ".long __tls_get_offset@plt-0b\n\t" \
638 ".long " #x "@tlsldm\n\t" \
639 ".long " #x "@dtpoff\n" \
640 "1:\tlr %1,%%r12\n\t" \
641 "l %%r12,0(%0)\n\t" \
642 "la %%r12,0(%%r12,%0)\n\t" \
643 "l %%r1,4(%0)\n\t" \
644 "l %%r2,8(%0)\n\t" \
645 "bas %%r14,0(%%r1,%0):tls_ldcall:" #x "\n\t" \
646 "l %0,12(%0)\n\t" \
647 "alr %0,%%r2\n\t" \
648 "lr %%r12,%1" \
649 : "=&a" (__offset), "=&a" (__save12) \
650 : : "cc", "0", "1", "2", "3", "4", "5" ); \
651 (int *) (__builtin_thread_pointer() + __offset); })
652 # else
653 # define TLS_LD(x) \
654 ({ unsigned long __offset; \
655 asm ("bras %0,1f\n" \
656 "0:\t.long _GLOBAL_OFFSET_TABLE_\n\t" \
657 ".long __tls_get_offset@plt\n\t" \
658 ".long " #x "@tlsldm\n\t" \
659 ".long " #x "@dtpoff\n" \
660 "1:\tl %%r12,0(%0)\n\t" \
661 "l %%r1,4(%0)\n\t" \
662 "l %%r2,8(%0)\n\t" \
663 "bas %%r14,0(%%r1):tls_ldcall:" #x "\n\t" \
664 "l %0,12(%0)\n\t" \
665 "alr %0,%%r2" \
666 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
667 (int *) (__builtin_thread_pointer() + __offset); })
668 # endif
670 # ifdef PIC
671 # define TLS_GD(x) \
672 ({ unsigned long __offset, __save12; \
673 asm ("bras %0,1f\n" \
674 "0:\t.long _GLOBAL_OFFSET_TABLE_-0b\n\t" \
675 ".long __tls_get_offset@plt-0b\n\t" \
676 ".long " #x "@tlsgd\n" \
677 "1:\tlr %1,%%r12\n\t" \
678 "l %%r12,0(%0)\n\t" \
679 "la %%r12,0(%%r12,%0)\n\t" \
680 "l %%r1,4(%0)\n\t" \
681 "l %%r2,8(%0)\n\t" \
682 "bas %%r14,0(%%r1,%0):tls_gdcall:" #x "\n\t" \
683 "lr %0,%%r2\n\t" \
684 "lr %%r12,%1" \
685 : "=&a" (__offset), "=&a" (__save12) \
686 : : "cc", "0", "1", "2", "3", "4", "5" ); \
687 (int *) (__builtin_thread_pointer() + __offset); })
688 # else
689 # define TLS_GD(x) \
690 ({ unsigned long __offset; \
691 asm ("bras %0,1f\n" \
692 "0:\t.long _GLOBAL_OFFSET_TABLE_\n\t" \
693 ".long __tls_get_offset@plt\n\t" \
694 ".long " #x "@tlsgd\n" \
695 "1:\tl %%r12,0(%0)\n\t" \
696 "l %%r1,4(%0)\n\t" \
697 "l %%r2,8(%0)\n\t" \
698 "bas %%r14,0(%%r1):tls_gdcall:" #x "\n\t" \
699 "lr %0,%%r2" \
700 : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
701 (int *) (__builtin_thread_pointer() + __offset); })
702 # endif
704 #elif defined __powerpc__
706 # define __TLS_CALL_CLOBBERS \
707 "0", "4", "5", "6", "7", "8", "9", "10", "11", "12", \
708 "lr", "ctr", "cr0", "cr1", "cr5", "cr6", "cr7"
710 # ifndef __powerpc64__
712 # include "config.h"
714 /* PowerPC32 Local Exec TLS access. */
715 # define TLS_LE(x) \
716 ({ int *__result; \
717 asm ("addi %0,2," #x "@tprel" \
718 : "=r" (__result)); \
719 __result; })
721 /* PowerPC32 Initial Exec TLS access. */
722 # ifdef HAVE_ASM_PPC_REL16
723 # define TLS_IE(x) \
724 ({ int *__result; \
725 asm ("bcl 20,31,1f\n1:\t" \
726 "mflr %0\n\t" \
727 "addis %0,%0,_GLOBAL_OFFSET_TABLE_-1b@ha\n\t" \
728 "addi %0,%0,_GLOBAL_OFFSET_TABLE_-1b@l\n\t" \
729 "lwz %0," #x "@got@tprel(%0)\n\t" \
730 "add %0,%0," #x "@tls" \
731 : "=b" (__result) : \
732 : "lr"); \
733 __result; })
734 # else
735 # define TLS_IE(x) \
736 ({ int *__result; \
737 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
738 "mflr %0\n\t" \
739 "lwz %0," #x "@got@tprel(%0)\n\t" \
740 "add %0,%0," #x "@tls" \
741 : "=b" (__result) : \
742 : "lr"); \
743 __result; })
744 # endif
746 /* PowerPC32 Local Dynamic TLS access. */
747 # ifdef HAVE_ASM_PPC_REL16
748 # define TLS_LD(x) \
749 ({ int *__result; \
750 asm ("bcl 20,31,1f\n1:\t" \
751 "mflr 3\n\t" \
752 "addis 3,3,_GLOBAL_OFFSET_TABLE_-1b@ha\n\t" \
753 "addi 3,3,_GLOBAL_OFFSET_TABLE_-1b@l\n\t" \
754 "addi 3,3," #x "@got@tlsld\n\t" \
755 "bl __tls_get_addr@plt\n\t" \
756 "addi %0,3," #x "@dtprel" \
757 : "=r" (__result) : \
758 : "3", __TLS_CALL_CLOBBERS); \
759 __result; })
760 # else
761 # define TLS_LD(x) \
762 ({ int *__result; \
763 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
764 "mflr 3\n\t" \
765 "addi 3,3," #x "@got@tlsld\n\t" \
766 "bl __tls_get_addr@plt\n\t" \
767 "addi %0,3," #x "@dtprel" \
768 : "=r" (__result) : \
769 : "3", __TLS_CALL_CLOBBERS); \
770 __result; })
771 # endif
773 /* PowerPC32 General Dynamic TLS access. */
774 # ifdef HAVE_ASM_PPC_REL16
775 # define TLS_GD(x) \
776 ({ register int *__result __asm__ ("r3"); \
777 asm ("bcl 20,31,1f\n1:\t" \
778 "mflr 3\n\t" \
779 "addis 3,3,_GLOBAL_OFFSET_TABLE_-1b@ha\n\t" \
780 "addi 3,3,_GLOBAL_OFFSET_TABLE_-1b@l\n\t" \
781 "addi 3,3," #x "@got@tlsgd\n\t" \
782 "bl __tls_get_addr@plt" \
783 : "=r" (__result) : \
784 : __TLS_CALL_CLOBBERS); \
785 __result; })
786 # else
787 # define TLS_GD(x) \
788 ({ register int *__result __asm__ ("r3"); \
789 asm ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
790 "mflr 3\n\t" \
791 "addi 3,3," #x "@got@tlsgd\n\t" \
792 "bl __tls_get_addr@plt" \
793 : "=r" (__result) : \
794 : __TLS_CALL_CLOBBERS); \
795 __result; })
796 # endif
798 # else
800 /* PowerPC64 Local Exec TLS access. */
801 # define TLS_LE(x) \
802 ({ int * __result; \
803 asm ("addis %0,13," #x "@tprel@ha\n\t" \
804 "addi %0,%0," #x "@tprel@l" \
805 : "=b" (__result) ); \
806 __result; \
808 /* PowerPC64 Initial Exec TLS access. */
809 # define TLS_IE(x) \
810 ({ int * __result; \
811 asm ("ld %0," #x "@got@tprel(2)\n\t" \
812 "add %0,%0," #x "@tls" \
813 : "=r" (__result) ); \
814 __result; \
816 # ifdef HAVE_ASM_GLOBAL_DOT_NAME
817 # define __TLS_GET_ADDR ".__tls_get_addr"
818 # else
819 # define __TLS_GET_ADDR "__tls_get_addr"
820 # endif
821 /* PowerPC64 Local Dynamic TLS access. */
822 # define TLS_LD(x) \
823 ({ int * __result; \
824 asm ("addi 3,2," #x "@got@tlsld\n\t" \
825 "bl " __TLS_GET_ADDR "\n\t" \
826 "nop \n\t" \
827 "addis %0,3," #x "@dtprel@ha\n\t" \
828 "addi %0,%0," #x "@dtprel@l" \
829 : "=b" (__result) : \
830 : "3", __TLS_CALL_CLOBBERS); \
831 __result; \
833 /* PowerPC64 General Dynamic TLS access. */
834 # define TLS_GD(x) \
835 ({ register int *__result __asm__ ("r3"); \
836 asm ("addi 3,2," #x "@got@tlsgd\n\t" \
837 "bl " __TLS_GET_ADDR "\n\t" \
838 "nop " \
839 : "=r" (__result) : \
840 : __TLS_CALL_CLOBBERS); \
841 __result; \
843 # endif
845 #elif !defined TLS_LE || !defined TLS_IE \
846 || !defined TLS_LD || !defined TLS_GD
847 # error "No support for this architecture so far."
848 #endif