summaryrefslogtreecommitdiffstats
path: root/test/tls/tls-macros-mips.h
blob: 0db383032d7aa2f94ccae61d86379919db380fc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* Macros to support TLS testing in times of missing compiler support.  */

#if _MIPS_SIM != _ABI64

/* These versions are for o32 and n32.  */

# define TLS_GD(x)					\
  ({ void *__result;					\
     extern void *__tls_get_addr (void *);		\
     __asm__ ("addiu %0, $28, %%tlsgd(" #x ")"		\
	  : "=r" (__result));				\
     (int *)__tls_get_addr (__result); })
#else
# define TLS_GD(x)					\
  ({ void *__result;					\
     extern void *__tls_get_addr (void *);		\
     __asm__ ("daddiu %0, $28, %%tlsgd(" #x ")"		\
	  : "=r" (__result));				\
     (int *)__tls_get_addr (__result); })
#endif

#if _MIPS_SIM != _ABI64
# define TLS_LD(x)					\
  ({ void *__result;					\
     extern void *__tls_get_addr (void *);		\
     __asm__ ("addiu %0, $28, %%tlsldm(" #x ")"		\
	  : "=r" (__result));				\
     __result = __tls_get_addr (__result);		\
     __asm__ ("lui $3,%%dtprel_hi(" #x ")\n\t"		\
	  "addiu $3,$3,%%dtprel_lo(" #x ")\n\t"		\
	  "addu %0,%0,$3"				\
	  : "+r" (__result) : : "$3");			\
     __result; })
# define TLS_IE(x)					\
  ({ void *__result;					\
     __asm__ (".set push\n\t.set mips32r2\n\t"		\
	  "rdhwr\t%0,$29\n\t.set pop"			\
	  : "=v" (__result));				\
     __asm__ ("lw $3,%%gottprel(" #x ")($28)\n\t"		\
	  "addu %0,%0,$3"				\
	  : "+r" (__result) : : "$3");			\
     __result; })
# define TLS_LE(x)					\
  ({ void *__result;					\
     __asm__ (".set push\n\t.set mips32r2\n\t"		\
	  "rdhwr\t%0,$29\n\t.set pop"			\
	  : "=v" (__result));				\
     __asm__ ("lui $3,%%tprel_hi(" #x ")\n\t"		\
	  "addiu $3,$3,%%tprel_lo(" #x ")\n\t"		\
	  "addu %0,%0,$3"				\
	  : "+r" (__result) : : "$3");			\
     __result; })

#else

/* These versions are for n64.  */

# define TLS_LD(x)					\
  ({ void *__result;					\
     extern void *__tls_get_addr (void *);		\
     __asm__ ("daddiu %0, $28, %%tlsldm(" #x ")"		\
	  : "=r" (__result));				\
     __result = __tls_get_addr (__result);		\
     __asm__ ("lui $3,%%dtprel_hi(" #x ")\n\t"		\
	  "daddiu $3,$3,%%dtprel_lo(" #x ")\n\t"	\
	  "daddu %0,%0,$3"				\
	  : "+r" (__result) : : "$3");			\
     __result; })
# define TLS_IE(x)					\
  ({ void *__result;					\
     __asm__ (".set push\n\t.set mips32r2\n\t"		\
	  "rdhwr\t%0,$29\n\t.set pop"			\
	  : "=v" (__result));				\
     __asm__ ("ld $3,%%gottprel(" #x ")($28)\n\t"		\
	  "daddu %0,%0,$3"				\
	  : "+r" (__result) : : "$3");			\
     __result; })
# define TLS_LE(x)					\
  ({ void *__result;					\
     __asm__ (".set push\n\t.set mips32r2\n\t"		\
	  "rdhwr\t%0,$29\n\t.set pop"			\
	  : "=v" (__result));				\
     __asm__ ("lui $3,%%tprel_hi(" #x ")\n\t"		\
	  "daddiu $3,$3,%%tprel_lo(" #x ")\n\t"		\
	  "daddu %0,%0,$3"				\
	  : "+r" (__result) : : "$3");			\
     __result; })
#endif