OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libpthread/] [linuxthreads/] [sysdeps/] [i386/] [tls.h] - Blame information for rev 1325

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* Definition for thread-local data handling.  linuxthreads/i386 version.
2
   Copyright (C) 2002 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 <stddef.h>
27
 
28
/* Type for the dtv.  */
29
typedef union dtv
30
{
31
  size_t counter;
32
  void *pointer;
33
} dtv_t;
34
 
35
 
36
typedef struct
37
{
38
  void *tcb;            /* Pointer to the TCB.  Not necessary the
39
                           thread descriptor used by libpthread.  */
40
  dtv_t *dtv;
41
  void *self;           /* Pointer to the thread descriptor.  */
42
} tcbhead_t;
43
#endif
44
 
45
 
46
/* We can support TLS only if the floating-stack support is available.  */
47
#if defined FLOATING_STACKS && defined HAVE_TLS_SUPPORT
48
 
49
/* Signal that TLS support is available.  */
50
//# define USE_TLS      1
51
 
52
# ifndef __ASSEMBLER__
53
/* Get system call information.  */
54
#  include <sysdep.h>
55
 
56
 
57
/* Get the thread descriptor definition.  */
58
#  include <linuxthreads/descr.h>
59
 
60
/* This is the size of the initial TCB.  */
61
#  define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
62
 
63
/* Alignment requirements for the initial TCB.  */
64
#  define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
65
 
66
/* This is the size of the TCB.  */
67
#  define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
68
 
69
/* Alignment requirements for the TCB.  */
70
#  define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
71
 
72
/* The TCB can have any size and the memory following the address the
73
   thread pointer points to is unspecified.  Allocate the TCB there.  */
74
#  define TLS_TCB_AT_TP 1
75
 
76
 
77
/* Install the dtv pointer.  The pointer passed is to the element with
78
   index -1 which contain the length.  */
79
#  define INSTALL_DTV(descr, dtvp) \
80
  ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
81
 
82
/* Install new dtv for current thread.  */
83
#  define INSTALL_NEW_DTV(dtv) \
84
  ({ struct _pthread_descr_struct *__descr;                                   \
85
     THREAD_SETMEM (__descr, p_header.data.dtvp, (dtv)); })
86
 
87
/* Return dtv of given thread descriptor.  */
88
#  define GET_DTV(descr) \
89
  (((tcbhead_t *) (descr))->dtv)
90
 
91
#  ifdef __PIC__
92
#   define TLS_EBX_ARG "r"
93
#   define TLS_LOAD_EBX "xchgl %3, %%ebx\n\t"
94
#  else
95
#   define TLS_EBX_ARG "b"
96
#   define TLS_LOAD_EBX
97
#  endif
98
 
99
#  define TLS_DO_MODIFY_LDT(descr, nr)                                        \
100
({                                                                            \
101
  struct modify_ldt_ldt_s ldt_entry =                                         \
102
    { nr, (unsigned long int) (descr), 0xfffff /* 4GB in pages */,            \
103
      1, 0, 0, 1, 0, 1, 0 };                                                      \
104
  int result;                                                                 \
105
  asm volatile (TLS_LOAD_EBX                                                  \
106
                "int $0x80\n\t"                                               \
107
                TLS_LOAD_EBX                                                  \
108
                : "=a" (result)                                               \
109
                : "0" (__NR_modify_ldt),                               \
110
                /* The extra argument with the "m" constraint is necessary    \
111
                   to let the compiler know that we are accessing LDT_ENTRY   \
112
                   here.  */                                                  \
113
                "m" (ldt_entry), TLS_EBX_ARG (1), "c" (&ldt_entry),           \
114
                "d" (sizeof (ldt_entry)));                                    \
115
  __builtin_expect (result, 0) != 0 ? -1 : nr * 8 + 7;                          \
116
})
117
 
118
#  define TLS_DO_SET_THREAD_AREA(descr, secondcall)                           \
119
({                                                                            \
120
  struct modify_ldt_ldt_s ldt_entry =                                         \
121
    { -1, (unsigned long int) (descr), 0xfffff /* 4GB in pages */,            \
122
      1, 0, 0, 1, 0, 1, 0 };                                                      \
123
  int result;                                                                 \
124
  if (secondcall)                                                             \
125
    ldt_entry.entry_number = ({ int _gs;                                      \
126
                                asm ("movw %%gs, %w0" : "=q" (_gs));          \
127
                                (_gs & 0xffff) >> 3; });                      \
128
  asm volatile (TLS_LOAD_EBX                                                  \
129
                "int $0x80\n\t"                                               \
130
                TLS_LOAD_EBX                                                  \
131
                : "=a" (result), "=m" (ldt_entry.entry_number)                \
132
                : "0" (__NR_set_thread_area),                                  \
133
                /* The extra argument with the "m" constraint is necessary    \
134
                   to let the compiler know that we are accessing LDT_ENTRY   \
135
                   here.  */                                                  \
136
                TLS_EBX_ARG (&ldt_entry), "m" (ldt_entry));                   \
137
    __builtin_expect (result, 0) == 0 ? ldt_entry.entry_number * 8 + 3 : -1;  \
138
})
139
 
140
#  ifdef __ASSUME_SET_THREAD_AREA_SYSCALL
141
#   define TLS_SETUP_GS_SEGMENT(descr, secondcall) \
142
  TLS_DO_SET_THREAD_AREA (descr, firstcall)
143
#  elif defined __NR_set_thread_area
144
#   define TLS_SETUP_GS_SEGMENT(descr, secondcall) \
145
  ({ int __seg = TLS_DO_SET_THREAD_AREA (descr, secondcall); \
146
     __seg == -1 ? TLS_DO_MODIFY_LDT (descr, 0) : __seg; })
147
#  else
148
#   define TLS_SETUP_GS_SEGMENT(descr, secondcall) \
149
  TLS_DO_MODIFY_LDT ((descr), 0)
150
#  endif
151
 
152
/* Code to initially initialize the thread pointer.  This might need
153
   special attention since 'errno' is not yet available and if the
154
   operation can cause a failure 'errno' must not be touched.  */
155
#  define TLS_INIT_TP(descr, secondcall)                                      \
156
  ({                                                                          \
157
    void *_descr = (descr);                                                   \
158
    tcbhead_t *head = _descr;                                                 \
159
    int __gs;                                                                 \
160
                                                                              \
161
    head->tcb = _descr;                                                       \
162
    /* For now the thread descriptor is at the same address.  */              \
163
    head->self = _descr;                                                      \
164
                                                                              \
165
    __gs = TLS_SETUP_GS_SEGMENT (_descr, secondcall);                         \
166
    if (__builtin_expect (__gs, 7) != -1)                                     \
167
      {                                                                       \
168
        asm ("movw %w0, %%gs" : : "q" (__gs));                                \
169
        __gs = 0;                                                              \
170
      }                                                                       \
171
    __gs;                                                                     \
172
  })
173
 
174
 
175
/* Return the address of the dtv for the current thread.  */
176
#  define THREAD_DTV() \
177
  ({ struct _pthread_descr_struct *__descr;                                   \
178
     THREAD_GETMEM (__descr, p_header.data.dtvp); })
179
 
180
# endif /* FLOATING_STACKS && HAVE_TLS_SUPPORT */
181
#endif /* __ASSEMBLER__ */
182
 
183
#endif  /* tls.h */

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.