source: rtems-schedsim/schedsim/rtems/sched_cpu/rtems/score/cpu.h @ 66f2b7f

Last change on this file since 66f2b7f was b38dbcc, checked in by Joel Sherrill <joel.sherrill@…>, on 05/14/14 at 14:55:21

Many files: rm white space at EOL and EOF

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