source: rtems/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h @ 48dd7b8c

Last change on this file since 48dd7b8c was 48dd7b8c, checked in by Kinsey Moore <kinsey.moore@…>, on 06/29/20 at 19:35:08

score: Add CPU_USE_LIBC_INIT_FINI_ARRAY

This introduces the CPU_USE_LIBC_INIT_FINI_ARRAY define for use by CPU
ports to determine which global constructor and destructor methods are
used instead of placing architecture defines where they shouldn't be.

Close #4018

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