source: rtems/c/src/lib/libbsp/sparc/shared/irq_asm.S @ f8ad6c6f

4.115
Last change on this file since f8ad6c6f was f8ad6c6f, checked in by Sebastian Huber <sebastian.huber@…>, on 08/02/13 at 12:12:55

sparc: Make _CPU_ISR_Dispatch_disable per-CPU

This variable must be available for each processor in the system.

  • Property mode set to 100644
File size: 26.3 KB
Line 
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 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *  http://www.rtems.com/license/LICENSE.
13 *
14 *  Ported to ERC32 implementation of the SPARC by On-Line Applications
15 *  Research Corporation (OAR) under contract to the European Space
16 *  Agency (ESA).
17 *
18 *  ERC32 modifications of respective RTEMS file: COPYRIGHT (c) 1995.
19 *  European Space Agency.
20 */
21
22#include <rtems/asm.h>
23#include <rtems/score/percpu.h>
24#include <bspopts.h>
25
26.macro GET_SELF_CPU_CONTROL REG, TMP
27        sethi    %hi(_Per_CPU_Information), \REG
28        add      \REG, %lo(_Per_CPU_Information), \REG
29
30#if defined( RTEMS_SMP )
31#if BSP_LEON3_SMP
32        /* LEON3 SMP support */
33        rd       %asr17, \TMP
34        srl      \TMP, 28, \TMP /* CPU number is upper 4 bits so shift */
35#else
36        mov      0, \TMP
37        nop
38#endif
39        sll      \TMP, PER_CPU_CONTROL_SIZE_LOG2, \TMP
40        add      \REG, \TMP, \REG
41#endif /* defined( RTEMS_SMP ) */
42.endm
43
44/*
45 *  void _CPU_Context_switch(
46 *    Context_Control  *run,
47 *    Context_Control  *heir
48 *  )
49 *
50 *  This routine performs a normal non-FP context switch.
51 */
52
53        .align 4
54        PUBLIC(_CPU_Context_switch)
55SYM(_CPU_Context_switch):
56        ! skip g0
57        st      %g1, [%o0 + G1_OFFSET]       ! save the global registers
58        std     %g2, [%o0 + G2_OFFSET]
59        std     %g4, [%o0 + G4_OFFSET]
60        std     %g6, [%o0 + G6_OFFSET]
61
62        std     %l0, [%o0 + L0_OFFSET]       ! save the local registers
63        std     %l2, [%o0 + L2_OFFSET]
64        std     %l4, [%o0 + L4_OFFSET]
65        std     %l6, [%o0 + L6_OFFSET]
66
67        std     %i0, [%o0 + I0_OFFSET]       ! save the input registers
68        std     %i2, [%o0 + I2_OFFSET]
69        std     %i4, [%o0 + I4_OFFSET]
70        std     %i6, [%o0 + I6_FP_OFFSET]
71
72        std     %o0, [%o0 + O0_OFFSET]       ! save the output registers
73        std     %o2, [%o0 + O2_OFFSET]
74        std     %o4, [%o0 + O4_OFFSET]
75        std     %o6, [%o0 + O6_SP_OFFSET]
76
77        ! o3 = self per-CPU control
78        GET_SELF_CPU_CONTROL %o3, %o4
79
80        ! load the ISR stack nesting prevention flag
81        ld      [%o3 + SPARC_PER_CPU_ISR_DISPATCH_DISABLE], %o4
82        ! save it a bit later so we do not waste a couple of cycles
83
84        rd      %psr, %o2
85        st      %o2, [%o0 + PSR_OFFSET]      ! save status register
86
87        ! Now actually save ISR stack nesting prevention flag
88        st       %o4, [%o0 + ISR_DISPATCH_DISABLE_STACK_OFFSET]
89
90        /*
91         *  This is entered from _CPU_Context_restore with:
92         *    o1 = context to restore
93         *    o2 = psr
94         *    o3 = self per-CPU control
95         */
96
97        PUBLIC(_CPU_Context_restore_heir)
98SYM(_CPU_Context_restore_heir):
99        /*
100         *  Flush all windows with valid contents except the current one.
101         *  In examining the set register windows, one may logically divide
102         *  the windows into sets (some of which may be empty) based on their
103         *  current status:
104         *
105         *    + current (i.e. in use),
106         *    + used (i.e. a restore would not trap)
107         *    + invalid (i.e. 1 in corresponding bit in WIM)
108         *    + unused
109         *
110         *  Either the used or unused set of windows may be empty.
111         *
112         *  NOTE: We assume only one bit is set in the WIM at a time.
113         *
114         *  Given a CWP of 5 and a WIM of 0x1, the registers are divided
115         *  into sets as follows:
116         *
117         *    + 0   - invalid
118         *    + 1-4 - unused
119         *    + 5   - current
120         *    + 6-7 - used
121         *
122         *  In this case, we only would save the used windows -- 6 and 7.
123         *
124         *   Traps are disabled for the same logical period as in a
125         *     flush all windows trap handler.
126         *
127         *    Register Usage while saving the windows:
128         *      g1 = current PSR
129         *      g2 = current wim
130         *      g3 = CWP
131         *      g4 = wim scratch
132         *      g5 = scratch
133         */
134
135        ld      [%o1 + PSR_OFFSET], %g1       ! g1 = saved psr
136
137        and     %o2, SPARC_PSR_CWP_MASK, %g3  ! g3 = CWP
138                                              ! g1 = psr w/o cwp
139        andn    %g1, SPARC_PSR_ET_MASK | SPARC_PSR_CWP_MASK, %g1
140        or      %g1, %g3, %g1                 ! g1 = heirs psr
141        mov     %g1, %psr                     ! restore status register and
142                                              ! **** DISABLE TRAPS ****
143        mov     %wim, %g2                     ! g2 = wim
144        mov     1, %g4
145        sll     %g4, %g3, %g4                 ! g4 = WIM mask for CW invalid
146
147save_frame_loop:
148        sll     %g4, 1, %g5                   ! rotate the "wim" left 1
149        srl     %g4, SPARC_NUMBER_OF_REGISTER_WINDOWS - 1, %g4
150        or      %g4, %g5, %g4                 ! g4 = wim if we do one restore
151
152        /*
153         *  If a restore would not underflow, then continue.
154         */
155
156        andcc   %g4, %g2, %g0                 ! Any windows to flush?
157        bnz     done_flushing                 ! No, then continue
158        nop
159
160        restore                               ! back one window
161
162        /*
163         *  Now save the window just as if we overflowed to it.
164         */
165
166        std     %l0, [%sp + CPU_STACK_FRAME_L0_OFFSET]
167        std     %l2, [%sp + CPU_STACK_FRAME_L2_OFFSET]
168        std     %l4, [%sp + CPU_STACK_FRAME_L4_OFFSET]
169        std     %l6, [%sp + CPU_STACK_FRAME_L6_OFFSET]
170
171        std     %i0, [%sp + CPU_STACK_FRAME_I0_OFFSET]
172        std     %i2, [%sp + CPU_STACK_FRAME_I2_OFFSET]
173        std     %i4, [%sp + CPU_STACK_FRAME_I4_OFFSET]
174        std     %i6, [%sp + CPU_STACK_FRAME_I6_FP_OFFSET]
175
176        ba      save_frame_loop
177        nop
178
179done_flushing:
180
181        add     %g3, 1, %g3                   ! calculate desired WIM
182        and     %g3, SPARC_NUMBER_OF_REGISTER_WINDOWS - 1, %g3
183        mov     1, %g4
184        sll     %g4, %g3, %g4                 ! g4 = new WIM
185        mov     %g4, %wim
186
187        or      %g1, SPARC_PSR_ET_MASK, %g1
188        mov     %g1, %psr                     ! **** ENABLE TRAPS ****
189                                              !   and restore CWP
190        nop
191        nop
192        nop
193
194        ! skip g0
195        ld      [%o1 + G1_OFFSET], %g1        ! restore the global registers
196        ldd     [%o1 + G2_OFFSET], %g2
197        ldd     [%o1 + G4_OFFSET], %g4
198        ldd     [%o1 + G6_OFFSET], %g6
199
200        ! Load thread specific ISR dispatch prevention flag
201        ld      [%o1 + ISR_DISPATCH_DISABLE_STACK_OFFSET], %o2
202        ! Store it to memory later to use the cycles
203
204        ldd     [%o1 + L0_OFFSET], %l0        ! restore the local registers
205        ldd     [%o1 + L2_OFFSET], %l2
206        ldd     [%o1 + L4_OFFSET], %l4
207        ldd     [%o1 + L6_OFFSET], %l6
208
209        ! Now restore thread specific ISR dispatch prevention flag
210        st      %o2, [%o3 + SPARC_PER_CPU_ISR_DISPATCH_DISABLE]
211
212        ldd     [%o1 + I0_OFFSET], %i0        ! restore the output registers
213        ldd     [%o1 + I2_OFFSET], %i2
214        ldd     [%o1 + I4_OFFSET], %i4
215        ldd     [%o1 + I6_FP_OFFSET], %i6
216
217        ldd     [%o1 + O2_OFFSET], %o2        ! restore the output registers
218        ldd     [%o1 + O4_OFFSET], %o4
219        ldd     [%o1 + O6_SP_OFFSET], %o6
220        ! do o0/o1 last to avoid destroying heir context pointer
221        ldd     [%o1 + O0_OFFSET], %o0        ! overwrite heir pointer
222
223        jmp     %o7 + 8                       ! return
224        nop                                   ! delay slot
225
226/*
227 *  void _CPU_Context_restore(
228 *    Context_Control *new_context
229 *  )
230 *
231 *  This routine is generally used only to perform restart self.
232 *
233 *  NOTE: It is unnecessary to reload some registers.
234 */
235        .align 4
236        PUBLIC(_CPU_Context_restore)
237SYM(_CPU_Context_restore):
238        save    %sp, -CPU_MINIMUM_STACK_FRAME_SIZE, %sp
239        rd      %psr, %o2
240        GET_SELF_CPU_CONTROL %o3, %o4
241        ba      SYM(_CPU_Context_restore_heir)
242        mov     %i0, %o1                      ! in the delay slot
243        .align 4
244
245#if defined(RTEMS_SMP)
246/*
247 *  void _CPU_Context_switch_to_first_task_smp(
248 *    Context_Control *new_context
249 *  )
250 *
251 *  This routine is only used to switch to the first task on a
252 *  secondary core in an SMP configuration.  We do not need to
253 *  flush any windows and, in fact, this can be dangerous
254 *  as they may or may not be initialized properly.  So we just
255 *  reinitialize the PSR and WIM.
256 */
257        PUBLIC(_CPU_Context_switch_to_first_task_smp)
258SYM(_CPU_Context_switch_to_first_task_smp):
259        mov     %psr, %g1               ! Turn of traps when modifying WIM
260        andn    %g1, SPARC_PSR_ET_MASK, %g1
261        mov     %g1, %psr
262        /* WIM and PSR will be set in done_flushing, it need args:
263         * g1=PSR, g3=CWP, o1=Context
264         */
265        and     %g1, SPARC_NUMBER_OF_REGISTER_WINDOWS - 1, %g3
266        nop
267        mov     %o0, %o1                ! in the delay slot
268        ba,a    done_flushing
269#endif
270
271/*
272 *  void _ISR_Handler()
273 *
274 *  This routine provides the RTEMS interrupt management.
275 *
276 *  We enter this handler from the 4 instructions in the trap table with
277 *  the following registers assumed to be set as shown:
278 *
279 *    l0 = PSR
280 *    l1 = PC
281 *    l2 = nPC
282 *    l3 = trap type
283 *
284 *  NOTE: By an executive defined convention, trap type is between 0 and 255 if
285 *        it is an asynchonous trap and 256 and 511 if it is synchronous.
286 */
287
288        .align 4
289        PUBLIC(_ISR_Handler)
290SYM(_ISR_Handler):
291        /*
292         *  Fix the return address for synchronous traps.
293         */
294
295        andcc   %l3, SPARC_SYNCHRONOUS_TRAP_BIT_MASK, %g0
296                                      ! Is this a synchronous trap?
297        be,a    win_ovflow            ! No, then skip the adjustment
298        nop                           ! DELAY
299        mov     %l1, %l6              ! save trapped pc for debug info
300        mov     %l2, %l1              ! do not return to the instruction
301        add     %l2, 4, %l2           ! indicated
302
303win_ovflow:
304        /*
305         *  Save the globals this block uses.
306         *
307         *  These registers are not restored from the locals.  Their contents
308         *  are saved directly from the locals into the ISF below.
309         */
310
311        mov     %g4, %l4                 ! save the globals this block uses
312        mov     %g5, %l5
313
314        /*
315         *  When at a "window overflow" trap, (wim == (1 << cwp)).
316         *  If we get here like that, then process a window overflow.
317         */
318
319        rd      %wim, %g4
320        srl     %g4, %l0, %g5            ! g5 = win >> cwp ; shift count and CWP
321                                         !   are LS 5 bits ; how convenient :)
322        cmp     %g5, 1                   ! Is this an invalid window?
323        bne     dont_do_the_window       ! No, then skip all this stuff
324        ! we are using the delay slot
325
326        /*
327         *  The following is same as a 1 position right rotate of WIM
328         */
329
330        srl     %g4, 1, %g5              ! g5 = WIM >> 1
331        sll     %g4, SPARC_NUMBER_OF_REGISTER_WINDOWS-1 , %g4
332                                         ! g4 = WIM << (Number Windows - 1)
333        or      %g4, %g5, %g4            ! g4 = (WIM >> 1) |
334                                         !      (WIM << (Number Windows - 1))
335
336        /*
337         *  At this point:
338         *
339         *    g4 = the new WIM
340         *    g5 is free
341         */
342
343        /*
344         *  Since we are tinkering with the register windows, we need to
345         *  make sure that all the required information is in global registers.
346         */
347
348        save                          ! Save into the window
349        wr      %g4, 0, %wim          ! WIM = new WIM
350        nop                           ! delay slots
351        nop
352        nop
353
354        /*
355         *  Now save the window just as if we overflowed to it.
356         */
357
358        std     %l0, [%sp + CPU_STACK_FRAME_L0_OFFSET]
359        std     %l2, [%sp + CPU_STACK_FRAME_L2_OFFSET]
360        std     %l4, [%sp + CPU_STACK_FRAME_L4_OFFSET]
361        std     %l6, [%sp + CPU_STACK_FRAME_L6_OFFSET]
362
363        std     %i0, [%sp + CPU_STACK_FRAME_I0_OFFSET]
364        std     %i2, [%sp + CPU_STACK_FRAME_I2_OFFSET]
365        std     %i4, [%sp + CPU_STACK_FRAME_I4_OFFSET]
366        std     %i6, [%sp + CPU_STACK_FRAME_I6_FP_OFFSET]
367
368        restore
369        nop
370
371dont_do_the_window:
372        /*
373         *  Global registers %g4 and %g5 are saved directly from %l4 and
374         *  %l5 directly into the ISF below.
375         */
376
377save_isf:
378
379        /*
380         *  Save the state of the interrupted task -- especially the global
381         *  registers -- in the Interrupt Stack Frame.  Note that the ISF
382         *  includes a regular minimum stack frame which will be used if
383         *  needed by register window overflow and underflow handlers.
384         *
385         *  REGISTERS SAME AS AT _ISR_Handler
386         */
387
388        sub     %fp, CONTEXT_CONTROL_INTERRUPT_FRAME_SIZE, %sp
389                                               ! make space for ISF
390
391        std     %l0, [%sp + ISF_PSR_OFFSET]    ! save psr, PC
392        st      %l2, [%sp + ISF_NPC_OFFSET]    ! save nPC
393        st      %g1, [%sp + ISF_G1_OFFSET]     ! save g1
394        std     %g2, [%sp + ISF_G2_OFFSET]     ! save g2, g3
395        std     %l4, [%sp + ISF_G4_OFFSET]     ! save g4, g5 -- see above
396        std     %g6, [%sp + ISF_G6_OFFSET]     ! save g6, g7
397
398        std     %i0, [%sp + ISF_I0_OFFSET]     ! save i0, i1
399        std     %i2, [%sp + ISF_I2_OFFSET]     ! save i2, i3
400        std     %i4, [%sp + ISF_I4_OFFSET]     ! save i4, i5
401        std     %i6, [%sp + ISF_I6_FP_OFFSET]  ! save i6/fp, i7
402
403        rd      %y, %g1
404        st      %g1, [%sp + ISF_Y_OFFSET]      ! save y
405        st      %l6, [%sp + ISF_TPC_OFFSET]    ! save real trapped pc
406
407        mov     %sp, %o1                       ! 2nd arg to ISR Handler
408
409        /*
410         *  Increment ISR nest level and Thread dispatch disable level.
411         *
412         *  Register usage for this section:
413         *
414         *    l4 = _Thread_Dispatch_disable_level pointer
415         *    l5 = per cpu info pointer
416         *    l6 = _Thread_Dispatch_disable_level value
417         *    l7 = _ISR_Nest_level value
418         *
419         *  NOTE: It is assumed that l4 - l7 will be preserved until the ISR
420         *        nest and thread dispatch disable levels are unnested.
421         */
422
423        GET_SELF_CPU_CONTROL %l5, %l7
424
425        ld       [%l5 + PER_CPU_THREAD_DISPATCH_DISABLE_LEVEL], %l6
426        ld       [%l5 + PER_CPU_ISR_NEST_LEVEL], %l7
427
428        add      %l6, 1, %l6
429        st       %l6, [%l5 + PER_CPU_THREAD_DISPATCH_DISABLE_LEVEL]
430
431        add      %l7, 1, %l7
432        st       %l7, [%l5 + PER_CPU_ISR_NEST_LEVEL]
433
434        /*
435         *  If ISR nest level was zero (now 1), then switch stack.
436         */
437
438        mov      %sp, %fp
439        subcc    %l7, 1, %l7             ! outermost interrupt handler?
440        bnz      dont_switch_stacks      ! No, then do not switch stacks
441
442        nop
443        ld       [%l5 + PER_CPU_INTERRUPT_STACK_HIGH], %sp
444
445dont_switch_stacks:
446        /*
447         *  Make sure we have a place on the stack for the window overflow
448         *  trap handler to write into.  At this point it is safe to
449         *  enable traps again.
450         */
451
452        sub      %sp, CPU_MINIMUM_STACK_FRAME_SIZE, %sp
453
454        /*
455         *  Check if we have an external interrupt (trap 0x11 - 0x1f). If so,
456         *  set the PIL in the %psr to mask off interrupts with lower priority.
457         *  The original %psr in %l0 is not modified since it will be restored
458         *  when the interrupt handler returns.
459         */
460
461        mov      %l0, %g5
462        and      %l3, 0x0ff, %g4
463
464/* This is a fix for ERC32 with FPU rev.B or rev.C */
465
466#if defined(FPU_REVB)
467
468
469        subcc    %g4, 0x08, %g0
470        be       fpu_revb
471        subcc    %g4, 0x11, %g0
472        bl       dont_fix_pil
473        subcc    %g4, 0x1f, %g0
474        bg       dont_fix_pil
475        sll      %g4, 8, %g4
476        and      %g4, SPARC_PSR_PIL_MASK, %g4
477        andn     %l0, SPARC_PSR_PIL_MASK, %g5
478        or       %g4, %g5, %g5
479        srl      %l0, 12, %g4
480        andcc    %g4, 1, %g0
481        be       dont_fix_pil
482        nop
483        ba,a     enable_irq
484
485
486fpu_revb:
487        srl      %l0, 12, %g4   ! check if EF is set in %psr
488        andcc    %g4, 1, %g0
489        be       dont_fix_pil   ! if FPU disabled than continue as normal
490        and      %l3, 0xff, %g4
491        subcc    %g4, 0x08, %g0
492        bne      enable_irq     ! if not a FPU exception then do two fmovs
493        set      __sparc_fq, %g4
494        st       %fsr, [%g4]    ! if FQ is not empty and FQ[1] = fmovs
495        ld       [%g4], %g4     ! than this is bug 3.14
496        srl      %g4, 13, %g4
497        andcc    %g4, 1, %g0
498        be       dont_fix_pil
499        set      __sparc_fq, %g4
500        std      %fq, [%g4]
501        ld       [%g4+4], %g4
502        set      0x81a00020, %g5
503        subcc    %g4, %g5, %g0
504        bne,a    dont_fix_pil2
505        wr       %l0, SPARC_PSR_ET_MASK, %psr ! **** ENABLE TRAPS ****
506        ba,a     simple_return
507       
508enable_irq:
509        or       %g5, SPARC_PSR_PIL_MASK, %g4
510        wr       %g4, SPARC_PSR_ET_MASK, %psr ! **** ENABLE TRAPS ****
511        nop; nop; nop
512        fmovs    %f0, %f0
513        ba       dont_fix_pil
514        fmovs    %f0, %f0
515
516        .data
517        .global __sparc_fq
518        .align 8
519__sparc_fq:
520        .word 0,0
521
522        .text
523/* end of ERC32 FPU rev.B/C fix */
524
525#else
526
527        subcc    %g4, 0x11, %g0
528        bl       dont_fix_pil
529        subcc    %g4, 0x1f, %g0
530        bg       dont_fix_pil
531        sll      %g4, 8, %g4
532        and      %g4, SPARC_PSR_PIL_MASK, %g4
533        andn     %l0, SPARC_PSR_PIL_MASK, %g5
534        ba       pil_fixed
535        or       %g4, %g5, %g5
536#endif
537
538dont_fix_pil:
539        or       %g5, SPARC_PSR_PIL_MASK, %g5
540pil_fixed:
541        wr       %g5, SPARC_PSR_ET_MASK, %psr ! **** ENABLE TRAPS ****
542dont_fix_pil2:
543
544        /*
545         *  Vector to user's handler.
546         *
547         *  NOTE: TBR may no longer have vector number in it since
548         *        we just enabled traps.  It is definitely in l3.
549         */
550
551        sethi    %hi(SYM(_ISR_Vector_table)), %g4
552        ld       [%g4+%lo(SYM(_ISR_Vector_table))], %g4
553        and      %l3, 0xFF, %g5         ! remove synchronous trap indicator
554        sll      %g5, 2, %g5            ! g5 = offset into table
555        ld       [%g4 + %g5], %g4       ! g4 = _ISR_Vector_table[ vector ]
556
557
558                                        ! o1 = 2nd arg = address of the ISF
559                                        !   WAS LOADED WHEN ISF WAS SAVED!!!
560        mov      %l3, %o0               ! o0 = 1st arg = vector number
561        call     %g4, 0
562        nop                             ! delay slot
563
564        /*
565         *  Redisable traps so we can finish up the interrupt processing.
566         *  This is a VERY conservative place to do this.
567         *
568         *  NOTE: %l0 has the PSR which was in place when we took the trap.
569         */
570
571        mov      %l0, %psr             ! **** DISABLE TRAPS ****
572        nop; nop; nop
573
574        /*
575         *  Decrement ISR nest level and Thread dispatch disable level.
576         *
577         *  Register usage for this section:
578         *
579         *    l4 = _Thread_Dispatch_disable_level pointer
580         *    l5 = per cpu info pointer
581         *    l6 = _Thread_Dispatch_disable_level value
582         *    l7 = _ISR_Nest_level value
583         */
584
585        sub      %l6, 1, %l6
586        st       %l6, [%l5 + PER_CPU_THREAD_DISPATCH_DISABLE_LEVEL]
587
588        st       %l7, [%l5 + PER_CPU_ISR_NEST_LEVEL]
589
590        /*
591         *  If dispatching is disabled (includes nested interrupt case),
592         *  then do a "simple" exit.
593         */
594
595        orcc     %l6, %g0, %g0   ! Is dispatching disabled?
596        bnz      simple_return   ! Yes, then do a "simple" exit
597        nop
598
599        ! Are we dispatching from a previous ISR in the interrupted thread?
600        ld       [%l5 + SPARC_PER_CPU_ISR_DISPATCH_DISABLE], %l7
601        orcc     %l7, %g0, %g0   ! Is this thread already doing an ISR?
602        bnz      simple_return   ! Yes, then do a "simple" exit
603        nop
604
605
606        /*
607         *  If a context switch is necessary, then do fudge stack to
608         *  return to the interrupt dispatcher.
609         */
610
611        ldub     [%l5 + PER_CPU_DISPATCH_NEEDED], %l6
612
613        orcc     %l6, %g0, %g0   ! Is thread switch necessary?
614        bz       simple_return   ! no, then do a simple return
615        nop
616
617        /*
618         *  Invoke interrupt dispatcher.
619         */
620
621        ! Set ISR dispatch nesting prevention flag
622        mov      1,%l6
623        st       %l6, [%l5 + SPARC_PER_CPU_ISR_DISPATCH_DISABLE]
624
625        /*
626         *  The following subtract should get us back on the interrupted
627         *  tasks stack and add enough room to invoke the dispatcher.
628         *  When we enable traps, we are mostly back in the context
629         *  of the task and subsequent interrupts can operate normally.
630         */
631
632        sub      %fp, CPU_MINIMUM_STACK_FRAME_SIZE, %sp
633
634        or      %l0, SPARC_PSR_ET_MASK, %l7    ! l7 = PSR with ET=1
635        mov     %l7, %psr                      !  **** ENABLE TRAPS ****
636        nop
637        nop
638        nop
639isr_dispatch:
640        call    SYM(_Thread_Dispatch), 0
641        nop
642
643        /*
644         *  We invoked _Thread_Dispatch in a state similar to the interrupted
645         *  task.  In order to safely be able to tinker with the register
646         *  windows and get the task back to its pre-interrupt state,
647         *  we need to disable interrupts disabled so we can safely tinker
648         *  with the register windowing.  In particular, the CWP in the PSR
649         *  is fragile during this period. (See PR578.)
650         */
651        mov     2,%g1                           ! syscall (disable interrupts)
652        ta      0                               ! syscall (disable interrupts)
653
654        /*
655         *  While we had ISR dispatching disabled in this thread,
656         *  did we miss anything.  If so, then we need to do another
657         *  _Thread_Dispatch before leaving this ISR Dispatch context.
658         */
659
660        GET_SELF_CPU_CONTROL %l5, %l7
661
662        ldub     [%l5 + PER_CPU_DISPATCH_NEEDED], %l7
663
664        orcc     %l7, %g0, %g0    ! Is thread switch necesary?
665        bz       allow_nest_again ! No, then clear out and return
666        nop
667
668        ! Yes, then invoke the dispatcher
669dispatchAgain:
670        mov     3,%g1                           ! syscall (enable interrupts)
671        ta      0                               ! syscall (enable interrupts)
672        ba      isr_dispatch
673        nop
674
675allow_nest_again:
676
677        ! Zero out ISR stack nesting prevention flag
678        st       %g0, [%l5 + SPARC_PER_CPU_ISR_DISPATCH_DISABLE]
679
680        /*
681         *  The CWP in place at this point may be different from
682         *  that which was in effect at the beginning of the ISR if we
683         *  have been context switched between the beginning of this invocation
684         *  of _ISR_Handler and this point.  Thus the CWP and WIM should
685         *  not be changed back to their values at ISR entry time.  Any
686         *  changes to the PSR must preserve the CWP.
687         */
688
689simple_return:
690        ld      [%fp + ISF_Y_OFFSET], %l5      ! restore y
691        wr      %l5, 0, %y
692
693        ldd     [%fp + ISF_PSR_OFFSET], %l0    ! restore psr, PC
694        ld      [%fp + ISF_NPC_OFFSET], %l2    ! restore nPC
695        rd      %psr, %l3
696        and     %l3, SPARC_PSR_CWP_MASK, %l3   ! want "current" CWP
697        andn    %l0, SPARC_PSR_CWP_MASK, %l0   ! want rest from task
698        or      %l3, %l0, %l0                  ! install it later...
699        andn    %l0, SPARC_PSR_ET_MASK, %l0
700
701        /*
702         *  Restore tasks global and out registers
703         */
704
705        mov    %fp, %g1
706
707                                              ! g1 is restored later
708        ldd     [%fp + ISF_G2_OFFSET], %g2    ! restore g2, g3
709        ldd     [%fp + ISF_G4_OFFSET], %g4    ! restore g4, g5
710        ldd     [%fp + ISF_G6_OFFSET], %g6    ! restore g6, g7
711
712        ldd     [%fp + ISF_I0_OFFSET], %i0    ! restore i0, i1
713        ldd     [%fp + ISF_I2_OFFSET], %i2    ! restore i2, i3
714        ldd     [%fp + ISF_I4_OFFSET], %i4    ! restore i4, i5
715        ldd     [%fp + ISF_I6_FP_OFFSET], %i6 ! restore i6/fp, i7
716
717        /*
718         *  Registers:
719         *
720         *   ALL global registers EXCEPT G1 and the input registers have
721         *   already been restored and thuse off limits.
722         *
723         *   The following is the contents of the local registers:
724         *
725         *     l0 = original psr
726         *     l1 = return address (i.e. PC)
727         *     l2 = nPC
728         *     l3 = CWP
729         */
730
731        /*
732         *  if (CWP + 1) is an invalid window then we need to reload it.
733         *
734         *  WARNING: Traps should now be disabled
735         */
736
737        mov     %l0, %psr                  !  **** DISABLE TRAPS ****
738        nop
739        nop
740        nop
741        rd      %wim, %l4
742        add     %l0, 1, %l6                ! l6 = cwp + 1
743        and     %l6, SPARC_PSR_CWP_MASK, %l6 ! do the modulo on it
744        srl     %l4, %l6, %l5              ! l5 = win >> cwp + 1 ; shift count
745                                           !  and CWP are conveniently LS 5 bits
746        cmp     %l5, 1                     ! Is tasks window invalid?
747        bne     good_task_window
748
749        /*
750         *  The following code is the same as a 1 position left rotate of WIM.
751         */
752
753        sll     %l4, 1, %l5                ! l5 = WIM << 1
754        srl     %l4, SPARC_NUMBER_OF_REGISTER_WINDOWS-1 , %l4
755                                           ! l4 = WIM >> (Number Windows - 1)
756        or      %l4, %l5, %l4              ! l4 = (WIM << 1) |
757                                           !      (WIM >> (Number Windows - 1))
758
759        /*
760         *  Now restore the window just as if we underflowed to it.
761         */
762
763        wr      %l4, 0, %wim               ! WIM = new WIM
764        nop                                ! must delay after writing WIM
765        nop
766        nop
767        restore                            ! now into the tasks window
768
769        ldd     [%g1 + CPU_STACK_FRAME_L0_OFFSET], %l0
770        ldd     [%g1 + CPU_STACK_FRAME_L2_OFFSET], %l2
771        ldd     [%g1 + CPU_STACK_FRAME_L4_OFFSET], %l4
772        ldd     [%g1 + CPU_STACK_FRAME_L6_OFFSET], %l6
773        ldd     [%g1 + CPU_STACK_FRAME_I0_OFFSET], %i0
774        ldd     [%g1 + CPU_STACK_FRAME_I2_OFFSET], %i2
775        ldd     [%g1 + CPU_STACK_FRAME_I4_OFFSET], %i4
776        ldd     [%g1 + CPU_STACK_FRAME_I6_FP_OFFSET], %i6
777                                           ! reload of sp clobbers ISF
778        save                               ! Back to ISR dispatch window
779
780good_task_window:
781
782        mov     %l0, %psr                  !  **** DISABLE TRAPS ****
783        nop; nop; nop
784                                           !  and restore condition codes.
785        ld      [%g1 + ISF_G1_OFFSET], %g1 ! restore g1
786        jmp     %l1                        ! transfer control and
787        rett    %l2                        ! go back to tasks window
788
789/* end of file */
Note: See TracBrowser for help on using the repository browser.