source: rtems/c/src/exec/score/cpu/sh/cpu.h @ 50cf94da

4.104.114.84.95
Last change on this file since 50cf94da was 50cf94da, checked in by Joel Sherrill <joel.sherrill@…>, on 03/20/98 at 17:16:31

SH port submitted from Ralf Corsepius <corsepiu@…>.

  • Property mode set to 100644
File size: 26.9 KB
Line 
1/*
2 *  This include file contains information pertaining to the Hitachi SH
3 *  processor.
4 *
5 *  Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
6 *           Bernd Becker (becker@faw.uni-ulm.de)
7 *
8 *  COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
9 *
10 *  This program is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 *
15 *  COPYRIGHT (c) 1998.
16 *  On-Line Applications Research Corporation (OAR).
17 *  Copyright assigned to U.S. Government, 1994.
18 *
19 *  The license and distribution terms for this file may be
20 *  found in the file LICENSE in this distribution or at
21 *  http://www.OARcorp.com/rtems/license.html.
22 *
23 *  $Id$
24 */
25
26#ifndef _SH_CPU_h
27#define _SH_CPU_h
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include <rtems/score/sh.h>              /* pick up machine definitions */
34#ifndef ASM
35#include <rtems/score/shtypes.h>
36#endif
37
38/* conditional compilation parameters */
39
40/*
41 *  Should the calls to _Thread_Enable_dispatch be inlined?
42 *
43 *  If TRUE, then they are inlined.
44 *  If FALSE, then a subroutine call is made.
45 *
46 *  Basically this is an example of the classic trade-off of size
47 *  versus speed.  Inlining the call (TRUE) typically increases the
48 *  size of RTEMS while speeding up the enabling of dispatching.
49 *  [NOTE: In general, the _Thread_Dispatch_disable_level will
50 *  only be 0 or 1 unless you are in an interrupt handler and that
51 *  interrupt handler invokes the executive.]  When not inlined
52 *  something calls _Thread_Enable_dispatch which in turns calls
53 *  _Thread_Dispatch.  If the enable dispatch is inlined, then
54 *  one subroutine call is avoided entirely.]
55 */
56
57#define CPU_INLINE_ENABLE_DISPATCH       FALSE
58
59/*
60 *  Should the body of the search loops in _Thread_queue_Enqueue_priority
61 *  be unrolled one time?  In unrolled each iteration of the loop examines
62 *  two "nodes" on the chain being searched.  Otherwise, only one node
63 *  is examined per iteration.
64 *
65 *  If TRUE, then the loops are unrolled.
66 *  If FALSE, then the loops are not unrolled.
67 *
68 *  The primary factor in making this decision is the cost of disabling
69 *  and enabling interrupts (_ISR_Flash) versus the cost of rest of the
70 *  body of the loop.  On some CPUs, the flash is more expensive than
71 *  one iteration of the loop body.  In this case, it might be desirable
72 *  to unroll the loop.  It is important to note that on some CPUs, this
73 *  code is the longest interrupt disable period in RTEMS.  So it is
74 *  necessary to strike a balance when setting this parameter.
75 */
76
77#define CPU_UNROLL_ENQUEUE_PRIORITY      TRUE
78
79/*
80 *  Does RTEMS manage a dedicated interrupt stack in software?
81 *
82 *  If TRUE, then a stack is allocated in _Interrupt_Manager_initialization.
83 *  If FALSE, nothing is done.
84 *
85 *  If the CPU supports a dedicated interrupt stack in hardware,
86 *  then it is generally the responsibility of the BSP to allocate it
87 *  and set it up.
88 *
89 *  If the CPU does not support a dedicated interrupt stack, then
90 *  the porter has two options: (1) execute interrupts on the
91 *  stack of the interrupted task, and (2) have RTEMS manage a dedicated
92 *  interrupt stack.
93 *
94 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
95 *
96 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
97 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
98 *  possible that both are FALSE for a particular CPU.  Although it
99 *  is unclear what that would imply about the interrupt processing
100 *  procedure on that CPU.
101 */
102
103#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
104#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
105
106/*
107 * We define the interrupt stack in the linker script
108 */
109#define CPU_ALLOCATE_INTERRUPT_STACK FALSE
110
111
112/*
113 *  Does the CPU have hardware floating point?
114 *
115 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
116 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
117 *
118 *  We currently support sh1 only, which has no FPU, other SHes have an FPU
119 *
120 *  The macro name "NO_CPU_HAS_FPU" should be made CPU specific.
121 *  It indicates whether or not this CPU model has FP support.  For
122 *  example, it would be possible to have an i386_nofp CPU model
123 *  which set this to false to indicate that you have an i386 without
124 *  an i387 and wish to leave floating point support out of RTEMS.
125 */
126
127#define CPU_HARDWARE_FP     FALSE
128
129/*
130 *  Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
131 *
132 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
133 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
134 *
135 *  So far, the only CPU in which this option has been used is the
136 *  HP PA-RISC.  The HP C compiler and gcc both implicitly use the
137 *  floating point registers to perform integer multiplies.  If
138 *  a function which you would not think utilize the FP unit DOES,
139 *  then one can not easily predict which tasks will use the FP hardware.
140 *  In this case, this option should be TRUE.
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
187#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
188
189/*
190 *  Does this port provide a CPU dependent IDLE task implementation?
191 *
192 *  If TRUE, then the routine _CPU_Thread_Idle_body
193 *  must be provided and is the default IDLE thread body instead of
194 *  _CPU_Thread_Idle_body.
195 *
196 *  If FALSE, then use the generic IDLE thread body if the BSP does
197 *  not provide one.
198 *
199 *  This is intended to allow for supporting processors which have
200 *  a low power or idle mode.  When the IDLE thread is executed, then
201 *  the CPU can be powered down.
202 *
203 *  The order of precedence for selecting the IDLE thread body is:
204 *
205 *    1.  BSP provided
206 *    2.  CPU dependent (if provided)
207 *    3.  generic (if no BSP and no CPU dependent)
208 */
209
210#define CPU_PROVIDES_IDLE_THREAD_BODY    TRUE
211
212/*
213 *  Does the stack grow up (toward higher addresses) or down
214 *  (toward lower addresses)?
215 *
216 *  If TRUE, then the grows upward.
217 *  If FALSE, then the grows toward smaller addresses.
218 */
219
220#define CPU_STACK_GROWS_UP               FALSE
221
222/*
223 *  The following is the variable attribute used to force alignment
224 *  of critical RTEMS structures.  On some processors it may make
225 *  sense to have these aligned on tighter boundaries than
226 *  the minimum requirements of the compiler in order to have as
227 *  much of the critical data area as possible in a cache line.
228 *
229 *  The placement of this macro in the declaration of the variables
230 *  is based on the syntactically requirements of the GNU C
231 *  "__attribute__" extension.  For example with GNU C, use
232 *  the following to force a structures to a 32 byte boundary.
233 *
234 *      __attribute__ ((aligned (32)))
235 *
236 *  NOTE:  Currently only the Priority Bit Map table uses this feature.
237 *         To benefit from using this, the data must be heavily
238 *         used so it will stay in the cache and used frequently enough
239 *         in the executive to justify turning this on.
240 */
241
242#define CPU_STRUCTURE_ALIGNMENT __attribute__ ((aligned(16)))
243
244/*
245 *  The following defines the number of bits actually used in the
246 *  interrupt field of the task mode.  How those bits map to the
247 *  CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
248 */
249
250#define CPU_MODES_INTERRUPT_MASK   0x0000000f
251
252/*
253 *  Processor defined structures
254 *
255 *  Examples structures include the descriptor tables from the i386
256 *  and the processor control structure on the i960ca.
257 */
258
259/* may need to put some structures here.  */
260
261/*
262 * Contexts
263 *
264 *  Generally there are 2 types of context to save.
265 *     1. Interrupt registers to save
266 *     2. Task level registers to save
267 *
268 *  This means we have the following 3 context items:
269 *     1. task level context stuff::  Context_Control
270 *     2. floating point task stuff:: Context_Control_fp
271 *     3. special interrupt level context :: Context_Control_interrupt
272 *
273 *  On some processors, it is cost-effective to save only the callee
274 *  preserved registers during a task context switch.  This means
275 *  that the ISR code needs to save those registers which do not
276 *  persist across function calls.  It is not mandatory to make this
277 *  distinctions between the caller/callee saves registers for the
278 *  purpose of minimizing context saved during task switch and on interrupts.
279 *  If the cost of saving extra registers is minimal, simplicity is the
280 *  choice.  Save the same context on interrupt entry as for tasks in
281 *  this case.
282 *
283 *  Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
284 *  care should be used in designing the context area.
285 *
286 *  On some CPUs with hardware floating point support, the Context_Control_fp
287 *  structure will not be used or it simply consist of an array of a
288 *  fixed number of bytes.   This is done when the floating point context
289 *  is dumped by a "FP save context" type instruction and the format
290 *  is not really defined by the CPU.  In this case, there is no need
291 *  to figure out the exact format -- only the size.  Of course, although
292 *  this is enough information for RTEMS, it is probably not enough for
293 *  a debugger such as gdb.  But that is another problem.
294 */
295
296typedef struct {
297  unsigned32 *r15;      /* stack pointer */
298
299  unsigned32 macl;
300  unsigned32 mach;
301  unsigned32 *pr;
302
303  unsigned32 *r14;      /* frame pointer/call saved */
304
305  unsigned32 r13;       /* call saved */
306  unsigned32 r12;       /* call saved */
307  unsigned32 r11;       /* call saved */
308  unsigned32 r10;       /* call saved */
309  unsigned32 r9;        /* call saved */
310  unsigned32 r8;        /* call saved */
311
312  unsigned32 *r7;       /* arg in */
313  unsigned32 *r6;       /* arg in */
314
315#if 0
316  unsigned32 *r5;       /* arg in */
317  unsigned32 *r4;       /* arg in */
318#endif
319
320  unsigned32 *r3;       /* scratch */
321  unsigned32 *r2;       /* scratch */
322  unsigned32 *r1;       /* scratch */
323
324  unsigned32 *r0;       /* arg return */
325
326  unsigned32 gbr;
327  unsigned32 sr;
328
329} Context_Control;
330
331typedef struct {
332} Context_Control_fp;
333
334typedef struct {
335} CPU_Interrupt_frame;
336
337
338/*
339 *  The following table contains the information required to configure
340 *  the SH processor specific parameters.
341 */
342
343typedef struct {
344  void       (*pretasking_hook)( void );
345  void       (*predriver_hook)( void );
346  void       (*postdriver_hook)( void );
347  void       (*idle_task)( void );
348  boolean      do_zero_of_workspace;
349  unsigned32   interrupt_stack_size;
350  unsigned32   extra_mpci_receive_server_stack;
351  void *     (*stack_allocate_hook)( unsigned32 );
352  void       (*stack_free_hook)( void* );
353  /* end of fields required on all CPUs */
354}   rtems_cpu_table;
355
356/*
357 *  This variable is optional.  It is used on CPUs on which it is difficult
358 *  to generate an "uninitialized" FP context.  It is filled in by
359 *  _CPU_Initialize and copied into the task's FP context area during
360 *  _CPU_Context_Initialize.
361 */
362
363/*
364SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
365*/
366
367/*
368 *  On some CPUs, RTEMS supports a software managed interrupt stack.
369 *  This stack is allocated by the Interrupt Manager and the switch
370 *  is performed in _ISR_Handler.  These variables contain pointers
371 *  to the lowest and highest addresses in the chunk of memory allocated
372 *  for the interrupt stack.  Since it is unknown whether the stack
373 *  grows up or down (in general), this give the CPU dependent
374 *  code the option of picking the version it wants to use.
375 *
376 *  NOTE: These two variables are required if the macro
377 *        CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
378 */
379
380SCORE_EXTERN void               *_CPU_Interrupt_stack_low;
381SCORE_EXTERN void               *_CPU_Interrupt_stack_high;
382
383/*
384 *  With some compilation systems, it is difficult if not impossible to
385 *  call a high-level language routine from assembly language.  This
386 *  is especially true of commercial Ada compilers and name mangling
387 *  C++ ones.  This variable can be optionally defined by the CPU porter
388 *  and contains the address of the routine _Thread_Dispatch.  This
389 *  can make it easier to invoke that routine at the end of the interrupt
390 *  sequence (if a dispatch is necessary).
391 */
392
393SCORE_EXTERN void           (*_CPU_Thread_dispatch_pointer)();
394
395/*
396 *  Nothing prevents the porter from declaring more CPU specific variables.
397 */
398
399/* XXX: if needed, put more variables here */
400
401/*
402 *  The size of the floating point context area.  On some CPUs this
403 *  will not be a "sizeof" because the format of the floating point
404 *  area is not defined -- only the size is.  This is usually on
405 *  CPUs with a "floating point save context" instruction.
406 */
407
408#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
409
410/*
411 *  Amount of extra stack (above minimum stack size) required by
412 *  MPCI receive server thread.  Remember that in a multiprocessor
413 *  system this thread must exist and be able to process all directives.
414 */
415
416#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
417
418/*
419 *  This defines the number of entries in the ISR_Vector_table managed
420 *  by RTEMS.
421 */
422
423#define CPU_INTERRUPT_NUMBER_OF_VECTORS      256
424#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER  (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
425
426/*
427 *  Should be large enough to run all RTEMS tests.  This insures
428 *  that a "reasonable" small application should not have any problems.
429 *
430 *  We have been able to run the sptests with this value, but have not
431 *  been able to run the tmtest suite.
432 */
433
434#define CPU_STACK_MINIMUM_SIZE          4096
435
436/*
437 *  CPU's worst alignment requirement for data types on a byte boundary.  This
438 *  alignment does not take into account the requirements for the stack.
439 */
440
441#define CPU_ALIGNMENT              4
442
443/*
444 *  This number corresponds to the byte alignment requirement for the
445 *  heap handler.  This alignment requirement may be stricter than that
446 *  for the data types alignment specified by CPU_ALIGNMENT.  It is
447 *  common for the heap to follow the same alignment requirement as
448 *  CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
449 *  then this should be set to CPU_ALIGNMENT.
450 *
451 *  NOTE:  This does not have to be a power of 2.  It does have to
452 *         be greater or equal to than CPU_ALIGNMENT.
453 */
454
455#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
456
457/*
458 *  This number corresponds to the byte alignment requirement for memory
459 *  buffers allocated by the partition manager.  This alignment requirement
460 *  may be stricter than that for the data types alignment specified by
461 *  CPU_ALIGNMENT.  It is common for the partition to follow the same
462 *  alignment requirement as CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict
463 *  enough for the partition, then this should be set to CPU_ALIGNMENT.
464 *
465 *  NOTE:  This does not have to be a power of 2.  It does have to
466 *         be greater or equal to than CPU_ALIGNMENT.
467 */
468
469#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
470
471/*
472 *  This number corresponds to the byte alignment requirement for the
473 *  stack.  This alignment requirement may be stricter than that for the
474 *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
475 *  is strict enough for the stack, then this should be set to 0.
476 *
477 *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
478 */
479
480#define CPU_STACK_ALIGNMENT        CPU_ALIGNMENT
481
482/* ISR handler macros */
483
484/*
485 *  Disable all interrupts for an RTEMS critical section.  The previous
486 *  level is returned in _level.
487 */
488
489#define _CPU_ISR_Disable( _level) \
490  sh_disable_interrupts( _level )
491
492/*
493 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
494 *  This indicates the end of an RTEMS critical section.  The parameter
495 *  _level is not modified.
496 */
497
498#define _CPU_ISR_Enable( _level) \
499   sh_enable_interrupts( _level)
500
501/*
502 *  This temporarily restores the interrupt to _level before immediately
503 *  disabling them again.  This is used to divide long RTEMS critical
504 *  sections into two or more parts.  The parameter _level is not
505 * modified.
506 */
507
508#define _CPU_ISR_Flash( _level) \
509  sh_flash_interrupts( _level)
510
511/*
512 *  Map interrupt level in task mode onto the hardware that the CPU
513 *  actually provides.  Currently, interrupt levels which do not
514 *  map onto the CPU in a generic fashion are undefined.  Someday,
515 *  it would be nice if these were "mapped" by the application
516 *  via a callout.  For example, m68k has 8 levels 0 - 7, levels
517 *  8 - 255 would be available for bsp/application specific meaning.
518 *  This could be used to manage a programmable interrupt controller
519 *  via the rtems_task_mode directive.
520 */
521
522#define _CPU_ISR_Set_level( _newlevel) \
523  sh_set_interrupt_level(_newlevel)
524
525unsigned32 _CPU_ISR_Get_level( void );
526
527/* end of ISR handler macros */
528
529/* Context handler macros */
530
531/*
532 *  Initialize the context to a state suitable for starting a
533 *  task after a context restore operation.  Generally, this
534 *  involves:
535 *
536 *     - setting a starting address
537 *     - preparing the stack
538 *     - preparing the stack and frame pointers
539 *     - setting the proper interrupt level in the context
540 *     - initializing the floating point context
541 *
542 *  This routine generally does not set any unnecessary register
543 *  in the context.  The state of the "general data" registers is
544 *  undefined at task start time.
545 *
546 *  NOTE: This is_fp parameter is TRUE if the thread is to be a floating
547 *        point thread.  This is typically only used on CPUs where the
548 *        FPU may be easily disabled by software such as on the SPARC
549 *        where the PSR contains an enable FPU bit.
550 */
551
552/*
553 * FIXME: defined as a function for debugging - should be a macro
554 */
555SCORE_EXTERN void _CPU_Context_Initialize(
556  Context_Control       *_the_context,
557  void                  *_stack_base,
558  unsigned32            _size,
559  unsigned32            _isr,
560  void    (*_entry_point)(void),
561  int                   _is_fp );
562
563/*
564 *  This routine is responsible for somehow restarting the currently
565 *  executing task.  If you are lucky, then all that is necessary
566 *  is restoring the context.  Otherwise, there will need to be
567 *  a special assembly routine which does something special in this
568 *  case.  Context_Restore should work most of the time.  It will
569 *  not work if restarting self conflicts with the stack frame
570 *  assumptions of restoring a context.
571 */
572
573#define _CPU_Context_Restart_self( _the_context ) \
574   _CPU_Context_restore( (_the_context) );
575
576/*
577 *  The purpose of this macro is to allow the initial pointer into
578 *  a floating point context area (used to save the floating point
579 *  context) to be at an arbitrary place in the floating point
580 *  context area.
581 *
582 *  This is necessary because some FP units are designed to have
583 *  their context saved as a stack which grows into lower addresses.
584 *  Other FP units can be saved by simply moving registers into offsets
585 *  from the base of the context area.  Finally some FP units provide
586 *  a "dump context" instruction which could fill in from high to low
587 *  or low to high based on the whim of the CPU designers.
588 */
589
590#define _CPU_Context_Fp_start( _base, _offset ) \
591   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
592
593/*
594 *  This routine initializes the FP context area passed to it to.
595 *  There are a few standard ways in which to initialize the
596 *  floating point context.  The code included for this macro assumes
597 *  that this is a CPU in which a "initial" FP context was saved into
598 *  _CPU_Null_fp_context and it simply copies it to the destination
599 *  context passed to it.
600 *
601 *  Other models include (1) not doing anything, and (2) putting
602 *  a "null FP status word" in the correct place in the FP context.
603 *  SH has no FPU !!!!!!!!!!!!
604 */
605
606#define _CPU_Context_Initialize_fp( _destination ) \
607  {  }
608
609/* end of Context handler macros */
610
611/* Fatal Error manager macros */
612
613/*
614 * FIXME: Trap32 ???
615 *
616 *  This routine copies _error into a known place -- typically a stack
617 *  location or a register, optionally disables interrupts, and
618 *  invokes a Trap32 Instruction which returns to the breakpoint
619 *  routine of cmon.
620 */
621
622#ifdef BSP_FATAL_HALT
623  /* we manage the fatal error in the board support package */
624  void bsp_fatal_halt( unsigned32 _error);
625#define _CPU_Fatal_halt( _error ) bsp_fatal_halt( _error)
626#else
627#define _CPU_Fatal_halt( _error)\
628{ \
629  asm volatile("mov.l %0,r0"::"m" (_error)); \
630  asm volatile("trapa #34"); \
631}
632#endif
633
634/* end of Fatal Error manager macros */
635
636/* Bitfield handler macros */
637
638/*
639 *  This routine sets _output to the bit number of the first bit
640 *  set in _value.  _value is of CPU dependent type Priority_Bit_map_control.
641 *  This type may be either 16 or 32 bits wide although only the 16
642 *  least significant bits will be used.
643 *
644 *  There are a number of variables in using a "find first bit" type
645 *  instruction.
646 *
647 *    (1) What happens when run on a value of zero?
648 *    (2) Bits may be numbered from MSB to LSB or vice-versa.
649 *    (3) The numbering may be zero or one based.
650 *    (4) The "find first bit" instruction may search from MSB or LSB.
651 *
652 *  RTEMS guarantees that (1) will never happen so it is not a concern.
653 *  (2),(3), (4) are handled by the macros _CPU_Priority_mask() and
654 *  _CPU_Priority_bits_index().  These three form a set of routines
655 *  which must logically operate together.  Bits in the _value are
656 *  set and cleared based on masks built by _CPU_Priority_mask().
657 *  The basic major and minor values calculated by _Priority_Major()
658 *  and _Priority_Minor() are "massaged" by _CPU_Priority_bits_index()
659 *  to properly range between the values returned by the "find first bit"
660 *  instruction.  This makes it possible for _Priority_Get_highest() to
661 *  calculate the major and directly index into the minor table.
662 *  This mapping is necessary to ensure that 0 (a high priority major/minor)
663 *  is the first bit found.
664 *
665 *  This entire "find first bit" and mapping process depends heavily
666 *  on the manner in which a priority is broken into a major and minor
667 *  components with the major being the 4 MSB of a priority and minor
668 *  the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
669 *  priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
670 *  to the lowest priority.
671 *
672 *  If your CPU does not have a "find first bit" instruction, then
673 *  there are ways to make do without it.  Here are a handful of ways
674 *  to implement this in software:
675 *
676 *    - a series of 16 bit test instructions
677 *    - a "binary search using if's"
678 *    - _number = 0
679 *      if _value > 0x00ff
680 *        _value >>=8
681 *        _number = 8;
682 *
683 *      if _value > 0x0000f
684 *        _value >=8
685 *        _number += 4
686 *
687 *      _number += bit_set_table[ _value ]
688 *
689 *    where bit_set_table[ 16 ] has values which indicate the first
690 *      bit set
691 */
692
693#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
694#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
695
696#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
697
698extern unsigned8 _bit_set_table[];
699
700#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
701  { \
702      _output = 0;\
703      if(_value > 0x00ff) \
704      { _value >>= 8; _output = 8; } \
705      if(_value > 0x000f) \
706        { _output += 4; _value >>= 4; } \
707      _output += _bit_set_table[ _value]; }
708
709#endif
710
711/* end of Bitfield handler macros */
712
713/*
714 *  This routine builds the mask which corresponds to the bit fields
715 *  as searched by _CPU_Bitfield_Find_first_bit().  See the discussion
716 *  for that routine.
717 */
718
719#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
720
721#define _CPU_Priority_Mask( _bit_number ) \
722  ( 1 << (_bit_number) )
723
724#endif
725
726/*
727 *  This routine translates the bit numbers returned by
728 *  _CPU_Bitfield_Find_first_bit() into something suitable for use as
729 *  a major or minor component of a priority.  See the discussion
730 *  for that routine.
731 */
732
733#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
734
735#define _CPU_Priority_bits_index( _priority ) \
736  (_priority)
737
738#endif
739
740/* end of Priority handler macros */
741
742/* functions */
743
744/*
745 *  _CPU_Initialize
746 *
747 *  This routine performs CPU dependent initialization.
748 */
749
750void _CPU_Initialize(
751  rtems_cpu_table  *cpu_table,
752  void      (*thread_dispatch)
753);
754
755/*
756 *  _CPU_ISR_install_raw_handler
757 *
758 *  This routine installs a "raw" interrupt handler directly into the
759 *  processor's vector table.
760 */
761 
762void _CPU_ISR_install_raw_handler(
763  unsigned32  vector,
764  proc_ptr    new_handler,
765  proc_ptr   *old_handler
766);
767
768/*
769 *  _CPU_ISR_install_vector
770 *
771 *  This routine installs an interrupt vector.
772 */
773
774void _CPU_ISR_install_vector(
775  unsigned32  vector,
776  proc_ptr    new_handler,
777  proc_ptr   *old_handler
778);
779
780/*
781 *  _CPU_Install_interrupt_stack
782 *
783 *  This routine installs the hardware interrupt stack pointer.
784 *
785 *  NOTE:  It needs only be provided if CPU_HAS_HARDWARE_INTERRUPT_STACK
786 *         is TRUE.
787 */
788
789void _CPU_Install_interrupt_stack( void );
790
791/*
792 *  _CPU_Thread_Idle_body
793 *
794 *  This routine is the CPU dependent IDLE thread body.
795 *
796 *  NOTE:  It need only be provided if CPU_PROVIDES_IDLE_THREAD_BODY
797 *         is TRUE.
798 */
799
800void _CPU_Thread_Idle_body( void );
801
802/*
803 *  _CPU_Context_switch
804 *
805 *  This routine switches from the run context to the heir context.
806 */
807
808void _CPU_Context_switch(
809  Context_Control  *run,
810  Context_Control  *heir
811);
812
813/*
814 *  _CPU_Context_restore
815 *
816 *  This routine is generally used only to restart self in an
817 *  efficient manner.  It may simply be a label in _CPU_Context_switch.
818 */
819
820void _CPU_Context_restore(
821  Context_Control *new_context
822);
823
824/*
825 *  _CPU_Context_save_fp
826 *
827 *  This routine saves the floating point context passed to it.
828 */
829
830void _CPU_Context_save_fp(
831  void **fp_context_ptr
832);
833
834/*
835 *  _CPU_Context_restore_fp
836 *
837 *  This routine restores the floating point context passed to it.
838 */
839
840void _CPU_Context_restore_fp(
841  void **fp_context_ptr
842);
843
844
845#ifdef __cplusplus
846}
847#endif
848
849#endif
Note: See TracBrowser for help on using the repository browser.