source: rtems/cpukit/score/cpu/sparc64/rtems/score/cpu.h @ 89b85e51

4.115
Last change on this file since 89b85e51 was 89b85e51, checked in by Sebastian Huber <sebastian.huber@…>, on 07/16/10 at 08:46:29

2010-07-16 Sebastian Huber <sebastian.huber@…>

  • rtems/score/cpu.h: Include <rtems/score/types.h> first.
  • rtems/score/types.h: Use <rtems/score/basedefs.h> header file.
  • Property mode set to 100644
File size: 30.9 KB
Line 
1/**
2 * @file rtems/score/cpu.h
3 */
4
5/*
6 *  This include file contains information pertaining to the port of
7 *  the executive to the SPARC64 processor.
8 *
9 *  COPYRIGHT (c) 1989-2006.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  This file is based on the SPARC cpu.h file. Modifications are made
13 *  to support the SPARC64 processor.
14 *    COPYRIGHT (c) 2010. Gedare Bloom.
15 *
16 *  The license and distribution terms for this file may be
17 *  found in the file LICENSE in this distribution or at
18 *  http://www.rtems.com/license/LICENSE.
19 *
20 *  $Id$
21 */
22
23#ifndef _RTEMS_SCORE_CPU_H
24#define _RTEMS_SCORE_CPU_H
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#include <rtems/score/types.h>
31#include <rtems/score/sparc64.h>
32
33/* conditional compilation parameters */
34
35/*
36 *  Should the calls to _Thread_Enable_dispatch be inlined?
37 *
38 *  If TRUE, then they are inlined.
39 *  If FALSE, then a subroutine call is made.
40 */
41
42#define CPU_INLINE_ENABLE_DISPATCH       TRUE
43
44/*
45 *  Should the body of the search loops in _Thread_queue_Enqueue_priority
46 *  be unrolled one time?  In unrolled each iteration of the loop examines
47 *  two "nodes" on the chain being searched.  Otherwise, only one node
48 *  is examined per iteration.
49 *
50 *  If TRUE, then the loops are unrolled.
51 *  If FALSE, then the loops are not unrolled.
52 *
53 *  This parameter could go either way on the SPARC.  The interrupt flash
54 *  code is relatively lengthy given the requirements for nops following
55 *  writes to the psr.  But if the clock speed were high enough, this would
56 *  not represent a great deal of time.
57 */
58
59#define CPU_UNROLL_ENQUEUE_PRIORITY      TRUE
60
61/*
62 *  Does the executive manage a dedicated interrupt stack in software?
63 *
64 *  If TRUE, then a stack is allocated in _ISR_Handler_initialization.
65 *  If FALSE, nothing is done.
66 *
67 *  The SPARC does not have a dedicated HW interrupt stack and one has
68 *  been implemented in SW.
69 */
70
71#define CPU_HAS_SOFTWARE_INTERRUPT_STACK   TRUE
72
73/*
74 *  Does the CPU follow the simple vectored interrupt model?
75 *
76 *  If TRUE, then RTEMS allocates the vector table it internally manages.
77 *  If FALSE, then the BSP is assumed to allocate and manage the vector
78 *  table
79 *
80 *  SPARC Specific Information:
81 *
82 *  XXX document implementation including references if appropriate
83 */
84#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
85
86/*
87 *  Does this CPU have hardware support for a dedicated interrupt stack?
88 *
89 *  If TRUE, then it must be installed during initialization.
90 *  If FALSE, then no installation is performed.
91 *
92 *  The SPARC does not have a dedicated HW interrupt stack.
93 */
94
95#define CPU_HAS_HARDWARE_INTERRUPT_STACK  FALSE
96
97/*
98 *  Do we allocate a dedicated interrupt stack in the Interrupt Manager?
99 *
100 *  If TRUE, then the memory is allocated during initialization.
101 *  If FALSE, then the memory is allocated during initialization.
102 */
103
104#define CPU_ALLOCATE_INTERRUPT_STACK      TRUE
105
106/*
107 *  Does the RTEMS invoke the user's ISR with the vector number and
108 *  a pointer to the saved interrupt frame (1) or just the vector
109 *  number (0)?
110 */
111
112#define CPU_ISR_PASSES_FRAME_POINTER 0
113
114/*
115 *  Does the CPU have hardware floating point?
116 *
117 *  If TRUE, then the FLOATING_POINT task attribute is supported.
118 *  If FALSE, then the FLOATING_POINT task attribute is ignored.
119 */
120
121#if ( SPARC_HAS_FPU == 1 )
122#define CPU_HARDWARE_FP     TRUE
123#else
124#define CPU_HARDWARE_FP     FALSE
125#endif
126#define CPU_SOFTWARE_FP     FALSE
127
128/*
129 *  Are all tasks FLOATING_POINT tasks implicitly?
130 *
131 *  If TRUE, then the FLOATING_POINT task attribute is assumed.
132 *  If FALSE, then the FLOATING_POINT task attribute is followed.
133 */
134
135#define CPU_ALL_TASKS_ARE_FP     FALSE
136
137/*
138 *  Should the IDLE task have a floating point context?
139 *
140 *  If TRUE, then the IDLE task is created as a FLOATING_POINT task
141 *  and it has a floating point context which is switched in and out.
142 *  If FALSE, then the IDLE task does not have a floating point context.
143 */
144
145#define CPU_IDLE_TASK_IS_FP      FALSE
146
147/*
148 *  Should the saving of the floating point registers be deferred
149 *  until a context switch is made to another different floating point
150 *  task?
151 *
152 *  If TRUE, then the floating point context will not be stored until
153 *  necessary.  It will remain in the floating point registers and not
154 *  disturned until another floating point task is switched to.
155 *
156 *  If FALSE, then the floating point context is saved when a floating
157 *  point task is switched out and restored when the next floating point
158 *  task is restored.  The state of the floating point registers between
159 *  those two operations is not specified.
160 */
161
162#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
163
164/*
165 *  Does this port provide a CPU dependent IDLE task implementation?
166 *
167 *  If TRUE, then the routine _CPU_Thread_Idle_body
168 *  must be provided and is the default IDLE thread body instead of
169 *  _CPU_Thread_Idle_body.
170 *
171 *  If FALSE, then use the generic IDLE thread body if the BSP does
172 *  not provide one.
173 */
174
175#define CPU_PROVIDES_IDLE_THREAD_BODY    FALSE
176
177/*
178 *  Does the stack grow up (toward higher addresses) or down
179 *  (toward lower addresses)?
180 *
181 *  If TRUE, then the grows upward.
182 *  If FALSE, then the grows toward smaller addresses.
183 *
184 *  The stack grows to lower addresses on the SPARC.
185 */
186
187#define CPU_STACK_GROWS_UP               FALSE
188
189/*
190 *  The following is the variable attribute used to force alignment
191 *  of critical data structures.  On some processors it may make
192 *  sense to have these aligned on tighter boundaries than
193 *  the minimum requirements of the compiler in order to have as
194 *  much of the critical data area as possible in a cache line.
195 *
196 *  The SPARC does not appear to have particularly strict alignment
197 *  requirements.  This value (16) was chosen to take advantages of caches.
198 *
199 *  SPARC 64 requirements on floating point alignment is at least 8,
200 *  and is 16 if quad-word fp instructions are available (e.g. LDQF).
201 */
202
203#define CPU_STRUCTURE_ALIGNMENT          __attribute__ ((aligned (16)))
204
205/*
206 *  Define what is required to specify how the network to host conversion
207 *  routines are handled.
208 */
209
210#define CPU_BIG_ENDIAN                           TRUE
211#define CPU_LITTLE_ENDIAN                        FALSE
212
213/*
214 *  The following defines the number of bits actually used in the
215 *  interrupt field of the task mode.  How those bits map to the
216 *  CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
217 *
218 *  The SPARC v9 has 16 interrupt levels in the PIL field of the PSR.
219 */
220
221#define CPU_MODES_INTERRUPT_MASK   0x0000000F
222
223/*
224 *  This structure represents the organization of the minimum stack frame
225 *  for the SPARC.  More framing information is required in certain situaions
226 *  such as when there are a large number of out parameters or when the callee
227 *  must save floating point registers.
228 */
229
230#ifndef ASM
231
232typedef struct {
233  uint64_t    l0;
234  uint64_t    l1;
235  uint64_t    l2;
236  uint64_t    l3;
237  uint64_t    l4;
238  uint64_t    l5;
239  uint64_t    l6;
240  uint64_t    l7;
241  uint64_t    i0;
242  uint64_t    i1;
243  uint64_t    i2;
244  uint64_t    i3;
245  uint64_t    i4;
246  uint64_t    i5;
247  uint64_t    i6_fp;
248  uint64_t    i7;
249  void       *structure_return_address;
250  /*
251   *  The following are for the callee to save the register arguments in
252   *  should this be necessary.
253   */
254  uint64_t    saved_arg0;
255  uint64_t    saved_arg1;
256  uint64_t    saved_arg2;
257  uint64_t    saved_arg3;
258  uint64_t    saved_arg4;
259  uint64_t    saved_arg5;
260  uint64_t    pad0;
261}  CPU_Minimum_stack_frame;
262
263#endif /* !ASM */
264
265#define CPU_STACK_FRAME_L0_OFFSET             0x00
266#define CPU_STACK_FRAME_L1_OFFSET             0x08
267#define CPU_STACK_FRAME_L2_OFFSET             0x10
268#define CPU_STACK_FRAME_L3_OFFSET             0x18
269#define CPU_STACK_FRAME_L4_OFFSET             0x20
270#define CPU_STACK_FRAME_L5_OFFSET             0x28
271#define CPU_STACK_FRAME_L6_OFFSET             0x30
272#define CPU_STACK_FRAME_L7_OFFSET             0x38
273#define CPU_STACK_FRAME_I0_OFFSET             0x40
274#define CPU_STACK_FRAME_I1_OFFSET             0x48
275#define CPU_STACK_FRAME_I2_OFFSET             0x50
276#define CPU_STACK_FRAME_I3_OFFSET             0x58
277#define CPU_STACK_FRAME_I4_OFFSET             0x60
278#define CPU_STACK_FRAME_I5_OFFSET             0x68
279#define CPU_STACK_FRAME_I6_FP_OFFSET          0x70
280#define CPU_STACK_FRAME_I7_OFFSET             0x78
281#define CPU_STRUCTURE_RETURN_ADDRESS_OFFSET   0x80
282#define CPU_STACK_FRAME_SAVED_ARG0_OFFSET     0x88
283#define CPU_STACK_FRAME_SAVED_ARG1_OFFSET     0x90
284#define CPU_STACK_FRAME_SAVED_ARG2_OFFSET     0x98
285#define CPU_STACK_FRAME_SAVED_ARG3_OFFSET     0xA0
286#define CPU_STACK_FRAME_SAVED_ARG4_OFFSET     0xA8
287#define CPU_STACK_FRAME_SAVED_ARG5_OFFSET     0xB0
288#define CPU_STACK_FRAME_PAD0_OFFSET           0xB8
289
290#define CPU_MINIMUM_STACK_FRAME_SIZE          0xC0
291
292/*
293 * Contexts
294 *
295 *  Generally there are 2 types of context to save.
296 *     1. Interrupt registers to save
297 *     2. Task level registers to save
298 *
299 *  This means we have the following 3 context items:
300 *     1. task level context stuff::  Context_Control
301 *     2. floating point task stuff:: Context_Control_fp
302 *     3. special interrupt level context :: Context_Control_interrupt
303 *
304 *  On the SPARC, we are relatively conservative in that we save most
305 *  of the CPU state in the context area.  The ET (enable trap) bit and
306 *  the CWP (current window pointer) fields of the PSR are considered
307 *  system wide resources and are not maintained on a per-thread basis.
308 */
309
310#ifndef ASM
311
312typedef struct {
313    uint64_t   g1;
314    uint64_t   g2;
315    uint64_t   g3;
316    uint64_t   g4;
317    uint64_t   g5;
318    uint64_t   g6;
319    uint64_t   g7;
320
321    uint64_t   l0;
322    uint64_t   l1;
323    uint64_t   l2;
324    uint64_t   l3;
325    uint64_t   l4;
326    uint64_t   l5;
327    uint64_t   l6;
328    uint64_t   l7;
329
330    uint64_t   i0;
331    uint64_t   i1;
332    uint64_t   i2;
333    uint64_t   i3;
334    uint64_t   i4;
335    uint64_t   i5;
336    uint64_t   i6_fp;
337    uint64_t   i7;
338
339    uint64_t   o0;
340    uint64_t   o1;
341    uint64_t   o2;
342    uint64_t   o3;
343    uint64_t   o4;
344    uint64_t   o5;
345    uint64_t   o6_sp;
346    uint64_t   o7;
347
348    uint32_t   isr_dispatch_disable;
349    uint32_t   pad;
350} Context_Control;
351
352#define _CPU_Context_Get_SP( _context ) \
353  (_context)->o6_sp
354
355#endif /* ASM */
356
357/*
358 *  Offsets of fields with Context_Control for assembly routines.
359 */
360
361#define G1_OFFSET    0x00
362#define G2_OFFSET    0x08
363#define G3_OFFSET    0x10
364#define G4_OFFSET    0x18
365#define G5_OFFSET    0x20
366#define G6_OFFSET    0x28
367#define G7_OFFSET    0x30
368
369#define L0_OFFSET    0x38
370#define L1_OFFSET    0x40
371#define L2_OFFSET    0x48
372#define L3_OFFSET    0x50
373#define L4_OFFSET    0x58
374#define L5_OFFSET    0x60
375#define L6_OFFSET    0x68
376#define L7_OFFSET    0x70
377
378#define I0_OFFSET    0x78
379#define I1_OFFSET    0x80
380#define I2_OFFSET    0x88
381#define I3_OFFSET    0x90
382#define I4_OFFSET    0x98
383#define I5_OFFSET    0xA0
384#define I6_FP_OFFSET    0xA8
385#define I7_OFFSET 0xB0
386
387#define O0_OFFSET    0xB8
388#define O1_OFFSET    0xC0
389#define O2_OFFSET    0xC8
390#define O3_OFFSET    0xD0
391#define O4_OFFSET    0xD8
392#define O5_OFFSET    0xE0
393#define O6_SP_OFFSET    0xE8
394#define O7_OFFSET 0xF0
395
396#define ISR_DISPATCH_DISABLE_STACK_OFFSET 0xF8
397#define ISR_PAD_OFFSET 0xFC
398
399#define CONTEXT_CONTROL_SIZE 0x100
400
401/*
402 *  The floating point context area.
403 */
404
405#ifndef ASM
406
407typedef struct {
408    double      f0;     /* f0-f1 */
409    double      f2;     /* f2-f3 */
410    double      f4;     /* f4-f5 */
411    double      f6;     /* f6-f7 */
412    double      f8;     /* f8-f9 */
413    double      f10;    /* f10-f11 */
414    double      f12;    /* f12-f13 */
415    double      f14;    /* f14-f15 */
416    double      f16;    /* f16-f17 */
417    double      f18;    /* f18-f19 */
418    double      f20;    /* f20-f21 */
419    double      f22;    /* f22-f23 */
420    double      f24;    /* f24-f25 */
421    double      f26;    /* f26-f27 */
422    double      f28;    /* f28-f29 */
423    double      f30;    /* f30-f31 */
424    double      f32;
425    double      f34;
426    double      f36;
427    double      f38;
428    double      f40;
429    double      f42;
430    double      f44;
431    double      f46;
432    double      f48;
433    double      f50;
434    double      f52;
435    double      f54;
436    double      f56;
437    double      f58;
438    double      f60;
439    double      f62;
440    uint64_t    fsr;
441} Context_Control_fp;
442
443#endif /* !ASM */
444
445/*
446 *  Offsets of fields with Context_Control_fp for assembly routines.
447 */
448
449#define FO_OFFSET    0x00
450#define F2_OFFSET    0x08
451#define F4_OFFSET    0x10
452#define F6_OFFSET    0x18
453#define F8_OFFSET    0x20
454#define F1O_OFFSET   0x28
455#define F12_OFFSET   0x30
456#define F14_OFFSET   0x38
457#define F16_OFFSET   0x40
458#define F18_OFFSET   0x48
459#define F2O_OFFSET   0x50
460#define F22_OFFSET   0x58
461#define F24_OFFSET   0x60
462#define F26_OFFSET   0x68
463#define F28_OFFSET   0x70
464#define F3O_OFFSET   0x78
465#define F32_OFFSET   0x80
466#define F34_OFFSET   0x88
467#define F36_OFFSET   0x90
468#define F38_OFFSET   0x98
469#define F4O_OFFSET   0xA0
470#define F42_OFFSET   0xA8
471#define F44_OFFSET   0xB0
472#define F46_OFFSET   0xB8
473#define F48_OFFSET   0xC0
474#define F5O_OFFSET   0xC8
475#define F52_OFFSET   0xD0
476#define F54_OFFSET   0xD8
477#define F56_OFFSET   0xE0
478#define F58_OFFSET   0xE8
479#define F6O_OFFSET   0xF0
480#define F62_OFFSET   0xF8
481#define FSR_OFFSET   0x100
482
483#define CONTEXT_CONTROL_FP_SIZE 0x108
484
485#ifndef ASM
486
487/*
488 *  Context saved on stack for an interrupt.
489 *
490 *  NOTE:  The tstate, tpc, and tnpc are saved in this structure
491 *         to allow resetting the TL while still being able to return
492 *         from a trap later.  The PIL is saved because
493 *         if this is an external interrupt, we will mask lower
494 *         priority interrupts until finishing. Even though the y register
495 *         is deprecated, gcc still uses it.
496 */
497
498typedef struct {
499  CPU_Minimum_stack_frame  Stack_frame;
500  uint64_t                 tstate;
501  uint64_t                 tpc;
502  uint64_t                 tnpc;
503  uint64_t                 pil;
504  uint64_t                 y;
505  uint64_t                 g1;
506  uint64_t                 g2;
507  uint64_t                 g3;
508  uint64_t                 g4;
509  uint64_t                 g5;
510  uint64_t                 g6;
511  uint64_t                 g7;
512  uint64_t                 o0;
513  uint64_t                 o1;
514  uint64_t                 o2;
515  uint64_t                 o3;
516  uint64_t                 o4;
517  uint64_t                 o5;
518  uint64_t                 o6_sp;
519  uint64_t                 o7;
520} CPU_Interrupt_frame;
521
522#endif /* ASM */
523
524/*
525 *  Offsets of fields with CPU_Interrupt_frame for assembly routines.
526 */
527
528#define ISF_STACK_FRAME_OFFSET 0x00
529#define ISF_TSTATE_OFFSET      CPU_MINIMUM_STACK_FRAME_SIZE + 0x00
530#define ISF_TPC_OFFSET         CPU_MINIMUM_STACK_FRAME_SIZE + 0x08
531#define ISF_TNPC_OFFSET        CPU_MINIMUM_STACK_FRAME_SIZE + 0x10
532#define ISF_PIL_OFFSET         CPU_MINIMUM_STACK_FRAME_SIZE + 0x18
533#define ISF_Y_OFFSET           CPU_MINIMUM_STACK_FRAME_SIZE + 0x20
534#define ISF_G1_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x28
535#define ISF_G2_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x30
536#define ISF_G3_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x38
537#define ISF_G4_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x40
538#define ISF_G5_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x48
539#define ISF_G6_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x50
540#define ISF_G7_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x58
541#define ISF_O0_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x60
542#define ISF_O1_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x68
543#define ISF_O2_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x70
544#define ISF_O3_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x78
545#define ISF_O4_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x80
546#define ISF_O5_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x88
547#define ISF_O6_SP_OFFSET       CPU_MINIMUM_STACK_FRAME_SIZE + 0x90
548#define ISF_O7_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x98
549#define ISF_TVEC_NUM            CPU_MINIMUM_STACK_FRAME_SIZE + 0xA0
550
551#define CONTEXT_CONTROL_INTERRUPT_FRAME_SIZE CPU_MINIMUM_STACK_FRAME_SIZE + 0xA8
552#ifndef ASM
553/*
554 *  This variable is contains the initialize context for the FP unit.
555 *  It is filled in by _CPU_Initialize and copied into the task's FP
556 *  context area during _CPU_Context_Initialize.
557 */
558
559SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context CPU_STRUCTURE_ALIGNMENT;
560
561/*
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.  Thus
568 *  both must be present if either is.
569 *
570 *  The SPARC supports a software based interrupt stack and these
571 *  are required.
572 */
573
574SCORE_EXTERN void *_CPU_Interrupt_stack_low;
575SCORE_EXTERN void *_CPU_Interrupt_stack_high;
576
577/*
578 *  This flag is context switched with each thread.  It indicates
579 *  that THIS thread has an _ISR_Dispatch stack frame on its stack.
580 *  By using this flag, we can avoid nesting more interrupt dispatching
581 *  attempts on a previously interrupted thread's stack.
582 */
583
584SCORE_EXTERN volatile uint32_t _CPU_ISR_Dispatch_disable;
585
586/*
587 *  The following type defines an entry in the SPARC's trap table.
588 *
589 *  NOTE: The instructions chosen are RTEMS dependent although one is
590 *        obligated to use two of the four instructions to perform a
591 *        long jump.  The other instructions load one register with the
592 *        trap type (a.k.a. vector) and another with the psr.
593 */
594/* For SPARC V9, we must use 6 of these instructions to perform a long
595 * jump, because the _handler value is now 64-bits. We also need to store
596 * temporary values in the global register set at this trap level. Because
597 * the handler runs at TL > 0 with GL > 0, it should be OK to use g2 and g3
598 * to pass parameters to ISR_Handler.
599 *
600 * The instruction sequence is now more like:
601 *      rdpr %tstate, %g4
602 *      setx _handler, %g2, %g3
603 *      jmp %g3+0
604 *      mov _vector, %g2
605 */
606typedef struct {
607  uint32_t     rdpr_tstate_g4;                  /* rdpr  %tstate, %g4        */
608  uint32_t     sethi_of_hh_handler_to_g2;       /* sethi %hh(_handler), %g2  */
609  uint32_t     or_g2_hm_handler_to_g2;          /* or %l3, %hm(_handler), %g2 */
610  uint32_t     sllx_g2_by_32_to_g2;             /* sllx   %g2, 32, %g2 */
611  uint32_t     sethi_of_handler_to_g3;          /* sethi %hi(_handler), %g3  */
612  uint32_t     or_g3_g2_to_g3;                  /* or     %g3, %g2, %g3 */
613  uint32_t     jmp_to_low_of_handler_plus_g3;   /* jmp   %g3 + %lo(_handler) */
614  uint32_t     mov_vector_g2;                   /* mov   _vector, %g2        */
615} CPU_Trap_table_entry;
616 
617/*
618 *  This is the set of opcodes for the instructions loaded into a trap
619 *  table entry.  The routine which installs a handler is responsible
620 *  for filling in the fields for the _handler address and the _vector
621 *  trap type.
622 *
623 *  The constants following this structure are masks for the fields which
624 *  must be filled in when the handler is installed.
625 */
626 
627extern const CPU_Trap_table_entry _CPU_Trap_slot_template;
628
629/*
630 *  The size of the floating point context area. 
631 */
632
633#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
634
635#endif
636
637/*
638 *  Amount of extra stack (above minimum stack size) required by
639 *  MPCI receive server thread.  Remember that in a multiprocessor
640 *  system this thread must exist and be able to process all directives.
641 */
642
643#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 1024
644
645/*
646 *  This defines the number of entries in the ISR_Vector_table managed
647 *  by the executive.
648 *
649 *  On the SPARC, there are really only 256 vectors.  However, the executive
650 *  has no easy, fast, reliable way to determine which traps are synchronous
651 *  and which are asynchronous.  By default, synchronous traps return to the
652 *  instruction which caused the interrupt.  So if you install a software
653 *  trap handler as an executive interrupt handler (which is desirable since
654 *  RTEMS takes care of window and register issues), then the executive needs
655 *  to know that the return address is to the trap rather than the instruction
656 *  following the trap.
657 *
658 *  So vectors 0 through 255 are treated as regular asynchronous traps which
659 *  provide the "correct" return address.  Vectors 256 through 512 are assumed
660 *  by the executive to be synchronous and to require that the return address
661 *  be fudged.
662 *
663 *  If you use this mechanism to install a trap handler which must reexecute
664 *  the instruction which caused the trap, then it should be installed as
665 *  an asynchronous trap.  This will avoid the executive changing the return
666 *  address.
667 */
668/* On SPARC v9, there are 512 vectors. The same philosophy applies to
669 * vector installation and use, we just provide a larger table.
670 */
671#define CPU_INTERRUPT_NUMBER_OF_VECTORS     512
672#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER 1023
673
674#define SPARC_SYNCHRONOUS_TRAP_BIT_MASK     0x200
675#define SPARC_ASYNCHRONOUS_TRAP( _trap )    (_trap)
676#define SPARC_SYNCHRONOUS_TRAP( _trap )     ((_trap) + 512 )
677
678#define SPARC_REAL_TRAP_NUMBER( _trap )     ((_trap) % 512)
679
680/*
681 *  This is defined if the port has a special way to report the ISR nesting
682 *  level.  Most ports maintain the variable _ISR_Nest_level.
683 */
684
685#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
686
687/*
688 *  Should be large enough to run all tests.  This ensures
689 *  that a "reasonable" small application should not have any problems.
690 *
691 *  This appears to be a fairly generous number for the SPARC since
692 *  represents a call depth of about 20 routines based on the minimum
693 *  stack frame.
694 */
695
696#define CPU_STACK_MINIMUM_SIZE  (1024*8)
697
698/*
699 *  CPU's worst alignment requirement for data types on a byte boundary.  This
700 *  alignment does not take into account the requirements for the stack.
701 *
702 *  On the SPARC, this is required for double word loads and stores.
703 *
704 *  Note: quad-word loads/stores need alignment of 16, but currently supported
705 *  architectures do not provide HW implemented quad-word operations.
706 */
707
708#define CPU_ALIGNMENT      8
709
710/*
711 *  This number corresponds to the byte alignment requirement for the
712 *  heap handler.  This alignment requirement may be stricter than that
713 *  for the data types alignment specified by CPU_ALIGNMENT.  It is
714 *  common for the heap to follow the same alignment requirement as
715 *  CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
716 *  then this should be set to CPU_ALIGNMENT.
717 *
718 *  NOTE:  This does not have to be a power of 2.  It does have to
719 *         be greater or equal to than CPU_ALIGNMENT.
720 */
721
722#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
723
724/*
725 *  This number corresponds to the byte alignment requirement for memory
726 *  buffers allocated by the partition manager.  This alignment requirement
727 *  may be stricter than that for the data types alignment specified by
728 *  CPU_ALIGNMENT.  It is common for the partition to follow the same
729 *  alignment requirement as CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict
730 *  enough for the partition, then this should be set to CPU_ALIGNMENT.
731 *
732 *  NOTE:  This does not have to be a power of 2.  It does have to
733 *         be greater or equal to than CPU_ALIGNMENT.
734 */
735
736#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
737
738/*
739 *  This number corresponds to the byte alignment requirement for the
740 *  stack.  This alignment requirement may be stricter than that for the
741 *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
742 *  is strict enough for the stack, then this should be set to 0.
743 *
744 *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
745 *
746 *  The alignment restrictions for the SPARC are not that strict but this
747 *  should unsure that the stack is always sufficiently alignment that the
748 *  window overflow, underflow, and flush routines can use double word loads
749 *  and stores.
750 */
751
752#define CPU_STACK_ALIGNMENT        16
753
754#ifndef ASM
755
756/*
757 *  ISR handler macros
758 */
759
760/*
761 *  Support routine to initialize the RTEMS vector table after it is allocated.
762 */
763
764#define _CPU_Initialize_vectors()
765
766/*
767 *  Disable all interrupts for a critical section.  The previous
768 *  level is returned in _level.
769 */
770
771 #define _CPU_ISR_Disable( _level ) \
772  (_level) = sparc_disable_interrupts()
773
774/*
775 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
776 *  This indicates the end of a critical section.  The parameter
777 *  _level is not modified.
778 */
779
780#define _CPU_ISR_Enable( _level ) \
781  sparc_enable_interrupts( _level )
782
783/*
784 *  This temporarily restores the interrupt to _level before immediately
785 *  disabling them again.  This is used to divide long critical
786 *  sections into two or more parts.  The parameter _level is not
787 *  modified.
788 */
789
790#define _CPU_ISR_Flash( _level ) \
791   sparc_flash_interrupts( _level )
792
793/*
794 *  Map interrupt level in task mode onto the hardware that the CPU
795 *  actually provides.  Currently, interrupt levels which do not
796 *  map onto the CPU in a straight fashion are undefined. 
797 */
798
799#define _CPU_ISR_Set_level( _newlevel ) \
800   sparc_enable_interrupts( _newlevel)
801
802uint32_t   _CPU_ISR_Get_level( void );
803 
804/* end of ISR handler macros */
805
806/* Context handler macros */
807
808/*
809 *  Initialize the context to a state suitable for starting a
810 *  task after a context restore operation.  Generally, this
811 *  involves:
812 *
813 *     - setting a starting address
814 *     - preparing the stack
815 *     - preparing the stack and frame pointers
816 *     - setting the proper interrupt level in the context
817 *     - initializing the floating point context
818 *
819 *  NOTE:  Implemented as a subroutine for the SPARC port.
820 */
821
822void _CPU_Context_Initialize(
823  Context_Control  *the_context,
824  void         *stack_base,
825  uint32_t          size,
826  uint32_t          new_level,
827  void             *entry_point,
828  bool              is_fp
829);
830
831/*
832 *  This macro is invoked from _Thread_Handler to do whatever CPU
833 *  specific magic is required that must be done in the context of
834 *  the thread when it starts.
835 *
836 *  On the SPARC, this is setting the frame pointer so GDB is happy.
837 *  Make GDB stop unwinding at _Thread_Handler, previous register window
838 *  Frame pointer is 0 and calling address must be a function with starting
839 *  with a SAVE instruction. If return address is leaf-function (no SAVE)
840 *  GDB will not look at prev reg window fp.
841 *
842 *  _Thread_Handler is known to start with SAVE.
843 */
844
845#define _CPU_Context_Initialization_at_thread_begin() \
846  do { \
847    asm volatile ("set _Thread_Handler,%%i7\n"::); \
848  } while (0)
849
850/*
851 *  This routine is responsible for somehow restarting the currently
852 *  executing task. 
853 *
854 *  On the SPARC, this is is relatively painless but requires a small
855 *  amount of wrapper code before using the regular restore code in
856 *  of the context switch.
857 */
858
859#define _CPU_Context_Restart_self( _the_context ) \
860   _CPU_Context_restore( (_the_context) );
861
862/*
863 *  The FP context area for the SPARC is a simple structure and nothing
864 *  special is required to find the "starting load point"
865 */
866
867#define _CPU_Context_Fp_start( _base, _offset ) \
868   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
869
870/*
871 *  This routine initializes the FP context area passed to it to.
872 *
873 *  The SPARC allows us to use the simple initialization model
874 *  in which an "initial" FP context was saved into _CPU_Null_fp_context
875 *  at CPU initialization and it is simply copied into the destination
876 *  context.
877 */
878
879#define _CPU_Context_Initialize_fp( _destination ) \
880  do { \
881   *(*(_destination)) = _CPU_Null_fp_context; \
882  } while (0)
883
884/* end of Context handler macros */
885
886/* Fatal Error manager macros */
887
888/*
889 *  This routine copies _error into a known place -- typically a stack
890 *  location or a register, optionally disables interrupts, and
891 *  halts/stops the CPU.
892 */
893
894#define _CPU_Fatal_halt( _error ) \
895  do { \
896    uint32_t   level; \
897    \
898    level = sparc_disable_interrupts(); \
899    asm volatile ( "mov  %0, %%g1 " : "=r" (level) : "0" (level) ); \
900    while (1); /* loop forever */ \
901  } while (0)
902
903/* end of Fatal Error manager macros */
904
905/* Bitfield handler macros */
906
907/*
908 *  The SPARC port uses the generic C algorithm for bitfield scan if the
909 *  CPU model does not have a scan instruction.
910 */
911
912#if ( SPARC_HAS_BITSCAN == 0 )
913#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
914#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
915#else
916#error "scan instruction not currently supported by RTEMS!!"
917#endif
918
919/* end of Bitfield handler macros */
920
921/* Priority handler handler macros */
922
923/*
924 *  The SPARC port uses the generic C algorithm for bitfield scan if the
925 *  CPU model does not have a scan instruction.
926 */
927
928#if ( SPARC_HAS_BITSCAN == 1 )
929#error "scan instruction not currently supported by RTEMS!!"
930#endif
931
932/* end of Priority handler macros */
933
934/* functions */
935
936/*
937 *  _CPU_Initialize
938 *
939 *  This routine performs CPU dependent initialization.
940 */
941
942void _CPU_Initialize(void);
943
944/*
945 *  _CPU_ISR_install_raw_handler
946 *
947 *  This routine installs new_handler to be directly called from the trap
948 *  table.
949 */
950 
951void _CPU_ISR_install_raw_handler(
952  uint32_t    vector,
953  proc_ptr    new_handler,
954  proc_ptr   *old_handler
955);
956
957/*
958 *  _CPU_ISR_install_vector
959 *
960 *  This routine installs an interrupt vector.
961 */
962
963void _CPU_ISR_install_vector(
964  uint64_t    vector,
965  proc_ptr    new_handler,
966  proc_ptr   *old_handler
967);
968
969#if (CPU_PROVIDES_IDLE_THREAD_BODY == TRUE)
970 
971/*
972 *  _CPU_Thread_Idle_body
973 *
974 *  Some SPARC implementations have low power, sleep, or idle modes.  This
975 *  tries to take advantage of those models.
976 */
977 
978void *_CPU_Thread_Idle_body( uintptr_t ignored );
979
980#endif /* CPU_PROVIDES_IDLE_THREAD_BODY */
981
982/*
983 *  _CPU_Context_switch
984 *
985 *  This routine switches from the run context to the heir context.
986 */
987
988void _CPU_Context_switch(
989  Context_Control  *run,
990  Context_Control  *heir
991);
992
993/*
994 *  _CPU_Context_restore
995 *
996 *  This routine is generally used only to restart self in an
997 *  efficient manner.
998 */
999
1000void _CPU_Context_restore(
1001  Context_Control *new_context
1002);
1003
1004/*
1005 *  _CPU_Context_save_fp
1006 *
1007 *  This routine saves the floating point context passed to it.
1008 */
1009
1010void _CPU_Context_save_fp(
1011  Context_Control_fp **fp_context_ptr
1012);
1013
1014/*
1015 *  _CPU_Context_restore_fp
1016 *
1017 *  This routine restores the floating point context passed to it.
1018 */
1019
1020void _CPU_Context_restore_fp(
1021  Context_Control_fp **fp_context_ptr
1022);
1023
1024/*
1025 *  CPU_swap_u32
1026 *
1027 *  The following routine swaps the endian format of an unsigned int.
1028 *  It must be static because it is referenced indirectly.
1029 *
1030 *  This version will work on any processor, but if you come across a better
1031 *  way for the SPARC PLEASE use it.  The most common way to swap a 32-bit
1032 *  entity as shown below is not any more efficient on the SPARC.
1033 *
1034 *     swap least significant two bytes with 16-bit rotate
1035 *     swap upper and lower 16-bits
1036 *     swap most significant two bytes with 16-bit rotate
1037 *
1038 *  It is not obvious how the SPARC can do significantly better than the
1039 *  generic code.  gcc 2.7.0 only generates about 12 instructions for the
1040 *  following code at optimization level four (i.e. -O4).
1041 */
1042 
1043static inline uint32_t CPU_swap_u32(
1044  uint32_t value
1045)
1046{
1047  uint32_t   byte1, byte2, byte3, byte4, swapped;
1048 
1049  byte4 = (value >> 24) & 0xff;
1050  byte3 = (value >> 16) & 0xff;
1051  byte2 = (value >> 8)  & 0xff;
1052  byte1 =  value        & 0xff;
1053 
1054  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
1055  return( swapped );
1056}
1057
1058#define CPU_swap_u16( value ) \
1059  (((value&0xff) << 8) | ((value >> 8)&0xff))
1060
1061#endif /* ASM */
1062
1063#ifdef __cplusplus
1064}
1065#endif
1066
1067#endif
Note: See TracBrowser for help on using the repository browser.