RTEMS  5.0.0
cpu.h
Go to the documentation of this file.
1 
10 /*
11  * COPYRIGHT (c) 1989-2006.
12  * On-Line Applications Research Corporation (OAR).
13  * adapted to Blackfin by Alain Schaefer <alain.schaefer@easc.ch>
14  * and Antonio Giovanini <antonio@atos.com.br>
15  *
16  * The license and distribution terms for this file may be
17  * found in the file LICENSE in this distribution or at
18  * http://www.rtems.org/license/LICENSE.
19  */
20 
21 #ifndef _RTEMS_SCORE_CPU_H
22 #define _RTEMS_SCORE_CPU_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #include <rtems/score/basedefs.h>
29 #include <rtems/score/bfin.h>
30 
31 /* conditional compilation parameters */
32 
33 /*
34  * Does the CPU follow the simple vectored interrupt model?
35  *
36  * If TRUE, then RTEMS allocates the vector table it internally manages.
37  * If FALSE, then the BSP is assumed to allocate and manage the vector
38  * table
39  *
40  * BFIN Specific Information:
41  *
42  * XXX document implementation including references if appropriate
43  */
44 #define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
45 
55 #define CPU_ISR_PASSES_FRAME_POINTER TRUE
56 
92 #if ( BLACKFIN_CPU_HAS_FPU == 1 )
93 #define CPU_HARDWARE_FP TRUE
94 #else
95 #define CPU_HARDWARE_FP FALSE
96 #endif
97 #define CPU_SOFTWARE_FP FALSE
98 
123 #define CPU_ALL_TASKS_ARE_FP FALSE
124 
140 #define CPU_IDLE_TASK_IS_FP FALSE
141 
171 #define CPU_USE_DEFERRED_FP_SWITCH TRUE
172 
173 #define CPU_ENABLE_ROBUST_THREAD_DISPATCH FALSE
174 
186 #define CPU_STACK_GROWS_UP FALSE
187 
188 /* FIXME: Is this the right value? */
189 #define CPU_CACHE_LINE_BYTES 32
190 
191 #define CPU_STRUCTURE_ALIGNMENT
192 
203 #define CPU_MODES_INTERRUPT_MASK 0x00000001
204 
205 #define CPU_MAXIMUM_PROCESSORS 32
206 
207 /*
208  * Processor defined structures required for cpukit/score.
209  *
210  * Port Specific Information:
211  *
212  * XXX document implementation including references if appropriate
213  */
214 
215 /* may need to put some structures here. */
216 
217 #ifndef ASM
218 
270 /* make sure this stays in sync with the assembly function
271  __CPU_Context_switch in cpu_asm.S */
272 typedef struct {
273  uint32_t register_r4;
274  uint32_t register_r5;
275  uint32_t register_r6;
276  uint32_t register_r7;
277 
278  uint32_t register_p3;
279  uint32_t register_p4;
280  uint32_t register_p5;
281  uint32_t register_fp;
282  uint32_t register_sp;
283 
284  uint32_t register_rets;
285 
286  uint32_t imask;
288 
289 #define _CPU_Context_Get_SP( _context ) \
290  (_context)->register_sp
291 
296 typedef struct {
297  /* FPU registers are listed here */
298  /* Blackfin has no Floating Point */
300 
306 typedef struct {
311  /*uint32_t special_interrupt_register;*/
313 
324 /*
325  * Nothing prevents the porter from declaring more CPU specific variables.
326  *
327  * Port Specific Information:
328  *
329  * XXX document implementation including references if appropriate
330  */
331 
332 /* XXX: if needed, put more variables here */
333 
345 #define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
346 
347 #endif /* ASM */
348 
359 #define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
360 
370 #define CPU_INTERRUPT_NUMBER_OF_VECTORS 16
371 
376 #define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
377 
383 #define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
384 
394 #define CPU_STACK_MINIMUM_SIZE (1024*8)
395 
396 #define CPU_SIZEOF_POINTER 4
397 
406 #define CPU_ALIGNMENT 8
407 
431 #define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
432 
446 #define CPU_STACK_ALIGNMENT 8
447 
448 #define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
449 
450 #ifndef ASM
451 
452 /*
453  * ISR handler macros
454  */
455 
468 #define _CPU_Initialize_vectors()
469 
480 #define _CPU_ISR_Disable( _level ) \
481  { \
482  __asm__ volatile ("cli %0; csync \n" : "=d" (_level) ); \
483  }
484 
485 
497 #define _CPU_ISR_Enable( _level ) { \
498  __asm__ __volatile__ ("sti %0; csync \n" : : "d" (_level) ); \
499  }
500 
513 #define _CPU_ISR_Flash( _level ) { \
514  __asm__ __volatile__ ("sti %0; csync; cli r0; csync" \
515  : : "d"(_level) : "R0" ); \
516  }
517 
518 RTEMS_INLINE_ROUTINE bool _CPU_ISR_Is_enabled( uint32_t level )
519 {
520  return level != 0;
521 }
522 
538 #define _CPU_ISR_Set_level( _new_level ) \
539  { \
540  __asm__ __volatile__ ( "sti %0; csync" : : "d"(_new_level ? 0 : 0xffff) ); \
541  }
542 
553 uint32_t _CPU_ISR_Get_level( void );
554 
555 /* end of ISR handler macros */
556 
559 /* Context handler macros */
560 
594  Context_Control *the_context,
595  uint32_t *stack_base,
596  uint32_t size,
597  uint32_t new_level,
598  void *entry_point,
599  bool is_fp,
600  void *tls_area
601 );
602 
618 #define _CPU_Context_Restart_self( _the_context ) \
619  _CPU_Context_restore( (_the_context) );
620 
621 #define _CPU_Context_Initialize_fp( _destination ) \
622  memset( *( _destination ), 0, CPU_CONTEXT_FP_SIZE );
623 
624 /* end of Context handler macros */
625 
626 /* Fatal Error manager macros */
627 
637 #define _CPU_Fatal_halt( _source, _error ) \
638  { \
639  __asm__ volatile ( "cli R1; \
640  R1 = %0; \
641  _halt: \
642  idle; \
643  jump _halt;"\
644  : : "r" (_error) ); \
645  }
646 
647 /* end of Fatal Error manager macros */
648 
649 #define CPU_USE_GENERIC_BITFIELD_CODE TRUE
650 
651 /* functions */
652 
661 void _CPU_Initialize(void);
662 
663 typedef void ( *CPU_ISR_raw_handler )( void );
664 
666  uint32_t vector,
667  CPU_ISR_raw_handler new_handler,
668  CPU_ISR_raw_handler *old_handler
669 );
670 
671 typedef void ( *CPU_ISR_handler )( uint32_t );
672 
674  uint32_t vector,
675  CPU_ISR_handler new_handler,
676  CPU_ISR_handler *old_handler
677 );
678 
679 void *_CPU_Thread_Idle_body( uintptr_t ignored );
680 
697  Context_Control *run,
698  Context_Control *heir
699 );
700 
714  Context_Control *new_context
716 
731  Context_Control_fp **fp_context_ptr
732 );
733 
748  Context_Control_fp **fp_context_ptr
749 );
750 
753 /* FIXME */
754 typedef CPU_Interrupt_frame CPU_Exception_frame;
755 
756 void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
757 
767 /*
768  *
769  * The following routine swaps the endian format of an unsigned int.
770  * It must be static because it is referenced indirectly.
771  *
772  * This version will work on any processor, but if there is a better
773  * way for your CPU PLEASE use it. The most common way to do this is to:
774  *
775  * swap least significant two bytes with 16-bit rotate
776  * swap upper and lower 16-bits
777  * swap most significant two bytes with 16-bit rotate
778  *
779  * Some CPUs have special instructions which swap a 32-bit quantity in
780  * a single instruction (e.g. i486). It is probably best to avoid
781  * an "endian swapping control bit" in the CPU. One good reason is
782  * that interrupts would probably have to be disabled to ensure that
783  * an interrupt does not try to access the same "chunk" with the wrong
784  * endian. Another good reason is that on some CPUs, the endian bit
785  * endianness for ALL fetches -- both code and data -- so the code
786  * will be fetched incorrectly.
787  *
788  * @param[in] value is the value to be swapped
789  * @return the value after being endian swapped
790  *
791  * Port Specific Information:
792  *
793  * XXX document implementation including references if appropriate
794  */
795 
796 static inline uint32_t CPU_swap_u32(
797  uint32_t value
798 )
799 {
800  uint32_t byte1, byte2, byte3, byte4, swapped;
801 
802  byte4 = (value >> 24) & 0xff;
803  byte3 = (value >> 16) & 0xff;
804  byte2 = (value >> 8) & 0xff;
805  byte1 = value & 0xff;
806 
807  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
808  return( swapped );
809 }
810 
817 #define CPU_swap_u16( value ) \
818  (((value&0xff) << 8) | ((value >> 8)&0xff))
819 
822 typedef uint32_t CPU_Counter_ticks;
823 
824 uint32_t _CPU_Counter_frequency( void );
825 
826 CPU_Counter_ticks _CPU_Counter_read( void );
827 
828 static inline CPU_Counter_ticks _CPU_Counter_difference(
829  CPU_Counter_ticks second,
830  CPU_Counter_ticks first
831 )
832 {
833  return second - first;
834 }
835 
837 typedef uintptr_t CPU_Uint32ptr;
838 
839 #endif /* ASM */
840 
841 #ifdef __cplusplus
842 }
843 #endif
844 
845 #endif
void _CPU_Exception_frame_print(const CPU_Exception_frame *frame)
Prints the exception frame via printk().
Definition: vectorexceptions.c:45
CPU_Counter_ticks _CPU_Counter_read(void)
Returns the current CPU counter value.
Definition: system-clocks.c:117
Thread register context.
Definition: cpu.h:196
void * _CPU_Thread_Idle_body(uintptr_t ignored)
Definition: idle-mcf5272.c:20
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
Blackfin Set up Basic CPU Dependency Settings Based on Compiler Settings.
void _CPU_Context_restore_fp(Context_Control_fp **fp_context_ptr)
Definition: cpu.c:207
Interrupt stack frame (ISF).
Definition: cpu.h:306
void _CPU_Context_Initialize(Context_Control *context, void *stack_area_begin, size_t stack_area_size, uint32_t new_level, void(*entry_point)(void), bool is_fp, void *tls_area)
Initializes the CPU context.
Definition: epiphany-context-initialize.c:40
void _CPU_Context_switch(Context_Control *run, Context_Control *heir)
CPU switch context.
Definition: cpu_asm.c:91
void _CPU_Initialize(void)
CPU initialization.
Definition: cpu.c:45
SPARC basic context.
Definition: cpu.h:242
uint32_t CPU_Counter_ticks
Unsigned integer type for CPU counter values.
Definition: cpu.h:1202
#define RTEMS_NO_RETURN
Definition: basedefs.h:101
uint32_t _CPU_ISR_Get_level(void)
Definition: cpu.c:88
RTEMS_INLINE_ROUTINE void _CPU_ISR_install_raw_handler(uint32_t vector, CPU_ISR_raw_handler new_handler, CPU_ISR_raw_handler *old_handler)
SPARC specific raw ISR installer.
Definition: cpu.h:703
bool _CPU_ISR_Is_enabled(uint32_t level)
Returns true if interrupts are enabled in the specified ISR level, otherwise returns false...
Definition: cpu.h:381
void _CPU_Context_restore(Context_Control *new_context) RTEMS_NO_RETURN
Definition: cpu_asm.c:111
uintptr_t CPU_Uint32ptr
Definition: cpu.h:668
uint32_t _CPU_Counter_frequency(void)
Returns the current CPU counter frequency in Hz.
Definition: system-clocks.c:112
Basic Definitions.
unsigned size
Definition: tte.h:74
RTEMS_INLINE_ROUTINE void _CPU_ISR_install_vector(uint32_t vector, CPU_ISR_handler new_handler, CPU_ISR_handler *old_handler)
SPARC specific RTEMS ISR installer.
Definition: cpu.h:605
void _CPU_Context_save_fp(Context_Control_fp **fp_context_ptr)
Definition: cpu.c:198
The set of registers that specifies the complete processor state.
Definition: cpu.h:635