3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
4 * Rewritten by Cort Dougan (cort@fsmlabs.com) for PReP
5 * Copyright (C) 1996 Cort Dougan <cort@fsmlabs.com>
6 * Adapted for Power Macintosh by Paul Mackerras.
7 * Low-level exception handlers and MMU support
8 * rewritten by Paul Mackerras.
9 * Copyright (C) 1996 Paul Mackerras.
10 * MPC8xx modifications Copyright (C) 1997 Dan Malek (dmalek@jlc.net).
12 * This file contains the system call entry code, context switch
13 * code, and exception/interrupt return code for PowerPC.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version.
22 #include <linux/errno.h>
23 #include <linux/sys.h>
24 #include <linux/threads.h>
28 #include <asm/cputable.h>
29 #include <asm/thread_info.h>
30 #include <asm/ppc_asm.h>
31 #include <asm/asm-offsets.h>
32 #include <asm/unistd.h>
33 #include <asm/ftrace.h>
36 #undef SHOW_SYSCALLS_TASK
39 * MSR_KERNEL is > 0x10000 on 4xx/Book-E since it include MSR_CE.
41 #if MSR_KERNEL >= 0x10000
42 #define LOAD_MSR_KERNEL(r, x) lis r,(x)@h; ori r,r,(x)@l
44 #define LOAD_MSR_KERNEL(r, x) li r,(x)
48 .globl mcheck_transfer_to_handler
49 mcheck_transfer_to_handler:
56 .globl debug_transfer_to_handler
57 debug_transfer_to_handler:
64 .globl crit_transfer_to_handler
65 crit_transfer_to_handler:
66 #ifdef CONFIG_PPC_BOOK3E_MMU
77 #ifdef CONFIG_PHYS_64BIT
80 #endif /* CONFIG_PHYS_64BIT */
81 #endif /* CONFIG_PPC_BOOK3E_MMU */
93 stw r0,SAVED_KSP_LIMIT(r11)
94 rlwimi 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)
113 stw r0,saved_ksp_limit@l(0)
114 rlwimi r0,r1,0,0,(31-THREAD_SHIFT)
120 * This code finishes saving the registers to the exception frame
121 * and jumps to the appropriate handler for the exception, turning
122 * on address translation.
123 * Note that we rely on the caller having set cr0.eq iff the exception
124 * occurred in kernel mode (i.e. MSR:PR = 0).
126 .globl transfer_to_handler_full
127 transfer_to_handler_full:
131 .globl transfer_to_handler
143 tovirt(r2,r2) /* set r2 to current */
144 beq 2f /* if from user, fix up THREAD.regs */
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 /* From user and task is ptraced - load up global dbcr0 */
154 li r12,-1 /* clear all pending debug events */
156 lis r11,global_dbcr0@ha
158 addi r11,r11,global_dbcr0@l
160 rlwinm r9,r1,0,0,(31-THREAD_SHIFT)
173 2: /* if from kernel, check interrupted DOZE/NAP mode and
174 * check for stack overflow
176 lwz r9,KSP_LIMIT(r12)
177 cmplw r1,r9 /* if r1 <= ksp_limit */
178 ble- stack_ovf /* then the kernel stack overflowed */
180 #if defined(CONFIG_6xx) || defined(CONFIG_E500)
181 rlwinm r9,r1,0,0,31-THREAD_SHIFT
182 tophys(r9,r9) /* check local flags */
183 lwz r12,TI_LOCAL_FLAGS(r9)
185 bt- 31-TLF_NAPPING,4f
186 bt- 31-TLF_SLEEPING,7f
187 #endif /* CONFIG_6xx || CONFIG_E500 */
188 .globl transfer_to_handler_cont
189 transfer_to_handler_cont:
192 lwz r11,0(r9) /* virtual address of handler */
193 lwz r9,4(r9) /* where to go when done */
194 #ifdef CONFIG_TRACE_IRQFLAGS
195 lis r12,reenable_mmu@h
196 ori r12,r12,reenable_mmu@l
201 reenable_mmu: /* re-enable mmu so we can */
205 andi. r10,r10,MSR_EE /* Did EE change? */
208 /* Save handler and return address into the 2 unused words
209 * of the STACK_FRAME_OVERHEAD (sneak sneak sneak). Everything
210 * else can be recovered from the pt_regs except r3 which for
211 * normal interrupts has been set to pt_regs and for syscalls
212 * is an argument, so we temporarily use ORIG_GPR3 to save it
217 bl trace_hardirqs_off
229 bctr /* jump to handler */
230 #else /* CONFIG_TRACE_IRQFLAGS */
235 RFI /* jump to handler, enable MMU */
236 #endif /* CONFIG_TRACE_IRQFLAGS */
238 #if defined (CONFIG_6xx) || defined(CONFIG_E500)
239 4: rlwinm r12,r12,0,~_TLF_NAPPING
240 stw r12,TI_LOCAL_FLAGS(r9)
241 b power_save_ppc32_restore
243 7: rlwinm r12,r12,0,~_TLF_SLEEPING
244 stw r12,TI_LOCAL_FLAGS(r9)
245 lwz r9,_MSR(r11) /* if sleeping, clear MSR.EE */
246 rlwinm r9,r9,0,~MSR_EE
247 lwz r12,_LINK(r11) /* and return to address in LR */
248 b fast_exception_return
252 * On kernel stack overflow, load up an initial stack pointer
253 * and call StackOverflow(regs), which should not return.
256 /* sometimes we use a statically-allocated stack, which is OK. */
260 ble 5b /* r1 <= &_end is OK */
262 addi r3,r1,STACK_FRAME_OVERHEAD
263 lis r1,init_thread_union@ha
264 addi r1,r1,init_thread_union@l
265 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
266 lis r9,StackOverflow@ha
267 addi r9,r9,StackOverflow@l
268 LOAD_MSR_KERNEL(r10,MSR_KERNEL)
276 * Handle a system call.
278 .stabs "arch/powerpc/kernel/",N_SO,0,0,0f
279 .stabs "entry_32.S",N_SO,0,0,0f
286 lwz r11,_CCR(r1) /* Clear SO bit in CR */
291 #endif /* SHOW_SYSCALLS */
292 #ifdef CONFIG_TRACE_IRQFLAGS
293 /* Return from syscalls can (and generally will) hard enable
294 * interrupts. You aren't supposed to call a syscall with
295 * interrupts disabled in the first place. However, to ensure
296 * that we get it right vs. lockdep if it happens, we force
297 * that hard enable here with appropriate tracing if we see
298 * that we have been called with interrupts off
303 /* We came in with interrupts disabled, we enable them now */
316 #endif /* CONFIG_TRACE_IRQFLAGS */
317 rlwinm r10,r1,0,0,(31-THREAD_SHIFT) /* current_thread_info() */
318 lwz r11,TI_FLAGS(r10)
319 andi. r11,r11,_TIF_SYSCALL_T_OR_A
321 syscall_dotrace_cont:
322 cmplwi 0,r0,NR_syscalls
323 lis r10,sys_call_table@h
324 ori r10,r10,sys_call_table@l
327 lwzx r10,r10,r0 /* Fetch system call handler [ptr] */
329 addi r9,r1,STACK_FRAME_OVERHEAD
331 blrl /* Call handler */
332 .globl ret_from_syscall
335 bl do_show_syscall_exit
338 rlwinm r12,r1,0,0,(31-THREAD_SHIFT) /* current_thread_info() */
339 /* disable interrupts so current_thread_info()->flags can't change */
340 LOAD_MSR_KERNEL(r10,MSR_KERNEL) /* doesn't include MSR_EE */
341 /* Note: We don't bother telling lockdep about it */
346 andi. r0,r9,(_TIF_SYSCALL_T_OR_A|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
347 bne- syscall_exit_work
349 blt+ syscall_exit_cont
350 lwz r11,_CCR(r1) /* Load CR */
352 oris r11,r11,0x1000 /* Set SO bit in CR */
356 #ifdef CONFIG_TRACE_IRQFLAGS
357 /* If we are going to return from the syscall with interrupts
358 * off, we trace that here. It shouldn't happen though but we
359 * want to catch the bugger if it does right ?
364 bl trace_hardirqs_off
367 #endif /* CONFIG_TRACE_IRQFLAGS */
368 #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
369 /* If the process has its own DBCR0 value, load it up. The internal
370 debug mode bit tells us that dbcr0 should be loaded. */
371 lwz r0,THREAD+THREAD_DBCR0(r2)
372 andis. r10,r0,DBCR0_IDM@h
376 lis r4,icache_44x_need_flush@ha
377 lwz r5,icache_44x_need_flush@l(r4)
381 #endif /* CONFIG_44x */
384 END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
385 stwcx. r0,0,r1 /* to clear the reservation */
401 stw r7,icache_44x_need_flush@l(r4)
403 #endif /* CONFIG_44x */
415 /* Traced system call support */
420 addi r3,r1,STACK_FRAME_OVERHEAD
421 bl do_syscall_trace_enter
423 * Restore argument registers possibly just changed.
424 * We use the return value of do_syscall_trace_enter
425 * for call number to look up in the table (r0).
435 b syscall_dotrace_cont
438 andi. r0,r9,_TIF_RESTOREALL
444 andi. r0,r9,_TIF_NOERROR
446 lwz r11,_CCR(r1) /* Load CR */
448 oris r11,r11,0x1000 /* Set SO bit in CR */
451 1: stw r6,RESULT(r1) /* Save result */
452 stw r3,GPR3(r1) /* Update return value */
453 2: andi. r0,r9,(_TIF_PERSYSCALL_MASK)
456 /* Clear per-syscall TIF flags if any are set. */
458 li r11,_TIF_PERSYSCALL_MASK
459 addi r12,r12,TI_FLAGS
462 #ifdef CONFIG_IBM405_ERR77
467 subi r12,r12,TI_FLAGS
469 4: /* Anything which requires enabling interrupts? */
470 andi. r0,r9,(_TIF_SYSCALL_T_OR_A|_TIF_SINGLESTEP)
473 /* Re-enable interrupts. There is no need to trace that with
474 * lockdep as we are supposed to have IRQs on at this point
480 /* Save NVGPRS if they're not saved already */
488 addi r3,r1,STACK_FRAME_OVERHEAD
489 bl do_syscall_trace_leave
490 b ret_from_except_full
494 #ifdef SHOW_SYSCALLS_TASK
495 lis r11,show_syscalls_task@ha
496 lwz r11,show_syscalls_task@l(r11)
527 do_show_syscall_exit:
528 #ifdef SHOW_SYSCALLS_TASK
529 lis r11,show_syscalls_task@ha
530 lwz r11,show_syscalls_task@l(r11)
536 stw r3,RESULT(r1) /* Save result */
546 7: .string "syscall %d(%x, %x, %x, %x, %x, "
547 77: .string "%x), current=%p\n"
548 79: .string " -> %x\n"
551 #ifdef SHOW_SYSCALLS_TASK
553 .globl show_syscalls_task
558 #endif /* SHOW_SYSCALLS */
561 * The fork/clone functions need to copy the full register set into
562 * the child process. Therefore we need to save all the nonvolatile
563 * registers (r13 - r31) before calling the C code.
569 rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
570 stw r0,_TRAP(r1) /* register set saved */
577 rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
578 stw r0,_TRAP(r1) /* register set saved */
585 rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
586 stw r0,_TRAP(r1) /* register set saved */
589 .globl ppc_swapcontext
593 rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
594 stw r0,_TRAP(r1) /* register set saved */
598 * Top-level page fault handling.
599 * This is in assembler because if do_page_fault tells us that
600 * it is a bad kernel page fault, we want to save the non-volatile
601 * registers before calling bad_page_fault.
603 .globl handle_page_fault
606 addi r3,r1,STACK_FRAME_OVERHEAD
615 addi r3,r1,STACK_FRAME_OVERHEAD
618 b ret_from_except_full
621 * This routine switches between two different tasks. The process
622 * state of one is saved on its kernel stack. Then the state
623 * of the other is restored from its kernel stack. The memory
624 * management hardware is updated to the second process's state.
625 * Finally, we can return to the second process.
626 * On entry, r3 points to the THREAD for the current task, r4
627 * points to the THREAD for the new task.
629 * This routine is always called with interrupts disabled.
631 * Note: there are two ways to get to the "going out" portion
632 * of this code; either by coming in via the entry (_switch)
633 * or via "fork" which must set up an environment equivalent
634 * to the "_switch" path. If you change this , you'll have to
635 * change the fork code also.
637 * The code which creates the new task context is in 'copy_thread'
638 * in arch/ppc/kernel/process.c
641 stwu r1,-INT_FRAME_SIZE(r1)
643 stw r0,INT_FRAME_SIZE+4(r1)
644 /* r3-r12 are caller saved -- Cort */
646 stw r0,_NIP(r1) /* Return to switch caller */
648 li r0,MSR_FP /* Disable floating-point */
649 #ifdef CONFIG_ALTIVEC
651 oris r0,r0,MSR_VEC@h /* Disable altivec */
652 mfspr r12,SPRN_VRSAVE /* save vrsave register value */
653 stw r12,THREAD+THREAD_VRSAVE(r2)
654 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
655 #endif /* CONFIG_ALTIVEC */
658 oris r0,r0,MSR_SPE@h /* Disable SPE */
659 mfspr r12,SPRN_SPEFSCR /* save spefscr register value */
660 stw r12,THREAD+THREAD_SPEFSCR(r2)
661 END_FTR_SECTION_IFSET(CPU_FTR_SPE)
662 #endif /* CONFIG_SPE */
663 and. r0,r0,r11 /* FP or altivec or SPE enabled? */
671 stw r1,KSP(r3) /* Set old stack pointer */
674 /* We need a sync somewhere here to make sure that if the
675 * previous task gets rescheduled on another CPU, it sees all
676 * stores it has performed on this one.
679 #endif /* CONFIG_SMP */
683 mtspr SPRN_SPRG3,r0 /* Update current THREAD phys addr */
684 lwz r1,KSP(r4) /* Load new stack pointer */
686 /* save the old current 'last' for return value */
688 addi r2,r4,-THREAD /* Update current */
690 #ifdef CONFIG_ALTIVEC
692 lwz r0,THREAD+THREAD_VRSAVE(r2)
693 mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */
694 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
695 #endif /* CONFIG_ALTIVEC */
698 lwz r0,THREAD+THREAD_SPEFSCR(r2)
699 mtspr SPRN_SPEFSCR,r0 /* restore SPEFSCR reg */
700 END_FTR_SECTION_IFSET(CPU_FTR_SPE)
701 #endif /* CONFIG_SPE */
705 /* r3-r12 are destroyed -- Cort */
708 lwz r4,_NIP(r1) /* Return to _switch caller in new task */
710 addi r1,r1,INT_FRAME_SIZE
713 .globl fast_exception_return
714 fast_exception_return:
715 #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
716 andi. r10,r9,MSR_RI /* check for recoverable interrupt */
717 beq 1f /* if not, we've got problems */
720 2: REST_4GPRS(3, r11)
735 #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
736 /* check if the exception happened in a restartable section */
737 1: lis r3,exc_exit_restart_end@ha
738 addi r3,r3,exc_exit_restart_end@l
741 lis r4,exc_exit_restart@ha
742 addi r4,r4,exc_exit_restart@l
745 lis r3,fee_restarts@ha
747 lwz r5,fee_restarts@l(r3)
749 stw r5,fee_restarts@l(r3)
750 mr r12,r4 /* restart at exc_exit_restart */
759 /* aargh, a nonrecoverable interrupt, panic */
760 /* aargh, we don't know which trap this is */
761 /* but the 601 doesn't implement the RI bit, so assume it's OK */
765 END_FTR_SECTION_IFSET(CPU_FTR_601)
768 addi r3,r1,STACK_FRAME_OVERHEAD
770 ori r10,r10,MSR_KERNEL@l
771 bl transfer_to_handler_full
772 .long nonrecoverable_exception
773 .long ret_from_except
776 .globl ret_from_except_full
777 ret_from_except_full:
781 .globl ret_from_except
783 /* Hard-disable interrupts so that current_thread_info()->flags
784 * can't change between when we test it and when we return
785 * from the interrupt. */
786 /* Note: We don't bother telling lockdep about it */
787 LOAD_MSR_KERNEL(r10,MSR_KERNEL)
788 SYNC /* Some chip revs have problems here... */
789 MTMSRD(r10) /* disable interrupts */
791 lwz r3,_MSR(r1) /* Returning to user mode? */
795 user_exc_return: /* r10 contains MSR_KERNEL here */
796 /* Check current_thread_info()->flags */
797 rlwinm r9,r1,0,0,(31-THREAD_SHIFT)
799 andi. r0,r9,_TIF_USER_WORK_MASK
803 #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
804 /* Check whether this process has its own DBCR0 value. The internal
805 debug mode bit tells us that dbcr0 should be loaded. */
806 lwz r0,THREAD+THREAD_DBCR0(r2)
807 andis. r10,r0,DBCR0_IDM@h
811 #ifdef CONFIG_PREEMPT
814 /* N.B. the only way to get here is from the beq following ret_from_except. */
816 /* check current_thread_info->preempt_count */
817 rlwinm r9,r1,0,0,(31-THREAD_SHIFT)
818 lwz r0,TI_PREEMPT(r9)
819 cmpwi 0,r0,0 /* if non-zero, just restore regs and return */
822 andi. r0,r0,_TIF_NEED_RESCHED
824 andi. r0,r3,MSR_EE /* interrupts off? */
825 beq restore /* don't schedule if so */
826 #ifdef CONFIG_TRACE_IRQFLAGS
827 /* Lockdep thinks irqs are enabled, we need to call
828 * preempt_schedule_irq with IRQs off, so we inform lockdep
829 * now that we -did- turn them off already
831 bl trace_hardirqs_off
833 1: bl preempt_schedule_irq
834 rlwinm r9,r1,0,0,(31-THREAD_SHIFT)
836 andi. r0,r3,_TIF_NEED_RESCHED
838 #ifdef CONFIG_TRACE_IRQFLAGS
839 /* And now, to properly rebalance the above, we tell lockdep they
840 * are being turned back on, which will happen when we return
846 #endif /* CONFIG_PREEMPT */
848 /* interrupts are hard-disabled at this point */
851 lis r4,icache_44x_need_flush@ha
852 lwz r5,icache_44x_need_flush@l(r4)
857 stw r6,icache_44x_need_flush@l(r4)
859 #endif /* CONFIG_44x */
862 #ifdef CONFIG_TRACE_IRQFLAGS
863 /* Lockdep doesn't know about the fact that IRQs are temporarily turned
864 * off in this assembly code while peeking at TI_FLAGS() and such. However
865 * we need to inform it if the exception turned interrupts off, and we
866 * are about to trun them back on.
868 * The problem here sadly is that we don't know whether the exceptions was
869 * one that turned interrupts off or not. So we always tell lockdep about
870 * turning them on here when we go back to wherever we came from with EE
871 * on, even if that may meen some redudant calls being tracked. Maybe later
872 * we could encode what the exception did somewhere or test the exception
873 * type in the pt_regs but that sounds overkill
880 #endif /* CONFIG_TRACE_IRQFLAGS */
895 END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
896 stwcx. r0,0,r1 /* to clear the reservation */
898 #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
899 andi. r10,r9,MSR_RI /* check if this exception occurred */
900 beql nonrecoverable /* at a bad place (MSR:RI = 0) */
908 * Once we put values in SRR0 and SRR1, we are in a state
909 * where exceptions are not recoverable, since taking an
910 * exception will trash SRR0 and SRR1. Therefore we clear the
911 * MSR:RI bit to indicate this. If we do take an exception,
912 * we can't return to the point of the exception but we
913 * can restart the exception exit path at the label
914 * exc_exit_restart below. -- paulus
916 LOAD_MSR_KERNEL(r10,MSR_KERNEL & ~MSR_RI)
918 MTMSRD(r10) /* clear the RI bit */
919 .globl exc_exit_restart
927 .globl exc_exit_restart_end
928 exc_exit_restart_end:
932 #else /* !(CONFIG_4xx || CONFIG_BOOKE) */
934 * This is a bit different on 4xx/Book-E because it doesn't have
935 * the RI bit in the MSR.
936 * The TLB miss handler checks if we have interrupted
937 * the exception exit path and restarts it if so
938 * (well maybe one day it will... :).
945 .globl exc_exit_restart
954 .globl exc_exit_restart_end
955 exc_exit_restart_end:
958 b . /* prevent prefetch past rfi */
961 * Returning from a critical interrupt in user mode doesn't need
962 * to be any different from a normal exception. For a critical
963 * interrupt in the kernel, we just return (without checking for
964 * preemption) since the interrupt may have happened at some crucial
965 * place (e.g. inside the TLB miss handler), and because we will be
966 * running with r1 pointing into critical_stack, not the current
967 * process's kernel stack (and therefore current_thread_info() will
968 * give the wrong answer).
969 * We have to restore various SPRs that may have been in use at the
970 * time of the critical interrupt.
974 #define PPC_40x_TURN_OFF_MSR_DR \
975 /* avoid any possible TLB misses here by turning off MSR.DR, we \
976 * assume the instructions here are mapped by a pinned TLB entry */ \
982 #define PPC_40x_TURN_OFF_MSR_DR
985 #define RET_FROM_EXC_LEVEL(exc_lvl_srr0, exc_lvl_srr1, exc_lvl_rfi) \
988 andi. r3,r3,MSR_PR; \
989 LOAD_MSR_KERNEL(r10,MSR_KERNEL); \
990 bne user_exc_return; \
997 mtspr SPRN_XER,r10; \
999 PPC405_ERR77(0,r1); \
1000 stwcx. r0,0,r1; /* to clear the reservation */ \
1001 lwz r11,_LINK(r1); \
1005 PPC_40x_TURN_OFF_MSR_DR; \
1008 mtspr SPRN_DEAR,r9; \
1009 mtspr SPRN_ESR,r10; \
1012 mtspr exc_lvl_srr0,r11; \
1013 mtspr exc_lvl_srr1,r12; \
1015 lwz r12,GPR12(r1); \
1016 lwz r10,GPR10(r1); \
1017 lwz r11,GPR11(r1); \
1019 PPC405_ERR77_SYNC; \
1021 b .; /* prevent prefetch past exc_lvl_rfi */
1023 #define RESTORE_xSRR(exc_lvl_srr0, exc_lvl_srr1) \
1024 lwz r9,_##exc_lvl_srr0(r1); \
1025 lwz r10,_##exc_lvl_srr1(r1); \
1026 mtspr SPRN_##exc_lvl_srr0,r9; \
1027 mtspr SPRN_##exc_lvl_srr1,r10;
1029 #if defined(CONFIG_PPC_BOOK3E_MMU)
1030 #ifdef CONFIG_PHYS_64BIT
1031 #define RESTORE_MAS7 \
1033 mtspr SPRN_MAS7,r11;
1035 #define RESTORE_MAS7
1036 #endif /* CONFIG_PHYS_64BIT */
1037 #define RESTORE_MMU_REGS \
1041 mtspr SPRN_MAS0,r9; \
1043 mtspr SPRN_MAS1,r10; \
1045 mtspr SPRN_MAS2,r11; \
1046 mtspr SPRN_MAS3,r9; \
1047 mtspr SPRN_MAS6,r10; \
1049 #elif defined(CONFIG_44x)
1050 #define RESTORE_MMU_REGS \
1052 mtspr SPRN_MMUCR,r9;
1054 #define RESTORE_MMU_REGS
1058 .globl ret_from_crit_exc
1061 lis r10,saved_ksp_limit@ha;
1062 lwz r10,saved_ksp_limit@l(r10);
1064 stw r10,KSP_LIMIT(r9)
1065 lis r9,crit_srr0@ha;
1066 lwz r9,crit_srr0@l(r9);
1067 lis r10,crit_srr1@ha;
1068 lwz r10,crit_srr1@l(r10);
1070 mtspr SPRN_SRR1,r10;
1071 RET_FROM_EXC_LEVEL(SPRN_CSRR0, SPRN_CSRR1, PPC_RFCI)
1072 #endif /* CONFIG_40x */
1075 .globl ret_from_crit_exc
1078 lwz r10,SAVED_KSP_LIMIT(r1)
1079 stw r10,KSP_LIMIT(r9)
1080 RESTORE_xSRR(SRR0,SRR1);
1082 RET_FROM_EXC_LEVEL(SPRN_CSRR0, SPRN_CSRR1, PPC_RFCI)
1084 .globl ret_from_debug_exc
1087 lwz r10,SAVED_KSP_LIMIT(r1)
1088 stw r10,KSP_LIMIT(r9)
1089 lwz r9,THREAD_INFO-THREAD(r9)
1090 rlwinm r10,r1,0,0,(31-THREAD_SHIFT)
1091 lwz r10,TI_PREEMPT(r10)
1092 stw r10,TI_PREEMPT(r9)
1093 RESTORE_xSRR(SRR0,SRR1);
1094 RESTORE_xSRR(CSRR0,CSRR1);
1096 RET_FROM_EXC_LEVEL(SPRN_DSRR0, SPRN_DSRR1, PPC_RFDI)
1098 .globl ret_from_mcheck_exc
1099 ret_from_mcheck_exc:
1101 lwz r10,SAVED_KSP_LIMIT(r1)
1102 stw r10,KSP_LIMIT(r9)
1103 RESTORE_xSRR(SRR0,SRR1);
1104 RESTORE_xSRR(CSRR0,CSRR1);
1105 RESTORE_xSRR(DSRR0,DSRR1);
1107 RET_FROM_EXC_LEVEL(SPRN_MCSRR0, SPRN_MCSRR1, PPC_RFMCI)
1108 #endif /* CONFIG_BOOKE */
1111 * Load the DBCR0 value for a task that is being ptraced,
1112 * having first saved away the global DBCR0. Note that r0
1113 * has the dbcr0 value to set upon entry to this.
1116 mfmsr r10 /* first disable debug exceptions */
1117 rlwinm r10,r10,0,~MSR_DE
1120 mfspr r10,SPRN_DBCR0
1121 lis r11,global_dbcr0@ha
1122 addi r11,r11,global_dbcr0@l
1124 rlwinm r9,r1,0,0,(31-THREAD_SHIFT)
1135 mtspr SPRN_DBSR,r11 /* clear all pending debug events */
1143 #endif /* !(CONFIG_4xx || CONFIG_BOOKE) */
1145 do_work: /* r10 contains MSR_KERNEL here */
1146 andi. r0,r9,_TIF_NEED_RESCHED
1149 do_resched: /* r10 contains MSR_KERNEL here */
1150 /* Note: We don't need to inform lockdep that we are enabling
1151 * interrupts here. As far as it knows, they are already enabled
1155 MTMSRD(r10) /* hard-enable interrupts */
1158 /* Note: And we don't tell it we are disabling them again
1159 * neither. Those disable/enable cycles used to peek at
1160 * TI_FLAGS aren't advertised.
1162 LOAD_MSR_KERNEL(r10,MSR_KERNEL)
1164 MTMSRD(r10) /* disable interrupts */
1165 rlwinm r9,r1,0,0,(31-THREAD_SHIFT)
1167 andi. r0,r9,_TIF_NEED_RESCHED
1169 andi. r0,r9,_TIF_USER_WORK_MASK
1171 do_user_signal: /* r10 contains MSR_KERNEL here */
1174 MTMSRD(r10) /* hard-enable interrupts */
1175 /* save r13-r31 in the exception frame, if not already done */
1182 2: addi r3,r1,STACK_FRAME_OVERHEAD
1189 * We come here when we are at the end of handling an exception
1190 * that occurred at a place where taking an exception will lose
1191 * state information, such as the contents of SRR0 and SRR1.
1194 lis r10,exc_exit_restart_end@ha
1195 addi r10,r10,exc_exit_restart_end@l
1198 lis r11,exc_exit_restart@ha
1199 addi r11,r11,exc_exit_restart@l
1202 lis r10,ee_restarts@ha
1203 lwz r12,ee_restarts@l(r10)
1205 stw r12,ee_restarts@l(r10)
1206 mr r12,r11 /* restart at exc_exit_restart */
1208 3: /* OK, we can't recover, kill this process */
1209 /* but the 601 doesn't implement the RI bit, so assume it's OK */
1212 END_FTR_SECTION_IFSET(CPU_FTR_601)
1219 4: addi r3,r1,STACK_FRAME_OVERHEAD
1220 bl nonrecoverable_exception
1221 /* shouldn't return */
1231 * PROM code for specific machines follows. Put it
1232 * here so it's easy to add arch-specific sections later.
1235 #ifdef CONFIG_PPC_RTAS
1237 * On CHRP, the Run-Time Abstraction Services (RTAS) have to be
1238 * called with the MMU off.
1241 stwu r1,-INT_FRAME_SIZE(r1)
1243 stw r0,INT_FRAME_SIZE+4(r1)
1244 LOAD_REG_ADDR(r4, rtas)
1245 lis r6,1f@ha /* physical return address for rtas */
1249 lwz r8,RTASENTRY(r4)
1253 LOAD_MSR_KERNEL(r0,MSR_KERNEL)
1254 SYNC /* disable interrupts so SRR0/1 */
1255 MTMSRD(r0) /* don't get trashed */
1256 li r9,MSR_KERNEL & ~(MSR_IR|MSR_DR)
1263 lwz r8,INT_FRAME_SIZE+4(r9) /* get return address */
1264 lwz r9,8(r9) /* original msr value */
1266 addi r1,r1,INT_FRAME_SIZE
1271 RFI /* return to caller */
1273 .globl machine_check_in_rtas
1274 machine_check_in_rtas:
1276 /* XXX load up BATs and panic */
1278 #endif /* CONFIG_PPC_RTAS */
1280 #ifdef CONFIG_FUNCTION_TRACER
1281 #ifdef CONFIG_DYNAMIC_FTRACE
1285 * It is required that _mcount on PPC32 must preserve the
1286 * link register. But we have r0 to play with. We use r0
1287 * to push the return address back to the caller of mcount
1288 * into the ctr register, restore the link register and
1289 * then jump back using the ctr register.
1297 _GLOBAL(ftrace_caller)
1299 /* r3 ends up with link register */
1300 subi r3, r3, MCOUNT_INSN_SIZE
1305 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1306 .globl ftrace_graph_call
1309 _GLOBAL(ftrace_graph_stub)
1311 MCOUNT_RESTORE_FRAME
1312 /* old link register ends up in ctr reg */
1320 subi r3, r3, MCOUNT_INSN_SIZE
1321 LOAD_REG_ADDR(r5, ftrace_trace_function)
1328 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1329 b ftrace_graph_caller
1331 MCOUNT_RESTORE_FRAME
1335 _GLOBAL(ftrace_stub)
1338 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1339 _GLOBAL(ftrace_graph_caller)
1340 /* load r4 with local address */
1342 subi r4, r4, MCOUNT_INSN_SIZE
1344 /* get the parent address */
1347 bl prepare_ftrace_return
1350 MCOUNT_RESTORE_FRAME
1351 /* old link register ends up in ctr reg */
1354 _GLOBAL(return_to_handler)
1355 /* need to save return values */
1362 bl ftrace_return_to_handler
1365 /* return value has real return address */
1373 /* Jump back to real return address */
1375 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
1377 #endif /* CONFIG_MCOUNT */