source: rtems/cpukit/score/cpu/powerpc/rtems/new-exceptions/cpu.h @ 36e95a87

Last change on this file since 36e95a87 was 36e95a87, checked in by Joel Sherrill <joel.sherrill@…>, on 07/18/03 at 17:23:40

2003-07-18 Till Straumann <strauman@…>

PR 288/rtems

  • rtems/new-exceptions/cpu.h: _ISR_Nest_level is now properly maintained and does not reside in SPRG0.
  • Property mode set to 100644
File size: 30.8 KB
Line 
1/*  cpu.h
2 *
3 *  This include file contains information pertaining to the PowerPC
4 *  processor.
5 *
6 *  Modified for MPC8260 Andy Dachs <a.dachs@sstl.co.uk>
7 *  Surrey Satellite Technology Limited (SSTL), 2001
8 *
9 *  Author:     Andrew Bray <andy@i-cubed.co.uk>
10 *
11 *  COPYRIGHT (c) 1995 by i-cubed ltd.
12 *
13 *  To anyone who acknowledges that this file is provided "AS IS"
14 *  without any express or implied warranty:
15 *      permission to use, copy, modify, and distribute this file
16 *      for any purpose is hereby granted without fee, provided that
17 *      the above copyright notice and this notice appears in all
18 *      copies, and that the name of i-cubed limited not be used in
19 *      advertising or publicity pertaining to distribution of the
20 *      software without specific, written prior permission.
21 *      i-cubed limited makes no representations about the suitability
22 *      of this software for any purpose.
23 *
24 *  Derived from c/src/exec/cpu/no_cpu/cpu.h:
25 *
26 *  COPYRIGHT (c) 1989-1997.
27 *  On-Line Applications Research Corporation (OAR).
28 *
29 *  The license and distribution terms for this file may be found in
30 *  the file LICENSE in this distribution or at
31 *  http://www.OARcorp.com/rtems/license.html.
32 *
33 *  $Id$
34 */
35
36#ifndef __CPU_h
37#define __CPU_h
38
39#ifndef _rtems_score_cpu_h
40#error "You should include <rtems/score/cpu.h>"
41#endif
42
43#include <rtems/powerpc/registers.h>
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49/* conditional compilation parameters */
50
51/*
52 *  Does RTEMS manage a dedicated interrupt stack in software?
53 *
54 *  If TRUE, then a stack is allocated in _ISR_Handler_initialization.
55 *  If FALSE, nothing is done.
56 *
57 *  If the CPU supports a dedicated interrupt stack in hardware,
58 *  then it is generally the responsibility of the BSP to allocate it
59 *  and set it up.
60 *
61 *  If the CPU does not support a dedicated interrupt stack, then
62 *  the porter has two options: (1) execute interrupts on the
63 *  stack of the interrupted task, and (2) have RTEMS manage a dedicated
64 *  interrupt stack.
65 *
66 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
67 *
68 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
69 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
70 *  possible that both are FALSE for a particular CPU.  Although it
71 *  is unclear what that would imply about the interrupt processing
72 *  procedure on that CPU.
73 */
74
75#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
76
77/*
78 *  Does this CPU have hardware support for a dedicated interrupt stack?
79 *
80 *  If TRUE, then it must be installed during initialization.
81 *  If FALSE, then no installation is performed.
82 *
83 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
84 *
85 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
86 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
87 *  possible that both are FALSE for a particular CPU.  Although it
88 *  is unclear what that would imply about the interrupt processing
89 *  procedure on that CPU.
90 */
91
92#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
93
94/*
95 *  Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
96 *
97 *  If TRUE, then the memory is allocated during initialization.
98 *  If FALSE, then the memory is allocated during initialization.
99 *
100 *  This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE
101 *  or CPU_INSTALL_HARDWARE_INTERRUPT_STACK is TRUE.
102 */
103
104#define CPU_ALLOCATE_INTERRUPT_STACK FALSE
105
106/*
107 *  Does the RTEMS invoke the user's ISR with the vector number and
108 *  a pointer to the saved interrupt frame (1) or just the vector
109 *  number (0)?
110 */
111
112#define CPU_ISR_PASSES_FRAME_POINTER 0
113
114/*
115 *  Does the CPU have hardware floating point?
116 *
117 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
118 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
119 *
120 *  If there is a FP coprocessor such as the i387 or mc68881, then
121 *  the answer is TRUE.
122 *
123 *  The macro name "PPC_HAS_FPU" should be made CPU specific.
124 *  It indicates whether or not this CPU model has FP support.  For
125 *  example, it would be possible to have an i386_nofp CPU model
126 *  which set this to false to indicate that you have an i386 without
127 *  an i387 and wish to leave floating point support out of RTEMS.
128 */
129
130#if ( PPC_HAS_FPU == 1 )
131#define CPU_HARDWARE_FP     TRUE
132#else
133#define CPU_HARDWARE_FP     FALSE
134#endif
135
136/*
137 *  Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
138 *
139 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
140 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
141 *
142 *  So far, the only CPU in which this option has been used is the
143 *  HP PA-RISC.  The HP C compiler and gcc both implicitly use the
144 *  floating point registers to perform integer multiplies.  If
145 *  a function which you would not think utilize the FP unit DOES,
146 *  then one can not easily predict which tasks will use the FP hardware.
147 *  In this case, this option should be TRUE.
148 *
149 *  If CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
150 */
151
152#define CPU_ALL_TASKS_ARE_FP     FALSE
153
154/*
155 *  Should the IDLE task have a floating point context?
156 *
157 *  If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
158 *  and it has a floating point context which is switched in and out.
159 *  If FALSE, then the IDLE task does not have a floating point context.
160 *
161 *  Setting this to TRUE negatively impacts the time required to preempt
162 *  the IDLE task from an interrupt because the floating point context
163 *  must be saved as part of the preemption.
164 */
165
166#define CPU_IDLE_TASK_IS_FP      FALSE
167
168/*
169 *  Should the saving of the floating point registers be deferred
170 *  until a context switch is made to another different floating point
171 *  task?
172 *
173 *  If TRUE, then the floating point context will not be stored until
174 *  necessary.  It will remain in the floating point registers and not
175 *  disturned until another floating point task is switched to.
176 *
177 *  If FALSE, then the floating point context is saved when a floating
178 *  point task is switched out and restored when the next floating point
179 *  task is restored.  The state of the floating point registers between
180 *  those two operations is not specified.
181 *
182 *  If the floating point context does NOT have to be saved as part of
183 *  interrupt dispatching, then it should be safe to set this to TRUE.
184 *
185 *  Setting this flag to TRUE results in using a different algorithm
186 *  for deciding when to save and restore the floating point context.
187 *  The deferred FP switch algorithm minimizes the number of times
188 *  the FP context is saved and restored.  The FP context is not saved
189 *  until a context switch is made to another, different FP task.
190 *  Thus in a system with only one FP task, the FP context will never
191 *  be saved or restored.
192 *
193 *  Note, however that compilers may use floating point registers/
194 *  instructions for optimization or they may save/restore FP registers
195 *  on the stack. You must not use deferred switching in these cases
196 *  and on the PowerPC attempting to do so will raise a "FP unavailable"
197 *  exception.
198 */
199/*
200 *  ACB Note:  This could make debugging tricky..
201 */
202
203/* conservative setting (FALSE); probably doesn't affect performance too much */
204#define CPU_USE_DEFERRED_FP_SWITCH       FALSE
205
206/*
207 *  Does this port provide a CPU dependent IDLE task implementation?
208 *
209 *  If TRUE, then the routine _CPU_Thread_Idle_body
210 *  must be provided and is the default IDLE thread body instead of
211 *  _CPU_Thread_Idle_body.
212 *
213 *  If FALSE, then use the generic IDLE thread body if the BSP does
214 *  not provide one.
215 *
216 *  This is intended to allow for supporting processors which have
217 *  a low power or idle mode.  When the IDLE thread is executed, then
218 *  the CPU can be powered down.
219 *
220 *  The order of precedence for selecting the IDLE thread body is:
221 *
222 *    1.  BSP provided
223 *    2.  CPU dependent (if provided)
224 *    3.  generic (if no BSP and no CPU dependent)
225 */
226
227#define CPU_PROVIDES_IDLE_THREAD_BODY    FALSE
228
229
230/*
231 *  Does the stack grow up (toward higher addresses) or down
232 *  (toward lower addresses)?
233 *
234 *  If TRUE, then the grows upward.
235 *  If FALSE, then the grows toward smaller addresses.
236 */
237
238#define CPU_STACK_GROWS_UP               FALSE
239
240/*
241 *  The following is the variable attribute used to force alignment
242 *  of critical RTEMS structures.  On some processors it may make
243 *  sense to have these aligned on tighter boundaries than
244 *  the minimum requirements of the compiler in order to have as
245 *  much of the critical data area as possible in a cache line.
246 *
247 *  The placement of this macro in the declaration of the variables
248 *  is based on the syntactically requirements of the GNU C
249 *  "__attribute__" extension.  For example with GNU C, use
250 *  the following to force a structures to a 32 byte boundary.
251 *
252 *      __attribute__ ((aligned (32)))
253 *
254 *  NOTE:  Currently only the Priority Bit Map table uses this feature.
255 *         To benefit from using this, the data must be heavily
256 *         used so it will stay in the cache and used frequently enough
257 *         in the executive to justify turning this on.
258 */
259
260#define CPU_STRUCTURE_ALIGNMENT \
261  __attribute__ ((aligned (PPC_CACHE_ALIGNMENT)))
262
263/*
264 *  Define what is required to specify how the network to host conversion
265 *  routines are handled.
266 */
267
268#define CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES     FALSE
269#define CPU_BIG_ENDIAN                           TRUE
270#define CPU_LITTLE_ENDIAN                        FALSE
271
272
273/*
274 *  Processor defined structures
275 *
276 *  Examples structures include the descriptor tables from the i386
277 *  and the processor control structure on the i960ca.
278 */
279
280/* may need to put some structures here.  */
281
282/*
283 * Contexts
284 *
285 *  Generally there are 2 types of context to save.
286 *     1. Interrupt registers to save
287 *     2. Task level registers to save
288 *
289 *  This means we have the following 3 context items:
290 *     1. task level context stuff::  Context_Control
291 *     2. floating point task stuff:: Context_Control_fp
292 *     3. special interrupt level context :: Context_Control_interrupt
293 *
294 *  On some processors, it is cost-effective to save only the callee
295 *  preserved registers during a task context switch.  This means
296 *  that the ISR code needs to save those registers which do not
297 *  persist across function calls.  It is not mandatory to make this
298 *  distinctions between the caller/callee saves registers for the
299 *  purpose of minimizing context saved during task switch and on interrupts.
300 *  If the cost of saving extra registers is minimal, simplicity is the
301 *  choice.  Save the same context on interrupt entry as for tasks in
302 *  this case.
303 *
304 *  Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
305 *  care should be used in designing the context area.
306 *
307 *  On some CPUs with hardware floating point support, the Context_Control_fp
308 *  structure will not be used or it simply consist of an array of a
309 *  fixed number of bytes.   This is done when the floating point context
310 *  is dumped by a "FP save context" type instruction and the format
311 *  is not really defined by the CPU.  In this case, there is no need
312 *  to figure out the exact format -- only the size.  Of course, although
313 *  this is enough information for RTEMS, it is probably not enough for
314 *  a debugger such as gdb.  But that is another problem.
315 */
316
317#ifndef ASM
318
319typedef struct {
320    unsigned32 gpr1;    /* Stack pointer for all */
321    unsigned32 gpr2;    /* TOC in PowerOpen, reserved SVR4, section ptr EABI + */
322    unsigned32 gpr13;   /* First non volatile PowerOpen, section ptr SVR4/EABI */
323    unsigned32 gpr14;   /* Non volatile for all */
324    unsigned32 gpr15;   /* Non volatile for all */
325    unsigned32 gpr16;   /* Non volatile for all */
326    unsigned32 gpr17;   /* Non volatile for all */
327    unsigned32 gpr18;   /* Non volatile for all */
328    unsigned32 gpr19;   /* Non volatile for all */
329    unsigned32 gpr20;   /* Non volatile for all */
330    unsigned32 gpr21;   /* Non volatile for all */
331    unsigned32 gpr22;   /* Non volatile for all */
332    unsigned32 gpr23;   /* Non volatile for all */
333    unsigned32 gpr24;   /* Non volatile for all */
334    unsigned32 gpr25;   /* Non volatile for all */
335    unsigned32 gpr26;   /* Non volatile for all */
336    unsigned32 gpr27;   /* Non volatile for all */
337    unsigned32 gpr28;   /* Non volatile for all */
338    unsigned32 gpr29;   /* Non volatile for all */
339    unsigned32 gpr30;   /* Non volatile for all */
340    unsigned32 gpr31;   /* Non volatile for all */
341    unsigned32 cr;      /* PART of the CR is non volatile for all */
342    unsigned32 pc;      /* Program counter/Link register */
343    unsigned32 msr;     /* Initial interrupt level */
344} Context_Control;
345
346typedef struct {
347    /* The ABIs (PowerOpen/SVR4/EABI) only require saving f14-f31 over
348     * procedure calls.  However, this would mean that the interrupt
349     * frame had to hold f0-f13, and the fpscr.  And as the majority
350     * of tasks will not have an FP context, we will save the whole
351     * context here.
352     */
353#if (PPC_HAS_DOUBLE == 1)
354    double      f[32];
355    double      fpscr;
356#else
357    float       f[32];
358    float       fpscr;
359#endif
360} Context_Control_fp;
361
362typedef struct CPU_Interrupt_frame {
363    unsigned32 stacklink;       /* Ensure this is a real frame (also reg1 save) */
364    unsigned32 calleeLr;        /* link register used by callees: SVR4/EABI */
365  /* This is what is left out of the primary contexts */
366    unsigned32 gpr0;
367    unsigned32 gpr2;            /* play safe */
368    unsigned32 gpr3;
369    unsigned32 gpr4;
370    unsigned32 gpr5;
371    unsigned32 gpr6;
372    unsigned32 gpr7;
373    unsigned32 gpr8;
374    unsigned32 gpr9;
375    unsigned32 gpr10;
376    unsigned32 gpr11;
377    unsigned32 gpr12;
378    unsigned32 gpr13;   /* Play safe */
379    unsigned32 gpr28;   /* For internal use by the IRQ handler */
380    unsigned32 gpr29;   /* For internal use by the IRQ handler */
381    unsigned32 gpr30;   /* For internal use by the IRQ handler */
382    unsigned32 gpr31;   /* For internal use by the IRQ handler */
383    unsigned32 cr;      /* Bits of this are volatile, so no-one may save */
384    unsigned32 ctr;
385    unsigned32 xer;
386    unsigned32 lr;
387    unsigned32 pc;
388    unsigned32 msr;
389    unsigned32 pad[3];
390} CPU_Interrupt_frame;
391 
392/*
393 *  The following table contains the information required to configure
394 *  the PowerPC processor specific parameters.
395 */
396
397typedef struct {
398  void       (*pretasking_hook)( void );
399  void       (*predriver_hook)( void );
400  void       (*postdriver_hook)( void );
401  void       (*idle_task)( void );
402  boolean      do_zero_of_workspace;
403  unsigned32   idle_task_stack_size;
404  unsigned32   interrupt_stack_size;
405  unsigned32   extra_mpci_receive_server_stack;
406  void *     (*stack_allocate_hook)( unsigned32 );
407  void       (*stack_free_hook)( void* );
408  /* end of fields required on all CPUs */
409
410  unsigned32   clicks_per_usec;        /* Timer clicks per microsecond */
411  boolean      exceptions_in_RAM;     /* TRUE if in RAM */
412
413#if (defined(ppc403) || defined(mpc860) || defined(mpc821) || defined(mpc8260))
414  unsigned32   serial_per_sec;         /* Serial clocks per second */
415  boolean      serial_external_clock;
416  boolean      serial_xon_xoff;
417  boolean      serial_cts_rts;
418  unsigned32   serial_rate;
419  unsigned32   timer_average_overhead; /* Average overhead of timer in ticks */
420  unsigned32   timer_least_valid;      /* Least valid number from timer      */
421  boolean      timer_internal_clock;   /* TRUE, when timer runs with CPU clk */
422#endif
423
424#if (defined(mpc860) || defined(mpc821) || defined(mpc8260))
425  unsigned32   clock_speed;            /* Speed of CPU in Hz */
426#endif
427}   rtems_cpu_table;
428
429/*
430 *  Macros to access required entires in the CPU Table are in
431 *  the file rtems/system.h.
432 */
433
434/*
435 *  Macros to access PowerPC MPC750 specific additions to the CPU Table
436 */
437
438#define rtems_cpu_configuration_get_clicks_per_usec() \
439   (_CPU_Table.clicks_per_usec)
440
441#define rtems_cpu_configuration_get_exceptions_in_ram() \
442   (_CPU_Table.exceptions_in_RAM)
443
444/*
445 *  This variable is optional.  It is used on CPUs on which it is difficult
446 *  to generate an "uninitialized" FP context.  It is filled in by
447 *  _CPU_Initialize and copied into the task's FP context area during
448 *  _CPU_Context_Initialize.
449 */
450
451/* EXTERN Context_Control_fp  _CPU_Null_fp_context; */
452
453/*
454 *  On some CPUs, RTEMS supports a software managed interrupt stack.
455 *  This stack is allocated by the Interrupt Manager and the switch
456 *  is performed in _ISR_Handler.  These variables contain pointers
457 *  to the lowest and highest addresses in the chunk of memory allocated
458 *  for the interrupt stack.  Since it is unknown whether the stack
459 *  grows up or down (in general), this give the CPU dependent
460 *  code the option of picking the version it wants to use.
461 *
462 *  NOTE: These two variables are required if the macro
463 *        CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
464 */
465
466SCORE_EXTERN void               *_CPU_Interrupt_stack_low;
467SCORE_EXTERN void               *_CPU_Interrupt_stack_high;
468
469#endif /* ndef ASM */
470
471/*
472 *  This defines the number of levels and the mask used to pick those
473 *  bits out of a thread mode.
474 */
475
476#define CPU_MODES_INTERRUPT_LEVEL  0x00000001 /* interrupt level in mode */
477#define CPU_MODES_INTERRUPT_MASK   0x00000001 /* interrupt level in mode */
478
479/*
480 *  With some compilation systems, it is difficult if not impossible to
481 *  call a high-level language routine from assembly language.  This
482 *  is especially true of commercial Ada compilers and name mangling
483 *  C++ ones.  This variable can be optionally defined by the CPU porter
484 *  and contains the address of the routine _Thread_Dispatch.  This
485 *  can make it easier to invoke that routine at the end of the interrupt
486 *  sequence (if a dispatch is necessary).
487 */
488
489/* EXTERN void           (*_CPU_Thread_dispatch_pointer)(); */
490
491/*
492 *  Nothing prevents the porter from declaring more CPU specific variables.
493 */
494
495#ifndef ASM
496 
497SCORE_EXTERN struct {
498  unsigned32 *Disable_level;
499  void *Stack;
500  volatile boolean *Switch_necessary;
501  boolean *Signal;
502
503} _CPU_IRQ_info CPU_STRUCTURE_ALIGNMENT;
504
505#endif /* ndef ASM */
506
507/*
508 *  The size of the floating point context area.  On some CPUs this
509 *  will not be a "sizeof" because the format of the floating point
510 *  area is not defined -- only the size is.  This is usually on
511 *  CPUs with a "floating point save context" instruction.
512 */
513
514#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
515
516/*
517 * (Optional) # of bytes for libmisc/stackchk to check
518 * If not specifed, then it defaults to something reasonable
519 * for most architectures.
520 */
521
522#define CPU_STACK_CHECK_SIZE    (128)
523
524/*
525 *  Amount of extra stack (above minimum stack size) required by
526 *  MPCI receive server thread.  Remember that in a multiprocessor
527 *  system this thread must exist and be able to process all directives.
528 */
529
530#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
531
532/*
533 *  This defines the number of entries in the ISR_Vector_table managed
534 *  by RTEMS.
535 */
536
537#define CPU_INTERRUPT_NUMBER_OF_VECTORS     (PPC_INTERRUPT_MAX)
538#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (PPC_INTERRUPT_MAX - 1)
539
540/*
541 *  This is defined if the port has a special way to report the ISR nesting
542 *  level.  Most ports maintain the variable _ISR_Nest_level. Note that
543 *  this is not an option - RTEMS/score _relies_ on _ISR_Nest_level
544 *  being maintained (e.g. watchdog queues).
545 */
546
547#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
548
549/*
550 *  Should be large enough to run all RTEMS tests.  This insures
551 *  that a "reasonable" small application should not have any problems.
552 */
553
554#define CPU_STACK_MINIMUM_SIZE          (1024*8)
555
556/*
557 *  CPU's worst alignment requirement for data types on a byte boundary.  This
558 *  alignment does not take into account the requirements for the stack.
559 */
560
561#define CPU_ALIGNMENT              (PPC_ALIGNMENT)
562
563/*
564 *  This number corresponds to the byte alignment requirement for the
565 *  heap handler.  This alignment requirement may be stricter than that
566 *  for the data types alignment specified by CPU_ALIGNMENT.  It is
567 *  common for the heap to follow the same alignment requirement as
568 *  CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
569 *  then this should be set to CPU_ALIGNMENT.
570 *
571 *  NOTE:  This does not have to be a power of 2.  It does have to
572 *         be greater or equal to than CPU_ALIGNMENT.
573 */
574
575#define CPU_HEAP_ALIGNMENT         (PPC_ALIGNMENT)
576
577/*
578 *  This number corresponds to the byte alignment requirement for memory
579 *  buffers allocated by the partition manager.  This alignment requirement
580 *  may be stricter than that for the data types alignment specified by
581 *  CPU_ALIGNMENT.  It is common for the partition to follow the same
582 *  alignment requirement as CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict
583 *  enough for the partition, then this should be set to CPU_ALIGNMENT.
584 *
585 *  NOTE:  This does not have to be a power of 2.  It does have to
586 *         be greater or equal to than CPU_ALIGNMENT.
587 */
588
589#define CPU_PARTITION_ALIGNMENT    (PPC_ALIGNMENT)
590
591/*
592 *  This number corresponds to the byte alignment requirement for the
593 *  stack.  This alignment requirement may be stricter than that for the
594 *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
595 *  is strict enough for the stack, then this should be set to 0.
596 *
597 *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
598 */
599
600#define CPU_STACK_ALIGNMENT        (PPC_STACK_ALIGNMENT)
601
602/*
603 * Needed for Interrupt stack
604 */
605#define CPU_MINIMUM_STACK_FRAME_SIZE 8
606
607
608/*
609 *  ISR handler macros
610 */
611
612#define _CPU_Initialize_vectors()
613
614/*
615 *  Disable all interrupts for an RTEMS critical section.  The previous
616 *  level is returned in _isr_cookie.
617 */
618
619#ifndef ASM
620 
621static inline unsigned32 _CPU_ISR_Get_level( void )
622{
623  register unsigned int msr;
624  _CPU_MSR_GET(msr);
625  if (msr & MSR_EE) return 0;
626  else  return 1;
627}
628
629static inline void _CPU_ISR_Set_level( unsigned32 level )
630{
631  register unsigned int msr;
632  _CPU_MSR_GET(msr);
633  if (!(level & CPU_MODES_INTERRUPT_MASK)) {
634    msr |= MSR_EE;
635  }
636  else {
637    msr &= ~MSR_EE;
638  }
639  _CPU_MSR_SET(msr);
640}
641 
642void BSP_panic(char *);
643#define _CPU_ISR_install_vector(irq, new, old) \
644   {BSP_panic("_CPU_ISR_install_vector called\n");}
645
646/* Context handler macros */
647
648/*
649 *  Initialize the context to a state suitable for starting a
650 *  task after a context restore operation.  Generally, this
651 *  involves:
652 *
653 *     - setting a starting address
654 *     - preparing the stack
655 *     - preparing the stack and frame pointers
656 *     - setting the proper interrupt level in the context
657 *     - initializing the floating point context
658 *
659 *  This routine generally does not set any unnecessary register
660 *  in the context.  The state of the "general data" registers is
661 *  undefined at task start time.
662 *
663 *  NOTE:  Implemented as a subroutine for the SPARC port.
664 */
665
666void _CPU_Context_Initialize(
667  Context_Control  *the_context,
668  unsigned32       *stack_base,
669  unsigned32        size,
670  unsigned32        new_level,
671  void             *entry_point,
672  boolean           is_fp
673);
674
675/*
676 *  This routine is responsible for somehow restarting the currently
677 *  executing task.  If you are lucky, then all that is necessary
678 *  is restoring the context.  Otherwise, there will need to be
679 *  a special assembly routine which does something special in this
680 *  case.  Context_Restore should work most of the time.  It will
681 *  not work if restarting self conflicts with the stack frame
682 *  assumptions of restoring a context.
683 */
684
685#define _CPU_Context_Restart_self( _the_context ) \
686   _CPU_Context_restore( (_the_context) );
687
688/*
689 *  The purpose of this macro is to allow the initial pointer into
690 *  a floating point context area (used to save the floating point
691 *  context) to be at an arbitrary place in the floating point
692 *  context area.
693 *
694 *  This is necessary because some FP units are designed to have
695 *  their context saved as a stack which grows into lower addresses.
696 *  Other FP units can be saved by simply moving registers into offsets
697 *  from the base of the context area.  Finally some FP units provide
698 *  a "dump context" instruction which could fill in from high to low
699 *  or low to high based on the whim of the CPU designers.
700 */
701
702#define _CPU_Context_Fp_start( _base, _offset ) \
703   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
704
705/*
706 *  This routine initializes the FP context area passed to it to.
707 *  There are a few standard ways in which to initialize the
708 *  floating point context.  The code included for this macro assumes
709 *  that this is a CPU in which a "initial" FP context was saved into
710 *  _CPU_Null_fp_context and it simply copies it to the destination
711 *  context passed to it.
712 *
713 *  Other models include (1) not doing anything, and (2) putting
714 *  a "null FP status word" in the correct place in the FP context.
715 */
716
717#define _CPU_Context_Initialize_fp( _destination ) \
718  { \
719   ((Context_Control_fp *) *((void **) _destination))->fpscr = PPC_INIT_FPSCR; \
720  }
721
722/* end of Context handler macros */
723
724/* Fatal Error manager macros */
725
726/*
727 *  This routine copies _error into a known place -- typically a stack
728 *  location or a register, optionally disables interrupts, and
729 *  halts/stops the CPU.
730 */
731
732void _BSP_Fatal_error(unsigned int);
733
734#define _CPU_Fatal_halt( _error ) \
735  _BSP_Fatal_error(_error)
736
737/* end of Fatal Error manager macros */
738
739/* Bitfield handler macros */
740
741/*
742 *  This routine sets _output to the bit number of the first bit
743 *  set in _value.  _value is of CPU dependent type Priority_Bit_map_control.
744 *  This type may be either 16 or 32 bits wide although only the 16
745 *  least significant bits will be used.
746 *
747 *  There are a number of variables in using a "find first bit" type
748 *  instruction.
749 *
750 *    (1) What happens when run on a value of zero?
751 *    (2) Bits may be numbered from MSB to LSB or vice-versa.
752 *    (3) The numbering may be zero or one based.
753 *    (4) The "find first bit" instruction may search from MSB or LSB.
754 *
755 *  RTEMS guarantees that (1) will never happen so it is not a concern.
756 *  (2),(3), (4) are handled by the macros _CPU_Priority_mask() and
757 *  _CPU_Priority_Bits_index().  These three form a set of routines
758 *  which must logically operate together.  Bits in the _value are
759 *  set and cleared based on masks built by _CPU_Priority_mask().
760 *  The basic major and minor values calculated by _Priority_Major()
761 *  and _Priority_Minor() are "massaged" by _CPU_Priority_Bits_index()
762 *  to properly range between the values returned by the "find first bit"
763 *  instruction.  This makes it possible for _Priority_Get_highest() to
764 *  calculate the major and directly index into the minor table.
765 *  This mapping is necessary to ensure that 0 (a high priority major/minor)
766 *  is the first bit found.
767 *
768 *  This entire "find first bit" and mapping process depends heavily
769 *  on the manner in which a priority is broken into a major and minor
770 *  components with the major being the 4 MSB of a priority and minor
771 *  the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
772 *  priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
773 *  to the lowest priority.
774 *
775 *  If your CPU does not have a "find first bit" instruction, then
776 *  there are ways to make do without it.  Here are a handful of ways
777 *  to implement this in software:
778 *
779 *    - a series of 16 bit test instructions
780 *    - a "binary search using if's"
781 *    - _number = 0
782 *      if _value > 0x00ff
783 *        _value >>=8
784 *        _number = 8;
785 *
786 *      if _value > 0x0000f
787 *        _value >=8
788 *        _number += 4
789 *
790 *      _number += bit_set_table[ _value ]
791 *
792 *    where bit_set_table[ 16 ] has values which indicate the first
793 *      bit set
794 */
795
796#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
797  { \
798    asm volatile ("cntlzw %0, %1" : "=r" ((_output)), "=r" ((_value)) : \
799                  "1" ((_value))); \
800  }
801
802/* end of Bitfield handler macros */
803
804/*
805 *  This routine builds the mask which corresponds to the bit fields
806 *  as searched by _CPU_Bitfield_Find_first_bit().  See the discussion
807 *  for that routine.
808 */
809
810#define _CPU_Priority_Mask( _bit_number ) \
811  ( 0x80000000 >> (_bit_number) )
812
813/*
814 *  This routine translates the bit numbers returned by
815 *  _CPU_Bitfield_Find_first_bit() into something suitable for use as
816 *  a major or minor component of a priority.  See the discussion
817 *  for that routine.
818 */
819
820#define _CPU_Priority_bits_index( _priority ) \
821  (_priority)
822
823/* end of Priority handler macros */
824
825/* variables */
826
827extern const unsigned32 _CPU_msrs[4];
828
829/* functions */
830
831/*
832 *  _CPU_Initialize
833 *
834 *  This routine performs CPU dependent initialization.
835 *
836 *  Until all new-exception processing BSPs have fixed
837 *  PR288, we let the good BSPs pass
838 *
839 *  PPC_BSP_HAS_FIXED_PR288
840 *
841 *  in SPRG0 and let _CPU_Initialize assert this.
842 */
843
844#define PPC_BSP_HAS_FIXED_PR288 0x600dbabe
845
846void _CPU_Initialize(
847  rtems_cpu_table  *cpu_table,
848  void            (*thread_dispatch)
849);
850
851
852/*
853 *  _CPU_Install_interrupt_stack
854 *
855 *  This routine installs the hardware interrupt stack pointer.
856 *
857 *  NOTE:  It need only be provided if CPU_HAS_HARDWARE_INTERRUPT_STACK
858 *         is TRUE.
859 */
860
861void _CPU_Install_interrupt_stack( void );
862
863/*
864 *  _CPU_Context_switch
865 *
866 *  This routine switches from the run context to the heir context.
867 */
868
869void _CPU_Context_switch(
870  Context_Control  *run,
871  Context_Control  *heir
872);
873
874/*
875 *  _CPU_Context_restore
876 *
877 *  This routine is generallu used only to restart self in an
878 *  efficient manner.  It may simply be a label in _CPU_Context_switch.
879 *
880 *  NOTE: May be unnecessary to reload some registers.
881 */
882
883void _CPU_Context_restore(
884  Context_Control *new_context
885);
886
887/*
888 *  _CPU_Context_save_fp
889 *
890 *  This routine saves the floating point context passed to it.
891 */
892
893void _CPU_Context_save_fp(
894  void **fp_context_ptr
895);
896
897/*
898 *  _CPU_Context_restore_fp
899 *
900 *  This routine restores the floating point context passed to it.
901 */
902
903void _CPU_Context_restore_fp(
904  void **fp_context_ptr
905);
906
907void _CPU_Fatal_error(
908  unsigned32 _error
909);
910
911/*  The following routine swaps the endian format of an unsigned int.
912 *  It must be static because it is referenced indirectly.
913 *
914 *  This version will work on any processor, but if there is a better
915 *  way for your CPU PLEASE use it.  The most common way to do this is to:
916 *
917 *     swap least significant two bytes with 16-bit rotate
918 *     swap upper and lower 16-bits
919 *     swap most significant two bytes with 16-bit rotate
920 *
921 *  Some CPUs have special instructions which swap a 32-bit quantity in
922 *  a single instruction (e.g. i486).  It is probably best to avoid
923 *  an "endian swapping control bit" in the CPU.  One good reason is
924 *  that interrupts would probably have to be disabled to insure that
925 *  an interrupt does not try to access the same "chunk" with the wrong
926 *  endian.  Another good reason is that on some CPUs, the endian bit
927 *  endianness for ALL fetches -- both code and data -- so the code
928 *  will be fetched incorrectly.
929 */
930 
931static inline unsigned int CPU_swap_u32(
932  unsigned int value
933)
934{
935  unsigned32 swapped;
936 
937  asm volatile("rlwimi %0,%1,8,24,31;"
938               "rlwimi %0,%1,24,16,23;"
939               "rlwimi %0,%1,8,8,15;"
940               "rlwimi %0,%1,24,0,7;" :
941               "=&r" ((swapped)) : "r" ((value)));
942
943  return( swapped );
944}
945
946#define CPU_swap_u16( value ) \
947  (((value&0xff) << 8) | ((value >> 8)&0xff))
948
949#endif /* ndef ASM */
950
951#ifdef __cplusplus
952}
953#endif
954
955#endif
Note: See TracBrowser for help on using the repository browser.