source: rtems/cpukit/score/cpu/sparc/cpu_asm.S @ bdcc814

Last change on this file since bdcc814 was bdcc814, checked in by Sebastian Huber <sebastian.huber@…>, on 11/23/21 at 15:32:23

sparc: Add workaround for GRLIB-TN-0011

Affected components are the GR712RC, UT699, UT699E, UT700, and
LEON3FT-RTAX. Strictly, the workaround is only necessary if the MMU is
enabled. Use FIX_LEON3FT_B2BST to enable the workaround. This is not
100% appropriate, but the best thing we can use to enable the
workaround.

Close #4551.

  • Property mode set to 100644
File size: 31.0 KB
RevLine 
[5d69cd3]1/*  cpu_asm.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) 1989-2011.
8 *  On-Line Applications Research Corporation (OAR).
9 *
[146adb1]10 *  Copyright (c) 2014, 2017 embedded brains GmbH
[fbda4a8]11 *
[5d69cd3]12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
[c499856]14 *  http://www.rtems.org/license/LICENSE.
[5d69cd3]15 *
16 *  Ported to ERC32 implementation of the SPARC by On-Line Applications
17 *  Research Corporation (OAR) under contract to the European Space
18 *  Agency (ESA).
19 *
20 *  ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995.
21 *  European Space Agency.
22 */
23
24#include <rtems/asm.h>
[f8ad6c6f]25#include <rtems/score/percpu.h>
[b2da982]26#include <libcpu/grlib-tn-0018.h>
[8b077ca0]27
[88f6c4fc]28/*
29 *  void _CPU_Context_switch(
30 *    Context_Control  *run,
31 *    Context_Control  *heir
32 *  )
33 *
34 *  This routine performs a normal non-FP context switch.
35 */
36
37        .align 4
38        PUBLIC(_CPU_Context_switch)
[d45f87cf]39        PUBLIC(_CPU_Context_switch_no_return)
[88f6c4fc]40SYM(_CPU_Context_switch):
[d45f87cf]41SYM(_CPU_Context_switch_no_return):
[b2ec2d15]42        st      %g5, [%o0 + G5_OFFSET]       ! save the global registers
[32b4a0c]43
44        /*
45         * No need to save the thread pointer %g7 since it is a thread
46         * invariant.  It is initialized once in _CPU_Context_Initialize().
47         */
[88f6c4fc]48
49        std     %l0, [%o0 + L0_OFFSET]       ! save the local registers
[2f8704b6]50        SPARC_LEON3FT_B2BST_NOP
[88f6c4fc]51        std     %l2, [%o0 + L2_OFFSET]
[2f8704b6]52        SPARC_LEON3FT_B2BST_NOP
[88f6c4fc]53        std     %l4, [%o0 + L4_OFFSET]
[2f8704b6]54        SPARC_LEON3FT_B2BST_NOP
[88f6c4fc]55        std     %l6, [%o0 + L6_OFFSET]
[2f8704b6]56        SPARC_LEON3FT_B2BST_NOP
[88f6c4fc]57
58        std     %i0, [%o0 + I0_OFFSET]       ! save the input registers
[2f8704b6]59        SPARC_LEON3FT_B2BST_NOP
[88f6c4fc]60        std     %i2, [%o0 + I2_OFFSET]
[2f8704b6]61        SPARC_LEON3FT_B2BST_NOP
[88f6c4fc]62        std     %i4, [%o0 + I4_OFFSET]
[2f8704b6]63        SPARC_LEON3FT_B2BST_NOP
[88f6c4fc]64        std     %i6, [%o0 + I6_FP_OFFSET]
[2f8704b6]65        SPARC_LEON3FT_B2BST_NOP
[88f6c4fc]66
[97cf623d]67        std     %o6, [%o0 + O6_SP_OFFSET]    ! save the output registers
[88f6c4fc]68
[f8ad6c6f]69        ! load the ISR stack nesting prevention flag
[c11ac2d5]70        ld      [%g6 + PER_CPU_ISR_DISPATCH_DISABLE], %o4
[f8ad6c6f]71        ! save it a bit later so we do not waste a couple of cycles
72
[88f6c4fc]73        rd      %psr, %o2
74        st      %o2, [%o0 + PSR_OFFSET]      ! save status register
75
[f8ad6c6f]76        ! Now actually save ISR stack nesting prevention flag
77        st       %o4, [%o0 + ISR_DISPATCH_DISABLE_STACK_OFFSET]
78
[88f6c4fc]79        /*
80         *  This is entered from _CPU_Context_restore with:
81         *    o1 = context to restore
82         *    o2 = psr
83         */
84
85        PUBLIC(_CPU_Context_restore_heir)
86SYM(_CPU_Context_restore_heir):
87        /*
88         *  Flush all windows with valid contents except the current one.
89         *  In examining the set register windows, one may logically divide
90         *  the windows into sets (some of which may be empty) based on their
91         *  current status:
92         *
93         *    + current (i.e. in use),
94         *    + used (i.e. a restore would not trap)
95         *    + invalid (i.e. 1 in corresponding bit in WIM)
96         *    + unused
97         *
98         *  Either the used or unused set of windows may be empty.
99         *
100         *  NOTE: We assume only one bit is set in the WIM at a time.
101         *
102         *  Given a CWP of 5 and a WIM of 0x1, the registers are divided
103         *  into sets as follows:
104         *
105         *    + 0   - invalid
106         *    + 1-4 - unused
107         *    + 5   - current
108         *    + 6-7 - used
109         *
110         *  In this case, we only would save the used windows -- 6 and 7.
111         *
112         *   Traps are disabled for the same logical period as in a
113         *     flush all windows trap handler.
114         *
115         *    Register Usage while saving the windows:
116         *      g1 = current PSR
117         *      g2 = current wim
118         *      g3 = CWP
119         *      g4 = wim scratch
120         *      g5 = scratch
121         */
122
123        and     %o2, SPARC_PSR_CWP_MASK, %g3  ! g3 = CWP
[78cac9b]124        andn    %o2, SPARC_PSR_ET_MASK, %g1   ! g1 = psr with traps disabled
125        mov     %g1, %psr                     ! **** DISABLE TRAPS ****
[88f6c4fc]126        mov     %wim, %g2                     ! g2 = wim
127        mov     1, %g4
128        sll     %g4, %g3, %g4                 ! g4 = WIM mask for CW invalid
129
130save_frame_loop:
131        sll     %g4, 1, %g5                   ! rotate the "wim" left 1
132        srl     %g4, SPARC_NUMBER_OF_REGISTER_WINDOWS - 1, %g4
133        or      %g4, %g5, %g4                 ! g4 = wim if we do one restore
134
135        /*
136         *  If a restore would not underflow, then continue.
137         */
138
139        andcc   %g4, %g2, %g0                 ! Any windows to flush?
140        bnz     done_flushing                 ! No, then continue
141        nop
142
143        restore                               ! back one window
144
145        /*
146         *  Now save the window just as if we overflowed to it.
147         */
148
149        std     %l0, [%sp + CPU_STACK_FRAME_L0_OFFSET]
[2f8704b6]150        SPARC_LEON3FT_B2BST_NOP
[88f6c4fc]151        std     %l2, [%sp + CPU_STACK_FRAME_L2_OFFSET]
[2f8704b6]152        SPARC_LEON3FT_B2BST_NOP
[88f6c4fc]153        std     %l4, [%sp + CPU_STACK_FRAME_L4_OFFSET]
[2f8704b6]154        SPARC_LEON3FT_B2BST_NOP
[88f6c4fc]155        std     %l6, [%sp + CPU_STACK_FRAME_L6_OFFSET]
[2f8704b6]156        SPARC_LEON3FT_B2BST_NOP
[88f6c4fc]157
158        std     %i0, [%sp + CPU_STACK_FRAME_I0_OFFSET]
[2f8704b6]159        SPARC_LEON3FT_B2BST_NOP
[88f6c4fc]160        std     %i2, [%sp + CPU_STACK_FRAME_I2_OFFSET]
[2f8704b6]161        SPARC_LEON3FT_B2BST_NOP
[88f6c4fc]162        std     %i4, [%sp + CPU_STACK_FRAME_I4_OFFSET]
[2f8704b6]163        SPARC_LEON3FT_B2BST_NOP
[88f6c4fc]164        std     %i6, [%sp + CPU_STACK_FRAME_I6_FP_OFFSET]
[2f8704b6]165        SPARC_LEON3FT_B2BST_NOP
[88f6c4fc]166
167        ba      save_frame_loop
168        nop
169
170done_flushing:
171
[78cac9b]172        ! Wait three instructions after the write to PSR before using
173        ! non-global registers or instructions affecting the CWP
174        mov     %g1, %psr                     ! restore cwp
175        add     %g3, 1, %g2                   ! calculate desired WIM
176        and     %g2, SPARC_NUMBER_OF_REGISTER_WINDOWS - 1, %g2
[88f6c4fc]177        mov     1, %g4
[78cac9b]178        sll     %g4, %g2, %g4                 ! g4 = new WIM
[88f6c4fc]179        mov     %g4, %wim
180
[38b59a6]181#if defined(RTEMS_SMP)
[d5e073c]182        /*
183         * The executing thread no longer executes on this processor.  Switch
184         * the stack to the temporary interrupt stack of this processor.  Mark
185         * the context of the executing thread as not executing.
186         */
187        add     %g6, PER_CPU_INTERRUPT_FRAME_AREA + CPU_INTERRUPT_FRAME_SIZE, %sp
[fbda4a8]188        st      %g0, [%o0 + SPARC_CONTEXT_CONTROL_IS_EXECUTING_OFFSET]
189
190        ! Try to update the is executing indicator of the heir context
191        mov     1, %g1
192
[bdcc814]193#if defined(__FIX_LEON3FT_B2BST)
194        /*
195         * This is a workaround for GRLIB-TN-0011 (Technical Note on LEON3/FT
196         * AHB Lock Release During Atomic Operation).  Affected components are
197         * the GR712RC, UT699, UT699E, UT700, and LEON3FT-RTAX.  Strictly, the
198         * workaround is only necessary if the MMU is enabled.  Using the
199         * __FIX_LEON3FT_B2BST is not 100% appropriate, but the best thing we
200         * can use to enable the workaround.  An alignment padding is filled
201         * with nops.
202         */
203.align 16
204#endif
[d5e073c]205.Ltry_update_is_executing:
[38b59a6]206
[fbda4a8]207        swap    [%o1 + SPARC_CONTEXT_CONTROL_IS_EXECUTING_OFFSET], %g1
[38b59a6]208        cmp     %g1, 0
[d5e073c]209        bne     .Lcheck_is_executing
[38b59a6]210
[fbda4a8]211        ! The next load is in a delay slot, which is all right
[38b59a6]212#endif
213
[146adb1]214#if defined(SPARC_USE_LAZY_FP_SWITCH)
215        ld      [%g6 + SPARC_PER_CPU_FP_OWNER_OFFSET], %g2
216#endif
[78cac9b]217        ld      [%o1 + PSR_OFFSET], %g1       ! g1 = heir psr with traps enabled
[146adb1]218#if defined(SPARC_USE_LAZY_FP_SWITCH)
219        sethi   %hi(SPARC_PSR_EF_MASK), %g5
220        cmp     %g2, %g0
221        bne,a   .Lclear_psr_ef_done
222         andn   %g1, %g5, %g1                 ! g1 = heir psr w/o PSR[EF]
223.Lclear_psr_ef_done:
224#endif
[78cac9b]225        andn    %g1, SPARC_PSR_CWP_MASK, %g1  ! g1 = heir psr w/o cwp
226        or      %g1, %g3, %g1                 ! g1 = heir psr with cwp
227        mov     %g1, %psr                     ! restore status register and
228                                              ! **** ENABLE TRAPS ****
229
[b2ec2d15]230        ld      [%o1 + G5_OFFSET], %g5        ! restore the global registers
[7c0bd74]231        ld      [%o1 + G7_OFFSET], %g7
[88f6c4fc]232
233        ! Load thread specific ISR dispatch prevention flag
234        ld      [%o1 + ISR_DISPATCH_DISABLE_STACK_OFFSET], %o2
235        ! Store it to memory later to use the cycles
236
237        ldd     [%o1 + L0_OFFSET], %l0        ! restore the local registers
238        ldd     [%o1 + L2_OFFSET], %l2
239        ldd     [%o1 + L4_OFFSET], %l4
240        ldd     [%o1 + L6_OFFSET], %l6
241
242        ! Now restore thread specific ISR dispatch prevention flag
[c11ac2d5]243        st      %o2, [%g6 + PER_CPU_ISR_DISPATCH_DISABLE]
[88f6c4fc]244
[20828099]245        ldd     [%o1 + I0_OFFSET], %i0        ! restore the input registers
[88f6c4fc]246        ldd     [%o1 + I2_OFFSET], %i2
247        ldd     [%o1 + I4_OFFSET], %i4
248        ldd     [%o1 + I6_FP_OFFSET], %i6
249
[97cf623d]250        ldd     [%o1 + O6_SP_OFFSET], %o6     ! restore the output registers
[88f6c4fc]251
252        jmp     %o7 + 8                       ! return
253        nop                                   ! delay slot
254
[fbda4a8]255#if defined(RTEMS_SMP)
[d5e073c]256.Lcheck_is_executing:
[fbda4a8]257
258        ! Check the is executing indicator of the heir context
259        ld      [%o1 + SPARC_CONTEXT_CONTROL_IS_EXECUTING_OFFSET], %g1
260        cmp     %g1, 0
[d5e073c]261        beq     .Ltry_update_is_executing
[fbda4a8]262         mov    1, %g1
263
[258ad71]264        ! We may have a new heir
[fbda4a8]265
266        ! Read the executing and heir
[d64f2e7]267        ld      [%g6 + PER_CPU_OFFSET_EXECUTING], %g2
268        ld      [%g6 + PER_CPU_OFFSET_HEIR], %g4
[fbda4a8]269
[258ad71]270        ! Update the executing only if necessary to avoid cache line
271        ! monopolization.
[d64f2e7]272        cmp     %g2, %g4
[d5e073c]273        beq     .Ltry_update_is_executing
[258ad71]274         mov    1, %g1
275
[fbda4a8]276        ! Calculate the heir context pointer
[d64f2e7]277        sub     %o1, %g2, %g2
278        add     %g2, %g4, %o1
[fbda4a8]279
280        ! Update the executing
[d64f2e7]281        st      %g4, [%g6 + PER_CPU_OFFSET_EXECUTING]
[fbda4a8]282
[d5e073c]283        ba      .Ltry_update_is_executing
[fbda4a8]284         mov    1, %g1
285#endif
286
[88f6c4fc]287/*
288 *  void _CPU_Context_restore(
289 *    Context_Control *new_context
290 *  )
291 *
292 *  This routine is generally used only to perform restart self.
293 *
294 *  NOTE: It is unnecessary to reload some registers.
295 */
296        .align 4
297        PUBLIC(_CPU_Context_restore)
298SYM(_CPU_Context_restore):
[427dcee]299        save    %sp, -SPARC_MINIMUM_STACK_FRAME_SIZE, %sp
[88f6c4fc]300        rd      %psr, %o2
[38b59a6]301#if defined(RTEMS_SMP)
[26ffb8c2]302        ! On SPARC the restore path needs also a valid executing context on SMP
303        ! to update the is executing indicator.
[38b59a6]304        mov     %i0, %o0
305#endif
[88f6c4fc]306        ba      SYM(_CPU_Context_restore_heir)
307        mov     %i0, %o1                      ! in the delay slot
308
[5d69cd3]309/*
[be96cb43]310 *  void _SPARC_Interrupt_trap()
[5d69cd3]311 *
312 *  This routine provides the RTEMS interrupt management.
313 *
314 *  We enter this handler from the 4 instructions in the trap table with
315 *  the following registers assumed to be set as shown:
316 *
317 *    l0 = PSR
318 *    l1 = PC
319 *    l2 = nPC
[be96cb43]320 *    l3 = interrupt vector number (this is not the trap type)
[5d69cd3]321 *
[be96cb43]322 *  NOTE: This trap handler is intended to service external interrupts.
[5d69cd3]323 */
324
325        .align 4
[be96cb43]326        PUBLIC(_SPARC_Interrupt_trap)
327SYM(_SPARC_Interrupt_trap):
[5d69cd3]328        /*
329         *  Save the globals this block uses.
330         *
331         *  These registers are not restored from the locals.  Their contents
332         *  are saved directly from the locals into the ISF below.
333         */
334
335        mov     %g4, %l4                 ! save the globals this block uses
336        mov     %g5, %l5
337
338        /*
339         *  When at a "window overflow" trap, (wim == (1 << cwp)).
340         *  If we get here like that, then process a window overflow.
341         */
342
343        rd      %wim, %g4
344        srl     %g4, %l0, %g5            ! g5 = win >> cwp ; shift count and CWP
345                                         !   are LS 5 bits ; how convenient :)
346        cmp     %g5, 1                   ! Is this an invalid window?
347        bne     dont_do_the_window       ! No, then skip all this stuff
348        ! we are using the delay slot
349
350        /*
351         *  The following is same as a 1 position right rotate of WIM
352         */
353
354        srl     %g4, 1, %g5              ! g5 = WIM >> 1
355        sll     %g4, SPARC_NUMBER_OF_REGISTER_WINDOWS-1 , %g4
356                                         ! g4 = WIM << (Number Windows - 1)
357        or      %g4, %g5, %g4            ! g4 = (WIM >> 1) |
358                                         !      (WIM << (Number Windows - 1))
359
360        /*
361         *  At this point:
362         *
363         *    g4 = the new WIM
364         *    g5 is free
365         */
366
367        /*
368         *  Since we are tinkering with the register windows, we need to
369         *  make sure that all the required information is in global registers.
370         */
371
372        save                          ! Save into the window
373        wr      %g4, 0, %wim          ! WIM = new WIM
374        nop                           ! delay slots
375        nop
376        nop
377
378        /*
379         *  Now save the window just as if we overflowed to it.
380         */
381
382        std     %l0, [%sp + CPU_STACK_FRAME_L0_OFFSET]
[2f8704b6]383        SPARC_LEON3FT_B2BST_NOP
[5d69cd3]384        std     %l2, [%sp + CPU_STACK_FRAME_L2_OFFSET]
[2f8704b6]385        SPARC_LEON3FT_B2BST_NOP
[5d69cd3]386        std     %l4, [%sp + CPU_STACK_FRAME_L4_OFFSET]
[2f8704b6]387        SPARC_LEON3FT_B2BST_NOP
[5d69cd3]388        std     %l6, [%sp + CPU_STACK_FRAME_L6_OFFSET]
[2f8704b6]389        SPARC_LEON3FT_B2BST_NOP
[5d69cd3]390
391        std     %i0, [%sp + CPU_STACK_FRAME_I0_OFFSET]
[2f8704b6]392        SPARC_LEON3FT_B2BST_NOP
[5d69cd3]393        std     %i2, [%sp + CPU_STACK_FRAME_I2_OFFSET]
[2f8704b6]394        SPARC_LEON3FT_B2BST_NOP
[5d69cd3]395        std     %i4, [%sp + CPU_STACK_FRAME_I4_OFFSET]
[2f8704b6]396        SPARC_LEON3FT_B2BST_NOP
[5d69cd3]397        std     %i6, [%sp + CPU_STACK_FRAME_I6_FP_OFFSET]
398
399        restore
400        nop
401
402dont_do_the_window:
403        /*
404         *  Global registers %g4 and %g5 are saved directly from %l4 and
405         *  %l5 directly into the ISF below.
406         */
407
408        /*
409         *  Save the state of the interrupted task -- especially the global
410         *  registers -- in the Interrupt Stack Frame.  Note that the ISF
411         *  includes a regular minimum stack frame which will be used if
412         *  needed by register window overflow and underflow handlers.
413         *
[be96cb43]414         *  REGISTERS SAME AS AT _SPARC_Interrupt_trap()
[5d69cd3]415         */
416
[c539a865]417        sub     %fp, CPU_INTERRUPT_FRAME_SIZE, %sp
[5d69cd3]418                                               ! make space for ISF
419
420        std     %l0, [%sp + ISF_PSR_OFFSET]    ! save psr, PC
[2f8704b6]421        SPARC_LEON3FT_B2BST_NOP
[5d69cd3]422        st      %l2, [%sp + ISF_NPC_OFFSET]    ! save nPC
423        st      %g1, [%sp + ISF_G1_OFFSET]     ! save g1
424        std     %g2, [%sp + ISF_G2_OFFSET]     ! save g2, g3
[2f8704b6]425        SPARC_LEON3FT_B2BST_NOP
[5d69cd3]426        std     %l4, [%sp + ISF_G4_OFFSET]     ! save g4, g5 -- see above
[2f8704b6]427        SPARC_LEON3FT_B2BST_NOP
[7c0bd74]428        st      %g7, [%sp + ISF_G7_OFFSET]     ! save g7
[5d69cd3]429
430        std     %i0, [%sp + ISF_I0_OFFSET]     ! save i0, i1
[2f8704b6]431        SPARC_LEON3FT_B2BST_NOP
[5d69cd3]432        std     %i2, [%sp + ISF_I2_OFFSET]     ! save i2, i3
[2f8704b6]433        SPARC_LEON3FT_B2BST_NOP
[5d69cd3]434        std     %i4, [%sp + ISF_I4_OFFSET]     ! save i4, i5
[2f8704b6]435        SPARC_LEON3FT_B2BST_NOP
[5d69cd3]436        std     %i6, [%sp + ISF_I6_FP_OFFSET]  ! save i6/fp, i7
437
438        rd      %y, %g1
439        st      %g1, [%sp + ISF_Y_OFFSET]      ! save y
440
[849bb7a3]441        /*
442         *  Increment ISR nest level and Thread dispatch disable level.
443         *
444         *  Register usage for this section:
445         *
446         *    l6 = _Thread_Dispatch_disable_level value
447         *    l7 = _ISR_Nest_level value
448         *
[7c0bd74]449         *  NOTE: It is assumed that l6 - l7 will be preserved until the ISR
[849bb7a3]450         *        nest and thread dispatch disable levels are unnested.
451         */
452
[7c0bd74]453        ld       [%g6 + PER_CPU_ISR_NEST_LEVEL], %l7
454        ld       [%g6 + PER_CPU_THREAD_DISPATCH_DISABLE_LEVEL], %l6
[849bb7a3]455
456        add      %l7, 1, %l7
[7c0bd74]457        st       %l7, [%g6 + PER_CPU_ISR_NEST_LEVEL]
[2f8704b6]458        SPARC_LEON3FT_B2BST_NOP
[849bb7a3]459
[f715433]460        add      %l6, 1, %l6
[7c0bd74]461        st       %l6, [%g6 + PER_CPU_THREAD_DISPATCH_DISABLE_LEVEL]
[f715433]462
[2764bd43]463#if SPARC_HAS_FPU == 1
464        /*
465         * We cannot use an intermediate value for operations with the PSR[EF]
466         * bit since they use a 13-bit sign extension and PSR[EF] is bit 12.
467         */
468        sethi    %hi(SPARC_PSR_EF_MASK), %l5
469#endif
470
[849bb7a3]471        /*
472         *  If ISR nest level was zero (now 1), then switch stack.
473         */
474
475        mov      %sp, %fp
476        subcc    %l7, 1, %l7             ! outermost interrupt handler?
477        bnz      dont_switch_stacks      ! No, then do not switch stacks
478
[9460333e]479#if defined(RTEMS_PROFILING)
480         sethi   %hi(_SPARC_Counter), %o5
481        ld       [%o5 + %lo(_SPARC_Counter)], %l4
[8639685]482        call     %l4
[9460333e]483         nop
484        mov      %o0, %o5
[de5d6d0]485#else
486         nop
487#endif
488
[26ffb8c2]489        ld       [%g6 + PER_CPU_INTERRUPT_STACK_HIGH], %sp
[849bb7a3]490
[2764bd43]491#if SPARC_HAS_FPU == 1
492        /*
493         * Test if the interrupted thread uses the floating point unit
494         * (PSR[EF] == 1).  In case it uses the floating point unit, then store
495         * the floating point status register.  This has the side-effect that
496         * all pending floating point operations complete before the store
497         * completes.  The PSR[EF] bit is restored after the call to the
498         * interrupt handler.  Thus post-switch actions (e.g. signal handlers)
499         * and context switch extensions may still corrupt the floating point
500         * context.
501         */
502        andcc    %l0, %l5, %g0
[89d90c0]503        beq      dont_switch_stacks
504         nop
505        st      %fsr, [%g6 + SPARC_PER_CPU_FSR_OFFSET]
[2764bd43]506#endif
507
[849bb7a3]508dont_switch_stacks:
509        /*
510         *  Make sure we have a place on the stack for the window overflow
511         *  trap handler to write into.  At this point it is safe to
512         *  enable traps again.
513         */
514
[427dcee]515        sub      %sp, SPARC_MINIMUM_STACK_FRAME_SIZE, %sp
[849bb7a3]516
[5d69cd3]517        /*
[be96cb43]518         *  Set the PIL in the %psr to mask off interrupts with lower priority.
[5d69cd3]519         *  The original %psr in %l0 is not modified since it will be restored
520         *  when the interrupt handler returns.
521         */
522
523        mov      %l0, %g5
[be96cb43]524        sll      %l3, 8, %g4
[5d69cd3]525        and      %g4, SPARC_PSR_PIL_MASK, %g4
526        andn     %l0, SPARC_PSR_PIL_MASK, %g5
527        or       %g4, %g5, %g5
[2764bd43]528
529#if SPARC_HAS_FPU == 1
530        /*
531         * Clear the PSR[EF] bit of the interrupted context to ensure that
532         * interrupt service routines cannot corrupt the floating point context.
533         */
534        andn     %g5, %l5, %g5
535#endif
536
[5d69cd3]537        wr       %g5, SPARC_PSR_ET_MASK, %psr ! **** ENABLE TRAPS ****
538
539        /*
[be96cb43]540         *  Call _SPARC_Interrupt_dispatch( %l3 )
[5d69cd3]541         */
542        mov      %l3, %o0               ! o0 = 1st arg = vector number
[be96cb43]543        call     SYM(_SPARC_Interrupt_dispatch)
[9460333e]544#if defined(RTEMS_PROFILING)
[de5d6d0]545         mov     %o5, %l3               ! save interrupt entry instant
[6a1b9e4]546#else
547         nop                            ! delay slot
548#endif
549
[146adb1]550#if defined(SPARC_USE_SYNCHRONOUS_FP_SWITCH)
[6a1b9e4]551        mov      %l0, %g1               ! PSR[EF] value of interrupted context
552        ta       SPARC_SWTRAP_IRQDIS_FP ! **** DISABLE INTERRUPTS ****
553#else
554        ta       SPARC_SWTRAP_IRQDIS    ! **** DISABLE INTERRUPTS ****
555#endif
556
557#if defined(RTEMS_PROFILING)
[de5d6d0]558        cmp      %l7, 0
559        bne      profiling_not_outer_most_exit
560         nop
[8639685]561        call     %l4                    ! Call _SPARC_Counter.counter_read
[6a1b9e4]562         mov     %g1, %l4               ! Save previous interrupt status
[9460333e]563        mov      %o0, %o2               ! o2 = 3rd arg = interrupt exit instant
[de5d6d0]564        mov      %l3, %o1               ! o1 = 2nd arg = interrupt entry instant
[8639685]565        call     SYM(_Profiling_Outer_most_interrupt_entry_and_exit)
[7c0bd74]566         mov     %g6, %o0               ! o0 = 1st arg = per-CPU control
[de5d6d0]567profiling_not_outer_most_exit:
568#endif
[5d69cd3]569
570        /*
571         *  Decrement ISR nest level and Thread dispatch disable level.
572         *
573         *  Register usage for this section:
574         *
[6a1b9e4]575         *    o2 = g6->dispatch_necessary value
576         *    o3 = g6->isr_dispatch_disable value
577         *    l6 = g6->thread_dispatch_disable_level value
578         *    l7 = g6->isr_nest_level value
[5d69cd3]579         */
580
[6a1b9e4]581        ldub     [%g6 + PER_CPU_DISPATCH_NEEDED], %o2
582        ld       [%g6 + PER_CPU_ISR_DISPATCH_DISABLE], %o3
[7c0bd74]583        st       %l7, [%g6 + PER_CPU_ISR_NEST_LEVEL]
[2f8704b6]584        SPARC_LEON3FT_B2BST_NOP
[5d69cd3]585        sub      %l6, 1, %l6
[7c0bd74]586        st       %l6, [%g6 + PER_CPU_THREAD_DISPATCH_DISABLE_LEVEL]
[5d69cd3]587
588        /*
[6a1b9e4]589         * Thread dispatching is necessary and allowed if and only if
590         *   g6->dispatch_necessary == 1 and
591         *   g6->isr_dispatch_disable == 0 and
592         *   g6->thread_dispatch_disable_level == 0.
593         *
594         * Otherwise, continue with the simple return.
[5d69cd3]595         */
[6a1b9e4]596        xor      %o2, 1, %o2
597        or       %o2, %l6, %o2
598        orcc     %o2, %o3, %o2
599        bnz      simple_return
[5d69cd3]600
601        /*
[6a1b9e4]602         * Switch back on the interrupted tasks stack and add enough room to
603         * invoke the dispatcher.  Doing this in the delay slot causes no harm,
604         * since the stack pointer (%sp) is not used in the simple return path.
[5d69cd3]605         */
[6a1b9e4]606         sub     %fp, SPARC_MINIMUM_STACK_FRAME_SIZE, %sp
[5d69cd3]607
[6a1b9e4]608isr_dispatch:
[5d69cd3]609
[6a1b9e4]610        /* Set ISR dispatch disable and thread dispatch disable level to one */
611        mov      1, %l6
612        st       %l6, [%g6 + PER_CPU_THREAD_DISPATCH_DISABLE_LEVEL]
[c11ac2d5]613        st       %l6, [%g6 + PER_CPU_ISR_DISPATCH_DISABLE]
[5d69cd3]614
[6a1b9e4]615        /* Call _Thread_Do_dispatch(), this function will enable interrupts */
[5d69cd3]616
[6a1b9e4]617        mov      0, %o1                 ! ISR level for _Thread_Do_dispatch()
[a51b352]618
[146adb1]619#if defined(SPARC_USE_LAZY_FP_SWITCH)
620        /* Test if we interrupted a floating point thread (PSR[EF] == 1) */
621        andcc   %l0, %l5, %g0
622        be      .Lnon_fp_thread_dispatch
623         ld     [%g6 + PER_CPU_OFFSET_EXECUTING], %l6
624
625        /* Set new floating point unit owner to executing thread */
626        st      %l6, [%g6 + SPARC_PER_CPU_FP_OWNER_OFFSET]
627
628        call    SYM(_Thread_Do_dispatch)
629         mov    %g6, %o0
630
631        /*
632         * If we are still the floating point unit owner, then reset the
633         * floating point unit owner to NULL, otherwise clear PSR[EF] in the
634         * interrupt frame and let the FP disabled system call do the floating
635         * point context save/restore.
636         */
637        ld      [%g6 + SPARC_PER_CPU_FP_OWNER_OFFSET], %l7
638        cmp     %l6, %l7
[2a720f4]639        bne,a   .Ldisable_fp
[146adb1]640         andn   %l0, %l5, %l0
[0cae482a]641        st      %g0, [%g6 + SPARC_PER_CPU_FP_OWNER_OFFSET]
[146adb1]642        ba      .Lthread_dispatch_done
[0cae482a]643         nop
[146adb1]644.Ldisable_fp:
[0cae482a]645        st       %l0, [%fp + ISF_PSR_OFFSET]
[146adb1]646        ba      .Lthread_dispatch_done
[0cae482a]647         nop
[146adb1]648.Lnon_fp_thread_dispatch:
649#elif defined(SPARC_USE_SYNCHRONOUS_FP_SWITCH)
[a51b352]650        /* Test if we interrupted a floating point thread (PSR[EF] == 1) */
651        andcc   %l0, %l5, %g0
[146adb1]652        be      .Lnon_fp_thread_dispatch
[a51b352]653         nop
654
655        /*
656         * Yes, this is a floating point thread, then save the floating point
657         * context to a new stack frame.  Then do the thread dispatch.
658         * Post-switch actions (e.g. signal handlers) and context switch
659         * extensions may safely use the floating point unit.
660         */
[b9d5f516]661        sub     %sp, SPARC_FP_FRAME_SIZE, %sp
662        std     %f0, [%sp + SPARC_FP_FRAME_OFFSET_FO_F1]
[2f8704b6]663        SPARC_LEON3FT_B2BST_NOP
[b9d5f516]664        std     %f2, [%sp + SPARC_FP_FRAME_OFFSET_F2_F3]
[2f8704b6]665        SPARC_LEON3FT_B2BST_NOP
[b9d5f516]666        std     %f4, [%sp + SPARC_FP_FRAME_OFFSET_F4_F5]
[2f8704b6]667        SPARC_LEON3FT_B2BST_NOP
[b9d5f516]668        std     %f6, [%sp + SPARC_FP_FRAME_OFFSET_F6_F7]
[2f8704b6]669        SPARC_LEON3FT_B2BST_NOP
[b9d5f516]670        std     %f8, [%sp + SPARC_FP_FRAME_OFFSET_F8_F9]
[2f8704b6]671        SPARC_LEON3FT_B2BST_NOP
[b9d5f516]672        std     %f10, [%sp + SPARC_FP_FRAME_OFFSET_F1O_F11]
[2f8704b6]673        SPARC_LEON3FT_B2BST_NOP
[b9d5f516]674        std     %f12, [%sp + SPARC_FP_FRAME_OFFSET_F12_F13]
[2f8704b6]675        SPARC_LEON3FT_B2BST_NOP
[b9d5f516]676        std     %f14, [%sp + SPARC_FP_FRAME_OFFSET_F14_F15]
[2f8704b6]677        SPARC_LEON3FT_B2BST_NOP
[b9d5f516]678        std     %f16, [%sp + SPARC_FP_FRAME_OFFSET_F16_F17]
[2f8704b6]679        SPARC_LEON3FT_B2BST_NOP
[b9d5f516]680        std     %f18, [%sp + SPARC_FP_FRAME_OFFSET_F18_F19]
[2f8704b6]681        SPARC_LEON3FT_B2BST_NOP
[b9d5f516]682        std     %f20, [%sp + SPARC_FP_FRAME_OFFSET_F2O_F21]
[2f8704b6]683        SPARC_LEON3FT_B2BST_NOP
[b9d5f516]684        std     %f22, [%sp + SPARC_FP_FRAME_OFFSET_F22_F23]
[2f8704b6]685        SPARC_LEON3FT_B2BST_NOP
[b9d5f516]686        std     %f24, [%sp + SPARC_FP_FRAME_OFFSET_F24_F25]
[2f8704b6]687        SPARC_LEON3FT_B2BST_NOP
[b9d5f516]688        std     %f26, [%sp + SPARC_FP_FRAME_OFFSET_F26_F27]
[2f8704b6]689        SPARC_LEON3FT_B2BST_NOP
[b9d5f516]690        std     %f28, [%sp + SPARC_FP_FRAME_OFFSET_F28_F29]
[2f8704b6]691        SPARC_LEON3FT_B2BST_NOP
[b9d5f516]692        std     %f30, [%sp + SPARC_FP_FRAME_OFFSET_F3O_F31]
[2f8704b6]693        SPARC_LEON3FT_B2BST_NOP
[b9d5f516]694        st      %fsr, [%sp + SPARC_FP_FRAME_OFFSET_FSR]
[8639685]695        call    SYM(_Thread_Do_dispatch)
[6a1b9e4]696         mov    %g6, %o0
[a51b352]697
698        /*
699         * Restore the floating point context from stack frame and release the
700         * stack frame.
701         */
[b9d5f516]702        ldd     [%sp + SPARC_FP_FRAME_OFFSET_FO_F1], %f0
703        ldd     [%sp + SPARC_FP_FRAME_OFFSET_F2_F3], %f2
704        ldd     [%sp + SPARC_FP_FRAME_OFFSET_F4_F5], %f4
705        ldd     [%sp + SPARC_FP_FRAME_OFFSET_F6_F7], %f6
706        ldd     [%sp + SPARC_FP_FRAME_OFFSET_F8_F9], %f8
707        ldd     [%sp + SPARC_FP_FRAME_OFFSET_F1O_F11], %f10
708        ldd     [%sp + SPARC_FP_FRAME_OFFSET_F12_F13], %f12
709        ldd     [%sp + SPARC_FP_FRAME_OFFSET_F14_F15], %f14
710        ldd     [%sp + SPARC_FP_FRAME_OFFSET_F16_F17], %f16
711        ldd     [%sp + SPARC_FP_FRAME_OFFSET_F18_F19], %f18
712        ldd     [%sp + SPARC_FP_FRAME_OFFSET_F2O_F21], %f20
713        ldd     [%sp + SPARC_FP_FRAME_OFFSET_F22_F23], %f22
714        ldd     [%sp + SPARC_FP_FRAME_OFFSET_F24_F25], %f24
715        ldd     [%sp + SPARC_FP_FRAME_OFFSET_F26_F27], %f26
716        ldd     [%sp + SPARC_FP_FRAME_OFFSET_F28_F29], %f28
717        ldd     [%sp + SPARC_FP_FRAME_OFFSET_F3O_F31], %f30
718        ld      [%sp + SPARC_FP_FRAME_OFFSET_FSR], %fsr
[146adb1]719        ba      .Lthread_dispatch_done
[b9d5f516]720         add    %sp, SPARC_FP_FRAME_SIZE, %sp
[a51b352]721
[146adb1]722.Lnon_fp_thread_dispatch:
[a51b352]723#endif
724
[8639685]725        call    SYM(_Thread_Do_dispatch)
[6a1b9e4]726         mov    %g6, %o0
[5d69cd3]727
[146adb1]728#if SPARC_HAS_FPU == 1
729.Lthread_dispatch_done:
[a51b352]730#endif
731
[6a1b9e4]732        ta       SPARC_SWTRAP_IRQDIS ! **** DISABLE INTERRUPTS ****
[5d69cd3]733
734        /*
735         *  While we had ISR dispatching disabled in this thread,
[6a1b9e4]736         *  did we miss anything?  If so, then we need to do another
737         *  _Thread_Do_dispatch() before leaving this ISR dispatch context.
[5d69cd3]738         */
[dff1803]739        ldub    [%g6 + PER_CPU_DISPATCH_NEEDED], %l7
[5d69cd3]740
[6a1b9e4]741        orcc    %l7, %g0, %g0        ! Is a thread dispatch necessary?
742        bne     isr_dispatch         ! Yes, then invoke the dispatcher again.
743         mov    0, %o1               ! ISR level for _Thread_Do_dispatch()
[5d69cd3]744
[6a1b9e4]745        /*
746         * No, then set the ISR dispatch disable flag to zero and continue with
747         * the simple return.
748         */
[c11ac2d5]749        st       %g0, [%g6 + PER_CPU_ISR_DISPATCH_DISABLE]
[5d69cd3]750
751        /*
752         *  The CWP in place at this point may be different from
753         *  that which was in effect at the beginning of the ISR if we
754         *  have been context switched between the beginning of this invocation
[be96cb43]755         *  of _SPARC_Interrupt_trap() and this point.  Thus the CWP and WIM
756         *  should not be changed back to their values at ISR entry time.  Any
[5d69cd3]757         *  changes to the PSR must preserve the CWP.
758         */
759
760simple_return:
761        ld      [%fp + ISF_Y_OFFSET], %l5      ! restore y
762        wr      %l5, 0, %y
763
764        ldd     [%fp + ISF_PSR_OFFSET], %l0    ! restore psr, PC
765        ld      [%fp + ISF_NPC_OFFSET], %l2    ! restore nPC
766        rd      %psr, %l3
767        and     %l3, SPARC_PSR_CWP_MASK, %l3   ! want "current" CWP
768        andn    %l0, SPARC_PSR_CWP_MASK, %l0   ! want rest from task
769        or      %l3, %l0, %l0                  ! install it later...
770        andn    %l0, SPARC_PSR_ET_MASK, %l0
771
772        /*
773         *  Restore tasks global and out registers
774         */
775
776        mov    %fp, %g1
777
778                                              ! g1 is restored later
779        ldd     [%fp + ISF_G2_OFFSET], %g2    ! restore g2, g3
780        ldd     [%fp + ISF_G4_OFFSET], %g4    ! restore g4, g5
[7c0bd74]781        ld      [%fp + ISF_G7_OFFSET], %g7    ! restore g7
[5d69cd3]782
783        ldd     [%fp + ISF_I0_OFFSET], %i0    ! restore i0, i1
784        ldd     [%fp + ISF_I2_OFFSET], %i2    ! restore i2, i3
785        ldd     [%fp + ISF_I4_OFFSET], %i4    ! restore i4, i5
786        ldd     [%fp + ISF_I6_FP_OFFSET], %i6 ! restore i6/fp, i7
787
788        /*
789         *  Registers:
790         *
791         *   ALL global registers EXCEPT G1 and the input registers have
792         *   already been restored and thuse off limits.
793         *
794         *   The following is the contents of the local registers:
795         *
796         *     l0 = original psr
797         *     l1 = return address (i.e. PC)
798         *     l2 = nPC
799         *     l3 = CWP
800         */
801
802        /*
803         *  if (CWP + 1) is an invalid window then we need to reload it.
804         *
805         *  WARNING: Traps should now be disabled
806         */
807
808        mov     %l0, %psr                  !  **** DISABLE TRAPS ****
809        nop
810        nop
811        nop
812        rd      %wim, %l4
813        add     %l0, 1, %l6                ! l6 = cwp + 1
814        and     %l6, SPARC_PSR_CWP_MASK, %l6 ! do the modulo on it
815        srl     %l4, %l6, %l5              ! l5 = win >> cwp + 1 ; shift count
816                                           !  and CWP are conveniently LS 5 bits
817        cmp     %l5, 1                     ! Is tasks window invalid?
818        bne     good_task_window
819
820        /*
821         *  The following code is the same as a 1 position left rotate of WIM.
822         */
823
824        sll     %l4, 1, %l5                ! l5 = WIM << 1
825        srl     %l4, SPARC_NUMBER_OF_REGISTER_WINDOWS-1 , %l4
826                                           ! l4 = WIM >> (Number Windows - 1)
827        or      %l4, %l5, %l4              ! l4 = (WIM << 1) |
828                                           !      (WIM >> (Number Windows - 1))
829
830        /*
831         *  Now restore the window just as if we underflowed to it.
832         */
833
834        wr      %l4, 0, %wim               ! WIM = new WIM
835        nop                                ! must delay after writing WIM
836        nop
837        nop
838        restore                            ! now into the tasks window
839
840        ldd     [%g1 + CPU_STACK_FRAME_L0_OFFSET], %l0
841        ldd     [%g1 + CPU_STACK_FRAME_L2_OFFSET], %l2
842        ldd     [%g1 + CPU_STACK_FRAME_L4_OFFSET], %l4
843        ldd     [%g1 + CPU_STACK_FRAME_L6_OFFSET], %l6
844        ldd     [%g1 + CPU_STACK_FRAME_I0_OFFSET], %i0
845        ldd     [%g1 + CPU_STACK_FRAME_I2_OFFSET], %i2
846        ldd     [%g1 + CPU_STACK_FRAME_I4_OFFSET], %i4
847        ldd     [%g1 + CPU_STACK_FRAME_I6_FP_OFFSET], %i6
848                                           ! reload of sp clobbers ISF
849        save                               ! Back to ISR dispatch window
850
851good_task_window:
[b2da982]852        TN0018_WAIT_IFLUSH %l3,%l4         ! GRLIB-TN-0018 work around macro
[5d69cd3]853
854        mov     %l0, %psr                  !  **** DISABLE TRAPS ****
[26ffb8c2]855        nop; nop; nop
[5d69cd3]856                                           !  and restore condition codes.
857        ld      [%g1 + ISF_G1_OFFSET], %g1 ! restore g1
[b2da982]858        TN0018_FIX %l3,%l4                 ! GRLIB-TN-0018 work around macro
[5d69cd3]859        jmp     %l1                        ! transfer control and
860        rett    %l2                        ! go back to tasks window
861
862/* end of file */
Note: See TracBrowser for help on using the repository browser.