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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [sh/] [arch/] [current/] [include/] [hal_var_bank.h] - Blame information for rev 856

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

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_HAL_VAR_BANK_H
2
#define CYGONCE_HAL_VAR_BANK_H
3
//=============================================================================
4
//
5
//      hal_var_bank.h
6
//
7
//      Architecture abstractions for variants with banked registers
8
//
9
//=============================================================================
10
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
11
// -------------------------------------------                              
12
// This file is part of eCos, the Embedded Configurable Operating System.   
13
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
14
//
15
// eCos is free software; you can redistribute it and/or modify it under    
16
// the terms of the GNU General Public License as published by the Free     
17
// Software Foundation; either version 2 or (at your option) any later      
18
// version.                                                                 
19
//
20
// eCos is distributed in the hope that it will be useful, but WITHOUT      
21
// ANY 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        
26
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
27
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
28
//
29
// As a special exception, if other files instantiate templates or use      
30
// macros or inline functions from this file, or you compile this file      
31
// and link it with other works to produce a work based on this file,       
32
// this file does not by itself cause the resulting work to be covered by   
33
// the GNU General Public License. However the source code for this file    
34
// must still be made available in accordance with section (3) of the GNU   
35
// General Public License v2.                                               
36
//
37
// This exception does not invalidate any other reasons why a work based    
38
// on this file might be covered by the GNU General Public License.         
39
// -------------------------------------------                              
40
// ####ECOSGPLCOPYRIGHTEND####                                              
41
//=============================================================================
42
//#####DESCRIPTIONBEGIN####
43
//
44
// Author(s):   jskov
45
// Contributors:jskov, nickg
46
// Date:        2002-01-11
47
// Purpose:     Architecture abstractions for variants with banked registers
48
//              
49
//####DESCRIPTIONEND####
50
//
51
//=============================================================================
52
 
53
//-----------------------------------------------------------------------------
54
// Processor saved states:
55
 
56
typedef struct
57
{
58
    // These are common to all saved states
59
    cyg_uint32   r[16];                 // Data regs
60
    cyg_uint32   macl;                  // Multiply and accumulate - low
61
    cyg_uint32   mach;                  // Multiply and accumulate - high
62
 
63
#ifdef CYGHWR_HAL_SH_FPU
64
    cyg_uint32  fr[CYGHWR_HAL_SH_FPU_REGS]; // Floating point registers
65
    cyg_uint32  fpul;                   // Floating point comm reg
66
    cyg_uint32  fpscr;                  // Floating point status/control reg
67
#endif
68
 
69
    cyg_uint32   pr;                    // Procedure Reg
70
    cyg_uint32   sr;                    // Status Reg
71
    cyg_uint32   pc;                    // Program Counter
72
 
73
    // This marks the limit of state saved during a context switch and
74
    // is used to calculate necessary stack allocation for context switches.
75
    // It would probably be better to have a union instead...
76
    cyg_uint32   context_size[0];
77
 
78
    // These are only saved on interrupts
79
    cyg_uint32   vbr;                   // Vector Base Register
80
    cyg_uint32   gbr;                   // Global Base Register
81
 
82
    // These are only saved on interrupts
83
    cyg_uint32   event;                 // EXCEVT or INTEVT
84
} HAL_SavedRegisters;
85
 
86
//-----------------------------------------------------------------------------
87
// Context Initialization
88
// Initialize the context of a thread.
89
// Arguments:
90
// _sparg_ name of variable containing current sp, will be written with new sp
91
// _thread_ thread object address, passed as argument to entry point
92
// _entry_ entry point address.
93
// _id_ bit pattern used in initializing registers, for debugging.
94
 
95
#ifdef CYGHWR_HAL_SH_FPU
96
#include <cyg/hal/sh_regs.h>
97
#define HAL_THREAD_INIT_CONTEXT_FPU( _regs_ )           \
98
{                                                       \
99
    int _i_;                                            \
100
    (_regs_)->fpul = 0;                                 \
101
    (_regs_)->fpscr = CYG_FPSCR;                        \
102
    for( _i_ = 0; _i_ < CYGHWR_HAL_SH_FPU_REGS; _i_++ ) \
103
        (_regs_)->fr[_i_] = 0;                          \
104
}
105
#else
106
#define HAL_THREAD_INIT_CONTEXT_FPU( _regs_ )
107
#endif
108
 
109
#define HAL_THREAD_INIT_CONTEXT( _sparg_, _thread_, _entry_, _id_ )           \
110
    CYG_MACRO_START                                                           \
111
    register CYG_WORD _sp_ = (CYG_WORD)_sparg_;                               \
112
    register HAL_SavedRegisters *_regs_;                                      \
113
    int _i_;                                                                  \
114
    _sp_ = _sp_ & ~(CYGARC_ALIGNMENT-1);                                      \
115
    /* Note that _regs_ below should be aligned if HAL_SavedRegisters */      \
116
    /* stops being aligned to CYGARC_ALIGNMENT                        */      \
117
    _regs_ = (HAL_SavedRegisters *)((_sp_) - sizeof(HAL_SavedRegisters));     \
118
    for( _i_ = 0; _i_ < 16; _i_++ ) (_regs_)->r[_i_] = (_id_)|_i_;            \
119
    (_regs_)->r[15] = (CYG_WORD)(_regs_);      /* SP = top of stack      */   \
120
    (_regs_)->r[04] = (CYG_WORD)(_thread_);    /* R4 = arg1 = thread ptr */   \
121
    (_regs_)->mach = 0;                        /* MACH = 0               */   \
122
    (_regs_)->macl = 0;                        /* MACL = 0               */   \
