source: rtems/cpukit/score/cpu/powerpc/rtems/score/cpu.h @ 815994f

4.115
Last change on this file since 815994f was 815994f, checked in by Sebastian Huber <sebastian.huber@…>, on 11/25/12 at 16:48:11

score: Add CPU_Exception_frame

Add CPU port type CPU_Exception_frame and function
_CPU_Exception_frame_print().

The CPU ports of avr, bfin, h8300, lm32, m32c, m32r, m68k, nios2, sh,
sparc64, and v850 use an empty default implementation of
_CPU_Exception_frame_print().

Add rtems_exception_frame and rtems_exception_frame_print().

Add RTEMS_FATAL_SOURCE_EXCEPTION for CPU exceptions. Use rtems_fatal()
with source RTEMS_FATAL_SOURCE_EXCEPTION in CPU ports of i386, powerpc,
and sparc for unexpected exceptions.

Add third parameter to RTEMS_BSP_CLEANUP_OPTIONS() which controls the
BSP_PRINT_EXCEPTION_CONTEXT define used in the default
bsp_fatal_extension().

Add test sptests/spfatal26.

  • Property mode set to 100644
File size: 33.4 KB
Line 
1/**
2 * @file rtems/score/cpu.h
3 */
4
5/*
6 *  COPYRIGHT (c) 1989-2012.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  COPYRIGHT (c) 1995 i-cubed ltd.
10 *
11 *  To anyone who acknowledges that this file is provided "AS IS"
12 *  without any express or implied warranty:
13 *      permission to use, copy, modify, and distribute this file
14 *      for any purpose is hereby granted without fee, provided that
15 *      the above copyright notice and this notice appears in all
16 *      copies, and that the name of i-cubed limited not be used in
17 *      advertising or publicity pertaining to distribution of the
18 *      software without specific, written prior permission.
19 *      i-cubed limited makes no representations about the suitability
20 *      of this software for any purpose.
21 *
22 *  Copyright (c) 2001 Andy Dachs <a.dachs@sstl.co.uk>.
23 *
24 *  Copyright (c) 2001 Surrey Satellite Technology Limited (SSTL).
25 *
26 *  Copyright (c) 2010-2012 embedded brains GmbH.
27 *
28 *  The license and distribution terms for this file may be
29 *  found in the file LICENSE in this distribution or at
30 *  http://www.rtems.com/license/LICENSE.
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/powerpc.h>
38#include <rtems/powerpc/registers.h>
39
40#ifndef ASM
41  #include <string.h> /* for memset() */
42#endif
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48/* conditional compilation parameters */
49
50/*
51 *  Should the calls to _Thread_Enable_dispatch be inlined?
52 *
53 *  If TRUE, then they are inlined.
54 *  If FALSE, then a subroutine call is made.
55 *
56 *  Basically this is an example of the classic trade-off of size
57 *  versus speed.  Inlining the call (TRUE) typically increases the
58 *  size of RTEMS while speeding up the enabling of dispatching.
59 *  [NOTE: In general, the _Thread_Dispatch_disable_level will
60 *  only be 0 or 1 unless you are in an interrupt handler and that
61 *  interrupt handler invokes the executive.]  When not inlined
62 *  something calls _Thread_Enable_dispatch which in turns calls
63 *  _Thread_Dispatch.  If the enable dispatch is inlined, then
64 *  one subroutine call is avoided entirely.]
65 */
66
67#define CPU_INLINE_ENABLE_DISPATCH       FALSE
68
69/*
70 *  Should the body of the search loops in _Thread_queue_Enqueue_priority
71 *  be unrolled one time?  In unrolled each iteration of the loop examines
72 *  two "nodes" on the chain being searched.  Otherwise, only one node
73 *  is examined per iteration.
74 *
75 *  If TRUE, then the loops are unrolled.
76 *  If FALSE, then the loops are not unrolled.
77 *
78 *  The primary factor in making this decision is the cost of disabling
79 *  and enabling interrupts (_ISR_Flash) versus the cost of rest of the
80 *  body of the loop.  On some CPUs, the flash is more expensive than
81 *  one iteration of the loop body.  In this case, it might be desirable
82 *  to unroll the loop.  It is important to note that on some CPUs, this
83 *  code is the longest interrupt disable period in RTEMS.  So it is
84 *  necessary to strike a balance when setting this parameter.
85 */
86
87#define CPU_UNROLL_ENQUEUE_PRIORITY      FALSE
88
89/*
90 *  Does this port provide a CPU dependent IDLE task implementation?
91 *
92 *  If TRUE, then the routine _CPU_Thread_Idle_body
93 *  must be provided and is the default IDLE thread body instead of
94 *  _CPU_Thread_Idle_body.
95 *
96 *  If FALSE, then use the generic IDLE thread body if the BSP does
97 *  not provide one.
98 *
99 *  This is intended to allow for supporting processors which have
100 *  a low power or idle mode.  When the IDLE thread is executed, then
101 *  the CPU can be powered down.
102 *
103 *  The order of precedence for selecting the IDLE thread body is:
104 *
105 *    1.  BSP provided
106 *    2.  CPU dependent (if provided)
107 *    3.  generic (if no BSP and no CPU dependent)
108 */
109
110#define CPU_PROVIDES_IDLE_THREAD_BODY    FALSE
111
112/*
113 *  Does the stack grow up (toward higher addresses) or down
114 *  (toward lower addresses)?
115 *
116 *  If TRUE, then the grows upward.
117 *  If FALSE, then the grows toward smaller addresses.
118 */
119
120#define CPU_STACK_GROWS_UP               FALSE
121
122/*
123 *  The following is the variable attribute used to force alignment
124 *  of critical RTEMS structures.  On some processors it may make
125 *  sense to have these aligned on tighter boundaries than
126 *  the minimum requirements of the compiler in order to have as
127 *  much of the critical data area as possible in a cache line.
128 *
129 *  The placement of this macro in the declaration of the variables
130 *  is based on the syntactically requirements of the GNU C
131 *  "__attribute__" extension.  For example with GNU C, use
132 *  the following to force a structures to a 32 byte boundary.
133 *
134 *      __attribute__ ((aligned (32)))
135 *
136 *  NOTE:  Currently only the Priority Bit Map table uses this feature.
137 *         To benefit from using this, the data must be heavily
138 *         used so it will stay in the cache and used frequently enough
139 *         in the executive to justify turning this on.
140 */
141
142#define CPU_STRUCTURE_ALIGNMENT \
143  __attribute__ ((aligned (PPC_STRUCTURE_ALIGNMENT)))
144
145#define CPU_TIMESTAMP_USE_INT64_INLINE TRUE
146
147/*
148 *  Define what is required to specify how the network to host conversion
149 *  routines are handled.
150 */
151
152#if defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
153#define CPU_BIG_ENDIAN                           TRUE
154#define CPU_LITTLE_ENDIAN                        FALSE
155#else
156#define CPU_BIG_ENDIAN                           FALSE
157#define CPU_LITTLE_ENDIAN                        TRUE
158#endif
159
160/*
161 *  Does the CPU have hardware floating point?
162 *
163 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
164 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
165 *
166 *  If there is a FP coprocessor such as the i387 or mc68881, then
167 *  the answer is TRUE.
168 *
169 *  The macro name "PPC_HAS_FPU" should be made CPU specific.
170 *  It indicates whether or not this CPU model has FP support.  For
171 *  example, it would be possible to have an i386_nofp CPU model
172 *  which set this to false to indicate that you have an i386 without
173 *  an i387 and wish to leave floating point support out of RTEMS.
174 */
175
176#if ( PPC_HAS_FPU == 1 )
177#define CPU_HARDWARE_FP     TRUE
178#define CPU_SOFTWARE_FP     FALSE
179#else
180#define CPU_HARDWARE_FP     FALSE
181#define CPU_SOFTWARE_FP     FALSE
182#endif
183
184/*
185 *  Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
186 *
187 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
188 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
189 *
190 *  If CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
191 *
192 *  PowerPC Note: It appears the GCC can implicitly generate FPU
193 *  and Altivec instructions when you least expect them.  So make
194 *  all tasks floating point.
195 */
196
197#define CPU_ALL_TASKS_ARE_FP CPU_HARDWARE_FP
198
199/*
200 *  Should the IDLE task have a floating point context?
201 *
202 *  If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
203 *  and it has a floating point context which is switched in and out.
204 *  If FALSE, then the IDLE task does not have a floating point context.
205 *
206 *  Setting this to TRUE negatively impacts the time required to preempt
207 *  the IDLE task from an interrupt because the floating point context
208 *  must be saved as part of the preemption.
209 */
210
211#define CPU_IDLE_TASK_IS_FP      FALSE
212
213/*
214 *  Processor defined structures required for cpukit/score.
215 */
216
217/*
218 * Contexts
219 *
220 *  Generally there are 2 types of context to save.
221 *     1. Interrupt registers to save
222 *     2. Task level registers to save
223 *
224 *  This means we have the following 3 context items:
225 *     1. task level context stuff::  Context_Control
226 *     2. floating point task stuff:: Context_Control_fp
227 *     3. special interrupt level context :: Context_Control_interrupt
228 *
229 *  On some processors, it is cost-effective to save only the callee
230 *  preserved registers during a task context switch.  This means
231 *  that the ISR code needs to save those registers which do not
232 *  persist across function calls.  It is not mandatory to make this
233 *  distinctions between the caller/callee saves registers for the
234 *  purpose of minimizing context saved during task switch and on interrupts.
235 *  If the cost of saving extra registers is minimal, simplicity is the
236 *  choice.  Save the same context on interrupt entry as for tasks in
237 *  this case.
238 *
239 *  Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
240 *  care should be used in designing the context area.
241 *
242 *  On some CPUs with hardware floating point support, the Context_Control_fp
243 *  structure will not be used or it simply consist of an array of a
244 *  fixed number of bytes.   This is done when the floating point context
245 *  is dumped by a "FP save context" type instruction and the format
246 *  is not really defined by the CPU.  In this case, there is no need
247 *  to figure out the exact format -- only the size.  Of course, although
248 *  this is enough information for RTEMS, it is probably not enough for
249 *  a debugger such as gdb.  But that is another problem.
250 */
251
252#ifndef __SPE__
253  #define PPC_GPR_TYPE uint32_t
254  #define PPC_GPR_SIZE 4
255  #define PPC_GPR_LOAD lwz
256  #define PPC_GPR_STORE stw
257#else
258  #define PPC_GPR_TYPE uint64_t
259  #define PPC_GPR_SIZE 8
260  #define PPC_GPR_LOAD evldd
261  #define PPC_GPR_STORE evstdd
262#endif
263
264#define PPC_DEFAULT_CACHE_LINE_SIZE 32
265
266#ifndef ASM
267
268/* Non-volatile context according to E500ABIUG and EABI */
269typedef struct {
270  uint32_t gpr1;
271  uint32_t msr;
272  uint32_t lr;
273  uint32_t cr;
274  PPC_GPR_TYPE gpr14;
275  PPC_GPR_TYPE gpr15;
276  PPC_GPR_TYPE gpr16;
277  PPC_GPR_TYPE gpr17;
278  PPC_GPR_TYPE gpr18;
279  PPC_GPR_TYPE gpr19;
280  PPC_GPR_TYPE gpr20;
281  PPC_GPR_TYPE gpr21;
282  PPC_GPR_TYPE gpr22;
283  PPC_GPR_TYPE gpr23;
284  PPC_GPR_TYPE gpr24;
285  PPC_GPR_TYPE gpr25;
286  PPC_GPR_TYPE gpr26;
287  PPC_GPR_TYPE gpr27;
288  PPC_GPR_TYPE gpr28;
289  PPC_GPR_TYPE gpr29;
290  PPC_GPR_TYPE gpr30;
291  PPC_GPR_TYPE gpr31;
292  #ifdef __ALTIVEC__
293    /*
294     * 12 non-volatile vector registers, cache-aligned area for vscr/vrsave
295     * and padding to ensure cache-alignment.  Unfortunately, we can't verify
296     * the cache line size here in the cpukit but altivec support code will
297     * produce an error if this is ever different from 32 bytes.
298     *
299     * Note: it is the BSP/CPU-support's responsibility to save/restore
300     *       volatile vregs across interrupts and exceptions.
301     */
302    uint8_t altivec[16*12 + 32 + PPC_DEFAULT_CACHE_LINE_SIZE];
303  #endif
304} ppc_context;
305
306typedef struct {
307  uint8_t context [
308    PPC_DEFAULT_CACHE_LINE_SIZE
309      + sizeof(ppc_context)
310      + (sizeof(ppc_context) % PPC_DEFAULT_CACHE_LINE_SIZE == 0
311        ? 0
312          : PPC_DEFAULT_CACHE_LINE_SIZE
313            - sizeof(ppc_context) % PPC_DEFAULT_CACHE_LINE_SIZE)
314  ];
315} Context_Control;
316
317static inline ppc_context *ppc_get_context( Context_Control *context )
318{
319  uintptr_t clsz = PPC_DEFAULT_CACHE_LINE_SIZE;
320  uintptr_t mask = clsz - 1;
321  uintptr_t addr = (uintptr_t) context;
322
323  return (ppc_context *) ((addr & ~mask) + clsz);
324}
325
326#define _CPU_Context_Get_SP( _context ) \
327  ppc_get_context(_context)->gpr1
328#endif /* ASM */
329
330#define PPC_CONTEXT_OFFSET_GPR1 32
331#define PPC_CONTEXT_OFFSET_MSR 36
332#define PPC_CONTEXT_OFFSET_LR 40
333#define PPC_CONTEXT_OFFSET_CR 44
334
335#define PPC_CONTEXT_GPR_OFFSET( gpr ) \
336  (((gpr) - 14) * PPC_GPR_SIZE + 48)
337
338#define PPC_CONTEXT_OFFSET_GPR14 PPC_CONTEXT_GPR_OFFSET( 14 )
339#define PPC_CONTEXT_OFFSET_GPR15 PPC_CONTEXT_GPR_OFFSET( 15 )
340#define PPC_CONTEXT_OFFSET_GPR16 PPC_CONTEXT_GPR_OFFSET( 16 )
341#define PPC_CONTEXT_OFFSET_GPR17 PPC_CONTEXT_GPR_OFFSET( 17 )
342#define PPC_CONTEXT_OFFSET_GPR18 PPC_CONTEXT_GPR_OFFSET( 18 )
343#define PPC_CONTEXT_OFFSET_GPR19 PPC_CONTEXT_GPR_OFFSET( 19 )
344#define PPC_CONTEXT_OFFSET_GPR20 PPC_CONTEXT_GPR_OFFSET( 20 )
345#define PPC_CONTEXT_OFFSET_GPR21 PPC_CONTEXT_GPR_OFFSET( 21 )
346#define PPC_CONTEXT_OFFSET_GPR22 PPC_CONTEXT_GPR_OFFSET( 22 )
347#define PPC_CONTEXT_OFFSET_GPR23 PPC_CONTEXT_GPR_OFFSET( 23 )
348#define PPC_CONTEXT_OFFSET_GPR24 PPC_CONTEXT_GPR_OFFSET( 24 )
349#define PPC_CONTEXT_OFFSET_GPR25 PPC_CONTEXT_GPR_OFFSET( 25 )
350#define PPC_CONTEXT_OFFSET_GPR26 PPC_CONTEXT_GPR_OFFSET( 26 )
351#define PPC_CONTEXT_OFFSET_GPR27 PPC_CONTEXT_GPR_OFFSET( 27 )
352#define PPC_CONTEXT_OFFSET_GPR28 PPC_CONTEXT_GPR_OFFSET( 28 )
353#define PPC_CONTEXT_OFFSET_GPR29 PPC_CONTEXT_GPR_OFFSET( 29 )
354#define PPC_CONTEXT_OFFSET_GPR30 PPC_CONTEXT_GPR_OFFSET( 30 )
355#define PPC_CONTEXT_OFFSET_GPR31 PPC_CONTEXT_GPR_OFFSET( 31 )
356
357#ifndef ASM
358typedef struct {
359    /* The ABIs (PowerOpen/SVR4/EABI) only require saving f14-f31 over
360     * procedure calls.  However, this would mean that the interrupt
361     * frame had to hold f0-f13, and the fpscr.  And as the majority
362     * of tasks will not have an FP context, we will save the whole
363     * context here.
364     */
365#if (PPC_HAS_DOUBLE == 1)
366    double      f[32];
367    uint64_t    fpscr;
368#else
369    float       f[32];
370    uint32_t    fpscr;
371#endif
372} Context_Control_fp;
373
374typedef struct CPU_Interrupt_frame {
375    uint32_t   stacklink;       /* Ensure this is a real frame (also reg1 save) */
376    uint32_t   calleeLr;        /* link register used by callees: SVR4/EABI */
377
378    /* This is what is left out of the primary contexts */
379    uint32_t   gpr0;
380    uint32_t   gpr2;            /* play safe */
381    uint32_t   gpr3;
382    uint32_t   gpr4;
383    uint32_t   gpr5;
384    uint32_t   gpr6;
385    uint32_t   gpr7;
386    uint32_t   gpr8;
387    uint32_t   gpr9;
388    uint32_t   gpr10;
389    uint32_t   gpr11;
390    uint32_t   gpr12;
391    uint32_t   gpr13;   /* Play safe */
392    uint32_t   gpr28;   /* For internal use by the IRQ handler */
393    uint32_t   gpr29;   /* For internal use by the IRQ handler */
394    uint32_t   gpr30;   /* For internal use by the IRQ handler */
395    uint32_t   gpr31;   /* For internal use by the IRQ handler */
396    uint32_t   cr;      /* Bits of this are volatile, so no-one may save */
397    uint32_t   ctr;
398    uint32_t   xer;
399    uint32_t   lr;
400    uint32_t   pc;
401    uint32_t   msr;
402    uint32_t   pad[3];
403} CPU_Interrupt_frame;
404
405#endif /* ASM */
406
407/*
408 *  Does the CPU follow the simple vectored interrupt model?
409 *
410 *  If TRUE, then RTEMS allocates the vector table it internally manages.
411 *  If FALSE, then the BSP is assumed to allocate and manage the vector
412 *  table
413 *
414 *  PowerPC Specific Information:
415 *
416 *  The PowerPC and x86 were the first to use the PIC interrupt model.
417 *  They do not use the simple vectored interrupt model.
418 */
419#define CPU_SIMPLE_VECTORED_INTERRUPTS FALSE
420
421/*
422 *  Does RTEMS manage a dedicated interrupt stack in software?
423 *
424 *  If TRUE, then a stack is allocated in _ISR_Handler_initialization.
425 *  If FALSE, nothing is done.
426 *
427 *  If the CPU supports a dedicated interrupt stack in hardware,
428 *  then it is generally the responsibility of the BSP to allocate it
429 *  and set it up.
430 *
431 *  If the CPU does not support a dedicated interrupt stack, then
432 *  the porter has two options: (1) execute interrupts on the
433 *  stack of the interrupted task, and (2) have RTEMS manage a dedicated
434 *  interrupt stack.
435 *
436 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
437 *
438 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
439 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
440 *  possible that both are FALSE for a particular CPU.  Although it
441 *  is unclear what that would imply about the interrupt processing
442 *  procedure on that CPU.
443 */
444
445#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
446
447/*
448 *  Does this CPU have hardware support for a dedicated interrupt stack?
449 *
450 *  If TRUE, then it must be installed during initialization.
451 *  If FALSE, then no installation is performed.
452 *
453 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
454 *
455 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
456 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
457 *  possible that both are FALSE for a particular CPU.  Although it
458 *  is unclear what that would imply about the interrupt processing
459 *  procedure on that CPU.
460 */
461
462#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
463
464/*
465 *  Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
466 *
467 *  If TRUE, then the memory is allocated during initialization.
468 *  If FALSE, then the memory is allocated during initialization.
469 *
470 *  This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
471 */
472
473#define CPU_ALLOCATE_INTERRUPT_STACK FALSE
474
475/*
476 *  Does the RTEMS invoke the user's ISR with the vector number and
477 *  a pointer to the saved interrupt frame (1) or just the vector
478 *  number (0)?
479 */
480
481#define CPU_ISR_PASSES_FRAME_POINTER 0
482
483/*
484 *  Should the saving of the floating point registers be deferred
485 *  until a context switch is made to another different floating point
486 *  task?
487 *
488 *  If TRUE, then the floating point context will not be stored until
489 *  necessary.  It will remain in the floating point registers and not
490 *  disturned until another floating point task is switched to.
491 *
492 *  If FALSE, then the floating point context is saved when a floating
493 *  point task is switched out and restored when the next floating point
494 *  task is restored.  The state of the floating point registers between
495 *  those two operations is not specified.
496 *
497 *  If the floating point context does NOT have to be saved as part of
498 *  interrupt dispatching, then it should be safe to set this to TRUE.
499 *
500 *  Setting this flag to TRUE results in using a different algorithm
501 *  for deciding when to save and restore the floating point context.
502 *  The deferred FP switch algorithm minimizes the number of times
503 *  the FP context is saved and restored.  The FP context is not saved
504 *  until a context switch is made to another, different FP task.
505 *  Thus in a system with only one FP task, the FP context will never
506 *  be saved or restored.
507 *
508 *  Note, however that compilers may use floating point registers/
509 *  instructions for optimization or they may save/restore FP registers
510 *  on the stack. You must not use deferred switching in these cases
511 *  and on the PowerPC attempting to do so will raise a "FP unavailable"
512 *  exception.
513 */
514/*
515 *  ACB Note:  This could make debugging tricky..
516 */
517
518/* conservative setting (FALSE); probably doesn't affect performance too much */
519#define CPU_USE_DEFERRED_FP_SWITCH       FALSE
520
521/*
522 *  Processor defined structures required for cpukit/score.
523 */
524
525#ifndef ASM
526
527/*
528 *  This variable is optional.  It is used on CPUs on which it is difficult
529 *  to generate an "uninitialized" FP context.  It is filled in by
530 *  _CPU_Initialize and copied into the task's FP context area during
531 *  _CPU_Context_Initialize.
532 */
533
534/* EXTERN Context_Control_fp  _CPU_Null_fp_context; */
535
536#endif /* ndef ASM */
537
538/*
539 *  This defines the number of levels and the mask used to pick those
540 *  bits out of a thread mode.
541 */
542
543#define CPU_MODES_INTERRUPT_LEVEL  0x00000001 /* interrupt level in mode */
544#define CPU_MODES_INTERRUPT_MASK   0x00000001 /* interrupt level in mode */
545
546/*
547 *  Nothing prevents the porter from declaring more CPU specific variables.
548 */
549
550#ifndef ASM
551
552SCORE_EXTERN struct {
553  uint32_t      *Disable_level;
554  void          *Stack;
555  volatile bool *Switch_necessary;
556  bool          *Signal;
557
558} _CPU_IRQ_info CPU_STRUCTURE_ALIGNMENT;
559
560#endif /* ndef ASM */
561
562/*
563 *  The size of the floating point context area.  On some CPUs this
564 *  will not be a "sizeof" because the format of the floating point
565 *  area is not defined -- only the size is.  This is usually on
566 *  CPUs with a "floating point save context" instruction.
567 */
568
569#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
570
571/*
572 * (Optional) # of bytes for libmisc/stackchk to check
573 * If not specifed, then it defaults to something reasonable
574 * for most architectures.
575 */
576
577#define CPU_STACK_CHECK_SIZE    (128)
578
579/*
580 *  Amount of extra stack (above minimum stack size) required by
581 *  MPCI receive server thread.  Remember that in a multiprocessor
582 *  system this thread must exist and be able to process all directives.
583 */
584
585#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
586
587/*
588 *  This defines the number of entries in the ISR_Vector_table managed
589 *  by RTEMS.
590 *
591 *  NOTE: CPU_INTERRUPT_NUMBER_OF_VECTORS and
592 *        CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER are only used on
593 *        Simple Vectored Architectures and thus are not defined
594 *        for this architecture.
595 */
596
597/*
598 *  This is defined if the port has a special way to report the ISR nesting
599 *  level.  Most ports maintain the variable _ISR_Nest_level. Note that
600 *  this is not an option - RTEMS/score _relies_ on _ISR_Nest_level
601 *  being maintained (e.g. watchdog queues).
602 */
603
604#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
605
606/*
607 *  ISR handler macros
608 */
609
610/*
611 *  Disable all interrupts for an RTEMS critical section.  The previous
612 *  level is returned in _isr_cookie.
613 */
614
615#ifndef ASM
616
617static inline uint32_t   _CPU_ISR_Get_level( void )
618{
619  register unsigned int msr;
620  _CPU_MSR_GET(msr);
621  if (msr & MSR_EE) return 0;
622  else  return 1;
623}
624
625static inline void _CPU_ISR_Set_level( uint32_t   level )
626{
627  register unsigned int msr;
628  _CPU_MSR_GET(msr);
629  if (!(level & CPU_MODES_INTERRUPT_MASK)) {
630    msr |= ppc_interrupt_get_disable_mask();
631  }
632  else {
633    msr &= ~ppc_interrupt_get_disable_mask();
634  }
635  _CPU_MSR_SET(msr);
636}
637
638void BSP_panic(char *);
639
640/* Fatal Error manager macros */
641
642/*
643 *  This routine copies _error into a known place -- typically a stack
644 *  location or a register, optionally disables interrupts, and
645 *  halts/stops the CPU.
646 */
647
648void _BSP_Fatal_error(unsigned int);
649
650#endif /* ASM */
651
652#define _CPU_Fatal_halt( _error ) \
653  _BSP_Fatal_error(_error)
654
655/* end of Fatal Error manager macros */
656
657/*
658 * SPRG0 was previously used to make sure that the BSP fixed the PR288 bug.
659 * Now SPRG0 is devoted to the interrupt disable mask.
660 */
661
662#define PPC_BSP_HAS_FIXED_PR288 ppc_this_is_now_the_interrupt_disable_mask
663
664/*
665 *  Should be large enough to run all RTEMS tests.  This ensures
666 *  that a "reasonable" small application should not have any problems.
667 */
668
669#define CPU_STACK_MINIMUM_SIZE          (1024*8)
670
671#define CPU_SIZEOF_POINTER 4
672
673/*
674 *  CPU's worst alignment requirement for data types on a byte boundary.  This
675 *  alignment does not take into account the requirements for the stack.
676 */
677
678#define CPU_ALIGNMENT              (PPC_ALIGNMENT)
679
680/*
681 *  This number corresponds to the byte alignment requirement for the
682 *  heap handler.  This alignment requirement may be stricter than that
683 *  for the data types alignment specified by CPU_ALIGNMENT.  It is
684 *  common for the heap to follow the same alignment requirement as
685 *  CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
686 *  then this should be set to CPU_ALIGNMENT.
687 *
688 *  NOTE:  This does not have to be a power of 2.  It does have to
689 *         be greater or equal to than CPU_ALIGNMENT.
690 */
691
692#define CPU_HEAP_ALIGNMENT         (PPC_ALIGNMENT)
693
694/*
695 *  This number corresponds to the byte alignment requirement for memory
696 *  buffers allocated by the partition manager.  This alignment requirement
697 *  may be stricter than that for the data types alignment specified by
698 *  CPU_ALIGNMENT.  It is common for the partition to follow the same
699 *  alignment requirement as CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict
700 *  enough for the partition, then this should be set to CPU_ALIGNMENT.
701 *
702 *  NOTE:  This does not have to be a power of 2.  It does have to
703 *         be greater or equal to than CPU_ALIGNMENT.
704 */
705
706#define CPU_PARTITION_ALIGNMENT    (PPC_ALIGNMENT)
707
708/*
709 *  This number corresponds to the byte alignment requirement for the
710 *  stack.  This alignment requirement may be stricter than that for the
711 *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
712 *  is strict enough for the stack, then this should be set to 0.
713 *
714 *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
715 */
716
717#define CPU_STACK_ALIGNMENT        (PPC_STACK_ALIGNMENT)
718
719#ifndef ASM
720/*  The following routine swaps the endian format of an unsigned int.
721 *  It must be static because it is referenced indirectly.
722 *
723 *  This version will work on any processor, but if there is a better
724 *  way for your CPU PLEASE use it.  The most common way to do this is to:
725 *
726 *     swap least significant two bytes with 16-bit rotate
727 *     swap upper and lower 16-bits
728 *     swap most significant two bytes with 16-bit rotate
729 *
730 *  Some CPUs have special instructions which swap a 32-bit quantity in
731 *  a single instruction (e.g. i486).  It is probably best to avoid
732 *  an "endian swapping control bit" in the CPU.  One good reason is
733 *  that interrupts would probably have to be disabled to ensure that
734 *  an interrupt does not try to access the same "chunk" with the wrong
735 *  endian.  Another good reason is that on some CPUs, the endian bit
736 *  endianness for ALL fetches -- both code and data -- so the code
737 *  will be fetched incorrectly.
738 */
739
740static inline uint32_t CPU_swap_u32(
741  uint32_t value
742)
743{
744  uint32_t   swapped;
745
746  __asm__ volatile("rlwimi %0,%1,8,24,31;"
747               "rlwimi %0,%1,24,16,23;"
748               "rlwimi %0,%1,8,8,15;"
749               "rlwimi %0,%1,24,0,7;" :
750               "=&r" ((swapped)) : "r" ((value)));
751
752  return( swapped );
753}
754
755#define CPU_swap_u16( value ) \
756  (((value&0xff) << 8) | ((value >> 8)&0xff))
757
758#endif /* ASM */
759
760
761#ifndef ASM
762/* Context handler macros */
763
764/*
765 *  Initialize the context to a state suitable for starting a
766 *  task after a context restore operation.  Generally, this
767 *  involves:
768 *
769 *     - setting a starting address
770 *     - preparing the stack
771 *     - preparing the stack and frame pointers
772 *     - setting the proper interrupt level in the context
773 *     - initializing the floating point context
774 *
775 *  This routine generally does not set any unnecessary register
776 *  in the context.  The state of the "general data" registers is
777 *  undefined at task start time.
778 */
779
780void _CPU_Context_Initialize(
781  Context_Control  *the_context,
782  uint32_t         *stack_base,
783  uint32_t          size,
784  uint32_t          new_level,
785  void             *entry_point,
786  bool              is_fp
787);
788
789/*
790 *  This routine is responsible for somehow restarting the currently
791 *  executing task.  If you are lucky, then all that is necessary
792 *  is restoring the context.  Otherwise, there will need to be
793 *  a special assembly routine which does something special in this
794 *  case.  Context_Restore should work most of the time.  It will
795 *  not work if restarting self conflicts with the stack frame
796 *  assumptions of restoring a context.
797 */
798
799#define _CPU_Context_Restart_self( _the_context ) \
800   _CPU_Context_restore( (_the_context) );
801
802/*
803 *  The purpose of this macro is to allow the initial pointer into
804 *  a floating point context area (used to save the floating point
805 *  context) to be at an arbitrary place in the floating point
806 *  context area.
807 *
808 *  This is necessary because some FP units are designed to have
809 *  their context saved as a stack which grows into lower addresses.
810 *  Other FP units can be saved by simply moving registers into offsets
811 *  from the base of the context area.  Finally some FP units provide
812 *  a "dump context" instruction which could fill in from high to low
813 *  or low to high based on the whim of the CPU designers.
814 */
815
816#define _CPU_Context_Fp_start( _base, _offset ) \
817   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
818
819/*
820 *  This routine initializes the FP context area passed to it to.
821 *  There are a few standard ways in which to initialize the
822 *  floating point context.  The code included for this macro assumes
823 *  that this is a CPU in which a "initial" FP context was saved into
824 *  _CPU_Null_fp_context and it simply copies it to the destination
825 *  context passed to it.
826 *
827 *  Other models include (1) not doing anything, and (2) putting
828 *  a "null FP status word" in the correct place in the FP context.
829 */
830
831#define _CPU_Context_Initialize_fp( _destination ) \
832  memset( *(_destination), 0, sizeof( **(_destination) ) )
833
834/* end of Context handler macros */
835#endif /* ASM */
836
837#ifndef ASM
838/* Bitfield handler macros */
839
840/*
841 *  This routine sets _output to the bit number of the first bit
842 *  set in _value.  _value is of CPU dependent type Priority_bit_map_Control.
843 *  This type may be either 16 or 32 bits wide although only the 16
844 *  least significant bits will be used.
845 *
846 *  There are a number of variables in using a "find first bit" type
847 *  instruction.
848 *
849 *    (1) What happens when run on a value of zero?
850 *    (2) Bits may be numbered from MSB to LSB or vice-versa.
851 *    (3) The numbering may be zero or one based.
852 *    (4) The "find first bit" instruction may search from MSB or LSB.
853 *
854 *  RTEMS guarantees that (1) will never happen so it is not a concern.
855 *  (2),(3), (4) are handled by the macros _CPU_Priority_mask() and
856 *  _CPU_Priority_Bits_index().  These three form a set of routines
857 *  which must logically operate together.  Bits in the _value are
858 *  set and cleared based on masks built by _CPU_Priority_mask().
859 *  The basic major and minor values calculated by _Priority_Major()
860 *  and _Priority_Minor() are "massaged" by _CPU_Priority_Bits_index()
861 *  to properly range between the values returned by the "find first bit"
862 *  instruction.  This makes it possible for _Priority_Get_highest() to
863 *  calculate the major and directly index into the minor table.
864 *  This mapping is necessary to ensure that 0 (a high priority major/minor)
865 *  is the first bit found.
866 *
867 *  This entire "find first bit" and mapping process depends heavily
868 *  on the manner in which a priority is broken into a major and minor
869 *  components with the major being the 4 MSB of a priority and minor
870 *  the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
871 *  priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
872 *  to the lowest priority.
873 *
874 *  If your CPU does not have a "find first bit" instruction, then
875 *  there are ways to make do without it.  Here are a handful of ways
876 *  to implement this in software:
877 *
878 *    - a series of 16 bit test instructions
879 *    - a "binary search using if's"
880 *    - _number = 0
881 *      if _value > 0x00ff
882 *        _value >>=8
883 *        _number = 8;
884 *
885 *      if _value > 0x0000f
886 *        _value >=8
887 *        _number += 4
888 *
889 *      _number += bit_set_table[ _value ]
890 *
891 *    where bit_set_table[ 16 ] has values which indicate the first
892 *      bit set
893 */
894
895#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
896  { \
897    __asm__ volatile ("cntlzw %0, %1" : "=r" ((_output)), "=r" ((_value)) : \
898                  "1" ((_value))); \
899  }
900
901/* end of Bitfield handler macros */
902
903/*
904 *  This routine builds the mask which corresponds to the bit fields
905 *  as searched by _CPU_Bitfield_Find_first_bit().  See the discussion
906 *  for that routine.
907 */
908
909#define _CPU_Priority_Mask( _bit_number ) \
910  ( 0x80000000 >> (_bit_number) )
911
912/*
913 *  This routine translates the bit numbers returned by
914 *  _CPU_Bitfield_Find_first_bit() into something suitable for use as
915 *  a major or minor component of a priority.  See the discussion
916 *  for that routine.
917 */
918
919#define _CPU_Priority_bits_index( _priority ) \
920  (_priority)
921
922/* end of Priority handler macros */
923#endif /* ASM */
924
925/* functions */
926
927#ifndef ASM
928
929/*
930 *  _CPU_Initialize
931 *
932 *  This routine performs CPU dependent initialization.
933 */
934
935void _CPU_Initialize(void);
936
937/*
938 *  _CPU_ISR_install_vector
939 *
940 *  This routine installs an interrupt vector.
941 */
942
943void _CPU_ISR_install_vector(
944  uint32_t    vector,
945  proc_ptr    new_handler,
946  proc_ptr   *old_handler
947);
948
949/*
950 *  _CPU_Context_switch
951 *
952 *  This routine switches from the run context to the heir context.
953 */
954
955void _CPU_Context_switch(
956  Context_Control  *run,
957  Context_Control  *heir
958);
959
960/*
961 *  _CPU_Context_restore
962 *
963 *  This routine is generallu used only to restart self in an
964 *  efficient manner.  It may simply be a label in _CPU_Context_switch.
965 *
966 *  NOTE: May be unnecessary to reload some registers.
967 */
968
969void _CPU_Context_restore(
970  Context_Control *new_context
971) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
972
973/*
974 *  _CPU_Context_save_fp
975 *
976 *  This routine saves the floating point context passed to it.
977 */
978
979void _CPU_Context_save_fp(
980  Context_Control_fp **fp_context_ptr
981);
982
983/*
984 *  _CPU_Context_restore_fp
985 *
986 *  This routine restores the floating point context passed to it.
987 */
988
989void _CPU_Context_restore_fp(
990  Context_Control_fp **fp_context_ptr
991);
992
993typedef struct {
994  uint32_t EXC_SRR0;
995  uint32_t EXC_SRR1;
996  uint32_t _EXC_number;
997  uint32_t EXC_CR;
998  uint32_t EXC_CTR;
999  uint32_t EXC_XER;
1000  uint32_t EXC_LR;
1001  #ifdef __SPE__
1002    uint32_t EXC_SPEFSCR;
1003    uint64_t EXC_ACC;
1004  #endif
1005  PPC_GPR_TYPE GPR0;
1006  PPC_GPR_TYPE GPR1;
1007  PPC_GPR_TYPE GPR2;
1008  PPC_GPR_TYPE GPR3;
1009  PPC_GPR_TYPE GPR4;
1010  PPC_GPR_TYPE GPR5;
1011  PPC_GPR_TYPE GPR6;
1012  PPC_GPR_TYPE GPR7;
1013  PPC_GPR_TYPE GPR8;
1014  PPC_GPR_TYPE GPR9;
1015  PPC_GPR_TYPE GPR10;
1016  PPC_GPR_TYPE GPR11;
1017  PPC_GPR_TYPE GPR12;
1018  PPC_GPR_TYPE GPR13;
1019  PPC_GPR_TYPE GPR14;
1020  PPC_GPR_TYPE GPR15;
1021  PPC_GPR_TYPE GPR16;
1022  PPC_GPR_TYPE GPR17;
1023  PPC_GPR_TYPE GPR18;
1024  PPC_GPR_TYPE GPR19;
1025  PPC_GPR_TYPE GPR20;
1026  PPC_GPR_TYPE GPR21;
1027  PPC_GPR_TYPE GPR22;
1028  PPC_GPR_TYPE GPR23;
1029  PPC_GPR_TYPE GPR24;
1030  PPC_GPR_TYPE GPR25;
1031  PPC_GPR_TYPE GPR26;
1032  PPC_GPR_TYPE GPR27;
1033  PPC_GPR_TYPE GPR28;
1034  PPC_GPR_TYPE GPR29;
1035  PPC_GPR_TYPE GPR30;
1036  PPC_GPR_TYPE GPR31;
1037} CPU_Exception_frame;
1038
1039void _BSP_Exception_frame_print( const CPU_Exception_frame *frame );
1040
1041static inline void _CPU_Exception_frame_print(
1042  const CPU_Exception_frame *frame
1043)
1044{
1045  _BSP_Exception_frame_print( frame );
1046}
1047
1048/*
1049 * _CPU_Initialize_altivec()
1050 *
1051 * Global altivec-related initialization.
1052 */
1053void
1054_CPU_Initialize_altivec(void);
1055
1056/*
1057 * _CPU_Context_switch_altivec
1058 *
1059 * This routine switches the altivec contexts passed to it.
1060 */
1061
1062void
1063_CPU_Context_switch_altivec(
1064  Context_Control *from,
1065  Context_Control *to
1066);
1067
1068/*
1069 * _CPU_Context_restore_altivec
1070 *
1071 * This routine restores the altivec context passed to it.
1072 */
1073
1074void
1075_CPU_Context_restore_altivec(
1076  Context_Control *ctxt
1077);
1078
1079/*
1080 * _CPU_Context_initialize_altivec
1081 *
1082 * This routine initializes the altivec context passed to it.
1083 */
1084
1085void
1086_CPU_Context_initialize_altivec(
1087  Context_Control *ctxt
1088);
1089
1090void _CPU_Fatal_error(
1091  uint32_t   _error
1092);
1093
1094#endif /* ASM */
1095
1096#ifdef __cplusplus
1097}
1098#endif
1099
1100#endif /* _RTEMS_SCORE_CPU_H */
Note: See TracBrowser for help on using the repository browser.