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

4.104.114.84.95
Last change on this file since 98e4ebf5 was 98e4ebf5, checked in by Joel Sherrill <joel.sherrill@…>, on 10/08/97 at 15:45:54

Fixed typo in the pointer to the license terms.

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