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

Subversion Repositories openrisc_me

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

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
//
6
//      hal_arch.h
7
//
8
//      Architecture specific abstractions
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):    msalter
47
// Contributors: msalter
48
// Date:         2001-02-17
49
// Purpose:      Define architecture abstractions
50
// Usage:        #include <cyg/hal/hal_arch.h>
51
//              
52
//####DESCRIPTIONEND####
53
//
54
//==========================================================================
55
 
56
#ifndef __ASSEMBLER__
57
#include <pkgconf/hal.h>
58
#include <cyg/infra/cyg_type.h>
59
 
60
#include <cyg/hal/var_arch.h>
61
 
62
//--------------------------------------------------------------------------
63
// Processor saved states:
64
// The layout of this structure is also defined in "arch.inc", for assembly
65
// code. Do not change this without changing that (or vice versa).
66
// Notes: This structure is carefully laid out. It is a multiple of 8
67
// bytes and the pc and badvr fields are positioned to ensure that
68
// they are on 8 byte boundaries. 
69
 
70
 
71
typedef struct
72
{
73
    CYG_WORD16    vector;
74
    CYG_WORD32    spc_fiq;
75
    CYG_WORD32    spc_irq;
76
    CYG_WORD16    ssr_fiq;
77
    CYG_WORD16    ssr_irq;
78
    CYG_WORD16    ssr_swi;
79
    CYG_WORD16    r[8];
80
    CYG_WORD32    a[8];
81
} HAL_SavedRegisters;
82
 
83
//--------------------------------------------------------------------------
84
// Exception handling function.
85
// This function is defined by the kernel according to this prototype. It is
86
// invoked from the HAL to deal with any CPU exceptions that the HAL does
87
// not want to deal with itself. It usually invokes the kernel's exception
88
// delivery mechanism.
89
 
90
externC void cyg_hal_deliver_exception( CYG_WORD code, CYG_ADDRWORD data );
91
 
92
//--------------------------------------------------------------------------
93
// Bit manipulation macros
94
 
95
externC cyg_uint32 hal_lsbit_index(cyg_uint32 mask);
96
externC cyg_uint32 hal_msbit_index(cyg_uint32 mask);
97
 
98
#define HAL_LSBIT_INDEX(index, mask) index = hal_lsbit_index(mask);
99
 
100
#define HAL_MSBIT_INDEX(index, mask) index = hal_msbit_index(mask);
101
 
102
//--------------------------------------------------------------------------
103
// Context Initialization
104
 
105
// Optional FPU context initialization
106
#define HAL_THREAD_INIT_FPU_CONTEXT( _regs_, _id_ )
107
 
108
// Initialize the context of a thread.
109
// Arguments:
110
// _sparg_ name of variable containing current sp, will be written with new sp
111
// _thread_ thread object address, passed as argument to entry point
112
// _entry_ entry point address.
113
// _id_ bit pattern used in initializing registers, for debugging.
114
#define HAL_THREAD_INIT_CONTEXT( _sparg_, _thread_, _entry_, _id_ )                     \
115
{                                                                                       \
116
}
117
 
118
//--------------------------------------------------------------------------
119
// Context switch macros.
120
// The arguments are pointers to locations where the stack pointer
121
// of the current thread is to be stored, and from where the sp of the
122
// next thread is to be fetched.
123
 
124
externC void hal_thread_switch_context( CYG_ADDRESS to, CYG_ADDRESS from );
125
externC void hal_thread_load_context( CYG_ADDRESS to )
126
    __attribute__ ((noreturn));
127
 
128
#define HAL_THREAD_SWITCH_CONTEXT(_fspptr_,_tspptr_)                    \
129
        hal_thread_switch_context( (CYG_ADDRESS)_tspptr_,               \
130
                                   (CYG_ADDRESS)_fspptr_);
131
 
132
#define HAL_THREAD_LOAD_CONTEXT(_tspptr_)                               \
133
        hal_thread_load_context( (CYG_ADDRESS)_tspptr_ );
