(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / nptl / sysdeps / powerpc / tls.h
blobce7f5bd53d425588fadbf903a95ac1b1b39d12b1
1 /* Definition for thread-local data handling. NPTL/PowerPC version.
2 Copyright (C) 2003 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
18 02111-1307 USA. */
20 #ifndef _TLS_H
21 #define _TLS_H 1
23 # include <dl-sysdep.h>
25 #ifndef __ASSEMBLER__
26 # include <stddef.h>
27 # include <stdint.h>
29 /* Type for the dtv. */
30 typedef union dtv
32 size_t counter;
33 void *pointer;
34 } dtv_t;
36 #else /* __ASSEMBLER__ */
37 # include <tcb-offsets.h>
38 #endif /* __ASSEMBLER__ */
41 /* We require TLS support in the tools. */
42 #ifndef HAVE_TLS_SUPPORT
43 # error "TLS support is required."
44 #endif
46 /* Signal that TLS support is available. */
47 # define USE_TLS 1
49 #ifndef __ASSEMBLER__
51 /* Get system call information. */
52 # include <sysdep.h>
54 /* The TP points to the start of the thread blocks. */
55 # define TLS_DTV_AT_TP 1
57 /* We use the multiple_threads field in the pthread struct */
58 #define TLS_MULTIPLE_THREADS_IN_TCB 1
60 /* Get the thread descriptor definition. */
61 # include <nptl/descr.h>
63 /* This layout is actually wholly private and not affected by the ABI.
64 Nor does it overlap the pthread data structure, so we need nothing
65 extra here at all. */
66 typedef struct
68 dtv_t *dtv;
69 } tcbhead_t;
71 /* This is the size of the initial TCB. */
72 # define TLS_INIT_TCB_SIZE 0
74 /* Alignment requirements for the initial TCB. */
75 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
77 /* This is the size of the TCB. */
78 # define TLS_TCB_SIZE 0
80 /* Alignment requirements for the TCB. */
81 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
83 /* This is the size we need before TCB. */
84 # define TLS_PRE_TCB_SIZE \
85 (sizeof (struct pthread) \
86 + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
88 # ifndef __powerpc64__
89 /* Register r2 (tp) is reserved by the ABI as "thread pointer". */
90 register void *__thread_register __asm__ ("r2");
91 # define PT_THREAD_POINTER PT_R2
92 # else
93 /* Register r13 (tp) is reserved by the ABI as "thread pointer". */
94 register void *__thread_register __asm__ ("r13");
95 # define PT_THREAD_POINTER PT_R13
96 # endif
98 /* The following assumes that TP (R2 or R13) points to the end of the
99 TCB + 0x7000 (per the ABI). This implies that TCB address is
100 TP - 0x7000. As we define TLS_DTV_AT_TP we can
101 assume that the pthread struct is allocated immediately ahead of the
102 TCB. This implies that the pthread_descr address is
103 TP - (TLS_PRE_TCB_SIZE + 0x7000). */
104 # define TLS_TCB_OFFSET 0x7000
106 /* Install the dtv pointer. The pointer passed is to the element with
107 index -1 which contain the length. */
108 # define INSTALL_DTV(tcbp, dtvp) \
109 ((tcbhead_t *) (tcbp))[-1].dtv = dtvp + 1
111 /* Install new dtv for current thread. */
112 # define INSTALL_NEW_DTV(dtv) (THREAD_DTV() = (dtv))
114 /* Return dtv of given thread descriptor. */
115 # define GET_DTV(tcbp) (((tcbhead_t *) (tcbp))[-1].dtv)
117 /* Code to initially initialize the thread pointer. This might need
118 special attention since 'errno' is not yet available and if the
119 operation can cause a failure 'errno' must not be touched. */
120 # define TLS_INIT_TP(tcbp, secondcall) \
121 (__thread_register = (void *) (tcbp) + TLS_TCB_OFFSET, NULL)
123 /* Return the address of the dtv for the current thread. */
124 # define THREAD_DTV() \
125 (((tcbhead_t *) (__thread_register - TLS_TCB_OFFSET))[-1].dtv)
127 /* Return the thread descriptor for the current thread. */
128 # define THREAD_SELF \
129 ((struct pthread *) (__thread_register \
130 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
132 /* Magic for libthread_db to know how to do THREAD_SELF. */
133 # define DB_THREAD_SELF \
134 REGISTER (32, 32, PT_THREAD_POINTER * 4, \
135 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE) \
136 REGISTER (64, 64, PT_THREAD_POINTER * 8, \
137 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)
139 /* Read member of the thread descriptor directly. */
140 # define THREAD_GETMEM(descr, member) ((void)(descr), (THREAD_SELF)->member)
142 /* Same as THREAD_GETMEM, but the member offset can be non-constant. */
143 # define THREAD_GETMEM_NC(descr, member, idx) \
144 ((void)(descr), (THREAD_SELF)->member[idx])
146 /* Set member of the thread descriptor directly. */
147 # define THREAD_SETMEM(descr, member, value) \
148 ((void)(descr), (THREAD_SELF)->member = (value))
150 /* Same as THREAD_SETMEM, but the member offset can be non-constant. */
151 # define THREAD_SETMEM_NC(descr, member, idx, value) \
152 ((void)(descr), (THREAD_SELF)->member[idx] = (value))
154 /* l_tls_offset == 0 is perfectly valid on PPC, so we have to use some
155 different value to mean unset l_tls_offset. */
156 # define NO_TLS_OFFSET -1
158 #endif /* __ASSEMBLER__ */
160 #endif /* tls.h */