source: rtems/cpukit/score/cpu/bfin/rtems/score/cpu.h @ 4ef13360

4.115
Last change on this file since 4ef13360 was 4ef13360, checked in by Joel Sherrill <joel.sherrill@…>, on 07/29/10 at 17:51:56

2010-07-29 Gedare Bloom <giddyup44@…>

PR 1635/cpukit

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