source: rtems/cpukit/score/cpu/bfin/rtems/score/cpu.h @ 142868b2

5
Last change on this file since 142868b2 was 142868b2, checked in by Sebastian Huber <sebastian.huber@…>, on 02/03/16 at 10:54:59

bfin: Delete superfluous _CPU_Null_fp_context

Update #2559.

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