source: rtems/cpukit/score/cpu/nios2/rtems/score/cpu.h @ 143696a

5
Last change on this file since 143696a was 143696a, checked in by Sebastian Huber <sebastian.huber@…>, on 10/16/15 at 06:15:03

basedefs.h: Add and use RTEMS_NO_RETURN

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