source: rtems/cpukit/score/cpu/powerpc/rtems/new-exceptions/cpu.h @ 1aa101b

4.104.114.84.95
Last change on this file since 1aa101b was 1aa101b, checked in by Joel Sherrill <joel.sherrill@…>, on 09/26/03 at 21:56:51

2003-09-26 Joel Sherrill <joel@…>

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