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
1280 .globl sys_sigreturn
1283 add %sp, STACKFRAME_SZ, %o0
1285 ld [%curptr + TI_FLAGS], %l5
1286 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1294 /* We don't want to muck with user registers like a
1295 * normal syscall, just return.
1300 .globl sys_rt_sigreturn
1302 call do_rt_sigreturn
1303 add %sp, STACKFRAME_SZ, %o0
1305 ld [%curptr + TI_FLAGS], %l5
1306 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1314 /* We are returning to a signal handler. */
1317 /* Now that we have a real sys_clone, sys_fork() is
1318 * implemented in terms of it. Our _real_ implementation
1319 * of SunOS vfork() will use sys_vfork().
1321 * XXX These three should be consolidated into mostly shared
1322 * XXX code just like on sparc64... -DaveM
1325 .globl sys_fork, flush_patch_two
1329 FLUSH_ALL_KERNEL_WINDOWS;
1330 ld [%curptr + TI_TASK], %o4
1333 mov SIGCHLD, %o0 ! arg0: clone flags
1336 mov %fp, %o1 ! arg1: usp
1337 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1338 add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
1343 /* Whee, kernel threads! */
1344 .globl sys_clone, flush_patch_three
1348 FLUSH_ALL_KERNEL_WINDOWS;
1349 ld [%curptr + TI_TASK], %o4
1353 /* arg0,1: flags,usp -- loaded already */
1354 cmp %o1, 0x0 ! Is new_usp NULL?
1358 mov %fp, %o1 ! yes, use callers usp
1359 andn %o1, 7, %o1 ! no, align to 8 bytes
1361 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1362 add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
1367 /* Whee, real vfork! */
1368 .globl sys_vfork, flush_patch_four
1371 FLUSH_ALL_KERNEL_WINDOWS;
1372 ld [%curptr + TI_TASK], %o4
1377 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1378 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1380 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1381 sethi %hi(sparc_do_fork), %l1
1383 jmpl %l1 + %lo(sparc_do_fork), %g0
1384 add %sp, STACKFRAME_SZ, %o2
1387 linux_sparc_ni_syscall:
1388 sethi %hi(sys_ni_syscall), %l7
1389 b syscall_is_too_hard
1390 or %l7, %lo(sys_ni_syscall), %l7
1400 linux_syscall_trace:
1410 .globl ret_from_fork
1415 ld [%sp + STACKFRAME_SZ + PT_I0], %o0
1417 /* Linux native and SunOS system calls enter here... */
1419 .globl linux_sparc_syscall
1420 linux_sparc_syscall:
1421 /* Direct access to user regs, must faster. */
1422 cmp %g1, NR_SYSCALLS
1423 bgeu linux_sparc_ni_syscall
1427 bne linux_fast_syscall
1428 /* Just do first insn from SAVE_ALL in the delay slot */
1430 .globl syscall_is_too_hard
1431 syscall_is_too_hard:
1435 wr %l0, PSR_ET, %psr
1440 ld [%curptr + TI_FLAGS], %l5
1442 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1444 bne linux_syscall_trace
1450 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1454 ld [%curptr + TI_FLAGS], %l6
1455 cmp %o0, -ERESTART_RESTARTBLOCK
1456 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1459 andcc %l6, _TIF_SYSCALL_TRACE, %g0
1461 /* System call success, clear Carry condition code. */
1464 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1465 bne linux_syscall_trace2
1466 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1467 add %l1, 0x4, %l2 /* npc = npc+4 */
1468 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1470 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1472 /* System call failure, set Carry condition code.
1473 * Also, get abs(errno) to return to the process.
1477 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1479 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1480 bne linux_syscall_trace2
1481 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1482 add %l1, 0x4, %l2 /* npc = npc+4 */
1483 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1485 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1487 linux_syscall_trace2:
1489 add %l1, 0x4, %l2 /* npc = npc+4 */
1490 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1492 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1496 * Solaris system calls and indirect system calls enter here.
1498 * I have named the solaris indirect syscalls like that because
1499 * it seems like Solaris has some fast path syscalls that can
1500 * be handled as indirect system calls. - mig
1503 linux_syscall_for_solaris:
1504 sethi %hi(sys_call_table), %l7
1505 b linux_sparc_syscall
1506 or %l7, %lo(sys_call_table), %l7
1509 .globl solaris_syscall
1512 be linux_syscall_for_solaris
1514 be linux_syscall_for_solaris
1516 be linux_syscall_for_solaris
1518 be,a linux_syscall_for_solaris
1524 wr %l0, PSR_ET, %psr
1529 call do_solaris_syscall
1530 add %sp, STACKFRAME_SZ, %o0
1532 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1534 cmp %o0, -ERESTART_RESTARTBLOCK
1536 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1538 /* System call success, clear Carry condition code. */
1542 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1545 /* System call failure, set Carry condition code.
1546 * Also, get abs(errno) to return to the process.
1550 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1552 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1554 /* Advance the pc and npc over the trap instruction.
1555 * If the npc is unaligned (has a 1 in the lower byte), it means
1556 * the kernel does not want us to play magic (ie, skipping over
1557 * traps). Mainly when the Solaris code wants to set some PC and
1561 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1564 add %l1, 0x4, %l2 /* npc = npc+4 */
1565 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1567 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1569 /* kernel knows what it is doing, fixup npc and continue */
1573 st %l1, [%sp + STACKFRAME_SZ + PT_NPC]
1575 #ifndef CONFIG_SUNOS_EMUL
1577 .globl sunos_syscall
1581 wr %l0, PSR_ET, %psr
1585 call do_sunos_syscall
1586 add %sp, STACKFRAME_SZ, %o0
1589 /* {net, open}bsd system calls enter here... */
1593 /* Direct access to user regs, must faster. */
1594 cmp %g1, NR_SYSCALLS
1598 set sys_ni_syscall, %l7
1605 .globl bsd_is_too_hard
1610 wr %l0, PSR_ET, %psr
1623 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1625 cmp %o0, -ERESTART_RESTARTBLOCK
1627 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1629 /* System call success, clear Carry condition code. */
1633 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1636 /* System call failure, set Carry condition code.
1637 * Also, get abs(errno) to return to the process.
1640 #if 0 /* XXX todo XXX */
1641 sethi %hi(bsd_xlatb_rorl), %o3
1642 or %o3, %lo(bsd_xlatb_rorl), %o3
1647 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1649 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1651 /* Advance the pc and npc over the trap instruction. */
1653 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1654 add %l1, 0x4, %l2 /* npc = npc+4 */
1655 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1657 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1659 /* Saving and restoring the FPU state is best done from lowlevel code.
1661 * void fpsave(unsigned long *fpregs, unsigned long *fsr,
1662 * void *fpqueue, unsigned long *fpqdepth)
1667 st %fsr, [%o1] ! this can trap on us if fpu is in bogon state
1674 /* We have an fpqueue to save. */
1688 std %f0, [%o0 + 0x00]
1689 std %f2, [%o0 + 0x08]
1690 std %f4, [%o0 + 0x10]
1691 std %f6, [%o0 + 0x18]
1692 std %f8, [%o0 + 0x20]
1693 std %f10, [%o0 + 0x28]
1694 std %f12, [%o0 + 0x30]
1695 std %f14, [%o0 + 0x38]
1696 std %f16, [%o0 + 0x40]
1697 std %f18, [%o0 + 0x48]
1698 std %f20, [%o0 + 0x50]
1699 std %f22, [%o0 + 0x58]
1700 std %f24, [%o0 + 0x60]
1701 std %f26, [%o0 + 0x68]
1702 std %f28, [%o0 + 0x70]
1704 std %f30, [%o0 + 0x78]
1706 /* Thanks for Theo Deraadt and the authors of the Sprite/netbsd/openbsd
1707 * code for pointing out this possible deadlock, while we save state
1708 * above we could trap on the fsr store so our low level fpu trap
1709 * code has to know how to deal with this.
1719 /* void fpload(unsigned long *fpregs, unsigned long *fsr); */
1723 ldd [%o0 + 0x00], %f0
1724 ldd [%o0 + 0x08], %f2
1725 ldd [%o0 + 0x10], %f4
1726 ldd [%o0 + 0x18], %f6
1727 ldd [%o0 + 0x20], %f8
1728 ldd [%o0 + 0x28], %f10
1729 ldd [%o0 + 0x30], %f12
1730 ldd [%o0 + 0x38], %f14
1731 ldd [%o0 + 0x40], %f16
1732 ldd [%o0 + 0x48], %f18
1733 ldd [%o0 + 0x50], %f20
1734 ldd [%o0 + 0x58], %f22
1735 ldd [%o0 + 0x60], %f24
1736 ldd [%o0 + 0x68], %f26
1737 ldd [%o0 + 0x70], %f28
1738 ldd [%o0 + 0x78], %f30
1743 /* __ndelay and __udelay take two arguments:
1744 * 0 - nsecs or usecs to delay
1745 * 1 - per_cpu udelay_val (loops per jiffy)
1747 * Note that ndelay gives HZ times higher resolution but has a 10ms
1748 * limit. udelay can handle up to 1s.
1752 save %sp, -STACKFRAME_SZ, %sp
1755 mov 0x1ad, %o1 ! 2**32 / (1 000 000 000 / HZ)
1757 mov %i1, %o1 ! udelay_val
1759 mov %o1, %o0 ! >>32 later for better resolution
1763 save %sp, -STACKFRAME_SZ, %sp
1765 sethi %hi(0x10c6), %o1
1767 or %o1, %lo(0x10c6), %o1 ! 2**32 / 1 000 000
1769 mov %i1, %o1 ! udelay_val
1771 mov HZ, %o0 ! >>32 earlier for wider range
1782 /* Handle a software breakpoint */
1783 /* We have to inform parent that child has stopped */
1785 .globl breakpoint_trap
1789 wr %l0, PSR_ET, %psr
1792 st %i0, [%sp + STACKFRAME_SZ + PT_G0] ! for restarting syscalls
1793 call sparc_breakpoint
1794 add %sp, STACKFRAME_SZ, %o0
1799 .globl __handle_exception, flush_patch_exception
1801 flush_patch_exception:
1802 FLUSH_ALL_KERNEL_WINDOWS;
1804 jmpl %o7 + 0xc, %g0 ! see asm-sparc/processor.h
1805 mov 1, %g1 ! signal EFAULT condition
1808 .globl kill_user_windows, kuw_patch1_7win
1810 kuw_patch1_7win: sll %o3, 6, %o3
1812 /* No matter how much overhead this routine has in the worst
1813 * case scenerio, it is several times better than taking the
1814 * traps with the old method of just doing flush_user_windows().
1817 ld [%g6 + TI_UWINMASK], %o0 ! get current umask
1818 orcc %g0, %o0, %g0 ! if no bits set, we are done
1819 be 3f ! nothing to do
1820 rd %psr, %o5 ! must clear interrupts
1821 or %o5, PSR_PIL, %o4 ! or else that could change
1822 wr %o4, 0x0, %psr ! the uwinmask state
1823 WRITE_PAUSE ! burn them cycles
1825 ld [%g6 + TI_UWINMASK], %o0 ! get consistent state
1826 orcc %g0, %o0, %g0 ! did an interrupt come in?
1827 be 4f ! yep, we are done
1828 rd %wim, %o3 ! get current wim
1829 srl %o3, 1, %o4 ! simulate a save
1831 sll %o3, 7, %o3 ! compute next wim
1832 or %o4, %o3, %o3 ! result
1833 andncc %o0, %o3, %o0 ! clean this bit in umask
1834 bne kuw_patch1 ! not done yet
1835 srl %o3, 1, %o4 ! begin another save simulation
1836 wr %o3, 0x0, %wim ! set the new wim
1837 st %g0, [%g6 + TI_UWINMASK] ! clear uwinmask
1839 wr %o5, 0x0, %psr ! re-enable interrupts
1840 WRITE_PAUSE ! burn baby burn
1843 st %g0, [%g6 + TI_W_SAVED] ! no windows saved
1846 .globl restore_current
1848 LOAD_CURRENT(g6, o0)
1853 #include <asm/pcic.h>
1856 .globl linux_trap_ipi15_pcic
1857 linux_trap_ipi15_pcic:
1862 * First deactivate NMI
1863 * or we cannot drop ET, cannot get window spill traps.
1864 * The busy loop is necessary because the PIO error
1865 * sometimes does not go away quickly and we trap again.
1867 sethi %hi(pcic_regs), %o1
1868 ld [%o1 + %lo(pcic_regs)], %o2
1870 ! Get pending status for printouts later.
1871 ld [%o2 + PCI_SYS_INT_PENDING], %o0
1873 mov PCI_SYS_INT_PENDING_CLEAR_ALL, %o1
1874 stb %o1, [%o2 + PCI_SYS_INT_PENDING_CLEAR]
1876 ld [%o2 + PCI_SYS_INT_PENDING], %o1
1877 andcc %o1, ((PCI_SYS_INT_PENDING_PIO|PCI_SYS_INT_PENDING_PCI)>>24), %g0
1881 or %l0, PSR_PIL, %l4
1884 wr %l4, PSR_ET, %psr
1888 add %sp, STACKFRAME_SZ, %o1 ! struct pt_regs *regs
1891 .globl pcic_nmi_trap_patch
1892 pcic_nmi_trap_patch:
1893 sethi %hi(linux_trap_ipi15_pcic), %l3
1894 jmpl %l3 + %lo(linux_trap_ipi15_pcic), %g0
1898 #endif /* CONFIG_PCI */
1900 /* End of entry.S */