Merge branch 'merge'
[linux-2.6-block.git] / arch / powerpc / kernel / entry_64.S
CommitLineData
9994a338 1/*
9994a338
PM
2 * PowerPC version
3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
4 * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
5 * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
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
9994a338
PM
21#include <linux/errno.h>
22#include <asm/unistd.h>
23#include <asm/processor.h>
24#include <asm/page.h>
25#include <asm/mmu.h>
26#include <asm/thread_info.h>
27#include <asm/ppc_asm.h>
28#include <asm/asm-offsets.h>
29#include <asm/cputable.h>
30
31#ifdef CONFIG_PPC_ISERIES
32#define DO_SOFT_DISABLE
33#endif
34
35/*
36 * System calls.
37 */
38 .section ".toc","aw"
39.SYS_CALL_TABLE:
40 .tc .sys_call_table[TC],.sys_call_table
41
42/* This value is used to mark exception frames on the stack. */
43exception_marker:
44 .tc ID_72656773_68657265[TC],0x7265677368657265
45
46 .section ".text"
47 .align 7
48
49#undef SHOW_SYSCALLS
50
51 .globl system_call_common
52system_call_common:
53 andi. r10,r12,MSR_PR
54 mr r10,r1
55 addi r1,r1,-INT_FRAME_SIZE
56 beq- 1f
57 ld r1,PACAKSAVE(r13)
581: std r10,0(r1)
bd19c899 59 crclr so
9994a338
PM
60 std r11,_NIP(r1)
61 std r12,_MSR(r1)
62 std r0,GPR0(r1)
63 std r10,GPR1(r1)
c6622f63 64 ACCOUNT_CPU_USER_ENTRY(r10, r11)
9994a338
PM
65 std r2,GPR2(r1)
66 std r3,GPR3(r1)
67 std r4,GPR4(r1)
68 std r5,GPR5(r1)
69 std r6,GPR6(r1)
70 std r7,GPR7(r1)
71 std r8,GPR8(r1)
72 li r11,0
73 std r11,GPR9(r1)
74 std r11,GPR10(r1)
75 std r11,GPR11(r1)
76 std r11,GPR12(r1)
77 std r9,GPR13(r1)
9994a338
PM
78 mfcr r9
79 mflr r10
80 li r11,0xc01
81 std r9,_CCR(r1)
82 std r10,_LINK(r1)
83 std r11,_TRAP(r1)
84 mfxer r9
85 mfctr r10
86 std r9,_XER(r1)
87 std r10,_CTR(r1)
88 std r3,ORIG_GPR3(r1)
89 ld r2,PACATOC(r13)
90 addi r9,r1,STACK_FRAME_OVERHEAD
91 ld r11,exception_marker@toc(r2)
92 std r11,-16(r9) /* "regshere" marker */
93#ifdef CONFIG_PPC_ISERIES
94 /* Hack for handling interrupts when soft-enabling on iSeries */
95 cmpdi cr1,r0,0x5555 /* syscall 0x5555 */
96 andi. r10,r12,MSR_PR /* from kernel */
97 crand 4*cr0+eq,4*cr1+eq,4*cr0+eq
98 beq hardware_interrupt_entry
99 lbz r10,PACAPROCENABLED(r13)
100 std r10,SOFTE(r1)
101#endif
102 mfmsr r11
103 ori r11,r11,MSR_EE
104 mtmsrd r11,1
105
106#ifdef SHOW_SYSCALLS
107 bl .do_show_syscall
108 REST_GPR(0,r1)
109 REST_4GPRS(3,r1)
110 REST_2GPRS(7,r1)
111 addi r9,r1,STACK_FRAME_OVERHEAD
112#endif
113 clrrdi r11,r1,THREAD_SHIFT
9994a338 114 ld r10,TI_FLAGS(r11)
9994a338
PM
115 andi. r11,r10,_TIF_SYSCALL_T_OR_A
116 bne- syscall_dotrace
117syscall_dotrace_cont:
118 cmpldi 0,r0,NR_syscalls
119 bge- syscall_enosys
120
121system_call: /* label this so stack traces look sane */
122/*
123 * Need to vector to 32 Bit or default sys_call_table here,
124 * based on caller's run-mode / personality.
125 */
126 ld r11,.SYS_CALL_TABLE@toc(2)
127 andi. r10,r10,_TIF_32BIT
128 beq 15f
129 addi r11,r11,8 /* use 32-bit syscall entries */
130 clrldi r3,r3,32
131 clrldi r4,r4,32
132 clrldi r5,r5,32
133 clrldi r6,r6,32
134 clrldi r7,r7,32
135 clrldi r8,r8,32
13615:
137 slwi r0,r0,4
138 ldx r10,r11,r0 /* Fetch system call handler [ptr] */
139 mtctr r10
140 bctrl /* Call handler */
141
142syscall_exit:
401d1f02 143 std r3,RESULT(r1)
9994a338 144#ifdef SHOW_SYSCALLS
9994a338 145 bl .do_show_syscall_exit
401d1f02 146 ld r3,RESULT(r1)
9994a338 147#endif
9994a338 148 clrrdi r12,r1,THREAD_SHIFT
9994a338
PM
149
150 /* disable interrupts so current_thread_info()->flags can't change,
151 and so that we don't get interrupted after loading SRR0/1. */
152 ld r8,_MSR(r1)
153 andi. r10,r8,MSR_RI
154 beq- unrecov_restore
155 mfmsr r10
156 rldicl r10,r10,48,1
157 rotldi r10,r10,16
158 mtmsrd r10,1
159 ld r9,TI_FLAGS(r12)
401d1f02 160 li r11,-_LAST_ERRNO
1bd79336 161 andi. r0,r9,(_TIF_SYSCALL_T_OR_A|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
9994a338 162 bne- syscall_exit_work
401d1f02
DW
163 cmpld r3,r11
164 ld r5,_CCR(r1)
165 bge- syscall_error
166syscall_error_cont:
9994a338
PM
167 ld r7,_NIP(r1)
168 stdcx. r0,0,r1 /* to clear the reservation */
169 andi. r6,r8,MSR_PR
170 ld r4,_LINK(r1)
c6622f63
PM
171 beq- 1f
172 ACCOUNT_CPU_USER_EXIT(r11, r12)
173 ld r13,GPR13(r1) /* only restore r13 if returning to usermode */
9994a338
PM
1741: ld r2,GPR2(r1)
175 li r12,MSR_RI
3eb6f26b
PM
176 andc r11,r10,r12
177 mtmsrd r11,1 /* clear MSR.RI */
9994a338
PM
178 ld r1,GPR1(r1)
179 mtlr r4
180 mtcr r5
181 mtspr SPRN_SRR0,r7
182 mtspr SPRN_SRR1,r8
183 rfid
184 b . /* prevent speculative execution */
185
401d1f02 186syscall_error:
9994a338 187 oris r5,r5,0x1000 /* Set SO bit in CR */
401d1f02 188 neg r3,r3
9994a338
PM
189 std r5,_CCR(r1)
190 b syscall_error_cont
401d1f02 191
9994a338
PM
192/* Traced system call support */
193syscall_dotrace:
194 bl .save_nvgprs
195 addi r3,r1,STACK_FRAME_OVERHEAD
196 bl .do_syscall_trace_enter
197 ld r0,GPR0(r1) /* Restore original registers */
198 ld r3,GPR3(r1)
199 ld r4,GPR4(r1)
200 ld r5,GPR5(r1)
201 ld r6,GPR6(r1)
202 ld r7,GPR7(r1)
203 ld r8,GPR8(r1)
204 addi r9,r1,STACK_FRAME_OVERHEAD
205 clrrdi r10,r1,THREAD_SHIFT
206 ld r10,TI_FLAGS(r10)
207 b syscall_dotrace_cont
208
401d1f02
DW
209syscall_enosys:
210 li r3,-ENOSYS
211 b syscall_exit
212
213syscall_exit_work:
214 /* If TIF_RESTOREALL is set, don't scribble on either r3 or ccr.
215 If TIF_NOERROR is set, just save r3 as it is. */
216
217 andi. r0,r9,_TIF_RESTOREALL
1bd79336
PM
218 beq+ 0f
219 REST_NVGPRS(r1)
220 b 2f
2210: cmpld r3,r11 /* r10 is -LAST_ERRNO */
401d1f02
DW
222 blt+ 1f
223 andi. r0,r9,_TIF_NOERROR
224 bne- 1f
225 ld r5,_CCR(r1)
226 neg r3,r3
227 oris r5,r5,0x1000 /* Set SO bit in CR */
228 std r5,_CCR(r1)
2291: std r3,GPR3(r1)
2302: andi. r0,r9,(_TIF_PERSYSCALL_MASK)
231 beq 4f
232
1bd79336 233 /* Clear per-syscall TIF flags if any are set. */
401d1f02
DW
234
235 li r11,_TIF_PERSYSCALL_MASK
236 addi r12,r12,TI_FLAGS
2373: ldarx r10,0,r12
238 andc r10,r10,r11
239 stdcx. r10,0,r12
240 bne- 3b
241 subi r12,r12,TI_FLAGS
1bd79336
PM
242
2434: /* Anything else left to do? */
244 andi. r0,r9,(_TIF_SYSCALL_T_OR_A|_TIF_SINGLESTEP)
401d1f02
DW
245 beq .ret_from_except_lite
246
247 /* Re-enable interrupts */
248 mfmsr r10
249 ori r10,r10,MSR_EE
250 mtmsrd r10,1
251
1bd79336 252 bl .save_nvgprs
9994a338
PM
253 addi r3,r1,STACK_FRAME_OVERHEAD
254 bl .do_syscall_trace_leave
1bd79336 255 b .ret_from_except
9994a338
PM
256
257/* Save non-volatile GPRs, if not already saved. */
258_GLOBAL(save_nvgprs)
259 ld r11,_TRAP(r1)
260 andi. r0,r11,1
261 beqlr-
262 SAVE_NVGPRS(r1)
263 clrrdi r0,r11,1
264 std r0,_TRAP(r1)
265 blr
266
401d1f02 267
9994a338
PM
268/*
269 * The sigsuspend and rt_sigsuspend system calls can call do_signal
270 * and thus put the process into the stopped state where we might
271 * want to examine its user state with ptrace. Therefore we need
272 * to save all the nonvolatile registers (r14 - r31) before calling
273 * the C code. Similarly, fork, vfork and clone need the full
274 * register state on the stack so that it can be copied to the child.
275 */
9994a338
PM
276
277_GLOBAL(ppc_fork)
278 bl .save_nvgprs
279 bl .sys_fork
280 b syscall_exit
281
282_GLOBAL(ppc_vfork)
283 bl .save_nvgprs
284 bl .sys_vfork
285 b syscall_exit
286
287_GLOBAL(ppc_clone)
288 bl .save_nvgprs
289 bl .sys_clone
290 b syscall_exit
291
1bd79336
PM
292_GLOBAL(ppc32_swapcontext)
293 bl .save_nvgprs
294 bl .compat_sys_swapcontext
295 b syscall_exit
296
297_GLOBAL(ppc64_swapcontext)
298 bl .save_nvgprs
299 bl .sys_swapcontext
300 b syscall_exit
301
9994a338
PM
302_GLOBAL(ret_from_fork)
303 bl .schedule_tail
304 REST_NVGPRS(r1)
305 li r3,0
306 b syscall_exit
307
308/*
309 * This routine switches between two different tasks. The process
310 * state of one is saved on its kernel stack. Then the state
311 * of the other is restored from its kernel stack. The memory
312 * management hardware is updated to the second process's state.
313 * Finally, we can return to the second process, via ret_from_except.
314 * On entry, r3 points to the THREAD for the current task, r4
315 * points to the THREAD for the new task.
316 *
317 * Note: there are two ways to get to the "going out" portion
318 * of this code; either by coming in via the entry (_switch)
319 * or via "fork" which must set up an environment equivalent
320 * to the "_switch" path. If you change this you'll have to change
321 * the fork code also.
322 *
323 * The code which creates the new task context is in 'copy_thread'
2ef9481e 324 * in arch/powerpc/kernel/process.c
9994a338 325 */
2f6093c8
MN
326#define SHADOW_SLB_BOLTED_STACK_ESID \
327 (SLBSHADOW_SAVEAREA + 0x10*(SLB_NUM_BOLTED-1))
328#define SHADOW_SLB_BOLTED_STACK_VSID \
329 (SLBSHADOW_SAVEAREA + 0x10*(SLB_NUM_BOLTED-1) + 8)
330
9994a338
PM
331 .align 7
332_GLOBAL(_switch)
333 mflr r0
334 std r0,16(r1)
335 stdu r1,-SWITCH_FRAME_SIZE(r1)
336 /* r3-r13 are caller saved -- Cort */
337 SAVE_8GPRS(14, r1)
338 SAVE_10GPRS(22, r1)
339 mflr r20 /* Return to switch caller */
340 mfmsr r22
341 li r0, MSR_FP
342#ifdef CONFIG_ALTIVEC
343BEGIN_FTR_SECTION
344 oris r0,r0,MSR_VEC@h /* Disable altivec */
345 mfspr r24,SPRN_VRSAVE /* save vrsave register value */
346 std r24,THREAD_VRSAVE(r3)
347END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
348#endif /* CONFIG_ALTIVEC */
349 and. r0,r0,r22
350 beq+ 1f
351 andc r22,r22,r0
352 mtmsrd r22
353 isync
3541: std r20,_NIP(r1)
355 mfcr r23
356 std r23,_CCR(r1)
357 std r1,KSP(r3) /* Set old stack pointer */
358
359#ifdef CONFIG_SMP
360 /* We need a sync somewhere here to make sure that if the
361 * previous task gets rescheduled on another CPU, it sees all
362 * stores it has performed on this one.
363 */
364 sync
365#endif /* CONFIG_SMP */
366
367 addi r6,r4,-THREAD /* Convert THREAD to 'current' */
368 std r6,PACACURRENT(r13) /* Set new 'current' */
369
370 ld r8,KSP(r4) /* new stack pointer */
371BEGIN_FTR_SECTION
372 clrrdi r6,r8,28 /* get its ESID */
373 clrrdi r9,r1,28 /* get current sp ESID */
374 clrldi. r0,r6,2 /* is new ESID c00000000? */
375 cmpd cr1,r6,r9 /* or is new ESID the same as current ESID? */
376 cror eq,4*cr1+eq,eq
377 beq 2f /* if yes, don't slbie it */
378
379 /* Bolt in the new stack SLB entry */
380 ld r7,KSP_VSID(r4) /* Get new stack's VSID */
381 oris r0,r6,(SLB_ESID_V)@h
382 ori r0,r0,(SLB_NUM_BOLTED-1)@l
2f6093c8
MN
383
384 /* Update the last bolted SLB */
385 ld r9,PACA_SLBSHADOWPTR(r13)
386 li r12,0
387 std r12,SHADOW_SLB_BOLTED_STACK_ESID(r9) /* Clear ESID */
388 std r7,SHADOW_SLB_BOLTED_STACK_VSID(r9) /* Save VSID */
389 std r0,SHADOW_SLB_BOLTED_STACK_ESID(r9) /* Save ESID */
390
9994a338
PM
391 slbie r6
392 slbie r6 /* Workaround POWER5 < DD2.1 issue */
393 slbmte r7,r0
394 isync
395
3962:
397END_FTR_SECTION_IFSET(CPU_FTR_SLB)
398 clrrdi r7,r8,THREAD_SHIFT /* base of new stack */
399 /* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE
400 because we don't need to leave the 288-byte ABI gap at the
401 top of the kernel stack. */
402 addi r7,r7,THREAD_SIZE-SWITCH_FRAME_SIZE
403
404 mr r1,r8 /* start using new stack pointer */
405 std r7,PACAKSAVE(r13)
406
407 ld r6,_CCR(r1)
408 mtcrf 0xFF,r6
409
410#ifdef CONFIG_ALTIVEC
411BEGIN_FTR_SECTION
412 ld r0,THREAD_VRSAVE(r4)
413 mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */
414END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
415#endif /* CONFIG_ALTIVEC */
416
417 /* r3-r13 are destroyed -- Cort */
418 REST_8GPRS(14, r1)
419 REST_10GPRS(22, r1)
420
421 /* convert old thread to its task_struct for return value */
422 addi r3,r3,-THREAD
423 ld r7,_NIP(r1) /* Return to _switch caller in new task */
424 mtlr r7
425 addi r1,r1,SWITCH_FRAME_SIZE
426 blr
427
428 .align 7
429_GLOBAL(ret_from_except)
430 ld r11,_TRAP(r1)
431 andi. r0,r11,1
432 bne .ret_from_except_lite
433 REST_NVGPRS(r1)
434
435_GLOBAL(ret_from_except_lite)
436 /*
437 * Disable interrupts so that current_thread_info()->flags
438 * can't change between when we test it and when we return
439 * from the interrupt.
440 */
441 mfmsr r10 /* Get current interrupt state */
442 rldicl r9,r10,48,1 /* clear MSR_EE */
443 rotldi r9,r9,16
444 mtmsrd r9,1 /* Update machine state */
445
446#ifdef CONFIG_PREEMPT
447 clrrdi r9,r1,THREAD_SHIFT /* current_thread_info() */
448 li r0,_TIF_NEED_RESCHED /* bits to check */
449 ld r3,_MSR(r1)
450 ld r4,TI_FLAGS(r9)
451 /* Move MSR_PR bit in r3 to _TIF_SIGPENDING position in r0 */
452 rlwimi r0,r3,32+TIF_SIGPENDING-MSR_PR_LG,_TIF_SIGPENDING
453 and. r0,r4,r0 /* check NEED_RESCHED and maybe SIGPENDING */
454 bne do_work
455
456#else /* !CONFIG_PREEMPT */
457 ld r3,_MSR(r1) /* Returning to user mode? */
458 andi. r3,r3,MSR_PR
459 beq restore /* if not, just restore regs and return */
460
461 /* Check current_thread_info()->flags */
462 clrrdi r9,r1,THREAD_SHIFT
463 ld r4,TI_FLAGS(r9)
464 andi. r0,r4,_TIF_USER_WORK_MASK
465 bne do_work
466#endif
467
468restore:
469#ifdef CONFIG_PPC_ISERIES
470 ld r5,SOFTE(r1)
471 cmpdi 0,r5,0
472 beq 4f
473 /* Check for pending interrupts (iSeries) */
3356bb9f
DG
474 ld r3,PACALPPACAPTR(r13)
475 ld r3,LPPACAANYINT(r3)
9994a338
PM
476 cmpdi r3,0
477 beq+ 4f /* skip do_IRQ if no interrupts */
478
479 li r3,0
480 stb r3,PACAPROCENABLED(r13) /* ensure we are soft-disabled */
481 ori r10,r10,MSR_EE
482 mtmsrd r10 /* hard-enable again */
483 addi r3,r1,STACK_FRAME_OVERHEAD
484 bl .do_IRQ
485 b .ret_from_except_lite /* loop back and handle more */
486
4874: stb r5,PACAPROCENABLED(r13)
488#endif
489
490 ld r3,_MSR(r1)
491 andi. r0,r3,MSR_RI
492 beq- unrecov_restore
493
494 andi. r0,r3,MSR_PR
495
496 /*
497 * r13 is our per cpu area, only restore it if we are returning to
498 * userspace
499 */
500 beq 1f
c6622f63 501 ACCOUNT_CPU_USER_EXIT(r3, r4)
9994a338
PM
502 REST_GPR(13, r1)
5031:
504 ld r3,_CTR(r1)
505 ld r0,_LINK(r1)
506 mtctr r3
507 mtlr r0
508 ld r3,_XER(r1)
509 mtspr SPRN_XER,r3
510
511 REST_8GPRS(5, r1)
512
513 stdcx. r0,0,r1 /* to clear the reservation */
514
515 mfmsr r0
516 li r2, MSR_RI
517 andc r0,r0,r2
518 mtmsrd r0,1
519
520 ld r0,_MSR(r1)
521 mtspr SPRN_SRR1,r0
522
523 ld r2,_CCR(r1)
524 mtcrf 0xFF,r2
525 ld r2,_NIP(r1)
526 mtspr SPRN_SRR0,r2
527
528 ld r0,GPR0(r1)
529 ld r2,GPR2(r1)
530 ld r3,GPR3(r1)
531 ld r4,GPR4(r1)
532 ld r1,GPR1(r1)
533
534 rfid
535 b . /* prevent speculative execution */
536
537/* Note: this must change if we start using the TIF_NOTIFY_RESUME bit */
538do_work:
539#ifdef CONFIG_PREEMPT
540 andi. r0,r3,MSR_PR /* Returning to user mode? */
541 bne user_work
542 /* Check that preempt_count() == 0 and interrupts are enabled */
543 lwz r8,TI_PREEMPT(r9)
544 cmpwi cr1,r8,0
545#ifdef CONFIG_PPC_ISERIES
546 ld r0,SOFTE(r1)
547 cmpdi r0,0
548#else
549 andi. r0,r3,MSR_EE
550#endif
551 crandc eq,cr1*4+eq,eq
552 bne restore
553 /* here we are preempting the current task */
5541:
555#ifdef CONFIG_PPC_ISERIES
556 li r0,1
557 stb r0,PACAPROCENABLED(r13)
558#endif
559 ori r10,r10,MSR_EE
560 mtmsrd r10,1 /* reenable interrupts */
561 bl .preempt_schedule
562 mfmsr r10
563 clrrdi r9,r1,THREAD_SHIFT
564 rldicl r10,r10,48,1 /* disable interrupts again */
565 rotldi r10,r10,16
566 mtmsrd r10,1
567 ld r4,TI_FLAGS(r9)
568 andi. r0,r4,_TIF_NEED_RESCHED
569 bne 1b
570 b restore
571
572user_work:
573#endif
574 /* Enable interrupts */
575 ori r10,r10,MSR_EE
576 mtmsrd r10,1
577
578 andi. r0,r4,_TIF_NEED_RESCHED
579 beq 1f
580 bl .schedule
581 b .ret_from_except_lite
582
5831: bl .save_nvgprs
584 li r3,0
585 addi r4,r1,STACK_FRAME_OVERHEAD
586 bl .do_signal
587 b .ret_from_except
588
589unrecov_restore:
590 addi r3,r1,STACK_FRAME_OVERHEAD
591 bl .unrecoverable_exception
592 b unrecov_restore
593
594#ifdef CONFIG_PPC_RTAS
595/*
596 * On CHRP, the Run-Time Abstraction Services (RTAS) have to be
597 * called with the MMU off.
598 *
599 * In addition, we need to be in 32b mode, at least for now.
600 *
601 * Note: r3 is an input parameter to rtas, so don't trash it...
602 */
603_GLOBAL(enter_rtas)
604 mflr r0
605 std r0,16(r1)
606 stdu r1,-RTAS_FRAME_SIZE(r1) /* Save SP and create stack space. */
607
608 /* Because RTAS is running in 32b mode, it clobbers the high order half
609 * of all registers that it saves. We therefore save those registers
610 * RTAS might touch to the stack. (r0, r3-r13 are caller saved)
611 */
612 SAVE_GPR(2, r1) /* Save the TOC */
613 SAVE_GPR(13, r1) /* Save paca */
614 SAVE_8GPRS(14, r1) /* Save the non-volatiles */
615 SAVE_10GPRS(22, r1) /* ditto */
616
617 mfcr r4
618 std r4,_CCR(r1)
619 mfctr r5
620 std r5,_CTR(r1)
621 mfspr r6,SPRN_XER
622 std r6,_XER(r1)
623 mfdar r7
624 std r7,_DAR(r1)
625 mfdsisr r8
626 std r8,_DSISR(r1)
627 mfsrr0 r9
628 std r9,_SRR0(r1)
629 mfsrr1 r10
630 std r10,_SRR1(r1)
631
9fe901d1
MK
632 /* Temporary workaround to clear CR until RTAS can be modified to
633 * ignore all bits.
634 */
635 li r0,0
636 mtcr r0
637
9994a338
PM
638 /* There is no way it is acceptable to get here with interrupts enabled,
639 * check it with the asm equivalent of WARN_ON
640 */
641 mfmsr r6
642 andi. r0,r6,MSR_EE
6431: tdnei r0,0
644.section __bug_table,"a"
645 .llong 1b,__LINE__ + 0x1000000, 1f, 2f
646.previous
647.section .rodata,"a"
6481: .asciz __FILE__
6492: .asciz "enter_rtas"
650.previous
651
652 /* Unfortunately, the stack pointer and the MSR are also clobbered,
653 * so they are saved in the PACA which allows us to restore
654 * our original state after RTAS returns.
655 */
656 std r1,PACAR1(r13)
657 std r6,PACASAVEDMSR(r13)
658
659 /* Setup our real return addr */
e58c3495
DG
660 LOAD_REG_ADDR(r4,.rtas_return_loc)
661 clrldi r4,r4,2 /* convert to realmode address */
9994a338
PM
662 mtlr r4
663
664 li r0,0
665 ori r0,r0,MSR_EE|MSR_SE|MSR_BE|MSR_RI
666 andc r0,r6,r0
667
668 li r9,1
669 rldicr r9,r9,MSR_SF_LG,(63-MSR_SF_LG)
670 ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP
671 andc r6,r0,r9
672 ori r6,r6,MSR_RI
673 sync /* disable interrupts so SRR0/1 */
674 mtmsrd r0 /* don't get trashed */
675
e58c3495 676 LOAD_REG_ADDR(r4, rtas)
9994a338
PM
677 ld r5,RTASENTRY(r4) /* get the rtas->entry value */
678 ld r4,RTASBASE(r4) /* get the rtas->base value */
679
680 mtspr SPRN_SRR0,r5
681 mtspr SPRN_SRR1,r6
682 rfid
683 b . /* prevent speculative execution */
684
685_STATIC(rtas_return_loc)
686 /* relocation is off at this point */
687 mfspr r4,SPRN_SPRG3 /* Get PACA */
e58c3495 688 clrldi r4,r4,2 /* convert to realmode address */
9994a338
PM
689
690 mfmsr r6
691 li r0,MSR_RI
692 andc r6,r6,r0
693 sync
694 mtmsrd r6
695
696 ld r1,PACAR1(r4) /* Restore our SP */
e58c3495 697 LOAD_REG_IMMEDIATE(r3,.rtas_restore_regs)
9994a338
PM
698 ld r4,PACASAVEDMSR(r4) /* Restore our MSR */
699
700 mtspr SPRN_SRR0,r3
701 mtspr SPRN_SRR1,r4
702 rfid
703 b . /* prevent speculative execution */
704
705_STATIC(rtas_restore_regs)
706 /* relocation is on at this point */
707 REST_GPR(2, r1) /* Restore the TOC */
708 REST_GPR(13, r1) /* Restore paca */
709 REST_8GPRS(14, r1) /* Restore the non-volatiles */
710 REST_10GPRS(22, r1) /* ditto */
711
712 mfspr r13,SPRN_SPRG3
713
714 ld r4,_CCR(r1)
715 mtcr r4
716 ld r5,_CTR(r1)
717 mtctr r5
718 ld r6,_XER(r1)
719 mtspr SPRN_XER,r6
720 ld r7,_DAR(r1)
721 mtdar r7
722 ld r8,_DSISR(r1)
723 mtdsisr r8
724 ld r9,_SRR0(r1)
725 mtsrr0 r9
726 ld r10,_SRR1(r1)
727 mtsrr1 r10
728
729 addi r1,r1,RTAS_FRAME_SIZE /* Unstack our frame */
730 ld r0,16(r1) /* get return address */
731
732 mtlr r0
733 blr /* return to caller */
734
735#endif /* CONFIG_PPC_RTAS */
736
737#ifdef CONFIG_PPC_MULTIPLATFORM
738
739_GLOBAL(enter_prom)
740 mflr r0
741 std r0,16(r1)
742 stdu r1,-PROM_FRAME_SIZE(r1) /* Save SP and create stack space */
743
744 /* Because PROM is running in 32b mode, it clobbers the high order half
745 * of all registers that it saves. We therefore save those registers
746 * PROM might touch to the stack. (r0, r3-r13 are caller saved)
747 */
748 SAVE_8GPRS(2, r1)
749 SAVE_GPR(13, r1)
750 SAVE_8GPRS(14, r1)
751 SAVE_10GPRS(22, r1)
752 mfcr r4
753 std r4,_CCR(r1)
754 mfctr r5
755 std r5,_CTR(r1)
756 mfspr r6,SPRN_XER
757 std r6,_XER(r1)
758 mfdar r7
759 std r7,_DAR(r1)
760 mfdsisr r8
761 std r8,_DSISR(r1)
762 mfsrr0 r9
763 std r9,_SRR0(r1)
764 mfsrr1 r10
765 std r10,_SRR1(r1)
766 mfmsr r11
767 std r11,_MSR(r1)
768
769 /* Get the PROM entrypoint */
770 ld r0,GPR4(r1)
771 mtlr r0
772
773 /* Switch MSR to 32 bits mode
774 */
775 mfmsr r11
776 li r12,1
777 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
778 andc r11,r11,r12
779 li r12,1
780 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
781 andc r11,r11,r12
782 mtmsrd r11
783 isync
784
785 /* Restore arguments & enter PROM here... */
786 ld r3,GPR3(r1)
787 blrl
788
789 /* Just make sure that r1 top 32 bits didn't get
790 * corrupt by OF
791 */
792 rldicl r1,r1,0,32
793
794 /* Restore the MSR (back to 64 bits) */
795 ld r0,_MSR(r1)
796 mtmsrd r0
797 isync
798
799 /* Restore other registers */
800 REST_GPR(2, r1)
801 REST_GPR(13, r1)
802 REST_8GPRS(14, r1)
803 REST_10GPRS(22, r1)
804 ld r4,_CCR(r1)
805 mtcr r4
806 ld r5,_CTR(r1)
807 mtctr r5
808 ld r6,_XER(r1)
809 mtspr SPRN_XER,r6
810 ld r7,_DAR(r1)
811 mtdar r7
812 ld r8,_DSISR(r1)
813 mtdsisr r8
814 ld r9,_SRR0(r1)
815 mtsrr0 r9
816 ld r10,_SRR1(r1)
817 mtsrr1 r10
818
819 addi r1,r1,PROM_FRAME_SIZE
820 ld r0,16(r1)
821 mtlr r0
822 blr
823
824#endif /* CONFIG_PPC_MULTIPLATFORM */