source: rtems/cpukit/score/cpu/bfin/rtems/score/cpu.h @ 432a662c

4.104.114.95
Last change on this file since 432a662c was 432a662c, checked in by Joel Sherrill <joel.sherrill@…>, on 07/31/08 at 14:55:54

2008-07-31 Joel Sherrill <joel.sherrill@…>

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