134
 
135
//--------------------------------------------------------------------------
136
// Execution reorder barrier.
137
// When optimizing the compiler can reorder code. In multithreaded systems
138
// where the order of actions is vital, this can sometimes cause problems.
139
// This macro may be inserted into places where reordering should not happen.
140
// The "memory" keyword is potentially unnecessary, but it is harmless to
141
// keep it.
142
 
143
#define HAL_REORDER_BARRIER() asm volatile ( "" : : : "memory" )
144
 
145
//--------------------------------------------------------------------------
146
// Breakpoint support
147
// HAL_BREAKPOINT() is a code sequence that will cause a breakpoint to
148
// happen if executed.
149
// HAL_BREAKINST is the value of the breakpoint instruction and
150
// HAL_BREAKINST_SIZE is its size in bytes.
151
// HAL_BREAKINST_TYPE is the type.
152
 
153
#define HAL_BREAKPOINT(_label_)                 \
154
asm volatile (" .globl  _" #_label_ "\n"        \
155
              "_" #_label_":"                   \
156
              " break\n"                        \
157
    );
158
 
159
#define HAL_BREAKINST           0x9e99
160
#define HAL_BREAKINST_SIZE      2
161
#define HAL_BREAKINST_TYPE      cyg_uint16
162
 
163
//--------------------------------------------------------------------------
164
// Thread register state manipulation for GDB support.
165
 
166
// Default to a 32 bit register size for GDB register dumps.
167
#ifndef CYG_HAL_GDB_REG
168
#define CYG_HAL_GDB_REG CYG_WORD32
169
#endif
170
 
171
// Translate a stack pointer as saved by the thread context macros above into
172
// a pointer to a HAL_SavedRegisters structure.
173
#define HAL_THREAD_GET_SAVED_REGISTERS( _sp_, _regs_ )          \
174
        (_regs_) = (HAL_SavedRegisters *)(_sp_)
175
 
176
// Copy a set of registers from a HAL_SavedRegisters structure into a
177
// GDB ordered array.    
178
#define HAL_GET_GDB_REGISTERS( _aregval_ , _regs_ )             \
179
{                                                               \
180
    CYG_HAL_GDB_REG *_regval_ = (CYG_HAL_GDB_REG *)(_aregval_); \
181
    int _i_;                                                    \
182
                                                                \
183
    for( _i_ = 0; _i_ < 8; _i_++ )                              \
184
        _regval_[_i_] = ((CYG_WORD32)((_regs_)->r[_i_])) << 16; \
185
                                                                \
186
    for( _i_ = 0; _i_ < 8; _i_++ )                              \
187
        _regval_[_i_+8] = ((_regs_)->a[_i_]) << 16;             \
188
                                                                \
189
    for( _i_ = 0; _i_ < 8; _i_++ )                              \
190
        _regval_[_i_+16] = ((_regs_)->a[_i_]) & 0xffff0000UL;   \
191
                                                                \
192
    for( _i_ = 0; _i_ < 8; _i_++ )                              \
193
        _regval_[_i_+24] = (_regs_)->a[_i_];                    \
194
                                                                \
195
    _regval_[REG_SSR_FIQ] = ((CYG_WORD32)((_regs_)->ssr_fiq)) << 16; \
196
    _regval_[REG_SSR_IRQ] = ((CYG_WORD32)((_regs_)->ssr_irq)) << 16; \
197
    _regval_[REG_SSR_SWI] = ((CYG_WORD32)((_regs_)->ssr_swi)) << 16; \
198
    _regval_[REG_SPC_FIQ] = (_regs_)->spc_fiq;                  \
199
    _regval_[REG_SPC_IRQ] = (_regs_)->spc_irq;                  \
200
    switch ((_regs_)->vector) {                                 \
201
      case CYGNUM_HAL_VECTOR_SWI:                               \
202
        _regval_[REG_SR] = _regval_[REG_SSR_SWI];               \
203
        _regval_[REG_PC] = (_regs_)->a[6]; break;               \
204
      case CYGNUM_HAL_VECTOR_FIQ:                               \
205
        _regval_[REG_SR] = _regval_[REG_SSR_FIQ];               \
206
        _regval_[REG_PC] = (_regs_)->spc_fiq; break;            \
207
      default:                                                  \
208
        _regval_[REG_SR] = _regval_[REG_SSR_IRQ];               \
209
        _regval_[REG_PC] = (_regs_)->spc_irq; break;            \
210
    }                                                           \
211
}
212
 
