[POWERPC] Fix powerpc 44x_mmu build
[deliverable/linux.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
PM
325 */
326 .align 7
327_GLOBAL(_switch)
328 mflr r0
329 std r0,16(r1)
330 stdu r1,-SWITCH_FRAME_SIZE(r1)
331 /* r3-r13 are caller saved -- Cort */
332 SAVE_8GPRS(14, r1)
333 SAVE_10GPRS(22, r1)
334 mflr r20 /* Return to switch caller */
335 mfmsr r22
336 li r0, MSR_FP
337#ifdef CONFIG_ALTIVEC
338BEGIN_FTR_SECTION
339 oris r0,r0,MSR_VEC@h /* Disable altivec */
340 mfspr r24,SPRN_VRSAVE /* save vrsave register value */
341 std r24,THREAD_VRSAVE(r3)
342END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
343#endif /* CONFIG_ALTIVEC */
344 and. r0,r0,r22
345 beq+ 1f
346 andc r22,r22,r0
347 mtmsrd r22
348 isync
3491: std r20,_NIP(r1)
350 mfcr r23
351 std r23,_CCR(r1)
352 std r1,KSP(r3) /* Set old stack pointer */
353
354#ifdef CONFIG_SMP
355 /* We need a sync somewhere here to make sure that if the
356 * previous task gets rescheduled on another CPU, it sees all
357 * stores it has performed on this one.
358 */
359 sync
360#endif /* CONFIG_SMP */
361
362 addi r6,r4,-THREAD /* Convert THREAD to 'current' */
363 std r6,PACACURRENT(r13) /* Set new 'current' */
364
365 ld r8,KSP(r4) /* new stack pointer */
366BEGIN_FTR_SECTION
367 clrrdi r6,r8,28 /* get its ESID */
368 clrrdi r9,r1,28 /* get current sp ESID */
369 clrldi. r0,r6,2 /* is new ESID c00000000? */
370 cmpd cr1,r6,r9 /* or is new ESID the same as current ESID? */
371 cror eq,4*cr1+eq,eq
372 beq 2f /* if yes, don't slbie it */
373
374 /* Bolt in the new stack SLB entry */
375 ld r7,KSP_VSID(r4) /* Get new stack's VSID */
376 oris r0,r6,(SLB_ESID_V)@h
377 ori r0,r0,(SLB_NUM_BOLTED-1)@l
378 slbie r6
379 slbie r6 /* Workaround POWER5 < DD2.1 issue */
380 slbmte r7,r0
381 isync
382
3832:
384END_FTR_SECTION_IFSET(CPU_FTR_SLB)
385 clrrdi r7,r8,THREAD_SHIFT /* base of new stack */
386 /* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE
387 because we don't need to leave the 288-byte ABI gap at the
388 top of the kernel stack. */
389 addi r7,r7,THREAD_SIZE-SWITCH_FRAME_SIZE
390
391 mr r1,r8 /* start using new stack pointer */
392 std r7,PACAKSAVE(r13)
393
394 ld r6,_CCR(r1)
395 mtcrf 0xFF,r6
396
397#ifdef CONFIG_ALTIVEC
398BEGIN_FTR_SECTION
399 ld r0,THREAD_VRSAVE(r4)
400 mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */
401END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
402#endif /* CONFIG_ALTIVEC */
403
404 /* r3-r13 are destroyed -- Cort */
405 REST_8GPRS(14, r1)
406 REST_10GPRS(22, r1)
407
408 /* convert old thread to its task_struct for return value */
409 addi r3,r3,-THREAD
410 ld r7,_NIP(r1) /* Return to _switch caller in new task */
411 mtlr r7
412 addi r1,r1,SWITCH_FRAME_SIZE
413 blr
414
415 .align 7
416_GLOBAL(ret_from_except)
417 ld r11,_TRAP(r1)
418 andi. r0,r11,1
419 bne .ret_from_except_lite
420 REST_NVGPRS(r1)
421
422_GLOBAL(ret_from_except_lite)
423 /*
424 * Disable interrupts so that current_thread_info()->flags
425 * can't change between when we test it and when we return
426 * from the interrupt.
427 */
428 mfmsr r10 /* Get current interrupt state */
429 rldicl r9,r10,48,1 /* clear MSR_EE */
430 rotldi r9,r9,16
431 mtmsrd r9,1 /* Update machine state */
432
433#ifdef CONFIG_PREEMPT
434 clrrdi r9,r1,THREAD_SHIFT /* current_thread_info() */
435 li r0,_TIF_NEED_RESCHED /* bits to check */
436 ld r3,_MSR(r1)
437 ld r4,TI_FLAGS(r9)
438 /* Move MSR_PR bit in r3 to _TIF_SIGPENDING position in r0 */
439 rlwimi r0,r3,32+TIF_SIGPENDING-MSR_PR_LG,_TIF_SIGPENDING
440 and. r0,r4,r0 /* check NEED_RESCHED and maybe SIGPENDING */
441 bne do_work
442
443#else /* !CONFIG_PREEMPT */
444 ld r3,_MSR(r1) /* Returning to user mode? */
445 andi. r3,r3,MSR_PR
446 beq restore /* if not, just restore regs and return */
447
448 /* Check current_thread_info()->flags */
449 clrrdi r9,r1,THREAD_SHIFT
450 ld r4,TI_FLAGS(r9)
451 andi. r0,r4,_TIF_USER_WORK_MASK
452 bne do_work
453#endif
454
455restore:
456#ifdef CONFIG_PPC_ISERIES
457 ld r5,SOFTE(r1)
458 cmpdi 0,r5,0
459 beq 4f
460 /* Check for pending interrupts (iSeries) */
3356bb9f
DG
461 ld r3,PACALPPACAPTR(r13)
462 ld r3,LPPACAANYINT(r3)
9994a338
PM
463 cmpdi r3,0
464 beq+ 4f /* skip do_IRQ if no interrupts */
465
466 li r3,0
467 stb r3,PACAPROCENABLED(r13) /* ensure we are soft-disabled */
468 ori r10,r10,MSR_EE
469 mtmsrd r10 /* hard-enable again */
470 addi r3,r1,STACK_FRAME_OVERHEAD
471 bl .do_IRQ
472 b .ret_from_except_lite /* loop back and handle more */
473
4744: stb r5,PACAPROCENABLED(r13)
475#endif
476
477 ld r3,_MSR(r1)
478 andi. r0,r3,MSR_RI
479 beq- unrecov_restore
480
481 andi. r0,r3,MSR_PR
482
483 /*
484 * r13 is our per cpu area, only restore it if we are returning to
485 * userspace
486 */
487 beq 1f
c6622f63 488 ACCOUNT_CPU_USER_EXIT(r3, r4)
9994a338
PM
489 REST_GPR(13, r1)
4901:
491 ld r3,_CTR(r1)
492 ld r0,_LINK(r1)
493 mtctr r3
494 mtlr r0
495 ld r3,_XER(r1)
496 mtspr SPRN_XER,r3
497
498 REST_8GPRS(5, r1)
499
500 stdcx. r0,0,r1 /* to clear the reservation */
501
502 mfmsr r0
503 li r2, MSR_RI
504 andc r0,r0,r2
505 mtmsrd r0,1
506
507 ld r0,_MSR(r1)
508 mtspr SPRN_SRR1,r0
509
510 ld r2,_CCR(r1)
511 mtcrf 0xFF,r2
512 ld r2,_NIP(r1)
513 mtspr SPRN_SRR0,r2
514
515 ld r0,GPR0(r1)
516 ld r2,GPR2(r1)
517 ld r3,GPR3(r1)
518 ld r4,GPR4(r1)
519 ld r1,GPR1(r1)
520
521 rfid
522 b . /* prevent speculative execution */
523
524/* Note: this must change if we start using the TIF_NOTIFY_RESUME bit */
525do_work:
526#ifdef CONFIG_PREEMPT
527 andi. r0,r3,MSR_PR /* Returning to user mode? */
528 bne user_work
529 /* Check that preempt_count() == 0 and interrupts are enabled */
530 lwz r8,TI_PREEMPT(r9)
531 cmpwi cr1,r8,0
532#ifdef CONFIG_PPC_ISERIES
533 ld r0,SOFTE(r1)
534 cmpdi r0,0
535#else
536 andi. r0,r3,MSR_EE
537#endif
538 crandc eq,cr1*4+eq,eq
539 bne restore
540 /* here we are preempting the current task */
5411:
542#ifdef CONFIG_PPC_ISERIES
543 li r0,1
544 stb r0,PACAPROCENABLED(r13)
545#endif
546 ori r10,r10,MSR_EE
547 mtmsrd r10,1 /* reenable interrupts */
548 bl .preempt_schedule
549 mfmsr r10
550 clrrdi r9,r1,THREAD_SHIFT
551 rldicl r10,r10,48,1 /* disable interrupts again */
552 rotldi r10,r10,16
553 mtmsrd r10,1
554 ld r4,TI_FLAGS(r9)
555 andi. r0,r4,_TIF_NEED_RESCHED
556 bne 1b
557 b restore
558
559user_work:
560#endif
561 /* Enable interrupts */
562 ori r10,r10,MSR_EE
563 mtmsrd r10,1
564
565 andi. r0,r4,_TIF_NEED_RESCHED
566 beq 1f
567 bl .schedule
568 b .ret_from_except_lite
569
5701: bl .save_nvgprs
571 li r3,0
572 addi r4,r1,STACK_FRAME_OVERHEAD
573 bl .do_signal
574 b .ret_from_except
575
576unrecov_restore:
577 addi r3,r1,STACK_FRAME_OVERHEAD
578 bl .unrecoverable_exception
579 b unrecov_restore
580
581#ifdef CONFIG_PPC_RTAS
582/*
583 * On CHRP, the Run-Time Abstraction Services (RTAS) have to be
584 * called with the MMU off.
585 *
586 * In addition, we need to be in 32b mode, at least for now.
587 *
588 * Note: r3 is an input parameter to rtas, so don't trash it...
589 */
590_GLOBAL(enter_rtas)
591 mflr r0
592 std r0,16(r1)
593 stdu r1,-RTAS_FRAME_SIZE(r1) /* Save SP and create stack space. */
594
595 /* Because RTAS is running in 32b mode, it clobbers the high order half
596 * of all registers that it saves. We therefore save those registers
597 * RTAS might touch to the stack. (r0, r3-r13 are caller saved)
598 */
599 SAVE_GPR(2, r1) /* Save the TOC */
600 SAVE_GPR(13, r1) /* Save paca */
601 SAVE_8GPRS(14, r1) /* Save the non-volatiles */
602 SAVE_10GPRS(22, r1) /* ditto */
603
604 mfcr r4
605 std r4,_CCR(r1)
606 mfctr r5
607 std r5,_CTR(r1)
608 mfspr r6,SPRN_XER
609 std r6,_XER(r1)
610 mfdar r7
611 std r7,_DAR(r1)
612 mfdsisr r8
613 std r8,_DSISR(r1)
614 mfsrr0 r9
615 std r9,_SRR0(r1)
616 mfsrr1 r10
617 std r10,_SRR1(r1)
618
9fe901d1
MK
619 /* Temporary workaround to clear CR until RTAS can be modified to
620 * ignore all bits.
621 */
622 li r0,0
623 mtcr r0
624
9994a338
PM
625 /* There is no way it is acceptable to get here with interrupts enabled,
626 * check it with the asm equivalent of WARN_ON
627 */
628 mfmsr r6
629 andi. r0,r6,MSR_EE
6301: tdnei r0,0
631.section __bug_table,"a"
632 .llong 1b,__LINE__ + 0x1000000, 1f, 2f
633.previous
634.section .rodata,"a"
6351: .asciz __FILE__
6362: .asciz "enter_rtas"
637.previous
638
639 /* Unfortunately, the stack pointer and the MSR are also clobbered,
640 * so they are saved in the PACA which allows us to restore
641 * our original state after RTAS returns.
642 */
643 std r1,PACAR1(r13)
644 std r6,PACASAVEDMSR(r13)
645
646 /* Setup our real return addr */
e58c3495
DG
647 LOAD_REG_ADDR(r4,.rtas_return_loc)
648 clrldi r4,r4,2 /* convert to realmode address */
9994a338
PM
649 mtlr r4
650
651 li r0,0
652 ori r0,r0,MSR_EE|MSR_SE|MSR_BE|MSR_RI
653 andc r0,r6,r0
654
655 li r9,1
656 rldicr r9,r9,MSR_SF_LG,(63-MSR_SF_LG)
657 ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP
658 andc r6,r0,r9
659 ori r6,r6,MSR_RI
660 sync /* disable interrupts so SRR0/1 */
661 mtmsrd r0 /* don't get trashed */
662
e58c3495 663 LOAD_REG_ADDR(r4, rtas)
9994a338
PM
664 ld r5,RTASENTRY(r4) /* get the rtas->entry value */
665 ld r4,RTASBASE(r4) /* get the rtas->base value */
666
667 mtspr SPRN_SRR0,r5
668 mtspr SPRN_SRR1,r6
669 rfid
670 b . /* prevent speculative execution */
671
672_STATIC(rtas_return_loc)
673 /* relocation is off at this point */
674 mfspr r4,SPRN_SPRG3 /* Get PACA */
e58c3495 675 clrldi r4,r4,2 /* convert to realmode address */
9994a338
PM
676
677 mfmsr r6
678 li r0,MSR_RI
679 andc r6,r6,r0
680 sync
681 mtmsrd r6
682
683 ld r1,PACAR1(r4) /* Restore our SP */
e58c3495 684 LOAD_REG_IMMEDIATE(r3,.rtas_restore_regs)
9994a338
PM
685 ld r4,PACASAVEDMSR(r4) /* Restore our MSR */
686
687 mtspr SPRN_SRR0,r3
688 mtspr SPRN_SRR1,r4
689 rfid
690 b . /* prevent speculative execution */
691
692_STATIC(rtas_restore_regs)
693 /* relocation is on at this point */
694 REST_GPR(2, r1) /* Restore the TOC */
695 REST_GPR(13, r1) /* Restore paca */
696 REST_8GPRS(14, r1) /* Restore the non-volatiles */
697 REST_10GPRS(22, r1) /* ditto */
698
699 mfspr r13,SPRN_SPRG3
700
701 ld r4,_CCR(r1)
702 mtcr r4
703 ld r5,_CTR(r1)
704 mtctr r5
705 ld r6,_XER(r1)
706 mtspr SPRN_XER,r6
707 ld r7,_DAR(r1)
708 mtdar r7
709 ld r8,_DSISR(r1)
710 mtdsisr r8
711 ld r9,_SRR0(r1)
712 mtsrr0 r9
713 ld r10,_SRR1(r1)
714 mtsrr1 r10
715
716 addi r1,r1,RTAS_FRAME_SIZE /* Unstack our frame */
717 ld r0,16(r1) /* get return address */
718
719 mtlr r0
720 blr /* return to caller */
721
722#endif /* CONFIG_PPC_RTAS */
723
724#ifdef CONFIG_PPC_MULTIPLATFORM
725
726_GLOBAL(enter_prom)
727 mflr r0
728 std r0,16(r1)
729 stdu r1,-PROM_FRAME_SIZE(r1) /* Save SP and create stack space */
730
731 /* Because PROM is running in 32b mode, it clobbers the high order half
732 * of all registers that it saves. We therefore save those registers
733 * PROM might touch to the stack. (r0, r3-r13 are caller saved)
734 */
735 SAVE_8GPRS(2, r1)
736 SAVE_GPR(13, r1)
737 SAVE_8GPRS(14, r1)
738 SAVE_10GPRS(22, r1)
739 mfcr r4
740 std r4,_CCR(r1)
741 mfctr r5
742 std r5,_CTR(r1)
743 mfspr r6,SPRN_XER
744 std r6,_XER(r1)
745 mfdar r7
746 std r7,_DAR(r1)
747 mfdsisr r8
748 std r8,_DSISR(r1)
749 mfsrr0 r9
750 std r9,_SRR0(r1)
751 mfsrr1 r10
752 std r10,_SRR1(r1)
753 mfmsr r11
754 std r11,_MSR(r1)
755
756 /* Get the PROM entrypoint */
757 ld r0,GPR4(r1)
758 mtlr r0
759
760 /* Switch MSR to 32 bits mode
761 */
762 mfmsr r11
763 li r12,1
764 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
765 andc r11,r11,r12
766 li r12,1
767 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
768 andc r11,r11,r12
769 mtmsrd r11
770 isync
771
772 /* Restore arguments & enter PROM here... */
773 ld r3,GPR3(r1)
774 blrl
775
776 /* Just make sure that r1 top 32 bits didn't get
777 * corrupt by OF
778 */
779 rldicl r1,r1,0,32
780
781 /* Restore the MSR (back to 64 bits) */
782 ld r0,_MSR(r1)
783 mtmsrd r0
784 isync
785
786 /* Restore other registers */
787 REST_GPR(2, r1)
788 REST_GPR(13, r1)
789 REST_8GPRS(14, r1)
790 REST_10GPRS(22, r1)
791 ld r4,_CCR(r1)
792 mtcr r4
793 ld r5,_CTR(r1)
794 mtctr r5
795 ld r6,_XER(r1)
796 mtspr SPRN_XER,r6
797 ld r7,_DAR(r1)
798 mtdar r7
799 ld r8,_DSISR(r1)
800 mtdsisr r8
801 ld r9,_SRR0(r1)
802 mtsrr0 r9
803 ld r10,_SRR1(r1)
804 mtsrr1 r10
805
806 addi r1,r1,PROM_FRAME_SIZE
807 ld r0,16(r1)
808 mtlr r0
809 blr
810
811#endif /* CONFIG_PPC_MULTIPLATFORM */
This page took 0.138017 seconds and 5 git commands to generate.