source: rtems/c/src/exec/score/cpu/c4x/rtems/score/cpu.h @ 61ba9763

4.104.114.84.95
Last change on this file since 61ba9763 was 61ba9763, checked in by Joel Sherrill <joel.sherrill@…>, on 02/22/00 at 18:39:52

New port of RTEMS to TI C3x and C4x.

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