sparc32: delete pgtsun4c.h
[firefly-linux-kernel-4.4.55.git] / arch / sparc / kernel / entry.S
1 /* arch/sparc/kernel/entry.S:  Sparc trap low-level entry points.
2  *
3  * Copyright (C) 1995, 2007 David S. Miller (davem@davemloft.net)
4  * Copyright (C) 1996 Eddie C. Dost   (ecd@skynet.be)
5  * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
6  * Copyright (C) 1996-1999 Jakub Jelinek   (jj@sunsite.mff.cuni.cz)
7  * Copyright (C) 1997 Anton Blanchard (anton@progsoc.uts.edu.au)
8  */
9
10 #include <linux/errno.h>
11
12 #include <asm/head.h>
13 #include <asm/asi.h>
14 #include <asm/smp.h>
15 #include <asm/contregs.h>
16 #include <asm/ptrace.h>
17 #include <asm/asm-offsets.h>
18 #include <asm/psr.h>
19 #include <asm/vaddrs.h>
20 #include <asm/page.h>
21 #include <asm/pgtable.h>
22 #include <asm/winmacro.h>
23 #include <asm/signal.h>
24 #include <asm/obio.h>
25 #include <asm/mxcc.h>
26 #include <asm/thread_info.h>
27 #include <asm/param.h>
28 #include <asm/unistd.h>
29
30 #include <asm/asmmacro.h>
31
32 #define curptr      g6
33
34 /* These are just handy. */
35 #define _SV     save    %sp, -STACKFRAME_SZ, %sp
36 #define _RS     restore 
37
38 #define FLUSH_ALL_KERNEL_WINDOWS \
39         _SV; _SV; _SV; _SV; _SV; _SV; _SV; \
40         _RS; _RS; _RS; _RS; _RS; _RS; _RS;
41
42         .text
43
44 #ifdef CONFIG_KGDB
45         .align  4
46         .globl          arch_kgdb_breakpoint
47         .type           arch_kgdb_breakpoint,#function
48 arch_kgdb_breakpoint:
49         ta              0x7d
50         retl
51          nop
52         .size           arch_kgdb_breakpoint,.-arch_kgdb_breakpoint
53 #endif
54
55 #if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
56         .align  4
57         .globl  floppy_hardint
58 floppy_hardint:
59         /*
60          * This code cannot touch registers %l0 %l1 and %l2
61          * because SAVE_ALL depends on their values. It depends
62          * on %l3 also, but we regenerate it before a call.
63          * Other registers are:
64          * %l3 -- base address of fdc registers
65          * %l4 -- pdma_vaddr
66          * %l5 -- scratch for ld/st address
67          * %l6 -- pdma_size
68          * %l7 -- scratch [floppy byte, ld/st address, aux. data]
69          */
70
71         /* Do we have work to do? */
72         sethi   %hi(doing_pdma), %l7
73         ld      [%l7 + %lo(doing_pdma)], %l7
74         cmp     %l7, 0
75         be      floppy_dosoftint
76          nop
77
78         /* Load fdc register base */
79         sethi   %hi(fdc_status), %l3
80         ld      [%l3 + %lo(fdc_status)], %l3
81
82         /* Setup register addresses */
83         sethi   %hi(pdma_vaddr), %l5    ! transfer buffer
84         ld      [%l5 + %lo(pdma_vaddr)], %l4
85         sethi   %hi(pdma_size), %l5     ! bytes to go
86         ld      [%l5 + %lo(pdma_size)], %l6
87 next_byte:
88         ldub    [%l3], %l7
89
90         andcc   %l7, 0x80, %g0          ! Does fifo still have data
91         bz      floppy_fifo_emptied     ! fifo has been emptied...
92          andcc  %l7, 0x20, %g0          ! in non-dma mode still?
93         bz      floppy_overrun          ! nope, overrun
94          andcc  %l7, 0x40, %g0          ! 0=write 1=read
95         bz      floppy_write
96          sub    %l6, 0x1, %l6
97
98         /* Ok, actually read this byte */
99         ldub    [%l3 + 1], %l7
100         orcc    %g0, %l6, %g0
101         stb     %l7, [%l4]
102         bne     next_byte
103          add    %l4, 0x1, %l4
104
105         b       floppy_tdone
106          nop
107
108 floppy_write:
109         /* Ok, actually write this byte */
110         ldub    [%l4], %l7
111         orcc    %g0, %l6, %g0
112         stb     %l7, [%l3 + 1]
113         bne     next_byte
114          add    %l4, 0x1, %l4
115
116         /* fall through... */
117 floppy_tdone:
118         sethi   %hi(pdma_vaddr), %l5
119         st      %l4, [%l5 + %lo(pdma_vaddr)]
120         sethi   %hi(pdma_size), %l5
121         st      %l6, [%l5 + %lo(pdma_size)]
122         /* Flip terminal count pin */
123         set     auxio_register, %l7
124         ld      [%l7], %l7
125
126         set     sparc_cpu_model, %l5
127         ld      [%l5], %l5
128         subcc   %l5, 1, %g0             /* enum { sun4c = 1 }; */
129         be      1f
130          ldub   [%l7], %l5
131
132         or      %l5, 0xc2, %l5
133         stb     %l5, [%l7]
134         andn    %l5, 0x02, %l5
135         b       2f
136          nop
137
138 1:
139         or      %l5, 0xf4, %l5
140         stb     %l5, [%l7]
141         andn    %l5, 0x04, %l5
142
143 2:
144         /* Kill some time so the bits set */
145         WRITE_PAUSE
146         WRITE_PAUSE
147
148         stb     %l5, [%l7]
149
150         /* Prevent recursion */
151         sethi   %hi(doing_pdma), %l7
152         b       floppy_dosoftint
153          st     %g0, [%l7 + %lo(doing_pdma)]
154
155         /* We emptied the FIFO, but we haven't read everything
156          * as of yet.  Store the current transfer address and
157          * bytes left to read so we can continue when the next
158          * fast IRQ comes in.
159          */
160 floppy_fifo_emptied:
161         sethi   %hi(pdma_vaddr), %l5
162         st      %l4, [%l5 + %lo(pdma_vaddr)]
163         sethi   %hi(pdma_size), %l7
164         st      %l6, [%l7 + %lo(pdma_size)]
165
166         /* Restore condition codes */
167         wr      %l0, 0x0, %psr
168         WRITE_PAUSE
169
170         jmp     %l1
171         rett    %l2
172
173 floppy_overrun:
174         sethi   %hi(pdma_vaddr), %l5
175         st      %l4, [%l5 + %lo(pdma_vaddr)]
176         sethi   %hi(pdma_size), %l5
177         st      %l6, [%l5 + %lo(pdma_size)]
178         /* Prevent recursion */
179         sethi   %hi(doing_pdma), %l7
180         st      %g0, [%l7 + %lo(doing_pdma)]
181
182         /* fall through... */
183 floppy_dosoftint:
184         rd      %wim, %l3
185         SAVE_ALL
186
187         /* Set all IRQs off. */
188         or      %l0, PSR_PIL, %l4
189         wr      %l4, 0x0, %psr
190         WRITE_PAUSE
191         wr      %l4, PSR_ET, %psr
192         WRITE_PAUSE
193
194         mov     11, %o0                 ! floppy irq level (unused anyway)
195         mov     %g0, %o1                ! devid is not used in fast interrupts
196         call    sparc_floppy_irq
197          add    %sp, STACKFRAME_SZ, %o2 ! struct pt_regs *regs
198
199         RESTORE_ALL
200         
201 #endif /* (CONFIG_BLK_DEV_FD) */
202
203         /* Bad trap handler */
204         .globl  bad_trap_handler
205 bad_trap_handler:
206         SAVE_ALL
207
208         wr      %l0, PSR_ET, %psr
209         WRITE_PAUSE
210
211         add     %sp, STACKFRAME_SZ, %o0 ! pt_regs
212         call    do_hw_interrupt
213          mov    %l7, %o1                ! trap number
214
215         RESTORE_ALL
216         
217 /* For now all IRQ's not registered get sent here. handler_irq() will
218  * see if a routine is registered to handle this interrupt and if not
219  * it will say so on the console.
220  */
221
222         .align  4
223         .globl  real_irq_entry, patch_handler_irq
224 real_irq_entry:
225         SAVE_ALL
226
227 #ifdef CONFIG_SMP
228         .globl  patchme_maybe_smp_msg
229
230         cmp     %l7, 11
231 patchme_maybe_smp_msg:
232         bgu     maybe_smp4m_msg
233          nop
234 #endif
235
236 real_irq_continue:
237         or      %l0, PSR_PIL, %g2
238         wr      %g2, 0x0, %psr
239         WRITE_PAUSE
240         wr      %g2, PSR_ET, %psr
241         WRITE_PAUSE
242         mov     %l7, %o0                ! irq level
243 patch_handler_irq:
244         call    handler_irq
245          add    %sp, STACKFRAME_SZ, %o1 ! pt_regs ptr
246         or      %l0, PSR_PIL, %g2       ! restore PIL after handler_irq
247         wr      %g2, PSR_ET, %psr       ! keep ET up
248         WRITE_PAUSE
249
250         RESTORE_ALL
251
252 #ifdef CONFIG_SMP
253         /* SMP per-cpu ticker interrupts are handled specially. */
254 smp4m_ticker:
255         bne     real_irq_continue+4
256          or     %l0, PSR_PIL, %g2
257         wr      %g2, 0x0, %psr
258         WRITE_PAUSE
259         wr      %g2, PSR_ET, %psr
260         WRITE_PAUSE
261         call    smp4m_percpu_timer_interrupt
262          add    %sp, STACKFRAME_SZ, %o0
263         wr      %l0, PSR_ET, %psr
264         WRITE_PAUSE
265         RESTORE_ALL
266
267         /* Here is where we check for possible SMP IPI passed to us
268          * on some level other than 15 which is the NMI and only used
269          * for cross calls.  That has a separate entry point below.
270          *
271          * IPIs are sent on Level 12, 13 and 14. See IRQ_IPI_*.
272          */
273 maybe_smp4m_msg:
274         GET_PROCESSOR4M_ID(o3)
275         sethi   %hi(sun4m_irq_percpu), %l5
276         sll     %o3, 2, %o3
277         or      %l5, %lo(sun4m_irq_percpu), %o5
278         sethi   %hi(0x70000000), %o2    ! Check all soft-IRQs
279         ld      [%o5 + %o3], %o1
280         ld      [%o1 + 0x00], %o3       ! sun4m_irq_percpu[cpu]->pending
281         andcc   %o3, %o2, %g0
282         be,a    smp4m_ticker
283          cmp    %l7, 14
284         /* Soft-IRQ IPI */
285         st      %o2, [%o1 + 0x04]       ! sun4m_irq_percpu[cpu]->clear=0x70000000
286         WRITE_PAUSE
287         ld      [%o1 + 0x00], %g0       ! sun4m_irq_percpu[cpu]->pending
288         WRITE_PAUSE
289         or      %l0, PSR_PIL, %l4
290         wr      %l4, 0x0, %psr
291         WRITE_PAUSE
292         wr      %l4, PSR_ET, %psr
293         WRITE_PAUSE
294         srl     %o3, 28, %o2            ! shift for simpler checks below
295 maybe_smp4m_msg_check_single:
296         andcc   %o2, 0x1, %g0
297         beq,a   maybe_smp4m_msg_check_mask
298          andcc  %o2, 0x2, %g0
299         call    smp_call_function_single_interrupt
300          nop
301         andcc   %o2, 0x2, %g0
302 maybe_smp4m_msg_check_mask:
303         beq,a   maybe_smp4m_msg_check_resched
304          andcc  %o2, 0x4, %g0
305         call    smp_call_function_interrupt
306          nop
307         andcc   %o2, 0x4, %g0
308 maybe_smp4m_msg_check_resched:
309         /* rescheduling is done in RESTORE_ALL regardless, but incr stats */
310         beq,a   maybe_smp4m_msg_out
311          nop
312         call    smp_resched_interrupt
313          nop
314 maybe_smp4m_msg_out:
315         RESTORE_ALL
316
317         .align  4
318         .globl  linux_trap_ipi15
319 linux_trap_ipi15:
320         SAVE_ALL
321         sethi   %hi(0x80000000), %o2
322         GET_PROCESSOR4M_ID(o0)
323         sethi   %hi(sun4m_irq_percpu), %l5
324         or      %l5, %lo(sun4m_irq_percpu), %o5
325         sll     %o0, 2, %o0
326         ld      [%o5 + %o0], %o5
327         ld      [%o5 + 0x00], %o3       ! sun4m_irq_percpu[cpu]->pending
328         andcc   %o3, %o2, %g0
329         be      1f                      ! Must be an NMI async memory error
330          st     %o2, [%o5 + 0x04]       ! sun4m_irq_percpu[cpu]->clear=0x80000000
331         WRITE_PAUSE
332         ld      [%o5 + 0x00], %g0       ! sun4m_irq_percpu[cpu]->pending
333         WRITE_PAUSE
334         or      %l0, PSR_PIL, %l4
335         wr      %l4, 0x0, %psr
336         WRITE_PAUSE
337         wr      %l4, PSR_ET, %psr
338         WRITE_PAUSE
339         call    smp4m_cross_call_irq
340          nop
341         b       ret_trap_lockless_ipi
342          clr    %l6
343 1:
344         /* NMI async memory error handling. */
345         sethi   %hi(0x80000000), %l4
346         sethi   %hi(sun4m_irq_global), %o5
347         ld      [%o5 + %lo(sun4m_irq_global)], %l5
348         st      %l4, [%l5 + 0x0c]       ! sun4m_irq_global->mask_set=0x80000000
349         WRITE_PAUSE
350         ld      [%l5 + 0x00], %g0       ! sun4m_irq_global->pending
351         WRITE_PAUSE
352         or      %l0, PSR_PIL, %l4
353         wr      %l4, 0x0, %psr
354         WRITE_PAUSE
355         wr      %l4, PSR_ET, %psr
356         WRITE_PAUSE
357         call    sun4m_nmi
358          nop
359         st      %l4, [%l5 + 0x08]       ! sun4m_irq_global->mask_clear=0x80000000
360         WRITE_PAUSE
361         ld      [%l5 + 0x00], %g0       ! sun4m_irq_global->pending
362         WRITE_PAUSE
363         RESTORE_ALL
364
365         .globl  smp4d_ticker
366         /* SMP per-cpu ticker interrupts are handled specially. */
367 smp4d_ticker:
368         SAVE_ALL
369         or      %l0, PSR_PIL, %g2
370         sethi   %hi(CC_ICLR), %o0
371         sethi   %hi(1 << 14), %o1
372         or      %o0, %lo(CC_ICLR), %o0
373         stha    %o1, [%o0] ASI_M_MXCC   /* Clear PIL 14 in MXCC's ICLR */
374         wr      %g2, 0x0, %psr
375         WRITE_PAUSE
376         wr      %g2, PSR_ET, %psr
377         WRITE_PAUSE
378         call    smp4d_percpu_timer_interrupt
379          add    %sp, STACKFRAME_SZ, %o0
380         wr      %l0, PSR_ET, %psr
381         WRITE_PAUSE
382         RESTORE_ALL
383
384         .align  4
385         .globl  linux_trap_ipi15_sun4d
386 linux_trap_ipi15_sun4d:
387         SAVE_ALL
388         sethi   %hi(CC_BASE), %o4
389         sethi   %hi(MXCC_ERR_ME|MXCC_ERR_PEW|MXCC_ERR_ASE|MXCC_ERR_PEE), %o2
390         or      %o4, (CC_EREG - CC_BASE), %o0
391         ldda    [%o0] ASI_M_MXCC, %o0
392         andcc   %o0, %o2, %g0
393         bne     1f
394          sethi  %hi(BB_STAT2), %o2
395         lduba   [%o2] ASI_M_CTL, %o2
396         andcc   %o2, BB_STAT2_MASK, %g0
397         bne     2f
398          or     %o4, (CC_ICLR - CC_BASE), %o0
399         sethi   %hi(1 << 15), %o1
400         stha    %o1, [%o0] ASI_M_MXCC   /* Clear PIL 15 in MXCC's ICLR */
401         or      %l0, PSR_PIL, %l4
402         wr      %l4, 0x0, %psr
403         WRITE_PAUSE
404         wr      %l4, PSR_ET, %psr
405         WRITE_PAUSE
406         call    smp4d_cross_call_irq
407          nop
408         b       ret_trap_lockless_ipi
409          clr    %l6
410
411 1:      /* MXCC error */
412 2:      /* BB error */
413         /* Disable PIL 15 */
414         set     CC_IMSK, %l4
415         lduha   [%l4] ASI_M_MXCC, %l5
416         sethi   %hi(1 << 15), %l7
417         or      %l5, %l7, %l5
418         stha    %l5, [%l4] ASI_M_MXCC
419         /* FIXME */
420 1:      b,a     1b
421
422 #ifdef CONFIG_SPARC_LEON
423         .globl  smpleon_ipi
424         .extern leon_ipi_interrupt
425         /* SMP per-cpu IPI interrupts are handled specially. */
426 smpleon_ipi:
427         SAVE_ALL
428         or      %l0, PSR_PIL, %g2
429         wr      %g2, 0x0, %psr
430         WRITE_PAUSE
431         wr      %g2, PSR_ET, %psr
432         WRITE_PAUSE
433         call    leonsmp_ipi_interrupt
434          add    %sp, STACKFRAME_SZ, %o1 ! pt_regs
435         wr      %l0, PSR_ET, %psr
436         WRITE_PAUSE
437         RESTORE_ALL
438
439         .align  4
440         .globl  linux_trap_ipi15_leon
441 linux_trap_ipi15_leon:
442         SAVE_ALL
443         or      %l0, PSR_PIL, %l4
444         wr      %l4, 0x0, %psr
445         WRITE_PAUSE
446         wr      %l4, PSR_ET, %psr
447         WRITE_PAUSE
448         call    leon_cross_call_irq
449          nop
450         b       ret_trap_lockless_ipi
451          clr    %l6
452
453 #endif /* CONFIG_SPARC_LEON */
454
455 #endif /* CONFIG_SMP */
456
457         /* This routine handles illegal instructions and privileged
458          * instruction attempts from user code.
459          */
460         .align  4
461         .globl  bad_instruction
462 bad_instruction:
463         sethi   %hi(0xc1f80000), %l4
464         ld      [%l1], %l5
465         sethi   %hi(0x81d80000), %l7
466         and     %l5, %l4, %l5
467         cmp     %l5, %l7
468         be      1f
469         SAVE_ALL
470
471         wr      %l0, PSR_ET, %psr               ! re-enable traps
472         WRITE_PAUSE
473
474         add     %sp, STACKFRAME_SZ, %o0
475         mov     %l1, %o1
476         mov     %l2, %o2
477         call    do_illegal_instruction
478          mov    %l0, %o3
479
480         RESTORE_ALL
481
482 1:      /* unimplemented flush - just skip */
483         jmpl    %l2, %g0
484          rett   %l2 + 4
485
486         .align  4
487         .globl  priv_instruction
488 priv_instruction:
489         SAVE_ALL
490
491         wr      %l0, PSR_ET, %psr
492         WRITE_PAUSE
493
494         add     %sp, STACKFRAME_SZ, %o0
495         mov     %l1, %o1
496         mov     %l2, %o2
497         call    do_priv_instruction
498          mov    %l0, %o3
499
500         RESTORE_ALL
501
502         /* This routine handles unaligned data accesses. */
503         .align  4
504         .globl  mna_handler
505 mna_handler:
506         andcc   %l0, PSR_PS, %g0
507         be      mna_fromuser
508          nop
509
510         SAVE_ALL
511
512         wr      %l0, PSR_ET, %psr
513         WRITE_PAUSE
514
515         ld      [%l1], %o1
516         call    kernel_unaligned_trap
517          add    %sp, STACKFRAME_SZ, %o0
518
519         RESTORE_ALL
520
521 mna_fromuser:
522         SAVE_ALL
523
524         wr      %l0, PSR_ET, %psr               ! re-enable traps
525         WRITE_PAUSE
526
527         ld      [%l1], %o1
528         call    user_unaligned_trap
529          add    %sp, STACKFRAME_SZ, %o0
530
531         RESTORE_ALL
532
533         /* This routine handles floating point disabled traps. */
534         .align  4
535         .globl  fpd_trap_handler
536 fpd_trap_handler:
537         SAVE_ALL
538
539         wr      %l0, PSR_ET, %psr               ! re-enable traps
540         WRITE_PAUSE
541
542         add     %sp, STACKFRAME_SZ, %o0
543         mov     %l1, %o1
544         mov     %l2, %o2
545         call    do_fpd_trap
546          mov    %l0, %o3
547
548         RESTORE_ALL
549
550         /* This routine handles Floating Point Exceptions. */
551         .align  4
552         .globl  fpe_trap_handler
553 fpe_trap_handler:
554         set     fpsave_magic, %l5
555         cmp     %l1, %l5
556         be      1f
557          sethi  %hi(fpsave), %l5
558         or      %l5, %lo(fpsave), %l5
559         cmp     %l1, %l5
560         bne     2f
561          sethi  %hi(fpsave_catch2), %l5
562         or      %l5, %lo(fpsave_catch2), %l5
563         wr      %l0, 0x0, %psr
564         WRITE_PAUSE
565         jmp     %l5
566          rett   %l5 + 4
567 1:      
568         sethi   %hi(fpsave_catch), %l5
569         or      %l5, %lo(fpsave_catch), %l5
570         wr      %l0, 0x0, %psr
571         WRITE_PAUSE
572         jmp     %l5
573          rett   %l5 + 4
574
575 2:
576         SAVE_ALL
577
578         wr      %l0, PSR_ET, %psr               ! re-enable traps
579         WRITE_PAUSE
580
581         add     %sp, STACKFRAME_SZ, %o0
582         mov     %l1, %o1
583         mov     %l2, %o2
584         call    do_fpe_trap
585          mov    %l0, %o3
586
587         RESTORE_ALL
588
589         /* This routine handles Tag Overflow Exceptions. */
590         .align  4
591         .globl  do_tag_overflow
592 do_tag_overflow:
593         SAVE_ALL
594
595         wr      %l0, PSR_ET, %psr               ! re-enable traps
596         WRITE_PAUSE
597
598         add     %sp, STACKFRAME_SZ, %o0
599         mov     %l1, %o1
600         mov     %l2, %o2
601         call    handle_tag_overflow
602          mov    %l0, %o3
603
604         RESTORE_ALL
605
606         /* This routine handles Watchpoint Exceptions. */
607         .align  4
608         .globl  do_watchpoint
609 do_watchpoint:
610         SAVE_ALL
611
612         wr      %l0, PSR_ET, %psr               ! re-enable traps
613         WRITE_PAUSE
614
615         add     %sp, STACKFRAME_SZ, %o0
616         mov     %l1, %o1
617         mov     %l2, %o2
618         call    handle_watchpoint
619          mov    %l0, %o3
620
621         RESTORE_ALL
622
623         /* This routine handles Register Access Exceptions. */
624         .align  4
625         .globl  do_reg_access
626 do_reg_access:
627         SAVE_ALL
628
629         wr      %l0, PSR_ET, %psr               ! re-enable traps
630         WRITE_PAUSE
631
632         add     %sp, STACKFRAME_SZ, %o0
633         mov     %l1, %o1
634         mov     %l2, %o2
635         call    handle_reg_access
636          mov    %l0, %o3
637
638         RESTORE_ALL
639
640         /* This routine handles Co-Processor Disabled Exceptions. */
641         .align  4
642         .globl  do_cp_disabled
643 do_cp_disabled:
644         SAVE_ALL
645
646         wr      %l0, PSR_ET, %psr               ! re-enable traps
647         WRITE_PAUSE
648
649         add     %sp, STACKFRAME_SZ, %o0
650         mov     %l1, %o1
651         mov     %l2, %o2
652         call    handle_cp_disabled
653          mov    %l0, %o3
654
655         RESTORE_ALL
656
657         /* This routine handles Co-Processor Exceptions. */
658         .align  4
659         .globl  do_cp_exception
660 do_cp_exception:
661         SAVE_ALL
662
663         wr      %l0, PSR_ET, %psr               ! re-enable traps
664         WRITE_PAUSE
665
666         add     %sp, STACKFRAME_SZ, %o0
667         mov     %l1, %o1
668         mov     %l2, %o2
669         call    handle_cp_exception
670          mov    %l0, %o3
671
672         RESTORE_ALL
673
674         /* This routine handles Hardware Divide By Zero Exceptions. */
675         .align  4
676         .globl  do_hw_divzero
677 do_hw_divzero:
678         SAVE_ALL
679
680         wr      %l0, PSR_ET, %psr               ! re-enable traps
681         WRITE_PAUSE
682
683         add     %sp, STACKFRAME_SZ, %o0
684         mov     %l1, %o1
685         mov     %l2, %o2
686         call    handle_hw_divzero
687          mov    %l0, %o3
688
689         RESTORE_ALL
690
691         .align  4
692         .globl  do_flush_windows
693 do_flush_windows:
694         SAVE_ALL
695
696         wr      %l0, PSR_ET, %psr
697         WRITE_PAUSE
698
699         andcc   %l0, PSR_PS, %g0
700         bne     dfw_kernel
701          nop
702
703         call    flush_user_windows
704          nop
705
706         /* Advance over the trap instruction. */
707         ld      [%sp + STACKFRAME_SZ + PT_NPC], %l1
708         add     %l1, 0x4, %l2
709         st      %l1, [%sp + STACKFRAME_SZ + PT_PC]
710         st      %l2, [%sp + STACKFRAME_SZ + PT_NPC]
711
712         RESTORE_ALL
713
714         .globl  flush_patch_one
715
716         /* We get these for debugging routines using __builtin_return_address() */
717 dfw_kernel:
718 flush_patch_one:
719         FLUSH_ALL_KERNEL_WINDOWS
720
721         /* Advance over the trap instruction. */
722         ld      [%sp + STACKFRAME_SZ + PT_NPC], %l1
723         add     %l1, 0x4, %l2
724         st      %l1, [%sp + STACKFRAME_SZ + PT_PC]
725         st      %l2, [%sp + STACKFRAME_SZ + PT_NPC]
726
727         RESTORE_ALL
728
729         /* The getcc software trap.  The user wants the condition codes from
730          * the %psr in register %g1.
731          */
732
733         .align  4
734         .globl  getcc_trap_handler
735 getcc_trap_handler:
736         srl     %l0, 20, %g1    ! give user
737         and     %g1, 0xf, %g1   ! only ICC bits in %psr
738         jmp     %l2             ! advance over trap instruction
739         rett    %l2 + 0x4       ! like this...
740
741         /* The setcc software trap.  The user has condition codes in %g1
742          * that it would like placed in the %psr.  Be careful not to flip
743          * any unintentional bits!
744          */
745
746         .align  4
747         .globl  setcc_trap_handler
748 setcc_trap_handler:
749         sll     %g1, 0x14, %l4
750         set     PSR_ICC, %l5
751         andn    %l0, %l5, %l0   ! clear ICC bits in %psr
752         and     %l4, %l5, %l4   ! clear non-ICC bits in user value
753         or      %l4, %l0, %l4   ! or them in... mix mix mix
754
755         wr      %l4, 0x0, %psr  ! set new %psr
756         WRITE_PAUSE             ! TI scumbags...
757
758         jmp     %l2             ! advance over trap instruction
759         rett    %l2 + 0x4       ! like this...
760
761 #ifndef CONFIG_SMP
762         .align  4
763         .globl  linux_trap_ipi15
764 linux_trap_ipi15:
765         SAVE_ALL
766
767         /* Now it is safe to re-enable traps without recursion. */
768         or      %l0, PSR_PIL, %l0
769         wr      %l0, PSR_ET, %psr
770         WRITE_PAUSE
771
772         /* Now call the c-code with the pt_regs frame ptr and the
773          * memory error registers as arguments.  The ordering chosen
774          * here is due to unlatching semantics.
775          */
776         sethi   %hi(AC_SYNC_ERR), %o0
777         add     %o0, 0x4, %o0
778         lda     [%o0] ASI_CONTROL, %o2  ! sync vaddr
779         sub     %o0, 0x4, %o0
780         lda     [%o0] ASI_CONTROL, %o1  ! sync error
781         add     %o0, 0xc, %o0
782         lda     [%o0] ASI_CONTROL, %o4  ! async vaddr
783         sub     %o0, 0x4, %o0
784         lda     [%o0] ASI_CONTROL, %o3  ! async error
785         call    sparc_lvl15_nmi
786          add    %sp, STACKFRAME_SZ, %o0
787
788         RESTORE_ALL
789
790 #endif /* CONFIG_SMP */
791
792         .align  4
793         .globl  invalid_segment_patch1_ff
794         .globl  invalid_segment_patch2_ff
795 invalid_segment_patch1_ff:      cmp     %l4, 0xff
796 invalid_segment_patch2_ff:      mov     0xff, %l3
797
798         .align  4
799         .globl  invalid_segment_patch1_1ff
800         .globl  invalid_segment_patch2_1ff
801 invalid_segment_patch1_1ff:     cmp     %l4, 0x1ff
802 invalid_segment_patch2_1ff:     mov     0x1ff, %l3
803
804         .align  4
805         .globl  num_context_patch1_16, num_context_patch2_16
806 num_context_patch1_16:          mov     0x10, %l7
807 num_context_patch2_16:          mov     0x10, %l7
808
809         .align  4
810         .globl  vac_linesize_patch_32
811 vac_linesize_patch_32:          subcc   %l7, 32, %l7
812
813         .align  4
814         .globl  vac_hwflush_patch1_on, vac_hwflush_patch2_on
815
816 /*
817  * Ugly, but we can't use hardware flushing on the sun4 and we'd require
818  * two instructions (Anton)
819  */
820 vac_hwflush_patch1_on:          addcc   %l7, -PAGE_SIZE, %l7
821
822 vac_hwflush_patch2_on:          sta     %g0, [%l3 + %l7] ASI_HWFLUSHSEG
823
824         .globl  invalid_segment_patch1, invalid_segment_patch2
825         .globl  num_context_patch1
826         .globl  vac_linesize_patch, vac_hwflush_patch1
827         .globl  vac_hwflush_patch2
828
829         .align  4
830         .globl  srmmu_fault
831 srmmu_fault:
832         mov     0x400, %l5
833         mov     0x300, %l4
834
835         lda     [%l5] ASI_M_MMUREGS, %l6        ! read sfar first
836         lda     [%l4] ASI_M_MMUREGS, %l5        ! read sfsr last
837
838         andn    %l6, 0xfff, %l6
839         srl     %l5, 6, %l5                     ! and encode all info into l7
840
841         and     %l5, 2, %l5
842         or      %l5, %l6, %l6
843
844         or      %l6, %l7, %l7                   ! l7 = [addr,write,txtfault]
845
846         SAVE_ALL
847
848         mov     %l7, %o1
849         mov     %l7, %o2
850         and     %o1, 1, %o1             ! arg2 = text_faultp
851         mov     %l7, %o3
852         and     %o2, 2, %o2             ! arg3 = writep
853         andn    %o3, 0xfff, %o3         ! arg4 = faulting address
854
855         wr      %l0, PSR_ET, %psr
856         WRITE_PAUSE
857
858         call    do_sparc_fault
859          add    %sp, STACKFRAME_SZ, %o0 ! arg1 = pt_regs ptr
860
861         RESTORE_ALL
862
863         .align  4
864         .globl  sys_nis_syscall
865 sys_nis_syscall:
866         mov     %o7, %l5
867         add     %sp, STACKFRAME_SZ, %o0         ! pt_regs *regs arg
868         call    c_sys_nis_syscall
869          mov    %l5, %o7
870
871         .align  4
872         .globl  sys_execve
873 sys_execve:
874         mov     %o7, %l5
875         add     %sp, STACKFRAME_SZ, %o0         ! pt_regs *regs arg
876         call    sparc_execve
877          mov    %l5, %o7
878
879         .globl  sunos_execv
880 sunos_execv:
881         st      %g0, [%sp + STACKFRAME_SZ + PT_I2]
882
883         call    sparc_execve
884          add    %sp, STACKFRAME_SZ, %o0
885
886         b       ret_sys_call
887          ld     [%sp + STACKFRAME_SZ + PT_I0], %o0
888
889         .align  4
890         .globl  sys_sparc_pipe
891 sys_sparc_pipe:
892         mov     %o7, %l5
893         add     %sp, STACKFRAME_SZ, %o0         ! pt_regs *regs arg
894         call    sparc_pipe
895          mov    %l5, %o7
896
897         .align  4
898         .globl  sys_sigaltstack
899 sys_sigaltstack:
900         mov     %o7, %l5
901         mov     %fp, %o2
902         call    do_sigaltstack
903          mov    %l5, %o7
904
905         .align  4
906         .globl  sys_sigstack
907 sys_sigstack:
908         mov     %o7, %l5
909         mov     %fp, %o2
910         call    do_sys_sigstack
911          mov    %l5, %o7
912
913         .align  4
914         .globl  sys_sigreturn
915 sys_sigreturn:
916         call    do_sigreturn
917          add    %sp, STACKFRAME_SZ, %o0
918
919         ld      [%curptr + TI_FLAGS], %l5
920         andcc   %l5, _TIF_SYSCALL_TRACE, %g0
921         be      1f
922          nop
923
924         call    syscall_trace
925          nop
926
927 1:
928         /* We don't want to muck with user registers like a
929          * normal syscall, just return.
930          */
931         RESTORE_ALL
932
933         .align  4
934         .globl  sys_rt_sigreturn
935 sys_rt_sigreturn:
936         call    do_rt_sigreturn
937          add    %sp, STACKFRAME_SZ, %o0
938
939         ld      [%curptr + TI_FLAGS], %l5
940         andcc   %l5, _TIF_SYSCALL_TRACE, %g0
941         be      1f
942          nop
943
944         add     %sp, STACKFRAME_SZ, %o0
945         call    syscall_trace
946          mov    1, %o1
947
948 1:
949         /* We are returning to a signal handler. */
950         RESTORE_ALL
951
952         /* Now that we have a real sys_clone, sys_fork() is
953          * implemented in terms of it.  Our _real_ implementation
954          * of SunOS vfork() will use sys_vfork().
955          *
956          * XXX These three should be consolidated into mostly shared
957          * XXX code just like on sparc64... -DaveM
958          */
959         .align  4
960         .globl  sys_fork, flush_patch_two
961 sys_fork:
962         mov     %o7, %l5
963 flush_patch_two:
964         FLUSH_ALL_KERNEL_WINDOWS;
965         ld      [%curptr + TI_TASK], %o4
966         rd      %psr, %g4
967         WRITE_PAUSE
968         mov     SIGCHLD, %o0                    ! arg0: clone flags
969         rd      %wim, %g5
970         WRITE_PAUSE
971         mov     %fp, %o1                        ! arg1: usp
972         std     %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
973         add     %sp, STACKFRAME_SZ, %o2         ! arg2: pt_regs ptr
974         mov     0, %o3
975         call    sparc_do_fork
976          mov    %l5, %o7
977
978         /* Whee, kernel threads! */
979         .globl  sys_clone, flush_patch_three
980 sys_clone:
981         mov     %o7, %l5
982 flush_patch_three:
983         FLUSH_ALL_KERNEL_WINDOWS;
984         ld      [%curptr + TI_TASK], %o4
985         rd      %psr, %g4
986         WRITE_PAUSE
987
988         /* arg0,1: flags,usp  -- loaded already */
989         cmp     %o1, 0x0                        ! Is new_usp NULL?
990         rd      %wim, %g5
991         WRITE_PAUSE
992         be,a    1f
993          mov    %fp, %o1                        ! yes, use callers usp
994         andn    %o1, 7, %o1                     ! no, align to 8 bytes
995 1:
996         std     %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
997         add     %sp, STACKFRAME_SZ, %o2         ! arg2: pt_regs ptr
998         mov     0, %o3
999         call    sparc_do_fork
1000          mov    %l5, %o7
1001
1002         /* Whee, real vfork! */
1003         .globl  sys_vfork, flush_patch_four
1004 sys_vfork:
1005 flush_patch_four:
1006         FLUSH_ALL_KERNEL_WINDOWS;
1007         ld      [%curptr + TI_TASK], %o4
1008         rd      %psr, %g4
1009         WRITE_PAUSE
1010         rd      %wim, %g5
1011         WRITE_PAUSE
1012         std     %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1013         sethi   %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1014         mov     %fp, %o1
1015         or      %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1016         sethi   %hi(sparc_do_fork), %l1
1017         mov     0, %o3
1018         jmpl    %l1 + %lo(sparc_do_fork), %g0
1019          add    %sp, STACKFRAME_SZ, %o2
1020
1021         .align  4
1022 linux_sparc_ni_syscall:
1023         sethi   %hi(sys_ni_syscall), %l7
1024         b       syscall_is_too_hard
1025          or     %l7, %lo(sys_ni_syscall), %l7
1026
1027 linux_fast_syscall:
1028         andn    %l7, 3, %l7
1029         mov     %i0, %o0
1030         mov     %i1, %o1
1031         mov     %i2, %o2
1032         jmpl    %l7 + %g0, %g0
1033          mov    %i3, %o3
1034
1035 linux_syscall_trace:
1036         add     %sp, STACKFRAME_SZ, %o0
1037         call    syscall_trace
1038          mov    0, %o1
1039         cmp     %o0, 0
1040         bne     3f
1041          mov    -ENOSYS, %o0
1042         mov     %i0, %o0
1043         mov     %i1, %o1
1044         mov     %i2, %o2
1045         mov     %i3, %o3
1046         b       2f
1047          mov    %i4, %o4
1048
1049         .globl  ret_from_fork
1050 ret_from_fork:
1051         call    schedule_tail
1052          ld     [%g3 + TI_TASK], %o0
1053         b       ret_sys_call
1054          ld     [%sp + STACKFRAME_SZ + PT_I0], %o0
1055
1056         /* Linux native system calls enter here... */
1057         .align  4
1058         .globl  linux_sparc_syscall
1059 linux_sparc_syscall:
1060         sethi   %hi(PSR_SYSCALL), %l4
1061         or      %l0, %l4, %l0
1062         /* Direct access to user regs, must faster. */
1063         cmp     %g1, NR_syscalls
1064         bgeu    linux_sparc_ni_syscall
1065          sll    %g1, 2, %l4
1066         ld      [%l7 + %l4], %l7
1067         andcc   %l7, 1, %g0
1068         bne     linux_fast_syscall
1069          /* Just do first insn from SAVE_ALL in the delay slot */
1070
1071 syscall_is_too_hard:
1072         SAVE_ALL_HEAD
1073          rd     %wim, %l3
1074
1075         wr      %l0, PSR_ET, %psr
1076         mov     %i0, %o0
1077         mov     %i1, %o1
1078         mov     %i2, %o2
1079
1080         ld      [%curptr + TI_FLAGS], %l5
1081         mov     %i3, %o3
1082         andcc   %l5, _TIF_SYSCALL_TRACE, %g0
1083         mov     %i4, %o4
1084         bne     linux_syscall_trace
1085          mov    %i0, %l5
1086 2:
1087         call    %l7
1088          mov    %i5, %o5
1089
1090 3:
1091         st      %o0, [%sp + STACKFRAME_SZ + PT_I0]
1092
1093 ret_sys_call:
1094         ld      [%curptr + TI_FLAGS], %l6
1095         cmp     %o0, -ERESTART_RESTARTBLOCK
1096         ld      [%sp + STACKFRAME_SZ + PT_PSR], %g3
1097         set     PSR_C, %g2
1098         bgeu    1f
1099          andcc  %l6, _TIF_SYSCALL_TRACE, %g0
1100
1101         /* System call success, clear Carry condition code. */
1102         andn    %g3, %g2, %g3
1103         clr     %l6
1104         st      %g3, [%sp + STACKFRAME_SZ + PT_PSR]     
1105         bne     linux_syscall_trace2
1106          ld     [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1107         add     %l1, 0x4, %l2                   /* npc = npc+4 */
1108         st      %l1, [%sp + STACKFRAME_SZ + PT_PC]
1109         b       ret_trap_entry
1110          st     %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1111 1:
1112         /* System call failure, set Carry condition code.
1113          * Also, get abs(errno) to return to the process.
1114          */
1115         sub     %g0, %o0, %o0
1116         or      %g3, %g2, %g3
1117         st      %o0, [%sp + STACKFRAME_SZ + PT_I0]
1118         mov     1, %l6
1119         st      %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1120         bne     linux_syscall_trace2
1121          ld     [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1122         add     %l1, 0x4, %l2                   /* npc = npc+4 */
1123         st      %l1, [%sp + STACKFRAME_SZ + PT_PC]
1124         b       ret_trap_entry
1125          st     %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1126
1127 linux_syscall_trace2:
1128         add     %sp, STACKFRAME_SZ, %o0
1129         mov     1, %o1
1130         call    syscall_trace
1131          add    %l1, 0x4, %l2                   /* npc = npc+4 */
1132         st      %l1, [%sp + STACKFRAME_SZ + PT_PC]
1133         b       ret_trap_entry
1134          st     %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1135
1136
1137 /* Saving and restoring the FPU state is best done from lowlevel code.
1138  *
1139  * void fpsave(unsigned long *fpregs, unsigned long *fsr,
1140  *             void *fpqueue, unsigned long *fpqdepth)
1141  */
1142
1143         .globl  fpsave
1144 fpsave:
1145         st      %fsr, [%o1]     ! this can trap on us if fpu is in bogon state
1146         ld      [%o1], %g1
1147         set     0x2000, %g4
1148         andcc   %g1, %g4, %g0
1149         be      2f
1150          mov    0, %g2
1151
1152         /* We have an fpqueue to save. */
1153 1:
1154         std     %fq, [%o2]
1155 fpsave_magic:
1156         st      %fsr, [%o1]
1157         ld      [%o1], %g3
1158         andcc   %g3, %g4, %g0
1159         add     %g2, 1, %g2
1160         bne     1b
1161          add    %o2, 8, %o2
1162
1163 2:
1164         st      %g2, [%o3]
1165
1166         std     %f0, [%o0 + 0x00]
1167         std     %f2, [%o0 + 0x08]
1168         std     %f4, [%o0 + 0x10]
1169         std     %f6, [%o0 + 0x18]
1170         std     %f8, [%o0 + 0x20]
1171         std     %f10, [%o0 + 0x28]
1172         std     %f12, [%o0 + 0x30]
1173         std     %f14, [%o0 + 0x38]
1174         std     %f16, [%o0 + 0x40]
1175         std     %f18, [%o0 + 0x48]
1176         std     %f20, [%o0 + 0x50]
1177         std     %f22, [%o0 + 0x58]
1178         std     %f24, [%o0 + 0x60]
1179         std     %f26, [%o0 + 0x68]
1180         std     %f28, [%o0 + 0x70]
1181         retl
1182          std    %f30, [%o0 + 0x78]
1183
1184         /* Thanks for Theo Deraadt and the authors of the Sprite/netbsd/openbsd
1185          * code for pointing out this possible deadlock, while we save state
1186          * above we could trap on the fsr store so our low level fpu trap
1187          * code has to know how to deal with this.
1188          */
1189 fpsave_catch:
1190         b       fpsave_magic + 4
1191          st     %fsr, [%o1]
1192
1193 fpsave_catch2:
1194         b       fpsave + 4
1195          st     %fsr, [%o1]
1196
1197         /* void fpload(unsigned long *fpregs, unsigned long *fsr); */
1198
1199         .globl  fpload
1200 fpload:
1201         ldd     [%o0 + 0x00], %f0
1202         ldd     [%o0 + 0x08], %f2
1203         ldd     [%o0 + 0x10], %f4
1204         ldd     [%o0 + 0x18], %f6
1205         ldd     [%o0 + 0x20], %f8
1206         ldd     [%o0 + 0x28], %f10
1207         ldd     [%o0 + 0x30], %f12
1208         ldd     [%o0 + 0x38], %f14
1209         ldd     [%o0 + 0x40], %f16
1210         ldd     [%o0 + 0x48], %f18
1211         ldd     [%o0 + 0x50], %f20
1212         ldd     [%o0 + 0x58], %f22
1213         ldd     [%o0 + 0x60], %f24
1214         ldd     [%o0 + 0x68], %f26
1215         ldd     [%o0 + 0x70], %f28
1216         ldd     [%o0 + 0x78], %f30
1217         ld      [%o1], %fsr
1218         retl
1219          nop
1220
1221         /* __ndelay and __udelay take two arguments:
1222          * 0 - nsecs or usecs to delay
1223          * 1 - per_cpu udelay_val (loops per jiffy)
1224          *
1225          * Note that ndelay gives HZ times higher resolution but has a 10ms
1226          * limit.  udelay can handle up to 1s.
1227          */
1228         .globl  __ndelay
1229 __ndelay:
1230         save    %sp, -STACKFRAME_SZ, %sp
1231         mov     %i0, %o0
1232         call    .umul                   ! round multiplier up so large ns ok
1233          mov    0x1ae, %o1              ! 2**32 / (1 000 000 000 / HZ)
1234         call    .umul
1235          mov    %i1, %o1                ! udelay_val
1236         ba      delay_continue
1237          mov    %o1, %o0                ! >>32 later for better resolution
1238
1239         .globl  __udelay
1240 __udelay:
1241         save    %sp, -STACKFRAME_SZ, %sp
1242         mov     %i0, %o0
1243         sethi   %hi(0x10c7), %o1        ! round multiplier up so large us ok
1244         call    .umul
1245          or     %o1, %lo(0x10c7), %o1   ! 2**32 / 1 000 000
1246         call    .umul
1247          mov    %i1, %o1                ! udelay_val
1248         sethi   %hi(0x028f4b62), %l0    ! Add in rounding constant * 2**32,
1249         or      %g0, %lo(0x028f4b62), %l0
1250         addcc   %o0, %l0, %o0           ! 2**32 * 0.009 999
1251         bcs,a   3f
1252          add    %o1, 0x01, %o1
1253 3:
1254         call    .umul
1255          mov    HZ, %o0                 ! >>32 earlier for wider range
1256
1257 delay_continue:
1258         cmp     %o0, 0x0
1259 1:
1260         bne     1b
1261          subcc  %o0, 1, %o0
1262         
1263         ret
1264         restore
1265
1266         /* Handle a software breakpoint */
1267         /* We have to inform parent that child has stopped */
1268         .align 4
1269         .globl breakpoint_trap
1270 breakpoint_trap:
1271         rd      %wim,%l3
1272         SAVE_ALL
1273         wr      %l0, PSR_ET, %psr
1274         WRITE_PAUSE
1275
1276         st      %i0, [%sp + STACKFRAME_SZ + PT_G0] ! for restarting syscalls
1277         call    sparc_breakpoint
1278          add    %sp, STACKFRAME_SZ, %o0
1279
1280         RESTORE_ALL
1281
1282 #ifdef CONFIG_KGDB
1283         .align  4
1284         .globl  kgdb_trap_low
1285         .type   kgdb_trap_low,#function
1286 kgdb_trap_low:
1287         rd      %wim,%l3
1288         SAVE_ALL
1289         wr      %l0, PSR_ET, %psr
1290         WRITE_PAUSE
1291
1292         call    kgdb_trap
1293          add    %sp, STACKFRAME_SZ, %o0
1294
1295         RESTORE_ALL
1296         .size   kgdb_trap_low,.-kgdb_trap_low
1297 #endif
1298
1299         .align  4
1300         .globl  flush_patch_exception
1301 flush_patch_exception:
1302         FLUSH_ALL_KERNEL_WINDOWS;
1303         ldd     [%o0], %o6
1304         jmpl    %o7 + 0xc, %g0                  ! see asm-sparc/processor.h
1305          mov    1, %g1                          ! signal EFAULT condition
1306
1307         .align  4
1308         .globl  kill_user_windows, kuw_patch1_7win
1309         .globl  kuw_patch1
1310 kuw_patch1_7win:        sll     %o3, 6, %o3
1311
1312         /* No matter how much overhead this routine has in the worst
1313          * case scenerio, it is several times better than taking the
1314          * traps with the old method of just doing flush_user_windows().
1315          */
1316 kill_user_windows:
1317         ld      [%g6 + TI_UWINMASK], %o0        ! get current umask
1318         orcc    %g0, %o0, %g0                   ! if no bits set, we are done
1319         be      3f                              ! nothing to do
1320          rd     %psr, %o5                       ! must clear interrupts
1321         or      %o5, PSR_PIL, %o4               ! or else that could change
1322         wr      %o4, 0x0, %psr                  ! the uwinmask state
1323         WRITE_PAUSE                             ! burn them cycles
1324 1:
1325         ld      [%g6 + TI_UWINMASK], %o0        ! get consistent state
1326         orcc    %g0, %o0, %g0                   ! did an interrupt come in?
1327         be      4f                              ! yep, we are done
1328          rd     %wim, %o3                       ! get current wim
1329         srl     %o3, 1, %o4                     ! simulate a save
1330 kuw_patch1:
1331         sll     %o3, 7, %o3                     ! compute next wim
1332         or      %o4, %o3, %o3                   ! result
1333         andncc  %o0, %o3, %o0                   ! clean this bit in umask
1334         bne     kuw_patch1                      ! not done yet
1335          srl    %o3, 1, %o4                     ! begin another save simulation
1336         wr      %o3, 0x0, %wim                  ! set the new wim
1337         st      %g0, [%g6 + TI_UWINMASK]        ! clear uwinmask
1338 4:
1339         wr      %o5, 0x0, %psr                  ! re-enable interrupts
1340         WRITE_PAUSE                             ! burn baby burn
1341 3:
1342         retl                                    ! return
1343          st     %g0, [%g6 + TI_W_SAVED]         ! no windows saved
1344
1345         .align  4
1346         .globl  restore_current
1347 restore_current:
1348         LOAD_CURRENT(g6, o0)
1349         retl
1350          nop
1351
1352 #ifdef CONFIG_PCIC_PCI
1353 #include <asm/pcic.h>
1354
1355         .align  4
1356         .globl  linux_trap_ipi15_pcic
1357 linux_trap_ipi15_pcic:
1358         rd      %wim, %l3
1359         SAVE_ALL
1360
1361         /*
1362          * First deactivate NMI
1363          * or we cannot drop ET, cannot get window spill traps.
1364          * The busy loop is necessary because the PIO error
1365          * sometimes does not go away quickly and we trap again.
1366          */
1367         sethi   %hi(pcic_regs), %o1
1368         ld      [%o1 + %lo(pcic_regs)], %o2
1369
1370         ! Get pending status for printouts later.
1371         ld      [%o2 + PCI_SYS_INT_PENDING], %o0
1372
1373         mov     PCI_SYS_INT_PENDING_CLEAR_ALL, %o1
1374         stb     %o1, [%o2 + PCI_SYS_INT_PENDING_CLEAR]
1375 1:
1376         ld      [%o2 + PCI_SYS_INT_PENDING], %o1
1377         andcc   %o1, ((PCI_SYS_INT_PENDING_PIO|PCI_SYS_INT_PENDING_PCI)>>24), %g0
1378         bne     1b
1379          nop
1380
1381         or      %l0, PSR_PIL, %l4
1382         wr      %l4, 0x0, %psr
1383         WRITE_PAUSE
1384         wr      %l4, PSR_ET, %psr
1385         WRITE_PAUSE
1386
1387         call    pcic_nmi
1388          add    %sp, STACKFRAME_SZ, %o1 ! struct pt_regs *regs
1389         RESTORE_ALL
1390
1391         .globl  pcic_nmi_trap_patch
1392 pcic_nmi_trap_patch:
1393         sethi   %hi(linux_trap_ipi15_pcic), %l3
1394         jmpl    %l3 + %lo(linux_trap_ipi15_pcic), %g0
1395          rd     %psr, %l0
1396         .word   0
1397
1398 #endif /* CONFIG_PCIC_PCI */
1399
1400         .globl  flushw_all
1401 flushw_all:
1402         save    %sp, -0x40, %sp
1403         save    %sp, -0x40, %sp
1404         save    %sp, -0x40, %sp
1405         save    %sp, -0x40, %sp
1406         save    %sp, -0x40, %sp
1407         save    %sp, -0x40, %sp
1408         save    %sp, -0x40, %sp
1409         restore
1410         restore
1411         restore
1412         restore
1413         restore
1414         restore
1415         ret
1416          restore
1417
1418 /* End of entry.S */