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 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
437 ldub [%g3 + 0x04], %g4 /* pil */
442 TRAP_LOAD_IRQ_WORK(%g6, %g1)
444 lduw [%g6 + %g4], %g5 /* g5 = irq_work(cpu, pil) */
445 stw %g5, [%g3 + 0x00] /* bucket->irq_chain = g5 */
446 stw %g3, [%g6 + %g4] /* irq_work(cpu, pil) = bucket */
447 wr %g2, 0x0, %set_softint
451 ldxa [%g1 + %g0] ASI_INTR_R, %g1
455 ldxa [%g7 + %g0] ASI_INTR_R, %g7
456 stxa %g0, [%g0] ASI_INTR_RECEIVE
467 ldx [%o0 + PT_V9_TSTATE], %o1
471 stx %o1, [%o0 + PT_V9_G1]
473 ldx [%o0 + PT_V9_TSTATE], %o1
474 ldx [%o0 + PT_V9_G1], %o2
475 or %g0, %ulo(TSTATE_ICC), %o3
482 stx %o1, [%o0 + PT_V9_TSTATE]
485 utrap_trap: /* %g3=handler,%g4=level */
486 TRAP_LOAD_THREAD_REG(%g6, %g1)
487 ldx [%g6 + TI_UTRAPS], %g1
488 brnz,pt %g1, invoke_utrap
495 add %sp, PTREGS_OFF, %o0
505 andn %l6, TSTATE_CWP, %l6
506 wrpr %l6, %l7, %tstate
512 /* We need to carefully read the error status, ACK
513 * the errors, prevent recursive traps, and pass the
514 * information on to C code for logging.
516 * We pass the AFAR in as-is, and we encode the status
517 * information as described in asm-sparc64/sfafsr.h
519 .globl __spitfire_access_error
520 __spitfire_access_error:
521 /* Disable ESTATE error reporting so that we do not
522 * take recursive traps and RED state the processor.
524 stxa %g0, [%g0] ASI_ESTATE_ERROR_EN
528 ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
530 /* __spitfire_cee_trap branches here with AFSR in %g4 and
531 * UDBE_CE in %g1. It only clears ESTATE_ERR_CE in the
532 * ESTATE Error Enable register.
534 __spitfire_cee_trap_continue:
535 ldxa [%g0] ASI_AFAR, %g5 ! Get AFAR
538 and %g3, 0x1ff, %g3 ! Paranoia
539 sllx %g3, SFSTAT_TRAP_TYPE_SHIFT, %g3
545 sllx %g3, SFSTAT_TL_GT_ONE_SHIFT, %g3
549 /* Read in the UDB error register state, clearing the
550 * sticky error bits as-needed. We only clear them if
551 * the UE bit is set. Likewise, __spitfire_cee_trap
552 * below will only do so if the CE bit is set.
554 * NOTE: UltraSparc-I/II have high and low UDB error
555 * registers, corresponding to the two UDB units
556 * present on those chips. UltraSparc-IIi only
557 * has a single UDB, called "SDB" in the manual.
558 * For IIi the upper UDB register always reads
559 * as zero so for our purposes things will just
560 * work with the checks below.
562 1: ldxa [%g0] ASI_UDBH_ERROR_R, %g3
563 and %g3, 0x3ff, %g7 ! Paranoia
564 sllx %g7, SFSTAT_UDBH_SHIFT, %g7
566 andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
569 stxa %g3, [%g0] ASI_UDB_ERROR_W
573 ldxa [%g3] ASI_UDBL_ERROR_R, %g3
574 and %g3, 0x3ff, %g7 ! Paranoia
575 sllx %g7, SFSTAT_UDBL_SHIFT, %g7
577 andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
581 stxa %g3, [%g7] ASI_UDB_ERROR_W
584 1: /* Ok, now that we've latched the error state,
585 * clear the sticky bits in the AFSR.
587 stxa %g4, [%g0] ASI_AFSR
602 1: ba,pt %xcc, etrap_irq
607 call spitfire_access_error
608 add %sp, PTREGS_OFF, %o0
612 /* This is the trap handler entry point for ECC correctable
613 * errors. They are corrected, but we listen for the trap
614 * so that the event can be logged.
616 * Disrupting errors are either:
617 * 1) single-bit ECC errors during UDB reads to system
619 * 2) data parity errors during write-back events
621 * As far as I can make out from the manual, the CEE trap
622 * is only for correctable errors during memory read
623 * accesses by the front-end of the processor.
625 * The code below is only for trap level 1 CEE events,
626 * as it is the only situation where we can safely record
627 * and log. For trap level >1 we just clear the CE bit
628 * in the AFSR and return.
630 * This is just like __spiftire_access_error above, but it
631 * specifically handles correctable errors. If an
632 * uncorrectable error is indicated in the AFSR we
633 * will branch directly above to __spitfire_access_error
634 * to handle it instead. Uncorrectable therefore takes
635 * priority over correctable, and the error logging
636 * C code will notice this case by inspecting the
639 .globl __spitfire_cee_trap
641 ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
643 sllx %g3, SFAFSR_UE_SHIFT, %g3
644 andcc %g4, %g3, %g0 ! Check for UE
645 bne,pn %xcc, __spitfire_access_error
648 /* Ok, in this case we only have a correctable error.
649 * Indicate we only wish to capture that state in register
650 * %g1, and we only disable CE error reporting unlike UE
651 * handling which disables all errors.
653 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g3
654 andn %g3, ESTATE_ERR_CE, %g3
655 stxa %g3, [%g0] ASI_ESTATE_ERROR_EN
658 /* Preserve AFSR in %g4, indicate UDB state to capture in %g1 */
659 ba,pt %xcc, __spitfire_cee_trap_continue
662 .globl __spitfire_data_access_exception
663 .globl __spitfire_data_access_exception_tl1
664 __spitfire_data_access_exception_tl1:
666 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
669 ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
670 ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
671 stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
674 cmp %g3, 0x80 ! first win spill/fill trap
676 cmp %g3, 0xff ! last win spill/fill trap
679 ba,pt %xcc, winfix_dax
681 1: sethi %hi(109f), %g7
683 109: or %g7, %lo(109b), %g7
686 call spitfire_data_access_exception_tl1
687 add %sp, PTREGS_OFF, %o0
691 __spitfire_data_access_exception:
693 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
696 ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
697 ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
698 stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
702 109: or %g7, %lo(109b), %g7
705 call spitfire_data_access_exception
706 add %sp, PTREGS_OFF, %o0
710 .globl __spitfire_insn_access_exception
711 .globl __spitfire_insn_access_exception_tl1
712 __spitfire_insn_access_exception_tl1:
714 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
716 ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
717 rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
718 stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
722 109: or %g7, %lo(109b), %g7
725 call spitfire_insn_access_exception_tl1
726 add %sp, PTREGS_OFF, %o0
730 __spitfire_insn_access_exception:
732 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
734 ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
735 rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
736 stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
740 109: or %g7, %lo(109b), %g7
743 call spitfire_insn_access_exception
744 add %sp, PTREGS_OFF, %o0
748 /* These get patched into the trap table at boot time
749 * once we know we have a cheetah processor.
751 .globl cheetah_fecc_trap_vector, cheetah_fecc_trap_vector_tl1
752 cheetah_fecc_trap_vector:
754 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
755 andn %g1, DCU_DC | DCU_IC, %g1
756 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
758 sethi %hi(cheetah_fast_ecc), %g2
759 jmpl %g2 + %lo(cheetah_fast_ecc), %g0
761 cheetah_fecc_trap_vector_tl1:
763 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
764 andn %g1, DCU_DC | DCU_IC, %g1
765 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
767 sethi %hi(cheetah_fast_ecc), %g2
768 jmpl %g2 + %lo(cheetah_fast_ecc), %g0
770 .globl cheetah_cee_trap_vector, cheetah_cee_trap_vector_tl1
771 cheetah_cee_trap_vector:
773 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
774 andn %g1, DCU_IC, %g1
775 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
777 sethi %hi(cheetah_cee), %g2
778 jmpl %g2 + %lo(cheetah_cee), %g0
780 cheetah_cee_trap_vector_tl1:
782 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
783 andn %g1, DCU_IC, %g1
784 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
786 sethi %hi(cheetah_cee), %g2
787 jmpl %g2 + %lo(cheetah_cee), %g0
789 .globl cheetah_deferred_trap_vector, cheetah_deferred_trap_vector_tl1
790 cheetah_deferred_trap_vector:
792 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
793 andn %g1, DCU_DC | DCU_IC, %g1;
794 stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
796 sethi %hi(cheetah_deferred_trap), %g2
797 jmpl %g2 + %lo(cheetah_deferred_trap), %g0
799 cheetah_deferred_trap_vector_tl1:
801 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
802 andn %g1, DCU_DC | DCU_IC, %g1;
803 stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
805 sethi %hi(cheetah_deferred_trap), %g2
806 jmpl %g2 + %lo(cheetah_deferred_trap), %g0
809 /* Cheetah+ specific traps. These are for the new I/D cache parity
810 * error traps. The first argument to cheetah_plus_parity_handler
811 * is encoded as follows:
813 * Bit0: 0=dcache,1=icache
814 * Bit1: 0=recoverable,1=unrecoverable
816 .globl cheetah_plus_dcpe_trap_vector, cheetah_plus_dcpe_trap_vector_tl1
817 cheetah_plus_dcpe_trap_vector:
819 sethi %hi(do_cheetah_plus_data_parity), %g7
820 jmpl %g7 + %lo(do_cheetah_plus_data_parity), %g0
827 do_cheetah_plus_data_parity:
830 ba,pt %xcc, etrap_irq
833 call cheetah_plus_parity_error
834 add %sp, PTREGS_OFF, %o1
835 ba,a,pt %xcc, rtrap_irq
837 cheetah_plus_dcpe_trap_vector_tl1:
839 wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
840 sethi %hi(do_dcpe_tl1), %g3
841 jmpl %g3 + %lo(do_dcpe_tl1), %g0
847 .globl cheetah_plus_icpe_trap_vector, cheetah_plus_icpe_trap_vector_tl1
848 cheetah_plus_icpe_trap_vector:
850 sethi %hi(do_cheetah_plus_insn_parity), %g7
851 jmpl %g7 + %lo(do_cheetah_plus_insn_parity), %g0
858 do_cheetah_plus_insn_parity:
861 ba,pt %xcc, etrap_irq
864 call cheetah_plus_parity_error
865 add %sp, PTREGS_OFF, %o1
866 ba,a,pt %xcc, rtrap_irq
868 cheetah_plus_icpe_trap_vector_tl1:
870 wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
871 sethi %hi(do_icpe_tl1), %g3
872 jmpl %g3 + %lo(do_icpe_tl1), %g0
878 /* If we take one of these traps when tl >= 1, then we
879 * jump to interrupt globals. If some trap level above us
880 * was also using interrupt globals, we cannot recover.
881 * We may use all interrupt global registers except %g6.
883 .globl do_dcpe_tl1, do_icpe_tl1
885 rdpr %tl, %g1 ! Save original trap level
886 mov 1, %g2 ! Setup TSTATE checking loop
887 sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
888 1: wrpr %g2, %tl ! Set trap level to check
889 rdpr %tstate, %g4 ! Read TSTATE for this level
890 andcc %g4, %g3, %g0 ! Interrupt globals in use?
891 bne,a,pn %xcc, do_dcpe_tl1_fatal ! Yep, irrecoverable
892 wrpr %g1, %tl ! Restore original trap level
893 add %g2, 1, %g2 ! Next trap level
894 cmp %g2, %g1 ! Hit them all yet?
895 ble,pt %icc, 1b ! Not yet
897 wrpr %g1, %tl ! Restore original trap level
898 do_dcpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
899 sethi %hi(dcache_parity_tl1_occurred), %g2
900 lduw [%g2 + %lo(dcache_parity_tl1_occurred)], %g1
902 stw %g1, [%g2 + %lo(dcache_parity_tl1_occurred)]
903 /* Reset D-cache parity */
904 sethi %hi(1 << 16), %g1 ! D-cache size
905 mov (1 << 5), %g2 ! D-cache line size
906 sub %g1, %g2, %g1 ! Move down 1 cacheline
907 1: srl %g1, 14, %g3 ! Compute UTAG
909 stxa %g3, [%g1] ASI_DCACHE_UTAG
911 sub %g2, 8, %g3 ! 64-bit data word within line
913 stxa %g0, [%g1 + %g3] ASI_DCACHE_DATA
915 subcc %g3, 8, %g3 ! Next 64-bit data word
918 subcc %g1, %g2, %g1 ! Next cacheline
921 ba,pt %xcc, dcpe_icpe_tl1_common
927 1: or %g7, %lo(1b), %g7
929 call cheetah_plus_parity_error
930 add %sp, PTREGS_OFF, %o1
935 rdpr %tl, %g1 ! Save original trap level
936 mov 1, %g2 ! Setup TSTATE checking loop
937 sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
938 1: wrpr %g2, %tl ! Set trap level to check
939 rdpr %tstate, %g4 ! Read TSTATE for this level
940 andcc %g4, %g3, %g0 ! Interrupt globals in use?
941 bne,a,pn %xcc, do_icpe_tl1_fatal ! Yep, irrecoverable
942 wrpr %g1, %tl ! Restore original trap level
943 add %g2, 1, %g2 ! Next trap level
944 cmp %g2, %g1 ! Hit them all yet?
945 ble,pt %icc, 1b ! Not yet
947 wrpr %g1, %tl ! Restore original trap level
948 do_icpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
949 sethi %hi(icache_parity_tl1_occurred), %g2
950 lduw [%g2 + %lo(icache_parity_tl1_occurred)], %g1
952 stw %g1, [%g2 + %lo(icache_parity_tl1_occurred)]
954 sethi %hi(1 << 15), %g1 ! I-cache size
955 mov (1 << 5), %g2 ! I-cache line size
957 1: or %g1, (2 << 3), %g3
958 stxa %g0, [%g3] ASI_IC_TAG
963 ba,pt %xcc, dcpe_icpe_tl1_common
969 1: or %g7, %lo(1b), %g7
971 call cheetah_plus_parity_error
972 add %sp, PTREGS_OFF, %o1
976 dcpe_icpe_tl1_common:
977 /* Flush D-cache, re-enable D/I caches in DCU and finally
978 * retry the trapping instruction.
980 sethi %hi(1 << 16), %g1 ! D-cache size
981 mov (1 << 5), %g2 ! D-cache line size
983 1: stxa %g0, [%g1] ASI_DCACHE_TAG
988 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
989 or %g1, (DCU_DC | DCU_IC), %g1
990 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
994 /* Capture I/D/E-cache state into per-cpu error scoreboard.
996 * %g1: (TL>=0) ? 1 : 0
1001 * %g6: unused, will have current thread ptr after etrap
1004 __cheetah_log_error:
1005 /* Put "TL1" software bit into AFSR. */
1010 /* Get log entry pointer for this cpu at this trap level. */
1011 BRANCH_IF_JALAPENO(g2,g3,50f)
1012 ldxa [%g0] ASI_SAFARI_CONFIG, %g2
1017 50: ldxa [%g0] ASI_JBUS_CONFIG, %g2
1021 60: sllx %g2, 9, %g2
1022 sethi %hi(cheetah_error_log), %g3
1023 ldx [%g3 + %lo(cheetah_error_log)], %g3
1031 /* %g1 holds pointer to the top of the logging scoreboard */
1032 ldx [%g1 + 0x0], %g7
1037 stx %g4, [%g1 + 0x0]
1038 stx %g5, [%g1 + 0x8]
1041 /* %g1 now points to D-cache logging area */
1042 set 0x3ff8, %g2 /* DC_addr mask */
1043 and %g5, %g2, %g2 /* DC_addr bits of AFAR */
1045 or %g3, 1, %g3 /* PHYS tag + valid */
1047 10: ldxa [%g2] ASI_DCACHE_TAG, %g7
1048 cmp %g3, %g7 /* TAG match? */
1052 /* Yep, what we want, capture state. */
1053 stx %g2, [%g1 + 0x20]
1054 stx %g7, [%g1 + 0x28]
1056 /* A membar Sync is required before and after utag access. */
1058 ldxa [%g2] ASI_DCACHE_UTAG, %g7
1060 stx %g7, [%g1 + 0x30]
1061 ldxa [%g2] ASI_DCACHE_SNOOP_TAG, %g7
1062 stx %g7, [%g1 + 0x38]
1065 12: ldxa [%g2 + %g3] ASI_DCACHE_DATA, %g7
1067 add %g3, (1 << 5), %g3
1075 13: sethi %hi(1 << 14), %g7
1084 /* %g1 now points to I-cache logging area */
1085 20: set 0x1fe0, %g2 /* IC_addr mask */
1086 and %g5, %g2, %g2 /* IC_addr bits of AFAR */
1087 sllx %g2, 1, %g2 /* IC_addr[13:6]==VA[12:5] */
1088 srlx %g5, (13 - 8), %g3 /* Make PTAG */
1089 andn %g3, 0xff, %g3 /* Mask off undefined bits */
1091 21: ldxa [%g2] ASI_IC_TAG, %g7
1097 /* Yep, what we want, capture state. */
1098 stx %g2, [%g1 + 0x40]
1099 stx %g7, [%g1 + 0x48]
1100 add %g2, (1 << 3), %g2
1101 ldxa [%g2] ASI_IC_TAG, %g7
1102 add %g2, (1 << 3), %g2
1103 stx %g7, [%g1 + 0x50]
1104 ldxa [%g2] ASI_IC_TAG, %g7
1105 add %g2, (1 << 3), %g2
1106 stx %g7, [%g1 + 0x60]
1107 ldxa [%g2] ASI_IC_TAG, %g7
1108 stx %g7, [%g1 + 0x68]
1109 sub %g2, (3 << 3), %g2
1110 ldxa [%g2] ASI_IC_STAG, %g7
1111 stx %g7, [%g1 + 0x58]
1115 22: ldxa [%g2 + %g3] ASI_IC_INSTR, %g7
1117 add %g3, (1 << 3), %g3
1125 23: sethi %hi(1 << 14), %g7
1134 /* %g1 now points to E-cache logging area */
1135 30: andn %g5, (32 - 1), %g2
1136 stx %g2, [%g1 + 0x20]
1137 ldxa [%g2] ASI_EC_TAG_DATA, %g7
1138 stx %g7, [%g1 + 0x28]
1139 ldxa [%g2] ASI_EC_R, %g0
1142 31: ldxa [%g3] ASI_EC_DATA, %g7
1143 stx %g7, [%g1 + %g3]
1156 ba,pt %xcc, c_deferred
1158 /* Cheetah FECC trap handling, we get here from tl{0,1}_fecc
1159 * in the trap table. That code has done a memory barrier
1160 * and has disabled both the I-cache and D-cache in the DCU
1161 * control register. The I-cache is disabled so that we may
1162 * capture the corrupted cache line, and the D-cache is disabled
1163 * because corrupt data may have been placed there and we don't
1164 * want to reference it.
1166 * %g1 is one if this trap occurred at %tl >= 1.
1168 * Next, we turn off error reporting so that we don't recurse.
1170 .globl cheetah_fast_ecc
1172 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1173 andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
1174 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1177 /* Fetch and clear AFSR/AFAR */
1178 ldxa [%g0] ASI_AFSR, %g4
1179 ldxa [%g0] ASI_AFAR, %g5
1180 stxa %g4, [%g0] ASI_AFSR
1183 ba,pt %xcc, __cheetah_log_error
1189 ba,pt %xcc, etrap_irq
1193 call cheetah_fecc_handler
1194 add %sp, PTREGS_OFF, %o0
1195 ba,a,pt %xcc, rtrap_irq
1197 /* Our caller has disabled I-cache and performed membar Sync. */
1200 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1201 andn %g2, ESTATE_ERROR_CEEN, %g2
1202 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1205 /* Fetch and clear AFSR/AFAR */
1206 ldxa [%g0] ASI_AFSR, %g4
1207 ldxa [%g0] ASI_AFAR, %g5
1208 stxa %g4, [%g0] ASI_AFSR
1211 ba,pt %xcc, __cheetah_log_error
1217 ba,pt %xcc, etrap_irq
1221 call cheetah_cee_handler
1222 add %sp, PTREGS_OFF, %o0
1223 ba,a,pt %xcc, rtrap_irq
1225 /* Our caller has disabled I-cache+D-cache and performed membar Sync. */
1226 .globl cheetah_deferred_trap
1227 cheetah_deferred_trap:
1228 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1229 andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
1230 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1233 /* Fetch and clear AFSR/AFAR */
1234 ldxa [%g0] ASI_AFSR, %g4
1235 ldxa [%g0] ASI_AFAR, %g5
1236 stxa %g4, [%g0] ASI_AFSR
1239 ba,pt %xcc, __cheetah_log_error
1245 ba,pt %xcc, etrap_irq
1249 call cheetah_deferred_handler
1250 add %sp, PTREGS_OFF, %o0
1251 ba,a,pt %xcc, rtrap_irq
1256 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
1258 sethi %hi(109f), %g7
1260 109: or %g7, %lo(109b), %g7
1262 add %sp, PTREGS_OFF, %o0
1271 /* Setup %g4/%g5 now as they are used in the
1276 ldxa [%g4] ASI_DMMU, %g4
1277 ldxa [%g3] ASI_DMMU, %g5
1278 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
1280 bgu,pn %icc, winfix_mna
1283 1: sethi %hi(109f), %g7
1285 109: or %g7, %lo(109b), %g7
1288 call mem_address_unaligned
1289 add %sp, PTREGS_OFF, %o0
1295 sethi %hi(109f), %g7
1297 ldxa [%g4] ASI_DMMU, %g5
1298 stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
1301 ldxa [%g4] ASI_DMMU, %g4
1303 109: or %g7, %lo(109b), %g7
1307 add %sp, PTREGS_OFF, %o0
1313 sethi %hi(109f), %g7
1315 ldxa [%g4] ASI_DMMU, %g5
1316 stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
1319 ldxa [%g4] ASI_DMMU, %g4
1321 109: or %g7, %lo(109b), %g7
1325 add %sp, PTREGS_OFF, %o0
1329 .globl breakpoint_trap
1331 call sparc_breakpoint
1332 add %sp, PTREGS_OFF, %o0
1336 #if defined(CONFIG_SUNOS_EMUL) || defined(CONFIG_SOLARIS_EMUL) || \
1337 defined(CONFIG_SOLARIS_EMUL_MODULE)
1338 /* SunOS uses syscall zero as the 'indirect syscall' it looks
1339 * like indir_syscall(scall_num, arg0, arg1, arg2...); etc.
1340 * This is complete brain damage.
1346 cmp %o0, NR_SYSCALLS
1349 sethi %hi(sunos_nosys), %l6
1351 or %l6, %lo(sunos_nosys), %l6
1352 1: sethi %hi(sunos_sys_table), %l7
1353 or %l7, %lo(sunos_sys_table), %l7
1354 lduw [%l7 + %o0], %l6
1368 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1369 b,pt %xcc, ret_sys_call
1370 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1372 /* SunOS getuid() returns uid in %o0 and euid in %o1 */
1375 call sys32_geteuid16
1378 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1379 b,pt %xcc, ret_sys_call
1380 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1382 /* SunOS getgid() returns gid in %o0 and egid in %o1 */
1385 call sys32_getegid16
1388 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1389 b,pt %xcc, ret_sys_call
1390 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1393 /* SunOS's execv() call only specifies the argv argument, the
1394 * environment settings are the same as the calling processes.
1398 sethi %hi(sparc_execve), %g1
1399 ba,pt %xcc, execve_merge
1400 or %g1, %lo(sparc_execve), %g1
1401 #ifdef CONFIG_COMPAT
1404 stx %g0, [%sp + PTREGS_OFF + PT_V9_I2]
1407 sethi %hi(sparc32_execve), %g1
1408 or %g1, %lo(sparc32_execve), %g1
1413 add %sp, PTREGS_OFF, %o0
1415 .globl sys_pipe, sys_sigpause, sys_nis_syscall
1416 .globl sys_rt_sigreturn
1418 .globl sys_sigaltstack
1420 sys_pipe: ba,pt %xcc, sparc_pipe
1421 add %sp, PTREGS_OFF, %o0
1422 sys_nis_syscall:ba,pt %xcc, c_sys_nis_syscall
1423 add %sp, PTREGS_OFF, %o0
1424 sys_memory_ordering:
1425 ba,pt %xcc, sparc_memory_ordering
1426 add %sp, PTREGS_OFF, %o1
1427 sys_sigaltstack:ba,pt %xcc, do_sigaltstack
1428 add %i6, STACK_BIAS, %o2
1429 #ifdef CONFIG_COMPAT
1430 .globl sys32_sigstack
1431 sys32_sigstack: ba,pt %xcc, do_sys32_sigstack
1433 .globl sys32_sigaltstack
1435 ba,pt %xcc, do_sys32_sigaltstack
1439 #ifdef CONFIG_COMPAT
1440 .globl sys32_sigreturn
1442 add %sp, PTREGS_OFF, %o0
1444 add %o7, 1f-.-4, %o7
1448 add %sp, PTREGS_OFF, %o0
1449 call do_rt_sigreturn
1450 add %o7, 1f-.-4, %o7
1452 #ifdef CONFIG_COMPAT
1453 .globl sys32_rt_sigreturn
1455 add %sp, PTREGS_OFF, %o0
1456 call do_rt_sigreturn32
1457 add %o7, 1f-.-4, %o7
1460 sys_ptrace: add %sp, PTREGS_OFF, %o0
1462 add %o7, 1f-.-4, %o7
1465 1: ldx [%curptr + TI_FLAGS], %l5
1466 andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1469 add %sp, PTREGS_OFF, %o0
1476 /* This is how fork() was meant to be done, 8 instruction entry.
1478 * I questioned the following code briefly, let me clear things
1479 * up so you must not reason on it like I did.
1481 * Know the fork_kpsr etc. we use in the sparc32 port? We don't
1482 * need it here because the only piece of window state we copy to
1483 * the child is the CWP register. Even if the parent sleeps,
1484 * we are safe because we stuck it into pt_regs of the parent
1485 * so it will not change.
1487 * XXX This raises the question, whether we can do the same on
1488 * XXX sparc32 to get rid of fork_kpsr _and_ fork_kwim. The
1489 * XXX answer is yes. We stick fork_kpsr in UREG_G0 and
1490 * XXX fork_kwim in UREG_G1 (global registers are considered
1491 * XXX volatile across a system call in the sparc ABI I think
1492 * XXX if it isn't we can use regs->y instead, anyone who depends
1493 * XXX upon the Y register being preserved across a fork deserves
1496 * In fact we should take advantage of that fact for other things
1497 * during system calls...
1499 .globl sys_fork, sys_vfork, sys_clone, sparc_exit
1500 .globl ret_from_syscall
1502 sys_vfork: /* Under Linux, vfork and fork are just special cases of clone. */
1503 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1504 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1505 ba,pt %xcc, sys_clone
1511 ba,pt %xcc, sparc_do_fork
1512 add %sp, PTREGS_OFF, %o2
1514 /* Clear current_thread_info()->new_child, and
1515 * check performance counter stuff too.
1517 stb %g0, [%g6 + TI_NEW_CHILD]
1518 ldx [%g6 + TI_FLAGS], %l0
1521 andcc %l0, _TIF_PERFCTR, %g0
1524 ldx [%g6 + TI_PCR], %o7
1527 /* Blackbird errata workaround. See commentary in
1528 * smp.c:smp_percpu_timer_interrupt() for more
1534 99: wr %g0, %g0, %pic
1537 1: b,pt %xcc, ret_sys_call
1538 ldx [%sp + PTREGS_OFF + PT_V9_I0], %o0
1539 sparc_exit: rdpr %pstate, %g2
1540 wrpr %g2, PSTATE_IE, %pstate
1544 wrpr %g3, 0x0, %cansave
1545 wrpr %g0, 0x0, %otherwin
1546 wrpr %g2, 0x0, %pstate
1547 ba,pt %xcc, sys_exit
1548 stb %g0, [%g6 + TI_WSAVED]
1550 linux_sparc_ni_syscall:
1551 sethi %hi(sys_ni_syscall), %l7
1553 or %l7, %lo(sys_ni_syscall), %l7
1555 linux_syscall_trace32:
1556 add %sp, PTREGS_OFF, %o0
1566 linux_syscall_trace:
1567 add %sp, PTREGS_OFF, %o0
1578 /* Linux 32-bit and SunOS system calls enter here... */
1580 .globl linux_sparc_syscall32
1581 linux_sparc_syscall32:
1582 /* Direct access to user regs, much faster. */
1583 cmp %g1, NR_SYSCALLS ! IEU1 Group
1584 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
1585 srl %i0, 0, %o0 ! IEU0
1586 sll %g1, 2, %l4 ! IEU0 Group
1587 srl %i4, 0, %o4 ! IEU1
1588 lduw [%l7 + %l4], %l7 ! Load
1589 srl %i1, 0, %o1 ! IEU0 Group
1590 ldx [%curptr + TI_FLAGS], %l0 ! Load
1592 srl %i5, 0, %o5 ! IEU1
1593 srl %i2, 0, %o2 ! IEU0 Group
1594 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1595 bne,pn %icc, linux_syscall_trace32 ! CTI
1597 call %l7 ! CTI Group brk forced
1598 srl %i3, 0, %o3 ! IEU0
1601 /* Linux native and SunOS system calls enter here... */
1603 .globl linux_sparc_syscall, ret_sys_call
1604 linux_sparc_syscall:
1605 /* Direct access to user regs, much faster. */
1606 cmp %g1, NR_SYSCALLS ! IEU1 Group
1607 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
1609 sll %g1, 2, %l4 ! IEU0 Group
1611 lduw [%l7 + %l4], %l7 ! Load
1612 4: mov %i2, %o2 ! IEU0 Group
1613 ldx [%curptr + TI_FLAGS], %l0 ! Load
1616 mov %i4, %o4 ! IEU0 Group
1617 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1618 bne,pn %icc, linux_syscall_trace ! CTI Group
1620 2: call %l7 ! CTI Group brk forced
1624 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1626 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
1627 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
1629 mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
1632 /* Check if force_successful_syscall_return()
1635 ldub [%curptr + TI_SYS_NOERROR], %l2
1637 stb %g0, [%curptr + TI_SYS_NOERROR]
1639 cmp %o0, -ERESTART_RESTARTBLOCK
1641 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
1643 /* System call success, clear Carry condition code. */
1645 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
1646 bne,pn %icc, linux_syscall_trace2
1647 add %l1, 0x4, %l2 ! npc = npc+4
1648 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1649 ba,pt %xcc, rtrap_clr_l6
1650 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1653 /* System call failure, set Carry condition code.
1654 * Also, get abs(errno) to return to the process.
1656 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
1659 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1661 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
1662 bne,pn %icc, linux_syscall_trace2
1663 add %l1, 0x4, %l2 ! npc = npc+4
1664 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1667 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1668 linux_syscall_trace2:
1669 add %sp, PTREGS_OFF, %o0
1672 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1674 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1677 .globl __flushw_user
1682 1: save %sp, -128, %sp
1688 restore %g0, %g0, %g0
1693 .globl hard_smp_processor_id
1694 hard_smp_processor_id:
1696 .globl real_hard_smp_processor_id
1697 real_hard_smp_processor_id:
1705 * returns %o0: sysino
1707 .globl sun4v_devino_to_sysino
1708 sun4v_devino_to_sysino:
1709 mov HV_FAST_INTR_DEVINO2SYSINO, %o5
1716 * returns %o0: intr_enabled (HV_INTR_{DISABLED,ENABLED})
1718 .globl sun4v_intr_getenabled
1719 sun4v_intr_getenabled:
1720 mov HV_FAST_INTR_GETENABLED, %o5
1726 * %o1: intr_enabled (HV_INTR_{DISABLED,ENABLED})
1728 .globl sun4v_intr_setenabled
1729 sun4v_intr_setenabled:
1730 mov HV_FAST_INTR_SETENABLED, %o5
1737 * returns %o0: intr_state (HV_INTR_STATE_*)
1739 .globl sun4v_intr_getstate
1740 sun4v_intr_getstate:
1741 mov HV_FAST_INTR_GETSTATE, %o5
1747 * %o1: intr_state (HV_INTR_STATE_*)
1749 .globl sun4v_intr_setstate
1750 sun4v_intr_setstate:
1751 mov HV_FAST_INTR_SETSTATE, %o5
1758 * returns %o0: cpuid
1760 .globl sun4v_intr_gettarget
1761 sun4v_intr_gettarget:
1762 mov HV_FAST_INTR_GETTARGET, %o5
1770 .globl sun4v_intr_settarget
1771 sun4v_intr_settarget:
1772 mov HV_FAST_INTR_SETTARGET, %o5
1779 * %o2: num queue entries
1781 * returns %o0: status
1783 .globl sun4v_cpu_qconf
1785 mov HV_FAST_CPU_QCONF, %o5