source: rtems/cpukit/score/cpu/no_cpu/rtems/score/cpu.h @ b60dc893

4.104.114.84.95
Last change on this file since b60dc893 was b60dc893, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/17/07 at 05:57:57

Use Context_Control_fp* instead of void* for fp_contexts.
Eliminate evil casts.

  • Property mode set to 100644
File size: 43.8 KB
Line 
1/**
2 * @file rtems/score/cpu.h
3 */
4
5/*
6 *  This include file contains information pertaining to the XXX
7 *  processor.
8 *
9 *  @note This file is part of a porting template that is intended
10 *  to be used as the starting point when porting RTEMS to a new
11 *  CPU family.  The following needs to be done when using this as
12 *  the starting point for a new port:
13 *
14 *  + Anywhere there is an XXX, it should be replaced
15 *    with information about the CPU family being ported to.
16 * 
17 *  + At the end of each comment section, there is a heading which
18 *    says "Port Specific Information:".  When porting to RTEMS,
19 *    add CPU family specific information in this section
20 */
21
22/*  COPYRIGHT (c) 1989-2006.
23 *  On-Line Applications Research Corporation (OAR).
24 *
25 *  The license and distribution terms for this file may be
26 *  found in the file LICENSE in this distribution or at
27 *  http://www.rtems.com/license/LICENSE.
28 *
29 *  $Id$
30 */
31
32#ifndef _RTEMS_SCORE_CPU_H
33#define _RTEMS_SCORE_CPU_H
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39#include <rtems/score/no_cpu.h>            /* pick up machine definitions */
40#ifndef ASM
41#include <rtems/score/types.h>
42#endif
43
44/* conditional compilation parameters */
45
46/**
47 *  Should the calls to @ref _Thread_Enable_dispatch be inlined?
48 *
49 *  If TRUE, then they are inlined.
50 *  If FALSE, then a subroutine call is made.
51 *
52 *  This conditional 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 *
56 *  @note In general, the @ref _Thread_Dispatch_disable_level will
57 *  only be 0 or 1 unless you are in an interrupt handler and that
58 *  interrupt handler invokes the executive.]  When not inlined
59 *  something calls @ref _Thread_Enable_dispatch which in turns calls
60 *  @ref _Thread_Dispatch.  If the enable dispatch is inlined, then
61 *  one subroutine call is avoided entirely.
62 *
63 *  Port Specific Information:
64 *
65 *  XXX document implementation including references if appropriate
66 */
67#define CPU_INLINE_ENABLE_DISPATCH       FALSE
68
69/**
70 *  Should the body of the search loops in _Thread_queue_Enqueue_priority
71 *  be unrolled one time?  In unrolled each iteration of the loop examines
72 *  two "nodes" on the chain being searched.  Otherwise, only one node
73 *  is examined per iteration.
74 *
75 *  If TRUE, then the loops are unrolled.
76 *  If FALSE, then the loops are not unrolled.
77 *
78 *  The primary factor in making this decision is the cost of disabling
79 *  and enabling interrupts (_ISR_Flash) versus the cost of rest of the
80 *  body of the loop.  On some CPUs, the flash is more expensive than
81 *  one iteration of the loop body.  In this case, it might be desirable
82 *  to unroll the loop.  It is important to note that on some CPUs, this
83 *  code is the longest interrupt disable period in RTEMS.  So it is
84 *  necessary to strike a balance when setting this parameter.
85 *
86 *  Port Specific Information:
87 *
88 *  XXX document implementation including references if appropriate
89 */
90#define CPU_UNROLL_ENQUEUE_PRIORITY      TRUE
91
92/**
93 *  Does RTEMS manage a dedicated interrupt stack in software?
94 *
95 *  If TRUE, then a stack is allocated in @ref _ISR_Handler_initialization.
96 *  If FALSE, nothing is done.
97 *
98 *  If the CPU supports a dedicated interrupt stack in hardware,
99 *  then it is generally the responsibility of the BSP to allocate it
100 *  and set it up.
101 *
102 *  If the CPU does not support a dedicated interrupt stack, then
103 *  the porter has two options: (1) execute interrupts on the
104 *  stack of the interrupted task, and (2) have RTEMS manage a dedicated
105 *  interrupt stack.
106 *
107 *  If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
108 *
109 *  Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
110 *  @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
111 *  possible that both are FALSE for a particular CPU.  Although it
112 *  is unclear what that would imply about the interrupt processing
113 *  procedure on that CPU.
114 *
115 *  Port Specific Information:
116 *
117 *  XXX document implementation including references if appropriate
118 */
119#define CPU_HAS_SOFTWARE_INTERRUPT_STACK FALSE
120
121/**
122 *  Does this CPU have hardware support for a dedicated interrupt stack?
123 *
124 *  If TRUE, then it must be installed during initialization.
125 *  If FALSE, then no installation is performed.
126 *
127 *  If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
128 *
129 *  Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
130 *  @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
131 *  possible that both are FALSE for a particular CPU.  Although it
132 *  is unclear what that would imply about the interrupt processing
133 *  procedure on that CPU.
134 *
135 *  Port Specific Information:
136 *
137 *  XXX document implementation including references if appropriate
138 */
139#define CPU_HAS_HARDWARE_INTERRUPT_STACK TRUE
140
141/**
142 *  Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
143 *
144 *  If TRUE, then the memory is allocated during initialization.
145 *  If FALSE, then the memory is allocated during initialization.
146 *
147 *  This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
148 *
149 *  Port Specific Information:
150 *
151 *  XXX document implementation including references if appropriate
152 */
153#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
154
155/**
156 *  Does the RTEMS invoke the user's ISR with the vector number and
157 *  a pointer to the saved interrupt frame (1) or just the vector
158 *  number (0)?
159 *
160 *  Port Specific Information:
161 *
162 *  XXX document implementation including references if appropriate
163 */
164#define CPU_ISR_PASSES_FRAME_POINTER 0
165
166/**
167 *  @def CPU_HARDWARE_FP
168 *
169 *  Does the CPU have hardware floating point?
170 *
171 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
172 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
173 *
174 *  If there is a FP coprocessor such as the i387 or mc68881, then
175 *  the answer is TRUE.
176 *
177 *  The macro name "NO_CPU_HAS_FPU" should be made CPU specific.
178 *  It indicates whether or not this CPU model has FP support.  For
179 *  example, it would be possible to have an i386_nofp CPU model
180 *  which set this to false to indicate that you have an i386 without
181 *  an i387 and wish to leave floating point support out of RTEMS.
182 */
183
184/**
185 *  @def CPU_SOFTWARE_FP
186 *
187 *  Does the CPU have no hardware floating point and GCC provides a
188 *  software floating point implementation which must be context
189 *  switched?
190 *
191 *  This feature conditional is used to indicate whether or not there
192 *  is software implemented floating point that must be context
193 *  switched.  The determination of whether or not this applies
194 *  is very tool specific and the state saved/restored is also
195 *  compiler specific.
196 *
197 *  Port Specific Information:
198 *
199 *  XXX document implementation including references if appropriate
200 */
201#if ( NO_CPU_HAS_FPU == 1 )
202#define CPU_HARDWARE_FP     TRUE
203#else
204#define CPU_HARDWARE_FP     FALSE
205#endif
206#define CPU_SOFTWARE_FP     FALSE
207
208/**
209 *  Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
210 *
211 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
212 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
213 *
214 *  So far, the only CPUs in which this option has been used are the
215 *  HP PA-RISC and PowerPC.  On the PA-RISC, The HP C compiler and
216 *  gcc both implicitly used the floating point registers to perform
217 *  integer multiplies.  Similarly, the PowerPC port of gcc has been
218 *  seen to allocate floating point local variables and touch the FPU
219 *  even when the flow through a subroutine (like vfprintf()) might
220 *  not use floating point formats.
221 *
222 *  If a function which you would not think utilize the FP unit DOES,
223 *  then one can not easily predict which tasks will use the FP hardware.
224 *  In this case, this option should be TRUE.
225 *
226 *  If @ref CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
227 *
228 *  Port Specific Information:
229 *
230 *  XXX document implementation including references if appropriate
231 */
232#define CPU_ALL_TASKS_ARE_FP     TRUE
233
234/**
235 *  Should the IDLE task have a floating point context?
236 *
237 *  If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
238 *  and it has a floating point context which is switched in and out.
239 *  If FALSE, then the IDLE task does not have a floating point context.
240 *
241 *  Setting this to TRUE negatively impacts the time required to preempt
242 *  the IDLE task from an interrupt because the floating point context
243 *  must be saved as part of the preemption.
244 *
245 *  Port Specific Information:
246 *
247 *  XXX document implementation including references if appropriate
248 */
249#define CPU_IDLE_TASK_IS_FP      FALSE
250
251/**
252 *  Should the saving of the floating point registers be deferred
253 *  until a context switch is made to another different floating point
254 *  task?
255 *
256 *  If TRUE, then the floating point context will not be stored until
257 *  necessary.  It will remain in the floating point registers and not
258 *  disturned until another floating point task is switched to.
259 *
260 *  If FALSE, then the floating point context is saved when a floating
261 *  point task is switched out and restored when the next floating point
262 *  task is restored.  The state of the floating point registers between
263 *  those two operations is not specified.
264 *
265 *  If the floating point context does NOT have to be saved as part of
266 *  interrupt dispatching, then it should be safe to set this to TRUE.
267 *
268 *  Setting this flag to TRUE results in using a different algorithm
269 *  for deciding when to save and restore the floating point context.
270 *  The deferred FP switch algorithm minimizes the number of times
271 *  the FP context is saved and restored.  The FP context is not saved
272 *  until a context switch is made to another, different FP task.
273 *  Thus in a system with only one FP task, the FP context will never
274 *  be saved or restored.
275 *
276 *  Port Specific Information:
277 *
278 *  XXX document implementation including references if appropriate
279 */
280#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
281
282/**
283 *  Does this port provide a CPU dependent IDLE task implementation?
284 *
285 *  If TRUE, then the routine @ref _CPU_Thread_Idle_body
286 *  must be provided and is the default IDLE thread body instead of
287 *  @ref _CPU_Thread_Idle_body.
288 *
289 *  If FALSE, then use the generic IDLE thread body if the BSP does
290 *  not provide one.
291 *
292 *  This is intended to allow for supporting processors which have
293 *  a low power or idle mode.  When the IDLE thread is executed, then
294 *  the CPU can be powered down.
295 *
296 *  The order of precedence for selecting the IDLE thread body is:
297 *
298 *    -#  BSP provided
299 *    -#  CPU dependent (if provided)
300 *    -#  generic (if no BSP and no CPU dependent)
301 *
302 *  Port Specific Information:
303 *
304 *  XXX document implementation including references if appropriate
305 */
306#define CPU_PROVIDES_IDLE_THREAD_BODY    TRUE
307
308/**
309 *  Does the stack grow up (toward higher addresses) or down
310 *  (toward lower addresses)?
311 *
312 *  If TRUE, then the grows upward.
313 *  If FALSE, then the grows toward smaller addresses.
314 *
315 *  Port Specific Information:
316 *
317 *  XXX document implementation including references if appropriate
318 */
319#define CPU_STACK_GROWS_UP               TRUE
320
321/**
322 *  The following is the variable attribute used to force alignment
323 *  of critical RTEMS structures.  On some processors it may make
324 *  sense to have these aligned on tighter boundaries than
325 *  the minimum requirements of the compiler in order to have as
326 *  much of the critical data area as possible in a cache line.
327 *
328 *  The placement of this macro in the declaration of the variables
329 *  is based on the syntactically requirements of the GNU C
330 *  "__attribute__" extension.  For example with GNU C, use
331 *  the following to force a structures to a 32 byte boundary.
332 *
333 *      __attribute__ ((aligned (32)))
334 *
335 *  @note Currently only the Priority Bit Map table uses this feature.
336 *        To benefit from using this, the data must be heavily
337 *        used so it will stay in the cache and used frequently enough
338 *        in the executive to justify turning this on.
339 *
340 *  Port Specific Information:
341 *
342 *  XXX document implementation including references if appropriate
343 */
344#define CPU_STRUCTURE_ALIGNMENT
345
346/**
347 *  @defgroup CPUEndian Processor Dependent Endianness Support
348 *
349 *  This group assists in issues related to processor endianness.
350 */
351
352/**
353 *  @ingroup CPUEndian
354 *  Define what is required to specify how the network to host conversion
355 *  routines are handled.
356 *
357 *  @note @a CPU_BIG_ENDIAN and @a CPU_LITTLE_ENDIAN should NOT have the
358 *  same values.
359 *
360 *  @see CPU_LITTLE_ENDIAN
361 *
362 *  Port Specific Information:
363 *
364 *  XXX document implementation including references if appropriate
365 */
366#define CPU_BIG_ENDIAN                           TRUE
367
368/**
369 *  @ingroup CPUEndian
370 *  Define what is required to specify how the network to host conversion
371 *  routines are handled.
372 *
373 *  @note @ref CPU_BIG_ENDIAN and @ref CPU_LITTLE_ENDIAN should NOT have the
374 *  same values.
375 *
376 *  @see CPU_BIG_ENDIAN
377 *
378 *  Port Specific Information:
379 *
380 *  XXX document implementation including references if appropriate
381 */
382#define CPU_LITTLE_ENDIAN                        FALSE
383
384/**
385 *  @ingroup CPUInterrupt
386 *  The following defines the number of bits actually used in the
387 *  interrupt field of the task mode.  How those bits map to the
388 *  CPU interrupt levels is defined by the routine @ref _CPU_ISR_Set_level.
389 *
390 *  Port Specific Information:
391 *
392 *  XXX document implementation including references if appropriate
393 */
394#define CPU_MODES_INTERRUPT_MASK   0x00000001
395
396/*
397 *  Processor defined structures required for cpukit/score.
398 *
399 *  Port Specific Information:
400 *
401 *  XXX document implementation including references if appropriate
402 */
403
404/* may need to put some structures here.  */
405
406/**
407 * @defgroup CPUContext Processor Dependent Context Management
408 *
409 *  From the highest level viewpoint, there are 2 types of context to save.
410 *
411 *     -# Interrupt registers to save
412 *     -# Task level registers to save
413 *
414 *  Since RTEMS handles integer and floating point contexts separately, this
415 *  means we have the following 3 context items:
416 *
417 *     -# task level context stuff::  Context_Control
418 *     -# floating point task stuff:: Context_Control_fp
419 *     -# special interrupt level context :: CPU_Interrupt_frame
420 *
421 *  On some processors, it is cost-effective to save only the callee
422 *  preserved registers during a task context switch.  This means
423 *  that the ISR code needs to save those registers which do not
424 *  persist across function calls.  It is not mandatory to make this
425 *  distinctions between the caller/callee saves registers for the
426 *  purpose of minimizing context saved during task switch and on interrupts.
427 *  If the cost of saving extra registers is minimal, simplicity is the
428 *  choice.  Save the same context on interrupt entry as for tasks in
429 *  this case.
430 *
431 *  Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
432 *  care should be used in designing the context area.
433 *
434 *  On some CPUs with hardware floating point support, the Context_Control_fp
435 *  structure will not be used or it simply consist of an array of a
436 *  fixed number of bytes.   This is done when the floating point context
437 *  is dumped by a "FP save context" type instruction and the format
438 *  is not really defined by the CPU.  In this case, there is no need
439 *  to figure out the exact format -- only the size.  Of course, although
440 *  this is enough information for RTEMS, it is probably not enough for
441 *  a debugger such as gdb.  But that is another problem.
442 *
443 *  Port Specific Information:
444 *
445 *  XXX document implementation including references if appropriate
446 */
447
448/**
449 *  @ingroup CPUContext Management
450 *  This defines the minimal set of integer and processor state registers
451 *  that must be saved during a voluntary context switch from one thread
452 *  to another.
453 */
454typedef struct {
455    /** This field is a hint that a port will have a number of integer
456     *  registers that need to be saved at a context switch.
457     */
458    uint32_t   some_integer_register;
459    /** This field is a hint that a port will have a number of system
460     *  registers that need to be saved at a context switch.
461     */
462    uint32_t   some_system_register;
463} Context_Control;
464
465/**
466 *  @ingroup CPUContext Management
467 *  This defines the complete set of floating point registers that must
468 *  be saved during any context switch from one thread to another.
469 */
470typedef struct {
471    /** FPU registers are listed here */
472    double      some_float_register;
473} Context_Control_fp;
474
475/**
476 *  @ingroup CPUContext Management
477 *  This defines the set of integer and processor state registers that must
478 *  be saved during an interrupt.  This set does not include any which are
479 *  in @ref Context_Control.
480 */
481typedef struct {
482    /** This field is a hint that a port will have a number of integer
483     *  registers that need to be saved when an interrupt occurs or
484     *  when a context switch occurs at the end of an ISR.
485     */
486    uint32_t   special_interrupt_register;
487} CPU_Interrupt_frame;
488
489
490/**
491 *  The following table contains the information required to configure
492 *  the XXX processor specific parameters.
493 *
494 *  Port Specific Information:
495 *
496 *  XXX document implementation including references if appropriate
497 */
498
499typedef struct {
500  /** This element points to the BSP's pretasking hook. */
501  void       (*pretasking_hook)( void );
502  /** This element points to the BSP's predriver hook. */
503  void       (*predriver_hook)( void );
504  /** This element points to the BSP's postdriver hook. */
505  void       (*postdriver_hook)( void );
506  /** This element points to the BSP's optional idle task which may override
507   *  the default one provided with RTEMS.
508   */
509  void       (*idle_task)( void );
510  /** If this element is TRUE, then RTEMS will zero the Executive Workspace.
511   *  When this element is FALSE, it is assumed that the BSP or invoking
512   *  environment has ensured that memory was cleared before RTEMS was
513   *  invoked.
514   */
515  boolean      do_zero_of_workspace;
516  /** This field specifies the size of the IDLE task's stack.  If less than or
517   *  equal to the minimum stack size, then the IDLE task will have the minimum
518   *  stack size.
519   */
520  uint32_t     idle_task_stack_size;
521  /** This field specifies the size of the interrupt stack.  If less than or
522   *  equal to the minimum stack size, then the interrupt stack will be of
523   *  minimum stack size.
524   */
525  uint32_t     interrupt_stack_size;
526  /** The MPCI Receive server is assumed to have a stack of at least
527   *  minimum stack size.  This field specifies the amount of extra
528   *  stack this task will be given in bytes.
529   */
530  uint32_t     extra_mpci_receive_server_stack;
531  /** The BSP may want to provide it's own stack allocation routines.
532   *  In this case, the BSP will provide this stack allocation hook.
533   */
534  void *     (*stack_allocate_hook)( uint32_t   );
535  /** The BSP may want to provide it's own stack free routines.
536   *  In this case, the BSP will provide this stack free hook.
537   */
538  void       (*stack_free_hook)( void *);
539  /* end of fields required on all CPUs */
540}   rtems_cpu_table;
541
542/*
543 *  Macros to access required entires in the CPU Table are in
544 *  the file rtems/system.h.
545 *
546 *  Port Specific Information:
547 *
548 *  XXX document implementation including references if appropriate
549 */
550
551/*
552 *  Macros to access NO_CPU specific additions to the CPU Table
553 *
554 *  Port Specific Information:
555 *
556 *  XXX document implementation including references if appropriate
557 */
558
559/* There are no CPU specific additions to the CPU Table for this port. */
560
561/**
562 *  This variable is optional.  It is used on CPUs on which it is difficult
563 *  to generate an "uninitialized" FP context.  It is filled in by
564 *  @ref _CPU_Initialize and copied into the task's FP context area during
565 *  @ref _CPU_Context_Initialize.
566 *
567 *  Port Specific Information:
568 *
569 *  XXX document implementation including references if appropriate
570 */
571SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
572
573/**
574 *  @defgroup CPUInterrupt Processor Dependent Interrupt Management
575 *
576 *  On some CPUs, RTEMS supports a software managed interrupt stack.
577 *  This stack is allocated by the Interrupt Manager and the switch
578 *  is performed in @ref _ISR_Handler.  These variables contain pointers
579 *  to the lowest and highest addresses in the chunk of memory allocated
580 *  for the interrupt stack.  Since it is unknown whether the stack
581 *  grows up or down (in general), this give the CPU dependent
582 *  code the option of picking the version it wants to use.
583 *
584 *  @note These two variables are required if the macro
585 *        @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
586 *
587 *  Port Specific Information:
588 *
589 *  XXX document implementation including references if appropriate
590 */
591
592/**
593 *  @ingroup CPUInterrupt
594 *  This variable points to the lowest physical address of the interrupt
595 *  stack.
596 */
597SCORE_EXTERN void               *_CPU_Interrupt_stack_low;
598
599/**
600 *  @ingroup CPUInterrupt
601 *  This variable points to the lowest physical address of the interrupt
602 *  stack.
603 */
604SCORE_EXTERN void               *_CPU_Interrupt_stack_high;
605
606/**
607 *  @ingroup CPUInterrupt
608 *  With some compilation systems, it is difficult if not impossible to
609 *  call a high-level language routine from assembly language.  This
610 *  is especially true of commercial Ada compilers and name mangling
611 *  C++ ones.  This variable can be optionally defined by the CPU porter
612 *  and contains the address of the routine @ref _Thread_Dispatch.  This
613 *  can make it easier to invoke that routine at the end of the interrupt
614 *  sequence (if a dispatch is necessary).
615 *
616 *  Port Specific Information:
617 *
618 *  XXX document implementation including references if appropriate
619 */
620SCORE_EXTERN void           (*_CPU_Thread_dispatch_pointer)();
621
622/*
623 *  Nothing prevents the porter from declaring more CPU specific variables.
624 *
625 *  Port Specific Information:
626 *
627 *  XXX document implementation including references if appropriate
628 */
629
630/* XXX: if needed, put more variables here */
631
632/**
633 *  @ingroup CPUContext
634 *  The size of the floating point context area.  On some CPUs this
635 *  will not be a "sizeof" because the format of the floating point
636 *  area is not defined -- only the size is.  This is usually on
637 *  CPUs with a "floating point save context" instruction.
638 *
639 *  Port Specific Information:
640 *
641 *  XXX document implementation including references if appropriate
642 */
643#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
644
645/**
646 *  Amount of extra stack (above minimum stack size) required by
647 *  MPCI receive server thread.  Remember that in a multiprocessor
648 *  system this thread must exist and be able to process all directives.
649 *
650 *  Port Specific Information:
651 *
652 *  XXX document implementation including references if appropriate
653 */
654#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
655
656/**
657 *  @ingroup CPUInterrupt
658 *  This defines the number of entries in the @ref _ISR_Vector_table managed
659 *  by RTEMS.
660 *
661 *  Port Specific Information:
662 *
663 *  XXX document implementation including references if appropriate
664 */
665#define CPU_INTERRUPT_NUMBER_OF_VECTORS      32
666
667/**
668 *  @ingroup CPUInterrupt
669 *  This defines the highest interrupt vector number for this port.
670 */
671#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER  (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
672
673/**
674 *  @ingroup CPUInterrupt
675 *  This is defined if the port has a special way to report the ISR nesting
676 *  level.  Most ports maintain the variable @a _ISR_Nest_level.
677 */
678#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
679
680/**
681 *  @ingroup CPUContext
682 *  Should be large enough to run all RTEMS tests.  This ensures
683 *  that a "reasonable" small application should not have any problems.
684 *
685 *  Port Specific Information:
686 *
687 *  XXX document implementation including references if appropriate
688 */
689#define CPU_STACK_MINIMUM_SIZE          (1024*4)
690
691/**
692 *  CPU's worst alignment requirement for data types on a byte boundary.  This
693 *  alignment does not take into account the requirements for the stack.
694 *
695 *  Port Specific Information:
696 *
697 *  XXX document implementation including references if appropriate
698 */
699#define CPU_ALIGNMENT              8
700
701/**
702 *  This number corresponds to the byte alignment requirement for the
703 *  heap handler.  This alignment requirement may be stricter than that
704 *  for the data types alignment specified by @ref CPU_ALIGNMENT.  It is
705 *  common for the heap to follow the same alignment requirement as
706 *  @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is strict enough for
707 *  the heap, then this should be set to @ref CPU_ALIGNMENT.
708 *
709 *  @note  This does not have to be a power of 2 although it should be
710 *         a multiple of 2 greater than or equal to 2.  The requirement
711 *         to be a multiple of 2 is because the heap uses the least
712 *         significant field of the front and back flags to indicate
713 *         that a block is in use or free.  So you do not want any odd
714 *         length blocks really putting length data in that bit.
715 *
716 *         On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will
717 *         have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that
718 *         elements allocated from the heap meet all restrictions.
719 *
720 *  Port Specific Information:
721 *
722 *  XXX document implementation including references if appropriate
723 */
724#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
725
726/**
727 *  This number corresponds to the byte alignment requirement for memory
728 *  buffers allocated by the partition manager.  This alignment requirement
729 *  may be stricter than that for the data types alignment specified by
730 *  @ref CPU_ALIGNMENT.  It is common for the partition to follow the same
731 *  alignment requirement as @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is
732 *  strict enough for the partition, then this should be set to
733 *  @ref CPU_ALIGNMENT.
734 *
735 *  @note  This does not have to be a power of 2.  It does have to
736 *         be greater or equal to than @ref CPU_ALIGNMENT.
737 *
738 *  Port Specific Information:
739 *
740 *  XXX document implementation including references if appropriate
741 */
742#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
743
744/**
745 *  This number corresponds to the byte alignment requirement for the
746 *  stack.  This alignment requirement may be stricter than that for the
747 *  data types alignment specified by @ref CPU_ALIGNMENT.  If the
748 *  @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
749 *  set to 0.
750 *
751 *  @note This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
752 *
753 *  Port Specific Information:
754 *
755 *  XXX document implementation including references if appropriate
756 */
757#define CPU_STACK_ALIGNMENT        0
758
759/*
760 *  ISR handler macros
761 */
762
763/**
764 *  @ingroup CPUInterrupt
765 *  Support routine to initialize the RTEMS vector table after it is allocated.
766 *
767 *  Port Specific Information:
768 *
769 *  XXX document implementation including references if appropriate
770 */
771#define _CPU_Initialize_vectors()
772
773/**
774 *  @ingroup CPUInterrupt
775 *  Disable all interrupts for an RTEMS critical section.  The previous
776 *  level is returned in @a _isr_cookie.
777 *
778 *  @param[out] _isr_cookie will contain the previous level cookie
779 *
780 *  Port Specific Information:
781 *
782 *  XXX document implementation including references if appropriate
783 */
784#define _CPU_ISR_Disable( _isr_cookie ) \
785  { \
786    (_isr_cookie) = 0;   /* do something to prevent warnings */ \
787  }
788
789/**
790 *  @ingroup CPUInterrupt
791 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
792 *  This indicates the end of an RTEMS critical section.  The parameter
793 *  @a _isr_cookie is not modified.
794 *
795 *  @param[in] _isr_cookie contain the previous level cookie
796 *
797 *  Port Specific Information:
798 *
799 *  XXX document implementation including references if appropriate
800 */
801#define _CPU_ISR_Enable( _isr_cookie )  \
802  { \
803  }
804
805/**
806 *  @ingroup CPUInterrupt
807 *  This temporarily restores the interrupt to @a _isr_cookie before immediately
808 *  disabling them again.  This is used to divide long RTEMS critical
809 *  sections into two or more parts.  The parameter @a _isr_cookie is not
810 *  modified.
811 *
812 *  @param[in] _isr_cookie contain the previous level cookie
813 *
814 *  Port Specific Information:
815 *
816 *  XXX document implementation including references if appropriate
817 */
818#define _CPU_ISR_Flash( _isr_cookie ) \
819  { \
820  }
821
822/**
823 *  @ingroup CPUInterrupt
824 *
825 *  This routine and @ref _CPU_ISR_Get_level
826 *  Map the interrupt level in task mode onto the hardware that the CPU
827 *  actually provides.  Currently, interrupt levels which do not
828 *  map onto the CPU in a generic fashion are undefined.  Someday,
829 *  it would be nice if these were "mapped" by the application
830 *  via a callout.  For example, m68k has 8 levels 0 - 7, levels
831 *  8 - 255 would be available for bsp/application specific meaning.
832 *  This could be used to manage a programmable interrupt controller
833 *  via the rtems_task_mode directive.
834 *
835 *  Port Specific Information:
836 *
837 *  XXX document implementation including references if appropriate
838 */
839#define _CPU_ISR_Set_level( new_level ) \
840  { \
841  }
842
843/**
844 *  @ingroup CPUInterrupt
845 *  Return the current interrupt disable level for this task in
846 *  the format used by the interrupt level portion of the task mode.
847 *
848 *  @note This routine usually must be implemented as a subroutine.
849 *
850 *  Port Specific Information:
851 *
852 *  XXX document implementation including references if appropriate
853 */
854uint32_t   _CPU_ISR_Get_level( void );
855
856/* end of ISR handler macros */
857
858/* Context handler macros */
859
860/**
861 *  @ingroup CPUContext
862 *  Initialize the context to a state suitable for starting a
863 *  task after a context restore operation.  Generally, this
864 *  involves:
865 *
866 *     - setting a starting address
867 *     - preparing the stack
868 *     - preparing the stack and frame pointers
869 *     - setting the proper interrupt level in the context
870 *     - initializing the floating point context
871 *
872 *  This routine generally does not set any unnecessary register
873 *  in the context.  The state of the "general data" registers is
874 *  undefined at task start time.
875 *
876 *  @param[in] _the_context is the context structure to be initialized
877 *  @param[in] _stack_base is the lowest physical address of this task's stack
878 *  @param[in] _size is the size of this task's stack
879 *  @param[in] _isr is the interrupt disable level
880 *  @param[in] _entry_point is the thread's entry point.  This is
881 *         always @a _Thread_Handler
882 *  @param[in] _is_fp is TRUE if the thread is to be a floating
883 *        point thread.  This is typically only used on CPUs where the
884 *        FPU may be easily disabled by software such as on the SPARC
885 *        where the PSR contains an enable FPU bit.
886 *
887 *  Port Specific Information:
888 *
889 *  XXX document implementation including references if appropriate
890 */
891#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
892                                 _isr, _entry_point, _is_fp ) \
893  { \
894  }
895
896/**
897 *  This routine is responsible for somehow restarting the currently
898 *  executing task.  If you are lucky, then all that is necessary
899 *  is restoring the context.  Otherwise, there will need to be
900 *  a special assembly routine which does something special in this
901 *  case.  For many ports, simply adding a label to the restore path
902 *  of @ref _CPU_Context_switch will work.  On other ports, it may be
903 *  possibly to load a few arguments and jump to the restore path. It will
904 *  not work if restarting self conflicts with the stack frame
905 *  assumptions of restoring a context.
906 *
907 *  Port Specific Information:
908 *
909 *  XXX document implementation including references if appropriate
910 */
911#define _CPU_Context_Restart_self( _the_context ) \
912   _CPU_Context_restore( (_the_context) );
913
914/**
915 *  @ingroup CPUContext
916 *  The purpose of this macro is to allow the initial pointer into
917 *  a floating point context area (used to save the floating point
918 *  context) to be at an arbitrary place in the floating point
919 *  context area.
920 *
921 *  This is necessary because some FP units are designed to have
922 *  their context saved as a stack which grows into lower addresses.
923 *  Other FP units can be saved by simply moving registers into offsets
924 *  from the base of the context area.  Finally some FP units provide
925 *  a "dump context" instruction which could fill in from high to low
926 *  or low to high based on the whim of the CPU designers.
927 *
928 *  @param[in] _base is the lowest physical address of the floating point
929 *         context area
930 *  @param[in] _offset is the offset into the floating point area
931 *
932 *  Port Specific Information:
933 *
934 *  XXX document implementation including references if appropriate
935 */
936#define _CPU_Context_Fp_start( _base, _offset ) \
937   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
938
939/**
940 *  This routine initializes the FP context area passed to it to.
941 *  There are a few standard ways in which to initialize the
942 *  floating point context.  The code included for this macro assumes
943 *  that this is a CPU in which a "initial" FP context was saved into
944 *  @a _CPU_Null_fp_context and it simply copies it to the destination
945 *  context passed to it.
946 *
947 *  Other floating point context save/restore models include:
948 *    -# not doing anything, and
949 *    -# putting a "null FP status word" in the correct place in the FP context.
950 *
951 *  @param[in] _destination is the floating point context area
952 *
953 *  Port Specific Information:
954 *
955 *  XXX document implementation including references if appropriate
956 */
957#define _CPU_Context_Initialize_fp( _destination ) \
958  { \
959   *(*(_destination)) = _CPU_Null_fp_context; \
960  }
961
962/* end of Context handler macros */
963
964/* Fatal Error manager macros */
965
966/**
967 *  This routine copies _error into a known place -- typically a stack
968 *  location or a register, optionally disables interrupts, and
969 *  halts/stops the CPU.
970 *
971 *  Port Specific Information:
972 *
973 *  XXX document implementation including references if appropriate
974 */
975#define _CPU_Fatal_halt( _error ) \
976  { \
977  }
978
979/* end of Fatal Error manager macros */
980
981/* Bitfield handler macros */
982
983/**
984 *  @defgroup CPUBitfield Processor Dependent Bitfield Manipulation
985 *
986 *  This set of routines are used to implement fast searches for
987 *  the most important ready task.
988 */
989
990/**
991 *  @ingroup CPUBitfield
992 *  This definition is set to TRUE if the port uses the generic bitfield
993 *  manipulation implementation.
994 */
995#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
996
997/**
998 *  @ingroup CPUBitfield
999 *  This definition is set to TRUE if the port uses the data tables provided
1000 *  by the generic bitfield manipulation implementation.
1001 *  This can occur when actually using the generic bitfield manipulation
1002 *  implementation or when implementing the same algorithm in assembly
1003 *  language for improved performance.  It is unlikely that a port will use
1004 *  the data if it has a bitfield scan instruction.
1005 */
1006#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
1007
1008/**
1009 *  @ingroup CPUBitfield
1010 *  This routine sets @a _output to the bit number of the first bit
1011 *  set in @a _value.  @a _value is of CPU dependent type
1012 *  @a Priority_Bit_map_control.  This type may be either 16 or 32 bits
1013 *  wide although only the 16 least significant bits will be used.
1014 *
1015 *  There are a number of variables in using a "find first bit" type
1016 *  instruction.
1017 *
1018 *    -# What happens when run on a value of zero?
1019 *    -# Bits may be numbered from MSB to LSB or vice-versa.
1020 *    -# The numbering may be zero or one based.
1021 *    -# The "find first bit" instruction may search from MSB or LSB.
1022 *
1023 *  RTEMS guarantees that (1) will never happen so it is not a concern.
1024 *  (2),(3), (4) are handled by the macros @ref _CPU_Priority_Mask and
1025 *  @ref _CPU_Priority_bits_index.  These three form a set of routines
1026 *  which must logically operate together.  Bits in the _value are
1027 *  set and cleared based on masks built by @ref _CPU_Priority_Mask.
1028 *  The basic major and minor values calculated by @ref _Priority_Major
1029 *  and @ref _Priority_Minor are "massaged" by @ref _CPU_Priority_bits_index
1030 *  to properly range between the values returned by the "find first bit"
1031 *  instruction.  This makes it possible for @ref _Priority_Get_highest to
1032 *  calculate the major and directly index into the minor table.
1033 *  This mapping is necessary to ensure that 0 (a high priority major/minor)
1034 *  is the first bit found.
1035 *
1036 *  This entire "find first bit" and mapping process depends heavily
1037 *  on the manner in which a priority is broken into a major and minor
1038 *  components with the major being the 4 MSB of a priority and minor
1039 *  the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
1040 *  priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
1041 *  to the lowest priority.
1042 *
1043 *  If your CPU does not have a "find first bit" instruction, then
1044 *  there are ways to make do without it.  Here are a handful of ways
1045 *  to implement this in software:
1046 *
1047@verbatim
1048      - a series of 16 bit test instructions
1049      - a "binary search using if's"
1050      - _number = 0
1051        if _value > 0x00ff
1052          _value >>=8
1053          _number = 8;
1054 
1055        if _value > 0x0000f
1056          _value >=8
1057          _number += 4
1058 
1059        _number += bit_set_table[ _value ]
1060@endverbatim
1061 
1062 *    where bit_set_table[ 16 ] has values which indicate the first
1063 *      bit set
1064 *
1065 *  @param[in] _value is the value to be scanned
1066 *  @param[in] _output is the first bit set
1067 *
1068 *  Port Specific Information:
1069 *
1070 *  XXX document implementation including references if appropriate
1071 */
1072
1073#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1074#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
1075  { \
1076    (_output) = 0;   /* do something to prevent warnings */ \
1077  }
1078#endif
1079
1080/* end of Bitfield handler macros */
1081
1082/**
1083 *  This routine builds the mask which corresponds to the bit fields
1084 *  as searched by @ref _CPU_Bitfield_Find_first_bit.  See the discussion
1085 *  for that routine.
1086 *
1087 *  Port Specific Information:
1088 *
1089 *  XXX document implementation including references if appropriate
1090 */
1091#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1092
1093#define _CPU_Priority_Mask( _bit_number ) \
1094  ( 1 << (_bit_number) )
1095
1096#endif
1097
1098/**
1099 *  @ingroup CPUBitfield
1100 *  This routine translates the bit numbers returned by
1101 *  @ref _CPU_Bitfield_Find_first_bit into something suitable for use as
1102 *  a major or minor component of a priority.  See the discussion
1103 *  for that routine.
1104 *
1105 *  @param[in] _priority is the major or minor number to translate
1106 *
1107 *  Port Specific Information:
1108 *
1109 *  XXX document implementation including references if appropriate
1110 */
1111#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1112
1113#define _CPU_Priority_bits_index( _priority ) \
1114  (_priority)
1115
1116#endif
1117
1118/* end of Priority handler macros */
1119
1120/* functions */
1121
1122/**
1123 *  This routine performs CPU dependent initialization.
1124 *
1125 *  @param[in] cpu_table is the CPU Dependent Configuration Table
1126 *  @param[in] thread_dispatch is the address of @ref _Thread_Dispatch
1127 *
1128 *  Port Specific Information:
1129 *
1130 *  XXX document implementation including references if appropriate
1131 */
1132void _CPU_Initialize(
1133  rtems_cpu_table  *cpu_table,
1134  void      (*thread_dispatch)
1135);
1136
1137/**
1138 *  @ingroup CPUInterrupt
1139 *  This routine installs a "raw" interrupt handler directly into the
1140 *  processor's vector table.
1141 *
1142 *  @param[in] vector is the vector number
1143 *  @param[in] new_handler is the raw ISR handler to install
1144 *  @param[in] old_handler is the previously installed ISR Handler
1145 *
1146 *  Port Specific Information:
1147 *
1148 *  XXX document implementation including references if appropriate
1149 */
1150void _CPU_ISR_install_raw_handler(
1151  uint32_t    vector,
1152  proc_ptr    new_handler,
1153  proc_ptr   *old_handler
1154);
1155
1156/**
1157 *  @ingroup CPUInterrupt
1158 *  This routine installs an interrupt vector.
1159 *
1160 *  @param[in] vector is the vector number
1161 *  @param[in] new_handler is the RTEMS ISR handler to install
1162 *  @param[in] old_handler is the previously installed ISR Handler
1163 *
1164 *  Port Specific Information:
1165 *
1166 *  XXX document implementation including references if appropriate
1167 */
1168void _CPU_ISR_install_vector(
1169  uint32_t    vector,
1170  proc_ptr    new_handler,
1171  proc_ptr   *old_handler
1172);
1173
1174/**
1175 *  @ingroup CPUInterrupt
1176 *  This routine installs the hardware interrupt stack pointer.
1177 *
1178 *  @note  It need only be provided if @ref CPU_HAS_HARDWARE_INTERRUPT_STACK
1179 *         is TRUE.
1180 *
1181 *  Port Specific Information:
1182 *
1183 *  XXX document implementation including references if appropriate
1184 */
1185void _CPU_Install_interrupt_stack( void );
1186
1187/**
1188 *  This routine is the CPU dependent IDLE thread body.
1189 *
1190 *  @note  It need only be provided if @ref CPU_PROVIDES_IDLE_THREAD_BODY
1191 *         is TRUE.
1192 *
1193 *  Port Specific Information:
1194 *
1195 *  XXX document implementation including references if appropriate
1196 */
1197void _CPU_Thread_Idle_body( void );
1198
1199/**
1200 *  @ingroup CPUContext
1201 *  This routine switches from the run context to the heir context.
1202 *
1203 *  @param[in] run points to the context of the currently executing task
1204 *  @param[in] heir points to the context of the heir task
1205 *
1206 *  Port Specific Information:
1207 *
1208 *  XXX document implementation including references if appropriate
1209 */
1210void _CPU_Context_switch(
1211  Context_Control  *run,
1212  Context_Control  *heir
1213);
1214
1215/**
1216 *  @ingroup CPUContext
1217 *  This routine is generally used only to restart self in an
1218 *  efficient manner.  It may simply be a label in @ref _CPU_Context_switch.
1219 *
1220 *  @param[in] new_context points to the context to be restored.
1221 *
1222 *  @note May be unnecessary to reload some registers.
1223 *
1224 *  Port Specific Information:
1225 *
1226 *  XXX document implementation including references if appropriate
1227 */
1228void _CPU_Context_restore(
1229  Context_Control *new_context
1230);
1231
1232/**
1233 *  @ingroup CPUContext
1234 *  This routine saves the floating point context passed to it.
1235 *
1236 *  @param[in] fp_context_ptr is a pointer to a pointer to a floating
1237 *  point context area
1238 *
1239 *  @return on output @a *fp_context_ptr will contain the address that
1240 *  should be used with @ref _CPU_Context_restore_fp to restore this context.
1241 *
1242 *  Port Specific Information:
1243 *
1244 *  XXX document implementation including references if appropriate
1245 */
1246void _CPU_Context_save_fp(
1247  Context_Control_fp **fp_context_ptr
1248);
1249
1250/**
1251 *  @ingroup CPUContext
1252 *  This routine restores the floating point context passed to it.
1253 *
1254 *  @param[in] fp_context_ptr is a pointer to a pointer to a floating
1255 *  point context area to restore
1256 *
1257 *  @return on output @a *fp_context_ptr will contain the address that
1258 *  should be used with @ref _CPU_Context_save_fp to save this context.
1259 *
1260 *  Port Specific Information:
1261 *
1262 *  XXX document implementation including references if appropriate
1263 */
1264void _CPU_Context_restore_fp(
1265  Context_Control_fp **fp_context_ptr
1266);
1267
1268/**
1269 *  @ingroup CPUEndian
1270 *  The following routine swaps the endian format of an unsigned int.
1271 *  It must be static because it is referenced indirectly.
1272 *
1273 *  This version will work on any processor, but if there is a better
1274 *  way for your CPU PLEASE use it.  The most common way to do this is to:
1275 *
1276 *     swap least significant two bytes with 16-bit rotate
1277 *     swap upper and lower 16-bits
1278 *     swap most significant two bytes with 16-bit rotate
1279 *
1280 *  Some CPUs have special instructions which swap a 32-bit quantity in
1281 *  a single instruction (e.g. i486).  It is probably best to avoid
1282 *  an "endian swapping control bit" in the CPU.  One good reason is
1283 *  that interrupts would probably have to be disabled to ensure that
1284 *  an interrupt does not try to access the same "chunk" with the wrong
1285 *  endian.  Another good reason is that on some CPUs, the endian bit
1286 *  endianness for ALL fetches -- both code and data -- so the code
1287 *  will be fetched incorrectly.
1288 *
1289 *  @param[in] value is the value to be swapped
1290 *  @return the value after being endian swapped
1291 *
1292 *  Port Specific Information:
1293 *
1294 *  XXX document implementation including references if appropriate
1295 */
1296static inline uint32_t CPU_swap_u32(
1297  uint32_t value
1298)
1299{
1300  uint32_t   byte1, byte2, byte3, byte4, swapped;
1301 
1302  byte4 = (value >> 24) & 0xff;
1303  byte3 = (value >> 16) & 0xff;
1304  byte2 = (value >> 8)  & 0xff;
1305  byte1 =  value        & 0xff;
1306 
1307  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
1308  return( swapped );
1309}
1310
1311/**
1312 *  @ingroup CPUEndian
1313 *  This routine swaps a 16 bir quantity.
1314 *
1315 *  @param[in] value is the value to be swapped
1316 *  @return the value after being endian swapped
1317 */
1318#define CPU_swap_u16( value ) \
1319  (((value&0xff) << 8) | ((value >> 8)&0xff))
1320
1321#ifdef __cplusplus
1322}
1323#endif
1324
1325#endif
Note: See TracBrowser for help on using the repository browser.