]>
Commit | Line | Data |
---|---|---|
9994a338 PM |
1 | /* |
2 | * PowerPC version | |
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). | |
11 | * | |
12 | * This file contains the system call entry code, context switch | |
13 | * code, and exception/interrupt return code for PowerPC. | |
14 | * | |
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. | |
19 | * | |
20 | */ | |
21 | ||
9994a338 | 22 | #include <linux/errno.h> |
c3525940 | 23 | #include <linux/err.h> |
9994a338 PM |
24 | #include <linux/sys.h> |
25 | #include <linux/threads.h> | |
26 | #include <asm/reg.h> | |
27 | #include <asm/page.h> | |
28 | #include <asm/mmu.h> | |
29 | #include <asm/cputable.h> | |
30 | #include <asm/thread_info.h> | |
31 | #include <asm/ppc_asm.h> | |
32 | #include <asm/asm-offsets.h> | |
33 | #include <asm/unistd.h> | |
395a59d0 | 34 | #include <asm/ftrace.h> |
46f52210 | 35 | #include <asm/ptrace.h> |
9994a338 | 36 | |
9994a338 PM |
37 | /* |
38 | * MSR_KERNEL is > 0x10000 on 4xx/Book-E since it include MSR_CE. | |
39 | */ | |
40 | #if MSR_KERNEL >= 0x10000 | |
41 | #define LOAD_MSR_KERNEL(r, x) lis r,(x)@h; ori r,r,(x)@l | |
42 | #else | |
43 | #define LOAD_MSR_KERNEL(r, x) li r,(x) | |
44 | #endif | |
45 | ||
46 | #ifdef CONFIG_BOOKE | |
9994a338 PM |
47 | .globl mcheck_transfer_to_handler |
48 | mcheck_transfer_to_handler: | |
fca622c5 KG |
49 | mfspr r0,SPRN_DSRR0 |
50 | stw r0,_DSRR0(r11) | |
51 | mfspr r0,SPRN_DSRR1 | |
52 | stw r0,_DSRR1(r11) | |
53 | /* fall through */ | |
9994a338 PM |
54 | |
55 | .globl debug_transfer_to_handler | |
56 | debug_transfer_to_handler: | |
fca622c5 KG |
57 | mfspr r0,SPRN_CSRR0 |
58 | stw r0,_CSRR0(r11) | |
59 | mfspr r0,SPRN_CSRR1 | |
60 | stw r0,_CSRR1(r11) | |
61 | /* fall through */ | |
9994a338 PM |
62 | |
63 | .globl crit_transfer_to_handler | |
64 | crit_transfer_to_handler: | |
70fe3af8 | 65 | #ifdef CONFIG_PPC_BOOK3E_MMU |
fca622c5 KG |
66 | mfspr r0,SPRN_MAS0 |
67 | stw r0,MAS0(r11) | |
68 | mfspr r0,SPRN_MAS1 | |
69 | stw r0,MAS1(r11) | |
70 | mfspr r0,SPRN_MAS2 | |
71 | stw r0,MAS2(r11) | |
72 | mfspr r0,SPRN_MAS3 | |
73 | stw r0,MAS3(r11) | |
74 | mfspr r0,SPRN_MAS6 | |
75 | stw r0,MAS6(r11) | |
76 | #ifdef CONFIG_PHYS_64BIT | |
77 | mfspr r0,SPRN_MAS7 | |
78 | stw r0,MAS7(r11) | |
79 | #endif /* CONFIG_PHYS_64BIT */ | |
70fe3af8 | 80 | #endif /* CONFIG_PPC_BOOK3E_MMU */ |
fca622c5 KG |
81 | #ifdef CONFIG_44x |
82 | mfspr r0,SPRN_MMUCR | |
83 | stw r0,MMUCR(r11) | |
84 | #endif | |
85 | mfspr r0,SPRN_SRR0 | |
86 | stw r0,_SRR0(r11) | |
87 | mfspr r0,SPRN_SRR1 | |
88 | stw r0,_SRR1(r11) | |
89 | ||
1f8b0bc8 SY |
90 | /* set the stack limit to the current stack |
91 | * and set the limit to protect the thread_info | |
92 | * struct | |
93 | */ | |
ee43eb78 | 94 | mfspr r8,SPRN_SPRG_THREAD |
fca622c5 KG |
95 | lwz r0,KSP_LIMIT(r8) |
96 | stw r0,SAVED_KSP_LIMIT(r11) | |
1f8b0bc8 | 97 | rlwimi r0,r1,0,0,(31-THREAD_SHIFT) |
fca622c5 | 98 | stw r0,KSP_LIMIT(r8) |
9994a338 PM |
99 | /* fall through */ |
100 | #endif | |
101 | ||
102 | #ifdef CONFIG_40x | |
103 | .globl crit_transfer_to_handler | |
104 | crit_transfer_to_handler: | |
105 | lwz r0,crit_r10@l(0) | |
106 | stw r0,GPR10(r11) | |
107 | lwz r0,crit_r11@l(0) | |
108 | stw r0,GPR11(r11) | |
fca622c5 KG |
109 | mfspr r0,SPRN_SRR0 |
110 | stw r0,crit_srr0@l(0) | |
111 | mfspr r0,SPRN_SRR1 | |
112 | stw r0,crit_srr1@l(0) | |
113 | ||
1f8b0bc8 SY |
114 | /* set the stack limit to the current stack |
115 | * and set the limit to protect the thread_info | |
116 | * struct | |
117 | */ | |
ee43eb78 | 118 | mfspr r8,SPRN_SPRG_THREAD |
fca622c5 KG |
119 | lwz r0,KSP_LIMIT(r8) |
120 | stw r0,saved_ksp_limit@l(0) | |
1f8b0bc8 | 121 | rlwimi r0,r1,0,0,(31-THREAD_SHIFT) |
fca622c5 | 122 | stw r0,KSP_LIMIT(r8) |
9994a338 PM |
123 | /* fall through */ |
124 | #endif | |
125 | ||
126 | /* | |
127 | * This code finishes saving the registers to the exception frame | |
128 | * and jumps to the appropriate handler for the exception, turning | |
129 | * on address translation. | |
130 | * Note that we rely on the caller having set cr0.eq iff the exception | |
131 | * occurred in kernel mode (i.e. MSR:PR = 0). | |
132 | */ | |
133 | .globl transfer_to_handler_full | |
134 | transfer_to_handler_full: | |
135 | SAVE_NVGPRS(r11) | |
136 | /* fall through */ | |
137 | ||
138 | .globl transfer_to_handler | |
139 | transfer_to_handler: | |
140 | stw r2,GPR2(r11) | |
141 | stw r12,_NIP(r11) | |
142 | stw r9,_MSR(r11) | |
143 | andi. r2,r9,MSR_PR | |
144 | mfctr r12 | |
145 | mfspr r2,SPRN_XER | |
146 | stw r12,_CTR(r11) | |
147 | stw r2,_XER(r11) | |
ee43eb78 | 148 | mfspr r12,SPRN_SPRG_THREAD |
9994a338 PM |
149 | addi r2,r12,-THREAD |
150 | tovirt(r2,r2) /* set r2 to current */ | |
151 | beq 2f /* if from user, fix up THREAD.regs */ | |
152 | addi r11,r1,STACK_FRAME_OVERHEAD | |
153 | stw r11,PT_REGS(r12) | |
154 | #if defined(CONFIG_40x) || defined(CONFIG_BOOKE) | |
155 | /* Check to see if the dbcr0 register is set up to debug. Use the | |
4eaddb4d | 156 | internal debug mode bit to do this. */ |
9994a338 | 157 | lwz r12,THREAD_DBCR0(r12) |
2325f0a0 | 158 | andis. r12,r12,DBCR0_IDM@h |
9994a338 PM |
159 | beq+ 3f |
160 | /* From user and task is ptraced - load up global dbcr0 */ | |
161 | li r12,-1 /* clear all pending debug events */ | |
162 | mtspr SPRN_DBSR,r12 | |
163 | lis r11,global_dbcr0@ha | |
164 | tophys(r11,r11) | |
165 | addi r11,r11,global_dbcr0@l | |
4eaddb4d | 166 | #ifdef CONFIG_SMP |
9778b696 | 167 | CURRENT_THREAD_INFO(r9, r1) |
4eaddb4d KG |
168 | lwz r9,TI_CPU(r9) |
169 | slwi r9,r9,3 | |
170 | add r11,r11,r9 | |
171 | #endif | |
9994a338 PM |
172 | lwz r12,0(r11) |
173 | mtspr SPRN_DBCR0,r12 | |
174 | lwz r12,4(r11) | |
175 | addi r12,r12,-1 | |
176 | stw r12,4(r11) | |
177 | #endif | |
178 | b 3f | |
f39224a8 | 179 | |
9994a338 PM |
180 | 2: /* if from kernel, check interrupted DOZE/NAP mode and |
181 | * check for stack overflow | |
182 | */ | |
85218827 KG |
183 | lwz r9,KSP_LIMIT(r12) |
184 | cmplw r1,r9 /* if r1 <= ksp_limit */ | |
f39224a8 PM |
185 | ble- stack_ovf /* then the kernel stack overflowed */ |
186 | 5: | |
fc4033b2 | 187 | #if defined(CONFIG_6xx) || defined(CONFIG_E500) |
9778b696 | 188 | CURRENT_THREAD_INFO(r9, r1) |
f39224a8 PM |
189 | tophys(r9,r9) /* check local flags */ |
190 | lwz r12,TI_LOCAL_FLAGS(r9) | |
191 | mtcrf 0x01,r12 | |
192 | bt- 31-TLF_NAPPING,4f | |
a560643e | 193 | bt- 31-TLF_SLEEPING,7f |
fc4033b2 | 194 | #endif /* CONFIG_6xx || CONFIG_E500 */ |
9994a338 PM |
195 | .globl transfer_to_handler_cont |
196 | transfer_to_handler_cont: | |
9994a338 PM |
197 | 3: |
198 | mflr r9 | |
199 | lwz r11,0(r9) /* virtual address of handler */ | |
200 | lwz r9,4(r9) /* where to go when done */ | |
5d38902c BH |
201 | #ifdef CONFIG_TRACE_IRQFLAGS |
202 | lis r12,reenable_mmu@h | |
203 | ori r12,r12,reenable_mmu@l | |
204 | mtspr SPRN_SRR0,r12 | |
205 | mtspr SPRN_SRR1,r10 | |
206 | SYNC | |
207 | RFI | |
208 | reenable_mmu: /* re-enable mmu so we can */ | |
209 | mfmsr r10 | |
210 | lwz r12,_MSR(r1) | |
211 | xor r10,r10,r12 | |
212 | andi. r10,r10,MSR_EE /* Did EE change? */ | |
213 | beq 1f | |
214 | ||
2cd76629 KH |
215 | /* |
216 | * The trace_hardirqs_off will use CALLER_ADDR0 and CALLER_ADDR1. | |
217 | * If from user mode there is only one stack frame on the stack, and | |
218 | * accessing CALLER_ADDR1 will cause oops. So we need create a dummy | |
219 | * stack frame to make trace_hardirqs_off happy. | |
08f1ec8a BH |
220 | * |
221 | * This is handy because we also need to save a bunch of GPRs, | |
222 | * r3 can be different from GPR3(r1) at this point, r9 and r11 | |
223 | * contains the old MSR and handler address respectively, | |
224 | * r4 & r5 can contain page fault arguments that need to be passed | |
225 | * along as well. r12, CCR, CTR, XER etc... are left clobbered as | |
226 | * they aren't useful past this point (aren't syscall arguments), | |
227 | * the rest is restored from the exception frame. | |
2cd76629 | 228 | */ |
08f1ec8a BH |
229 | stwu r1,-32(r1) |
230 | stw r9,8(r1) | |
231 | stw r11,12(r1) | |
232 | stw r3,16(r1) | |
233 | stw r4,20(r1) | |
234 | stw r5,24(r1) | |
2cd76629 | 235 | bl trace_hardirqs_off |
08f1ec8a BH |
236 | lwz r5,24(r1) |
237 | lwz r4,20(r1) | |
238 | lwz r3,16(r1) | |
239 | lwz r11,12(r1) | |
240 | lwz r9,8(r1) | |
241 | addi r1,r1,32 | |
5d38902c | 242 | lwz r0,GPR0(r1) |
5d38902c BH |
243 | lwz r6,GPR6(r1) |
244 | lwz r7,GPR7(r1) | |
245 | lwz r8,GPR8(r1) | |
5d38902c BH |
246 | 1: mtctr r11 |
247 | mtlr r9 | |
248 | bctr /* jump to handler */ | |
249 | #else /* CONFIG_TRACE_IRQFLAGS */ | |
9994a338 PM |
250 | mtspr SPRN_SRR0,r11 |
251 | mtspr SPRN_SRR1,r10 | |
252 | mtlr r9 | |
253 | SYNC | |
254 | RFI /* jump to handler, enable MMU */ | |
5d38902c | 255 | #endif /* CONFIG_TRACE_IRQFLAGS */ |
9994a338 | 256 | |
fc4033b2 | 257 | #if defined (CONFIG_6xx) || defined(CONFIG_E500) |
f39224a8 PM |
258 | 4: rlwinm r12,r12,0,~_TLF_NAPPING |
259 | stw r12,TI_LOCAL_FLAGS(r9) | |
fc4033b2 | 260 | b power_save_ppc32_restore |
a560643e PM |
261 | |
262 | 7: rlwinm r12,r12,0,~_TLF_SLEEPING | |
263 | stw r12,TI_LOCAL_FLAGS(r9) | |
264 | lwz r9,_MSR(r11) /* if sleeping, clear MSR.EE */ | |
265 | rlwinm r9,r9,0,~MSR_EE | |
266 | lwz r12,_LINK(r11) /* and return to address in LR */ | |
267 | b fast_exception_return | |
a0652fc9 PM |
268 | #endif |
269 | ||
9994a338 PM |
270 | /* |
271 | * On kernel stack overflow, load up an initial stack pointer | |
272 | * and call StackOverflow(regs), which should not return. | |
273 | */ | |
274 | stack_ovf: | |
275 | /* sometimes we use a statically-allocated stack, which is OK. */ | |
f39224a8 PM |
276 | lis r12,_end@h |
277 | ori r12,r12,_end@l | |
278 | cmplw r1,r12 | |
279 | ble 5b /* r1 <= &_end is OK */ | |
9994a338 PM |
280 | SAVE_NVGPRS(r11) |
281 | addi r3,r1,STACK_FRAME_OVERHEAD | |
282 | lis r1,init_thread_union@ha | |
283 | addi r1,r1,init_thread_union@l | |
284 | addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD | |
285 | lis r9,StackOverflow@ha | |
286 | addi r9,r9,StackOverflow@l | |
287 | LOAD_MSR_KERNEL(r10,MSR_KERNEL) | |
288 | FIX_SRR1(r10,r12) | |
289 | mtspr SPRN_SRR0,r9 | |
290 | mtspr SPRN_SRR1,r10 | |
291 | SYNC | |
292 | RFI | |
293 | ||
294 | /* | |
295 | * Handle a system call. | |
296 | */ | |
297 | .stabs "arch/powerpc/kernel/",N_SO,0,0,0f | |
298 | .stabs "entry_32.S",N_SO,0,0,0f | |
299 | 0: | |
300 | ||
301 | _GLOBAL(DoSyscall) | |
9994a338 PM |
302 | stw r3,ORIG_GPR3(r1) |
303 | li r12,0 | |
304 | stw r12,RESULT(r1) | |
305 | lwz r11,_CCR(r1) /* Clear SO bit in CR */ | |
306 | rlwinm r11,r11,0,4,2 | |
307 | stw r11,_CCR(r1) | |
5d38902c BH |
308 | #ifdef CONFIG_TRACE_IRQFLAGS |
309 | /* Return from syscalls can (and generally will) hard enable | |
310 | * interrupts. You aren't supposed to call a syscall with | |
311 | * interrupts disabled in the first place. However, to ensure | |
312 | * that we get it right vs. lockdep if it happens, we force | |
313 | * that hard enable here with appropriate tracing if we see | |
314 | * that we have been called with interrupts off | |
315 | */ | |
316 | mfmsr r11 | |
317 | andi. r12,r11,MSR_EE | |
318 | bne+ 1f | |
319 | /* We came in with interrupts disabled, we enable them now */ | |
320 | bl trace_hardirqs_on | |
321 | mfmsr r11 | |
322 | lwz r0,GPR0(r1) | |
323 | lwz r3,GPR3(r1) | |
324 | lwz r4,GPR4(r1) | |
325 | ori r11,r11,MSR_EE | |
326 | lwz r5,GPR5(r1) | |
327 | lwz r6,GPR6(r1) | |
328 | lwz r7,GPR7(r1) | |
329 | lwz r8,GPR8(r1) | |
330 | mtmsr r11 | |
331 | 1: | |
332 | #endif /* CONFIG_TRACE_IRQFLAGS */ | |
9778b696 | 333 | CURRENT_THREAD_INFO(r10, r1) |
9994a338 | 334 | lwz r11,TI_FLAGS(r10) |
10ea8343 | 335 | andi. r11,r11,_TIF_SYSCALL_DOTRACE |
9994a338 PM |
336 | bne- syscall_dotrace |
337 | syscall_dotrace_cont: | |
338 | cmplwi 0,r0,NR_syscalls | |
339 | lis r10,sys_call_table@h | |
340 | ori r10,r10,sys_call_table@l | |
341 | slwi r0,r0,2 | |
342 | bge- 66f | |
343 | lwzx r10,r10,r0 /* Fetch system call handler [ptr] */ | |
344 | mtlr r10 | |
345 | addi r9,r1,STACK_FRAME_OVERHEAD | |
346 | PPC440EP_ERR42 | |
347 | blrl /* Call handler */ | |
348 | .globl ret_from_syscall | |
349 | ret_from_syscall: | |
9994a338 | 350 | mr r6,r3 |
9778b696 | 351 | CURRENT_THREAD_INFO(r12, r1) |
9994a338 | 352 | /* disable interrupts so current_thread_info()->flags can't change */ |
401d1f02 | 353 | LOAD_MSR_KERNEL(r10,MSR_KERNEL) /* doesn't include MSR_EE */ |
5d38902c | 354 | /* Note: We don't bother telling lockdep about it */ |
9994a338 PM |
355 | SYNC |
356 | MTMSRD(r10) | |
357 | lwz r9,TI_FLAGS(r12) | |
c3525940 | 358 | li r8,-MAX_ERRNO |
10ea8343 | 359 | andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK) |
9994a338 | 360 | bne- syscall_exit_work |
401d1f02 DW |
361 | cmplw 0,r3,r8 |
362 | blt+ syscall_exit_cont | |
363 | lwz r11,_CCR(r1) /* Load CR */ | |
364 | neg r3,r3 | |
365 | oris r11,r11,0x1000 /* Set SO bit in CR */ | |
366 | stw r11,_CCR(r1) | |
9994a338 | 367 | syscall_exit_cont: |
5d38902c BH |
368 | lwz r8,_MSR(r1) |
369 | #ifdef CONFIG_TRACE_IRQFLAGS | |
370 | /* If we are going to return from the syscall with interrupts | |
371 | * off, we trace that here. It shouldn't happen though but we | |
372 | * want to catch the bugger if it does right ? | |
373 | */ | |
374 | andi. r10,r8,MSR_EE | |
375 | bne+ 1f | |
376 | stw r3,GPR3(r1) | |
377 | bl trace_hardirqs_off | |
378 | lwz r3,GPR3(r1) | |
379 | 1: | |
380 | #endif /* CONFIG_TRACE_IRQFLAGS */ | |
9994a338 | 381 | #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE) |
4eaddb4d KG |
382 | /* If the process has its own DBCR0 value, load it up. The internal |
383 | debug mode bit tells us that dbcr0 should be loaded. */ | |
9994a338 | 384 | lwz r0,THREAD+THREAD_DBCR0(r2) |
2325f0a0 | 385 | andis. r10,r0,DBCR0_IDM@h |
9994a338 PM |
386 | bnel- load_dbcr0 |
387 | #endif | |
b98ac05d | 388 | #ifdef CONFIG_44x |
e7f75ad0 | 389 | BEGIN_MMU_FTR_SECTION |
b98ac05d BH |
390 | lis r4,icache_44x_need_flush@ha |
391 | lwz r5,icache_44x_need_flush@l(r4) | |
392 | cmplwi cr0,r5,0 | |
393 | bne- 2f | |
394 | 1: | |
e7f75ad0 | 395 | END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_47x) |
b98ac05d | 396 | #endif /* CONFIG_44x */ |
b64f87c1 BB |
397 | BEGIN_FTR_SECTION |
398 | lwarx r7,0,r1 | |
399 | END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX) | |
9994a338 PM |
400 | stwcx. r0,0,r1 /* to clear the reservation */ |
401 | lwz r4,_LINK(r1) | |
402 | lwz r5,_CCR(r1) | |
403 | mtlr r4 | |
404 | mtcr r5 | |
405 | lwz r7,_NIP(r1) | |
9994a338 PM |
406 | FIX_SRR1(r8, r0) |
407 | lwz r2,GPR2(r1) | |
408 | lwz r1,GPR1(r1) | |
409 | mtspr SPRN_SRR0,r7 | |
410 | mtspr SPRN_SRR1,r8 | |
411 | SYNC | |
412 | RFI | |
b98ac05d BH |
413 | #ifdef CONFIG_44x |
414 | 2: li r7,0 | |
415 | iccci r0,r0 | |
416 | stw r7,icache_44x_need_flush@l(r4) | |
417 | b 1b | |
418 | #endif /* CONFIG_44x */ | |
9994a338 PM |
419 | |
420 | 66: li r3,-ENOSYS | |
421 | b ret_from_syscall | |
422 | ||
423 | .globl ret_from_fork | |
424 | ret_from_fork: | |
425 | REST_NVGPRS(r1) | |
426 | bl schedule_tail | |
427 | li r3,0 | |
428 | b ret_from_syscall | |
429 | ||
58254e10 AV |
430 | .globl ret_from_kernel_thread |
431 | ret_from_kernel_thread: | |
432 | REST_NVGPRS(r1) | |
433 | bl schedule_tail | |
434 | mtlr r14 | |
435 | mr r3,r15 | |
436 | PPC440EP_ERR42 | |
437 | blrl | |
438 | li r3,0 | |
be6abfa7 | 439 | b ret_from_syscall |
9994a338 PM |
440 | |
441 | /* Traced system call support */ | |
442 | syscall_dotrace: | |
443 | SAVE_NVGPRS(r1) | |
444 | li r0,0xc00 | |
d73e0c99 | 445 | stw r0,_TRAP(r1) |
9994a338 PM |
446 | addi r3,r1,STACK_FRAME_OVERHEAD |
447 | bl do_syscall_trace_enter | |
4f72c427 RM |
448 | /* |
449 | * Restore argument registers possibly just changed. | |
450 | * We use the return value of do_syscall_trace_enter | |
451 | * for call number to look up in the table (r0). | |
452 | */ | |
453 | mr r0,r3 | |
9994a338 PM |
454 | lwz r3,GPR3(r1) |
455 | lwz r4,GPR4(r1) | |
456 | lwz r5,GPR5(r1) | |
457 | lwz r6,GPR6(r1) | |
458 | lwz r7,GPR7(r1) | |
459 | lwz r8,GPR8(r1) | |
460 | REST_NVGPRS(r1) | |
461 | b syscall_dotrace_cont | |
462 | ||
463 | syscall_exit_work: | |
401d1f02 | 464 | andi. r0,r9,_TIF_RESTOREALL |
1bd79336 PM |
465 | beq+ 0f |
466 | REST_NVGPRS(r1) | |
467 | b 2f | |
468 | 0: cmplw 0,r3,r8 | |
401d1f02 DW |
469 | blt+ 1f |
470 | andi. r0,r9,_TIF_NOERROR | |
471 | bne- 1f | |
472 | lwz r11,_CCR(r1) /* Load CR */ | |
473 | neg r3,r3 | |
474 | oris r11,r11,0x1000 /* Set SO bit in CR */ | |
475 | stw r11,_CCR(r1) | |
476 | ||
477 | 1: stw r6,RESULT(r1) /* Save result */ | |
9994a338 | 478 | stw r3,GPR3(r1) /* Update return value */ |
401d1f02 DW |
479 | 2: andi. r0,r9,(_TIF_PERSYSCALL_MASK) |
480 | beq 4f | |
481 | ||
1bd79336 | 482 | /* Clear per-syscall TIF flags if any are set. */ |
401d1f02 DW |
483 | |
484 | li r11,_TIF_PERSYSCALL_MASK | |
485 | addi r12,r12,TI_FLAGS | |
486 | 3: lwarx r8,0,r12 | |
487 | andc r8,r8,r11 | |
488 | #ifdef CONFIG_IBM405_ERR77 | |
489 | dcbt 0,r12 | |
490 | #endif | |
491 | stwcx. r8,0,r12 | |
492 | bne- 3b | |
493 | subi r12,r12,TI_FLAGS | |
494 | ||
495 | 4: /* Anything which requires enabling interrupts? */ | |
10ea8343 | 496 | andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP) |
1bd79336 PM |
497 | beq ret_from_except |
498 | ||
5d38902c BH |
499 | /* Re-enable interrupts. There is no need to trace that with |
500 | * lockdep as we are supposed to have IRQs on at this point | |
501 | */ | |
1bd79336 PM |
502 | ori r10,r10,MSR_EE |
503 | SYNC | |
504 | MTMSRD(r10) | |
401d1f02 DW |
505 | |
506 | /* Save NVGPRS if they're not saved already */ | |
d73e0c99 | 507 | lwz r4,_TRAP(r1) |
9994a338 | 508 | andi. r4,r4,1 |
401d1f02 | 509 | beq 5f |
9994a338 PM |
510 | SAVE_NVGPRS(r1) |
511 | li r4,0xc00 | |
d73e0c99 | 512 | stw r4,_TRAP(r1) |
1bd79336 | 513 | 5: |
9994a338 PM |
514 | addi r3,r1,STACK_FRAME_OVERHEAD |
515 | bl do_syscall_trace_leave | |
1bd79336 | 516 | b ret_from_except_full |
9994a338 | 517 | |
9994a338 | 518 | /* |
401d1f02 DW |
519 | * The fork/clone functions need to copy the full register set into |
520 | * the child process. Therefore we need to save all the nonvolatile | |
521 | * registers (r13 - r31) before calling the C code. | |
9994a338 | 522 | */ |
9994a338 PM |
523 | .globl ppc_fork |
524 | ppc_fork: | |
525 | SAVE_NVGPRS(r1) | |
d73e0c99 | 526 | lwz r0,_TRAP(r1) |
9994a338 | 527 | rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */ |
d73e0c99 | 528 | stw r0,_TRAP(r1) /* register set saved */ |
9994a338 PM |
529 | b sys_fork |
530 | ||
531 | .globl ppc_vfork | |
532 | ppc_vfork: | |
533 | SAVE_NVGPRS(r1) | |
d73e0c99 | 534 | lwz r0,_TRAP(r1) |
9994a338 | 535 | rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */ |
d73e0c99 | 536 | stw r0,_TRAP(r1) /* register set saved */ |
9994a338 PM |
537 | b sys_vfork |
538 | ||
539 | .globl ppc_clone | |
540 | ppc_clone: | |
541 | SAVE_NVGPRS(r1) | |
d73e0c99 | 542 | lwz r0,_TRAP(r1) |
9994a338 | 543 | rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */ |
d73e0c99 | 544 | stw r0,_TRAP(r1) /* register set saved */ |
9994a338 PM |
545 | b sys_clone |
546 | ||
1bd79336 PM |
547 | .globl ppc_swapcontext |
548 | ppc_swapcontext: | |
549 | SAVE_NVGPRS(r1) | |
550 | lwz r0,_TRAP(r1) | |
551 | rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */ | |
552 | stw r0,_TRAP(r1) /* register set saved */ | |
553 | b sys_swapcontext | |
554 | ||
9994a338 PM |
555 | /* |
556 | * Top-level page fault handling. | |
557 | * This is in assembler because if do_page_fault tells us that | |
558 | * it is a bad kernel page fault, we want to save the non-volatile | |
559 | * registers before calling bad_page_fault. | |
560 | */ | |
561 | .globl handle_page_fault | |
562 | handle_page_fault: | |
563 | stw r4,_DAR(r1) | |
564 | addi r3,r1,STACK_FRAME_OVERHEAD | |
565 | bl do_page_fault | |
566 | cmpwi r3,0 | |
567 | beq+ ret_from_except | |
568 | SAVE_NVGPRS(r1) | |
d73e0c99 | 569 | lwz r0,_TRAP(r1) |
9994a338 | 570 | clrrwi r0,r0,1 |
d73e0c99 | 571 | stw r0,_TRAP(r1) |
9994a338 PM |
572 | mr r5,r3 |
573 | addi r3,r1,STACK_FRAME_OVERHEAD | |
574 | lwz r4,_DAR(r1) | |
575 | bl bad_page_fault | |
576 | b ret_from_except_full | |
577 | ||
578 | /* | |
579 | * This routine switches between two different tasks. The process | |
580 | * state of one is saved on its kernel stack. Then the state | |
581 | * of the other is restored from its kernel stack. The memory | |
582 | * management hardware is updated to the second process's state. | |
583 | * Finally, we can return to the second process. | |
584 | * On entry, r3 points to the THREAD for the current task, r4 | |
585 | * points to the THREAD for the new task. | |
586 | * | |
587 | * This routine is always called with interrupts disabled. | |
588 | * | |
589 | * Note: there are two ways to get to the "going out" portion | |
590 | * of this code; either by coming in via the entry (_switch) | |
591 | * or via "fork" which must set up an environment equivalent | |
592 | * to the "_switch" path. If you change this , you'll have to | |
593 | * change the fork code also. | |
594 | * | |
595 | * The code which creates the new task context is in 'copy_thread' | |
596 | * in arch/ppc/kernel/process.c | |
597 | */ | |
598 | _GLOBAL(_switch) | |
599 | stwu r1,-INT_FRAME_SIZE(r1) | |
600 | mflr r0 | |
601 | stw r0,INT_FRAME_SIZE+4(r1) | |
602 | /* r3-r12 are caller saved -- Cort */ | |
603 | SAVE_NVGPRS(r1) | |
604 | stw r0,_NIP(r1) /* Return to switch caller */ | |
605 | mfmsr r11 | |
606 | li r0,MSR_FP /* Disable floating-point */ | |
607 | #ifdef CONFIG_ALTIVEC | |
608 | BEGIN_FTR_SECTION | |
609 | oris r0,r0,MSR_VEC@h /* Disable altivec */ | |
610 | mfspr r12,SPRN_VRSAVE /* save vrsave register value */ | |
611 | stw r12,THREAD+THREAD_VRSAVE(r2) | |
612 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) | |
613 | #endif /* CONFIG_ALTIVEC */ | |
614 | #ifdef CONFIG_SPE | |
5e14d21e | 615 | BEGIN_FTR_SECTION |
9994a338 PM |
616 | oris r0,r0,MSR_SPE@h /* Disable SPE */ |
617 | mfspr r12,SPRN_SPEFSCR /* save spefscr register value */ | |
618 | stw r12,THREAD+THREAD_SPEFSCR(r2) | |
5e14d21e | 619 | END_FTR_SECTION_IFSET(CPU_FTR_SPE) |
9994a338 PM |
620 | #endif /* CONFIG_SPE */ |
621 | and. r0,r0,r11 /* FP or altivec or SPE enabled? */ | |
622 | beq+ 1f | |
623 | andc r11,r11,r0 | |
624 | MTMSRD(r11) | |
625 | isync | |
626 | 1: stw r11,_MSR(r1) | |
627 | mfcr r10 | |
628 | stw r10,_CCR(r1) | |
629 | stw r1,KSP(r3) /* Set old stack pointer */ | |
630 | ||
631 | #ifdef CONFIG_SMP | |
632 | /* We need a sync somewhere here to make sure that if the | |
633 | * previous task gets rescheduled on another CPU, it sees all | |
634 | * stores it has performed on this one. | |
635 | */ | |
636 | sync | |
637 | #endif /* CONFIG_SMP */ | |
638 | ||
639 | tophys(r0,r4) | |
640 | CLR_TOP32(r0) | |
ee43eb78 | 641 | mtspr SPRN_SPRG_THREAD,r0 /* Update current THREAD phys addr */ |
9994a338 PM |
642 | lwz r1,KSP(r4) /* Load new stack pointer */ |
643 | ||
644 | /* save the old current 'last' for return value */ | |
645 | mr r3,r2 | |
646 | addi r2,r4,-THREAD /* Update current */ | |
647 | ||
648 | #ifdef CONFIG_ALTIVEC | |
649 | BEGIN_FTR_SECTION | |
650 | lwz r0,THREAD+THREAD_VRSAVE(r2) | |
651 | mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */ | |
652 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) | |
653 | #endif /* CONFIG_ALTIVEC */ | |
654 | #ifdef CONFIG_SPE | |
5e14d21e | 655 | BEGIN_FTR_SECTION |
9994a338 PM |
656 | lwz r0,THREAD+THREAD_SPEFSCR(r2) |
657 | mtspr SPRN_SPEFSCR,r0 /* restore SPEFSCR reg */ | |
5e14d21e | 658 | END_FTR_SECTION_IFSET(CPU_FTR_SPE) |
9994a338 PM |
659 | #endif /* CONFIG_SPE */ |
660 | ||
661 | lwz r0,_CCR(r1) | |
662 | mtcrf 0xFF,r0 | |
663 | /* r3-r12 are destroyed -- Cort */ | |
664 | REST_NVGPRS(r1) | |
665 | ||
666 | lwz r4,_NIP(r1) /* Return to _switch caller in new task */ | |
667 | mtlr r4 | |
668 | addi r1,r1,INT_FRAME_SIZE | |
669 | blr | |
670 | ||
671 | .globl fast_exception_return | |
672 | fast_exception_return: | |
673 | #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE)) | |
674 | andi. r10,r9,MSR_RI /* check for recoverable interrupt */ | |
675 | beq 1f /* if not, we've got problems */ | |
676 | #endif | |
677 | ||
678 | 2: REST_4GPRS(3, r11) | |
679 | lwz r10,_CCR(r11) | |
680 | REST_GPR(1, r11) | |
681 | mtcr r10 | |
682 | lwz r10,_LINK(r11) | |
683 | mtlr r10 | |
684 | REST_GPR(10, r11) | |
685 | mtspr SPRN_SRR1,r9 | |
686 | mtspr SPRN_SRR0,r12 | |
687 | REST_GPR(9, r11) | |
688 | REST_GPR(12, r11) | |
689 | lwz r11,GPR11(r11) | |
690 | SYNC | |
691 | RFI | |
692 | ||
693 | #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE)) | |
694 | /* check if the exception happened in a restartable section */ | |
695 | 1: lis r3,exc_exit_restart_end@ha | |
696 | addi r3,r3,exc_exit_restart_end@l | |
697 | cmplw r12,r3 | |
698 | bge 3f | |
699 | lis r4,exc_exit_restart@ha | |
700 | addi r4,r4,exc_exit_restart@l | |
701 | cmplw r12,r4 | |
702 | blt 3f | |
703 | lis r3,fee_restarts@ha | |
704 | tophys(r3,r3) | |
705 | lwz r5,fee_restarts@l(r3) | |
706 | addi r5,r5,1 | |
707 | stw r5,fee_restarts@l(r3) | |
708 | mr r12,r4 /* restart at exc_exit_restart */ | |
709 | b 2b | |
710 | ||
991eb43a KG |
711 | .section .bss |
712 | .align 2 | |
713 | fee_restarts: | |
714 | .space 4 | |
715 | .previous | |
9994a338 PM |
716 | |
717 | /* aargh, a nonrecoverable interrupt, panic */ | |
718 | /* aargh, we don't know which trap this is */ | |
719 | /* but the 601 doesn't implement the RI bit, so assume it's OK */ | |
720 | 3: | |
721 | BEGIN_FTR_SECTION | |
722 | b 2b | |
723 | END_FTR_SECTION_IFSET(CPU_FTR_601) | |
724 | li r10,-1 | |
d73e0c99 | 725 | stw r10,_TRAP(r11) |
9994a338 PM |
726 | addi r3,r1,STACK_FRAME_OVERHEAD |
727 | lis r10,MSR_KERNEL@h | |
728 | ori r10,r10,MSR_KERNEL@l | |
729 | bl transfer_to_handler_full | |
730 | .long nonrecoverable_exception | |
731 | .long ret_from_except | |
732 | #endif | |
733 | ||
9994a338 PM |
734 | .globl ret_from_except_full |
735 | ret_from_except_full: | |
736 | REST_NVGPRS(r1) | |
737 | /* fall through */ | |
738 | ||
739 | .globl ret_from_except | |
740 | ret_from_except: | |
741 | /* Hard-disable interrupts so that current_thread_info()->flags | |
742 | * can't change between when we test it and when we return | |
743 | * from the interrupt. */ | |
5d38902c | 744 | /* Note: We don't bother telling lockdep about it */ |
9994a338 PM |
745 | LOAD_MSR_KERNEL(r10,MSR_KERNEL) |
746 | SYNC /* Some chip revs have problems here... */ | |
747 | MTMSRD(r10) /* disable interrupts */ | |
748 | ||
749 | lwz r3,_MSR(r1) /* Returning to user mode? */ | |
750 | andi. r0,r3,MSR_PR | |
751 | beq resume_kernel | |
752 | ||
753 | user_exc_return: /* r10 contains MSR_KERNEL here */ | |
754 | /* Check current_thread_info()->flags */ | |
9778b696 | 755 | CURRENT_THREAD_INFO(r9, r1) |
9994a338 | 756 | lwz r9,TI_FLAGS(r9) |
7a10174e | 757 | andi. r0,r9,_TIF_USER_WORK_MASK |
9994a338 PM |
758 | bne do_work |
759 | ||
760 | restore_user: | |
761 | #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE) | |
4eaddb4d KG |
762 | /* Check whether this process has its own DBCR0 value. The internal |
763 | debug mode bit tells us that dbcr0 should be loaded. */ | |
9994a338 | 764 | lwz r0,THREAD+THREAD_DBCR0(r2) |
2325f0a0 | 765 | andis. r10,r0,DBCR0_IDM@h |
9994a338 PM |
766 | bnel- load_dbcr0 |
767 | #endif | |
768 | ||
9994a338 PM |
769 | b restore |
770 | ||
771 | /* N.B. the only way to get here is from the beq following ret_from_except. */ | |
772 | resume_kernel: | |
a9c4e541 | 773 | /* check current_thread_info, _TIF_EMULATE_STACK_STORE */ |
9778b696 | 774 | CURRENT_THREAD_INFO(r9, r1) |
a9c4e541 | 775 | lwz r8,TI_FLAGS(r9) |
f7b33677 | 776 | andis. r0,r8,_TIF_EMULATE_STACK_STORE@h |
a9c4e541 TC |
777 | beq+ 1f |
778 | ||
779 | addi r8,r1,INT_FRAME_SIZE /* Get the kprobed function entry */ | |
780 | ||
781 | lwz r3,GPR1(r1) | |
782 | subi r3,r3,INT_FRAME_SIZE /* dst: Allocate a trampoline exception frame */ | |
783 | mr r4,r1 /* src: current exception frame */ | |
784 | mr r1,r3 /* Reroute the trampoline frame to r1 */ | |
785 | ||
786 | /* Copy from the original to the trampoline. */ | |
787 | li r5,INT_FRAME_SIZE/4 /* size: INT_FRAME_SIZE */ | |
788 | li r6,0 /* start offset: 0 */ | |
789 | mtctr r5 | |
790 | 2: lwzx r0,r6,r4 | |
791 | stwx r0,r6,r3 | |
792 | addi r6,r6,4 | |
793 | bdnz 2b | |
794 | ||
795 | /* Do real store operation to complete stwu */ | |
796 | lwz r5,GPR1(r1) | |
797 | stw r8,0(r5) | |
798 | ||
799 | /* Clear _TIF_EMULATE_STACK_STORE flag */ | |
800 | lis r11,_TIF_EMULATE_STACK_STORE@h | |
801 | addi r5,r9,TI_FLAGS | |
802 | 0: lwarx r8,0,r5 | |
803 | andc r8,r8,r11 | |
804 | #ifdef CONFIG_IBM405_ERR77 | |
805 | dcbt 0,r5 | |
806 | #endif | |
807 | stwcx. r8,0,r5 | |
808 | bne- 0b | |
809 | 1: | |
810 | ||
811 | #ifdef CONFIG_PREEMPT | |
812 | /* check current_thread_info->preempt_count */ | |
9994a338 PM |
813 | lwz r0,TI_PREEMPT(r9) |
814 | cmpwi 0,r0,0 /* if non-zero, just restore regs and return */ | |
815 | bne restore | |
a9c4e541 | 816 | andi. r8,r8,_TIF_NEED_RESCHED |
9994a338 | 817 | beq+ restore |
a9c4e541 | 818 | lwz r3,_MSR(r1) |
9994a338 PM |
819 | andi. r0,r3,MSR_EE /* interrupts off? */ |
820 | beq restore /* don't schedule if so */ | |
5d38902c BH |
821 | #ifdef CONFIG_TRACE_IRQFLAGS |
822 | /* Lockdep thinks irqs are enabled, we need to call | |
823 | * preempt_schedule_irq with IRQs off, so we inform lockdep | |
824 | * now that we -did- turn them off already | |
825 | */ | |
826 | bl trace_hardirqs_off | |
827 | #endif | |
9994a338 | 828 | 1: bl preempt_schedule_irq |
9778b696 | 829 | CURRENT_THREAD_INFO(r9, r1) |
9994a338 PM |
830 | lwz r3,TI_FLAGS(r9) |
831 | andi. r0,r3,_TIF_NEED_RESCHED | |
832 | bne- 1b | |
5d38902c BH |
833 | #ifdef CONFIG_TRACE_IRQFLAGS |
834 | /* And now, to properly rebalance the above, we tell lockdep they | |
835 | * are being turned back on, which will happen when we return | |
836 | */ | |
837 | bl trace_hardirqs_on | |
838 | #endif | |
9994a338 PM |
839 | #endif /* CONFIG_PREEMPT */ |
840 | ||
841 | /* interrupts are hard-disabled at this point */ | |
842 | restore: | |
b98ac05d | 843 | #ifdef CONFIG_44x |
e7f75ad0 DK |
844 | BEGIN_MMU_FTR_SECTION |
845 | b 1f | |
846 | END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_47x) | |
b98ac05d BH |
847 | lis r4,icache_44x_need_flush@ha |
848 | lwz r5,icache_44x_need_flush@l(r4) | |
849 | cmplwi cr0,r5,0 | |
850 | beq+ 1f | |
851 | li r6,0 | |
852 | iccci r0,r0 | |
853 | stw r6,icache_44x_need_flush@l(r4) | |
854 | 1: | |
855 | #endif /* CONFIG_44x */ | |
5d38902c BH |
856 | |
857 | lwz r9,_MSR(r1) | |
858 | #ifdef CONFIG_TRACE_IRQFLAGS | |
859 | /* Lockdep doesn't know about the fact that IRQs are temporarily turned | |
860 | * off in this assembly code while peeking at TI_FLAGS() and such. However | |
861 | * we need to inform it if the exception turned interrupts off, and we | |
862 | * are about to trun them back on. | |
863 | * | |
864 | * The problem here sadly is that we don't know whether the exceptions was | |
865 | * one that turned interrupts off or not. So we always tell lockdep about | |
866 | * turning them on here when we go back to wherever we came from with EE | |
867 | * on, even if that may meen some redudant calls being tracked. Maybe later | |
868 | * we could encode what the exception did somewhere or test the exception | |
869 | * type in the pt_regs but that sounds overkill | |
870 | */ | |
871 | andi. r10,r9,MSR_EE | |
872 | beq 1f | |
06ca2188 SR |
873 | /* |
874 | * Since the ftrace irqsoff latency trace checks CALLER_ADDR1, | |
875 | * which is the stack frame here, we need to force a stack frame | |
876 | * in case we came from user space. | |
877 | */ | |
878 | stwu r1,-32(r1) | |
879 | mflr r0 | |
880 | stw r0,4(r1) | |
881 | stwu r1,-32(r1) | |
5d38902c | 882 | bl trace_hardirqs_on |
06ca2188 SR |
883 | lwz r1,0(r1) |
884 | lwz r1,0(r1) | |
5d38902c BH |
885 | lwz r9,_MSR(r1) |
886 | 1: | |
887 | #endif /* CONFIG_TRACE_IRQFLAGS */ | |
888 | ||
9994a338 PM |
889 | lwz r0,GPR0(r1) |
890 | lwz r2,GPR2(r1) | |
891 | REST_4GPRS(3, r1) | |
892 | REST_2GPRS(7, r1) | |
893 | ||
894 | lwz r10,_XER(r1) | |
895 | lwz r11,_CTR(r1) | |
896 | mtspr SPRN_XER,r10 | |
897 | mtctr r11 | |
898 | ||
899 | PPC405_ERR77(0,r1) | |
b64f87c1 BB |
900 | BEGIN_FTR_SECTION |
901 | lwarx r11,0,r1 | |
902 | END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX) | |
9994a338 PM |
903 | stwcx. r0,0,r1 /* to clear the reservation */ |
904 | ||
905 | #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE)) | |
9994a338 PM |
906 | andi. r10,r9,MSR_RI /* check if this exception occurred */ |
907 | beql nonrecoverable /* at a bad place (MSR:RI = 0) */ | |
908 | ||
909 | lwz r10,_CCR(r1) | |
910 | lwz r11,_LINK(r1) | |
911 | mtcrf 0xFF,r10 | |
912 | mtlr r11 | |
913 | ||
914 | /* | |
915 | * Once we put values in SRR0 and SRR1, we are in a state | |
916 | * where exceptions are not recoverable, since taking an | |
917 | * exception will trash SRR0 and SRR1. Therefore we clear the | |
918 | * MSR:RI bit to indicate this. If we do take an exception, | |
919 | * we can't return to the point of the exception but we | |
920 | * can restart the exception exit path at the label | |
921 | * exc_exit_restart below. -- paulus | |
922 | */ | |
923 | LOAD_MSR_KERNEL(r10,MSR_KERNEL & ~MSR_RI) | |
924 | SYNC | |
925 | MTMSRD(r10) /* clear the RI bit */ | |
926 | .globl exc_exit_restart | |
927 | exc_exit_restart: | |
9994a338 PM |
928 | lwz r12,_NIP(r1) |
929 | FIX_SRR1(r9,r10) | |
930 | mtspr SPRN_SRR0,r12 | |
931 | mtspr SPRN_SRR1,r9 | |
932 | REST_4GPRS(9, r1) | |
933 | lwz r1,GPR1(r1) | |
934 | .globl exc_exit_restart_end | |
935 | exc_exit_restart_end: | |
936 | SYNC | |
937 | RFI | |
938 | ||
939 | #else /* !(CONFIG_4xx || CONFIG_BOOKE) */ | |
940 | /* | |
941 | * This is a bit different on 4xx/Book-E because it doesn't have | |
942 | * the RI bit in the MSR. | |
943 | * The TLB miss handler checks if we have interrupted | |
944 | * the exception exit path and restarts it if so | |
945 | * (well maybe one day it will... :). | |
946 | */ | |
947 | lwz r11,_LINK(r1) | |
948 | mtlr r11 | |
949 | lwz r10,_CCR(r1) | |
950 | mtcrf 0xff,r10 | |
951 | REST_2GPRS(9, r1) | |
952 | .globl exc_exit_restart | |
953 | exc_exit_restart: | |
954 | lwz r11,_NIP(r1) | |
955 | lwz r12,_MSR(r1) | |
956 | exc_exit_start: | |
957 | mtspr SPRN_SRR0,r11 | |
958 | mtspr SPRN_SRR1,r12 | |
959 | REST_2GPRS(11, r1) | |
960 | lwz r1,GPR1(r1) | |
961 | .globl exc_exit_restart_end | |
962 | exc_exit_restart_end: | |
963 | PPC405_ERR77_SYNC | |
964 | rfi | |
965 | b . /* prevent prefetch past rfi */ | |
966 | ||
967 | /* | |
968 | * Returning from a critical interrupt in user mode doesn't need | |
969 | * to be any different from a normal exception. For a critical | |
970 | * interrupt in the kernel, we just return (without checking for | |
971 | * preemption) since the interrupt may have happened at some crucial | |
972 | * place (e.g. inside the TLB miss handler), and because we will be | |
973 | * running with r1 pointing into critical_stack, not the current | |
974 | * process's kernel stack (and therefore current_thread_info() will | |
975 | * give the wrong answer). | |
976 | * We have to restore various SPRs that may have been in use at the | |
977 | * time of the critical interrupt. | |
978 | * | |
979 | */ | |
980 | #ifdef CONFIG_40x | |
981 | #define PPC_40x_TURN_OFF_MSR_DR \ | |
982 | /* avoid any possible TLB misses here by turning off MSR.DR, we \ | |
983 | * assume the instructions here are mapped by a pinned TLB entry */ \ | |
984 | li r10,MSR_IR; \ | |
985 | mtmsr r10; \ | |
986 | isync; \ | |
987 | tophys(r1, r1); | |
988 | #else | |
989 | #define PPC_40x_TURN_OFF_MSR_DR | |
990 | #endif | |
991 | ||
992 | #define RET_FROM_EXC_LEVEL(exc_lvl_srr0, exc_lvl_srr1, exc_lvl_rfi) \ | |
993 | REST_NVGPRS(r1); \ | |
994 | lwz r3,_MSR(r1); \ | |
995 | andi. r3,r3,MSR_PR; \ | |
996 | LOAD_MSR_KERNEL(r10,MSR_KERNEL); \ | |
997 | bne user_exc_return; \ | |
998 | lwz r0,GPR0(r1); \ | |
999 | lwz r2,GPR2(r1); \ | |
1000 | REST_4GPRS(3, r1); \ | |
1001 | REST_2GPRS(7, r1); \ | |
1002 | lwz r10,_XER(r1); \ | |
1003 | lwz r11,_CTR(r1); \ | |
1004 | mtspr SPRN_XER,r10; \ | |
1005 | mtctr r11; \ | |
1006 | PPC405_ERR77(0,r1); \ | |
1007 | stwcx. r0,0,r1; /* to clear the reservation */ \ | |
1008 | lwz r11,_LINK(r1); \ | |
1009 | mtlr r11; \ | |
1010 | lwz r10,_CCR(r1); \ | |
1011 | mtcrf 0xff,r10; \ | |
1012 | PPC_40x_TURN_OFF_MSR_DR; \ | |
1013 | lwz r9,_DEAR(r1); \ | |
1014 | lwz r10,_ESR(r1); \ | |
1015 | mtspr SPRN_DEAR,r9; \ | |
1016 | mtspr SPRN_ESR,r10; \ | |
1017 | lwz r11,_NIP(r1); \ | |
1018 | lwz r12,_MSR(r1); \ | |
1019 | mtspr exc_lvl_srr0,r11; \ | |
1020 | mtspr exc_lvl_srr1,r12; \ | |
1021 | lwz r9,GPR9(r1); \ | |
1022 | lwz r12,GPR12(r1); \ | |
1023 | lwz r10,GPR10(r1); \ | |
1024 | lwz r11,GPR11(r1); \ | |
1025 | lwz r1,GPR1(r1); \ | |
1026 | PPC405_ERR77_SYNC; \ | |
1027 | exc_lvl_rfi; \ | |
1028 | b .; /* prevent prefetch past exc_lvl_rfi */ | |
1029 | ||
fca622c5 KG |
1030 | #define RESTORE_xSRR(exc_lvl_srr0, exc_lvl_srr1) \ |
1031 | lwz r9,_##exc_lvl_srr0(r1); \ | |
1032 | lwz r10,_##exc_lvl_srr1(r1); \ | |
1033 | mtspr SPRN_##exc_lvl_srr0,r9; \ | |
1034 | mtspr SPRN_##exc_lvl_srr1,r10; | |
1035 | ||
70fe3af8 | 1036 | #if defined(CONFIG_PPC_BOOK3E_MMU) |
fca622c5 KG |
1037 | #ifdef CONFIG_PHYS_64BIT |
1038 | #define RESTORE_MAS7 \ | |
1039 | lwz r11,MAS7(r1); \ | |
1040 | mtspr SPRN_MAS7,r11; | |
1041 | #else | |
1042 | #define RESTORE_MAS7 | |
1043 | #endif /* CONFIG_PHYS_64BIT */ | |
1044 | #define RESTORE_MMU_REGS \ | |
1045 | lwz r9,MAS0(r1); \ | |
1046 | lwz r10,MAS1(r1); \ | |
1047 | lwz r11,MAS2(r1); \ | |
1048 | mtspr SPRN_MAS0,r9; \ | |
1049 | lwz r9,MAS3(r1); \ | |
1050 | mtspr SPRN_MAS1,r10; \ | |
1051 | lwz r10,MAS6(r1); \ | |
1052 | mtspr SPRN_MAS2,r11; \ | |
1053 | mtspr SPRN_MAS3,r9; \ | |
1054 | mtspr SPRN_MAS6,r10; \ | |
1055 | RESTORE_MAS7; | |
1056 | #elif defined(CONFIG_44x) | |
1057 | #define RESTORE_MMU_REGS \ | |
1058 | lwz r9,MMUCR(r1); \ | |
1059 | mtspr SPRN_MMUCR,r9; | |
1060 | #else | |
1061 | #define RESTORE_MMU_REGS | |
1062 | #endif | |
1063 | ||
1064 | #ifdef CONFIG_40x | |
9994a338 PM |
1065 | .globl ret_from_crit_exc |
1066 | ret_from_crit_exc: | |
ee43eb78 | 1067 | mfspr r9,SPRN_SPRG_THREAD |
fca622c5 KG |
1068 | lis r10,saved_ksp_limit@ha; |
1069 | lwz r10,saved_ksp_limit@l(r10); | |
1070 | tovirt(r9,r9); | |
1071 | stw r10,KSP_LIMIT(r9) | |
1072 | lis r9,crit_srr0@ha; | |
1073 | lwz r9,crit_srr0@l(r9); | |
1074 | lis r10,crit_srr1@ha; | |
1075 | lwz r10,crit_srr1@l(r10); | |
1076 | mtspr SPRN_SRR0,r9; | |
1077 | mtspr SPRN_SRR1,r10; | |
16c57b36 | 1078 | RET_FROM_EXC_LEVEL(SPRN_CSRR0, SPRN_CSRR1, PPC_RFCI) |
fca622c5 | 1079 | #endif /* CONFIG_40x */ |
9994a338 PM |
1080 | |
1081 | #ifdef CONFIG_BOOKE | |
fca622c5 KG |
1082 | .globl ret_from_crit_exc |
1083 | ret_from_crit_exc: | |
ee43eb78 | 1084 | mfspr r9,SPRN_SPRG_THREAD |
fca622c5 KG |
1085 | lwz r10,SAVED_KSP_LIMIT(r1) |
1086 | stw r10,KSP_LIMIT(r9) | |
1087 | RESTORE_xSRR(SRR0,SRR1); | |
1088 | RESTORE_MMU_REGS; | |
16c57b36 | 1089 | RET_FROM_EXC_LEVEL(SPRN_CSRR0, SPRN_CSRR1, PPC_RFCI) |
fca622c5 | 1090 | |
9994a338 PM |
1091 | .globl ret_from_debug_exc |
1092 | ret_from_debug_exc: | |
ee43eb78 | 1093 | mfspr r9,SPRN_SPRG_THREAD |
fca622c5 KG |
1094 | lwz r10,SAVED_KSP_LIMIT(r1) |
1095 | stw r10,KSP_LIMIT(r9) | |
1096 | lwz r9,THREAD_INFO-THREAD(r9) | |
9778b696 | 1097 | CURRENT_THREAD_INFO(r10, r1) |
fca622c5 KG |
1098 | lwz r10,TI_PREEMPT(r10) |
1099 | stw r10,TI_PREEMPT(r9) | |
1100 | RESTORE_xSRR(SRR0,SRR1); | |
1101 | RESTORE_xSRR(CSRR0,CSRR1); | |
1102 | RESTORE_MMU_REGS; | |
16c57b36 | 1103 | RET_FROM_EXC_LEVEL(SPRN_DSRR0, SPRN_DSRR1, PPC_RFDI) |
9994a338 PM |
1104 | |
1105 | .globl ret_from_mcheck_exc | |
1106 | ret_from_mcheck_exc: | |
ee43eb78 | 1107 | mfspr r9,SPRN_SPRG_THREAD |
fca622c5 KG |
1108 | lwz r10,SAVED_KSP_LIMIT(r1) |
1109 | stw r10,KSP_LIMIT(r9) | |
1110 | RESTORE_xSRR(SRR0,SRR1); | |
1111 | RESTORE_xSRR(CSRR0,CSRR1); | |
1112 | RESTORE_xSRR(DSRR0,DSRR1); | |
1113 | RESTORE_MMU_REGS; | |
16c57b36 | 1114 | RET_FROM_EXC_LEVEL(SPRN_MCSRR0, SPRN_MCSRR1, PPC_RFMCI) |
9994a338 PM |
1115 | #endif /* CONFIG_BOOKE */ |
1116 | ||
1117 | /* | |
1118 | * Load the DBCR0 value for a task that is being ptraced, | |
1119 | * having first saved away the global DBCR0. Note that r0 | |
1120 | * has the dbcr0 value to set upon entry to this. | |
1121 | */ | |
1122 | load_dbcr0: | |
1123 | mfmsr r10 /* first disable debug exceptions */ | |
1124 | rlwinm r10,r10,0,~MSR_DE | |
1125 | mtmsr r10 | |
1126 | isync | |
1127 | mfspr r10,SPRN_DBCR0 | |
1128 | lis r11,global_dbcr0@ha | |
1129 | addi r11,r11,global_dbcr0@l | |
4eaddb4d | 1130 | #ifdef CONFIG_SMP |
9778b696 | 1131 | CURRENT_THREAD_INFO(r9, r1) |
4eaddb4d KG |
1132 | lwz r9,TI_CPU(r9) |
1133 | slwi r9,r9,3 | |
1134 | add r11,r11,r9 | |
1135 | #endif | |
9994a338 PM |
1136 | stw r10,0(r11) |
1137 | mtspr SPRN_DBCR0,r0 | |
1138 | lwz r10,4(r11) | |
1139 | addi r10,r10,1 | |
1140 | stw r10,4(r11) | |
1141 | li r11,-1 | |
1142 | mtspr SPRN_DBSR,r11 /* clear all pending debug events */ | |
1143 | blr | |
1144 | ||
991eb43a KG |
1145 | .section .bss |
1146 | .align 4 | |
1147 | global_dbcr0: | |
4eaddb4d | 1148 | .space 8*NR_CPUS |
991eb43a | 1149 | .previous |
9994a338 PM |
1150 | #endif /* !(CONFIG_4xx || CONFIG_BOOKE) */ |
1151 | ||
1152 | do_work: /* r10 contains MSR_KERNEL here */ | |
1153 | andi. r0,r9,_TIF_NEED_RESCHED | |
1154 | beq do_user_signal | |
1155 | ||
1156 | do_resched: /* r10 contains MSR_KERNEL here */ | |
5d38902c BH |
1157 | /* Note: We don't need to inform lockdep that we are enabling |
1158 | * interrupts here. As far as it knows, they are already enabled | |
1159 | */ | |
9994a338 PM |
1160 | ori r10,r10,MSR_EE |
1161 | SYNC | |
1162 | MTMSRD(r10) /* hard-enable interrupts */ | |
1163 | bl schedule | |
1164 | recheck: | |
5d38902c BH |
1165 | /* Note: And we don't tell it we are disabling them again |
1166 | * neither. Those disable/enable cycles used to peek at | |
1167 | * TI_FLAGS aren't advertised. | |
1168 | */ | |
9994a338 PM |
1169 | LOAD_MSR_KERNEL(r10,MSR_KERNEL) |
1170 | SYNC | |
1171 | MTMSRD(r10) /* disable interrupts */ | |
9778b696 | 1172 | CURRENT_THREAD_INFO(r9, r1) |
9994a338 PM |
1173 | lwz r9,TI_FLAGS(r9) |
1174 | andi. r0,r9,_TIF_NEED_RESCHED | |
1175 | bne- do_resched | |
7a10174e | 1176 | andi. r0,r9,_TIF_USER_WORK_MASK |
9994a338 PM |
1177 | beq restore_user |
1178 | do_user_signal: /* r10 contains MSR_KERNEL here */ | |
1179 | ori r10,r10,MSR_EE | |
1180 | SYNC | |
1181 | MTMSRD(r10) /* hard-enable interrupts */ | |
1182 | /* save r13-r31 in the exception frame, if not already done */ | |
d73e0c99 | 1183 | lwz r3,_TRAP(r1) |
9994a338 PM |
1184 | andi. r0,r3,1 |
1185 | beq 2f | |
1186 | SAVE_NVGPRS(r1) | |
1187 | rlwinm r3,r3,0,0,30 | |
d73e0c99 | 1188 | stw r3,_TRAP(r1) |
7d6d637d RM |
1189 | 2: addi r3,r1,STACK_FRAME_OVERHEAD |
1190 | mr r4,r9 | |
18b246fa | 1191 | bl do_notify_resume |
9994a338 PM |
1192 | REST_NVGPRS(r1) |
1193 | b recheck | |
1194 | ||
1195 | /* | |
1196 | * We come here when we are at the end of handling an exception | |
1197 | * that occurred at a place where taking an exception will lose | |
1198 | * state information, such as the contents of SRR0 and SRR1. | |
1199 | */ | |
1200 | nonrecoverable: | |
1201 | lis r10,exc_exit_restart_end@ha | |
1202 | addi r10,r10,exc_exit_restart_end@l | |
1203 | cmplw r12,r10 | |
1204 | bge 3f | |
1205 | lis r11,exc_exit_restart@ha | |
1206 | addi r11,r11,exc_exit_restart@l | |
1207 | cmplw r12,r11 | |
1208 | blt 3f | |
1209 | lis r10,ee_restarts@ha | |
1210 | lwz r12,ee_restarts@l(r10) | |
1211 | addi r12,r12,1 | |
1212 | stw r12,ee_restarts@l(r10) | |
1213 | mr r12,r11 /* restart at exc_exit_restart */ | |
1214 | blr | |
1215 | 3: /* OK, we can't recover, kill this process */ | |
1216 | /* but the 601 doesn't implement the RI bit, so assume it's OK */ | |
1217 | BEGIN_FTR_SECTION | |
1218 | blr | |
1219 | END_FTR_SECTION_IFSET(CPU_FTR_601) | |
d73e0c99 | 1220 | lwz r3,_TRAP(r1) |
9994a338 PM |
1221 | andi. r0,r3,1 |
1222 | beq 4f | |
1223 | SAVE_NVGPRS(r1) | |
1224 | rlwinm r3,r3,0,0,30 | |
d73e0c99 | 1225 | stw r3,_TRAP(r1) |
9994a338 PM |
1226 | 4: addi r3,r1,STACK_FRAME_OVERHEAD |
1227 | bl nonrecoverable_exception | |
1228 | /* shouldn't return */ | |
1229 | b 4b | |
1230 | ||
991eb43a KG |
1231 | .section .bss |
1232 | .align 2 | |
1233 | ee_restarts: | |
1234 | .space 4 | |
1235 | .previous | |
9994a338 PM |
1236 | |
1237 | /* | |
1238 | * PROM code for specific machines follows. Put it | |
1239 | * here so it's easy to add arch-specific sections later. | |
1240 | * -- Cort | |
1241 | */ | |
033ef338 | 1242 | #ifdef CONFIG_PPC_RTAS |
9994a338 PM |
1243 | /* |
1244 | * On CHRP, the Run-Time Abstraction Services (RTAS) have to be | |
1245 | * called with the MMU off. | |
1246 | */ | |
1247 | _GLOBAL(enter_rtas) | |
1248 | stwu r1,-INT_FRAME_SIZE(r1) | |
1249 | mflr r0 | |
1250 | stw r0,INT_FRAME_SIZE+4(r1) | |
e58c3495 | 1251 | LOAD_REG_ADDR(r4, rtas) |
9994a338 PM |
1252 | lis r6,1f@ha /* physical return address for rtas */ |
1253 | addi r6,r6,1f@l | |
1254 | tophys(r6,r6) | |
1255 | tophys(r7,r1) | |
033ef338 PM |
1256 | lwz r8,RTASENTRY(r4) |
1257 | lwz r4,RTASBASE(r4) | |
9994a338 PM |
1258 | mfmsr r9 |
1259 | stw r9,8(r1) | |
1260 | LOAD_MSR_KERNEL(r0,MSR_KERNEL) | |
1261 | SYNC /* disable interrupts so SRR0/1 */ | |
1262 | MTMSRD(r0) /* don't get trashed */ | |
1263 | li r9,MSR_KERNEL & ~(MSR_IR|MSR_DR) | |
1264 | mtlr r6 | |
ee43eb78 | 1265 | mtspr SPRN_SPRG_RTAS,r7 |
9994a338 PM |
1266 | mtspr SPRN_SRR0,r8 |
1267 | mtspr SPRN_SRR1,r9 | |
1268 | RFI | |
1269 | 1: tophys(r9,r1) | |
1270 | lwz r8,INT_FRAME_SIZE+4(r9) /* get return address */ | |
1271 | lwz r9,8(r9) /* original msr value */ | |
1272 | FIX_SRR1(r9,r0) | |
1273 | addi r1,r1,INT_FRAME_SIZE | |
1274 | li r0,0 | |
ee43eb78 | 1275 | mtspr SPRN_SPRG_RTAS,r0 |
9994a338 PM |
1276 | mtspr SPRN_SRR0,r8 |
1277 | mtspr SPRN_SRR1,r9 | |
1278 | RFI /* return to caller */ | |
1279 | ||
1280 | .globl machine_check_in_rtas | |
1281 | machine_check_in_rtas: | |
1282 | twi 31,0,0 | |
1283 | /* XXX load up BATs and panic */ | |
1284 | ||
033ef338 | 1285 | #endif /* CONFIG_PPC_RTAS */ |
4e491d14 | 1286 | |
606576ce | 1287 | #ifdef CONFIG_FUNCTION_TRACER |
4e491d14 SR |
1288 | #ifdef CONFIG_DYNAMIC_FTRACE |
1289 | _GLOBAL(mcount) | |
1290 | _GLOBAL(_mcount) | |
c7b0d173 SR |
1291 | /* |
1292 | * It is required that _mcount on PPC32 must preserve the | |
1293 | * link register. But we have r0 to play with. We use r0 | |
1294 | * to push the return address back to the caller of mcount | |
1295 | * into the ctr register, restore the link register and | |
1296 | * then jump back using the ctr register. | |
1297 | */ | |
1298 | mflr r0 | |
4e491d14 | 1299 | mtctr r0 |
c7b0d173 | 1300 | lwz r0, 4(r1) |
4e491d14 | 1301 | mtlr r0 |
4e491d14 SR |
1302 | bctr |
1303 | ||
1304 | _GLOBAL(ftrace_caller) | |
bf528a3a SR |
1305 | MCOUNT_SAVE_FRAME |
1306 | /* r3 ends up with link register */ | |
395a59d0 | 1307 | subi r3, r3, MCOUNT_INSN_SIZE |
4e491d14 SR |
1308 | .globl ftrace_call |
1309 | ftrace_call: | |
1310 | bl ftrace_stub | |
1311 | nop | |
60ce8f72 SR |
1312 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
1313 | .globl ftrace_graph_call | |
1314 | ftrace_graph_call: | |
1315 | b ftrace_graph_stub | |
1316 | _GLOBAL(ftrace_graph_stub) | |
1317 | #endif | |
bf528a3a SR |
1318 | MCOUNT_RESTORE_FRAME |
1319 | /* old link register ends up in ctr reg */ | |
4e491d14 SR |
1320 | bctr |
1321 | #else | |
1322 | _GLOBAL(mcount) | |
1323 | _GLOBAL(_mcount) | |
bf528a3a SR |
1324 | |
1325 | MCOUNT_SAVE_FRAME | |
4e491d14 | 1326 | |
395a59d0 | 1327 | subi r3, r3, MCOUNT_INSN_SIZE |
4e491d14 | 1328 | LOAD_REG_ADDR(r5, ftrace_trace_function) |
4e491d14 | 1329 | lwz r5,0(r5) |
ccbfac29 | 1330 | |
4e491d14 SR |
1331 | mtctr r5 |
1332 | bctrl | |
4e491d14 SR |
1333 | nop |
1334 | ||
fad4f47c SR |
1335 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
1336 | b ftrace_graph_caller | |
1337 | #endif | |
bf528a3a | 1338 | MCOUNT_RESTORE_FRAME |
4e491d14 SR |
1339 | bctr |
1340 | #endif | |
1341 | ||
1342 | _GLOBAL(ftrace_stub) | |
1343 | blr | |
1344 | ||
fad4f47c SR |
1345 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
1346 | _GLOBAL(ftrace_graph_caller) | |
1347 | /* load r4 with local address */ | |
1348 | lwz r4, 44(r1) | |
1349 | subi r4, r4, MCOUNT_INSN_SIZE | |
1350 | ||
b3c18725 AB |
1351 | /* Grab the LR out of the caller stack frame */ |
1352 | lwz r3,52(r1) | |
fad4f47c SR |
1353 | |
1354 | bl prepare_ftrace_return | |
1355 | nop | |
1356 | ||
b3c18725 AB |
1357 | /* |
1358 | * prepare_ftrace_return gives us the address we divert to. | |
1359 | * Change the LR in the callers stack frame to this. | |
1360 | */ | |
1361 | stw r3,52(r1) | |
1362 | ||
fad4f47c SR |
1363 | MCOUNT_RESTORE_FRAME |
1364 | /* old link register ends up in ctr reg */ | |
1365 | bctr | |
1366 | ||
1367 | _GLOBAL(return_to_handler) | |
1368 | /* need to save return values */ | |
1369 | stwu r1, -32(r1) | |
1370 | stw r3, 20(r1) | |
1371 | stw r4, 16(r1) | |
1372 | stw r31, 12(r1) | |
1373 | mr r31, r1 | |
1374 | ||
1375 | bl ftrace_return_to_handler | |
1376 | nop | |
1377 | ||
1378 | /* return value has real return address */ | |
1379 | mtlr r3 | |
1380 | ||
1381 | lwz r3, 20(r1) | |
1382 | lwz r4, 16(r1) | |
1383 | lwz r31,12(r1) | |
1384 | lwz r1, 0(r1) | |
1385 | ||
1386 | /* Jump back to real return address */ | |
1387 | blr | |
1388 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ | |
1389 | ||
60878dfb | 1390 | #endif /* CONFIG_FUNCTION_TRACER */ |