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

4.115
Last change on this file since f40139b was f40139b, checked in by Sebastian Huber <sebastian.huber@…>, on 09/22/11 at 07:16:06

2011-09-22 Sebastian Huber <sebastian.huber@…>

PR 1914/cpukit

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