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>
16 #include <asm/contregs.h>
17 #include <asm/ptrace.h>
18 #include <asm/asm-offsets.h>
20 #include <asm/vaddrs.h>
21 #include <asm/memreg.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;
48 /* First, KGDB low level things. This is a rewrite
49 * of the routines found in the sparc-stub.c asm() statement
50 * from the gdb distribution. This is also dual-purpose
51 * as a software trap for userlevel programs.
62 #if 0 /* kgdb is dropped from 2.5.33 */
63 ! This function is called when any SPARC trap (except window overflow or
64 ! underflow) occurs. It makes sure that the invalid register window is still
65 ! available before jumping into C code. It will also restore the world if you
66 ! return from handle_exception.
73 sethi %hi(in_trap_handler), %l4
74 ld [%lo(in_trap_handler) + %l4], %l5
76 st %l5, [%lo(in_trap_handler) + %l4]
78 /* Make sure kgdb sees the same state we just saved. */
81 ld [%sp + STACKFRAME_SZ + PT_Y], %l4
82 ld [%sp + STACKFRAME_SZ + PT_WIM], %l3
83 ld [%sp + STACKFRAME_SZ + PT_PSR], %l0
84 ld [%sp + STACKFRAME_SZ + PT_PC], %l1
85 ld [%sp + STACKFRAME_SZ + PT_NPC], %l2
86 rd %tbr, %l5 /* Never changes... */
88 /* Make kgdb exception frame. */
89 sub %sp,(16+1+6+1+72)*4,%sp ! Make room for input & locals
90 ! + hidden arg + arg spill
91 ! + doubleword alignment
92 ! + registers[72] local var
95 SAVE_KGDB_SREGS(sp, l4, l0, l3, l5, l1, l2)
97 /* We are increasing PIL, so two writes. */
104 call handle_exception
105 add %sp, STACKFRAME_SZ, %o0 ! Pass address of registers
107 /* Load new kgdb register set. */
108 LOAD_KGDB_GLOBALS(sp)
110 LOAD_KGDB_SREGS(sp, l4, l0, l3, l5, l1, l2)
113 sethi %hi(in_trap_handler), %l4
114 ld [%lo(in_trap_handler) + %l4], %l5
116 st %l5, [%lo(in_trap_handler) + %l4]
118 add %sp,(16+1+6+1+72)*4,%sp ! Undo the kgdb trap frame.
120 /* Now take what kgdb did and place it into the pt_regs
121 * frame which SparcLinux RESTORE_ALL understands.,
125 STORE_PT_YREG(sp, g2)
126 STORE_PT_PRIV(sp, l0, l1, l2)
131 #if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
134 .globl floppy_hardint
137 * This code cannot touch registers %l0 %l1 and %l2
138 * because SAVE_ALL depends on their values. It depends
139 * on %l3 also, but we regenerate it before a call.
140 * Other registers are:
141 * %l3 -- base address of fdc registers
143 * %l5 -- scratch for ld/st address
145 * %l7 -- scratch [floppy byte, ld/st address, aux. data]
148 /* Do we have work to do? */
149 sethi %hi(doing_pdma), %l7
150 ld [%l7 + %lo(doing_pdma)], %l7
155 /* Load fdc register base */
156 sethi %hi(fdc_status), %l3
157 ld [%l3 + %lo(fdc_status)], %l3
159 /* Setup register addresses */
160 sethi %hi(pdma_vaddr), %l5 ! transfer buffer
161 ld [%l5 + %lo(pdma_vaddr)], %l4
162 sethi %hi(pdma_size), %l5 ! bytes to go
163 ld [%l5 + %lo(pdma_size)], %l6
167 andcc %l7, 0x80, %g0 ! Does fifo still have data
168 bz floppy_fifo_emptied ! fifo has been emptied...
169 andcc %l7, 0x20, %g0 ! in non-dma mode still?
170 bz floppy_overrun ! nope, overrun
171 andcc %l7, 0x40, %g0 ! 0=write 1=read
175 /* Ok, actually read this byte */
186 /* Ok, actually write this byte */
193 /* fall through... */
195 sethi %hi(pdma_vaddr), %l5
196 st %l4, [%l5 + %lo(pdma_vaddr)]
197 sethi %hi(pdma_size), %l5
198 st %l6, [%l5 + %lo(pdma_size)]
199 /* Flip terminal count pin */
200 set auxio_register, %l7
203 set sparc_cpu_model, %l5
205 subcc %l5, 1, %g0 /* enum { sun4c = 1 }; */
221 /* Kill some time so the bits set */
227 /* Prevent recursion */
228 sethi %hi(doing_pdma), %l7
230 st %g0, [%l7 + %lo(doing_pdma)]
232 /* We emptied the FIFO, but we haven't read everything
233 * as of yet. Store the current transfer address and
234 * bytes left to read so we can continue when the next
238 sethi %hi(pdma_vaddr), %l5
239 st %l4, [%l5 + %lo(pdma_vaddr)]
240 sethi %hi(pdma_size), %l7
241 st %l6, [%l7 + %lo(pdma_size)]
243 /* Restore condition codes */
251 sethi %hi(pdma_vaddr), %l5
252 st %l4, [%l5 + %lo(pdma_vaddr)]
253 sethi %hi(pdma_size), %l5
254 st %l6, [%l5 + %lo(pdma_size)]
255 /* Prevent recursion */
256 sethi %hi(doing_pdma), %l7
257 st %g0, [%l7 + %lo(doing_pdma)]
259 /* fall through... */
264 /* Set all IRQs off. */
271 mov 11, %o0 ! floppy irq level (unused anyway)
272 mov %g0, %o1 ! devid is not used in fast interrupts
273 call sparc_floppy_irq
274 add %sp, STACKFRAME_SZ, %o2 ! struct pt_regs *regs
278 #endif /* (CONFIG_BLK_DEV_FD) */
280 /* Bad trap handler */
281 .globl bad_trap_handler
288 add %sp, STACKFRAME_SZ, %o0 ! pt_regs
290 mov %l7, %o1 ! trap number
294 /* For now all IRQ's not registered get sent here. handler_irq() will
295 * see if a routine is registered to handle this interrupt and if not
296 * it will say so on the console.
300 .globl real_irq_entry, patch_handler_irq
305 .globl patchme_maybe_smp_msg
308 patchme_maybe_smp_msg:
319 mov %l7, %o0 ! irq level
322 add %sp, STACKFRAME_SZ, %o1 ! pt_regs ptr
323 or %l0, PSR_PIL, %g2 ! restore PIL after handler_irq
324 wr %g2, PSR_ET, %psr ! keep ET up
330 /* SMP per-cpu ticker interrupts are handled specially. */
332 bne real_irq_continue+4
338 call smp4m_percpu_timer_interrupt
339 add %sp, STACKFRAME_SZ, %o0
344 /* Here is where we check for possible SMP IPI passed to us
345 * on some level other than 15 which is the NMI and only used
346 * for cross calls. That has a separate entry point below.
349 GET_PROCESSOR4M_ID(o3)
350 set sun4m_interrupts, %l5
352 sethi %hi(0x40000000), %o2
367 call smp_reschedule_irq
373 .globl linux_trap_ipi15_sun4m
374 linux_trap_ipi15_sun4m:
376 sethi %hi(0x80000000), %o2
377 GET_PROCESSOR4M_ID(o0)
378 set sun4m_interrupts, %l5
384 be 1f ! Must be an NMI async memory error
394 call smp4m_cross_call_irq
396 b ret_trap_lockless_ipi
399 /* NMI async memory error handling. */
400 sethi %hi(0x80000000), %l4
401 sethi %hi(0x4000), %o3
422 /* SMP per-cpu ticker interrupts are handled specially. */
426 sethi %hi(CC_ICLR), %o0
427 sethi %hi(1 << 14), %o1
428 or %o0, %lo(CC_ICLR), %o0
429 stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 14 in MXCC's ICLR */
434 call smp4d_percpu_timer_interrupt
435 add %sp, STACKFRAME_SZ, %o0
441 .globl linux_trap_ipi15_sun4d
442 linux_trap_ipi15_sun4d:
444 sethi %hi(CC_BASE), %o4
445 sethi %hi(MXCC_ERR_ME|MXCC_ERR_PEW|MXCC_ERR_ASE|MXCC_ERR_PEE), %o2
446 or %o4, (CC_EREG - CC_BASE), %o0
447 ldda [%o0] ASI_M_MXCC, %o0
450 sethi %hi(BB_STAT2), %o2
451 lduba [%o2] ASI_M_CTL, %o2
452 andcc %o2, BB_STAT2_MASK, %g0
454 or %o4, (CC_ICLR - CC_BASE), %o0
455 sethi %hi(1 << 15), %o1
456 stha %o1, [%o0] ASI_M_MXCC /* Clear PIL 15 in MXCC's ICLR */
462 call smp4d_cross_call_irq
464 b ret_trap_lockless_ipi
471 lduha [%l4] ASI_M_MXCC, %l5
472 sethi %hi(1 << 15), %l7
474 stha %l5, [%l4] ASI_M_MXCC
478 #endif /* CONFIG_SMP */
480 /* This routine handles illegal instructions and privileged
481 * instruction attempts from user code.
484 .globl bad_instruction
486 sethi %hi(0xc1f80000), %l4
488 sethi %hi(0x81d80000), %l7
494 wr %l0, PSR_ET, %psr ! re-enable traps
497 add %sp, STACKFRAME_SZ, %o0
500 call do_illegal_instruction
505 1: /* unimplemented flush - just skip */
510 .globl priv_instruction
517 add %sp, STACKFRAME_SZ, %o0
520 call do_priv_instruction
525 /* This routine handles unaligned data accesses. */
529 andcc %l0, PSR_PS, %g0
539 call kernel_unaligned_trap
540 add %sp, STACKFRAME_SZ, %o0
547 wr %l0, PSR_ET, %psr ! re-enable traps
551 call user_unaligned_trap
552 add %sp, STACKFRAME_SZ, %o0
556 /* This routine handles floating point disabled traps. */
558 .globl fpd_trap_handler
562 wr %l0, PSR_ET, %psr ! re-enable traps
565 add %sp, STACKFRAME_SZ, %o0
573 /* This routine handles Floating Point Exceptions. */
575 .globl fpe_trap_handler
577 set fpsave_magic, %l5
580 sethi %hi(fpsave), %l5
581 or %l5, %lo(fpsave), %l5
584 sethi %hi(fpsave_catch2), %l5
585 or %l5, %lo(fpsave_catch2), %l5
591 sethi %hi(fpsave_catch), %l5
592 or %l5, %lo(fpsave_catch), %l5
601 wr %l0, PSR_ET, %psr ! re-enable traps
604 add %sp, STACKFRAME_SZ, %o0
612 /* This routine handles Tag Overflow Exceptions. */
614 .globl do_tag_overflow
618 wr %l0, PSR_ET, %psr ! re-enable traps
621 add %sp, STACKFRAME_SZ, %o0
624 call handle_tag_overflow
629 /* This routine handles Watchpoint Exceptions. */
635 wr %l0, PSR_ET, %psr ! re-enable traps
638 add %sp, STACKFRAME_SZ, %o0
641 call handle_watchpoint
646 /* This routine handles Register Access Exceptions. */
652 wr %l0, PSR_ET, %psr ! re-enable traps
655 add %sp, STACKFRAME_SZ, %o0
658 call handle_reg_access
663 /* This routine handles Co-Processor Disabled Exceptions. */
665 .globl do_cp_disabled
669 wr %l0, PSR_ET, %psr ! re-enable traps
672 add %sp, STACKFRAME_SZ, %o0
675 call handle_cp_disabled
680 /* This routine handles Co-Processor Exceptions. */
682 .globl do_cp_exception
686 wr %l0, PSR_ET, %psr ! re-enable traps
689 add %sp, STACKFRAME_SZ, %o0
692 call handle_cp_exception
697 /* This routine handles Hardware Divide By Zero Exceptions. */
703 wr %l0, PSR_ET, %psr ! re-enable traps
706 add %sp, STACKFRAME_SZ, %o0
709 call handle_hw_divzero
715 .globl do_flush_windows
722 andcc %l0, PSR_PS, %g0
726 call flush_user_windows
729 /* Advance over the trap instruction. */
730 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1
732 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
733 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
737 .globl flush_patch_one
739 /* We get these for debugging routines using __builtin_return_address() */
742 FLUSH_ALL_KERNEL_WINDOWS
744 /* Advance over the trap instruction. */
745 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1
747 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
748 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
752 /* The getcc software trap. The user wants the condition codes from
753 * the %psr in register %g1.
757 .globl getcc_trap_handler
759 srl %l0, 20, %g1 ! give user
760 and %g1, 0xf, %g1 ! only ICC bits in %psr
761 jmp %l2 ! advance over trap instruction
762 rett %l2 + 0x4 ! like this...
764 /* The setcc software trap. The user has condition codes in %g1
765 * that it would like placed in the %psr. Be careful not to flip
766 * any unintentional bits!
770 .globl setcc_trap_handler
774 andn %l0, %l5, %l0 ! clear ICC bits in %psr
775 and %l4, %l5, %l4 ! clear non-ICC bits in user value
776 or %l4, %l0, %l4 ! or them in... mix mix mix
778 wr %l4, 0x0, %psr ! set new %psr
779 WRITE_PAUSE ! TI scumbags...
781 jmp %l2 ! advance over trap instruction
782 rett %l2 + 0x4 ! like this...
785 .globl linux_trap_nmi_sun4c
786 linux_trap_nmi_sun4c:
789 /* Ugh, we need to clear the IRQ line. This is now
790 * a very sun4c specific trap handler...
792 sethi %hi(interrupt_enable), %l5
793 ld [%l5 + %lo(interrupt_enable)], %l5
795 andn %l6, INTS_ENAB, %l6
798 /* Now it is safe to re-enable traps without recursion. */
803 /* Now call the c-code with the pt_regs frame ptr and the
804 * memory error registers as arguments. The ordering chosen
805 * here is due to unlatching semantics.
807 sethi %hi(AC_SYNC_ERR), %o0
809 lda [%o0] ASI_CONTROL, %o2 ! sync vaddr
811 lda [%o0] ASI_CONTROL, %o1 ! sync error
813 lda [%o0] ASI_CONTROL, %o4 ! async vaddr
815 lda [%o0] ASI_CONTROL, %o3 ! async error
817 add %sp, STACKFRAME_SZ, %o0
822 .globl invalid_segment_patch1_ff
823 .globl invalid_segment_patch2_ff
824 invalid_segment_patch1_ff: cmp %l4, 0xff
825 invalid_segment_patch2_ff: mov 0xff, %l3
828 .globl invalid_segment_patch1_1ff
829 .globl invalid_segment_patch2_1ff
830 invalid_segment_patch1_1ff: cmp %l4, 0x1ff
831 invalid_segment_patch2_1ff: mov 0x1ff, %l3
834 .globl num_context_patch1_16, num_context_patch2_16
835 num_context_patch1_16: mov 0x10, %l7
836 num_context_patch2_16: mov 0x10, %l7
839 .globl vac_linesize_patch_32
840 vac_linesize_patch_32: subcc %l7, 32, %l7
843 .globl vac_hwflush_patch1_on, vac_hwflush_patch2_on
846 * Ugly, but we cant use hardware flushing on the sun4 and we'd require
847 * two instructions (Anton)
850 vac_hwflush_patch1_on: nop
852 vac_hwflush_patch1_on: addcc %l7, -PAGE_SIZE, %l7
855 vac_hwflush_patch2_on: sta %g0, [%l3 + %l7] ASI_HWFLUSHSEG
857 .globl invalid_segment_patch1, invalid_segment_patch2
858 .globl num_context_patch1
859 .globl vac_linesize_patch, vac_hwflush_patch1
860 .globl vac_hwflush_patch2
869 ! %l7 = 1 for textfault
870 ! We want error in %l5, vaddr in %l6
873 sethi %hi(sun4c_memerr_reg), %l4
874 ld [%l4+%lo(sun4c_memerr_reg)], %l4 ! memerr ctrl reg addr
875 ld [%l4], %l6 ! memerr ctrl reg
876 ld [%l4 + 4], %l5 ! memerr vaddr reg
877 andcc %l6, 0x80, %g0 ! check for error type
878 st %g0, [%l4 + 4] ! clear the error
880 sethi %hi(AC_BUS_ERROR), %l4 ! bus err reg addr
882 call prom_halt ! something weird happened
883 ! what exactly did happen?
884 ! what should we do here?
886 0: or %l4, %lo(AC_BUS_ERROR), %l4 ! bus err reg addr
887 lduba [%l4] ASI_CONTROL, %l6 ! bus err reg
889 cmp %l7, 1 ! text fault?
893 ld [%l1], %l4 ! load instruction that caused fault
895 andcc %l4, 1, %g0 ! store instruction?
898 sethi %hi(SUN4C_SYNC_BADWRITE), %l4 ! yep
899 ! %lo(SUN4C_SYNC_BADWRITE) = 0
900 or %l4, %l6, %l6 ! set write bit to emulate sun4c
903 sethi %hi(AC_SYNC_ERR), %l4
904 add %l4, 0x4, %l6 ! AC_SYNC_VA in %l6
905 lda [%l6] ASI_CONTROL, %l5 ! Address
906 lda [%l4] ASI_CONTROL, %l6 ! Error, retained for a bit
909 andn %l5, 0xfff, %l5 ! Encode all info into l7
915 or %l4, %l7, %l7 ! l7 = [addr,write,txtfault]
917 andcc %l0, PSR_PS, %g0
918 be sun4c_fault_fromuser
919 andcc %l7, 1, %g0 ! Text fault?
922 sethi %hi(KERNBASE), %l4
928 blu sun4c_fault_fromuser
929 sethi %hi(~((1 << SUN4C_REAL_PGDIR_SHIFT) - 1)), %l4
931 /* If the kernel references a bum kernel pointer, or a pte which
932 * points to a non existant page in ram, we will run this code
933 * _forever_ and lock up the machine!!!!! So we must check for
934 * this condition, the AC_SYNC_ERR bits are what we must examine.
935 * Also a parity error would make this happen as well. So we just
936 * check that we are in fact servicing a tlb miss and not some
937 * other type of fault for the kernel.
940 be sun4c_fault_fromuser
943 /* Test for NULL pte_t * in vmalloc area. */
944 sethi %hi(VMALLOC_START), %l4
946 blu,a invalid_segment_patch1
947 lduXa [%l5] ASI_SEGMAP, %l4
949 sethi %hi(swapper_pg_dir), %l4
950 srl %l5, SUN4C_PGDIR_SHIFT, %l6
951 or %l4, %lo(swapper_pg_dir), %l4
955 sethi %hi(PAGE_MASK), %l6
958 andcc %l4, PAGE_MASK, %g0
960 be sun4c_fault_fromuser
961 lduXa [%l5] ASI_SEGMAP, %l4
963 invalid_segment_patch1:
966 sethi %hi(sun4c_kfree_ring), %l4
967 or %l4, %lo(sun4c_kfree_ring), %l4
969 deccc %l3 ! do we have a free entry?
970 bcs,a 2f ! no, unmap one.
971 sethi %hi(sun4c_kernel_ring), %l4
973 st %l3, [%l4 + 0x18] ! sun4c_kfree_ring.num_entries--
975 ld [%l4 + 0x00], %l6 ! entry = sun4c_kfree_ring.ringhd.next
976 st %l5, [%l6 + 0x08] ! entry->vaddr = address
978 ld [%l6 + 0x00], %l3 ! next = entry->next
979 ld [%l6 + 0x04], %l7 ! entry->prev
981 st %l7, [%l3 + 0x04] ! next->prev = entry->prev
982 st %l3, [%l7 + 0x00] ! entry->prev->next = next
984 sethi %hi(sun4c_kernel_ring), %l4
985 or %l4, %lo(sun4c_kernel_ring), %l4
986 ! head = &sun4c_kernel_ring.ringhd
988 ld [%l4 + 0x00], %l7 ! head->next
990 st %l4, [%l6 + 0x04] ! entry->prev = head
991 st %l7, [%l6 + 0x00] ! entry->next = head->next
992 st %l6, [%l7 + 0x04] ! head->next->prev = entry
994 st %l6, [%l4 + 0x00] ! head->next = entry
997 inc %l3 ! sun4c_kernel_ring.num_entries++
1000 ld [%l6 + 0x08], %l5
1003 or %l4, %lo(sun4c_kernel_ring), %l4
1004 ! head = &sun4c_kernel_ring.ringhd
1006 ld [%l4 + 0x04], %l6 ! entry = head->prev
1008 ld [%l6 + 0x08], %l3 ! tmp = entry->vaddr
1010 ! Flush segment from the cache.
1012 sethi %hi((128 * 1024)), %l7
1014 sethi %hi((64 * 1024)), %l7
1022 sta %g0, [%l3 + %l7] ASI_FLUSHSEG
1024 st %l5, [%l6 + 0x08] ! entry->vaddr = address
1026 ld [%l6 + 0x00], %l5 ! next = entry->next
1027 ld [%l6 + 0x04], %l7 ! entry->prev
1029 st %l7, [%l5 + 0x04] ! next->prev = entry->prev
1030 st %l5, [%l7 + 0x00] ! entry->prev->next = next
1031 st %l4, [%l6 + 0x04] ! entry->prev = head
1033 ld [%l4 + 0x00], %l7 ! head->next
1035 st %l7, [%l6 + 0x00] ! entry->next = head->next
1036 st %l6, [%l7 + 0x04] ! head->next->prev = entry
1037 st %l6, [%l4 + 0x00] ! head->next = entry
1039 mov %l3, %l5 ! address = tmp
1045 ld [%l6 + 0x08], %l4
1046 ldub [%l6 + 0x0c], %l3
1047 or %l4, %l3, %l4 ! encode new vaddr/pseg into l4
1049 sethi %hi(AC_CONTEXT), %l3
1050 lduba [%l3] ASI_CONTROL, %l6
1052 /* Invalidate old mapping, instantiate new mapping,
1053 * for each context. Registers l6/l7 are live across
1057 sethi %hi(AC_CONTEXT), %l3
1058 stba %l7, [%l3] ASI_CONTROL
1059 invalid_segment_patch2:
1061 stXa %l3, [%l5] ASI_SEGMAP
1062 andn %l4, 0x1ff, %l3
1064 stXa %l4, [%l3] ASI_SEGMAP
1066 sethi %hi(AC_CONTEXT), %l3
1067 stba %l6, [%l3] ASI_CONTROL
1069 andn %l4, 0x1ff, %l5
1072 sethi %hi(VMALLOC_START), %l4
1076 mov 1 << (SUN4C_REAL_PGDIR_SHIFT - PAGE_SHIFT), %l7
1078 sethi %hi(KERNBASE), %l6
1081 srl %l4, PAGE_SHIFT, %l4
1082 sethi %hi((SUN4C_PAGE_KERNEL & 0xf4000000)), %l3
1085 sethi %hi(PAGE_SIZE), %l4
1088 sta %l3, [%l5] ASI_PTE
1095 sethi %hi(sun4c_kernel_faults), %l4
1098 srl %l5, SUN4C_PGDIR_SHIFT, %l3
1099 sethi %hi(swapper_pg_dir), %l4
1100 or %l4, %lo(swapper_pg_dir), %l4
1104 and %l4, PAGE_MASK, %l4
1106 sethi %hi(PAGE_MASK), %l6
1110 srl %l5, (PAGE_SHIFT - 2), %l6
1111 and %l6, ((SUN4C_PTRS_PER_PTE - 1) << 2), %l6
1114 sethi %hi(PAGE_SIZE), %l4
1119 sta %l3, [%l5] ASI_PTE
1124 sethi %hi(sun4c_kernel_faults), %l4
1126 ld [%l4 + %lo(sun4c_kernel_faults)], %l3
1128 st %l3, [%l4 + %lo(sun4c_kernel_faults)]
1130 /* Restore condition codes */
1136 sun4c_fault_fromuser:
1140 mov %l7, %o1 ! Decode the info from %l7
1142 and %o1, 1, %o1 ! arg2 = text_faultp
1144 and %o2, 2, %o2 ! arg3 = writep
1145 andn %o3, 0xfff, %o3 ! arg4 = faulting address
1147 wr %l0, PSR_ET, %psr
1151 add %sp, STACKFRAME_SZ, %o0 ! arg1 = pt_regs ptr
1161 lda [%l5] ASI_M_MMUREGS, %l6 ! read sfar first
1162 lda [%l4] ASI_M_MMUREGS, %l5 ! read sfsr last
1164 andn %l6, 0xfff, %l6
1165 srl %l5, 6, %l5 ! and encode all info into l7
1170 or %l6, %l7, %l7 ! l7 = [addr,write,txtfault]
1176 and %o1, 1, %o1 ! arg2 = text_faultp
1178 and %o2, 2, %o2 ! arg3 = writep
1179 andn %o3, 0xfff, %o3 ! arg4 = faulting address
1181 wr %l0, PSR_ET, %psr
1185 add %sp, STACKFRAME_SZ, %o0 ! arg1 = pt_regs ptr
1189 #ifdef CONFIG_SUNOS_EMUL
1190 /* SunOS uses syscall zero as the 'indirect syscall' it looks
1191 * like indir_syscall(scall_num, arg0, arg1, arg2...); etc.
1192 * This is complete brain damage.
1197 cmp %o0, NR_SYSCALLS
1201 sethi %hi(sunos_nosys), %l6
1203 or %l6, %lo(sunos_nosys), %l6
1206 set sunos_sys_table, %l7
1220 .globl sys_nis_syscall
1223 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1224 call c_sys_nis_syscall
1231 add %sp, STACKFRAME_SZ, %o0
1233 ld [%curptr + TI_FLAGS], %l5
1234 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1248 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1256 add %sp, STACKFRAME_SZ, %o0 ! pt_regs *regs arg
1261 .globl sys_sigaltstack
1273 call do_sys_sigstack
1277 .globl sys_sigreturn
1280 add %sp, STACKFRAME_SZ, %o0
1282 ld [%curptr + TI_FLAGS], %l5
1283 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1291 /* We don't want to muck with user registers like a
1292 * normal syscall, just return.
1297 .globl sys_rt_sigreturn
1299 call do_rt_sigreturn
1300 add %sp, STACKFRAME_SZ, %o0
1302 ld [%curptr + TI_FLAGS], %l5
1303 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1311 /* We are returning to a signal handler. */
1314 /* Now that we have a real sys_clone, sys_fork() is
1315 * implemented in terms of it. Our _real_ implementation
1316 * of SunOS vfork() will use sys_vfork().
1318 * XXX These three should be consolidated into mostly shared
1319 * XXX code just like on sparc64... -DaveM
1322 .globl sys_fork, flush_patch_two
1326 FLUSH_ALL_KERNEL_WINDOWS;
1327 ld [%curptr + TI_TASK], %o4
1330 mov SIGCHLD, %o0 ! arg0: clone flags
1333 mov %fp, %o1 ! arg1: usp
1334 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1335 add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
1340 /* Whee, kernel threads! */
1341 .globl sys_clone, flush_patch_three
1345 FLUSH_ALL_KERNEL_WINDOWS;
1346 ld [%curptr + TI_TASK], %o4
1350 /* arg0,1: flags,usp -- loaded already */
1351 cmp %o1, 0x0 ! Is new_usp NULL?
1355 mov %fp, %o1 ! yes, use callers usp
1356 andn %o1, 7, %o1 ! no, align to 8 bytes
1358 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1359 add %sp, STACKFRAME_SZ, %o2 ! arg2: pt_regs ptr
1364 /* Whee, real vfork! */
1365 .globl sys_vfork, flush_patch_four
1368 FLUSH_ALL_KERNEL_WINDOWS;
1369 ld [%curptr + TI_TASK], %o4
1374 std %g4, [%o4 + AOFF_task_thread + AOFF_thread_fork_kpsr]
1375 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1377 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1378 sethi %hi(sparc_do_fork), %l1
1380 jmpl %l1 + %lo(sparc_do_fork), %g0
1381 add %sp, STACKFRAME_SZ, %o2
1384 linux_sparc_ni_syscall:
1385 sethi %hi(sys_ni_syscall), %l7
1386 b syscall_is_too_hard
1387 or %l7, %lo(sys_ni_syscall), %l7
1397 linux_syscall_trace:
1407 .globl ret_from_fork
1412 ld [%sp + STACKFRAME_SZ + PT_I0], %o0
1414 /* Linux native and SunOS system calls enter here... */
1416 .globl linux_sparc_syscall
1417 linux_sparc_syscall:
1418 /* Direct access to user regs, must faster. */
1419 cmp %g1, NR_SYSCALLS
1420 bgeu linux_sparc_ni_syscall
1424 bne linux_fast_syscall
1425 /* Just do first insn from SAVE_ALL in the delay slot */
1427 .globl syscall_is_too_hard
1428 syscall_is_too_hard:
1432 wr %l0, PSR_ET, %psr
1437 ld [%curptr + TI_FLAGS], %l5
1439 andcc %l5, _TIF_SYSCALL_TRACE, %g0
1441 bne linux_syscall_trace
1447 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1451 ld [%curptr + TI_FLAGS], %l6
1452 cmp %o0, -ERESTART_RESTARTBLOCK
1453 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1456 andcc %l6, _TIF_SYSCALL_TRACE, %g0
1458 /* System call success, clear Carry condition code. */
1461 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1462 bne linux_syscall_trace2
1463 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1464 add %l1, 0x4, %l2 /* npc = npc+4 */
1465 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1467 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1469 /* System call failure, set Carry condition code.
1470 * Also, get abs(errno) to return to the process.
1474 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1476 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1477 bne linux_syscall_trace2
1478 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1479 add %l1, 0x4, %l2 /* npc = npc+4 */
1480 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1482 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1484 linux_syscall_trace2:
1486 add %l1, 0x4, %l2 /* npc = npc+4 */
1487 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1489 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1493 * Solaris system calls and indirect system calls enter here.
1495 * I have named the solaris indirect syscalls like that because
1496 * it seems like Solaris has some fast path syscalls that can
1497 * be handled as indirect system calls. - mig
1500 linux_syscall_for_solaris:
1501 sethi %hi(sys_call_table), %l7
1502 b linux_sparc_syscall
1503 or %l7, %lo(sys_call_table), %l7
1506 .globl solaris_syscall
1509 be linux_syscall_for_solaris
1511 be linux_syscall_for_solaris
1513 be linux_syscall_for_solaris
1515 be,a linux_syscall_for_solaris
1521 wr %l0, PSR_ET, %psr
1526 call do_solaris_syscall
1527 add %sp, STACKFRAME_SZ, %o0
1529 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1531 cmp %o0, -ERESTART_RESTARTBLOCK
1533 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1535 /* System call success, clear Carry condition code. */
1539 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1542 /* System call failure, set Carry condition code.
1543 * Also, get abs(errno) to return to the process.
1547 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1549 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1551 /* Advance the pc and npc over the trap instruction.
1552 * If the npc is unaligned (has a 1 in the lower byte), it means
1553 * the kernel does not want us to play magic (ie, skipping over
1554 * traps). Mainly when the Solaris code wants to set some PC and
1558 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1561 add %l1, 0x4, %l2 /* npc = npc+4 */
1562 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1564 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1566 /* kernel knows what it is doing, fixup npc and continue */
1570 st %l1, [%sp + STACKFRAME_SZ + PT_NPC]
1572 #ifndef CONFIG_SUNOS_EMUL
1574 .globl sunos_syscall
1578 wr %l0, PSR_ET, %psr
1582 call do_sunos_syscall
1583 add %sp, STACKFRAME_SZ, %o0
1586 /* {net, open}bsd system calls enter here... */
1590 /* Direct access to user regs, must faster. */
1591 cmp %g1, NR_SYSCALLS
1595 set sys_ni_syscall, %l7
1602 .globl bsd_is_too_hard
1607 wr %l0, PSR_ET, %psr
1620 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1622 cmp %o0, -ERESTART_RESTARTBLOCK
1624 ld [%sp + STACKFRAME_SZ + PT_PSR], %g3
1626 /* System call success, clear Carry condition code. */
1630 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1633 /* System call failure, set Carry condition code.
1634 * Also, get abs(errno) to return to the process.
1637 #if 0 /* XXX todo XXX */
1638 sethi %hi(bsd_xlatb_rorl), %o3
1639 or %o3, %lo(bsd_xlatb_rorl), %o3
1644 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1646 st %g3, [%sp + STACKFRAME_SZ + PT_PSR]
1648 /* Advance the pc and npc over the trap instruction. */
1650 ld [%sp + STACKFRAME_SZ + PT_NPC], %l1 /* pc = npc */
1651 add %l1, 0x4, %l2 /* npc = npc+4 */
1652 st %l1, [%sp + STACKFRAME_SZ + PT_PC]
1654 st %l2, [%sp + STACKFRAME_SZ + PT_NPC]
1656 /* Saving and restoring the FPU state is best done from lowlevel code.
1658 * void fpsave(unsigned long *fpregs, unsigned long *fsr,
1659 * void *fpqueue, unsigned long *fpqdepth)
1664 st %fsr, [%o1] ! this can trap on us if fpu is in bogon state
1671 /* We have an fpqueue to save. */
1685 std %f0, [%o0 + 0x00]
1686 std %f2, [%o0 + 0x08]
1687 std %f4, [%o0 + 0x10]
1688 std %f6, [%o0 + 0x18]
1689 std %f8, [%o0 + 0x20]
1690 std %f10, [%o0 + 0x28]
1691 std %f12, [%o0 + 0x30]
1692 std %f14, [%o0 + 0x38]
1693 std %f16, [%o0 + 0x40]
1694 std %f18, [%o0 + 0x48]
1695 std %f20, [%o0 + 0x50]
1696 std %f22, [%o0 + 0x58]
1697 std %f24, [%o0 + 0x60]
1698 std %f26, [%o0 + 0x68]
1699 std %f28, [%o0 + 0x70]
1701 std %f30, [%o0 + 0x78]
1703 /* Thanks for Theo Deraadt and the authors of the Sprite/netbsd/openbsd
1704 * code for pointing out this possible deadlock, while we save state
1705 * above we could trap on the fsr store so our low level fpu trap
1706 * code has to know how to deal with this.
1716 /* void fpload(unsigned long *fpregs, unsigned long *fsr); */
1720 ldd [%o0 + 0x00], %f0
1721 ldd [%o0 + 0x08], %f2
1722 ldd [%o0 + 0x10], %f4
1723 ldd [%o0 + 0x18], %f6
1724 ldd [%o0 + 0x20], %f8
1725 ldd [%o0 + 0x28], %f10
1726 ldd [%o0 + 0x30], %f12
1727 ldd [%o0 + 0x38], %f14
1728 ldd [%o0 + 0x40], %f16
1729 ldd [%o0 + 0x48], %f18
1730 ldd [%o0 + 0x50], %f20
1731 ldd [%o0 + 0x58], %f22
1732 ldd [%o0 + 0x60], %f24
1733 ldd [%o0 + 0x68], %f26
1734 ldd [%o0 + 0x70], %f28
1735 ldd [%o0 + 0x78], %f30
1740 /* __ndelay and __udelay take two arguments:
1741 * 0 - nsecs or usecs to delay
1742 * 1 - per_cpu udelay_val (loops per jiffy)
1744 * Note that ndelay gives HZ times higher resolution but has a 10ms
1745 * limit. udelay can handle up to 1s.
1749 save %sp, -STACKFRAME_SZ, %sp
1751 call .umul ! round multiplier up so large ns ok
1752 mov 0x1ae, %o1 ! 2**32 / (1 000 000 000 / HZ)
1754 mov %i1, %o1 ! udelay_val
1756 mov %o1, %o0 ! >>32 later for better resolution
1760 save %sp, -STACKFRAME_SZ, %sp
1762 sethi %hi(0x10c7), %o1 ! round multiplier up so large us ok
1764 or %o1, %lo(0x10c7), %o1 ! 2**32 / 1 000 000
1766 mov %i1, %o1 ! udelay_val
1767 sethi %hi(0x028f4b62), %l0 ! Add in rounding constant * 2**32,
1768 or %g0, %lo(0x028f4b62), %l0
1769 addcc %o0, %l0, %o0 ! 2**32 * 0.009 999
1774 mov HZ, %o0 ! >>32 earlier for wider range
1785 /* Handle a software breakpoint */
1786 /* We have to inform parent that child has stopped */
1788 .globl breakpoint_trap
1792 wr %l0, PSR_ET, %psr
1795 st %i0, [%sp + STACKFRAME_SZ + PT_G0] ! for restarting syscalls
1796 call sparc_breakpoint
1797 add %sp, STACKFRAME_SZ, %o0
1802 .globl __handle_exception, flush_patch_exception
1804 flush_patch_exception:
1805 FLUSH_ALL_KERNEL_WINDOWS;
1807 jmpl %o7 + 0xc, %g0 ! see asm-sparc/processor.h
1808 mov 1, %g1 ! signal EFAULT condition
1811 .globl kill_user_windows, kuw_patch1_7win
1813 kuw_patch1_7win: sll %o3, 6, %o3
1815 /* No matter how much overhead this routine has in the worst
1816 * case scenerio, it is several times better than taking the
1817 * traps with the old method of just doing flush_user_windows().
1820 ld [%g6 + TI_UWINMASK], %o0 ! get current umask
1821 orcc %g0, %o0, %g0 ! if no bits set, we are done
1822 be 3f ! nothing to do
1823 rd %psr, %o5 ! must clear interrupts
1824 or %o5, PSR_PIL, %o4 ! or else that could change
1825 wr %o4, 0x0, %psr ! the uwinmask state
1826 WRITE_PAUSE ! burn them cycles
1828 ld [%g6 + TI_UWINMASK], %o0 ! get consistent state
1829 orcc %g0, %o0, %g0 ! did an interrupt come in?
1830 be 4f ! yep, we are done
1831 rd %wim, %o3 ! get current wim
1832 srl %o3, 1, %o4 ! simulate a save
1834 sll %o3, 7, %o3 ! compute next wim
1835 or %o4, %o3, %o3 ! result
1836 andncc %o0, %o3, %o0 ! clean this bit in umask
1837 bne kuw_patch1 ! not done yet
1838 srl %o3, 1, %o4 ! begin another save simulation
1839 wr %o3, 0x0, %wim ! set the new wim
1840 st %g0, [%g6 + TI_UWINMASK] ! clear uwinmask
1842 wr %o5, 0x0, %psr ! re-enable interrupts
1843 WRITE_PAUSE ! burn baby burn
1846 st %g0, [%g6 + TI_W_SAVED] ! no windows saved
1849 .globl restore_current
1851 LOAD_CURRENT(g6, o0)
1856 #include <asm/pcic.h>
1859 .globl linux_trap_ipi15_pcic
1860 linux_trap_ipi15_pcic:
1865 * First deactivate NMI
1866 * or we cannot drop ET, cannot get window spill traps.
1867 * The busy loop is necessary because the PIO error
1868 * sometimes does not go away quickly and we trap again.
1870 sethi %hi(pcic_regs), %o1
1871 ld [%o1 + %lo(pcic_regs)], %o2
1873 ! Get pending status for printouts later.
1874 ld [%o2 + PCI_SYS_INT_PENDING], %o0
1876 mov PCI_SYS_INT_PENDING_CLEAR_ALL, %o1
1877 stb %o1, [%o2 + PCI_SYS_INT_PENDING_CLEAR]
1879 ld [%o2 + PCI_SYS_INT_PENDING], %o1
1880 andcc %o1, ((PCI_SYS_INT_PENDING_PIO|PCI_SYS_INT_PENDING_PCI)>>24), %g0
1884 or %l0, PSR_PIL, %l4
1887 wr %l4, PSR_ET, %psr
1891 add %sp, STACKFRAME_SZ, %o1 ! struct pt_regs *regs
1894 .globl pcic_nmi_trap_patch
1895 pcic_nmi_trap_patch:
1896 sethi %hi(linux_trap_ipi15_pcic), %l3
1897 jmpl %l3 + %lo(linux_trap_ipi15_pcic), %g0
1901 #endif /* CONFIG_PCI */
1903 /* End of entry.S */