2 * FPU support code, moved here from head.S so that it can be used
3 * by chips which use other head-whatever.S files.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
12 #include <linux/config.h>
13 #include <asm/processor.h>
16 #include <asm/pgtable.h>
17 #include <asm/cputable.h>
18 #include <asm/cache.h>
19 #include <asm/thread_info.h>
20 #include <asm/ppc_asm.h>
21 #include <asm/asm-offsets.h>
24 * This task wants to use the FPU now.
25 * On UP, disable FP for the task which had the FPU previously,
26 * and save its floating-point registers in its thread_struct.
27 * Load up this task's FP registers from its thread_struct,
28 * enable the FPU for the current task and return to the task.
34 #ifdef CONFIG_PPC64BRIDGE
35 clrldi r5,r5,1 /* turn off 64-bit mode */
36 #endif /* CONFIG_PPC64BRIDGE */
38 MTMSRD(r5) /* enable use of fpu now */
41 * For SMP, we don't do lazy FPU switching because it just gets too
42 * horrendously complex, especially when a task switches from one CPU
43 * to another. Instead we call giveup_fpu in switch_to.
46 tophys(r6,0) /* get __pa constant */
47 addis r3,r6,last_task_used_math@ha
48 lwz r4,last_task_used_math@l(r3)
52 addi r4,r4,THREAD /* want last_task_used_math->thread */
55 stfd fr0,THREAD_FPSCR-4(r4)
58 lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
59 li r10,MSR_FP|MSR_FE0|MSR_FE1
60 andc r4,r4,r10 /* disable FP for previous task */
61 stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
63 #endif /* CONFIG_SMP */
64 /* enable use of FP after return */
65 mfspr r5,SPRN_SPRG3 /* current task's THREAD (phys) */
66 lwz r4,THREAD_FPEXC_MODE(r5)
67 ori r9,r9,MSR_FP /* enable FP for current */
69 lfd fr0,THREAD_FPSCR-4(r5)
75 stw r4,last_task_used_math@l(r3)
76 #endif /* CONFIG_SMP */
77 /* restore registers and return */
78 /* we haven't used ctr or xer or lr */
79 b fast_exception_return
82 * FP unavailable trap from kernel - print a message, but let
83 * the task use FP in the kernel until it returns to user mode.
89 stw r3,_MSR(r1) /* enable use of FP after return */
92 mr r4,r2 /* current */
96 86: .string "floating point used in kernel (task=%p, pc=%x)\n"
101 * Disable FP for the task given as the argument,
102 * and save the floating-point registers in its thread_struct.
103 * Enables the FPU for use in the kernel on return.
111 MTMSRD(r5) /* enable use of fpu now */
115 beqlr- /* if no previous owner, done */
116 addi r3,r3,THREAD /* want THREAD of task */
121 stfd fr0,THREAD_FPSCR-4(r3)
123 lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5)
124 li r3,MSR_FP|MSR_FE0|MSR_FE1
125 andc r4,r4,r3 /* disable FP for previous task */
126 stw r4,_MSR-STACK_FRAME_OVERHEAD(r5)
130 lis r4,last_task_used_math@ha
131 stw r5,last_task_used_math@l(r4)
132 #endif /* CONFIG_SMP */