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