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/config.h>
12 #include <linux/errno.h>
18 #include <asm/contregs.h>
19 #include <asm/ptrace.h>
20 #include <asm/asm-offsets.h>
22 #include <asm/vaddrs.h>
23 #include <asm/memreg.h>
26 #include <asm/pgtsun4.h>
28 #include <asm/pgtsun4c.h>
30 #include <asm/winmacro.h>
31 #include <asm/signal.h>
34 #include <asm/thread_info.h>
35 #include <asm/param.h>
37 #include <asm/asmmacro.h>
41 #define NR_SYSCALLS 284 /* Each OS is different... */
43 /* These are just handy. */
44 #define _SV save %sp, -STACKFRAME_SZ, %sp
47 #define FLUSH_ALL_KERNEL_WINDOWS \
48 _SV; _SV; _SV; _SV; _SV; _SV; _SV; \
49 _RS; _RS; _RS; _RS; _RS; _RS; _RS;
51 /* First, KGDB low level things. This is a rewrite
52 * of the routines found in the sparc-stub.c asm() statement
53 * from the gdb distribution. This is also dual-purpose
54 * as a software trap for userlevel programs.
65 #if 0 /* kgdb is dropped from 2.5.33 */
66 ! This function is called when any SPARC trap (except window overflow or
67 ! underflow) occurs. It makes sure that the invalid register window is still
68 ! available before jumping into C code. It will also restore the world if you
69 ! return from handle_exception.
76 sethi %hi(in_trap_handler), %l4
77 ld [%lo(in_trap_handler) + %l4], %l5
79 st %l5, [%lo(in_trap_handler) + %l4]
81 /* Make sure kgdb sees the same state we just saved. */
84 ld [%sp + STACKFRAME_SZ + PT_Y], %l4
85 ld [%sp + STACKFRAME_SZ + PT_WIM], %l3
86 ld [%sp + STACKFRAME_SZ + PT_PSR], %l0
87 ld [%sp + STACKFRAME_SZ + PT_PC], %l1
88 ld [%sp + STACKFRAME_SZ + PT_NPC], %l2
89 rd %tbr, %l5 /* Never changes... */
91 /* Make kgdb exception frame. */
92 sub %sp,(16+1+6+1+72)*4,%sp ! Make room for input & locals
93 ! + hidden arg + arg spill
94 ! + doubleword alignment
95 ! + registers[72] local var
98 SAVE_KGDB_SREGS(sp, l4, l0, l3, l5, l1, l2)
100 /* We are increasing PIL, so two writes. */
107 call handle_exception
108 add %sp, STACKFRAME_SZ, %o0 ! Pass address of registers
110 /* Load new kgdb register set. */
111 LOAD_KGDB_GLOBALS(sp)
113 LOAD_KGDB_SREGS(sp, l4, l0, l3, l5, l1, l2)
116 sethi %hi(in_trap_handler), %l4
117 ld [%lo(in_trap_handler) + %l4], %l5
119 st %l5, [%lo(in_trap_handler) + %l4]
121 add %sp,(16+1+6+1+72)*4,%sp ! Undo the kgdb trap frame.
123 /* Now take what kgdb did and place it into the pt_regs
124 * frame which SparcLinux RESTORE_ALL understands.,
128 STORE_PT_YREG(sp, g2)
129 STORE_PT_PRIV(sp, l0, l1, l2)
134 #ifdef CONFIG_BLK_DEV_FD
137 .globl floppy_hardint
140 * This code cannot touch registers %l0 %l1 and %l2
141 * because SAVE_ALL depends on their values. It depends
142 * on %l3 also, but we regenerate it before a call.
143 * Other registers are:
144 * %l3 -- base address of fdc registers
146 * %l5 -- scratch for ld/st address
148 * %l7 -- scratch [floppy byte, ld/st address, aux. data]
151 /* Do we have work to do? */
152 sethi %hi(doing_pdma), %l7
153 ld [%l7 + %lo(doing_pdma)], %l7
158 /* Load fdc register base */
159 sethi %hi(fdc_status), %l3
160 ld [%l3 + %lo(fdc_status)], %l3
162 /* Setup register addresses */
163 sethi %hi(pdma_vaddr), %l5 ! transfer buffer
164 ld [%l5 + %lo(pdma_vaddr)], %l4
165 sethi %hi(pdma_size), %l5 ! bytes to go
166 ld [%l5 + %lo(pdma_size)], %l6
170 andcc %l7, 0x80, %g0 ! Does fifo still have data
171 bz floppy_fifo_emptied ! fifo has been emptied...
172 andcc %l7, 0x20, %g0 ! in non-dma mode still?
173 bz floppy_overrun ! nope, overrun
174 andcc %l7, 0x40, %g0 ! 0=write 1=read
178 /* Ok, actually read this byte */
189 /* Ok, actually write this byte */
196 /* fall through... */
198 sethi %hi(pdma_vaddr), %l5
199 st %l4, [%l5 + %lo(pdma_vaddr)]
200 sethi %hi(pdma_size), %l5
201 st %l6, [%l5 + %lo(pdma_size)]
202 /* Flip terminal count pin */
203 set auxio_register, %l7
206 set sparc_cpu_model, %l5
208 subcc %l5, 1, %g0 /* enum { sun4c = 1 }; */
224 /* Kill some time so the bits set */
230 /* Prevent recursion */
231 sethi %hi(doing_pdma), %l7
233 st %g0, [%l7 + %lo(doing_pdma)]
235 /* We emptied the FIFO, but we haven't read everything
236 * as of yet. Store the current transfer address and
237 * bytes left to read so we can continue when the next
241 sethi %hi(pdma_vaddr), %l5
242 st %l4, [%l5 + %lo(pdma_vaddr)]
243 sethi %hi(pdma_size), %l7
244 st %l6, [%l7 + %lo(pdma_size)]
246 /* Restore condition codes */
254 sethi %hi(pdma_vaddr), %l5
255 st %l4, [%l5 + %lo(pdma_vaddr)]
256 sethi %hi(pdma_size), %l5
257 st %l6, [%l5 + %lo(pdma_size)]
258 /* Prevent recursion */
259 sethi %hi(doing_pdma), %l7
260 st %g0, [%l7 + %lo(doing_pdma)]
262 /* fall through... */
267 /* Set all IRQs off. */
274 mov 11, %o0 ! floppy irq level (unused anyway)
275 mov %g0, %o1 ! devid is not used in fast interrupts
276 call sparc_floppy_irq
277 add %sp, STACKFRAME_SZ, %o2 ! struct pt_regs *regs
281 #endif /* (CONFIG_BLK_DEV_FD) */
283 /* Bad trap handler */
284 .globl bad_trap_handler
291 add %sp, STACKFRAME_SZ, %o0 ! pt_regs
293 mov %l7, %o1 ! trap number
297 /* For now all IRQ's not registered get sent here. handler_irq() will
298 * see if a routine is registered to handle this interrupt and if not
299 * it will say so on the console.
303 .globl real_irq_entry, patch_handler_irq
308 .globl patchme_maybe_smp_msg
311 patchme_maybe_smp_msg:
322 mov %l7, %o0 ! irq level
325 add %sp, STACKFRAME_SZ, %o1 ! pt_regs ptr
326 or %l0, PSR_PIL, %g2 ! restore PIL after handler_irq
327 wr %g2, PSR_ET, %psr ! keep ET up
333 /* SMP per-cpu ticker interrupts are handled specially. */
335 bne real_irq_continue+4
341 call smp4m_percpu_timer_interrupt
342 add %sp, STACKFRAME_SZ, %o0
347 /* Here is where we check for possible SMP IPI passed to us
348 * on some level other than 15 which is the NMI and only used
349 * for cross calls. That has a separate entry point below.
352 GET_PROCESSOR4M_ID(o3)
353 set sun4m_interrupts, %l5
355 sethi %hi(0x40000000), %o2
370 call smp_reschedule_irq
376 .globl linux_trap_ipi15_sun4m
377 linux_trap_ipi15_sun4m:
379 sethi %hi(0x80000000), %o2
380 GET_PROCESSOR4M_ID(o0)
381 set sun4m_interrupts, %l5
387 be 1f ! Must be an NMI async memory error
397 call smp4m_cross_call_irq
399 b ret_trap_lockless_ipi
402 /* NMI async memory error handling. */
403 sethi %hi(0x80000000), %l4
404 sethi %hi(0x4000), %o3
425 /* SMP per-cpu ticker interrupts are handled specially. */
429 sethi %hi(CC_ICLR), %o0
430 sethi %hi(1 << 14), %o1
431 or %o0, %lo(CC_ICLR), %o0
432 stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 14 in MXCC's ICLR */
437 call smp4d_percpu_timer_interrupt
438 add %sp, STACKFRAME_SZ, %o0
444 .globl linux_trap_ipi15_sun4d
445 linux_trap_ipi15_sun4d:
447 sethi %hi(CC_BASE), %o4
448 sethi %hi(MXCC_ERR_ME|MXCC_ERR_PEW|MXCC_ERR_ASE|MXCC_ERR_PEE), %o2
449 or %o4, (CC_EREG - CC_BASE), %o0
450 ldda [%o0] ASI_M_MXCC, %o0
453 sethi %hi(BB_STAT2), %o2
454 lduba [%o2] ASI_M_CTL, %o2
455 andcc %o2, BB_STAT2_MASK, %g0
457 or %o4, (CC_ICLR - CC_BASE), %o0
458 sethi %hi(1 << 15), %o1
459 stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 15 in MXCC's ICLR */
465 call smp4d_cross_call_irq
467 b ret_trap_lockless_ipi
474 lduha [%l4] ASI_M_MXCC, %l5
475 sethi %hi(1 << 15), %l7
477 stha %l5, [%l4] ASI_M_MXCC
481 #endif /* CONFIG_SMP */
483 /* This routine handles illegal instructions and privileged
484 * instruction attempts from user code.
487 .globl bad_instruction
489 sethi %hi(0xc1f80000), %l4
491 sethi %hi(0x81d80000), %l7
497 wr %l0, PSR_ET, %psr ! re-enable traps
500 add %sp, STACKFRAME_SZ, %o0
503 call do_illegal_instruction
508 1: /* unimplemented flush - just skip */
513 .globl priv_instruction
520 add %sp, STACKFRAME_SZ, %o0
523 call do_priv_instruction
528 /* This routine handles unaligned data accesses. */
532 andcc %l0, PSR_PS, %g0
542 call kernel_unaligned_trap
543 add %sp, STACKFRAME_SZ, %o0
550 wr %l0, PSR_ET, %psr ! re-enable traps
554 call user_unaligned_trap
555 add %sp, STACKFRAME_SZ, %o0
559 /* This routine handles floating point disabled traps. */
561 .globl fpd_trap_handler
565 wr %l0, PSR_ET, %psr ! re-enable traps
568 add %sp, STACKFRAME_SZ, %o0
576 /* This routine handles Floating Point Exceptions. */
578 .globl fpe_trap_handler
580 set fpsave_magic, %l5
583 sethi %hi(fpsave), %l5
584 or %l5, %lo(fpsave), %l5
587 sethi %hi(fpsave_catch2), %l5
588 or %l5, %lo(fpsave_catch2), %l5
594 sethi %hi(fpsave_catch), %l5
595 or %l5, %lo(fpsave_catch), %l5
604 wr %l0, PSR_ET, %psr ! re-enable traps
607 add %sp, STACKFRAME_SZ, %o0
615 /* This routine handles Tag Overflow Exceptions. */
617 .globl do_tag_overflow
621 wr %l0, PSR_ET, %psr ! re-enable traps
624 add %sp, STACKFRAME_SZ, %o0
627 call handle_tag_overflow
632 /* This routine handles Watchpoint Exceptions. */
638 wr %l0, PSR_ET, %psr ! re-enable traps
641 add %sp, STACKFRAME_SZ, %o0
644 call handle_watchpoint
649 /* This routine handles Register Access Exceptions. */
655 wr %l0, PSR_ET, %psr ! re-enable traps
658 add %sp, STACKFRAME_SZ, %o0
661 call handle_reg_access
666 /* This routine handles Co-Processor Disabled Exceptions. */
668 .globl do_cp_disabled
672 wr %l0, PSR_ET, %psr ! re-enable traps
675 add %sp, STACKFRAME_SZ, %o0
678 call handle_cp_disabled
683 /* This routine handles Co-Processor Exceptions. */
685 .globl do_cp_exception
689 wr %l0, PSR_ET, %psr ! re-enable traps
692 add %sp, STACKFRAME_SZ, %o0
695 call handle_cp_exception
700 /* This routine handles Hardware Divide By Zero Exceptions. */
706 wr %l0, PSR_ET, %psr ! re-enable traps
709 add %sp, STACKFRAME_SZ, %o0
712 call handle_hw_divzero
718 .globl do_flush_windows
725 andcc %l0, PSR_PS, %g0
729 call flush_user_windows
732 /* Advance over the trap instruction. */
733 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1
735 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
736 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
740 .globl flush_patch_one
742 /* We get these for debugging routines using __builtin_return_address() */
745 FLUSH_ALL_KERNEL_WINDOWS
747 /* Advance over the trap instruction. */
748 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1
750 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
751 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
755 /* The getcc software trap. The user wants the condition codes from
756 * the %psr in register %g1.
760 .globl getcc_trap_handler
762 srl %l0, 20, %g1 ! give user
763 and %g1, 0xf, %g1 ! only ICC bits in %psr
764 jmp %l2 ! advance over trap instruction
765 rett %l2 + 0x4 ! like this...
767 /* The setcc software trap. The user has condition codes in %g1
768 * that it would like placed in the %psr. Be careful not to flip
769 * any unintentional bits!
773 .globl setcc_trap_handler
777 andn %l0, %l5, %l0 ! clear ICC bits in %psr
778 and %l4, %l5, %l4 ! clear non-ICC bits in user value
779 or %l4, %l0, %l4 ! or them in... mix mix mix
781 wr %l4, 0x0, %psr ! set new %psr
782 WRITE_PAUSE ! TI scumbags...
784 jmp %l2 ! advance over trap instruction
785 rett %l2 + 0x4 ! like this...
788 .globl linux_trap_nmi_sun4c
789 linux_trap_nmi_sun4c:
792 /* Ugh, we need to clear the IRQ line. This is now
793 * a very sun4c specific trap handler...
795 sethi %hi(interrupt_enable), %l5
796 ld [%l5 + %lo(interrupt_enable)], %l5
798 andn %l6, INTS_ENAB, %l6
801 /* Now it is safe to re-enable traps without recursion. */
806 /* Now call the c-code with the pt_regs frame ptr and the
807 * memory error registers as arguments. The ordering chosen
808 * here is due to unlatching semantics.
810 sethi %hi(AC_SYNC_ERR), %o0
812 lda [%o0] ASI_CONTROL, %o2 ! sync vaddr
814 lda [%o0] ASI_CONTROL, %o1 ! sync error
816 lda [%o0] ASI_CONTROL, %o4 ! async vaddr
818 lda [%o0] ASI_CONTROL, %o3 ! async error
820 add %sp, STACKFRAME_SZ, %o0
825 .globl invalid_segment_patch1_ff
826 .globl invalid_segment_patch2_ff
827 invalid_segment_patch1_ff: cmp %l4, 0xff
828 invalid_segment_patch2_ff: mov 0xff, %l3
831 .globl invalid_segment_patch1_1ff
832 .globl invalid_segment_patch2_1ff
833 invalid_segment_patch1_1ff: cmp %l4, 0x1ff
834 invalid_segment_patch2_1ff: mov 0x1ff, %l3
837 .globl num_context_patch1_16, num_context_patch2_16
838 num_context_patch1_16: mov 0x10, %l7
839 num_context_patch2_16: mov 0x10, %l7
842 .globl vac_linesize_patch_32
843 vac_linesize_patch_32: subcc %l7, 32, %l7
846 .globl vac_hwflush_patch1_on, vac_hwflush_patch2_on
849 * Ugly, but we cant use hardware flushing on the sun4 and we'd require
850 * two instructions (Anton)
853 vac_hwflush_patch1_on: nop
855 vac_hwflush_patch1_on: addcc %l7, -PAGE_SIZE, %l7
858 vac_hwflush_patch2_on: sta %g0, [%l3 + %l7] ASI_HWFLUSHSEG
860 .globl invalid_segment_patch1, invalid_segment_patch2
861 .globl num_context_patch1
862 .globl vac_linesize_patch, vac_hwflush_patch1
863 .globl vac_hwflush_patch2
872 ! %l7 = 1 for textfault
873 ! We want error in %l5, vaddr in %l6
876 sethi %hi(sun4c_memerr_reg), %l4
877 ld [%l4+%lo(sun4c_memerr_reg)], %l4 ! memerr ctrl reg addr
878 ld [%l4], %l6 ! memerr ctrl reg
879 ld [%l4 + 4], %l5 ! memerr vaddr reg
880 andcc %l6, 0x80, %g0 ! check for error type
881 st %g0, [%l4 + 4] ! clear the error
883 sethi %hi(AC_BUS_ERROR), %l4 ! bus err reg addr
885 call prom_halt ! something weird happened
886 ! what exactly did happen?
887 ! what should we do here?
889 0: or %l4, %lo(AC_BUS_ERROR), %l4 ! bus err reg addr
890 lduba [%l4] ASI_CONTROL, %l6 ! bus err reg
892 cmp %l7, 1 ! text fault?
896 ld [%l1], %l4 ! load instruction that caused fault
898 andcc %l4, 1, %g0 ! store instruction?
901 sethi %hi(SUN4C_SYNC_BADWRITE), %l4 ! yep
902 ! %lo(SUN4C_SYNC_BADWRITE) = 0
903 or %l4, %l6, %l6 ! set write bit to emulate sun4c
906 sethi %hi(AC_SYNC_ERR), %l4
907 add %l4, 0x4, %l6 ! AC_SYNC_VA in %l6
908 lda [%l6] ASI_CONTROL, %l5 ! Address
909 lda [%l4] ASI_CONTROL, %l6 ! Error, retained for a bit
912 andn %l5, 0xfff, %l5 ! Encode all info into l7
918 or %l4, %l7, %l7 ! l7 = [addr,write,txtfault]
920 andcc %l0, PSR_PS, %g0
921 be sun4c_fault_fromuser
922 andcc %l7, 1, %g0 ! Text fault?
925 sethi %hi(KERNBASE), %l4
931 blu sun4c_fault_fromuser
932 sethi %hi(~((1 << SUN4C_REAL_PGDIR_SHIFT) - 1)), %l4
934 /* If the kernel references a bum kernel pointer, or a pte which
935 * points to a non existant page in ram, we will run this code
936 * _forever_ and lock up the machine!!!!! So we must check for
937 * this condition, the AC_SYNC_ERR bits are what we must examine.
938 * Also a parity error would make this happen as well. So we just
939 * check that we are in fact servicing a tlb miss and not some
940 * other type of fault for the kernel.
943 be sun4c_fault_fromuser
946 /* Test for NULL pte_t * in vmalloc area. */
947 sethi %hi(VMALLOC_START), %l4
949 blu,a invalid_segment_patch1
950 lduXa [%l5] ASI_SEGMAP, %l4
952 sethi %hi(swapper_pg_dir), %l4
953 srl %l5, SUN4C_PGDIR_SHIFT, %l6
954 or %l4, %lo(swapper_pg_dir), %l4
958 sethi %hi(PAGE_MASK), %l6
961 andcc %l4, PAGE_MASK, %g0
963 be sun4c_fault_fromuser
964 lduXa [%l5] ASI_SEGMAP, %l4
966 invalid_segment_patch1:
969 sethi %hi(sun4c_kfree_ring), %l4
970 or %l4, %lo(sun4c_kfree_ring), %l4
972 deccc %l3 ! do we have a free entry?
973 bcs,a 2f ! no, unmap one.
974 sethi %hi(sun4c_kernel_ring), %l4
976 st %l3, [%l4 + 0x18] ! sun4c_kfree_ring.num_entries--
978 ld [%l4 + 0x00], %l6 ! entry = sun4c_kfree_ring.ringhd.next
979 st %l5, [%l6 + 0x08] ! entry->vaddr = address
981 ld [%l6 + 0x00], %l3 ! next = entry->next
982 ld [%l6 + 0x04], %l7 ! entry->prev
984 st %l7, [%l3 + 0x04] ! next->prev = entry->prev
985 st %l3, [%l7 + 0x00] ! entry->prev->next = next
987 sethi %hi(sun4c_kernel_ring), %l4
988 or %l4, %lo(sun4c_kernel_ring), %l4
989 ! head = &sun4c_kernel_ring.ringhd
991 ld [%l4 + 0x00], %l7 ! head->next
993 st %l4, [%l6 + 0x04] ! entry->prev = head
994 st %l7, [%l6 + 0x00] ! entry->next = head->next
995 st %l6, [%l7 + 0x04] ! head->next->prev = entry
997 st %l6, [%l4 + 0x00] ! head->next = entry
1000 inc %l3 ! sun4c_kernel_ring.num_entries++
1001 st %l3, [%l4 + 0x18]
1003 ld [%l6 + 0x08], %l5
1006 or %l4, %lo(sun4c_kernel_ring), %l4
1007 ! head = &sun4c_kernel_ring.ringhd
1009 ld [%l4 + 0x04], %l6 ! entry = head->prev
1011 ld [%l6 + 0x08], %l3 ! tmp = entry->vaddr
1013 ! Flush segment from the cache.
1015 sethi %hi((128 * 1024)), %l7
1017 sethi %hi((64 * 1024)), %l7
1025 sta %g0, [%l3 + %l7] ASI_FLUSHSEG
1027 st %l5, [%l6 + 0x08] ! entry->vaddr = address
1029 ld [%l6 + 0x00], %l5 ! next = entry->next
1030 ld [%l6 + 0x04], %l7 ! entry->prev
1032 st %l7, [%l5 + 0x04] ! next->prev = entry->prev
1033 st %l5, [%l7 + 0x00] ! entry->prev->next = next
1034 st %l4, [%l6 + 0x04] ! entry->prev = head
1036 ld [%l4 + 0x00], %l7 ! head->next
1038 st %l7, [%l6 + 0x00] ! entry->next = head->next
1039 st %l6, [%l7 + 0x04] ! head->next->prev = entry
1040 st %l6, [%l4 + 0x00] ! head->next = entry
1042 mov %l3, %l5 ! address = tmp
1048 ld [%l6 + 0x08], %l4
1049 ldub [%l6 + 0x0c], %l3
1050 or %l4, %l3, %l4 ! encode new vaddr/pseg into l4
1052 sethi %hi(AC_CONTEXT), %l3
1053 lduba [%l3] ASI_CONTROL, %l6
1055 /* Invalidate old mapping, instantiate new mapping,
1056 * for each context. Registers l6/l7 are live across
1060 sethi %hi(AC_CONTEXT), %l3
1061 stba %l7, [%l3] ASI_CONTROL
1062 invalid_segment_patch2:
1064 stXa %l3, [%l5] ASI_SEGMAP
1065 andn %l4, 0x1ff, %l3
1067 stXa %l4, [%l3] ASI_SEGMAP
1069 sethi %hi(AC_CONTEXT), %l3
1070 stba %l6, [%l3] ASI_CONTROL
1072 andn %l4, 0x1ff, %l5
1075 sethi %hi(VMALLOC_START), %l4
1079 mov 1 << (SUN4C_REAL_PGDIR_SHIFT - PAGE_SHIFT), %l7
1081 sethi %hi(KERNBASE), %l6
1084 srl %l4, PAGE_SHIFT, %l4
1085 sethi %hi((SUN4C_PAGE_KERNEL & 0xf4000000)), %l3
1088 sethi %hi(PAGE_SIZE), %l4
1091 sta %l3, [%l5] ASI_PTE
1098 sethi %hi(sun4c_kernel_faults), %l4
1101 srl %l5, SUN4C_PGDIR_SHIFT, %l3
1102 sethi %hi(swapper_pg_dir), %l4
1103 or %l4, %lo(swapper_pg_dir), %l4
1107 and %l4, PAGE_MASK, %l4
1109 sethi %hi(PAGE_MASK), %l6
1113 srl %l5, (PAGE_SHIFT - 2), %l6
1114 and %l6, ((SUN4C_PTRS_PER_PTE - 1) << 2), %l6
1117 sethi %hi(PAGE_SIZE), %l4
1122 sta %l3, [%l5] ASI_PTE
1127 sethi %hi(sun4c_kernel_faults), %l4
1129 ld [%l4 + %lo(sun4c_kernel_faults)], %l3
1131 st %l3, [%l4 + %lo(sun4c_kernel_faults)]
1133 /* Restore condition codes */
1139 sun4c_fault_fromuser:
1143 mov %l7, %o1 ! Decode the info from %l7
1145 and %o1, 1, %o1 ! arg2 = text_faultp
1147 and %o2, 2, %o2 ! arg3 = writep
1148 andn %o3, 0xfff, %o3 ! arg4 = faulting address
1150 wr %l0, PSR_ET, %psr
1154 add %sp, STACKFRAME_SZ, %o0 ! arg1 = pt_regs ptr
1164 lda [%l5] ASI_M_MMUREGS, %l6 ! read sfar first
1165 lda [%l4] ASI_M_MMUREGS, %l5 ! read sfsr last
1167 andn %l6, 0xfff, %l6
1168 srl %l5, 6, %l5 ! and encode all info into l7
1173 or %l6, %l7, %l7 ! l7 = [addr,write,txtfault]
1179 and %o1, 1, %o1 ! arg2 = text_faultp
1181 and %o2, 2, %o2 ! arg3 = writep
1182 andn %o3, 0xfff, %o3 ! arg4 = faulting address
1184 wr %l0, PSR_ET, %psr
1188 add %sp, STACKFRAME_SZ, %o0 ! arg1 = pt_regs ptr
1192 #ifdef CONFIG_SUNOS_EMUL
1193 /* SunOS uses syscall zero as the 'indirect syscall' it looks
1194 * like indir_syscall(scall_num, arg0, arg1, arg2...); etc.
1195 * This is complete brain damage.
1200 cmp %o0, NR_SYSCALLS
1204 sethi %hi(sunos_nosys), %l6
1206 or %l6, %lo(sunos_nosys), %l6
1209 set sunos_sys_table, %l7
1223 .globl sys_nis_syscall
1226 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1227 call c_sys_nis_syscall
1234 add %sp, STACKFRAME_SZ, %o0
1236 ld [%curptr + TI_FLAGS], %l5
1237 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1251 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1259 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1264 .globl sys_sigaltstack
1276 call do_sys_sigstack
1282 /* Note: %o0 already has correct value... */
1284 add %sp, STACKFRAME_SZ, %o1
1286 ld [%curptr + TI_FLAGS], %l5
1287 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1295 /* We are returning to a signal handler. */
1299 .globl sys_sigsuspend
1302 add %sp, STACKFRAME_SZ, %o0
1304 ld [%curptr + TI_FLAGS], %l5
1305 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1313 /* We are returning to a signal handler. */
1317 .globl sys_rt_sigsuspend
1319 /* Note: %o0, %o1 already have correct value... */
1320 call do_rt_sigsuspend
1321 add %sp, STACKFRAME_SZ, %o2
1323 ld [%curptr + TI_FLAGS], %l5
1324 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1332 /* We are returning to a signal handler. */
1336 .globl sys_sigreturn
1339 add %sp, STACKFRAME_SZ, %o0
1341 ld [%curptr + TI_FLAGS], %l5
1342 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1350 /* We don't want to muck with user registers like a
1351 * normal syscall, just return.
1356 .globl sys_rt_sigreturn
1358 call do_rt_sigreturn
1359 add %sp, STACKFRAME_SZ, %o0
1361 ld [%curptr + TI_FLAGS], %l5
1362 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1370 /* We are returning to a signal handler. */
1373 /* Now that we have a real sys_clone, sys_fork() is
1374 * implemented in terms of it. Our _real_ implementation
1375 * of SunOS vfork() will use sys_vfork().
1377 * XXX These three should be consolidated into mostly shared
1378 * XXX code just like on sparc64... -DaveM
1381 .globl sys_fork, flush_patch_two
1385 FLUSH_ALL_KERNEL_WINDOWS;
1386 ld [%curptr + TI_TASK], %o4
1389 mov SIGCHLD, %o0 ! arg0: clone flags
1392 mov %fp, %o1 ! arg1: usp
1393 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1394 add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
1399 /* Whee, kernel threads! */
1400 .globl sys_clone, flush_patch_three
1404 FLUSH_ALL_KERNEL_WINDOWS;
1405 ld [%curptr + TI_TASK], %o4
1409 /* arg0,1: flags,usp -- loaded already */
1410 cmp %o1, 0x0 ! Is new_usp NULL?
1414 mov %fp, %o1 ! yes, use callers usp
1415 andn %o1, 7, %o1 ! no, align to 8 bytes
1417 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1418 add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
1423 /* Whee, real vfork! */
1424 .globl sys_vfork, flush_patch_four
1427 FLUSH_ALL_KERNEL_WINDOWS;
1428 ld [%curptr + TI_TASK], %o4
1433 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1434 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1436 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1437 sethi %hi(sparc_do_fork), %l1
1439 jmpl %l1 + %lo(sparc_do_fork), %g0
1440 add %sp, STACKFRAME_SZ, %o2
1443 linux_sparc_ni_syscall:
1444 sethi %hi(sys_ni_syscall), %l7
1445 b syscall_is_too_hard
1446 or %l7, %lo(sys_ni_syscall), %l7
1456 linux_syscall_trace:
1466 .globl ret_from_fork
1471 ld [%sp + STACKFRAME_SZ + PT_I0], %o0
1473 /* Linux native and SunOS system calls enter here... */
1475 .globl linux_sparc_syscall
1476 linux_sparc_syscall:
1477 /* Direct access to user regs, must faster. */
1478 cmp %g1, NR_SYSCALLS
1479 bgeu linux_sparc_ni_syscall
1483 bne linux_fast_syscall
1484 /* Just do first insn from SAVE_ALL in the delay slot */
1486 .globl syscall_is_too_hard
1487 syscall_is_too_hard:
1491 wr %l0, PSR_ET, %psr
1496 ld [%curptr + TI_FLAGS], %l5
1498 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1500 bne linux_syscall_trace
1506 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1510 ld [%curptr + TI_FLAGS], %l6
1511 cmp %o0, -ERESTART_RESTARTBLOCK
1512 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1515 andcc %l6, _TIF_SYSCALL_TRACE, %g0
1517 /* System call success, clear Carry condition code. */
1520 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1521 bne linux_syscall_trace2
1522 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1523 add %l1, 0x4, %l2 /* npc = npc+4 */
1524 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1526 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1528 /* System call failure, set Carry condition code.
1529 * Also, get abs(errno) to return to the process.
1533 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1535 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1536 bne linux_syscall_trace2
1537 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1538 add %l1, 0x4, %l2 /* npc = npc+4 */
1539 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1541 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1543 linux_syscall_trace2:
1545 add %l1, 0x4, %l2 /* npc = npc+4 */
1546 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1548 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1552 * Solaris system calls and indirect system calls enter here.
1554 * I have named the solaris indirect syscalls like that because
1555 * it seems like Solaris has some fast path syscalls that can
1556 * be handled as indirect system calls. - mig
1559 linux_syscall_for_solaris:
1560 sethi %hi(sys_call_table), %l7
1561 b linux_sparc_syscall
1562 or %l7, %lo(sys_call_table), %l7
1565 .globl solaris_syscall
1568 be linux_syscall_for_solaris
1570 be linux_syscall_for_solaris
1572 be linux_syscall_for_solaris
1574 be,a linux_syscall_for_solaris
1580 wr %l0, PSR_ET, %psr
1585 call do_solaris_syscall
1586 add %sp, STACKFRAME_SZ, %o0
1588 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1590 cmp %o0, -ERESTART_RESTARTBLOCK
1592 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1594 /* System call success, clear Carry condition code. */
1598 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1601 /* System call failure, set Carry condition code.
1602 * Also, get abs(errno) to return to the process.
1606 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1608 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1610 /* Advance the pc and npc over the trap instruction.
1611 * If the npc is unaligned (has a 1 in the lower byte), it means
1612 * the kernel does not want us to play magic (ie, skipping over
1613 * traps). Mainly when the Solaris code wants to set some PC and
1617 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1620 add %l1, 0x4, %l2 /* npc = npc+4 */
1621 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1623 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1625 /* kernel knows what it is doing, fixup npc and continue */
1629 st %l1, [%sp + STACKFRAME_SZ + PT_NPC]
1631 #ifndef CONFIG_SUNOS_EMUL
1633 .globl sunos_syscall
1637 wr %l0, PSR_ET, %psr
1641 call do_sunos_syscall
1642 add %sp, STACKFRAME_SZ, %o0
1645 /* {net, open}bsd system calls enter here... */
1649 /* Direct access to user regs, must faster. */
1650 cmp %g1, NR_SYSCALLS
1654 set sys_ni_syscall, %l7
1661 .globl bsd_is_too_hard
1666 wr %l0, PSR_ET, %psr
1679 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1681 cmp %o0, -ERESTART_RESTARTBLOCK
1683 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1685 /* System call success, clear Carry condition code. */
1689 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1692 /* System call failure, set Carry condition code.
1693 * Also, get abs(errno) to return to the process.
1696 #if 0 /* XXX todo XXX */
1697 sethi %hi(bsd_xlatb_rorl), %o3
1698 or %o3, %lo(bsd_xlatb_rorl), %o3
1703 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1705 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1707 /* Advance the pc and npc over the trap instruction. */
1709 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1710 add %l1, 0x4, %l2 /* npc = npc+4 */
1711 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1713 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1715 /* Saving and restoring the FPU state is best done from lowlevel code.
1717 * void fpsave(unsigned long *fpregs, unsigned long *fsr,
1718 * void *fpqueue, unsigned long *fpqdepth)
1723 st %fsr, [%o1] ! this can trap on us if fpu is in bogon state
1730 /* We have an fpqueue to save. */
1744 std %f0, [%o0 + 0x00]
1745 std %f2, [%o0 + 0x08]
1746 std %f4, [%o0 + 0x10]
1747 std %f6, [%o0 + 0x18]
1748 std %f8, [%o0 + 0x20]
1749 std %f10, [%o0 + 0x28]
1750 std %f12, [%o0 + 0x30]
1751 std %f14, [%o0 + 0x38]
1752 std %f16, [%o0 + 0x40]
1753 std %f18, [%o0 + 0x48]
1754 std %f20, [%o0 + 0x50]
1755 std %f22, [%o0 + 0x58]
1756 std %f24, [%o0 + 0x60]
1757 std %f26, [%o0 + 0x68]
1758 std %f28, [%o0 + 0x70]
1760 std %f30, [%o0 + 0x78]
1762 /* Thanks for Theo Deraadt and the authors of the Sprite/netbsd/openbsd
1763 * code for pointing out this possible deadlock, while we save state
1764 * above we could trap on the fsr store so our low level fpu trap
1765 * code has to know how to deal with this.
1775 /* void fpload(unsigned long *fpregs, unsigned long *fsr); */
1779 ldd [%o0 + 0x00], %f0
1780 ldd [%o0 + 0x08], %f2
1781 ldd [%o0 + 0x10], %f4
1782 ldd [%o0 + 0x18], %f6
1783 ldd [%o0 + 0x20], %f8
1784 ldd [%o0 + 0x28], %f10
1785 ldd [%o0 + 0x30], %f12
1786 ldd [%o0 + 0x38], %f14
1787 ldd [%o0 + 0x40], %f16
1788 ldd [%o0 + 0x48], %f18
1789 ldd [%o0 + 0x50], %f20
1790 ldd [%o0 + 0x58], %f22
1791 ldd [%o0 + 0x60], %f24
1792 ldd [%o0 + 0x68], %f26
1793 ldd [%o0 + 0x70], %f28
1794 ldd [%o0 + 0x78], %f30
1799 /* __ndelay and __udelay take two arguments:
1800 * 0 - nsecs or usecs to delay
1801 * 1 - per_cpu udelay_val (loops per jiffy)
1803 * Note that ndelay gives HZ times higher resolution but has a 10ms
1804 * limit. udelay can handle up to 1s.
1808 save %sp, -STACKFRAME_SZ, %sp
1811 mov 0x1ad, %o1 ! 2**32 / (1 000 000 000 / HZ)
1813 mov %i1, %o1 ! udelay_val
1815 mov %o1, %o0 ! >>32 later for better resolution
1819 save %sp, -STACKFRAME_SZ, %sp
1821 sethi %hi(0x10c6), %o1
1823 or %o1, %lo(0x10c6), %o1 ! 2**32 / 1 000 000
1825 mov %i1, %o1 ! udelay_val
1827 mov HZ, %o0 ! >>32 earlier for wider range
1838 /* Handle a software breakpoint */
1839 /* We have to inform parent that child has stopped */
1841 .globl breakpoint_trap
1845 wr %l0, PSR_ET, %psr
1848 st %i0, [%sp + STACKFRAME_SZ + PT_G0] ! for restarting syscalls
1849 call sparc_breakpoint
1850 add %sp, STACKFRAME_SZ, %o0
1855 .globl __handle_exception, flush_patch_exception
1857 flush_patch_exception:
1858 FLUSH_ALL_KERNEL_WINDOWS;
1860 jmpl %o7 + 0xc, %g0 ! see asm-sparc/processor.h
1861 mov 1, %g1 ! signal EFAULT condition
1864 .globl kill_user_windows, kuw_patch1_7win
1866 kuw_patch1_7win: sll %o3, 6, %o3
1868 /* No matter how much overhead this routine has in the worst
1869 * case scenerio, it is several times better than taking the
1870 * traps with the old method of just doing flush_user_windows().
1873 ld [%g6 + TI_UWINMASK], %o0 ! get current umask
1874 orcc %g0, %o0, %g0 ! if no bits set, we are done
1875 be 3f ! nothing to do
1876 rd %psr, %o5 ! must clear interrupts
1877 or %o5, PSR_PIL, %o4 ! or else that could change
1878 wr %o4, 0x0, %psr ! the uwinmask state
1879 WRITE_PAUSE ! burn them cycles
1881 ld [%g6 + TI_UWINMASK], %o0 ! get consistent state
1882 orcc %g0, %o0, %g0 ! did an interrupt come in?
1883 be 4f ! yep, we are done
1884 rd %wim, %o3 ! get current wim
1885 srl %o3, 1, %o4 ! simulate a save
1887 sll %o3, 7, %o3 ! compute next wim
1888 or %o4, %o3, %o3 ! result
1889 andncc %o0, %o3, %o0 ! clean this bit in umask
1890 bne kuw_patch1 ! not done yet
1891 srl %o3, 1, %o4 ! begin another save simulation
1892 wr %o3, 0x0, %wim ! set the new wim
1893 st %g0, [%g6 + TI_UWINMASK] ! clear uwinmask
1895 wr %o5, 0x0, %psr ! re-enable interrupts
1896 WRITE_PAUSE ! burn baby burn
1899 st %g0, [%g6 + TI_W_SAVED] ! no windows saved
1902 .globl restore_current
1904 LOAD_CURRENT(g6, o0)
1909 #include <asm/pcic.h>
1912 .globl linux_trap_ipi15_pcic
1913 linux_trap_ipi15_pcic:
1918 * First deactivate NMI
1919 * or we cannot drop ET, cannot get window spill traps.
1920 * The busy loop is necessary because the PIO error
1921 * sometimes does not go away quickly and we trap again.
1923 sethi %hi(pcic_regs), %o1
1924 ld [%o1 + %lo(pcic_regs)], %o2
1926 ! Get pending status for printouts later.
1927 ld [%o2 + PCI_SYS_INT_PENDING], %o0
1929 mov PCI_SYS_INT_PENDING_CLEAR_ALL, %o1
1930 stb %o1, [%o2 + PCI_SYS_INT_PENDING_CLEAR]
1932 ld [%o2 + PCI_SYS_INT_PENDING], %o1
1933 andcc %o1, ((PCI_SYS_INT_PENDING_PIO|PCI_SYS_INT_PENDING_PCI)>>24), %g0
1937 or %l0, PSR_PIL, %l4
1940 wr %l4, PSR_ET, %psr
1944 add %sp, STACKFRAME_SZ, %o1 ! struct pt_regs *regs
1947 .globl pcic_nmi_trap_patch
1948 pcic_nmi_trap_patch:
1949 sethi %hi(linux_trap_ipi15_pcic), %l3
1950 jmpl %l3 + %lo(linux_trap_ipi15_pcic), %g0
1954 #endif /* CONFIG_PCI */
1956 /* End of entry.S */