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.
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.
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.
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
23 # include <pt-machine.h>
30 /* Type for the dtv. */
41 #else /* __ASSEMBLER__ */
42 # include <tcb-offsets.h>
43 #endif /* __ASSEMBLER__ */
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)
50 /* Signal that TLS support is available. */
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
56 #ifndef FLOATING_STACKS
57 # define INCLUDE_TLS_PADDING 1
60 # ifndef __ASSEMBLER__
68 /* This is the size of the initial TCB. */
69 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
71 /* Alignment requirements for the initial TCB. */
72 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
74 /* This is the size of the TCB. */
75 # define TLS_TCB_SIZE sizeof (tcbhead_t)
77 /* This is the size we need before TCB. */
78 # define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct)
80 /* Alignment requirements for the TCB. */
81 # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
83 /* The TLS blocks start right after the TCB. */
84 # define TLS_DTV_AT_TP 1
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
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);})
97 /* Return dtv of given thread descriptor. */
98 # define GET_DTV(tcbp) \
99 (((tcbhead_t *) (tcbp))->dtv)
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; })
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)); \
113 /* Return the thread descriptor for the current thread. */
115 # define THREAD_SELF \
116 ({ struct _pthread_descr_struct *__self; \
117 __asm__ ("stc gbr,%0" : "=r" (__self)); \
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)); \
126 # define TLS_MULTIPLE_THREADS_IN_TCB 1
128 /* Get the thread descriptor definition. This must be after the
129 the definition of THREAD_SELF for TLS. */
130 # include <linuxthreads/descr.h>
132 # endif /* __ASSEMBLER__ */
136 # ifndef __ASSEMBLER__
143 int multiple_threads;
146 /* Get the thread descriptor definition. */
147 # include <linuxthreads/descr.h>
149 # define NONTLS_INIT_TP \
151 static const tcbhead_t nontls_init_tp = { .multiple_threads = 0 }; \
152 __asm__ __volatile__ ("ldc %0,gbr" : : "r" (&nontls_init_tp)); \
155 # endif /* __ASSEMBLER__ */
157 #endif /* HAVE_TLS_SUPPORT && (FLOATING_STACKS || !IS_IN_libpthread) */