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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [mn10300/] [arch/] [current/] [include/] [hal_arch.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_HAL_ARCH_H
2
#define CYGONCE_HAL_HAL_ARCH_H
3
//==========================================================================
4
//
5
//      hal_arch.h
6
//
7
//      Architecture specific abstractions
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 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):     nickg
45
// Contributors:  nickg, dmoseley
46
// Date:          1999-02-18
47
// Purpose:       Define architecture abstractions
48
// Usage:         #include <cyg/hal/hal_arch.h>
49
//              
50
//####DESCRIPTIONEND####
51
//
52
//==========================================================================
53
 
54
#include <pkgconf/hal.h>
55
#include <cyg/infra/cyg_type.h>
56
 
57
#include <cyg/hal/var_arch.h>
58
 
59
//--------------------------------------------------------------------------
60
// Exception handling function.
61
// This function is defined by the kernel according to this prototype. It is
62
// invoked from the HAL to deal with any CPU exceptions that the HAL does
63
// not want to deal with itself. It usually invokes the kernel's exception
64
// delivery mechanism.
65
 
66
externC void cyg_hal_deliver_exception( CYG_WORD code, CYG_ADDRWORD data );
67
 
68
//--------------------------------------------------------------------------
69
// Bit manipulation routines
70
 
71
externC cyg_uint32 hal_lsbit_index(cyg_uint32 mask);
72
externC cyg_uint32 hal_msbit_index(cyg_uint32 mask);
73
 
74
#define HAL_LSBIT_INDEX(index, mask) index = hal_lsbit_index(mask);
75
 
76
#define HAL_MSBIT_INDEX(index, mask) index = hal_msbit_index(mask);
77
 
78
//--------------------------------------------------------------------------
79
// Context Initialization
80
// Initialize the context of a thread.
81
// Arguments:
82
// _sp_ name of variable containing current sp, will be written with new sp
83
// _thread_ thread object address, passed as argument to entry point
84
// _entry_ entry point address.
85
// _id_ bit pattern used in initializing registers, for debugging.
86
 
87
#ifndef HAL_THREAD_INIT_CONTEXT_EXTRA
88
#define HAL_THREAD_INIT_CONTEXT_EXTRA(_regs_, _id_)
89
#endif
90
 
91
#define HAL_THREAD_INIT_CONTEXT( _sp_, _thread_, _entry_, _id_ )            \
92
{                                                                           \
93
    register HAL_SavedRegisters *_regs_;                                    \
94
    _regs_ = (HAL_SavedRegisters *)(((CYG_ADDRWORD)(_sp_)&~15) -            \
95
                                    sizeof(HAL_SavedRegisters)*2);          \
96
    HAL_THREAD_INIT_CONTEXT_EXTRA(_regs_, _id_);                            \
97
    _regs_->d0    = (CYG_WORD)(_thread_);                                   \
98
    _regs_->d1    = (_id_)|0xddd1;                                          \
99
    _regs_->d2    = (_id_)|0xddd2;                                          \
100
    _regs_->d3    = (_id_)|0xddd3;                                          \
101
    _regs_->a0    = (_id_)|0xaaa0;                                          \
102
    _regs_->a1    = (_id_)|0xaaa1;                                          \
103
    _regs_->a2    = (_id_)|0xaaa2;                                          \
104
    _regs_->a3    = (_id_)|0xaaa3;                                          \
105
    _regs_->mdr   = 0;                                                      \
106
    _regs_->lir   = 0;                                                      \
107
    _regs_->lar   = 0;                                                      \
108
    _regs_->psw   = 0x0000F00;                                              \
109
    _regs_->pc    = (CYG_WORD)(_entry_);                                    \
110
    _sp_          = (CYG_ADDRESS)_regs_;                                    \
111
}
112
 
113
//--------------------------------------------------------------------------
114
// Context switch macros.
115
// The arguments are pointers to locations where the stack pointer
116
// of the current thread is to be stored, and from where the sp of the
117
// next thread is to be fetched.
118
 
119
externC void hal_thread_switch_context( CYG_ADDRESS to, CYG_ADDRESS from );
120
externC void hal_thread_load_context( CYG_ADDRESS to )
121
    __attribute__ ((noreturn));
122
 
