source: rtems/cpukit/score/cpu/sparc64/context.S @ 9165349d

Last change on this file since 9165349d was d18560a, checked in by Sebastian Huber <sebastian.huber@…>, on 11/11/16 at 10:16:33

sparc64: Rename CPU_Minimum_stack_frame

Rename SPARC64-specific CPU_Minimum_stack_frame to
SPARC64_Minimum_stack_frame. Rename SPARC64-specific
CPU_MINIMUM_STACK_FRAME_SIZE to SPARC64_MINIMUM_STACK_FRAME_SIZE.

Update #2809.

  • Property mode set to 100644
File size: 9.0 KB
Line 
1/*  context.S
2 *
3 *  This file contains the basic algorithms for all assembly code used
4 *  in an specific CPU port of RTEMS.  These algorithms must be implemented
5 *  in assembly language.
6 *
7 *  COPYRIGHT (c) 2010. Gedare Bloom.
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.org/license/LICENSE.
12 */
13
14#include <rtems/asm.h>
15
16
17/*
18 *  The assembler needs to be told that we know what to do with
19 *  the global registers.
20 */
21.register %g2, #scratch
22.register %g3, #scratch
23.register %g6, #scratch
24.register %g7, #scratch
25
26#if (SPARC_HAS_FPU == 1)
27
28/*
29 *  void _CPU_Context_save_fp(
30 *    void **fp_context_ptr
31 *  )
32 *
33 *  This routine is responsible for saving the FP context
34 *  at *fp_context_ptr.  If the point to load the FP context
35 *  from is changed then the pointer is modified by this routine.
36 *
37 */
38
39  .align 4
40PUBLIC(_CPU_Context_save_fp)
41  SYM(_CPU_Context_save_fp):
42    save    %sp, -SPARC64_MINIMUM_STACK_FRAME_SIZE, %sp
43
44    /*
45     *  The following enables the floating point unit.
46     */
47
48    sparc64_enable_FPU(%l0)
49
50  /*
51   *  Although sun4v supports alternate register names for double-
52   *  and quad-word floating point, SPARC v9 only uses f[#]
53   *
54   *  Because quad-word fp is not supported by the hardware in
55   *  many situations, we stick with double-word fp operations
56   */
57  ldx    [%i0], %l0     
58  std     %f0, [%l0]
59  std     %f2, [%l0 + F2_OFFSET]
60  std     %f4, [%l0 + F4_OFFSET]
61  std     %f6, [%l0 + F6_OFFSET]
62  std     %f8, [%l0 + F8_OFFSET]
63  std     %f10, [%l0 + F1O_OFFSET]
64  std     %f12, [%l0 + F12_OFFSET]
65  std     %f14, [%l0 + F14_OFFSET]
66  std     %f16, [%l0 + F16_OFFSET]
67  std     %f18, [%l0 + F18_OFFSET]
68  std     %f20, [%l0 + F2O_OFFSET]
69  std     %f22, [%l0 + F22_OFFSET]
70  std     %f24, [%l0 + F24_OFFSET]
71  std     %f26, [%l0 + F26_OFFSET]
72  std     %f28, [%l0 + F28_OFFSET]
73  std     %f30, [%l0 + F3O_OFFSET]
74  std     %f32, [%l0 + F32_OFFSET]
75  std     %f34, [%l0 + F34_OFFSET]
76  std     %f36, [%l0 + F36_OFFSET]
77  std     %f38, [%l0 + F38_OFFSET]
78  std     %f40, [%l0 + F4O_OFFSET]
79  std     %f42, [%l0 + F42_OFFSET]
80  std     %f44, [%l0 + F44_OFFSET]
81  std     %f46, [%l0 + F46_OFFSET]
82  std     %f48, [%l0 + F48_OFFSET]
83  std     %f50, [%l0 + F5O_OFFSET]
84  std     %f52, [%l0 + F52_OFFSET]
85  std     %f54, [%l0 + F54_OFFSET]
86  std     %f56, [%l0 + F56_OFFSET]
87  std     %f58, [%l0 + F58_OFFSET]
88  std     %f60, [%l0 + F6O_OFFSET]       
89  std     %f62, [%l0 + F62_OFFSET]
90  stx     %fsr, [%l0 + FSR_OFFSET]
91  ret
92  restore
93
94  /*
95   *  void _CPU_Context_restore_fp(
96   *    void **fp_context_ptr
97   *  )
98   *
99   *  This routine is responsible for restoring the FP context
100   *  at *fp_context_ptr.  If the point to load the FP context
101   *  from is changed then the pointer is modified by this routine.
102   *
103   */
104
105  .align 4
106PUBLIC(_CPU_Context_restore_fp)
107  SYM(_CPU_Context_restore_fp):
108    save    %sp, -SPARC64_MINIMUM_STACK_FRAME_SIZE , %sp
109
110    /*
111     *  The following enables the floating point unit.
112     */
113
114    sparc64_enable_FPU(%l0)
115
116  ldx     [%i0], %l0
117  ldd     [%l0 + FO_OFFSET], %f0
118  ldd     [%l0 + F2_OFFSET], %f2
119  ldd     [%l0 + F4_OFFSET], %f4
120  ldd     [%l0 + F6_OFFSET], %f6
121  ldd     [%l0 + F8_OFFSET], %f8
122  ldd     [%l0 + F1O_OFFSET], %f10
123  ldd     [%l0 + F12_OFFSET], %f12
124  ldd     [%l0 + F14_OFFSET], %f14
125  ldd     [%l0 + F16_OFFSET], %f16
126  ldd     [%l0 + F18_OFFSET], %f18
127  ldd     [%l0 + F2O_OFFSET], %f20
128  ldd     [%l0 + F22_OFFSET], %f22
129  ldd     [%l0 + F24_OFFSET], %f24
130  ldd     [%l0 + F26_OFFSET], %f26
131  ldd     [%l0 + F28_OFFSET], %f28
132  ldd     [%l0 + F3O_OFFSET], %f30
133  ldd     [%l0 + F32_OFFSET], %f32
134  ldd     [%l0 + F34_OFFSET], %f34
135  ldd     [%l0 + F36_OFFSET], %f36
136  ldd     [%l0 + F38_OFFSET], %f38
137  ldd     [%l0 + F4O_OFFSET], %f40
138  ldd     [%l0 + F42_OFFSET], %f42
139  ldd     [%l0 + F44_OFFSET], %f44
140  ldd     [%l0 + F46_OFFSET], %f46
141  ldd     [%l0 + F48_OFFSET], %f48
142  ldd     [%l0 + F5O_OFFSET], %f50
143  ldd     [%l0 + F52_OFFSET], %f52
144  ldd     [%l0 + F54_OFFSET], %f54
145  ldd     [%l0 + F56_OFFSET], %f56
146  ldd     [%l0 + F58_OFFSET], %f58
147  ldd     [%l0 + F6O_OFFSET], %f60
148  ldd     [%l0 + F62_OFFSET], %f62
149  ldx     [%l0 + FSR_OFFSET], %fsr
150  ret
151  restore
152
153#endif /* SPARC_HAS_FPU */
154
155  /*
156   *  void _CPU_Context_switch(
157   *    Context_Control  *run,
158   *    Context_Control  *heir
159   *  )
160   *
161   *  This routine performs a normal non-FP context switch.
162   */
163
164  .align 4
165PUBLIC(_CPU_Context_switch)
166  SYM(_CPU_Context_switch):
167    ! skip g0
168      stx     %g1, [%o0 + G1_OFFSET]       ! save the global registers
169      stx     %g2, [%o0 + G2_OFFSET]
170      stx     %g3, [%o0 + G3_OFFSET]       
171      stx     %g4, [%o0 + G4_OFFSET]
172      stx     %g5, [%o0 + G5_OFFSET]       
173      stx     %g6, [%o0 + G6_OFFSET]
174      stx     %g7, [%o0 + G7_OFFSET]
175
176      ! load the address of the ISR stack nesting prevention flag
177      setx  SYM(_CPU_ISR_Dispatch_disable), %g1, %g2
178      lduw  [%g2], %g2
179
180      ! save it a bit later so we do not waste a couple of cycles
181
182      stx     %l0, [%o0 + L0_OFFSET]       ! save the local registers
183      stx     %l1, [%o0 + L1_OFFSET]
184      stx     %l2, [%o0 + L2_OFFSET]
185      stx     %l3, [%o0 + L3_OFFSET]
186      stx     %l4, [%o0 + L4_OFFSET]
187      stx     %l5, [%o0 + L5_OFFSET]
188      stx     %l6, [%o0 + L6_OFFSET]
189      stx     %l7, [%o0 + L7_OFFSET]
190
191      ! Now actually save ISR stack nesting prevention flag
192      stuw     %g2, [%o0 + ISR_DISPATCH_DISABLE_STACK_OFFSET]
193
194      stx     %i0, [%o0 + I0_OFFSET]       ! save the input registers
195      stx     %i1, [%o0 + I1_OFFSET]
196      stx     %i2, [%o0 + I2_OFFSET]
197      stx     %i3, [%o0 + I3_OFFSET]
198      stx     %i4, [%o0 + I4_OFFSET]
199      stx     %i5, [%o0 + I5_OFFSET]
200      stx     %i6, [%o0 + I6_FP_OFFSET]
201      stx     %i7, [%o0 + I7_OFFSET]
202
203      stx     %o0, [%o0 + O0_OFFSET]       ! save the output registers
204      stx     %o1, [%o0 + O1_OFFSET]
205      stx     %o2, [%o0 + O2_OFFSET]
206      stx     %o3, [%o0 + O3_OFFSET]
207      stx     %o4, [%o0 + O4_OFFSET]
208      stx     %o5, [%o0 + O5_OFFSET]
209      stx     %o6, [%o0 + O6_SP_OFFSET]
210      stx     %o7, [%o0 + O7_OFFSET]       ! o7 is the PC
211
212!      rdpr    %pil, %o2
213!      stuw    %o2, [%o0 + PIL_OFFSET] ! save pil
214
215!      rdpr    %pstate, %o2
216!      stx     %o2, [%o0 + PSTATE_OFFSET]      ! save status register
217
218      /*
219       *  This is entered from _CPU_Context_restore with:
220       *    o1 = context to restore
221!       *    o2 = pstate
222       *
223       *  NOTE: Flushing the register windows is necessary, but it adds
224       *  an unpredictable (but bounded) overhead to context switching.
225       */
226
227PUBLIC(_CPU_Context_restore_heir)
228  SYM(_CPU_Context_restore_heir):
229
230    flushw
231
232
233
234    ! skip g0
235    ldx     [%o1 + G1_OFFSET], %g1        ! restore the global registers
236    ldx     [%o1 + G2_OFFSET], %g2
237    ldx     [%o1 + G3_OFFSET], %g3
238    ldx     [%o1 + G4_OFFSET], %g4
239    ldx     [%o1 + G5_OFFSET], %g5
240    ldx     [%o1 + G6_OFFSET], %g6
241    ldx     [%o1 + G7_OFFSET], %g7
242
243    ! Load thread specific ISR dispatch prevention flag
244    ldx    [%o1 + ISR_DISPATCH_DISABLE_STACK_OFFSET], %o2
245    setx  SYM(_CPU_ISR_Dispatch_disable), %o5, %o3
246    ! Store it to memory later to use the cycles
247
248    ldx     [%o1 + L0_OFFSET], %l0        ! restore the local registers
249    ldx     [%o1 + L1_OFFSET], %l1
250    ldx     [%o1 + L2_OFFSET], %l2
251    ldx     [%o1 + L3_OFFSET], %l3
252    ldx     [%o1 + L4_OFFSET], %l4
253    ldx     [%o1 + L5_OFFSET], %l5
254    ldx     [%o1 + L6_OFFSET], %l6
255    ldx     [%o1 + L7_OFFSET], %l7
256
257    ! Now restore thread specific ISR dispatch prevention flag
258    stuw  %o2, [%o3]
259
260    ldx     [%o1 + I0_OFFSET], %i0        ! restore the input registers
261    ldx     [%o1 + I1_OFFSET], %i1
262    ldx     [%o1 + I2_OFFSET], %i2
263    ldx     [%o1 + I3_OFFSET], %i3
264    ldx     [%o1 + I4_OFFSET], %i4
265    ldx     [%o1 + I5_OFFSET], %i5
266    ldx     [%o1 + I6_FP_OFFSET], %i6
267    ldx     [%o1 + I7_OFFSET], %i7
268
269    ldx     [%o1 + O0_OFFSET], %o0
270    ldx     [%o1 + O2_OFFSET], %o2        ! restore the output registers
271    ldx     [%o1 + O3_OFFSET], %o3
272    ldx     [%o1 + O4_OFFSET], %o4
273    ldx     [%o1 + O5_OFFSET], %o5
274    ldx     [%o1 + O6_SP_OFFSET], %o6
275    ldx     [%o1 + O7_OFFSET], %o7       ! PC
276
277    ! on a hunch... we should be able to use some of the %o regs
278!    lduw    [%o1 + PIL_OFFSET], %o2
279!    wrpr    %g0, %o2, %pil
280
281!    ldx     [%o1 + PSTATE_OFFSET], %o2
282
283    ! do o1 last to avoid destroying heir context pointer
284    ldx     [%o1 + O1_OFFSET], %o1        ! overwrite heir pointer
285!    wrpr    %g0, %o2, %pstate
286
287    retl
288    nop
289
290    /*
291     *  void _CPU_Context_restore(
292     *    Context_Control *new_context
293     *  )
294     *
295     *  This routine is generally used only to perform restart self.
296     *
297     *  NOTE: It is unnecessary to reload some registers.
298     */
299    /* if _CPU_Context_restore_heir does not flushw, then do it here */
300  .align 4
301PUBLIC(_CPU_Context_restore)
302  SYM(_CPU_Context_restore):
303    save    %sp, -SPARC64_MINIMUM_STACK_FRAME_SIZE, %sp
304!    rdpr    %pstate, %o2
305    ba      SYM(_CPU_Context_restore_heir)
306    mov     %i0, %o1                      ! in the delay slot
307
308/* end of file */
Note: See TracBrowser for help on using the repository browser.