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

4.104.114.84.95
Last change on this file since bc5fc7a6 was bc5fc7a6, checked in by Joel Sherrill <joel.sherrill@…>, on 10/12/01 at 17:40:22

2001-10-12 Alexandra Kossovsky <sasha@…>

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