123
#define HAL_THREAD_SWITCH_CONTEXT(_fspptr_,_tspptr_)                    \
124
        hal_thread_switch_context((CYG_ADDRESS)_tspptr_,                \
125
                                  (CYG_ADDRESS)_fspptr_);
126
 
127
#define HAL_THREAD_LOAD_CONTEXT(_tspptr_)                               \
128
        hal_thread_load_context( (CYG_ADDRESS)_tspptr_ );
129
 
130
//--------------------------------------------------------------------------
131
// Execution reorder barrier.
132
// When optimizing the compiler can reorder code. In multithreaded systems
133
// where the order of actions is vital, this can sometimes cause problems.
134
// This macro may be inserted into places where reordering should not happen.
135
 
136
#define HAL_REORDER_BARRIER() asm volatile ( "" : : : "memory" )
137
 
138
//--------------------------------------------------------------------------
139
// Breakpoint support
140
// HAL_BREAKPOINT() is a code sequence that will cause a breakpoint to
141
// happen if executed.
142
// HAL_BREAKINST is the value of the breakpoint instruction and
143
// HAL_BREAKINST_SIZE is its size in bytes.
144
// HAL_BREAKINST_TYPE is the type.
145
 
146
#define HAL_BREAKPOINT(_label_)                 \
147
asm volatile (" .globl  _" #_label_ ";"         \
148
              "_"#_label_":"                    \
149
              ".byte 0xFF"                      \
150
    );
151
 
152
#define HAL_BREAKINST           0xFF
153
 
154
#define HAL_BREAKINST_SIZE      1
155
 
156
#define HAL_BREAKINST_TYPE      cyg_uint8
157
 
158
//--------------------------------------------------------------------------
159
// Thread register state manipulation for GDB support.
160
 
161
// Translate a stack pointer as saved by the thread context macros above into
162
// a pointer to a HAL_SavedRegisters structure.
163
#define HAL_THREAD_GET_SAVED_REGISTERS( _sp_, _regs_ )                     \
164
        (_regs_) = (HAL_SavedRegisters *)(_sp_)
165
 
166
#ifndef HAL_GET_GDB_EXTRA_REGISTERS
167
#define HAL_GET_GDB_EXTRA_REGISTERS( _regval_, _regs_ )
168
#endif
169
#ifndef HAL_SET_GDB_EXTRA_REGISTERS
170
#define HAL_SET_GDB_EXTRA_REGISTERS( _regs_, _regval_ )
171
#endif
172
 
173
 
174
// Copy a set of registers from a HAL_SavedRegisters structure into a
175
// GDB ordered array.    
176
//
177
// The CYGMON version should differ by also handling SP and PSW
178
// since we will be using a different stack.
179
#ifdef CYGPKG_CYGMON
180
#define HAL_GET_GDB_REGISTERS( _aregval_ , _regs_ )             \
181
{                                                               \
182
    CYG_ADDRWORD *_regval_ = (CYG_ADDRWORD *)(_aregval_);       \
183
                                                                \
184
    _regval_[0]         = (_regs_)->d0;                         \
185
    _regval_[1]         = (_regs_)->d1;                         \
186
    _regval_[2]         = (_regs_)->d2;                         \
187
    _regval_[3]         = (_regs_)->d3;                         \
188
    _regval_[4]         = (_regs_)->a0;                         \
189
    _regval_[5]         = (_regs_)->a1;                         \
190
    _regval_[6]         = (_regs_)->a2;                         \
191
    _regval_[7]         = (_regs_)->a3;                         \
192
                                                                \
193
    _regval_[8]         = (_regs_)->sp;                         \
194
    _regval_[9]         = (_regs_)->pc;                         \
195
    _regval_[10]        = (_regs_)->mdr;                        \
196
    _regval_[11]        = (_regs_)->psw;                        \
197
                                                                \
198
    _regval_[12]        = (_regs_)->lar;                        \
199
    _regval_[13]        = (_regs_)->lir;                        \
200
    HAL_GET_GDB_EXTRA_REGISTERS( _regval_, _regs_ );            \
201
}
202
#else
203
#define HAL_GET_GDB_REGISTERS( _aregval_ , _regs_ )             \
204
{                                                               \
205
    CYG_ADDRWORD *_regval_ = (CYG_ADDRWORD *)(_aregval_);       \
206
                                                                \
207
    _regval_[0]         = (_regs_)->d0;                         \
208
    _regval_[1]         = (_regs_)->d1;                         \
209
    _regval_[2]         = (_regs_)->d2;                         \
210
    _regval_[3]         = (_regs_)->d3;                         \
211
    _regval_[4]         = (_regs_)->a0;                         \
212
    _regval_[5]         = (_regs_)->a1;                         \
213
    _regval_[6]         = (_regs_)->a2;                         \
214
    _regval_[7]         = (_regs_)->a3;                         \
215
                                                                \
216
    _regval_[8] = (_regs_)->sp = (CYG_ADDRWORD)(_regs_) +       \
217
                                 sizeof(HAL_SavedRegisters);    \
218
    _regval_[9]         = (_regs_)->pc;                         \
219
    _regval_[10]        = (_regs_)->mdr;                        \
220
    _regval_[11]        = (_regs_)->psw;                        \
221
                                                                \
222
    _regval_[12]        = (_regs_)->lar;                        \
223
    _regval_[13]        = (_regs_)->lir;                        \
224
    HAL_GET_GDB_EXTRA_REGISTERS( _regval_, _regs_ );            \
225
}
226
#endif
227
 
