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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [mn10300/] [arch/] [v2_0/] [include/] [hal_arch.h] - Blame information for rev 324

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

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

powered by: WebSVN 2.1.0

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