tls-macros.h 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. /* Macros to support TLS testing in times of missing compiler support. */
  2. #define COMMON_INT_DEF(x) \
  3. __asm__ (".tls_common " #x ",4,4")
  4. /* XXX Until we get compiler support we don't need declarations. */
  5. #define COMMON_INT_DECL(x)
  6. /* XXX This definition will probably be machine specific, too. */
  7. #define VAR_INT_DEF(x) \
  8. __asm__ (".section .tdata\n\t" \
  9. ".globl " #x "\n" \
  10. ".balign 4\n" \
  11. #x ":\t.long 0\n\t" \
  12. ".size " #x ",4\n\t" \
  13. ".previous")
  14. /* XXX Until we get compiler support we don't need declarations. */
  15. #define VAR_INT_DECL(x)
  16. #ifdef __mips__
  17. #include <tls-macros-mips.h>
  18. #endif
  19. #ifdef __arm__
  20. #ifdef __thumb__
  21. #include <tls-macros-thumb.h>
  22. #else
  23. #include <tls-macros-arm.h>
  24. #endif
  25. #endif
  26. /* XXX Each architecture must have its own asm for now. */
  27. #ifdef __i386__
  28. # define TLS_LE(x) \
  29. ({ int *__l; \
  30. __asm__ ("movl %%gs:0,%0\n\t" \
  31. "subl $" #x "@tpoff,%0" \
  32. : "=r" (__l)); \
  33. __l; })
  34. # ifdef __PIC__
  35. # define TLS_IE(x) \
  36. ({ int *__l; \
  37. __asm__ ("movl %%gs:0,%0\n\t" \
  38. "subl " #x "@gottpoff(%%ebx),%0" \
  39. : "=r" (__l)); \
  40. __l; })
  41. # else
  42. # define TLS_IE(x) \
  43. ({ int *__l; \
  44. __asm__ ("call 1f\n\t" \
  45. ".subsection 1\n" \
  46. "1:\tmovl (%%esp), %%ebx\n\t" \
  47. "ret\n\t" \
  48. ".previous\n\t" \
  49. "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t" \
  50. "movl %%gs:0,%0\n\t" \
  51. "subl " #x "@gottpoff(%%ebx),%0" \
  52. : "=r" (__l)); \
  53. __l; })
  54. # endif
  55. # ifdef __PIC__
  56. # define TLS_LD(x) \
  57. ({ int *__l, __c, __d; \
  58. __asm__ ("leal " #x "@tlsldm(%%ebx),%%eax\n\t" \
  59. "call ___tls_get_addr@plt\n\t" \
  60. "leal " #x "@dtpoff(%%eax), %%eax" \
  61. : "=a" (__l), "=&c" (__c), "=&d" (__d)); \
  62. __l; })
  63. # else
  64. # define TLS_LD(x) \
  65. ({ int *__l, __b, __c, __d; \
  66. __asm__ ("call 1f\n\t" \
  67. ".subsection 1\n" \
  68. "1:\tmovl (%%esp), %%ebx\n\t" \
  69. "ret\n\t" \
  70. ".previous\n\t" \
  71. "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t" \
  72. "leal " #x "@tlsldm(%%ebx),%%eax\n\t" \
  73. "call ___tls_get_addr@plt\n\t" \
  74. "leal " #x "@dtpoff(%%eax), %%eax" \
  75. : "=a" (__l), "=&b" (__b), "=&c" (__c), "=&d" (__d)); \
  76. __l; })
  77. # endif
  78. # ifdef __PIC__
  79. # define TLS_GD(x) \
  80. ({ int *__l, __c, __d; \
  81. __asm__ ("leal " #x "@tlsgd(%%ebx),%%eax\n\t" \
  82. "call ___tls_get_addr@plt\n\t" \
  83. "nop" \
  84. : "=a" (__l), "=&c" (__c), "=&d" (__d)); \
  85. __l; })
  86. # else
  87. # define TLS_GD(x) \
  88. ({ int *__l, __c, __d; \
  89. __asm__ ("call 1f\n\t" \
  90. ".subsection 1\n" \
  91. "1:\tmovl (%%esp), %%ebx\n\t" \
  92. "ret\n\t" \
  93. ".previous\n\t" \
  94. "addl $_GLOBAL_OFFSET_TABLE_, %%ebx\n\t" \
  95. "leal " #x "@tlsgd(%%ebx),%%eax\n\t" \
  96. "call ___tls_get_addr@plt\n\t" \
  97. "nop" \
  98. : "=a" (__l), "=&c" (__c), "=&d" (__d)); \
  99. __l; })
  100. # endif
  101. #elif defined __x86_64__
  102. # define TLS_LE(x) \
  103. ({ int *__l; \
  104. __asm__ ("mov %%fs:0,%0\n\t" \
  105. "lea " #x "@tpoff(%0), %0" \
  106. : "=r" (__l)); \
  107. __l; })
  108. # define TLS_IE(x) \
  109. ({ int *__l; \
  110. __asm__ ("mov %%fs:0,%0\n\t" \
  111. "add " #x "@gottpoff(%%rip),%0" \
  112. : "=r" (__l)); \
  113. __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; })
  122. # ifdef __ILP32__
  123. # define TLS_GD_PREFIX
  124. # else
  125. # define TLS_GD_PREFIX ".byte 0x66\n\t"
  126. # endif
  127. # define TLS_GD(x) \
  128. ({ int *__l, __c, __d; \
  129. __asm__ (TLS_GD_PREFIX \
  130. "leaq " #x "@tlsgd(%%rip),%%rdi\n\t" \
  131. ".word 0x6666\n\t" \
  132. "rex64\n\t" \
  133. "call __tls_get_addr@plt" \
  134. : "=a" (__l), "=&c" (__c), "=&d" (__d) \
  135. : : "rdi", "rsi", "r8", "r9", "r10", "r11"); \
  136. __l; })
  137. #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; })
  149. # ifdef __PIC__
  150. # define TLS_IE(x) \
  151. ({ int *__l; void *__tp; \
  152. register void *__gp __asm__("r12"); \
  153. __asm__ ("mov.l 1f,r0\n\t" \
  154. "stc gbr,%1\n\t" \
  155. "mov.l @(r0,r12),%0\n\t" \
  156. "bra 2f\n\t" \
  157. " add %1,%0\n\t" \
  158. ".align 2\n\t" \
  159. "1: .long " #x "@gottpoff\n\t" \
  160. "2:" \
  161. : "=r" (__l), "=r" (__tp) : "r" (__gp) : "r0"); \
  162. __l; })
  163. # else
  164. # define TLS_IE(x) \
  165. ({ int *__l; void *__tp; \
  166. __asm__ ("mov.l r12,@-r15\n\t" \
  167. "mova 0f,r0\n\t" \
  168. "mov.l 0f,r12\n\t" \
  169. "add r0,r12\n\t" \
  170. "mov.l 1f,r0\n\t" \
  171. "stc gbr,%1\n\t" \
  172. "mov.l @(r0,r12),%0\n\t" \
  173. "bra 2f\n\t" \
  174. " add %1,%0\n\t" \
  175. ".align 2\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"); \
  180. __l; })
  181. #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
  235. # ifdef __PIC__
  236. # define TLS_GD(x) \
  237. ({ int *__l; \
  238. register void *__gp __asm__("r12"); \
  239. __asm__ ("mov.l 1f,r4\n\t" \
  240. "mova 2f,r0\n\t" \
  241. "mov.l 2f,r1\n\t" \
  242. "add r0,r1\n\t" \
  243. "jsr @r1\n\t" \
  244. " add r12,r4\n\t" \
  245. "bra 3f\n\t" \
  246. " mov r0,%0\n\t" \
  247. ".align 2\n\t" \
  248. "1: .long " #x "@tlsgd\n\t" \
  249. "2: .long __tls_get_addr@plt\n\t" \
  250. "3:" \
  251. : "=r" (__l) : "r" (__gp) : "r0", "r1", "r2", "r3", "r4", "r5", \
  252. "r6", "r7", "pr", "t"); \
  253. __l; })
  254. # else
  255. # define TLS_GD(x) \
  256. ({ int *__l; \
  257. __asm__ ("mov.l r12,@-r15\n\t" \
  258. "mova 0f,r0\n\t" \
  259. "mov.l 0f,r12\n\t" \
  260. "add r0,r12\n\t" \
  261. "mov.l 1f,r4\n\t" \
  262. "mova 2f,r0\n\t" \
  263. "mov.l 2f,r1\n\t" \
  264. "add r0,r1\n\t" \
  265. "jsr @r1\n\t" \
  266. " add r12,r4\n\t" \
  267. "bra 3f\n\t" \
  268. " mov r0,%0\n\t" \
  269. ".align 2\n\t" \
  270. "1: .long " #x "@tlsgd\n\t" \
  271. "2: .long __tls_get_addr@plt\n\t" \
  272. "0: .long _GLOBAL_OFFSET_TABLE_\n\t" \
  273. "3: mov.l @r15+,r12" \
  274. : "=r" (__l) : : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
  275. "pr", "t"); \
  276. __l; })
  277. #endif
  278. #elif defined __alpha__
  279. register void *__gp __asm__("$29");
  280. # define TLS_LE(x) \
  281. ({ int *__l; \
  282. __asm__ ("call_pal 158\n\tlda $0," #x "($0)\t\t!tprel" : "=v"(__l)); \
  283. __l; })
  284. # define TLS_IE(x) \
  285. ({ char *__tp; unsigned long __o; \
  286. __asm__ ("call_pal 158\n\tldq %1," #x "($gp)\t\t!gottprel" \
  287. : "=v"(__tp), "=r"(__o) : "r"(__gp)); \
  288. (int *)(__tp + __o); })
  289. # define TLS_LD(x) \
  290. ({ extern void *__tls_get_addr(void *); int *__l; void *__i; \
  291. __asm__ ("lda %0," #x "($gp)\t\t!tlsldm" : "=r" (__i) : "r"(__gp)); \
  292. __i = __tls_get_addr(__i); \
  293. __asm__ ("lda %0, " #x "(%1)\t\t!dtprel" : "=r"(__l) : "r"(__i)); \
  294. __l; })
  295. # define TLS_GD(x) \
  296. ({ extern void *__tls_get_addr(void *); void *__i; \
  297. __asm__ ("lda %0," #x "($gp)\t\t!tlsgd" : "=r" (__i) : "r"(__gp)); \
  298. (int *) __tls_get_addr(__i); })
  299. #elif defined __ia64__
  300. # define TLS_LE(x) \
  301. ({ void *__l; \
  302. __asm__ ("mov r2=r13\n\t" \
  303. ";;\n\t" \
  304. "addl %0=@tprel(" #x "),r2\n\t" \
  305. : "=r" (__l) : : "r2" ); __l; })
  306. # define TLS_IE(x) \
  307. ({ void *__l; \
  308. register long __gp __asm__ ("gp"); \
  309. __asm__ (";;\n\t" \
  310. "addl r16=@ltoff(@tprel(" #x ")),gp\n\t" \
  311. ";;\n\t" \
  312. "ld8 r17=[r16]\n\t" \
  313. ";;\n\t" \
  314. "add %0=r13,r17\n\t" \
  315. ";;\n\t" \
  316. : "=r" (__l) : "r" (__gp) : "r16", "r17" ); __l; })
  317. # define __TLS_CALL_CLOBBERS \
  318. "r2", "r3", "r8", "r9", "r10", "r11", "r14", "r15", "r16", "r17", \
  319. "r18", "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", \
  320. "r27", "r28", "r29", "r30", "r31", \
  321. "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", \
  322. "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
  323. "b6", "b7", \
  324. "out0", "out1", "out2", "out3", "out4", "out5", "out6", "out7"
  325. # define TLS_LD(x) \
  326. ({ void *__l; \
  327. register long __gp __asm__ ("gp"); \
  328. __asm__ (";;\n\t" \
  329. "mov loc0=gp\n\t" \
  330. "addl r16=@ltoff(@dtpmod(" #x ")),gp\n\t" \
  331. "addl out1=@dtprel(" #x "),r0\n\t" \
  332. ";;\n\t" \
  333. "ld8 out0=[r16]\n\t" \
  334. "br.call.sptk.many b0=__tls_get_addr" \
  335. ";;\n\t" \
  336. "mov gp=loc0\n\t" \
  337. "mov %0=r8\n\t" \
  338. ";;\n\t" \
  339. : "=r" (__l) : "r" (__gp) : "loc0", __TLS_CALL_CLOBBERS); \
  340. __l; })
  341. # define TLS_GD(x) \
  342. ({ void *__l; \
  343. register long __gp __asm__ ("gp"); \
  344. __asm__ (";;\n\t" \
  345. "mov loc0=gp\n\t" \
  346. "addl r16=@ltoff(@dtpmod(" #x ")),gp\n\t" \
  347. "addl r17=@ltoff(@dtprel(" #x ")),gp\n\t" \
  348. ";;\n\t" \
  349. "ld8 out0=[r16]\n\t" \
  350. "ld8 out1=[r17]\n\t" \
  351. "br.call.sptk.many b0=__tls_get_addr" \
  352. ";;\n\t" \
  353. "mov gp=loc0\n\t" \
  354. "mov %0=r8\n\t" \
  355. ";;\n\t" \
  356. : "=r" (__l) : "r" (__gp) : "loc0", __TLS_CALL_CLOBBERS); \
  357. __l; })
  358. #elif defined __sparc__ && !defined __arch64__
  359. # define TLS_LE(x) \
  360. ({ int *__l; \
  361. __asm__ ("sethi %%tle_hix22(" #x "), %0" : "=r" (__l)); \
  362. __asm__ ("xor %1, %%tle_lox10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
  363. __asm__ ("add %%g7, %1, %0" : "=r" (__l) : "r" (__l)); \
  364. __l; })
  365. # ifdef __PIC__
  366. # define TLS_LOAD_PIC \
  367. ({ register long pc __asm__ ("%o7"); \
  368. long got; \
  369. __asm__ ("sethi %%hi(_GLOBAL_OFFSET_TABLE_-4), %1\n\t" \
  370. "call .+8\n\t" \
  371. "add %1, %%lo(_GLOBAL_OFFSET_TABLE_+4), %1\n\t" \
  372. "add %1, %0, %1\n\t" \
  373. : "=r" (pc), "=r" (got)); \
  374. got; })
  375. # else
  376. # define TLS_LOAD_PIC \
  377. ({ long got; \
  378. __asm__ (".hidden _GLOBAL_OFFSET_TABLE_\n\t" \
  379. "sethi %%hi(_GLOBAL_OFFSET_TABLE_), %0\n\t" \
  380. "or %0, %%lo(_GLOBAL_OFFSET_TABLE_), %0" \
  381. : "=r" (got)); \
  382. got; })
  383. # endif
  384. # define TLS_IE(x) \
  385. ({ int *__l; \
  386. __asm__ ("sethi %%tie_hi22(" #x "), %0" : "=r" (__l)); \
  387. __asm__ ("add %1, %%tie_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
  388. __asm__ ("ld [%1 + %2], %0, %%tie_ld(" #x ")" \
  389. : "=r" (__l) : "r" (TLS_LOAD_PIC), "r" (__l)); \
  390. __asm__ ("add %%g7, %1, %0, %%tie_add(" #x ")" : "=r" (__l) : "r" (__l)); \
  391. __l; })
  392. # define TLS_LD(x) \
  393. ({ int *__l; register void *__o0 __asm__ ("%o0"); \
  394. long __o; \
  395. __asm__ ("sethi %%tldm_hi22(" #x "), %0" : "=r" (__l)); \
  396. __asm__ ("add %1, %%tldm_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
  397. __asm__ ("add %1, %2, %0, %%tldm_add(" #x ")" \
  398. : "=r" (__o0) : "r" (TLS_LOAD_PIC), "r" (__l)); \
  399. __asm__ ("call __tls_get_addr, %%tgd_call(" #x ")\n\t" \
  400. " nop" \
  401. : "=r" (__o0) : "0" (__o0) \
  402. : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
  403. "o5", "o7", "cc"); \
  404. __asm__ ("sethi %%tldo_hix22(" #x "), %0" : "=r" (__o)); \
  405. __asm__ ("xor %1, %%tldo_lox10(" #x "), %0" : "=r" (__o) : "r" (__o)); \
  406. __asm__ ("add %1, %2, %0, %%tldo_add(" #x ")" : "=r" (__l) \
  407. : "r" (__o0), "r" (__o)); \
  408. __l; })
  409. # define TLS_GD(x) \
  410. ({ int *__l; register void *__o0 __asm__ ("%o0"); \
  411. __asm__ ("sethi %%tgd_hi22(" #x "), %0" : "=r" (__l)); \
  412. __asm__ ("add %1, %%tgd_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
  413. __asm__ ("add %1, %2, %0, %%tgd_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. __o0; })
  421. #elif defined __sparc__ && defined __arch64__
  422. # define TLS_LE(x) \
  423. ({ int *__l; \
  424. __asm__ ("sethi %%tle_hix22(" #x "), %0" : "=r" (__l)); \
  425. __asm__ ("xor %1, %%tle_lox10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
  426. __asm__ ("add %%g7, %1, %0" : "=r" (__l) : "r" (__l)); \
  427. __l; })
  428. # ifdef __PIC__
  429. # define TLS_LOAD_PIC \
  430. ({ long pc, got; \
  431. __asm__ ("sethi %%hi(_GLOBAL_OFFSET_TABLE_-4), %1\n\t" \
  432. "rd %%pc, %0\n\t" \
  433. "add %1, %%lo(_GLOBAL_OFFSET_TABLE_+4), %1\n\t" \
  434. "add %1, %0, %1\n\t" \
  435. : "=r" (pc), "=r" (got)); \
  436. got; })
  437. # else
  438. # define TLS_LOAD_PIC \
  439. ({ long got; \
  440. __asm__ (".hidden _GLOBAL_OFFSET_TABLE_\n\t" \
  441. "sethi %%hi(_GLOBAL_OFFSET_TABLE_), %0\n\t" \
  442. "or %0, %%lo(_GLOBAL_OFFSET_TABLE_), %0" \
  443. : "=r" (got)); \
  444. got; })
  445. # endif
  446. # define TLS_IE(x) \
  447. ({ int *__l; \
  448. __asm__ ("sethi %%tie_hi22(" #x "), %0" : "=r" (__l)); \
  449. __asm__ ("add %1, %%tie_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
  450. __asm__ ("ldx [%1 + %2], %0, %%tie_ldx(" #x ")" \
  451. : "=r" (__l) : "r" (TLS_LOAD_PIC), "r" (__l)); \
  452. __asm__ ("add %%g7, %1, %0, %%tie_add(" #x ")" : "=r" (__l) : "r" (__l)); \
  453. __l; })
  454. # define TLS_LD(x) \
  455. ({ int *__l; register void *__o0 __asm__ ("%o0"); \
  456. long __o; \
  457. __asm__ ("sethi %%tldm_hi22(" #x "), %0" : "=r" (__l)); \
  458. __asm__ ("add %1, %%tldm_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
  459. __asm__ ("add %1, %2, %0, %%tldm_add(" #x ")" \
  460. : "=r" (__o0) : "r" (TLS_LOAD_PIC), "r" (__l)); \
  461. __asm__ ("call __tls_get_addr, %%tgd_call(" #x ")\n\t" \
  462. " nop" \
  463. : "=r" (__o0) : "0" (__o0) \
  464. : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
  465. "o5", "o7", "cc"); \
  466. __asm__ ("sethi %%tldo_hix22(" #x "), %0" : "=r" (__o)); \
  467. __asm__ ("xor %1, %%tldo_lox10(" #x "), %0" : "=r" (__o) : "r" (__o)); \
  468. __asm__ ("add %1, %2, %0, %%tldo_add(" #x ")" : "=r" (__l) \
  469. : "r" (__o0), "r" (__o)); \
  470. __l; })
  471. # define TLS_GD(x) \
  472. ({ int *__l; register void *__o0 __asm__ ("%o0"); \
  473. __asm__ ("sethi %%tgd_hi22(" #x "), %0" : "=r" (__l)); \
  474. __asm__ ("add %1, %%tgd_lo10(" #x "), %0" : "=r" (__l) : "r" (__l)); \
  475. __asm__ ("add %1, %2, %0, %%tgd_add(" #x ")" \
  476. : "=r" (__o0) : "r" (TLS_LOAD_PIC), "r" (__l)); \
  477. __asm__ ("call __tls_get_addr, %%tgd_call(" #x ")\n\t" \
  478. " nop" \
  479. : "=r" (__o0) : "0" (__o0) \
  480. : "g1", "g2", "g3", "g4", "g5", "g6", "o1", "o2", "o3", "o4", \
  481. "o5", "o7", "cc"); \
  482. __o0; })
  483. #elif defined __s390x__
  484. # define TLS_LE(x) \
  485. ({ unsigned long __offset; \
  486. __asm__ ("bras %0,1f\n" \
  487. "0:\t.quad " #x "@ntpoff\n" \
  488. "1:\tlg %0,0(%0)" \
  489. : "=a" (__offset) : : "cc" ); \
  490. (int *) (__builtin_thread_pointer() + __offset); })
  491. # ifdef __PIC__
  492. # define TLS_IE(x) \
  493. ({ unsigned long __offset; \
  494. __asm__ ("bras %0,1f\n" \
  495. "0:\t.quad " #x "@gotntpoff\n" \
  496. "1:\tlg %0,0(%0)\n\t" \
  497. "lg %0,0(%0,%%r12):tls_load:" #x \
  498. : "=&a" (__offset) : : "cc" ); \
  499. (int *) (__builtin_thread_pointer() + __offset); })
  500. # else
  501. # define TLS_IE(x) \
  502. ({ unsigned long __offset; \
  503. __asm__ ("bras %0,1f\n" \
  504. "0:\t.quad " #x "@indntpoff\n" \
  505. "1:\t lg %0,0(%0)\n\t" \
  506. "lg %0,0(%0):tls_load:" #x \
  507. : "=&a" (__offset) : : "cc" ); \
  508. (int *) (__builtin_thread_pointer() + __offset); })
  509. # endif
  510. # ifdef __PIC__
  511. # define TLS_LD(x) \
  512. ({ unsigned long __offset, __save12; \
  513. __asm__ ("bras %0,1f\n" \
  514. "0:\t.quad " #x "@tlsldm\n\t" \
  515. ".quad " #x "@dtpoff\n" \
  516. "1:\tlgr %1,%%r12\n\t" \
  517. "larl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
  518. "lg %%r2,0(%0)\n\t" \
  519. "brasl %%r14,__tls_get_offset@plt:tls_ldcall:" #x "\n\t" \
  520. "lg %0,8(%0)\n\t" \
  521. "algr %0,%%r2\n\t" \
  522. "lgr %%r12,%1" \
  523. : "=&a" (__offset), "=&a" (__save12) \
  524. : : "cc", "0", "1", "2", "3", "4", "5", "14" ); \
  525. (int *) (__builtin_thread_pointer() + __offset); })
  526. # else
  527. # define TLS_LD(x) \
  528. ({ unsigned long __offset; \
  529. __asm__ ("bras %0,1f\n" \
  530. "0:\t.quad " #x "@tlsldm\n\t" \
  531. ".quad " #x "@dtpoff\n" \
  532. "1:\tlarl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
  533. "lg %%r2,0(%0)\n\t" \
  534. "brasl %%r14,__tls_get_offset@plt:tls_ldcall:" #x "\n\t" \
  535. "lg %0,8(%0)\n\t" \
  536. "algr %0,%%r2" \
  537. : "=&a" (__offset) \
  538. : : "cc", "0", "1", "2", "3", "4", "5", "12", "14" ); \
  539. (int *) (__builtin_thread_pointer() + __offset); })
  540. # endif
  541. # ifdef __PIC__
  542. # define TLS_GD(x) \
  543. ({ unsigned long __offset, __save12; \
  544. __asm__ ("bras %0,1f\n" \
  545. "0:\t.quad " #x "@tlsgd\n" \
  546. "1:\tlgr %1,%%r12\n\t" \
  547. "larl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
  548. "lg %%r2,0(%0)\n\t" \
  549. "brasl %%r14,__tls_get_offset@plt:tls_gdcall:" #x "\n\t" \
  550. "lgr %0,%%r2\n\t" \
  551. "lgr %%r12,%1" \
  552. : "=&a" (__offset), "=&a" (__save12) \
  553. : : "cc", "0", "1", "2", "3", "4", "5", "14" ); \
  554. (int *) (__builtin_thread_pointer() + __offset); })
  555. # else
  556. # define TLS_GD(x) \
  557. ({ unsigned long __offset; \
  558. __asm__ ("bras %0,1f\n" \
  559. "0:\t.quad " #x "@tlsgd\n" \
  560. "1:\tlarl %%r12,_GLOBAL_OFFSET_TABLE_\n\t" \
  561. "lg %%r2,0(%0)\n\t" \
  562. "brasl %%r14,__tls_get_offset@plt:tls_gdcall:" #x "\n\t" \
  563. "lgr %0,%%r2" \
  564. : "=&a" (__offset) \
  565. : : "cc", "0", "1", "2", "3", "4", "5", "12", "14" ); \
  566. (int *) (__builtin_thread_pointer() + __offset); })
  567. # endif
  568. #elif defined __s390__
  569. # define TLS_LE(x) \
  570. ({ unsigned long __offset; \
  571. __asm__ ("bras %0,1f\n" \
  572. "0:\t.long " #x "@ntpoff\n" \
  573. "1:\tl %0,0(%0)" \
  574. : "=a" (__offset) : : "cc" ); \
  575. (int *) (__builtin_thread_pointer() + __offset); })
  576. # ifdef __PIC__
  577. # define TLS_IE(x) \
  578. ({ unsigned long __offset; \
  579. __asm__ ("bras %0,1f\n" \
  580. "0:\t.long " #x "@gotntpoff\n" \
  581. "1:\tl %0,0(%0)\n\t" \
  582. "l %0,0(%0,%%r12):tls_load:" #x \
  583. : "=&a" (__offset) : : "cc" ); \
  584. (int *) (__builtin_thread_pointer() + __offset); })
  585. # else
  586. # define TLS_IE(x) \
  587. ({ unsigned long __offset; \
  588. __asm__ ("bras %0,1f\n" \
  589. "0:\t.long " #x "@indntpoff\n" \
  590. "1:\t l %0,0(%0)\n\t" \
  591. "l %0,0(%0):tls_load:" #x \
  592. : "=&a" (__offset) : : "cc" ); \
  593. (int *) (__builtin_thread_pointer() + __offset); })
  594. # endif
  595. # ifdef __PIC__
  596. # define TLS_LD(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 "@tlsldm\n\t" \
  602. ".long " #x "@dtpoff\n" \
  603. "1:\tlr %1,%%r12\n\t" \
  604. "l %%r12,0(%0)\n\t" \
  605. "la %%r12,0(%%r12,%0)\n\t" \
  606. "l %%r1,4(%0)\n\t" \
  607. "l %%r2,8(%0)\n\t" \
  608. "bas %%r14,0(%%r1,%0):tls_ldcall:" #x "\n\t" \
  609. "l %0,12(%0)\n\t" \
  610. "alr %0,%%r2\n\t" \
  611. "lr %%r12,%1" \
  612. : "=&a" (__offset), "=&a" (__save12) \
  613. : : "cc", "0", "1", "2", "3", "4", "5" ); \
  614. (int *) (__builtin_thread_pointer() + __offset); })
  615. # else
  616. # define TLS_LD(x) \
  617. ({ unsigned long __offset; \
  618. __asm__ ("bras %0,1f\n" \
  619. "0:\t.long _GLOBAL_OFFSET_TABLE_\n\t" \
  620. ".long __tls_get_offset@plt\n\t" \
  621. ".long " #x "@tlsldm\n\t" \
  622. ".long " #x "@dtpoff\n" \
  623. "1:\tl %%r12,0(%0)\n\t" \
  624. "l %%r1,4(%0)\n\t" \
  625. "l %%r2,8(%0)\n\t" \
  626. "bas %%r14,0(%%r1):tls_ldcall:" #x "\n\t" \
  627. "l %0,12(%0)\n\t" \
  628. "alr %0,%%r2" \
  629. : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
  630. (int *) (__builtin_thread_pointer() + __offset); })
  631. # endif
  632. # ifdef __PIC__
  633. # define TLS_GD(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 "@tlsgd\n" \
  639. "1:\tlr %1,%%r12\n\t" \
  640. "l %%r12,0(%0)\n\t" \
  641. "la %%r12,0(%%r12,%0)\n\t" \
  642. "l %%r1,4(%0)\n\t" \
  643. "l %%r2,8(%0)\n\t" \
  644. "bas %%r14,0(%%r1,%0):tls_gdcall:" #x "\n\t" \
  645. "lr %0,%%r2\n\t" \
  646. "lr %%r12,%1" \
  647. : "=&a" (__offset), "=&a" (__save12) \
  648. : : "cc", "0", "1", "2", "3", "4", "5" ); \
  649. (int *) (__builtin_thread_pointer() + __offset); })
  650. # else
  651. # define TLS_GD(x) \
  652. ({ unsigned long __offset; \
  653. __asm__ ("bras %0,1f\n" \
  654. "0:\t.long _GLOBAL_OFFSET_TABLE_\n\t" \
  655. ".long __tls_get_offset@plt\n\t" \
  656. ".long " #x "@tlsgd\n" \
  657. "1:\tl %%r12,0(%0)\n\t" \
  658. "l %%r1,4(%0)\n\t" \
  659. "l %%r2,8(%0)\n\t" \
  660. "bas %%r14,0(%%r1):tls_gdcall:" #x "\n\t" \
  661. "lr %0,%%r2" \
  662. : "=&a" (__offset) : : "cc", "0", "1", "2", "3", "4", "5", "12" ); \
  663. (int *) (__builtin_thread_pointer() + __offset); })
  664. # endif
  665. #elif defined __powerpc__ && !defined __powerpc64__
  666. /*#include "config.h"*/
  667. # define __TLS_CALL_CLOBBERS \
  668. "0", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", \
  669. "lr", "ctr", "cr0", "cr1", "cr5", "cr6", "cr7"
  670. /* PowerPC32 Local Exec TLS access. */
  671. # define TLS_LE(x) \
  672. ({ int *__result; \
  673. __asm__ ("addi %0,2," #x "@tprel" \
  674. : "=r" (__result)); \
  675. __result; })
  676. /* PowerPC32 Initial Exec TLS access. */
  677. # ifdef HAVE_ASM_PPC_REL16
  678. # define TLS_IE(x) \
  679. ({ int *__result; \
  680. __asm__ ("bcl 20,31,1f\n1:\t" \
  681. "mflr %0\n\t" \
  682. "addis %0,%0,_GLOBAL_OFFSET_TABLE_-1b@ha\n\t" \
  683. "addi %0,%0,_GLOBAL_OFFSET_TABLE_-1b@l\n\t" \
  684. "lwz %0," #x "@got@tprel(%0)\n\t" \
  685. "add %0,%0," #x "@tls" \
  686. : "=b" (__result) : \
  687. : "lr"); \
  688. __result; })
  689. # else
  690. # define TLS_IE(x) \
  691. ({ int *__result; \
  692. __asm__ ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
  693. "mflr %0\n\t" \
  694. "lwz %0," #x "@got@tprel(%0)\n\t" \
  695. "add %0,%0," #x "@tls" \
  696. : "=b" (__result) : \
  697. : "lr"); \
  698. __result; })
  699. # endif
  700. /* PowerPC32 Local Dynamic TLS access. */
  701. # ifdef HAVE_ASM_PPC_REL16
  702. # define TLS_LD(x) \
  703. ({ int *__result; \
  704. __asm__ ("bcl 20,31,1f\n1:\t" \
  705. "mflr 3\n\t" \
  706. "addis 3,3,_GLOBAL_OFFSET_TABLE_-1b@ha\n\t" \
  707. "addi 3,3,_GLOBAL_OFFSET_TABLE_-1b@l\n\t" \
  708. "addi 3,3," #x "@got@tlsld\n\t" \
  709. "bl __tls_get_addr@plt\n\t" \
  710. "addi %0,3," #x "@dtprel" \
  711. : "=r" (__result) : \
  712. : __TLS_CALL_CLOBBERS); \
  713. __result; })
  714. # else
  715. # define TLS_LD(x) \
  716. ({ int *__result; \
  717. __asm__ ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
  718. "mflr 3\n\t" \
  719. "addi 3,3," #x "@got@tlsld\n\t" \
  720. "bl __tls_get_addr@plt\n\t" \
  721. "addi %0,3," #x "@dtprel" \
  722. : "=r" (__result) : \
  723. : __TLS_CALL_CLOBBERS); \
  724. __result; })
  725. # endif
  726. /* PowerPC32 General Dynamic TLS access. */
  727. # ifdef HAVE_ASM_PPC_REL16
  728. # define TLS_GD(x) \
  729. ({ register int *__result __asm__ ("r3"); \
  730. __asm__ ("bcl 20,31,1f\n1:\t" \
  731. "mflr 3\n\t" \
  732. "addis 3,3,_GLOBAL_OFFSET_TABLE_-1b@ha\n\t" \
  733. "addi 3,3,_GLOBAL_OFFSET_TABLE_-1b@l\n\t" \
  734. "addi 3,3," #x "@got@tlsgd\n\t" \
  735. "bl __tls_get_addr@plt" \
  736. : : \
  737. : __TLS_CALL_CLOBBERS); \
  738. __result; })
  739. # else
  740. # define TLS_GD(x) \
  741. ({ register int *__result __asm__ ("r3"); \
  742. __asm__ ("bl _GLOBAL_OFFSET_TABLE_@local-4\n\t" \
  743. "mflr 3\n\t" \
  744. "addi 3,3," #x "@got@tlsgd\n\t" \
  745. "bl __tls_get_addr@plt" \
  746. : : \
  747. : __TLS_CALL_CLOBBERS); \
  748. __result; })
  749. # endif
  750. #elif defined __powerpc__ && defined __powerpc64__
  751. /* PowerPC64 Local Exec TLS access. */
  752. # define TLS_LE(x) \
  753. ({ int * __result; \
  754. __asm__ ( \
  755. " addis %0,13," #x "@tprel@ha\n" \
  756. " addi %0,%0," #x "@tprel@l\n" \
  757. : "=b" (__result) ); \
  758. __result; \
  759. })
  760. /* PowerPC64 Initial Exec TLS access. */
  761. # define TLS_IE(x) \
  762. ({ int * __result; \
  763. __asm__ ( \
  764. " ld %0," #x "@got@tprel(2)\n" \
  765. " add %0,%0," #x "@tls\n" \
  766. : "=b" (__result) ); \
  767. __result; \
  768. })
  769. /* PowerPC64 Local Dynamic TLS access. */
  770. # define TLS_LD(x) \
  771. ({ int * __result; \
  772. __asm__ ( \
  773. " addi 3,2," #x "@got@tlsld\n" \
  774. " bl .__tls_get_addr\n" \
  775. " nop \n" \
  776. " addis %0,3," #x "@dtprel@ha\n" \
  777. " addi %0,%0," #x "@dtprel@l\n" \
  778. : "=b" (__result) : \
  779. : "0", "3", "4", "5", "6", "7", \
  780. "8", "9", "10", "11", "12", \
  781. "lr", "ctr", \
  782. "cr0", "cr1", "cr5", "cr6", "cr7"); \
  783. __result; \
  784. })
  785. /* PowerPC64 General Dynamic TLS access. */
  786. # define TLS_GD(x) \
  787. ({ int * __result; \
  788. __asm__ ( \
  789. " addi 3,2," #x "@got@tlsgd\n" \
  790. " bl .__tls_get_addr\n" \
  791. " nop \n" \
  792. " mr %0,3\n" \
  793. : "=b" (__result) : \
  794. : "0", "3", "4", "5", "6", "7", \
  795. "8", "9", "10", "11", "12", \
  796. "lr", "ctr", \
  797. "cr0", "cr1", "cr5", "cr6", "cr7"); \
  798. __result; \
  799. })
  800. #elif defined __arc__
  801. /* For now */
  802. #define TLS_LD(x) TLS_IE(x)
  803. #define TLS_GD(x) \
  804. ({ int *__result; \
  805. __asm__ ("add r0, pcl, @" #x "@tlsgd \n" \
  806. ".tls_gd_ld " #x "`bl __tls_get_addr@plt \n" \
  807. "mov %0, r0 \n" \
  808. : "=&r" (__result) \
  809. ::"r0","r1","r2","r3","r4","r5","r6","r7", \
  810. "r8","r9","r10","r11","r12"); \
  811. __result; })
  812. #define TLS_LE(x) \
  813. ({ int *__result; \
  814. void *tp = __builtin_thread_pointer(); \
  815. __asm__ ("add %0, %1, @" #x "@tpoff \n" \
  816. : "=r" (__result) : "r"(tp)); \
  817. __result; })
  818. #define TLS_IE(x) \
  819. ({ int *__result; \
  820. void *tp = __builtin_thread_pointer(); \
  821. __asm__ ("ld %0, [pcl, @" #x "@tlsie] \n" \
  822. "add %0, %1, %0 \n" \
  823. : "=&r" (__result) : "r" (tp)); \
  824. __result; })
  825. #elif defined __xtensa__
  826. #if defined(__XTENSA_WINDOWED_ABI__)
  827. #define TLS_GD(x) \
  828. ({ int *__l; \
  829. __asm__ ("movi a8, " #x "@TLSFUNC\n\t" \
  830. "movi a10, " #x "@TLSARG\n\t" \
  831. "callx8.tls a8, " #x "@TLSCALL\n\t" \
  832. "mov %0, a10\n\t" \
  833. : "=r" (__l) \
  834. : \
  835. : "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15"); \
  836. __l; })
  837. #define TLS_LD(x) \
  838. ({ int *__l; \
  839. __asm__ ("movi a8, _TLS_MODULE_BASE_@TLSFUNC\n\t" \
  840. "movi a10, _TLS_MODULE_BASE_@TLSARG\n\t" \
  841. "callx8.tls a8, _TLS_MODULE_BASE_@TLSCALL\n\t" \
  842. "movi %0, " #x "@TPOFF\n\t" \
  843. "add %0, %0, a10\n\t" \
  844. : "=r" (__l) \
  845. : \
  846. : "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15"); \
  847. __l; })
  848. #elif defined(__XTENSA_CALL0_ABI__)
  849. #define TLS_GD(x) \
  850. ({ int *__l; \
  851. __asm__ ("movi a0, " #x "@TLSFUNC\n\t" \
  852. "movi a2, " #x "@TLSARG\n\t" \
  853. "callx0.tls a0, " #x "@TLSCALL\n\t" \
  854. "mov %0, a2\n\t" \
  855. : "=r" (__l) \
  856. : \
  857. : "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11");\
  858. __l; })
  859. #define TLS_LD(x) \
  860. ({ int *__l; \
  861. __asm__ ("movi a0, _TLS_MODULE_BASE_@TLSFUNC\n\t" \
  862. "movi a2, _TLS_MODULE_BASE_@TLSARG\n\t" \
  863. "callx0.tls a0, _TLS_MODULE_BASE_@TLSCALL\n\t" \
  864. "movi %0, " #x "@TPOFF\n\t" \
  865. "add %0, %0, a2\n\t" \
  866. : "=r" (__l) \
  867. : \
  868. : "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11");\
  869. __l; })
  870. #else
  871. #error Unsupported Xtensa ABI
  872. #endif
  873. #define TLS_IE(x) TLS_LE(x)
  874. #define TLS_LE(x) \
  875. ({ int *__l; \
  876. int __t; \
  877. __asm__ ("rur %0, threadptr\n\t" \
  878. "movi %1, " #x "@TPOFF\n\t" \
  879. "add %0, %0, %1\n\t" \
  880. : "=r" (__l), "=r" (__t) ); \
  881. __l; }); \
  882. #elif defined __metag__
  883. # define TLS_GD(x) \
  884. ({ void *__result; \
  885. extern void *__tls_get_addr (void *); \
  886. __asm__ ("MOV %0, A1LbP\n\t" \
  887. "ADD %0, %0, #(" #x "@TLSGD)" \
  888. : "=d" (__result)); \
  889. (int *)__tls_get_addr (__result); })
  890. # define TLS_LD(x) \
  891. ({ void *__result; \
  892. extern void *__tls_get_addr (void *); \
  893. __asm__ ("MOV %0, A1LbP\n\t" \
  894. "ADD %0, %0, #(" #x "@TLSLDM)" \
  895. : "=d" (__result)); \
  896. __result = __tls_get_addr (__result); \
  897. __asm__ ("ADDT %0,%0,#HI(" #x "@TLSLDO)\n\t" \
  898. "ADD %0,%0,#LO(" #x "@TLSLDO)" \
  899. : "+d" (__result)); \
  900. __result; })
  901. # define TLS_IE(x) \
  902. ({ void *__result; \
  903. unsigned long __rel; \
  904. extern void *__metag_load_tp (void); \
  905. __asm__ ("GETD %0,[A1LbP+#(" #x "@TLSIE)]" \
  906. : "=d" (__rel)); \
  907. __result = __metag_load_tp(); \
  908. __result + __rel; })
  909. # define TLS_LE(x) \
  910. ({ void *__result; \
  911. extern void *__metag_load_tp (void); \
  912. __result = __metag_load_tp(); \
  913. __asm__ ("ADDT %0,%0,#HI(" #x "@TLSLE)\n\t" \
  914. "ADD %0,%0,#LO(" #x "@TLSLE)" \
  915. : "+d" (__result)); \
  916. __result; })
  917. #elif !defined TLS_LE || !defined TLS_IE \
  918. || !defined TLS_LD || !defined TLS_GD
  919. # error "No support for this architecture so far."
  920. #endif