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