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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [synth/] [i386linux/] [v2_0/] [include/] [var_arch.h] - Blame information for rev 197

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

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