source: rtems/cpukit/score/cpu/powerpc/rtems/score/cpu.h @ 0ca6d0d9

4.104.114.95
Last change on this file since 0ca6d0d9 was 0ca6d0d9, checked in by Joel Sherrill <joel.sherrill@…>, on 12/17/07 at 22:35:25

2007-12-17 Joel Sherrill <joel.sherrill@…>

  • rtems/score/cpu.h: Add _CPU_Context_Get_SP() for stack check utility.
  • Property mode set to 100644
File size: 23.9 KB
Line 
1/**
2 * @file rtems/score/cpu.h
3 */
4
5/*
6 *  COPYRIGHT (c) 1989-2007.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.com/license/LICENSE.
12 *
13 * $Id$
14 */
15 
16#ifndef _RTEMS_SCORE_CPU_H
17#define _RTEMS_SCORE_CPU_H
18
19#include <rtems/score/powerpc.h>              /* pick up machine definitions */
20#ifndef ASM
21#include <rtems/score/types.h>
22#endif
23
24/* conditional compilation parameters */
25
26/*
27 *  Should the calls to _Thread_Enable_dispatch be inlined?
28 *
29 *  If TRUE, then they are inlined.
30 *  If FALSE, then a subroutine call is made.
31 *
32 *  Basically this is an example of the classic trade-off of size
33 *  versus speed.  Inlining the call (TRUE) typically increases the
34 *  size of RTEMS while speeding up the enabling of dispatching.
35 *  [NOTE: In general, the _Thread_Dispatch_disable_level will
36 *  only be 0 or 1 unless you are in an interrupt handler and that
37 *  interrupt handler invokes the executive.]  When not inlined
38 *  something calls _Thread_Enable_dispatch which in turns calls
39 *  _Thread_Dispatch.  If the enable dispatch is inlined, then
40 *  one subroutine call is avoided entirely.]
41 */
42
43#define CPU_INLINE_ENABLE_DISPATCH       FALSE
44
45/*
46 *  Should the body of the search loops in _Thread_queue_Enqueue_priority
47 *  be unrolled one time?  In unrolled each iteration of the loop examines
48 *  two "nodes" on the chain being searched.  Otherwise, only one node
49 *  is examined per iteration.
50 *
51 *  If TRUE, then the loops are unrolled.
52 *  If FALSE, then the loops are not unrolled.
53 *
54 *  The primary factor in making this decision is the cost of disabling
55 *  and enabling interrupts (_ISR_Flash) versus the cost of rest of the
56 *  body of the loop.  On some CPUs, the flash is more expensive than
57 *  one iteration of the loop body.  In this case, it might be desirable
58 *  to unroll the loop.  It is important to note that on some CPUs, this
59 *  code is the longest interrupt disable period in RTEMS.  So it is
60 *  necessary to strike a balance when setting this parameter.
61 */
62
63#define CPU_UNROLL_ENQUEUE_PRIORITY      FALSE
64
65/*
66 *  Does this port provide a CPU dependent IDLE task implementation?
67 *
68 *  If TRUE, then the routine _CPU_Thread_Idle_body
69 *  must be provided and is the default IDLE thread body instead of
70 *  _CPU_Thread_Idle_body.
71 *
72 *  If FALSE, then use the generic IDLE thread body if the BSP does
73 *  not provide one.
74 *
75 *  This is intended to allow for supporting processors which have
76 *  a low power or idle mode.  When the IDLE thread is executed, then
77 *  the CPU can be powered down.
78 *
79 *  The order of precedence for selecting the IDLE thread body is:
80 *
81 *    1.  BSP provided
82 *    2.  CPU dependent (if provided)
83 *    3.  generic (if no BSP and no CPU dependent)
84 */
85
86#define CPU_PROVIDES_IDLE_THREAD_BODY    FALSE
87
88/*
89 *  Does the stack grow up (toward higher addresses) or down
90 *  (toward lower addresses)?
91 *
92 *  If TRUE, then the grows upward.
93 *  If FALSE, then the grows toward smaller addresses.
94 */
95
96#define CPU_STACK_GROWS_UP               FALSE
97
98/*
99 *  The following is the variable attribute used to force alignment
100 *  of critical RTEMS structures.  On some processors it may make
101 *  sense to have these aligned on tighter boundaries than
102 *  the minimum requirements of the compiler in order to have as
103 *  much of the critical data area as possible in a cache line.
104 *
105 *  The placement of this macro in the declaration of the variables
106 *  is based on the syntactically requirements of the GNU C
107 *  "__attribute__" extension.  For example with GNU C, use
108 *  the following to force a structures to a 32 byte boundary.
109 *
110 *      __attribute__ ((aligned (32)))
111 *
112 *  NOTE:  Currently only the Priority Bit Map table uses this feature.
113 *         To benefit from using this, the data must be heavily
114 *         used so it will stay in the cache and used frequently enough
115 *         in the executive to justify turning this on.
116 */
117
118#define CPU_STRUCTURE_ALIGNMENT \
119  __attribute__ ((aligned (PPC_CACHE_ALIGNMENT)))
120
121/*
122 *  Define what is required to specify how the network to host conversion
123 *  routines are handled.
124 */
125
126#if defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
127#define CPU_BIG_ENDIAN                           TRUE
128#define CPU_LITTLE_ENDIAN                        FALSE
129#else
130#define CPU_BIG_ENDIAN                           FALSE
131#define CPU_LITTLE_ENDIAN                        TRUE
132#endif
133
134/*
135 *  Does the CPU have hardware floating point?
136 *
137 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
138 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
139 *
140 *  If there is a FP coprocessor such as the i387 or mc68881, then
141 *  the answer is TRUE.
142 *
143 *  The macro name "PPC_HAS_FPU" should be made CPU specific.
144 *  It indicates whether or not this CPU model has FP support.  For
145 *  example, it would be possible to have an i386_nofp CPU model
146 *  which set this to false to indicate that you have an i386 without
147 *  an i387 and wish to leave floating point support out of RTEMS.
148 */
149
150#if ( PPC_HAS_FPU == 1 )
151#define CPU_HARDWARE_FP     TRUE
152#define CPU_SOFTWARE_FP     FALSE
153#else
154#define CPU_HARDWARE_FP     FALSE
155#define CPU_SOFTWARE_FP     FALSE
156#endif
157
158/*
159 *  Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
160 *
161 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
162 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
163 *
164 *  If CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
165 *
166 *  PowerPC Note: It appears the GCC can implicitly generate FPU
167 *  and Altivec instructions when you least expect them.  So make
168 *  all tasks floating point.
169 */
170
171#define CPU_ALL_TASKS_ARE_FP CPU_HARDWARE_FP
172
173/*
174 *  Should the IDLE task have a floating point context?
175 *
176 *  If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
177 *  and it has a floating point context which is switched in and out.
178 *  If FALSE, then the IDLE task does not have a floating point context.
179 *
180 *  Setting this to TRUE negatively impacts the time required to preempt
181 *  the IDLE task from an interrupt because the floating point context
182 *  must be saved as part of the preemption.
183 */
184
185#define CPU_IDLE_TASK_IS_FP      FALSE
186
187/*
188 *  Processor defined structures required for cpukit/score.
189 */
190
191/*
192 * Contexts
193 *
194 *  Generally there are 2 types of context to save.
195 *     1. Interrupt registers to save
196 *     2. Task level registers to save
197 *
198 *  This means we have the following 3 context items:
199 *     1. task level context stuff::  Context_Control
200 *     2. floating point task stuff:: Context_Control_fp
201 *     3. special interrupt level context :: Context_Control_interrupt
202 *
203 *  On some processors, it is cost-effective to save only the callee
204 *  preserved registers during a task context switch.  This means
205 *  that the ISR code needs to save those registers which do not
206 *  persist across function calls.  It is not mandatory to make this
207 *  distinctions between the caller/callee saves registers for the
208 *  purpose of minimizing context saved during task switch and on interrupts.
209 *  If the cost of saving extra registers is minimal, simplicity is the
210 *  choice.  Save the same context on interrupt entry as for tasks in
211 *  this case.
212 *
213 *  Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
214 *  care should be used in designing the context area.
215 *
216 *  On some CPUs with hardware floating point support, the Context_Control_fp
217 *  structure will not be used or it simply consist of an array of a
218 *  fixed number of bytes.   This is done when the floating point context
219 *  is dumped by a "FP save context" type instruction and the format
220 *  is not really defined by the CPU.  In this case, there is no need
221 *  to figure out the exact format -- only the size.  Of course, although
222 *  this is enough information for RTEMS, it is probably not enough for
223 *  a debugger such as gdb.  But that is another problem.
224 */
225
226#ifndef ASM
227typedef struct {
228    uint32_t   gpr1;    /* Stack pointer for all */
229    uint32_t   gpr2;    /* Reserved SVR4, section ptr EABI + */
230    uint32_t   gpr13;   /* Section ptr SVR4/EABI */
231    uint32_t   gpr14;   /* Non volatile for all */
232    uint32_t   gpr15;   /* Non volatile for all */
233    uint32_t   gpr16;   /* Non volatile for all */
234    uint32_t   gpr17;   /* Non volatile for all */
235    uint32_t   gpr18;   /* Non volatile for all */
236    uint32_t   gpr19;   /* Non volatile for all */
237    uint32_t   gpr20;   /* Non volatile for all */
238    uint32_t   gpr21;   /* Non volatile for all */
239    uint32_t   gpr22;   /* Non volatile for all */
240    uint32_t   gpr23;   /* Non volatile for all */
241    uint32_t   gpr24;   /* Non volatile for all */
242    uint32_t   gpr25;   /* Non volatile for all */
243    uint32_t   gpr26;   /* Non volatile for all */
244    uint32_t   gpr27;   /* Non volatile for all */
245    uint32_t   gpr28;   /* Non volatile for all */
246    uint32_t   gpr29;   /* Non volatile for all */
247    uint32_t   gpr30;   /* Non volatile for all */
248    uint32_t   gpr31;   /* Non volatile for all */
249    uint32_t   cr;      /* PART of the CR is non volatile for all */
250    uint32_t   pc;      /* Program counter/Link register */
251    uint32_t   msr;     /* Initial interrupt level */
252} Context_Control;
253
254#define _CPU_Context_Get_SP( _context ) \
255  (_context)->gpr1
256
257typedef struct {
258    /* The ABIs (PowerOpen/SVR4/EABI) only require saving f14-f31 over
259     * procedure calls.  However, this would mean that the interrupt
260     * frame had to hold f0-f13, and the fpscr.  And as the majority
261     * of tasks will not have an FP context, we will save the whole
262     * context here.
263     */
264#if (PPC_HAS_DOUBLE == 1)
265    double      f[32];
266    double      fpscr;
267#else
268    float       f[32];
269    float       fpscr;
270#endif
271} Context_Control_fp;
272#endif /* ASM */
273
274#ifndef ASM
275typedef struct CPU_Interrupt_frame {
276    uint32_t   stacklink;       /* Ensure this is a real frame (also reg1 save) */
277    uint32_t   calleeLr;        /* link register used by callees: SVR4/EABI */
278
279    /* This is what is left out of the primary contexts */
280    uint32_t   gpr0;
281    uint32_t   gpr2;            /* play safe */
282    uint32_t   gpr3;
283    uint32_t   gpr4;
284    uint32_t   gpr5;
285    uint32_t   gpr6;
286    uint32_t   gpr7;
287    uint32_t   gpr8;
288    uint32_t   gpr9;
289    uint32_t   gpr10;
290    uint32_t   gpr11;
291    uint32_t   gpr12;
292    uint32_t   gpr13;   /* Play safe */
293    uint32_t   gpr28;   /* For internal use by the IRQ handler */
294    uint32_t   gpr29;   /* For internal use by the IRQ handler */
295    uint32_t   gpr30;   /* For internal use by the IRQ handler */
296    uint32_t   gpr31;   /* For internal use by the IRQ handler */
297    uint32_t   cr;      /* Bits of this are volatile, so no-one may save */
298    uint32_t   ctr;
299    uint32_t   xer;
300    uint32_t   lr;
301    uint32_t   pc;
302    uint32_t   msr;
303    uint32_t   pad[3];
304} CPU_Interrupt_frame;
305#endif /* ASM */
306
307#ifdef _OLD_EXCEPTIONS
308#include <rtems/old-exceptions/cpu.h>
309#else
310#include <rtems/new-exceptions/cpu.h>
311#endif
312
313/*
314 *  Should be large enough to run all RTEMS tests.  This ensures
315 *  that a "reasonable" small application should not have any problems.
316 */
317
318#define CPU_STACK_MINIMUM_SIZE          (1024*8)
319
320/*
321 *  CPU's worst alignment requirement for data types on a byte boundary.  This
322 *  alignment does not take into account the requirements for the stack.
323 */
324
325#define CPU_ALIGNMENT              (PPC_ALIGNMENT)
326
327/*
328 *  This number corresponds to the byte alignment requirement for the
329 *  heap handler.  This alignment requirement may be stricter than that
330 *  for the data types alignment specified by CPU_ALIGNMENT.  It is
331 *  common for the heap to follow the same alignment requirement as
332 *  CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
333 *  then this should be set to CPU_ALIGNMENT.
334 *
335 *  NOTE:  This does not have to be a power of 2.  It does have to
336 *         be greater or equal to than CPU_ALIGNMENT.
337 */
338
339#define CPU_HEAP_ALIGNMENT         (PPC_ALIGNMENT)
340
341/*
342 *  This number corresponds to the byte alignment requirement for memory
343 *  buffers allocated by the partition manager.  This alignment requirement
344 *  may be stricter than that for the data types alignment specified by
345 *  CPU_ALIGNMENT.  It is common for the partition to follow the same
346 *  alignment requirement as CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict
347 *  enough for the partition, then this should be set to CPU_ALIGNMENT.
348 *
349 *  NOTE:  This does not have to be a power of 2.  It does have to
350 *         be greater or equal to than CPU_ALIGNMENT.
351 */
352
353#define CPU_PARTITION_ALIGNMENT    (PPC_ALIGNMENT)
354
355/*
356 *  This number corresponds to the byte alignment requirement for the
357 *  stack.  This alignment requirement may be stricter than that for the
358 *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
359 *  is strict enough for the stack, then this should be set to 0.
360 *
361 *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
362 */
363
364#define CPU_STACK_ALIGNMENT        (PPC_STACK_ALIGNMENT)
365
366#ifndef ASM
367/*  The following routine swaps the endian format of an unsigned int.
368 *  It must be static because it is referenced indirectly.
369 *
370 *  This version will work on any processor, but if there is a better
371 *  way for your CPU PLEASE use it.  The most common way to do this is to:
372 *
373 *     swap least significant two bytes with 16-bit rotate
374 *     swap upper and lower 16-bits
375 *     swap most significant two bytes with 16-bit rotate
376 *
377 *  Some CPUs have special instructions which swap a 32-bit quantity in
378 *  a single instruction (e.g. i486).  It is probably best to avoid
379 *  an "endian swapping control bit" in the CPU.  One good reason is
380 *  that interrupts would probably have to be disabled to ensure that
381 *  an interrupt does not try to access the same "chunk" with the wrong
382 *  endian.  Another good reason is that on some CPUs, the endian bit
383 *  endianness for ALL fetches -- both code and data -- so the code
384 *  will be fetched incorrectly.
385 */
386 
387static inline uint32_t CPU_swap_u32(
388  uint32_t value
389)
390{
391  uint32_t   swapped;
392 
393  asm volatile("rlwimi %0,%1,8,24,31;"
394               "rlwimi %0,%1,24,16,23;"
395               "rlwimi %0,%1,8,8,15;"
396               "rlwimi %0,%1,24,0,7;" :
397               "=&r" ((swapped)) : "r" ((value)));
398
399  return( swapped );
400}
401
402#define CPU_swap_u16( value ) \
403  (((value&0xff) << 8) | ((value >> 8)&0xff))
404
405#endif /* ASM */
406
407#ifndef ASM
408/*
409 *  Simple spin delay in microsecond units for device drivers.
410 *  This is very dependent on the clock speed of the target.
411 */
412
413#if 0
414/* Wonderful bookE doesn't have mftb/mftbu; they only
415 * define the TBRU/TBRL SPRs so we use these. Luckily,
416 * we run in supervisory mode so that should work on
417 * all CPUs. In user mode we'd have a problem...
418 * 2007/11/30, T.S.
419 *
420 * OTOH, PSIM currently lacks support for reading
421 * SPRs 268/269. You need GDB patch sim/2376 to avoid
422 * a crash...
423 */
424#define CPU_Get_timebase_low( _value ) \
425    asm volatile( "mftb  %0" : "=r" (_value) )
426#else
427#define CPU_Get_timebase_low( _value ) \
428    asm volatile( "mfspr %0,268" : "=r" (_value) )
429#endif
430
431#define rtems_bsp_delay( _microseconds ) \
432  do { \
433    uint32_t   start, ticks, now; \
434    extern     uint32_t bsp_clicks_per_usec; \
435    CPU_Get_timebase_low( start ) ; \
436    ticks = (_microseconds) * bsp_clicks_per_usec; \
437    do \
438      CPU_Get_timebase_low( now ) ; \
439    while (now - start < ticks); \
440  } while (0)
441
442#define rtems_bsp_delay_in_bus_cycles( _cycles ) \
443  do { \
444    uint32_t   start, now; \
445    CPU_Get_timebase_low( start ); \
446    do \
447      CPU_Get_timebase_low( now ); \
448    while (now - start < (_cycles)); \
449  } while (0)
450
451#endif /* ASM */
452
453#ifndef ASM
454/*
455 *  Routines to access the decrementer register
456 */
457
458#define PPC_Set_decrementer( _clicks ) \
459  do { \
460    asm volatile( "mtdec %0" : : "r" ((_clicks)) ); \
461  } while (0)
462
463#define PPC_Get_decrementer( _clicks ) \
464    asm volatile( "mfdec  %0" : "=r" (_clicks) )
465
466#endif /* ASM */
467
468#ifndef ASM
469/*
470 *  Routines to access the time base register
471 */
472
473static inline uint64_t PPC_Get_timebase_register( void )
474{
475  uint32_t tbr_low;
476  uint32_t tbr_high;
477  uint32_t tbr_high_old;
478  uint64_t tbr;
479
480  do {
481#if 0
482/* See comment above (CPU_Get_timebase_low) */
483    asm volatile( "mftbu %0" : "=r" (tbr_high_old));
484    asm volatile( "mftb  %0" : "=r" (tbr_low));
485    asm volatile( "mftbu %0" : "=r" (tbr_high));
486#else
487    asm volatile( "mfspr %0, 269" : "=r" (tbr_high_old));
488    asm volatile( "mfspr %0, 268" : "=r" (tbr_low));
489    asm volatile( "mfspr %0, 269" : "=r" (tbr_high));
490#endif
491  } while ( tbr_high_old != tbr_high );
492
493  tbr = tbr_high;
494  tbr <<= 32;
495  tbr |= tbr_low;
496  return tbr;
497}
498
499static inline  void PPC_Set_timebase_register (uint64_t tbr)
500{
501  uint32_t tbr_low;
502  uint32_t tbr_high;
503
504  tbr_low = (tbr & 0xffffffff) ;
505  tbr_high = (tbr >> 32) & 0xffffffff;
506  asm volatile( "mtspr 284, %0" : : "r" (tbr_low));
507  asm volatile( "mtspr 285, %0" : : "r" (tbr_high));
508 
509}
510#endif /* ASM */
511
512#ifndef ASM
513/* Context handler macros */
514
515/*
516 *  Initialize the context to a state suitable for starting a
517 *  task after a context restore operation.  Generally, this
518 *  involves:
519 *
520 *     - setting a starting address
521 *     - preparing the stack
522 *     - preparing the stack and frame pointers
523 *     - setting the proper interrupt level in the context
524 *     - initializing the floating point context
525 *
526 *  This routine generally does not set any unnecessary register
527 *  in the context.  The state of the "general data" registers is
528 *  undefined at task start time.
529 */
530
531void _CPU_Context_Initialize(
532  Context_Control  *the_context,
533  uint32_t         *stack_base,
534  uint32_t          size,
535  uint32_t          new_level,
536  void             *entry_point,
537  boolean           is_fp
538);
539
540/*
541 *  This routine is responsible for somehow restarting the currently
542 *  executing task.  If you are lucky, then all that is necessary
543 *  is restoring the context.  Otherwise, there will need to be
544 *  a special assembly routine which does something special in this
545 *  case.  Context_Restore should work most of the time.  It will
546 *  not work if restarting self conflicts with the stack frame
547 *  assumptions of restoring a context.
548 */
549
550#define _CPU_Context_Restart_self( _the_context ) \
551   _CPU_Context_restore( (_the_context) );
552
553/*
554 *  The purpose of this macro is to allow the initial pointer into
555 *  a floating point context area (used to save the floating point
556 *  context) to be at an arbitrary place in the floating point
557 *  context area.
558 *
559 *  This is necessary because some FP units are designed to have
560 *  their context saved as a stack which grows into lower addresses.
561 *  Other FP units can be saved by simply moving registers into offsets
562 *  from the base of the context area.  Finally some FP units provide
563 *  a "dump context" instruction which could fill in from high to low
564 *  or low to high based on the whim of the CPU designers.
565 */
566
567#define _CPU_Context_Fp_start( _base, _offset ) \
568   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
569
570/*
571 *  This routine initializes the FP context area passed to it to.
572 *  There are a few standard ways in which to initialize the
573 *  floating point context.  The code included for this macro assumes
574 *  that this is a CPU in which a "initial" FP context was saved into
575 *  _CPU_Null_fp_context and it simply copies it to the destination
576 *  context passed to it.
577 *
578 *  Other models include (1) not doing anything, and (2) putting
579 *  a "null FP status word" in the correct place in the FP context.
580 */
581
582#define _CPU_Context_Initialize_fp( _destination ) \
583  { \
584    (*(_destination))->fpscr = PPC_INIT_FPSCR; \
585  }
586
587/* end of Context handler macros */
588#endif /* ASM */
589
590#ifndef ASM
591/* Bitfield handler macros */
592
593/*
594 *  This routine sets _output to the bit number of the first bit
595 *  set in _value.  _value is of CPU dependent type Priority_Bit_map_control.
596 *  This type may be either 16 or 32 bits wide although only the 16
597 *  least significant bits will be used.
598 *
599 *  There are a number of variables in using a "find first bit" type
600 *  instruction.
601 *
602 *    (1) What happens when run on a value of zero?
603 *    (2) Bits may be numbered from MSB to LSB or vice-versa.
604 *    (3) The numbering may be zero or one based.
605 *    (4) The "find first bit" instruction may search from MSB or LSB.
606 *
607 *  RTEMS guarantees that (1) will never happen so it is not a concern.
608 *  (2),(3), (4) are handled by the macros _CPU_Priority_mask() and
609 *  _CPU_Priority_Bits_index().  These three form a set of routines
610 *  which must logically operate together.  Bits in the _value are
611 *  set and cleared based on masks built by _CPU_Priority_mask().
612 *  The basic major and minor values calculated by _Priority_Major()
613 *  and _Priority_Minor() are "massaged" by _CPU_Priority_Bits_index()
614 *  to properly range between the values returned by the "find first bit"
615 *  instruction.  This makes it possible for _Priority_Get_highest() to
616 *  calculate the major and directly index into the minor table.
617 *  This mapping is necessary to ensure that 0 (a high priority major/minor)
618 *  is the first bit found.
619 *
620 *  This entire "find first bit" and mapping process depends heavily
621 *  on the manner in which a priority is broken into a major and minor
622 *  components with the major being the 4 MSB of a priority and minor
623 *  the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
624 *  priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
625 *  to the lowest priority.
626 *
627 *  If your CPU does not have a "find first bit" instruction, then
628 *  there are ways to make do without it.  Here are a handful of ways
629 *  to implement this in software:
630 *
631 *    - a series of 16 bit test instructions
632 *    - a "binary search using if's"
633 *    - _number = 0
634 *      if _value > 0x00ff
635 *        _value >>=8
636 *        _number = 8;
637 *
638 *      if _value > 0x0000f
639 *        _value >=8
640 *        _number += 4
641 *
642 *      _number += bit_set_table[ _value ]
643 *
644 *    where bit_set_table[ 16 ] has values which indicate the first
645 *      bit set
646 */
647
648#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
649  { \
650    asm volatile ("cntlzw %0, %1" : "=r" ((_output)), "=r" ((_value)) : \
651                  "1" ((_value))); \
652  }
653
654/* end of Bitfield handler macros */
655
656/*
657 *  This routine builds the mask which corresponds to the bit fields
658 *  as searched by _CPU_Bitfield_Find_first_bit().  See the discussion
659 *  for that routine.
660 */
661
662#define _CPU_Priority_Mask( _bit_number ) \
663  ( 0x80000000 >> (_bit_number) )
664
665/*
666 *  This routine translates the bit numbers returned by
667 *  _CPU_Bitfield_Find_first_bit() into something suitable for use as
668 *  a major or minor component of a priority.  See the discussion
669 *  for that routine.
670 */
671
672#define _CPU_Priority_bits_index( _priority ) \
673  (_priority)
674
675/* end of Priority handler macros */
676#endif /* ASM */
677
678/* functions */
679
680#ifndef ASM
681
682/*
683 *  _CPU_Initialize
684 *
685 *  This routine performs CPU dependent initialization.
686 */
687
688void _CPU_Initialize(
689  void            (*thread_dispatch)
690);
691
692/*
693 *  _CPU_ISR_install_vector
694 *
695 *  This routine installs an interrupt vector.
696 */
697
698void _CPU_ISR_install_vector(
699  uint32_t    vector,
700  proc_ptr    new_handler,
701  proc_ptr   *old_handler
702);
703
704/*
705 *  _CPU_Install_interrupt_stack
706 *
707 *  This routine installs the hardware interrupt stack pointer.
708 *
709 *  NOTE:  It need only be provided if CPU_HAS_HARDWARE_INTERRUPT_STACK
710 *         is TRUE.
711 */
712
713void _CPU_Install_interrupt_stack( void );
714
715/*
716 *  _CPU_Context_switch
717 *
718 *  This routine switches from the run context to the heir context.
719 */
720
721void _CPU_Context_switch(
722  Context_Control  *run,
723  Context_Control  *heir
724);
725
726/*
727 *  _CPU_Context_restore
728 *
729 *  This routine is generallu used only to restart self in an
730 *  efficient manner.  It may simply be a label in _CPU_Context_switch.
731 *
732 *  NOTE: May be unnecessary to reload some registers.
733 */
734
735void _CPU_Context_restore(
736  Context_Control *new_context
737);
738
739/*
740 *  _CPU_Context_save_fp
741 *
742 *  This routine saves the floating point context passed to it.
743 */
744
745void _CPU_Context_save_fp(
746  Context_Control_fp **fp_context_ptr
747);
748
749/*
750 *  _CPU_Context_restore_fp
751 *
752 *  This routine restores the floating point context passed to it.
753 */
754
755void _CPU_Context_restore_fp(
756  Context_Control_fp **fp_context_ptr
757);
758
759void _CPU_Fatal_error(
760  uint32_t   _error
761);
762
763#endif /* ASM */
764
765#endif /* _RTEMS_SCORE_CPU_H */
Note: See TracBrowser for help on using the repository browser.