source: rtems/cpukit/score/cpu/bfin/rtems/score/cpu.h @ a8865f8

5
Last change on this file since a8865f8 was a8865f8, checked in by Sebastian Huber <sebastian.huber@…>, on 01/25/16 at 09:20:28

score: Introduce CPU_CACHE_LINE_BYTES

Add CPU_CACHE_LINE_BYTES for the maximum cache line size in bytes. The
actual processor may use no cache or a smaller cache line size.

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