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>
29 #define NR_SYSCALLS 300 /* Each OS is different... */
34 /* This is trivial with the new code... */
37 sethi %hi(TSTATE_PEF), %g4
43 andcc %g5, FPRS_FEF, %g0
47 /* Legal state when DCR_IFPOE is set in Cheetah %dcr. */
50 109: or %g7, %lo(109b), %g7
52 ba,a,pt %xcc, rtrap_clr_l6
54 1: TRAP_LOAD_THREAD_REG(%g6, %g1)
55 ldub [%g6 + TI_FPSAVED], %g5
56 wr %g0, FPRS_FEF, %fprs
57 andcc %g5, FPRS_FEF, %g0
60 ldx [%g6 + TI_GSR], %g7
61 1: andcc %g5, FPRS_DL, %g0
64 andcc %g5, FPRS_DU, %g0
95 b,pt %xcc, fpdis_exit2
97 1: mov SECONDARY_CONTEXT, %g3
98 add %g6, TI_FPREGS + 0x80, %g1
102 661: ldxa [%g3] ASI_DMMU, %g5
103 .section .sun4v_1insn_patch, "ax"
105 ldxa [%g3] ASI_MMU, %g5
108 sethi %hi(sparc64_kern_sec_context), %g2
109 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
111 661: stxa %g2, [%g3] ASI_DMMU
112 .section .sun4v_1insn_patch, "ax"
114 stxa %g2, [%g3] ASI_MMU
118 add %g6, TI_FPREGS + 0xc0, %g2
122 ldda [%g1] ASI_BLK_S, %f32
123 ldda [%g2] ASI_BLK_S, %f48
135 b,pt %xcc, fpdis_exit
137 2: andcc %g5, FPRS_DU, %g0
140 mov SECONDARY_CONTEXT, %g3
143 661: ldxa [%g3] ASI_DMMU, %g5
144 .section .sun4v_1insn_patch, "ax"
146 ldxa [%g3] ASI_MMU, %g5
149 add %g6, TI_FPREGS, %g1
150 sethi %hi(sparc64_kern_sec_context), %g2
151 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
153 661: stxa %g2, [%g3] ASI_DMMU
154 .section .sun4v_1insn_patch, "ax"
156 stxa %g2, [%g3] ASI_MMU
160 add %g6, TI_FPREGS + 0x40, %g2
161 faddd %f32, %f34, %f36
162 fmuld %f32, %f34, %f38
164 ldda [%g1] ASI_BLK_S, %f0
165 ldda [%g2] ASI_BLK_S, %f16
167 faddd %f32, %f34, %f40
168 fmuld %f32, %f34, %f42
169 faddd %f32, %f34, %f44
170 fmuld %f32, %f34, %f46
171 faddd %f32, %f34, %f48
172 fmuld %f32, %f34, %f50
173 faddd %f32, %f34, %f52
174 fmuld %f32, %f34, %f54
175 faddd %f32, %f34, %f56
176 fmuld %f32, %f34, %f58
177 faddd %f32, %f34, %f60
178 fmuld %f32, %f34, %f62
179 ba,pt %xcc, fpdis_exit
181 3: mov SECONDARY_CONTEXT, %g3
182 add %g6, TI_FPREGS, %g1
184 661: ldxa [%g3] ASI_DMMU, %g5
185 .section .sun4v_1insn_patch, "ax"
187 ldxa [%g3] ASI_MMU, %g5
190 sethi %hi(sparc64_kern_sec_context), %g2
191 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
193 661: stxa %g2, [%g3] ASI_DMMU
194 .section .sun4v_1insn_patch, "ax"
196 stxa %g2, [%g3] ASI_MMU
202 ldda [%g1] ASI_BLK_S, %f0
203 ldda [%g1 + %g2] ASI_BLK_S, %f16
205 ldda [%g1] ASI_BLK_S, %f32
206 ldda [%g1 + %g2] ASI_BLK_S, %f48
210 661: stxa %g5, [%g3] ASI_DMMU
211 .section .sun4v_1insn_patch, "ax"
213 stxa %g5, [%g3] ASI_MMU
219 ldx [%g6 + TI_XFSR], %fsr
221 or %g3, %g4, %g3 ! anal...
223 wr %g0, FPRS_FEF, %fprs ! clean DU/DL bits
229 add %sp, PTREGS_OFF, %o0
233 .globl do_fpother_check_fitos
235 do_fpother_check_fitos:
236 TRAP_LOAD_THREAD_REG(%g6, %g1)
237 sethi %hi(fp_other_bounce - 4), %g7
238 or %g7, %lo(fp_other_bounce - 4), %g7
240 /* NOTE: Need to preserve %g7 until we fully commit
241 * to the fitos fixup.
243 stx %fsr, [%g6 + TI_XFSR]
245 andcc %g3, TSTATE_PRIV, %g0
246 bne,pn %xcc, do_fptrap_after_fsr
248 ldx [%g6 + TI_XFSR], %g3
251 cmp %g1, 2 ! Unfinished FP-OP
252 bne,pn %xcc, do_fptrap_after_fsr
253 sethi %hi(1 << 23), %g1 ! Inexact
255 bne,pn %xcc, do_fptrap_after_fsr
257 lduwa [%g1] ASI_AIUP, %g3 ! This cannot ever fail
258 #define FITOS_MASK 0xc1f83fe0
259 #define FITOS_COMPARE 0x81a01880
260 sethi %hi(FITOS_MASK), %g1
261 or %g1, %lo(FITOS_MASK), %g1
263 sethi %hi(FITOS_COMPARE), %g2
264 or %g2, %lo(FITOS_COMPARE), %g2
266 bne,pn %xcc, do_fptrap_after_fsr
268 std %f62, [%g6 + TI_FPREGS + (62 * 4)]
269 sethi %hi(fitos_table_1), %g1
271 or %g1, %lo(fitos_table_1), %g1
274 ba,pt %xcc, fitos_emul_continue
311 sethi %hi(fitos_table_2), %g1
313 or %g1, %lo(fitos_table_2), %g1
317 ba,pt %xcc, fitos_emul_fini
354 ldd [%g6 + TI_FPREGS + (62 * 4)], %f62
360 TRAP_LOAD_THREAD_REG(%g6, %g1)
361 stx %fsr, [%g6 + TI_XFSR]
363 ldub [%g6 + TI_FPSAVED], %g3
366 stb %g3, [%g6 + TI_FPSAVED]
368 stx %g3, [%g6 + TI_GSR]
369 mov SECONDARY_CONTEXT, %g3
371 661: ldxa [%g3] ASI_DMMU, %g5
372 .section .sun4v_1insn_patch, "ax"
374 ldxa [%g3] ASI_MMU, %g5
377 sethi %hi(sparc64_kern_sec_context), %g2
378 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
380 661: stxa %g2, [%g3] ASI_DMMU
381 .section .sun4v_1insn_patch, "ax"
383 stxa %g2, [%g3] ASI_MMU
387 add %g6, TI_FPREGS, %g2
388 andcc %g1, FPRS_DL, %g0
391 stda %f0, [%g2] ASI_BLK_S
392 stda %f16, [%g2 + %g3] ASI_BLK_S
393 andcc %g1, FPRS_DU, %g0
396 stda %f32, [%g2] ASI_BLK_S
397 stda %f48, [%g2 + %g3] ASI_BLK_S
398 5: mov SECONDARY_CONTEXT, %g1
401 661: stxa %g5, [%g1] ASI_DMMU
402 .section .sun4v_1insn_patch, "ax"
404 stxa %g5, [%g1] ASI_MMU
411 /* The registers for cross calls will be:
413 * DATA 0: [low 32-bits] Address of function to call, jmp to this
414 * [high 32-bits] MMU Context Argument 0, place in %g5
415 * DATA 1: Address Argument 1, place in %g1
416 * DATA 2: Address Argument 2, place in %g7
418 * With this method we can do most of the cross-call tlb/cache
419 * flushing very quickly.
426 ldxa [%g3 + %g0] ASI_INTR_R, %g3
427 sethi %hi(KERNBASE), %g4
429 bgeu,pn %xcc, do_ivec_xcall
431 stxa %g0, [%g0] ASI_INTR_RECEIVE
434 sethi %hi(ivector_table), %g2
436 or %g2, %lo(ivector_table), %g2
439 TRAP_LOAD_IRQ_WORK(%g6, %g1)
441 lduw [%g6], %g5 /* g5 = irq_work(cpu) */
442 stw %g5, [%g3 + 0x00] /* bucket->irq_chain = g5 */
443 stw %g3, [%g6] /* irq_work(cpu) = bucket */
444 wr %g0, 1 << PIL_DEVICE_IRQ, %set_softint
448 ldxa [%g1 + %g0] ASI_INTR_R, %g1
452 ldxa [%g7 + %g0] ASI_INTR_R, %g7
453 stxa %g0, [%g0] ASI_INTR_RECEIVE
464 ldx [%o0 + PT_V9_TSTATE], %o1
468 stx %o1, [%o0 + PT_V9_G1]
470 ldx [%o0 + PT_V9_TSTATE], %o1
471 ldx [%o0 + PT_V9_G1], %o2
472 or %g0, %ulo(TSTATE_ICC), %o3
479 stx %o1, [%o0 + PT_V9_TSTATE]
482 utrap_trap: /* %g3=handler,%g4=level */
483 TRAP_LOAD_THREAD_REG(%g6, %g1)
484 ldx [%g6 + TI_UTRAPS], %g1
485 brnz,pt %g1, invoke_utrap
492 add %sp, PTREGS_OFF, %o0
502 andn %l6, TSTATE_CWP, %l6
503 wrpr %l6, %l7, %tstate
509 /* We need to carefully read the error status, ACK
510 * the errors, prevent recursive traps, and pass the
511 * information on to C code for logging.
513 * We pass the AFAR in as-is, and we encode the status
514 * information as described in asm-sparc64/sfafsr.h
516 .globl __spitfire_access_error
517 __spitfire_access_error:
518 /* Disable ESTATE error reporting so that we do not
519 * take recursive traps and RED state the processor.
521 stxa %g0, [%g0] ASI_ESTATE_ERROR_EN
525 ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
527 /* __spitfire_cee_trap branches here with AFSR in %g4 and
528 * UDBE_CE in %g1. It only clears ESTATE_ERR_CE in the
529 * ESTATE Error Enable register.
531 __spitfire_cee_trap_continue:
532 ldxa [%g0] ASI_AFAR, %g5 ! Get AFAR
535 and %g3, 0x1ff, %g3 ! Paranoia
536 sllx %g3, SFSTAT_TRAP_TYPE_SHIFT, %g3
542 sllx %g3, SFSTAT_TL_GT_ONE_SHIFT, %g3
546 /* Read in the UDB error register state, clearing the
547 * sticky error bits as-needed. We only clear them if
548 * the UE bit is set. Likewise, __spitfire_cee_trap
549 * below will only do so if the CE bit is set.
551 * NOTE: UltraSparc-I/II have high and low UDB error
552 * registers, corresponding to the two UDB units
553 * present on those chips. UltraSparc-IIi only
554 * has a single UDB, called "SDB" in the manual.
555 * For IIi the upper UDB register always reads
556 * as zero so for our purposes things will just
557 * work with the checks below.
559 1: ldxa [%g0] ASI_UDBH_ERROR_R, %g3
560 and %g3, 0x3ff, %g7 ! Paranoia
561 sllx %g7, SFSTAT_UDBH_SHIFT, %g7
563 andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
566 stxa %g3, [%g0] ASI_UDB_ERROR_W
570 ldxa [%g3] ASI_UDBL_ERROR_R, %g3
571 and %g3, 0x3ff, %g7 ! Paranoia
572 sllx %g7, SFSTAT_UDBL_SHIFT, %g7
574 andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
578 stxa %g3, [%g7] ASI_UDB_ERROR_W
581 1: /* Ok, now that we've latched the error state,
582 * clear the sticky bits in the AFSR.
584 stxa %g4, [%g0] ASI_AFSR
599 1: ba,pt %xcc, etrap_irq
604 call spitfire_access_error
605 add %sp, PTREGS_OFF, %o0
609 /* This is the trap handler entry point for ECC correctable
610 * errors. They are corrected, but we listen for the trap
611 * so that the event can be logged.
613 * Disrupting errors are either:
614 * 1) single-bit ECC errors during UDB reads to system
616 * 2) data parity errors during write-back events
618 * As far as I can make out from the manual, the CEE trap
619 * is only for correctable errors during memory read
620 * accesses by the front-end of the processor.
622 * The code below is only for trap level 1 CEE events,
623 * as it is the only situation where we can safely record
624 * and log. For trap level >1 we just clear the CE bit
625 * in the AFSR and return.
627 * This is just like __spiftire_access_error above, but it
628 * specifically handles correctable errors. If an
629 * uncorrectable error is indicated in the AFSR we
630 * will branch directly above to __spitfire_access_error
631 * to handle it instead. Uncorrectable therefore takes
632 * priority over correctable, and the error logging
633 * C code will notice this case by inspecting the
636 .globl __spitfire_cee_trap
638 ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
640 sllx %g3, SFAFSR_UE_SHIFT, %g3
641 andcc %g4, %g3, %g0 ! Check for UE
642 bne,pn %xcc, __spitfire_access_error
645 /* Ok, in this case we only have a correctable error.
646 * Indicate we only wish to capture that state in register
647 * %g1, and we only disable CE error reporting unlike UE
648 * handling which disables all errors.
650 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g3
651 andn %g3, ESTATE_ERR_CE, %g3
652 stxa %g3, [%g0] ASI_ESTATE_ERROR_EN
655 /* Preserve AFSR in %g4, indicate UDB state to capture in %g1 */
656 ba,pt %xcc, __spitfire_cee_trap_continue
659 .globl __spitfire_data_access_exception
660 .globl __spitfire_data_access_exception_tl1
661 __spitfire_data_access_exception_tl1:
663 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
666 ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
667 ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
668 stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
671 cmp %g3, 0x80 ! first win spill/fill trap
673 cmp %g3, 0xff ! last win spill/fill trap
676 ba,pt %xcc, winfix_dax
678 1: sethi %hi(109f), %g7
680 109: or %g7, %lo(109b), %g7
683 call spitfire_data_access_exception_tl1
684 add %sp, PTREGS_OFF, %o0
688 __spitfire_data_access_exception:
690 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
693 ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
694 ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
695 stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
699 109: or %g7, %lo(109b), %g7
702 call spitfire_data_access_exception
703 add %sp, PTREGS_OFF, %o0
707 .globl __spitfire_insn_access_exception
708 .globl __spitfire_insn_access_exception_tl1
709 __spitfire_insn_access_exception_tl1:
711 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
713 ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
714 rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
715 stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
719 109: or %g7, %lo(109b), %g7
722 call spitfire_insn_access_exception_tl1
723 add %sp, PTREGS_OFF, %o0
727 __spitfire_insn_access_exception:
729 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
731 ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
732 rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
733 stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
737 109: or %g7, %lo(109b), %g7
740 call spitfire_insn_access_exception
741 add %sp, PTREGS_OFF, %o0
745 /* These get patched into the trap table at boot time
746 * once we know we have a cheetah processor.
748 .globl cheetah_fecc_trap_vector, cheetah_fecc_trap_vector_tl1
749 cheetah_fecc_trap_vector:
751 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
752 andn %g1, DCU_DC | DCU_IC, %g1
753 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
755 sethi %hi(cheetah_fast_ecc), %g2
756 jmpl %g2 + %lo(cheetah_fast_ecc), %g0
758 cheetah_fecc_trap_vector_tl1:
760 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
761 andn %g1, DCU_DC | DCU_IC, %g1
762 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
764 sethi %hi(cheetah_fast_ecc), %g2
765 jmpl %g2 + %lo(cheetah_fast_ecc), %g0
767 .globl cheetah_cee_trap_vector, cheetah_cee_trap_vector_tl1
768 cheetah_cee_trap_vector:
770 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
771 andn %g1, DCU_IC, %g1
772 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
774 sethi %hi(cheetah_cee), %g2
775 jmpl %g2 + %lo(cheetah_cee), %g0
777 cheetah_cee_trap_vector_tl1:
779 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
780 andn %g1, DCU_IC, %g1
781 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
783 sethi %hi(cheetah_cee), %g2
784 jmpl %g2 + %lo(cheetah_cee), %g0
786 .globl cheetah_deferred_trap_vector, cheetah_deferred_trap_vector_tl1
787 cheetah_deferred_trap_vector:
789 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
790 andn %g1, DCU_DC | DCU_IC, %g1;
791 stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
793 sethi %hi(cheetah_deferred_trap), %g2
794 jmpl %g2 + %lo(cheetah_deferred_trap), %g0
796 cheetah_deferred_trap_vector_tl1:
798 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
799 andn %g1, DCU_DC | DCU_IC, %g1;
800 stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
802 sethi %hi(cheetah_deferred_trap), %g2
803 jmpl %g2 + %lo(cheetah_deferred_trap), %g0
806 /* Cheetah+ specific traps. These are for the new I/D cache parity
807 * error traps. The first argument to cheetah_plus_parity_handler
808 * is encoded as follows:
810 * Bit0: 0=dcache,1=icache
811 * Bit1: 0=recoverable,1=unrecoverable
813 .globl cheetah_plus_dcpe_trap_vector, cheetah_plus_dcpe_trap_vector_tl1
814 cheetah_plus_dcpe_trap_vector:
816 sethi %hi(do_cheetah_plus_data_parity), %g7
817 jmpl %g7 + %lo(do_cheetah_plus_data_parity), %g0
824 do_cheetah_plus_data_parity:
827 ba,pt %xcc, etrap_irq
830 call cheetah_plus_parity_error
831 add %sp, PTREGS_OFF, %o1
832 ba,a,pt %xcc, rtrap_irq
834 cheetah_plus_dcpe_trap_vector_tl1:
836 wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
837 sethi %hi(do_dcpe_tl1), %g3
838 jmpl %g3 + %lo(do_dcpe_tl1), %g0
844 .globl cheetah_plus_icpe_trap_vector, cheetah_plus_icpe_trap_vector_tl1
845 cheetah_plus_icpe_trap_vector:
847 sethi %hi(do_cheetah_plus_insn_parity), %g7
848 jmpl %g7 + %lo(do_cheetah_plus_insn_parity), %g0
855 do_cheetah_plus_insn_parity:
858 ba,pt %xcc, etrap_irq
861 call cheetah_plus_parity_error
862 add %sp, PTREGS_OFF, %o1
863 ba,a,pt %xcc, rtrap_irq
865 cheetah_plus_icpe_trap_vector_tl1:
867 wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
868 sethi %hi(do_icpe_tl1), %g3
869 jmpl %g3 + %lo(do_icpe_tl1), %g0
875 /* If we take one of these traps when tl >= 1, then we
876 * jump to interrupt globals. If some trap level above us
877 * was also using interrupt globals, we cannot recover.
878 * We may use all interrupt global registers except %g6.
880 .globl do_dcpe_tl1, do_icpe_tl1
882 rdpr %tl, %g1 ! Save original trap level
883 mov 1, %g2 ! Setup TSTATE checking loop
884 sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
885 1: wrpr %g2, %tl ! Set trap level to check
886 rdpr %tstate, %g4 ! Read TSTATE for this level
887 andcc %g4, %g3, %g0 ! Interrupt globals in use?
888 bne,a,pn %xcc, do_dcpe_tl1_fatal ! Yep, irrecoverable
889 wrpr %g1, %tl ! Restore original trap level
890 add %g2, 1, %g2 ! Next trap level
891 cmp %g2, %g1 ! Hit them all yet?
892 ble,pt %icc, 1b ! Not yet
894 wrpr %g1, %tl ! Restore original trap level
895 do_dcpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
896 sethi %hi(dcache_parity_tl1_occurred), %g2
897 lduw [%g2 + %lo(dcache_parity_tl1_occurred)], %g1
899 stw %g1, [%g2 + %lo(dcache_parity_tl1_occurred)]
900 /* Reset D-cache parity */
901 sethi %hi(1 << 16), %g1 ! D-cache size
902 mov (1 << 5), %g2 ! D-cache line size
903 sub %g1, %g2, %g1 ! Move down 1 cacheline
904 1: srl %g1, 14, %g3 ! Compute UTAG
906 stxa %g3, [%g1] ASI_DCACHE_UTAG
908 sub %g2, 8, %g3 ! 64-bit data word within line
910 stxa %g0, [%g1 + %g3] ASI_DCACHE_DATA
912 subcc %g3, 8, %g3 ! Next 64-bit data word
915 subcc %g1, %g2, %g1 ! Next cacheline
918 ba,pt %xcc, dcpe_icpe_tl1_common
924 1: or %g7, %lo(1b), %g7
926 call cheetah_plus_parity_error
927 add %sp, PTREGS_OFF, %o1
932 rdpr %tl, %g1 ! Save original trap level
933 mov 1, %g2 ! Setup TSTATE checking loop
934 sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
935 1: wrpr %g2, %tl ! Set trap level to check
936 rdpr %tstate, %g4 ! Read TSTATE for this level
937 andcc %g4, %g3, %g0 ! Interrupt globals in use?
938 bne,a,pn %xcc, do_icpe_tl1_fatal ! Yep, irrecoverable
939 wrpr %g1, %tl ! Restore original trap level
940 add %g2, 1, %g2 ! Next trap level
941 cmp %g2, %g1 ! Hit them all yet?
942 ble,pt %icc, 1b ! Not yet
944 wrpr %g1, %tl ! Restore original trap level
945 do_icpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
946 sethi %hi(icache_parity_tl1_occurred), %g2
947 lduw [%g2 + %lo(icache_parity_tl1_occurred)], %g1
949 stw %g1, [%g2 + %lo(icache_parity_tl1_occurred)]
951 sethi %hi(1 << 15), %g1 ! I-cache size
952 mov (1 << 5), %g2 ! I-cache line size
954 1: or %g1, (2 << 3), %g3
955 stxa %g0, [%g3] ASI_IC_TAG
960 ba,pt %xcc, dcpe_icpe_tl1_common
966 1: or %g7, %lo(1b), %g7
968 call cheetah_plus_parity_error
969 add %sp, PTREGS_OFF, %o1
973 dcpe_icpe_tl1_common:
974 /* Flush D-cache, re-enable D/I caches in DCU and finally
975 * retry the trapping instruction.
977 sethi %hi(1 << 16), %g1 ! D-cache size
978 mov (1 << 5), %g2 ! D-cache line size
980 1: stxa %g0, [%g1] ASI_DCACHE_TAG
985 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
986 or %g1, (DCU_DC | DCU_IC), %g1
987 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
991 /* Capture I/D/E-cache state into per-cpu error scoreboard.
993 * %g1: (TL>=0) ? 1 : 0
998 * %g6: unused, will have current thread ptr after etrap
1001 __cheetah_log_error:
1002 /* Put "TL1" software bit into AFSR. */
1007 /* Get log entry pointer for this cpu at this trap level. */
1008 BRANCH_IF_JALAPENO(g2,g3,50f)
1009 ldxa [%g0] ASI_SAFARI_CONFIG, %g2
1014 50: ldxa [%g0] ASI_JBUS_CONFIG, %g2
1018 60: sllx %g2, 9, %g2
1019 sethi %hi(cheetah_error_log), %g3
1020 ldx [%g3 + %lo(cheetah_error_log)], %g3
1028 /* %g1 holds pointer to the top of the logging scoreboard */
1029 ldx [%g1 + 0x0], %g7
1034 stx %g4, [%g1 + 0x0]
1035 stx %g5, [%g1 + 0x8]
1038 /* %g1 now points to D-cache logging area */
1039 set 0x3ff8, %g2 /* DC_addr mask */
1040 and %g5, %g2, %g2 /* DC_addr bits of AFAR */
1042 or %g3, 1, %g3 /* PHYS tag + valid */
1044 10: ldxa [%g2] ASI_DCACHE_TAG, %g7
1045 cmp %g3, %g7 /* TAG match? */
1049 /* Yep, what we want, capture state. */
1050 stx %g2, [%g1 + 0x20]
1051 stx %g7, [%g1 + 0x28]
1053 /* A membar Sync is required before and after utag access. */
1055 ldxa [%g2] ASI_DCACHE_UTAG, %g7
1057 stx %g7, [%g1 + 0x30]
1058 ldxa [%g2] ASI_DCACHE_SNOOP_TAG, %g7
1059 stx %g7, [%g1 + 0x38]
1062 12: ldxa [%g2 + %g3] ASI_DCACHE_DATA, %g7
1064 add %g3, (1 << 5), %g3
1072 13: sethi %hi(1 << 14), %g7
1081 /* %g1 now points to I-cache logging area */
1082 20: set 0x1fe0, %g2 /* IC_addr mask */
1083 and %g5, %g2, %g2 /* IC_addr bits of AFAR */
1084 sllx %g2, 1, %g2 /* IC_addr[13:6]==VA[12:5] */
1085 srlx %g5, (13 - 8), %g3 /* Make PTAG */
1086 andn %g3, 0xff, %g3 /* Mask off undefined bits */
1088 21: ldxa [%g2] ASI_IC_TAG, %g7
1094 /* Yep, what we want, capture state. */
1095 stx %g2, [%g1 + 0x40]
1096 stx %g7, [%g1 + 0x48]
1097 add %g2, (1 << 3), %g2
1098 ldxa [%g2] ASI_IC_TAG, %g7
1099 add %g2, (1 << 3), %g2
1100 stx %g7, [%g1 + 0x50]
1101 ldxa [%g2] ASI_IC_TAG, %g7
1102 add %g2, (1 << 3), %g2
1103 stx %g7, [%g1 + 0x60]
1104 ldxa [%g2] ASI_IC_TAG, %g7
1105 stx %g7, [%g1 + 0x68]
1106 sub %g2, (3 << 3), %g2
1107 ldxa [%g2] ASI_IC_STAG, %g7
1108 stx %g7, [%g1 + 0x58]
1112 22: ldxa [%g2 + %g3] ASI_IC_INSTR, %g7
1114 add %g3, (1 << 3), %g3
1122 23: sethi %hi(1 << 14), %g7
1131 /* %g1 now points to E-cache logging area */
1132 30: andn %g5, (32 - 1), %g2
1133 stx %g2, [%g1 + 0x20]
1134 ldxa [%g2] ASI_EC_TAG_DATA, %g7
1135 stx %g7, [%g1 + 0x28]
1136 ldxa [%g2] ASI_EC_R, %g0
1139 31: ldxa [%g3] ASI_EC_DATA, %g7
1140 stx %g7, [%g1 + %g3]
1153 ba,pt %xcc, c_deferred
1155 /* Cheetah FECC trap handling, we get here from tl{0,1}_fecc
1156 * in the trap table. That code has done a memory barrier
1157 * and has disabled both the I-cache and D-cache in the DCU
1158 * control register. The I-cache is disabled so that we may
1159 * capture the corrupted cache line, and the D-cache is disabled
1160 * because corrupt data may have been placed there and we don't
1161 * want to reference it.
1163 * %g1 is one if this trap occurred at %tl >= 1.
1165 * Next, we turn off error reporting so that we don't recurse.
1167 .globl cheetah_fast_ecc
1169 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1170 andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
1171 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1174 /* Fetch and clear AFSR/AFAR */
1175 ldxa [%g0] ASI_AFSR, %g4
1176 ldxa [%g0] ASI_AFAR, %g5
1177 stxa %g4, [%g0] ASI_AFSR
1180 ba,pt %xcc, __cheetah_log_error
1186 ba,pt %xcc, etrap_irq
1190 call cheetah_fecc_handler
1191 add %sp, PTREGS_OFF, %o0
1192 ba,a,pt %xcc, rtrap_irq
1194 /* Our caller has disabled I-cache and performed membar Sync. */
1197 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1198 andn %g2, ESTATE_ERROR_CEEN, %g2
1199 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1202 /* Fetch and clear AFSR/AFAR */
1203 ldxa [%g0] ASI_AFSR, %g4
1204 ldxa [%g0] ASI_AFAR, %g5
1205 stxa %g4, [%g0] ASI_AFSR
1208 ba,pt %xcc, __cheetah_log_error
1214 ba,pt %xcc, etrap_irq
1218 call cheetah_cee_handler
1219 add %sp, PTREGS_OFF, %o0
1220 ba,a,pt %xcc, rtrap_irq
1222 /* Our caller has disabled I-cache+D-cache and performed membar Sync. */
1223 .globl cheetah_deferred_trap
1224 cheetah_deferred_trap:
1225 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1226 andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
1227 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1230 /* Fetch and clear AFSR/AFAR */
1231 ldxa [%g0] ASI_AFSR, %g4
1232 ldxa [%g0] ASI_AFAR, %g5
1233 stxa %g4, [%g0] ASI_AFSR
1236 ba,pt %xcc, __cheetah_log_error
1242 ba,pt %xcc, etrap_irq
1246 call cheetah_deferred_handler
1247 add %sp, PTREGS_OFF, %o0
1248 ba,a,pt %xcc, rtrap_irq
1253 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
1255 sethi %hi(109f), %g7
1257 109: or %g7, %lo(109b), %g7
1259 add %sp, PTREGS_OFF, %o0
1268 /* Setup %g4/%g5 now as they are used in the
1273 ldxa [%g4] ASI_DMMU, %g4
1274 ldxa [%g3] ASI_DMMU, %g5
1275 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
1277 bgu,pn %icc, winfix_mna
1280 1: sethi %hi(109f), %g7
1282 109: or %g7, %lo(109b), %g7
1285 call mem_address_unaligned
1286 add %sp, PTREGS_OFF, %o0
1292 sethi %hi(109f), %g7
1294 ldxa [%g4] ASI_DMMU, %g5
1295 stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
1298 ldxa [%g4] ASI_DMMU, %g4
1300 109: or %g7, %lo(109b), %g7
1304 add %sp, PTREGS_OFF, %o0
1310 sethi %hi(109f), %g7
1312 ldxa [%g4] ASI_DMMU, %g5
1313 stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
1316 ldxa [%g4] ASI_DMMU, %g4
1318 109: or %g7, %lo(109b), %g7
1322 add %sp, PTREGS_OFF, %o0
1326 .globl breakpoint_trap
1328 call sparc_breakpoint
1329 add %sp, PTREGS_OFF, %o0
1333 #if defined(CONFIG_SUNOS_EMUL) || defined(CONFIG_SOLARIS_EMUL) || \
1334 defined(CONFIG_SOLARIS_EMUL_MODULE)
1335 /* SunOS uses syscall zero as the 'indirect syscall' it looks
1336 * like indir_syscall(scall_num, arg0, arg1, arg2...); etc.
1337 * This is complete brain damage.
1343 cmp %o0, NR_SYSCALLS
1346 sethi %hi(sunos_nosys), %l6
1348 or %l6, %lo(sunos_nosys), %l6
1349 1: sethi %hi(sunos_sys_table), %l7
1350 or %l7, %lo(sunos_sys_table), %l7
1351 lduw [%l7 + %o0], %l6
1365 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1366 b,pt %xcc, ret_sys_call
1367 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1369 /* SunOS getuid() returns uid in %o0 and euid in %o1 */
1372 call sys32_geteuid16
1375 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1376 b,pt %xcc, ret_sys_call
1377 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1379 /* SunOS getgid() returns gid in %o0 and egid in %o1 */
1382 call sys32_getegid16
1385 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1386 b,pt %xcc, ret_sys_call
1387 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1390 /* SunOS's execv() call only specifies the argv argument, the
1391 * environment settings are the same as the calling processes.
1395 sethi %hi(sparc_execve), %g1
1396 ba,pt %xcc, execve_merge
1397 or %g1, %lo(sparc_execve), %g1
1398 #ifdef CONFIG_COMPAT
1401 stx %g0, [%sp + PTREGS_OFF + PT_V9_I2]
1404 sethi %hi(sparc32_execve), %g1
1405 or %g1, %lo(sparc32_execve), %g1
1410 add %sp, PTREGS_OFF, %o0
1412 .globl sys_pipe, sys_sigpause, sys_nis_syscall
1413 .globl sys_rt_sigreturn
1415 .globl sys_sigaltstack
1417 sys_pipe: ba,pt %xcc, sparc_pipe
1418 add %sp, PTREGS_OFF, %o0
1419 sys_nis_syscall:ba,pt %xcc, c_sys_nis_syscall
1420 add %sp, PTREGS_OFF, %o0
1421 sys_memory_ordering:
1422 ba,pt %xcc, sparc_memory_ordering
1423 add %sp, PTREGS_OFF, %o1
1424 sys_sigaltstack:ba,pt %xcc, do_sigaltstack
1425 add %i6, STACK_BIAS, %o2
1426 #ifdef CONFIG_COMPAT
1427 .globl sys32_sigstack
1428 sys32_sigstack: ba,pt %xcc, do_sys32_sigstack
1430 .globl sys32_sigaltstack
1432 ba,pt %xcc, do_sys32_sigaltstack
1436 #ifdef CONFIG_COMPAT
1437 .globl sys32_sigreturn
1439 add %sp, PTREGS_OFF, %o0
1441 add %o7, 1f-.-4, %o7
1445 add %sp, PTREGS_OFF, %o0
1446 call do_rt_sigreturn
1447 add %o7, 1f-.-4, %o7
1449 #ifdef CONFIG_COMPAT
1450 .globl sys32_rt_sigreturn
1452 add %sp, PTREGS_OFF, %o0
1453 call do_rt_sigreturn32
1454 add %o7, 1f-.-4, %o7
1457 sys_ptrace: add %sp, PTREGS_OFF, %o0
1459 add %o7, 1f-.-4, %o7
1462 1: ldx [%curptr + TI_FLAGS], %l5
1463 andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1466 add %sp, PTREGS_OFF, %o0
1473 /* This is how fork() was meant to be done, 8 instruction entry.
1475 * I questioned the following code briefly, let me clear things
1476 * up so you must not reason on it like I did.
1478 * Know the fork_kpsr etc. we use in the sparc32 port? We don't
1479 * need it here because the only piece of window state we copy to
1480 * the child is the CWP register. Even if the parent sleeps,
1481 * we are safe because we stuck it into pt_regs of the parent
1482 * so it will not change.
1484 * XXX This raises the question, whether we can do the same on
1485 * XXX sparc32 to get rid of fork_kpsr _and_ fork_kwim. The
1486 * XXX answer is yes. We stick fork_kpsr in UREG_G0 and
1487 * XXX fork_kwim in UREG_G1 (global registers are considered
1488 * XXX volatile across a system call in the sparc ABI I think
1489 * XXX if it isn't we can use regs->y instead, anyone who depends
1490 * XXX upon the Y register being preserved across a fork deserves
1493 * In fact we should take advantage of that fact for other things
1494 * during system calls...
1496 .globl sys_fork, sys_vfork, sys_clone, sparc_exit
1497 .globl ret_from_syscall
1499 sys_vfork: /* Under Linux, vfork and fork are just special cases of clone. */
1500 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1501 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1502 ba,pt %xcc, sys_clone
1508 ba,pt %xcc, sparc_do_fork
1509 add %sp, PTREGS_OFF, %o2
1511 /* Clear current_thread_info()->new_child, and
1512 * check performance counter stuff too.
1514 stb %g0, [%g6 + TI_NEW_CHILD]
1515 ldx [%g6 + TI_FLAGS], %l0
1518 andcc %l0, _TIF_PERFCTR, %g0
1521 ldx [%g6 + TI_PCR], %o7
1524 /* Blackbird errata workaround. See commentary in
1525 * smp.c:smp_percpu_timer_interrupt() for more
1531 99: wr %g0, %g0, %pic
1534 1: b,pt %xcc, ret_sys_call
1535 ldx [%sp + PTREGS_OFF + PT_V9_I0], %o0
1536 sparc_exit: rdpr %pstate, %g2
1537 wrpr %g2, PSTATE_IE, %pstate
1541 wrpr %g3, 0x0, %cansave
1542 wrpr %g0, 0x0, %otherwin
1543 wrpr %g2, 0x0, %pstate
1544 ba,pt %xcc, sys_exit
1545 stb %g0, [%g6 + TI_WSAVED]
1547 linux_sparc_ni_syscall:
1548 sethi %hi(sys_ni_syscall), %l7
1550 or %l7, %lo(sys_ni_syscall), %l7
1552 linux_syscall_trace32:
1553 add %sp, PTREGS_OFF, %o0
1563 linux_syscall_trace:
1564 add %sp, PTREGS_OFF, %o0
1575 /* Linux 32-bit and SunOS system calls enter here... */
1577 .globl linux_sparc_syscall32
1578 linux_sparc_syscall32:
1579 /* Direct access to user regs, much faster. */
1580 cmp %g1, NR_SYSCALLS ! IEU1 Group
1581 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
1582 srl %i0, 0, %o0 ! IEU0
1583 sll %g1, 2, %l4 ! IEU0 Group
1584 srl %i4, 0, %o4 ! IEU1
1585 lduw [%l7 + %l4], %l7 ! Load
1586 srl %i1, 0, %o1 ! IEU0 Group
1587 ldx [%curptr + TI_FLAGS], %l0 ! Load
1589 srl %i5, 0, %o5 ! IEU1
1590 srl %i2, 0, %o2 ! IEU0 Group
1591 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1592 bne,pn %icc, linux_syscall_trace32 ! CTI
1594 call %l7 ! CTI Group brk forced
1595 srl %i3, 0, %o3 ! IEU0
1598 /* Linux native and SunOS system calls enter here... */
1600 .globl linux_sparc_syscall, ret_sys_call
1601 linux_sparc_syscall:
1602 /* Direct access to user regs, much faster. */
1603 cmp %g1, NR_SYSCALLS ! IEU1 Group
1604 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
1606 sll %g1, 2, %l4 ! IEU0 Group
1608 lduw [%l7 + %l4], %l7 ! Load
1609 4: mov %i2, %o2 ! IEU0 Group
1610 ldx [%curptr + TI_FLAGS], %l0 ! Load
1613 mov %i4, %o4 ! IEU0 Group
1614 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1615 bne,pn %icc, linux_syscall_trace ! CTI Group
1617 2: call %l7 ! CTI Group brk forced
1621 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1623 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
1624 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
1626 mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
1629 /* Check if force_successful_syscall_return()
1632 ldub [%curptr + TI_SYS_NOERROR], %l2
1634 stb %g0, [%curptr + TI_SYS_NOERROR]
1636 cmp %o0, -ERESTART_RESTARTBLOCK
1638 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
1640 /* System call success, clear Carry condition code. */
1642 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
1643 bne,pn %icc, linux_syscall_trace2
1644 add %l1, 0x4, %l2 ! npc = npc+4
1645 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1646 ba,pt %xcc, rtrap_clr_l6
1647 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1650 /* System call failure, set Carry condition code.
1651 * Also, get abs(errno) to return to the process.
1653 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
1656 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1658 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
1659 bne,pn %icc, linux_syscall_trace2
1660 add %l1, 0x4, %l2 ! npc = npc+4
1661 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1664 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1665 linux_syscall_trace2:
1666 add %sp, PTREGS_OFF, %o0
1669 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1671 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1674 .globl __flushw_user
1679 1: save %sp, -128, %sp
1685 restore %g0, %g0, %g0
1690 .globl hard_smp_processor_id
1691 hard_smp_processor_id:
1693 .globl real_hard_smp_processor_id
1694 real_hard_smp_processor_id:
1702 * returns %o0: sysino
1704 .globl sun4v_devino_to_sysino
1705 sun4v_devino_to_sysino:
1706 mov HV_FAST_INTR_DEVINO2SYSINO, %o5
1713 * returns %o0: intr_enabled (HV_INTR_{DISABLED,ENABLED})
1715 .globl sun4v_intr_getenabled
1716 sun4v_intr_getenabled:
1717 mov HV_FAST_INTR_GETENABLED, %o5
1723 * %o1: intr_enabled (HV_INTR_{DISABLED,ENABLED})
1725 .globl sun4v_intr_setenabled
1726 sun4v_intr_setenabled:
1727 mov HV_FAST_INTR_SETENABLED, %o5
1734 * returns %o0: intr_state (HV_INTR_STATE_*)
1736 .globl sun4v_intr_getstate
1737 sun4v_intr_getstate:
1738 mov HV_FAST_INTR_GETSTATE, %o5
1744 * %o1: intr_state (HV_INTR_STATE_*)
1746 .globl sun4v_intr_setstate
1747 sun4v_intr_setstate:
1748 mov HV_FAST_INTR_SETSTATE, %o5
1755 * returns %o0: cpuid
1757 .globl sun4v_intr_gettarget
1758 sun4v_intr_gettarget:
1759 mov HV_FAST_INTR_GETTARGET, %o5
1767 .globl sun4v_intr_settarget
1768 sun4v_intr_settarget:
1769 mov HV_FAST_INTR_SETTARGET, %o5
1776 * %o2: num queue entries
1778 * returns %o0: status
1780 .globl sun4v_cpu_qconf
1782 mov HV_FAST_CPU_QCONF, %o5
1787 /* returns %o0: status
1789 .globl sun4v_cpu_yield
1791 mov HV_FAST_CPU_YIELD, %o5
1796 /* %o0: num cpus in cpu list
1797 * %o1: cpu list paddr
1798 * %o2: mondo block paddr
1800 * returns %o0: status
1802 .globl sun4v_cpu_mondo_send
1803 sun4v_cpu_mondo_send:
1804 mov HV_FAST_CPU_MONDO_SEND, %o5
1811 * returns %o0: -status if status non-zero, else
1812 * %o0: cpu state as HV_CPU_STATE_*
1814 .globl sun4v_cpu_state
1816 mov HV_FAST_CPU_STATE, %o5