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
36 * Load state from memory into VMX registers including VSCR.
37 * Assumes the caller has enabled VMX in the MSR.
39 _GLOBAL(load_vr_state)
47 * Store VMX state into memory, including VSCR.
48 * Assumes the caller has enabled VMX in the MSR.
50 _GLOBAL(store_vr_state)
58 * Disable VMX for the task which had it previously,
59 * and save its vector registers in its thread_struct.
60 * Enables the VMX for use in the kernel on return.
61 * On SMP we know the VMX is free, since we give it up every
62 * switch (ie, no lazy save of the vector registers).
64 * Note that on 32-bit this can only use registers that will be
65 * restored by fast_exception_return, i.e. r3 - r6, r10 and r11.
67 _GLOBAL(load_up_altivec)
68 mfmsr r5 /* grab the current MSR */
70 MTMSRD(r5) /* enable use of AltiVec now */
73 /* Hack: if we get an altivec unavailable trap with VRSAVE
74 * set to all zeros, we assume this is a broken application
75 * that fails to set it properly, and thus we switch it to
84 /* enable use of VMX after return */
86 mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */
89 ld r4,PACACURRENT(r13)
90 addi r5,r4,THREAD /* Get THREAD */
91 oris r12,r12,MSR_VEC@h
94 /* Don't care if r4 overflows, this is desired behaviour */
95 lbz r4,THREAD_LOAD_VEC(r5)
97 stb r4,THREAD_LOAD_VEC(r5)
98 addi r6,r5,THREAD_VRSTATE
101 stw r4,THREAD_USED_VR(r5)
105 /* restore registers and return */
110 * Save the vector registers to its thread_struct
112 _GLOBAL(save_altivec)
113 addi r3,r3,THREAD /* want THREAD of task */
114 PPC_LL r7,THREAD_VRSAVEAREA(r3)
115 PPC_LL r5,PT_REGS(r3)
118 addi r7,r3,THREAD_VRSTATE
119 2: SAVE_32VRS(0,r4,r7)
128 #error This asm code isn't ready for 32-bit kernels
132 * load_up_vsx(unused, unused, tsk)
133 * Disable VSX for the task which had it previously,
134 * and save its vector registers in its thread_struct.
135 * Reuse the fp and vsx saves, but first check to see if they have
136 * been saved already.
139 /* Load FP and VSX registers if they haven't been done yet */
141 beql+ load_up_fpu /* skip if already loaded */
142 andis. r5,r12,MSR_VEC@h
143 beql+ load_up_altivec /* skip if already loaded */
145 ld r4,PACACURRENT(r13)
146 addi r4,r4,THREAD /* Get THREAD */
148 stw r6,THREAD_USED_VSR(r4) /* ... also set thread used vsr */
149 /* enable use of VSX after return */
150 oris r12,r12,MSR_VSX@h
152 b fast_exception_return
156 * Disable VSX for the task given as the argument.
157 * Does NOT save vsx registers.
159 _GLOBAL(__giveup_vsx)
160 addi r3,r3,THREAD /* want THREAD of task */
164 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
166 andc r4,r4,r3 /* disable VSX for previous task */
167 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
171 #endif /* CONFIG_VSX */
175 * The routines below are in assembler so we can closely control the
176 * usage of floating-point registers. These routines must be called
177 * with preempt disabled.
184 .long 0x3f800000 /* 1.0 in single-precision FP */
186 .long 0x3f000000 /* 0.5 in single-precision FP */
188 #define LDCONST(fr, name) \
197 .tc FD_3ff00000_0[TC],0x3ff0000000000000 /* 1.0 */
199 .tc FD_3fe00000_0[TC],0x3fe0000000000000 /* 0.5 */
201 #define LDCONST(fr, name) \
207 * Internal routine to enable floating point and set FPSCR to 0.
208 * Don't call it from C; it doesn't use the normal calling convention.
240 * Vector add, floating point.
257 * Vector subtract, floating point.
274 * Vector multiply and add, floating point.
286 fmadds fr0,fr0,fr2,fr1
294 * Vector negative multiply and subtract, floating point.
306 fnmsubs fr0,fr0,fr2,fr1
314 * Vector reciprocal estimate. We just compute 1.0/x.
315 * r3 -> destination, r4 -> source.
332 * Vector reciprocal square-root estimate, floating point.
333 * We use the frsqrte instruction for the initial estimate followed
334 * by 2 iterations of Newton-Raphson to get sufficient accuracy.
335 * r3 -> destination, r4 -> source.
350 frsqrte fr1,fr0 /* r = frsqrte(s) */
351 fmuls fr3,fr1,fr0 /* r * s */
352 fmuls fr2,fr1,fr5 /* r * 0.5 */
353 fnmsubs fr3,fr1,fr3,fr4 /* 1 - s * r * r */
354 fmadds fr1,fr2,fr3,fr1 /* r = r + 0.5 * r * (1 - s * r * r) */
355 fmuls fr3,fr1,fr0 /* r * s */
356 fmuls fr2,fr1,fr5 /* r * 0.5 */
357 fnmsubs fr3,fr1,fr3,fr4 /* 1 - s * r * r */
358 fmadds fr1,fr2,fr3,fr1 /* r = r + 0.5 * r * (1 - s * r * r) */