source: rtems/cpukit/score/cpu/sparc/rtems/score/cpu.h @ 655ce0fb

5
Last change on this file since 655ce0fb was 655ce0fb, checked in by Sebastian Huber <sebastian.huber@…>, on 06/22/16 at 11:45:02

sparc: Optimize CPU counter support

  • Property mode set to 100644
File size: 46.0 KB
Line 
1/**
2 * @file
3 *
4 * @brief SPARC CPU Department Source
5 *
6 * This include file contains information pertaining to the port of
7 * the executive to the SPARC processor.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2011.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#ifndef _RTEMS_SCORE_CPU_H
20#define _RTEMS_SCORE_CPU_H
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#include <rtems/score/types.h>
27#include <rtems/score/sparc.h>
28
29/* conditional compilation parameters */
30
31#if defined(RTEMS_SMP)
32  /*
33   * The SPARC ABI is a bit special with respect to the floating point context.
34   * The complete floating point context is volatile.  Thus from an ABI point
35   * of view nothing needs to be saved and restored during a context switch.
36   * Instead the floating point context must be saved and restored during
37   * interrupt processing.  Historically the deferred floating point switch is
38   * used for SPARC and the complete floating point context is saved and
39   * restored during a context switch to the new floating point unit owner.
40   * This is a bit dangerous since post-switch actions (e.g. signal handlers)
41   * and context switch extensions may silently corrupt the floating point
42   * context.  The floating point unit is disabled for interrupt handlers.
43   * Thus in case an interrupt handler uses the floating point unit then this
44   * will result in a trap.
45   *
46   * On SMP configurations the deferred floating point switch is not
47   * supported in principle.  So use here a safe floating point support.  Safe
48   * means that the volatile floating point context is saved and restored
49   * around a thread dispatch issued during interrupt processing.  Thus
50   * post-switch actions and context switch extensions may safely use the
51   * floating point unit.
52   */
53  #define SPARC_USE_SAFE_FP_SUPPORT
54#endif
55
56/**
57 * Should the calls to _Thread_Enable_dispatch be inlined?
58 *
59 * - If TRUE, then they are inlined.
60 * - If FALSE, then a subroutine call is made.
61 *
62 * On this port, it is faster to inline _Thread_Enable_dispatch.
63 */
64#define CPU_INLINE_ENABLE_DISPATCH       TRUE
65
66/**
67 * Does the executive manage a dedicated interrupt stack in software?
68 *
69 * If TRUE, then a stack is allocated in _ISR_Handler_initialization.
70 * If FALSE, nothing is done.
71 *
72 * The SPARC does not have a dedicated HW interrupt stack and one has
73 * been implemented in SW.
74 */
75#define CPU_HAS_SOFTWARE_INTERRUPT_STACK   TRUE
76
77/**
78 * Does the CPU follow the simple vectored interrupt model?
79 *
80 * - If TRUE, then RTEMS allocates the vector table it internally manages.
81 * - If FALSE, then the BSP is assumed to allocate and manage the vector
82 *   table
83 *
84 * THe SPARC is a simple vectored architecture.  Usually there is no
85 * PIC and the CPU directly vectors the interrupts.
86 */
87#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
88
89/**
90 * Does this CPU have hardware support for a dedicated interrupt stack?
91 *
92 * - If TRUE, then it must be installed during initialization.
93 * - If FALSE, then no installation is performed.
94 *
95 * The SPARC does not have a dedicated HW interrupt stack.
96 */
97#define CPU_HAS_HARDWARE_INTERRUPT_STACK  FALSE
98
99/**
100 * Do we allocate a dedicated interrupt stack in the Interrupt Manager?
101 *
102 * - If TRUE, then the memory is allocated during initialization.
103 * - If FALSE, then the memory is allocated during initialization.
104 *
105 * The SPARC does not have hardware support for switching to a
106 * dedicated interrupt stack.  The port includes support for doing this
107 * in software.
108 *
109 */
110#define CPU_ALLOCATE_INTERRUPT_STACK      TRUE
111
112/**
113 * Does the RTEMS invoke the user's ISR with the vector number and
114 * a pointer to the saved interrupt frame (1) or just the vector
115 * number (0)?
116 *
117 * The SPARC port does not pass an Interrupt Stack Frame pointer to
118 * interrupt handlers.
119 */
120#define CPU_ISR_PASSES_FRAME_POINTER 0
121
122/**
123 * Does the CPU have hardware floating point?
124 *
125 * - If TRUE, then the FLOATING_POINT task attribute is supported.
126 * - If FALSE, then the FLOATING_POINT task attribute is ignored.
127 *
128 * This is set based upon the multilib settings.
129 */
130#if ( SPARC_HAS_FPU == 1 ) && !defined(SPARC_USE_SAFE_FP_SUPPORT)
131  #define CPU_HARDWARE_FP     TRUE
132#else
133  #define CPU_HARDWARE_FP     FALSE
134#endif
135
136/**
137 * The SPARC GCC port does not have a software floating point library
138 * that requires RTEMS assistance.
139 */
140#define CPU_SOFTWARE_FP     FALSE
141
142/**
143 * Are all tasks FLOATING_POINT tasks implicitly?
144 *
145 * - If TRUE, then the FLOATING_POINT task attribute is assumed.
146 * - If FALSE, then the FLOATING_POINT task attribute is followed.
147 *
148 * The SPARC GCC port does not implicitly use floating point registers.
149 */
150#define CPU_ALL_TASKS_ARE_FP     FALSE
151
152/**
153 * Should the IDLE task have a floating point context?
154 *
155 * - If TRUE, then the IDLE task is created as a FLOATING_POINT task
156 *   and it has a floating point context which is switched in and out.
157 * - If FALSE, then the IDLE task does not have a floating point context.
158 *
159 * The IDLE task does not have to be floating point on the SPARC.
160 */
161#define CPU_IDLE_TASK_IS_FP      FALSE
162
163/**
164 * Should the saving of the floating point registers be deferred
165 * until a context switch is made to another different floating point
166 * task?
167 *
168 * - If TRUE, then the floating point context will not be stored until
169 * necessary.  It will remain in the floating point registers and not
170 * disturned until another floating point task is switched to.
171 *
172 * - If FALSE, then the floating point context is saved when a floating
173 * point task is switched out and restored when the next floating point
174 * task is restored.  The state of the floating point registers between
175 * those two operations is not specified.
176 *
177 * On the SPARC, we can disable the FPU for integer only tasks so
178 * it is safe to defer floating point context switches.
179 */
180#if defined(SPARC_USE_SAFE_FP_SUPPORT)
181  #define CPU_USE_DEFERRED_FP_SWITCH FALSE
182#else
183  #define CPU_USE_DEFERRED_FP_SWITCH TRUE
184#endif
185
186/**
187 * Does this port provide a CPU dependent IDLE task implementation?
188 *
189 * - If TRUE, then the routine _CPU_Thread_Idle_body
190 * must be provided and is the default IDLE thread body instead of
191 * _CPU_Thread_Idle_body.
192 *
193 * - If FALSE, then use the generic IDLE thread body if the BSP does
194 * not provide one.
195 *
196 * The SPARC architecture does not have a low power or halt instruction.
197 * It is left to the BSP and/or CPU specific code to provide an IDLE
198 * thread body which is aware of low power modes.
199 */
200#define CPU_PROVIDES_IDLE_THREAD_BODY    FALSE
201
202/**
203 * Does the stack grow up (toward higher addresses) or down
204 * (toward lower addresses)?
205 *
206 * - If TRUE, then the grows upward.
207 * - If FALSE, then the grows toward smaller addresses.
208 *
209 * The stack grows to lower addresses on the SPARC.
210 */
211#define CPU_STACK_GROWS_UP               FALSE
212
213/* LEON3 systems may use a cache line size of 64 */
214#define CPU_CACHE_LINE_BYTES 64
215
216#define CPU_STRUCTURE_ALIGNMENT RTEMS_ALIGNED( CPU_CACHE_LINE_BYTES )
217
218/**
219 * Define what is required to specify how the network to host conversion
220 * routines are handled.
221 *
222 * The SPARC is big endian.
223 */
224#define CPU_BIG_ENDIAN                           TRUE
225
226/**
227 * Define what is required to specify how the network to host conversion
228 * routines are handled.
229 *
230 * The SPARC is NOT little endian.
231 */
232#define CPU_LITTLE_ENDIAN                        FALSE
233
234/**
235 * The following defines the number of bits actually used in the
236 * interrupt field of the task mode.  How those bits map to the
237 * CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
238 *
239 * The SPARC has 16 interrupt levels in the PIL field of the PSR.
240 */
241#define CPU_MODES_INTERRUPT_MASK   0x0000000F
242
243#ifndef ASM
244/**
245 * This structure represents the organization of the minimum stack frame
246 * for the SPARC.  More framing information is required in certain situaions
247 * such as when there are a large number of out parameters or when the callee
248 * must save floating point registers.
249 */
250typedef struct {
251  /** This is the offset of the l0 register. */
252  uint32_t    l0;
253  /** This is the offset of the l1 register. */
254  uint32_t    l1;
255  /** This is the offset of the l2 register. */
256  uint32_t    l2;
257  /** This is the offset of the l3 register. */
258  uint32_t    l3;
259  /** This is the offset of the l4 register. */
260  uint32_t    l4;
261  /** This is the offset of the l5 register. */
262  uint32_t    l5;
263  /** This is the offset of the l6 register. */
264  uint32_t    l6;
265  /** This is the offset of the l7 register. */
266  uint32_t    l7;
267  /** This is the offset of the l0 register. */
268  uint32_t    i0;
269  /** This is the offset of the i1 register. */
270  uint32_t    i1;
271  /** This is the offset of the i2 register. */
272  uint32_t    i2;
273  /** This is the offset of the i3 register. */
274  uint32_t    i3;
275  /** This is the offset of the i4 register. */
276  uint32_t    i4;
277  /** This is the offset of the i5 register. */
278  uint32_t    i5;
279  /** This is the offset of the i6 register. */
280  uint32_t    i6_fp;
281  /** This is the offset of the i7 register. */
282  uint32_t    i7;
283  /** This is the offset of the register used to return structures. */
284  void       *structure_return_address;
285
286  /*
287   * The following are for the callee to save the register arguments in
288   * should this be necessary.
289   */
290  /** This is the offset of the register for saved argument 0. */
291  uint32_t    saved_arg0;
292  /** This is the offset of the register for saved argument 1. */
293  uint32_t    saved_arg1;
294  /** This is the offset of the register for saved argument 2. */
295  uint32_t    saved_arg2;
296  /** This is the offset of the register for saved argument 3. */
297  uint32_t    saved_arg3;
298  /** This is the offset of the register for saved argument 4. */
299  uint32_t    saved_arg4;
300  /** This is the offset of the register for saved argument 5. */
301  uint32_t    saved_arg5;
302  /** This field pads the structure so ldd and std instructions can be used. */
303  uint32_t    pad0;
304}  CPU_Minimum_stack_frame;
305
306#endif /* ASM */
307
308/** This macro defines an offset into the stack frame for use in assembly. */
309#define CPU_STACK_FRAME_L0_OFFSET             0x00
310/** This macro defines an offset into the stack frame for use in assembly. */
311#define CPU_STACK_FRAME_L1_OFFSET             0x04
312/** This macro defines an offset into the stack frame for use in assembly. */
313#define CPU_STACK_FRAME_L2_OFFSET             0x08
314/** This macro defines an offset into the stack frame for use in assembly. */
315#define CPU_STACK_FRAME_L3_OFFSET             0x0c
316/** This macro defines an offset into the stack frame for use in assembly. */
317#define CPU_STACK_FRAME_L4_OFFSET             0x10
318/** This macro defines an offset into the stack frame for use in assembly. */
319#define CPU_STACK_FRAME_L5_OFFSET             0x14
320/** This macro defines an offset into the stack frame for use in assembly. */
321#define CPU_STACK_FRAME_L6_OFFSET             0x18
322/** This macro defines an offset into the stack frame for use in assembly. */
323#define CPU_STACK_FRAME_L7_OFFSET             0x1c
324/** This macro defines an offset into the stack frame for use in assembly. */
325#define CPU_STACK_FRAME_I0_OFFSET             0x20
326/** This macro defines an offset into the stack frame for use in assembly. */
327#define CPU_STACK_FRAME_I1_OFFSET             0x24
328/** This macro defines an offset into the stack frame for use in assembly. */
329#define CPU_STACK_FRAME_I2_OFFSET             0x28
330/** This macro defines an offset into the stack frame for use in assembly. */
331#define CPU_STACK_FRAME_I3_OFFSET             0x2c
332/** This macro defines an offset into the stack frame for use in assembly. */
333#define CPU_STACK_FRAME_I4_OFFSET             0x30
334/** This macro defines an offset into the stack frame for use in assembly. */
335#define CPU_STACK_FRAME_I5_OFFSET             0x34
336/** This macro defines an offset into the stack frame for use in assembly. */
337#define CPU_STACK_FRAME_I6_FP_OFFSET          0x38
338/** This macro defines an offset into the stack frame for use in assembly. */
339#define CPU_STACK_FRAME_I7_OFFSET             0x3c
340/** This macro defines an offset into the stack frame for use in assembly. */
341#define CPU_STRUCTURE_RETURN_ADDRESS_OFFSET   0x40
342/** This macro defines an offset into the stack frame for use in assembly. */
343#define CPU_STACK_FRAME_SAVED_ARG0_OFFSET     0x44
344/** This macro defines an offset into the stack frame for use in assembly. */
345#define CPU_STACK_FRAME_SAVED_ARG1_OFFSET     0x48
346/** This macro defines an offset into the stack frame for use in assembly. */
347#define CPU_STACK_FRAME_SAVED_ARG2_OFFSET     0x4c
348/** This macro defines an offset into the stack frame for use in assembly. */
349#define CPU_STACK_FRAME_SAVED_ARG3_OFFSET     0x50
350/** This macro defines an offset into the stack frame for use in assembly. */
351#define CPU_STACK_FRAME_SAVED_ARG4_OFFSET     0x54
352/** This macro defines an offset into the stack frame for use in assembly. */
353#define CPU_STACK_FRAME_SAVED_ARG5_OFFSET     0x58
354/** This macro defines an offset into the stack frame for use in assembly. */
355#define CPU_STACK_FRAME_PAD0_OFFSET           0x5c
356
357/** This defines the size of the minimum stack frame. */
358#define CPU_MINIMUM_STACK_FRAME_SIZE          0x60
359
360#if ( SPARC_HAS_FPU == 1 )
361  #define CPU_PER_CPU_CONTROL_SIZE 8
362#else
363  #define CPU_PER_CPU_CONTROL_SIZE 4
364#endif
365
366#define CPU_MAXIMUM_PROCESSORS 32
367
368/**
369 * @brief Offset of the CPU_Per_CPU_control::isr_dispatch_disable field
370 * relative to the Per_CPU_Control begin.
371 */
372#define SPARC_PER_CPU_ISR_DISPATCH_DISABLE 0
373
374#if ( SPARC_HAS_FPU == 1 )
375  /**
376   * @brief Offset of the CPU_Per_CPU_control::fsr field relative to the
377   * Per_CPU_Control begin.
378   */
379  #define SPARC_PER_CPU_FSR_OFFSET 4
380#endif
381
382/**
383 * @defgroup Contexts SPARC Context Structures
384 *
385 * @ingroup Score
386 *
387 * Generally there are 2 types of context to save.
388 *    + Interrupt registers to save
389 *    + Task level registers to save
390 *
391 * This means we have the following 3 context items:
392 *    + task level context stuff::  Context_Control
393 *    + floating point task stuff:: Context_Control_fp
394 *    + special interrupt level context :: Context_Control_interrupt
395 *
396 * On the SPARC, we are relatively conservative in that we save most
397 * of the CPU state in the context area.  The ET (enable trap) bit and
398 * the CWP (current window pointer) fields of the PSR are considered
399 * system wide resources and are not maintained on a per-thread basis.
400 */
401/**@{**/
402
403#ifndef ASM
404
405typedef struct {
406  /**
407   * This flag is context switched with each thread.  It indicates
408   * that THIS thread has an _ISR_Dispatch stack frame on its stack.
409   * By using this flag, we can avoid nesting more interrupt dispatching
410   * attempts on a previously interrupted thread's stack.
411   */
412  uint32_t isr_dispatch_disable;
413
414#if ( SPARC_HAS_FPU == 1 )
415  /**
416   * @brief Memory location to store the FSR register during interrupt
417   * processing.
418   *
419   * This is a write-only field.  The FSR is written to force a completion of
420   * floating point operations in progress.
421   */
422  uint32_t fsr;
423#endif
424} CPU_Per_CPU_control;
425
426/**
427 * @brief SPARC basic context.
428 *
429 * This structure defines the non-volatile integer and processor state context
430 * for the SPARC architecture according to "SYSTEM V APPLICATION BINARY
431 * INTERFACE - SPARC Processor Supplement", Third Edition.
432 *
433 * The registers g2 through g4 are reserved for applications.  GCC uses them as
434 * volatile registers by default.  So they are treated like volatile registers
435 * in RTEMS as well.
436 *
437 * The register g6 contains the per-CPU control of the current processor.  It
438 * is an invariant of the processor context.  This register must not be saved
439 * and restored during context switches or interrupt services.
440 */
441typedef struct {
442  /** This will contain the contents of the g5 register. */
443  uint32_t   g5;
444  /** This will contain the contents of the g7 register. */
445  uint32_t   g7;
446
447  /**
448   * This will contain the contents of the l0 and l1 registers.
449   *
450   * Using a double l0_and_l1 will put everything in this structure on a double
451   * word boundary which allows us to use double word loads and stores safely
452   * in the context switch.
453   */
454  double     l0_and_l1;
455  /** This will contain the contents of the l2 register. */
456  uint32_t   l2;
457  /** This will contain the contents of the l3 register. */
458  uint32_t   l3;
459  /** This will contain the contents of the l4 register. */
460  uint32_t   l4;
461  /** This will contain the contents of the l5 registeer.*/
462  uint32_t   l5;
463  /** This will contain the contents of the l6 register. */
464  uint32_t   l6;
465  /** This will contain the contents of the l7 register. */
466  uint32_t   l7;
467
468  /** This will contain the contents of the i0 register. */
469  uint32_t   i0;
470  /** This will contain the contents of the i1 register. */
471  uint32_t   i1;
472  /** This will contain the contents of the i2 register. */
473  uint32_t   i2;
474  /** This will contain the contents of the i3 register. */
475  uint32_t   i3;
476  /** This will contain the contents of the i4 register. */
477  uint32_t   i4;
478  /** This will contain the contents of the i5 register. */
479  uint32_t   i5;
480  /** This will contain the contents of the i6 (e.g. frame pointer) register. */
481  uint32_t   i6_fp;
482  /** This will contain the contents of the i7 register. */
483  uint32_t   i7;
484
485  /** This will contain the contents of the o6 (e.g. frame pointer) register. */
486  uint32_t   o6_sp;
487  /**
488   * This will contain the contents of the o7 (e.g. address of CALL
489   * instruction) register.
490   */
491  uint32_t   o7;
492
493  /** This will contain the contents of the processor status register. */
494  uint32_t   psr;
495  /**
496   * This field is used to prevent heavy nesting of calls to _Thread_Dispatch
497   * on an interrupted  task's stack.  This is problematic on the slower
498   * SPARC CPU models at high interrupt rates.
499   */
500  uint32_t   isr_dispatch_disable;
501
502#if defined(RTEMS_SMP)
503  volatile uint32_t is_executing;
504#endif
505} Context_Control;
506
507/**
508 * This macro provides a CPU independent way for RTEMS to access the
509 * stack pointer in a context structure. The actual name and offset is
510 * CPU architecture dependent.
511 */
512#define _CPU_Context_Get_SP( _context ) \
513  (_context)->o6_sp
514
515#ifdef RTEMS_SMP
516  static inline bool _CPU_Context_Get_is_executing(
517    const Context_Control *context
518  )
519  {
520    return context->is_executing;
521  }
522
523  static inline void _CPU_Context_Set_is_executing(
524    Context_Control *context,
525    bool is_executing
526  )
527  {
528    context->is_executing = is_executing;
529  }
530#endif
531
532#endif /* ASM */
533
534/*
535 *  Offsets of fields with Context_Control for assembly routines.
536 */
537
538/** This macro defines an offset into the context for use in assembly. */
539#define G5_OFFSET    0x00
540/** This macro defines an offset into the context for use in assembly. */
541#define G7_OFFSET    0x04
542
543/** This macro defines an offset into the context for use in assembly. */
544#define L0_OFFSET    0x08
545/** This macro defines an offset into the context for use in assembly. */
546#define L1_OFFSET    0x0C
547/** This macro defines an offset into the context for use in assembly. */
548#define L2_OFFSET    0x10
549/** This macro defines an offset into the context for use in assembly. */
550#define L3_OFFSET    0x14
551/** This macro defines an offset into the context for use in assembly. */
552#define L4_OFFSET    0x18
553/** This macro defines an offset into the context for use in assembly. */
554#define L5_OFFSET    0x1C
555/** This macro defines an offset into the context for use in assembly. */
556#define L6_OFFSET    0x20
557/** This macro defines an offset into the context for use in assembly. */
558#define L7_OFFSET    0x24
559
560/** This macro defines an offset into the context for use in assembly. */
561#define I0_OFFSET    0x28
562/** This macro defines an offset into the context for use in assembly. */
563#define I1_OFFSET    0x2C
564/** This macro defines an offset into the context for use in assembly. */
565#define I2_OFFSET    0x30
566/** This macro defines an offset into the context for use in assembly. */
567#define I3_OFFSET    0x34
568/** This macro defines an offset into the context for use in assembly. */
569#define I4_OFFSET    0x38
570/** This macro defines an offset into the context for use in assembly. */
571#define I5_OFFSET    0x3C
572/** This macro defines an offset into the context for use in assembly. */
573#define I6_FP_OFFSET 0x40
574/** This macro defines an offset into the context for use in assembly. */
575#define I7_OFFSET    0x44
576
577/** This macro defines an offset into the context for use in assembly. */
578#define O6_SP_OFFSET 0x48
579/** This macro defines an offset into the context for use in assembly. */
580#define O7_OFFSET    0x4C
581
582/** This macro defines an offset into the context for use in assembly. */
583#define PSR_OFFSET   0x50
584/** This macro defines an offset into the context for use in assembly. */
585#define ISR_DISPATCH_DISABLE_STACK_OFFSET 0x54
586
587#if defined(RTEMS_SMP)
588  #define SPARC_CONTEXT_CONTROL_IS_EXECUTING_OFFSET 0x58
589#endif
590
591#ifndef ASM
592/**
593 * @brief SPARC basic context.
594 *
595 * This structure defines floating point context area.
596 */
597typedef struct {
598  /** This will contain the contents of the f0 and f1 register. */
599  double      f0_f1;
600  /** This will contain the contents of the f2 and f3 register. */
601  double      f2_f3;
602  /** This will contain the contents of the f4 and f5 register. */
603  double      f4_f5;
604  /** This will contain the contents of the f6 and f7 register. */
605  double      f6_f7;
606  /** This will contain the contents of the f8 and f9 register. */
607  double      f8_f9;
608  /** This will contain the contents of the f10 and f11 register. */
609  double      f10_f11;
610  /** This will contain the contents of the f12 and f13 register. */
611  double      f12_f13;
612  /** This will contain the contents of the f14 and f15 register. */
613  double      f14_f15;
614  /** This will contain the contents of the f16 and f17 register. */
615  double      f16_f17;
616  /** This will contain the contents of the f18 and f19 register. */
617  double      f18_f19;
618  /** This will contain the contents of the f20 and f21 register. */
619  double      f20_f21;
620  /** This will contain the contents of the f22 and f23 register. */
621  double      f22_f23;
622  /** This will contain the contents of the f24 and f25 register. */
623  double      f24_f25;
624  /** This will contain the contents of the f26 and f27 register. */
625  double      f26_f27;
626  /** This will contain the contents of the f28 and f29 register. */
627  double      f28_f29;
628  /** This will contain the contents of the f30 and f31 register. */
629  double      f30_f31;
630  /** This will contain the contents of the floating point status register. */
631  uint32_t    fsr;
632} Context_Control_fp;
633
634#endif /* ASM */
635
636/*
637 *  Offsets of fields with Context_Control_fp for assembly routines.
638 */
639
640/** This macro defines an offset into the FPU context for use in assembly. */
641#define FO_F1_OFFSET     0x00
642/** This macro defines an offset into the FPU context for use in assembly. */
643#define F2_F3_OFFSET     0x08
644/** This macro defines an offset into the FPU context for use in assembly. */
645#define F4_F5_OFFSET     0x10
646/** This macro defines an offset into the FPU context for use in assembly. */
647#define F6_F7_OFFSET     0x18
648/** This macro defines an offset into the FPU context for use in assembly. */
649#define F8_F9_OFFSET     0x20
650/** This macro defines an offset into the FPU context for use in assembly. */
651#define F1O_F11_OFFSET   0x28
652/** This macro defines an offset into the FPU context for use in assembly. */
653#define F12_F13_OFFSET   0x30
654/** This macro defines an offset into the FPU context for use in assembly. */
655#define F14_F15_OFFSET   0x38
656/** This macro defines an offset into the FPU context for use in assembly. */
657#define F16_F17_OFFSET   0x40
658/** This macro defines an offset into the FPU context for use in assembly. */
659#define F18_F19_OFFSET   0x48
660/** This macro defines an offset into the FPU context for use in assembly. */
661#define F2O_F21_OFFSET   0x50
662/** This macro defines an offset into the FPU context for use in assembly. */
663#define F22_F23_OFFSET   0x58
664/** This macro defines an offset into the FPU context for use in assembly. */
665#define F24_F25_OFFSET   0x60
666/** This macro defines an offset into the FPU context for use in assembly. */
667#define F26_F27_OFFSET   0x68
668/** This macro defines an offset into the FPU context for use in assembly. */
669#define F28_F29_OFFSET   0x70
670/** This macro defines an offset into the FPU context for use in assembly. */
671#define F3O_F31_OFFSET   0x78
672/** This macro defines an offset into the FPU context for use in assembly. */
673#define FSR_OFFSET       0x80
674
675/** This defines the size of the FPU context area for use in assembly. */
676#define CONTEXT_CONTROL_FP_SIZE 0x84
677
678#ifndef ASM
679
680/** @} */
681
682/**
683 * @brief Interrupt stack frame (ISF).
684 *
685 * Context saved on stack for an interrupt.
686 *
687 * NOTE: The PSR, PC, and NPC are only saved in this structure for the
688 *       benefit of the user's handler.
689 */
690typedef struct {
691  /** On an interrupt, we must save the minimum stack frame. */
692  CPU_Minimum_stack_frame  Stack_frame;
693  /** This is the offset of the PSR on an ISF. */
694  uint32_t                 psr;
695  /** This is the offset of the XXX on an ISF. */
696  uint32_t                 pc;
697  /** This is the offset of the XXX on an ISF. */
698  uint32_t                 npc;
699  /** This is the offset of the g1 register on an ISF. */
700  uint32_t                 g1;
701  /** This is the offset of the g2 register on an ISF. */
702  uint32_t                 g2;
703  /** This is the offset of the g3 register on an ISF. */
704  uint32_t                 g3;
705  /** This is the offset of the g4 register on an ISF. */
706  uint32_t                 g4;
707  /** This is the offset of the g5 register on an ISF. */
708  uint32_t                 g5;
709  /** This is the offset is reserved for alignment on an ISF. */
710  uint32_t                 reserved_for_alignment;
711  /** This is the offset of the g7 register on an ISF. */
712  uint32_t                 g7;
713  /** This is the offset of the i0 register on an ISF. */
714  uint32_t                 i0;
715  /** This is the offset of the i1 register on an ISF. */
716  uint32_t                 i1;
717  /** This is the offset of the i2 register on an ISF. */
718  uint32_t                 i2;
719  /** This is the offset of the i3 register on an ISF. */
720  uint32_t                 i3;
721  /** This is the offset of the i4 register on an ISF. */
722  uint32_t                 i4;
723  /** This is the offset of the i5 register on an ISF. */
724  uint32_t                 i5;
725  /** This is the offset of the i6 register on an ISF. */
726  uint32_t                 i6_fp;
727  /** This is the offset of the i7 register on an ISF. */
728  uint32_t                 i7;
729  /** This is the offset of the y register on an ISF. */
730  uint32_t                 y;
731  /** This is the offset of the tpc register on an ISF. */
732  uint32_t                 tpc;
733} CPU_Interrupt_frame;
734
735#endif /* ASM */
736
737/*
738 *  Offsets of fields with CPU_Interrupt_frame for assembly routines.
739 */
740
741/** This macro defines an offset into the ISF for use in assembly. */
742#define ISF_PSR_OFFSET         CPU_MINIMUM_STACK_FRAME_SIZE + 0x00
743/** This macro defines an offset into the ISF for use in assembly. */
744#define ISF_PC_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x04
745/** This macro defines an offset into the ISF for use in assembly. */
746#define ISF_NPC_OFFSET         CPU_MINIMUM_STACK_FRAME_SIZE + 0x08
747/** This macro defines an offset into the ISF for use in assembly. */
748#define ISF_G1_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x0c
749/** This macro defines an offset into the ISF for use in assembly. */
750#define ISF_G2_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x10
751/** This macro defines an offset into the ISF for use in assembly. */
752#define ISF_G3_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x14
753/** This macro defines an offset into the ISF for use in assembly. */
754#define ISF_G4_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x18
755/** This macro defines an offset into the ISF for use in assembly. */
756#define ISF_G5_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x1c
757/** This macro defines an offset into the ISF for use in assembly. */
758#define ISF_G7_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x24
759/** This macro defines an offset into the ISF for use in assembly. */
760#define ISF_I0_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x28
761/** This macro defines an offset into the ISF for use in assembly. */
762#define ISF_I1_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x2c
763/** This macro defines an offset into the ISF for use in assembly. */
764#define ISF_I2_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x30
765/** This macro defines an offset into the ISF for use in assembly. */
766#define ISF_I3_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x34
767/** This macro defines an offset into the ISF for use in assembly. */
768#define ISF_I4_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x38
769/** This macro defines an offset into the ISF for use in assembly. */
770#define ISF_I5_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x3c
771/** This macro defines an offset into the ISF for use in assembly. */
772#define ISF_I6_FP_OFFSET       CPU_MINIMUM_STACK_FRAME_SIZE + 0x40
773/** This macro defines an offset into the ISF for use in assembly. */
774#define ISF_I7_OFFSET          CPU_MINIMUM_STACK_FRAME_SIZE + 0x44
775/** This macro defines an offset into the ISF for use in assembly. */
776#define ISF_Y_OFFSET           CPU_MINIMUM_STACK_FRAME_SIZE + 0x48
777/** This macro defines an offset into the ISF for use in assembly. */
778#define ISF_TPC_OFFSET         CPU_MINIMUM_STACK_FRAME_SIZE + 0x4c
779
780/** This defines the size of the ISF area for use in assembly. */
781#define CONTEXT_CONTROL_INTERRUPT_FRAME_SIZE \
782        CPU_MINIMUM_STACK_FRAME_SIZE + 0x50
783
784#ifndef ASM
785/**
786 * This variable is contains the initialize context for the FP unit.
787 * It is filled in by _CPU_Initialize and copied into the task's FP
788 * context area during _CPU_Context_Initialize.
789 */
790extern Context_Control_fp _CPU_Null_fp_context;
791
792/**
793 * The following type defines an entry in the SPARC's trap table.
794 *
795 * NOTE: The instructions chosen are RTEMS dependent although one is
796 *       obligated to use two of the four instructions to perform a
797 *       long jump.  The other instructions load one register with the
798 *       trap type (a.k.a. vector) and another with the psr.
799 */
800typedef struct {
801  /** This will contain a "mov %psr, %l0" instruction. */
802  uint32_t     mov_psr_l0;
803  /** This will contain a "sethi %hi(_handler), %l4" instruction. */
804  uint32_t     sethi_of_handler_to_l4;
805  /** This will contain a "jmp %l4 + %lo(_handler)" instruction. */
806  uint32_t     jmp_to_low_of_handler_plus_l4;
807  /** This will contain a " mov _vector, %l3" instruction. */
808  uint32_t     mov_vector_l3;
809} CPU_Trap_table_entry;
810
811/**
812 * This is the set of opcodes for the instructions loaded into a trap
813 * table entry.  The routine which installs a handler is responsible
814 * for filling in the fields for the _handler address and the _vector
815 * trap type.
816 *
817 * The constants following this structure are masks for the fields which
818 * must be filled in when the handler is installed.
819 */
820extern const CPU_Trap_table_entry _CPU_Trap_slot_template;
821
822/**
823 * The size of the floating point context area.
824 */
825#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
826
827#endif
828
829/**
830 * Amount of extra stack (above minimum stack size) required by
831 * MPCI receive server thread.  Remember that in a multiprocessor
832 * system this thread must exist and be able to process all directives.
833 */
834#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 1024
835
836/**
837 * This defines the number of entries in the ISR_Vector_table managed
838 * by the executive.
839 *
840 * On the SPARC, there are really only 256 vectors.  However, the executive
841 * has no easy, fast, reliable way to determine which traps are synchronous
842 * and which are asynchronous.  By default, synchronous traps return to the
843 * instruction which caused the interrupt.  So if you install a software
844 * trap handler as an executive interrupt handler (which is desirable since
845 * RTEMS takes care of window and register issues), then the executive needs
846 * to know that the return address is to the trap rather than the instruction
847 * following the trap.
848 *
849 * So vectors 0 through 255 are treated as regular asynchronous traps which
850 * provide the "correct" return address.  Vectors 256 through 512 are assumed
851 * by the executive to be synchronous and to require that the return address
852 * be fudged.
853 *
854 * If you use this mechanism to install a trap handler which must reexecute
855 * the instruction which caused the trap, then it should be installed as
856 * an asynchronous trap.  This will avoid the executive changing the return
857 * address.
858 */
859#define CPU_INTERRUPT_NUMBER_OF_VECTORS     256
860
861/**
862 * The SPARC has 256 vectors but the port treats 256-512 as synchronous
863 * traps.
864 */
865#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER 511
866
867/**
868 * This is the bit step in a vector number to indicate it is being installed
869 * as a synchronous trap.
870 */
871#define SPARC_SYNCHRONOUS_TRAP_BIT_MASK     0x100
872
873/**
874 * This macro indicates that @a _trap as an asynchronous trap.
875 */
876#define SPARC_ASYNCHRONOUS_TRAP( _trap )    (_trap)
877
878/**
879 * This macro indicates that @a _trap as a synchronous trap.
880 */
881#define SPARC_SYNCHRONOUS_TRAP( _trap )     ((_trap) + 256 )
882
883/**
884 * This macro returns the real hardware vector number associated with @a _trap.
885 */
886#define SPARC_REAL_TRAP_NUMBER( _trap )     ((_trap) % 256)
887
888/**
889 * This is defined if the port has a special way to report the ISR nesting
890 * level.  Most ports maintain the variable _ISR_Nest_level.
891 */
892#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
893
894/**
895 * Should be large enough to run all tests.  This ensures
896 * that a "reasonable" small application should not have any problems.
897 *
898 * This appears to be a fairly generous number for the SPARC since
899 * represents a call depth of about 20 routines based on the minimum
900 * stack frame.
901 */
902#define CPU_STACK_MINIMUM_SIZE  (1024*4)
903
904/**
905 * What is the size of a pointer on this architecture?
906 */
907#define CPU_SIZEOF_POINTER 4
908
909/**
910 * CPU's worst alignment requirement for data types on a byte boundary.  This
911 * alignment does not take into account the requirements for the stack.
912 *
913 * On the SPARC, this is required for double word loads and stores.
914 */
915#define CPU_ALIGNMENT      8
916
917/**
918 * This number corresponds to the byte alignment requirement for the
919 * heap handler.  This alignment requirement may be stricter than that
920 * for the data types alignment specified by CPU_ALIGNMENT.  It is
921 * common for the heap to follow the same alignment requirement as
922 * CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
923 * then this should be set to CPU_ALIGNMENT.
924 *
925 * NOTE:  This does not have to be a power of 2.  It does have to
926 *        be greater or equal to than CPU_ALIGNMENT.
927 */
928#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
929
930/**
931 * This number corresponds to the byte alignment requirement for memory
932 * buffers allocated by the partition manager.  This alignment requirement
933 * may be stricter than that for the data types alignment specified by
934 * CPU_ALIGNMENT.  It is common for the partition to follow the same
935 * alignment requirement as CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict
936 * enough for the partition, then this should be set to CPU_ALIGNMENT.
937 *
938 * NOTE:  This does not have to be a power of 2.  It does have to
939 *        be greater or equal to than CPU_ALIGNMENT.
940 */
941#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
942
943/**
944 * This number corresponds to the byte alignment requirement for the
945 * stack.  This alignment requirement may be stricter than that for the
946 * data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
947 * is strict enough for the stack, then this should be set to 0.
948 *
949 * NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
950 *
951 * The alignment restrictions for the SPARC are not that strict but this
952 * should unsure that the stack is always sufficiently alignment that the
953 * window overflow, underflow, and flush routines can use double word loads
954 * and stores.
955 */
956#define CPU_STACK_ALIGNMENT        16
957
958#ifndef ASM
959
960/*
961 *  ISR handler macros
962 */
963
964/**
965 * Support routine to initialize the RTEMS vector table after it is allocated.
966 */
967#define _CPU_Initialize_vectors()
968
969/**
970 * Disable all interrupts for a critical section.  The previous
971 * level is returned in _level.
972 */
973#define _CPU_ISR_Disable( _level ) \
974  (_level) = sparc_disable_interrupts()
975
976/**
977 * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
978 * This indicates the end of a critical section.  The parameter
979 * _level is not modified.
980 */
981#define _CPU_ISR_Enable( _level ) \
982  sparc_enable_interrupts( _level )
983
984/**
985 * This temporarily restores the interrupt to _level before immediately
986 * disabling them again.  This is used to divide long critical
987 * sections into two or more parts.  The parameter _level is not
988 * modified.
989 */
990#define _CPU_ISR_Flash( _level ) \
991  sparc_flash_interrupts( _level )
992
993/**
994 * Map interrupt level in task mode onto the hardware that the CPU
995 * actually provides.  Currently, interrupt levels which do not
996 * map onto the CPU in a straight fashion are undefined.
997 */
998#define _CPU_ISR_Set_level( _newlevel ) \
999   sparc_enable_interrupts( _newlevel << 8)
1000
1001/**
1002 * @brief Obtain the current interrupt disable level.
1003 *
1004 * This method is invoked to return the current interrupt disable level.
1005 *
1006 * @return This method returns the current interrupt disable level.
1007 */
1008uint32_t   _CPU_ISR_Get_level( void );
1009
1010/* end of ISR handler macros */
1011
1012/* Context handler macros */
1013
1014/**
1015 * Initialize the context to a state suitable for starting a
1016 * task after a context restore operation.  Generally, this
1017 * involves:
1018 *
1019 * - setting a starting address
1020 * - preparing the stack
1021 * - preparing the stack and frame pointers
1022 * - setting the proper interrupt level in the context
1023 * - initializing the floating point context
1024 *
1025 * @param[in] the_context points to the context area
1026 * @param[in] stack_base is the low address of the allocated stack area
1027 * @param[in] size is the size of the stack area in bytes
1028 * @param[in] new_level is the interrupt level for the task
1029 * @param[in] entry_point is the task's entry point
1030 * @param[in] is_fp is set to TRUE if the task is a floating point task
1031 * @param[in] tls_area is the thread-local storage (TLS) area
1032 *
1033 * NOTE:  Implemented as a subroutine for the SPARC port.
1034 */
1035void _CPU_Context_Initialize(
1036  Context_Control  *the_context,
1037  uint32_t         *stack_base,
1038  uint32_t          size,
1039  uint32_t          new_level,
1040  void             *entry_point,
1041  bool              is_fp,
1042  void             *tls_area
1043);
1044
1045/**
1046 * This macro is invoked from _Thread_Handler to do whatever CPU
1047 * specific magic is required that must be done in the context of
1048 * the thread when it starts.
1049 *
1050 * On the SPARC, this is setting the frame pointer so GDB is happy.
1051 * Make GDB stop unwinding at _Thread_Handler, previous register window
1052 * Frame pointer is 0 and calling address must be a function with starting
1053 * with a SAVE instruction. If return address is leaf-function (no SAVE)
1054 * GDB will not look at prev reg window fp.
1055 *
1056 * _Thread_Handler is known to start with SAVE.
1057 */
1058#define _CPU_Context_Initialization_at_thread_begin() \
1059  do { \
1060    __asm__ volatile ("set _Thread_Handler,%%i7\n"::); \
1061  } while (0)
1062
1063/**
1064 * This routine is responsible for somehow restarting the currently
1065 * executing task.
1066 *
1067 * On the SPARC, this is is relatively painless but requires a small
1068 * amount of wrapper code before using the regular restore code in
1069 * of the context switch.
1070 */
1071#define _CPU_Context_Restart_self( _the_context ) \
1072   _CPU_Context_restore( (_the_context) );
1073
1074/**
1075 * The FP context area for the SPARC is a simple structure and nothing
1076 * special is required to find the "starting load point"
1077 */
1078#define _CPU_Context_Fp_start( _base, _offset ) \
1079   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
1080
1081/**
1082 * This routine initializes the FP context area passed to it to.
1083 *
1084 * The SPARC allows us to use the simple initialization model
1085 * in which an "initial" FP context was saved into _CPU_Null_fp_context
1086 * at CPU initialization and it is simply copied into the destination
1087 * context.
1088 */
1089#define _CPU_Context_Initialize_fp( _destination ) \
1090  do { \
1091   *(*(_destination)) = _CPU_Null_fp_context; \
1092  } while (0)
1093
1094/* end of Context handler macros */
1095
1096/* Fatal Error manager macros */
1097
1098/**
1099 * This routine copies _error into a known place -- typically a stack
1100 * location or a register, optionally disables interrupts, and
1101 * halts/stops the CPU.
1102 */
1103extern void _CPU_Fatal_halt(uint32_t source, uint32_t error)
1104  RTEMS_NO_RETURN;
1105
1106/* end of Fatal Error manager macros */
1107
1108/* Bitfield handler macros */
1109
1110#if ( SPARC_HAS_BITSCAN == 0 )
1111  /**
1112   * The SPARC port uses the generic C algorithm for bitfield scan if the
1113   * CPU model does not have a scan instruction.
1114   */
1115  #define CPU_USE_GENERIC_BITFIELD_CODE TRUE
1116#else
1117  #error "scan instruction not currently supported by RTEMS!!"
1118#endif
1119
1120/* end of Bitfield handler macros */
1121
1122/* functions */
1123
1124/**
1125 * @brief SPARC specific initialization.
1126 *
1127 * This routine performs CPU dependent initialization.
1128 */
1129void _CPU_Initialize(void);
1130
1131/**
1132 * @brief SPARC specific raw ISR installer.
1133 *
1134 * This routine installs @a new_handler to be directly called from the trap
1135 * table.
1136 *
1137 * @param[in] vector is the vector number
1138 * @param[in] new_handler is the new ISR handler
1139 * @param[in] old_handler will contain the old ISR handler
1140 */
1141void _CPU_ISR_install_raw_handler(
1142  uint32_t    vector,
1143  proc_ptr    new_handler,
1144  proc_ptr   *old_handler
1145);
1146
1147/**
1148 * @brief SPARC specific RTEMS ISR installer.
1149 *
1150 * This routine installs an interrupt vector.
1151 *
1152 * @param[in] vector is the vector number
1153 * @param[in] new_handler is the new ISR handler
1154 * @param[in] old_handler will contain the old ISR handler
1155 */
1156
1157void _CPU_ISR_install_vector(
1158  uint32_t    vector,
1159  proc_ptr    new_handler,
1160  proc_ptr   *old_handler
1161);
1162
1163/**
1164 * @brief SPARC specific context switch.
1165 *
1166 * This routine switches from the run context to the heir context.
1167 *
1168 * @param[in] run is the currently executing thread
1169 * @param[in] heir will become the currently executing thread
1170 */
1171void _CPU_Context_switch(
1172  Context_Control  *run,
1173  Context_Control  *heir
1174);
1175
1176/**
1177 * @brief SPARC specific context restore.
1178 *
1179 * This routine is generally used only to restart self in an
1180 * efficient manner.
1181 *
1182 * @param[in] new_context is the context to restore
1183 */
1184void _CPU_Context_restore(
1185  Context_Control *new_context
1186) RTEMS_NO_RETURN;
1187
1188/**
1189 * @brief The pointer to the current per-CPU control is available via register
1190 * g6.
1191 */
1192register struct Per_CPU_Control *_SPARC_Per_CPU_current __asm__( "g6" );
1193
1194#define _CPU_Get_current_per_CPU_control() _SPARC_Per_CPU_current
1195
1196#if defined(RTEMS_SMP)
1197  uint32_t _CPU_SMP_Initialize( void );
1198
1199  bool _CPU_SMP_Start_processor( uint32_t cpu_index );
1200
1201  void _CPU_SMP_Finalize_initialization( uint32_t cpu_count );
1202
1203  void _CPU_SMP_Prepare_start_multitasking( void );
1204
1205  #if defined(__leon__) && !defined(RTEMS_PARAVIRT)
1206    static inline uint32_t _CPU_SMP_Get_current_processor( void )
1207    {
1208      return _LEON3_Get_current_processor();
1209    }
1210  #else
1211    uint32_t _CPU_SMP_Get_current_processor( void );
1212  #endif
1213
1214  void _CPU_SMP_Send_interrupt( uint32_t target_processor_index );
1215
1216  static inline void _CPU_SMP_Processor_event_broadcast( void )
1217  {
1218    __asm__ volatile ( "" : : : "memory" );
1219  }
1220
1221  static inline void _CPU_SMP_Processor_event_receive( void )
1222  {
1223    __asm__ volatile ( "" : : : "memory" );
1224  }
1225#endif
1226
1227/**
1228 * @brief SPARC specific save FPU method.
1229 *
1230 * This routine saves the floating point context passed to it.
1231 *
1232 * @param[in] fp_context_ptr is the area to save into
1233 */
1234void _CPU_Context_save_fp(
1235  Context_Control_fp **fp_context_ptr
1236);
1237
1238/**
1239 * @brief SPARC specific restore FPU method.
1240 *
1241 * This routine restores the floating point context passed to it.
1242 *
1243 * @param[in] fp_context_ptr is the area to restore from
1244 */
1245void _CPU_Context_restore_fp(
1246  Context_Control_fp **fp_context_ptr
1247);
1248
1249void _CPU_Context_volatile_clobber( uintptr_t pattern );
1250
1251void _CPU_Context_validate( uintptr_t pattern );
1252
1253typedef struct {
1254  uint32_t trap;
1255  CPU_Interrupt_frame *isf;
1256} CPU_Exception_frame;
1257
1258void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
1259
1260/**
1261 * @brief SPARC specific method to endian swap an uint32_t.
1262 *
1263 * The following routine swaps the endian format of an unsigned int.
1264 * It must be static because it is referenced indirectly.
1265 *
1266 * @param[in] value is the value to endian swap
1267 *
1268 * This version will work on any processor, but if you come across a better
1269 * way for the SPARC PLEASE use it.  The most common way to swap a 32-bit
1270 * entity as shown below is not any more efficient on the SPARC.
1271 *
1272 *    - swap least significant two bytes with 16-bit rotate
1273 *    - swap upper and lower 16-bits
1274 *    - swap most significant two bytes with 16-bit rotate
1275 *
1276 * It is not obvious how the SPARC can do significantly better than the
1277 * generic code.  gcc 2.7.0 only generates about 12 instructions for the
1278 * following code at optimization level four (i.e. -O4).
1279 */
1280static inline uint32_t CPU_swap_u32(
1281  uint32_t value
1282)
1283{
1284  uint32_t   byte1, byte2, byte3, byte4, swapped;
1285
1286  byte4 = (value >> 24) & 0xff;
1287  byte3 = (value >> 16) & 0xff;
1288  byte2 = (value >> 8)  & 0xff;
1289  byte1 =  value        & 0xff;
1290
1291  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
1292  return( swapped );
1293}
1294
1295/**
1296 * @brief SPARC specific method to endian swap an uint16_t.
1297 *
1298 * The following routine swaps the endian format of a uint16_t.
1299 *
1300 * @param[in] value is the value to endian swap
1301 */
1302#define CPU_swap_u16( value ) \
1303  (((value&0xff) << 8) | ((value >> 8)&0xff))
1304
1305typedef uint32_t CPU_Counter_ticks;
1306
1307typedef CPU_Counter_ticks ( *SPARC_Counter_read )( void );
1308
1309typedef CPU_Counter_ticks ( *SPARC_Counter_difference )(
1310  CPU_Counter_ticks second,
1311  CPU_Counter_ticks first
1312);
1313
1314/*
1315 * The SPARC processors supported by RTEMS have no built-in CPU counter
1316 * support.  We have to use some hardware counter module for this purpose, for
1317 * example the GPTIMER instance used by the clock driver.  The BSP must provide
1318 * an implementation of the CPU counter read and difference functions.  This
1319 * allows the use of dynamic hardware enumeration.
1320 */
1321typedef struct {
1322  SPARC_Counter_read                counter_read;
1323  SPARC_Counter_difference          counter_difference;
1324  volatile const CPU_Counter_ticks *counter_address;
1325} SPARC_Counter;
1326
1327extern const SPARC_Counter _SPARC_Counter;
1328
1329static inline CPU_Counter_ticks _CPU_Counter_read( void )
1330{
1331  return ( *_SPARC_Counter.counter_read )();
1332}
1333
1334static inline CPU_Counter_ticks _CPU_Counter_difference(
1335  CPU_Counter_ticks second,
1336  CPU_Counter_ticks first
1337)
1338{
1339  return ( *_SPARC_Counter.counter_difference )( second, first );
1340}
1341
1342#endif /* ASM */
1343
1344#ifdef __cplusplus
1345}
1346#endif
1347
1348#endif
Note: See TracBrowser for help on using the repository browser.