source: rtems/cpukit/score/cpu/nios2/rtems/score/cpu.h @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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