2 * arch/ppc64/kernel/entry.S
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6 * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
7 * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
8 * Adapted for Power Macintosh by Paul Mackerras.
9 * Low-level exception handlers and MMU support
10 * rewritten by Paul Mackerras.
11 * Copyright (C) 1996 Paul Mackerras.
12 * MPC8xx modifications Copyright (C) 1997 Dan Malek (dmalek@jlc.net).
14 * This file contains the system call entry code, context switch
15 * code, and exception/interrupt return code for PowerPC.
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version
20 * 2 of the License, or (at your option) any later version.
23 #include <linux/config.h>
24 #include <linux/errno.h>
25 #include <asm/unistd.h>
26 #include <asm/processor.h>
29 #include <asm/thread_info.h>
30 #include <asm/ppc_asm.h>
31 #include <asm/offsets.h>
32 #include <asm/cputable.h>
34 #ifdef CONFIG_PPC_ISERIES
35 #define DO_SOFT_DISABLE
39 #undef SHOW_SYSCALLS_TASK
41 #ifdef SHOW_SYSCALLS_TASK
49 .tc .sys_call_table[TC],.sys_call_table
52 .tc .sys_call_table32[TC],.sys_call_table32
58 * Handle a system call.
62 ld r11,_CCR(r1) /* Clear SO bit in CR */
67 #ifdef SHOW_SYSCALLS_TASK
68 LOADBASE(r31,show_syscalls_task)
69 ld r31,show_syscalls_task@l(r31)
70 ld r10,PACACURRENT(r13)
85 ld r6, PACACURRENT(r13)
95 #endif /* SHOW_SYSCALLS */
96 clrrdi r10,r1,THREAD_SHIFT
98 andi. r11,r10,_TIF_SYSCALL_T_OR_A
100 cmpli 0,r0,NR_syscalls
103 * Need to vector to 32 Bit or default sys_call_table here,
104 * based on caller's run-mode / personality.
106 andi. r11,r10,_TIF_32BIT
108 ld r10,.SYS_CALL_TABLE32@toc(2)
110 * We now zero extend all six arguments (r3 - r8), the compatibility
111 * layer assumes this.
121 ld r10,.SYS_CALL_TABLE@toc(2)
123 ldx r10,r10,r0 /* Fetch system call handler [ptr] */
125 addi r9,r1,STACK_FRAME_OVERHEAD
126 blrl /* Call handler */
127 _GLOBAL(ret_from_syscall_1)
128 std r3,RESULT(r1) /* Save result */
130 #ifdef SHOW_SYSCALLS_TASK
131 ld r10, PACACURRENT(13)
145 22: ld r10,_CCR(r1) /* Set SO bit in CR */
148 30: std r3,GPR3(r1) /* Update return value */
153 /* Traced system call support */
154 50: addi r3,r1,STACK_FRAME_OVERHEAD
155 bl .do_syscall_trace_enter
156 ld r0,GPR0(r1) /* Restore original registers */
163 /* XXX check this - Anton */
165 cmpli 0,r0,NR_syscalls
168 * Need to vector to 32 Bit or default sys_call_table here,
169 * based on caller's run-mode / personality.
171 clrrdi r10,r1,THREAD_SHIFT
173 andi. r11,r10,_TIF_32BIT
175 ld r10,.SYS_CALL_TABLE32@toc(2)
177 * We now zero extend all six arguments (r3 - r8), the compatibility
178 * layer assumes this.
188 ld r10,.SYS_CALL_TABLE@toc(2)
191 ldx r10,r10,r0 /* Fetch system call handler [ptr] */
193 addi r9,r1,STACK_FRAME_OVERHEAD
194 blrl /* Call handler */
195 _GLOBAL(ret_from_syscall_2)
196 std r3,RESULT(r1) /* Save result */
201 57: ld r10,_CCR(r1) /* Set SO bit in CR */
204 60: std r3,GPR3(r1) /* Update return value */
205 bl .do_syscall_trace_leave
210 7: .string "syscall %d(%x, %x, %x, %x, %x, "
211 77: .string "%x, %x), current=%p\n"
212 79: .string " -> %x\n"
217 _GLOBAL(ppc32_swapcontext)
218 bl .sys32_swapcontext
221 _GLOBAL(ppc64_swapcontext)
225 _GLOBAL(ppc32_sigreturn)
229 _GLOBAL(ppc32_rt_sigreturn)
230 bl .sys32_rt_sigreturn
233 _GLOBAL(ppc64_rt_sigreturn)
236 80: clrrdi r4,r1,THREAD_SHIFT
238 andi. r4,r4,_TIF_SYSCALL_T_OR_A
242 b .ret_from_syscall_1
244 blt .ret_from_syscall_2
245 bl .do_syscall_trace_leave
249 * This routine switches between two different tasks. The process
250 * state of one is saved on its kernel stack. Then the state
251 * of the other is restored from its kernel stack. The memory
252 * management hardware is updated to the second process's state.
253 * Finally, we can return to the second process, via ret_from_except.
254 * On entry, r3 points to the THREAD for the current task, r4
255 * points to the THREAD for the new task.
257 * Note: there are two ways to get to the "going out" portion
258 * of this code; either by coming in via the entry (_switch)
259 * or via "fork" which must set up an environment equivalent
260 * to the "_switch" path. If you change this you'll have to change
261 * the fork code also.
263 * The code which creates the new task context is in 'copy_thread'
264 * in arch/ppc64/kernel/process.c
269 stdu r1,-SWITCH_FRAME_SIZE(r1)
270 /* r3-r13 are caller saved -- Cort */
273 mflr r20 /* Return to switch caller */
276 #ifdef CONFIG_ALTIVEC
278 oris r0,r0,MSR_VEC@h /* Disable altivec */
279 mfspr r24,SPRN_VRSAVE /* save vrsave register value */
280 std r24,THREAD_VRSAVE(r3)
281 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
282 #endif /* CONFIG_ALTIVEC */
291 std r1,KSP(r3) /* Set old stack pointer */
294 /* We need a sync somewhere here to make sure that if the
295 * previous task gets rescheduled on another CPU, it sees all
296 * stores it has performed on this one.
299 #endif /* CONFIG_SMP */
301 addi r6,r4,-THREAD /* Convert THREAD to 'current' */
302 std r6,PACACURRENT(r13) /* Set new 'current' */
304 ld r8,KSP(r4) /* new stack pointer */
306 clrrdi r6,r8,28 /* get its ESID */
307 clrrdi r9,r1,28 /* get current sp ESID */
308 clrldi. r0,r6,2 /* is new ESID c00000000? */
309 cmpd cr1,r6,r9 /* or is new ESID the same as current ESID? */
311 beq 2f /* if yes, don't slbie it */
312 oris r6,r6,0x0800 /* set C (class) bit */
314 slbie r6 /* Workaround POWER5 < DD2.1 issue */
316 END_FTR_SECTION_IFSET(CPU_FTR_SLB)
317 clrrdi r7,r8,THREAD_SHIFT /* base of new stack */
318 addi r7,r7,THREAD_SIZE-INT_FRAME_SIZE
320 mr r1,r8 /* start using new stack pointer */
321 std r7,PACAKSAVE(r13)
326 #ifdef CONFIG_ALTIVEC
328 ld r0,THREAD_VRSAVE(r4)
329 mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */
330 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
331 #endif /* CONFIG_ALTIVEC */
333 /* r3-r13 are destroyed -- Cort */
337 #ifdef CONFIG_PPC_ISERIES
338 clrrdi r7,r1,THREAD_SHIFT /* get current_thread_info() */
339 ld r7,TI_FLAGS(r7) /* Get run light flag */
341 srdi r7,r7,TIF_RUN_LIGHT
342 insrdi r9,r7,1,63 /* Insert run light into CTRL */
346 /* convert old thread to its task_struct for return value */
348 ld r7,_NIP(r1) /* Return to _switch caller in new task */
350 addi r1,r1,SWITCH_FRAME_SIZE
353 _GLOBAL(ret_from_fork)
355 clrrdi r4,r1,THREAD_SHIFT
357 andi. r4,r4,_TIF_SYSCALL_T_OR_A
358 beq+ .ret_from_except
359 bl .do_syscall_trace_leave
362 _GLOBAL(ret_from_except)
364 * Disable interrupts so that current_thread_info()->flags
365 * can't change between when we test it and when we return
366 * from the interrupt.
368 mfmsr r10 /* Get current interrupt state */
371 andc r9,r10,r4 /* clear MSR_EE */
372 mtmsrd r9,1 /* Update machine state */
374 ld r3,_MSR(r1) /* Returning to user mode? */
376 beq restore /* if not, just restore regs and return */
378 /* Check current_thread_info()->flags */
379 clrrdi r3,r1,THREAD_SHIFT
381 andi. r0,r3,_TIF_USER_WORK_MASK
384 addi r0,r1,INT_FRAME_SIZE /* size of frame */
385 ld r4,PACACURRENT(r13)
386 std r0,THREAD+KSP(r4) /* save kernel stack pointer */
389 * r13 is our per cpu area, only restore it if we are returning to
395 #ifdef CONFIG_PPC_ISERIES
397 mfspr r4,SPRG3 /* get paca address */
400 /* Check for pending interrupts (iSeries) */
401 /* this is CHECKANYINT except that we already have the paca address */
402 ld r3,PACALPPACA+LPPACAANYINT(r4)
404 beq+ 4f /* skip do_IRQ if no interrupts */
406 mfspr r13,SPRG3 /* get paca pointer back */
408 stb r3,PACAPROCENABLED(r13) /* ensure we are soft-disabled */
409 mtmsrd r10 /* hard-enable again */
410 addi r3,r1,STACK_FRAME_OVERHEAD
412 b .ret_from_except /* loop back and handle more */
414 4: stb r5,PACAPROCENABLED(r4)
432 stdcx. r0,0,r1 /* to clear the reservation */
455 /* Note: this must change if we start using the TIF_NOTIFY_RESUME bit */
457 /* Enable interrupts */
460 andi. r0,r3,_TIF_NEED_RESCHED
465 1: andi. r0,r3,_TIF_SIGPENDING
468 addi r4,r1,STACK_FRAME_OVERHEAD
474 addi r3,r1,STACK_FRAME_OVERHEAD
475 bl .unrecoverable_exception
478 #ifdef CONFIG_PPC_PSERIES
480 * On CHRP, the Run-Time Abstraction Services (RTAS) have to be
481 * called with the MMU off.
483 * In addition, we need to be in 32b mode, at least for now.
485 * Note: r3 is an input parameter to rtas, so don't trash it...
490 stdu r1,-RTAS_FRAME_SIZE(r1) /* Save SP and create stack space. */
492 /* Because RTAS is running in 32b mode, it clobbers the high order half
493 * of all registers that it saves. We therefore save those registers
494 * RTAS might touch to the stack. (r0, r3-r13 are caller saved)
496 SAVE_GPR(2, r1) /* Save the TOC */
497 SAVE_GPR(13, r1) /* Save paca */
498 SAVE_8GPRS(14, r1) /* Save the non-volatiles */
499 SAVE_10GPRS(22, r1) /* ditto */
516 /* There is no way it is acceptable to get here with interrupts enabled,
517 * check it with the asm equivalent of WARN_ON
522 .section __bug_table,"a"
523 .llong 1b,__LINE__ + 0x1000000, 1f, 2f
527 2: .asciz "enter_rtas"
530 /* Unfortunately, the stack pointer and the MSR are also clobbered,
531 * so they are saved in the PACA which allows us to restore
532 * our original state after RTAS returns.
535 std r6,PACASAVEDMSR(r13)
537 /* Setup our real return addr */
538 SET_REG_TO_LABEL(r4,.rtas_return_loc)
539 SET_REG_TO_CONST(r9,KERNELBASE)
544 ori r0,r0,MSR_EE|MSR_SE|MSR_BE|MSR_RI
548 rldicr r9,r9,MSR_SF_LG,(63-MSR_SF_LG)
549 ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP
552 sync /* disable interrupts so SRR0/1 */
553 mtmsrd r0 /* don't get trashed */
555 SET_REG_TO_LABEL(r4,rtas)
556 ld r5,RTASENTRY(r4) /* get the rtas->entry value */
557 ld r4,RTASBASE(r4) /* get the rtas->base value */
563 _STATIC(rtas_return_loc)
564 /* relocation is off at this point */
565 mfspr r4,SPRG3 /* Get PACA */
566 SET_REG_TO_CONST(r5, KERNELBASE)
567 sub r4,r4,r5 /* RELOC the PACA base pointer */
575 ld r1,PACAR1(r4) /* Restore our SP */
576 LOADADDR(r3,.rtas_restore_regs)
577 ld r4,PACASAVEDMSR(r4) /* Restore our MSR */
583 _STATIC(rtas_restore_regs)
584 /* relocation is on at this point */
585 REST_GPR(2, r1) /* Restore the TOC */
586 REST_GPR(13, r1) /* Restore paca */
587 REST_8GPRS(14, r1) /* Restore the non-volatiles */
588 REST_10GPRS(22, r1) /* ditto */
607 addi r1,r1,RTAS_FRAME_SIZE /* Unstack our frame */
608 ld r0,16(r1) /* get return address */
611 blr /* return to caller */
616 stdu r1,-PROM_FRAME_SIZE(r1) /* Save SP and create stack space */
618 /* Because PROM is running in 32b mode, it clobbers the high order half
619 * of all registers that it saves. We therefore save those registers
620 * PROM might touch to the stack. (r0, r3-r13 are caller saved)
643 /* Get the PROM entrypoint */
647 ld r12,PROMENTRY(r12)
650 /* Switch MSR to 32 bits mode
654 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
657 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
662 /* Restore arguments & enter PROM here... */
666 /* Just make sure that r1 top 32 bits didn't get
671 /* Restore the MSR (back to 64 bits) */
676 /* Restore other registers */
696 addi r1,r1,PROM_FRAME_SIZE
701 #endif /* defined(CONFIG_PPC_PSERIES) */