1 |
786 |
skrzyp |
#ifndef CYGONCE_HAL_ARCH_H
|
2 |
|
|
#define CYGONCE_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, 2004 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): nickg, gthomas
|
46 |
|
|
// Contributors: nickg, gthomas
|
47 |
|
|
// Date: 2001-09-07
|
48 |
|
|
// Purpose: Define architecture abstractions
|
49 |
|
|
// Usage: #include <cyg/hal/hal_arch.h>
|
50 |
|
|
|
51 |
|
|
//
|
52 |
|
|
//####DESCRIPTIONEND####
|
53 |
|
|
//
|
54 |
|
|
//==========================================================================
|
55 |
|
|
|
56 |
|
|
#include <pkgconf/hal.h> // To decide on stack usage
|
57 |
|
|
#include <cyg/infra/cyg_type.h>
|
58 |
|
|
|
59 |
|
|
#if CYGINT_HAL_FRV_ARCH_FR500 != 0
|
60 |
|
|
#define _NGPR 64
|
61 |
|
|
#define _NFPR 64
|
62 |
|
|
#elif CYGINT_HAL_FRV_ARCH_FR400 != 0
|
63 |
|
|
#define _NGPR 32
|
64 |
|
|
#define _NFPR 32
|
65 |
|
|
#else
|
66 |
|
|
#error No architecture defined?
|
67 |
|
|
#endif
|
68 |
|
|
|
69 |
|
|
//--------------------------------------------------------------------------
|
70 |
|
|
// Common "special" register definitions
|
71 |
|
|
|
72 |
|
|
// Processor status register
|
73 |
|
|
#define _PSR_PIVL_SHIFT 3
|
74 |
|
|
#define _PSR_PIVL_MASK (0xF<<(_PSR_PIVL_SHIFT)) // Interrupt mask level
|
75 |
|
|
#define _PSR_S (1<<2) // Supervisor state
|
76 |
|
|
#define _PSR_PS (1<<1) // Previous supervisor state
|
77 |
|
|
#define _PSR_ET (1<<0) // Enable interrupts
|
78 |
|
|
#define _PSR_CM (1<<13) // Enable conditionals
|
79 |
|
|
|
80 |
|
|
#define _PSR_INITIAL (_PSR_S|_PSR_PS|_PSR_ET|_PSR_CM) // Supervisor mode, exceptions
|
81 |
|
|
|
82 |
|
|
// Hardware status register
|
83 |
|
|
#define _HSR0_FRN (1<<11)
|
84 |
|
|
#define _HSR0_GRN (1<<10)
|
85 |
|
|
#define _HSR0_ICE (1<<31) // Instruction cache enable
|
86 |
|
|
#define _HSR0_DCE (1<<30) // Data cache enable
|
87 |
|
|
#define _HSR0_IMMU (1<<26) // Instruction MMU enable
|
88 |
|
|
#define _HSR0_DMMU (1<<25) // Data MMU enable
|
89 |
|
|
|
90 |
|
|
// Debug Control Register
|
91 |
|
|
#define _DCR_EBE (1 << 30)
|
92 |
|
|
#define _DCR_SE (1 << 29)
|
93 |
|
|
#define _DCR_DRBE0 (1 << 19)
|
94 |
|
|
#define _DCR_DWBE0 (1 << 18)
|
95 |
|
|
#define _DCR_DDBE0 (1 << 17)
|
96 |
|
|
#define _DCR_DRBE1 (1 << 16)
|
97 |
|
|
#define _DCR_DWBE1 (1 << 15)
|
98 |
|
|
#define _DCR_DDBE1 (1 << 14)
|
99 |
|
|
#define _DCR_DRBE2 (1 << 13)
|
100 |
|
|
#define _DCR_DWBE2 (1 << 12)
|
101 |
|
|
#define _DCR_DDBE2 (1 << 11)
|
102 |
|
|
#define _DCR_DRBE3 (1 << 10)
|
103 |
|
|
#define _DCR_DWBE3 (1 << 9)
|
104 |
|
|
#define _DCR_DDBE3 (1 << 8)
|
105 |
|
|
#define _DCR_IBE0 (1 << 7)
|
106 |
|
|
#define _DCR_IBCE0 (1 << 6)
|
107 |
|
|
#define _DCR_IBE1 (1 << 5)
|
108 |
|
|
#define _DCR_IBCE1 (1 << 4)
|
109 |
|
|
#define _DCR_IBE2 (1 << 3)
|
110 |
|
|
#define _DCR_IBCE2 (1 << 2)
|
111 |
|
|
#define _DCR_IBE3 (1 << 1)
|
112 |
|
|
#define _DCR_IBCE3 (1 << 0)
|
113 |
|
|
|
114 |
|
|
// Initial contents for special registers
|
115 |
|
|
|
116 |
|
|
#define _CCR_INITIAL 0
|
117 |
|
|
#define _LCR_INITIAL 0
|
118 |
|
|
#define _CCCR_INITIAL 0
|
119 |
|
|
|
120 |
|
|
//--------------------------------------------------------------------------
|
121 |
|
|
//
|
122 |
|
|
// Saved thread state
|
123 |
|
|
//
|
124 |
|
|
typedef struct
|
125 |
|
|
{
|
126 |
|
|
cyg_uint32 gpr[_NGPR]; // Saved general purpose registers
|
127 |
|
|
cyg_uint32 pc; // Current [next] instruction location
|
128 |
|
|
cyg_uint32 psr; // Processor status register
|
129 |
|
|
cyg_uint32 lr; // Link register
|
130 |
|
|
cyg_uint32 ccr; // Condition codes
|
131 |
|
|
cyg_uint32 cccr;
|
132 |
|
|
cyg_uint32 lcr;
|
133 |
|
|
cyg_int32 vector; // Reason for last exception
|
134 |
|
|
} HAL_SavedRegisters;
|
135 |
|
|
|
136 |
|
|
//-------------------------------------------------------------------------
|
137 |
|
|
// Exception handling function.
|
138 |
|
|
// This function is defined by the kernel according to this prototype. It is
|
139 |
|
|
// invoked from the HAL to deal with any CPU exceptions that the HAL does
|
140 |
|
|
// not want to deal with itself. It usually invokes the kernel's exception
|
141 |
|
|
// delivery mechanism.
|
142 |
|
|
|
143 |
|
|
externC void cyg_hal_deliver_exception( CYG_WORD code, CYG_ADDRWORD data );
|
144 |
|
|
|
145 |
|
|
//-------------------------------------------------------------------------
|
146 |
|
|
// Bit manipulation macros
|
147 |
|
|
|
148 |
|
|
externC int hal_lsbindex(int);
|
149 |
|
|
externC int hal_msbindex(int);
|
150 |
|
|
|
151 |
|
|
#define HAL_LSBIT_INDEX(index, mask) index = hal_lsbindex(mask)
|
152 |
|
|
#define HAL_MSBIT_INDEX(index, mask) index = hal_msbindex(mask)
|
153 |
|
|
|
154 |
|
|
//-------------------------------------------------------------------------
|
155 |
|
|
// Context Initialization
|
156 |
|
|
// Initialize the context of a thread.
|
157 |
|
|
// Arguments:
|
158 |
|
|
// _sparg_ name of variable containing current sp, will be changed to new sp
|
159 |
|
|
// _thread_ thread object address, passed as argument to entry point
|
160 |
|
|
// _entry_ entry point address.
|
161 |
|
|
// _id_ bit pattern used in initializing registers, for debugging.
|
162 |
|
|
|
163 |
|
|
#define HAL_THREAD_INIT_CONTEXT( _sparg_, _thread_, _entry_, _id_ ) \
|
164 |
|
|
CYG_MACRO_START \
|
165 |
|
|
register CYG_WORD _sp_ = ((CYG_WORD)_sparg_) &~15; \
|
166 |
|
|
register HAL_SavedRegisters *_regs_; \
|
167 |
|
|
int _i_; \
|
168 |
|
|
_regs_ = (HAL_SavedRegisters *)((_sp_) - sizeof(HAL_SavedRegisters)); \
|
169 |
|
|
for( _i_ = 1; _i_ < _NGPR; _i_++) \
|
170 |
|
|
(_regs_)->gpr[_i_] = (_id_)|_i_; \
|
171 |
|
|
(_regs_)->gpr[8] = (CYG_WORD)(_thread_); /* R8 = arg1 = thread ptr */ \
|
172 |
|
|
(_regs_)->gpr[1] = (CYG_WORD)(_sp_); /* SP = top of stack */ \
|
173 |
|
|
(_regs_)->lr = (CYG_WORD)(_entry_); /* LR = entry point */ \
|
174 |
|
|
(_regs_)->pc = (CYG_WORD)(_entry_); /* PC = [initial] entry point */ \
|
175 |
|
|
(_regs_)->psr = _PSR_INITIAL; /* PSR = Interrupt enabled */ \
|
176 |
|
|
(_regs_)->ccr = _CCR_INITIAL; \
|
177 |
|
|
(_regs_)->lcr = _LCR_INITIAL; \
|
178 |
|
|
(_regs_)->ccr = _CCCR_INITIAL; \
|
179 |
|
|
_sparg_ = (CYG_ADDRESS)_regs_; \
|
180 |
|
|
CYG_MACRO_END
|
181 |
|
|
|
182 |
|
|
//--------------------------------------------------------------------------
|
183 |
|
|
// Context switch macros.
|
184 |
|
|
// The arguments are pointers to locations where the stack pointer
|
185 |
|
|
// of the current thread is to be stored, and from where the sp of the
|
186 |
|
|
// next thread is to be fetched.
|
187 |
|
|
|
188 |
|
|
externC void hal_thread_switch_context( CYG_ADDRESS to, CYG_ADDRESS from );
|
189 |
|
|
externC void hal_thread_load_context( CYG_ADDRESS to )
|
190 |
|
|
__attribute__ ((noreturn));
|
191 |
|
|
|
192 |
|
|
#define HAL_THREAD_SWITCH_CONTEXT(_fspptr_,_tspptr_) \
|
193 |
|
|
hal_thread_switch_context((CYG_ADDRESS)_tspptr_, \
|
194 |
|
|
(CYG_ADDRESS)_fspptr_);
|
195 |
|
|
|
196 |
|
|
#define HAL_THREAD_LOAD_CONTEXT(_tspptr_) \
|
197 |
|
|
hal_thread_load_context( (CYG_ADDRESS)_tspptr_ );
|
198 |
|
|
|
199 |
|
|
//--------------------------------------------------------------------------
|
200 |
|
|
// Execution reorder barrier.
|
201 |
|
|
// When optimizing the compiler can reorder code. In multithreaded systems
|
202 |
|
|
// where the order of actions is vital, this can sometimes cause problems.
|
203 |
|
|
// This macro may be inserted into places where reordering should not happen.
|
204 |
|
|
|
205 |
|
|
#define HAL_REORDER_BARRIER() asm volatile ( "" : : : "memory" )
|
206 |
|
|
|
207 |
|
|
//--------------------------------------------------------------------------
|
208 |
|
|
// Breakpoint support
|
209 |
|
|
// HAL_BREAKPOINT() is a code sequence that will cause a breakpoint to happen
|
210 |
|
|
// if executed.
|
211 |
|
|
// HAL_BREAKINST is the value of the breakpoint instruction and
|
212 |
|
|
// HAL_BREAKINST_SIZE is its size in bytes.
|
213 |
|
|
|
214 |
|
|
// The choices for breakpoints seem to be:
|
215 |
|
|
// break 0x801000C0
|
216 |
|
|
// tira gr0,#1 0xC0700001
|
217 |
|
|
#ifdef CYGSEM_HAL_FRV_USE_BREAK_INSTRUCTION
|
218 |
|
|
#define HAL_BREAKPOINT(_label_) \
|
219 |
|
|
asm volatile (" .globl " #_label_ "\n" \
|
220 |
|
|
#_label_":\tbreak\n" \
|
221 |
|
|
);
|
222 |
|
|
|
223 |
|
|
#define HAL_BREAKINST 0x801000C0
|
224 |
|
|
#else
|
225 |
|
|
#define HAL_BREAKPOINT(_label_) \
|
226 |
|
|
asm volatile (" .globl " #_label_ "\n" \
|
227 |
|
|
#_label_":\ttira\tgr0,#1\n" \
|
228 |
|
|
);
|
229 |
|
|
|
230 |
|
|
#define HAL_BREAKINST 0xC0700001
|
231 |
|
|
#endif
|
232 |
|
|
#define HAL_BREAKINST_SIZE 4
|
233 |
|
|
#define HAL_BREAKINST_TYPE cyg_uint32
|
234 |
|
|
|
235 |
|
|
//--------------------------------------------------------------------------
|
236 |
|
|
// Thread register state manipulation for GDB support.
|
237 |
|
|
|
238 |
|
|
// GDB expects the registers in this structure:
|
239 |
|
|
// gr0..gr31, gr32..gr63 - 4 bytes each
|
240 |
|
|
// fpr0..fpr31, fpr32..fpr63 - 4 bytes each
|
241 |
|
|
// pc, psr, ccr, cccr - 4 bytes each
|
242 |
|
|
// 14 <unused> - 4 bytes each
|
243 |
|
|
// lr, lcr - 4 bytes each
|
244 |
|
|
|
245 |
|
|
// Translate a stack pointer as saved by the thread context macros above into
|
246 |
|
|
// a pointer to a HAL_SavedRegisters structure.
|
247 |
|
|
#define HAL_THREAD_GET_SAVED_REGISTERS( _sp_, _regs_ ) \
|
248 |
|
|
(_regs_) = (HAL_SavedRegisters *)(_sp_)
|
249 |
|
|
|
250 |
|
|
// Copy a set of registers from a HAL_SavedRegisters structure into a
|
251 |
|
|
// GDB ordered array.
|
252 |
|
|
#define HAL_GET_GDB_REGISTERS( _aregval_, _regs_ ) \
|
253 |
|
|
CYG_MACRO_START \
|
254 |
|
|
CYG_ADDRWORD *_regval_ = (CYG_ADDRWORD *)(_aregval_); \
|
255 |
|
|
int _i_; \
|
256 |
|
|
\
|
257 |
|
|
for( _i_ = 0; _i_ <= _NGPR; _i_++ ) \
|
258 |
|
|
_regval_[_i_] = (_regs_)->gpr[_i_]; \
|
259 |
|
|
_regval_[128] = (_regs_)->pc; \
|
260 |
|
|
_regval_[129] = (_regs_)->psr; \
|
261 |
|
|
_regval_[130] = (_regs_)->ccr; \
|
262 |
|
|
_regval_[135] = (_regs_)->vector; \
|
263 |
|
|
_regval_[145] = (_regs_)->lr; \
|
264 |
|
|
_regval_[146] = (_regs_)->lcr; \
|
265 |
|
|
CYG_MACRO_END
|
266 |
|
|
|
267 |
|
|
// Copy a GDB ordered array into a HAL_SavedRegisters structure.
|
268 |
|
|
#define HAL_SET_GDB_REGISTERS( _regs_ , _aregval_ ) \
|
269 |
|
|
CYG_MACRO_START \
|
270 |
|
|
CYG_ADDRWORD *_regval_ = (CYG_ADDRWORD *)(_aregval_); \
|
271 |
|
|
int _i_; \
|
272 |
|
|
\
|
273 |
|
|
for( _i_ = 0; _i_ <= _NGPR; _i_++ ) \
|
274 |
|
|
(_regs_)->gpr[_i_] = _regval_[_i_]; \
|
275 |
|
|
\
|
276 |
|
|
(_regs_)->pc = _regval_[128]; \
|
277 |
|
|
(_regs_)->psr = _regval_[129]; \
|
278 |
|
|
(_regs_)->ccr = _regval_[130]; \
|
279 |
|
|
(_regs_)->lr = _regval_[145]; \
|
280 |
|
|
(_regs_)->lcr = _regval_[146]; \
|
281 |
|
|
CYG_MACRO_END
|
282 |
|
|
|
283 |
|
|
//--------------------------------------------------------------------------
|
284 |
|
|
// HAL setjmp
|
285 |
|
|
|
286 |
|
|
#define CYGARC_JMP_BUF_SIZE 0x110
|
287 |
|
|
|
288 |
|
|
typedef cyg_uint32 hal_jmp_buf[CYGARC_JMP_BUF_SIZE];
|
289 |
|
|
|
290 |
|
|
externC int hal_setjmp(hal_jmp_buf env);
|
291 |
|
|
externC void hal_longjmp(hal_jmp_buf env, int val);
|
292 |
|
|
|
293 |
|
|
//--------------------------------------------------------------------------
|
294 |
|
|
// Idle thread code.
|
295 |
|
|
// This macro is called in the idle thread loop, and gives the HAL the
|
296 |
|
|
// chance to insert code. Typical idle thread behaviour might be to halt the
|
297 |
|
|
// processor.
|
298 |
|
|
|
299 |
|
|
externC void hal_idle_thread_action(cyg_uint32 loop_count);
|
300 |
|
|
|
301 |
|
|
#define HAL_IDLE_THREAD_ACTION(_count_) hal_idle_thread_action(_count_)
|
302 |
|
|
|
303 |
|
|
//---------------------------------------------------------------------------
|
304 |
|
|
|
305 |
|
|
// Minimal and sensible stack sizes: the intention is that applications
|
306 |
|
|
// will use these to provide a stack size in the first instance prior to
|
307 |
|
|
// proper analysis. Idle thread stack should be this big.
|
308 |
|
|
|
309 |
|
|
// THESE ARE NOT INTENDED TO BE MICROMETRICALLY ACCURATE FIGURES.
|
310 |
|
|
// THEY ARE HOWEVER ENOUGH TO START PROGRAMMING.
|
311 |
|
|
// YOU MUST MAKE YOUR STACKS LARGER IF YOU HAVE LARGE "AUTO" VARIABLES!
|
312 |
|
|
|
313 |
|
|
// This is not a config option because it should not be adjusted except
|
314 |
|
|
// under "enough rope" sort of disclaimers.
|
315 |
|
|
|
316 |
|
|
// A minimal, optimized stack frame, rounded up - no autos
|
317 |
|
|
#define CYGNUM_HAL_STACK_FRAME_SIZE (4 * 150)
|
318 |
|
|
|
319 |
|
|
// Stack needed for a context switch: this is implicit in the estimate for
|
320 |
|
|
// interrupts so not explicitly used below:
|
321 |
|
|
#define CYGNUM_HAL_STACK_CONTEXT_SIZE (4 * 150)
|
322 |
|
|
|
323 |
|
|
// Interrupt + call to ISR, interrupt_end() and the DSR
|
324 |
|
|
#define CYGNUM_HAL_STACK_INTERRUPT_SIZE \
|
325 |
|
|
((4 * 150) + 2 * CYGNUM_HAL_STACK_FRAME_SIZE)
|
326 |
|
|
|
327 |
|
|
// Space for the maximum number of nested interrupts, plus room to call functions
|
328 |
|
|
#define CYGNUM_HAL_MAX_INTERRUPT_NESTING 4
|
329 |
|
|
|
330 |
|
|
#define CYGNUM_HAL_STACK_SIZE_MINIMUM \
|
331 |
|
|
(CYGNUM_HAL_MAX_INTERRUPT_NESTING * CYGNUM_HAL_STACK_INTERRUPT_SIZE + \
|
332 |
|
|
2 * CYGNUM_HAL_STACK_FRAME_SIZE)
|
333 |
|
|
|
334 |
|
|
#define CYGNUM_HAL_STACK_SIZE_TYPICAL \
|
335 |
|
|
(CYGNUM_HAL_STACK_SIZE_MINIMUM + \
|
336 |
|
|
16 * CYGNUM_HAL_STACK_FRAME_SIZE)
|
337 |
|
|
|
338 |
|
|
|
339 |
|
|
//--------------------------------------------------------------------------
|
340 |
|
|
// Macros for switching context between two eCos instances (jump from
|
341 |
|
|
// code in ROM to code in RAM or vice versa).
|
342 |
|
|
#define CYGARC_HAL_SAVE_GP()
|
343 |
|
|
#define CYGARC_HAL_RESTORE_GP()
|
344 |
|
|
|
345 |
|
|
#endif // CYGONCE_HAL_ARCH_H
|
346 |
|
|
// End of hal_arch.h
|