source: rtems/cpukit/score/cpu/c4x/rtems/score/cpu.h @ 231aac4

4.104.114.84.95
Last change on this file since 231aac4 was 231aac4, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/17/07 at 05:18:49

Use Context_Control_fp* instead of void* for fp_contexts.
Eliminate evil casts.

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