source: rtems/cpukit/score/cpu/bfin/rtems/score/cpu.h @ 89b85e51

4.115
Last change on this file since 89b85e51 was 89b85e51, checked in by Sebastian Huber <sebastian.huber@…>, on 07/16/10 at 08:46:29

2010-07-16 Sebastian Huber <sebastian.huber@…>

  • rtems/score/cpu.h: Include <rtems/score/types.h> first.
  • rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
  • 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/**
462 *  @ingroup CPUContext Management
463 *  This defines the minimal set of integer and processor state registers
464 *  that must be saved during a voluntary context switch from one thread
465 *  to another.
466 */
467
468/* make sure this stays in sync with the assembly function
469   __CPU_Context_switch in cpu_asm.S  */
470typedef struct {
471    uint32_t   register_r4;
472    uint32_t   register_r5;
473    uint32_t   register_r6;
474    uint32_t   register_r7;
475
476    uint32_t   register_p3;
477    uint32_t   register_p4;
478    uint32_t   register_p5;
479    uint32_t   register_fp;
480    uint32_t   register_sp;
481
482    uint32_t   register_rets;
483
484    uint32_t   imask;
485} Context_Control;
486
487#define _CPU_Context_Get_SP( _context ) \
488  (_context)->register_sp
489
490/**
491 *  @ingroup CPUContext Management
492 *  This defines the complete set of floating point registers that must
493 *  be saved during any context switch from one thread to another.
494 */
495typedef struct {
496    /* FPU registers are listed here */
497    /* Blackfin has no Floating Point */
498} Context_Control_fp;
499
500/**
501 *  @ingroup CPUContext Management
502 *  This defines the set of integer and processor state registers that must
503 *  be saved during an interrupt.  This set does not include any which are
504 *  in @ref Context_Control.
505 */
506typedef struct {
507    /** This field is a hint that a port will have a number of integer
508     *  registers that need to be saved when an interrupt occurs or
509     *  when a context switch occurs at the end of an ISR.
510     */
511    /*uint32_t   special_interrupt_register;*/
512} CPU_Interrupt_frame;
513
514/**
515 *  This variable is optional.  It is used on CPUs on which it is difficult
516 *  to generate an "uninitialized" FP context.  It is filled in by
517 *  @ref _CPU_Initialize and copied into the task's FP context area during
518 *  @ref _CPU_Context_Initialize.
519 *
520 *  Port Specific Information:
521 *
522 *  XXX document implementation including references if appropriate
523 */
524SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
525
526/**
527 *  @defgroup CPUInterrupt Processor Dependent Interrupt Management
528 *
529 *  On some CPUs, RTEMS supports a software managed interrupt stack.
530 *  This stack is allocated by the Interrupt Manager and the switch
531 *  is performed in @ref _ISR_Handler.  These variables contain pointers
532 *  to the lowest and highest addresses in the chunk of memory allocated
533 *  for the interrupt stack.  Since it is unknown whether the stack
534 *  grows up or down (in general), this give the CPU dependent
535 *  code the option of picking the version it wants to use.
536 *
537 *  @note These two variables are required if the macro
538 *        @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
539 *
540 *  Port Specific Information:
541 *
542 *  XXX document implementation including references if appropriate
543 */
544
545/*
546 *  Nothing prevents the porter from declaring more CPU specific variables.
547 *
548 *  Port Specific Information:
549 *
550 *  XXX document implementation including references if appropriate
551 */
552
553/* XXX: if needed, put more variables here */
554
555/**
556 *  @ingroup CPUContext
557 *  The size of the floating point context area.  On some CPUs this
558 *  will not be a "sizeof" because the format of the floating point
559 *  area is not defined -- only the size is.  This is usually on
560 *  CPUs with a "floating point save context" instruction.
561 *
562 *  Port Specific Information:
563 *
564 *  XXX document implementation including references if appropriate
565 */
566#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
567
568/**
569 *  Amount of extra stack (above minimum stack size) required by
570 *  MPCI receive server thread.  Remember that in a multiprocessor
571 *  system this thread must exist and be able to process all directives.
572 *
573 *  Port Specific Information:
574 *
575 *  XXX document implementation including references if appropriate
576 */
577#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
578
579/**
580 *  @ingroup CPUInterrupt
581 *  This defines the number of entries in the @ref _ISR_Vector_table managed
582 *  by RTEMS.
583 *
584 *  Port Specific Information:
585 *
586 *  XXX document implementation including references if appropriate
587 */
588#define CPU_INTERRUPT_NUMBER_OF_VECTORS      16
589
590/**
591 *  @ingroup CPUInterrupt
592 *  This defines the highest interrupt vector number for this port.
593 */
594#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER  (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
595
596/**
597 *  @ingroup CPUInterrupt
598 *  This is defined if the port has a special way to report the ISR nesting
599 *  level.  Most ports maintain the variable @a _ISR_Nest_level.
600 */
601#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
602
603/**
604 *  @ingroup CPUContext
605 *  Should be large enough to run all RTEMS tests.  This ensures
606 *  that a "reasonable" small application should not have any problems.
607 *
608 *  Port Specific Information:
609 *
610 *  XXX document implementation including references if appropriate
611 */
612#define CPU_STACK_MINIMUM_SIZE          (1024*4)
613
614/**
615 *  CPU's worst alignment requirement for data types on a byte boundary.  This
616 *  alignment does not take into account the requirements for the stack.
617 *
618 *  Port Specific Information:
619 *
620 *  XXX document implementation including references if appropriate
621 */
622#define CPU_ALIGNMENT              8
623
624/**
625 *  This number corresponds to the byte alignment requirement for the
626 *  heap handler.  This alignment requirement may be stricter than that
627 *  for the data types alignment specified by @ref CPU_ALIGNMENT.  It is
628 *  common for the heap to follow the same alignment requirement as
629 *  @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is strict enough for
630 *  the heap, then this should be set to @ref CPU_ALIGNMENT.
631 *
632 *  @note  This does not have to be a power of 2 although it should be
633 *         a multiple of 2 greater than or equal to 2.  The requirement
634 *         to be a multiple of 2 is because the heap uses the least
635 *         significant field of the front and back flags to indicate
636 *         that a block is in use or free.  So you do not want any odd
637 *         length blocks really putting length data in that bit.
638 *
639 *         On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will
640 *         have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that
641 *         elements allocated from the heap meet all restrictions.
642 *
643 *  Port Specific Information:
644 *
645 *  XXX document implementation including references if appropriate
646 */
647#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
648
649/**
650 *  This number corresponds to the byte alignment requirement for memory
651 *  buffers allocated by the partition manager.  This alignment requirement
652 *  may be stricter than that for the data types alignment specified by
653 *  @ref CPU_ALIGNMENT.  It is common for the partition to follow the same
654 *  alignment requirement as @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is
655 *  strict enough for the partition, then this should be set to
656 *  @ref CPU_ALIGNMENT.
657 *
658 *  @note  This does not have to be a power of 2.  It does have to
659 *         be greater or equal to than @ref CPU_ALIGNMENT.
660 *
661 *  Port Specific Information:
662 *
663 *  XXX document implementation including references if appropriate
664 */
665#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
666
667/**
668 *  This number corresponds to the byte alignment requirement for the
669 *  stack.  This alignment requirement may be stricter than that for the
670 *  data types alignment specified by @ref CPU_ALIGNMENT.  If the
671 *  @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
672 *  set to 0.
673 *
674 *  @note This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
675 *
676 *  Port Specific Information:
677 *
678 *  XXX document implementation including references if appropriate
679 */
680#define CPU_STACK_ALIGNMENT        0
681
682/*
683 *  ISR handler macros
684 */
685
686/**
687 *  @ingroup CPUInterrupt
688 *  Support routine to initialize the RTEMS vector table after it is allocated.
689 *
690 *  Port Specific Information:
691 *
692 *  XXX document implementation including references if appropriate
693 */
694#define _CPU_Initialize_vectors()
695
696/**
697 *  @ingroup CPUInterrupt
698 *  Disable all interrupts for an RTEMS critical section.  The previous
699 *  level is returned in @a _isr_cookie.
700 *
701 *  @param[out] _isr_cookie will contain the previous level cookie
702 *
703 *  Port Specific Information:
704 *
705 *  XXX document implementation including references if appropriate
706 */
707#define _CPU_ISR_Disable( _level ) \
708  {                                     \
709       asm volatile ("cli %0; csync \n" : "=d" (_level) );     \
710  }
711
712
713/**
714 *  @ingroup CPUInterrupt
715 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
716 *  This indicates the end of an RTEMS critical section.  The parameter
717 *  @a _isr_cookie is not modified.
718 *
719 *  @param[in] _isr_cookie contain the previous level cookie
720 *
721 *  Port Specific Information:
722 *
723 *  XXX document implementation including references if appropriate
724 */
725#define _CPU_ISR_Enable( _level ) { \
726    __asm__ __volatile__ ("sti %0; csync \n" : : "d" (_level) );   \
727  }
728
729/**
730 *  @ingroup CPUInterrupt
731 *  This temporarily restores the interrupt to @a _isr_cookie before immediately
732 *  disabling them again.  This is used to divide long RTEMS critical
733 *  sections into two or more parts.  The parameter @a _isr_cookie is not
734 *  modified.
735 *
736 *  @param[in] _isr_cookie contain the previous level cookie
737 *
738 *  Port Specific Information:
739 *
740 *  XXX document implementation including references if appropriate
741 */
742#define _CPU_ISR_Flash( _level ) { \
743    __asm__ __volatile__ ("sti %0; csync; cli r0; csync" \
744                          : : "d"(_level) : "R0" ); \
745  }
746
747/**
748 *  @ingroup CPUInterrupt
749 *
750 *  This routine and @ref _CPU_ISR_Get_level
751 *  Map the interrupt level in task mode onto the hardware that the CPU
752 *  actually provides.  Currently, interrupt levels which do not
753 *  map onto the CPU in a generic fashion are undefined.  Someday,
754 *  it would be nice if these were "mapped" by the application
755 *  via a callout.  For example, m68k has 8 levels 0 - 7, levels
756 *  8 - 255 would be available for bsp/application specific meaning.
757 *  This could be used to manage a programmable interrupt controller
758 *  via the rtems_task_mode directive.
759 *
760 *  Port Specific Information:
761 *
762 *  XXX document implementation including references if appropriate
763 */
764#define _CPU_ISR_Set_level( _new_level ) \
765  { \
766    __asm__ __volatile__ ( "sti %0; csync" : : "d"(_new_level ? 0 : 0xffff) ); \
767  }
768
769
770/**
771 *  @ingroup CPUInterrupt
772 *  Return the current interrupt disable level for this task in
773 *  the format used by the interrupt level portion of the task mode.
774 *
775 *  @note This routine usually must be implemented as a subroutine.
776 *
777 *  Port Specific Information:
778 *
779 *  XXX document implementation including references if appropriate
780 */
781uint32_t   _CPU_ISR_Get_level( void );
782
783/* end of ISR handler macros */
784
785/* Context handler macros */
786
787/**
788 *  @ingroup CPUContext
789 *  Initialize the context to a state suitable for starting a
790 *  task after a context restore operation.  Generally, this
791 *  involves:
792 *
793 *     - setting a starting address
794 *     - preparing the stack
795 *     - preparing the stack and frame pointers
796 *     - setting the proper interrupt level in the context
797 *     - initializing the floating point context
798 *
799 *  This routine generally does not set any unnecessary register
800 *  in the context.  The state of the "general data" registers is
801 *  undefined at task start time.
802 *
803 *  @param[in] _the_context is the context structure to be initialized
804 *  @param[in] _stack_base is the lowest physical address of this task's stack
805 *  @param[in] _size is the size of this task's stack
806 *  @param[in] _isr is the interrupt disable level
807 *  @param[in] _entry_point is the thread's entry point.  This is
808 *         always @a _Thread_Handler
809 *  @param[in] _is_fp is TRUE if the thread is to be a floating
810 *        point thread.  This is typically only used on CPUs where the
811 *        FPU may be easily disabled by software such as on the SPARC
812 *        where the PSR contains an enable FPU bit.
813 *
814 *  Port Specific Information:
815 *
816 *  See implementation in cpu.c
817 */
818void _CPU_Context_Initialize(
819  Context_Control  *the_context,
820  uint32_t         *stack_base,
821  uint32_t          size,
822  uint32_t          new_level,
823  void             *entry_point,
824  bool              is_fp
825);
826
827/**
828 *  This routine is responsible for somehow restarting the currently
829 *  executing task.  If you are lucky, then all that is necessary
830 *  is restoring the context.  Otherwise, there will need to be
831 *  a special assembly routine which does something special in this
832 *  case.  For many ports, simply adding a label to the restore path
833 *  of @ref _CPU_Context_switch will work.  On other ports, it may be
834 *  possibly to load a few arguments and jump to the restore path. It will
835 *  not work if restarting self conflicts with the stack frame
836 *  assumptions of restoring a context.
837 *
838 *  Port Specific Information:
839 *
840 *  XXX document implementation including references if appropriate
841 */
842#define _CPU_Context_Restart_self( _the_context ) \
843   _CPU_Context_restore( (_the_context) );
844
845/**
846 *  @ingroup CPUContext
847 *  The purpose of this macro is to allow the initial pointer into
848 *  a floating point context area (used to save the floating point
849 *  context) to be at an arbitrary place in the floating point
850 *  context area.
851 *
852 *  This is necessary because some FP units are designed to have
853 *  their context saved as a stack which grows into lower addresses.
854 *  Other FP units can be saved by simply moving registers into offsets
855 *  from the base of the context area.  Finally some FP units provide
856 *  a "dump context" instruction which could fill in from high to low
857 *  or low to high based on the whim of the CPU designers.
858 *
859 *  @param[in] _base is the lowest physical address of the floating point
860 *         context area
861 *  @param[in] _offset is the offset into the floating point area
862 *
863 *  Port Specific Information:
864 *
865 *  XXX document implementation including references if appropriate
866 */
867#define _CPU_Context_Fp_start( _base, _offset ) \
868   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
869
870/**
871 *  This routine initializes the FP context area passed to it to.
872 *  There are a few standard ways in which to initialize the
873 *  floating point context.  The code included for this macro assumes
874 *  that this is a CPU in which a "initial" FP context was saved into
875 *  @a _CPU_Null_fp_context and it simply copies it to the destination
876 *  context passed to it.
877 *
878 *  Other floating point context save/restore models include:
879 *    -# not doing anything, and
880 *    -# putting a "null FP status word" in the correct place in the FP context.
881 *
882 *  @param[in] _destination is the floating point context area
883 *
884 *  Port Specific Information:
885 *
886 *  XXX document implementation including references if appropriate
887 */
888#define _CPU_Context_Initialize_fp( _destination ) \
889  { \
890   *(*(_destination)) = _CPU_Null_fp_context; \
891  }
892
893/* end of Context handler macros */
894
895/* Fatal Error manager macros */
896
897/**
898 *  This routine copies _error into a known place -- typically a stack
899 *  location or a register, optionally disables interrupts, and
900 *  halts/stops the CPU.
901 *
902 *  Port Specific Information:
903 *
904 *  XXX document implementation including references if appropriate
905 */
906#define _CPU_Fatal_halt( _error ) \
907  { \
908    asm volatile ( "cli R1; \
909                    R1 = %0; \
910                    _halt: \
911                    idle; \
912                    jump _halt;"\
913                    : : "r" (_error) ); \
914  }
915
916/* end of Fatal Error manager macros */
917
918/* Bitfield handler macros */
919
920/**
921 *  @defgroup CPUBitfield Processor Dependent Bitfield Manipulation
922 *
923 *  This set of routines are used to implement fast searches for
924 *  the most important ready task.
925 */
926
927/**
928 *  @ingroup CPUBitfield
929 *  This definition is set to TRUE if the port uses the generic bitfield
930 *  manipulation implementation.
931 */
932#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
933
934/**
935 *  @ingroup CPUBitfield
936 *  This definition is set to TRUE if the port uses the data tables provided
937 *  by the generic bitfield manipulation implementation.
938 *  This can occur when actually using the generic bitfield manipulation
939 *  implementation or when implementing the same algorithm in assembly
940 *  language for improved performance.  It is unlikely that a port will use
941 *  the data if it has a bitfield scan instruction.
942 */
943#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
944
945/**
946 *  @ingroup CPUBitfield
947 *  This routine sets @a _output to the bit number of the first bit
948 *  set in @a _value.  @a _value is of CPU dependent type
949 *  @a Priority_Bit_map_control.  This type may be either 16 or 32 bits
950 *  wide although only the 16 least significant bits will be used.
951 *
952 *  There are a number of variables in using a "find first bit" type
953 *  instruction.
954 *
955 *    -# What happens when run on a value of zero?
956 *    -# Bits may be numbered from MSB to LSB or vice-versa.
957 *    -# The numbering may be zero or one based.
958 *    -# The "find first bit" instruction may search from MSB or LSB.
959 *
960 *  RTEMS guarantees that (1) will never happen so it is not a concern.
961 *  (2),(3), (4) are handled by the macros @ref _CPU_Priority_Mask and
962 *  @ref _CPU_Priority_bits_index.  These three form a set of routines
963 *  which must logically operate together.  Bits in the _value are
964 *  set and cleared based on masks built by @ref _CPU_Priority_Mask.
965 *  The basic major and minor values calculated by @ref _Priority_Major
966 *  and @ref _Priority_Minor are "massaged" by @ref _CPU_Priority_bits_index
967 *  to properly range between the values returned by the "find first bit"
968 *  instruction.  This makes it possible for @ref _Priority_Get_highest to
969 *  calculate the major and directly index into the minor table.
970 *  This mapping is necessary to ensure that 0 (a high priority major/minor)
971 *  is the first bit found.
972 *
973 *  This entire "find first bit" and mapping process depends heavily
974 *  on the manner in which a priority is broken into a major and minor
975 *  components with the major being the 4 MSB of a priority and minor
976 *  the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
977 *  priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
978 *  to the lowest priority.
979 *
980 *  If your CPU does not have a "find first bit" instruction, then
981 *  there are ways to make do without it.  Here are a handful of ways
982 *  to implement this in software:
983 *
984@verbatim
985      - a series of 16 bit test instructions
986      - a "binary search using if's"
987      - _number = 0
988        if _value > 0x00ff
989          _value >>=8
990          _number = 8;
991
992        if _value > 0x0000f
993          _value >=8
994          _number += 4
995
996        _number += bit_set_table[ _value ]
997@endverbatim
998
999 *    where bit_set_table[ 16 ] has values which indicate the first
1000 *      bit set
1001 *
1002 *  @param[in] _value is the value to be scanned
1003 *  @param[in] _output is the first bit set
1004 *
1005 *  Port Specific Information:
1006 *
1007 *  XXX document implementation including references if appropriate
1008 */
1009
1010#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1011#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
1012  { \
1013    asm ("bit(1);"):
1014    (_output) = 0;   /* do something to prevent warnings */ \
1015  }
1016#endif
1017
1018/* end of Bitfield handler macros */
1019
1020/**
1021 *  This routine builds the mask which corresponds to the bit fields
1022 *  as searched by @ref _CPU_Bitfield_Find_first_bit.  See the discussion
1023 *  for that routine.
1024 *
1025 *  Port Specific Information:
1026 *
1027 *  XXX document implementation including references if appropriate
1028 */
1029#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1030
1031#define _CPU_Priority_Mask( _bit_number ) \
1032  ( 1 << (_bit_number) )
1033
1034#endif
1035
1036/**
1037 *  @ingroup CPUBitfield
1038 *  This routine translates the bit numbers returned by
1039 *  @ref _CPU_Bitfield_Find_first_bit into something suitable for use as
1040 *  a major or minor component of a priority.  See the discussion
1041 *  for that routine.
1042 *
1043 *  @param[in] _priority is the major or minor number to translate
1044 *
1045 *  Port Specific Information:
1046 *
1047 *  XXX document implementation including references if appropriate
1048 */
1049#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1050
1051#define _CPU_Priority_bits_index( _priority ) \
1052  (_priority)
1053
1054#endif
1055
1056/* end of Priority handler macros */
1057
1058/* functions */
1059
1060/**
1061 *  This routine performs CPU dependent initialization.
1062 *
1063 *  Port Specific Information:
1064 *
1065 *  XXX document implementation including references if appropriate
1066 */
1067void _CPU_Initialize(void);
1068
1069/**
1070 *  @ingroup CPUInterrupt
1071 *  This routine installs a "raw" interrupt handler directly into the
1072 *  processor's vector table.
1073 *
1074 *  @param[in] vector is the vector number
1075 *  @param[in] new_handler is the raw ISR handler to install
1076 *  @param[in] old_handler is the previously installed ISR Handler
1077 *
1078 *  Port Specific Information:
1079 *
1080 *  XXX document implementation including references if appropriate
1081 */
1082void _CPU_ISR_install_raw_handler(
1083  uint32_t    vector,
1084  proc_ptr    new_handler,
1085  proc_ptr   *old_handler
1086);
1087
1088/**
1089 *  @ingroup CPUInterrupt
1090 *  This routine installs an interrupt vector.
1091 *
1092 *  @param[in] vector is the vector number
1093 *  @param[in] new_handler is the RTEMS ISR handler to install
1094 *  @param[in] old_handler is the previously installed ISR Handler
1095 *
1096 *  Port Specific Information:
1097 *
1098 *  XXX document implementation including references if appropriate
1099 */
1100void _CPU_ISR_install_vector(
1101  uint32_t    vector,
1102  proc_ptr    new_handler,
1103  proc_ptr   *old_handler
1104);
1105
1106/**
1107 *  @ingroup CPUInterrupt
1108 *  This routine installs the hardware interrupt stack pointer.
1109 *
1110 *  @note  It need only be provided if @ref CPU_HAS_HARDWARE_INTERRUPT_STACK
1111 *         is TRUE.
1112 *
1113 *  Port Specific Information:
1114 *
1115 *  XXX document implementation including references if appropriate
1116 */
1117void _CPU_Install_interrupt_stack( void );
1118
1119/**
1120 *  This routine is the CPU dependent IDLE thread body.
1121 *
1122 *  @note  It need only be provided if @ref CPU_PROVIDES_IDLE_THREAD_BODY
1123 *         is TRUE.
1124 *
1125 *  Port Specific Information:
1126 *
1127 *  XXX document implementation including references if appropriate
1128 */
1129void *_CPU_Thread_Idle_body( uintptr_t ignored );
1130
1131/**
1132 *  @ingroup CPUContext
1133 *  This routine switches from the run context to the heir context.
1134 *
1135 *  @param[in] run points to the context of the currently executing task
1136 *  @param[in] heir points to the context of the heir task
1137 *
1138 *  Port Specific Information:
1139 *
1140 *  XXX document implementation including references if appropriate
1141 */
1142void _CPU_Context_switch(
1143  Context_Control  *run,
1144  Context_Control  *heir
1145);
1146
1147/**
1148 *  @ingroup CPUContext
1149 *  This routine is generally used only to restart self in an
1150 *  efficient manner.  It may simply be a label in @ref _CPU_Context_switch.
1151 *
1152 *  @param[in] new_context points to the context to be restored.
1153 *
1154 *  @note May be unnecessary to reload some registers.
1155 *
1156 *  Port Specific Information:
1157 *
1158 *  XXX document implementation including references if appropriate
1159 */
1160void _CPU_Context_restore(
1161  Context_Control *new_context
1162);
1163
1164/**
1165 *  @ingroup CPUContext
1166 *  This routine saves the floating point context passed to it.
1167 *
1168 *  @param[in] fp_context_ptr is a pointer to a pointer to a floating
1169 *  point context area
1170 *
1171 *  @return on output @a *fp_context_ptr will contain the address that
1172 *  should be used with @ref _CPU_Context_restore_fp to restore this context.
1173 *
1174 *  Port Specific Information:
1175 *
1176 *  XXX document implementation including references if appropriate
1177 */
1178void _CPU_Context_save_fp(
1179  Context_Control_fp **fp_context_ptr
1180);
1181
1182/**
1183 *  @ingroup CPUContext
1184 *  This routine restores the floating point context passed to it.
1185 *
1186 *  @param[in] fp_context_ptr is a pointer to a pointer to a floating
1187 *  point context area to restore
1188 *
1189 *  @return on output @a *fp_context_ptr will contain the address that
1190 *  should be used with @ref _CPU_Context_save_fp to save this context.
1191 *
1192 *  Port Specific Information:
1193 *
1194 *  XXX document implementation including references if appropriate
1195 */
1196void _CPU_Context_restore_fp(
1197  Context_Control_fp **fp_context_ptr
1198);
1199
1200/**
1201 *  @ingroup CPUEndian
1202 *  The following routine swaps the endian format of an unsigned int.
1203 *  It must be static because it is referenced indirectly.
1204 *
1205 *  This version will work on any processor, but if there is a better
1206 *  way for your CPU PLEASE use it.  The most common way to do this is to:
1207 *
1208 *     swap least significant two bytes with 16-bit rotate
1209 *     swap upper and lower 16-bits
1210 *     swap most significant two bytes with 16-bit rotate
1211 *
1212 *  Some CPUs have special instructions which swap a 32-bit quantity in
1213 *  a single instruction (e.g. i486).  It is probably best to avoid
1214 *  an "endian swapping control bit" in the CPU.  One good reason is
1215 *  that interrupts would probably have to be disabled to ensure that
1216 *  an interrupt does not try to access the same "chunk" with the wrong
1217 *  endian.  Another good reason is that on some CPUs, the endian bit
1218 *  endianness for ALL fetches -- both code and data -- so the code
1219 *  will be fetched incorrectly.
1220 *
1221 *  @param[in] value is the value to be swapped
1222 *  @return the value after being endian swapped
1223 *
1224 *  Port Specific Information:
1225 *
1226 *  XXX document implementation including references if appropriate
1227 */
1228static inline uint32_t CPU_swap_u32(
1229  uint32_t value
1230)
1231{
1232  uint32_t   byte1, byte2, byte3, byte4, swapped;
1233
1234  byte4 = (value >> 24) & 0xff;
1235  byte3 = (value >> 16) & 0xff;
1236  byte2 = (value >> 8)  & 0xff;
1237  byte1 =  value        & 0xff;
1238
1239  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
1240  return( swapped );
1241}
1242
1243/**
1244 *  @ingroup CPUEndian
1245 *  This routine swaps a 16 bir quantity.
1246 *
1247 *  @param[in] value is the value to be swapped
1248 *  @return the value after being endian swapped
1249 */
1250#define CPU_swap_u16( value ) \
1251  (((value&0xff) << 8) | ((value >> 8)&0xff))
1252
1253#ifdef __cplusplus
1254}
1255#endif
1256
1257#endif
Note: See TracBrowser for help on using the repository browser.