source: rtems/cpukit/score/cpu/sh/rtems/score/cpu.h @ ee29de05

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

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

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