source: rtems/cpukit/score/cpu/sparc64/rtems/score/cpu.h @ 408609f6

5
Last change on this file since 408609f6 was 408609f6, checked in by Sebastian Huber <sebastian.huber@…>, on 11/10/16 at 14:17:28

score: Add _ISR_Is_enabled()

In contrast to _ISR_Get_level() the _ISR_Is_enabled() function evaluates
a level parameter and returns a boolean value.

Update #2811.

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