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

Last change on this file since d7a48e1 was d7a48e1, checked in by Sebastian Huber <sebastian.huber@…>, on 10/06/20 at 05:39:44

rtems: Improve RTEMS_NO_RETURN attribute

Provide RTEMS_NO_RETURN also in case RTEMS_DEBUG is defined to prevent errors
like this:

error: no return statement in function returning non-void [-Werror=return-type]

Use C11 and C++11 standard means to declare a no-return function.

Close #4122.

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