source: rtems/cpukit/score/cpu/no_cpu/rtems/score/cpu.h @ 9f016ec9

5
Last change on this file since 9f016ec9 was 9f016ec9, checked in by Sebastian Huber <sebastian.huber@…>, on 02/03/16 at 10:53:10

no_cpu: Avoid SCORE_EXTERN

Update #2559.

  • Property mode set to 100644
File size: 49.6 KB
Line 
1/**
2 * @file rtems/score/cpu.h
3 *
4 * @brief NO_CPU Department Source
5 *
6 * This include file contains information pertaining to the NO_CPU
7 * processor.
8 */
9
10/*
11 *  This include file contains information pertaining to the XXX
12 *  processor.
13 *
14 *  @note This file is part of a porting template that is intended
15 *  to be used as the starting point when porting RTEMS to a new
16 *  CPU family.  The following needs to be done when using this as
17 *  the starting point for a new port:
18 *
19 *  + Anywhere there is an XXX, it should be replaced
20 *    with information about the CPU family being ported to.
21 *
22 *  + At the end of each comment section, there is a heading which
23 *    says "Port Specific Information:".  When porting to RTEMS,
24 *    add CPU family specific information in this section
25 */
26
27/*
28 *  COPYRIGHT (c) 1989-2008.
29 *  On-Line Applications Research Corporation (OAR).
30 *
31 *  The license and distribution terms for this file may be
32 *  found in the file LICENSE in this distribution or at
33 *  http://www.rtems.org/license/LICENSE.
34 */
35
36#ifndef _RTEMS_SCORE_CPU_H
37#define _RTEMS_SCORE_CPU_H
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43#include <rtems/score/types.h>
44#include <rtems/score/no_cpu.h>
45
46/* conditional compilation parameters */
47
48/**
49 * Should the calls to @ref _Thread_Enable_dispatch be inlined?
50 *
51 * If TRUE, then they are inlined.
52 * If FALSE, then a subroutine call is made.
53 *
54 * This conditional is an example of the classic trade-off of size
55 * versus speed.  Inlining the call (TRUE) typically increases the
56 * size of RTEMS while speeding up the enabling of dispatching.
57 *
58 * NOTE: In general, the @ref _Thread_Dispatch_disable_level will
59 * only be 0 or 1 unless you are in an interrupt handler and that
60 * interrupt handler invokes the executive.]  When not inlined
61 * something calls @ref _Thread_Enable_dispatch which in turns calls
62 * @ref _Thread_Dispatch.  If the enable dispatch is inlined, then
63 * one subroutine call is avoided entirely.
64 *
65 * Port Specific Information:
66 *
67 * XXX document implementation including references if appropriate
68 */
69#define CPU_INLINE_ENABLE_DISPATCH       FALSE
70
71/**
72 * Does RTEMS manage a dedicated interrupt stack in software?
73 *
74 * If TRUE, then a stack is allocated in @ref _ISR_Handler_initialization.
75 * If FALSE, nothing is done.
76 *
77 * If the CPU supports a dedicated interrupt stack in hardware,
78 * then it is generally the responsibility of the BSP to allocate it
79 * and set it up.
80 *
81 * If the CPU does not support a dedicated interrupt stack, then
82 * the porter has two options: (1) execute interrupts on the
83 * stack of the interrupted task, and (2) have RTEMS manage a dedicated
84 * interrupt stack.
85 *
86 * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
87 *
88 * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
89 * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
90 * possible that both are FALSE for a particular CPU.  Although it
91 * is unclear what that would imply about the interrupt processing
92 * procedure on that CPU.
93 *
94 * Port Specific Information:
95 *
96 * XXX document implementation including references if appropriate
97 */
98#define CPU_HAS_SOFTWARE_INTERRUPT_STACK FALSE
99
100/**
101 * Does the CPU follow the simple vectored interrupt model?
102 *
103 * If TRUE, then RTEMS allocates the vector table it internally manages.
104 * If FALSE, then the BSP is assumed to allocate and manage the vector
105 * table
106 *
107 * Port Specific Information:
108 *
109 * XXX document implementation including references if appropriate
110 */
111#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
112
113/**
114 * Does this CPU have hardware support for a dedicated interrupt stack?
115 *
116 * If TRUE, then it must be installed during initialization.
117 * If FALSE, then no installation is performed.
118 *
119 * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
120 *
121 * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
122 * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
123 * possible that both are FALSE for a particular CPU.  Although it
124 * is unclear what that would imply about the interrupt processing
125 * procedure on that CPU.
126 *
127 * Port Specific Information:
128 *
129 * XXX document implementation including references if appropriate
130 */
131#define CPU_HAS_HARDWARE_INTERRUPT_STACK TRUE
132
133/**
134 * Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
135 *
136 * If TRUE, then the memory is allocated during initialization.
137 * If FALSE, then the memory is allocated during initialization.
138 *
139 * This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
140 *
141 * Port Specific Information:
142 *
143 * XXX document implementation including references if appropriate
144 */
145#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
146
147/**
148 * Does the RTEMS invoke the user's ISR with the vector number and
149 * a pointer to the saved interrupt frame (1) or just the vector
150 * number (0)?
151 *
152 * Port Specific Information:
153 *
154 * XXX document implementation including references if appropriate
155 */
156#define CPU_ISR_PASSES_FRAME_POINTER 0
157
158/**
159 * @def CPU_HARDWARE_FP
160 *
161 * Does the CPU have hardware floating point?
162 *
163 * If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
164 * If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
165 *
166 * If there is a FP coprocessor such as the i387 or mc68881, then
167 * the answer is TRUE.
168 *
169 * The macro name "NO_CPU_HAS_FPU" should be made CPU specific.
170 * It indicates whether or not this CPU model has FP support.  For
171 * example, it would be possible to have an i386_nofp CPU model
172 * which set this to false to indicate that you have an i386 without
173 * an i387 and wish to leave floating point support out of RTEMS.
174 */
175
176/**
177 * @def CPU_SOFTWARE_FP
178 *
179 * Does the CPU have no hardware floating point and GCC provides a
180 * software floating point implementation which must be context
181 * switched?
182 *
183 * This feature conditional is used to indicate whether or not there
184 * is software implemented floating point that must be context
185 * switched.  The determination of whether or not this applies
186 * is very tool specific and the state saved/restored is also
187 * compiler specific.
188 *
189 * Port Specific Information:
190 *
191 * XXX document implementation including references if appropriate
192 */
193#if ( NO_CPU_HAS_FPU == 1 )
194#define CPU_HARDWARE_FP     TRUE
195#else
196#define CPU_HARDWARE_FP     FALSE
197#endif
198#define CPU_SOFTWARE_FP     FALSE
199
200/**
201 * Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
202 *
203 * If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
204 * If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
205 *
206 * So far, the only CPUs in which this option has been used are the
207 * HP PA-RISC and PowerPC.  On the PA-RISC, The HP C compiler and
208 * gcc both implicitly used the floating point registers to perform
209 * integer multiplies.  Similarly, the PowerPC port of gcc has been
210 * seen to allocate floating point local variables and touch the FPU
211 * even when the flow through a subroutine (like vfprintf()) might
212 * not use floating point formats.
213 *
214 * If a function which you would not think utilize the FP unit DOES,
215 * then one can not easily predict which tasks will use the FP hardware.
216 * In this case, this option should be TRUE.
217 *
218 * If @ref CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
219 *
220 * Port Specific Information:
221 *
222 * XXX document implementation including references if appropriate
223 */
224#define CPU_ALL_TASKS_ARE_FP     TRUE
225
226/**
227 * Should the IDLE task have a floating point context?
228 *
229 * If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
230 * and it has a floating point context which is switched in and out.
231 * If FALSE, then the IDLE task does not have a floating point context.
232 *
233 * Setting this to TRUE negatively impacts the time required to preempt
234 * the IDLE task from an interrupt because the floating point context
235 * must be saved as part of the preemption.
236 *
237 * Port Specific Information:
238 *
239 * XXX document implementation including references if appropriate
240 */
241#define CPU_IDLE_TASK_IS_FP      FALSE
242
243/**
244 * Should the saving of the floating point registers be deferred
245 * until a context switch is made to another different floating point
246 * task?
247 *
248 * If TRUE, then the floating point context will not be stored until
249 * necessary.  It will remain in the floating point registers and not
250 * disturned until another floating point task is switched to.
251 *
252 * If FALSE, then the floating point context is saved when a floating
253 * point task is switched out and restored when the next floating point
254 * task is restored.  The state of the floating point registers between
255 * those two operations is not specified.
256 *
257 * If the floating point context does NOT have to be saved as part of
258 * interrupt dispatching, then it should be safe to set this to TRUE.
259 *
260 * Setting this flag to TRUE results in using a different algorithm
261 * for deciding when to save and restore the floating point context.
262 * The deferred FP switch algorithm minimizes the number of times
263 * the FP context is saved and restored.  The FP context is not saved
264 * until a context switch is made to another, different FP task.
265 * Thus in a system with only one FP task, the FP context will never
266 * be saved or restored.
267 *
268 * Port Specific Information:
269 *
270 * XXX document implementation including references if appropriate
271 */
272#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
273
274/**
275 * Does this port provide a CPU dependent IDLE task implementation?
276 *
277 * If TRUE, then the routine @ref _CPU_Thread_Idle_body
278 * must be provided and is the default IDLE thread body instead of
279 * @ref _CPU_Thread_Idle_body.
280 *
281 * If FALSE, then use the generic IDLE thread body if the BSP does
282 * not provide one.
283 *
284 * This is intended to allow for supporting processors which have
285 * a low power or idle mode.  When the IDLE thread is executed, then
286 * the CPU can be powered down.
287 *
288 * The order of precedence for selecting the IDLE thread body is:
289 *
290 *   -#  BSP provided
291 *   -#  CPU dependent (if provided)
292 *   -#  generic (if no BSP and no CPU dependent)
293 *
294 * Port Specific Information:
295 *
296 * XXX document implementation including references if appropriate
297 */
298#define CPU_PROVIDES_IDLE_THREAD_BODY    TRUE
299
300/**
301 * Does the stack grow up (toward higher addresses) or down
302 * (toward lower addresses)?
303 *
304 * If TRUE, then the grows upward.
305 * If FALSE, then the grows toward smaller addresses.
306 *
307 * Port Specific Information:
308 *
309 * XXX document implementation including references if appropriate
310 */
311#define CPU_STACK_GROWS_UP               TRUE
312
313/**
314 * The maximum cache line size in bytes.
315 *
316 * The actual processor may use no cache or a smaller cache line size.
317 */
318#define CPU_CACHE_LINE_BYTES 32
319
320/**
321 * The following is the variable attribute used to force alignment
322 * of critical RTEMS structures.  On some processors it may make
323 * sense to have these aligned on tighter boundaries than
324 * the minimum requirements of the compiler in order to have as
325 * much of the critical data area as possible in a cache line.
326 *
327 * Port Specific Information:
328 *
329 * XXX document implementation including references if appropriate
330 */
331#define CPU_STRUCTURE_ALIGNMENT RTEMS_ALIGNED( CPU_CACHE_LINE_BYTES )
332
333/**
334 * @defgroup CPUEndian Processor Dependent Endianness Support
335 *
336 * This group assists in issues related to processor endianness.
337 *
338 */
339/**@{**/
340
341/**
342 * Define what is required to specify how the network to host conversion
343 * routines are handled.
344 *
345 * NOTE: @a CPU_BIG_ENDIAN and @a CPU_LITTLE_ENDIAN should NOT have the
346 * same values.
347 *
348 * @see CPU_LITTLE_ENDIAN
349 *
350 * Port Specific Information:
351 *
352 * XXX document implementation including references if appropriate
353 */
354#define CPU_BIG_ENDIAN                           TRUE
355
356/**
357 * Define what is required to specify how the network to host conversion
358 * routines are handled.
359 *
360 * NOTE: @ref CPU_BIG_ENDIAN and @ref CPU_LITTLE_ENDIAN should NOT have the
361 * same values.
362 *
363 * @see CPU_BIG_ENDIAN
364 *
365 * Port Specific Information:
366 *
367 * XXX document implementation including references if appropriate
368 */
369#define CPU_LITTLE_ENDIAN                        FALSE
370
371/** @} */
372
373/**
374 * @ingroup CPUInterrupt
375 *
376 * The following defines the number of bits actually used in the
377 * interrupt field of the task mode.  How those bits map to the
378 * CPU interrupt levels is defined by the routine @ref _CPU_ISR_Set_level.
379 *
380 * Port Specific Information:
381 *
382 * XXX document implementation including references if appropriate
383 */
384#define CPU_MODES_INTERRUPT_MASK   0x00000001
385
386/**
387 * @brief The size of the CPU specific per-CPU control.
388 *
389 * This define must be visible to assember files since it is used to derive
390 * structure offsets.
391 */
392#define CPU_PER_CPU_CONTROL_SIZE 0
393
394/*
395 *  Processor defined structures required for cpukit/score.
396 *
397 *  Port Specific Information:
398 *
399 *  XXX document implementation including references if appropriate
400 */
401
402/* may need to put some structures here.  */
403
404/**
405 * @brief The CPU specific per-CPU control.
406 *
407 * The CPU port can place here all state information that must be available and
408 * maintained for each CPU in the system.
409 */
410typedef struct {
411  /* CPU specific per-CPU state */
412} CPU_Per_CPU_control;
413
414/**
415 * @defgroup CPUContext Processor Dependent Context Management
416 *
417 * From the highest level viewpoint, there are 2 types of context to save.
418 *
419 *    -# Interrupt registers to save
420 *    -# Task level registers to save
421 *
422 * Since RTEMS handles integer and floating point contexts separately, this
423 * means we have the following 3 context items:
424 *
425 *    -# task level context stuff::  Context_Control
426 *    -# floating point task stuff:: Context_Control_fp
427 *    -# special interrupt level context :: CPU_Interrupt_frame
428 *
429 * On some processors, it is cost-effective to save only the callee
430 * preserved registers during a task context switch.  This means
431 * that the ISR code needs to save those registers which do not
432 * persist across function calls.  It is not mandatory to make this
433 * distinctions between the caller/callee saves registers for the
434 * purpose of minimizing context saved during task switch and on interrupts.
435 * If the cost of saving extra registers is minimal, simplicity is the
436 * choice.  Save the same context on interrupt entry as for tasks in
437 * this case.
438 *
439 * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
440 * care should be used in designing the context area.
441 *
442 * On some CPUs with hardware floating point support, the Context_Control_fp
443 * structure will not be used or it simply consist of an array of a
444 * fixed number of bytes.   This is done when the floating point context
445 * is dumped by a "FP save context" type instruction and the format
446 * is not really defined by the CPU.  In this case, there is no need
447 * to figure out the exact format -- only the size.  Of course, although
448 * this is enough information for RTEMS, it is probably not enough for
449 * a debugger such as gdb.  But that is another problem.
450 *
451 * Port Specific Information:
452 *
453 * XXX document implementation including references if appropriate
454 *
455 */
456/**@{**/
457
458/**
459 * @ingroup Management
460 * This defines the minimal set of integer and processor state registers
461 * that must be saved during a voluntary context switch from one thread
462 * to another.
463 */
464typedef struct {
465    /**
466     * This field is a hint that a port will have a number of integer
467     * registers that need to be saved at a context switch.
468     */
469    uint32_t   some_integer_register;
470    /**
471     * This field is a hint that a port will have a number of system
472     * registers that need to be saved at a context switch.
473     */
474    uint32_t   some_system_register;
475
476    /**
477     * This field is a hint that a port will have a register that
478     * is the stack pointer.
479     */
480    uint32_t   stack_pointer;
481
482#ifdef RTEMS_SMP
483    /**
484     * @brief On SMP configurations the thread context must contain a boolean
485     * indicator to signal if this context is executing on a processor.
486     *
487     * This field must be updated during a context switch.  The context switch
488     * to the heir must wait until the heir context indicates that it is no
489     * longer executing on a processor.  This indicator must be updated using
490     * an atomic test and set operation to ensure that at most one processor
491     * uses the heir context at the same time.  The context switch must also
492     * check for a potential new heir thread for this processor in case the
493     * heir context is not immediately available.  Update the executing thread
494     * for this processor only if necessary to avoid a cache line
495     * monopolization.
496     *
497     * @code
498     * void _CPU_Context_switch(
499     *   Context_Control *executing_context,
500     *   Context_Control *heir_context
501     * )
502     * {
503     *   save( executing_context );
504     *
505     *   executing_context->is_executing = false;
506     *   memory_barrier();
507     *
508     *   if ( test_and_set( &heir_context->is_executing ) ) {
509     *     do {
510     *       Per_CPU_Control *cpu_self = _Per_CPU_Get_snapshot();
511     *       Thread_Control *executing = cpu_self->executing;
512     *       Thread_Control *heir = cpu_self->heir;
513     *
514     *       if ( heir != executing ) {
515     *         cpu_self->executing = heir;
516     *         heir_context = (Context_Control *)
517     *           ((uintptr_t) heir + (uintptr_t) executing_context
518     *             - (uintptr_t) executing)
519     *       }
520     *     } while ( test_and_set( &heir_context->is_executing ) );
521     *   }
522     *
523     *   restore( heir_context );
524     * }
525     * @endcode
526     */
527    volatile bool is_executing;
528#endif
529} Context_Control;
530
531/**
532 * @ingroup Management
533 *
534 * This macro returns the stack pointer associated with @a _context.
535 *
536 * @param[in] _context is the thread context area to access
537 *
538 * @return This method returns the stack pointer.
539 */
540#define _CPU_Context_Get_SP( _context ) \
541  (_context)->stack_pointer
542
543/**
544 * @ingroup Management
545 *
546 * This defines the complete set of floating point registers that must
547 * be saved during any context switch from one thread to another.
548 */
549typedef struct {
550    /** FPU registers are listed here */
551    double      some_float_register;
552} Context_Control_fp;
553
554/**
555 * @ingroup Management
556 *
557 * This defines the set of integer and processor state registers that must
558 * be saved during an interrupt.  This set does not include any which are
559 * in @ref Context_Control.
560 */
561typedef struct {
562    /**
563     * This field is a hint that a port will have a number of integer
564     * registers that need to be saved when an interrupt occurs or
565     * when a context switch occurs at the end of an ISR.
566     */
567    uint32_t   special_interrupt_register;
568} CPU_Interrupt_frame;
569
570/**
571 * This variable is optional.  It is used on CPUs on which it is difficult
572 * to generate an "uninitialized" FP context.  It is filled in by
573 * @ref _CPU_Initialize and copied into the task's FP context area during
574 * @ref _CPU_Context_Initialize.
575 *
576 * Port Specific Information:
577 *
578 * XXX document implementation including references if appropriate
579 */
580extern Context_Control_fp _CPU_Null_fp_context;
581
582/** @} */
583
584/**
585 * @defgroup CPUInterrupt Processor Dependent Interrupt Management
586 *
587 * On some CPUs, RTEMS supports a software managed interrupt stack.
588 * This stack is allocated by the Interrupt Manager and the switch
589 * is performed in @ref _ISR_Handler.  These variables contain pointers
590 * to the lowest and highest addresses in the chunk of memory allocated
591 * for the interrupt stack.  Since it is unknown whether the stack
592 * grows up or down (in general), this give the CPU dependent
593 * code the option of picking the version it wants to use.
594 *
595 * NOTE: These two variables are required if the macro
596 *       @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
597 *
598 * Port Specific Information:
599 *
600 * XXX document implementation including references if appropriate
601 */
602
603/*
604 *  Nothing prevents the porter from declaring more CPU specific variables.
605 *
606 *  Port Specific Information:
607 *
608 *  XXX document implementation including references if appropriate
609 */
610
611/* XXX: if needed, put more variables here */
612
613/**
614 * @ingroup CPUContext
615 *
616 * The size of the floating point context area.  On some CPUs this
617 * will not be a "sizeof" because the format of the floating point
618 * area is not defined -- only the size is.  This is usually on
619 * CPUs with a "floating point save context" instruction.
620 *
621 * Port Specific Information:
622 *
623 * XXX document implementation including references if appropriate
624 */
625#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
626
627/**
628 * Amount of extra stack (above minimum stack size) required by
629 * MPCI receive server thread.  Remember that in a multiprocessor
630 * system this thread must exist and be able to process all directives.
631 *
632 * Port Specific Information:
633 *
634 * XXX document implementation including references if appropriate
635 */
636#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
637
638/**
639 * @ingroup CPUInterrupt
640 *
641 * This defines the number of entries in the _ISR_Vector_table managed by RTEMS
642 * in case CPU_SIMPLE_VECTORED_INTERRUPTS is defined to TRUE.  It must be a
643 * compile-time constant.
644 *
645 * It must be undefined in case CPU_SIMPLE_VECTORED_INTERRUPTS is defined to
646 * FALSE.
647 */
648#define CPU_INTERRUPT_NUMBER_OF_VECTORS      32
649
650/**
651 * @ingroup CPUInterrupt
652 *
653 * This defines the highest interrupt vector number for this port in case
654 * CPU_SIMPLE_VECTORED_INTERRUPTS is defined to TRUE.  It must be less than
655 * CPU_INTERRUPT_NUMBER_OF_VECTORS.  It may be not a compile-time constant.
656 *
657 * It must be undefined in case CPU_SIMPLE_VECTORED_INTERRUPTS is defined to
658 * FALSE.
659 */
660#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER  (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
661
662/**
663 * @ingroup CPUInterrupt
664 *
665 * This is defined if the port has a special way to report the ISR nesting
666 * level.  Most ports maintain the variable @a _ISR_Nest_level.
667 */
668#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
669
670/**
671 * @ingroup CPUContext
672 *
673 * Should be large enough to run all RTEMS tests.  This ensures
674 * that a "reasonable" small application should not have any problems.
675 *
676 * Port Specific Information:
677 *
678 * XXX document implementation including references if appropriate
679 */
680#define CPU_STACK_MINIMUM_SIZE          (1024*4)
681
682/**
683 * Size of a pointer.
684 *
685 * This must be an integer literal that can be used by the assembler.  This
686 * value will be used to calculate offsets of structure members.  These
687 * offsets will be used in assembler code.
688 */
689#define CPU_SIZEOF_POINTER         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.  It
694 * must be a power of two greater than or equal to two.  The power of two
695 * requirement makes it possible to align values easily using simple bit
696 * operations.
697 *
698 * Port Specific Information:
699 *
700 * XXX document implementation including references if appropriate
701 */
702#define CPU_ALIGNMENT              8
703
704/**
705 * This number corresponds to the byte alignment requirement for the
706 * heap handler.  This alignment requirement may be stricter than that
707 * for the data types alignment specified by @ref CPU_ALIGNMENT.  It is
708 * common for the heap to follow the same alignment requirement as
709 * @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is strict enough for
710 * the heap, then this should be set to @ref CPU_ALIGNMENT.
711 *
712 * NOTE:  It must be a power of two greater than or equal to two.  The
713 *        requirement to be a multiple of two is because the heap uses the
714 *        least significant field of the front and back flags to indicate that
715 *        a block is in use or free.  So you do not want any odd length blocks
716 *        really putting length data in that bit.
717 *
718 *        On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will
719 *        have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that
720 *        elements allocated from the heap meet all restrictions.
721 *
722 * Port Specific Information:
723 *
724 * XXX document implementation including references if appropriate
725 */
726#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
727
728/**
729 * This number corresponds to the byte alignment requirement for memory
730 * buffers allocated by the partition manager.  This alignment requirement
731 * may be stricter than that for the data types alignment specified by
732 * @ref CPU_ALIGNMENT.  It is common for the partition to follow the same
733 * alignment requirement as @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is
734 * strict enough for the partition, then this should be set to
735 * @ref CPU_ALIGNMENT.
736 *
737 * NOTE:  This does not have to be a power of 2.  It does have to
738 *        be greater or equal to than @ref CPU_ALIGNMENT.
739 *
740 * Port Specific Information:
741 *
742 * XXX document implementation including references if appropriate
743 */
744#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
745
746/**
747 * This number corresponds to the byte alignment requirement for the
748 * stack.  This alignment requirement may be stricter than that for the
749 * data types alignment specified by @ref CPU_ALIGNMENT.  If the
750 * @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
751 * set to 0.
752 *
753 * NOTE: This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
754 *
755 * Port Specific Information:
756 *
757 * XXX document implementation including references if appropriate
758 */
759#define CPU_STACK_ALIGNMENT        0
760
761/*
762 *  ISR handler macros
763 */
764
765/**
766 * @ingroup CPUInterrupt
767 *
768 * Support routine to initialize the RTEMS vector table after it is allocated.
769 *
770 * Port Specific Information:
771 *
772 * XXX document implementation including references if appropriate
773 */
774#define _CPU_Initialize_vectors()
775
776/**
777 * @ingroup CPUInterrupt
778 *
779 * Disable all interrupts for an RTEMS critical section.  The previous
780 * level is returned in @a _isr_cookie.
781 *
782 * @param[out] _isr_cookie will contain the previous level cookie
783 *
784 * Port Specific Information:
785 *
786 * XXX document implementation including references if appropriate
787 */
788#define _CPU_ISR_Disable( _isr_cookie ) \
789  { \
790    (_isr_cookie) = 0;   /* do something to prevent warnings */ \
791  }
792
793/**
794 * @ingroup CPUInterrupt
795 *
796 * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
797 * This indicates the end of an RTEMS critical section.  The parameter
798 * @a _isr_cookie is not modified.
799 *
800 * @param[in] _isr_cookie contain the previous level cookie
801 *
802 * Port Specific Information:
803 *
804 * XXX document implementation including references if appropriate
805 */
806#define _CPU_ISR_Enable( _isr_cookie )  \
807  { \
808  }
809
810/**
811 * @ingroup CPUInterrupt
812 *
813 * This temporarily restores the interrupt to @a _isr_cookie before immediately
814 * disabling them again.  This is used to divide long RTEMS critical
815 * sections into two or more parts.  The parameter @a _isr_cookie is not
816 * modified.
817 *
818 * @param[in] _isr_cookie contain the previous level cookie
819 *
820 * Port Specific Information:
821 *
822 * XXX document implementation including references if appropriate
823 */
824#define _CPU_ISR_Flash( _isr_cookie ) \
825  { \
826  }
827
828/**
829 * @ingroup CPUInterrupt
830 *
831 * This routine and @ref _CPU_ISR_Get_level
832 * Map the interrupt level in task mode onto the hardware that the CPU
833 * actually provides.  Currently, interrupt levels which do not
834 * map onto the CPU in a generic fashion are undefined.  Someday,
835 * it would be nice if these were "mapped" by the application
836 * via a callout.  For example, m68k has 8 levels 0 - 7, levels
837 * 8 - 255 would be available for bsp/application specific meaning.
838 * This could be used to manage a programmable interrupt controller
839 * via the rtems_task_mode directive.
840 *
841 * Port Specific Information:
842 *
843 * XXX document implementation including references if appropriate
844 */
845#define _CPU_ISR_Set_level( new_level ) \
846  { \
847  }
848
849/**
850 * @ingroup CPUInterrupt
851 *
852 * Return the current interrupt disable level for this task in
853 * the format used by the interrupt level portion of the task mode.
854 *
855 * NOTE: This routine usually must be implemented as a subroutine.
856 *
857 * Port Specific Information:
858 *
859 * XXX document implementation including references if appropriate
860 */
861uint32_t   _CPU_ISR_Get_level( void );
862
863/* end of ISR handler macros */
864
865/* Context handler macros */
866
867/**
868 *  @ingroup CPUContext
869 *
870 * Initialize the context to a state suitable for starting a
871 * task after a context restore operation.  Generally, this
872 * involves:
873 *
874 *    - setting a starting address
875 *    - preparing the stack
876 *    - preparing the stack and frame pointers
877 *    - setting the proper interrupt level in the context
878 *    - initializing the floating point context
879 *
880 * This routine generally does not set any unnecessary register
881 * in the context.  The state of the "general data" registers is
882 * undefined at task start time.
883 *
884 * @param[in] _the_context is the context structure to be initialized
885 * @param[in] _stack_base is the lowest physical address of this task's stack
886 * @param[in] _size is the size of this task's stack
887 * @param[in] _isr is the interrupt disable level
888 * @param[in] _entry_point is the thread's entry point.  This is
889 *        always @a _Thread_Handler
890 * @param[in] _is_fp is TRUE if the thread is to be a floating
891 *       point thread.  This is typically only used on CPUs where the
892 *       FPU may be easily disabled by software such as on the SPARC
893 *       where the PSR contains an enable FPU bit.
894 * @param[in] _tls_area The thread-local storage (TLS) area.
895 *
896 * Port Specific Information:
897 *
898 * XXX document implementation including references if appropriate
899 */
900#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
901                                 _isr, _entry_point, _is_fp, _tls_area ) \
902  { \
903  }
904
905/**
906 * This routine is responsible for somehow restarting the currently
907 * executing task.  If you are lucky, then all that is necessary
908 * is restoring the context.  Otherwise, there will need to be
909 * a special assembly routine which does something special in this
910 * case.  For many ports, simply adding a label to the restore path
911 * of @ref _CPU_Context_switch will work.  On other ports, it may be
912 * possibly to load a few arguments and jump to the restore path. It will
913 * not work if restarting self conflicts with the stack frame
914 * assumptions of restoring a context.
915 *
916 * Port Specific Information:
917 *
918 * XXX document implementation including references if appropriate
919 */
920#define _CPU_Context_Restart_self( _the_context ) \
921   _CPU_Context_restore( (_the_context) );
922
923/**
924 * @ingroup CPUContext
925 *
926 * The purpose of this macro is to allow the initial pointer into
927 * a floating point context area (used to save the floating point
928 * context) to be at an arbitrary place in the floating point
929 *context area.
930 *
931 * This is necessary because some FP units are designed to have
932 * their context saved as a stack which grows into lower addresses.
933 * Other FP units can be saved by simply moving registers into offsets
934 * from the base of the context area.  Finally some FP units provide
935 * a "dump context" instruction which could fill in from high to low
936 * or low to high based on the whim of the CPU designers.
937 *
938 * @param[in] _base is the lowest physical address of the floating point
939 *        context area
940 * @param[in] _offset is the offset into the floating point area
941 *
942 * Port Specific Information:
943 *
944 * XXX document implementation including references if appropriate
945 */
946#define _CPU_Context_Fp_start( _base, _offset ) \
947   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
948
949/**
950 * This routine initializes the FP context area passed to it to.
951 * There are a few standard ways in which to initialize the
952 * floating point context.  The code included for this macro assumes
953 * that this is a CPU in which a "initial" FP context was saved into
954 * @a _CPU_Null_fp_context and it simply copies it to the destination
955 * context passed to it.
956 *
957 * Other floating point context save/restore models include:
958 *   -# not doing anything, and
959 *   -# putting a "null FP status word" in the correct place in the FP context.
960 *
961 * @param[in] _destination is the floating point context area
962 *
963 * Port Specific Information:
964 *
965 * XXX document implementation including references if appropriate
966 */
967#define _CPU_Context_Initialize_fp( _destination ) \
968  { \
969   *(*(_destination)) = _CPU_Null_fp_context; \
970  }
971
972/* end of Context handler macros */
973
974/* Fatal Error manager macros */
975
976/**
977 * This routine copies _error into a known place -- typically a stack
978 * location or a register, optionally disables interrupts, and
979 * halts/stops the CPU.
980 *
981 * Port Specific Information:
982 *
983 * XXX document implementation including references if appropriate
984 */
985#define _CPU_Fatal_halt( _source, _error ) \
986  { \
987  }
988
989/* end of Fatal Error manager macros */
990
991/* Bitfield handler macros */
992
993/**
994 * @defgroup CPUBitfield Processor Dependent Bitfield Manipulation
995 *
996 * This set of routines are used to implement fast searches for
997 * the most important ready task.
998 *
999 */
1000/**@{**/
1001
1002/**
1003 * This definition is set to TRUE if the port uses the generic bitfield
1004 * manipulation implementation.
1005 */
1006#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
1007
1008/**
1009 * This definition is set to TRUE if the port uses the data tables provided
1010 * by the generic bitfield manipulation implementation.
1011 * This can occur when actually using the generic bitfield manipulation
1012 * implementation or when implementing the same algorithm in assembly
1013 * language for improved performance.  It is unlikely that a port will use
1014 * the data if it has a bitfield scan instruction.
1015 */
1016#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
1017
1018/**
1019 * This routine sets @a _output to the bit number of the first bit
1020 * set in @a _value.  @a _value is of CPU dependent type
1021 * @a Priority_bit_map_Word.  This type may be either 16 or 32 bits
1022 * wide although only the 16 least significant bits will be used.
1023 *
1024 * There are a number of variables in using a "find first bit" type
1025 * instruction.
1026 *
1027 *   -# What happens when run on a value of zero?
1028 *   -# Bits may be numbered from MSB to LSB or vice-versa.
1029 *   -# The numbering may be zero or one based.
1030 *   -# The "find first bit" instruction may search from MSB or LSB.
1031 *
1032 * RTEMS guarantees that (1) will never happen so it is not a concern.
1033 * (2),(3), (4) are handled by the macros @ref _CPU_Priority_Mask and
1034 * @ref _CPU_Priority_bits_index.  These three form a set of routines
1035 * which must logically operate together.  Bits in the _value are
1036 * set and cleared based on masks built by @ref _CPU_Priority_Mask.
1037 * The basic major and minor values calculated by @ref _Priority_Major
1038 * and @ref _Priority_Minor are "massaged" by @ref _CPU_Priority_bits_index
1039 * to properly range between the values returned by the "find first bit"
1040 * instruction.  This makes it possible for @ref _Priority_Get_highest to
1041 * calculate the major and directly index into the minor table.
1042 * This mapping is necessary to ensure that 0 (a high priority major/minor)
1043 * is the first bit found.
1044 *
1045 * This entire "find first bit" and mapping process depends heavily
1046 * on the manner in which a priority is broken into a major and minor
1047 * components with the major being the 4 MSB of a priority and minor
1048 * the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
1049 * priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
1050 * to the lowest priority.
1051 *
1052 * If your CPU does not have a "find first bit" instruction, then
1053 * there are ways to make do without it.  Here are a handful of ways
1054 * to implement this in software:
1055 *
1056@verbatim
1057      - a series of 16 bit test instructions
1058      - a "binary search using if's"
1059      - _number = 0
1060        if _value > 0x00ff
1061          _value >>=8
1062          _number = 8;
1063
1064        if _value > 0x0000f
1065          _value >=8
1066          _number += 4
1067
1068        _number += bit_set_table[ _value ]
1069@endverbatim
1070
1071 *   where bit_set_table[ 16 ] has values which indicate the first
1072 *     bit set
1073 *
1074 * @param[in] _value is the value to be scanned
1075 * @param[in] _output is the first bit set
1076 *
1077 * Port Specific Information:
1078 *
1079 * XXX document implementation including references if appropriate
1080 */
1081
1082#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1083#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
1084  { \
1085    (_output) = 0;   /* do something to prevent warnings */ \
1086  }
1087#endif
1088
1089/** @} */
1090
1091/* end of Bitfield handler macros */
1092
1093/**
1094 * This routine builds the mask which corresponds to the bit fields
1095 * as searched by @ref _CPU_Bitfield_Find_first_bit.  See the discussion
1096 * for that routine.
1097 *
1098 * Port Specific Information:
1099 *
1100 * XXX document implementation including references if appropriate
1101 */
1102#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1103
1104#define _CPU_Priority_Mask( _bit_number ) \
1105  ( 1 << (_bit_number) )
1106
1107#endif
1108
1109/**
1110 * @ingroup CPUBitfield
1111 *
1112 * This routine translates the bit numbers returned by
1113 * @ref _CPU_Bitfield_Find_first_bit into something suitable for use as
1114 * a major or minor component of a priority.  See the discussion
1115 * for that routine.
1116 *
1117 * @param[in] _priority is the major or minor number to translate
1118 *
1119 * Port Specific Information:
1120 *
1121 * XXX document implementation including references if appropriate
1122 */
1123#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1124
1125#define _CPU_Priority_bits_index( _priority ) \
1126  (_priority)
1127
1128#endif
1129
1130/* end of Priority handler macros */
1131
1132/* functions */
1133
1134/**
1135 * This routine performs CPU dependent initialization.
1136 *
1137 * Port Specific Information:
1138 *
1139 * XXX document implementation including references if appropriate
1140 */
1141void _CPU_Initialize(void);
1142
1143/**
1144 * @ingroup CPUInterrupt
1145 *
1146 * This routine installs a "raw" interrupt handler directly into the
1147 * processor's vector table.
1148 *
1149 * @param[in] vector is the vector number
1150 * @param[in] new_handler is the raw ISR handler to install
1151 * @param[in] old_handler is the previously installed ISR Handler
1152 *
1153 * Port Specific Information:
1154 *
1155 * XXX document implementation including references if appropriate
1156 */
1157void _CPU_ISR_install_raw_handler(
1158  uint32_t    vector,
1159  proc_ptr    new_handler,
1160  proc_ptr   *old_handler
1161);
1162
1163/**
1164 * @ingroup CPUInterrupt
1165 *
1166 * This routine installs an interrupt vector.
1167 *
1168 * @param[in] vector is the vector number
1169 * @param[in] new_handler is the RTEMS ISR handler to install
1170 * @param[in] old_handler is the previously installed ISR Handler
1171 *
1172 * Port Specific Information:
1173 *
1174 * XXX document implementation including references if appropriate
1175 */
1176void _CPU_ISR_install_vector(
1177  uint32_t    vector,
1178  proc_ptr    new_handler,
1179  proc_ptr   *old_handler
1180);
1181
1182/**
1183 * @ingroup CPUInterrupt
1184 * This routine installs the hardware interrupt stack pointer.
1185 *
1186 * NOTE:  It need only be provided if @ref CPU_HAS_HARDWARE_INTERRUPT_STACK
1187 *        is TRUE.
1188 *
1189 * Port Specific Information:
1190 *
1191 * XXX document implementation including references if appropriate
1192 */
1193void _CPU_Install_interrupt_stack( void );
1194
1195/**
1196 * This routine is the CPU dependent IDLE thread body.
1197 *
1198 * NOTE:  It need only be provided if @ref CPU_PROVIDES_IDLE_THREAD_BODY
1199 *         is TRUE.
1200 *
1201 * Port Specific Information:
1202 *
1203 * XXX document implementation including references if appropriate
1204 */
1205void *_CPU_Thread_Idle_body( uintptr_t ignored );
1206
1207/**
1208 * @ingroup CPUContext
1209 *
1210 * This routine switches from the run context to the heir context.
1211 *
1212 * @param[in] run points to the context of the currently executing task
1213 * @param[in] heir points to the context of the heir task
1214 *
1215 * Port Specific Information:
1216 *
1217 * XXX document implementation including references if appropriate
1218 */
1219void _CPU_Context_switch(
1220  Context_Control  *run,
1221  Context_Control  *heir
1222);
1223
1224/**
1225 * @ingroup CPUContext
1226 *
1227 * This routine is generally used only to restart self in an
1228 * efficient manner.  It may simply be a label in @ref _CPU_Context_switch.
1229 *
1230 * @param[in] new_context points to the context to be restored.
1231 *
1232 * NOTE: May be unnecessary to reload some registers.
1233 *
1234 * Port Specific Information:
1235 *
1236 * XXX document implementation including references if appropriate
1237 */
1238void _CPU_Context_restore(
1239  Context_Control *new_context
1240) RTEMS_NO_RETURN;
1241
1242/**
1243 * @ingroup CPUContext
1244 *
1245 * This routine saves the floating point context passed to it.
1246 *
1247 * @param[in] fp_context_ptr is a pointer to a pointer to a floating
1248 * point context area
1249 *
1250 * @return on output @a *fp_context_ptr will contain the address that
1251 * should be used with @ref _CPU_Context_restore_fp to restore this context.
1252 *
1253 * Port Specific Information:
1254 *
1255 * XXX document implementation including references if appropriate
1256 */
1257void _CPU_Context_save_fp(
1258  Context_Control_fp **fp_context_ptr
1259);
1260
1261/**
1262 * @ingroup CPUContext
1263 *
1264 * This routine restores the floating point context passed to it.
1265 *
1266 * @param[in] fp_context_ptr is a pointer to a pointer to a floating
1267 * point context area to restore
1268 *
1269 * @return on output @a *fp_context_ptr will contain the address that
1270 * should be used with @ref _CPU_Context_save_fp to save this context.
1271 *
1272 * Port Specific Information:
1273 *
1274 * XXX document implementation including references if appropriate
1275 */
1276void _CPU_Context_restore_fp(
1277  Context_Control_fp **fp_context_ptr
1278);
1279
1280/**
1281 * @ingroup CPUContext
1282 *
1283 * @brief Clobbers all volatile registers with values derived from the pattern
1284 * parameter.
1285 *
1286 * This function is used only in test sptests/spcontext01.
1287 *
1288 * @param[in] pattern Pattern used to generate distinct register values.
1289 *
1290 * @see _CPU_Context_validate().
1291 */
1292void _CPU_Context_volatile_clobber( uintptr_t pattern );
1293
1294/**
1295 * @ingroup CPUContext
1296 *
1297 * @brief Initializes and validates the CPU context with values derived from
1298 * the pattern parameter.
1299 *
1300 * This function will not return if the CPU context remains consistent.  In
1301 * case this function returns the CPU port is broken.
1302 *
1303 * This function is used only in test sptests/spcontext01.
1304 *
1305 * @param[in] pattern Pattern used to generate distinct register values.
1306 *
1307 * @see _CPU_Context_volatile_clobber().
1308 */
1309void _CPU_Context_validate( uintptr_t pattern );
1310
1311/**
1312 * @brief The set of registers that specifies the complete processor state.
1313 *
1314 * The CPU exception frame may be available in fatal error conditions like for
1315 * example illegal opcodes, instruction fetch errors, or data access errors.
1316 *
1317 * @see rtems_fatal(), RTEMS_FATAL_SOURCE_EXCEPTION, and
1318 * rtems_exception_frame_print().
1319 */
1320typedef struct {
1321  uint32_t processor_state_register;
1322  uint32_t integer_registers [1];
1323  double float_registers [1];
1324} CPU_Exception_frame;
1325
1326/**
1327 * @brief Prints the exception frame via printk().
1328 *
1329 * @see rtems_fatal() and RTEMS_FATAL_SOURCE_EXCEPTION.
1330 */
1331void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
1332
1333/**
1334 * @ingroup CPUEndian
1335 *
1336 * The following routine swaps the endian format of an unsigned int.
1337 * It must be static because it is referenced indirectly.
1338 *
1339 * This version will work on any processor, but if there is a better
1340 * way for your CPU PLEASE use it.  The most common way to do this is to:
1341 *
1342 *    swap least significant two bytes with 16-bit rotate
1343 *    swap upper and lower 16-bits
1344 *    swap most significant two bytes with 16-bit rotate
1345 *
1346 * Some CPUs have special instructions which swap a 32-bit quantity in
1347 * a single instruction (e.g. i486).  It is probably best to avoid
1348 * an "endian swapping control bit" in the CPU.  One good reason is
1349 * that interrupts would probably have to be disabled to ensure that
1350 * an interrupt does not try to access the same "chunk" with the wrong
1351 * endian.  Another good reason is that on some CPUs, the endian bit
1352 * endianness for ALL fetches -- both code and data -- so the code
1353 * will be fetched incorrectly.
1354 *
1355 * @param[in] value is the value to be swapped
1356 * @return the value after being endian swapped
1357 *
1358 * Port Specific Information:
1359 *
1360 * XXX document implementation including references if appropriate
1361 */
1362static inline uint32_t CPU_swap_u32(
1363  uint32_t value
1364)
1365{
1366  uint32_t byte1, byte2, byte3, byte4, swapped;
1367
1368  byte4 = (value >> 24) & 0xff;
1369  byte3 = (value >> 16) & 0xff;
1370  byte2 = (value >> 8)  & 0xff;
1371  byte1 =  value        & 0xff;
1372
1373  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
1374  return swapped;
1375}
1376
1377/**
1378 * @ingroup CPUEndian
1379 *
1380 * This routine swaps a 16 bir quantity.
1381 *
1382 * @param[in] value is the value to be swapped
1383 * @return the value after being endian swapped
1384 */
1385#define CPU_swap_u16( value ) \
1386  (((value&0xff) << 8) | ((value >> 8)&0xff))
1387
1388/**
1389 * @brief Unsigned integer type for CPU counter values.
1390 */
1391typedef uint32_t CPU_Counter_ticks;
1392
1393/**
1394 * @brief Returns the current CPU counter value.
1395 *
1396 * A CPU counter is some free-running counter.  It ticks usually with a
1397 * frequency close to the CPU or system bus clock.  The board support package
1398 * must ensure that this function works before the RTEMS initialization.
1399 * Otherwise invalid profiling statistics will be gathered.
1400 *
1401 * @return The current CPU counter value.
1402 */
1403CPU_Counter_ticks _CPU_Counter_read( void );
1404
1405/**
1406 * @brief Returns the difference between the second and first CPU counter
1407 * value.
1408 *
1409 * This operation may be carried out as a modulo operation depending on the
1410 * range of the CPU counter device.
1411 *
1412 * @param[in] second The second CPU counter value.
1413 * @param[in] first The first CPU counter value.
1414 *
1415 * @return Returns second minus first modulo counter period.
1416 */
1417CPU_Counter_ticks _CPU_Counter_difference(
1418  CPU_Counter_ticks second,
1419  CPU_Counter_ticks first
1420);
1421
1422/**
1423 * @brief Special register pointing to the per-CPU control of the current
1424 * processor.
1425 *
1426 * This is optional.  Not every CPU port needs this.  It is only an optional
1427 * optimization variant.
1428 */
1429register struct Per_CPU_Control *_CPU_Per_CPU_current asm( "rX" );
1430
1431/**
1432 * @brief Optional method to obtain the per-CPU control of the current processor.
1433 *
1434 * This is optional.  Not every CPU port needs this.  It is only an optional
1435 * optimization variant.  In case this macro is undefined, the default
1436 * implementation using the current processor index will be used.
1437 */
1438#define _CPU_Get_current_per_CPU_control() ( _CPU_Per_CPU_current )
1439
1440#ifdef RTEMS_SMP
1441  /**
1442   * @brief Performs CPU specific SMP initialization in the context of the boot
1443   * processor.
1444   *
1445   * This function is invoked on the boot processor during system
1446   * initialization.  All interrupt stacks are allocated at this point in case
1447   * the CPU port allocates the interrupt stacks.  This function is called
1448   * before _CPU_SMP_Start_processor() or _CPU_SMP_Finalize_initialization() is
1449   * used.
1450   *
1451   * @return The count of physically or virtually available processors.
1452   * Depending on the configuration the application may use not all processors.
1453   */
1454  uint32_t _CPU_SMP_Initialize( void );
1455
1456  /**
1457   * @brief Starts a processor specified by its index.
1458   *
1459   * This function is invoked on the boot processor during system
1460   * initialization.
1461   *
1462   * This function will be called after _CPU_SMP_Initialize().
1463   *
1464   * @param[in] cpu_index The processor index.
1465   *
1466   * @retval true Successful operation.
1467   * @retval false Unable to start this processor.
1468   */
1469  bool _CPU_SMP_Start_processor( uint32_t cpu_index );
1470
1471  /**
1472   * @brief Performs final steps of CPU specific SMP initialization in the
1473   * context of the boot processor.
1474   *
1475   * This function is invoked on the boot processor during system
1476   * initialization.
1477   *
1478   * This function will be called after all processors requested by the
1479   * application have been started.
1480   *
1481   * @param[in] cpu_count The minimum value of the count of processors
1482   * requested by the application configuration and the count of physically or
1483   * virtually available processors.
1484   */
1485  void _CPU_SMP_Finalize_initialization( uint32_t cpu_count );
1486
1487  /**
1488   * @brief Prepares a CPU to start multitasking in terms of SMP.
1489   *
1490   * This function is invoked on all processors requested by the application
1491   * during system initialization.
1492   *
1493   * This function will be called after all processors requested by the
1494   * application have been started right before the context switch to the first
1495   * thread takes place.
1496   */
1497  void _CPU_SMP_Prepare_start_multitasking( void );
1498
1499  /**
1500   * @brief Returns the index of the current processor.
1501   *
1502   * An architecture specific method must be used to obtain the index of the
1503   * current processor in the system.  The set of processor indices is the
1504   * range of integers starting with zero up to the processor count minus one.
1505   */
1506  static inline uint32_t _CPU_SMP_Get_current_processor( void )
1507  {
1508    return 123;
1509  }
1510
1511  /**
1512   * @brief Sends an inter-processor interrupt to the specified target
1513   * processor.
1514   *
1515   * This interrupt send and the corresponding inter-processor interrupt must
1516   * act as an release/acquire barrier so that all values written by the
1517   * sending processor are visible to the target processor.
1518   *
1519   * This operation is undefined for target processor indices out of range.
1520   *
1521   * @param[in] target_processor_index The target processor index.
1522   */
1523  void _CPU_SMP_Send_interrupt( uint32_t target_processor_index );
1524
1525  /**
1526   * @brief Broadcasts a processor event.
1527   *
1528   * Some architectures provide a low-level synchronization primitive for
1529   * processors in a multi-processor environment.  Processors waiting for this
1530   * event may go into a low-power state and stop generating system bus
1531   * transactions.  This function must ensure that preceding store operations
1532   * can be observed by other processors.
1533   *
1534   * @see _CPU_SMP_Processor_event_receive().
1535   */
1536  static inline void _CPU_SMP_Processor_event_broadcast( void )
1537  {
1538    __asm__ volatile ( "" : : : "memory" );
1539  }
1540
1541  /**
1542   * @brief Receives a processor event.
1543   *
1544   * This function will wait for the processor event and may wait forever if no
1545   * such event arrives.
1546   *
1547   * @see _CPU_SMP_Processor_event_broadcast().
1548   */
1549  static inline void _CPU_SMP_Processor_event_receive( void )
1550  {
1551    __asm__ volatile ( "" : : : "memory" );
1552  }
1553
1554  /**
1555   * @brief Gets the is executing indicator of the thread context.
1556   *
1557   * @param[in] context The context.
1558   */
1559  static inline bool _CPU_Context_Get_is_executing(
1560    const Context_Control *context
1561  )
1562  {
1563    return context->is_executing;
1564  }
1565
1566  /**
1567   * @brief Sets the is executing indicator of the thread context.
1568   *
1569   * @param[in] context The context.
1570   * @param[in] is_executing The new value for the is executing indicator.
1571   */
1572  static inline void _CPU_Context_Set_is_executing(
1573    Context_Control *context,
1574    bool is_executing
1575  )
1576  {
1577    context->is_executing = is_executing;
1578  }
1579#endif
1580
1581#ifdef __cplusplus
1582}
1583#endif
1584
1585#endif
Note: See TracBrowser for help on using the repository browser.