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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [synth/] [i386linux/] [current/] [include/] [var_arch.h] - Blame information for rev 834

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

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_HAL_VAR_ARCH_H
2
#define CYGONCE_HAL_VAR_ARCH_H
3
 
4
//=============================================================================
5
//
6
//      var_arch.h
7
//
8
//      Per-processor information such as processor save states.
9
//
10
//=============================================================================
11
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
12
// -------------------------------------------                              
13
// This file is part of eCos, the Embedded Configurable Operating System.   
14
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 Free Software Foundation, Inc.
15
//
16
// eCos is free software; you can redistribute it and/or modify it under    
17
// the terms of the GNU General Public License as published by the Free     
18
// Software Foundation; either version 2 or (at your option) any later      
19
// version.                                                                 
20
//
21
// eCos is distributed in the hope that it will be useful, but WITHOUT      
22
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
24
// for more details.                                                        
25
//
26
// You should have received a copy of the GNU General Public License        
27
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
28
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
29
//
30
// As a special exception, if other files instantiate templates or use      
31
// macros or inline functions from this file, or you compile this file      
32
// and link it with other works to produce a work based on this file,       
33
// this file does not by itself cause the resulting work to be covered by   
34
// the GNU General Public License. However the source code for this file    
35
// must still be made available in accordance with section (3) of the GNU   
36
// General Public License v2.                                               
37
//
38
// This exception does not invalidate any other reasons why a work based    
39
// on this file might be covered by the GNU General Public License.         
40
// -------------------------------------------                              
41
// ####ECOSGPLCOPYRIGHTEND####                                              
42
//=============================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):   proven
46
// Contributors:proven, pjo, nickg,bartv
47
// Date:        1998-10-05
48
// Purpose:     Define architecture abstractions
49
// Usage:       #include <cyg/hal/hal_arch.h>
50
//
51
//####DESCRIPTIONEND####
52
//
53
//=============================================================================
54
 
55
 
56
#include <cyg/infra/cyg_type.h>
57
 
58
//-----------------------------------------------------------------------------
59
// Processor saved states. This structure is also defined in arch.inc for
60
// assembly code. Do not change this without changing that (or vice versa).
61
// Note: there is no need to worry about floating point contexts, see context.S
62
 
63
typedef struct
64
{
65
    cyg_uint32  esp;
66
    cyg_uint32  next_context;           // only used when dropping through...
67
    cyg_uint32  ebp;                    // ...from switch_ to load_context
68
    cyg_uint32  ebx;
69
    cyg_uint32  esi;
70
    cyg_uint32  edi;
71
    cyg_bool    interrupts;             // Are interrupts enabled for this thread?
72
} HAL_SavedRegisters;
73
 
74
// An additional structure used for per-thread data. This is not
75
// actually part of the standard HAL. However gcc can generate code
76
// which expects one of these structures to be accessible via
77
// %gs:0, e.g. when -fstack-protector is enabled.
78
//
79
// This definition is based on one in the glibc sources.
80
typedef struct _HAL_TLS_Data {
81
    void*       tls_tcb;
82
    void*       tls_dtv;
83
    void*       tls_self;
84
    int         tls_multiple_threads;
85
    void*       tls_sysinfo;
86
    void*       tls_stack_guard;
87
    void*       tls_pointer_guard;
88
    int         tls_gscope_flag;
89
    int         tls_private_futex;
90
    void*       tls_private_tm[5];
91
} _HAL_TLS_Data;
92
 
93
//-----------------------------------------------------------------------------
94
// Bit manipulation routines. These are provided by the processor variant
95
// HAL to allow for processor-specific implementations.
96
 
97
#define HAL_LSBIT_INDEX(index, mask)            \
98
CYG_MACRO_START                                 \
99
    asm volatile( "bsfl %1,%0\n"                \
100
                  : "=r" (index)                \
101
                  : "r" (mask)                  \
102
                );                              \
103
CYG_MACRO_END
104
 
105
#define HAL_MSBIT_INDEX(index, mask)            \
106
CYG_MACRO_START                                 \
107
    asm volatile( "bsrl %1,%0\n"                \
108
                  : "=r" (index)                \
109
                  : "r" (mask)                  \
110
                );                              \
111
CYG_MACRO_END
112
 
113
//-----------------------------------------------------------------------------
114
// Context Initialization
115
// Initialize the context of a thread.
116
// Arguments:
117
// _sp_ name of variable containing current sp, will be written with new sp
118
// _thread_ thread object address, passed as argument to entry point
119
// _entry_ entry point address.
120
// _id_ bit pattern used in initializing registers, for debugging.
121
 
122
#define HAL_THREAD_INIT_CONTEXT( _sparg_, _thread_, _entry_, _id_ )       \
123
    CYG_MACRO_START                                                       \
124
    register CYG_WORD* _sp_ = ((CYG_WORD*)((_sparg_) &~15));              \
125
    register HAL_SavedRegisters *_regs_;                                  \
126
                                                                          \
127
    /* The 'ret' executed at the end of hal_thread_load_context will  */  \
128
    /* use the last entry on the stack as a return pointer (_entry_). */  \
129
    /* Cyg_HardwareThread::thread_entry expects one argument at stack */  \
130
    /* offset 4 (_thread_). The (0xDEADBEEF) entry is the return addr */  \
131
    /* for thread_entry (which is never used).                        */  \
132
    *(--_sp_) = (CYG_WORD)(0);                                            \
