1 /* SPDX-License-Identifier: GPL-2.0-or-later */
7 * Adapted for Power Macintosh by Paul Mackerras.
8 * Low-level exception handlers and MMU support
9 * rewritten by Paul Mackerras.
10 * Copyright (C) 1996 Paul Mackerras.
13 * This file contains the system call entry code, context switch
14 * code, and exception/interrupt return code for PowerPC.
17 #include <linux/errno.h>
18 #include <linux/err.h>
19 #include <linux/sys.h>
20 #include <linux/threads.h>
24 #include <asm/cputable.h>
25 #include <asm/thread_info.h>
26 #include <asm/ppc_asm.h>
27 #include <asm/asm-offsets.h>
28 #include <asm/unistd.h>
29 #include <asm/ptrace.h>
30 #include <asm/export.h>
31 #include <asm/asm-405.h>
32 #include <asm/feature-fixups.h>
33 #include <asm/barrier.h>
40 * Align to 4k in order to ensure that all functions modyfing srr0/srr1
41 * fit into one page in order to not encounter a TLB miss between the
42 * modification of srr0/srr1 and the associated rfi.
47 .globl mcheck_transfer_to_handler
48 mcheck_transfer_to_handler:
55 .globl debug_transfer_to_handler
56 debug_transfer_to_handler:
63 .globl crit_transfer_to_handler
64 crit_transfer_to_handler:
65 #ifdef CONFIG_PPC_BOOK3E_MMU
76 #ifdef CONFIG_PHYS_64BIT
79 #endif /* CONFIG_PHYS_64BIT */
80 #endif /* CONFIG_PPC_BOOK3E_MMU */
90 /* set the stack limit to the current stack */
91 mfspr r8,SPRN_SPRG_THREAD
93 stw r0,SAVED_KSP_LIMIT(r11)
94 rlwinm r0,r1,0,0,(31 - THREAD_SHIFT)
100 .globl crit_transfer_to_handler
101 crit_transfer_to_handler:
107 stw r0,crit_srr0@l(0)
109 stw r0,crit_srr1@l(0)
111 /* set the stack limit to the current stack */
112 mfspr r8,SPRN_SPRG_THREAD
114 stw r0,saved_ksp_limit@l(0)
115 rlwinm r0,r1,0,0,(31 - THREAD_SHIFT)
121 * This code finishes saving the registers to the exception frame
122 * and jumps to the appropriate handler for the exception, turning
123 * on address translation.
124 * Note that we rely on the caller having set cr0.eq iff the exception
125 * occurred in kernel mode (i.e. MSR:PR = 0).
127 .globl transfer_to_handler_full
128 transfer_to_handler_full:
132 .globl transfer_to_handler
142 mfspr r12,SPRN_SPRG_THREAD
143 beq 2f /* if from user, fix up THREAD.regs */
144 addi r2, r12, -THREAD
145 addi r11,r1,STACK_FRAME_OVERHEAD
147 #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
148 /* Check to see if the dbcr0 register is set up to debug. Use the
149 internal debug mode bit to do this. */
150 lwz r12,THREAD_DBCR0(r12)
151 andis. r12,r12,DBCR0_IDM@h
153 ACCOUNT_CPU_USER_ENTRY(r2, r11, r12)
154 #ifdef CONFIG_PPC_BOOK3S_32
157 #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
159 /* From user and task is ptraced - load up global dbcr0 */
160 li r12,-1 /* clear all pending debug events */
162 lis r11,global_dbcr0@ha
164 addi r11,r11,global_dbcr0@l
179 2: /* if from kernel, check interrupted DOZE/NAP mode and
180 * check for stack overflow
182 kuap_save_and_lock r11, r12, r9, r2, r0
183 addi r2, r12, -THREAD
184 lwz r9,KSP_LIMIT(r12)
185 cmplw r1,r9 /* if r1 <= ksp_limit */
186 ble- stack_ovf /* then the kernel stack overflowed */
188 #if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_E500)
189 lwz r12,TI_LOCAL_FLAGS(r2)
191 bt- 31-TLF_NAPPING,4f
192 bt- 31-TLF_SLEEPING,7f
193 #endif /* CONFIG_PPC_BOOK3S_32 || CONFIG_E500 */
194 .globl transfer_to_handler_cont
195 transfer_to_handler_cont:
198 tovirt(r2, r2) /* set r2 to current */
199 lwz r11,0(r9) /* virtual address of handler */
200 lwz r9,4(r9) /* where to go when done */
201 #if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
204 #ifdef CONFIG_TRACE_IRQFLAGS
206 * When tracing IRQ state (lockdep) we enable the MMU before we call
207 * the IRQ tracing functions as they might access vmalloc space or
208 * perform IOs for console output.
210 * To speed up the syscall path where interrupts stay on, let's check
211 * first if we are changing the MSR value at all.
218 /* MSR isn't changing, just transition directly */
224 RFI /* jump to handler, enable MMU */
226 #ifdef CONFIG_TRACE_IRQFLAGS
227 1: /* MSR is changing, re-enable MMU so we can notify lockdep. We need to
228 * keep interrupts disabled at this point otherwise we might risk
229 * taking an interrupt before we tell lockdep they are enabled.
231 lis r12,reenable_mmu@h
232 ori r12,r12,reenable_mmu@l
233 LOAD_MSR_KERNEL(r0, MSR_KERNEL)
241 * We save a bunch of GPRs,
242 * r3 can be different from GPR3(r1) at this point, r9 and r11
243 * contains the old MSR and handler address respectively,
244 * r4 & r5 can contain page fault arguments that need to be passed
245 * along as well. r12, CCR, CTR, XER etc... are left clobbered as
246 * they aren't useful past this point (aren't syscall arguments),
247 * the rest is restored from the exception frame.
257 /* If we are disabling interrupts (normal case), simply log it with
260 1: bl trace_hardirqs_off
273 bctr /* jump to handler */
274 #endif /* CONFIG_TRACE_IRQFLAGS */
276 #if defined (CONFIG_PPC_BOOK3S_32) || defined(CONFIG_E500)
277 4: rlwinm r12,r12,0,~_TLF_NAPPING
278 stw r12,TI_LOCAL_FLAGS(r2)
279 b power_save_ppc32_restore
281 7: rlwinm r12,r12,0,~_TLF_SLEEPING
282 stw r12,TI_LOCAL_FLAGS(r2)
283 lwz r9,_MSR(r11) /* if sleeping, clear MSR.EE */
284 rlwinm r9,r9,0,~MSR_EE
285 lwz r12,_LINK(r11) /* and return to address in LR */
286 kuap_restore r11, r2, r3, r4, r5
287 b fast_exception_return
291 * On kernel stack overflow, load up an initial stack pointer
292 * and call StackOverflow(regs), which should not return.
295 /* sometimes we use a statically-allocated stack, which is OK. */
299 ble 5b /* r1 <= &_end is OK */
301 addi r3,r1,STACK_FRAME_OVERHEAD
302 lis r1,init_thread_union@ha
303 addi r1,r1,init_thread_union@l
304 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
305 lis r9,StackOverflow@ha
306 addi r9,r9,StackOverflow@l
307 LOAD_MSR_KERNEL(r10,MSR_KERNEL)
308 #if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
316 #ifdef CONFIG_TRACE_IRQFLAGS
317 trace_syscall_entry_irq_off:
319 * Syscall shouldn't happen while interrupts are disabled,
320 * so let's do a warning here.
323 EMIT_BUG_ENTRY 0b,__FILE__,__LINE__, BUGFLAG_WARNING
326 /* Now enable for real */
327 LOAD_MSR_KERNEL(r10, MSR_KERNEL | MSR_EE)
334 #endif /* CONFIG_TRACE_IRQFLAGS */
336 .globl transfer_to_syscall
338 #ifdef CONFIG_TRACE_IRQFLAGS
340 beq- trace_syscall_entry_irq_off
341 #endif /* CONFIG_TRACE_IRQFLAGS */
344 * Handle a system call.
346 .stabs "arch/powerpc/kernel/",N_SO,0,0,0f
347 .stabs "entry_32.S",N_SO,0,0,0f
354 #ifdef CONFIG_TRACE_IRQFLAGS
355 /* Make sure interrupts are enabled */
358 /* We came in with interrupts disabled, we WARN and mark them enabled
361 EMIT_BUG_ENTRY 0b,__FILE__,__LINE__, BUGFLAG_WARNING
362 #endif /* CONFIG_TRACE_IRQFLAGS */
364 andi. r11,r11,_TIF_SYSCALL_DOTRACE
366 syscall_dotrace_cont:
367 cmplwi 0,r0,NR_syscalls
368 lis r10,sys_call_table@h
369 ori r10,r10,sys_call_table@l
375 * Prevent the load of the handler below (based on the user-passed
376 * system call number) being speculatively executed until the test
377 * against NR_syscalls and branch to .66f above has
381 lwzx r10,r10,r0 /* Fetch system call handler [ptr] */
383 addi r9,r1,STACK_FRAME_OVERHEAD
385 blrl /* Call handler */
386 .globl ret_from_syscall
388 #ifdef CONFIG_DEBUG_RSEQ
389 /* Check whether the syscall is issued inside a restartable sequence */
391 addi r3,r1,STACK_FRAME_OVERHEAD
396 /* disable interrupts so current_thread_info()->flags can't change */
397 LOAD_MSR_KERNEL(r10,MSR_KERNEL) /* doesn't include MSR_EE */
398 /* Note: We don't bother telling lockdep about it */
403 andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
404 bne- syscall_exit_work
406 blt+ syscall_exit_cont
407 lwz r11,_CCR(r1) /* Load CR */
409 oris r11,r11,0x1000 /* Set SO bit in CR */
413 #ifdef CONFIG_TRACE_IRQFLAGS
414 /* If we are going to return from the syscall with interrupts
415 * off, we trace that here. It shouldn't normally happen.
420 bl trace_hardirqs_off
423 #endif /* CONFIG_TRACE_IRQFLAGS */
424 #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
425 /* If the process has its own DBCR0 value, load it up. The internal
426 debug mode bit tells us that dbcr0 should be loaded. */
427 lwz r0,THREAD+THREAD_DBCR0(r2)
428 andis. r10,r0,DBCR0_IDM@h
432 BEGIN_MMU_FTR_SECTION
433 lis r4,icache_44x_need_flush@ha
434 lwz r5,icache_44x_need_flush@l(r4)
438 END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_47x)
439 #endif /* CONFIG_44x */
442 END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
443 stwcx. r0,0,r1 /* to clear the reservation */
444 ACCOUNT_CPU_USER_EXIT(r2, r5, r7)
445 #ifdef CONFIG_PPC_BOOK3S_32
456 #if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
466 stw r7,icache_44x_need_flush@l(r4)
468 #endif /* CONFIG_44x */
480 .globl ret_from_kernel_thread
481 ret_from_kernel_thread:
491 /* Traced system call support */
496 addi r3,r1,STACK_FRAME_OVERHEAD
497 bl do_syscall_trace_enter
499 * Restore argument registers possibly just changed.
500 * We use the return value of do_syscall_trace_enter
501 * for call number to look up in the table (r0).
512 cmplwi r0,NR_syscalls
513 /* Return code is already in r3 thanks to do_syscall_trace_enter() */
514 bge- ret_from_syscall
515 b syscall_dotrace_cont
518 andi. r0,r9,_TIF_RESTOREALL
524 andi. r0,r9,_TIF_NOERROR
526 lwz r11,_CCR(r1) /* Load CR */
528 oris r11,r11,0x1000 /* Set SO bit in CR */
531 1: stw r6,RESULT(r1) /* Save result */
532 stw r3,GPR3(r1) /* Update return value */
533 2: andi. r0,r9,(_TIF_PERSYSCALL_MASK)
536 /* Clear per-syscall TIF flags if any are set. */
538 li r11,_TIF_PERSYSCALL_MASK
542 #ifdef CONFIG_IBM405_ERR77
548 4: /* Anything which requires enabling interrupts? */
549 andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP)
552 /* Re-enable interrupts. There is no need to trace that with
553 * lockdep as we are supposed to have IRQs on at this point
559 /* Save NVGPRS if they're not saved already */
567 addi r3,r1,STACK_FRAME_OVERHEAD
568 bl do_syscall_trace_leave
569 b ret_from_except_full
572 * The fork/clone functions need to copy the full register set into
573 * the child process. Therefore we need to save all the nonvolatile
574 * registers (r13 - r31) before calling the C code.
580 rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
581 stw r0,_TRAP(r1) /* register set saved */
588 rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
589 stw r0,_TRAP(r1) /* register set saved */
596 rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
597 stw r0,_TRAP(r1) /* register set saved */
600 .globl ppc_swapcontext
604 rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
605 stw r0,_TRAP(r1) /* register set saved */
609 * Top-level page fault handling.
610 * This is in assembler because if do_page_fault tells us that
611 * it is a bad kernel page fault, we want to save the non-volatile
612 * registers before calling bad_page_fault.
614 .globl handle_page_fault
617 addi r3,r1,STACK_FRAME_OVERHEAD
618 #ifdef CONFIG_PPC_BOOK3S_32
619 andis. r0,r5,DSISR_DABRMATCH@h
620 bne- handle_dabr_fault
630 addi r3,r1,STACK_FRAME_OVERHEAD
633 b ret_from_except_full
635 #ifdef CONFIG_PPC_BOOK3S_32
636 /* We have a data breakpoint exception - handle it */
643 b ret_from_except_full
647 * This routine switches between two different tasks. The process
648 * state of one is saved on its kernel stack. Then the state
649 * of the other is restored from its kernel stack. The memory
650 * management hardware is updated to the second process's state.
651 * Finally, we can return to the second process.
652 * On entry, r3 points to the THREAD for the current task, r4
653 * points to the THREAD for the new task.
655 * This routine is always called with interrupts disabled.
657 * Note: there are two ways to get to the "going out" portion
658 * of this code; either by coming in via the entry (_switch)
659 * or via "fork" which must set up an environment equivalent
660 * to the "_switch" path. If you change this , you'll have to
661 * change the fork code also.
663 * The code which creates the new task context is in 'copy_thread'
664 * in arch/ppc/kernel/process.c
667 stwu r1,-INT_FRAME_SIZE(r1)
669 stw r0,INT_FRAME_SIZE+4(r1)
670 /* r3-r12 are caller saved -- Cort */
672 stw r0,_NIP(r1) /* Return to switch caller */
674 li r0,MSR_FP /* Disable floating-point */
675 #ifdef CONFIG_ALTIVEC
677 oris r0,r0,MSR_VEC@h /* Disable altivec */
678 mfspr r12,SPRN_VRSAVE /* save vrsave register value */
679 stw r12,THREAD+THREAD_VRSAVE(r2)
680 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
681 #endif /* CONFIG_ALTIVEC */
684 oris r0,r0,MSR_SPE@h /* Disable SPE */
685 mfspr r12,SPRN_SPEFSCR /* save spefscr register value */
686 stw r12,THREAD+THREAD_SPEFSCR(r2)
687 END_FTR_SECTION_IFSET(CPU_FTR_SPE)
688 #endif /* CONFIG_SPE */
689 and. r0,r0,r11 /* FP or altivec or SPE enabled? */
697 stw r1,KSP(r3) /* Set old stack pointer */
701 /* We need a sync somewhere here to make sure that if the
702 * previous task gets rescheduled on another CPU, it sees all
703 * stores it has performed on this one.
706 #endif /* CONFIG_SMP */
709 mtspr SPRN_SPRG_THREAD,r0 /* Update current THREAD phys addr */
710 lwz r1,KSP(r4) /* Load new stack pointer */
712 /* save the old current 'last' for return value */
714 addi r2,r4,-THREAD /* Update current */
716 #ifdef CONFIG_ALTIVEC
718 lwz r0,THREAD+THREAD_VRSAVE(r2)
719 mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */
720 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
721 #endif /* CONFIG_ALTIVEC */
724 lwz r0,THREAD+THREAD_SPEFSCR(r2)
725 mtspr SPRN_SPEFSCR,r0 /* restore SPEFSCR reg */
726 END_FTR_SECTION_IFSET(CPU_FTR_SPE)
727 #endif /* CONFIG_SPE */
731 /* r3-r12 are destroyed -- Cort */
734 lwz r4,_NIP(r1) /* Return to _switch caller in new task */
736 addi r1,r1,INT_FRAME_SIZE
739 .globl fast_exception_return
740 fast_exception_return:
741 #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
742 andi. r10,r9,MSR_RI /* check for recoverable interrupt */
743 beq 1f /* if not, we've got problems */
746 2: REST_4GPRS(3, r11)
752 /* Clear the exception_marker on the stack to avoid confusing stacktrace */
756 #if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
767 #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
768 /* check if the exception happened in a restartable section */
769 1: lis r3,exc_exit_restart_end@ha
770 addi r3,r3,exc_exit_restart_end@l
773 lis r4,exc_exit_restart@ha
774 addi r4,r4,exc_exit_restart@l
777 lis r3,fee_restarts@ha
779 lwz r5,fee_restarts@l(r3)
781 stw r5,fee_restarts@l(r3)
782 mr r12,r4 /* restart at exc_exit_restart */
791 /* aargh, a nonrecoverable interrupt, panic */
792 /* aargh, we don't know which trap this is */
793 /* but the 601 doesn't implement the RI bit, so assume it's OK */
797 END_FTR_SECTION_IFSET(CPU_FTR_601)
800 addi r3,r1,STACK_FRAME_OVERHEAD
802 ori r10,r10,MSR_KERNEL@l
803 bl transfer_to_handler_full
804 .long unrecoverable_exception
805 .long ret_from_except
808 .globl ret_from_except_full
809 ret_from_except_full:
813 .globl ret_from_except
815 /* Hard-disable interrupts so that current_thread_info()->flags
816 * can't change between when we test it and when we return
817 * from the interrupt. */
818 /* Note: We don't bother telling lockdep about it */
819 LOAD_MSR_KERNEL(r10,MSR_KERNEL)
820 SYNC /* Some chip revs have problems here... */
821 MTMSRD(r10) /* disable interrupts */
823 lwz r3,_MSR(r1) /* Returning to user mode? */
827 user_exc_return: /* r10 contains MSR_KERNEL here */
828 /* Check current_thread_info()->flags */
830 andi. r0,r9,_TIF_USER_WORK_MASK
834 #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
835 /* Check whether this process has its own DBCR0 value. The internal
836 debug mode bit tells us that dbcr0 should be loaded. */
837 lwz r0,THREAD+THREAD_DBCR0(r2)
838 andis. r10,r0,DBCR0_IDM@h
841 ACCOUNT_CPU_USER_EXIT(r2, r10, r11)
842 #ifdef CONFIG_PPC_BOOK3S_32
848 /* N.B. the only way to get here is from the beq following ret_from_except. */
850 /* check current_thread_info, _TIF_EMULATE_STACK_STORE */
852 andis. r0,r8,_TIF_EMULATE_STACK_STORE@h
855 addi r8,r1,INT_FRAME_SIZE /* Get the kprobed function entry */
858 subi r3,r3,INT_FRAME_SIZE /* dst: Allocate a trampoline exception frame */
859 mr r4,r1 /* src: current exception frame */
860 mr r1,r3 /* Reroute the trampoline frame to r1 */
862 /* Copy from the original to the trampoline. */
863 li r5,INT_FRAME_SIZE/4 /* size: INT_FRAME_SIZE */
864 li r6,0 /* start offset: 0 */
871 /* Do real store operation to complete stwu */
875 /* Clear _TIF_EMULATE_STACK_STORE flag */
876 lis r11,_TIF_EMULATE_STACK_STORE@h
880 #ifdef CONFIG_IBM405_ERR77
887 #ifdef CONFIG_PREEMPT
888 /* check current_thread_info->preempt_count */
889 lwz r0,TI_PREEMPT(r2)
890 cmpwi 0,r0,0 /* if non-zero, just restore regs and return */
892 andi. r8,r8,_TIF_NEED_RESCHED
895 andi. r0,r3,MSR_EE /* interrupts off? */
896 beq restore_kuap /* don't schedule if so */
897 #ifdef CONFIG_TRACE_IRQFLAGS
898 /* Lockdep thinks irqs are enabled, we need to call
899 * preempt_schedule_irq with IRQs off, so we inform lockdep
900 * now that we -did- turn them off already
902 bl trace_hardirqs_off
904 bl preempt_schedule_irq
905 #ifdef CONFIG_TRACE_IRQFLAGS
906 /* And now, to properly rebalance the above, we tell lockdep they
907 * are being turned back on, which will happen when we return
911 #endif /* CONFIG_PREEMPT */
913 kuap_restore r1, r2, r9, r10, r0
915 /* interrupts are hard-disabled at this point */
918 BEGIN_MMU_FTR_SECTION
920 END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_47x)
921 lis r4,icache_44x_need_flush@ha
922 lwz r5,icache_44x_need_flush@l(r4)
927 stw r6,icache_44x_need_flush@l(r4)
929 #endif /* CONFIG_44x */
932 #ifdef CONFIG_TRACE_IRQFLAGS
933 /* Lockdep doesn't know about the fact that IRQs are temporarily turned
934 * off in this assembly code while peeking at TI_FLAGS() and such. However
935 * we need to inform it if the exception turned interrupts off, and we
936 * are about to trun them back on.
947 #endif /* CONFIG_TRACE_IRQFLAGS */
962 END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
963 stwcx. r0,0,r1 /* to clear the reservation */
965 #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
966 andi. r10,r9,MSR_RI /* check if this exception occurred */
967 beql nonrecoverable /* at a bad place (MSR:RI = 0) */
974 /* Clear the exception_marker on the stack to avoid confusing stacktrace */
978 * Once we put values in SRR0 and SRR1, we are in a state
979 * where exceptions are not recoverable, since taking an
980 * exception will trash SRR0 and SRR1. Therefore we clear the
981 * MSR:RI bit to indicate this. If we do take an exception,
982 * we can't return to the point of the exception but we
983 * can restart the exception exit path at the label
984 * exc_exit_restart below. -- paulus
986 LOAD_MSR_KERNEL(r10,MSR_KERNEL & ~MSR_RI)
988 MTMSRD(r10) /* clear the RI bit */
989 .globl exc_exit_restart
996 .globl exc_exit_restart_end
997 exc_exit_restart_end:
1001 #else /* !(CONFIG_4xx || CONFIG_BOOKE) */
1003 * This is a bit different on 4xx/Book-E because it doesn't have
1004 * the RI bit in the MSR.
1005 * The TLB miss handler checks if we have interrupted
1006 * the exception exit path and restarts it if so
1007 * (well maybe one day it will... :).
1013 /* Clear the exception_marker on the stack to avoid confusing stacktrace */
1017 .globl exc_exit_restart
1026 .globl exc_exit_restart_end
1027 exc_exit_restart_end:
1030 b . /* prevent prefetch past rfi */
1033 * Returning from a critical interrupt in user mode doesn't need
1034 * to be any different from a normal exception. For a critical
1035 * interrupt in the kernel, we just return (without checking for
1036 * preemption) since the interrupt may have happened at some crucial
1037 * place (e.g. inside the TLB miss handler), and because we will be
1038 * running with r1 pointing into critical_stack, not the current
1039 * process's kernel stack (and therefore current_thread_info() will
1040 * give the wrong answer).
1041 * We have to restore various SPRs that may have been in use at the
1042 * time of the critical interrupt.
1046 #define PPC_40x_TURN_OFF_MSR_DR \
1047 /* avoid any possible TLB misses here by turning off MSR.DR, we \
1048 * assume the instructions here are mapped by a pinned TLB entry */ \
1054 #define PPC_40x_TURN_OFF_MSR_DR
1057 #define RET_FROM_EXC_LEVEL(exc_lvl_srr0, exc_lvl_srr1, exc_lvl_rfi) \
1060 andi. r3,r3,MSR_PR; \
1061 LOAD_MSR_KERNEL(r10,MSR_KERNEL); \
1062 bne user_exc_return; \
1065 REST_4GPRS(3, r1); \
1066 REST_2GPRS(7, r1); \
1069 mtspr SPRN_XER,r10; \
1071 PPC405_ERR77(0,r1); \
1072 stwcx. r0,0,r1; /* to clear the reservation */ \
1073 lwz r11,_LINK(r1); \
1077 PPC_40x_TURN_OFF_MSR_DR; \
1080 mtspr SPRN_DEAR,r9; \
1081 mtspr SPRN_ESR,r10; \
1084 mtspr exc_lvl_srr0,r11; \
1085 mtspr exc_lvl_srr1,r12; \
1087 lwz r12,GPR12(r1); \
1088 lwz r10,GPR10(r1); \
1089 lwz r11,GPR11(r1); \
1091 PPC405_ERR77_SYNC; \
1093 b .; /* prevent prefetch past exc_lvl_rfi */
1095 #define RESTORE_xSRR(exc_lvl_srr0, exc_lvl_srr1) \
1096 lwz r9,_##exc_lvl_srr0(r1); \
1097 lwz r10,_##exc_lvl_srr1(r1); \
1098 mtspr SPRN_##exc_lvl_srr0,r9; \
1099 mtspr SPRN_##exc_lvl_srr1,r10;
1101 #if defined(CONFIG_PPC_BOOK3E_MMU)
1102 #ifdef CONFIG_PHYS_64BIT
1103 #define RESTORE_MAS7 \
1105 mtspr SPRN_MAS7,r11;
1107 #define RESTORE_MAS7
1108 #endif /* CONFIG_PHYS_64BIT */
1109 #define RESTORE_MMU_REGS \
1113 mtspr SPRN_MAS0,r9; \
1115 mtspr SPRN_MAS1,r10; \
1117 mtspr SPRN_MAS2,r11; \
1118 mtspr SPRN_MAS3,r9; \
1119 mtspr SPRN_MAS6,r10; \
1121 #elif defined(CONFIG_44x)
1122 #define RESTORE_MMU_REGS \
1124 mtspr SPRN_MMUCR,r9;
1126 #define RESTORE_MMU_REGS
1130 .globl ret_from_crit_exc
1132 mfspr r9,SPRN_SPRG_THREAD
1133 lis r10,saved_ksp_limit@ha;
1134 lwz r10,saved_ksp_limit@l(r10);
1136 stw r10,KSP_LIMIT(r9)
1137 lis r9,crit_srr0@ha;
1138 lwz r9,crit_srr0@l(r9);
1139 lis r10,crit_srr1@ha;
1140 lwz r10,crit_srr1@l(r10);
1142 mtspr SPRN_SRR1,r10;
1143 RET_FROM_EXC_LEVEL(SPRN_CSRR0, SPRN_CSRR1, PPC_RFCI)
1144 #endif /* CONFIG_40x */
1147 .globl ret_from_crit_exc
1149 mfspr r9,SPRN_SPRG_THREAD
1150 lwz r10,SAVED_KSP_LIMIT(r1)
1151 stw r10,KSP_LIMIT(r9)
1152 RESTORE_xSRR(SRR0,SRR1);
1154 RET_FROM_EXC_LEVEL(SPRN_CSRR0, SPRN_CSRR1, PPC_RFCI)
1156 .globl ret_from_debug_exc
1158 mfspr r9,SPRN_SPRG_THREAD
1159 lwz r10,SAVED_KSP_LIMIT(r1)
1160 stw r10,KSP_LIMIT(r9)
1161 RESTORE_xSRR(SRR0,SRR1);
1162 RESTORE_xSRR(CSRR0,CSRR1);
1164 RET_FROM_EXC_LEVEL(SPRN_DSRR0, SPRN_DSRR1, PPC_RFDI)
1166 .globl ret_from_mcheck_exc
1167 ret_from_mcheck_exc:
1168 mfspr r9,SPRN_SPRG_THREAD
1169 lwz r10,SAVED_KSP_LIMIT(r1)
1170 stw r10,KSP_LIMIT(r9)
1171 RESTORE_xSRR(SRR0,SRR1);
1172 RESTORE_xSRR(CSRR0,CSRR1);
1173 RESTORE_xSRR(DSRR0,DSRR1);
1175 RET_FROM_EXC_LEVEL(SPRN_MCSRR0, SPRN_MCSRR1, PPC_RFMCI)
1176 #endif /* CONFIG_BOOKE */
1179 * Load the DBCR0 value for a task that is being ptraced,
1180 * having first saved away the global DBCR0. Note that r0
1181 * has the dbcr0 value to set upon entry to this.
1184 mfmsr r10 /* first disable debug exceptions */
1185 rlwinm r10,r10,0,~MSR_DE
1188 mfspr r10,SPRN_DBCR0
1189 lis r11,global_dbcr0@ha
1190 addi r11,r11,global_dbcr0@l
1202 mtspr SPRN_DBSR,r11 /* clear all pending debug events */
1207 .global global_dbcr0
1211 #endif /* !(CONFIG_4xx || CONFIG_BOOKE) */
1213 do_work: /* r10 contains MSR_KERNEL here */
1214 andi. r0,r9,_TIF_NEED_RESCHED
1217 do_resched: /* r10 contains MSR_KERNEL here */
1218 #ifdef CONFIG_TRACE_IRQFLAGS
1219 bl trace_hardirqs_on
1224 MTMSRD(r10) /* hard-enable interrupts */
1227 /* Note: And we don't tell it we are disabling them again
1228 * neither. Those disable/enable cycles used to peek at
1229 * TI_FLAGS aren't advertised.
1231 LOAD_MSR_KERNEL(r10,MSR_KERNEL)
1233 MTMSRD(r10) /* disable interrupts */
1235 andi. r0,r9,_TIF_NEED_RESCHED
1237 andi. r0,r9,_TIF_USER_WORK_MASK
1239 do_user_signal: /* r10 contains MSR_KERNEL here */
1242 MTMSRD(r10) /* hard-enable interrupts */
1243 /* save r13-r31 in the exception frame, if not already done */
1250 2: addi r3,r1,STACK_FRAME_OVERHEAD
1257 * We come here when we are at the end of handling an exception
1258 * that occurred at a place where taking an exception will lose
1259 * state information, such as the contents of SRR0 and SRR1.
1262 lis r10,exc_exit_restart_end@ha
1263 addi r10,r10,exc_exit_restart_end@l
1266 lis r11,exc_exit_restart@ha
1267 addi r11,r11,exc_exit_restart@l
1270 lis r10,ee_restarts@ha
1271 lwz r12,ee_restarts@l(r10)
1273 stw r12,ee_restarts@l(r10)
1274 mr r12,r11 /* restart at exc_exit_restart */
1276 3: /* OK, we can't recover, kill this process */
1277 /* but the 601 doesn't implement the RI bit, so assume it's OK */
1280 END_FTR_SECTION_IFSET(CPU_FTR_601)
1287 5: mfspr r2,SPRN_SPRG_THREAD
1289 tovirt(r2,r2) /* set back r2 to current */
1290 4: addi r3,r1,STACK_FRAME_OVERHEAD
1291 bl unrecoverable_exception
1292 /* shouldn't return */
1302 * PROM code for specific machines follows. Put it
1303 * here so it's easy to add arch-specific sections later.
1306 #ifdef CONFIG_PPC_RTAS
1308 * On CHRP, the Run-Time Abstraction Services (RTAS) have to be
1309 * called with the MMU off.
1312 stwu r1,-INT_FRAME_SIZE(r1)
1314 stw r0,INT_FRAME_SIZE+4(r1)
1315 LOAD_REG_ADDR(r4, rtas)
1316 lis r6,1f@ha /* physical return address for rtas */
1320 lwz r8,RTASENTRY(r4)
1324 LOAD_MSR_KERNEL(r0,MSR_KERNEL)
1325 SYNC /* disable interrupts so SRR0/1 */
1326 MTMSRD(r0) /* don't get trashed */
1327 li r9,MSR_KERNEL & ~(MSR_IR|MSR_DR)
1329 stw r7, THREAD + RTAS_SP(r2)
1334 lwz r8,INT_FRAME_SIZE+4(r9) /* get return address */
1335 lwz r9,8(r9) /* original msr value */
1336 addi r1,r1,INT_FRAME_SIZE
1339 stw r0, THREAD + RTAS_SP(r7)
1342 RFI /* return to caller */
1344 .globl machine_check_in_rtas
1345 machine_check_in_rtas:
1347 /* XXX load up BATs and panic */
1349 #endif /* CONFIG_PPC_RTAS */