source: rtems/cpukit/score/cpu/c4x/rtems/score/cpu.h @ 4b89ba7

4.104.114.95
Last change on this file since 4b89ba7 was 4b89ba7, checked in by Joel Sherrill <joel.sherrill@…>, on 12/03/07 at 22:22:55

2007-12-03 Joel Sherrill <joel.sherrill@…>

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