source: rtems/cpukit/score/cpu/c4x/rtems/score/cpu.h @ 10f8664

4.104.114.84.95
Last change on this file since 10f8664 was 10f8664, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/02/04 at 07:39:05

2004-10-02 Ralf Corsepius <ralf_corsepius@…>

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