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>
10 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
12 * Wrapper to call load_up_altivec from C.
13 * void do_load_up_altivec(struct pt_regs *regs);
15 _GLOBAL(do_load_up_altivec)
20 subi r6, r3, STACK_FRAME_OVERHEAD
21 /* load_up_altivec expects r12=MSR, r13=PACA, and returns
34 /* void do_load_up_transact_altivec(struct thread_struct *thread)
36 * This is similar to load_up_altivec but for the transactional version of the
37 * vector regs. It doesn't mess with the task MSR or valid flags.
38 * Furthermore, VEC laziness is not supported with TM currently.
40 _GLOBAL(do_load_up_transact_altivec)
47 stw r4,THREAD_USED_VR(r3)
49 li r10,THREAD_TRANSACT_VSCR
52 REST_32VRS_TRANSACT(0,r4,r3)
54 /* Disable VEC again. */
62 * load_up_altivec(unused, unused, tsk)
63 * Disable VMX for the task which had it previously,
64 * and save its vector registers in its thread_struct.
65 * Enables the VMX for use in the kernel on return.
66 * On SMP we know the VMX is free, since we give it up every
67 * switch (ie, no lazy save of the vector registers).
69 _GLOBAL(load_up_altivec)
70 mfmsr r5 /* grab the current MSR */
72 MTMSRD(r5) /* enable use of AltiVec now */
76 * For SMP, we don't do lazy VMX switching because it just gets too
77 * horrendously complex, especially when a task switches from one CPU
78 * to another. Instead we call giveup_altvec in switch_to.
79 * VRSAVE isn't dealt with here, that is done in the normal context
80 * switch code. Note that we could rely on vrsave value to eventually
81 * avoid saving all of the VREGs here...
84 LOAD_REG_ADDRBASE(r3, last_task_used_altivec)
86 PPC_LL r4,ADDROFF(last_task_used_altivec)(r3)
90 /* Save VMX state to last_task_used_altivec's THREAD struct */
97 /* Disable VMX for last_task_used_altivec */
100 PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
103 PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
105 #endif /* CONFIG_SMP */
107 /* Hack: if we get an altivec unavailable trap with VRSAVE
108 * set to all zeros, we assume this is a broken application
109 * that fails to set it properly, and thus we switch it to
118 /* enable use of VMX after return */
120 mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */
123 ld r4,PACACURRENT(r13)
124 addi r5,r4,THREAD /* Get THREAD */
125 oris r12,r12,MSR_VEC@h
130 stw r4,THREAD_USED_VR(r5)
135 /* Update last_task_used_altivec to 'current' */
136 subi r4,r5,THREAD /* Back to 'current' */
138 PPC_STL r4,ADDROFF(last_task_used_altivec)(r3)
139 #endif /* CONFIG_SMP */
140 /* restore registers and return */
143 _GLOBAL(giveup_altivec_notask)
145 andis. r4,r3,MSR_VEC@h
146 bnelr /* Already enabled? */
149 MTMSRD(r3) /* enable use of VMX now */
154 * giveup_altivec(tsk)
155 * Disable VMX for the task given as the argument,
156 * and save the vector registers in its thread_struct.
157 * Enables the VMX for use in the kernel on return.
159 _GLOBAL(giveup_altivec)
163 MTMSRD(r5) /* enable use of VMX now */
166 beqlr /* if no previous owner, done */
167 addi r3,r3,THREAD /* want THREAD of task */
168 PPC_LL r5,PT_REGS(r3)
175 PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
178 lis r3,(MSR_VEC|MSR_VSX)@h
181 ALT_FTR_SECTION_END_IFSET(CPU_FTR_VSX)
185 andc r4,r4,r3 /* disable FP for previous task */
186 PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
190 LOAD_REG_ADDRBASE(r4,last_task_used_altivec)
191 PPC_STL r5,ADDROFF(last_task_used_altivec)(r4)
192 #endif /* CONFIG_SMP */
198 #error This asm code isn't ready for 32-bit kernels
202 * load_up_vsx(unused, unused, tsk)
203 * Disable VSX for the task which had it previously,
204 * and save its vector registers in its thread_struct.
205 * Reuse the fp and vsx saves, but first check to see if they have
206 * been saved already.
209 /* Load FP and VSX registers if they haven't been done yet */
211 beql+ load_up_fpu /* skip if already loaded */
212 andis. r5,r12,MSR_VEC@h
213 beql+ load_up_altivec /* skip if already loaded */
216 ld r3,last_task_used_vsx@got(r2)
220 /* Disable VSX for last_task_used_vsx */
223 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
226 std r6,_MSR-STACK_FRAME_OVERHEAD(r5)
228 #endif /* CONFIG_SMP */
229 ld r4,PACACURRENT(r13)
230 addi r4,r4,THREAD /* Get THREAD */
232 stw r6,THREAD_USED_VSR(r4) /* ... also set thread used vsr */
233 /* enable use of VSX after return */
234 oris r12,r12,MSR_VSX@h
237 /* Update last_task_used_vsx to 'current' */
238 ld r4,PACACURRENT(r13)
240 #endif /* CONFIG_SMP */
241 b fast_exception_return
245 * Disable VSX for the task given as the argument.
246 * Does NOT save vsx registers.
247 * Enables the VSX for use in the kernel on return.
249 _GLOBAL(__giveup_vsx)
252 mtmsrd r5 /* enable use of VSX now */
256 beqlr- /* if no previous owner, done */
257 addi r3,r3,THREAD /* want THREAD of task */
261 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
263 andc r4,r4,r3 /* disable VSX for previous task */
264 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
268 ld r4,last_task_used_vsx@got(r2)
270 #endif /* CONFIG_SMP */
273 #endif /* CONFIG_VSX */
277 * The routines below are in assembler so we can closely control the
278 * usage of floating-point registers. These routines must be called
279 * with preempt disabled.
286 .long 0x3f800000 /* 1.0 in single-precision FP */
288 .long 0x3f000000 /* 0.5 in single-precision FP */
290 #define LDCONST(fr, name) \
299 .tc FD_3ff00000_0[TC],0x3ff0000000000000 /* 1.0 */
301 .tc FD_3fe00000_0[TC],0x3fe0000000000000 /* 0.5 */
303 #define LDCONST(fr, name) \
309 * Internal routine to enable floating point and set FPSCR to 0.
310 * Don't call it from C; it doesn't use the normal calling convention.
342 * Vector add, floating point.
359 * Vector subtract, floating point.
376 * Vector multiply and add, floating point.
388 fmadds fr0,fr0,fr2,fr1
396 * Vector negative multiply and subtract, floating point.
408 fnmsubs fr0,fr0,fr2,fr1
416 * Vector reciprocal estimate. We just compute 1.0/x.
417 * r3 -> destination, r4 -> source.
434 * Vector reciprocal square-root estimate, floating point.
435 * We use the frsqrte instruction for the initial estimate followed
436 * by 2 iterations of Newton-Raphson to get sufficient accuracy.
437 * r3 -> destination, r4 -> source.
452 frsqrte fr1,fr0 /* r = frsqrte(s) */
453 fmuls fr3,fr1,fr0 /* r * s */
454 fmuls fr2,fr1,fr5 /* r * 0.5 */
455 fnmsubs fr3,fr1,fr3,fr4 /* 1 - s * r * r */
456 fmadds fr1,fr2,fr3,fr1 /* r = r + 0.5 * r * (1 - s * r * r) */
457 fmuls fr3,fr1,fr0 /* r * s */
458 fmuls fr2,fr1,fr5 /* r * 0.5 */
459 fnmsubs fr3,fr1,fr3,fr4 /* 1 - s * r * r */
460 fmadds fr1,fr2,fr3,fr1 /* r = r + 0.5 * r * (1 - s * r * r) */