1 /* $Id: entry.S,v 1.144 2002/02/09 19:49:30 davem Exp $
2 * arch/sparc64/kernel/entry.S: Sparc64 trap low-level entry points.
4 * Copyright (C) 1995,1997 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
6 * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
7 * Copyright (C) 1996,98,99 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
10 #include <linux/config.h>
11 #include <linux/errno.h>
16 #include <asm/ptrace.h>
18 #include <asm/signal.h>
19 #include <asm/pgtable.h>
20 #include <asm/processor.h>
21 #include <asm/visasm.h>
22 #include <asm/estate.h>
23 #include <asm/auxio.h>
24 #include <asm/sfafsr.h>
28 #define NR_SYSCALLS 300 /* Each OS is different... */
33 /* This is trivial with the new code... */
36 sethi %hi(TSTATE_PEF), %g4
42 andcc %g5, FPRS_FEF, %g0
46 /* Legal state when DCR_IFPOE is set in Cheetah %dcr. */
49 109: or %g7, %lo(109b), %g7
51 ba,a,pt %xcc, rtrap_clr_l6
53 1: TRAP_LOAD_THREAD_REG(%g6, %g1)
54 ldub [%g6 + TI_FPSAVED], %g5
55 wr %g0, FPRS_FEF, %fprs
56 andcc %g5, FPRS_FEF, %g0
59 ldx [%g6 + TI_GSR], %g7
60 1: andcc %g5, FPRS_DL, %g0
63 andcc %g5, FPRS_DU, %g0
94 b,pt %xcc, fpdis_exit2
96 1: mov SECONDARY_CONTEXT, %g3
97 add %g6, TI_FPREGS + 0x80, %g1
101 661: ldxa [%g3] ASI_DMMU, %g5
102 .section .sun4v_1insn_patch, "ax"
104 ldxa [%g3] ASI_MMU, %g5
107 sethi %hi(sparc64_kern_sec_context), %g2
108 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
110 661: stxa %g2, [%g3] ASI_DMMU
111 .section .sun4v_1insn_patch, "ax"
113 stxa %g2, [%g3] ASI_MMU
117 add %g6, TI_FPREGS + 0xc0, %g2
121 ldda [%g1] ASI_BLK_S, %f32
122 ldda [%g2] ASI_BLK_S, %f48
134 b,pt %xcc, fpdis_exit
136 2: andcc %g5, FPRS_DU, %g0
139 mov SECONDARY_CONTEXT, %g3
142 661: ldxa [%g3] ASI_DMMU, %g5
143 .section .sun4v_1insn_patch, "ax"
145 ldxa [%g3] ASI_MMU, %g5
148 add %g6, TI_FPREGS, %g1
149 sethi %hi(sparc64_kern_sec_context), %g2
150 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
152 661: stxa %g2, [%g3] ASI_DMMU
153 .section .sun4v_1insn_patch, "ax"
155 stxa %g2, [%g3] ASI_MMU
159 add %g6, TI_FPREGS + 0x40, %g2
160 faddd %f32, %f34, %f36
161 fmuld %f32, %f34, %f38
163 ldda [%g1] ASI_BLK_S, %f0
164 ldda [%g2] ASI_BLK_S, %f16
166 faddd %f32, %f34, %f40
167 fmuld %f32, %f34, %f42
168 faddd %f32, %f34, %f44
169 fmuld %f32, %f34, %f46
170 faddd %f32, %f34, %f48
171 fmuld %f32, %f34, %f50
172 faddd %f32, %f34, %f52
173 fmuld %f32, %f34, %f54
174 faddd %f32, %f34, %f56
175 fmuld %f32, %f34, %f58
176 faddd %f32, %f34, %f60
177 fmuld %f32, %f34, %f62
178 ba,pt %xcc, fpdis_exit
180 3: mov SECONDARY_CONTEXT, %g3
181 add %g6, TI_FPREGS, %g1
183 661: ldxa [%g3] ASI_DMMU, %g5
184 .section .sun4v_1insn_patch, "ax"
186 ldxa [%g3] ASI_MMU, %g5
189 sethi %hi(sparc64_kern_sec_context), %g2
190 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
192 661: stxa %g2, [%g3] ASI_DMMU
193 .section .sun4v_1insn_patch, "ax"
195 stxa %g2, [%g3] ASI_MMU
201 ldda [%g1] ASI_BLK_S, %f0
202 ldda [%g1 + %g2] ASI_BLK_S, %f16
204 ldda [%g1] ASI_BLK_S, %f32
205 ldda [%g1 + %g2] ASI_BLK_S, %f48
209 661: stxa %g5, [%g3] ASI_DMMU
210 .section .sun4v_1insn_patch, "ax"
212 stxa %g5, [%g3] ASI_MMU
218 ldx [%g6 + TI_XFSR], %fsr
220 or %g3, %g4, %g3 ! anal...
222 wr %g0, FPRS_FEF, %fprs ! clean DU/DL bits
228 add %sp, PTREGS_OFF, %o0
232 .globl do_fpother_check_fitos
234 do_fpother_check_fitos:
235 TRAP_LOAD_THREAD_REG(%g6, %g1)
236 sethi %hi(fp_other_bounce - 4), %g7
237 or %g7, %lo(fp_other_bounce - 4), %g7
239 /* NOTE: Need to preserve %g7 until we fully commit
240 * to the fitos fixup.
242 stx %fsr, [%g6 + TI_XFSR]
244 andcc %g3, TSTATE_PRIV, %g0
245 bne,pn %xcc, do_fptrap_after_fsr
247 ldx [%g6 + TI_XFSR], %g3
250 cmp %g1, 2 ! Unfinished FP-OP
251 bne,pn %xcc, do_fptrap_after_fsr
252 sethi %hi(1 << 23), %g1 ! Inexact
254 bne,pn %xcc, do_fptrap_after_fsr
256 lduwa [%g1] ASI_AIUP, %g3 ! This cannot ever fail
257 #define FITOS_MASK 0xc1f83fe0
258 #define FITOS_COMPARE 0x81a01880
259 sethi %hi(FITOS_MASK), %g1
260 or %g1, %lo(FITOS_MASK), %g1
262 sethi %hi(FITOS_COMPARE), %g2
263 or %g2, %lo(FITOS_COMPARE), %g2
265 bne,pn %xcc, do_fptrap_after_fsr
267 std %f62, [%g6 + TI_FPREGS + (62 * 4)]
268 sethi %hi(fitos_table_1), %g1
270 or %g1, %lo(fitos_table_1), %g1
273 ba,pt %xcc, fitos_emul_continue
310 sethi %hi(fitos_table_2), %g1
312 or %g1, %lo(fitos_table_2), %g1
316 ba,pt %xcc, fitos_emul_fini
353 ldd [%g6 + TI_FPREGS + (62 * 4)], %f62
359 stx %fsr, [%g6 + TI_XFSR]
361 ldub [%g6 + TI_FPSAVED], %g3
364 stb %g3, [%g6 + TI_FPSAVED]
366 stx %g3, [%g6 + TI_GSR]
367 mov SECONDARY_CONTEXT, %g3
369 661: ldxa [%g3] ASI_DMMU, %g5
370 .section .sun4v_1insn_patch, "ax"
372 ldxa [%g3] ASI_MMU, %g5
375 sethi %hi(sparc64_kern_sec_context), %g2
376 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
378 661: stxa %g2, [%g3] ASI_DMMU
379 .section .sun4v_1insn_patch, "ax"
381 stxa %g2, [%g3] ASI_MMU
385 add %g6, TI_FPREGS, %g2
386 andcc %g1, FPRS_DL, %g0
389 stda %f0, [%g2] ASI_BLK_S
390 stda %f16, [%g2 + %g3] ASI_BLK_S
391 andcc %g1, FPRS_DU, %g0
394 stda %f32, [%g2] ASI_BLK_S
395 stda %f48, [%g2 + %g3] ASI_BLK_S
396 5: mov SECONDARY_CONTEXT, %g1
399 661: stxa %g5, [%g1] ASI_DMMU
400 .section .sun4v_1insn_patch, "ax"
402 stxa %g5, [%g1] ASI_MMU
409 /* The registers for cross calls will be:
411 * DATA 0: [low 32-bits] Address of function to call, jmp to this
412 * [high 32-bits] MMU Context Argument 0, place in %g5
413 * DATA 1: Address Argument 1, place in %g1
414 * DATA 2: Address Argument 2, place in %g7
416 * With this method we can do most of the cross-call tlb/cache
417 * flushing very quickly.
424 ldxa [%g3 + %g0] ASI_INTR_R, %g3
425 sethi %hi(KERNBASE), %g4
427 bgeu,pn %xcc, do_ivec_xcall
429 stxa %g0, [%g0] ASI_INTR_RECEIVE
432 sethi %hi(ivector_table), %g2
434 or %g2, %lo(ivector_table), %g2
436 ldub [%g3 + 0x04], %g4 /* pil */
441 TRAP_LOAD_IRQ_WORK(%g6, %g1)
443 lduw [%g6 + %g4], %g5 /* g5 = irq_work(cpu, pil) */
444 stw %g5, [%g3 + 0x00] /* bucket->irq_chain = g5 */
445 stw %g3, [%g6 + %g4] /* irq_work(cpu, pil) = bucket */
446 wr %g2, 0x0, %set_softint
450 ldxa [%g1 + %g0] ASI_INTR_R, %g1
454 ldxa [%g7 + %g0] ASI_INTR_R, %g7
455 stxa %g0, [%g0] ASI_INTR_RECEIVE
466 ldx [%o0 + PT_V9_TSTATE], %o1
470 stx %o1, [%o0 + PT_V9_G1]
472 ldx [%o0 + PT_V9_TSTATE], %o1
473 ldx [%o0 + PT_V9_G1], %o2
474 or %g0, %ulo(TSTATE_ICC), %o3
481 stx %o1, [%o0 + PT_V9_TSTATE]
484 utrap_trap: /* %g3=handler,%g4=level */
485 TRAP_LOAD_THREAD_REG(%g6, %g1)
486 ldx [%g6 + TI_UTRAPS], %g1
487 brnz,pt %g1, invoke_utrap
494 add %sp, PTREGS_OFF, %o0
504 andn %l6, TSTATE_CWP, %l6
505 wrpr %l6, %l7, %tstate
511 /* We need to carefully read the error status, ACK
512 * the errors, prevent recursive traps, and pass the
513 * information on to C code for logging.
515 * We pass the AFAR in as-is, and we encode the status
516 * information as described in asm-sparc64/sfafsr.h
518 .globl __spitfire_access_error
519 __spitfire_access_error:
520 /* Disable ESTATE error reporting so that we do not
521 * take recursive traps and RED state the processor.
523 stxa %g0, [%g0] ASI_ESTATE_ERROR_EN
527 ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
529 /* __spitfire_cee_trap branches here with AFSR in %g4 and
530 * UDBE_CE in %g1. It only clears ESTATE_ERR_CE in the
531 * ESTATE Error Enable register.
533 __spitfire_cee_trap_continue:
534 ldxa [%g0] ASI_AFAR, %g5 ! Get AFAR
537 and %g3, 0x1ff, %g3 ! Paranoia
538 sllx %g3, SFSTAT_TRAP_TYPE_SHIFT, %g3
544 sllx %g3, SFSTAT_TL_GT_ONE_SHIFT, %g3
548 /* Read in the UDB error register state, clearing the
549 * sticky error bits as-needed. We only clear them if
550 * the UE bit is set. Likewise, __spitfire_cee_trap
551 * below will only do so if the CE bit is set.
553 * NOTE: UltraSparc-I/II have high and low UDB error
554 * registers, corresponding to the two UDB units
555 * present on those chips. UltraSparc-IIi only
556 * has a single UDB, called "SDB" in the manual.
557 * For IIi the upper UDB register always reads
558 * as zero so for our purposes things will just
559 * work with the checks below.
561 1: ldxa [%g0] ASI_UDBH_ERROR_R, %g3
562 and %g3, 0x3ff, %g7 ! Paranoia
563 sllx %g7, SFSTAT_UDBH_SHIFT, %g7
565 andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
568 stxa %g3, [%g0] ASI_UDB_ERROR_W
572 ldxa [%g3] ASI_UDBL_ERROR_R, %g3
573 and %g3, 0x3ff, %g7 ! Paranoia
574 sllx %g7, SFSTAT_UDBL_SHIFT, %g7
576 andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
580 stxa %g3, [%g7] ASI_UDB_ERROR_W
583 1: /* Ok, now that we've latched the error state,
584 * clear the sticky bits in the AFSR.
586 stxa %g4, [%g0] ASI_AFSR
601 1: ba,pt %xcc, etrap_irq
606 call spitfire_access_error
607 add %sp, PTREGS_OFF, %o0
611 /* This is the trap handler entry point for ECC correctable
612 * errors. They are corrected, but we listen for the trap
613 * so that the event can be logged.
615 * Disrupting errors are either:
616 * 1) single-bit ECC errors during UDB reads to system
618 * 2) data parity errors during write-back events
620 * As far as I can make out from the manual, the CEE trap
621 * is only for correctable errors during memory read
622 * accesses by the front-end of the processor.
624 * The code below is only for trap level 1 CEE events,
625 * as it is the only situation where we can safely record
626 * and log. For trap level >1 we just clear the CE bit
627 * in the AFSR and return.
629 * This is just like __spiftire_access_error above, but it
630 * specifically handles correctable errors. If an
631 * uncorrectable error is indicated in the AFSR we
632 * will branch directly above to __spitfire_access_error
633 * to handle it instead. Uncorrectable therefore takes
634 * priority over correctable, and the error logging
635 * C code will notice this case by inspecting the
638 .globl __spitfire_cee_trap
640 ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
642 sllx %g3, SFAFSR_UE_SHIFT, %g3
643 andcc %g4, %g3, %g0 ! Check for UE
644 bne,pn %xcc, __spitfire_access_error
647 /* Ok, in this case we only have a correctable error.
648 * Indicate we only wish to capture that state in register
649 * %g1, and we only disable CE error reporting unlike UE
650 * handling which disables all errors.
652 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g3
653 andn %g3, ESTATE_ERR_CE, %g3
654 stxa %g3, [%g0] ASI_ESTATE_ERROR_EN
657 /* Preserve AFSR in %g4, indicate UDB state to capture in %g1 */
658 ba,pt %xcc, __spitfire_cee_trap_continue
661 .globl __spitfire_data_access_exception
662 .globl __spitfire_data_access_exception_tl1
663 __spitfire_data_access_exception_tl1:
665 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
668 ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
669 ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
670 stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
673 cmp %g3, 0x80 ! first win spill/fill trap
675 cmp %g3, 0xff ! last win spill/fill trap
678 ba,pt %xcc, winfix_dax
680 1: sethi %hi(109f), %g7
682 109: or %g7, %lo(109b), %g7
685 call spitfire_data_access_exception_tl1
686 add %sp, PTREGS_OFF, %o0
690 __spitfire_data_access_exception:
692 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
695 ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
696 ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
697 stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
701 109: or %g7, %lo(109b), %g7
704 call spitfire_data_access_exception
705 add %sp, PTREGS_OFF, %o0
709 .globl __spitfire_insn_access_exception
710 .globl __spitfire_insn_access_exception_tl1
711 __spitfire_insn_access_exception_tl1:
713 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
715 ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
716 rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
717 stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
721 109: or %g7, %lo(109b), %g7
724 call spitfire_insn_access_exception_tl1
725 add %sp, PTREGS_OFF, %o0
729 __spitfire_insn_access_exception:
731 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
733 ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
734 rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
735 stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
739 109: or %g7, %lo(109b), %g7
742 call spitfire_insn_access_exception
743 add %sp, PTREGS_OFF, %o0
747 /* These get patched into the trap table at boot time
748 * once we know we have a cheetah processor.
750 .globl cheetah_fecc_trap_vector, cheetah_fecc_trap_vector_tl1
751 cheetah_fecc_trap_vector:
753 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
754 andn %g1, DCU_DC | DCU_IC, %g1
755 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
757 sethi %hi(cheetah_fast_ecc), %g2
758 jmpl %g2 + %lo(cheetah_fast_ecc), %g0
760 cheetah_fecc_trap_vector_tl1:
762 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
763 andn %g1, DCU_DC | DCU_IC, %g1
764 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
766 sethi %hi(cheetah_fast_ecc), %g2
767 jmpl %g2 + %lo(cheetah_fast_ecc), %g0
769 .globl cheetah_cee_trap_vector, cheetah_cee_trap_vector_tl1
770 cheetah_cee_trap_vector:
772 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
773 andn %g1, DCU_IC, %g1
774 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
776 sethi %hi(cheetah_cee), %g2
777 jmpl %g2 + %lo(cheetah_cee), %g0
779 cheetah_cee_trap_vector_tl1:
781 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
782 andn %g1, DCU_IC, %g1
783 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
785 sethi %hi(cheetah_cee), %g2
786 jmpl %g2 + %lo(cheetah_cee), %g0
788 .globl cheetah_deferred_trap_vector, cheetah_deferred_trap_vector_tl1
789 cheetah_deferred_trap_vector:
791 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
792 andn %g1, DCU_DC | DCU_IC, %g1;
793 stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
795 sethi %hi(cheetah_deferred_trap), %g2
796 jmpl %g2 + %lo(cheetah_deferred_trap), %g0
798 cheetah_deferred_trap_vector_tl1:
800 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
801 andn %g1, DCU_DC | DCU_IC, %g1;
802 stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
804 sethi %hi(cheetah_deferred_trap), %g2
805 jmpl %g2 + %lo(cheetah_deferred_trap), %g0
808 /* Cheetah+ specific traps. These are for the new I/D cache parity
809 * error traps. The first argument to cheetah_plus_parity_handler
810 * is encoded as follows:
812 * Bit0: 0=dcache,1=icache
813 * Bit1: 0=recoverable,1=unrecoverable
815 .globl cheetah_plus_dcpe_trap_vector, cheetah_plus_dcpe_trap_vector_tl1
816 cheetah_plus_dcpe_trap_vector:
818 sethi %hi(do_cheetah_plus_data_parity), %g7
819 jmpl %g7 + %lo(do_cheetah_plus_data_parity), %g0
826 do_cheetah_plus_data_parity:
829 ba,pt %xcc, etrap_irq
832 call cheetah_plus_parity_error
833 add %sp, PTREGS_OFF, %o1
834 ba,a,pt %xcc, rtrap_irq
836 cheetah_plus_dcpe_trap_vector_tl1:
838 wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
839 sethi %hi(do_dcpe_tl1), %g3
840 jmpl %g3 + %lo(do_dcpe_tl1), %g0
846 .globl cheetah_plus_icpe_trap_vector, cheetah_plus_icpe_trap_vector_tl1
847 cheetah_plus_icpe_trap_vector:
849 sethi %hi(do_cheetah_plus_insn_parity), %g7
850 jmpl %g7 + %lo(do_cheetah_plus_insn_parity), %g0
857 do_cheetah_plus_insn_parity:
860 ba,pt %xcc, etrap_irq
863 call cheetah_plus_parity_error
864 add %sp, PTREGS_OFF, %o1
865 ba,a,pt %xcc, rtrap_irq
867 cheetah_plus_icpe_trap_vector_tl1:
869 wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
870 sethi %hi(do_icpe_tl1), %g3
871 jmpl %g3 + %lo(do_icpe_tl1), %g0
877 /* If we take one of these traps when tl >= 1, then we
878 * jump to interrupt globals. If some trap level above us
879 * was also using interrupt globals, we cannot recover.
880 * We may use all interrupt global registers except %g6.
882 .globl do_dcpe_tl1, do_icpe_tl1
884 rdpr %tl, %g1 ! Save original trap level
885 mov 1, %g2 ! Setup TSTATE checking loop
886 sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
887 1: wrpr %g2, %tl ! Set trap level to check
888 rdpr %tstate, %g4 ! Read TSTATE for this level
889 andcc %g4, %g3, %g0 ! Interrupt globals in use?
890 bne,a,pn %xcc, do_dcpe_tl1_fatal ! Yep, irrecoverable
891 wrpr %g1, %tl ! Restore original trap level
892 add %g2, 1, %g2 ! Next trap level
893 cmp %g2, %g1 ! Hit them all yet?
894 ble,pt %icc, 1b ! Not yet
896 wrpr %g1, %tl ! Restore original trap level
897 do_dcpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
898 sethi %hi(dcache_parity_tl1_occurred), %g2
899 lduw [%g2 + %lo(dcache_parity_tl1_occurred)], %g1
901 stw %g1, [%g2 + %lo(dcache_parity_tl1_occurred)]
902 /* Reset D-cache parity */
903 sethi %hi(1 << 16), %g1 ! D-cache size
904 mov (1 << 5), %g2 ! D-cache line size
905 sub %g1, %g2, %g1 ! Move down 1 cacheline
906 1: srl %g1, 14, %g3 ! Compute UTAG
908 stxa %g3, [%g1] ASI_DCACHE_UTAG
910 sub %g2, 8, %g3 ! 64-bit data word within line
912 stxa %g0, [%g1 + %g3] ASI_DCACHE_DATA
914 subcc %g3, 8, %g3 ! Next 64-bit data word
917 subcc %g1, %g2, %g1 ! Next cacheline
920 ba,pt %xcc, dcpe_icpe_tl1_common
926 1: or %g7, %lo(1b), %g7
928 call cheetah_plus_parity_error
929 add %sp, PTREGS_OFF, %o1
934 rdpr %tl, %g1 ! Save original trap level
935 mov 1, %g2 ! Setup TSTATE checking loop
936 sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
937 1: wrpr %g2, %tl ! Set trap level to check
938 rdpr %tstate, %g4 ! Read TSTATE for this level
939 andcc %g4, %g3, %g0 ! Interrupt globals in use?
940 bne,a,pn %xcc, do_icpe_tl1_fatal ! Yep, irrecoverable
941 wrpr %g1, %tl ! Restore original trap level
942 add %g2, 1, %g2 ! Next trap level
943 cmp %g2, %g1 ! Hit them all yet?
944 ble,pt %icc, 1b ! Not yet
946 wrpr %g1, %tl ! Restore original trap level
947 do_icpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
948 sethi %hi(icache_parity_tl1_occurred), %g2
949 lduw [%g2 + %lo(icache_parity_tl1_occurred)], %g1
951 stw %g1, [%g2 + %lo(icache_parity_tl1_occurred)]
953 sethi %hi(1 << 15), %g1 ! I-cache size
954 mov (1 << 5), %g2 ! I-cache line size
956 1: or %g1, (2 << 3), %g3
957 stxa %g0, [%g3] ASI_IC_TAG
962 ba,pt %xcc, dcpe_icpe_tl1_common
968 1: or %g7, %lo(1b), %g7
970 call cheetah_plus_parity_error
971 add %sp, PTREGS_OFF, %o1
975 dcpe_icpe_tl1_common:
976 /* Flush D-cache, re-enable D/I caches in DCU and finally
977 * retry the trapping instruction.
979 sethi %hi(1 << 16), %g1 ! D-cache size
980 mov (1 << 5), %g2 ! D-cache line size
982 1: stxa %g0, [%g1] ASI_DCACHE_TAG
987 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
988 or %g1, (DCU_DC | DCU_IC), %g1
989 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
993 /* Capture I/D/E-cache state into per-cpu error scoreboard.
995 * %g1: (TL>=0) ? 1 : 0
1000 * %g6: unused, will have current thread ptr after etrap
1003 __cheetah_log_error:
1004 /* Put "TL1" software bit into AFSR. */
1009 /* Get log entry pointer for this cpu at this trap level. */
1010 BRANCH_IF_JALAPENO(g2,g3,50f)
1011 ldxa [%g0] ASI_SAFARI_CONFIG, %g2
1016 50: ldxa [%g0] ASI_JBUS_CONFIG, %g2
1020 60: sllx %g2, 9, %g2
1021 sethi %hi(cheetah_error_log), %g3
1022 ldx [%g3 + %lo(cheetah_error_log)], %g3
1030 /* %g1 holds pointer to the top of the logging scoreboard */
1031 ldx [%g1 + 0x0], %g7
1036 stx %g4, [%g1 + 0x0]
1037 stx %g5, [%g1 + 0x8]
1040 /* %g1 now points to D-cache logging area */
1041 set 0x3ff8, %g2 /* DC_addr mask */
1042 and %g5, %g2, %g2 /* DC_addr bits of AFAR */
1044 or %g3, 1, %g3 /* PHYS tag + valid */
1046 10: ldxa [%g2] ASI_DCACHE_TAG, %g7
1047 cmp %g3, %g7 /* TAG match? */
1051 /* Yep, what we want, capture state. */
1052 stx %g2, [%g1 + 0x20]
1053 stx %g7, [%g1 + 0x28]
1055 /* A membar Sync is required before and after utag access. */
1057 ldxa [%g2] ASI_DCACHE_UTAG, %g7
1059 stx %g7, [%g1 + 0x30]
1060 ldxa [%g2] ASI_DCACHE_SNOOP_TAG, %g7
1061 stx %g7, [%g1 + 0x38]
1064 12: ldxa [%g2 + %g3] ASI_DCACHE_DATA, %g7
1066 add %g3, (1 << 5), %g3
1074 13: sethi %hi(1 << 14), %g7
1083 /* %g1 now points to I-cache logging area */
1084 20: set 0x1fe0, %g2 /* IC_addr mask */
1085 and %g5, %g2, %g2 /* IC_addr bits of AFAR */
1086 sllx %g2, 1, %g2 /* IC_addr[13:6]==VA[12:5] */
1087 srlx %g5, (13 - 8), %g3 /* Make PTAG */
1088 andn %g3, 0xff, %g3 /* Mask off undefined bits */
1090 21: ldxa [%g2] ASI_IC_TAG, %g7
1096 /* Yep, what we want, capture state. */
1097 stx %g2, [%g1 + 0x40]
1098 stx %g7, [%g1 + 0x48]
1099 add %g2, (1 << 3), %g2
1100 ldxa [%g2] ASI_IC_TAG, %g7
1101 add %g2, (1 << 3), %g2
1102 stx %g7, [%g1 + 0x50]
1103 ldxa [%g2] ASI_IC_TAG, %g7
1104 add %g2, (1 << 3), %g2
1105 stx %g7, [%g1 + 0x60]
1106 ldxa [%g2] ASI_IC_TAG, %g7
1107 stx %g7, [%g1 + 0x68]
1108 sub %g2, (3 << 3), %g2
1109 ldxa [%g2] ASI_IC_STAG, %g7
1110 stx %g7, [%g1 + 0x58]
1114 22: ldxa [%g2 + %g3] ASI_IC_INSTR, %g7
1116 add %g3, (1 << 3), %g3
1124 23: sethi %hi(1 << 14), %g7
1133 /* %g1 now points to E-cache logging area */
1134 30: andn %g5, (32 - 1), %g2
1135 stx %g2, [%g1 + 0x20]
1136 ldxa [%g2] ASI_EC_TAG_DATA, %g7
1137 stx %g7, [%g1 + 0x28]
1138 ldxa [%g2] ASI_EC_R, %g0
1141 31: ldxa [%g3] ASI_EC_DATA, %g7
1142 stx %g7, [%g1 + %g3]
1155 ba,pt %xcc, c_deferred
1157 /* Cheetah FECC trap handling, we get here from tl{0,1}_fecc
1158 * in the trap table. That code has done a memory barrier
1159 * and has disabled both the I-cache and D-cache in the DCU
1160 * control register. The I-cache is disabled so that we may
1161 * capture the corrupted cache line, and the D-cache is disabled
1162 * because corrupt data may have been placed there and we don't
1163 * want to reference it.
1165 * %g1 is one if this trap occurred at %tl >= 1.
1167 * Next, we turn off error reporting so that we don't recurse.
1169 .globl cheetah_fast_ecc
1171 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1172 andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
1173 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1176 /* Fetch and clear AFSR/AFAR */
1177 ldxa [%g0] ASI_AFSR, %g4
1178 ldxa [%g0] ASI_AFAR, %g5
1179 stxa %g4, [%g0] ASI_AFSR
1182 ba,pt %xcc, __cheetah_log_error
1188 ba,pt %xcc, etrap_irq
1192 call cheetah_fecc_handler
1193 add %sp, PTREGS_OFF, %o0
1194 ba,a,pt %xcc, rtrap_irq
1196 /* Our caller has disabled I-cache and performed membar Sync. */
1199 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1200 andn %g2, ESTATE_ERROR_CEEN, %g2
1201 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1204 /* Fetch and clear AFSR/AFAR */
1205 ldxa [%g0] ASI_AFSR, %g4
1206 ldxa [%g0] ASI_AFAR, %g5
1207 stxa %g4, [%g0] ASI_AFSR
1210 ba,pt %xcc, __cheetah_log_error
1216 ba,pt %xcc, etrap_irq
1220 call cheetah_cee_handler
1221 add %sp, PTREGS_OFF, %o0
1222 ba,a,pt %xcc, rtrap_irq
1224 /* Our caller has disabled I-cache+D-cache and performed membar Sync. */
1225 .globl cheetah_deferred_trap
1226 cheetah_deferred_trap:
1227 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1228 andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
1229 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1232 /* Fetch and clear AFSR/AFAR */
1233 ldxa [%g0] ASI_AFSR, %g4
1234 ldxa [%g0] ASI_AFAR, %g5
1235 stxa %g4, [%g0] ASI_AFSR
1238 ba,pt %xcc, __cheetah_log_error
1244 ba,pt %xcc, etrap_irq
1248 call cheetah_deferred_handler
1249 add %sp, PTREGS_OFF, %o0
1250 ba,a,pt %xcc, rtrap_irq
1255 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
1257 sethi %hi(109f), %g7
1259 109: or %g7, %lo(109b), %g7
1261 add %sp, PTREGS_OFF, %o0
1270 /* Setup %g4/%g5 now as they are used in the
1275 ldxa [%g4] ASI_DMMU, %g4
1276 ldxa [%g3] ASI_DMMU, %g5
1277 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
1279 bgu,pn %icc, winfix_mna
1282 1: sethi %hi(109f), %g7
1284 109: or %g7, %lo(109b), %g7
1287 call mem_address_unaligned
1288 add %sp, PTREGS_OFF, %o0
1294 sethi %hi(109f), %g7
1296 ldxa [%g4] ASI_DMMU, %g5
1297 stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
1300 ldxa [%g4] ASI_DMMU, %g4
1302 109: or %g7, %lo(109b), %g7
1306 add %sp, PTREGS_OFF, %o0
1312 sethi %hi(109f), %g7
1314 ldxa [%g4] ASI_DMMU, %g5
1315 stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
1318 ldxa [%g4] ASI_DMMU, %g4
1320 109: or %g7, %lo(109b), %g7
1324 add %sp, PTREGS_OFF, %o0
1328 .globl breakpoint_trap
1330 call sparc_breakpoint
1331 add %sp, PTREGS_OFF, %o0
1335 #if defined(CONFIG_SUNOS_EMUL) || defined(CONFIG_SOLARIS_EMUL) || \
1336 defined(CONFIG_SOLARIS_EMUL_MODULE)
1337 /* SunOS uses syscall zero as the 'indirect syscall' it looks
1338 * like indir_syscall(scall_num, arg0, arg1, arg2...); etc.
1339 * This is complete brain damage.
1345 cmp %o0, NR_SYSCALLS
1348 sethi %hi(sunos_nosys), %l6
1350 or %l6, %lo(sunos_nosys), %l6
1351 1: sethi %hi(sunos_sys_table), %l7
1352 or %l7, %lo(sunos_sys_table), %l7
1353 lduw [%l7 + %o0], %l6
1367 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1368 b,pt %xcc, ret_sys_call
1369 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1371 /* SunOS getuid() returns uid in %o0 and euid in %o1 */
1374 call sys32_geteuid16
1377 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1378 b,pt %xcc, ret_sys_call
1379 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1381 /* SunOS getgid() returns gid in %o0 and egid in %o1 */
1384 call sys32_getegid16
1387 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1388 b,pt %xcc, ret_sys_call
1389 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1392 /* SunOS's execv() call only specifies the argv argument, the
1393 * environment settings are the same as the calling processes.
1397 sethi %hi(sparc_execve), %g1
1398 ba,pt %xcc, execve_merge
1399 or %g1, %lo(sparc_execve), %g1
1400 #ifdef CONFIG_COMPAT
1403 stx %g0, [%sp + PTREGS_OFF + PT_V9_I2]
1406 sethi %hi(sparc32_execve), %g1
1407 or %g1, %lo(sparc32_execve), %g1
1412 add %sp, PTREGS_OFF, %o0
1414 .globl sys_pipe, sys_sigpause, sys_nis_syscall
1415 .globl sys_rt_sigreturn
1417 .globl sys_sigaltstack
1419 sys_pipe: ba,pt %xcc, sparc_pipe
1420 add %sp, PTREGS_OFF, %o0
1421 sys_nis_syscall:ba,pt %xcc, c_sys_nis_syscall
1422 add %sp, PTREGS_OFF, %o0
1423 sys_memory_ordering:
1424 ba,pt %xcc, sparc_memory_ordering
1425 add %sp, PTREGS_OFF, %o1
1426 sys_sigaltstack:ba,pt %xcc, do_sigaltstack
1427 add %i6, STACK_BIAS, %o2
1428 #ifdef CONFIG_COMPAT
1429 .globl sys32_sigstack
1430 sys32_sigstack: ba,pt %xcc, do_sys32_sigstack
1432 .globl sys32_sigaltstack
1434 ba,pt %xcc, do_sys32_sigaltstack
1438 #ifdef CONFIG_COMPAT
1439 .globl sys32_sigreturn
1441 add %sp, PTREGS_OFF, %o0
1443 add %o7, 1f-.-4, %o7
1447 add %sp, PTREGS_OFF, %o0
1448 call do_rt_sigreturn
1449 add %o7, 1f-.-4, %o7
1451 #ifdef CONFIG_COMPAT
1452 .globl sys32_rt_sigreturn
1454 add %sp, PTREGS_OFF, %o0
1455 call do_rt_sigreturn32
1456 add %o7, 1f-.-4, %o7
1459 sys_ptrace: add %sp, PTREGS_OFF, %o0
1461 add %o7, 1f-.-4, %o7
1464 1: ldx [%curptr + TI_FLAGS], %l5
1465 andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1468 add %sp, PTREGS_OFF, %o0
1475 /* This is how fork() was meant to be done, 8 instruction entry.
1477 * I questioned the following code briefly, let me clear things
1478 * up so you must not reason on it like I did.
1480 * Know the fork_kpsr etc. we use in the sparc32 port? We don't
1481 * need it here because the only piece of window state we copy to
1482 * the child is the CWP register. Even if the parent sleeps,
1483 * we are safe because we stuck it into pt_regs of the parent
1484 * so it will not change.
1486 * XXX This raises the question, whether we can do the same on
1487 * XXX sparc32 to get rid of fork_kpsr _and_ fork_kwim. The
1488 * XXX answer is yes. We stick fork_kpsr in UREG_G0 and
1489 * XXX fork_kwim in UREG_G1 (global registers are considered
1490 * XXX volatile across a system call in the sparc ABI I think
1491 * XXX if it isn't we can use regs->y instead, anyone who depends
1492 * XXX upon the Y register being preserved across a fork deserves
1495 * In fact we should take advantage of that fact for other things
1496 * during system calls...
1498 .globl sys_fork, sys_vfork, sys_clone, sparc_exit
1499 .globl ret_from_syscall
1501 sys_vfork: /* Under Linux, vfork and fork are just special cases of clone. */
1502 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1503 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1504 ba,pt %xcc, sys_clone
1510 ba,pt %xcc, sparc_do_fork
1511 add %sp, PTREGS_OFF, %o2
1513 /* Clear current_thread_info()->new_child, and
1514 * check performance counter stuff too.
1516 stb %g0, [%g6 + TI_NEW_CHILD]
1517 ldx [%g6 + TI_FLAGS], %l0
1520 andcc %l0, _TIF_PERFCTR, %g0
1523 ldx [%g6 + TI_PCR], %o7
1526 /* Blackbird errata workaround. See commentary in
1527 * smp.c:smp_percpu_timer_interrupt() for more
1533 99: wr %g0, %g0, %pic
1536 1: b,pt %xcc, ret_sys_call
1537 ldx [%sp + PTREGS_OFF + PT_V9_I0], %o0
1538 sparc_exit: rdpr %pstate, %g2
1539 wrpr %g2, PSTATE_IE, %pstate
1543 wrpr %g3, 0x0, %cansave
1544 wrpr %g0, 0x0, %otherwin
1545 wrpr %g2, 0x0, %pstate
1546 ba,pt %xcc, sys_exit
1547 stb %g0, [%g6 + TI_WSAVED]
1549 linux_sparc_ni_syscall:
1550 sethi %hi(sys_ni_syscall), %l7
1552 or %l7, %lo(sys_ni_syscall), %l7
1554 linux_syscall_trace32:
1555 add %sp, PTREGS_OFF, %o0
1565 linux_syscall_trace:
1566 add %sp, PTREGS_OFF, %o0
1577 /* Linux 32-bit and SunOS system calls enter here... */
1579 .globl linux_sparc_syscall32
1580 linux_sparc_syscall32:
1581 /* Direct access to user regs, much faster. */
1582 cmp %g1, NR_SYSCALLS ! IEU1 Group
1583 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
1584 srl %i0, 0, %o0 ! IEU0
1585 sll %g1, 2, %l4 ! IEU0 Group
1586 srl %i4, 0, %o4 ! IEU1
1587 lduw [%l7 + %l4], %l7 ! Load
1588 srl %i1, 0, %o1 ! IEU0 Group
1589 ldx [%curptr + TI_FLAGS], %l0 ! Load
1591 srl %i5, 0, %o5 ! IEU1
1592 srl %i2, 0, %o2 ! IEU0 Group
1593 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1594 bne,pn %icc, linux_syscall_trace32 ! CTI
1596 call %l7 ! CTI Group brk forced
1597 srl %i3, 0, %o3 ! IEU0
1600 /* Linux native and SunOS system calls enter here... */
1602 .globl linux_sparc_syscall, ret_sys_call
1603 linux_sparc_syscall:
1604 /* Direct access to user regs, much faster. */
1605 cmp %g1, NR_SYSCALLS ! IEU1 Group
1606 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
1608 sll %g1, 2, %l4 ! IEU0 Group
1610 lduw [%l7 + %l4], %l7 ! Load
1611 4: mov %i2, %o2 ! IEU0 Group
1612 ldx [%curptr + TI_FLAGS], %l0 ! Load
1615 mov %i4, %o4 ! IEU0 Group
1616 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1617 bne,pn %icc, linux_syscall_trace ! CTI Group
1619 2: call %l7 ! CTI Group brk forced
1623 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1625 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
1626 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
1628 mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
1631 /* Check if force_successful_syscall_return()
1634 ldub [%curptr + TI_SYS_NOERROR], %l2
1636 stb %g0, [%curptr + TI_SYS_NOERROR]
1638 cmp %o0, -ERESTART_RESTARTBLOCK
1640 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
1642 /* System call success, clear Carry condition code. */
1644 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
1645 bne,pn %icc, linux_syscall_trace2
1646 add %l1, 0x4, %l2 ! npc = npc+4
1647 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1648 ba,pt %xcc, rtrap_clr_l6
1649 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1652 /* System call failure, set Carry condition code.
1653 * Also, get abs(errno) to return to the process.
1655 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
1658 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1660 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
1661 bne,pn %icc, linux_syscall_trace2
1662 add %l1, 0x4, %l2 ! npc = npc+4
1663 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1666 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1667 linux_syscall_trace2:
1668 add %sp, PTREGS_OFF, %o0
1671 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1673 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1676 .globl __flushw_user
1681 1: save %sp, -128, %sp
1687 restore %g0, %g0, %g0
1692 .globl hard_smp_processor_id
1693 hard_smp_processor_id: