source: rtems/cpukit/score/cpu/powerpc/rtems/score/cpu.h @ 2906c7a

4.104.114.95
Last change on this file since 2906c7a was 2906c7a, checked in by Joel Sherrill <joel.sherrill@…>, on 12/04/07 at 22:19:05

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

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