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