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
11 /* void do_load_up_transact_altivec(struct thread_struct *thread)
13 * This is similar to load_up_altivec but for the transactional version of the
14 * vector regs. It doesn't mess with the task MSR or valid flags.
15 * Furthermore, VEC laziness is not supported with TM currently.
17 _GLOBAL(do_load_up_transact_altivec)
24 stw r4,THREAD_USED_VR(r3)
26 li r10,THREAD_TRANSACT_VRSTATE+VRSTATE_VSCR
29 addi r10,r3,THREAD_TRANSACT_VRSTATE
32 /* Disable VEC again. */
40 * Enable use of VMX/Altivec for the caller.
50 * Load state from memory into VMX registers including VSCR.
51 * Assumes the caller has enabled VMX in the MSR.
53 _GLOBAL(load_vr_state)
61 * Store VMX state into memory, including VSCR.
62 * Assumes the caller has enabled VMX in the MSR.
64 _GLOBAL(store_vr_state)
72 * Disable VMX for the task which had it previously,
73 * and save its vector registers in its thread_struct.
74 * Enables the VMX for use in the kernel on return.
75 * On SMP we know the VMX is free, since we give it up every
76 * switch (ie, no lazy save of the vector registers).
78 * Note that on 32-bit this can only use registers that will be
79 * restored by fast_exception_return, i.e. r3 - r6, r10 and r11.
81 _GLOBAL(load_up_altivec)
82 mfmsr r5 /* grab the current MSR */
84 MTMSRD(r5) /* enable use of AltiVec now */
88 * For SMP, we don't do lazy VMX switching because it just gets too
89 * horrendously complex, especially when a task switches from one CPU
90 * to another. Instead we call giveup_altvec in switch_to.
91 * VRSAVE isn't dealt with here, that is done in the normal context
92 * switch code. Note that we could rely on vrsave value to eventually
93 * avoid saving all of the VREGs here...
96 LOAD_REG_ADDRBASE(r3, last_task_used_altivec)
98 PPC_LL r4,ADDROFF(last_task_used_altivec)(r3)
102 /* Save VMX state to last_task_used_altivec's THREAD struct */
105 addi r6,r4,THREAD_VRSTATE
110 /* Disable VMX for last_task_used_altivec */
111 PPC_LL r5,PT_REGS(r4)
113 PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
116 PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
118 #endif /* CONFIG_SMP */
120 /* Hack: if we get an altivec unavailable trap with VRSAVE
121 * set to all zeros, we assume this is a broken application
122 * that fails to set it properly, and thus we switch it to
131 /* enable use of VMX after return */
133 mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */
136 ld r4,PACACURRENT(r13)
137 addi r5,r4,THREAD /* Get THREAD */
138 oris r12,r12,MSR_VEC@h
141 addi r6,r5,THREAD_VRSTATE
144 stw r4,THREAD_USED_VR(r5)
149 /* Update last_task_used_altivec to 'current' */
150 subi r4,r5,THREAD /* Back to 'current' */
152 PPC_STL r4,ADDROFF(last_task_used_altivec)(r3)
153 #endif /* CONFIG_SMP */
154 /* restore registers and return */
157 _GLOBAL(giveup_altivec_notask)
159 andis. r4,r3,MSR_VEC@h
160 bnelr /* Already enabled? */
163 MTMSRD(r3) /* enable use of VMX now */
168 * giveup_altivec(tsk)
169 * Disable VMX for the task given as the argument,
170 * and save the vector registers in its thread_struct.
171 * Enables the VMX for use in the kernel on return.
173 _GLOBAL(giveup_altivec)
177 MTMSRD(r5) /* enable use of VMX now */
180 beqlr /* if no previous owner, done */
181 addi r3,r3,THREAD /* want THREAD of task */
182 PPC_LL r7,THREAD_VRSAVEAREA(r3)
183 PPC_LL r5,PT_REGS(r3)
186 addi r7,r3,THREAD_VRSTATE
193 PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
196 lis r3,(MSR_VEC|MSR_VSX)@h
199 ALT_FTR_SECTION_END_IFSET(CPU_FTR_VSX)
203 andc r4,r4,r3 /* disable FP for previous task */
204 PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5)
208 LOAD_REG_ADDRBASE(r4,last_task_used_altivec)
209 PPC_STL r5,ADDROFF(last_task_used_altivec)(r4)
210 #endif /* CONFIG_SMP */
216 #error This asm code isn't ready for 32-bit kernels
220 * load_up_vsx(unused, unused, tsk)
221 * Disable VSX for the task which had it previously,
222 * and save its vector registers in its thread_struct.
223 * Reuse the fp and vsx saves, but first check to see if they have
224 * been saved already.
227 /* Load FP and VSX registers if they haven't been done yet */
229 beql+ load_up_fpu /* skip if already loaded */
230 andis. r5,r12,MSR_VEC@h
231 beql+ load_up_altivec /* skip if already loaded */
234 ld r3,last_task_used_vsx@got(r2)
238 /* Disable VSX for last_task_used_vsx */
241 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
244 std r6,_MSR-STACK_FRAME_OVERHEAD(r5)
246 #endif /* CONFIG_SMP */
247 ld r4,PACACURRENT(r13)
248 addi r4,r4,THREAD /* Get THREAD */
250 stw r6,THREAD_USED_VSR(r4) /* ... also set thread used vsr */
251 /* enable use of VSX after return */
252 oris r12,r12,MSR_VSX@h
255 /* Update last_task_used_vsx to 'current' */
256 ld r4,PACACURRENT(r13)
258 #endif /* CONFIG_SMP */
259 b fast_exception_return
263 * Disable VSX for the task given as the argument.
264 * Does NOT save vsx registers.
265 * Enables the VSX for use in the kernel on return.
267 _GLOBAL(__giveup_vsx)
270 mtmsrd r5 /* enable use of VSX now */
274 beqlr- /* if no previous owner, done */
275 addi r3,r3,THREAD /* want THREAD of task */
279 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
281 andc r4,r4,r3 /* disable VSX for previous task */
282 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
286 ld r4,last_task_used_vsx@got(r2)
288 #endif /* CONFIG_SMP */
291 #endif /* CONFIG_VSX */
295 * The routines below are in assembler so we can closely control the
296 * usage of floating-point registers. These routines must be called
297 * with preempt disabled.
304 .long 0x3f800000 /* 1.0 in single-precision FP */
306 .long 0x3f000000 /* 0.5 in single-precision FP */
308 #define LDCONST(fr, name) \
317 .tc FD_3ff00000_0[TC],0x3ff0000000000000 /* 1.0 */
319 .tc FD_3fe00000_0[TC],0x3fe0000000000000 /* 0.5 */
321 #define LDCONST(fr, name) \
327 * Internal routine to enable floating point and set FPSCR to 0.
328 * Don't call it from C; it doesn't use the normal calling convention.
360 * Vector add, floating point.
377 * Vector subtract, floating point.
394 * Vector multiply and add, floating point.
406 fmadds fr0,fr0,fr2,fr1
414 * Vector negative multiply and subtract, floating point.
426 fnmsubs fr0,fr0,fr2,fr1
434 * Vector reciprocal estimate. We just compute 1.0/x.
435 * r3 -> destination, r4 -> source.
452 * Vector reciprocal square-root estimate, floating point.
453 * We use the frsqrte instruction for the initial estimate followed
454 * by 2 iterations of Newton-Raphson to get sufficient accuracy.
455 * r3 -> destination, r4 -> source.
470 frsqrte fr1,fr0 /* r = frsqrte(s) */
471 fmuls fr3,fr1,fr0 /* r * s */
472 fmuls fr2,fr1,fr5 /* r * 0.5 */
473 fnmsubs fr3,fr1,fr3,fr4 /* 1 - s * r * r */
474 fmadds fr1,fr2,fr3,fr1 /* r = r + 0.5 * r * (1 - s * r * r) */
475 fmuls fr3,fr1,fr0 /* r * s */
476 fmuls fr2,fr1,fr5 /* r * 0.5 */
477 fnmsubs fr3,fr1,fr3,fr4 /* 1 - s * r * r */
478 fmadds fr1,fr2,fr3,fr1 /* r = r + 0.5 * r * (1 - s * r * r) */