source: rtems/cpukit/score/cpu/powerpc/rtems/score/cpu.h @ 721fe34

4.115
Last change on this file since 721fe34 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 33.8 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-2011 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 ASM
253
254typedef struct {
255  #ifndef __SPE__
256    uint32_t   gpr1;    /* Stack pointer for all */
257    uint32_t   gpr2;    /* Reserved SVR4, section ptr EABI + */
258    uint32_t   gpr13;   /* Section ptr SVR4/EABI */
259    uint32_t   gpr14;   /* Non volatile for all */
260    uint32_t   gpr15;   /* Non volatile for all */
261    uint32_t   gpr16;   /* Non volatile for all */
262    uint32_t   gpr17;   /* Non volatile for all */
263    uint32_t   gpr18;   /* Non volatile for all */
264    uint32_t   gpr19;   /* Non volatile for all */
265    uint32_t   gpr20;   /* Non volatile for all */
266    uint32_t   gpr21;   /* Non volatile for all */
267    uint32_t   gpr22;   /* Non volatile for all */
268    uint32_t   gpr23;   /* Non volatile for all */
269    uint32_t   gpr24;   /* Non volatile for all */
270    uint32_t   gpr25;   /* Non volatile for all */
271    uint32_t   gpr26;   /* Non volatile for all */
272    uint32_t   gpr27;   /* Non volatile for all */
273    uint32_t   gpr28;   /* Non volatile for all */
274    uint32_t   gpr29;   /* Non volatile for all */
275    uint32_t   gpr30;   /* Non volatile for all */
276    uint32_t   gpr31;   /* Non volatile for all */
277    uint32_t   cr;      /* PART of the CR is non volatile for all */
278    uint32_t   pc;      /* Program counter/Link register */
279    uint32_t   msr;     /* Initial interrupt level */
280    #ifdef __ALTIVEC__
281      /*
282       * 12 non-volatile vector registers, cache-aligned area for vscr/vrsave
283       * and padding to ensure cache-alignment.  Unfortunately, we can't verify
284       * the cache line size here in the cpukit but altivec support code will
285       * produce an error if this is ever different from 32 bytes.
286       *
287       * Note: it is the BSP/CPU-support's responsibility to save/restore
288       *       volatile vregs across interrupts and exceptions.
289       */
290      uint8_t altivec[16*12 + 32 + 32];
291    #endif
292  #else
293    /* Non-volatile context according to E500ABIUG and EABI */
294    uint32_t context [
295      8 /* Cache line padding */
296      + 1 /* Stack pointer */
297      + 1 /* MSR */
298      + 1 /* LR */
299      + 1 /* CR */
300      + 18 * 2 /* GPR 14 to GPR 31 */
301    ];
302  #endif
303} Context_Control;
304#endif /* ASM */
305
306#ifndef __SPE__
307  #define PPC_CONTEXT_SET_SP( _context, _sp ) \
308    do { \
309      (_context)->gpr1 = _sp; \
310    } while (0)
311
312  #define PPC_CONTEXT_GET_CR( _context ) \
313    (_context)->cr
314
315  #define PPC_CONTEXT_GET_MSR( _context ) \
316    (_context)->msr
317
318  #define PPC_CONTEXT_SET_MSR( _context, _msr ) \
319    do { \
320      (_context)->msr = _msr; \
321    } while (0)
322
323  #define PPC_CONTEXT_FIRST_SAVED_GPR 13
324
325  #define PPC_CONTEXT_GET_FIRST_SAVED( _context ) \
326    (_context)->gpr13
327
328  #define PPC_CONTEXT_GET_PC( _context ) \
329    (_context)->pc
330
331  #define PPC_CONTEXT_SET_PC( _context, _pc ) \
332    do { \
333      (_context)->pc = _pc; \
334    } while (0)
335
336  #define _CPU_Context_Get_SP( _context ) \
337    (_context)->gpr1
338#else
339  #define PPC_CONTEXT_CACHE_LINE_0 32
340  #define PPC_CONTEXT_OFFSET_SP 32
341  #define PPC_CONTEXT_OFFSET_MSR 36
342  #define PPC_CONTEXT_OFFSET_LR 40
343  #define PPC_CONTEXT_OFFSET_CR 44
344  #define PPC_CONTEXT_OFFSET_GPR14 48
345  #define PPC_CONTEXT_OFFSET_GPR15 56
346  #define PPC_CONTEXT_CACHE_LINE_1 64
347  #define PPC_CONTEXT_OFFSET_GPR16 64
348  #define PPC_CONTEXT_OFFSET_GPR17 72
349  #define PPC_CONTEXT_OFFSET_GPR18 80
350  #define PPC_CONTEXT_OFFSET_GPR19 88
351  #define PPC_CONTEXT_CACHE_LINE_2 96
352  #define PPC_CONTEXT_OFFSET_GPR20 96
353  #define PPC_CONTEXT_OFFSET_GPR21 104
354  #define PPC_CONTEXT_OFFSET_GPR22 112
355  #define PPC_CONTEXT_OFFSET_GPR23 120
356  #define PPC_CONTEXT_CACHE_LINE_3 128
357  #define PPC_CONTEXT_OFFSET_GPR24 128
358  #define PPC_CONTEXT_OFFSET_GPR25 136
359  #define PPC_CONTEXT_OFFSET_GPR26 144
360  #define PPC_CONTEXT_OFFSET_GPR27 152
361  #define PPC_CONTEXT_CACHE_LINE_4 160
362  #define PPC_CONTEXT_OFFSET_GPR28 160
363  #define PPC_CONTEXT_OFFSET_GPR29 168
364  #define PPC_CONTEXT_OFFSET_GPR30 176
365  #define PPC_CONTEXT_OFFSET_GPR31 184
366
367  #define PPC_CONTEXT_AREA( _context ) \
368    ((uint32_t *) (((uintptr_t) (_context)) & ~0x1fU))
369
370  #define PPC_CONTEXT_FIELD( _context, _offset ) \
371    PPC_CONTEXT_AREA( _context ) [(_offset) / 4]
372
373  #define PPC_CONTEXT_SET_SP( _context, _sp ) \
374    do { \
375      PPC_CONTEXT_FIELD( _context, PPC_CONTEXT_OFFSET_SP ) = _sp; \
376    } while (0)
377
378  #define PPC_CONTEXT_GET_CR( _context ) \
379    PPC_CONTEXT_FIELD( _context, PPC_CONTEXT_OFFSET_CR )
380
381  #define PPC_CONTEXT_GET_MSR( _context ) \
382    PPC_CONTEXT_FIELD( _context, PPC_CONTEXT_OFFSET_MSR )
383
384  #define PPC_CONTEXT_SET_MSR( _context, _msr ) \
385    do { \
386      PPC_CONTEXT_FIELD( _context, PPC_CONTEXT_OFFSET_MSR ) = _msr; \
387    } while (0)
388
389  #define PPC_CONTEXT_FIRST_SAVED_GPR 14
390
391  #define PPC_CONTEXT_GET_FIRST_SAVED( _context ) \
392    PPC_CONTEXT_FIELD( _context, PPC_CONTEXT_OFFSET_GPR14 )
393
394  #define PPC_CONTEXT_GET_PC( _context ) \
395    PPC_CONTEXT_FIELD( _context, PPC_CONTEXT_OFFSET_LR )
396
397  #define PPC_CONTEXT_SET_PC( _context, _pc ) \
398    do { \
399      PPC_CONTEXT_FIELD( _context, PPC_CONTEXT_OFFSET_LR ) = _pc; \
400    } while (0)
401
402  #define _CPU_Context_Get_SP( _context ) \
403    PPC_CONTEXT_FIELD( _context, PPC_CONTEXT_OFFSET_SP )
404#endif
405
406#ifndef ASM
407typedef struct {
408    /* The ABIs (PowerOpen/SVR4/EABI) only require saving f14-f31 over
409     * procedure calls.  However, this would mean that the interrupt
410     * frame had to hold f0-f13, and the fpscr.  And as the majority
411     * of tasks will not have an FP context, we will save the whole
412     * context here.
413     */
414#if (PPC_HAS_DOUBLE == 1)
415    double      f[32];
416    uint64_t    fpscr;
417#else
418    float       f[32];
419    uint32_t    fpscr;
420#endif
421} Context_Control_fp;
422
423typedef struct CPU_Interrupt_frame {
424    uint32_t   stacklink;       /* Ensure this is a real frame (also reg1 save) */
425    uint32_t   calleeLr;        /* link register used by callees: SVR4/EABI */
426
427    /* This is what is left out of the primary contexts */
428    uint32_t   gpr0;
429    uint32_t   gpr2;            /* play safe */
430    uint32_t   gpr3;
431    uint32_t   gpr4;
432    uint32_t   gpr5;
433    uint32_t   gpr6;
434    uint32_t   gpr7;
435    uint32_t   gpr8;
436    uint32_t   gpr9;
437    uint32_t   gpr10;
438    uint32_t   gpr11;
439    uint32_t   gpr12;
440    uint32_t   gpr13;   /* Play safe */
441    uint32_t   gpr28;   /* For internal use by the IRQ handler */
442    uint32_t   gpr29;   /* For internal use by the IRQ handler */
443    uint32_t   gpr30;   /* For internal use by the IRQ handler */
444    uint32_t   gpr31;   /* For internal use by the IRQ handler */
445    uint32_t   cr;      /* Bits of this are volatile, so no-one may save */
446    uint32_t   ctr;
447    uint32_t   xer;
448    uint32_t   lr;
449    uint32_t   pc;
450    uint32_t   msr;
451    uint32_t   pad[3];
452} CPU_Interrupt_frame;
453
454#endif /* ASM */
455
456/*
457 *  Does RTEMS manage a dedicated interrupt stack in software?
458 *
459 *  If TRUE, then a stack is allocated in _ISR_Handler_initialization.
460 *  If FALSE, nothing is done.
461 *
462 *  If the CPU supports a dedicated interrupt stack in hardware,
463 *  then it is generally the responsibility of the BSP to allocate it
464 *  and set it up.
465 *
466 *  If the CPU does not support a dedicated interrupt stack, then
467 *  the porter has two options: (1) execute interrupts on the
468 *  stack of the interrupted task, and (2) have RTEMS manage a dedicated
469 *  interrupt stack.
470 *
471 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
472 *
473 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
474 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
475 *  possible that both are FALSE for a particular CPU.  Although it
476 *  is unclear what that would imply about the interrupt processing
477 *  procedure on that CPU.
478 */
479
480#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
481
482/*
483 *  Does this CPU have hardware support for a dedicated interrupt stack?
484 *
485 *  If TRUE, then it must be installed during initialization.
486 *  If FALSE, then no installation is performed.
487 *
488 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
489 *
490 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
491 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
492 *  possible that both are FALSE for a particular CPU.  Although it
493 *  is unclear what that would imply about the interrupt processing
494 *  procedure on that CPU.
495 */
496
497#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
498
499/*
500 *  Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
501 *
502 *  If TRUE, then the memory is allocated during initialization.
503 *  If FALSE, then the memory is allocated during initialization.
504 *
505 *  This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
506 */
507
508#define CPU_ALLOCATE_INTERRUPT_STACK FALSE
509
510/*
511 *  Does the RTEMS invoke the user's ISR with the vector number and
512 *  a pointer to the saved interrupt frame (1) or just the vector
513 *  number (0)?
514 */
515
516#define CPU_ISR_PASSES_FRAME_POINTER 0
517
518/*
519 *  Should the saving of the floating point registers be deferred
520 *  until a context switch is made to another different floating point
521 *  task?
522 *
523 *  If TRUE, then the floating point context will not be stored until
524 *  necessary.  It will remain in the floating point registers and not
525 *  disturned until another floating point task is switched to.
526 *
527 *  If FALSE, then the floating point context is saved when a floating
528 *  point task is switched out and restored when the next floating point
529 *  task is restored.  The state of the floating point registers between
530 *  those two operations is not specified.
531 *
532 *  If the floating point context does NOT have to be saved as part of
533 *  interrupt dispatching, then it should be safe to set this to TRUE.
534 *
535 *  Setting this flag to TRUE results in using a different algorithm
536 *  for deciding when to save and restore the floating point context.
537 *  The deferred FP switch algorithm minimizes the number of times
538 *  the FP context is saved and restored.  The FP context is not saved
539 *  until a context switch is made to another, different FP task.
540 *  Thus in a system with only one FP task, the FP context will never
541 *  be saved or restored.
542 *
543 *  Note, however that compilers may use floating point registers/
544 *  instructions for optimization or they may save/restore FP registers
545 *  on the stack. You must not use deferred switching in these cases
546 *  and on the PowerPC attempting to do so will raise a "FP unavailable"
547 *  exception.
548 */
549/*
550 *  ACB Note:  This could make debugging tricky..
551 */
552
553/* conservative setting (FALSE); probably doesn't affect performance too much */
554#define CPU_USE_DEFERRED_FP_SWITCH       FALSE
555
556/*
557 *  Processor defined structures required for cpukit/score.
558 */
559
560#ifndef ASM
561
562/*
563 *  This variable is optional.  It is used on CPUs on which it is difficult
564 *  to generate an "uninitialized" FP context.  It is filled in by
565 *  _CPU_Initialize and copied into the task's FP context area during
566 *  _CPU_Context_Initialize.
567 */
568
569/* EXTERN Context_Control_fp  _CPU_Null_fp_context; */
570
571#endif /* ndef ASM */
572
573/*
574 *  This defines the number of levels and the mask used to pick those
575 *  bits out of a thread mode.
576 */
577
578#define CPU_MODES_INTERRUPT_LEVEL  0x00000001 /* interrupt level in mode */
579#define CPU_MODES_INTERRUPT_MASK   0x00000001 /* interrupt level in mode */
580
581/*
582 *  Nothing prevents the porter from declaring more CPU specific variables.
583 */
584
585#ifndef ASM
586
587SCORE_EXTERN struct {
588  uint32_t      *Disable_level;
589  void          *Stack;
590  volatile bool *Switch_necessary;
591  bool          *Signal;
592
593} _CPU_IRQ_info CPU_STRUCTURE_ALIGNMENT;
594
595#endif /* ndef ASM */
596
597/*
598 *  The size of the floating point context area.  On some CPUs this
599 *  will not be a "sizeof" because the format of the floating point
600 *  area is not defined -- only the size is.  This is usually on
601 *  CPUs with a "floating point save context" instruction.
602 */
603
604#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
605
606/*
607 * (Optional) # of bytes for libmisc/stackchk to check
608 * If not specifed, then it defaults to something reasonable
609 * for most architectures.
610 */
611
612#define CPU_STACK_CHECK_SIZE    (128)
613
614/*
615 *  Amount of extra stack (above minimum stack size) required by
616 *  MPCI receive server thread.  Remember that in a multiprocessor
617 *  system this thread must exist and be able to process all directives.
618 */
619
620#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
621
622/*
623 *  This defines the number of entries in the ISR_Vector_table managed
624 *  by RTEMS.
625 *
626 *  NOTE: CPU_INTERRUPT_NUMBER_OF_VECTORS and
627 *        CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER are only used on
628 *        Simple Vectored Architectures and thus are not defined
629 *        for this architecture.
630 */
631
632/*
633 *  This is defined if the port has a special way to report the ISR nesting
634 *  level.  Most ports maintain the variable _ISR_Nest_level. Note that
635 *  this is not an option - RTEMS/score _relies_ on _ISR_Nest_level
636 *  being maintained (e.g. watchdog queues).
637 */
638
639#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
640
641/*
642 *  ISR handler macros
643 */
644
645#define _CPU_Initialize_vectors()
646
647/*
648 *  Disable all interrupts for an RTEMS critical section.  The previous
649 *  level is returned in _isr_cookie.
650 */
651
652#ifndef ASM
653
654static inline uint32_t   _CPU_ISR_Get_level( void )
655{
656  register unsigned int msr;
657  _CPU_MSR_GET(msr);
658  if (msr & MSR_EE) return 0;
659  else  return 1;
660}
661
662static inline void _CPU_ISR_Set_level( uint32_t   level )
663{
664  register unsigned int msr;
665  _CPU_MSR_GET(msr);
666  if (!(level & CPU_MODES_INTERRUPT_MASK)) {
667    msr |= ppc_interrupt_get_disable_mask();
668  }
669  else {
670    msr &= ~ppc_interrupt_get_disable_mask();
671  }
672  _CPU_MSR_SET(msr);
673}
674
675void BSP_panic(char *);
676
677/* Fatal Error manager macros */
678
679/*
680 *  This routine copies _error into a known place -- typically a stack
681 *  location or a register, optionally disables interrupts, and
682 *  halts/stops the CPU.
683 */
684
685void _BSP_Fatal_error(unsigned int);
686
687#endif /* ASM */
688
689#define _CPU_Fatal_halt( _error ) \
690  _BSP_Fatal_error(_error)
691
692/* end of Fatal Error manager macros */
693
694/*
695 * SPRG0 was previously used to make sure that the BSP fixed the PR288 bug.
696 * Now SPRG0 is devoted to the interrupt disable mask.
697 */
698
699#define PPC_BSP_HAS_FIXED_PR288 ppc_this_is_now_the_interrupt_disable_mask
700
701/*
702 *  Should be large enough to run all RTEMS tests.  This ensures
703 *  that a "reasonable" small application should not have any problems.
704 */
705
706#define CPU_STACK_MINIMUM_SIZE          (1024*8)
707
708/*
709 *  CPU's worst alignment requirement for data types on a byte boundary.  This
710 *  alignment does not take into account the requirements for the stack.
711 */
712
713#define CPU_ALIGNMENT              (PPC_ALIGNMENT)
714
715/*
716 *  This number corresponds to the byte alignment requirement for the
717 *  heap handler.  This alignment requirement may be stricter than that
718 *  for the data types alignment specified by CPU_ALIGNMENT.  It is
719 *  common for the heap to follow the same alignment requirement as
720 *  CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
721 *  then this should be set to CPU_ALIGNMENT.
722 *
723 *  NOTE:  This does not have to be a power of 2.  It does have to
724 *         be greater or equal to than CPU_ALIGNMENT.
725 */
726
727#define CPU_HEAP_ALIGNMENT         (PPC_ALIGNMENT)
728
729/*
730 *  This number corresponds to the byte alignment requirement for memory
731 *  buffers allocated by the partition manager.  This alignment requirement
732 *  may be stricter than that for the data types alignment specified by
733 *  CPU_ALIGNMENT.  It is common for the partition to follow the same
734 *  alignment requirement as CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict
735 *  enough for the partition, then this should be set to CPU_ALIGNMENT.
736 *
737 *  NOTE:  This does not have to be a power of 2.  It does have to
738 *         be greater or equal to than CPU_ALIGNMENT.
739 */
740
741#define CPU_PARTITION_ALIGNMENT    (PPC_ALIGNMENT)
742
743/*
744 *  This number corresponds to the byte alignment requirement for the
745 *  stack.  This alignment requirement may be stricter than that for the
746 *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
747 *  is strict enough for the stack, then this should be set to 0.
748 *
749 *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
750 */
751
752#define CPU_STACK_ALIGNMENT        (PPC_STACK_ALIGNMENT)
753
754#ifndef ASM
755/*  The following routine swaps the endian format of an unsigned int.
756 *  It must be static because it is referenced indirectly.
757 *
758 *  This version will work on any processor, but if there is a better
759 *  way for your CPU PLEASE use it.  The most common way to do this is to:
760 *
761 *     swap least significant two bytes with 16-bit rotate
762 *     swap upper and lower 16-bits
763 *     swap most significant two bytes with 16-bit rotate
764 *
765 *  Some CPUs have special instructions which swap a 32-bit quantity in
766 *  a single instruction (e.g. i486).  It is probably best to avoid
767 *  an "endian swapping control bit" in the CPU.  One good reason is
768 *  that interrupts would probably have to be disabled to ensure that
769 *  an interrupt does not try to access the same "chunk" with the wrong
770 *  endian.  Another good reason is that on some CPUs, the endian bit
771 *  endianness for ALL fetches -- both code and data -- so the code
772 *  will be fetched incorrectly.
773 */
774
775static inline uint32_t CPU_swap_u32(
776  uint32_t value
777)
778{
779  uint32_t   swapped;
780
781  __asm__ volatile("rlwimi %0,%1,8,24,31;"
782               "rlwimi %0,%1,24,16,23;"
783               "rlwimi %0,%1,8,8,15;"
784               "rlwimi %0,%1,24,0,7;" :
785               "=&r" ((swapped)) : "r" ((value)));
786
787  return( swapped );
788}
789
790#define CPU_swap_u16( value ) \
791  (((value&0xff) << 8) | ((value >> 8)&0xff))
792
793#endif /* ASM */
794
795
796#ifndef ASM
797/* Context handler macros */
798
799/*
800 *  Initialize the context to a state suitable for starting a
801 *  task after a context restore operation.  Generally, this
802 *  involves:
803 *
804 *     - setting a starting address
805 *     - preparing the stack
806 *     - preparing the stack and frame pointers
807 *     - setting the proper interrupt level in the context
808 *     - initializing the floating point context
809 *
810 *  This routine generally does not set any unnecessary register
811 *  in the context.  The state of the "general data" registers is
812 *  undefined at task start time.
813 */
814
815void _CPU_Context_Initialize(
816  Context_Control  *the_context,
817  uint32_t         *stack_base,
818  uint32_t          size,
819  uint32_t          new_level,
820  void             *entry_point,
821  bool              is_fp
822);
823
824/*
825 *  This routine is responsible for somehow restarting the currently
826 *  executing task.  If you are lucky, then all that is necessary
827 *  is restoring the context.  Otherwise, there will need to be
828 *  a special assembly routine which does something special in this
829 *  case.  Context_Restore should work most of the time.  It will
830 *  not work if restarting self conflicts with the stack frame
831 *  assumptions of restoring a context.
832 */
833
834#define _CPU_Context_Restart_self( _the_context ) \
835   _CPU_Context_restore( (_the_context) );
836
837/*
838 *  The purpose of this macro is to allow the initial pointer into
839 *  a floating point context area (used to save the floating point
840 *  context) to be at an arbitrary place in the floating point
841 *  context area.
842 *
843 *  This is necessary because some FP units are designed to have
844 *  their context saved as a stack which grows into lower addresses.
845 *  Other FP units can be saved by simply moving registers into offsets
846 *  from the base of the context area.  Finally some FP units provide
847 *  a "dump context" instruction which could fill in from high to low
848 *  or low to high based on the whim of the CPU designers.
849 */
850
851#define _CPU_Context_Fp_start( _base, _offset ) \
852   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
853
854/*
855 *  This routine initializes the FP context area passed to it to.
856 *  There are a few standard ways in which to initialize the
857 *  floating point context.  The code included for this macro assumes
858 *  that this is a CPU in which a "initial" FP context was saved into
859 *  _CPU_Null_fp_context and it simply copies it to the destination
860 *  context passed to it.
861 *
862 *  Other models include (1) not doing anything, and (2) putting
863 *  a "null FP status word" in the correct place in the FP context.
864 */
865
866#define _CPU_Context_Initialize_fp( _destination ) \
867  memset( *(_destination), 0, sizeof( **(_destination) ) )
868
869/* end of Context handler macros */
870#endif /* ASM */
871
872#ifndef ASM
873/* Bitfield handler macros */
874
875/*
876 *  This routine sets _output to the bit number of the first bit
877 *  set in _value.  _value is of CPU dependent type Priority_bit_map_Control.
878 *  This type may be either 16 or 32 bits wide although only the 16
879 *  least significant bits will be used.
880 *
881 *  There are a number of variables in using a "find first bit" type
882 *  instruction.
883 *
884 *    (1) What happens when run on a value of zero?
885 *    (2) Bits may be numbered from MSB to LSB or vice-versa.
886 *    (3) The numbering may be zero or one based.
887 *    (4) The "find first bit" instruction may search from MSB or LSB.
888 *
889 *  RTEMS guarantees that (1) will never happen so it is not a concern.
890 *  (2),(3), (4) are handled by the macros _CPU_Priority_mask() and
891 *  _CPU_Priority_Bits_index().  These three form a set of routines
892 *  which must logically operate together.  Bits in the _value are
893 *  set and cleared based on masks built by _CPU_Priority_mask().
894 *  The basic major and minor values calculated by _Priority_Major()
895 *  and _Priority_Minor() are "massaged" by _CPU_Priority_Bits_index()
896 *  to properly range between the values returned by the "find first bit"
897 *  instruction.  This makes it possible for _Priority_Get_highest() to
898 *  calculate the major and directly index into the minor table.
899 *  This mapping is necessary to ensure that 0 (a high priority major/minor)
900 *  is the first bit found.
901 *
902 *  This entire "find first bit" and mapping process depends heavily
903 *  on the manner in which a priority is broken into a major and minor
904 *  components with the major being the 4 MSB of a priority and minor
905 *  the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
906 *  priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
907 *  to the lowest priority.
908 *
909 *  If your CPU does not have a "find first bit" instruction, then
910 *  there are ways to make do without it.  Here are a handful of ways
911 *  to implement this in software:
912 *
913 *    - a series of 16 bit test instructions
914 *    - a "binary search using if's"
915 *    - _number = 0
916 *      if _value > 0x00ff
917 *        _value >>=8
918 *        _number = 8;
919 *
920 *      if _value > 0x0000f
921 *        _value >=8
922 *        _number += 4
923 *
924 *      _number += bit_set_table[ _value ]
925 *
926 *    where bit_set_table[ 16 ] has values which indicate the first
927 *      bit set
928 */
929
930#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
931  { \
932    __asm__ volatile ("cntlzw %0, %1" : "=r" ((_output)), "=r" ((_value)) : \
933                  "1" ((_value))); \
934  }
935
936/* end of Bitfield handler macros */
937
938/*
939 *  This routine builds the mask which corresponds to the bit fields
940 *  as searched by _CPU_Bitfield_Find_first_bit().  See the discussion
941 *  for that routine.
942 */
943
944#define _CPU_Priority_Mask( _bit_number ) \
945  ( 0x80000000 >> (_bit_number) )
946
947/*
948 *  This routine translates the bit numbers returned by
949 *  _CPU_Bitfield_Find_first_bit() into something suitable for use as
950 *  a major or minor component of a priority.  See the discussion
951 *  for that routine.
952 */
953
954#define _CPU_Priority_bits_index( _priority ) \
955  (_priority)
956
957/* end of Priority handler macros */
958#endif /* ASM */
959
960/* functions */
961
962#ifndef ASM
963
964/*
965 *  _CPU_Initialize
966 *
967 *  This routine performs CPU dependent initialization.
968 */
969
970void _CPU_Initialize(void);
971
972/*
973 *  _CPU_ISR_install_vector
974 *
975 *  This routine installs an interrupt vector.
976 */
977
978void _CPU_ISR_install_vector(
979  uint32_t    vector,
980  proc_ptr    new_handler,
981  proc_ptr   *old_handler
982);
983
984/*
985 *  _CPU_Install_interrupt_stack
986 *
987 *  This routine installs the hardware interrupt stack pointer.
988 *
989 *  NOTE:  It need only be provided if CPU_HAS_HARDWARE_INTERRUPT_STACK
990 *         is TRUE.
991 */
992
993void _CPU_Install_interrupt_stack( void );
994
995/*
996 *  _CPU_Context_switch
997 *
998 *  This routine switches from the run context to the heir context.
999 */
1000
1001void _CPU_Context_switch(
1002  Context_Control  *run,
1003  Context_Control  *heir
1004);
1005
1006/*
1007 *  _CPU_Context_restore
1008 *
1009 *  This routine is generallu used only to restart self in an
1010 *  efficient manner.  It may simply be a label in _CPU_Context_switch.
1011 *
1012 *  NOTE: May be unnecessary to reload some registers.
1013 */
1014
1015void _CPU_Context_restore(
1016  Context_Control *new_context
1017) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
1018
1019/*
1020 *  _CPU_Context_save_fp
1021 *
1022 *  This routine saves the floating point context passed to it.
1023 */
1024
1025void _CPU_Context_save_fp(
1026  Context_Control_fp **fp_context_ptr
1027);
1028
1029/*
1030 *  _CPU_Context_restore_fp
1031 *
1032 *  This routine restores the floating point context passed to it.
1033 */
1034
1035void _CPU_Context_restore_fp(
1036  Context_Control_fp **fp_context_ptr
1037);
1038
1039/*
1040 * _CPU_Initialize_altivec()
1041 *
1042 * Global altivec-related initialization.
1043 */
1044void
1045_CPU_Initialize_altivec(void);
1046
1047/*
1048 * _CPU_Context_switch_altivec
1049 *
1050 * This routine switches the altivec contexts passed to it.
1051 */
1052
1053void
1054_CPU_Context_switch_altivec(
1055  Context_Control *from,
1056  Context_Control *to
1057);
1058
1059/*
1060 * _CPU_Context_restore_altivec
1061 *
1062 * This routine restores the altivec context passed to it.
1063 */
1064
1065void
1066_CPU_Context_restore_altivec(
1067  Context_Control *ctxt
1068);
1069
1070/*
1071 * _CPU_Context_initialize_altivec
1072 *
1073 * This routine initializes the altivec context passed to it.
1074 */
1075
1076void
1077_CPU_Context_initialize_altivec(
1078  Context_Control *ctxt
1079);
1080
1081void _CPU_Fatal_error(
1082  uint32_t   _error
1083);
1084
1085#endif /* ASM */
1086
1087#ifdef __cplusplus
1088}
1089#endif
1090
1091#endif /* _RTEMS_SCORE_CPU_H */
Note: See TracBrowser for help on using the repository browser.