OSDN Git Service

350d129db4d3f8c5443e362cbd002be67622366e
[uclinux-h8/uClibc.git] / libpthread / linuxthreads / sysdeps / sh / tls.h
1 /* Definition for thread-local data handling.  linuxthreads/SH version.
2    Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #ifndef _TLS_H
21 #define _TLS_H
22
23 # include <pt-machine.h>
24
25 #ifndef __ASSEMBLER__
26 # include <stdbool.h>
27 # include <stddef.h>
28 # include <stdint.h>
29
30 /* Type for the dtv.  */
31 typedef union dtv
32 {
33   size_t counter;
34   struct
35   {
36     void *val;
37     bool is_static;
38   } pointer;
39 } dtv_t;
40
41 #else /* __ASSEMBLER__ */
42 # include <tcb-offsets.h>
43 #endif /* __ASSEMBLER__ */
44
45
46 /* We can support TLS only if the floating-stack support is available.  */
47 #if defined HAVE_TLS_SUPPORT \
48     && (defined FLOATING_STACKS || !defined IS_IN_libpthread)
49
50 /* Signal that TLS support is available.  */
51 # define USE_TLS        1
52
53 /* Include padding in _pthread_descr_struct so that libc can find p_errno,
54    if libpthread will only include the padding because of the !IS_IN_libpthread
55    check.  */
56 #ifndef FLOATING_STACKS
57 # define INCLUDE_TLS_PADDING    1
58 #endif
59
60 # ifndef __ASSEMBLER__
61
62 typedef struct
63 {
64   dtv_t *dtv;
65   void *private;
66 } tcbhead_t;
67
68 /* This is the size of the initial TCB.  */
69 #  define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
70
71 /* Alignment requirements for the initial TCB.  */
72 #  define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
73
74 /* This is the size of the TCB.  */
75 #  define TLS_TCB_SIZE sizeof (tcbhead_t)
76
77 /* This is the size we need before TCB.  */
78 #  define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct)
79
80 /* Alignment requirements for the TCB.  */
81 #  define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
82
83 /* The TLS blocks start right after the TCB.  */
84 #  define TLS_DTV_AT_TP 1
85
86 /* Install the dtv pointer.  The pointer passed is to the element with
87    index -1 which contain the length.  */
88 #  define INSTALL_DTV(tcbp, dtvp) \
89   ((tcbhead_t *) (tcbp))->dtv = dtvp + 1
90
91 /* Install new dtv for current thread.  */
92 #  define INSTALL_NEW_DTV(dtv) \
93   ({ tcbhead_t *__tcbp;                                                       \
94      __asm__ __volatile__ ("stc gbr,%0" : "=r" (__tcbp));                             \
95      __tcbp->dtv = (dtv);})
96
97 /* Return dtv of given thread descriptor.  */
98 #  define GET_DTV(tcbp) \
99   (((tcbhead_t *) (tcbp))->dtv)
100
101 /* Code to initially initialize the thread pointer.  This might need
102    special attention since 'errno' is not yet available and if the
103    operation can cause a failure 'errno' must not be touched.  */
104 #  define TLS_INIT_TP(tcbp, secondcall) \
105   ({ __asm__ __volatile__ ("ldc %0,gbr" : : "r" (tcbp)); 0; })
106
107 /* Return the address of the dtv for the current thread.  */
108 #  define THREAD_DTV() \
109   ({ tcbhead_t *__tcbp;                                                       \
110      __asm__ __volatile__ ("stc gbr,%0" : "=r" (__tcbp));                             \
111      __tcbp->dtv;})
112
113 /* Return the thread descriptor for the current thread.  */
114 #  undef THREAD_SELF
115 #  define THREAD_SELF \
116   ({ struct _pthread_descr_struct *__self;                                    \
117      __asm__ ("stc gbr,%0" : "=r" (__self));                                  \
118      __self - 1;})
119
120 #  undef INIT_THREAD_SELF
121 #  define INIT_THREAD_SELF(descr, nr) \
122   ({ struct _pthread_descr_struct *__self = (void *) descr;                   \
123      __asm__ __volatile__ ("ldc %0,gbr" : : "r" (__self + 1));                \
124      0; })
125
126 # define TLS_MULTIPLE_THREADS_IN_TCB 1
127
128 /* Get the thread descriptor definition.  This must be after the
129    the definition of THREAD_SELF for TLS.  */
130 #  include <linuxthreads/descr.h>
131
132 # endif /* __ASSEMBLER__ */
133
134 #else
135
136 # ifndef __ASSEMBLER__
137
138 typedef struct
139 {
140   void *tcb;
141   dtv_t *dtv;
142   void *self;
143   int multiple_threads;
144 } tcbhead_t;
145
146 /* Get the thread descriptor definition.  */
147 #  include <linuxthreads/descr.h>
148
149 #  define NONTLS_INIT_TP \
150   do {                                                                  \
151     static const tcbhead_t nontls_init_tp = { .multiple_threads = 0 };  \
152     __asm__ __volatile__ ("ldc %0,gbr" : : "r" (&nontls_init_tp));              \
153   } while (0)
154
155 # endif /* __ASSEMBLER__ */
156
157 #endif  /* HAVE_TLS_SUPPORT && (FLOATING_STACKS || !IS_IN_libpthread) */
158
159 #endif  /* tls.h */