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>
36 #include <asm/asmmacro.h>
40 #define NR_SYSCALLS 300 /* Each OS is different... */
42 /* These are just handy. */
43 #define _SV save %sp, -STACKFRAME_SZ, %sp
46 #define FLUSH_ALL_KERNEL_WINDOWS \
47 _SV; _SV; _SV; _SV; _SV; _SV; _SV; \
48 _RS; _RS; _RS; _RS; _RS; _RS; _RS;
50 /* First, KGDB low level things. This is a rewrite
51 * of the routines found in the sparc-stub.c asm() statement
52 * from the gdb distribution. This is also dual-purpose
53 * as a software trap for userlevel programs.
64 #if 0 /* kgdb is dropped from 2.5.33 */
65 ! This function is called when any SPARC trap (except window overflow or
66 ! underflow) occurs. It makes sure that the invalid register window is still
67 ! available before jumping into C code. It will also restore the world if you
68 ! return from handle_exception.
75 sethi %hi(in_trap_handler), %l4
76 ld [%lo(in_trap_handler) + %l4], %l5
78 st %l5, [%lo(in_trap_handler) + %l4]
80 /* Make sure kgdb sees the same state we just saved. */
83 ld [%sp + STACKFRAME_SZ + PT_Y], %l4
84 ld [%sp + STACKFRAME_SZ + PT_WIM], %l3
85 ld [%sp + STACKFRAME_SZ + PT_PSR], %l0
86 ld [%sp + STACKFRAME_SZ + PT_PC], %l1
87 ld [%sp + STACKFRAME_SZ + PT_NPC], %l2
88 rd %tbr, %l5 /* Never changes... */
90 /* Make kgdb exception frame. */
91 sub %sp,(16+1+6+1+72)*4,%sp ! Make room for input & locals
92 ! + hidden arg + arg spill
93 ! + doubleword alignment
94 ! + registers[72] local var
97 SAVE_KGDB_SREGS(sp, l4, l0, l3, l5, l1, l2)
99 /* We are increasing PIL, so two writes. */
106 call handle_exception
107 add %sp, STACKFRAME_SZ, %o0 ! Pass address of registers
109 /* Load new kgdb register set. */
110 LOAD_KGDB_GLOBALS(sp)
112 LOAD_KGDB_SREGS(sp, l4, l0, l3, l5, l1, l2)
115 sethi %hi(in_trap_handler), %l4
116 ld [%lo(in_trap_handler) + %l4], %l5
118 st %l5, [%lo(in_trap_handler) + %l4]
120 add %sp,(16+1+6+1+72)*4,%sp ! Undo the kgdb trap frame.
122 /* Now take what kgdb did and place it into the pt_regs
123 * frame which SparcLinux RESTORE_ALL understands.,
127 STORE_PT_YREG(sp, g2)
128 STORE_PT_PRIV(sp, l0, l1, l2)
133 #ifdef CONFIG_BLK_DEV_FD
136 .globl floppy_hardint
139 * This code cannot touch registers %l0 %l1 and %l2
140 * because SAVE_ALL depends on their values. It depends
141 * on %l3 also, but we regenerate it before a call.
142 * Other registers are:
143 * %l3 -- base address of fdc registers
145 * %l5 -- scratch for ld/st address
147 * %l7 -- scratch [floppy byte, ld/st address, aux. data]
150 /* Do we have work to do? */
151 sethi %hi(doing_pdma), %l7
152 ld [%l7 + %lo(doing_pdma)], %l7
157 /* Load fdc register base */
158 sethi %hi(fdc_status), %l3
159 ld [%l3 + %lo(fdc_status)], %l3
161 /* Setup register addresses */
162 sethi %hi(pdma_vaddr), %l5 ! transfer buffer
163 ld [%l5 + %lo(pdma_vaddr)], %l4
164 sethi %hi(pdma_size), %l5 ! bytes to go
165 ld [%l5 + %lo(pdma_size)], %l6
169 andcc %l7, 0x80, %g0 ! Does fifo still have data
170 bz floppy_fifo_emptied ! fifo has been emptied...
171 andcc %l7, 0x20, %g0 ! in non-dma mode still?
172 bz floppy_overrun ! nope, overrun
173 andcc %l7, 0x40, %g0 ! 0=write 1=read
177 /* Ok, actually read this byte */
188 /* Ok, actually write this byte */
195 /* fall through... */
197 sethi %hi(pdma_vaddr), %l5
198 st %l4, [%l5 + %lo(pdma_vaddr)]
199 sethi %hi(pdma_size), %l5
200 st %l6, [%l5 + %lo(pdma_size)]
201 /* Flip terminal count pin */
202 set auxio_register, %l7
205 set sparc_cpu_model, %l5
207 subcc %l5, 1, %g0 /* enum { sun4c = 1 }; */
223 /* Kill some time so the bits set */
229 /* Prevent recursion */
230 sethi %hi(doing_pdma), %l7
232 st %g0, [%l7 + %lo(doing_pdma)]
234 /* We emptied the FIFO, but we haven't read everything
235 * as of yet. Store the current transfer address and
236 * bytes left to read so we can continue when the next
240 sethi %hi(pdma_vaddr), %l5
241 st %l4, [%l5 + %lo(pdma_vaddr)]
242 sethi %hi(pdma_size), %l7
243 st %l6, [%l7 + %lo(pdma_size)]
245 /* Restore condition codes */
253 sethi %hi(pdma_vaddr), %l5
254 st %l4, [%l5 + %lo(pdma_vaddr)]
255 sethi %hi(pdma_size), %l5
256 st %l6, [%l5 + %lo(pdma_size)]
257 /* Prevent recursion */
258 sethi %hi(doing_pdma), %l7
259 st %g0, [%l7 + %lo(doing_pdma)]
261 /* fall through... */
266 /* Set all IRQs off. */
273 mov 11, %o0 ! floppy irq level (unused anyway)
274 mov %g0, %o1 ! devid is not used in fast interrupts
275 call sparc_floppy_irq
276 add %sp, STACKFRAME_SZ, %o2 ! struct pt_regs *regs
280 #endif /* (CONFIG_BLK_DEV_FD) */
282 /* Bad trap handler */
283 .globl bad_trap_handler
290 add %sp, STACKFRAME_SZ, %o0 ! pt_regs
292 mov %l7, %o1 ! trap number
296 /* For now all IRQ's not registered get sent here. handler_irq() will
297 * see if a routine is registered to handle this interrupt and if not
298 * it will say so on the console.
302 .globl real_irq_entry, patch_handler_irq
307 .globl patchme_maybe_smp_msg
310 patchme_maybe_smp_msg:
321 mov %l7, %o0 ! irq level
324 add %sp, STACKFRAME_SZ, %o1 ! pt_regs ptr
325 or %l0, PSR_PIL, %g2 ! restore PIL after handler_irq
326 wr %g2, PSR_ET, %psr ! keep ET up
332 /* SMP per-cpu ticker interrupts are handled specially. */
334 bne real_irq_continue+4
340 call smp4m_percpu_timer_interrupt
341 add %sp, STACKFRAME_SZ, %o0
346 /* Here is where we check for possible SMP IPI passed to us
347 * on some level other than 15 which is the NMI and only used
348 * for cross calls. That has a separate entry point below.
351 GET_PROCESSOR4M_ID(o3)
352 set sun4m_interrupts, %l5
354 sethi %hi(0x40000000), %o2
369 call smp_reschedule_irq
375 .globl linux_trap_ipi15_sun4m
376 linux_trap_ipi15_sun4m:
378 sethi %hi(0x80000000), %o2
379 GET_PROCESSOR4M_ID(o0)
380 set sun4m_interrupts, %l5
386 be 1f ! Must be an NMI async memory error
396 call smp4m_cross_call_irq
398 b ret_trap_lockless_ipi
401 /* NMI async memory error handling. */
402 sethi %hi(0x80000000), %l4
403 sethi %hi(0x4000), %o3
424 /* SMP per-cpu ticker interrupts are handled specially. */
428 sethi %hi(CC_ICLR), %o0
429 sethi %hi(1 << 14), %o1
430 or %o0, %lo(CC_ICLR), %o0
431 stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 14 in MXCC's ICLR */
436 call smp4d_percpu_timer_interrupt
437 add %sp, STACKFRAME_SZ, %o0
443 .globl linux_trap_ipi15_sun4d
444 linux_trap_ipi15_sun4d:
446 sethi %hi(CC_BASE), %o4
447 sethi %hi(MXCC_ERR_ME|MXCC_ERR_PEW|MXCC_ERR_ASE|MXCC_ERR_PEE), %o2
448 or %o4, (CC_EREG - CC_BASE), %o0
449 ldda [%o0] ASI_M_MXCC, %o0
452 sethi %hi(BB_STAT2), %o2
453 lduba [%o2] ASI_M_CTL, %o2
454 andcc %o2, BB_STAT2_MASK, %g0
456 or %o4, (CC_ICLR - CC_BASE), %o0
457 sethi %hi(1 << 15), %o1
458 stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 15 in MXCC's ICLR */
464 call smp4d_cross_call_irq
466 b ret_trap_lockless_ipi
473 lduha [%l4] ASI_M_MXCC, %l5
474 sethi %hi(1 << 15), %l7
476 stha %l5, [%l4] ASI_M_MXCC
480 #endif /* CONFIG_SMP */
482 /* This routine handles illegal instructions and privileged
483 * instruction attempts from user code.
486 .globl bad_instruction
488 sethi %hi(0xc1f80000), %l4
490 sethi %hi(0x81d80000), %l7
496 wr %l0, PSR_ET, %psr ! re-enable traps
499 add %sp, STACKFRAME_SZ, %o0
502 call do_illegal_instruction
507 1: /* unimplemented flush - just skip */
512 .globl priv_instruction
519 add %sp, STACKFRAME_SZ, %o0
522 call do_priv_instruction
527 /* This routine handles unaligned data accesses. */
531 andcc %l0, PSR_PS, %g0
541 call kernel_unaligned_trap
542 add %sp, STACKFRAME_SZ, %o0
549 wr %l0, PSR_ET, %psr ! re-enable traps
553 call user_unaligned_trap
554 add %sp, STACKFRAME_SZ, %o0
558 /* This routine handles floating point disabled traps. */
560 .globl fpd_trap_handler
564 wr %l0, PSR_ET, %psr ! re-enable traps
567 add %sp, STACKFRAME_SZ, %o0
575 /* This routine handles Floating Point Exceptions. */
577 .globl fpe_trap_handler
579 set fpsave_magic, %l5
582 sethi %hi(fpsave), %l5
583 or %l5, %lo(fpsave), %l5
586 sethi %hi(fpsave_catch2), %l5
587 or %l5, %lo(fpsave_catch2), %l5
593 sethi %hi(fpsave_catch), %l5
594 or %l5, %lo(fpsave_catch), %l5
603 wr %l0, PSR_ET, %psr ! re-enable traps
606 add %sp, STACKFRAME_SZ, %o0
614 /* This routine handles Tag Overflow Exceptions. */
616 .globl do_tag_overflow
620 wr %l0, PSR_ET, %psr ! re-enable traps
623 add %sp, STACKFRAME_SZ, %o0
626 call handle_tag_overflow
631 /* This routine handles Watchpoint Exceptions. */
637 wr %l0, PSR_ET, %psr ! re-enable traps
640 add %sp, STACKFRAME_SZ, %o0
643 call handle_watchpoint
648 /* This routine handles Register Access Exceptions. */
654 wr %l0, PSR_ET, %psr ! re-enable traps
657 add %sp, STACKFRAME_SZ, %o0
660 call handle_reg_access
665 /* This routine handles Co-Processor Disabled Exceptions. */
667 .globl do_cp_disabled
671 wr %l0, PSR_ET, %psr ! re-enable traps
674 add %sp, STACKFRAME_SZ, %o0
677 call handle_cp_disabled
682 /* This routine handles Co-Processor Exceptions. */
684 .globl do_cp_exception
688 wr %l0, PSR_ET, %psr ! re-enable traps
691 add %sp, STACKFRAME_SZ, %o0
694 call handle_cp_exception
699 /* This routine handles Hardware Divide By Zero Exceptions. */
705 wr %l0, PSR_ET, %psr ! re-enable traps
708 add %sp, STACKFRAME_SZ, %o0
711 call handle_hw_divzero
717 .globl do_flush_windows
724 andcc %l0, PSR_PS, %g0
728 call flush_user_windows
731 /* Advance over the trap instruction. */
732 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1
734 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
735 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
739 .globl flush_patch_one
741 /* We get these for debugging routines using __builtin_return_address() */
744 FLUSH_ALL_KERNEL_WINDOWS
746 /* Advance over the trap instruction. */
747 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1
749 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
750 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
754 /* The getcc software trap. The user wants the condition codes from
755 * the %psr in register %g1.
759 .globl getcc_trap_handler
761 srl %l0, 20, %g1 ! give user
762 and %g1, 0xf, %g1 ! only ICC bits in %psr
763 jmp %l2 ! advance over trap instruction
764 rett %l2 + 0x4 ! like this...
766 /* The setcc software trap. The user has condition codes in %g1
767 * that it would like placed in the %psr. Be careful not to flip
768 * any unintentional bits!
772 .globl setcc_trap_handler
776 andn %l0, %l5, %l0 ! clear ICC bits in %psr
777 and %l4, %l5, %l4 ! clear non-ICC bits in user value
778 or %l4, %l0, %l4 ! or them in... mix mix mix
780 wr %l4, 0x0, %psr ! set new %psr
781 WRITE_PAUSE ! TI scumbags...
783 jmp %l2 ! advance over trap instruction
784 rett %l2 + 0x4 ! like this...
787 .globl linux_trap_nmi_sun4c
788 linux_trap_nmi_sun4c:
791 /* Ugh, we need to clear the IRQ line. This is now
792 * a very sun4c specific trap handler...
794 sethi %hi(interrupt_enable), %l5
795 ld [%l5 + %lo(interrupt_enable)], %l5
797 andn %l6, INTS_ENAB, %l6
800 /* Now it is safe to re-enable traps without recursion. */
805 /* Now call the c-code with the pt_regs frame ptr and the
806 * memory error registers as arguments. The ordering chosen
807 * here is due to unlatching semantics.
809 sethi %hi(AC_SYNC_ERR), %o0
811 lda [%o0] ASI_CONTROL, %o2 ! sync vaddr
813 lda [%o0] ASI_CONTROL, %o1 ! sync error
815 lda [%o0] ASI_CONTROL, %o4 ! async vaddr
817 lda [%o0] ASI_CONTROL, %o3 ! async error
819 add %sp, STACKFRAME_SZ, %o0
824 .globl invalid_segment_patch1_ff
825 .globl invalid_segment_patch2_ff
826 invalid_segment_patch1_ff: cmp %l4, 0xff
827 invalid_segment_patch2_ff: mov 0xff, %l3
830 .globl invalid_segment_patch1_1ff
831 .globl invalid_segment_patch2_1ff
832 invalid_segment_patch1_1ff: cmp %l4, 0x1ff
833 invalid_segment_patch2_1ff: mov 0x1ff, %l3
836 .globl num_context_patch1_16, num_context_patch2_16
837 num_context_patch1_16: mov 0x10, %l7
838 num_context_patch2_16: mov 0x10, %l7
841 .globl vac_linesize_patch_32
842 vac_linesize_patch_32: subcc %l7, 32, %l7
845 .globl vac_hwflush_patch1_on, vac_hwflush_patch2_on
848 * Ugly, but we cant use hardware flushing on the sun4 and we'd require
849 * two instructions (Anton)
852 vac_hwflush_patch1_on: nop
854 vac_hwflush_patch1_on: addcc %l7, -PAGE_SIZE, %l7
857 vac_hwflush_patch2_on: sta %g0, [%l3 + %l7] ASI_HWFLUSHSEG
859 .globl invalid_segment_patch1, invalid_segment_patch2
860 .globl num_context_patch1
861 .globl vac_linesize_patch, vac_hwflush_patch1
862 .globl vac_hwflush_patch2
871 ! %l7 = 1 for textfault
872 ! We want error in %l5, vaddr in %l6
875 sethi %hi(sun4c_memerr_reg), %l4
876 ld [%l4+%lo(sun4c_memerr_reg)], %l4 ! memerr ctrl reg addr
877 ld [%l4], %l6 ! memerr ctrl reg
878 ld [%l4 + 4], %l5 ! memerr vaddr reg
879 andcc %l6, 0x80, %g0 ! check for error type
880 st %g0, [%l4 + 4] ! clear the error
882 sethi %hi(AC_BUS_ERROR), %l4 ! bus err reg addr
884 call prom_halt ! something weird happened
885 ! what exactly did happen?
886 ! what should we do here?
888 0: or %l4, %lo(AC_BUS_ERROR), %l4 ! bus err reg addr
889 lduba [%l4] ASI_CONTROL, %l6 ! bus err reg
891 cmp %l7, 1 ! text fault?
895 ld [%l1], %l4 ! load instruction that caused fault
897 andcc %l4, 1, %g0 ! store instruction?
900 sethi %hi(SUN4C_SYNC_BADWRITE), %l4 ! yep
901 ! %lo(SUN4C_SYNC_BADWRITE) = 0
902 or %l4, %l6, %l6 ! set write bit to emulate sun4c
905 sethi %hi(AC_SYNC_ERR), %l4
906 add %l4, 0x4, %l6 ! AC_SYNC_VA in %l6
907 lda [%l6] ASI_CONTROL, %l5 ! Address
908 lda [%l4] ASI_CONTROL, %l6 ! Error, retained for a bit
911 andn %l5, 0xfff, %l5 ! Encode all info into l7
917 or %l4, %l7, %l7 ! l7 = [addr,write,txtfault]
919 andcc %l0, PSR_PS, %g0
920 be sun4c_fault_fromuser
921 andcc %l7, 1, %g0 ! Text fault?
924 sethi %hi(KERNBASE), %l4
930 blu sun4c_fault_fromuser
931 sethi %hi(~((1 << SUN4C_REAL_PGDIR_SHIFT) - 1)), %l4
933 /* If the kernel references a bum kernel pointer, or a pte which
934 * points to a non existant page in ram, we will run this code
935 * _forever_ and lock up the machine!!!!! So we must check for
936 * this condition, the AC_SYNC_ERR bits are what we must examine.
937 * Also a parity error would make this happen as well. So we just
938 * check that we are in fact servicing a tlb miss and not some
939 * other type of fault for the kernel.
942 be sun4c_fault_fromuser
945 /* Test for NULL pte_t * in vmalloc area. */
946 sethi %hi(VMALLOC_START), %l4
948 blu,a invalid_segment_patch1
949 lduXa [%l5] ASI_SEGMAP, %l4
951 sethi %hi(swapper_pg_dir), %l4
952 srl %l5, SUN4C_PGDIR_SHIFT, %l6
953 or %l4, %lo(swapper_pg_dir), %l4
957 sethi %hi(PAGE_MASK), %l6
960 andcc %l4, PAGE_MASK, %g0
962 be sun4c_fault_fromuser
963 lduXa [%l5] ASI_SEGMAP, %l4
965 invalid_segment_patch1:
968 sethi %hi(sun4c_kfree_ring), %l4
969 or %l4, %lo(sun4c_kfree_ring), %l4
971 deccc %l3 ! do we have a free entry?
972 bcs,a 2f ! no, unmap one.
973 sethi %hi(sun4c_kernel_ring), %l4
975 st %l3, [%l4 + 0x18] ! sun4c_kfree_ring.num_entries--
977 ld [%l4 + 0x00], %l6 ! entry = sun4c_kfree_ring.ringhd.next
978 st %l5, [%l6 + 0x08] ! entry->vaddr = address
980 ld [%l6 + 0x00], %l3 ! next = entry->next
981 ld [%l6 + 0x04], %l7 ! entry->prev
983 st %l7, [%l3 + 0x04] ! next->prev = entry->prev
984 st %l3, [%l7 + 0x00] ! entry->prev->next = next
986 sethi %hi(sun4c_kernel_ring), %l4
987 or %l4, %lo(sun4c_kernel_ring), %l4
988 ! head = &sun4c_kernel_ring.ringhd
990 ld [%l4 + 0x00], %l7 ! head->next
992 st %l4, [%l6 + 0x04] ! entry->prev = head
993 st %l7, [%l6 + 0x00] ! entry->next = head->next
994 st %l6, [%l7 + 0x04] ! head->next->prev = entry
996 st %l6, [%l4 + 0x00] ! head->next = entry
999 inc %l3 ! sun4c_kernel_ring.num_entries++
1000 st %l3, [%l4 + 0x18]
1002 ld [%l6 + 0x08], %l5
1005 or %l4, %lo(sun4c_kernel_ring), %l4
1006 ! head = &sun4c_kernel_ring.ringhd
1008 ld [%l4 + 0x04], %l6 ! entry = head->prev
1010 ld [%l6 + 0x08], %l3 ! tmp = entry->vaddr
1012 ! Flush segment from the cache.
1014 sethi %hi((128 * 1024)), %l7
1016 sethi %hi((64 * 1024)), %l7
1024 sta %g0, [%l3 + %l7] ASI_FLUSHSEG
1026 st %l5, [%l6 + 0x08] ! entry->vaddr = address
1028 ld [%l6 + 0x00], %l5 ! next = entry->next
1029 ld [%l6 + 0x04], %l7 ! entry->prev
1031 st %l7, [%l5 + 0x04] ! next->prev = entry->prev
1032 st %l5, [%l7 + 0x00] ! entry->prev->next = next
1033 st %l4, [%l6 + 0x04] ! entry->prev = head
1035 ld [%l4 + 0x00], %l7 ! head->next
1037 st %l7, [%l6 + 0x00] ! entry->next = head->next
1038 st %l6, [%l7 + 0x04] ! head->next->prev = entry
1039 st %l6, [%l4 + 0x00] ! head->next = entry
1041 mov %l3, %l5 ! address = tmp
1047 ld [%l6 + 0x08], %l4
1048 ldub [%l6 + 0x0c], %l3
1049 or %l4, %l3, %l4 ! encode new vaddr/pseg into l4
1051 sethi %hi(AC_CONTEXT), %l3
1052 lduba [%l3] ASI_CONTROL, %l6
1054 /* Invalidate old mapping, instantiate new mapping,
1055 * for each context. Registers l6/l7 are live across
1059 sethi %hi(AC_CONTEXT), %l3
1060 stba %l7, [%l3] ASI_CONTROL
1061 invalid_segment_patch2:
1063 stXa %l3, [%l5] ASI_SEGMAP
1064 andn %l4, 0x1ff, %l3
1066 stXa %l4, [%l3] ASI_SEGMAP
1068 sethi %hi(AC_CONTEXT), %l3
1069 stba %l6, [%l3] ASI_CONTROL
1071 andn %l4, 0x1ff, %l5
1074 sethi %hi(VMALLOC_START), %l4
1078 mov 1 << (SUN4C_REAL_PGDIR_SHIFT - PAGE_SHIFT), %l7
1080 sethi %hi(KERNBASE), %l6
1083 srl %l4, PAGE_SHIFT, %l4
1084 sethi %hi((SUN4C_PAGE_KERNEL & 0xf4000000)), %l3
1087 sethi %hi(PAGE_SIZE), %l4
1090 sta %l3, [%l5] ASI_PTE
1097 sethi %hi(sun4c_kernel_faults), %l4
1100 srl %l5, SUN4C_PGDIR_SHIFT, %l3
1101 sethi %hi(swapper_pg_dir), %l4
1102 or %l4, %lo(swapper_pg_dir), %l4
1106 and %l4, PAGE_MASK, %l4
1108 sethi %hi(PAGE_MASK), %l6
1112 srl %l5, (PAGE_SHIFT - 2), %l6
1113 and %l6, ((SUN4C_PTRS_PER_PTE - 1) << 2), %l6
1116 sethi %hi(PAGE_SIZE), %l4
1121 sta %l3, [%l5] ASI_PTE
1126 sethi %hi(sun4c_kernel_faults), %l4
1128 ld [%l4 + %lo(sun4c_kernel_faults)], %l3
1130 st %l3, [%l4 + %lo(sun4c_kernel_faults)]
1132 /* Restore condition codes */
1138 sun4c_fault_fromuser:
1142 mov %l7, %o1 ! Decode the info from %l7
1144 and %o1, 1, %o1 ! arg2 = text_faultp
1146 and %o2, 2, %o2 ! arg3 = writep
1147 andn %o3, 0xfff, %o3 ! arg4 = faulting address
1149 wr %l0, PSR_ET, %psr
1153 add %sp, STACKFRAME_SZ, %o0 ! arg1 = pt_regs ptr
1163 lda [%l5] ASI_M_MMUREGS, %l6 ! read sfar first
1164 lda [%l4] ASI_M_MMUREGS, %l5 ! read sfsr last
1166 andn %l6, 0xfff, %l6
1167 srl %l5, 6, %l5 ! and encode all info into l7
1172 or %l6, %l7, %l7 ! l7 = [addr,write,txtfault]
1178 and %o1, 1, %o1 ! arg2 = text_faultp
1180 and %o2, 2, %o2 ! arg3 = writep
1181 andn %o3, 0xfff, %o3 ! arg4 = faulting address
1183 wr %l0, PSR_ET, %psr
1187 add %sp, STACKFRAME_SZ, %o0 ! arg1 = pt_regs ptr
1191 #ifdef CONFIG_SUNOS_EMUL
1192 /* SunOS uses syscall zero as the 'indirect syscall' it looks
1193 * like indir_syscall(scall_num, arg0, arg1, arg2...); etc.
1194 * This is complete brain damage.
1199 cmp %o0, NR_SYSCALLS
1203 sethi %hi(sunos_nosys), %l6
1205 or %l6, %lo(sunos_nosys), %l6
1208 set sunos_sys_table, %l7
1222 .globl sys_nis_syscall
1225 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1226 call c_sys_nis_syscall
1233 add %sp, STACKFRAME_SZ, %o0
1235 ld [%curptr + TI_FLAGS], %l5
1236 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1250 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1258 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1263 .globl sys_sigaltstack
1275 call do_sys_sigstack
1279 .globl sys_sigreturn
1282 add %sp, STACKFRAME_SZ, %o0
1284 ld [%curptr + TI_FLAGS], %l5
1285 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1293 /* We don't want to muck with user registers like a
1294 * normal syscall, just return.
1299 .globl sys_rt_sigreturn
1301 call do_rt_sigreturn
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. */
1316 /* Now that we have a real sys_clone, sys_fork() is
1317 * implemented in terms of it. Our _real_ implementation
1318 * of SunOS vfork() will use sys_vfork().
1320 * XXX These three should be consolidated into mostly shared
1321 * XXX code just like on sparc64... -DaveM
1324 .globl sys_fork, flush_patch_two
1328 FLUSH_ALL_KERNEL_WINDOWS;
1329 ld [%curptr + TI_TASK], %o4
1332 mov SIGCHLD, %o0 ! arg0: clone flags
1335 mov %fp, %o1 ! arg1: usp
1336 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1337 add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
1342 /* Whee, kernel threads! */
1343 .globl sys_clone, flush_patch_three
1347 FLUSH_ALL_KERNEL_WINDOWS;
1348 ld [%curptr + TI_TASK], %o4
1352 /* arg0,1: flags,usp -- loaded already */
1353 cmp %o1, 0x0 ! Is new_usp NULL?
1357 mov %fp, %o1 ! yes, use callers usp
1358 andn %o1, 7, %o1 ! no, align to 8 bytes
1360 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1361 add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
1366 /* Whee, real vfork! */
1367 .globl sys_vfork, flush_patch_four
1370 FLUSH_ALL_KERNEL_WINDOWS;
1371 ld [%curptr + TI_TASK], %o4
1376 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1377 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1379 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1380 sethi %hi(sparc_do_fork), %l1
1382 jmpl %l1 + %lo(sparc_do_fork), %g0
1383 add %sp, STACKFRAME_SZ, %o2
1386 linux_sparc_ni_syscall:
1387 sethi %hi(sys_ni_syscall), %l7
1388 b syscall_is_too_hard
1389 or %l7, %lo(sys_ni_syscall), %l7
1399 linux_syscall_trace:
1409 .globl ret_from_fork
1414 ld [%sp + STACKFRAME_SZ + PT_I0], %o0
1416 /* Linux native and SunOS system calls enter here... */
1418 .globl linux_sparc_syscall
1419 linux_sparc_syscall:
1420 /* Direct access to user regs, must faster. */
1421 cmp %g1, NR_SYSCALLS
1422 bgeu linux_sparc_ni_syscall
1426 bne linux_fast_syscall
1427 /* Just do first insn from SAVE_ALL in the delay slot */
1429 .globl syscall_is_too_hard
1430 syscall_is_too_hard:
1434 wr %l0, PSR_ET, %psr
1439 ld [%curptr + TI_FLAGS], %l5
1441 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1443 bne linux_syscall_trace
1449 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1453 ld [%curptr + TI_FLAGS], %l6
1454 cmp %o0, -ERESTART_RESTARTBLOCK
1455 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1458 andcc %l6, _TIF_SYSCALL_TRACE, %g0
1460 /* System call success, clear Carry condition code. */
1463 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1464 bne linux_syscall_trace2
1465 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1466 add %l1, 0x4, %l2 /* npc = npc+4 */
1467 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1469 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1471 /* System call failure, set Carry condition code.
1472 * Also, get abs(errno) to return to the process.
1476 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1478 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1479 bne linux_syscall_trace2
1480 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1481 add %l1, 0x4, %l2 /* npc = npc+4 */
1482 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1484 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1486 linux_syscall_trace2:
1488 add %l1, 0x4, %l2 /* npc = npc+4 */
1489 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1491 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1495 * Solaris system calls and indirect system calls enter here.
1497 * I have named the solaris indirect syscalls like that because
1498 * it seems like Solaris has some fast path syscalls that can
1499 * be handled as indirect system calls. - mig
1502 linux_syscall_for_solaris:
1503 sethi %hi(sys_call_table), %l7
1504 b linux_sparc_syscall
1505 or %l7, %lo(sys_call_table), %l7
1508 .globl solaris_syscall
1511 be linux_syscall_for_solaris
1513 be linux_syscall_for_solaris
1515 be linux_syscall_for_solaris
1517 be,a linux_syscall_for_solaris
1523 wr %l0, PSR_ET, %psr
1528 call do_solaris_syscall
1529 add %sp, STACKFRAME_SZ, %o0
1531 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1533 cmp %o0, -ERESTART_RESTARTBLOCK
1535 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1537 /* System call success, clear Carry condition code. */
1541 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1544 /* System call failure, set Carry condition code.
1545 * Also, get abs(errno) to return to the process.
1549 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1551 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1553 /* Advance the pc and npc over the trap instruction.
1554 * If the npc is unaligned (has a 1 in the lower byte), it means
1555 * the kernel does not want us to play magic (ie, skipping over
1556 * traps). Mainly when the Solaris code wants to set some PC and
1560 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1563 add %l1, 0x4, %l2 /* npc = npc+4 */
1564 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1566 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1568 /* kernel knows what it is doing, fixup npc and continue */
1572 st %l1, [%sp + STACKFRAME_SZ + PT_NPC]
1574 #ifndef CONFIG_SUNOS_EMUL
1576 .globl sunos_syscall
1580 wr %l0, PSR_ET, %psr
1584 call do_sunos_syscall
1585 add %sp, STACKFRAME_SZ, %o0
1588 /* {net, open}bsd system calls enter here... */
1592 /* Direct access to user regs, must faster. */
1593 cmp %g1, NR_SYSCALLS
1597 set sys_ni_syscall, %l7
1604 .globl bsd_is_too_hard
1609 wr %l0, PSR_ET, %psr
1622 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1624 cmp %o0, -ERESTART_RESTARTBLOCK
1626 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1628 /* System call success, clear Carry condition code. */
1632 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1635 /* System call failure, set Carry condition code.
1636 * Also, get abs(errno) to return to the process.
1639 #if 0 /* XXX todo XXX */
1640 sethi %hi(bsd_xlatb_rorl), %o3
1641 or %o3, %lo(bsd_xlatb_rorl), %o3
1646 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1648 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1650 /* Advance the pc and npc over the trap instruction. */
1652 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1653 add %l1, 0x4, %l2 /* npc = npc+4 */
1654 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1656 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1658 /* Saving and restoring the FPU state is best done from lowlevel code.
1660 * void fpsave(unsigned long *fpregs, unsigned long *fsr,
1661 * void *fpqueue, unsigned long *fpqdepth)
1666 st %fsr, [%o1] ! this can trap on us if fpu is in bogon state
1673 /* We have an fpqueue to save. */
1687 std %f0, [%o0 + 0x00]
1688 std %f2, [%o0 + 0x08]
1689 std %f4, [%o0 + 0x10]
1690 std %f6, [%o0 + 0x18]
1691 std %f8, [%o0 + 0x20]
1692 std %f10, [%o0 + 0x28]
1693 std %f12, [%o0 + 0x30]
1694 std %f14, [%o0 + 0x38]
1695 std %f16, [%o0 + 0x40]
1696 std %f18, [%o0 + 0x48]
1697 std %f20, [%o0 + 0x50]
1698 std %f22, [%o0 + 0x58]
1699 std %f24, [%o0 + 0x60]
1700 std %f26, [%o0 + 0x68]
1701 std %f28, [%o0 + 0x70]
1703 std %f30, [%o0 + 0x78]
1705 /* Thanks for Theo Deraadt and the authors of the Sprite/netbsd/openbsd
1706 * code for pointing out this possible deadlock, while we save state
1707 * above we could trap on the fsr store so our low level fpu trap
1708 * code has to know how to deal with this.
1718 /* void fpload(unsigned long *fpregs, unsigned long *fsr); */
1722 ldd [%o0 + 0x00], %f0
1723 ldd [%o0 + 0x08], %f2
1724 ldd [%o0 + 0x10], %f4
1725 ldd [%o0 + 0x18], %f6
1726 ldd [%o0 + 0x20], %f8
1727 ldd [%o0 + 0x28], %f10
1728 ldd [%o0 + 0x30], %f12
1729 ldd [%o0 + 0x38], %f14
1730 ldd [%o0 + 0x40], %f16
1731 ldd [%o0 + 0x48], %f18
1732 ldd [%o0 + 0x50], %f20
1733 ldd [%o0 + 0x58], %f22
1734 ldd [%o0 + 0x60], %f24
1735 ldd [%o0 + 0x68], %f26
1736 ldd [%o0 + 0x70], %f28
1737 ldd [%o0 + 0x78], %f30
1742 /* __ndelay and __udelay take two arguments:
1743 * 0 - nsecs or usecs to delay
1744 * 1 - per_cpu udelay_val (loops per jiffy)
1746 * Note that ndelay gives HZ times higher resolution but has a 10ms
1747 * limit. udelay can handle up to 1s.
1751 save %sp, -STACKFRAME_SZ, %sp
1754 mov 0x1ad, %o1 ! 2**32 / (1 000 000 000 / HZ)
1756 mov %i1, %o1 ! udelay_val
1758 mov %o1, %o0 ! >>32 later for better resolution
1762 save %sp, -STACKFRAME_SZ, %sp
1764 sethi %hi(0x10c6), %o1
1766 or %o1, %lo(0x10c6), %o1 ! 2**32 / 1 000 000
1768 mov %i1, %o1 ! udelay_val
1770 mov HZ, %o0 ! >>32 earlier for wider range
1781 /* Handle a software breakpoint */
1782 /* We have to inform parent that child has stopped */
1784 .globl breakpoint_trap
1788 wr %l0, PSR_ET, %psr
1791 st %i0, [%sp + STACKFRAME_SZ + PT_G0] ! for restarting syscalls
1792 call sparc_breakpoint
1793 add %sp, STACKFRAME_SZ, %o0
1798 .globl __handle_exception, flush_patch_exception
1800 flush_patch_exception:
1801 FLUSH_ALL_KERNEL_WINDOWS;
1803 jmpl %o7 + 0xc, %g0 ! see asm-sparc/processor.h
1804 mov 1, %g1 ! signal EFAULT condition
1807 .globl kill_user_windows, kuw_patch1_7win
1809 kuw_patch1_7win: sll %o3, 6, %o3
1811 /* No matter how much overhead this routine has in the worst
1812 * case scenerio, it is several times better than taking the
1813 * traps with the old method of just doing flush_user_windows().
1816 ld [%g6 + TI_UWINMASK], %o0 ! get current umask
1817 orcc %g0, %o0, %g0 ! if no bits set, we are done
1818 be 3f ! nothing to do
1819 rd %psr, %o5 ! must clear interrupts
1820 or %o5, PSR_PIL, %o4 ! or else that could change
1821 wr %o4, 0x0, %psr ! the uwinmask state
1822 WRITE_PAUSE ! burn them cycles
1824 ld [%g6 + TI_UWINMASK], %o0 ! get consistent state
1825 orcc %g0, %o0, %g0 ! did an interrupt come in?
1826 be 4f ! yep, we are done
1827 rd %wim, %o3 ! get current wim
1828 srl %o3, 1, %o4 ! simulate a save
1830 sll %o3, 7, %o3 ! compute next wim
1831 or %o4, %o3, %o3 ! result
1832 andncc %o0, %o3, %o0 ! clean this bit in umask
1833 bne kuw_patch1 ! not done yet
1834 srl %o3, 1, %o4 ! begin another save simulation
1835 wr %o3, 0x0, %wim ! set the new wim
1836 st %g0, [%g6 + TI_UWINMASK] ! clear uwinmask
1838 wr %o5, 0x0, %psr ! re-enable interrupts
1839 WRITE_PAUSE ! burn baby burn
1842 st %g0, [%g6 + TI_W_SAVED] ! no windows saved
1845 .globl restore_current
1847 LOAD_CURRENT(g6, o0)
1852 #include <asm/pcic.h>
1855 .globl linux_trap_ipi15_pcic
1856 linux_trap_ipi15_pcic:
1861 * First deactivate NMI
1862 * or we cannot drop ET, cannot get window spill traps.
1863 * The busy loop is necessary because the PIO error
1864 * sometimes does not go away quickly and we trap again.
1866 sethi %hi(pcic_regs), %o1
1867 ld [%o1 + %lo(pcic_regs)], %o2
1869 ! Get pending status for printouts later.
1870 ld [%o2 + PCI_SYS_INT_PENDING], %o0
1872 mov PCI_SYS_INT_PENDING_CLEAR_ALL, %o1
1873 stb %o1, [%o2 + PCI_SYS_INT_PENDING_CLEAR]
1875 ld [%o2 + PCI_SYS_INT_PENDING], %o1
1876 andcc %o1, ((PCI_SYS_INT_PENDING_PIO|PCI_SYS_INT_PENDING_PCI)>>24), %g0
1880 or %l0, PSR_PIL, %l4
1883 wr %l4, PSR_ET, %psr
1887 add %sp, STACKFRAME_SZ, %o1 ! struct pt_regs *regs
1890 .globl pcic_nmi_trap_patch
1891 pcic_nmi_trap_patch:
1892 sethi %hi(linux_trap_ipi15_pcic), %l3
1893 jmpl %l3 + %lo(linux_trap_ipi15_pcic), %g0
1897 #endif /* CONFIG_PCI */
1899 /* End of entry.S */