213
// Copy a GDB ordered array into a HAL_SavedRegisters structure.
214
#define HAL_SET_GDB_REGISTERS( _regs_ , _aregval_ )             \
215
{                                                               \
216
    CYG_HAL_GDB_REG *_regval_ = (CYG_HAL_GDB_REG *)(_aregval_); \
217
    int _i_;                                                    \
218
                                                                \
219
    for( _i_ = 0; _i_ < 8; _i_++ )                              \
220
        (_regs_)->r[_i_] = _regval_[_i_] >> 16;                 \
221
                                                                \
222
    for( _i_ = 0; _i_ < 8; _i_++ )                              \
223
        (_regs_)->a[_i_] = _regval_[_i_+24];                    \
224
                                                                \
225
    (_regs_)->ssr_fiq = _regval_[REG_SSR_FIQ] >> 16;            \
226
    (_regs_)->ssr_irq = _regval_[REG_SSR_IRQ] >> 16;            \
227
    (_regs_)->ssr_swi = _regval_[REG_SSR_SWI] >> 16;            \
228
    (_regs_)->spc_fiq = _regval_[REG_SPC_FIQ];                  \
229
    (_regs_)->spc_irq = _regval_[REG_SPC_IRQ];                  \
230
    switch (__get_trap_number()) {                              \
231
      case CYGNUM_HAL_VECTOR_SWI:                               \
232
        (_regs_)->ssr_swi = _regval_[REG_SR] >> 16;             \
233
        (_regs_)->a[6] = _regval_[REG_PC]; break;               \
234
      case CYGNUM_HAL_VECTOR_FIQ:                               \
235
        (_regs_)->ssr_fiq = _regval_[REG_SR] >> 16;             \
236
        (_regs_)->spc_fiq = _regval_[REG_PC]; break;            \
237
      default:                                                  \
238
        (_regs_)->ssr_irq = _regval_[REG_SR] >> 16;             \
239
        (_regs_)->spc_irq = _regval_[REG_PC]; break;            \
240
    }                                                           \
241
}
242
 
243
#define CYGARC_HAL_GET_PC_REG(_regs_, _val_)                    \
244
{                                                               \
245
    switch ((_regs_)->vector) {                                 \
246
      case CYGNUM_HAL_VECTOR_SWI:                               \
247
        (_val_) = (_regs_)->a[6]; break;                        \
248
      case CYGNUM_HAL_VECTOR_FIQ:                               \
249
        (_val_) = (_regs_)->spc_fiq; break;                     \
250
      default:                                                  \
251
        (_val_) = (_regs_)->spc_irq; break;                     \
252
    }                                                           \
253
}
254
 
255
//--------------------------------------------------------------------------
256
// HAL setjmp
257
// Note: These definitions are repeated in context.S. If changes are
258
// required remember to update both sets.
259
 
260
#define CYGARC_JMP_BUF_R4        0
261
#define CYGARC_JMP_BUF_R5        2
262
#define CYGARC_JMP_BUF_A12       4
263
#define CYGARC_JMP_BUF_A13       8
264
#define CYGARC_JMP_BUF_A14      12
265
#define CYGARC_JMP_BUF_A15      16
266
 
267
#define CYGARC_JMP_BUF_SIZE     20
268
 
