lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* Macros to support TLS testing in times of missing compiler support. */ |
| 2 | |
| 3 | #if _MIPS_SIM != _ABI64 |
| 4 | |
| 5 | /* These versions are for o32 and n32. */ |
| 6 | |
| 7 | # define TLS_GD(x) \ |
| 8 | ({ void *__result; \ |
| 9 | extern void *__tls_get_addr (void *); \ |
| 10 | __asm__ ("addiu %0, $28, %%tlsgd(" #x ")" \ |
| 11 | : "=r" (__result)); \ |
| 12 | (int *)__tls_get_addr (__result); }) |
| 13 | #else |
| 14 | # define TLS_GD(x) \ |
| 15 | ({ void *__result; \ |
| 16 | extern void *__tls_get_addr (void *); \ |
| 17 | __asm__ ("daddiu %0, $28, %%tlsgd(" #x ")" \ |
| 18 | : "=r" (__result)); \ |
| 19 | (int *)__tls_get_addr (__result); }) |
| 20 | #endif |
| 21 | |
| 22 | #if _MIPS_SIM != _ABI64 |
| 23 | # define TLS_LD(x) \ |
| 24 | ({ void *__result; \ |
| 25 | extern void *__tls_get_addr (void *); \ |
| 26 | __asm__ ("addiu %0, $28, %%tlsldm(" #x ")" \ |
| 27 | : "=r" (__result)); \ |
| 28 | __result = __tls_get_addr (__result); \ |
| 29 | __asm__ ("lui $3,%%dtprel_hi(" #x ")\n\t" \ |
| 30 | "addiu $3,$3,%%dtprel_lo(" #x ")\n\t" \ |
| 31 | "addu %0,%0,$3" \ |
| 32 | : "+r" (__result) : : "$3"); \ |
| 33 | __result; }) |
| 34 | # define TLS_IE(x) \ |
| 35 | ({ void *__result; \ |
| 36 | __asm__ (".set push\n\t.set mips32r2\n\t" \ |
| 37 | "rdhwr\t%0,$29\n\t.set pop" \ |
| 38 | : "=v" (__result)); \ |
| 39 | __asm__ ("lw $3,%%gottprel(" #x ")($28)\n\t" \ |
| 40 | "addu %0,%0,$3" \ |
| 41 | : "+r" (__result) : : "$3"); \ |
| 42 | __result; }) |
| 43 | # define TLS_LE(x) \ |
| 44 | ({ void *__result; \ |
| 45 | __asm__ (".set push\n\t.set mips32r2\n\t" \ |
| 46 | "rdhwr\t%0,$29\n\t.set pop" \ |
| 47 | : "=v" (__result)); \ |
| 48 | __asm__ ("lui $3,%%tprel_hi(" #x ")\n\t" \ |
| 49 | "addiu $3,$3,%%tprel_lo(" #x ")\n\t" \ |
| 50 | "addu %0,%0,$3" \ |
| 51 | : "+r" (__result) : : "$3"); \ |
| 52 | __result; }) |
| 53 | |
| 54 | #else |
| 55 | |
| 56 | /* These versions are for n64. */ |
| 57 | |
| 58 | # define TLS_LD(x) \ |
| 59 | ({ void *__result; \ |
| 60 | extern void *__tls_get_addr (void *); \ |
| 61 | __asm__ ("daddiu %0, $28, %%tlsldm(" #x ")" \ |
| 62 | : "=r" (__result)); \ |
| 63 | __result = __tls_get_addr (__result); \ |
| 64 | __asm__ ("lui $3,%%dtprel_hi(" #x ")\n\t" \ |
| 65 | "daddiu $3,$3,%%dtprel_lo(" #x ")\n\t" \ |
| 66 | "daddu %0,%0,$3" \ |
| 67 | : "+r" (__result) : : "$3"); \ |
| 68 | __result; }) |
| 69 | # define TLS_IE(x) \ |
| 70 | ({ void *__result; \ |
| 71 | __asm__ (".set push\n\t.set mips32r2\n\t" \ |
| 72 | "rdhwr\t%0,$29\n\t.set pop" \ |
| 73 | : "=v" (__result)); \ |
| 74 | __asm__ ("ld $3,%%gottprel(" #x ")($28)\n\t" \ |
| 75 | "daddu %0,%0,$3" \ |
| 76 | : "+r" (__result) : : "$3"); \ |
| 77 | __result; }) |
| 78 | # define TLS_LE(x) \ |
| 79 | ({ void *__result; \ |
| 80 | __asm__ (".set push\n\t.set mips32r2\n\t" \ |
| 81 | "rdhwr\t%0,$29\n\t.set pop" \ |
| 82 | : "=v" (__result)); \ |
| 83 | __asm__ ("lui $3,%%tprel_hi(" #x ")\n\t" \ |
| 84 | "daddiu $3,$3,%%tprel_lo(" #x ")\n\t" \ |
| 85 | "daddu %0,%0,$3" \ |
| 86 | : "+r" (__result) : : "$3"); \ |
| 87 | __result; }) |
| 88 | #endif |