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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [synth/] [i386linux/] [current/] [src/] [tls.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//=============================================================================
2
//
3
//      tls.c
4
//
5
//      Support for the per-thread data expected by parts of gcc
6
//
7
//=============================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 2009 Free Software Foundation, Inc.                  
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//=============================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    bartv
43
// Contributors: bartv
44
// Date:         2009-08-09
45
//
46
//####DESCRIPTIONEND####
47
//=============================================================================
48
 
49
#include <pkgconf/mlt_synth_i386_rom.h>
50
#include <cyg/hal/hal_arch.h>
51
 
52
// At the time of writing some parts of gcc assume thread-local storage as
53
// provided by glibc. Of particular concern is -fstack-protector which is
54
// enabled by default in some distros. Without matching target-side support
55
// this causes synthetic target eCos applications to SEGV early on.
56
 
57
// eCos only needs a single TLS data structure. This will need alignment
58
// suitable for filling in an x86 descriptor table entry, so the linker
59
// script places this structure right at the start of RAM.
60
//
61
// Installing a TLS area involves a system call set_thread_area().
62
// This system call should be called from the assembler startup
63
// before any C code starts running, or we'll run into problems with
64
// -fstack-protector-all. However all relevant data can be
65
// statically initialized.
66
 
67
_HAL_TLS_Data _hal_synth_tls_data __attribute__ ((section (".tls._hal_synth_tls_data") )) = {
68
    // The meaning of most of the tls fields is not clear, so just
69
    // initialize them to 0 for now - until something else
70
    // stops working.
71
    .tls_tcb                = (void*) 0,
72
    .tls_dtv                = (void*) 0,
73
    .tls_self               = (void*) 0,
74
    .tls_multiple_threads   = 0,
75
    .tls_sysinfo            = (void*) 0,
76
    // This is the important one for the purposes of -fstack-protector.
77
    // The compiler assumes that %gs:0x14 points at the base of the stack.
78
    // For now we just point at the start of RAM. It should be possible
79
    // to update this during context switches and at the start of interrupt
80
    // handling to get a partial implementation of stack overflow checking.
81
    .tls_stack_guard        = (void*) CYGMEM_REGION_ram,
82
 
83
    .tls_pointer_guard      = (void*) 0,
84
    .tls_gscope_flag        = 0,
85
    .tls_private_futex      = 0,
86
    .tls_private_tm[0]      = (void*) 0,
87
    .tls_private_tm[1]      = (void*) 0,
88
    .tls_private_tm[2]      = (void*) 0,
89
    .tls_private_tm[3]      = (void*) 0,
90
    .tls_private_tm[4]      = (void*) 0
91
};
92
 
93
// The argument to set_thread_area() is not a _hal_synth_tls_data,
94
// unfortunately. Instead it is a user_desc structure as per
95
// <asm/ldt.h>.
96
typedef struct _HAL_user_desc {
97
    int             ud_entry_number;
98
    unsigned long   ud_base_addr;
99
    int             ud_limits;
100
    int             ud_flags;
101
} _HAL_user_desc;
102
 
103
#define _HAL_USER_DESC_FLAGS_SEG_32BIT          (0x01 << 0)
104
#define _HAL_USER_DESC_FLAGS_CONTENTS_MASK      (0x03 << 1)
105
#define _HAL_USER_DESC_FLAGS_CONTENTS_SHIFT     1
106
#define _HAL_USER_DESC_FLAGS_CONTENTS_DATA      (0x00 << 1)
107
#define _HAL_USER_DESC_FLAGS_CONTENTS_STACK     (0x01 << 1)
108
#define _HAL_USER_DESC_FLAGS_CONTENTS_CODE      (0x02 << 1)
109
#define _HAL_USER_DESC_FLAGS_READ_EXEC_ONLY     (0x01 << 3)
110
#define _HAL_USER_DESC_FLAGS_LIMIT_IN_PAGES     (0x01 << 4)
111
#define _HAL_USER_DESC_FLAGS_SEG_NOT_PRESENT    (0x01 << 5)
112
#define _HAL_USER_DESC_FLAGS_USEABLE            (0x01 << 6)
113
 
114
 
115
// And it can also be statically initialized. There is no need to worry
116
// about alignment this time. Note that one of the fields gets updated
117
// by the system call so this cannot be a const structure.
118
 
119
_HAL_user_desc   _hal_synth_user_desc = {
120
    .ud_entry_number        = -1,   // Let the kernel pick the descriptor table entry
121
    .ud_base_addr           = (unsigned long) &_hal_synth_tls_data,
122
    .ud_limits              = 1,    // A single page will do
123
    .ud_flags               = (_HAL_USER_DESC_FLAGS_SEG_32BIT       |
124
                               _HAL_USER_DESC_FLAGS_CONTENTS_DATA   |
125
                               _HAL_USER_DESC_FLAGS_READ_EXEC_ONLY  |
126
                               _HAL_USER_DESC_FLAGS_LIMIT_IN_PAGES  |
127
                               _HAL_USER_DESC_FLAGS_USEABLE)
128
};

powered by: WebSVN 2.1.0

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