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>
33 #ifdef CONFIG_PPC_ISERIES
34 #define DO_SOFT_DISABLE
38 #undef SHOW_SYSCALLS_TASK
40 #ifdef SHOW_SYSCALLS_TASK
48 .tc .sys_call_table[TC],.sys_call_table
51 .tc .sys_call_table32[TC],.sys_call_table32
57 * Handle a system call.
61 ld r11,_CCR(r1) /* Clear SO bit in CR */
66 #ifdef SHOW_SYSCALLS_TASK
67 LOADBASE(r31,show_syscalls_task)
68 ld r31,show_syscalls_task@l(r31)
69 ld r10,PACACURRENT(r13)
84 ld r6, PACACURRENT(r13)
94 #endif /* SHOW_SYSCALLS */
95 clrrdi r10,r1,THREAD_SHIFT
97 andi. r11,r10,_TIF_SYSCALL_TRACE
99 cmpli 0,r0,NR_syscalls
102 * Need to vector to 32 Bit or default sys_call_table here,
103 * based on caller's run-mode / personality.
105 andi. r11,r10,_TIF_32BIT
107 ld r10,.SYS_CALL_TABLE32@toc(2)
109 * We now zero extend all six arguments (r3 - r8), the compatibility
110 * layer assumes this.
120 ld r10,.SYS_CALL_TABLE@toc(2)
122 ldx r10,r10,r0 /* Fetch system call handler [ptr] */
124 addi r9,r1,STACK_FRAME_OVERHEAD
125 blrl /* Call handler */
126 _GLOBAL(ret_from_syscall_1)
127 std r3,RESULT(r1) /* Save result */
129 #ifdef SHOW_SYSCALLS_TASK
130 ld r10, PACACURRENT(13)
144 22: ld r10,_CCR(r1) /* Set SO bit in CR */
147 30: std r3,GPR3(r1) /* Update return value */
152 /* Traced system call support */
153 50: bl .do_syscall_trace
154 ld r0,GPR0(r1) /* Restore original registers */
161 /* XXX check this - Anton */
163 cmpli 0,r0,NR_syscalls
166 * Need to vector to 32 Bit or default sys_call_table here,
167 * based on caller's run-mode / personality.
169 clrrdi r10,r1,THREAD_SHIFT
171 andi. r11,r10,_TIF_32BIT
173 ld r10,.SYS_CALL_TABLE32@toc(2)
175 * We now zero extend all six arguments (r3 - r8), the compatibility
176 * layer assumes this.
186 ld r10,.SYS_CALL_TABLE@toc(2)
189 ldx r10,r10,r0 /* Fetch system call handler [ptr] */
191 addi r9,r1,STACK_FRAME_OVERHEAD
192 blrl /* Call handler */
193 _GLOBAL(ret_from_syscall_2)
194 std r3,RESULT(r1) /* Save result */
199 57: ld r10,_CCR(r1) /* Set SO bit in CR */
202 60: std r3,GPR3(r1) /* Update return value */
208 7: .string "syscall %d(%x, %x, %x, %x, %x, "
209 77: .string "%x, %x), current=%p\n"
210 79: .string " -> %x\n"
214 _GLOBAL(ppc32_sigreturn)
218 _GLOBAL(ppc32_rt_sigreturn)
219 bl .sys32_rt_sigreturn
222 _GLOBAL(ppc64_rt_sigreturn)
225 80: clrrdi r4,r1,THREAD_SHIFT
227 andi. r4,r4,_TIF_SYSCALL_TRACE
231 b .ret_from_syscall_1
233 blt .ret_from_syscall_2
238 * This routine switches between two different tasks. The process
239 * state of one is saved on its kernel stack. Then the state
240 * of the other is restored from its kernel stack. The memory
241 * management hardware is updated to the second process's state.
242 * Finally, we can return to the second process, via ret_from_except.
243 * On entry, r3 points to the THREAD for the current task, r4
244 * points to the THREAD for the new task.
246 * Note: there are two ways to get to the "going out" portion
247 * of this code; either by coming in via the entry (_switch)
248 * or via "fork" which must set up an environment equivalent
249 * to the "_switch" path. If you change this you'll have to change
250 * the fork code also.
252 * The code which creates the new task context is in 'copy_thread'
253 * in arch/ppc64/kernel/process.c
258 stdu r1,-SWITCH_FRAME_SIZE(r1)
259 /* r3-r13 are caller saved -- Cort */
262 mflr r20 /* Return to switch caller */
264 andi. r21, r22, MSR_FP
266 li r6,MSR_FP /* Disable floating-point */
273 std r1,KSP(r3) /* Set old stack pointer */
275 addi r6,r4,-THREAD /* Convert THREAD to 'current' */
276 std r6,PACACURRENT(r13) /* Set new 'current' */
278 #ifdef CONFIG_PPC_ISERIES
280 ld r7,TI_FLAGS(r4) /* Get run light flag */
282 srdi r7,r7,1 /* Align to run light bit in CTRL reg */
283 insrdi r9,r7,1,63 /* Insert run light into CTRL */
287 ld r1,KSP(r4) /* Load new stack pointer */
290 /* r3-r13 are destroyed -- Cort */
294 /* convert old thread to its task_struct for return value */
296 ld r7,_NIP(r1) /* Return to _switch caller in new task */
298 addi r1,r1,SWITCH_FRAME_SIZE
301 _GLOBAL(ret_from_fork)
303 clrrdi r4,r1,THREAD_SHIFT
305 andi. r4,r4,_TIF_SYSCALL_TRACE
306 beq+ .ret_from_except
310 _GLOBAL(ret_from_except)
311 #ifdef CONFIG_PPC_ISERIES
316 /* Check for pending interrupts (iSeries) */
318 beq+ 4f /* skip do_IRQ if no interrupts */
323 stb r3,PACAPROCENABLED(r5) /* ensure we are disabled */
324 addi r3,r1,STACK_FRAME_OVERHEAD
326 b irq_recheck /* loop back and handle more */
330 * Disable interrupts so that current_thread_info()->flags
331 * can't change between when we test it and when we return
332 * from the interrupt.
335 mfmsr r10 /* Get current interrupt state */
338 andc r10,r10,r4 /* clear MSR_EE */
339 mtmsrd r10,1 /* Update machine state */
341 #ifdef CONFIG_PPC_ISERIES
342 #error fix iSeries soft disable
345 ld r3,_MSR(r1) /* Returning to user mode? */
347 beq restore /* if not, just restore regs and return */
349 /* Check current_thread_info()->flags */
350 clrrdi r3,r1,THREAD_SHIFT
352 andi. r0,r3,_TIF_USER_WORK_MASK
355 addi r0,r1,INT_FRAME_SIZE /* size of frame */
356 ld r4,PACACURRENT(r13)
357 std r0,THREAD+KSP(r4) /* save kernel stack pointer */
358 std r1,PACAKSAVE(r13) /* save exception stack pointer */
361 * r13 is our per cpu area, only restore it if we are returning to
378 stdcx. r0,0,r1 /* to clear the reservation */
380 #ifdef DO_SOFT_DISABLE
381 /* XXX do this in do_work, r13 isnt valid here */
383 stb r0,PACAPROCENABLED(r13)
407 /* Note: this must change if we start using the TIF_NOTIFY_RESUME bit */
409 /* Enable interrupts */
413 andi. r0,r3,_TIF_NEED_RESCHED
418 1: andi. r0,r3,_TIF_SIGPENDING
421 addi r4,r1,STACK_FRAME_OVERHEAD
426 * On CHRP, the Run-Time Abstraction Services (RTAS) have to be
427 * called with the MMU off.
429 * In addition, we need to be in 32b mode, at least for now.
431 * Note: r3 is an input parameter to rtas, so don't trash it...
436 stdu r1,-RTAS_FRAME_SIZE(r1) /* Save SP and create stack space. */
438 /* Because RTAS is running in 32b mode, it clobbers the high order half
439 * of all registers that it saves. We therefore save those registers
440 * RTAS might touch to the stack. (r0, r3-r13 are caller saved)
442 SAVE_GPR(2, r1) /* Save the TOC */
443 SAVE_GPR(13, r1) /* Save paca */
444 SAVE_8GPRS(14, r1) /* Save the non-volatiles */
445 SAVE_10GPRS(22, r1) /* ditto */
462 /* Unfortunately, the stack pointer and the MSR are also clobbered,
463 * so they are saved in the PACA which allows us to restore
464 * our original state after RTAS returns.
468 std r6,PACASAVEDMSR(r13)
470 /* Setup our real return addr */
471 SET_REG_TO_LABEL(r4,.rtas_return_loc)
472 SET_REG_TO_CONST(r9,KERNELBASE)
477 ori r0,r0,MSR_EE|MSR_SE|MSR_BE|MSR_RI
481 rldicr r9,r9,MSR_SF_LG,(63-MSR_SF_LG)
482 ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP
485 sync /* disable interrupts so SRR0/1 */
486 mtmsrd r0 /* don't get trashed */
488 SET_REG_TO_LABEL(r4,rtas)
489 ld r5,RTASENTRY(r4) /* get the rtas->entry value */
490 ld r4,RTASBASE(r4) /* get the rtas->base value */
496 _STATIC(rtas_return_loc)
497 /* relocation is off at this point */
498 mfspr r4,SPRG3 /* Get PACA */
499 SET_REG_TO_CONST(r5, KERNELBASE)
500 sub r4,r4,r5 /* RELOC the PACA base pointer */
502 ld r1,PACAR1(r4) /* Restore our SP */
503 LOADADDR(r3,.rtas_restore_regs)
504 ld r4,PACASAVEDMSR(r4) /* Restore our MSR */
510 _STATIC(rtas_restore_regs)
511 /* relocation is on at this point */
512 REST_GPR(2, r1) /* Restore the TOC */
513 REST_GPR(13, r1) /* Restore paca */
514 REST_8GPRS(14, r1) /* Restore the non-volatiles */
515 REST_10GPRS(22, r1) /* ditto */
534 addi r1,r1,RTAS_FRAME_SIZE /* Unstack our frame */
535 ld r0,16(r1) /* get return address */
538 blr /* return to caller */
543 stdu r1,-PROM_FRAME_SIZE(r1) /* Save SP and create stack space */
545 /* Because PROM is running in 32b mode, it clobbers the high order half
546 * of all registers that it saves. We therefore save those registers
547 * PROM might touch to the stack. (r0, r3-r13 are caller saved)
549 SAVE_8GPRS(2, r1) /* Save the TOC & incoming param(s) */
550 SAVE_GPR(13, r1) /* Save paca */
551 SAVE_8GPRS(14, r1) /* Save the non-volatiles */
552 SAVE_10GPRS(22, r1) /* ditto */
571 /* Unfortunatly, the stack pointer is also clobbered, so it is saved
572 * in the SPRG2 which allows us to restore our original state after
577 /* put a relocation offset into r3 */
581 ld r12,PROMENTRY(r12) /* get the prom->entry value */
584 mfmsr r11 /* grab the current MSR */
586 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
589 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
594 REST_8GPRS(2, r1) /* Restore the TOC & param(s) */
595 REST_GPR(13, r1) /* Restore paca */
596 REST_8GPRS(14, r1) /* Restore the non-volatiles */
597 REST_10GPRS(22, r1) /* ditto */
598 blrl /* Entering PROM here... */
600 mfspr r1,SPRG2 /* Restore the stack pointer */
601 ld r6,_MSR(r1) /* Restore the MSR */
605 REST_GPR(2, r1) /* Restore the TOC */
606 REST_GPR(13, r1) /* Restore paca */
607 REST_8GPRS(14, r1) /* Restore the non-volatiles */
608 REST_10GPRS(22, r1) /* ditto */
624 addi r1,r1,PROM_FRAME_SIZE
625 ld r0,16(r1) /* get return address */
628 blr /* return to caller */