source: rtems/cpukit/score/cpu/arm/rtems/score/cpu.h @ d0630763

4.115
Last change on this file since d0630763 was d0630763, checked in by Sebastian Huber <sebastian.huber@…>, on 09/27/11 at 09:14:03

2011-09-28 Sebastian Huber <sebastian.huber@…>

PR 1914/cpukit

  • rtems/score/cpu.h: Select timestamp implementation.
  • Property mode set to 100644
File size: 13.0 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ScoreCPU
5 *
6 * @brief ARM architecture support API.
7 */
8
9/*
10 * $Id$
11 *
12 *  This include file contains information pertaining to the ARM
13 *  processor.
14 *
15 *  Copyright (c) 2009-2011 embedded brains GmbH.
16 *
17 *  Copyright (c) 2007 Ray Xu <Rayx.cn@gmail.com>
18 *
19 *  Copyright (c) 2006 OAR Corporation
20 *
21 *  Copyright (c) 2002 Advent Networks, Inc.
22 *        Jay Monkman <jmonkman@adventnetworks.com>
23 *
24 *  COPYRIGHT (c) 2000 Canon Research Centre France SA.
25 *  Emmanuel Raguet, mailto:raguet@crf.canon.fr
26 *
27 *  The license and distribution terms for this file may be
28 *  found in the file LICENSE in this distribution or at
29 *  http://www.rtems.com/license/LICENSE.
30 *
31 */
32
33#ifndef _RTEMS_SCORE_CPU_H
34#define _RTEMS_SCORE_CPU_H
35
36#include <rtems/score/types.h>
37#include <rtems/score/arm.h>
38
39#if defined(ARM_MULTILIB_ARCH_V4)
40
41/**
42 * @defgroup ScoreCPUARM ARM Specific Support
43 *
44 * @ingroup ScoreCPU
45 *
46 * @brief ARM specific support.
47 *
48 * @{
49 */
50
51#ifdef __thumb__
52  #define ARM_SWITCH_REGISTERS uint32_t arm_switch_reg
53  #define ARM_SWITCH_TO_ARM ".align 2\nbx pc\n.arm\n"
54  #define ARM_SWITCH_BACK "add %[arm_switch_reg], pc, #1\nbx %[arm_switch_reg]\n.thumb\n"
55  #define ARM_SWITCH_OUTPUT [arm_switch_reg] "=&r" (arm_switch_reg)
56  #define ARM_SWITCH_ADDITIONAL_OUTPUT , ARM_SWITCH_OUTPUT
57#else
58  #define ARM_SWITCH_REGISTERS
59  #define ARM_SWITCH_TO_ARM
60  #define ARM_SWITCH_BACK
61  #define ARM_SWITCH_OUTPUT
62  #define ARM_SWITCH_ADDITIONAL_OUTPUT
63#endif
64
65/**
66 * @name Program Status Register
67 *
68 * @{
69 */
70
71#define ARM_PSR_N (1 << 31)
72#define ARM_PSR_Z (1 << 30)
73#define ARM_PSR_C (1 << 29)
74#define ARM_PSR_V (1 << 28)
75#define ARM_PSR_Q (1 << 27)
76#define ARM_PSR_J (1 << 24)
77#define ARM_PSR_GE_SHIFT 16
78#define ARM_PSR_GE_MASK (0xf << ARM_PSR_GE_SHIFT)
79#define ARM_PSR_E (1 << 9)
80#define ARM_PSR_A (1 << 8)
81#define ARM_PSR_I (1 << 7)
82#define ARM_PSR_F (1 << 6)
83#define ARM_PSR_T (1 << 5)
84#define ARM_PSR_M_SHIFT 0
85#define ARM_PSR_M_MASK (0x1f << ARM_PSR_M_SHIFT)
86#define ARM_PSR_M_USR 0x10
87#define ARM_PSR_M_FIQ 0x11
88#define ARM_PSR_M_IRQ 0x12
89#define ARM_PSR_M_SVC 0x13
90#define ARM_PSR_M_ABT 0x17
91#define ARM_PSR_M_UND 0x1b
92#define ARM_PSR_M_SYS 0x1f
93
94/** @} */
95
96/** @} */
97
98#endif /* defined(ARM_MULTILIB_ARCH_V4) */
99
100/**
101 * @addtogroup ScoreCPU
102 *
103 * @{
104 */
105
106/* If someone uses THUMB we assume she wants minimal code size */
107#ifdef __thumb__
108  #define CPU_INLINE_ENABLE_DISPATCH FALSE
109#else
110  #define CPU_INLINE_ENABLE_DISPATCH TRUE
111#endif
112
113#if defined(__ARMEL__)
114  #define CPU_BIG_ENDIAN FALSE
115  #define CPU_LITTLE_ENDIAN TRUE
116#elif defined(__ARMEB__)
117  #define CPU_BIG_ENDIAN TRUE
118  #define CPU_LITTLE_ENDIAN FALSE
119#else
120  #error "unknown endianness"
121#endif
122
123#define CPU_UNROLL_ENQUEUE_PRIORITY TRUE
124
125#define CPU_HAS_SOFTWARE_INTERRUPT_STACK FALSE
126
127#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
128
129#define CPU_ALLOCATE_INTERRUPT_STACK FALSE
130
131#define CPU_ISR_PASSES_FRAME_POINTER 0
132
133#if ( ARM_HAS_FPU == 1 )
134  #define CPU_HARDWARE_FP TRUE
135#else
136  #define CPU_HARDWARE_FP FALSE
137#endif
138
139#define CPU_SOFTWARE_FP FALSE
140
141#define CPU_ALL_TASKS_ARE_FP FALSE
142
143#define CPU_IDLE_TASK_IS_FP FALSE
144
145#define CPU_USE_DEFERRED_FP_SWITCH FALSE
146
147#define CPU_PROVIDES_IDLE_THREAD_BODY FALSE
148
149#define CPU_STACK_GROWS_UP FALSE
150
151/* XXX Why 32? */
152#define CPU_STRUCTURE_ALIGNMENT __attribute__ ((aligned (32)))
153
154#define CPU_TIMESTAMP_USE_INT64_INLINE TRUE
155
156/*
157 * The interrupt mask disables only normal interrupts (IRQ).
158 *
159 * In order to support fast interrupts (FIQ) such that they can do something
160 * useful, we have to disable the operating system support for FIQs.  Having
161 * operating system support for them would require that FIQs are disabled
162 * during critical sections of the operating system and application.  At this
163 * level IRQs and FIQs would be equal.  It is true that FIQs could interrupt
164 * the non critical sections of IRQs, so here they would have a small
165 * advantage.  Without operating system support, the FIQs can execute at any
166 * time (of course not during the service of another FIQ). If someone needs
167 * operating system support for a FIQ, she can trigger a software interrupt and
168 * service the request in a two-step process.
169 */
170#define CPU_MODES_INTERRUPT_MASK 0x80
171
172#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
173
174#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
175
176#define CPU_INTERRUPT_NUMBER_OF_VECTORS 8
177
178#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
179
180#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
181
182#define CPU_STACK_MINIMUM_SIZE (1024 * 4)
183
184/* AAPCS, section 4.1, Fundamental Data Types */
185#define CPU_ALIGNMENT 8
186
187#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
188
189/* AAPCS, section 4.3.1, Aggregates */
190#define CPU_PARTITION_ALIGNMENT 4
191
192/* AAPCS, section 5.2.1.2, Stack constraints at a public interface */
193#define CPU_STACK_ALIGNMENT 8
194
195/*
196 * Bitfield handler macros.
197 *
198 * If we had a particularly fast function for finding the first
199 * bit set in a word, it would go here. Since we don't (*), we'll
200 * just use the universal macros.
201 *
202 * (*) On ARM V5 and later, there's a CLZ function which could be
203 *     used to implement much quicker than the default macro.
204 */
205
206#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
207
208#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
209
210/** @} */
211
212#ifndef ASM
213
214#ifdef __cplusplus
215extern "C" {
216#endif
217
218/**
219 * @addtogroup ScoreCPU
220 *
221 * @{
222 */
223
224typedef struct {
225#if defined(ARM_MULTILIB_ARCH_V4)
226  uint32_t register_cpsr;
227  uint32_t register_r4;
228  uint32_t register_r5;
229  uint32_t register_r6;
230  uint32_t register_r7;
231  uint32_t register_r8;
232  uint32_t register_r9;
233  uint32_t register_r10;
234  uint32_t register_fp;
235  uint32_t register_sp;
236  uint32_t register_lr;
237  uint32_t register_pc;
238#elif defined(ARM_MULTILIB_ARCH_V7M)
239  uint32_t register_r4;
240  uint32_t register_r5;
241  uint32_t register_r6;
242  uint32_t register_r7;
243  uint32_t register_r8;
244  uint32_t register_r9;
245  uint32_t register_r10;
246  uint32_t register_r11;
247  void *register_lr;
248  void *register_sp;
249  uint32_t isr_nest_level;
250#endif
251} Context_Control;
252
253typedef struct {
254  /* Not supported */
255} Context_Control_fp;
256
257SCORE_EXTERN Context_Control_fp _CPU_Null_fp_context;
258
259extern uint32_t arm_cpu_mode;
260
261static inline uint32_t arm_interrupt_disable( void )
262{
263#if defined(ARM_MULTILIB_ARCH_V4)
264  uint32_t arm_switch_reg;
265  uint32_t level;
266
267  __asm__ volatile (
268    ARM_SWITCH_TO_ARM
269    "mrs %[level], cpsr\n"
270    "orr %[arm_switch_reg], %[level], #0x80\n"
271    "msr cpsr, %[arm_switch_reg]\n"
272    ARM_SWITCH_BACK
273    : [arm_switch_reg] "=&r" (arm_switch_reg), [level] "=&r" (level)
274  );
275
276  return level;
277#elif defined(ARM_MULTILIB_ARCH_V7M)
278  uint32_t level;
279  uint32_t basepri = 0x80;
280
281  __asm__ volatile (
282    "mrs %[level], basepri\n"
283    "msr basepri_max, %[basepri]\n"
284    : [level] "=&r" (level)
285    : [basepri] "r" (basepri)
286  );
287
288  return level;
289#endif
290}
291
292static inline void arm_interrupt_enable( uint32_t level )
293{
294#if defined(ARM_MULTILIB_ARCH_V4)
295  ARM_SWITCH_REGISTERS;
296
297  __asm__ volatile (
298    ARM_SWITCH_TO_ARM
299    "msr cpsr, %[level]\n"
300    ARM_SWITCH_BACK
301    : ARM_SWITCH_OUTPUT
302    : [level] "r" (level)
303  );
304#elif defined(ARM_MULTILIB_ARCH_V7M)
305  __asm__ volatile (
306    "msr basepri, %[level]\n"
307    :
308    : [level] "r" (level)
309  );
310#endif
311}
312
313static inline void arm_interrupt_flash( uint32_t level )
314{
315#if defined(ARM_MULTILIB_ARCH_V4)
316  uint32_t arm_switch_reg;
317
318  __asm__ volatile (
319    ARM_SWITCH_TO_ARM
320    "mrs %[arm_switch_reg], cpsr\n"
321    "msr cpsr, %[level]\n"
322    "msr cpsr, %[arm_switch_reg]\n"
323    ARM_SWITCH_BACK
324    : [arm_switch_reg] "=&r" (arm_switch_reg)
325    : [level] "r" (level)
326  );
327#elif defined(ARM_MULTILIB_ARCH_V7M)
328  uint32_t basepri;
329
330  __asm__ volatile (
331    "mrs %[basepri], basepri\n"
332    "msr basepri, %[level]\n"
333    "msr basepri, %[basepri]\n"
334    : [basepri] "=&r" (basepri)
335    : [level] "r" (level)
336  );
337#endif
338}
339
340#define _CPU_ISR_Disable( _isr_cookie ) \
341  do { \
342    _isr_cookie = arm_interrupt_disable(); \
343  } while (0)
344
345#define _CPU_ISR_Enable( _isr_cookie )  \
346  arm_interrupt_enable( _isr_cookie )
347
348#define _CPU_ISR_Flash( _isr_cookie ) \
349  arm_interrupt_flash( _isr_cookie )
350
351void _CPU_ISR_Set_level( uint32_t level );
352
353uint32_t _CPU_ISR_Get_level( void );
354
355void _CPU_Context_Initialize(
356  Context_Control *the_context,
357  void *stack_area_begin,
358  size_t stack_area_size,
359  uint32_t new_level,
360  void (*entry_point)( void ),
361  bool is_fp
362);
363
364#define _CPU_Context_Get_SP( _context ) \
365  (_context)->register_sp
366
367#define _CPU_Context_Restart_self( _the_context ) \
368   _CPU_Context_restore( (_the_context) );
369
370#define _CPU_Context_Fp_start( _base, _offset ) \
371   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
372
373#define _CPU_Context_Initialize_fp( _destination ) \
374  do { \
375    *(*(_destination)) = _CPU_Null_fp_context; \
376  } while (0)
377
378#define _CPU_Fatal_halt( _err )             \
379   do {                                     \
380     uint32_t _level;                       \
381     uint32_t _error = _err;                \
382     _CPU_ISR_Disable( _level );            \
383     __asm__ volatile ("mov r0, %0\n"           \
384                   : "=r" (_error)          \
385                   : "0" (_error)           \
386                   : "r0" );                \
387     while (1);                             \
388   } while (0);
389
390void _CPU_Initialize( void );
391
392#define _CPU_Initialize_vectors()
393
394void _CPU_ISR_install_vector(
395  uint32_t vector,
396  proc_ptr new_handler,
397  proc_ptr *old_handler
398);
399
400void _CPU_Context_switch( Context_Control *run, Context_Control *heir );
401
402void _CPU_Context_restore( Context_Control *new_context )
403  RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
404
405#if defined(ARM_MULTILIB_ARCH_V7M)
406  void _ARMV7M_Start_multitasking( Context_Control *bsp, Context_Control *heir );
407  void _ARMV7M_Stop_multitasking( Context_Control *bsp )
408    RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
409  #define _CPU_Start_multitasking _ARMV7M_Start_multitasking
410  #define _CPU_Stop_multitasking _ARMV7M_Stop_multitasking
411#endif
412
413void _CPU_Context_save_fp( Context_Control_fp **fp_context_ptr );
414
415void _CPU_Context_restore_fp( Context_Control_fp **fp_context_ptr );
416
417static inline uint32_t CPU_swap_u32( uint32_t value )
418{
419#if defined(__thumb2__)
420  __asm__ volatile (
421    "rev %0, %0"
422    : "=r" (value)
423    : "0" (value)
424  );
425  return value;
426#elif defined(__thumb__)
427  uint32_t byte1, byte2, byte3, byte4, swapped;
428
429  byte4 = (value >> 24) & 0xff;
430  byte3 = (value >> 16) & 0xff;
431  byte2 = (value >> 8)  & 0xff;
432  byte1 =  value & 0xff;
433
434  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
435  return swapped;
436#else
437  uint32_t tmp = value; /* make compiler warnings go away */
438  __asm__ volatile ("EOR %1, %0, %0, ROR #16\n"
439                "BIC %1, %1, #0xff0000\n"
440                "MOV %0, %0, ROR #8\n"
441                "EOR %0, %0, %1, LSR #8\n"
442                : "=r" (value), "=r" (tmp)
443                : "0" (value), "1" (tmp));
444  return value;
445#endif
446}
447
448static inline uint16_t CPU_swap_u16( uint16_t value )
449{
450#if defined(__thumb2__)
451  __asm__ volatile (
452    "rev16 %0, %0"
453    : "=r" (value)
454    : "0" (value)
455  );
456  return value;
457#else
458  return (uint16_t) (((value & 0xffU) << 8) | ((value >> 8) & 0xffU));
459#endif
460}
461
462/** @} */
463
464#if defined(ARM_MULTILIB_ARCH_V4)
465
466/**
467 * @addtogroup ScoreCPUARM
468 *
469 * @{
470 */
471
472typedef struct {
473  uint32_t r0;
474  uint32_t r1;
475  uint32_t r2;
476  uint32_t r3;
477  uint32_t r4;
478  uint32_t r5;
479  uint32_t r6;
480  uint32_t r7;
481  uint32_t r8;
482  uint32_t r9;
483  uint32_t r10;
484  uint32_t r11;
485  uint32_t r12;
486  uint32_t sp;
487  uint32_t lr;
488  uint32_t pc;
489  uint32_t cpsr;
490} arm_cpu_context;
491
492typedef void arm_exc_abort_handler( arm_cpu_context *context );
493
494typedef enum {
495  ARM_EXCEPTION_RESET = 0,
496  ARM_EXCEPTION_UNDEF = 1,
497  ARM_EXCEPTION_SWI = 2,
498  ARM_EXCEPTION_PREF_ABORT = 3,
499  ARM_EXCEPTION_DATA_ABORT = 4,
500  ARM_EXCEPTION_RESERVED = 5,
501  ARM_EXCEPTION_IRQ = 6,
502  ARM_EXCEPTION_FIQ = 7,
503  MAX_EXCEPTIONS = 8
504} Arm_symbolic_exception_name;
505
506static inline uint32_t arm_status_irq_enable( void )
507{
508  uint32_t arm_switch_reg;
509  uint32_t psr;
510
511  RTEMS_COMPILER_MEMORY_BARRIER();
512
513  __asm__ volatile (
514    ARM_SWITCH_TO_ARM
515    "mrs %[psr], cpsr\n"
516    "bic %[arm_switch_reg], %[psr], #0x80\n"
517    "msr cpsr, %[arm_switch_reg]\n"
518    ARM_SWITCH_BACK
519    : [arm_switch_reg] "=&r" (arm_switch_reg), [psr] "=&r" (psr)
520  );
521
522  return psr;
523}
524
525static inline void arm_status_restore( uint32_t psr )
526{
527  ARM_SWITCH_REGISTERS;
528
529  __asm__ volatile (
530    ARM_SWITCH_TO_ARM
531    "msr cpsr, %[psr]\n"
532    ARM_SWITCH_BACK
533    : ARM_SWITCH_OUTPUT
534    : [psr] "r" (psr)
535  );
536
537  RTEMS_COMPILER_MEMORY_BARRIER();
538}
539
540void arm_exc_data_abort_set_handler( arm_exc_abort_handler handler );
541
542void arm_exc_data_abort( void );
543
544void arm_exc_prefetch_abort_set_handler( arm_exc_abort_handler handler );
545
546void arm_exc_prefetch_abort( void );
547
548void bsp_interrupt_dispatch( void );
549
550void arm_exc_interrupt( void );
551
552void arm_exc_undefined( void );
553
554/** @} */
555
556/* XXX This is out of date */
557typedef struct {
558  uint32_t register_r0;
559  uint32_t register_r1;
560  uint32_t register_r2;
561  uint32_t register_r3;
562  uint32_t register_ip;
563  uint32_t register_lr;
564} CPU_Exception_frame;
565
566typedef CPU_Exception_frame CPU_Interrupt_frame;
567
568#elif defined(ARM_MULTILIB_ARCH_V7M)
569
570typedef void CPU_Interrupt_frame;
571
572#endif /* defined(ARM_MULTILIB_ARCH_V7M) */
573
574#ifdef __cplusplus
575}
576#endif
577
578#endif /* ASM */
579
580#endif /* _RTEMS_SCORE_CPU_H */
Note: See TracBrowser for help on using the repository browser.