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/errno.h>
15 #include <asm/ptrace.h>
17 #include <asm/signal.h>
18 #include <asm/pgtable.h>
19 #include <asm/processor.h>
20 #include <asm/visasm.h>
21 #include <asm/estate.h>
22 #include <asm/auxio.h>
23 #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 TRAP_LOAD_THREAD_REG(%g6, %g1)
360 stx %fsr, [%g6 + TI_XFSR]
362 ldub [%g6 + TI_FPSAVED], %g3
365 stb %g3, [%g6 + TI_FPSAVED]
367 stx %g3, [%g6 + TI_GSR]
368 mov SECONDARY_CONTEXT, %g3
370 661: ldxa [%g3] ASI_DMMU, %g5
371 .section .sun4v_1insn_patch, "ax"
373 ldxa [%g3] ASI_MMU, %g5
376 sethi %hi(sparc64_kern_sec_context), %g2
377 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
379 661: stxa %g2, [%g3] ASI_DMMU
380 .section .sun4v_1insn_patch, "ax"
382 stxa %g2, [%g3] ASI_MMU
386 add %g6, TI_FPREGS, %g2
387 andcc %g1, FPRS_DL, %g0
390 stda %f0, [%g2] ASI_BLK_S
391 stda %f16, [%g2 + %g3] ASI_BLK_S
392 andcc %g1, FPRS_DU, %g0
395 stda %f32, [%g2] ASI_BLK_S
396 stda %f48, [%g2 + %g3] ASI_BLK_S
397 5: mov SECONDARY_CONTEXT, %g1
400 661: stxa %g5, [%g1] ASI_DMMU
401 .section .sun4v_1insn_patch, "ax"
403 stxa %g5, [%g1] ASI_MMU
410 /* The registers for cross calls will be:
412 * DATA 0: [low 32-bits] Address of function to call, jmp to this
413 * [high 32-bits] MMU Context Argument 0, place in %g5
414 * DATA 1: Address Argument 1, place in %g1
415 * DATA 2: Address Argument 2, place in %g7
417 * With this method we can do most of the cross-call tlb/cache
418 * flushing very quickly.
425 ldxa [%g3 + %g0] ASI_INTR_R, %g3
426 sethi %hi(KERNBASE), %g4
428 bgeu,pn %xcc, do_ivec_xcall
430 stxa %g0, [%g0] ASI_INTR_RECEIVE
433 sethi %hi(ivector_table), %g2
435 or %g2, %lo(ivector_table), %g2
438 TRAP_LOAD_IRQ_WORK(%g6, %g1)
440 lduw [%g6], %g5 /* g5 = irq_work(cpu) */
441 stw %g5, [%g3 + 0x00] /* bucket->irq_chain = g5 */
442 stw %g3, [%g6] /* irq_work(cpu) = bucket */
443 wr %g0, 1 << PIL_DEVICE_IRQ, %set_softint
447 ldxa [%g1 + %g0] ASI_INTR_R, %g1
451 ldxa [%g7 + %g0] ASI_INTR_R, %g7
452 stxa %g0, [%g0] ASI_INTR_RECEIVE
463 ldx [%o0 + PT_V9_TSTATE], %o1
467 stx %o1, [%o0 + PT_V9_G1]
469 ldx [%o0 + PT_V9_TSTATE], %o1
470 ldx [%o0 + PT_V9_G1], %o2
471 or %g0, %ulo(TSTATE_ICC), %o3
478 stx %o1, [%o0 + PT_V9_TSTATE]
481 utrap_trap: /* %g3=handler,%g4=level */
482 TRAP_LOAD_THREAD_REG(%g6, %g1)
483 ldx [%g6 + TI_UTRAPS], %g1
484 brnz,pt %g1, invoke_utrap
491 add %sp, PTREGS_OFF, %o0
501 andn %l6, TSTATE_CWP, %l6
502 wrpr %l6, %l7, %tstate
508 /* We need to carefully read the error status, ACK
509 * the errors, prevent recursive traps, and pass the
510 * information on to C code for logging.
512 * We pass the AFAR in as-is, and we encode the status
513 * information as described in asm-sparc64/sfafsr.h
515 .globl __spitfire_access_error
516 __spitfire_access_error:
517 /* Disable ESTATE error reporting so that we do not
518 * take recursive traps and RED state the processor.
520 stxa %g0, [%g0] ASI_ESTATE_ERROR_EN
524 ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
526 /* __spitfire_cee_trap branches here with AFSR in %g4 and
527 * UDBE_CE in %g1. It only clears ESTATE_ERR_CE in the
528 * ESTATE Error Enable register.
530 __spitfire_cee_trap_continue:
531 ldxa [%g0] ASI_AFAR, %g5 ! Get AFAR
534 and %g3, 0x1ff, %g3 ! Paranoia
535 sllx %g3, SFSTAT_TRAP_TYPE_SHIFT, %g3
541 sllx %g3, SFSTAT_TL_GT_ONE_SHIFT, %g3
545 /* Read in the UDB error register state, clearing the
546 * sticky error bits as-needed. We only clear them if
547 * the UE bit is set. Likewise, __spitfire_cee_trap
548 * below will only do so if the CE bit is set.
550 * NOTE: UltraSparc-I/II have high and low UDB error
551 * registers, corresponding to the two UDB units
552 * present on those chips. UltraSparc-IIi only
553 * has a single UDB, called "SDB" in the manual.
554 * For IIi the upper UDB register always reads
555 * as zero so for our purposes things will just
556 * work with the checks below.
558 1: ldxa [%g0] ASI_UDBH_ERROR_R, %g3
559 and %g3, 0x3ff, %g7 ! Paranoia
560 sllx %g7, SFSTAT_UDBH_SHIFT, %g7
562 andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
565 stxa %g3, [%g0] ASI_UDB_ERROR_W
569 ldxa [%g3] ASI_UDBL_ERROR_R, %g3
570 and %g3, 0x3ff, %g7 ! Paranoia
571 sllx %g7, SFSTAT_UDBL_SHIFT, %g7
573 andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
577 stxa %g3, [%g7] ASI_UDB_ERROR_W
580 1: /* Ok, now that we've latched the error state,
581 * clear the sticky bits in the AFSR.
583 stxa %g4, [%g0] ASI_AFSR
598 1: ba,pt %xcc, etrap_irq
603 call spitfire_access_error
604 add %sp, PTREGS_OFF, %o0
608 /* This is the trap handler entry point for ECC correctable
609 * errors. They are corrected, but we listen for the trap
610 * so that the event can be logged.
612 * Disrupting errors are either:
613 * 1) single-bit ECC errors during UDB reads to system
615 * 2) data parity errors during write-back events
617 * As far as I can make out from the manual, the CEE trap
618 * is only for correctable errors during memory read
619 * accesses by the front-end of the processor.
621 * The code below is only for trap level 1 CEE events,
622 * as it is the only situation where we can safely record
623 * and log. For trap level >1 we just clear the CE bit
624 * in the AFSR and return.
626 * This is just like __spiftire_access_error above, but it
627 * specifically handles correctable errors. If an
628 * uncorrectable error is indicated in the AFSR we
629 * will branch directly above to __spitfire_access_error
630 * to handle it instead. Uncorrectable therefore takes
631 * priority over correctable, and the error logging
632 * C code will notice this case by inspecting the
635 .globl __spitfire_cee_trap
637 ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
639 sllx %g3, SFAFSR_UE_SHIFT, %g3
640 andcc %g4, %g3, %g0 ! Check for UE
641 bne,pn %xcc, __spitfire_access_error
644 /* Ok, in this case we only have a correctable error.
645 * Indicate we only wish to capture that state in register
646 * %g1, and we only disable CE error reporting unlike UE
647 * handling which disables all errors.
649 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g3
650 andn %g3, ESTATE_ERR_CE, %g3
651 stxa %g3, [%g0] ASI_ESTATE_ERROR_EN
654 /* Preserve AFSR in %g4, indicate UDB state to capture in %g1 */
655 ba,pt %xcc, __spitfire_cee_trap_continue
658 .globl __spitfire_data_access_exception
659 .globl __spitfire_data_access_exception_tl1
660 __spitfire_data_access_exception_tl1:
662 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
665 ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
666 ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
667 stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
670 cmp %g3, 0x80 ! first win spill/fill trap
672 cmp %g3, 0xff ! last win spill/fill trap
675 ba,pt %xcc, winfix_dax
677 1: sethi %hi(109f), %g7
679 109: or %g7, %lo(109b), %g7
682 call spitfire_data_access_exception_tl1
683 add %sp, PTREGS_OFF, %o0
687 __spitfire_data_access_exception:
689 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
692 ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
693 ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
694 stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
698 109: or %g7, %lo(109b), %g7
701 call spitfire_data_access_exception
702 add %sp, PTREGS_OFF, %o0
706 .globl __spitfire_insn_access_exception
707 .globl __spitfire_insn_access_exception_tl1
708 __spitfire_insn_access_exception_tl1:
710 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
712 ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
713 rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
714 stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
718 109: or %g7, %lo(109b), %g7
721 call spitfire_insn_access_exception_tl1
722 add %sp, PTREGS_OFF, %o0
726 __spitfire_insn_access_exception:
728 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
730 ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
731 rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
732 stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
736 109: or %g7, %lo(109b), %g7
739 call spitfire_insn_access_exception
740 add %sp, PTREGS_OFF, %o0
744 /* These get patched into the trap table at boot time
745 * once we know we have a cheetah processor.
747 .globl cheetah_fecc_trap_vector, cheetah_fecc_trap_vector_tl1
748 cheetah_fecc_trap_vector:
750 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
751 andn %g1, DCU_DC | DCU_IC, %g1
752 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
754 sethi %hi(cheetah_fast_ecc), %g2
755 jmpl %g2 + %lo(cheetah_fast_ecc), %g0
757 cheetah_fecc_trap_vector_tl1:
759 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
760 andn %g1, DCU_DC | DCU_IC, %g1
761 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
763 sethi %hi(cheetah_fast_ecc), %g2
764 jmpl %g2 + %lo(cheetah_fast_ecc), %g0
766 .globl cheetah_cee_trap_vector, cheetah_cee_trap_vector_tl1
767 cheetah_cee_trap_vector:
769 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
770 andn %g1, DCU_IC, %g1
771 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
773 sethi %hi(cheetah_cee), %g2
774 jmpl %g2 + %lo(cheetah_cee), %g0
776 cheetah_cee_trap_vector_tl1:
778 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
779 andn %g1, DCU_IC, %g1
780 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
782 sethi %hi(cheetah_cee), %g2
783 jmpl %g2 + %lo(cheetah_cee), %g0
785 .globl cheetah_deferred_trap_vector, cheetah_deferred_trap_vector_tl1
786 cheetah_deferred_trap_vector:
788 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
789 andn %g1, DCU_DC | DCU_IC, %g1;
790 stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
792 sethi %hi(cheetah_deferred_trap), %g2
793 jmpl %g2 + %lo(cheetah_deferred_trap), %g0
795 cheetah_deferred_trap_vector_tl1:
797 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
798 andn %g1, DCU_DC | DCU_IC, %g1;
799 stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
801 sethi %hi(cheetah_deferred_trap), %g2
802 jmpl %g2 + %lo(cheetah_deferred_trap), %g0
805 /* Cheetah+ specific traps. These are for the new I/D cache parity
806 * error traps. The first argument to cheetah_plus_parity_handler
807 * is encoded as follows:
809 * Bit0: 0=dcache,1=icache
810 * Bit1: 0=recoverable,1=unrecoverable
812 .globl cheetah_plus_dcpe_trap_vector, cheetah_plus_dcpe_trap_vector_tl1
813 cheetah_plus_dcpe_trap_vector:
815 sethi %hi(do_cheetah_plus_data_parity), %g7
816 jmpl %g7 + %lo(do_cheetah_plus_data_parity), %g0
823 do_cheetah_plus_data_parity:
826 ba,pt %xcc, etrap_irq
829 call cheetah_plus_parity_error
830 add %sp, PTREGS_OFF, %o1
831 ba,a,pt %xcc, rtrap_irq
833 cheetah_plus_dcpe_trap_vector_tl1:
835 wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
836 sethi %hi(do_dcpe_tl1), %g3
837 jmpl %g3 + %lo(do_dcpe_tl1), %g0
843 .globl cheetah_plus_icpe_trap_vector, cheetah_plus_icpe_trap_vector_tl1
844 cheetah_plus_icpe_trap_vector:
846 sethi %hi(do_cheetah_plus_insn_parity), %g7
847 jmpl %g7 + %lo(do_cheetah_plus_insn_parity), %g0
854 do_cheetah_plus_insn_parity:
857 ba,pt %xcc, etrap_irq
860 call cheetah_plus_parity_error
861 add %sp, PTREGS_OFF, %o1
862 ba,a,pt %xcc, rtrap_irq
864 cheetah_plus_icpe_trap_vector_tl1:
866 wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
867 sethi %hi(do_icpe_tl1), %g3
868 jmpl %g3 + %lo(do_icpe_tl1), %g0
874 /* If we take one of these traps when tl >= 1, then we
875 * jump to interrupt globals. If some trap level above us
876 * was also using interrupt globals, we cannot recover.
877 * We may use all interrupt global registers except %g6.
879 .globl do_dcpe_tl1, do_icpe_tl1
881 rdpr %tl, %g1 ! Save original trap level
882 mov 1, %g2 ! Setup TSTATE checking loop
883 sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
884 1: wrpr %g2, %tl ! Set trap level to check
885 rdpr %tstate, %g4 ! Read TSTATE for this level
886 andcc %g4, %g3, %g0 ! Interrupt globals in use?
887 bne,a,pn %xcc, do_dcpe_tl1_fatal ! Yep, irrecoverable
888 wrpr %g1, %tl ! Restore original trap level
889 add %g2, 1, %g2 ! Next trap level
890 cmp %g2, %g1 ! Hit them all yet?
891 ble,pt %icc, 1b ! Not yet
893 wrpr %g1, %tl ! Restore original trap level
894 do_dcpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
895 sethi %hi(dcache_parity_tl1_occurred), %g2
896 lduw [%g2 + %lo(dcache_parity_tl1_occurred)], %g1
898 stw %g1, [%g2 + %lo(dcache_parity_tl1_occurred)]
899 /* Reset D-cache parity */
900 sethi %hi(1 << 16), %g1 ! D-cache size
901 mov (1 << 5), %g2 ! D-cache line size
902 sub %g1, %g2, %g1 ! Move down 1 cacheline
903 1: srl %g1, 14, %g3 ! Compute UTAG
905 stxa %g3, [%g1] ASI_DCACHE_UTAG
907 sub %g2, 8, %g3 ! 64-bit data word within line
909 stxa %g0, [%g1 + %g3] ASI_DCACHE_DATA
911 subcc %g3, 8, %g3 ! Next 64-bit data word
914 subcc %g1, %g2, %g1 ! Next cacheline
917 ba,pt %xcc, dcpe_icpe_tl1_common
923 1: or %g7, %lo(1b), %g7
925 call cheetah_plus_parity_error
926 add %sp, PTREGS_OFF, %o1
931 rdpr %tl, %g1 ! Save original trap level
932 mov 1, %g2 ! Setup TSTATE checking loop
933 sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
934 1: wrpr %g2, %tl ! Set trap level to check
935 rdpr %tstate, %g4 ! Read TSTATE for this level
936 andcc %g4, %g3, %g0 ! Interrupt globals in use?
937 bne,a,pn %xcc, do_icpe_tl1_fatal ! Yep, irrecoverable
938 wrpr %g1, %tl ! Restore original trap level
939 add %g2, 1, %g2 ! Next trap level
940 cmp %g2, %g1 ! Hit them all yet?
941 ble,pt %icc, 1b ! Not yet
943 wrpr %g1, %tl ! Restore original trap level
944 do_icpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
945 sethi %hi(icache_parity_tl1_occurred), %g2
946 lduw [%g2 + %lo(icache_parity_tl1_occurred)], %g1
948 stw %g1, [%g2 + %lo(icache_parity_tl1_occurred)]
950 sethi %hi(1 << 15), %g1 ! I-cache size
951 mov (1 << 5), %g2 ! I-cache line size
953 1: or %g1, (2 << 3), %g3
954 stxa %g0, [%g3] ASI_IC_TAG
959 ba,pt %xcc, dcpe_icpe_tl1_common
965 1: or %g7, %lo(1b), %g7
967 call cheetah_plus_parity_error
968 add %sp, PTREGS_OFF, %o1
972 dcpe_icpe_tl1_common:
973 /* Flush D-cache, re-enable D/I caches in DCU and finally
974 * retry the trapping instruction.
976 sethi %hi(1 << 16), %g1 ! D-cache size
977 mov (1 << 5), %g2 ! D-cache line size
979 1: stxa %g0, [%g1] ASI_DCACHE_TAG
984 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
985 or %g1, (DCU_DC | DCU_IC), %g1
986 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
990 /* Capture I/D/E-cache state into per-cpu error scoreboard.
992 * %g1: (TL>=0) ? 1 : 0
997 * %g6: unused, will have current thread ptr after etrap
1000 __cheetah_log_error:
1001 /* Put "TL1" software bit into AFSR. */
1006 /* Get log entry pointer for this cpu at this trap level. */
1007 BRANCH_IF_JALAPENO(g2,g3,50f)
1008 ldxa [%g0] ASI_SAFARI_CONFIG, %g2
1013 50: ldxa [%g0] ASI_JBUS_CONFIG, %g2
1017 60: sllx %g2, 9, %g2
1018 sethi %hi(cheetah_error_log), %g3
1019 ldx [%g3 + %lo(cheetah_error_log)], %g3
1027 /* %g1 holds pointer to the top of the logging scoreboard */
1028 ldx [%g1 + 0x0], %g7
1033 stx %g4, [%g1 + 0x0]
1034 stx %g5, [%g1 + 0x8]
1037 /* %g1 now points to D-cache logging area */
1038 set 0x3ff8, %g2 /* DC_addr mask */
1039 and %g5, %g2, %g2 /* DC_addr bits of AFAR */
1041 or %g3, 1, %g3 /* PHYS tag + valid */
1043 10: ldxa [%g2] ASI_DCACHE_TAG, %g7
1044 cmp %g3, %g7 /* TAG match? */
1048 /* Yep, what we want, capture state. */
1049 stx %g2, [%g1 + 0x20]
1050 stx %g7, [%g1 + 0x28]
1052 /* A membar Sync is required before and after utag access. */
1054 ldxa [%g2] ASI_DCACHE_UTAG, %g7
1056 stx %g7, [%g1 + 0x30]
1057 ldxa [%g2] ASI_DCACHE_SNOOP_TAG, %g7
1058 stx %g7, [%g1 + 0x38]
1061 12: ldxa [%g2 + %g3] ASI_DCACHE_DATA, %g7
1063 add %g3, (1 << 5), %g3
1071 13: sethi %hi(1 << 14), %g7
1080 /* %g1 now points to I-cache logging area */
1081 20: set 0x1fe0, %g2 /* IC_addr mask */
1082 and %g5, %g2, %g2 /* IC_addr bits of AFAR */
1083 sllx %g2, 1, %g2 /* IC_addr[13:6]==VA[12:5] */
1084 srlx %g5, (13 - 8), %g3 /* Make PTAG */
1085 andn %g3, 0xff, %g3 /* Mask off undefined bits */
1087 21: ldxa [%g2] ASI_IC_TAG, %g7
1093 /* Yep, what we want, capture state. */
1094 stx %g2, [%g1 + 0x40]
1095 stx %g7, [%g1 + 0x48]
1096 add %g2, (1 << 3), %g2
1097 ldxa [%g2] ASI_IC_TAG, %g7
1098 add %g2, (1 << 3), %g2
1099 stx %g7, [%g1 + 0x50]
1100 ldxa [%g2] ASI_IC_TAG, %g7
1101 add %g2, (1 << 3), %g2
1102 stx %g7, [%g1 + 0x60]
1103 ldxa [%g2] ASI_IC_TAG, %g7
1104 stx %g7, [%g1 + 0x68]
1105 sub %g2, (3 << 3), %g2
1106 ldxa [%g2] ASI_IC_STAG, %g7
1107 stx %g7, [%g1 + 0x58]
1111 22: ldxa [%g2 + %g3] ASI_IC_INSTR, %g7
1113 add %g3, (1 << 3), %g3
1121 23: sethi %hi(1 << 14), %g7
1130 /* %g1 now points to E-cache logging area */
1131 30: andn %g5, (32 - 1), %g2
1132 stx %g2, [%g1 + 0x20]
1133 ldxa [%g2] ASI_EC_TAG_DATA, %g7
1134 stx %g7, [%g1 + 0x28]
1135 ldxa [%g2] ASI_EC_R, %g0
1138 31: ldxa [%g3] ASI_EC_DATA, %g7
1139 stx %g7, [%g1 + %g3]
1152 ba,pt %xcc, c_deferred
1154 /* Cheetah FECC trap handling, we get here from tl{0,1}_fecc
1155 * in the trap table. That code has done a memory barrier
1156 * and has disabled both the I-cache and D-cache in the DCU
1157 * control register. The I-cache is disabled so that we may
1158 * capture the corrupted cache line, and the D-cache is disabled
1159 * because corrupt data may have been placed there and we don't
1160 * want to reference it.
1162 * %g1 is one if this trap occurred at %tl >= 1.
1164 * Next, we turn off error reporting so that we don't recurse.
1166 .globl cheetah_fast_ecc
1168 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1169 andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
1170 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1173 /* Fetch and clear AFSR/AFAR */
1174 ldxa [%g0] ASI_AFSR, %g4
1175 ldxa [%g0] ASI_AFAR, %g5
1176 stxa %g4, [%g0] ASI_AFSR
1179 ba,pt %xcc, __cheetah_log_error
1185 ba,pt %xcc, etrap_irq
1189 call cheetah_fecc_handler
1190 add %sp, PTREGS_OFF, %o0
1191 ba,a,pt %xcc, rtrap_irq
1193 /* Our caller has disabled I-cache and performed membar Sync. */
1196 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1197 andn %g2, ESTATE_ERROR_CEEN, %g2
1198 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1201 /* Fetch and clear AFSR/AFAR */
1202 ldxa [%g0] ASI_AFSR, %g4
1203 ldxa [%g0] ASI_AFAR, %g5
1204 stxa %g4, [%g0] ASI_AFSR
1207 ba,pt %xcc, __cheetah_log_error
1213 ba,pt %xcc, etrap_irq
1217 call cheetah_cee_handler
1218 add %sp, PTREGS_OFF, %o0
1219 ba,a,pt %xcc, rtrap_irq
1221 /* Our caller has disabled I-cache+D-cache and performed membar Sync. */
1222 .globl cheetah_deferred_trap
1223 cheetah_deferred_trap:
1224 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1225 andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
1226 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1229 /* Fetch and clear AFSR/AFAR */
1230 ldxa [%g0] ASI_AFSR, %g4
1231 ldxa [%g0] ASI_AFAR, %g5
1232 stxa %g4, [%g0] ASI_AFSR
1235 ba,pt %xcc, __cheetah_log_error
1241 ba,pt %xcc, etrap_irq
1245 call cheetah_deferred_handler
1246 add %sp, PTREGS_OFF, %o0
1247 ba,a,pt %xcc, rtrap_irq
1252 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
1254 sethi %hi(109f), %g7
1256 109: or %g7, %lo(109b), %g7
1258 add %sp, PTREGS_OFF, %o0
1267 /* Setup %g4/%g5 now as they are used in the
1272 ldxa [%g4] ASI_DMMU, %g4
1273 ldxa [%g3] ASI_DMMU, %g5
1274 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
1276 bgu,pn %icc, winfix_mna
1279 1: sethi %hi(109f), %g7
1281 109: or %g7, %lo(109b), %g7
1284 call mem_address_unaligned
1285 add %sp, PTREGS_OFF, %o0
1291 sethi %hi(109f), %g7
1293 ldxa [%g4] ASI_DMMU, %g5
1294 stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
1297 ldxa [%g4] ASI_DMMU, %g4
1299 109: or %g7, %lo(109b), %g7
1303 add %sp, PTREGS_OFF, %o0
1309 sethi %hi(109f), %g7
1311 ldxa [%g4] ASI_DMMU, %g5
1312 stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
1315 ldxa [%g4] ASI_DMMU, %g4
1317 109: or %g7, %lo(109b), %g7
1321 add %sp, PTREGS_OFF, %o0
1325 .globl breakpoint_trap
1327 call sparc_breakpoint
1328 add %sp, PTREGS_OFF, %o0
1332 #if defined(CONFIG_SUNOS_EMUL) || defined(CONFIG_SOLARIS_EMUL) || \
1333 defined(CONFIG_SOLARIS_EMUL_MODULE)
1334 /* SunOS uses syscall zero as the 'indirect syscall' it looks
1335 * like indir_syscall(scall_num, arg0, arg1, arg2...); etc.
1336 * This is complete brain damage.
1342 cmp %o0, NR_SYSCALLS
1345 sethi %hi(sunos_nosys), %l6
1347 or %l6, %lo(sunos_nosys), %l6
1348 1: sethi %hi(sunos_sys_table), %l7
1349 or %l7, %lo(sunos_sys_table), %l7
1350 lduw [%l7 + %o0], %l6
1364 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1365 b,pt %xcc, ret_sys_call
1366 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1368 /* SunOS getuid() returns uid in %o0 and euid in %o1 */
1371 call sys32_geteuid16
1374 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1375 b,pt %xcc, ret_sys_call
1376 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1378 /* SunOS getgid() returns gid in %o0 and egid in %o1 */
1381 call sys32_getegid16
1384 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1385 b,pt %xcc, ret_sys_call
1386 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1389 /* SunOS's execv() call only specifies the argv argument, the
1390 * environment settings are the same as the calling processes.
1394 sethi %hi(sparc_execve), %g1
1395 ba,pt %xcc, execve_merge
1396 or %g1, %lo(sparc_execve), %g1
1397 #ifdef CONFIG_COMPAT
1400 stx %g0, [%sp + PTREGS_OFF + PT_V9_I2]
1403 sethi %hi(sparc32_execve), %g1
1404 or %g1, %lo(sparc32_execve), %g1
1409 add %sp, PTREGS_OFF, %o0
1411 .globl sys_pipe, sys_sigpause, sys_nis_syscall
1412 .globl sys_rt_sigreturn
1414 .globl sys_sigaltstack
1416 sys_pipe: ba,pt %xcc, sparc_pipe
1417 add %sp, PTREGS_OFF, %o0
1418 sys_nis_syscall:ba,pt %xcc, c_sys_nis_syscall
1419 add %sp, PTREGS_OFF, %o0
1420 sys_memory_ordering:
1421 ba,pt %xcc, sparc_memory_ordering
1422 add %sp, PTREGS_OFF, %o1
1423 sys_sigaltstack:ba,pt %xcc, do_sigaltstack
1424 add %i6, STACK_BIAS, %o2
1425 #ifdef CONFIG_COMPAT
1426 .globl sys32_sigstack
1427 sys32_sigstack: ba,pt %xcc, do_sys32_sigstack
1429 .globl sys32_sigaltstack
1431 ba,pt %xcc, do_sys32_sigaltstack
1435 #ifdef CONFIG_COMPAT
1436 .globl sys32_sigreturn
1438 add %sp, PTREGS_OFF, %o0
1440 add %o7, 1f-.-4, %o7
1444 add %sp, PTREGS_OFF, %o0
1445 call do_rt_sigreturn
1446 add %o7, 1f-.-4, %o7
1448 #ifdef CONFIG_COMPAT
1449 .globl sys32_rt_sigreturn
1451 add %sp, PTREGS_OFF, %o0
1452 call do_rt_sigreturn32
1453 add %o7, 1f-.-4, %o7
1456 sys_ptrace: add %sp, PTREGS_OFF, %o0
1458 add %o7, 1f-.-4, %o7
1461 1: ldx [%curptr + TI_FLAGS], %l5
1462 andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1465 add %sp, PTREGS_OFF, %o0
1472 /* This is how fork() was meant to be done, 8 instruction entry.
1474 * I questioned the following code briefly, let me clear things
1475 * up so you must not reason on it like I did.
1477 * Know the fork_kpsr etc. we use in the sparc32 port? We don't
1478 * need it here because the only piece of window state we copy to
1479 * the child is the CWP register. Even if the parent sleeps,
1480 * we are safe because we stuck it into pt_regs of the parent
1481 * so it will not change.
1483 * XXX This raises the question, whether we can do the same on
1484 * XXX sparc32 to get rid of fork_kpsr _and_ fork_kwim. The
1485 * XXX answer is yes. We stick fork_kpsr in UREG_G0 and
1486 * XXX fork_kwim in UREG_G1 (global registers are considered
1487 * XXX volatile across a system call in the sparc ABI I think
1488 * XXX if it isn't we can use regs->y instead, anyone who depends
1489 * XXX upon the Y register being preserved across a fork deserves
1492 * In fact we should take advantage of that fact for other things
1493 * during system calls...
1495 .globl sys_fork, sys_vfork, sys_clone, sparc_exit
1496 .globl ret_from_syscall
1498 sys_vfork: /* Under Linux, vfork and fork are just special cases of clone. */
1499 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1500 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1501 ba,pt %xcc, sys_clone
1507 ba,pt %xcc, sparc_do_fork
1508 add %sp, PTREGS_OFF, %o2
1510 /* Clear current_thread_info()->new_child, and
1511 * check performance counter stuff too.
1513 stb %g0, [%g6 + TI_NEW_CHILD]
1514 ldx [%g6 + TI_FLAGS], %l0
1517 andcc %l0, _TIF_PERFCTR, %g0
1520 ldx [%g6 + TI_PCR], %o7
1523 /* Blackbird errata workaround. See commentary in
1524 * smp.c:smp_percpu_timer_interrupt() for more
1530 99: wr %g0, %g0, %pic
1533 1: b,pt %xcc, ret_sys_call
1534 ldx [%sp + PTREGS_OFF + PT_V9_I0], %o0
1535 sparc_exit: rdpr %pstate, %g2
1536 wrpr %g2, PSTATE_IE, %pstate
1540 wrpr %g3, 0x0, %cansave
1541 wrpr %g0, 0x0, %otherwin
1542 wrpr %g2, 0x0, %pstate
1543 ba,pt %xcc, sys_exit
1544 stb %g0, [%g6 + TI_WSAVED]
1546 linux_sparc_ni_syscall:
1547 sethi %hi(sys_ni_syscall), %l7
1549 or %l7, %lo(sys_ni_syscall), %l7
1551 linux_syscall_trace32:
1552 add %sp, PTREGS_OFF, %o0
1562 linux_syscall_trace:
1563 add %sp, PTREGS_OFF, %o0
1574 /* Linux 32-bit and SunOS system calls enter here... */
1576 .globl linux_sparc_syscall32
1577 linux_sparc_syscall32:
1578 /* Direct access to user regs, much faster. */
1579 cmp %g1, NR_SYSCALLS ! IEU1 Group
1580 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
1581 srl %i0, 0, %o0 ! IEU0
1582 sll %g1, 2, %l4 ! IEU0 Group
1583 srl %i4, 0, %o4 ! IEU1
1584 lduw [%l7 + %l4], %l7 ! Load
1585 srl %i1, 0, %o1 ! IEU0 Group
1586 ldx [%curptr + TI_FLAGS], %l0 ! Load
1588 srl %i5, 0, %o5 ! IEU1
1589 srl %i2, 0, %o2 ! IEU0 Group
1590 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1591 bne,pn %icc, linux_syscall_trace32 ! CTI
1593 call %l7 ! CTI Group brk forced
1594 srl %i3, 0, %o3 ! IEU0
1597 /* Linux native and SunOS system calls enter here... */
1599 .globl linux_sparc_syscall, ret_sys_call
1600 linux_sparc_syscall:
1601 /* Direct access to user regs, much faster. */
1602 cmp %g1, NR_SYSCALLS ! IEU1 Group
1603 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
1605 sll %g1, 2, %l4 ! IEU0 Group
1607 lduw [%l7 + %l4], %l7 ! Load
1608 4: mov %i2, %o2 ! IEU0 Group
1609 ldx [%curptr + TI_FLAGS], %l0 ! Load
1612 mov %i4, %o4 ! IEU0 Group
1613 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1614 bne,pn %icc, linux_syscall_trace ! CTI Group
1616 2: call %l7 ! CTI Group brk forced
1620 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1622 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
1623 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
1625 mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
1628 /* Check if force_successful_syscall_return()
1631 ldub [%curptr + TI_SYS_NOERROR], %l2
1633 stb %g0, [%curptr + TI_SYS_NOERROR]
1635 cmp %o0, -ERESTART_RESTARTBLOCK
1637 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
1639 /* System call success, clear Carry condition code. */
1641 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
1642 bne,pn %icc, linux_syscall_trace2
1643 add %l1, 0x4, %l2 ! npc = npc+4
1644 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1645 ba,pt %xcc, rtrap_clr_l6
1646 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1649 /* System call failure, set Carry condition code.
1650 * Also, get abs(errno) to return to the process.
1652 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
1655 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1657 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
1658 bne,pn %icc, linux_syscall_trace2
1659 add %l1, 0x4, %l2 ! npc = npc+4
1660 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1663 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1664 linux_syscall_trace2:
1665 add %sp, PTREGS_OFF, %o0
1668 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1670 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1673 .globl __flushw_user
1678 1: save %sp, -128, %sp
1684 restore %g0, %g0, %g0
1689 .globl hard_smp_processor_id
1690 hard_smp_processor_id:
1692 .globl real_hard_smp_processor_id
1693 real_hard_smp_processor_id:
1701 * returns %o0: sysino
1703 .globl sun4v_devino_to_sysino
1704 sun4v_devino_to_sysino:
1705 mov HV_FAST_INTR_DEVINO2SYSINO, %o5
1712 * returns %o0: intr_enabled (HV_INTR_{DISABLED,ENABLED})
1714 .globl sun4v_intr_getenabled
1715 sun4v_intr_getenabled:
1716 mov HV_FAST_INTR_GETENABLED, %o5
1722 * %o1: intr_enabled (HV_INTR_{DISABLED,ENABLED})
1724 .globl sun4v_intr_setenabled
1725 sun4v_intr_setenabled:
1726 mov HV_FAST_INTR_SETENABLED, %o5
1733 * returns %o0: intr_state (HV_INTR_STATE_*)
1735 .globl sun4v_intr_getstate
1736 sun4v_intr_getstate:
1737 mov HV_FAST_INTR_GETSTATE, %o5
1743 * %o1: intr_state (HV_INTR_STATE_*)
1745 .globl sun4v_intr_setstate
1746 sun4v_intr_setstate:
1747 mov HV_FAST_INTR_SETSTATE, %o5
1754 * returns %o0: cpuid
1756 .globl sun4v_intr_gettarget
1757 sun4v_intr_gettarget:
1758 mov HV_FAST_INTR_GETTARGET, %o5
1766 .globl sun4v_intr_settarget
1767 sun4v_intr_settarget:
1768 mov HV_FAST_INTR_SETTARGET, %o5
1775 * %o2: num queue entries
1777 * returns %o0: status
1779 .globl sun4v_cpu_qconf
1781 mov HV_FAST_CPU_QCONF, %o5
1786 /* returns %o0: status
1788 .globl sun4v_cpu_yield
1790 mov HV_FAST_CPU_YIELD, %o5
1795 /* %o0: num cpus in cpu list
1796 * %o1: cpu list paddr
1797 * %o2: mondo block paddr
1799 * returns %o0: status
1801 .globl sun4v_cpu_mondo_send
1802 sun4v_cpu_mondo_send:
1803 mov HV_FAST_CPU_MONDO_SEND, %o5
1810 * returns %o0: -status if status non-zero, else
1811 * %o0: cpu state as HV_CPU_STATE_*
1813 .globl sun4v_cpu_state
1815 mov HV_FAST_CPU_STATE, %o5