source: rtems/cpukit/score/cpu/nios2/rtems/score/cpu.h @ 4f5740f

4.115
Last change on this file since 4f5740f was 4f5740f, checked in by Alex Ivanov <alexivanov97@…>, on 01/08/13 at 19:36:13

score: Doxygen Clean Up Task #16

  • Property mode set to 100644
File size: 9.5 KB
Line 
1/**
2 * @file
3 *
4 * @brief Altera Nios II CPU Department Source
5 */
6
7/*
8 *  Copyright (c) 2011 embedded brains GmbH
9 *
10 *  Copyright (c) 2006 Kolja Waschk (rtemsdev/ixo.de)
11 *
12 *  COPYRIGHT (c) 1989-2004.
13 *  On-Line Applications Research Corporation (OAR).
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.com/license/LICENSE.
18 */
19
20#ifndef _RTEMS_SCORE_CPU_H
21#define _RTEMS_SCORE_CPU_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#include <rtems/score/types.h>
28#include <rtems/score/nios2.h>
29
30/*
31 * TODO: Run the timing tests and figure out what is better.
32 */
33#define CPU_INLINE_ENABLE_DISPATCH FALSE
34
35/*
36 * TODO: Run the timing tests and figure out what is better.
37 */
38#define CPU_UNROLL_ENQUEUE_PRIORITY TRUE
39
40#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
41
42#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
43
44#define CPU_INTERRUPT_NUMBER_OF_VECTORS 32
45
46#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
47
48#define CPU_PROVIDES_ISR_IS_IN_PROGRESS TRUE
49
50#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
51
52#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
53
54#define CPU_ISR_PASSES_FRAME_POINTER 1
55
56#define CPU_HARDWARE_FP FALSE
57
58#define CPU_SOFTWARE_FP FALSE
59
60#define CPU_CONTEXT_FP_SIZE 0
61
62#define CPU_ALL_TASKS_ARE_FP FALSE
63
64#define CPU_IDLE_TASK_IS_FP FALSE
65
66#define CPU_USE_DEFERRED_FP_SWITCH FALSE
67
68#define CPU_PROVIDES_IDLE_THREAD_BODY FALSE
69
70#define CPU_STACK_GROWS_UP FALSE
71
72#define CPU_STRUCTURE_ALIGNMENT __attribute__((section(".sdata"), aligned(32)))
73
74#define CPU_TIMESTAMP_USE_INT64_INLINE TRUE
75
76#define CPU_BIG_ENDIAN FALSE
77
78#define CPU_LITTLE_ENDIAN TRUE
79
80#define CPU_STACK_MINIMUM_SIZE (4 * 1024)
81
82#define CPU_SIZEOF_POINTER 4
83
84/*
85 * Alignment value according to "Nios II Processor Reference" chapter 7
86 * "Application Binary Interface" section "Memory Alignment".
87 */
88#define CPU_ALIGNMENT 4
89
90#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
91
92#define CPU_PARTITION_ALIGNMENT CPU_ALIGNMENT
93
94/*
95 * Alignment value according to "Nios II Processor Reference" chapter 7
96 * "Application Binary Interface" section "Stacks".
97 */
98#define CPU_STACK_ALIGNMENT 4
99
100/*
101 * A Nios II configuration with an external interrupt controller (EIC) supports
102 * up to 64 interrupt levels.  A Nios II configuration with an internal
103 * interrupt controller (IIC) has only two interrupt levels (enabled and
104 * disabled).  The _CPU_ISR_Get_level() and _CPU_ISR_Set_level() functions will
105 * take care about configuration specific mappings.
106 */
107#define CPU_MODES_INTERRUPT_MASK 0x3f
108
109#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
110
111#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
112
113#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
114
115#ifndef ASM
116
117/**
118 * @brief Thread register context.
119 *
120 * The thread register context covers the non-volatile registers, the thread
121 * stack pointer, the return address, and the processor status.
122 *
123 * There is no need to save the global pointer (gp) since it is a system wide
124 * constant and set-up with the C runtime environment.
125 *
126 * The @a thread_dispatch_disabled field is used for the external interrupt
127 * controller (EIC) support.
128 *
129 * @see _Nios2_Thread_dispatch_disabled
130 */
131typedef struct {
132  uint32_t r16;
133  uint32_t r17;
134  uint32_t r18;
135  uint32_t r19;
136  uint32_t r20;
137  uint32_t r21;
138  uint32_t r22;
139  uint32_t r23;
140  uint32_t fp;
141  uint32_t status;
142  uint32_t sp;
143  uint32_t ra;
144  uint32_t thread_dispatch_disabled;
145  uint32_t stack_mpubase;
146  uint32_t stack_mpuacc;
147} Context_Control;
148
149#define _CPU_Context_Get_SP( _context ) \
150  (_context)->sp
151
152typedef struct {
153  uint32_t r1;
154  uint32_t r2;
155  uint32_t r3;
156  uint32_t r4;
157  uint32_t r5;
158  uint32_t r6;
159  uint32_t r7;
160  uint32_t r8;
161  uint32_t r9;
162  uint32_t r10;
163  uint32_t r11;
164  uint32_t r12;
165  uint32_t r13;
166  uint32_t r14;
167  uint32_t r15;
168  uint32_t ra;
169  uint32_t gp;
170  uint32_t et;
171  uint32_t ea;
172} CPU_Interrupt_frame;
173
174typedef struct {
175  uint32_t r1;
176  uint32_t r2;
177  uint32_t r3;
178  uint32_t r4;
179  uint32_t r5;
180  uint32_t r6;
181  uint32_t r7;
182  uint32_t r8;
183  uint32_t r9;
184  uint32_t r10;
185  uint32_t r11;
186  uint32_t r12;
187  uint32_t r13;
188  uint32_t r14;
189  uint32_t r15;
190  uint32_t r16;
191  uint32_t r17;
192  uint32_t r18;
193  uint32_t r19;
194  uint32_t r20;
195  uint32_t r21;
196  uint32_t r22;
197  uint32_t r23;
198  uint32_t gp;
199  uint32_t fp;
200  uint32_t sp;
201  uint32_t ra;
202  uint32_t et;
203  uint32_t ea;
204  uint32_t status;
205  uint32_t ienable;
206  uint32_t ipending;
207} CPU_Exception_frame;
208
209void _CPU_Initialize_vectors( void );
210
211/**
212 * @brief Macro to disable interrupts.
213 *
214 * The processor status before disabling the interrupts will be stored in
215 * @a _isr_cookie.  This value will be used in _CPU_ISR_Flash() and
216 * _CPU_ISR_Enable().
217 *
218 * The global symbol _Nios2_ISR_Status_mask will be used to clear the bits in
219 * the status register representing the interrupt level.  The global symbol
220 * _Nios2_ISR_Status_bits will be used to set the bits representing an
221 * interrupt level that disables interrupts.  Both global symbols must be
222 * provided by the board support package.
223 *
224 * In case the Nios II uses the internal interrupt controller (IIC), then only
225 * the PIE status bit is used.
226 *
227 * In case the Nios II uses the external interrupt controller (EIC), then the
228 * RSIE status bit or the IL status field is used depending on the interrupt
229 * handling variant and the shadow register usage.
230 */
231#define _CPU_ISR_Disable( _isr_cookie ) \
232  do { \
233    int _tmp; \
234    __asm__ volatile ( \
235      "rdctl %0, status\n" \
236      "movhi %1, %%hiadj(_Nios2_ISR_Status_mask)\n" \
237      "addi %1, %1, %%lo(_Nios2_ISR_Status_mask)\n" \
238      "and %1, %0, %1\n" \
239      "ori %1, %1, %%lo(_Nios2_ISR_Status_bits)\n" \
240      "wrctl status, %1" \
241      : "=&r" (_isr_cookie), "=&r" (_tmp) \
242    ); \
243  } while ( 0 )
244
245/**
246 * @brief Macro to restore the processor status.
247 *
248 * The @a _isr_cookie must contain the processor status returned by
249 * _CPU_ISR_Disable().  The value is not modified.
250 */
251#define _CPU_ISR_Enable( _isr_cookie ) \
252  __builtin_wrctl( 0, (int) _isr_cookie )
253
254/**
255 * @brief Macro to restore the processor status and disable the interrupts
256 * again.
257 *
258 * The @a _isr_cookie must contain the processor status returned by
259 * _CPU_ISR_Disable().  The value is not modified.
260 *
261 * This flash code is optimal for all Nios II configurations.  The rdctl does
262 * not flush the pipeline and has only a late result penalty.  The wrctl on
263 * the other hand leads to a pipeline flush.
264 */
265#define _CPU_ISR_Flash( _isr_cookie ) \
266  do { \
267    int _status = __builtin_rdctl( 0 ); \
268    __builtin_wrctl( 0, (int) _isr_cookie ); \
269    __builtin_wrctl( 0, _status ); \
270  } while ( 0 )
271
272/**
273 * @brief Sets the interrupt level for the executing thread.
274 *
275 * The valid values of @a new_level depend on the Nios II configuration.  A
276 * value of zero represents enabled interrupts in all configurations.
277 *
278 * @see _CPU_ISR_Get_level()
279 */
280void _CPU_ISR_Set_level( uint32_t new_level );
281
282/**
283 * @brief Returns the interrupt level of the executing thread.
284 *
285 * @retval 0 Interrupts are enabled.
286 * @retval otherwise The value depends on the Nios II configuration.  In case
287 * of an internal interrupt controller (IIC) the only valid value is one which
288 * indicates disabled interrupts.  In case of an external interrupt controller
289 * (EIC) there are two possibilities.  Firstly if the RSIE status bit is used
290 * to disable interrupts, then one is the only valid value indicating disabled
291 * interrupts.  Secondly if the IL status field is used to disable interrupts,
292 * then this value will be returned.  Interrupts are disabled at the maximum
293 * level specified by the _Nios2_ISR_Status_bits.
294 */
295uint32_t _CPU_ISR_Get_level( void );
296
297/**
298 * @brief Initializes the CPU context.
299 *
300 * The following steps are performed:
301 *  - setting a starting address
302 *  - preparing the stack
303 *  - preparing the stack and frame pointers
304 *  - setting the proper interrupt level in the context
305 *
306 * @param[in] context points to the context area
307 * @param[in] stack_area_begin is the low address of the allocated stack area
308 * @param[in] stack_area_size is the size of the stack area in bytes
309 * @param[in] new_level is the interrupt level for the task
310 * @param[in] entry_point is the task's entry point
311 * @param[in] is_fp is set to @c true if the task is a floating point task
312 */
313void _CPU_Context_Initialize(
314  Context_Control *context,
315  void *stack_area_begin,
316  size_t stack_area_size,
317  uint32_t new_level,
318  void (*entry_point)( void ),
319  bool is_fp
320);
321
322#define _CPU_Context_Restart_self( _the_context ) \
323  _CPU_Context_restore( (_the_context) );
324
325void _CPU_Fatal_halt( uint32_t _error ) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
326
327/**
328 * @brief CPU initialization.
329 */
330void _CPU_Initialize( void );
331
332/**
333 * @brief CPU ISR install raw handler.
334 */
335void _CPU_ISR_install_raw_handler(
336  uint32_t vector,
337  proc_ptr new_handler,
338  proc_ptr *old_handler
339);
340
341/**
342 * @brief CPU ISR install vector.
343 */
344void _CPU_ISR_install_vector(
345  uint32_t vector,
346  proc_ptr new_handler,
347  proc_ptr *old_handler
348);
349
350void _CPU_Context_switch( Context_Control *run, Context_Control *heir );
351
352void _CPU_Context_restore(
353  Context_Control *new_context
354) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
355
356void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
357
358static inline uint32_t CPU_swap_u32( uint32_t value )
359{
360  uint32_t byte1, byte2, byte3, byte4, swapped;
361
362  byte4 = (value >> 24) & 0xff;
363  byte3 = (value >> 16) & 0xff;
364  byte2 = (value >> 8)  & 0xff;
365  byte1 =  value        & 0xff;
366
367  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
368
369  return swapped;
370}
371
372#define CPU_swap_u16( value ) \
373  (((value&0xff) << 8) | ((value >> 8)&0xff))
374
375#endif /* ASM */
376
377#ifdef __cplusplus
378}
379#endif
380
381#endif
Note: See TracBrowser for help on using the repository browser.