1 /* $Id: entry.S,v 1.170 2001/11/13 00:57:05 davem Exp $
2 * arch/sparc/kernel/entry.S: Sparc trap low-level entry points.
4 * Copyright (C) 1995 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-1999 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
8 * Copyright (C) 1997 Anton Blanchard (anton@progsoc.uts.edu.au)
11 #include <linux/errno.h>
17 #include <asm/contregs.h>
18 #include <asm/ptrace.h>
19 #include <asm/asm-offsets.h>
21 #include <asm/vaddrs.h>
22 #include <asm/memreg.h>
25 #include <asm/pgtsun4.h>
27 #include <asm/pgtsun4c.h>
29 #include <asm/winmacro.h>
30 #include <asm/signal.h>
33 #include <asm/thread_info.h>
34 #include <asm/param.h>
35 #include <asm/unistd.h>
37 #include <asm/asmmacro.h>
41 /* These are just handy. */
42 #define _SV save %sp, -STACKFRAME_SZ, %sp
45 #define FLUSH_ALL_KERNEL_WINDOWS \
46 _SV; _SV; _SV; _SV; _SV; _SV; _SV; \
47 _RS; _RS; _RS; _RS; _RS; _RS; _RS;
49 /* First, KGDB low level things. This is a rewrite
50 * of the routines found in the sparc-stub.c asm() statement
51 * from the gdb distribution. This is also dual-purpose
52 * as a software trap for userlevel programs.
63 #if 0 /* kgdb is dropped from 2.5.33 */
64 ! This function is called when any SPARC trap (except window overflow or
65 ! underflow) occurs. It makes sure that the invalid register window is still
66 ! available before jumping into C code. It will also restore the world if you
67 ! return from handle_exception.
74 sethi %hi(in_trap_handler), %l4
75 ld [%lo(in_trap_handler) + %l4], %l5
77 st %l5, [%lo(in_trap_handler) + %l4]
79 /* Make sure kgdb sees the same state we just saved. */
82 ld [%sp + STACKFRAME_SZ + PT_Y], %l4
83 ld [%sp + STACKFRAME_SZ + PT_WIM], %l3
84 ld [%sp + STACKFRAME_SZ + PT_PSR], %l0
85 ld [%sp + STACKFRAME_SZ + PT_PC], %l1
86 ld [%sp + STACKFRAME_SZ + PT_NPC], %l2
87 rd %tbr, %l5 /* Never changes... */
89 /* Make kgdb exception frame. */
90 sub %sp,(16+1+6+1+72)*4,%sp ! Make room for input & locals
91 ! + hidden arg + arg spill
92 ! + doubleword alignment
93 ! + registers[72] local var
96 SAVE_KGDB_SREGS(sp, l4, l0, l3, l5, l1, l2)
98 /* We are increasing PIL, so two writes. */
105 call handle_exception
106 add %sp, STACKFRAME_SZ, %o0 ! Pass address of registers
108 /* Load new kgdb register set. */
109 LOAD_KGDB_GLOBALS(sp)
111 LOAD_KGDB_SREGS(sp, l4, l0, l3, l5, l1, l2)
114 sethi %hi(in_trap_handler), %l4
115 ld [%lo(in_trap_handler) + %l4], %l5
117 st %l5, [%lo(in_trap_handler) + %l4]
119 add %sp,(16+1+6+1+72)*4,%sp ! Undo the kgdb trap frame.
121 /* Now take what kgdb did and place it into the pt_regs
122 * frame which SparcLinux RESTORE_ALL understands.,
126 STORE_PT_YREG(sp, g2)
127 STORE_PT_PRIV(sp, l0, l1, l2)
132 #ifdef CONFIG_BLK_DEV_FD
135 .globl floppy_hardint
138 * This code cannot touch registers %l0 %l1 and %l2
139 * because SAVE_ALL depends on their values. It depends
140 * on %l3 also, but we regenerate it before a call.
141 * Other registers are:
142 * %l3 -- base address of fdc registers
144 * %l5 -- scratch for ld/st address
146 * %l7 -- scratch [floppy byte, ld/st address, aux. data]
149 /* Do we have work to do? */
150 sethi %hi(doing_pdma), %l7
151 ld [%l7 + %lo(doing_pdma)], %l7
156 /* Load fdc register base */
157 sethi %hi(fdc_status), %l3
158 ld [%l3 + %lo(fdc_status)], %l3
160 /* Setup register addresses */
161 sethi %hi(pdma_vaddr), %l5 ! transfer buffer
162 ld [%l5 + %lo(pdma_vaddr)], %l4
163 sethi %hi(pdma_size), %l5 ! bytes to go
164 ld [%l5 + %lo(pdma_size)], %l6
168 andcc %l7, 0x80, %g0 ! Does fifo still have data
169 bz floppy_fifo_emptied ! fifo has been emptied...
170 andcc %l7, 0x20, %g0 ! in non-dma mode still?
171 bz floppy_overrun ! nope, overrun
172 andcc %l7, 0x40, %g0 ! 0=write 1=read
176 /* Ok, actually read this byte */
187 /* Ok, actually write this byte */
194 /* fall through... */
196 sethi %hi(pdma_vaddr), %l5
197 st %l4, [%l5 + %lo(pdma_vaddr)]
198 sethi %hi(pdma_size), %l5
199 st %l6, [%l5 + %lo(pdma_size)]
200 /* Flip terminal count pin */
201 set auxio_register, %l7
204 set sparc_cpu_model, %l5
206 subcc %l5, 1, %g0 /* enum { sun4c = 1 }; */
222 /* Kill some time so the bits set */
228 /* Prevent recursion */
229 sethi %hi(doing_pdma), %l7
231 st %g0, [%l7 + %lo(doing_pdma)]
233 /* We emptied the FIFO, but we haven't read everything
234 * as of yet. Store the current transfer address and
235 * bytes left to read so we can continue when the next
239 sethi %hi(pdma_vaddr), %l5
240 st %l4, [%l5 + %lo(pdma_vaddr)]
241 sethi %hi(pdma_size), %l7
242 st %l6, [%l7 + %lo(pdma_size)]
244 /* Restore condition codes */
252 sethi %hi(pdma_vaddr), %l5
253 st %l4, [%l5 + %lo(pdma_vaddr)]
254 sethi %hi(pdma_size), %l5
255 st %l6, [%l5 + %lo(pdma_size)]
256 /* Prevent recursion */
257 sethi %hi(doing_pdma), %l7
258 st %g0, [%l7 + %lo(doing_pdma)]
260 /* fall through... */
265 /* Set all IRQs off. */
272 mov 11, %o0 ! floppy irq level (unused anyway)
273 mov %g0, %o1 ! devid is not used in fast interrupts
274 call sparc_floppy_irq
275 add %sp, STACKFRAME_SZ, %o2 ! struct pt_regs *regs
279 #endif /* (CONFIG_BLK_DEV_FD) */
281 /* Bad trap handler */
282 .globl bad_trap_handler
289 add %sp, STACKFRAME_SZ, %o0 ! pt_regs
291 mov %l7, %o1 ! trap number
295 /* For now all IRQ's not registered get sent here. handler_irq() will
296 * see if a routine is registered to handle this interrupt and if not
297 * it will say so on the console.
301 .globl real_irq_entry, patch_handler_irq
306 .globl patchme_maybe_smp_msg
309 patchme_maybe_smp_msg:
320 mov %l7, %o0 ! irq level
323 add %sp, STACKFRAME_SZ, %o1 ! pt_regs ptr
324 or %l0, PSR_PIL, %g2 ! restore PIL after handler_irq
325 wr %g2, PSR_ET, %psr ! keep ET up
331 /* SMP per-cpu ticker interrupts are handled specially. */
333 bne real_irq_continue+4
339 call smp4m_percpu_timer_interrupt
340 add %sp, STACKFRAME_SZ, %o0
345 /* Here is where we check for possible SMP IPI passed to us
346 * on some level other than 15 which is the NMI and only used
347 * for cross calls. That has a separate entry point below.
350 GET_PROCESSOR4M_ID(o3)
351 set sun4m_interrupts, %l5
353 sethi %hi(0x40000000), %o2
368 call smp_reschedule_irq
374 .globl linux_trap_ipi15_sun4m
375 linux_trap_ipi15_sun4m:
377 sethi %hi(0x80000000), %o2
378 GET_PROCESSOR4M_ID(o0)
379 set sun4m_interrupts, %l5
385 be 1f ! Must be an NMI async memory error
395 call smp4m_cross_call_irq
397 b ret_trap_lockless_ipi
400 /* NMI async memory error handling. */
401 sethi %hi(0x80000000), %l4
402 sethi %hi(0x4000), %o3
423 /* SMP per-cpu ticker interrupts are handled specially. */
427 sethi %hi(CC_ICLR), %o0
428 sethi %hi(1 << 14), %o1
429 or %o0, %lo(CC_ICLR), %o0
430 stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 14 in MXCC's ICLR */
435 call smp4d_percpu_timer_interrupt
436 add %sp, STACKFRAME_SZ, %o0
442 .globl linux_trap_ipi15_sun4d
443 linux_trap_ipi15_sun4d:
445 sethi %hi(CC_BASE), %o4
446 sethi %hi(MXCC_ERR_ME|MXCC_ERR_PEW|MXCC_ERR_ASE|MXCC_ERR_PEE), %o2
447 or %o4, (CC_EREG - CC_BASE), %o0
448 ldda [%o0] ASI_M_MXCC, %o0
451 sethi %hi(BB_STAT2), %o2
452 lduba [%o2] ASI_M_CTL, %o2
453 andcc %o2, BB_STAT2_MASK, %g0
455 or %o4, (CC_ICLR - CC_BASE), %o0
456 sethi %hi(1 << 15), %o1
457 stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 15 in MXCC's ICLR */
463 call smp4d_cross_call_irq
465 b ret_trap_lockless_ipi
472 lduha [%l4] ASI_M_MXCC, %l5
473 sethi %hi(1 << 15), %l7
475 stha %l5, [%l4] ASI_M_MXCC
479 #endif /* CONFIG_SMP */
481 /* This routine handles illegal instructions and privileged
482 * instruction attempts from user code.
485 .globl bad_instruction
487 sethi %hi(0xc1f80000), %l4
489 sethi %hi(0x81d80000), %l7
495 wr %l0, PSR_ET, %psr ! re-enable traps
498 add %sp, STACKFRAME_SZ, %o0
501 call do_illegal_instruction
506 1: /* unimplemented flush - just skip */
511 .globl priv_instruction
518 add %sp, STACKFRAME_SZ, %o0
521 call do_priv_instruction
526 /* This routine handles unaligned data accesses. */
530 andcc %l0, PSR_PS, %g0
540 call kernel_unaligned_trap
541 add %sp, STACKFRAME_SZ, %o0
548 wr %l0, PSR_ET, %psr ! re-enable traps
552 call user_unaligned_trap
553 add %sp, STACKFRAME_SZ, %o0
557 /* This routine handles floating point disabled traps. */
559 .globl fpd_trap_handler
563 wr %l0, PSR_ET, %psr ! re-enable traps
566 add %sp, STACKFRAME_SZ, %o0
574 /* This routine handles Floating Point Exceptions. */
576 .globl fpe_trap_handler
578 set fpsave_magic, %l5
581 sethi %hi(fpsave), %l5
582 or %l5, %lo(fpsave), %l5
585 sethi %hi(fpsave_catch2), %l5
586 or %l5, %lo(fpsave_catch2), %l5
592 sethi %hi(fpsave_catch), %l5
593 or %l5, %lo(fpsave_catch), %l5
602 wr %l0, PSR_ET, %psr ! re-enable traps
605 add %sp, STACKFRAME_SZ, %o0
613 /* This routine handles Tag Overflow Exceptions. */
615 .globl do_tag_overflow
619 wr %l0, PSR_ET, %psr ! re-enable traps
622 add %sp, STACKFRAME_SZ, %o0
625 call handle_tag_overflow
630 /* This routine handles Watchpoint Exceptions. */
636 wr %l0, PSR_ET, %psr ! re-enable traps
639 add %sp, STACKFRAME_SZ, %o0
642 call handle_watchpoint
647 /* This routine handles Register Access Exceptions. */
653 wr %l0, PSR_ET, %psr ! re-enable traps
656 add %sp, STACKFRAME_SZ, %o0
659 call handle_reg_access
664 /* This routine handles Co-Processor Disabled Exceptions. */
666 .globl do_cp_disabled
670 wr %l0, PSR_ET, %psr ! re-enable traps
673 add %sp, STACKFRAME_SZ, %o0
676 call handle_cp_disabled
681 /* This routine handles Co-Processor Exceptions. */
683 .globl do_cp_exception
687 wr %l0, PSR_ET, %psr ! re-enable traps
690 add %sp, STACKFRAME_SZ, %o0
693 call handle_cp_exception
698 /* This routine handles Hardware Divide By Zero Exceptions. */
704 wr %l0, PSR_ET, %psr ! re-enable traps
707 add %sp, STACKFRAME_SZ, %o0
710 call handle_hw_divzero
716 .globl do_flush_windows
723 andcc %l0, PSR_PS, %g0
727 call flush_user_windows
730 /* Advance over the trap instruction. */
731 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1
733 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
734 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
738 .globl flush_patch_one
740 /* We get these for debugging routines using __builtin_return_address() */
743 FLUSH_ALL_KERNEL_WINDOWS
745 /* Advance over the trap instruction. */
746 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1
748 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
749 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
753 /* The getcc software trap. The user wants the condition codes from
754 * the %psr in register %g1.
758 .globl getcc_trap_handler
760 srl %l0, 20, %g1 ! give user
761 and %g1, 0xf, %g1 ! only ICC bits in %psr
762 jmp %l2 ! advance over trap instruction
763 rett %l2 + 0x4 ! like this...
765 /* The setcc software trap. The user has condition codes in %g1
766 * that it would like placed in the %psr. Be careful not to flip
767 * any unintentional bits!
771 .globl setcc_trap_handler
775 andn %l0, %l5, %l0 ! clear ICC bits in %psr
776 and %l4, %l5, %l4 ! clear non-ICC bits in user value
777 or %l4, %l0, %l4 ! or them in... mix mix mix
779 wr %l4, 0x0, %psr ! set new %psr
780 WRITE_PAUSE ! TI scumbags...
782 jmp %l2 ! advance over trap instruction
783 rett %l2 + 0x4 ! like this...
786 .globl linux_trap_nmi_sun4c
787 linux_trap_nmi_sun4c:
790 /* Ugh, we need to clear the IRQ line. This is now
791 * a very sun4c specific trap handler...
793 sethi %hi(interrupt_enable), %l5
794 ld [%l5 + %lo(interrupt_enable)], %l5
796 andn %l6, INTS_ENAB, %l6
799 /* Now it is safe to re-enable traps without recursion. */
804 /* Now call the c-code with the pt_regs frame ptr and the
805 * memory error registers as arguments. The ordering chosen
806 * here is due to unlatching semantics.
808 sethi %hi(AC_SYNC_ERR), %o0
810 lda [%o0] ASI_CONTROL, %o2 ! sync vaddr
812 lda [%o0] ASI_CONTROL, %o1 ! sync error
814 lda [%o0] ASI_CONTROL, %o4 ! async vaddr
816 lda [%o0] ASI_CONTROL, %o3 ! async error
818 add %sp, STACKFRAME_SZ, %o0
823 .globl invalid_segment_patch1_ff
824 .globl invalid_segment_patch2_ff
825 invalid_segment_patch1_ff: cmp %l4, 0xff
826 invalid_segment_patch2_ff: mov 0xff, %l3
829 .globl invalid_segment_patch1_1ff
830 .globl invalid_segment_patch2_1ff
831 invalid_segment_patch1_1ff: cmp %l4, 0x1ff
832 invalid_segment_patch2_1ff: mov 0x1ff, %l3
835 .globl num_context_patch1_16, num_context_patch2_16
836 num_context_patch1_16: mov 0x10, %l7
837 num_context_patch2_16: mov 0x10, %l7
840 .globl vac_linesize_patch_32
841 vac_linesize_patch_32: subcc %l7, 32, %l7
844 .globl vac_hwflush_patch1_on, vac_hwflush_patch2_on
847 * Ugly, but we cant use hardware flushing on the sun4 and we'd require
848 * two instructions (Anton)
851 vac_hwflush_patch1_on: nop
853 vac_hwflush_patch1_on: addcc %l7, -PAGE_SIZE, %l7
856 vac_hwflush_patch2_on: sta %g0, [%l3 + %l7] ASI_HWFLUSHSEG
858 .globl invalid_segment_patch1, invalid_segment_patch2
859 .globl num_context_patch1
860 .globl vac_linesize_patch, vac_hwflush_patch1
861 .globl vac_hwflush_patch2
870 ! %l7 = 1 for textfault
871 ! We want error in %l5, vaddr in %l6
874 sethi %hi(sun4c_memerr_reg), %l4
875 ld [%l4+%lo(sun4c_memerr_reg)], %l4 ! memerr ctrl reg addr
876 ld [%l4], %l6 ! memerr ctrl reg
877 ld [%l4 + 4], %l5 ! memerr vaddr reg
878 andcc %l6, 0x80, %g0 ! check for error type
879 st %g0, [%l4 + 4] ! clear the error
881 sethi %hi(AC_BUS_ERROR), %l4 ! bus err reg addr
883 call prom_halt ! something weird happened
884 ! what exactly did happen?
885 ! what should we do here?
887 0: or %l4, %lo(AC_BUS_ERROR), %l4 ! bus err reg addr
888 lduba [%l4] ASI_CONTROL, %l6 ! bus err reg
890 cmp %l7, 1 ! text fault?
894 ld [%l1], %l4 ! load instruction that caused fault
896 andcc %l4, 1, %g0 ! store instruction?
899 sethi %hi(SUN4C_SYNC_BADWRITE), %l4 ! yep
900 ! %lo(SUN4C_SYNC_BADWRITE) = 0
901 or %l4, %l6, %l6 ! set write bit to emulate sun4c
904 sethi %hi(AC_SYNC_ERR), %l4
905 add %l4, 0x4, %l6 ! AC_SYNC_VA in %l6
906 lda [%l6] ASI_CONTROL, %l5 ! Address
907 lda [%l4] ASI_CONTROL, %l6 ! Error, retained for a bit
910 andn %l5, 0xfff, %l5 ! Encode all info into l7
916 or %l4, %l7, %l7 ! l7 = [addr,write,txtfault]
918 andcc %l0, PSR_PS, %g0
919 be sun4c_fault_fromuser
920 andcc %l7, 1, %g0 ! Text fault?
923 sethi %hi(KERNBASE), %l4
929 blu sun4c_fault_fromuser
930 sethi %hi(~((1 << SUN4C_REAL_PGDIR_SHIFT) - 1)), %l4
932 /* If the kernel references a bum kernel pointer, or a pte which
933 * points to a non existant page in ram, we will run this code
934 * _forever_ and lock up the machine!!!!! So we must check for
935 * this condition, the AC_SYNC_ERR bits are what we must examine.
936 * Also a parity error would make this happen as well. So we just
937 * check that we are in fact servicing a tlb miss and not some
938 * other type of fault for the kernel.
941 be sun4c_fault_fromuser
944 /* Test for NULL pte_t * in vmalloc area. */
945 sethi %hi(VMALLOC_START), %l4
947 blu,a invalid_segment_patch1
948 lduXa [%l5] ASI_SEGMAP, %l4
950 sethi %hi(swapper_pg_dir), %l4
951 srl %l5, SUN4C_PGDIR_SHIFT, %l6
952 or %l4, %lo(swapper_pg_dir), %l4
956 sethi %hi(PAGE_MASK), %l6
959 andcc %l4, PAGE_MASK, %g0
961 be sun4c_fault_fromuser
962 lduXa [%l5] ASI_SEGMAP, %l4
964 invalid_segment_patch1:
967 sethi %hi(sun4c_kfree_ring), %l4
968 or %l4, %lo(sun4c_kfree_ring), %l4
970 deccc %l3 ! do we have a free entry?
971 bcs,a 2f ! no, unmap one.
972 sethi %hi(sun4c_kernel_ring), %l4
974 st %l3, [%l4 + 0x18] ! sun4c_kfree_ring.num_entries--
976 ld [%l4 + 0x00], %l6 ! entry = sun4c_kfree_ring.ringhd.next
977 st %l5, [%l6 + 0x08] ! entry->vaddr = address
979 ld [%l6 + 0x00], %l3 ! next = entry->next
980 ld [%l6 + 0x04], %l7 ! entry->prev
982 st %l7, [%l3 + 0x04] ! next->prev = entry->prev
983 st %l3, [%l7 + 0x00] ! entry->prev->next = next
985 sethi %hi(sun4c_kernel_ring), %l4
986 or %l4, %lo(sun4c_kernel_ring), %l4
987 ! head = &sun4c_kernel_ring.ringhd
989 ld [%l4 + 0x00], %l7 ! head->next
991 st %l4, [%l6 + 0x04] ! entry->prev = head
992 st %l7, [%l6 + 0x00] ! entry->next = head->next
993 st %l6, [%l7 + 0x04] ! head->next->prev = entry
995 st %l6, [%l4 + 0x00] ! head->next = entry
998 inc %l3 ! sun4c_kernel_ring.num_entries++
1001 ld [%l6 + 0x08], %l5
1004 or %l4, %lo(sun4c_kernel_ring), %l4
1005 ! head = &sun4c_kernel_ring.ringhd
1007 ld [%l4 + 0x04], %l6 ! entry = head->prev
1009 ld [%l6 + 0x08], %l3 ! tmp = entry->vaddr
1011 ! Flush segment from the cache.
1013 sethi %hi((128 * 1024)), %l7
1015 sethi %hi((64 * 1024)), %l7
1023 sta %g0, [%l3 + %l7] ASI_FLUSHSEG
1025 st %l5, [%l6 + 0x08] ! entry->vaddr = address
1027 ld [%l6 + 0x00], %l5 ! next = entry->next
1028 ld [%l6 + 0x04], %l7 ! entry->prev
1030 st %l7, [%l5 + 0x04] ! next->prev = entry->prev
1031 st %l5, [%l7 + 0x00] ! entry->prev->next = next
1032 st %l4, [%l6 + 0x04] ! entry->prev = head
1034 ld [%l4 + 0x00], %l7 ! head->next
1036 st %l7, [%l6 + 0x00] ! entry->next = head->next
1037 st %l6, [%l7 + 0x04] ! head->next->prev = entry
1038 st %l6, [%l4 + 0x00] ! head->next = entry
1040 mov %l3, %l5 ! address = tmp
1046 ld [%l6 + 0x08], %l4
1047 ldub [%l6 + 0x0c], %l3
1048 or %l4, %l3, %l4 ! encode new vaddr/pseg into l4
1050 sethi %hi(AC_CONTEXT), %l3
1051 lduba [%l3] ASI_CONTROL, %l6
1053 /* Invalidate old mapping, instantiate new mapping,
1054 * for each context. Registers l6/l7 are live across
1058 sethi %hi(AC_CONTEXT), %l3
1059 stba %l7, [%l3] ASI_CONTROL
1060 invalid_segment_patch2:
1062 stXa %l3, [%l5] ASI_SEGMAP
1063 andn %l4, 0x1ff, %l3
1065 stXa %l4, [%l3] ASI_SEGMAP
1067 sethi %hi(AC_CONTEXT), %l3
1068 stba %l6, [%l3] ASI_CONTROL
1070 andn %l4, 0x1ff, %l5
1073 sethi %hi(VMALLOC_START), %l4
1077 mov 1 << (SUN4C_REAL_PGDIR_SHIFT - PAGE_SHIFT), %l7
1079 sethi %hi(KERNBASE), %l6
1082 srl %l4, PAGE_SHIFT, %l4
1083 sethi %hi((SUN4C_PAGE_KERNEL & 0xf4000000)), %l3
1086 sethi %hi(PAGE_SIZE), %l4
1089 sta %l3, [%l5] ASI_PTE
1096 sethi %hi(sun4c_kernel_faults), %l4
1099 srl %l5, SUN4C_PGDIR_SHIFT, %l3
1100 sethi %hi(swapper_pg_dir), %l4
1101 or %l4, %lo(swapper_pg_dir), %l4
1105 and %l4, PAGE_MASK, %l4
1107 sethi %hi(PAGE_MASK), %l6
1111 srl %l5, (PAGE_SHIFT - 2), %l6
1112 and %l6, ((SUN4C_PTRS_PER_PTE - 1) << 2), %l6
1115 sethi %hi(PAGE_SIZE), %l4
1120 sta %l3, [%l5] ASI_PTE
1125 sethi %hi(sun4c_kernel_faults), %l4
1127 ld [%l4 + %lo(sun4c_kernel_faults)], %l3
1129 st %l3, [%l4 + %lo(sun4c_kernel_faults)]
1131 /* Restore condition codes */
1137 sun4c_fault_fromuser:
1141 mov %l7, %o1 ! Decode the info from %l7
1143 and %o1, 1, %o1 ! arg2 = text_faultp
1145 and %o2, 2, %o2 ! arg3 = writep
1146 andn %o3, 0xfff, %o3 ! arg4 = faulting address
1148 wr %l0, PSR_ET, %psr
1152 add %sp, STACKFRAME_SZ, %o0 ! arg1 = pt_regs ptr
1162 lda [%l5] ASI_M_MMUREGS, %l6 ! read sfar first
1163 lda [%l4] ASI_M_MMUREGS, %l5 ! read sfsr last
1165 andn %l6, 0xfff, %l6
1166 srl %l5, 6, %l5 ! and encode all info into l7
1171 or %l6, %l7, %l7 ! l7 = [addr,write,txtfault]
1177 and %o1, 1, %o1 ! arg2 = text_faultp
1179 and %o2, 2, %o2 ! arg3 = writep
1180 andn %o3, 0xfff, %o3 ! arg4 = faulting address
1182 wr %l0, PSR_ET, %psr
1186 add %sp, STACKFRAME_SZ, %o0 ! arg1 = pt_regs ptr
1190 #ifdef CONFIG_SUNOS_EMUL
1191 /* SunOS uses syscall zero as the 'indirect syscall' it looks
1192 * like indir_syscall(scall_num, arg0, arg1, arg2...); etc.
1193 * This is complete brain damage.
1198 cmp %o0, NR_SYSCALLS
1202 sethi %hi(sunos_nosys), %l6
1204 or %l6, %lo(sunos_nosys), %l6
1207 set sunos_sys_table, %l7
1221 .globl sys_nis_syscall
1224 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1225 call c_sys_nis_syscall
1232 add %sp, STACKFRAME_SZ, %o0
1234 ld [%curptr + TI_FLAGS], %l5
1235 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1249 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1257 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1262 .globl sys_sigaltstack
1274 call do_sys_sigstack
1278 .globl sys_sigreturn
1281 add %sp, STACKFRAME_SZ, %o0
1283 ld [%curptr + TI_FLAGS], %l5
1284 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1292 /* We don't want to muck with user registers like a
1293 * normal syscall, just return.
1298 .globl sys_rt_sigreturn
1300 call do_rt_sigreturn
1301 add %sp, STACKFRAME_SZ, %o0
1303 ld [%curptr + TI_FLAGS], %l5
1304 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1312 /* We are returning to a signal handler. */
1315 /* Now that we have a real sys_clone, sys_fork() is
1316 * implemented in terms of it. Our _real_ implementation
1317 * of SunOS vfork() will use sys_vfork().
1319 * XXX These three should be consolidated into mostly shared
1320 * XXX code just like on sparc64... -DaveM
1323 .globl sys_fork, flush_patch_two
1327 FLUSH_ALL_KERNEL_WINDOWS;
1328 ld [%curptr + TI_TASK], %o4
1331 mov SIGCHLD, %o0 ! arg0: clone flags
1334 mov %fp, %o1 ! arg1: usp
1335 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1336 add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
1341 /* Whee, kernel threads! */
1342 .globl sys_clone, flush_patch_three
1346 FLUSH_ALL_KERNEL_WINDOWS;
1347 ld [%curptr + TI_TASK], %o4
1351 /* arg0,1: flags,usp -- loaded already */
1352 cmp %o1, 0x0 ! Is new_usp NULL?
1356 mov %fp, %o1 ! yes, use callers usp
1357 andn %o1, 7, %o1 ! no, align to 8 bytes
1359 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1360 add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
1365 /* Whee, real vfork! */
1366 .globl sys_vfork, flush_patch_four
1369 FLUSH_ALL_KERNEL_WINDOWS;
1370 ld [%curptr + TI_TASK], %o4
1375 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1376 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1378 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1379 sethi %hi(sparc_do_fork), %l1
1381 jmpl %l1 + %lo(sparc_do_fork), %g0
1382 add %sp, STACKFRAME_SZ, %o2
1385 linux_sparc_ni_syscall:
1386 sethi %hi(sys_ni_syscall), %l7
1387 b syscall_is_too_hard
1388 or %l7, %lo(sys_ni_syscall), %l7
1398 linux_syscall_trace:
1408 .globl ret_from_fork
1413 ld [%sp + STACKFRAME_SZ + PT_I0], %o0
1415 /* Linux native and SunOS system calls enter here... */
1417 .globl linux_sparc_syscall
1418 linux_sparc_syscall:
1419 /* Direct access to user regs, must faster. */
1420 cmp %g1, NR_SYSCALLS
1421 bgeu linux_sparc_ni_syscall
1425 bne linux_fast_syscall
1426 /* Just do first insn from SAVE_ALL in the delay slot */
1428 .globl syscall_is_too_hard
1429 syscall_is_too_hard:
1433 wr %l0, PSR_ET, %psr
1438 ld [%curptr + TI_FLAGS], %l5
1440 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1442 bne linux_syscall_trace
1448 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1452 ld [%curptr + TI_FLAGS], %l6
1453 cmp %o0, -ERESTART_RESTARTBLOCK
1454 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1457 andcc %l6, _TIF_SYSCALL_TRACE, %g0
1459 /* System call success, clear Carry condition code. */
1462 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1463 bne linux_syscall_trace2
1464 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1465 add %l1, 0x4, %l2 /* npc = npc+4 */
1466 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1468 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1470 /* System call failure, set Carry condition code.
1471 * Also, get abs(errno) to return to the process.
1475 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1477 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1478 bne linux_syscall_trace2
1479 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1480 add %l1, 0x4, %l2 /* npc = npc+4 */
1481 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1483 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1485 linux_syscall_trace2:
1487 add %l1, 0x4, %l2 /* npc = npc+4 */
1488 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1490 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1494 * Solaris system calls and indirect system calls enter here.
1496 * I have named the solaris indirect syscalls like that because
1497 * it seems like Solaris has some fast path syscalls that can
1498 * be handled as indirect system calls. - mig
1501 linux_syscall_for_solaris:
1502 sethi %hi(sys_call_table), %l7
1503 b linux_sparc_syscall
1504 or %l7, %lo(sys_call_table), %l7
1507 .globl solaris_syscall
1510 be linux_syscall_for_solaris
1512 be linux_syscall_for_solaris
1514 be linux_syscall_for_solaris
1516 be,a linux_syscall_for_solaris
1522 wr %l0, PSR_ET, %psr
1527 call do_solaris_syscall
1528 add %sp, STACKFRAME_SZ, %o0
1530 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1532 cmp %o0, -ERESTART_RESTARTBLOCK
1534 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1536 /* System call success, clear Carry condition code. */
1540 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1543 /* System call failure, set Carry condition code.
1544 * Also, get abs(errno) to return to the process.
1548 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1550 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1552 /* Advance the pc and npc over the trap instruction.
1553 * If the npc is unaligned (has a 1 in the lower byte), it means
1554 * the kernel does not want us to play magic (ie, skipping over
1555 * traps). Mainly when the Solaris code wants to set some PC and
1559 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1562 add %l1, 0x4, %l2 /* npc = npc+4 */
1563 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1565 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1567 /* kernel knows what it is doing, fixup npc and continue */
1571 st %l1, [%sp + STACKFRAME_SZ + PT_NPC]
1573 #ifndef CONFIG_SUNOS_EMUL
1575 .globl sunos_syscall
1579 wr %l0, PSR_ET, %psr
1583 call do_sunos_syscall
1584 add %sp, STACKFRAME_SZ, %o0
1587 /* {net, open}bsd system calls enter here... */
1591 /* Direct access to user regs, must faster. */
1592 cmp %g1, NR_SYSCALLS
1596 set sys_ni_syscall, %l7
1603 .globl bsd_is_too_hard
1608 wr %l0, PSR_ET, %psr
1621 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1623 cmp %o0, -ERESTART_RESTARTBLOCK
1625 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1627 /* System call success, clear Carry condition code. */
1631 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1634 /* System call failure, set Carry condition code.
1635 * Also, get abs(errno) to return to the process.
1638 #if 0 /* XXX todo XXX */
1639 sethi %hi(bsd_xlatb_rorl), %o3
1640 or %o3, %lo(bsd_xlatb_rorl), %o3
1645 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1647 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1649 /* Advance the pc and npc over the trap instruction. */
1651 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1652 add %l1, 0x4, %l2 /* npc = npc+4 */
1653 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1655 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1657 /* Saving and restoring the FPU state is best done from lowlevel code.
1659 * void fpsave(unsigned long *fpregs, unsigned long *fsr,
1660 * void *fpqueue, unsigned long *fpqdepth)
1665 st %fsr, [%o1] ! this can trap on us if fpu is in bogon state
1672 /* We have an fpqueue to save. */
1686 std %f0, [%o0 + 0x00]
1687 std %f2, [%o0 + 0x08]
1688 std %f4, [%o0 + 0x10]
1689 std %f6, [%o0 + 0x18]
1690 std %f8, [%o0 + 0x20]
1691 std %f10, [%o0 + 0x28]
1692 std %f12, [%o0 + 0x30]
1693 std %f14, [%o0 + 0x38]
1694 std %f16, [%o0 + 0x40]
1695 std %f18, [%o0 + 0x48]
1696 std %f20, [%o0 + 0x50]
1697 std %f22, [%o0 + 0x58]
1698 std %f24, [%o0 + 0x60]
1699 std %f26, [%o0 + 0x68]
1700 std %f28, [%o0 + 0x70]
1702 std %f30, [%o0 + 0x78]
1704 /* Thanks for Theo Deraadt and the authors of the Sprite/netbsd/openbsd
1705 * code for pointing out this possible deadlock, while we save state
1706 * above we could trap on the fsr store so our low level fpu trap
1707 * code has to know how to deal with this.
1717 /* void fpload(unsigned long *fpregs, unsigned long *fsr); */
1721 ldd [%o0 + 0x00], %f0
1722 ldd [%o0 + 0x08], %f2
1723 ldd [%o0 + 0x10], %f4
1724 ldd [%o0 + 0x18], %f6
1725 ldd [%o0 + 0x20], %f8
1726 ldd [%o0 + 0x28], %f10
1727 ldd [%o0 + 0x30], %f12
1728 ldd [%o0 + 0x38], %f14
1729 ldd [%o0 + 0x40], %f16
1730 ldd [%o0 + 0x48], %f18
1731 ldd [%o0 + 0x50], %f20
1732 ldd [%o0 + 0x58], %f22
1733 ldd [%o0 + 0x60], %f24
1734 ldd [%o0 + 0x68], %f26
1735 ldd [%o0 + 0x70], %f28
1736 ldd [%o0 + 0x78], %f30
1741 /* __ndelay and __udelay take two arguments:
1742 * 0 - nsecs or usecs to delay
1743 * 1 - per_cpu udelay_val (loops per jiffy)
1745 * Note that ndelay gives HZ times higher resolution but has a 10ms
1746 * limit. udelay can handle up to 1s.
1750 save %sp, -STACKFRAME_SZ, %sp
1753 mov 0x1ad, %o1 ! 2**32 / (1 000 000 000 / HZ)
1755 mov %i1, %o1 ! udelay_val
1757 mov %o1, %o0 ! >>32 later for better resolution
1761 save %sp, -STACKFRAME_SZ, %sp
1763 sethi %hi(0x10c6), %o1
1765 or %o1, %lo(0x10c6), %o1 ! 2**32 / 1 000 000
1767 mov %i1, %o1 ! udelay_val
1769 mov HZ, %o0 ! >>32 earlier for wider range
1780 /* Handle a software breakpoint */
1781 /* We have to inform parent that child has stopped */
1783 .globl breakpoint_trap
1787 wr %l0, PSR_ET, %psr
1790 st %i0, [%sp + STACKFRAME_SZ + PT_G0] ! for restarting syscalls
1791 call sparc_breakpoint
1792 add %sp, STACKFRAME_SZ, %o0
1797 .globl __handle_exception, flush_patch_exception
1799 flush_patch_exception:
1800 FLUSH_ALL_KERNEL_WINDOWS;
1802 jmpl %o7 + 0xc, %g0 ! see asm-sparc/processor.h
1803 mov 1, %g1 ! signal EFAULT condition
1806 .globl kill_user_windows, kuw_patch1_7win
1808 kuw_patch1_7win: sll %o3, 6, %o3
1810 /* No matter how much overhead this routine has in the worst
1811 * case scenerio, it is several times better than taking the
1812 * traps with the old method of just doing flush_user_windows().
1815 ld [%g6 + TI_UWINMASK], %o0 ! get current umask
1816 orcc %g0, %o0, %g0 ! if no bits set, we are done
1817 be 3f ! nothing to do
1818 rd %psr, %o5 ! must clear interrupts
1819 or %o5, PSR_PIL, %o4 ! or else that could change
1820 wr %o4, 0x0, %psr ! the uwinmask state
1821 WRITE_PAUSE ! burn them cycles
1823 ld [%g6 + TI_UWINMASK], %o0 ! get consistent state
1824 orcc %g0, %o0, %g0 ! did an interrupt come in?
1825 be 4f ! yep, we are done
1826 rd %wim, %o3 ! get current wim
1827 srl %o3, 1, %o4 ! simulate a save
1829 sll %o3, 7, %o3 ! compute next wim
1830 or %o4, %o3, %o3 ! result
1831 andncc %o0, %o3, %o0 ! clean this bit in umask
1832 bne kuw_patch1 ! not done yet
1833 srl %o3, 1, %o4 ! begin another save simulation
1834 wr %o3, 0x0, %wim ! set the new wim
1835 st %g0, [%g6 + TI_UWINMASK] ! clear uwinmask
1837 wr %o5, 0x0, %psr ! re-enable interrupts
1838 WRITE_PAUSE ! burn baby burn
1841 st %g0, [%g6 + TI_W_SAVED] ! no windows saved
1844 .globl restore_current
1846 LOAD_CURRENT(g6, o0)
1851 #include <asm/pcic.h>
1854 .globl linux_trap_ipi15_pcic
1855 linux_trap_ipi15_pcic:
1860 * First deactivate NMI
1861 * or we cannot drop ET, cannot get window spill traps.
1862 * The busy loop is necessary because the PIO error
1863 * sometimes does not go away quickly and we trap again.
1865 sethi %hi(pcic_regs), %o1
1866 ld [%o1 + %lo(pcic_regs)], %o2
1868 ! Get pending status for printouts later.
1869 ld [%o2 + PCI_SYS_INT_PENDING], %o0
1871 mov PCI_SYS_INT_PENDING_CLEAR_ALL, %o1
1872 stb %o1, [%o2 + PCI_SYS_INT_PENDING_CLEAR]
1874 ld [%o2 + PCI_SYS_INT_PENDING], %o1
1875 andcc %o1, ((PCI_SYS_INT_PENDING_PIO|PCI_SYS_INT_PENDING_PCI)>>24), %g0
1879 or %l0, PSR_PIL, %l4
1882 wr %l4, PSR_ET, %psr
1886 add %sp, STACKFRAME_SZ, %o1 ! struct pt_regs *regs
1889 .globl pcic_nmi_trap_patch
1890 pcic_nmi_trap_patch:
1891 sethi %hi(linux_trap_ipi15_pcic), %l3
1892 jmpl %l3 + %lo(linux_trap_ipi15_pcic), %g0
1896 #endif /* CONFIG_PCI */
1898 /* End of entry.S */