123
    (_regs_)->pr = (CYG_WORD)(_entry_);        /* PR = entry point       */   \
124
    (_regs_)->sr = 0x70000000;                 /* SR = enable interrupts */   \
125
    (_regs_)->pc = (CYG_WORD)(_entry_);        /* set PC for thread dbg  */   \
126
    HAL_THREAD_INIT_CONTEXT_FPU( _regs_ );     /* Init FPU state         */   \
127
    _sparg_ = (CYG_ADDRESS)_regs_;                                            \
128
    CYG_MACRO_END
129
 
130
//-----------------------------------------------------------------------------
131
// Thread register state manipulation for GDB support.
132
 
133
// Translate a stack pointer as saved by the thread context macros above into
134
// a pointer to a HAL_SavedRegisters structure.
135
#define HAL_THREAD_GET_SAVED_REGISTERS( _sp_, _regs_ )  \
136
        (_regs_) = (HAL_SavedRegisters *)(_sp_)
137
 
138
#ifdef CYGHWR_HAL_SH_FPU
139
#define HAL_GET_GDB_REGISTERS_FPU( _regval_, _regs_ )   \
140
{                                                       \
141
    _regval_[23] = (_regs_)->fpul;                      \
142
    _regval_[24] = (_regs_)->fpscr;                     \
143
                                                        \
144
    for( _i_ = 0; _i_ < 16; _i_++ )                     \
145
        _regval_[25+_i_] = (_regs_)->fr[_i_];           \
146
}
147
 
148
#define HAL_SET_GDB_REGISTERS_FPU( _regs_, _regval_ )   \
149
{                                                       \
150
    (_regs_)->fpul = _regval_[23];                      \
151
    (_regs_)->fpscr = _regval_[24];                     \
152
                                                        \
153
    for( _i_ = 0; _i_ < 16; _i_++ )                     \
154
        (_regs_)->fr[_i_] = _regval_[25+_i_];           \
155
}
156
#else
157
#define HAL_GET_GDB_REGISTERS_FPU( _regval_, _regs_ )
158
#define HAL_SET_GDB_REGISTERS_FPU( _regs_, _regval_ )
159
#endif
160
 
161
// Copy a set of registers from a HAL_SavedRegisters structure into a
162
// GDB ordered array.    
163
#define HAL_GET_GDB_REGISTERS( _aregval_, _regs_ )              \
164
    CYG_MACRO_START                                             \
165
    CYG_ADDRWORD *_regval_ = (CYG_ADDRWORD *)(_aregval_);       \
166
    int _i_;                                                    \
167
                                                                \
168
    for( _i_ = 0; _i_ < 8; _i_++ )                              \
169
    {                                                           \
170
        _regval_[_i_] = (_regs_)->r[_i_];                       \
171
        _regval_[43+_i_] = (_regs_)->r[_i_];                    \
172
        _regval_[51+_i_] = 0;                                   \
173
    }                                                           \
174
                                                                \
175
    for( /* _i_ = 8 */ ; _i_ < 16; _i_++ )                      \
176
        _regval_[_i_] = (_regs_)->r[_i_];                       \
177
                                                                \
178
    _regval_[16] = (_regs_)->pc;                                \
179
    _regval_[17] = (_regs_)->pr;                                \
180
    _regval_[18] = (_regs_)->gbr;                               \
181
    _regval_[19] = (_regs_)->vbr;                               \
182
    _regval_[20] = (_regs_)->mach;                              \
183
    _regval_[21] = (_regs_)->macl;                              \
184
    _regval_[22] = (_regs_)->sr;                                \
185
                                                                \
186
    HAL_GET_GDB_REGISTERS_FPU( _regval_, _regs_ );              \
187
                                                                \
188
    CYG_MACRO_END
189
 
190
// Copy a GDB ordered array into a HAL_SavedRegisters structure.
191
#define HAL_SET_GDB_REGISTERS( _regs_ , _aregval_ )             \
192
    CYG_MACRO_START                                             \
193
    CYG_ADDRWORD *_regval_ = (CYG_ADDRWORD *)(_aregval_);       \
194
    int _i_;                                                    \
195
                                                                \
196
    for( _i_ = 0; _i_ < 16; _i_++ )                             \
197
        (_regs_)->r[_i_] = _regval_[_i_];                       \
198
                                                                \
199
    (_regs_)->pc = _regval_[16];                                \
200
    (_regs_)->pr = _regval_[17];                                \
201
    (_regs_)->gbr  = _regval_[18];                              \
202
    (_regs_)->vbr  = _regval_[19];                              \
203
    (_regs_)->mach = _regval_[20];                              \
204
    (_regs_)->macl = _regval_[21];                              \
205
    (_regs_)->sr = _regval_[22];                                \
206
                                                                \
207
    HAL_SET_GDB_REGISTERS_FPU( _regs_, _regval_ );              \
208
                                                                \
209
    CYG_MACRO_END
210
 
211
//--------------------------------------------------------------------------
212
// CPU address space translation macros
213
#define CYGARC_BUS_ADDRESS(x)       ((CYG_ADDRWORD)(x) & 0x1fffffff)
214
#define CYGARC_CACHED_ADDRESS(x)    (CYGARC_BUS_ADDRESS(x)|0x80000000)
215
#define CYGARC_UNCACHED_ADDRESS(x)  (CYGARC_BUS_ADDRESS(x)|0xa0000000)
216
 
217
//-----------------------------------------------------------------------------
218
#endif // CYGONCE_HAL_VAR_BANK_H
219
// End of hal_var_bank.h

powered by: WebSVN 2.1.0

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