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: ldub [%g6 + TI_FPSAVED], %g5
54 wr %g0, FPRS_FEF, %fprs
55 andcc %g5, FPRS_FEF, %g0
58 ldx [%g6 + TI_GSR], %g7
59 1: andcc %g5, FPRS_DL, %g0
62 andcc %g5, FPRS_DU, %g0
93 b,pt %xcc, fpdis_exit2
95 1: mov SECONDARY_CONTEXT, %g3
96 add %g6, TI_FPREGS + 0x80, %g1
99 ldxa [%g3] ASI_DMMU, %g5
100 sethi %hi(sparc64_kern_sec_context), %g2
101 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
102 stxa %g2, [%g3] ASI_DMMU
104 add %g6, TI_FPREGS + 0xc0, %g2
108 ldda [%g1] ASI_BLK_S, %f32
109 ldda [%g2] ASI_BLK_S, %f48
121 b,pt %xcc, fpdis_exit
123 2: andcc %g5, FPRS_DU, %g0
126 mov SECONDARY_CONTEXT, %g3
128 ldxa [%g3] ASI_DMMU, %g5
129 add %g6, TI_FPREGS, %g1
130 sethi %hi(sparc64_kern_sec_context), %g2
131 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
132 stxa %g2, [%g3] ASI_DMMU
134 add %g6, TI_FPREGS + 0x40, %g2
135 faddd %f32, %f34, %f36
136 fmuld %f32, %f34, %f38
138 ldda [%g1] ASI_BLK_S, %f0
139 ldda [%g2] ASI_BLK_S, %f16
141 faddd %f32, %f34, %f40
142 fmuld %f32, %f34, %f42
143 faddd %f32, %f34, %f44
144 fmuld %f32, %f34, %f46
145 faddd %f32, %f34, %f48
146 fmuld %f32, %f34, %f50
147 faddd %f32, %f34, %f52
148 fmuld %f32, %f34, %f54
149 faddd %f32, %f34, %f56
150 fmuld %f32, %f34, %f58
151 faddd %f32, %f34, %f60
152 fmuld %f32, %f34, %f62
153 ba,pt %xcc, fpdis_exit
155 3: mov SECONDARY_CONTEXT, %g3
156 add %g6, TI_FPREGS, %g1
157 ldxa [%g3] ASI_DMMU, %g5
158 sethi %hi(sparc64_kern_sec_context), %g2
159 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
160 stxa %g2, [%g3] ASI_DMMU
164 ldda [%g1] ASI_BLK_S, %f0
165 ldda [%g1 + %g2] ASI_BLK_S, %f16
167 ldda [%g1] ASI_BLK_S, %f32
168 ldda [%g1 + %g2] ASI_BLK_S, %f48
171 stxa %g5, [%g3] ASI_DMMU
175 ldx [%g6 + TI_XFSR], %fsr
177 or %g3, %g4, %g3 ! anal...
179 wr %g0, FPRS_FEF, %fprs ! clean DU/DL bits
185 add %sp, PTREGS_OFF, %o0
189 .globl do_fpother_check_fitos
191 do_fpother_check_fitos:
192 sethi %hi(fp_other_bounce - 4), %g7
193 or %g7, %lo(fp_other_bounce - 4), %g7
195 /* NOTE: Need to preserve %g7 until we fully commit
196 * to the fitos fixup.
198 stx %fsr, [%g6 + TI_XFSR]
200 andcc %g3, TSTATE_PRIV, %g0
201 bne,pn %xcc, do_fptrap_after_fsr
203 ldx [%g6 + TI_XFSR], %g3
206 cmp %g1, 2 ! Unfinished FP-OP
207 bne,pn %xcc, do_fptrap_after_fsr
208 sethi %hi(1 << 23), %g1 ! Inexact
210 bne,pn %xcc, do_fptrap_after_fsr
212 lduwa [%g1] ASI_AIUP, %g3 ! This cannot ever fail
213 #define FITOS_MASK 0xc1f83fe0
214 #define FITOS_COMPARE 0x81a01880
215 sethi %hi(FITOS_MASK), %g1
216 or %g1, %lo(FITOS_MASK), %g1
218 sethi %hi(FITOS_COMPARE), %g2
219 or %g2, %lo(FITOS_COMPARE), %g2
221 bne,pn %xcc, do_fptrap_after_fsr
223 std %f62, [%g6 + TI_FPREGS + (62 * 4)]
224 sethi %hi(fitos_table_1), %g1
226 or %g1, %lo(fitos_table_1), %g1
229 ba,pt %xcc, fitos_emul_continue
266 sethi %hi(fitos_table_2), %g1
268 or %g1, %lo(fitos_table_2), %g1
272 ba,pt %xcc, fitos_emul_fini
309 ldd [%g6 + TI_FPREGS + (62 * 4)], %f62
315 stx %fsr, [%g6 + TI_XFSR]
317 ldub [%g6 + TI_FPSAVED], %g3
320 stb %g3, [%g6 + TI_FPSAVED]
322 stx %g3, [%g6 + TI_GSR]
323 mov SECONDARY_CONTEXT, %g3
324 ldxa [%g3] ASI_DMMU, %g5
325 sethi %hi(sparc64_kern_sec_context), %g2
326 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
327 stxa %g2, [%g3] ASI_DMMU
329 add %g6, TI_FPREGS, %g2
330 andcc %g1, FPRS_DL, %g0
333 stda %f0, [%g2] ASI_BLK_S
334 stda %f16, [%g2 + %g3] ASI_BLK_S
335 andcc %g1, FPRS_DU, %g0
338 stda %f32, [%g2] ASI_BLK_S
339 stda %f48, [%g2 + %g3] ASI_BLK_S
340 5: mov SECONDARY_CONTEXT, %g1
342 stxa %g5, [%g1] ASI_DMMU
347 /* The registers for cross calls will be:
349 * DATA 0: [low 32-bits] Address of function to call, jmp to this
350 * [high 32-bits] MMU Context Argument 0, place in %g5
351 * DATA 1: Address Argument 1, place in %g1
352 * DATA 2: Address Argument 2, place in %g7
354 * With this method we can do most of the cross-call tlb/cache
355 * flushing very quickly.
357 * Current CPU's IRQ worklist table is locked into %g6, don't touch.
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 */
381 lduw [%g6 + %g4], %g5 /* g5 = irq_work(cpu, pil) */
382 stw %g5, [%g3 + 0x00] /* bucket->irq_chain = g5 */
383 stw %g3, [%g6 + %g4] /* irq_work(cpu, pil) = bucket */
384 wr %g2, 0x0, %set_softint
388 ldxa [%g1 + %g0] ASI_INTR_R, %g1
392 ldxa [%g7 + %g0] ASI_INTR_R, %g7
393 stxa %g0, [%g0] ASI_INTR_RECEIVE
402 .globl save_alternate_globals
403 save_alternate_globals: /* %o0 = save_area */
405 andn %o5, PSTATE_IE, %o1
406 wrpr %o1, PSTATE_AG, %pstate
407 stx %g0, [%o0 + 0x00]
408 stx %g1, [%o0 + 0x08]
409 stx %g2, [%o0 + 0x10]
410 stx %g3, [%o0 + 0x18]
411 stx %g4, [%o0 + 0x20]
412 stx %g5, [%o0 + 0x28]
413 stx %g6, [%o0 + 0x30]
414 stx %g7, [%o0 + 0x38]
415 wrpr %o1, PSTATE_IG, %pstate
416 stx %g0, [%o0 + 0x40]
417 stx %g1, [%o0 + 0x48]
418 stx %g2, [%o0 + 0x50]
419 stx %g3, [%o0 + 0x58]
420 stx %g4, [%o0 + 0x60]
421 stx %g5, [%o0 + 0x68]
422 stx %g6, [%o0 + 0x70]
423 stx %g7, [%o0 + 0x78]
424 wrpr %o1, PSTATE_MG, %pstate
425 stx %g0, [%o0 + 0x80]
426 stx %g1, [%o0 + 0x88]
427 stx %g2, [%o0 + 0x90]
428 stx %g3, [%o0 + 0x98]
429 stx %g4, [%o0 + 0xa0]
430 stx %g5, [%o0 + 0xa8]
431 stx %g6, [%o0 + 0xb0]
432 stx %g7, [%o0 + 0xb8]
433 wrpr %o5, 0x0, %pstate
437 .globl restore_alternate_globals
438 restore_alternate_globals: /* %o0 = save_area */
440 andn %o5, PSTATE_IE, %o1
441 wrpr %o1, PSTATE_AG, %pstate
442 ldx [%o0 + 0x00], %g0
443 ldx [%o0 + 0x08], %g1
444 ldx [%o0 + 0x10], %g2
445 ldx [%o0 + 0x18], %g3
446 ldx [%o0 + 0x20], %g4
447 ldx [%o0 + 0x28], %g5
448 ldx [%o0 + 0x30], %g6
449 ldx [%o0 + 0x38], %g7
450 wrpr %o1, PSTATE_IG, %pstate
451 ldx [%o0 + 0x40], %g0
452 ldx [%o0 + 0x48], %g1
453 ldx [%o0 + 0x50], %g2
454 ldx [%o0 + 0x58], %g3
455 ldx [%o0 + 0x60], %g4
456 ldx [%o0 + 0x68], %g5
457 ldx [%o0 + 0x70], %g6
458 ldx [%o0 + 0x78], %g7
459 wrpr %o1, PSTATE_MG, %pstate
460 ldx [%o0 + 0x80], %g0
461 ldx [%o0 + 0x88], %g1
462 ldx [%o0 + 0x90], %g2
463 ldx [%o0 + 0x98], %g3
464 ldx [%o0 + 0xa0], %g4
465 ldx [%o0 + 0xa8], %g5
466 ldx [%o0 + 0xb0], %g6
467 ldx [%o0 + 0xb8], %g7
468 wrpr %o5, 0x0, %pstate
474 ldx [%o0 + PT_V9_TSTATE], %o1
478 stx %o1, [%o0 + PT_V9_G1]
480 ldx [%o0 + PT_V9_TSTATE], %o1
481 ldx [%o0 + PT_V9_G1], %o2
482 or %g0, %ulo(TSTATE_ICC), %o3
489 stx %o1, [%o0 + PT_V9_TSTATE]
491 .globl utrap, utrap_ill
492 utrap: brz,pn %g1, etrap
497 andn %l6, TSTATE_CWP, %l6
498 wrpr %l6, %l7, %tstate
505 add %sp, PTREGS_OFF, %o0
509 /* XXX Here is stuff we still need to write... -DaveM XXX */
510 .globl netbsd_syscall
515 /* We need to carefully read the error status, ACK
516 * the errors, prevent recursive traps, and pass the
517 * information on to C code for logging.
519 * We pass the AFAR in as-is, and we encode the status
520 * information as described in asm-sparc64/sfafsr.h
522 .globl __spitfire_access_error
523 __spitfire_access_error:
524 /* Disable ESTATE error reporting so that we do not
525 * take recursive traps and RED state the processor.
527 stxa %g0, [%g0] ASI_ESTATE_ERROR_EN
531 ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
533 /* __spitfire_cee_trap branches here with AFSR in %g4 and
534 * UDBE_CE in %g1. It only clears ESTATE_ERR_CE in the
535 * ESTATE Error Enable register.
537 __spitfire_cee_trap_continue:
538 ldxa [%g0] ASI_AFAR, %g5 ! Get AFAR
541 and %g3, 0x1ff, %g3 ! Paranoia
542 sllx %g3, SFSTAT_TRAP_TYPE_SHIFT, %g3
548 sllx %g3, SFSTAT_TL_GT_ONE_SHIFT, %g3
552 /* Read in the UDB error register state, clearing the
553 * sticky error bits as-needed. We only clear them if
554 * the UE bit is set. Likewise, __spitfire_cee_trap
555 * below will only do so if the CE bit is set.
557 * NOTE: UltraSparc-I/II have high and low UDB error
558 * registers, corresponding to the two UDB units
559 * present on those chips. UltraSparc-IIi only
560 * has a single UDB, called "SDB" in the manual.
561 * For IIi the upper UDB register always reads
562 * as zero so for our purposes things will just
563 * work with the checks below.
565 1: ldxa [%g0] ASI_UDBH_ERROR_R, %g3
566 and %g3, 0x3ff, %g7 ! Paranoia
567 sllx %g7, SFSTAT_UDBH_SHIFT, %g7
569 andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
572 stxa %g3, [%g0] ASI_UDB_ERROR_W
576 ldxa [%g3] ASI_UDBL_ERROR_R, %g3
577 and %g3, 0x3ff, %g7 ! Paranoia
578 sllx %g7, SFSTAT_UDBL_SHIFT, %g7
580 andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
584 stxa %g3, [%g7] ASI_UDB_ERROR_W
587 1: /* Ok, now that we've latched the error state,
588 * clear the sticky bits in the AFSR.
590 stxa %g4, [%g0] ASI_AFSR
605 1: ba,pt %xcc, etrap_irq
610 call spitfire_access_error
611 add %sp, PTREGS_OFF, %o0
615 /* This is the trap handler entry point for ECC correctable
616 * errors. They are corrected, but we listen for the trap
617 * so that the event can be logged.
619 * Disrupting errors are either:
620 * 1) single-bit ECC errors during UDB reads to system
622 * 2) data parity errors during write-back events
624 * As far as I can make out from the manual, the CEE trap
625 * is only for correctable errors during memory read
626 * accesses by the front-end of the processor.
628 * The code below is only for trap level 1 CEE events,
629 * as it is the only situation where we can safely record
630 * and log. For trap level >1 we just clear the CE bit
631 * in the AFSR and return.
633 * This is just like __spiftire_access_error above, but it
634 * specifically handles correctable errors. If an
635 * uncorrectable error is indicated in the AFSR we
636 * will branch directly above to __spitfire_access_error
637 * to handle it instead. Uncorrectable therefore takes
638 * priority over correctable, and the error logging
639 * C code will notice this case by inspecting the
642 .globl __spitfire_cee_trap
644 ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
646 sllx %g3, SFAFSR_UE_SHIFT, %g3
647 andcc %g4, %g3, %g0 ! Check for UE
648 bne,pn %xcc, __spitfire_access_error
651 /* Ok, in this case we only have a correctable error.
652 * Indicate we only wish to capture that state in register
653 * %g1, and we only disable CE error reporting unlike UE
654 * handling which disables all errors.
656 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g3
657 andn %g3, ESTATE_ERR_CE, %g3
658 stxa %g3, [%g0] ASI_ESTATE_ERROR_EN
661 /* Preserve AFSR in %g4, indicate UDB state to capture in %g1 */
662 ba,pt %xcc, __spitfire_cee_trap_continue
665 .globl __spitfire_data_access_exception
666 .globl __spitfire_data_access_exception_tl1
667 __spitfire_data_access_exception_tl1:
669 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
672 ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
673 ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
674 stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
677 cmp %g3, 0x80 ! first win spill/fill trap
679 cmp %g3, 0xff ! last win spill/fill trap
682 ba,pt %xcc, winfix_dax
684 1: sethi %hi(109f), %g7
686 109: or %g7, %lo(109b), %g7
689 call spitfire_data_access_exception_tl1
690 add %sp, PTREGS_OFF, %o0
694 __spitfire_data_access_exception:
696 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
699 ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
700 ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
701 stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
705 109: or %g7, %lo(109b), %g7
708 call spitfire_data_access_exception
709 add %sp, PTREGS_OFF, %o0
713 .globl __spitfire_insn_access_exception
714 .globl __spitfire_insn_access_exception_tl1
715 __spitfire_insn_access_exception_tl1:
717 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
719 ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
720 rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
721 stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
725 109: or %g7, %lo(109b), %g7
728 call spitfire_insn_access_exception_tl1
729 add %sp, PTREGS_OFF, %o0
733 __spitfire_insn_access_exception:
735 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
737 ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
738 rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
739 stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
743 109: or %g7, %lo(109b), %g7
746 call spitfire_insn_access_exception
747 add %sp, PTREGS_OFF, %o0
751 /* These get patched into the trap table at boot time
752 * once we know we have a cheetah processor.
754 .globl cheetah_fecc_trap_vector, cheetah_fecc_trap_vector_tl1
755 cheetah_fecc_trap_vector:
757 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
758 andn %g1, DCU_DC | DCU_IC, %g1
759 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
761 sethi %hi(cheetah_fast_ecc), %g2
762 jmpl %g2 + %lo(cheetah_fast_ecc), %g0
764 cheetah_fecc_trap_vector_tl1:
766 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
767 andn %g1, DCU_DC | DCU_IC, %g1
768 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
770 sethi %hi(cheetah_fast_ecc), %g2
771 jmpl %g2 + %lo(cheetah_fast_ecc), %g0
773 .globl cheetah_cee_trap_vector, cheetah_cee_trap_vector_tl1
774 cheetah_cee_trap_vector:
776 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
777 andn %g1, DCU_IC, %g1
778 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
780 sethi %hi(cheetah_cee), %g2
781 jmpl %g2 + %lo(cheetah_cee), %g0
783 cheetah_cee_trap_vector_tl1:
785 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
786 andn %g1, DCU_IC, %g1
787 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
789 sethi %hi(cheetah_cee), %g2
790 jmpl %g2 + %lo(cheetah_cee), %g0
792 .globl cheetah_deferred_trap_vector, cheetah_deferred_trap_vector_tl1
793 cheetah_deferred_trap_vector:
795 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
796 andn %g1, DCU_DC | DCU_IC, %g1;
797 stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
799 sethi %hi(cheetah_deferred_trap), %g2
800 jmpl %g2 + %lo(cheetah_deferred_trap), %g0
802 cheetah_deferred_trap_vector_tl1:
804 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
805 andn %g1, DCU_DC | DCU_IC, %g1;
806 stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
808 sethi %hi(cheetah_deferred_trap), %g2
809 jmpl %g2 + %lo(cheetah_deferred_trap), %g0
812 /* Cheetah+ specific traps. These are for the new I/D cache parity
813 * error traps. The first argument to cheetah_plus_parity_handler
814 * is encoded as follows:
816 * Bit0: 0=dcache,1=icache
817 * Bit1: 0=recoverable,1=unrecoverable
819 .globl cheetah_plus_dcpe_trap_vector, cheetah_plus_dcpe_trap_vector_tl1
820 cheetah_plus_dcpe_trap_vector:
822 sethi %hi(do_cheetah_plus_data_parity), %g7
823 jmpl %g7 + %lo(do_cheetah_plus_data_parity), %g0
830 do_cheetah_plus_data_parity:
833 ba,pt %xcc, etrap_irq
836 call cheetah_plus_parity_error
837 add %sp, PTREGS_OFF, %o1
838 ba,a,pt %xcc, rtrap_irq
840 cheetah_plus_dcpe_trap_vector_tl1:
842 wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
843 sethi %hi(do_dcpe_tl1), %g3
844 jmpl %g3 + %lo(do_dcpe_tl1), %g0
850 .globl cheetah_plus_icpe_trap_vector, cheetah_plus_icpe_trap_vector_tl1
851 cheetah_plus_icpe_trap_vector:
853 sethi %hi(do_cheetah_plus_insn_parity), %g7
854 jmpl %g7 + %lo(do_cheetah_plus_insn_parity), %g0
861 do_cheetah_plus_insn_parity:
864 ba,pt %xcc, etrap_irq
867 call cheetah_plus_parity_error
868 add %sp, PTREGS_OFF, %o1
869 ba,a,pt %xcc, rtrap_irq
871 cheetah_plus_icpe_trap_vector_tl1:
873 wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
874 sethi %hi(do_icpe_tl1), %g3
875 jmpl %g3 + %lo(do_icpe_tl1), %g0
881 /* If we take one of these traps when tl >= 1, then we
882 * jump to interrupt globals. If some trap level above us
883 * was also using interrupt globals, we cannot recover.
884 * We may use all interrupt global registers except %g6.
886 .globl do_dcpe_tl1, do_icpe_tl1
888 rdpr %tl, %g1 ! Save original trap level
889 mov 1, %g2 ! Setup TSTATE checking loop
890 sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
891 1: wrpr %g2, %tl ! Set trap level to check
892 rdpr %tstate, %g4 ! Read TSTATE for this level
893 andcc %g4, %g3, %g0 ! Interrupt globals in use?
894 bne,a,pn %xcc, do_dcpe_tl1_fatal ! Yep, irrecoverable
895 wrpr %g1, %tl ! Restore original trap level
896 add %g2, 1, %g2 ! Next trap level
897 cmp %g2, %g1 ! Hit them all yet?
898 ble,pt %icc, 1b ! Not yet
900 wrpr %g1, %tl ! Restore original trap level
901 do_dcpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
902 sethi %hi(dcache_parity_tl1_occurred), %g2
903 lduw [%g2 + %lo(dcache_parity_tl1_occurred)], %g1
905 stw %g1, [%g2 + %lo(dcache_parity_tl1_occurred)]
906 /* Reset D-cache parity */
907 sethi %hi(1 << 16), %g1 ! D-cache size
908 mov (1 << 5), %g2 ! D-cache line size
909 sub %g1, %g2, %g1 ! Move down 1 cacheline
910 1: srl %g1, 14, %g3 ! Compute UTAG
912 stxa %g3, [%g1] ASI_DCACHE_UTAG
914 sub %g2, 8, %g3 ! 64-bit data word within line
916 stxa %g0, [%g1 + %g3] ASI_DCACHE_DATA
918 subcc %g3, 8, %g3 ! Next 64-bit data word
921 subcc %g1, %g2, %g1 ! Next cacheline
924 ba,pt %xcc, dcpe_icpe_tl1_common
930 1: or %g7, %lo(1b), %g7
932 call cheetah_plus_parity_error
933 add %sp, PTREGS_OFF, %o1
938 rdpr %tl, %g1 ! Save original trap level
939 mov 1, %g2 ! Setup TSTATE checking loop
940 sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
941 1: wrpr %g2, %tl ! Set trap level to check
942 rdpr %tstate, %g4 ! Read TSTATE for this level
943 andcc %g4, %g3, %g0 ! Interrupt globals in use?
944 bne,a,pn %xcc, do_icpe_tl1_fatal ! Yep, irrecoverable
945 wrpr %g1, %tl ! Restore original trap level
946 add %g2, 1, %g2 ! Next trap level
947 cmp %g2, %g1 ! Hit them all yet?
948 ble,pt %icc, 1b ! Not yet
950 wrpr %g1, %tl ! Restore original trap level
951 do_icpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
952 sethi %hi(icache_parity_tl1_occurred), %g2
953 lduw [%g2 + %lo(icache_parity_tl1_occurred)], %g1
955 stw %g1, [%g2 + %lo(icache_parity_tl1_occurred)]
957 sethi %hi(1 << 15), %g1 ! I-cache size
958 mov (1 << 5), %g2 ! I-cache line size
960 1: or %g1, (2 << 3), %g3
961 stxa %g0, [%g3] ASI_IC_TAG
966 ba,pt %xcc, dcpe_icpe_tl1_common
972 1: or %g7, %lo(1b), %g7
974 call cheetah_plus_parity_error
975 add %sp, PTREGS_OFF, %o1
979 dcpe_icpe_tl1_common:
980 /* Flush D-cache, re-enable D/I caches in DCU and finally
981 * retry the trapping instruction.
983 sethi %hi(1 << 16), %g1 ! D-cache size
984 mov (1 << 5), %g2 ! D-cache line size
986 1: stxa %g0, [%g1] ASI_DCACHE_TAG
991 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
992 or %g1, (DCU_DC | DCU_IC), %g1
993 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
997 /* Capture I/D/E-cache state into per-cpu error scoreboard.
999 * %g1: (TL>=0) ? 1 : 0
1004 * %g6: current thread ptr
1007 __cheetah_log_error:
1008 /* Put "TL1" software bit into AFSR. */
1013 /* Get log entry pointer for this cpu at this trap level. */
1014 BRANCH_IF_JALAPENO(g2,g3,50f)
1015 ldxa [%g0] ASI_SAFARI_CONFIG, %g2
1020 50: ldxa [%g0] ASI_JBUS_CONFIG, %g2
1024 60: sllx %g2, 9, %g2
1025 sethi %hi(cheetah_error_log), %g3
1026 ldx [%g3 + %lo(cheetah_error_log)], %g3
1034 /* %g1 holds pointer to the top of the logging scoreboard */
1035 ldx [%g1 + 0x0], %g7
1040 stx %g4, [%g1 + 0x0]
1041 stx %g5, [%g1 + 0x8]
1044 /* %g1 now points to D-cache logging area */
1045 set 0x3ff8, %g2 /* DC_addr mask */
1046 and %g5, %g2, %g2 /* DC_addr bits of AFAR */
1048 or %g3, 1, %g3 /* PHYS tag + valid */
1050 10: ldxa [%g2] ASI_DCACHE_TAG, %g7
1051 cmp %g3, %g7 /* TAG match? */
1055 /* Yep, what we want, capture state. */
1056 stx %g2, [%g1 + 0x20]
1057 stx %g7, [%g1 + 0x28]
1059 /* A membar Sync is required before and after utag access. */
1061 ldxa [%g2] ASI_DCACHE_UTAG, %g7
1063 stx %g7, [%g1 + 0x30]
1064 ldxa [%g2] ASI_DCACHE_SNOOP_TAG, %g7
1065 stx %g7, [%g1 + 0x38]
1068 12: ldxa [%g2 + %g3] ASI_DCACHE_DATA, %g7
1070 add %g3, (1 << 5), %g3
1078 13: sethi %hi(1 << 14), %g7
1087 /* %g1 now points to I-cache logging area */
1088 20: set 0x1fe0, %g2 /* IC_addr mask */
1089 and %g5, %g2, %g2 /* IC_addr bits of AFAR */
1090 sllx %g2, 1, %g2 /* IC_addr[13:6]==VA[12:5] */
1091 srlx %g5, (13 - 8), %g3 /* Make PTAG */
1092 andn %g3, 0xff, %g3 /* Mask off undefined bits */
1094 21: ldxa [%g2] ASI_IC_TAG, %g7
1100 /* Yep, what we want, capture state. */
1101 stx %g2, [%g1 + 0x40]
1102 stx %g7, [%g1 + 0x48]
1103 add %g2, (1 << 3), %g2
1104 ldxa [%g2] ASI_IC_TAG, %g7
1105 add %g2, (1 << 3), %g2
1106 stx %g7, [%g1 + 0x50]
1107 ldxa [%g2] ASI_IC_TAG, %g7
1108 add %g2, (1 << 3), %g2
1109 stx %g7, [%g1 + 0x60]
1110 ldxa [%g2] ASI_IC_TAG, %g7
1111 stx %g7, [%g1 + 0x68]
1112 sub %g2, (3 << 3), %g2
1113 ldxa [%g2] ASI_IC_STAG, %g7
1114 stx %g7, [%g1 + 0x58]
1118 22: ldxa [%g2 + %g3] ASI_IC_INSTR, %g7
1120 add %g3, (1 << 3), %g3
1128 23: sethi %hi(1 << 14), %g7
1137 /* %g1 now points to E-cache logging area */
1138 30: andn %g5, (32 - 1), %g2
1139 stx %g2, [%g1 + 0x20]
1140 ldxa [%g2] ASI_EC_TAG_DATA, %g7
1141 stx %g7, [%g1 + 0x28]
1142 ldxa [%g2] ASI_EC_R, %g0
1145 31: ldxa [%g3] ASI_EC_DATA, %g7
1146 stx %g7, [%g1 + %g3]
1159 ba,pt %xcc, c_deferred
1161 /* Cheetah FECC trap handling, we get here from tl{0,1}_fecc
1162 * in the trap table. That code has done a memory barrier
1163 * and has disabled both the I-cache and D-cache in the DCU
1164 * control register. The I-cache is disabled so that we may
1165 * capture the corrupted cache line, and the D-cache is disabled
1166 * because corrupt data may have been placed there and we don't
1167 * want to reference it.
1169 * %g1 is one if this trap occurred at %tl >= 1.
1171 * Next, we turn off error reporting so that we don't recurse.
1173 .globl cheetah_fast_ecc
1175 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1176 andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
1177 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1180 /* Fetch and clear AFSR/AFAR */
1181 ldxa [%g0] ASI_AFSR, %g4
1182 ldxa [%g0] ASI_AFAR, %g5
1183 stxa %g4, [%g0] ASI_AFSR
1186 ba,pt %xcc, __cheetah_log_error
1192 ba,pt %xcc, etrap_irq
1196 call cheetah_fecc_handler
1197 add %sp, PTREGS_OFF, %o0
1198 ba,a,pt %xcc, rtrap_irq
1200 /* Our caller has disabled I-cache and performed membar Sync. */
1203 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1204 andn %g2, ESTATE_ERROR_CEEN, %g2
1205 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1208 /* Fetch and clear AFSR/AFAR */
1209 ldxa [%g0] ASI_AFSR, %g4
1210 ldxa [%g0] ASI_AFAR, %g5
1211 stxa %g4, [%g0] ASI_AFSR
1214 ba,pt %xcc, __cheetah_log_error
1220 ba,pt %xcc, etrap_irq
1224 call cheetah_cee_handler
1225 add %sp, PTREGS_OFF, %o0
1226 ba,a,pt %xcc, rtrap_irq
1228 /* Our caller has disabled I-cache+D-cache and performed membar Sync. */
1229 .globl cheetah_deferred_trap
1230 cheetah_deferred_trap:
1231 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1232 andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
1233 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1236 /* Fetch and clear AFSR/AFAR */
1237 ldxa [%g0] ASI_AFSR, %g4
1238 ldxa [%g0] ASI_AFAR, %g5
1239 stxa %g4, [%g0] ASI_AFSR
1242 ba,pt %xcc, __cheetah_log_error
1248 ba,pt %xcc, etrap_irq
1252 call cheetah_deferred_handler
1253 add %sp, PTREGS_OFF, %o0
1254 ba,a,pt %xcc, rtrap_irq
1259 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
1261 sethi %hi(109f), %g7
1263 109: or %g7, %lo(109b), %g7
1265 add %sp, PTREGS_OFF, %o0
1274 /* Setup %g4/%g5 now as they are used in the
1279 ldxa [%g4] ASI_DMMU, %g4
1280 ldxa [%g3] ASI_DMMU, %g5
1281 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
1283 bgu,pn %icc, winfix_mna
1286 1: sethi %hi(109f), %g7
1288 109: or %g7, %lo(109b), %g7
1291 call mem_address_unaligned
1292 add %sp, PTREGS_OFF, %o0
1298 sethi %hi(109f), %g7
1300 ldxa [%g4] ASI_DMMU, %g5
1301 stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
1304 ldxa [%g4] ASI_DMMU, %g4
1306 109: or %g7, %lo(109b), %g7
1310 add %sp, PTREGS_OFF, %o0
1316 sethi %hi(109f), %g7
1318 ldxa [%g4] ASI_DMMU, %g5
1319 stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
1322 ldxa [%g4] ASI_DMMU, %g4
1324 109: or %g7, %lo(109b), %g7
1328 add %sp, PTREGS_OFF, %o0
1332 .globl breakpoint_trap
1334 call sparc_breakpoint
1335 add %sp, PTREGS_OFF, %o0
1339 #if defined(CONFIG_SUNOS_EMUL) || defined(CONFIG_SOLARIS_EMUL) || \
1340 defined(CONFIG_SOLARIS_EMUL_MODULE)
1341 /* SunOS uses syscall zero as the 'indirect syscall' it looks
1342 * like indir_syscall(scall_num, arg0, arg1, arg2...); etc.
1343 * This is complete brain damage.
1349 cmp %o0, NR_SYSCALLS
1352 sethi %hi(sunos_nosys), %l6
1354 or %l6, %lo(sunos_nosys), %l6
1355 1: sethi %hi(sunos_sys_table), %l7
1356 or %l7, %lo(sunos_sys_table), %l7
1357 lduw [%l7 + %o0], %l6
1371 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1372 b,pt %xcc, ret_sys_call
1373 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1375 /* SunOS getuid() returns uid in %o0 and euid in %o1 */
1378 call sys32_geteuid16
1381 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1382 b,pt %xcc, ret_sys_call
1383 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1385 /* SunOS getgid() returns gid in %o0 and egid in %o1 */
1388 call sys32_getegid16
1391 stx %o0, [%sp + PTREGS_OFF + PT_V9_I1]
1392 b,pt %xcc, ret_sys_call
1393 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1396 /* SunOS's execv() call only specifies the argv argument, the
1397 * environment settings are the same as the calling processes.
1401 sethi %hi(sparc_execve), %g1
1402 ba,pt %xcc, execve_merge
1403 or %g1, %lo(sparc_execve), %g1
1404 #ifdef CONFIG_COMPAT
1407 stx %g0, [%sp + PTREGS_OFF + PT_V9_I2]
1410 sethi %hi(sparc32_execve), %g1
1411 or %g1, %lo(sparc32_execve), %g1
1416 add %sp, PTREGS_OFF, %o0
1418 .globl sys_pipe, sys_sigpause, sys_nis_syscall
1419 .globl sys_rt_sigreturn
1421 .globl sys_sigaltstack
1423 sys_pipe: ba,pt %xcc, sparc_pipe
1424 add %sp, PTREGS_OFF, %o0
1425 sys_nis_syscall:ba,pt %xcc, c_sys_nis_syscall
1426 add %sp, PTREGS_OFF, %o0
1427 sys_memory_ordering:
1428 ba,pt %xcc, sparc_memory_ordering
1429 add %sp, PTREGS_OFF, %o1
1430 sys_sigaltstack:ba,pt %xcc, do_sigaltstack
1431 add %i6, STACK_BIAS, %o2
1432 #ifdef CONFIG_COMPAT
1433 .globl sys32_sigstack
1434 sys32_sigstack: ba,pt %xcc, do_sys32_sigstack
1436 .globl sys32_sigaltstack
1438 ba,pt %xcc, do_sys32_sigaltstack
1442 #ifdef CONFIG_COMPAT
1443 .globl sys32_sigreturn
1445 add %sp, PTREGS_OFF, %o0
1447 add %o7, 1f-.-4, %o7
1451 add %sp, PTREGS_OFF, %o0
1452 call do_rt_sigreturn
1453 add %o7, 1f-.-4, %o7
1455 #ifdef CONFIG_COMPAT
1456 .globl sys32_rt_sigreturn
1458 add %sp, PTREGS_OFF, %o0
1459 call do_rt_sigreturn32
1460 add %o7, 1f-.-4, %o7
1463 sys_ptrace: add %sp, PTREGS_OFF, %o0
1465 add %o7, 1f-.-4, %o7
1468 1: ldx [%curptr + TI_FLAGS], %l5
1469 andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1472 add %sp, PTREGS_OFF, %o0
1479 /* This is how fork() was meant to be done, 8 instruction entry.
1481 * I questioned the following code briefly, let me clear things
1482 * up so you must not reason on it like I did.
1484 * Know the fork_kpsr etc. we use in the sparc32 port? We don't
1485 * need it here because the only piece of window state we copy to
1486 * the child is the CWP register. Even if the parent sleeps,
1487 * we are safe because we stuck it into pt_regs of the parent
1488 * so it will not change.
1490 * XXX This raises the question, whether we can do the same on
1491 * XXX sparc32 to get rid of fork_kpsr _and_ fork_kwim. The
1492 * XXX answer is yes. We stick fork_kpsr in UREG_G0 and
1493 * XXX fork_kwim in UREG_G1 (global registers are considered
1494 * XXX volatile across a system call in the sparc ABI I think
1495 * XXX if it isn't we can use regs->y instead, anyone who depends
1496 * XXX upon the Y register being preserved across a fork deserves
1499 * In fact we should take advantage of that fact for other things
1500 * during system calls...
1502 .globl sys_fork, sys_vfork, sys_clone, sparc_exit
1503 .globl ret_from_syscall
1505 sys_vfork: /* Under Linux, vfork and fork are just special cases of clone. */
1506 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1507 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1508 ba,pt %xcc, sys_clone
1514 ba,pt %xcc, sparc_do_fork
1515 add %sp, PTREGS_OFF, %o2
1517 /* Clear current_thread_info()->new_child, and
1518 * check performance counter stuff too.
1520 stb %g0, [%g6 + TI_NEW_CHILD]
1521 ldx [%g6 + TI_FLAGS], %l0
1524 andcc %l0, _TIF_PERFCTR, %g0
1527 ldx [%g6 + TI_PCR], %o7
1530 /* Blackbird errata workaround. See commentary in
1531 * smp.c:smp_percpu_timer_interrupt() for more
1537 99: wr %g0, %g0, %pic
1540 1: b,pt %xcc, ret_sys_call
1541 ldx [%sp + PTREGS_OFF + PT_V9_I0], %o0
1542 sparc_exit: wrpr %g0, (PSTATE_RMO | PSTATE_PEF | PSTATE_PRIV), %pstate
1546 wrpr %g3, 0x0, %cansave
1547 wrpr %g0, 0x0, %otherwin
1548 wrpr %g0, (PSTATE_RMO | PSTATE_PEF | PSTATE_PRIV | PSTATE_IE), %pstate
1549 ba,pt %xcc, sys_exit
1550 stb %g0, [%g6 + TI_WSAVED]
1552 linux_sparc_ni_syscall:
1553 sethi %hi(sys_ni_syscall), %l7
1555 or %l7, %lo(sys_ni_syscall), %l7
1557 linux_syscall_trace32:
1558 add %sp, PTREGS_OFF, %o0
1568 linux_syscall_trace:
1569 add %sp, PTREGS_OFF, %o0
1580 /* Linux 32-bit and SunOS system calls enter here... */
1582 .globl linux_sparc_syscall32
1583 linux_sparc_syscall32:
1584 /* Direct access to user regs, much faster. */
1585 cmp %g1, NR_SYSCALLS ! IEU1 Group
1586 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
1587 srl %i0, 0, %o0 ! IEU0
1588 sll %g1, 2, %l4 ! IEU0 Group
1589 srl %i4, 0, %o4 ! IEU1
1590 lduw [%l7 + %l4], %l7 ! Load
1591 srl %i1, 0, %o1 ! IEU0 Group
1592 ldx [%curptr + TI_FLAGS], %l0 ! Load
1594 srl %i5, 0, %o5 ! IEU1
1595 srl %i2, 0, %o2 ! IEU0 Group
1596 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1597 bne,pn %icc, linux_syscall_trace32 ! CTI
1599 call %l7 ! CTI Group brk forced
1600 srl %i3, 0, %o3 ! IEU0
1603 /* Linux native and SunOS system calls enter here... */
1605 .globl linux_sparc_syscall, ret_sys_call
1606 linux_sparc_syscall:
1607 /* Direct access to user regs, much faster. */
1608 cmp %g1, NR_SYSCALLS ! IEU1 Group
1609 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
1611 sll %g1, 2, %l4 ! IEU0 Group
1613 lduw [%l7 + %l4], %l7 ! Load
1614 4: mov %i2, %o2 ! IEU0 Group
1615 ldx [%curptr + TI_FLAGS], %l0 ! Load
1618 mov %i4, %o4 ! IEU0 Group
1619 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1620 bne,pn %icc, linux_syscall_trace ! CTI Group
1622 2: call %l7 ! CTI Group brk forced
1626 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1628 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
1629 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
1631 mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
1634 /* Check if force_successful_syscall_return()
1637 ldub [%curptr + TI_SYS_NOERROR], %l2
1639 stb %g0, [%curptr + TI_SYS_NOERROR]
1641 cmp %o0, -ERESTART_RESTARTBLOCK
1643 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
1645 /* System call success, clear Carry condition code. */
1647 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
1648 bne,pn %icc, linux_syscall_trace2
1649 add %l1, 0x4, %l2 ! npc = npc+4
1650 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1651 ba,pt %xcc, rtrap_clr_l6
1652 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1655 /* System call failure, set Carry condition code.
1656 * Also, get abs(errno) to return to the process.
1658 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
1661 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1663 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
1664 bne,pn %icc, linux_syscall_trace2
1665 add %l1, 0x4, %l2 ! npc = npc+4
1666 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1669 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1670 linux_syscall_trace2:
1671 add %sp, PTREGS_OFF, %o0
1674 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1676 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1679 .globl __flushw_user
1684 1: save %sp, -128, %sp
1690 restore %g0, %g0, %g0