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
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
100 ldxa [%g3] ASI_DMMU, %g5
101 sethi %hi(sparc64_kern_sec_context), %g2
102 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
103 stxa %g2, [%g3] ASI_DMMU
105 add %g6, TI_FPREGS + 0xc0, %g2
109 ldda [%g1] ASI_BLK_S, %f32
110 ldda [%g2] ASI_BLK_S, %f48
122 b,pt %xcc, fpdis_exit
124 2: andcc %g5, FPRS_DU, %g0
127 mov SECONDARY_CONTEXT, %g3
129 ldxa [%g3] ASI_DMMU, %g5
130 add %g6, TI_FPREGS, %g1
131 sethi %hi(sparc64_kern_sec_context), %g2
132 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
133 stxa %g2, [%g3] ASI_DMMU
135 add %g6, TI_FPREGS + 0x40, %g2
136 faddd %f32, %f34, %f36
137 fmuld %f32, %f34, %f38
139 ldda [%g1] ASI_BLK_S, %f0
140 ldda [%g2] ASI_BLK_S, %f16
142 faddd %f32, %f34, %f40
143 fmuld %f32, %f34, %f42
144 faddd %f32, %f34, %f44
145 fmuld %f32, %f34, %f46
146 faddd %f32, %f34, %f48
147 fmuld %f32, %f34, %f50
148 faddd %f32, %f34, %f52
149 fmuld %f32, %f34, %f54
150 faddd %f32, %f34, %f56
151 fmuld %f32, %f34, %f58
152 faddd %f32, %f34, %f60
153 fmuld %f32, %f34, %f62
154 ba,pt %xcc, fpdis_exit
156 3: mov SECONDARY_CONTEXT, %g3
157 add %g6, TI_FPREGS, %g1
158 ldxa [%g3] ASI_DMMU, %g5
159 sethi %hi(sparc64_kern_sec_context), %g2
160 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
161 stxa %g2, [%g3] ASI_DMMU
165 ldda [%g1] ASI_BLK_S, %f0
166 ldda [%g1 + %g2] ASI_BLK_S, %f16
168 ldda [%g1] ASI_BLK_S, %f32
169 ldda [%g1 + %g2] ASI_BLK_S, %f48
172 stxa %g5, [%g3] ASI_DMMU
176 ldx [%g6 + TI_XFSR], %fsr
178 or %g3, %g4, %g3 ! anal...
180 wr %g0, FPRS_FEF, %fprs ! clean DU/DL bits
186 add %sp, PTREGS_OFF, %o0
190 .globl do_fpother_check_fitos
192 do_fpother_check_fitos:
194 sethi %hi(fp_other_bounce - 4), %g7
195 or %g7, %lo(fp_other_bounce - 4), %g7
197 /* NOTE: Need to preserve %g7 until we fully commit
198 * to the fitos fixup.
200 stx %fsr, [%g6 + TI_XFSR]
202 andcc %g3, TSTATE_PRIV, %g0
203 bne,pn %xcc, do_fptrap_after_fsr
205 ldx [%g6 + TI_XFSR], %g3
208 cmp %g1, 2 ! Unfinished FP-OP
209 bne,pn %xcc, do_fptrap_after_fsr
210 sethi %hi(1 << 23), %g1 ! Inexact
212 bne,pn %xcc, do_fptrap_after_fsr
214 lduwa [%g1] ASI_AIUP, %g3 ! This cannot ever fail
215 #define FITOS_MASK 0xc1f83fe0
216 #define FITOS_COMPARE 0x81a01880
217 sethi %hi(FITOS_MASK), %g1
218 or %g1, %lo(FITOS_MASK), %g1
220 sethi %hi(FITOS_COMPARE), %g2
221 or %g2, %lo(FITOS_COMPARE), %g2
223 bne,pn %xcc, do_fptrap_after_fsr
225 std %f62, [%g6 + TI_FPREGS + (62 * 4)]
226 sethi %hi(fitos_table_1), %g1
228 or %g1, %lo(fitos_table_1), %g1
231 ba,pt %xcc, fitos_emul_continue
268 sethi %hi(fitos_table_2), %g1
270 or %g1, %lo(fitos_table_2), %g1
274 ba,pt %xcc, fitos_emul_fini
311 ldd [%g6 + TI_FPREGS + (62 * 4)], %f62
317 stx %fsr, [%g6 + TI_XFSR]
319 ldub [%g6 + TI_FPSAVED], %g3
322 stb %g3, [%g6 + TI_FPSAVED]
324 stx %g3, [%g6 + TI_GSR]
325 mov SECONDARY_CONTEXT, %g3
326 ldxa [%g3] ASI_DMMU, %g5
327 sethi %hi(sparc64_kern_sec_context), %g2
328 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
329 stxa %g2, [%g3] ASI_DMMU
331 add %g6, TI_FPREGS, %g2
332 andcc %g1, FPRS_DL, %g0
335 stda %f0, [%g2] ASI_BLK_S
336 stda %f16, [%g2 + %g3] ASI_BLK_S
337 andcc %g1, FPRS_DU, %g0
340 stda %f32, [%g2] ASI_BLK_S
341 stda %f48, [%g2 + %g3] ASI_BLK_S
342 5: mov SECONDARY_CONTEXT, %g1
344 stxa %g5, [%g1] ASI_DMMU
349 /* The registers for cross calls will be:
351 * DATA 0: [low 32-bits] Address of function to call, jmp to this
352 * [high 32-bits] MMU Context Argument 0, place in %g5
353 * DATA 1: Address Argument 1, place in %g1
354 * DATA 2: Address Argument 2, place in %g7
356 * With this method we can do most of the cross-call tlb/cache
357 * flushing very quickly.
364 ldxa [%g3 + %g0] ASI_INTR_R, %g3
365 sethi %hi(KERNBASE), %g4
367 bgeu,pn %xcc, do_ivec_xcall
369 stxa %g0, [%g0] ASI_INTR_RECEIVE
372 sethi %hi(ivector_table), %g2
374 or %g2, %lo(ivector_table), %g2
376 ldub [%g3 + 0x04], %g4 /* pil */
383 lduw [%g6 + %g4], %g5 /* g5 = irq_work(cpu, pil) */
384 stw %g5, [%g3 + 0x00] /* bucket->irq_chain = g5 */
385 stw %g3, [%g6 + %g4] /* irq_work(cpu, pil) = bucket */
386 wr %g2, 0x0, %set_softint
390 ldxa [%g1 + %g0] ASI_INTR_R, %g1
394 ldxa [%g7 + %g0] ASI_INTR_R, %g7
395 stxa %g0, [%g0] ASI_INTR_RECEIVE
406 ldx [%o0 + PT_V9_TSTATE], %o1
410 stx %o1, [%o0 + PT_V9_G1]
412 ldx [%o0 + PT_V9_TSTATE], %o1
413 ldx [%o0 + PT_V9_G1], %o2
414 or %g0, %ulo(TSTATE_ICC), %o3
421 stx %o1, [%o0 + PT_V9_TSTATE]
424 utrap_trap: /* %g3=handler,%g4=level */
426 ldx [%g6 + TI_UTRAPS], %g1
427 brnz,pt %g1, invoke_utrap
434 add %sp, PTREGS_OFF, %o0
444 andn %l6, TSTATE_CWP, %l6
445 wrpr %l6, %l7, %tstate
451 /* We need to carefully read the error status, ACK
452 * the errors, prevent recursive traps, and pass the
453 * information on to C code for logging.
455 * We pass the AFAR in as-is, and we encode the status
456 * information as described in asm-sparc64/sfafsr.h
458 .globl __spitfire_access_error
459 __spitfire_access_error:
460 /* Disable ESTATE error reporting so that we do not
461 * take recursive traps and RED state the processor.
463 stxa %g0, [%g0] ASI_ESTATE_ERROR_EN
467 ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
469 /* __spitfire_cee_trap branches here with AFSR in %g4 and
470 * UDBE_CE in %g1. It only clears ESTATE_ERR_CE in the
471 * ESTATE Error Enable register.
473 __spitfire_cee_trap_continue:
474 ldxa [%g0] ASI_AFAR, %g5 ! Get AFAR
477 and %g3, 0x1ff, %g3 ! Paranoia
478 sllx %g3, SFSTAT_TRAP_TYPE_SHIFT, %g3
484 sllx %g3, SFSTAT_TL_GT_ONE_SHIFT, %g3
488 /* Read in the UDB error register state, clearing the
489 * sticky error bits as-needed. We only clear them if
490 * the UE bit is set. Likewise, __spitfire_cee_trap
491 * below will only do so if the CE bit is set.
493 * NOTE: UltraSparc-I/II have high and low UDB error
494 * registers, corresponding to the two UDB units
495 * present on those chips. UltraSparc-IIi only
496 * has a single UDB, called "SDB" in the manual.
497 * For IIi the upper UDB register always reads
498 * as zero so for our purposes things will just
499 * work with the checks below.
501 1: ldxa [%g0] ASI_UDBH_ERROR_R, %g3
502 and %g3, 0x3ff, %g7 ! Paranoia
503 sllx %g7, SFSTAT_UDBH_SHIFT, %g7
505 andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
508 stxa %g3, [%g0] ASI_UDB_ERROR_W
512 ldxa [%g3] ASI_UDBL_ERROR_R, %g3
513 and %g3, 0x3ff, %g7 ! Paranoia
514 sllx %g7, SFSTAT_UDBL_SHIFT, %g7
516 andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
520 stxa %g3, [%g7] ASI_UDB_ERROR_W
523 1: /* Ok, now that we've latched the error state,
524 * clear the sticky bits in the AFSR.
526 stxa %g4, [%g0] ASI_AFSR
541 1: ba,pt %xcc, etrap_irq
546 call spitfire_access_error
547 add %sp, PTREGS_OFF, %o0
551 /* This is the trap handler entry point for ECC correctable
552 * errors. They are corrected, but we listen for the trap
553 * so that the event can be logged.
555 * Disrupting errors are either:
556 * 1) single-bit ECC errors during UDB reads to system
558 * 2) data parity errors during write-back events
560 * As far as I can make out from the manual, the CEE trap
561 * is only for correctable errors during memory read
562 * accesses by the front-end of the processor.
564 * The code below is only for trap level 1 CEE events,
565 * as it is the only situation where we can safely record
566 * and log. For trap level >1 we just clear the CE bit
567 * in the AFSR and return.
569 * This is just like __spiftire_access_error above, but it
570 * specifically handles correctable errors. If an
571 * uncorrectable error is indicated in the AFSR we
572 * will branch directly above to __spitfire_access_error
573 * to handle it instead. Uncorrectable therefore takes
574 * priority over correctable, and the error logging
575 * C code will notice this case by inspecting the
578 .globl __spitfire_cee_trap
580 ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
582 sllx %g3, SFAFSR_UE_SHIFT, %g3
583 andcc %g4, %g3, %g0 ! Check for UE
584 bne,pn %xcc, __spitfire_access_error
587 /* Ok, in this case we only have a correctable error.
588 * Indicate we only wish to capture that state in register
589 * %g1, and we only disable CE error reporting unlike UE
590 * handling which disables all errors.
592 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g3
593 andn %g3, ESTATE_ERR_CE, %g3
594 stxa %g3, [%g0] ASI_ESTATE_ERROR_EN
597 /* Preserve AFSR in %g4, indicate UDB state to capture in %g1 */
598 ba,pt %xcc, __spitfire_cee_trap_continue
601 .globl __spitfire_data_access_exception
602 .globl __spitfire_data_access_exception_tl1
603 __spitfire_data_access_exception_tl1:
605 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
608 ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
609 ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
610 stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
613 cmp %g3, 0x80 ! first win spill/fill trap
615 cmp %g3, 0xff ! last win spill/fill trap
618 ba,pt %xcc, winfix_dax
620 1: sethi %hi(109f), %g7
622 109: or %g7, %lo(109b), %g7
625 call spitfire_data_access_exception_tl1
626 add %sp, PTREGS_OFF, %o0
630 __spitfire_data_access_exception:
632 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
635 ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
636 ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
637 stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
641 109: or %g7, %lo(109b), %g7
644 call spitfire_data_access_exception
645 add %sp, PTREGS_OFF, %o0
649 .globl __spitfire_insn_access_exception
650 .globl __spitfire_insn_access_exception_tl1
651 __spitfire_insn_access_exception_tl1:
653 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
655 ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
656 rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
657 stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
661 109: or %g7, %lo(109b), %g7
664 call spitfire_insn_access_exception_tl1
665 add %sp, PTREGS_OFF, %o0
669 __spitfire_insn_access_exception:
671 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
673 ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
674 rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
675 stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
679 109: or %g7, %lo(109b), %g7
682 call spitfire_insn_access_exception
683 add %sp, PTREGS_OFF, %o0
687 /* These get patched into the trap table at boot time
688 * once we know we have a cheetah processor.
690 .globl cheetah_fecc_trap_vector, cheetah_fecc_trap_vector_tl1
691 cheetah_fecc_trap_vector:
693 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
694 andn %g1, DCU_DC | DCU_IC, %g1
695 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
697 sethi %hi(cheetah_fast_ecc), %g2
698 jmpl %g2 + %lo(cheetah_fast_ecc), %g0
700 cheetah_fecc_trap_vector_tl1:
702 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
703 andn %g1, DCU_DC | DCU_IC, %g1
704 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
706 sethi %hi(cheetah_fast_ecc), %g2
707 jmpl %g2 + %lo(cheetah_fast_ecc), %g0
709 .globl cheetah_cee_trap_vector, cheetah_cee_trap_vector_tl1
710 cheetah_cee_trap_vector:
712 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
713 andn %g1, DCU_IC, %g1
714 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
716 sethi %hi(cheetah_cee), %g2
717 jmpl %g2 + %lo(cheetah_cee), %g0
719 cheetah_cee_trap_vector_tl1:
721 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
722 andn %g1, DCU_IC, %g1
723 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
725 sethi %hi(cheetah_cee), %g2
726 jmpl %g2 + %lo(cheetah_cee), %g0
728 .globl cheetah_deferred_trap_vector, cheetah_deferred_trap_vector_tl1
729 cheetah_deferred_trap_vector:
731 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
732 andn %g1, DCU_DC | DCU_IC, %g1;
733 stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
735 sethi %hi(cheetah_deferred_trap), %g2
736 jmpl %g2 + %lo(cheetah_deferred_trap), %g0
738 cheetah_deferred_trap_vector_tl1:
740 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
741 andn %g1, DCU_DC | DCU_IC, %g1;
742 stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
744 sethi %hi(cheetah_deferred_trap), %g2
745 jmpl %g2 + %lo(cheetah_deferred_trap), %g0
748 /* Cheetah+ specific traps. These are for the new I/D cache parity
749 * error traps. The first argument to cheetah_plus_parity_handler
750 * is encoded as follows:
752 * Bit0: 0=dcache,1=icache
753 * Bit1: 0=recoverable,1=unrecoverable
755 .globl cheetah_plus_dcpe_trap_vector, cheetah_plus_dcpe_trap_vector_tl1
756 cheetah_plus_dcpe_trap_vector:
758 sethi %hi(do_cheetah_plus_data_parity), %g7
759 jmpl %g7 + %lo(do_cheetah_plus_data_parity), %g0
766 do_cheetah_plus_data_parity:
769 ba,pt %xcc, etrap_irq
772 call cheetah_plus_parity_error
773 add %sp, PTREGS_OFF, %o1
774 ba,a,pt %xcc, rtrap_irq
776 cheetah_plus_dcpe_trap_vector_tl1:
778 wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
779 sethi %hi(do_dcpe_tl1), %g3
780 jmpl %g3 + %lo(do_dcpe_tl1), %g0
786 .globl cheetah_plus_icpe_trap_vector, cheetah_plus_icpe_trap_vector_tl1
787 cheetah_plus_icpe_trap_vector:
789 sethi %hi(do_cheetah_plus_insn_parity), %g7
790 jmpl %g7 + %lo(do_cheetah_plus_insn_parity), %g0
797 do_cheetah_plus_insn_parity:
800 ba,pt %xcc, etrap_irq
803 call cheetah_plus_parity_error
804 add %sp, PTREGS_OFF, %o1
805 ba,a,pt %xcc, rtrap_irq
807 cheetah_plus_icpe_trap_vector_tl1:
809 wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
810 sethi %hi(do_icpe_tl1), %g3
811 jmpl %g3 + %lo(do_icpe_tl1), %g0
817 /* If we take one of these traps when tl >= 1, then we
818 * jump to interrupt globals. If some trap level above us
819 * was also using interrupt globals, we cannot recover.
820 * We may use all interrupt global registers except %g6.
822 .globl do_dcpe_tl1, do_icpe_tl1
824 rdpr %tl, %g1 ! Save original trap level
825 mov 1, %g2 ! Setup TSTATE checking loop
826 sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
827 1: wrpr %g2, %tl ! Set trap level to check
828 rdpr %tstate, %g4 ! Read TSTATE for this level
829 andcc %g4, %g3, %g0 ! Interrupt globals in use?
830 bne,a,pn %xcc, do_dcpe_tl1_fatal ! Yep, irrecoverable
831 wrpr %g1, %tl ! Restore original trap level
832 add %g2, 1, %g2 ! Next trap level
833 cmp %g2, %g1 ! Hit them all yet?
834 ble,pt %icc, 1b ! Not yet
836 wrpr %g1, %tl ! Restore original trap level
837 do_dcpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
838 sethi %hi(dcache_parity_tl1_occurred), %g2
839 lduw [%g2 + %lo(dcache_parity_tl1_occurred)], %g1
841 stw %g1, [%g2 + %lo(dcache_parity_tl1_occurred)]
842 /* Reset D-cache parity */
843 sethi %hi(1 << 16), %g1 ! D-cache size
844 mov (1 << 5), %g2 ! D-cache line size
845 sub %g1, %g2, %g1 ! Move down 1 cacheline
846 1: srl %g1, 14, %g3 ! Compute UTAG
848 stxa %g3, [%g1] ASI_DCACHE_UTAG
850 sub %g2, 8, %g3 ! 64-bit data word within line
852 stxa %g0, [%g1 + %g3] ASI_DCACHE_DATA
854 subcc %g3, 8, %g3 ! Next 64-bit data word
857 subcc %g1, %g2, %g1 ! Next cacheline
860 ba,pt %xcc, dcpe_icpe_tl1_common
866 1: or %g7, %lo(1b), %g7
868 call cheetah_plus_parity_error
869 add %sp, PTREGS_OFF, %o1
874 rdpr %tl, %g1 ! Save original trap level
875 mov 1, %g2 ! Setup TSTATE checking loop
876 sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
877 1: wrpr %g2, %tl ! Set trap level to check
878 rdpr %tstate, %g4 ! Read TSTATE for this level
879 andcc %g4, %g3, %g0 ! Interrupt globals in use?
880 bne,a,pn %xcc, do_icpe_tl1_fatal ! Yep, irrecoverable
881 wrpr %g1, %tl ! Restore original trap level
882 add %g2, 1, %g2 ! Next trap level
883 cmp %g2, %g1 ! Hit them all yet?
884 ble,pt %icc, 1b ! Not yet
886 wrpr %g1, %tl ! Restore original trap level
887 do_icpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
888 sethi %hi(icache_parity_tl1_occurred), %g2
889 lduw [%g2 + %lo(icache_parity_tl1_occurred)], %g1
891 stw %g1, [%g2 + %lo(icache_parity_tl1_occurred)]
893 sethi %hi(1 << 15), %g1 ! I-cache size
894 mov (1 << 5), %g2 ! I-cache line size
896 1: or %g1, (2 << 3), %g3
897 stxa %g0, [%g3] ASI_IC_TAG
902 ba,pt %xcc, dcpe_icpe_tl1_common
908 1: or %g7, %lo(1b), %g7
910 call cheetah_plus_parity_error
911 add %sp, PTREGS_OFF, %o1
915 dcpe_icpe_tl1_common:
916 /* Flush D-cache, re-enable D/I caches in DCU and finally
917 * retry the trapping instruction.
919 sethi %hi(1 << 16), %g1 ! D-cache size
920 mov (1 << 5), %g2 ! D-cache line size
922 1: stxa %g0, [%g1] ASI_DCACHE_TAG
927 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
928 or %g1, (DCU_DC | DCU_IC), %g1
929 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
933 /* Capture I/D/E-cache state into per-cpu error scoreboard.
935 * %g1: (TL>=0) ? 1 : 0
940 * %g6: unused, will have current thread ptr after etrap
944 /* Put "TL1" software bit into AFSR. */
949 /* Get log entry pointer for this cpu at this trap level. */
950 BRANCH_IF_JALAPENO(g2,g3,50f)
951 ldxa [%g0] ASI_SAFARI_CONFIG, %g2
956 50: ldxa [%g0] ASI_JBUS_CONFIG, %g2
961 sethi %hi(cheetah_error_log), %g3
962 ldx [%g3 + %lo(cheetah_error_log)], %g3
970 /* %g1 holds pointer to the top of the logging scoreboard */
980 /* %g1 now points to D-cache logging area */
981 set 0x3ff8, %g2 /* DC_addr mask */
982 and %g5, %g2, %g2 /* DC_addr bits of AFAR */
984 or %g3, 1, %g3 /* PHYS tag + valid */
986 10: ldxa [%g2] ASI_DCACHE_TAG, %g7
987 cmp %g3, %g7 /* TAG match? */
991 /* Yep, what we want, capture state. */
992 stx %g2, [%g1 + 0x20]
993 stx %g7, [%g1 + 0x28]
995 /* A membar Sync is required before and after utag access. */
997 ldxa [%g2] ASI_DCACHE_UTAG, %g7
999 stx %g7, [%g1 + 0x30]
1000 ldxa [%g2] ASI_DCACHE_SNOOP_TAG, %g7
1001 stx %g7, [%g1 + 0x38]
1004 12: ldxa [%g2 + %g3] ASI_DCACHE_DATA, %g7
1006 add %g3, (1 << 5), %g3
1014 13: sethi %hi(1 << 14), %g7
1023 /* %g1 now points to I-cache logging area */
1024 20: set 0x1fe0, %g2 /* IC_addr mask */
1025 and %g5, %g2, %g2 /* IC_addr bits of AFAR */
1026 sllx %g2, 1, %g2 /* IC_addr[13:6]==VA[12:5] */
1027 srlx %g5, (13 - 8), %g3 /* Make PTAG */
1028 andn %g3, 0xff, %g3 /* Mask off undefined bits */
1030 21: ldxa [%g2] ASI_IC_TAG, %g7
1036 /* Yep, what we want, capture state. */
1037 stx %g2, [%g1 + 0x40]
1038 stx %g7, [%g1 + 0x48]
1039 add %g2, (1 << 3), %g2
1040 ldxa [%g2] ASI_IC_TAG, %g7
1041 add %g2, (1 << 3), %g2
1042 stx %g7, [%g1 + 0x50]
1043 ldxa [%g2] ASI_IC_TAG, %g7
1044 add %g2, (1 << 3), %g2
1045 stx %g7, [%g1 + 0x60]
1046 ldxa [%g2] ASI_IC_TAG, %g7
1047 stx %g7, [%g1 + 0x68]
1048 sub %g2, (3 << 3), %g2
1049 ldxa [%g2] ASI_IC_STAG, %g7
1050 stx %g7, [%g1 + 0x58]
1054 22: ldxa [%g2 + %g3] ASI_IC_INSTR, %g7
1056 add %g3, (1 << 3), %g3
1064 23: sethi %hi(1 << 14), %g7
1073 /* %g1 now points to E-cache logging area */
1074 30: andn %g5, (32 - 1), %g2
1075 stx %g2, [%g1 + 0x20]
1076 ldxa [%g2] ASI_EC_TAG_DATA, %g7
1077 stx %g7, [%g1 + 0x28]
1078 ldxa [%g2] ASI_EC_R, %g0
1081 31: ldxa [%g3] ASI_EC_DATA, %g7
1082 stx %g7, [%g1 + %g3]
1095 ba,pt %xcc, c_deferred
1097 /* Cheetah FECC trap handling, we get here from tl{0,1}_fecc
1098 * in the trap table. That code has done a memory barrier
1099 * and has disabled both the I-cache and D-cache in the DCU
1100 * control register. The I-cache is disabled so that we may
1101 * capture the corrupted cache line, and the D-cache is disabled
1102 * because corrupt data may have been placed there and we don't
1103 * want to reference it.
1105 * %g1 is one if this trap occurred at %tl >= 1.
1107 * Next, we turn off error reporting so that we don't recurse.
1109 .globl cheetah_fast_ecc
1111 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1112 andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
1113 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1116 /* Fetch and clear AFSR/AFAR */
1117 ldxa [%g0] ASI_AFSR, %g4
1118 ldxa [%g0] ASI_AFAR, %g5
1119 stxa %g4, [%g0] ASI_AFSR
1122 ba,pt %xcc, __cheetah_log_error
1128 ba,pt %xcc, etrap_irq
1132 call cheetah_fecc_handler
1133 add %sp, PTREGS_OFF, %o0
1134 ba,a,pt %xcc, rtrap_irq
1136 /* Our caller has disabled I-cache and performed membar Sync. */
1139 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1140 andn %g2, ESTATE_ERROR_CEEN, %g2
1141 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1144 /* Fetch and clear AFSR/AFAR */
1145 ldxa [%g0] ASI_AFSR, %g4
1146 ldxa [%g0] ASI_AFAR, %g5
1147 stxa %g4, [%g0] ASI_AFSR
1150 ba,pt %xcc, __cheetah_log_error
1156 ba,pt %xcc, etrap_irq
1160 call cheetah_cee_handler
1161 add %sp, PTREGS_OFF, %o0
1162 ba,a,pt %xcc, rtrap_irq
1164 /* Our caller has disabled I-cache+D-cache and performed membar Sync. */
1165 .globl cheetah_deferred_trap
1166 cheetah_deferred_trap:
1167 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1168 andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
1169 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1172 /* Fetch and clear AFSR/AFAR */
1173 ldxa [%g0] ASI_AFSR, %g4
1174 ldxa [%g0] ASI_AFAR, %g5
1175 stxa %g4, [%g0] ASI_AFSR
1178 ba,pt %xcc, __cheetah_log_error
1184 ba,pt %xcc, etrap_irq
1188 call cheetah_deferred_handler
1189 add %sp, PTREGS_OFF, %o0
1190 ba,a,pt %xcc, rtrap_irq
1195 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
1197 sethi %hi(109f), %g7
1199 109: or %g7, %lo(109b), %g7
1201 add %sp, PTREGS_OFF, %o0
1210 /* Setup %g4/%g5 now as they are used in the
1215 ldxa [%g4] ASI_DMMU, %g4
1216 ldxa [%g3] ASI_DMMU, %g5
1217 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
1219 bgu,pn %icc, winfix_mna
1222 1: sethi %hi(109f), %g7
1224 109: or %g7, %lo(109b), %g7
1227 call mem_address_unaligned
1228 add %sp, PTREGS_OFF, %o0
1234 sethi %hi(109f), %g7
1236 ldxa [%g4] ASI_DMMU, %g5
1237 stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
1240 ldxa [%g4] ASI_DMMU, %g4
1242 109: or %g7, %lo(109b), %g7
1246 add %sp, PTREGS_OFF, %o0
1252 sethi %hi(109f), %g7
1254 ldxa [%g4] ASI_DMMU, %g5
1255 stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
1258 ldxa [%g4] ASI_DMMU, %g4
1260 109: or %g7, %lo(109b), %g7
1264 add %sp, PTREGS_OFF, %o0
1268 .globl breakpoint_trap
1270 call sparc_breakpoint
1271 add %sp, PTREGS_OFF, %o0
1275 #if defined(CONFIG_SUNOS_EMUL) || defined(CONFIG_SOLARIS_EMUL) || \
1276 defined(CONFIG_SOLARIS_EMUL_MODULE)
1277 /* SunOS uses syscall zero as the 'indirect syscall' it looks
1278 * like indir_syscall(scall_num, arg0, arg1, arg2...); etc.
1279 * This is complete brain damage.
1285 cmp %o0, NR_SYSCALLS
1288 sethi %hi(sunos_nosys), %l6
1290 or %l6, %lo(sunos_nosys), %l6
1291 1: sethi %hi(sunos_sys_table), %l7
1292 or %l7, %lo(sunos_sys_table), %l7
1293 lduw [%l7 + %o0], %l6
1307 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1308 b,pt %xcc, ret_sys_call
1309 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1311 /* SunOS getuid() returns uid in %o0 and euid in %o1 */
1314 call sys32_geteuid16
1317 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1318 b,pt %xcc, ret_sys_call
1319 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1321 /* SunOS getgid() returns gid in %o0 and egid in %o1 */
1324 call sys32_getegid16
1327 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1328 b,pt %xcc, ret_sys_call
1329 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1332 /* SunOS's execv() call only specifies the argv argument, the
1333 * environment settings are the same as the calling processes.
1337 sethi %hi(sparc_execve), %g1
1338 ba,pt %xcc, execve_merge
1339 or %g1, %lo(sparc_execve), %g1
1340 #ifdef CONFIG_COMPAT
1343 stx %g0, [%sp + PTREGS_OFF + PT_V9_I2]
1346 sethi %hi(sparc32_execve), %g1
1347 or %g1, %lo(sparc32_execve), %g1
1352 add %sp, PTREGS_OFF, %o0
1354 .globl sys_pipe, sys_sigpause, sys_nis_syscall
1355 .globl sys_rt_sigreturn
1357 .globl sys_sigaltstack
1359 sys_pipe: ba,pt %xcc, sparc_pipe
1360 add %sp, PTREGS_OFF, %o0
1361 sys_nis_syscall:ba,pt %xcc, c_sys_nis_syscall
1362 add %sp, PTREGS_OFF, %o0
1363 sys_memory_ordering:
1364 ba,pt %xcc, sparc_memory_ordering
1365 add %sp, PTREGS_OFF, %o1
1366 sys_sigaltstack:ba,pt %xcc, do_sigaltstack
1367 add %i6, STACK_BIAS, %o2
1368 #ifdef CONFIG_COMPAT
1369 .globl sys32_sigstack
1370 sys32_sigstack: ba,pt %xcc, do_sys32_sigstack
1372 .globl sys32_sigaltstack
1374 ba,pt %xcc, do_sys32_sigaltstack
1378 #ifdef CONFIG_COMPAT
1379 .globl sys32_sigreturn
1381 add %sp, PTREGS_OFF, %o0
1383 add %o7, 1f-.-4, %o7
1387 add %sp, PTREGS_OFF, %o0
1388 call do_rt_sigreturn
1389 add %o7, 1f-.-4, %o7
1391 #ifdef CONFIG_COMPAT
1392 .globl sys32_rt_sigreturn
1394 add %sp, PTREGS_OFF, %o0
1395 call do_rt_sigreturn32
1396 add %o7, 1f-.-4, %o7
1399 sys_ptrace: add %sp, PTREGS_OFF, %o0
1401 add %o7, 1f-.-4, %o7
1404 1: ldx [%curptr + TI_FLAGS], %l5
1405 andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1408 add %sp, PTREGS_OFF, %o0
1415 /* This is how fork() was meant to be done, 8 instruction entry.
1417 * I questioned the following code briefly, let me clear things
1418 * up so you must not reason on it like I did.
1420 * Know the fork_kpsr etc. we use in the sparc32 port? We don't
1421 * need it here because the only piece of window state we copy to
1422 * the child is the CWP register. Even if the parent sleeps,
1423 * we are safe because we stuck it into pt_regs of the parent
1424 * so it will not change.
1426 * XXX This raises the question, whether we can do the same on
1427 * XXX sparc32 to get rid of fork_kpsr _and_ fork_kwim. The
1428 * XXX answer is yes. We stick fork_kpsr in UREG_G0 and
1429 * XXX fork_kwim in UREG_G1 (global registers are considered
1430 * XXX volatile across a system call in the sparc ABI I think
1431 * XXX if it isn't we can use regs->y instead, anyone who depends
1432 * XXX upon the Y register being preserved across a fork deserves
1435 * In fact we should take advantage of that fact for other things
1436 * during system calls...
1438 .globl sys_fork, sys_vfork, sys_clone, sparc_exit
1439 .globl ret_from_syscall
1441 sys_vfork: /* Under Linux, vfork and fork are just special cases of clone. */
1442 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1443 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1444 ba,pt %xcc, sys_clone
1450 ba,pt %xcc, sparc_do_fork
1451 add %sp, PTREGS_OFF, %o2
1453 /* Clear current_thread_info()->new_child, and
1454 * check performance counter stuff too.
1456 stb %g0, [%g6 + TI_NEW_CHILD]
1457 ldx [%g6 + TI_FLAGS], %l0
1460 andcc %l0, _TIF_PERFCTR, %g0
1463 ldx [%g6 + TI_PCR], %o7
1466 /* Blackbird errata workaround. See commentary in
1467 * smp.c:smp_percpu_timer_interrupt() for more
1473 99: wr %g0, %g0, %pic
1476 1: b,pt %xcc, ret_sys_call
1477 ldx [%sp + PTREGS_OFF + PT_V9_I0], %o0
1478 sparc_exit: wrpr %g0, (PSTATE_RMO | PSTATE_PEF | PSTATE_PRIV), %pstate
1482 wrpr %g3, 0x0, %cansave
1483 wrpr %g0, 0x0, %otherwin
1484 wrpr %g0, (PSTATE_RMO | PSTATE_PEF | PSTATE_PRIV | PSTATE_IE), %pstate
1485 ba,pt %xcc, sys_exit
1486 stb %g0, [%g6 + TI_WSAVED]
1488 linux_sparc_ni_syscall:
1489 sethi %hi(sys_ni_syscall), %l7
1491 or %l7, %lo(sys_ni_syscall), %l7
1493 linux_syscall_trace32:
1494 add %sp, PTREGS_OFF, %o0
1504 linux_syscall_trace:
1505 add %sp, PTREGS_OFF, %o0
1516 /* Linux 32-bit and SunOS system calls enter here... */
1518 .globl linux_sparc_syscall32
1519 linux_sparc_syscall32:
1520 /* Direct access to user regs, much faster. */
1521 cmp %g1, NR_SYSCALLS ! IEU1 Group
1522 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
1523 srl %i0, 0, %o0 ! IEU0
1524 sll %g1, 2, %l4 ! IEU0 Group
1525 srl %i4, 0, %o4 ! IEU1
1526 lduw [%l7 + %l4], %l7 ! Load
1527 srl %i1, 0, %o1 ! IEU0 Group
1528 ldx [%curptr + TI_FLAGS], %l0 ! Load
1530 srl %i5, 0, %o5 ! IEU1
1531 srl %i2, 0, %o2 ! IEU0 Group
1532 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1533 bne,pn %icc, linux_syscall_trace32 ! CTI
1535 call %l7 ! CTI Group brk forced
1536 srl %i3, 0, %o3 ! IEU0
1539 /* Linux native and SunOS system calls enter here... */
1541 .globl linux_sparc_syscall, ret_sys_call
1542 linux_sparc_syscall:
1543 /* Direct access to user regs, much faster. */
1544 cmp %g1, NR_SYSCALLS ! IEU1 Group
1545 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
1547 sll %g1, 2, %l4 ! IEU0 Group
1549 lduw [%l7 + %l4], %l7 ! Load
1550 4: mov %i2, %o2 ! IEU0 Group
1551 ldx [%curptr + TI_FLAGS], %l0 ! Load
1554 mov %i4, %o4 ! IEU0 Group
1555 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1556 bne,pn %icc, linux_syscall_trace ! CTI Group
1558 2: call %l7 ! CTI Group brk forced
1562 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1564 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
1565 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
1567 mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
1570 /* Check if force_successful_syscall_return()
1573 ldub [%curptr + TI_SYS_NOERROR], %l2
1575 stb %g0, [%curptr + TI_SYS_NOERROR]
1577 cmp %o0, -ERESTART_RESTARTBLOCK
1579 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
1581 /* System call success, clear Carry condition code. */
1583 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
1584 bne,pn %icc, linux_syscall_trace2
1585 add %l1, 0x4, %l2 ! npc = npc+4
1586 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1587 ba,pt %xcc, rtrap_clr_l6
1588 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1591 /* System call failure, set Carry condition code.
1592 * Also, get abs(errno) to return to the process.
1594 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
1597 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1599 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
1600 bne,pn %icc, linux_syscall_trace2
1601 add %l1, 0x4, %l2 ! npc = npc+4
1602 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1605 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1606 linux_syscall_trace2:
1607 add %sp, PTREGS_OFF, %o0
1610 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1612 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1615 .globl __flushw_user
1620 1: save %sp, -128, %sp
1626 restore %g0, %g0, %g0
1630 /* Read cpu ID from hardware, return in %g6.
1631 * (callers_pc - 4) is in %g1. Patched at boot time.
1633 * Default is spitfire implementation.
1635 * The instruction sequence needs to be 5 instructions
1636 * in order to fit the longest implementation, which is
1637 * currently starfire.
1642 ldxa [%g0] ASI_UPA_CONFIG, %g6
1648 __get_cpu_id_cheetah_safari:
1649 ldxa [%g0] ASI_SAFARI_CONFIG, %g6
1655 __get_cpu_id_cheetah_jbus:
1656 ldxa [%g0] ASI_JBUS_CONFIG, %g6
1662 __get_cpu_id_starfire:
1663 sethi %hi(0x1fff40000d0 >> 9), %g6
1667 lduwa [%g6] ASI_PHYS_BYPASS_EC_E, %g6
1669 .globl per_cpu_patch
1671 sethi %hi(this_is_starfire), %o0
1672 lduw [%o0 + %lo(this_is_starfire)], %o1
1673 sethi %hi(__get_cpu_id_starfire), %o0
1675 or %o0, %lo(__get_cpu_id_starfire), %o0
1676 sethi %hi(tlb_type), %o0
1677 lduw [%o0 + %lo(tlb_type)], %o1
1682 sethi %hi(0x003e0016), %o1
1683 or %o1, %lo(0x003e0016), %o1
1685 sethi %hi(__get_cpu_id_cheetah_jbus), %o0
1687 or %o0, %lo(__get_cpu_id_cheetah_jbus), %o0
1688 sethi %hi(__get_cpu_id_cheetah_safari), %o0
1689 or %o0, %lo(__get_cpu_id_cheetah_safari), %o0
1691 sethi %hi(__get_cpu_id), %o1
1692 or %o1, %lo(__get_cpu_id), %o1
1693 lduw [%o0 + 0x00], %o2
1694 stw %o2, [%o1 + 0x00]
1696 lduw [%o0 + 0x04], %o2
1697 stw %o2, [%o1 + 0x04]
1699 lduw [%o0 + 0x08], %o2
1700 stw %o2, [%o1 + 0x08]
1702 lduw [%o0 + 0x0c], %o2
1703 stw %o2, [%o1 + 0x0c]
1705 lduw [%o0 + 0x10], %o2
1706 stw %o2, [%o1 + 0x10]