228
// Copy a GDB ordered array into a HAL_SavedRegisters structure.
229
//
230
// The CYGMON version should differ by also handling SP and PSW
231
// since we will be using a different stack.
232
#ifdef CYGPKG_CYGMON
233
#define HAL_SET_GDB_REGISTERS( _regs_ , _aregval_ )                     \
234
{                                                                       \
235
    CYG_ADDRWORD *_regval_ = (CYG_ADDRWORD *)(_aregval_);               \
236
                                                                        \
237
    (_regs_)->d0             = _regval_[0];                             \
238
    (_regs_)->d1             = _regval_[1];                             \
239
    (_regs_)->d2             = _regval_[2];                             \
240
    (_regs_)->d3             = _regval_[3];                             \
241
    (_regs_)->a0             = _regval_[4];                             \
242
    (_regs_)->a1             = _regval_[5];                             \
243
    (_regs_)->a2             = _regval_[6];                             \
244
    (_regs_)->a3             = _regval_[7];                             \
245
                                                                        \
246
    (_regs_)->sp             = _regval_[8];                             \
247
    (_regs_)->pc             = _regval_[9];                             \
248
    (_regs_)->mdr            = _regval_[10];                            \
249
    (_regs_)->psw            = _regval_[11];                            \
250
                                                                        \
251
    (_regs_)->lar            = _regval_[12];                            \
252
    (_regs_)->lir            = _regval_[13];                            \
253
                                                                        \
254
    HAL_SET_GDB_EXTRA_REGISTERS( _regs_, _regval_ );                    \
255
}
256
#else
257
#define HAL_SET_GDB_REGISTERS( _regs_ , _aregval_ )                     \
258
{                                                                       \
259
    CYG_ADDRWORD *_regval_ = (CYG_ADDRWORD *)(_aregval_);               \
260
                                                                        \
261
    (_regs_)->d0             = _regval_[0];                             \
262
    (_regs_)->d1             = _regval_[1];                             \
263
    (_regs_)->d2             = _regval_[2];                             \
264
    (_regs_)->d3             = _regval_[3];                             \
265
    (_regs_)->a0             = _regval_[4];                             \
266
    (_regs_)->a1             = _regval_[5];                             \
267
    (_regs_)->a2             = _regval_[6];                             \
268
    (_regs_)->a3             = _regval_[7];                             \
269
                                                                        \
270
    (_regs_)->pc              = _regval_[9];                            \
271
    (_regs_)->mdr             = _regval_[10];                           \
272
                                                                        \
273
    (_regs_)->lar             = _regval_[12];                           \
274
    (_regs_)->lir             = _regval_[13];                           \
275
                                                                        \
276
    /* We do not allow the SP or PSW to be set. Changing the SP will    \
277
     * mess up the saved state. No PSW is saved on thread context       \
278
     * switches, so there is nowhere to save it to.                     \
279
     */                                                                 \
280
                                                                        \
281
     HAL_SET_GDB_EXTRA_REGISTERS( _regs_, _regval_ );                   \
282
}
283
#endif
284
 
