1 /* $Id: entry.S,v 1.167 2000/09/06 00:45:00 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>
21 #include <asm/cprefix.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>
35 #include <asm/asmmacro.h>
39 #define NR_SYSCALLS 256 /* Each OS is different... */
41 /* First, KGDB low level things. This is a rewrite
42 * of the routines found in the sparc-stub.c asm() statement
43 * from the gdb distribution. This is also dual-purpose
44 * as a software trap for userlevel programs.
55 ! This function is called when any SPARC trap (except window overflow or
56 ! underflow) occurs. It makes sure that the invalid register window is still
57 ! available before jumping into C code. It will also restore the world if you
58 ! return from handle_exception.
60 .globl C_LABEL(trap_low)
65 sethi %hi(in_trap_handler), %l4
66 ld [%lo(in_trap_handler) + %l4], %l5
68 st %l5, [%lo(in_trap_handler) + %l4]
70 /* Make sure kgdb sees the same state we just saved. */
73 ld [%sp + REGWIN_SZ + PT_Y], %l4
74 ld [%sp + REGWIN_SZ + PT_WIM], %l3
75 ld [%sp + REGWIN_SZ + PT_PSR], %l0
76 ld [%sp + REGWIN_SZ + PT_PC], %l1
77 ld [%sp + REGWIN_SZ + PT_NPC], %l2
78 rd %tbr, %l5 /* Never changes... */
80 /* Make kgdb exception frame. */
81 sub %sp,(16+1+6+1+72)*4,%sp ! Make room for input & locals
82 ! + hidden arg + arg spill
83 ! + doubleword alignment
84 ! + registers[72] local var
87 SAVE_KGDB_SREGS(sp, l4, l0, l3, l5, l1, l2)
89 /* We are increasing PIL, so two writes. */
96 call C_LABEL(handle_exception)
97 add %sp, REGWIN_SZ, %o0 ! Pass address of registers
99 /* Load new kgdb register set. */
100 LOAD_KGDB_GLOBALS(sp)
102 LOAD_KGDB_SREGS(sp, l4, l0, l3, l5, l1, l2)
105 sethi %hi(in_trap_handler), %l4
106 ld [%lo(in_trap_handler) + %l4], %l5
108 st %l5, [%lo(in_trap_handler) + %l4]
110 add %sp,(16+1+6+1+72)*4,%sp ! Undo the kgdb trap frame.
112 /* Now take what kgdb did and place it into the pt_regs
113 * frame which SparcLinux RESTORE_ALL understands.,
117 STORE_PT_YREG(sp, g2)
118 STORE_PT_PRIV(sp, l0, l1, l2)
123 #ifdef CONFIG_BLK_DEV_FD
126 .globl C_LABEL(floppy_hardint)
127 C_LABEL(floppy_hardint):
129 * This code cannot touch registers %l0 %l1 and %l2
130 * because SAVE_ALL depends on their values. It depends
131 * on %l3 also, but we regenerate it before a call.
132 * Other registers are:
133 * %l3 -- base address of fdc registers
135 * %l5 -- scratch for ld/st address
137 * %l7 -- scratch [floppy byte, ld/st address, aux. data]
140 /* Do we have work to do? */
141 sethi %hi(C_LABEL(doing_pdma)), %l7
142 ld [%l7 + %lo(C_LABEL(doing_pdma))], %l7
147 /* Load fdc register base */
148 sethi %hi(C_LABEL(fdc_status)), %l3
149 ld [%l3 + %lo(C_LABEL(fdc_status))], %l3
151 /* Setup register addresses */
152 sethi %hi(C_LABEL(pdma_vaddr)), %l5 ! transfer buffer
153 ld [%l5 + %lo(C_LABEL(pdma_vaddr))], %l4
154 sethi %hi(C_LABEL(pdma_size)), %l5 ! bytes to go
155 ld [%l5 + %lo(C_LABEL(pdma_size))], %l6
159 andcc %l7, 0x80, %g0 ! Does fifo still have data
160 bz floppy_fifo_emptied ! fifo has been emptied...
161 andcc %l7, 0x20, %g0 ! in non-dma mode still?
162 bz floppy_overrun ! nope, overrun
163 andcc %l7, 0x40, %g0 ! 0=write 1=read
167 /* Ok, actually read this byte */
178 /* Ok, actually write this byte */
185 /* fall through... */
187 sethi %hi(C_LABEL(pdma_vaddr)), %l5
188 st %l4, [%l5 + %lo(C_LABEL(pdma_vaddr))]
189 sethi %hi(C_LABEL(pdma_size)), %l5
190 st %l6, [%l5 + %lo(C_LABEL(pdma_size))]
191 /* Flip terminal count pin */
192 set C_LABEL(auxio_register), %l7
195 set C_LABEL(sparc_cpu_model), %l5
197 subcc %l5, 1, %g0 /* enum { sun4c = 1 }; */
213 /* Kill some time so the bits set */
219 /* Prevent recursion */
220 sethi %hi(C_LABEL(doing_pdma)), %l7
222 st %g0, [%l7 + %lo(C_LABEL(doing_pdma))]
224 /* We emptied the FIFO, but we haven't read everything
225 * as of yet. Store the current transfer address and
226 * bytes left to read so we can continue when the next
230 sethi %hi(C_LABEL(pdma_vaddr)), %l5
231 st %l4, [%l5 + %lo(C_LABEL(pdma_vaddr))]
232 sethi %hi(C_LABEL(pdma_size)), %l7
233 st %l6, [%l7 + %lo(C_LABEL(pdma_size))]
235 /* Restore condition codes */
243 sethi %hi(C_LABEL(pdma_vaddr)), %l5
244 st %l4, [%l5 + %lo(C_LABEL(pdma_vaddr))]
245 sethi %hi(C_LABEL(pdma_size)), %l5
246 st %l6, [%l5 + %lo(C_LABEL(pdma_size))]
247 /* Prevent recursion */
248 sethi %hi(C_LABEL(doing_pdma)), %l7
249 st %g0, [%l7 + %lo(C_LABEL(doing_pdma))]
251 /* fall through... */
256 /* Set all IRQs off. */
263 mov 11, %o0 ! floppy irq level (unused anyway)
264 mov %g0, %o1 ! devid is not used in fast interrupts
265 call C_LABEL(sparc_floppy_irq)
266 add %sp, REGWIN_SZ, %o2 ! struct pt_regs *regs
270 #endif /* (CONFIG_BLK_DEV_FD) */
272 /* Bad trap handler */
273 .globl bad_trap_handler
280 mov %l7, %o0 ! trap number
282 call C_LABEL(do_hw_interrupt)
287 /* For now all IRQ's not registered get sent here. handler_irq() will
288 * see if a routine is registered to handle this interrupt and if not
289 * it will say so on the console.
293 .globl real_irq_entry, patch_handler_irq
298 .globl patchme_maybe_smp_msg
301 patchme_maybe_smp_msg:
312 mov %l7, %o0 ! irq level
314 call C_LABEL(handler_irq)
315 add %sp, REGWIN_SZ, %o1 ! pt_regs ptr
316 or %l0, PSR_PIL, %g2 ! restore PIL after handler_irq
317 wr %g2, PSR_ET, %psr ! keep ET up
323 /* SMP per-cpu ticker interrupts are handled specially. */
325 bne real_irq_continue+4
331 call C_LABEL(smp4m_percpu_timer_interrupt)
332 add %sp, REGWIN_SZ, %o0
337 /* Here is where we check for possible SMP IPI passed to us
338 * on some level other than 15 which is the NMI and only used
339 * for cross calls. That has a separate entry point below.
342 GET_PROCESSOR_MID(o3, o2)
343 set C_LABEL(sun4m_interrupts), %l5
345 sethi %hi(0x60000000), %o4
354 sethi %hi(0x40000000), %o2
355 sethi %hi(0x20000000), %o2
369 call C_LABEL(smp_reschedule_irq)
372 call C_LABEL(smp_stop_cpu_irq)
377 .globl linux_trap_ipi15_sun4m
378 linux_trap_ipi15_sun4m:
380 sethi %hi(0x80000000), %o2
381 GET_PROCESSOR_MID(o0, o1)
382 set C_LABEL(sun4m_interrupts), %l5
388 be 1f ! Must be an NMI async memory error
398 call C_LABEL(smp4m_cross_call_irq)
400 b ret_trap_lockless_ipi
403 /* NMI async memory error handling. */
404 sethi %hi(0x80000000), %l4
405 sethi %hi(0x4000), %o3
417 call C_LABEL(sun4m_nmi)
426 /* SMP per-cpu ticker interrupts are handled specially. */
430 sethi %hi(CC_ICLR), %o0
431 sethi %hi(1 << 14), %o1
432 or %o0, %lo(CC_ICLR), %o0
433 stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 14 in MXCC's ICLR */
438 call C_LABEL(smp4d_percpu_timer_interrupt)
439 add %sp, REGWIN_SZ, %o0
445 .globl linux_trap_ipi15_sun4d
446 linux_trap_ipi15_sun4d:
448 sethi %hi(CC_BASE), %o4
449 sethi %hi(MXCC_ERR_ME|MXCC_ERR_PEW|MXCC_ERR_ASE|MXCC_ERR_PEE), %o2
450 or %o4, (CC_EREG - CC_BASE), %o0
451 ldda [%o0] ASI_M_MXCC, %o0
454 sethi %hi(BB_STAT2), %o2
455 lduba [%o2] ASI_M_CTL, %o2
456 andcc %o2, BB_STAT2_MASK, %g0
458 or %o4, (CC_ICLR - CC_BASE), %o0
459 sethi %hi(1 << 15), %o1
460 stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 15 in MXCC's ICLR */
466 call C_LABEL(smp4d_cross_call_irq)
468 b ret_trap_lockless_ipi
475 lduha [%l4] ASI_M_MXCC, %l5
476 sethi %hi(1 << 15), %l7
478 stha %l5, [%l4] ASI_M_MXCC
482 #endif /* CONFIG_SMP */
484 /* This routine handles illegal instructions and privileged
485 * instruction attempts from user code.
488 .globl bad_instruction
490 sethi %hi(0xc1f80000), %l4
492 sethi %hi(0x81d80000), %l7
498 wr %l0, PSR_ET, %psr ! re-enable traps
501 add %sp, REGWIN_SZ, %o0
504 call C_LABEL(do_illegal_instruction)
509 1: /* unimplemented flush - just skip */
514 .globl priv_instruction
521 add %sp, REGWIN_SZ, %o0
524 call C_LABEL(do_priv_instruction)
529 /* This routine handles unaligned data accesses. */
533 andcc %l0, PSR_PS, %g0
543 call C_LABEL(kernel_unaligned_trap)
544 add %sp, REGWIN_SZ, %o0
551 wr %l0, PSR_ET, %psr ! re-enable traps
555 call C_LABEL(user_unaligned_trap)
556 add %sp, REGWIN_SZ, %o0
560 /* This routine handles floating point disabled traps. */
562 .globl fpd_trap_handler
566 wr %l0, PSR_ET, %psr ! re-enable traps
569 add %sp, REGWIN_SZ, %o0
572 call C_LABEL(do_fpd_trap)
577 /* This routine handles Floating Point Exceptions. */
579 .globl fpe_trap_handler
581 set fpsave_magic, %l5
584 sethi %hi(C_LABEL(fpsave)), %l5
585 or %l5, %lo(C_LABEL(fpsave)), %l5
588 sethi %hi(fpsave_catch2), %l5
589 or %l5, %lo(fpsave_catch2), %l5
595 sethi %hi(fpsave_catch), %l5
596 or %l5, %lo(fpsave_catch), %l5
605 wr %l0, PSR_ET, %psr ! re-enable traps
608 add %sp, REGWIN_SZ, %o0
611 call C_LABEL(do_fpe_trap)
616 /* This routine handles Tag Overflow Exceptions. */
618 .globl do_tag_overflow
622 wr %l0, PSR_ET, %psr ! re-enable traps
625 add %sp, REGWIN_SZ, %o0
628 call C_LABEL(handle_tag_overflow)
633 /* This routine handles Watchpoint Exceptions. */
639 wr %l0, PSR_ET, %psr ! re-enable traps
642 add %sp, REGWIN_SZ, %o0
645 call C_LABEL(handle_watchpoint)
650 /* This routine handles Register Access Exceptions. */
656 wr %l0, PSR_ET, %psr ! re-enable traps
659 add %sp, REGWIN_SZ, %o0
662 call C_LABEL(handle_reg_access)
667 /* This routine handles Co-Processor Disabled Exceptions. */
669 .globl do_cp_disabled
673 wr %l0, PSR_ET, %psr ! re-enable traps
676 add %sp, REGWIN_SZ, %o0
679 call C_LABEL(handle_cp_disabled)
684 /* This routine handles Co-Processor Exceptions. */
686 .globl do_cp_exception
690 wr %l0, PSR_ET, %psr ! re-enable traps
693 add %sp, REGWIN_SZ, %o0
696 call C_LABEL(handle_cp_exception)
701 /* This routine handles Hardware Divide By Zero Exceptions. */
707 wr %l0, PSR_ET, %psr ! re-enable traps
710 add %sp, REGWIN_SZ, %o0
713 call C_LABEL(handle_hw_divzero)
719 .globl do_flush_windows
726 andcc %l0, PSR_PS, %g0
730 call C_LABEL(flush_user_windows)
733 /* Advance over the trap instruction. */
734 ld [%sp + REGWIN_SZ + PT_NPC], %l1
736 st %l1, [%sp + REGWIN_SZ + PT_PC]
737 st %l2, [%sp + REGWIN_SZ + PT_NPC]
741 .globl flush_patch_one
743 /* We get these for debugging routines using __builtin_return_address() */
746 FLUSH_ALL_KERNEL_WINDOWS
748 /* Advance over the trap instruction. */
749 ld [%sp + REGWIN_SZ + PT_NPC], %l1
751 st %l1, [%sp + REGWIN_SZ + PT_PC]
752 st %l2, [%sp + REGWIN_SZ + PT_NPC]
756 /* The getcc software trap. The user wants the condition codes from
757 * the %psr in register %g1.
761 .globl getcc_trap_handler
763 srl %l0, 20, %g1 ! give user
764 and %g1, 0xf, %g1 ! only ICC bits in %psr
765 jmp %l2 ! advance over trap instruction
766 rett %l2 + 0x4 ! like this...
768 /* The setcc software trap. The user has condition codes in %g1
769 * that it would like placed in the %psr. Be careful not to flip
770 * any unintentional bits!
774 .globl setcc_trap_handler
778 andn %l0, %l5, %l0 ! clear ICC bits in %psr
779 and %l4, %l5, %l4 ! clear non-ICC bits in user value
780 or %l4, %l0, %l4 ! or them in... mix mix mix
782 wr %l4, 0x0, %psr ! set new %psr
783 WRITE_PAUSE ! TI scumbags...
785 jmp %l2 ! advance over trap instruction
786 rett %l2 + 0x4 ! like this...
789 .globl linux_trap_nmi_sun4c
790 linux_trap_nmi_sun4c:
793 /* Ugh, we need to clear the IRQ line. This is now
794 * a very sun4c specific trap handler...
796 sethi %hi(C_LABEL(interrupt_enable)), %l5
797 ld [%l5 + %lo(C_LABEL(interrupt_enable))], %l5
799 andn %l6, INTS_ENAB, %l6
802 /* Now it is safe to re-enable traps without recursion. */
807 /* Now call the c-code with the pt_regs frame ptr and the
808 * memory error registers as arguments. The ordering chosen
809 * here is due to unlatching semantics.
811 sethi %hi(AC_SYNC_ERR), %o0
813 lda [%o0] ASI_CONTROL, %o2 ! sync vaddr
815 lda [%o0] ASI_CONTROL, %o1 ! sync error
817 lda [%o0] ASI_CONTROL, %o4 ! async vaddr
819 lda [%o0] ASI_CONTROL, %o3 ! async error
820 call C_LABEL(sparc_lvl15_nmi)
821 add %sp, REGWIN_SZ, %o0
826 .globl C_LABEL(invalid_segment_patch1_ff)
827 .globl C_LABEL(invalid_segment_patch2_ff)
828 C_LABEL(invalid_segment_patch1_ff): cmp %l4, 0xff
829 C_LABEL(invalid_segment_patch2_ff): mov 0xff, %l3
832 .globl C_LABEL(invalid_segment_patch1_1ff)
833 .globl C_LABEL(invalid_segment_patch2_1ff)
834 C_LABEL(invalid_segment_patch1_1ff): cmp %l4, 0x1ff
835 C_LABEL(invalid_segment_patch2_1ff): mov 0x1ff, %l3
838 .globl C_LABEL(num_context_patch1_16), C_LABEL(num_context_patch2_16)
839 C_LABEL(num_context_patch1_16): mov 0x10, %l7
840 C_LABEL(num_context_patch2_16): mov 0x10, %l7
843 .globl C_LABEL(vac_linesize_patch_32)
844 C_LABEL(vac_linesize_patch_32): subcc %l7, 32, %l7
847 .globl C_LABEL(vac_hwflush_patch1_on), C_LABEL(vac_hwflush_patch2_on)
850 * Ugly, but we cant use hardware flushing on the sun4 and we'd require
851 * two instructions (Anton)
854 C_LABEL(vac_hwflush_patch1_on): nop
856 C_LABEL(vac_hwflush_patch1_on): addcc %l7, -PAGE_SIZE, %l7
859 C_LABEL(vac_hwflush_patch2_on): sta %g0, [%l3 + %l7] ASI_HWFLUSHSEG
861 .globl C_LABEL(invalid_segment_patch1), C_LABEL(invalid_segment_patch2)
862 .globl C_LABEL(num_context_patch1), C_LABEL(num_context_patch2)
863 .globl C_LABEL(vac_linesize_patch), C_LABEL(vac_hwflush_patch1)
864 .globl C_LABEL(vac_hwflush_patch2)
873 ! %l7 = 1 for textfault
874 ! We want error in %l5, vaddr in %l6
877 sethi %hi(C_LABEL(sun4c_memerr_reg)), %l4
878 ld [%l4+%lo(C_LABEL(sun4c_memerr_reg))], %l4 ! memerr ctrl reg addr
879 ld [%l4], %l6 ! memerr ctrl reg
880 ld [%l4 + 4], %l5 ! memerr vaddr reg
881 andcc %l6, 0x80, %g0 ! check for error type
882 st %g0, [%l4 + 4] ! clear the error
884 sethi %hi(AC_BUS_ERROR), %l4 ! bus err reg addr
886 call C_LABEL(prom_halt) ! something weird happened
887 ! what exactly did happen?
888 ! what should we do here?
890 0: or %l4, %lo(AC_BUS_ERROR), %l4 ! bus err reg addr
891 lduba [%l4] ASI_CONTROL, %l6 ! bus err reg
893 cmp %l7, 1 ! text fault?
897 ld [%l1], %l4 ! load instruction that caused fault
899 andcc %l4, 1, %g0 ! store instruction?
902 sethi %hi(SUN4C_SYNC_BADWRITE), %l4 ! yep
903 ! %lo(SUN4C_SYNC_BADWRITE) = 0
904 or %l4, %l6, %l6 ! set write bit to emulate sun4c
907 sethi %hi(AC_SYNC_ERR), %l4
908 add %l4, 0x4, %l6 ! AC_SYNC_VA in %l6
909 lda [%l6] ASI_CONTROL, %l5 ! Address
910 lda [%l4] ASI_CONTROL, %l6 ! Error, retained for a bit
913 andn %l5, 0xfff, %l5 ! Encode all info into l7
919 or %l4, %l7, %l7 ! l7 = [addr,write,txtfault]
921 andcc %l0, PSR_PS, %g0
922 be sun4c_fault_fromuser
923 andcc %l7, 1, %g0 ! Text fault?
926 sethi %hi(KERNBASE), %l4
932 blu sun4c_fault_fromuser
933 sethi %hi(~((1 << SUN4C_REAL_PGDIR_SHIFT) - 1)), %l4
935 /* If the kernel references a bum kernel pointer, or a pte which
936 * points to a non existant page in ram, we will run this code
937 * _forever_ and lock up the machine!!!!! So we must check for
938 * this condition, the AC_SYNC_ERR bits are what we must examine.
939 * Also a parity error would make this happen as well. So we just
940 * check that we are in fact servicing a tlb miss and not some
941 * other type of fault for the kernel.
944 be sun4c_fault_fromuser
947 /* Test for NULL pte_t * in vmalloc area. */
948 sethi %hi(VMALLOC_START), %l4
950 blu,a C_LABEL(invalid_segment_patch1)
951 lduXa [%l5] ASI_SEGMAP, %l4
953 sethi %hi(C_LABEL(swapper_pg_dir)), %l4
954 srl %l5, SUN4C_PGDIR_SHIFT, %l6
955 or %l4, %lo(C_LABEL(swapper_pg_dir)), %l4
959 sethi %hi(PAGE_MASK), %l6
962 andcc %l4, PAGE_MASK, %g0
964 be sun4c_fault_fromuser
965 lduXa [%l5] ASI_SEGMAP, %l4
967 C_LABEL(invalid_segment_patch1):
970 sethi %hi(C_LABEL(sun4c_kfree_ring)), %l4
971 or %l4, %lo(C_LABEL(sun4c_kfree_ring)), %l4
973 deccc %l3 ! do we have a free entry?
974 bcs,a 2f ! no, unmap one.
975 sethi %hi(C_LABEL(sun4c_kernel_ring)), %l4
977 st %l3, [%l4 + 0x18] ! sun4c_kfree_ring.num_entries--
979 ld [%l4 + 0x00], %l6 ! entry = sun4c_kfree_ring.ringhd.next
980 st %l5, [%l6 + 0x08] ! entry->vaddr = address
982 ld [%l6 + 0x00], %l3 ! next = entry->next
983 ld [%l6 + 0x04], %l7 ! entry->prev
985 st %l7, [%l3 + 0x04] ! next->prev = entry->prev
986 st %l3, [%l7 + 0x00] ! entry->prev->next = next
988 sethi %hi(C_LABEL(sun4c_kernel_ring)), %l4
989 or %l4, %lo(C_LABEL(sun4c_kernel_ring)), %l4
990 ! head = &sun4c_kernel_ring.ringhd
992 ld [%l4 + 0x00], %l7 ! head->next
994 st %l4, [%l6 + 0x04] ! entry->prev = head
995 st %l7, [%l6 + 0x00] ! entry->next = head->next
996 st %l6, [%l7 + 0x04] ! head->next->prev = entry
998 st %l6, [%l4 + 0x00] ! head->next = entry
1000 ld [%l4 + 0x18], %l3
1001 inc %l3 ! sun4c_kernel_ring.num_entries++
1003 ld [%l6 + 0x08], %l5
1006 or %l4, %lo(C_LABEL(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
1020 C_LABEL(vac_hwflush_patch1):
1021 C_LABEL(vac_linesize_patch):
1024 C_LABEL(vac_hwflush_patch2):
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
1045 C_LABEL(num_context_patch1):
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 C_LABEL(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(C_LABEL(sun4c_kernel_faults)), %l4
1101 srl %l5, SUN4C_PGDIR_SHIFT, %l3
1102 sethi %hi(C_LABEL(swapper_pg_dir)), %l4
1103 or %l4, %lo(C_LABEL(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(C_LABEL(sun4c_kernel_faults)), %l4
1129 ld [%l4 + %lo(C_LABEL(sun4c_kernel_faults))], %l3
1131 st %l3, [%l4 + %lo(C_LABEL(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
1153 call C_LABEL(do_sun4c_fault)
1154 add %sp, REGWIN_SZ, %o0 ! arg1 = pt_regs ptr
1159 .globl C_LABEL(srmmu_fault)
1160 C_LABEL(srmmu_fault):
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
1187 call C_LABEL(do_sparc_fault)
1188 add %sp, REGWIN_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.
1197 .globl C_LABEL(sunos_indir)
1198 C_LABEL(sunos_indir):
1200 cmp %o0, NR_SYSCALLS
1204 sethi %hi(C_LABEL(sunos_nosys)), %l6
1206 or %l6, %lo(C_LABEL(sunos_nosys)), %l6
1209 set C_LABEL(sunos_sys_table), %l7
1223 .globl C_LABEL(sys_nis_syscall)
1224 C_LABEL(sys_nis_syscall):
1226 add %sp, REGWIN_SZ, %o0 ! pt_regs *regs arg
1227 call C_LABEL(c_sys_nis_syscall)
1231 .globl C_LABEL(sys_ptrace)
1232 C_LABEL(sys_ptrace):
1233 call C_LABEL(do_ptrace)
1234 add %sp, REGWIN_SZ, %o0
1236 ld [%curptr + AOFF_task_ptrace], %l5
1237 andcc %l5, 0x02, %g0
1241 call C_LABEL(syscall_trace)
1248 .globl C_LABEL(sys_execve)
1249 C_LABEL(sys_execve):
1251 add %sp, REGWIN_SZ, %o0 ! pt_regs *regs arg
1252 call C_LABEL(sparc_execve)
1256 .globl C_LABEL(sys_pipe)
1259 add %sp, REGWIN_SZ, %o0 ! pt_regs *regs arg
1260 call C_LABEL(sparc_pipe)
1264 .globl C_LABEL(sys_sigaltstack)
1265 C_LABEL(sys_sigaltstack):
1268 call C_LABEL(do_sigaltstack)
1272 .globl C_LABEL(sys_sigstack)
1273 C_LABEL(sys_sigstack):
1276 call C_LABEL(do_sys_sigstack)
1280 .globl C_LABEL(sys_sigpause)
1281 C_LABEL(sys_sigpause):
1282 /* Note: %o0 already has correct value... */
1283 call C_LABEL(do_sigpause)
1284 add %sp, REGWIN_SZ, %o1
1286 ld [%curptr + AOFF_task_ptrace], %l5
1287 andcc %l5, 0x02, %g0
1291 call C_LABEL(syscall_trace)
1295 /* We are returning to a signal handler. */
1299 .globl C_LABEL(sys_sigsuspend)
1300 C_LABEL(sys_sigsuspend):
1301 call C_LABEL(do_sigsuspend)
1302 add %sp, REGWIN_SZ, %o0
1304 ld [%curptr + AOFF_task_ptrace], %l5
1305 andcc %l5, 0x02, %g0
1309 call C_LABEL(syscall_trace)
1313 /* We are returning to a signal handler. */
1317 .globl C_LABEL(sys_rt_sigsuspend)
1318 C_LABEL(sys_rt_sigsuspend):
1319 /* Note: %o0, %o1 already have correct value... */
1320 call C_LABEL(do_rt_sigsuspend)
1321 add %sp, REGWIN_SZ, %o2
1323 ld [%curptr + AOFF_task_ptrace], %l5
1324 andcc %l5, 0x02, %g0
1328 call C_LABEL(syscall_trace)
1332 /* We are returning to a signal handler. */
1336 .globl C_LABEL(sys_sigreturn)
1337 C_LABEL(sys_sigreturn):
1338 call C_LABEL(do_sigreturn)
1339 add %sp, REGWIN_SZ, %o0
1341 ld [%curptr + AOFF_task_ptrace], %l5
1342 andcc %l5, 0x02, %g0
1346 call C_LABEL(syscall_trace)
1350 /* We don't want to muck with user registers like a
1351 * normal syscall, just return.
1356 .globl C_LABEL(sys_rt_sigreturn)
1357 C_LABEL(sys_rt_sigreturn):
1358 call C_LABEL(do_rt_sigreturn)
1359 add %sp, REGWIN_SZ, %o0
1361 ld [%curptr + AOFF_task_ptrace], %l5
1362 andcc %l5, 0x02, %g0
1366 call C_LABEL(syscall_trace)
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 C_LABEL(sys_fork), flush_patch_two
1385 FLUSH_ALL_KERNEL_WINDOWS;
1388 mov SIGCHLD, %o0 ! arg0: clone flags
1391 mov %fp, %o1 ! arg1: usp
1392 std %g4, [%curptr + AOFF_task_thread + AOFF_thread_fork_kpsr]
1393 add %sp, REGWIN_SZ, %o2 ! arg2: pt_regs ptr
1395 call C_LABEL(do_fork)
1398 /* Whee, kernel threads! */
1399 .globl C_LABEL(sys_clone), flush_patch_three
1403 FLUSH_ALL_KERNEL_WINDOWS;
1407 /* arg0,1: flags,usp -- loaded already */
1408 cmp %o1, 0x0 ! Is new_usp NULL?
1412 mov %fp, %o1 ! yes, use callers usp
1413 andn %o1, 7, %o1 ! no, align to 8 bytes
1415 std %g4, [%curptr + AOFF_task_thread + AOFF_thread_fork_kpsr]
1416 add %sp, REGWIN_SZ, %o2 ! arg2: pt_regs ptr
1418 call C_LABEL(do_fork)
1421 /* Whee, real vfork! */
1422 .globl C_LABEL(sys_vfork), flush_patch_four
1425 FLUSH_ALL_KERNEL_WINDOWS;
1430 std %g4, [%curptr + AOFF_task_thread + AOFF_thread_fork_kpsr]
1431 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1433 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1434 sethi %hi(C_LABEL(do_fork)), %l1
1436 jmpl %l1 + %lo(C_LABEL(do_fork)), %g0
1437 add %sp, REGWIN_SZ, %o2
1440 linux_sparc_ni_syscall:
1441 sethi %hi(C_LABEL(sys_ni_syscall)), %l7
1442 b syscall_is_too_hard
1443 or %l7, %lo(C_LABEL(sys_ni_syscall)), %l7
1453 linux_syscall_trace:
1454 call C_LABEL(syscall_trace)
1463 .globl C_LABEL(ret_from_syscall)
1464 C_LABEL(ret_from_syscall):
1465 b C_LABEL(ret_sys_call)
1466 ld [%sp + REGWIN_SZ + PT_I0], %o0
1469 .globl C_LABEL(ret_from_smpfork)
1470 C_LABEL(ret_from_smpfork):
1471 wr %l0, PSR_ET, %psr
1475 b C_LABEL(ret_sys_call)
1476 ld [%sp + REGWIN_SZ + PT_I0], %o0
1479 /* Linux native and SunOS system calls enter here... */
1481 .globl linux_sparc_syscall
1482 linux_sparc_syscall:
1483 /* Direct access to user regs, must faster. */
1484 cmp %g1, NR_SYSCALLS
1485 bgeu linux_sparc_ni_syscall
1489 bne linux_fast_syscall
1490 /* Just do first insn from SAVE_ALL in the delay slot */
1492 .globl syscall_is_too_hard
1493 syscall_is_too_hard:
1497 wr %l0, PSR_ET, %psr
1502 ld [%curptr + AOFF_task_ptrace], %l5
1504 andcc %l5, 0x02, %g0
1506 bne linux_syscall_trace
1512 st %o0, [%sp + REGWIN_SZ + PT_I0]
1514 .globl C_LABEL(ret_sys_call)
1515 C_LABEL(ret_sys_call):
1516 ld [%curptr + AOFF_task_ptrace], %l6
1517 cmp %o0, -ENOIOCTLCMD
1518 ld [%sp + REGWIN_SZ + PT_PSR], %g3
1521 andcc %l6, 0x02, %l6
1523 /* System call success, clear Carry condition code. */
1526 st %g3, [%sp + REGWIN_SZ + PT_PSR]
1527 bne linux_syscall_trace2
1528 ld [%sp + REGWIN_SZ + PT_NPC], %l1 /* pc = npc */
1529 add %l1, 0x4, %l2 /* npc = npc+4 */
1530 st %l1, [%sp + REGWIN_SZ + PT_PC]
1532 st %l2, [%sp + REGWIN_SZ + PT_NPC]
1534 /* System call failure, set Carry condition code.
1535 * Also, get abs(errno) to return to the process.
1539 st %o0, [%sp + REGWIN_SZ + PT_I0]
1541 st %g3, [%sp + REGWIN_SZ + PT_PSR]
1542 bne linux_syscall_trace2
1543 ld [%sp + REGWIN_SZ + PT_NPC], %l1 /* pc = npc */
1544 add %l1, 0x4, %l2 /* npc = npc+4 */
1545 st %l1, [%sp + REGWIN_SZ + PT_PC]
1547 st %l2, [%sp + REGWIN_SZ + PT_NPC]
1549 linux_syscall_trace2:
1550 call C_LABEL(syscall_trace)
1551 add %l1, 0x4, %l2 /* npc = npc+4 */
1552 st %l1, [%sp + REGWIN_SZ + PT_PC]
1554 st %l2, [%sp + REGWIN_SZ + PT_NPC]
1558 * Solaris system calls and indirect system calls enter here.
1560 * I have named the solaris indirect syscalls like that because
1561 * it seems like Solaris has some fast path syscalls that can
1562 * be handled as indirect system calls. - mig
1565 linux_syscall_for_solaris:
1566 sethi %hi(sys_call_table), %l7
1567 b linux_sparc_syscall
1568 or %l7, %lo(sys_call_table), %l7
1571 .globl solaris_syscall
1574 be linux_syscall_for_solaris
1576 be linux_syscall_for_solaris
1578 be linux_syscall_for_solaris
1580 be,a linux_syscall_for_solaris
1586 wr %l0, PSR_ET, %psr
1591 call C_LABEL(do_solaris_syscall)
1592 add %sp, REGWIN_SZ, %o0
1594 st %o0, [%sp + REGWIN_SZ + PT_I0]
1596 cmp %o0, -ENOIOCTLCMD
1598 ld [%sp + REGWIN_SZ + PT_PSR], %g3
1600 /* System call success, clear Carry condition code. */
1604 st %g3, [%sp + REGWIN_SZ + PT_PSR]
1607 /* System call failure, set Carry condition code.
1608 * Also, get abs(errno) to return to the process.
1612 st %o0, [%sp + REGWIN_SZ + PT_I0]
1614 st %g3, [%sp + REGWIN_SZ + PT_PSR]
1616 /* Advance the pc and npc over the trap instruction.
1617 * If the npc is unaligned (has a 1 in the lower byte), it means
1618 * the kernel does not want us to play magic (ie, skipping over
1619 * traps). Mainly when the Solaris code wants to set some PC and
1623 ld [%sp + REGWIN_SZ + PT_NPC], %l1 /* pc = npc */
1626 add %l1, 0x4, %l2 /* npc = npc+4 */
1627 st %l1, [%sp + REGWIN_SZ + PT_PC]
1629 st %l2, [%sp + REGWIN_SZ + PT_NPC]
1631 /* kernel knows what it is doing, fixup npc and continue */
1635 st %l1, [%sp + REGWIN_SZ + PT_NPC]
1637 #ifndef CONFIG_SUNOS_EMUL
1639 .globl sunos_syscall
1643 wr %l0, PSR_ET, %psr
1647 call C_LABEL(do_sunos_syscall)
1648 add %sp, REGWIN_SZ, %o0
1651 /* {net, open}bsd system calls enter here... */
1655 /* Direct access to user regs, must faster. */
1656 cmp %g1, NR_SYSCALLS
1660 set C_LABEL(sys_ni_syscall), %l7
1667 .globl bsd_is_too_hard
1672 wr %l0, PSR_ET, %psr
1685 st %o0, [%sp + REGWIN_SZ + PT_I0]
1687 cmp %o0, -ENOIOCTLCMD
1689 ld [%sp + REGWIN_SZ + PT_PSR], %g3
1691 /* System call success, clear Carry condition code. */
1695 st %g3, [%sp + REGWIN_SZ + PT_PSR]
1698 /* System call failure, set Carry condition code.
1699 * Also, get abs(errno) to return to the process.
1702 #if 0 /* XXX todo XXX */
1703 sethi %hi(C_LABEL(bsd_xlatb_rorl), %o3
1704 or %o3, %lo(C_LABEL(bsd_xlatb_rorl)), %o3
1709 st %o0, [%sp + REGWIN_SZ + PT_I0]
1711 st %g3, [%sp + REGWIN_SZ + PT_PSR]
1713 /* Advance the pc and npc over the trap instruction. */
1715 ld [%sp + REGWIN_SZ + PT_NPC], %l1 /* pc = npc */
1716 add %l1, 0x4, %l2 /* npc = npc+4 */
1717 st %l1, [%sp + REGWIN_SZ + PT_PC]
1719 st %l2, [%sp + REGWIN_SZ + PT_NPC]
1721 /* Saving and restoring the FPU state is best done from lowlevel code.
1723 * void fpsave(unsigned long *fpregs, unsigned long *fsr,
1724 * void *fpqueue, unsigned long *fpqdepth)
1727 .globl C_LABEL(fpsave)
1729 st %fsr, [%o1] ! this can trap on us if fpu is in bogon state
1736 /* We have an fpqueue to save. */
1750 std %f0, [%o0 + 0x00]
1751 std %f2, [%o0 + 0x08]
1752 std %f4, [%o0 + 0x10]
1753 std %f6, [%o0 + 0x18]
1754 std %f8, [%o0 + 0x20]
1755 std %f10, [%o0 + 0x28]
1756 std %f12, [%o0 + 0x30]
1757 std %f14, [%o0 + 0x38]
1758 std %f16, [%o0 + 0x40]
1759 std %f18, [%o0 + 0x48]
1760 std %f20, [%o0 + 0x50]
1761 std %f22, [%o0 + 0x58]
1762 std %f24, [%o0 + 0x60]
1763 std %f26, [%o0 + 0x68]
1764 std %f28, [%o0 + 0x70]
1766 std %f30, [%o0 + 0x78]
1768 /* Thanks for Theo Deraadt and the authors of the Sprite/netbsd/openbsd
1769 * code for pointing out this possible deadlock, while we save state
1770 * above we could trap on the fsr store so our low level fpu trap
1771 * code has to know how to deal with this.
1778 b C_LABEL(fpsave) + 4
1781 /* void fpload(unsigned long *fpregs, unsigned long *fsr); */
1783 .globl C_LABEL(fpload)
1785 ldd [%o0 + 0x00], %f0
1786 ldd [%o0 + 0x08], %f2
1787 ldd [%o0 + 0x10], %f4
1788 ldd [%o0 + 0x18], %f6
1789 ldd [%o0 + 0x20], %f8
1790 ldd [%o0 + 0x28], %f10
1791 ldd [%o0 + 0x30], %f12
1792 ldd [%o0 + 0x38], %f14
1793 ldd [%o0 + 0x40], %f16
1794 ldd [%o0 + 0x48], %f18
1795 ldd [%o0 + 0x50], %f20
1796 ldd [%o0 + 0x58], %f22
1797 ldd [%o0 + 0x60], %f24
1798 ldd [%o0 + 0x68], %f26
1799 ldd [%o0 + 0x70], %f28
1800 ldd [%o0 + 0x78], %f30
1805 .globl C_LABEL(udelay)
1807 save %sp, -REGWIN_SZ, %sp
1809 sethi %hi(0x10c6), %o1
1811 or %o1, %lo(0x10c6), %o1
1813 sethi %hi(C_LABEL(loops_per_sec)), %o3
1815 ld [%o3 + %lo(C_LABEL(loops_per_sec))], %o1
1817 GET_PROCESSOR_OFFSET(o4, o2)
1818 set C_LABEL(cpu_data), %o3
1831 /* Handle a software breakpoint */
1832 /* We have to inform parent that child has stopped */
1834 .globl breakpoint_trap
1838 wr %l0, PSR_ET, %psr
1841 st %i0, [%sp + REGWIN_SZ + PT_G0] ! for restarting syscalls
1842 call C_LABEL(sparc_breakpoint)
1843 add %sp, REGWIN_SZ, %o0
1848 .globl C_LABEL(__handle_exception), flush_patch_exception
1849 C_LABEL(__handle_exception):
1850 flush_patch_exception:
1851 FLUSH_ALL_KERNEL_WINDOWS;
1853 jmpl %o7 + 0xc, %g0 ! see asm-sparc/processor.h
1854 mov 1, %g1 ! signal EFAULT condition
1857 .globl C_LABEL(kill_user_windows), kuw_patch1_7win
1859 kuw_patch1_7win: sll %o3, 6, %o3
1861 /* No matter how much overhead this routine has in the worst
1862 * case scenerio, it is several times better than taking the
1863 * traps with the old method of just doing flush_user_windows().
1865 C_LABEL(kill_user_windows):
1866 ld [%g6 + AOFF_task_thread + AOFF_thread_uwinmask], %o0 ! get current umask
1867 orcc %g0, %o0, %g0 ! if no bits set, we are done
1868 be 3f ! nothing to do
1869 rd %psr, %o5 ! must clear interrupts
1870 or %o5, PSR_PIL, %o4 ! or else that could change
1871 wr %o4, 0x0, %psr ! the uwinmask state
1872 WRITE_PAUSE ! burn them cycles
1874 ld [%g6 + AOFF_task_thread + AOFF_thread_uwinmask], %o0 ! get consistant state
1875 orcc %g0, %o0, %g0 ! did an interrupt come in?
1876 be 4f ! yep, we are done
1877 rd %wim, %o3 ! get current wim
1878 srl %o3, 1, %o4 ! simulate a save
1880 sll %o3, 7, %o3 ! compute next wim
1881 or %o4, %o3, %o3 ! result
1882 andncc %o0, %o3, %o0 ! clean this bit in umask
1883 bne kuw_patch1 ! not done yet
1884 srl %o3, 1, %o4 ! begin another save simulation
1885 wr %o3, 0x0, %wim ! set the new wim
1886 st %g0, [%g6 + AOFF_task_thread + AOFF_thread_uwinmask] ! clear uwinmask
1888 wr %o5, 0x0, %psr ! re-enable interrupts
1889 WRITE_PAUSE ! burn baby burn
1892 st %g0, [%g6 + AOFF_task_thread + AOFF_thread_w_saved] ! no windows saved
1895 .globl C_LABEL(restore_current)
1896 C_LABEL(restore_current):
1897 LOAD_CURRENT(g6, o0)
1902 #include <asm/pcic.h>
1905 .globl linux_trap_ipi15_pcic
1906 linux_trap_ipi15_pcic:
1911 * First deactivate NMI
1912 * or we cannot drop ET, cannot get window spill traps.
1913 * The busy loop is necessary because the PIO error
1914 * sometimes does not go away quickly and we trap again.
1916 sethi %hi(C_LABEL(pcic_regs)), %o1
1917 ld [%o1 + %lo(C_LABEL(pcic_regs))], %o2
1919 ! Get pending status for printouts later.
1920 ld [%o2 + PCI_SYS_INT_PENDING], %o0
1922 mov PCI_SYS_INT_PENDING_CLEAR_ALL, %o1
1923 stb %o1, [%o2 + PCI_SYS_INT_PENDING_CLEAR]
1925 ld [%o2 + PCI_SYS_INT_PENDING], %o1
1926 andcc %o1, ((PCI_SYS_INT_PENDING_PIO|PCI_SYS_INT_PENDING_PCI)>>24), %g0
1930 or %l0, PSR_PIL, %l4
1933 wr %l4, PSR_ET, %psr
1936 call C_LABEL(pcic_nmi)
1937 add %sp, REGWIN_SZ, %o1 ! struct pt_regs *regs
1940 .globl C_LABEL(pcic_nmi_trap_patch)
1941 C_LABEL(pcic_nmi_trap_patch):
1942 sethi %hi(linux_trap_ipi15_pcic), %l3
1943 jmpl %l3 + %lo(linux_trap_ipi15_pcic), %g0
1947 #endif /* CONFIG_PCI */
1949 /* End of entry.S */