|
Packit Service |
82fcde |
/* Macros to support TLS testing in times of missing compiler support. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <sys/cdefs.h>
|
|
Packit Service |
82fcde |
#include <sys/asm.h>
|
|
Packit Service |
82fcde |
#include <sysdep.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __STRING2(X) __STRING(X)
|
|
Packit Service |
82fcde |
#define ADDU __STRING2(PTR_ADDU)
|
|
Packit Service |
82fcde |
#define ADDIU __STRING2(PTR_ADDIU)
|
|
Packit Service |
82fcde |
#define LW __STRING2(PTR_L)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Load the GOT pointer, which may not be in $28 in a non-PIC
|
|
Packit Service |
82fcde |
(abicalls pic0) function. */
|
|
Packit Service |
82fcde |
#ifndef __PIC__
|
|
Packit Service |
82fcde |
# if _MIPS_SIM != _ABI64
|
|
Packit Service |
82fcde |
# ifndef __mips16
|
|
Packit Service |
82fcde |
# define LOAD_GP "move %[tmp], $28\n\tla $28, __gnu_local_gp\n\t"
|
|
Packit Service |
82fcde |
# else
|
|
Packit Service |
82fcde |
# define LOAD_GP \
|
|
Packit Service |
82fcde |
"li %[tmp], %%hi(__gnu_local_gp)\n\t" \
|
|
Packit Service |
82fcde |
"sll %[tmp], 16\n\t" \
|
|
Packit Service |
82fcde |
"addiu %[tmp], %%lo(__gnu_local_gp)\n\t"
|
|
Packit Service |
82fcde |
# endif
|
|
Packit Service |
82fcde |
# else
|
|
Packit Service |
82fcde |
# define LOAD_GP "move %[tmp], $28\n\tdla $28, __gnu_local_gp\n\t"
|
|
Packit Service |
82fcde |
# endif
|
|
Packit Service |
82fcde |
# define UNLOAD_GP "\n\tmove $28, %[tmp]"
|
|
Packit Service |
82fcde |
#else
|
|
Packit Service |
82fcde |
/* MIPS16 (re)creates the GP value using PC-relative instructions. */
|
|
Packit Service |
82fcde |
# ifdef __mips16
|
|
Packit Service |
82fcde |
# define LOAD_GP \
|
|
Packit Service |
82fcde |
"li %[tmp], %%hi(_gp_disp)\n\t" \
|
|
Packit Service |
82fcde |
"addiu %0, $pc, %%lo(_gp_disp)\n\t" \
|
|
Packit Service |
82fcde |
"sll %[tmp], 16\n\t" \
|
|
Packit Service |
82fcde |
"addu %[tmp], %0\n\t"
|
|
Packit Service |
82fcde |
# else
|
|
Packit Service |
82fcde |
# define LOAD_GP
|
|
Packit Service |
82fcde |
# endif
|
|
Packit Service |
82fcde |
# define UNLOAD_GP
|
|
Packit Service |
82fcde |
#endif
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
# if __mips_isa_rev >= 2
|
|
Packit Service |
82fcde |
# define TLS_RDHWR "rdhwr\t%0,$29"
|
|
Packit Service |
82fcde |
# else
|
|
Packit Service |
82fcde |
# define TLS_RDHWR \
|
|
Packit Service |
82fcde |
".set push\n\t.set mips32r2\n\t" \
|
|
Packit Service |
82fcde |
"rdhwr\t%0,$29\n\t.set pop"
|
|
Packit Service |
82fcde |
#endif
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#ifndef __mips16
|
|
Packit Service |
82fcde |
# define TLS_GD(x) \
|
|
Packit Service |
82fcde |
({ void *__result, *__tmp; \
|
|
Packit Service |
82fcde |
extern void *__tls_get_addr (void *); \
|
|
Packit Service |
82fcde |
asm (LOAD_GP ADDIU " %0, $28, %%tlsgd(" #x ")" \
|
|
Packit Service |
82fcde |
UNLOAD_GP \
|
|
Packit Service |
82fcde |
: "=r" (__result), [tmp] "=&r" (__tmp)); \
|
|
Packit Service |
82fcde |
(int *)__tls_get_addr (__result); })
|
|
Packit Service |
82fcde |
# define TLS_LD(x) \
|
|
Packit Service |
82fcde |
({ void *__result, *__tmp; \
|
|
Packit Service |
82fcde |
extern void *__tls_get_addr (void *); \
|
|
Packit Service |
82fcde |
asm (LOAD_GP ADDIU " %0, $28, %%tlsldm(" #x ")" \
|
|
Packit Service |
82fcde |
UNLOAD_GP \
|
|
Packit Service |
82fcde |
: "=r" (__result), [tmp] "=&r" (__tmp)); \
|
|
Packit Service |
82fcde |
__result = __tls_get_addr (__result); \
|
|
Packit Service |
82fcde |
asm ("lui $3,%%dtprel_hi(" #x ")\n\t" \
|
|
Packit Service |
82fcde |
"addiu $3,$3,%%dtprel_lo(" #x ")\n\t" \
|
|
Packit Service |
82fcde |
ADDU " %0,%0,$3" \
|
|
Packit Service |
82fcde |
: "+r" (__result) : : "$3"); \
|
|
Packit Service |
82fcde |
__result; })
|
|
Packit Service |
82fcde |
# define TLS_IE(x) \
|
|
Packit Service |
82fcde |
({ void *__result, *__tmp; \
|
|
Packit Service |
82fcde |
asm (TLS_RDHWR \
|
|
Packit Service |
82fcde |
: "=v" (__result)); \
|
|
Packit Service |
82fcde |
asm (LOAD_GP LW " $3,%%gottprel(" #x ")($28)\n\t" \
|
|
Packit Service |
82fcde |
ADDU " %0,%0,$3" \
|
|
Packit Service |
82fcde |
UNLOAD_GP \
|
|
Packit Service |
82fcde |
: "+r" (__result), [tmp] "=&r" (__tmp) \
|
|
Packit Service |
82fcde |
: : "$3"); \
|
|
Packit Service |
82fcde |
__result; })
|
|
Packit Service |
82fcde |
# define TLS_LE(x) \
|
|
Packit Service |
82fcde |
({ void *__result; \
|
|
Packit Service |
82fcde |
asm (TLS_RDHWR \
|
|
Packit Service |
82fcde |
: "=v" (__result)); \
|
|
Packit Service |
82fcde |
asm ("lui $3,%%tprel_hi(" #x ")\n\t" \
|
|
Packit Service |
82fcde |
"addiu $3,$3,%%tprel_lo(" #x ")\n\t" \
|
|
Packit Service |
82fcde |
ADDU " %0,%0,$3" \
|
|
Packit Service |
82fcde |
: "+r" (__result) : : "$3"); \
|
|
Packit Service |
82fcde |
__result; })
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#else /* __mips16 */
|
|
Packit Service |
82fcde |
/* MIPS16 version. */
|
|
Packit Service |
82fcde |
# define TLS_GD(x) \
|
|
Packit Service |
82fcde |
({ void *__result, *__tmp; \
|
|
Packit Service |
82fcde |
extern void *__tls_get_addr (void *); \
|
|
Packit Service |
82fcde |
asm (LOAD_GP ADDIU " %1, %%tlsgd(" #x ")" \
|
|
Packit Service |
82fcde |
"\n\tmove %0, %1" \
|
|
Packit Service |
82fcde |
: "=d" (__result), [tmp] "=&d" (__tmp)); \
|
|
Packit Service |
82fcde |
(int *) __tls_get_addr (__result); })
|
|
Packit Service |
82fcde |
# define TLS_LD(x) \
|
|
Packit Service |
82fcde |
({ void *__result, *__tmp; \
|
|
Packit Service |
82fcde |
extern void *__tls_get_addr (void *); \
|
|
Packit Service |
82fcde |
asm (LOAD_GP ADDIU " %1, %%tlsldm(" #x ")" \
|
|
Packit Service |
82fcde |
"\n\tmove %0, %1" \
|
|
Packit Service |
82fcde |
: "=d" (__result), [tmp] "=&d" (__tmp)); \
|
|
Packit Service |
82fcde |
__result = __tls_get_addr (__result); \
|
|
Packit Service |
82fcde |
asm ("li $3,%%dtprel_hi(" #x ")\n\t" \
|
|
Packit Service |
82fcde |
"sll $3,16\n\t" \
|
|
Packit Service |
82fcde |
"addiu $3,%%dtprel_lo(" #x ")\n\t" \
|
|
Packit Service |
82fcde |
ADDU " %0,%0,$3" \
|
|
Packit Service |
82fcde |
: "+d" (__result) : : "$3"); \
|
|
Packit Service |
82fcde |
__result; })
|
|
Packit Service |
82fcde |
# define TLS_IE(x) \
|
|
Packit Service |
82fcde |
({ void *__result, *__tmp, *__tp; \
|
|
Packit Service |
82fcde |
__tp = __builtin_thread_pointer (); \
|
|
Packit Service |
82fcde |
asm (LOAD_GP LW " $3,%%gottprel(" #x ")(%1)\n\t" \
|
|
Packit Service |
82fcde |
ADDU " %0,%[tp],$3" \
|
|
Packit Service |
82fcde |
: "=&d" (__result), [tmp] "=&d" (__tmp) \
|
|
Packit Service |
82fcde |
: [tp] "d" (__tp) : "$3"); \
|
|
Packit Service |
82fcde |
__result; })
|
|
Packit Service |
82fcde |
# define TLS_LE(x) \
|
|
Packit Service |
82fcde |
({ void *__result, *__tp; \
|
|
Packit Service |
82fcde |
__tp = __builtin_thread_pointer (); \
|
|
Packit Service |
82fcde |
asm ("li $3,%%tprel_hi(" #x ")\n\t" \
|
|
Packit Service |
82fcde |
"sll $3,16\n\t" \
|
|
Packit Service |
82fcde |
"addiu $3,%%tprel_lo(" #x ")\n\t" \
|
|
Packit Service |
82fcde |
ADDU " %0,%[tp],$3" \
|
|
Packit Service |
82fcde |
: "=d" (__result) : [tp] "d" (__tp) : "$3"); \
|
|
Packit Service |
82fcde |
__result; })
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#endif /* __mips16 */
|