269
typedef cyg_uint16 hal_jmp_buf[CYGARC_JMP_BUF_SIZE/sizeof(cyg_uint16)];
270
 
271
externC int hal_setjmp(hal_jmp_buf env);
272
externC void hal_longjmp(hal_jmp_buf env, int val);
273
 
274
//-------------------------------------------------------------------------
275
// Idle thread code.
276
// This macro is called in the idle thread loop, and gives the HAL the
277
// chance to insert code. Typical idle thread behaviour might be to halt the
278
// processor.
279
 
280
externC void hal_idle_thread_action(cyg_uint32 loop_count);
281
 
282
#define HAL_IDLE_THREAD_ACTION(_count_) hal_idle_thread_action(_count_)
283
 
284
//--------------------------------------------------------------------------
285
// Minimal and sensible stack sizes: the intention is that applications
286
// will use these to provide a stack size in the first instance prior to
287
// proper analysis.  Idle thread stack should be this big.
288
 
289
//    THESE ARE NOT INTENDED TO BE MICROMETRICALLY ACCURATE FIGURES.
290
//           THEY ARE HOWEVER ENOUGH TO START PROGRAMMING.
291
// YOU MUST MAKE YOUR STACKS LARGER IF YOU HAVE LARGE "AUTO" VARIABLES!
292
 
293
// This is not a config option because it should not be adjusted except
294
// under "enough rope" sort of disclaimers.
295
 
296
// Typical case stack frame size: return link + 4 pushed registers + some locals.
297
#define CYGNUM_HAL_STACK_FRAME_SIZE (48)
298
 
299
// Stack needed for a context switch:
300
#define CYGNUM_HAL_STACK_CONTEXT_SIZE ((32+10)*CYG_HAL_MIPS_REG_SIZE)
301
 
302
// Interrupt + call to ISR, interrupt_end() and the DSR
303
#define CYGNUM_HAL_STACK_INTERRUPT_SIZE (4+2*CYGNUM_HAL_STACK_CONTEXT_SIZE) 
304
 
305
#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
306
 
307
// An interrupt stack which is large enough for all possible interrupt
308
// conditions (and only used for that purpose) exists.  "User" stacks
309
// can be much smaller
310
 
311
#define CYGNUM_HAL_STACK_SIZE_MINIMUM (CYGNUM_HAL_STACK_CONTEXT_SIZE+      \
312
                                       CYGNUM_HAL_STACK_INTERRUPT_SIZE*2+  \
313
                                       CYGNUM_HAL_STACK_FRAME_SIZE*8)
314
#define CYGNUM_HAL_STACK_SIZE_TYPICAL (CYGNUM_HAL_STACK_SIZE_MINIMUM+1024)
315
 
316
#else // CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK 
317
 
318
// No separate interrupt stack exists.  Make sure all threads contain
319
// a stack sufficiently large.
320
 
321
#define CYGNUM_HAL_STACK_SIZE_MINIMUM (4096)
322
#define CYGNUM_HAL_STACK_SIZE_TYPICAL (4096)
323
 
324
#endif
325
 
326
#endif /* __ASSEMBLER__ */
327
 
328
 
329
//--------------------------------------------------------------------------
330
// Macros for switching context between two eCos instances (jump from
331
// code in ROM to code in RAM or vice versa).
332
#define CYGARC_HAL_SAVE_GP()
333
#define CYGARC_HAL_RESTORE_GP()
334
 
335
//--------------------------------------------------------------------------
336
// Defines for status register bit access
337
 
338
#define CYGARC_SR_PM   (1<<6)
339
#define CYGARC_SR_TE   (1<<2)
340
#define CYGARC_SR_IE   (1<<1)
341
#define CYGARC_SR_FE   (1<<0)
342
 
343
//--------------------------------------------------------------------------
344
#endif // CYGONCE_HAL_HAL_ARCH_H
345
// End of hal_arch.h

powered by: WebSVN 2.1.0

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