1 #include <asm/processor.h>
2 #include <asm/ppc_asm.h>
4 #include <asm/asm-offsets.h>
5 #include <asm/cputable.h>
6 #include <asm/thread_info.h>
8 #include <asm/ptrace.h>
11 * load_up_altivec(unused, unused, tsk)
12 * Disable VMX for the task which had it previously,
13 * and save its vector registers in its thread_struct.
14 * Enables the VMX for use in the kernel on return.
15 * On SMP we know the VMX is free, since we give it up every
16 * switch (ie, no lazy save of the vector registers).
18 _GLOBAL(load_up_altivec)
19 mfmsr r5 /* grab the current MSR */
21 MTMSRD(r5) /* enable use of AltiVec now */
25 * For SMP, we don't do lazy VMX switching because it just gets too
26 * horrendously complex, especially when a task switches from one CPU
27 * to another. Instead we call giveup_altvec in switch_to.
28 * VRSAVE isn't dealt with here, that is done in the normal context
29 * switch code. Note that we could rely on vrsave value to eventually
30 * avoid saving all of the VREGs here...
33 LOAD_REG_ADDRBASE(r3, last_task_used_altivec)
35 PPC_LL r4,ADDROFF(last_task_used_altivec)(r3)
39 /* Save VMX state to last_task_used_altivec's THREAD struct */
46 /* Disable VMX for last_task_used_altivec */
49 PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
52 PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
54 #endif /* CONFIG_SMP */
56 /* Hack: if we get an altivec unavailable trap with VRSAVE
57 * set to all zeros, we assume this is a broken application
58 * that fails to set it properly, and thus we switch it to
67 /* enable use of VMX after return */
69 mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */
72 ld r4,PACACURRENT(r13)
73 addi r5,r4,THREAD /* Get THREAD */
74 oris r12,r12,MSR_VEC@h
79 stw r4,THREAD_USED_VR(r5)
84 /* Update last_task_used_altivec to 'current' */
85 subi r4,r5,THREAD /* Back to 'current' */
87 PPC_STL r4,ADDROFF(last_task_used_altivec)(r3)
88 #endif /* CONFIG_SMP */
89 /* restore registers and return */
92 _GLOBAL(giveup_altivec_notask)
94 andis. r4,r3,MSR_VEC@h
95 bnelr /* Already enabled? */
98 MTMSRD(r3) /* enable use of VMX now */
103 * giveup_altivec(tsk)
104 * Disable VMX for the task given as the argument,
105 * and save the vector registers in its thread_struct.
106 * Enables the VMX for use in the kernel on return.
108 _GLOBAL(giveup_altivec)
112 MTMSRD(r5) /* enable use of VMX now */
115 beqlr /* if no previous owner, done */
116 addi r3,r3,THREAD /* want THREAD of task */
117 PPC_LL r5,PT_REGS(r3)
124 PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
127 lis r3,(MSR_VEC|MSR_VSX)@h
130 ALT_FTR_SECTION_END_IFSET(CPU_FTR_VSX)
134 andc r4,r4,r3 /* disable FP for previous task */
135 PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
139 LOAD_REG_ADDRBASE(r4,last_task_used_altivec)
140 PPC_STL r5,ADDROFF(last_task_used_altivec)(r4)
141 #endif /* CONFIG_SMP */
147 #error This asm code isn't ready for 32-bit kernels
151 * load_up_vsx(unused, unused, tsk)
152 * Disable VSX for the task which had it previously,
153 * and save its vector registers in its thread_struct.
154 * Reuse the fp and vsx saves, but first check to see if they have
155 * been saved already.
158 /* Load FP and VSX registers if they haven't been done yet */
160 beql+ load_up_fpu /* skip if already loaded */
161 andis. r5,r12,MSR_VEC@h
162 beql+ load_up_altivec /* skip if already loaded */
165 ld r3,last_task_used_vsx@got(r2)
169 /* Disable VSX for last_task_used_vsx */
172 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
175 std r6,_MSR-STACK_FRAME_OVERHEAD(r5)
177 #endif /* CONFIG_SMP */
178 ld r4,PACACURRENT(r13)
179 addi r4,r4,THREAD /* Get THREAD */
181 stw r6,THREAD_USED_VSR(r4) /* ... also set thread used vsr */
182 /* enable use of VSX after return */
183 oris r12,r12,MSR_VSX@h
186 /* Update last_task_used_vsx to 'current' */
187 ld r4,PACACURRENT(r13)
189 #endif /* CONFIG_SMP */
190 b fast_exception_return
194 * Disable VSX for the task given as the argument.
195 * Does NOT save vsx registers.
196 * Enables the VSX for use in the kernel on return.
198 _GLOBAL(__giveup_vsx)
201 mtmsrd r5 /* enable use of VSX now */
205 beqlr- /* if no previous owner, done */
206 addi r3,r3,THREAD /* want THREAD of task */
210 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
212 andc r4,r4,r3 /* disable VSX for previous task */
213 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
217 ld r4,last_task_used_vsx@got(r2)
219 #endif /* CONFIG_SMP */
222 #endif /* CONFIG_VSX */
226 * The routines below are in assembler so we can closely control the
227 * usage of floating-point registers. These routines must be called
228 * with preempt disabled.
235 .long 0x3f800000 /* 1.0 in single-precision FP */
237 .long 0x3f000000 /* 0.5 in single-precision FP */
239 #define LDCONST(fr, name) \
248 .tc FD_3ff00000_0[TC],0x3ff0000000000000 /* 1.0 */
250 .tc FD_3fe00000_0[TC],0x3fe0000000000000 /* 0.5 */
252 #define LDCONST(fr, name) \
258 * Internal routine to enable floating point and set FPSCR to 0.
259 * Don't call it from C; it doesn't use the normal calling convention.
291 * Vector add, floating point.
308 * Vector subtract, floating point.
325 * Vector multiply and add, floating point.
337 fmadds fr0,fr0,fr2,fr1
345 * Vector negative multiply and subtract, floating point.
357 fnmsubs fr0,fr0,fr2,fr1
365 * Vector reciprocal estimate. We just compute 1.0/x.
366 * r3 -> destination, r4 -> source.
383 * Vector reciprocal square-root estimate, floating point.
384 * We use the frsqrte instruction for the initial estimate followed
385 * by 2 iterations of Newton-Raphson to get sufficient accuracy.
386 * r3 -> destination, r4 -> source.
401 frsqrte fr1,fr0 /* r = frsqrte(s) */
402 fmuls fr3,fr1,fr0 /* r * s */
403 fmuls fr2,fr1,fr5 /* r * 0.5 */
404 fnmsubs fr3,fr1,fr3,fr4 /* 1 - s * r * r */
405 fmadds fr1,fr2,fr3,fr1 /* r = r + 0.5 * r * (1 - s * r * r) */
406 fmuls fr3,fr1,fr0 /* r * s */
407 fmuls fr2,fr1,fr5 /* r * 0.5 */
408 fnmsubs fr3,fr1,fr3,fr4 /* 1 - s * r * r */
409 fmadds fr1,fr2,fr3,fr1 /* r = r + 0.5 * r * (1 - s * r * r) */