285
//-------------------------------------------------------------------------
286
// HAL setjmp
287
// Note: These definitions are repeated in context.S. If changes are required
288
// remember to update both sets.
289
 
290
#define CYGARC_JMP_BUF_SP        0
291
#define CYGARC_JMP_BUF_D2        1
292
#define CYGARC_JMP_BUF_D3        2
293
#define CYGARC_JMP_BUF_A2        3
294
#define CYGARC_JMP_BUF_A3        4
295
#define CYGARC_JMP_BUF_LR        5
296
 
297
#define CYGARC_JMP_BUF_SIZE      6
298
 
299
typedef cyg_uint32 hal_jmp_buf[CYGARC_JMP_BUF_SIZE];
300
 
301
externC int hal_setjmp(hal_jmp_buf env);
302
externC void hal_longjmp(hal_jmp_buf env, int val);
303
 
304
//-------------------------------------------------------------------------
305
// Idle thread code.
306
// This macro is called in the idle thread loop, and gives the HAL the
307
// chance to insert code. Typical idle thread behaviour might be to halt the
308
// processor.
309
 
310
externC void hal_idle_thread_action(cyg_uint32 loop_count);
311
 
312
#define HAL_IDLE_THREAD_ACTION(_count_) hal_idle_thread_action(_count_)
313
 
314
//-----------------------------------------------------------------------------
315
// Minimal and sensible stack sizes: the intention is that applications
316
// will use these to provide a stack size in the first instance prior to
317
// proper analysis.  Idle thread stack should be this big.
318
 
319
//    THESE ARE NOT INTENDED TO BE MICROMETRICALLY ACCURATE FIGURES.
320
//           THEY ARE HOWEVER ENOUGH TO START PROGRAMMING.
321
// YOU MUST MAKE YOUR STACKS LARGER IF YOU HAVE LARGE "AUTO" VARIABLES!
322
 
323
// We define quite large stack needs for SPARClite, for it requires 576
324
// bytes (144 words) to process an interrupt and thread-switch, and
325
// momentarily, but needed in case of recursive interrupts, it needs 208
326
// words - if a sequence of saves to push out other regsets is interrupted.
327
 
328
// This is not a config option because it should not be adjusted except
329
// under "enough rope" sort of disclaimers.
330
 
331
// Worst case stack frame size: return link + 4 args + 4 pushed registers.
332
#define CYGNUM_HAL_STACK_FRAME_SIZE (40)
333
 
334
// Stack needed for a context switch:
335
#define CYGNUM_HAL_STACK_CONTEXT_SIZE (60)
336
 
337
// Interrupt + call to ISR, interrupt_end() and the DSR
338
#define CYGNUM_HAL_STACK_INTERRUPT_SIZE (128)
339
 
340
#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK 
341
 
342
// An interrupt stack which is large enough for all possible interrupt
343
// conditions (and only used for that purpose) exists.  "User" stacks
344
// can be much smaller
345
 
346
#define CYGNUM_HAL_STACK_SIZE_MINIMUM (CYGNUM_HAL_STACK_CONTEXT_SIZE+      \
347
                                       CYGNUM_HAL_STACK_INTERRUPT_SIZE*2+  \
348
                                       CYGNUM_HAL_STACK_FRAME_SIZE*16)
349
#define CYGNUM_HAL_STACK_SIZE_TYPICAL (2048)
350
 
351
#else // CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK 
352
 
353
// No separate interrupt stack exists.  Make sure all threads contain
354
// a stack sufficiently large.
355
 
356
#define CYGNUM_HAL_STACK_SIZE_MINIMUM (4096)
357
#define CYGNUM_HAL_STACK_SIZE_TYPICAL (4096)
358
 
359
#endif
360
 
361
//--------------------------------------------------------------------------
362
// Macros for switching context between two eCos instances (jump from
363
// code in ROM to code in RAM or vice versa).
364
#define CYGARC_HAL_SAVE_GP()
365
#define CYGARC_HAL_RESTORE_GP()
366
 
367
//--------------------------------------------------------------------------
368
#endif // CYGONCE_HAL_HAL_ARCH_H
369
// EOF hal_arch.h

powered by: WebSVN 2.1.0

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