source: rtems/cpukit/score/cpu/c4x/rtems/score/cpu.h @ f404fa1

Last change on this file since f404fa1 was f404fa1, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:47:23

2003-09-04 Joel Sherrill <joel@…>

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