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

4.115
Last change on this file since f7bac00b was f7bac00b, checked in by Sebastian Huber <sebastian.huber@…>, on 07/06/10 at 07:52:36

2010-07-06 Sebastian Huber <sebastian.huber@…>

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