source: rtems/c/src/exec/score/cpu/sparc/cpu.h @ 9700578

4.104.114.84.95
Last change on this file since 9700578 was 9700578, checked in by Joel Sherrill <joel.sherrill@…>, on 10/30/95 at 21:54:45

SPARC port passes all tests

  • Property mode set to 100644
File size: 27.8 KB
Line 
1/*  cpu.h
2 *
3 *  This include file contains information pertaining to the port of
4 *  the executive to the SPARC processor.
5 *
6 *  $Id$
7 */
8
9#ifndef __CPU_h
10#define __CPU_h
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16#include <rtems/score/sparc.h>               /* pick up machine definitions */
17#ifndef ASM
18#include <rtems/score/sparctypes.h>
19#endif
20
21/* conditional compilation parameters */
22
23/*
24 *  Should the calls to _Thread_Enable_dispatch be inlined?
25 *
26 *  If TRUE, then they are inlined.
27 *  If FALSE, then a subroutine call is made.
28 */
29
30#define CPU_INLINE_ENABLE_DISPATCH       TRUE
31
32/*
33 *  Should the body of the search loops in _Thread_queue_Enqueue_priority
34 *  be unrolled one time?  In unrolled each iteration of the loop examines
35 *  two "nodes" on the chain being searched.  Otherwise, only one node
36 *  is examined per iteration.
37 *
38 *  If TRUE, then the loops are unrolled.
39 *  If FALSE, then the loops are not unrolled.
40 *
41 *  This parameter could go either way on the SPARC.  The interrupt flash
42 *  code is relatively lengthy given the requirements for nops following
43 *  writes to the psr.  But if the clock speed were high enough, this would
44 *  not represent a great deal of time.
45 */
46
47#define CPU_UNROLL_ENQUEUE_PRIORITY      TRUE
48
49/*
50 *  Does the executive manage a dedicated interrupt stack in software?
51 *
52 *  If TRUE, then a stack is allocated in _Interrupt_Manager_initialization.
53 *  If FALSE, nothing is done.
54 *
55 *  The SPARC does not have a dedicated HW interrupt stack and one has
56 *  been implemented in SW.
57 */
58
59#define CPU_HAS_SOFTWARE_INTERRUPT_STACK   TRUE
60
61/*
62 *  Does this CPU have hardware support for a dedicated interrupt stack?
63 *
64 *  If TRUE, then it must be installed during initialization.
65 *  If FALSE, then no installation is performed.
66 *
67 *  The SPARC does not have a dedicated HW interrupt stack.
68 */
69
70#define CPU_HAS_HARDWARE_INTERRUPT_STACK  FALSE
71
72/*
73 *  Do we allocate a dedicated interrupt stack in the Interrupt Manager?
74 *
75 *  If TRUE, then the memory is allocated during initialization.
76 *  If FALSE, then the memory is allocated during initialization.
77 */
78
79#define CPU_ALLOCATE_INTERRUPT_STACK      TRUE
80
81/*
82 *  Does the CPU have hardware floating point?
83 *
84 *  If TRUE, then the FLOATING_POINT task attribute is supported.
85 *  If FALSE, then the FLOATING_POINT task attribute is ignored.
86 */
87
88#if ( SPARC_HAS_FPU == 1 )
89#define CPU_HARDWARE_FP     TRUE
90#else
91#define CPU_HARDWARE_FP     FALSE
92#endif
93
94/*
95 *  Are all tasks FLOATING_POINT tasks implicitly?
96 *
97 *  If TRUE, then the FLOATING_POINT task attribute is assumed.
98 *  If FALSE, then the FLOATING_POINT task attribute is followed.
99 */
100
101#define CPU_ALL_TASKS_ARE_FP     FALSE
102
103/*
104 *  Should the IDLE task have a floating point context?
105 *
106 *  If TRUE, then the IDLE task is created as a FLOATING_POINT task
107 *  and it has a floating point context which is switched in and out.
108 *  If FALSE, then the IDLE task does not have a floating point context.
109 */
110
111#define CPU_IDLE_TASK_IS_FP      FALSE
112
113/*
114 *  Should the saving of the floating point registers be deferred
115 *  until a context switch is made to another different floating point
116 *  task?
117 *
118 *  If TRUE, then the floating point context will not be stored until
119 *  necessary.  It will remain in the floating point registers and not
120 *  disturned until another floating point task is switched to.
121 *
122 *  If FALSE, then the floating point context is saved when a floating
123 *  point task is switched out and restored when the next floating point
124 *  task is restored.  The state of the floating point registers between
125 *  those two operations is not specified.
126 */
127
128#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
129
130/*
131 *  Does this port provide a CPU dependent IDLE task implementation?
132 *
133 *  If TRUE, then the routine _CPU_Internal_threads_Idle_thread_body
134 *  must be provided and is the default IDLE thread body instead of
135 *  _Internal_threads_Idle_thread_body.
136 *
137 *  If FALSE, then use the generic IDLE thread body if the BSP does
138 *  not provide one.
139 */
140
141#if (SPARC_HAS_LOW_POWER_MODE == 1)
142#define CPU_PROVIDES_IDLE_THREAD_BODY    TRUE
143#else
144#define CPU_PROVIDES_IDLE_THREAD_BODY    FALSE
145#endif
146
147/*
148 *  Does the stack grow up (toward higher addresses) or down
149 *  (toward lower addresses)?
150 *
151 *  If TRUE, then the grows upward.
152 *  If FALSE, then the grows toward smaller addresses.
153 *
154 *  The stack grows to lower addresses on the SPARC.
155 */
156
157#define CPU_STACK_GROWS_UP               FALSE
158
159/*
160 *  The following is the variable attribute used to force alignment
161 *  of critical data structures.  On some processors it may make
162 *  sense to have these aligned on tighter boundaries than
163 *  the minimum requirements of the compiler in order to have as
164 *  much of the critical data area as possible in a cache line.
165 *
166 *  The SPARC does not appear to have particularly strict alignment
167 *  requirements.  This value was chosen to take advantages of caches.
168 */
169
170#define CPU_STRUCTURE_ALIGNMENT          __attribute__ ((aligned (16)))
171
172/*
173 *  The following defines the number of bits actually used in the
174 *  interrupt field of the task mode.  How those bits map to the
175 *  CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
176 *
177 *  The SPARC has 16 interrupt levels in the PIL field of the PSR.
178 */
179
180#define CPU_MODES_INTERRUPT_MASK   0x0000000F
181
182/*
183 *  This structure represents the organization of the minimum stack frame
184 *  for the SPARC.  More framing information is required in certain situaions
185 *  such as when there are a large number of out parameters or when the callee
186 *  must save floating point registers.
187 */
188
189#ifndef ASM
190
191typedef struct {
192  unsigned32  l0;
193  unsigned32  l1;
194  unsigned32  l2;
195  unsigned32  l3;
196  unsigned32  l4;
197  unsigned32  l5;
198  unsigned32  l6;
199  unsigned32  l7;
200  unsigned32  i0;
201  unsigned32  i1;
202  unsigned32  i2;
203  unsigned32  i3;
204  unsigned32  i4;
205  unsigned32  i5;
206  unsigned32  i6_fp;
207  unsigned32  i7;
208  void       *structure_return_address;
209  /*
210   *  The following are for the callee to save the register arguments in
211   *  should this be necessary.
212   */
213  unsigned32  saved_arg0;
214  unsigned32  saved_arg1;
215  unsigned32  saved_arg2;
216  unsigned32  saved_arg3;
217  unsigned32  saved_arg4;
218  unsigned32  saved_arg5;
219  unsigned32  pad0;
220}  CPU_Minimum_stack_frame;
221
222#endif /* ASM */
223
224#define CPU_STACK_FRAME_L0_OFFSET             0x00
225#define CPU_STACK_FRAME_L1_OFFSET             0x04
226#define CPU_STACK_FRAME_L2_OFFSET             0x08
227#define CPU_STACK_FRAME_L3_OFFSET             0x0c
228#define CPU_STACK_FRAME_L4_OFFSET             0x10
229#define CPU_STACK_FRAME_L5_OFFSET             0x14
230#define CPU_STACK_FRAME_L6_OFFSET             0x18
231#define CPU_STACK_FRAME_L7_OFFSET             0x1c
232#define CPU_STACK_FRAME_I0_OFFSET             0x20
233#define CPU_STACK_FRAME_I1_OFFSET             0x24
234#define CPU_STACK_FRAME_I2_OFFSET             0x28
235#define CPU_STACK_FRAME_I3_OFFSET             0x2c
236#define CPU_STACK_FRAME_I4_OFFSET             0x30
237#define CPU_STACK_FRAME_I5_OFFSET             0x34
238#define CPU_STACK_FRAME_I6_FP_OFFSET          0x38
239#define CPU_STACK_FRAME_I7_OFFSET             0x3c
240#define CPU_STRUCTURE_RETURN_ADDRESS_OFFSET   0x40
241#define CPU_STACK_FRAME_SAVED_ARG0_OFFSET     0x44
242#define CPU_STACK_FRAME_SAVED_ARG1_OFFSET     0x48
243#define CPU_STACK_FRAME_SAVED_ARG2_OFFSET     0x4c
244#define CPU_STACK_FRAME_SAVED_ARG3_OFFSET     0x50
245#define CPU_STACK_FRAME_SAVED_ARG4_OFFSET     0x54
246#define CPU_STACK_FRAME_SAVED_ARG5_OFFSET     0x58
247#define CPU_STACK_FRAME_PAD0_OFFSET           0x5c
248
249#define CPU_MINIMUM_STACK_FRAME_SIZE          0x60
250
251/*
252 * Contexts
253 *
254 *  Generally there are 2 types of context to save.
255 *     1. Interrupt registers to save
256 *     2. Task level registers to save
257 *
258 *  This means we have the following 3 context items:
259 *     1. task level context stuff::  Context_Control
260 *     2. floating point task stuff:: Context_Control_fp
261 *     3. special interrupt level context :: Context_Control_interrupt
262 *
263 *  On the SPARC, we are relatively conservative in that we save most
264 *  of the CPU state in the context area.  The ET (enable trap) bit and
265 *  the CWP (current window pointer) fields of the PSR are considered
266 *  system wide resources and are not maintained on a per-thread basis.
267 */
268
269#ifndef ASM
270
271typedef struct {
272    /*
273     *  Using a double g0_g1 will put everything in this structure on a
274     *  double word boundary which allows us to use double word loads
275     *  and stores safely in the context switch.
276     */
277    double     g0_g1;
278    unsigned32 g2;
279    unsigned32 g3;
280    unsigned32 g4;
281    unsigned32 g5;
282    unsigned32 g6;
283    unsigned32 g7;
284
285    unsigned32 l0;
286    unsigned32 l1;
287    unsigned32 l2;
288    unsigned32 l3;
289    unsigned32 l4;
290    unsigned32 l5;
291    unsigned32 l6;
292    unsigned32 l7;
293
294    unsigned32 i0;
295    unsigned32 i1;
296    unsigned32 i2;
297    unsigned32 i3;
298    unsigned32 i4;
299    unsigned32 i5;
300    unsigned32 i6_fp;
301    unsigned32 i7;
302
303    unsigned32 o0;
304    unsigned32 o1;
305    unsigned32 o2;
306    unsigned32 o3;
307    unsigned32 o4;
308    unsigned32 o5;
309    unsigned32 o6_sp;
310    unsigned32 o7;
311
312    unsigned32 psr;
313} Context_Control;
314
315#endif /* ASM */
316
317/*
318 *  Offsets of fields with Context_Control for assembly routines.
319 */
320
321#define G0_OFFSET    0x00
322#define G1_OFFSET    0x04
323#define G2_OFFSET    0x08
324#define G3_OFFSET    0x0C
325#define G4_OFFSET    0x10
326#define G5_OFFSET    0x14
327#define G6_OFFSET    0x18
328#define G7_OFFSET    0x1C
329
330#define L0_OFFSET    0x20
331#define L1_OFFSET    0x24
332#define L2_OFFSET    0x28
333#define L3_OFFSET    0x2C
334#define L4_OFFSET    0x30
335#define L5_OFFSET    0x34
336#define L6_OFFSET    0x38
337#define L7_OFFSET    0x3C
338
339#define I0_OFFSET    0x40
340#define I1_OFFSET    0x44
341#define I2_OFFSET    0x48
342#define I3_OFFSET    0x4C
343#define I4_OFFSET    0x50
344#define I5_OFFSET    0x54
345#define I6_FP_OFFSET 0x58
346#define I7_OFFSET    0x5C
347
348#define O0_OFFSET    0x60
349#define O1_OFFSET    0x64
350#define O2_OFFSET    0x68
351#define O3_OFFSET    0x6C
352#define O4_OFFSET    0x70
353#define O5_OFFSET    0x74
354#define O6_SP_OFFSET 0x78
355#define O7_OFFSET    0x7C
356
357#define PSR_OFFSET   0x80
358
359#define CONTEXT_CONTROL_SIZE 0x84
360
361/*
362 *  The floating point context area.
363 */
364
365#ifndef ASM
366
367typedef struct {
368    double      f0_f1;
369    double      f2_f3;
370    double      f4_f5;
371    double      f6_f7;
372    double      f8_f9;
373    double      f10_f11;
374    double      f12_f13;
375    double      f14_f15;
376    double      f16_f17;
377    double      f18_f19;
378    double      f20_f21;
379    double      f22_f23;
380    double      f24_f25;
381    double      f26_f27;
382    double      f28_f29;
383    double      f30_f31;
384    unsigned32  fsr;
385} Context_Control_fp;
386
387#endif /* ASM */
388
389/*
390 *  Offsets of fields with Context_Control_fp for assembly routines.
391 */
392
393#define FO_F1_OFFSET     0x00
394#define F2_F3_OFFSET     0x08
395#define F4_F5_OFFSET     0x10
396#define F6_F7_OFFSET     0x18
397#define F8_F9_OFFSET     0x20
398#define F1O_F11_OFFSET   0x28
399#define F12_F13_OFFSET   0x30
400#define F14_F15_OFFSET   0x38
401#define F16_F17_OFFSET   0x40
402#define F18_F19_OFFSET   0x48
403#define F2O_F21_OFFSET   0x50
404#define F22_F23_OFFSET   0x58
405#define F24_F25_OFFSET   0x60
406#define F26_F27_OFFSET   0x68
407#define F28_F29_OFFSET   0x70
408#define F3O_F31_OFFSET   0x78
409#define FSR_OFFSET       0x80
410
411#define CONTEXT_CONTROL_FP_SIZE 0x84
412
413#ifndef ASM
414
415/*
416 *  Context saved on stack for an interrupt.
417 *
418 *  NOTE:  The PSR, PC, and NPC are only saved in this structure for the
419 *         benefit of the user's handler.
420 */
421
422typedef struct {
423  CPU_Minimum_stack_frame  Stack_frame;
424  unsigned32               psr;
425  unsigned32               pc;
426  unsigned32               npc;
427  unsigned32               g1;
428  unsigned32               g2;
429  unsigned32               g3;
430  unsigned32               g4;
431  unsigned32               g5;
432  unsigned32               g6;
433  unsigned32               g7;
434  unsigned32               i0;
435  unsigned32               i1;
436  unsigned32               i2;
437  unsigned32               i3;
438  unsigned32               i4;
439  unsigned32               i5;
440  unsigned32               i6_fp;
441  unsigned32               i7;
442  unsigned32               y;
443  unsigned32               pad0_offset;
444} CPU_Interrupt_frame;
445
446#endif /* ASM */
447
448/*
449 *  Offsets of fields with CPU_Interrupt_frame for assembly routines.
450 */
451
452#define ISF_STACK_FRAME_OFFSET 0x00
453#define ISF_PSR_OFFSET         CPU_MINIMUM_STACK_FRAME_SIZE + 0x00
454#define ISF_PC_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x04
455#define ISF_NPC_OFFSET         CPU_MINIMUM_STACK_FRAME_SIZE + 0x08
456#define ISF_G1_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x0c
457#define ISF_G2_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x10
458#define ISF_G3_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x14
459#define ISF_G4_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x18
460#define ISF_G5_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x1c
461#define ISF_G6_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x20
462#define ISF_G7_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x24
463#define ISF_I0_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x28
464#define ISF_I1_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x2c
465#define ISF_I2_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x30
466#define ISF_I3_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x34
467#define ISF_I4_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x38
468#define ISF_I5_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x3c
469#define ISF_I6_FP_OFFSET       CPU_MINIMUM_STACK_FRAME_SIZE + 0x40
470#define ISF_I7_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x44
471#define ISF_Y_OFFSET           CPU_MINIMUM_STACK_FRAME_SIZE + 0x48
472#define ISF_PAD0_OFFSET        CPU_MINIMUM_STACK_FRAME_SIZE + 0x4c
473
474#define CONTEXT_CONTROL_INTERRUPT_FRAME_SIZE CPU_MINIMUM_STACK_FRAME_SIZE + 0x50
475#ifndef ASM
476
477/*
478 *  The following table contains the information required to configure
479 *  the processor specific parameters.
480 *
481 *  NOTE: The interrupt_stack_size field is required if
482 *        CPU_ALLOCATE_INTERRUPT_STACK is defined as TRUE.
483 *
484 *        The pretasking_hook, predriver_hook, and postdriver_hook,
485 *        and the do_zero_of_workspace fields are required on ALL CPUs.
486 */
487
488typedef struct {
489  void       (*pretasking_hook)( void );
490  void       (*predriver_hook)( void );
491  void       (*postdriver_hook)( void );
492  void       (*idle_task)( void );
493  boolean      do_zero_of_workspace;
494  unsigned32   interrupt_stack_size;
495  unsigned32   extra_system_initialization_stack;
496}   rtems_cpu_table;
497
498/*
499 *  This variable is contains the initialize context for the FP unit.
500 *  It is filled in by _CPU_Initialize and copied into the task's FP
501 *  context area during _CPU_Context_Initialize.
502 */
503
504EXTERN Context_Control_fp  _CPU_Null_fp_context CPU_STRUCTURE_ALIGNMENT;
505
506/*
507 *  This stack is allocated by the Interrupt Manager and the switch
508 *  is performed in _ISR_Handler.  These variables contain pointers
509 *  to the lowest and highest addresses in the chunk of memory allocated
510 *  for the interrupt stack.  Since it is unknown whether the stack
511 *  grows up or down (in general), this give the CPU dependent
512 *  code the option of picking the version it wants to use.  Thus
513 *  both must be present if either is.
514 *
515 *  The SPARC supports a software based interrupt stack and these
516 *  are required.
517 */
518
519EXTERN void *_CPU_Interrupt_stack_low;
520EXTERN void *_CPU_Interrupt_stack_high;
521
522#if defined(erc32)
523
524/*
525 *  ERC32 Specific Variables
526 */
527
528EXTERN unsigned32 _ERC32_MEC_Timer_Control_Mirror;
529
530#endif
531
532/*
533 *  The following type defines an entry in the SPARC's trap table.
534 *
535 *  NOTE: The instructions chosen are RTEMS dependent although one is
536 *        obligated to use two of the four instructions to perform a
537 *        long jump.  The other instructions load one register with the
538 *        trap type (a.k.a. vector) and another with the psr.
539 */
540 
541typedef struct {
542  unsigned32   mov_psr_l0;                     /* mov   %psr, %l0           */
543  unsigned32   sethi_of_handler_to_l4;         /* sethi %hi(_handler), %l4  */
544  unsigned32   jmp_to_low_of_handler_plus_l4;  /* jmp   %l4 + %lo(_handler) */
545  unsigned32   mov_vector_l3;                  /* mov   _vector, %l3        */
546} CPU_Trap_table_entry;
547 
548/*
549 *  This is the set of opcodes for the instructions loaded into a trap
550 *  table entry.  The routine which installs a handler is responsible
551 *  for filling in the fields for the _handler address and the _vector
552 *  trap type.
553 *
554 *  The constants following this structure are masks for the fields which
555 *  must be filled in when the handler is installed.
556 */
557 
558extern const CPU_Trap_table_entry _CPU_Trap_slot_template;
559
560/*
561 *  This is the executive's trap table which is installed into the TBR
562 *  register.
563 *
564 *  NOTE:  Unfortunately, this must be aligned on a 4096 byte boundary.
565 *         The GNU tools as of binutils 2.5.2 and gcc 2.7.0 would not
566 *         align an entity to anything greater than a 512 byte boundary.
567 *
568 *         Because of this, we pull a little bit of a trick.  We allocate
569 *         enough memory so we can grab an address on a 4096 byte boundary
570 *         from this area.
571 */
572 
573#define SPARC_TRAP_TABLE_ALIGNMENT 4096
574 
575EXTERN unsigned8 _CPU_Trap_Table_area[ 8192 ]
576           __attribute__ ((aligned (SPARC_TRAP_TABLE_ALIGNMENT)));
577 
578
579/*
580 *  The size of the floating point context area. 
581 */
582
583#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
584
585#endif
586
587/*
588 *  Amount of extra stack (above minimum stack size) required by
589 *  system initialization thread.  Remember that in a multiprocessor
590 *  system the system intialization thread becomes the MP server thread.
591 */
592
593#define CPU_SYSTEM_INITIALIZATION_THREAD_EXTRA_STACK 1024
594
595/*
596 *  This defines the number of entries in the ISR_Vector_table managed
597 *  by the executive.
598 *
599 *  On the SPARC, there are really only 256 vectors.  However, the executive
600 *  has no easy, fast, reliable way to determine which traps are synchronous
601 *  and which are asynchronous.  By default, synchronous traps return to the
602 *  instruction which caused the interrupt.  So if you install a software
603 *  trap handler as an executive interrupt handler (which is desirable since
604 *  RTEMS takes care of window and register issues), then the executive needs
605 *  to know that the return address is to the trap rather than the instruction
606 *  following the trap.
607 *
608 *  So vectors 0 through 255 are treated as regular asynchronous traps which
609 *  provide the "correct" return address.  Vectors 256 through 512 are assumed
610 *  by the executive to be synchronous and to require that the return address
611 *  be fudged.
612 *
613 *  If you use this mechanism to install a trap handler which must reexecute
614 *  the instruction which caused the trap, then it should be installed as
615 *  an asynchronous trap.  This will avoid the executive changing the return
616 *  address.
617 */
618
619#define CPU_INTERRUPT_NUMBER_OF_VECTORS     256
620#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER 511
621
622#define SPARC_SYNCHRONOUS_TRAP_BIT_MASK     0x100
623#define SPARC_ASYNCHRONOUS_TRAP( _trap )    (_trap)
624#define SPARC_SYNCHRONOUS_TRAP( _trap )     ((_trap) + 256 )
625
626#define SPARC_REAL_TRAP_NUMBER( _trap )     ((_trap) % 256)
627
628/*
629 *  Should be large enough to run all tests.  This insures
630 *  that a "reasonable" small application should not have any problems.
631 *
632 *  This appears to be a fairly generous number for the SPARC since
633 *  represents a call depth of about 20 routines based on the minimum
634 *  stack frame.
635 */
636
637#define CPU_STACK_MINIMUM_SIZE  (1024*2)
638
639/*
640 *  CPU's worst alignment requirement for data types on a byte boundary.  This
641 *  alignment does not take into account the requirements for the stack.
642 *
643 *  On the SPARC, this is required for double word loads and stores.
644 */
645
646#define CPU_ALIGNMENT      8
647
648/*
649 *  This number corresponds to the byte alignment requirement for the
650 *  heap handler.  This alignment requirement may be stricter than that
651 *  for the data types alignment specified by CPU_ALIGNMENT.  It is
652 *  common for the heap to follow the same alignment requirement as
653 *  CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
654 *  then this should be set to CPU_ALIGNMENT.
655 *
656 *  NOTE:  This does not have to be a power of 2.  It does have to
657 *         be greater or equal to than CPU_ALIGNMENT.
658 */
659
660#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
661
662/*
663 *  This number corresponds to the byte alignment requirement for memory
664 *  buffers allocated by the partition manager.  This alignment requirement
665 *  may be stricter than that for the data types alignment specified by
666 *  CPU_ALIGNMENT.  It is common for the partition to follow the same
667 *  alignment requirement as CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict
668 *  enough for the partition, then this should be set to CPU_ALIGNMENT.
669 *
670 *  NOTE:  This does not have to be a power of 2.  It does have to
671 *         be greater or equal to than CPU_ALIGNMENT.
672 */
673
674#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
675
676/*
677 *  This number corresponds to the byte alignment requirement for the
678 *  stack.  This alignment requirement may be stricter than that for the
679 *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
680 *  is strict enough for the stack, then this should be set to 0.
681 *
682 *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
683 *
684 *  The alignment restrictions for the SPARC are not that strict but this
685 *  should unsure that the stack is always sufficiently alignment that the
686 *  window overflow, underflow, and flush routines can use double word loads
687 *  and stores.
688 */
689
690#define CPU_STACK_ALIGNMENT        16
691
692#ifndef ASM
693
694/* ISR handler macros */
695
696/*
697 *  Disable all interrupts for a critical section.  The previous
698 *  level is returned in _level.
699 */
700
701#define _CPU_ISR_Disable( _level ) \
702  sparc_disable_interrupts( _level )
703 
704/*
705 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
706 *  This indicates the end of a critical section.  The parameter
707 *  _level is not modified.
708 */
709
710#define _CPU_ISR_Enable( _level ) \
711  sparc_enable_interrupts( _level )
712 
713/*
714 *  This temporarily restores the interrupt to _level before immediately
715 *  disabling them again.  This is used to divide long critical
716 *  sections into two or more parts.  The parameter _level is not
717 *  modified.
718 */
719
720#define _CPU_ISR_Flash( _level ) \
721  sparc_flash_interrupts( _level )
722 
723/*
724 *  Map interrupt level in task mode onto the hardware that the CPU
725 *  actually provides.  Currently, interrupt levels which do not
726 *  map onto the CPU in a straight fashion are undefined. 
727 */
728
729#define _CPU_ISR_Set_level( _newlevel ) \
730   sparc_set_interrupt_level( _newlevel )
731 
732unsigned32 _CPU_ISR_Get_level( void );
733 
734/* end of ISR handler macros */
735
736/* Context handler macros */
737
738/*
739 *  Initialize the context to a state suitable for starting a
740 *  task after a context restore operation.  Generally, this
741 *  involves:
742 *
743 *     - setting a starting address
744 *     - preparing the stack
745 *     - preparing the stack and frame pointers
746 *     - setting the proper interrupt level in the context
747 *     - initializing the floating point context
748 *
749 *  NOTE:  Implemented as a subroutine for the SPARC port.
750 */
751
752void _CPU_Context_Initialize(
753  Context_Control  *the_context,
754  unsigned32       *stack_base,
755  unsigned32        size,
756  unsigned32        new_level,
757  void             *entry_point,
758  boolean           is_fp
759);
760
761/*
762 *  This routine is responsible for somehow restarting the currently
763 *  executing task. 
764 *
765 *  On the SPARC, this is is relatively painless but requires a small
766 *  amount of wrapper code before using the regular restore code in
767 *  of the context switch.
768 */
769
770#define _CPU_Context_Restart_self( _the_context ) \
771   _CPU_Context_restore( (_the_context) );
772
773/*
774 *  The FP context area for the SPARC is a simple structure and nothing
775 *  special is required to find the "starting load point"
776 */
777
778#define _CPU_Context_Fp_start( _base, _offset ) \
779   ( (void *) (_base) + (_offset) )
780
781/*
782 *  This routine initializes the FP context area passed to it to.
783 *
784 *  The SPARC allows us to use the simple initialization model
785 *  in which an "initial" FP context was saved into _CPU_Null_fp_context
786 *  at CPU initialization and it is simply copied into the destination
787 *  context.
788 */
789
790#define _CPU_Context_Initialize_fp( _destination ) \
791  do { \
792   *((Context_Control_fp *) *((void **) _destination)) = _CPU_Null_fp_context; \
793  } while (0)
794
795/* end of Context handler macros */
796
797/* Fatal Error manager macros */
798
799/*
800 *  This routine copies _error into a known place -- typically a stack
801 *  location or a register, optionally disables interrupts, and
802 *  halts/stops the CPU.
803 */
804
805#define _CPU_Fatal_halt( _error ) \
806  do { \
807    unsigned32 level; \
808    \
809    sparc_disable_interrupts( level ); \
810    asm volatile ( "mov  %0, %%g1 " : "=r" (level) : "0" (level) ); \
811    while (1); /* loop forever */ \
812  } while (0)
813
814/* end of Fatal Error manager macros */
815
816/* Bitfield handler macros */
817
818/*
819 *  The SPARC port uses the generic C algorithm for bitfield scan if the
820 *  CPU model does not have a scan instruction.
821 */
822
823#if ( SPARC_HAS_BITSCAN == 0 )
824#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
825#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
826#else
827#error "scan instruction not currently supported by RTEMS!!"
828#endif
829
830/* end of Bitfield handler macros */
831
832/* Priority handler handler macros */
833
834/*
835 *  The SPARC port uses the generic C algorithm for bitfield scan if the
836 *  CPU model does not have a scan instruction.
837 */
838
839#if ( SPARC_HAS_BITSCAN == 1 )
840#error "scan instruction not currently supported by RTEMS!!"
841#endif
842
843/* end of Priority handler macros */
844
845/* functions */
846
847/*
848 *  _CPU_Initialize
849 *
850 *  This routine performs CPU dependent initialization.
851 */
852
853void _CPU_Initialize(
854  rtems_cpu_table  *cpu_table,
855  void            (*thread_dispatch)
856);
857
858/*
859 *  _CPU_ISR_install_raw_handler
860 *
861 *  This routine installs new_handler to be directly called from the trap
862 *  table.
863 */
864 
865void _CPU_ISR_install_raw_handler(
866  unsigned32  vector,
867  proc_ptr    new_handler,
868  proc_ptr   *old_handler
869);
870
871/*
872 *  _CPU_ISR_install_vector
873 *
874 *  This routine installs an interrupt vector.
875 */
876
877void _CPU_ISR_install_vector(
878  unsigned32  vector,
879  proc_ptr    new_handler,
880  proc_ptr   *old_handler
881);
882
883#if (CPU_PROVIDES_IDLE_THREAD_BODY == TRUE)
884 
885/*
886 *  _CPU_Internal_threads_Idle_thread_body
887 *
888 *  Some SPARC implementations have low power, sleep, or idle modes.  This
889 *  tries to take advantage of those models.
890 */
891 
892void _CPU_Internal_threads_Idle_thread_body( void );
893 
894#endif /* CPU_PROVIDES_IDLE_THREAD_BODY */
895
896/*
897 *  _CPU_Context_switch
898 *
899 *  This routine switches from the run context to the heir context.
900 */
901
902void _CPU_Context_switch(
903  Context_Control  *run,
904  Context_Control  *heir
905);
906
907/*
908 *  _CPU_Context_restore
909 *
910 *  This routine is generallu used only to restart self in an
911 *  efficient manner.
912 */
913
914void _CPU_Context_restore(
915  Context_Control *new_context
916);
917
918/*
919 *  _CPU_Context_save_fp
920 *
921 *  This routine saves the floating point context passed to it.
922 */
923
924void _CPU_Context_save_fp(
925  void **fp_context_ptr
926);
927
928/*
929 *  _CPU_Context_restore_fp
930 *
931 *  This routine restores the floating point context passed to it.
932 */
933
934void _CPU_Context_restore_fp(
935  void **fp_context_ptr
936);
937
938/*
939 *  CPU_swap_u32
940 *
941 *  The following routine swaps the endian format of an unsigned int.
942 *  It must be static because it is referenced indirectly.
943 *
944 *  This version will work on any processor, but if you come across a better
945 *  way for the SPARC PLEASE use it.  The most common way to swap a 32-bit
946 *  entity as shown below is not any more efficient on the SPARC.
947 *
948 *     swap least significant two bytes with 16-bit rotate
949 *     swap upper and lower 16-bits
950 *     swap most significant two bytes with 16-bit rotate
951 *
952 *  It is not obvious how the SPARC can do significantly better than the
953 *  generic code.  gcc 2.7.0 only generates about 12 instructions for the
954 *  following code at optimization level four (i.e. -O4).
955 */
956 
957static inline unsigned int CPU_swap_u32(
958  unsigned int value
959)
960{
961  unsigned32 byte1, byte2, byte3, byte4, swapped;
962 
963  byte4 = (value >> 24) & 0xff;
964  byte3 = (value >> 16) & 0xff;
965  byte2 = (value >> 8)  & 0xff;
966  byte1 =  value        & 0xff;
967 
968  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
969  return( swapped );
970}
971
972#endif ASM
973
974#ifdef __cplusplus
975}
976#endif
977
978#endif
Note: See TracBrowser for help on using the repository browser.