133
    *(--_sp_) = (CYG_WORD)(0);                                            \
134
    *(--_sp_) = (CYG_WORD)(0);                                            \
135
    *(--_sp_) = (CYG_WORD)(0);                                            \
136
    *(--_sp_) = (CYG_WORD)(_thread_);                                     \
137
    *(--_sp_) = (CYG_WORD)(0);                                            \
138
    *(--_sp_) = (CYG_WORD)(_entry_);                                      \
139
                                                                          \
140
    _regs_ = (HAL_SavedRegisters *)                                       \
141
               ((unsigned long)_sp_ - sizeof(HAL_SavedRegisters));        \
142
    _regs_->esp    = (CYG_WORD) _sp_;                                     \
143
    _regs_->ebx    = (CYG_WORD)(_id_);                                    \
144
    _regs_->ebp    = (CYG_WORD)(_id_);                                    \
145
    _regs_->esi    = (CYG_WORD)(_id_);                                    \
146
    _regs_->edi    = (CYG_WORD)(_id_);                                    \
147
    _regs_->interrupts = true;                                            \
148
    (_sparg_)      = (CYG_ADDRESS) _regs_;                                \
149
    CYG_MACRO_END
150
 
151
//-----------------------------------------------------------------------------
152
// Context switch macros.
153
// The arguments are pointers to locations where the stack pointer
154
// of the current thread is to be stored, and from where the sp of the
155
// next thread is to be fetched.
156
 
157
externC void hal_thread_switch_context( CYG_ADDRESS _to_, CYG_ADDRESS _from_ );
158
externC void hal_thread_load_context( CYG_ADDRESS _to_ )
159
    __attribute__ ((noreturn));
160
 
161
#define HAL_THREAD_SWITCH_CONTEXT(_fspptr_,_tspptr_)                    \
162
        hal_thread_switch_context((CYG_ADDRESS)_tspptr_,(CYG_ADDRESS)_fspptr_);
163
 
164
#define HAL_THREAD_LOAD_CONTEXT(_tspptr_)                               \
165
        hal_thread_load_context( (CYG_ADDRESS)_tspptr_ );
166
 
167
//-----------------------------------------------------------------------------
168
// HAL setjmp
169
 
170
#define CYGARC_JMP_BUF_SP        0
171
#define CYGARC_JMP_BUF_EBP       1
172
#define CYGARC_JMP_BUF_EBX       2
173
#define CYGARC_JMP_BUF_ESI       3
174
#define CYGARC_JMP_BUF_EDI       4
175
#define CYGARC_JMP_BUF_PC        5
176
 
177
#define CYGARC_JMP_BUF_SIZE      6
178
 
179
typedef cyg_uint32 hal_jmp_buf[CYGARC_JMP_BUF_SIZE];
180
 
181
externC int hal_setjmp(hal_jmp_buf env);
182
externC void hal_longjmp(hal_jmp_buf env, int val);
183
 
184
//-----------------------------------------------------------------------------
185
// Minimal and sensible stack sizes: the intention is that applications
186
// will use these to provide a stack size in the first instance prior to
187
// proper analysis.  Idle thread stack should be this big.
188
 
189
//    THESE ARE NOT INTENDED TO BE MICROMETRICALLY ACCURATE FIGURES.
190
//           THEY ARE HOWEVER ENOUGH TO START PROGRAMMING.
191
// YOU MUST MAKE YOUR STACKS LARGER IF YOU HAVE LARGE "AUTO" VARIABLES!
192
 
193
// This is not a config option because it should not be adjusted except
194
// under "enough rope" sort of disclaimers.
195
 
196
// Stack frame overhead per call. 3 local registers (edi, esi, ebx) and
197
// return address.
198
#define CYGNUM_HAL_STACK_FRAME_SIZE (4 * 4)
199
 
200
// Stack needed for a context switch (i386reg_context_size from i386.inc)
201
#define CYGNUM_HAL_STACK_CONTEXT_SIZE (4 * 24)
202
 
203
// Interrupt stack size. Interrupts are handled by signals so the relevant
204
// data is MINSIGSTKSIZE (see man sigaltstack) or 2048. Given the
205
// multiplier *15 for STACK_SIZE_MINIMUM, this should be adequate.
206
#define CYGNUM_HAL_STACK_INTERRUPT_SIZE 2048
207
 
208
// We define a minimum stack size as the minimum any thread could ever
209
// legitimately get away with. We can throw asserts if users ask for less
210
// than this. Allow enough for three interrupt sources - clock, serial and
211
// one other
212
//
213
// On the synthetic target memory is cheap so comparatively large stacks
214
// are possible. This avoids stack overflow problems when working with
215
// the synthetic target, although arguably the problem is now deferred to
216
// when the application is moved to real hardware where it will be more
217
// difficult to track down.
218
#define CYGNUM_HAL_STACK_SIZE_MINIMUM (16 * 1024)
219
#define CYGNUM_HAL_STACK_SIZE_TYPICAL (32 * 1024)
220
 
221
//--------------------------------------------------------------------------
222
// Macros for switching context between two eCos instances (jump from
223
// code in ROM to code in RAM or vice versa).
224
#define CYGARC_HAL_SAVE_GP()
225
#define CYGARC_HAL_RESTORE_GP()
226
 
227
//--------------------------------------------------------------------------
228
#endif // CYGONCE_HAL_VAR_ARCH_H
229
// End of var_arch.h

powered by: WebSVN 2.1.0

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