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>
22 #include <asm/pgtable.h>
24 #include <asm/pgtsun4.h>
26 #include <asm/pgtsun4c.h>
28 #include <asm/winmacro.h>
29 #include <asm/signal.h>
32 #include <asm/thread_info.h>
33 #include <asm/param.h>
34 #include <asm/unistd.h>
36 #include <asm/asmmacro.h>
40 /* These are just handy. */
41 #define _SV save %sp, -STACKFRAME_SZ, %sp
44 #define FLUSH_ALL_KERNEL_WINDOWS \
45 _SV; _SV; _SV; _SV; _SV; _SV; _SV; \
46 _RS; _RS; _RS; _RS; _RS; _RS; _RS;
52 .globl arch_kgdb_breakpoint
53 .type arch_kgdb_breakpoint,#function
58 .size arch_kgdb_breakpoint,.-arch_kgdb_breakpoint
61 #if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
66 * This code cannot touch registers %l0 %l1 and %l2
67 * because SAVE_ALL depends on their values. It depends
68 * on %l3 also, but we regenerate it before a call.
69 * Other registers are:
70 * %l3 -- base address of fdc registers
72 * %l5 -- scratch for ld/st address
74 * %l7 -- scratch [floppy byte, ld/st address, aux. data]
77 /* Do we have work to do? */
78 sethi %hi(doing_pdma), %l7
79 ld [%l7 + %lo(doing_pdma)], %l7
84 /* Load fdc register base */
85 sethi %hi(fdc_status), %l3
86 ld [%l3 + %lo(fdc_status)], %l3
88 /* Setup register addresses */
89 sethi %hi(pdma_vaddr), %l5 ! transfer buffer
90 ld [%l5 + %lo(pdma_vaddr)], %l4
91 sethi %hi(pdma_size), %l5 ! bytes to go
92 ld [%l5 + %lo(pdma_size)], %l6
96 andcc %l7, 0x80, %g0 ! Does fifo still have data
97 bz floppy_fifo_emptied ! fifo has been emptied...
98 andcc %l7, 0x20, %g0 ! in non-dma mode still?
99 bz floppy_overrun ! nope, overrun
100 andcc %l7, 0x40, %g0 ! 0=write 1=read
104 /* Ok, actually read this byte */
115 /* Ok, actually write this byte */
122 /* fall through... */
124 sethi %hi(pdma_vaddr), %l5
125 st %l4, [%l5 + %lo(pdma_vaddr)]
126 sethi %hi(pdma_size), %l5
127 st %l6, [%l5 + %lo(pdma_size)]
128 /* Flip terminal count pin */
129 set auxio_register, %l7
132 set sparc_cpu_model, %l5
134 subcc %l5, 1, %g0 /* enum { sun4c = 1 }; */
150 /* Kill some time so the bits set */
156 /* Prevent recursion */
157 sethi %hi(doing_pdma), %l7
159 st %g0, [%l7 + %lo(doing_pdma)]
161 /* We emptied the FIFO, but we haven't read everything
162 * as of yet. Store the current transfer address and
163 * bytes left to read so we can continue when the next
167 sethi %hi(pdma_vaddr), %l5
168 st %l4, [%l5 + %lo(pdma_vaddr)]
169 sethi %hi(pdma_size), %l7
170 st %l6, [%l7 + %lo(pdma_size)]
172 /* Restore condition codes */
180 sethi %hi(pdma_vaddr), %l5
181 st %l4, [%l5 + %lo(pdma_vaddr)]
182 sethi %hi(pdma_size), %l5
183 st %l6, [%l5 + %lo(pdma_size)]
184 /* Prevent recursion */
185 sethi %hi(doing_pdma), %l7
186 st %g0, [%l7 + %lo(doing_pdma)]
188 /* fall through... */
193 /* Set all IRQs off. */
200 mov 11, %o0 ! floppy irq level (unused anyway)
201 mov %g0, %o1 ! devid is not used in fast interrupts
202 call sparc_floppy_irq
203 add %sp, STACKFRAME_SZ, %o2 ! struct pt_regs *regs
207 #endif /* (CONFIG_BLK_DEV_FD) */
209 /* Bad trap handler */
210 .globl bad_trap_handler
217 add %sp, STACKFRAME_SZ, %o0 ! pt_regs
219 mov %l7, %o1 ! trap number
223 /* For now all IRQ's not registered get sent here. handler_irq() will
224 * see if a routine is registered to handle this interrupt and if not
225 * it will say so on the console.
229 .globl real_irq_entry, patch_handler_irq
234 .globl patchme_maybe_smp_msg
237 patchme_maybe_smp_msg:
248 mov %l7, %o0 ! irq level
251 add %sp, STACKFRAME_SZ, %o1 ! pt_regs ptr
252 or %l0, PSR_PIL, %g2 ! restore PIL after handler_irq
253 wr %g2, PSR_ET, %psr ! keep ET up
259 /* SMP per-cpu ticker interrupts are handled specially. */
261 bne real_irq_continue+4
267 call smp4m_percpu_timer_interrupt
268 add %sp, STACKFRAME_SZ, %o0
273 /* Here is where we check for possible SMP IPI passed to us
274 * on some level other than 15 which is the NMI and only used
275 * for cross calls. That has a separate entry point below.
278 GET_PROCESSOR4M_ID(o3)
279 set sun4m_interrupts, %l5
281 sethi %hi(0x40000000), %o2
296 call smp_reschedule_irq
302 .globl linux_trap_ipi15_sun4m
303 linux_trap_ipi15_sun4m:
305 sethi %hi(0x80000000), %o2
306 GET_PROCESSOR4M_ID(o0)
307 set sun4m_interrupts, %l5
313 be 1f ! Must be an NMI async memory error
323 call smp4m_cross_call_irq
325 b ret_trap_lockless_ipi
328 /* NMI async memory error handling. */
329 sethi %hi(0x80000000), %l4
330 sethi %hi(0x4000), %o3
351 /* SMP per-cpu ticker interrupts are handled specially. */
355 sethi %hi(CC_ICLR), %o0
356 sethi %hi(1 << 14), %o1
357 or %o0, %lo(CC_ICLR), %o0
358 stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 14 in MXCC's ICLR */
363 call smp4d_percpu_timer_interrupt
364 add %sp, STACKFRAME_SZ, %o0
370 .globl linux_trap_ipi15_sun4d
371 linux_trap_ipi15_sun4d:
373 sethi %hi(CC_BASE), %o4
374 sethi %hi(MXCC_ERR_ME|MXCC_ERR_PEW|MXCC_ERR_ASE|MXCC_ERR_PEE), %o2
375 or %o4, (CC_EREG - CC_BASE), %o0
376 ldda [%o0] ASI_M_MXCC, %o0
379 sethi %hi(BB_STAT2), %o2
380 lduba [%o2] ASI_M_CTL, %o2
381 andcc %o2, BB_STAT2_MASK, %g0
383 or %o4, (CC_ICLR - CC_BASE), %o0
384 sethi %hi(1 << 15), %o1
385 stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 15 in MXCC's ICLR */
391 call smp4d_cross_call_irq
393 b ret_trap_lockless_ipi
400 lduha [%l4] ASI_M_MXCC, %l5
401 sethi %hi(1 << 15), %l7
403 stha %l5, [%l4] ASI_M_MXCC
407 #endif /* CONFIG_SMP */
409 /* This routine handles illegal instructions and privileged
410 * instruction attempts from user code.
413 .globl bad_instruction
415 sethi %hi(0xc1f80000), %l4
417 sethi %hi(0x81d80000), %l7
423 wr %l0, PSR_ET, %psr ! re-enable traps
426 add %sp, STACKFRAME_SZ, %o0
429 call do_illegal_instruction
434 1: /* unimplemented flush - just skip */
439 .globl priv_instruction
446 add %sp, STACKFRAME_SZ, %o0
449 call do_priv_instruction
454 /* This routine handles unaligned data accesses. */
458 andcc %l0, PSR_PS, %g0
468 call kernel_unaligned_trap
469 add %sp, STACKFRAME_SZ, %o0
476 wr %l0, PSR_ET, %psr ! re-enable traps
480 call user_unaligned_trap
481 add %sp, STACKFRAME_SZ, %o0
485 /* This routine handles floating point disabled traps. */
487 .globl fpd_trap_handler
491 wr %l0, PSR_ET, %psr ! re-enable traps
494 add %sp, STACKFRAME_SZ, %o0
502 /* This routine handles Floating Point Exceptions. */
504 .globl fpe_trap_handler
506 set fpsave_magic, %l5
509 sethi %hi(fpsave), %l5
510 or %l5, %lo(fpsave), %l5
513 sethi %hi(fpsave_catch2), %l5
514 or %l5, %lo(fpsave_catch2), %l5
520 sethi %hi(fpsave_catch), %l5
521 or %l5, %lo(fpsave_catch), %l5
530 wr %l0, PSR_ET, %psr ! re-enable traps
533 add %sp, STACKFRAME_SZ, %o0
541 /* This routine handles Tag Overflow Exceptions. */
543 .globl do_tag_overflow
547 wr %l0, PSR_ET, %psr ! re-enable traps
550 add %sp, STACKFRAME_SZ, %o0
553 call handle_tag_overflow
558 /* This routine handles Watchpoint Exceptions. */
564 wr %l0, PSR_ET, %psr ! re-enable traps
567 add %sp, STACKFRAME_SZ, %o0
570 call handle_watchpoint
575 /* This routine handles Register Access Exceptions. */
581 wr %l0, PSR_ET, %psr ! re-enable traps
584 add %sp, STACKFRAME_SZ, %o0
587 call handle_reg_access
592 /* This routine handles Co-Processor Disabled Exceptions. */
594 .globl do_cp_disabled
598 wr %l0, PSR_ET, %psr ! re-enable traps
601 add %sp, STACKFRAME_SZ, %o0
604 call handle_cp_disabled
609 /* This routine handles Co-Processor Exceptions. */
611 .globl do_cp_exception
615 wr %l0, PSR_ET, %psr ! re-enable traps
618 add %sp, STACKFRAME_SZ, %o0
621 call handle_cp_exception
626 /* This routine handles Hardware Divide By Zero Exceptions. */
632 wr %l0, PSR_ET, %psr ! re-enable traps
635 add %sp, STACKFRAME_SZ, %o0
638 call handle_hw_divzero
644 .globl do_flush_windows
651 andcc %l0, PSR_PS, %g0
655 call flush_user_windows
658 /* Advance over the trap instruction. */
659 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1
661 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
662 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
666 .globl flush_patch_one
668 /* We get these for debugging routines using __builtin_return_address() */
671 FLUSH_ALL_KERNEL_WINDOWS
673 /* Advance over the trap instruction. */
674 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1
676 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
677 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
681 /* The getcc software trap. The user wants the condition codes from
682 * the %psr in register %g1.
686 .globl getcc_trap_handler
688 srl %l0, 20, %g1 ! give user
689 and %g1, 0xf, %g1 ! only ICC bits in %psr
690 jmp %l2 ! advance over trap instruction
691 rett %l2 + 0x4 ! like this...
693 /* The setcc software trap. The user has condition codes in %g1
694 * that it would like placed in the %psr. Be careful not to flip
695 * any unintentional bits!
699 .globl setcc_trap_handler
703 andn %l0, %l5, %l0 ! clear ICC bits in %psr
704 and %l4, %l5, %l4 ! clear non-ICC bits in user value
705 or %l4, %l0, %l4 ! or them in... mix mix mix
707 wr %l4, 0x0, %psr ! set new %psr
708 WRITE_PAUSE ! TI scumbags...
710 jmp %l2 ! advance over trap instruction
711 rett %l2 + 0x4 ! like this...
714 .globl linux_trap_nmi_sun4c
715 linux_trap_nmi_sun4c:
718 /* Ugh, we need to clear the IRQ line. This is now
719 * a very sun4c specific trap handler...
721 sethi %hi(interrupt_enable), %l5
722 ld [%l5 + %lo(interrupt_enable)], %l5
724 andn %l6, INTS_ENAB, %l6
727 /* Now it is safe to re-enable traps without recursion. */
732 /* Now call the c-code with the pt_regs frame ptr and the
733 * memory error registers as arguments. The ordering chosen
734 * here is due to unlatching semantics.
736 sethi %hi(AC_SYNC_ERR), %o0
738 lda [%o0] ASI_CONTROL, %o2 ! sync vaddr
740 lda [%o0] ASI_CONTROL, %o1 ! sync error
742 lda [%o0] ASI_CONTROL, %o4 ! async vaddr
744 lda [%o0] ASI_CONTROL, %o3 ! async error
746 add %sp, STACKFRAME_SZ, %o0
751 .globl invalid_segment_patch1_ff
752 .globl invalid_segment_patch2_ff
753 invalid_segment_patch1_ff: cmp %l4, 0xff
754 invalid_segment_patch2_ff: mov 0xff, %l3
757 .globl invalid_segment_patch1_1ff
758 .globl invalid_segment_patch2_1ff
759 invalid_segment_patch1_1ff: cmp %l4, 0x1ff
760 invalid_segment_patch2_1ff: mov 0x1ff, %l3
763 .globl num_context_patch1_16, num_context_patch2_16
764 num_context_patch1_16: mov 0x10, %l7
765 num_context_patch2_16: mov 0x10, %l7
768 .globl vac_linesize_patch_32
769 vac_linesize_patch_32: subcc %l7, 32, %l7
772 .globl vac_hwflush_patch1_on, vac_hwflush_patch2_on
775 * Ugly, but we cant use hardware flushing on the sun4 and we'd require
776 * two instructions (Anton)
779 vac_hwflush_patch1_on: nop
781 vac_hwflush_patch1_on: addcc %l7, -PAGE_SIZE, %l7
784 vac_hwflush_patch2_on: sta %g0, [%l3 + %l7] ASI_HWFLUSHSEG
786 .globl invalid_segment_patch1, invalid_segment_patch2
787 .globl num_context_patch1
788 .globl vac_linesize_patch, vac_hwflush_patch1
789 .globl vac_hwflush_patch2
798 ! %l7 = 1 for textfault
799 ! We want error in %l5, vaddr in %l6
802 sethi %hi(sun4c_memerr_reg), %l4
803 ld [%l4+%lo(sun4c_memerr_reg)], %l4 ! memerr ctrl reg addr
804 ld [%l4], %l6 ! memerr ctrl reg
805 ld [%l4 + 4], %l5 ! memerr vaddr reg
806 andcc %l6, 0x80, %g0 ! check for error type
807 st %g0, [%l4 + 4] ! clear the error
809 sethi %hi(AC_BUS_ERROR), %l4 ! bus err reg addr
811 call prom_halt ! something weird happened
812 ! what exactly did happen?
813 ! what should we do here?
815 0: or %l4, %lo(AC_BUS_ERROR), %l4 ! bus err reg addr
816 lduba [%l4] ASI_CONTROL, %l6 ! bus err reg
818 cmp %l7, 1 ! text fault?
822 ld [%l1], %l4 ! load instruction that caused fault
824 andcc %l4, 1, %g0 ! store instruction?
827 sethi %hi(SUN4C_SYNC_BADWRITE), %l4 ! yep
828 ! %lo(SUN4C_SYNC_BADWRITE) = 0
829 or %l4, %l6, %l6 ! set write bit to emulate sun4c
832 sethi %hi(AC_SYNC_ERR), %l4
833 add %l4, 0x4, %l6 ! AC_SYNC_VA in %l6
834 lda [%l6] ASI_CONTROL, %l5 ! Address
835 lda [%l4] ASI_CONTROL, %l6 ! Error, retained for a bit
838 andn %l5, 0xfff, %l5 ! Encode all info into l7
844 or %l4, %l7, %l7 ! l7 = [addr,write,txtfault]
846 andcc %l0, PSR_PS, %g0
847 be sun4c_fault_fromuser
848 andcc %l7, 1, %g0 ! Text fault?
851 sethi %hi(KERNBASE), %l4
857 blu sun4c_fault_fromuser
858 sethi %hi(~((1 << SUN4C_REAL_PGDIR_SHIFT) - 1)), %l4
860 /* If the kernel references a bum kernel pointer, or a pte which
861 * points to a non existant page in ram, we will run this code
862 * _forever_ and lock up the machine!!!!! So we must check for
863 * this condition, the AC_SYNC_ERR bits are what we must examine.
864 * Also a parity error would make this happen as well. So we just
865 * check that we are in fact servicing a tlb miss and not some
866 * other type of fault for the kernel.
869 be sun4c_fault_fromuser
872 /* Test for NULL pte_t * in vmalloc area. */
873 sethi %hi(VMALLOC_START), %l4
875 blu,a invalid_segment_patch1
876 lduXa [%l5] ASI_SEGMAP, %l4
878 sethi %hi(swapper_pg_dir), %l4
879 srl %l5, SUN4C_PGDIR_SHIFT, %l6
880 or %l4, %lo(swapper_pg_dir), %l4
884 sethi %hi(PAGE_MASK), %l6
887 andcc %l4, PAGE_MASK, %g0
889 be sun4c_fault_fromuser
890 lduXa [%l5] ASI_SEGMAP, %l4
892 invalid_segment_patch1:
895 sethi %hi(sun4c_kfree_ring), %l4
896 or %l4, %lo(sun4c_kfree_ring), %l4
898 deccc %l3 ! do we have a free entry?
899 bcs,a 2f ! no, unmap one.
900 sethi %hi(sun4c_kernel_ring), %l4
902 st %l3, [%l4 + 0x18] ! sun4c_kfree_ring.num_entries--
904 ld [%l4 + 0x00], %l6 ! entry = sun4c_kfree_ring.ringhd.next
905 st %l5, [%l6 + 0x08] ! entry->vaddr = address
907 ld [%l6 + 0x00], %l3 ! next = entry->next
908 ld [%l6 + 0x04], %l7 ! entry->prev
910 st %l7, [%l3 + 0x04] ! next->prev = entry->prev
911 st %l3, [%l7 + 0x00] ! entry->prev->next = next
913 sethi %hi(sun4c_kernel_ring), %l4
914 or %l4, %lo(sun4c_kernel_ring), %l4
915 ! head = &sun4c_kernel_ring.ringhd
917 ld [%l4 + 0x00], %l7 ! head->next
919 st %l4, [%l6 + 0x04] ! entry->prev = head
920 st %l7, [%l6 + 0x00] ! entry->next = head->next
921 st %l6, [%l7 + 0x04] ! head->next->prev = entry
923 st %l6, [%l4 + 0x00] ! head->next = entry
926 inc %l3 ! sun4c_kernel_ring.num_entries++
932 or %l4, %lo(sun4c_kernel_ring), %l4
933 ! head = &sun4c_kernel_ring.ringhd
935 ld [%l4 + 0x04], %l6 ! entry = head->prev
937 ld [%l6 + 0x08], %l3 ! tmp = entry->vaddr
939 ! Flush segment from the cache.
941 sethi %hi((128 * 1024)), %l7
943 sethi %hi((64 * 1024)), %l7
951 sta %g0, [%l3 + %l7] ASI_FLUSHSEG
953 st %l5, [%l6 + 0x08] ! entry->vaddr = address
955 ld [%l6 + 0x00], %l5 ! next = entry->next
956 ld [%l6 + 0x04], %l7 ! entry->prev
958 st %l7, [%l5 + 0x04] ! next->prev = entry->prev
959 st %l5, [%l7 + 0x00] ! entry->prev->next = next
960 st %l4, [%l6 + 0x04] ! entry->prev = head
962 ld [%l4 + 0x00], %l7 ! head->next
964 st %l7, [%l6 + 0x00] ! entry->next = head->next
965 st %l6, [%l7 + 0x04] ! head->next->prev = entry
966 st %l6, [%l4 + 0x00] ! head->next = entry
968 mov %l3, %l5 ! address = tmp
975 ldub [%l6 + 0x0c], %l3
976 or %l4, %l3, %l4 ! encode new vaddr/pseg into l4
978 sethi %hi(AC_CONTEXT), %l3
979 lduba [%l3] ASI_CONTROL, %l6
981 /* Invalidate old mapping, instantiate new mapping,
982 * for each context. Registers l6/l7 are live across
986 sethi %hi(AC_CONTEXT), %l3
987 stba %l7, [%l3] ASI_CONTROL
988 invalid_segment_patch2:
990 stXa %l3, [%l5] ASI_SEGMAP
993 stXa %l4, [%l3] ASI_SEGMAP
995 sethi %hi(AC_CONTEXT), %l3
996 stba %l6, [%l3] ASI_CONTROL
1001 sethi %hi(VMALLOC_START), %l4
1005 mov 1 << (SUN4C_REAL_PGDIR_SHIFT - PAGE_SHIFT), %l7
1007 sethi %hi(KERNBASE), %l6
1010 srl %l4, PAGE_SHIFT, %l4
1011 sethi %hi((SUN4C_PAGE_KERNEL & 0xf4000000)), %l3
1014 sethi %hi(PAGE_SIZE), %l4
1017 sta %l3, [%l5] ASI_PTE
1024 sethi %hi(sun4c_kernel_faults), %l4
1027 srl %l5, SUN4C_PGDIR_SHIFT, %l3
1028 sethi %hi(swapper_pg_dir), %l4
1029 or %l4, %lo(swapper_pg_dir), %l4
1033 and %l4, PAGE_MASK, %l4
1035 sethi %hi(PAGE_MASK), %l6
1039 srl %l5, (PAGE_SHIFT - 2), %l6
1040 and %l6, ((SUN4C_PTRS_PER_PTE - 1) << 2), %l6
1043 sethi %hi(PAGE_SIZE), %l4
1048 sta %l3, [%l5] ASI_PTE
1053 sethi %hi(sun4c_kernel_faults), %l4
1055 ld [%l4 + %lo(sun4c_kernel_faults)], %l3
1057 st %l3, [%l4 + %lo(sun4c_kernel_faults)]
1059 /* Restore condition codes */
1065 sun4c_fault_fromuser:
1069 mov %l7, %o1 ! Decode the info from %l7
1071 and %o1, 1, %o1 ! arg2 = text_faultp
1073 and %o2, 2, %o2 ! arg3 = writep
1074 andn %o3, 0xfff, %o3 ! arg4 = faulting address
1076 wr %l0, PSR_ET, %psr
1080 add %sp, STACKFRAME_SZ, %o0 ! arg1 = pt_regs ptr
1090 lda [%l5] ASI_M_MMUREGS, %l6 ! read sfar first
1091 lda [%l4] ASI_M_MMUREGS, %l5 ! read sfsr last
1093 andn %l6, 0xfff, %l6
1094 srl %l5, 6, %l5 ! and encode all info into l7
1099 or %l6, %l7, %l7 ! l7 = [addr,write,txtfault]
1105 and %o1, 1, %o1 ! arg2 = text_faultp
1107 and %o2, 2, %o2 ! arg3 = writep
1108 andn %o3, 0xfff, %o3 ! arg4 = faulting address
1110 wr %l0, PSR_ET, %psr
1114 add %sp, STACKFRAME_SZ, %o0 ! arg1 = pt_regs ptr
1119 .globl sys_nis_syscall
1122 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1123 call c_sys_nis_syscall
1130 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1136 st %g0, [%sp + STACKFRAME_SZ + PT_I2]
1139 add %sp, STACKFRAME_SZ, %o0
1142 ld [%sp + STACKFRAME_SZ + PT_I0], %o0
1148 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1153 .globl sys_sigaltstack
1165 call do_sys_sigstack
1169 .globl sys_sigreturn
1172 add %sp, STACKFRAME_SZ, %o0
1174 ld [%curptr + TI_FLAGS], %l5
1175 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1183 /* We don't want to muck with user registers like a
1184 * normal syscall, just return.
1189 .globl sys_rt_sigreturn
1191 call do_rt_sigreturn
1192 add %sp, STACKFRAME_SZ, %o0
1194 ld [%curptr + TI_FLAGS], %l5
1195 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1203 /* We are returning to a signal handler. */
1206 /* Now that we have a real sys_clone, sys_fork() is
1207 * implemented in terms of it. Our _real_ implementation
1208 * of SunOS vfork() will use sys_vfork().
1210 * XXX These three should be consolidated into mostly shared
1211 * XXX code just like on sparc64... -DaveM
1214 .globl sys_fork, flush_patch_two
1218 FLUSH_ALL_KERNEL_WINDOWS;
1219 ld [%curptr + TI_TASK], %o4
1222 mov SIGCHLD, %o0 ! arg0: clone flags
1225 mov %fp, %o1 ! arg1: usp
1226 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1227 add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
1232 /* Whee, kernel threads! */
1233 .globl sys_clone, flush_patch_three
1237 FLUSH_ALL_KERNEL_WINDOWS;
1238 ld [%curptr + TI_TASK], %o4
1242 /* arg0,1: flags,usp -- loaded already */
1243 cmp %o1, 0x0 ! Is new_usp NULL?
1247 mov %fp, %o1 ! yes, use callers usp
1248 andn %o1, 7, %o1 ! no, align to 8 bytes
1250 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1251 add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
1256 /* Whee, real vfork! */
1257 .globl sys_vfork, flush_patch_four
1260 FLUSH_ALL_KERNEL_WINDOWS;
1261 ld [%curptr + TI_TASK], %o4
1266 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1267 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1269 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1270 sethi %hi(sparc_do_fork), %l1
1272 jmpl %l1 + %lo(sparc_do_fork), %g0
1273 add %sp, STACKFRAME_SZ, %o2
1276 linux_sparc_ni_syscall:
1277 sethi %hi(sys_ni_syscall), %l7
1278 b syscall_is_too_hard
1279 or %l7, %lo(sys_ni_syscall), %l7
1289 linux_syscall_trace:
1299 .globl ret_from_fork
1304 ld [%sp + STACKFRAME_SZ + PT_I0], %o0
1306 /* Linux native system calls enter here... */
1308 .globl linux_sparc_syscall
1309 linux_sparc_syscall:
1310 sethi %hi(PSR_SYSCALL), %l4
1312 /* Direct access to user regs, must faster. */
1313 cmp %g1, NR_SYSCALLS
1314 bgeu linux_sparc_ni_syscall
1318 bne linux_fast_syscall
1319 /* Just do first insn from SAVE_ALL in the delay slot */
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 flush_patch_exception
1548 flush_patch_exception:
1549 FLUSH_ALL_KERNEL_WINDOWS;
1551 jmpl %o7 + 0xc, %g0 ! see asm-sparc/processor.h
1552 mov 1, %g1 ! signal EFAULT condition
1555 .globl kill_user_windows, kuw_patch1_7win
1557 kuw_patch1_7win: sll %o3, 6, %o3
1559 /* No matter how much overhead this routine has in the worst
1560 * case scenerio, it is several times better than taking the
1561 * traps with the old method of just doing flush_user_windows().
1564 ld [%g6 + TI_UWINMASK], %o0 ! get current umask
1565 orcc %g0, %o0, %g0 ! if no bits set, we are done
1566 be 3f ! nothing to do
1567 rd %psr, %o5 ! must clear interrupts
1568 or %o5, PSR_PIL, %o4 ! or else that could change
1569 wr %o4, 0x0, %psr ! the uwinmask state
1570 WRITE_PAUSE ! burn them cycles
1572 ld [%g6 + TI_UWINMASK], %o0 ! get consistent state
1573 orcc %g0, %o0, %g0 ! did an interrupt come in?
1574 be 4f ! yep, we are done
1575 rd %wim, %o3 ! get current wim
1576 srl %o3, 1, %o4 ! simulate a save
1578 sll %o3, 7, %o3 ! compute next wim
1579 or %o4, %o3, %o3 ! result
1580 andncc %o0, %o3, %o0 ! clean this bit in umask
1581 bne kuw_patch1 ! not done yet
1582 srl %o3, 1, %o4 ! begin another save simulation
1583 wr %o3, 0x0, %wim ! set the new wim
1584 st %g0, [%g6 + TI_UWINMASK] ! clear uwinmask
1586 wr %o5, 0x0, %psr ! re-enable interrupts
1587 WRITE_PAUSE ! burn baby burn
1590 st %g0, [%g6 + TI_W_SAVED] ! no windows saved
1593 .globl restore_current
1595 LOAD_CURRENT(g6, o0)
1600 #include <asm/pcic.h>
1603 .globl linux_trap_ipi15_pcic
1604 linux_trap_ipi15_pcic:
1609 * First deactivate NMI
1610 * or we cannot drop ET, cannot get window spill traps.
1611 * The busy loop is necessary because the PIO error
1612 * sometimes does not go away quickly and we trap again.
1614 sethi %hi(pcic_regs), %o1
1615 ld [%o1 + %lo(pcic_regs)], %o2
1617 ! Get pending status for printouts later.
1618 ld [%o2 + PCI_SYS_INT_PENDING], %o0
1620 mov PCI_SYS_INT_PENDING_CLEAR_ALL, %o1
1621 stb %o1, [%o2 + PCI_SYS_INT_PENDING_CLEAR]
1623 ld [%o2 + PCI_SYS_INT_PENDING], %o1
1624 andcc %o1, ((PCI_SYS_INT_PENDING_PIO|PCI_SYS_INT_PENDING_PCI)>>24), %g0
1628 or %l0, PSR_PIL, %l4
1631 wr %l4, PSR_ET, %psr
1635 add %sp, STACKFRAME_SZ, %o1 ! struct pt_regs *regs
1638 .globl pcic_nmi_trap_patch
1639 pcic_nmi_trap_patch:
1640 sethi %hi(linux_trap_ipi15_pcic), %l3
1641 jmpl %l3 + %lo(linux_trap_ipi15_pcic), %g0
1645 #endif /* CONFIG_PCI */
1649 save %sp, -0x40, %sp
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
1665 /* End of entry.S */