1 /* arch/sparc/kernel/entry.S: Sparc trap low-level entry points.
3 * Copyright (C) 1995, 2007 David S. Miller (davem@davemloft.net)
4 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
5 * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
6 * Copyright (C) 1996-1999 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7 * Copyright (C) 1997 Anton Blanchard (anton@progsoc.uts.edu.au)
10 #include <linux/errno.h>
15 #include <asm/contregs.h>
16 #include <asm/ptrace.h>
17 #include <asm/asm-offsets.h>
19 #include <asm/vaddrs.h>
20 #include <asm/memreg.h>
23 #include <asm/pgtsun4.h>
25 #include <asm/pgtsun4c.h>
27 #include <asm/winmacro.h>
28 #include <asm/signal.h>
31 #include <asm/thread_info.h>
32 #include <asm/param.h>
33 #include <asm/unistd.h>
35 #include <asm/asmmacro.h>
39 /* These are just handy. */
40 #define _SV save %sp, -STACKFRAME_SZ, %sp
43 #define FLUSH_ALL_KERNEL_WINDOWS \
44 _SV; _SV; _SV; _SV; _SV; _SV; _SV; \
45 _RS; _RS; _RS; _RS; _RS; _RS; _RS;
51 .globl arch_kgdb_breakpoint
52 .type arch_kgdb_breakpoint,#function
57 .size arch_kgdb_breakpoint,.-arch_kgdb_breakpoint
60 #if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
65 * This code cannot touch registers %l0 %l1 and %l2
66 * because SAVE_ALL depends on their values. It depends
67 * on %l3 also, but we regenerate it before a call.
68 * Other registers are:
69 * %l3 -- base address of fdc registers
71 * %l5 -- scratch for ld/st address
73 * %l7 -- scratch [floppy byte, ld/st address, aux. data]
76 /* Do we have work to do? */
77 sethi %hi(doing_pdma), %l7
78 ld [%l7 + %lo(doing_pdma)], %l7
83 /* Load fdc register base */
84 sethi %hi(fdc_status), %l3
85 ld [%l3 + %lo(fdc_status)], %l3
87 /* Setup register addresses */
88 sethi %hi(pdma_vaddr), %l5 ! transfer buffer
89 ld [%l5 + %lo(pdma_vaddr)], %l4
90 sethi %hi(pdma_size), %l5 ! bytes to go
91 ld [%l5 + %lo(pdma_size)], %l6
95 andcc %l7, 0x80, %g0 ! Does fifo still have data
96 bz floppy_fifo_emptied ! fifo has been emptied...
97 andcc %l7, 0x20, %g0 ! in non-dma mode still?
98 bz floppy_overrun ! nope, overrun
99 andcc %l7, 0x40, %g0 ! 0=write 1=read
103 /* Ok, actually read this byte */
114 /* Ok, actually write this byte */
121 /* fall through... */
123 sethi %hi(pdma_vaddr), %l5
124 st %l4, [%l5 + %lo(pdma_vaddr)]
125 sethi %hi(pdma_size), %l5
126 st %l6, [%l5 + %lo(pdma_size)]
127 /* Flip terminal count pin */
128 set auxio_register, %l7
131 set sparc_cpu_model, %l5
133 subcc %l5, 1, %g0 /* enum { sun4c = 1 }; */
149 /* Kill some time so the bits set */
155 /* Prevent recursion */
156 sethi %hi(doing_pdma), %l7
158 st %g0, [%l7 + %lo(doing_pdma)]
160 /* We emptied the FIFO, but we haven't read everything
161 * as of yet. Store the current transfer address and
162 * bytes left to read so we can continue when the next
166 sethi %hi(pdma_vaddr), %l5
167 st %l4, [%l5 + %lo(pdma_vaddr)]
168 sethi %hi(pdma_size), %l7
169 st %l6, [%l7 + %lo(pdma_size)]
171 /* Restore condition codes */
179 sethi %hi(pdma_vaddr), %l5
180 st %l4, [%l5 + %lo(pdma_vaddr)]
181 sethi %hi(pdma_size), %l5
182 st %l6, [%l5 + %lo(pdma_size)]
183 /* Prevent recursion */
184 sethi %hi(doing_pdma), %l7
185 st %g0, [%l7 + %lo(doing_pdma)]
187 /* fall through... */
192 /* Set all IRQs off. */
199 mov 11, %o0 ! floppy irq level (unused anyway)
200 mov %g0, %o1 ! devid is not used in fast interrupts
201 call sparc_floppy_irq
202 add %sp, STACKFRAME_SZ, %o2 ! struct pt_regs *regs
206 #endif /* (CONFIG_BLK_DEV_FD) */
208 /* Bad trap handler */
209 .globl bad_trap_handler
216 add %sp, STACKFRAME_SZ, %o0 ! pt_regs
218 mov %l7, %o1 ! trap number
222 /* For now all IRQ's not registered get sent here. handler_irq() will
223 * see if a routine is registered to handle this interrupt and if not
224 * it will say so on the console.
228 .globl real_irq_entry, patch_handler_irq
233 .globl patchme_maybe_smp_msg
236 patchme_maybe_smp_msg:
247 mov %l7, %o0 ! irq level
250 add %sp, STACKFRAME_SZ, %o1 ! pt_regs ptr
251 or %l0, PSR_PIL, %g2 ! restore PIL after handler_irq
252 wr %g2, PSR_ET, %psr ! keep ET up
258 /* SMP per-cpu ticker interrupts are handled specially. */
260 bne real_irq_continue+4
266 call smp4m_percpu_timer_interrupt
267 add %sp, STACKFRAME_SZ, %o0
272 /* Here is where we check for possible SMP IPI passed to us
273 * on some level other than 15 which is the NMI and only used
274 * for cross calls. That has a separate entry point below.
277 GET_PROCESSOR4M_ID(o3)
278 set sun4m_interrupts, %l5
280 sethi %hi(0x40000000), %o2
295 call smp_reschedule_irq
301 .globl linux_trap_ipi15_sun4m
302 linux_trap_ipi15_sun4m:
304 sethi %hi(0x80000000), %o2
305 GET_PROCESSOR4M_ID(o0)
306 set sun4m_interrupts, %l5
312 be 1f ! Must be an NMI async memory error
322 call smp4m_cross_call_irq
324 b ret_trap_lockless_ipi
327 /* NMI async memory error handling. */
328 sethi %hi(0x80000000), %l4
329 sethi %hi(0x4000), %o3
350 /* SMP per-cpu ticker interrupts are handled specially. */
354 sethi %hi(CC_ICLR), %o0
355 sethi %hi(1 << 14), %o1
356 or %o0, %lo(CC_ICLR), %o0
357 stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 14 in MXCC's ICLR */
362 call smp4d_percpu_timer_interrupt
363 add %sp, STACKFRAME_SZ, %o0
369 .globl linux_trap_ipi15_sun4d
370 linux_trap_ipi15_sun4d:
372 sethi %hi(CC_BASE), %o4
373 sethi %hi(MXCC_ERR_ME|MXCC_ERR_PEW|MXCC_ERR_ASE|MXCC_ERR_PEE), %o2
374 or %o4, (CC_EREG - CC_BASE), %o0
375 ldda [%o0] ASI_M_MXCC, %o0
378 sethi %hi(BB_STAT2), %o2
379 lduba [%o2] ASI_M_CTL, %o2
380 andcc %o2, BB_STAT2_MASK, %g0
382 or %o4, (CC_ICLR - CC_BASE), %o0
383 sethi %hi(1 << 15), %o1
384 stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 15 in MXCC's ICLR */
390 call smp4d_cross_call_irq
392 b ret_trap_lockless_ipi
399 lduha [%l4] ASI_M_MXCC, %l5
400 sethi %hi(1 << 15), %l7
402 stha %l5, [%l4] ASI_M_MXCC
406 #endif /* CONFIG_SMP */
408 /* This routine handles illegal instructions and privileged
409 * instruction attempts from user code.
412 .globl bad_instruction
414 sethi %hi(0xc1f80000), %l4
416 sethi %hi(0x81d80000), %l7
422 wr %l0, PSR_ET, %psr ! re-enable traps
425 add %sp, STACKFRAME_SZ, %o0
428 call do_illegal_instruction
433 1: /* unimplemented flush - just skip */
438 .globl priv_instruction
445 add %sp, STACKFRAME_SZ, %o0
448 call do_priv_instruction
453 /* This routine handles unaligned data accesses. */
457 andcc %l0, PSR_PS, %g0
467 call kernel_unaligned_trap
468 add %sp, STACKFRAME_SZ, %o0
475 wr %l0, PSR_ET, %psr ! re-enable traps
479 call user_unaligned_trap
480 add %sp, STACKFRAME_SZ, %o0
484 /* This routine handles floating point disabled traps. */
486 .globl fpd_trap_handler
490 wr %l0, PSR_ET, %psr ! re-enable traps
493 add %sp, STACKFRAME_SZ, %o0
501 /* This routine handles Floating Point Exceptions. */
503 .globl fpe_trap_handler
505 set fpsave_magic, %l5
508 sethi %hi(fpsave), %l5
509 or %l5, %lo(fpsave), %l5
512 sethi %hi(fpsave_catch2), %l5
513 or %l5, %lo(fpsave_catch2), %l5
519 sethi %hi(fpsave_catch), %l5
520 or %l5, %lo(fpsave_catch), %l5
529 wr %l0, PSR_ET, %psr ! re-enable traps
532 add %sp, STACKFRAME_SZ, %o0
540 /* This routine handles Tag Overflow Exceptions. */
542 .globl do_tag_overflow
546 wr %l0, PSR_ET, %psr ! re-enable traps
549 add %sp, STACKFRAME_SZ, %o0
552 call handle_tag_overflow
557 /* This routine handles Watchpoint Exceptions. */
563 wr %l0, PSR_ET, %psr ! re-enable traps
566 add %sp, STACKFRAME_SZ, %o0
569 call handle_watchpoint
574 /* This routine handles Register Access Exceptions. */
580 wr %l0, PSR_ET, %psr ! re-enable traps
583 add %sp, STACKFRAME_SZ, %o0
586 call handle_reg_access
591 /* This routine handles Co-Processor Disabled Exceptions. */
593 .globl do_cp_disabled
597 wr %l0, PSR_ET, %psr ! re-enable traps
600 add %sp, STACKFRAME_SZ, %o0
603 call handle_cp_disabled
608 /* This routine handles Co-Processor Exceptions. */
610 .globl do_cp_exception
614 wr %l0, PSR_ET, %psr ! re-enable traps
617 add %sp, STACKFRAME_SZ, %o0
620 call handle_cp_exception
625 /* This routine handles Hardware Divide By Zero Exceptions. */
631 wr %l0, PSR_ET, %psr ! re-enable traps
634 add %sp, STACKFRAME_SZ, %o0
637 call handle_hw_divzero
643 .globl do_flush_windows
650 andcc %l0, PSR_PS, %g0
654 call flush_user_windows
657 /* Advance over the trap instruction. */
658 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1
660 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
661 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
665 .globl flush_patch_one
667 /* We get these for debugging routines using __builtin_return_address() */
670 FLUSH_ALL_KERNEL_WINDOWS
672 /* Advance over the trap instruction. */
673 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1
675 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
676 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
680 /* The getcc software trap. The user wants the condition codes from
681 * the %psr in register %g1.
685 .globl getcc_trap_handler
687 srl %l0, 20, %g1 ! give user
688 and %g1, 0xf, %g1 ! only ICC bits in %psr
689 jmp %l2 ! advance over trap instruction
690 rett %l2 + 0x4 ! like this...
692 /* The setcc software trap. The user has condition codes in %g1
693 * that it would like placed in the %psr. Be careful not to flip
694 * any unintentional bits!
698 .globl setcc_trap_handler
702 andn %l0, %l5, %l0 ! clear ICC bits in %psr
703 and %l4, %l5, %l4 ! clear non-ICC bits in user value
704 or %l4, %l0, %l4 ! or them in... mix mix mix
706 wr %l4, 0x0, %psr ! set new %psr
707 WRITE_PAUSE ! TI scumbags...
709 jmp %l2 ! advance over trap instruction
710 rett %l2 + 0x4 ! like this...
713 .globl linux_trap_nmi_sun4c
714 linux_trap_nmi_sun4c:
717 /* Ugh, we need to clear the IRQ line. This is now
718 * a very sun4c specific trap handler...
720 sethi %hi(interrupt_enable), %l5
721 ld [%l5 + %lo(interrupt_enable)], %l5
723 andn %l6, INTS_ENAB, %l6
726 /* Now it is safe to re-enable traps without recursion. */
731 /* Now call the c-code with the pt_regs frame ptr and the
732 * memory error registers as arguments. The ordering chosen
733 * here is due to unlatching semantics.
735 sethi %hi(AC_SYNC_ERR), %o0
737 lda [%o0] ASI_CONTROL, %o2 ! sync vaddr
739 lda [%o0] ASI_CONTROL, %o1 ! sync error
741 lda [%o0] ASI_CONTROL, %o4 ! async vaddr
743 lda [%o0] ASI_CONTROL, %o3 ! async error
745 add %sp, STACKFRAME_SZ, %o0
750 .globl invalid_segment_patch1_ff
751 .globl invalid_segment_patch2_ff
752 invalid_segment_patch1_ff: cmp %l4, 0xff
753 invalid_segment_patch2_ff: mov 0xff, %l3
756 .globl invalid_segment_patch1_1ff
757 .globl invalid_segment_patch2_1ff
758 invalid_segment_patch1_1ff: cmp %l4, 0x1ff
759 invalid_segment_patch2_1ff: mov 0x1ff, %l3
762 .globl num_context_patch1_16, num_context_patch2_16
763 num_context_patch1_16: mov 0x10, %l7
764 num_context_patch2_16: mov 0x10, %l7
767 .globl vac_linesize_patch_32
768 vac_linesize_patch_32: subcc %l7, 32, %l7
771 .globl vac_hwflush_patch1_on, vac_hwflush_patch2_on
774 * Ugly, but we cant use hardware flushing on the sun4 and we'd require
775 * two instructions (Anton)
778 vac_hwflush_patch1_on: nop
780 vac_hwflush_patch1_on: addcc %l7, -PAGE_SIZE, %l7
783 vac_hwflush_patch2_on: sta %g0, [%l3 + %l7] ASI_HWFLUSHSEG
785 .globl invalid_segment_patch1, invalid_segment_patch2
786 .globl num_context_patch1
787 .globl vac_linesize_patch, vac_hwflush_patch1
788 .globl vac_hwflush_patch2
797 ! %l7 = 1 for textfault
798 ! We want error in %l5, vaddr in %l6
801 sethi %hi(sun4c_memerr_reg), %l4
802 ld [%l4+%lo(sun4c_memerr_reg)], %l4 ! memerr ctrl reg addr
803 ld [%l4], %l6 ! memerr ctrl reg
804 ld [%l4 + 4], %l5 ! memerr vaddr reg
805 andcc %l6, 0x80, %g0 ! check for error type
806 st %g0, [%l4 + 4] ! clear the error
808 sethi %hi(AC_BUS_ERROR), %l4 ! bus err reg addr
810 call prom_halt ! something weird happened
811 ! what exactly did happen?
812 ! what should we do here?
814 0: or %l4, %lo(AC_BUS_ERROR), %l4 ! bus err reg addr
815 lduba [%l4] ASI_CONTROL, %l6 ! bus err reg
817 cmp %l7, 1 ! text fault?
821 ld [%l1], %l4 ! load instruction that caused fault
823 andcc %l4, 1, %g0 ! store instruction?
826 sethi %hi(SUN4C_SYNC_BADWRITE), %l4 ! yep
827 ! %lo(SUN4C_SYNC_BADWRITE) = 0
828 or %l4, %l6, %l6 ! set write bit to emulate sun4c
831 sethi %hi(AC_SYNC_ERR), %l4
832 add %l4, 0x4, %l6 ! AC_SYNC_VA in %l6
833 lda [%l6] ASI_CONTROL, %l5 ! Address
834 lda [%l4] ASI_CONTROL, %l6 ! Error, retained for a bit
837 andn %l5, 0xfff, %l5 ! Encode all info into l7
843 or %l4, %l7, %l7 ! l7 = [addr,write,txtfault]
845 andcc %l0, PSR_PS, %g0
846 be sun4c_fault_fromuser
847 andcc %l7, 1, %g0 ! Text fault?
850 sethi %hi(KERNBASE), %l4
856 blu sun4c_fault_fromuser
857 sethi %hi(~((1 << SUN4C_REAL_PGDIR_SHIFT) - 1)), %l4
859 /* If the kernel references a bum kernel pointer, or a pte which
860 * points to a non existant page in ram, we will run this code
861 * _forever_ and lock up the machine!!!!! So we must check for
862 * this condition, the AC_SYNC_ERR bits are what we must examine.
863 * Also a parity error would make this happen as well. So we just
864 * check that we are in fact servicing a tlb miss and not some
865 * other type of fault for the kernel.
868 be sun4c_fault_fromuser
871 /* Test for NULL pte_t * in vmalloc area. */
872 sethi %hi(VMALLOC_START), %l4
874 blu,a invalid_segment_patch1
875 lduXa [%l5] ASI_SEGMAP, %l4
877 sethi %hi(swapper_pg_dir), %l4
878 srl %l5, SUN4C_PGDIR_SHIFT, %l6
879 or %l4, %lo(swapper_pg_dir), %l4
883 sethi %hi(PAGE_MASK), %l6
886 andcc %l4, PAGE_MASK, %g0
888 be sun4c_fault_fromuser
889 lduXa [%l5] ASI_SEGMAP, %l4
891 invalid_segment_patch1:
894 sethi %hi(sun4c_kfree_ring), %l4
895 or %l4, %lo(sun4c_kfree_ring), %l4
897 deccc %l3 ! do we have a free entry?
898 bcs,a 2f ! no, unmap one.
899 sethi %hi(sun4c_kernel_ring), %l4
901 st %l3, [%l4 + 0x18] ! sun4c_kfree_ring.num_entries--
903 ld [%l4 + 0x00], %l6 ! entry = sun4c_kfree_ring.ringhd.next
904 st %l5, [%l6 + 0x08] ! entry->vaddr = address
906 ld [%l6 + 0x00], %l3 ! next = entry->next
907 ld [%l6 + 0x04], %l7 ! entry->prev
909 st %l7, [%l3 + 0x04] ! next->prev = entry->prev
910 st %l3, [%l7 + 0x00] ! entry->prev->next = next
912 sethi %hi(sun4c_kernel_ring), %l4
913 or %l4, %lo(sun4c_kernel_ring), %l4
914 ! head = &sun4c_kernel_ring.ringhd
916 ld [%l4 + 0x00], %l7 ! head->next
918 st %l4, [%l6 + 0x04] ! entry->prev = head
919 st %l7, [%l6 + 0x00] ! entry->next = head->next
920 st %l6, [%l7 + 0x04] ! head->next->prev = entry
922 st %l6, [%l4 + 0x00] ! head->next = entry
925 inc %l3 ! sun4c_kernel_ring.num_entries++
931 or %l4, %lo(sun4c_kernel_ring), %l4
932 ! head = &sun4c_kernel_ring.ringhd
934 ld [%l4 + 0x04], %l6 ! entry = head->prev
936 ld [%l6 + 0x08], %l3 ! tmp = entry->vaddr
938 ! Flush segment from the cache.
940 sethi %hi((128 * 1024)), %l7
942 sethi %hi((64 * 1024)), %l7
950 sta %g0, [%l3 + %l7] ASI_FLUSHSEG
952 st %l5, [%l6 + 0x08] ! entry->vaddr = address
954 ld [%l6 + 0x00], %l5 ! next = entry->next
955 ld [%l6 + 0x04], %l7 ! entry->prev
957 st %l7, [%l5 + 0x04] ! next->prev = entry->prev
958 st %l5, [%l7 + 0x00] ! entry->prev->next = next
959 st %l4, [%l6 + 0x04] ! entry->prev = head
961 ld [%l4 + 0x00], %l7 ! head->next
963 st %l7, [%l6 + 0x00] ! entry->next = head->next
964 st %l6, [%l7 + 0x04] ! head->next->prev = entry
965 st %l6, [%l4 + 0x00] ! head->next = entry
967 mov %l3, %l5 ! address = tmp
974 ldub [%l6 + 0x0c], %l3
975 or %l4, %l3, %l4 ! encode new vaddr/pseg into l4
977 sethi %hi(AC_CONTEXT), %l3
978 lduba [%l3] ASI_CONTROL, %l6
980 /* Invalidate old mapping, instantiate new mapping,
981 * for each context. Registers l6/l7 are live across
985 sethi %hi(AC_CONTEXT), %l3
986 stba %l7, [%l3] ASI_CONTROL
987 invalid_segment_patch2:
989 stXa %l3, [%l5] ASI_SEGMAP
992 stXa %l4, [%l3] ASI_SEGMAP
994 sethi %hi(AC_CONTEXT), %l3
995 stba %l6, [%l3] ASI_CONTROL
1000 sethi %hi(VMALLOC_START), %l4
1004 mov 1 << (SUN4C_REAL_PGDIR_SHIFT - PAGE_SHIFT), %l7
1006 sethi %hi(KERNBASE), %l6
1009 srl %l4, PAGE_SHIFT, %l4
1010 sethi %hi((SUN4C_PAGE_KERNEL & 0xf4000000)), %l3
1013 sethi %hi(PAGE_SIZE), %l4
1016 sta %l3, [%l5] ASI_PTE
1023 sethi %hi(sun4c_kernel_faults), %l4
1026 srl %l5, SUN4C_PGDIR_SHIFT, %l3
1027 sethi %hi(swapper_pg_dir), %l4
1028 or %l4, %lo(swapper_pg_dir), %l4
1032 and %l4, PAGE_MASK, %l4
1034 sethi %hi(PAGE_MASK), %l6
1038 srl %l5, (PAGE_SHIFT - 2), %l6
1039 and %l6, ((SUN4C_PTRS_PER_PTE - 1) << 2), %l6
1042 sethi %hi(PAGE_SIZE), %l4
1047 sta %l3, [%l5] ASI_PTE
1052 sethi %hi(sun4c_kernel_faults), %l4
1054 ld [%l4 + %lo(sun4c_kernel_faults)], %l3
1056 st %l3, [%l4 + %lo(sun4c_kernel_faults)]
1058 /* Restore condition codes */
1064 sun4c_fault_fromuser:
1068 mov %l7, %o1 ! Decode the info from %l7
1070 and %o1, 1, %o1 ! arg2 = text_faultp
1072 and %o2, 2, %o2 ! arg3 = writep
1073 andn %o3, 0xfff, %o3 ! arg4 = faulting address
1075 wr %l0, PSR_ET, %psr
1079 add %sp, STACKFRAME_SZ, %o0 ! arg1 = pt_regs ptr
1089 lda [%l5] ASI_M_MMUREGS, %l6 ! read sfar first
1090 lda [%l4] ASI_M_MMUREGS, %l5 ! read sfsr last
1092 andn %l6, 0xfff, %l6
1093 srl %l5, 6, %l5 ! and encode all info into l7
1098 or %l6, %l7, %l7 ! l7 = [addr,write,txtfault]
1104 and %o1, 1, %o1 ! arg2 = text_faultp
1106 and %o2, 2, %o2 ! arg3 = writep
1107 andn %o3, 0xfff, %o3 ! arg4 = faulting address
1109 wr %l0, PSR_ET, %psr
1113 add %sp, STACKFRAME_SZ, %o0 ! arg1 = pt_regs ptr
1118 .globl sys_nis_syscall
1121 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1122 call c_sys_nis_syscall
1129 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1135 st %g0, [%sp + STACKFRAME_SZ + PT_I2]
1138 add %sp, STACKFRAME_SZ, %o0
1141 ld [%sp + STACKFRAME_SZ + PT_I0], %o0
1147 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1152 .globl sys_sigaltstack
1164 call do_sys_sigstack
1168 .globl sys_sigreturn
1171 add %sp, STACKFRAME_SZ, %o0
1173 ld [%curptr + TI_FLAGS], %l5
1174 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1182 /* We don't want to muck with user registers like a
1183 * normal syscall, just return.
1188 .globl sys_rt_sigreturn
1190 call do_rt_sigreturn
1191 add %sp, STACKFRAME_SZ, %o0
1193 ld [%curptr + TI_FLAGS], %l5
1194 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1202 /* We are returning to a signal handler. */
1205 /* Now that we have a real sys_clone, sys_fork() is
1206 * implemented in terms of it. Our _real_ implementation
1207 * of SunOS vfork() will use sys_vfork().
1209 * XXX These three should be consolidated into mostly shared
1210 * XXX code just like on sparc64... -DaveM
1213 .globl sys_fork, flush_patch_two
1217 FLUSH_ALL_KERNEL_WINDOWS;
1218 ld [%curptr + TI_TASK], %o4
1221 mov SIGCHLD, %o0 ! arg0: clone flags
1224 mov %fp, %o1 ! arg1: usp
1225 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1226 add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
1231 /* Whee, kernel threads! */
1232 .globl sys_clone, flush_patch_three
1236 FLUSH_ALL_KERNEL_WINDOWS;
1237 ld [%curptr + TI_TASK], %o4
1241 /* arg0,1: flags,usp -- loaded already */
1242 cmp %o1, 0x0 ! Is new_usp NULL?
1246 mov %fp, %o1 ! yes, use callers usp
1247 andn %o1, 7, %o1 ! no, align to 8 bytes
1249 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1250 add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
1255 /* Whee, real vfork! */
1256 .globl sys_vfork, flush_patch_four
1259 FLUSH_ALL_KERNEL_WINDOWS;
1260 ld [%curptr + TI_TASK], %o4
1265 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1266 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1268 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1269 sethi %hi(sparc_do_fork), %l1
1271 jmpl %l1 + %lo(sparc_do_fork), %g0
1272 add %sp, STACKFRAME_SZ, %o2
1275 linux_sparc_ni_syscall:
1276 sethi %hi(sys_ni_syscall), %l7
1277 b syscall_is_too_hard
1278 or %l7, %lo(sys_ni_syscall), %l7
1288 linux_syscall_trace:
1298 .globl ret_from_fork
1303 ld [%sp + STACKFRAME_SZ + PT_I0], %o0
1305 /* Linux native system calls enter here... */
1307 .globl linux_sparc_syscall
1308 linux_sparc_syscall:
1309 sethi %hi(PSR_SYSCALL), %l4
1311 /* Direct access to user regs, must faster. */
1312 cmp %g1, NR_SYSCALLS
1313 bgeu linux_sparc_ni_syscall
1317 bne linux_fast_syscall
1318 /* Just do first insn from SAVE_ALL in the delay slot */
1320 .globl syscall_is_too_hard
1321 syscall_is_too_hard:
1325 wr %l0, PSR_ET, %psr
1330 ld [%curptr + TI_FLAGS], %l5
1332 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1334 bne linux_syscall_trace
1340 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1343 ld [%curptr + TI_FLAGS], %l6
1344 cmp %o0, -ERESTART_RESTARTBLOCK
1345 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1348 andcc %l6, _TIF_SYSCALL_TRACE, %g0
1350 /* System call success, clear Carry condition code. */
1353 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1354 bne linux_syscall_trace2
1355 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1356 add %l1, 0x4, %l2 /* npc = npc+4 */
1357 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1359 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1361 /* System call failure, set Carry condition code.
1362 * Also, get abs(errno) to return to the process.
1366 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1368 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1369 bne linux_syscall_trace2
1370 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1371 add %l1, 0x4, %l2 /* npc = npc+4 */
1372 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1374 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1376 linux_syscall_trace2:
1378 add %l1, 0x4, %l2 /* npc = npc+4 */
1379 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1381 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1384 /* Saving and restoring the FPU state is best done from lowlevel code.
1386 * void fpsave(unsigned long *fpregs, unsigned long *fsr,
1387 * void *fpqueue, unsigned long *fpqdepth)
1392 st %fsr, [%o1] ! this can trap on us if fpu is in bogon state
1399 /* We have an fpqueue to save. */
1413 std %f0, [%o0 + 0x00]
1414 std %f2, [%o0 + 0x08]
1415 std %f4, [%o0 + 0x10]
1416 std %f6, [%o0 + 0x18]
1417 std %f8, [%o0 + 0x20]
1418 std %f10, [%o0 + 0x28]
1419 std %f12, [%o0 + 0x30]
1420 std %f14, [%o0 + 0x38]
1421 std %f16, [%o0 + 0x40]
1422 std %f18, [%o0 + 0x48]
1423 std %f20, [%o0 + 0x50]
1424 std %f22, [%o0 + 0x58]
1425 std %f24, [%o0 + 0x60]
1426 std %f26, [%o0 + 0x68]
1427 std %f28, [%o0 + 0x70]
1429 std %f30, [%o0 + 0x78]
1431 /* Thanks for Theo Deraadt and the authors of the Sprite/netbsd/openbsd
1432 * code for pointing out this possible deadlock, while we save state
1433 * above we could trap on the fsr store so our low level fpu trap
1434 * code has to know how to deal with this.
1444 /* void fpload(unsigned long *fpregs, unsigned long *fsr); */
1448 ldd [%o0 + 0x00], %f0
1449 ldd [%o0 + 0x08], %f2
1450 ldd [%o0 + 0x10], %f4
1451 ldd [%o0 + 0x18], %f6
1452 ldd [%o0 + 0x20], %f8
1453 ldd [%o0 + 0x28], %f10
1454 ldd [%o0 + 0x30], %f12
1455 ldd [%o0 + 0x38], %f14
1456 ldd [%o0 + 0x40], %f16
1457 ldd [%o0 + 0x48], %f18
1458 ldd [%o0 + 0x50], %f20
1459 ldd [%o0 + 0x58], %f22
1460 ldd [%o0 + 0x60], %f24
1461 ldd [%o0 + 0x68], %f26
1462 ldd [%o0 + 0x70], %f28
1463 ldd [%o0 + 0x78], %f30
1468 /* __ndelay and __udelay take two arguments:
1469 * 0 - nsecs or usecs to delay
1470 * 1 - per_cpu udelay_val (loops per jiffy)
1472 * Note that ndelay gives HZ times higher resolution but has a 10ms
1473 * limit. udelay can handle up to 1s.
1477 save %sp, -STACKFRAME_SZ, %sp
1479 call .umul ! round multiplier up so large ns ok
1480 mov 0x1ae, %o1 ! 2**32 / (1 000 000 000 / HZ)
1482 mov %i1, %o1 ! udelay_val
1484 mov %o1, %o0 ! >>32 later for better resolution
1488 save %sp, -STACKFRAME_SZ, %sp
1490 sethi %hi(0x10c7), %o1 ! round multiplier up so large us ok
1492 or %o1, %lo(0x10c7), %o1 ! 2**32 / 1 000 000
1494 mov %i1, %o1 ! udelay_val
1495 sethi %hi(0x028f4b62), %l0 ! Add in rounding constant * 2**32,
1496 or %g0, %lo(0x028f4b62), %l0
1497 addcc %o0, %l0, %o0 ! 2**32 * 0.009 999
1502 mov HZ, %o0 ! >>32 earlier for wider range
1513 /* Handle a software breakpoint */
1514 /* We have to inform parent that child has stopped */
1516 .globl breakpoint_trap
1520 wr %l0, PSR_ET, %psr
1523 st %i0, [%sp + STACKFRAME_SZ + PT_G0] ! for restarting syscalls
1524 call sparc_breakpoint
1525 add %sp, STACKFRAME_SZ, %o0
1531 .globl kgdb_trap_low
1532 .type kgdb_trap_low,#function
1536 wr %l0, PSR_ET, %psr
1540 add %sp, STACKFRAME_SZ, %o0
1543 .size kgdb_trap_low,.-kgdb_trap_low
1547 .globl __handle_exception, flush_patch_exception
1549 flush_patch_exception:
1550 FLUSH_ALL_KERNEL_WINDOWS;
1552 jmpl %o7 + 0xc, %g0 ! see asm-sparc/processor.h
1553 mov 1, %g1 ! signal EFAULT condition
1556 .globl kill_user_windows, kuw_patch1_7win
1558 kuw_patch1_7win: sll %o3, 6, %o3
1560 /* No matter how much overhead this routine has in the worst
1561 * case scenerio, it is several times better than taking the
1562 * traps with the old method of just doing flush_user_windows().
1565 ld [%g6 + TI_UWINMASK], %o0 ! get current umask
1566 orcc %g0, %o0, %g0 ! if no bits set, we are done
1567 be 3f ! nothing to do
1568 rd %psr, %o5 ! must clear interrupts
1569 or %o5, PSR_PIL, %o4 ! or else that could change
1570 wr %o4, 0x0, %psr ! the uwinmask state
1571 WRITE_PAUSE ! burn them cycles
1573 ld [%g6 + TI_UWINMASK], %o0 ! get consistent state
1574 orcc %g0, %o0, %g0 ! did an interrupt come in?
1575 be 4f ! yep, we are done
1576 rd %wim, %o3 ! get current wim
1577 srl %o3, 1, %o4 ! simulate a save
1579 sll %o3, 7, %o3 ! compute next wim
1580 or %o4, %o3, %o3 ! result
1581 andncc %o0, %o3, %o0 ! clean this bit in umask
1582 bne kuw_patch1 ! not done yet
1583 srl %o3, 1, %o4 ! begin another save simulation
1584 wr %o3, 0x0, %wim ! set the new wim
1585 st %g0, [%g6 + TI_UWINMASK] ! clear uwinmask
1587 wr %o5, 0x0, %psr ! re-enable interrupts
1588 WRITE_PAUSE ! burn baby burn
1591 st %g0, [%g6 + TI_W_SAVED] ! no windows saved
1594 .globl restore_current
1596 LOAD_CURRENT(g6, o0)
1601 #include <asm/pcic.h>
1604 .globl linux_trap_ipi15_pcic
1605 linux_trap_ipi15_pcic:
1610 * First deactivate NMI
1611 * or we cannot drop ET, cannot get window spill traps.
1612 * The busy loop is necessary because the PIO error
1613 * sometimes does not go away quickly and we trap again.
1615 sethi %hi(pcic_regs), %o1
1616 ld [%o1 + %lo(pcic_regs)], %o2
1618 ! Get pending status for printouts later.
1619 ld [%o2 + PCI_SYS_INT_PENDING], %o0
1621 mov PCI_SYS_INT_PENDING_CLEAR_ALL, %o1
1622 stb %o1, [%o2 + PCI_SYS_INT_PENDING_CLEAR]
1624 ld [%o2 + PCI_SYS_INT_PENDING], %o1
1625 andcc %o1, ((PCI_SYS_INT_PENDING_PIO|PCI_SYS_INT_PENDING_PCI)>>24), %g0
1629 or %l0, PSR_PIL, %l4
1632 wr %l4, PSR_ET, %psr
1636 add %sp, STACKFRAME_SZ, %o1 ! struct pt_regs *regs
1639 .globl pcic_nmi_trap_patch
1640 pcic_nmi_trap_patch:
1641 sethi %hi(linux_trap_ipi15_pcic), %l3
1642 jmpl %l3 + %lo(linux_trap_ipi15_pcic), %g0
1646 #endif /* CONFIG_PCI */
1650 save %sp, -0x40, %sp
1651 save %sp, -0x40, %sp
1652 save %sp, -0x40, %sp
1653 save %sp, -0x40, %sp
1654 save %sp, -0x40, %sp
1655 save %sp, -0x40, %sp
1656 save %sp, -0x40, %sp
1666 /* End of entry.S */