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>
9 #include <asm/export.h>
12 * Load state from memory into VMX registers including VSCR.
13 * Assumes the caller has enabled VMX in the MSR.
15 _GLOBAL(load_vr_state)
21 EXPORT_SYMBOL(load_vr_state)
24 * Store VMX state into memory, including VSCR.
25 * Assumes the caller has enabled VMX in the MSR.
27 _GLOBAL(store_vr_state)
33 EXPORT_SYMBOL(store_vr_state)
36 * Disable VMX for the task which had it previously,
37 * and save its vector registers in its thread_struct.
38 * Enables the VMX for use in the kernel on return.
39 * On SMP we know the VMX is free, since we give it up every
40 * switch (ie, no lazy save of the vector registers).
42 * Note that on 32-bit this can only use registers that will be
43 * restored by fast_exception_return, i.e. r3 - r6, r10 and r11.
45 _GLOBAL(load_up_altivec)
46 mfmsr r5 /* grab the current MSR */
48 MTMSRD(r5) /* enable use of AltiVec now */
52 * While userspace in general ignores VRSAVE, glibc uses it as a boolean
53 * to optimise userspace context save/restore. Whenever we take an
54 * altivec unavailable exception we must set VRSAVE to something non
55 * zero. Set it to all 1s. See also the programming note in the ISA.
63 /* enable use of VMX after return */
65 mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */
68 ld r4,PACACURRENT(r13)
69 addi r5,r4,THREAD /* Get THREAD */
70 oris r12,r12,MSR_VEC@h
73 /* Don't care if r4 overflows, this is desired behaviour */
74 lbz r4,THREAD_LOAD_VEC(r5)
76 stb r4,THREAD_LOAD_VEC(r5)
77 addi r6,r5,THREAD_VRSTATE
80 stw r4,THREAD_USED_VR(r5)
84 /* restore registers and return */
89 * Save the vector registers to its thread_struct
92 addi r3,r3,THREAD /* want THREAD of task */
93 PPC_LL r7,THREAD_VRSAVEAREA(r3)
97 addi r7,r3,THREAD_VRSTATE
98 2: SAVE_32VRS(0,r4,r7)
107 #error This asm code isn't ready for 32-bit kernels
111 * load_up_vsx(unused, unused, tsk)
112 * Disable VSX for the task which had it previously,
113 * and save its vector registers in its thread_struct.
114 * Reuse the fp and vsx saves, but first check to see if they have
115 * been saved already.
118 /* Load FP and VSX registers if they haven't been done yet */
120 beql+ load_up_fpu /* skip if already loaded */
121 andis. r5,r12,MSR_VEC@h
122 beql+ load_up_altivec /* skip if already loaded */
124 ld r4,PACACURRENT(r13)
125 addi r4,r4,THREAD /* Get THREAD */
127 stw r6,THREAD_USED_VSR(r4) /* ... also set thread used vsr */
128 /* enable use of VSX after return */
129 oris r12,r12,MSR_VSX@h
131 b fast_exception_return
133 #endif /* CONFIG_VSX */
137 * The routines below are in assembler so we can closely control the
138 * usage of floating-point registers. These routines must be called
139 * with preempt disabled.
146 .long 0x3f800000 /* 1.0 in single-precision FP */
148 .long 0x3f000000 /* 0.5 in single-precision FP */
150 #define LDCONST(fr, name) \
159 .tc FD_3ff00000_0[TC],0x3ff0000000000000 /* 1.0 */
161 .tc FD_3fe00000_0[TC],0x3fe0000000000000 /* 0.5 */
163 #define LDCONST(fr, name) \
169 * Internal routine to enable floating point and set FPSCR to 0.
170 * Don't call it from C; it doesn't use the normal calling convention.
202 * Vector add, floating point.
219 * Vector subtract, floating point.
236 * Vector multiply and add, floating point.
248 fmadds fr0,fr0,fr2,fr1
256 * Vector negative multiply and subtract, floating point.
268 fnmsubs fr0,fr0,fr2,fr1
276 * Vector reciprocal estimate. We just compute 1.0/x.
277 * r3 -> destination, r4 -> source.
294 * Vector reciprocal square-root estimate, floating point.
295 * We use the frsqrte instruction for the initial estimate followed
296 * by 2 iterations of Newton-Raphson to get sufficient accuracy.
297 * r3 -> destination, r4 -> source.
312 frsqrte fr1,fr0 /* r = frsqrte(s) */
313 fmuls fr3,fr1,fr0 /* r * s */
314 fmuls fr2,fr1,fr5 /* r * 0.5 */
315 fnmsubs fr3,fr1,fr3,fr4 /* 1 - s * r * r */
316 fmadds fr1,fr2,fr3,fr1 /* r = r + 0.5 * r * (1 - s * r * r) */
317 fmuls fr3,fr1,fr0 /* r * s */
318 fmuls fr2,fr1,fr5 /* r * 0.5 */
319 fnmsubs fr3,fr1,fr3,fr4 /* 1 - s * r * r */
320 fmadds fr1,fr2,fr3,fr1 /* r = r + 0.5 * r * (1 - s * r * r) */