diff options
author | Alexander Graf <agraf@suse.de> | 2010-02-19 05:00:40 -0500 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-04-25 05:35:15 -0400 |
commit | 963cf3dc6342fe60bb78c615884537621abca0bc (patch) | |
tree | f99b26e7e6eee2235d8fabe448c8bbc6c0a8f24f | |
parent | aba3bd7ffe13fad6c4483b49686ad454a4cb409b (diff) |
KVM: PPC: Add helpers to call FPU instructions
To emulate paired single instructions, we need to be able to call FPU
operations from within the kernel. Since we don't want gcc to spill
arbitrary FPU code everywhere, we tell it to use a soft fpu.
Since we know we can really call the FPU in safe areas, let's also add
some calls that we can later use to actually execute real world FPU
operations on the host's FPU.
Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
-rw-r--r-- | arch/powerpc/include/asm/kvm_fpu.h | 85 | ||||
-rw-r--r-- | arch/powerpc/kernel/ppc_ksyms.c | 2 | ||||
-rw-r--r-- | arch/powerpc/kvm/Makefile | 1 | ||||
-rw-r--r-- | arch/powerpc/kvm/fpu.S | 273 |
4 files changed, 361 insertions, 0 deletions
diff --git a/arch/powerpc/include/asm/kvm_fpu.h b/arch/powerpc/include/asm/kvm_fpu.h new file mode 100644 index 000000000000..94f05de9ad04 --- /dev/null +++ b/arch/powerpc/include/asm/kvm_fpu.h | |||
@@ -0,0 +1,85 @@ | |||
1 | /* | ||
2 | * This program is free software; you can redistribute it and/or modify | ||
3 | * it under the terms of the GNU General Public License, version 2, as | ||
4 | * published by the Free Software Foundation. | ||
5 | * | ||
6 | * This program is distributed in the hope that it will be useful, | ||
7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
9 | * GNU General Public License for more details. | ||
10 | * | ||
11 | * You should have received a copy of the GNU General Public License | ||
12 | * along with this program; if not, write to the Free Software | ||
13 | * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
14 | * | ||
15 | * Copyright Novell Inc. 2010 | ||
16 | * | ||
17 | * Authors: Alexander Graf <agraf@suse.de> | ||
18 | */ | ||
19 | |||
20 | #ifndef __ASM_KVM_FPU_H__ | ||
21 | #define __ASM_KVM_FPU_H__ | ||
22 | |||
23 | #include <linux/types.h> | ||
24 | |||
25 | extern void fps_fres(struct thread_struct *t, u32 *dst, u32 *src1); | ||
26 | extern void fps_frsqrte(struct thread_struct *t, u32 *dst, u32 *src1); | ||
27 | extern void fps_fsqrts(struct thread_struct *t, u32 *dst, u32 *src1); | ||
28 | |||
29 | extern void fps_fadds(struct thread_struct *t, u32 *dst, u32 *src1, u32 *src2); | ||
30 | extern void fps_fdivs(struct thread_struct *t, u32 *dst, u32 *src1, u32 *src2); | ||
31 | extern void fps_fmuls(struct thread_struct *t, u32 *dst, u32 *src1, u32 *src2); | ||
32 | extern void fps_fsubs(struct thread_struct *t, u32 *dst, u32 *src1, u32 *src2); | ||
33 | |||
34 | extern void fps_fmadds(struct thread_struct *t, u32 *dst, u32 *src1, u32 *src2, | ||
35 | u32 *src3); | ||
36 | extern void fps_fmsubs(struct thread_struct *t, u32 *dst, u32 *src1, u32 *src2, | ||
37 | u32 *src3); | ||
38 | extern void fps_fnmadds(struct thread_struct *t, u32 *dst, u32 *src1, u32 *src2, | ||
39 | u32 *src3); | ||
40 | extern void fps_fnmsubs(struct thread_struct *t, u32 *dst, u32 *src1, u32 *src2, | ||
41 | u32 *src3); | ||
42 | extern void fps_fsel(struct thread_struct *t, u32 *dst, u32 *src1, u32 *src2, | ||
43 | u32 *src3); | ||
44 | |||
45 | #define FPD_ONE_IN(name) extern void fpd_ ## name(u64 *fpscr, u32 *cr, \ | ||
46 | u64 *dst, u64 *src1); | ||
47 | #define FPD_TWO_IN(name) extern void fpd_ ## name(u64 *fpscr, u32 *cr, \ | ||
48 | u64 *dst, u64 *src1, u64 *src2); | ||
49 | #define FPD_THREE_IN(name) extern void fpd_ ## name(u64 *fpscr, u32 *cr, \ | ||
50 | u64 *dst, u64 *src1, u64 *src2, u64 *src3); | ||
51 | |||
52 | extern void fpd_fcmpu(u64 *fpscr, u32 *cr, u64 *src1, u64 *src2); | ||
53 | extern void fpd_fcmpo(u64 *fpscr, u32 *cr, u64 *src1, u64 *src2); | ||
54 | |||
55 | FPD_ONE_IN(fsqrts) | ||
56 | FPD_ONE_IN(frsqrtes) | ||
57 | FPD_ONE_IN(fres) | ||
58 | FPD_ONE_IN(frsp) | ||
59 | FPD_ONE_IN(fctiw) | ||
60 | FPD_ONE_IN(fctiwz) | ||
61 | FPD_ONE_IN(fsqrt) | ||
62 | FPD_ONE_IN(fre) | ||
63 | FPD_ONE_IN(frsqrte) | ||
64 | FPD_ONE_IN(fneg) | ||
65 | FPD_ONE_IN(fabs) | ||
66 | FPD_TWO_IN(fadds) | ||
67 | FPD_TWO_IN(fsubs) | ||
68 | FPD_TWO_IN(fdivs) | ||
69 | FPD_TWO_IN(fmuls) | ||
70 | FPD_TWO_IN(fcpsgn) | ||
71 | FPD_TWO_IN(fdiv) | ||
72 | FPD_TWO_IN(fadd) | ||
73 | FPD_TWO_IN(fmul) | ||
74 | FPD_TWO_IN(fsub) | ||
75 | FPD_THREE_IN(fmsubs) | ||
76 | FPD_THREE_IN(fmadds) | ||
77 | FPD_THREE_IN(fnmsubs) | ||
78 | FPD_THREE_IN(fnmadds) | ||
79 | FPD_THREE_IN(fsel) | ||
80 | FPD_THREE_IN(fmsub) | ||
81 | FPD_THREE_IN(fmadd) | ||
82 | FPD_THREE_IN(fnmsub) | ||
83 | FPD_THREE_IN(fnmadd) | ||
84 | |||
85 | #endif | ||
diff --git a/arch/powerpc/kernel/ppc_ksyms.c b/arch/powerpc/kernel/ppc_ksyms.c index ab3e392ac63c..58fdb3a784de 100644 --- a/arch/powerpc/kernel/ppc_ksyms.c +++ b/arch/powerpc/kernel/ppc_ksyms.c | |||
@@ -101,6 +101,8 @@ EXPORT_SYMBOL(pci_dram_offset); | |||
101 | EXPORT_SYMBOL(start_thread); | 101 | EXPORT_SYMBOL(start_thread); |
102 | EXPORT_SYMBOL(kernel_thread); | 102 | EXPORT_SYMBOL(kernel_thread); |
103 | 103 | ||
104 | EXPORT_SYMBOL_GPL(cvt_df); | ||
105 | EXPORT_SYMBOL_GPL(cvt_fd); | ||
104 | EXPORT_SYMBOL(giveup_fpu); | 106 | EXPORT_SYMBOL(giveup_fpu); |
105 | #ifdef CONFIG_ALTIVEC | 107 | #ifdef CONFIG_ALTIVEC |
106 | EXPORT_SYMBOL(giveup_altivec); | 108 | EXPORT_SYMBOL(giveup_altivec); |
diff --git a/arch/powerpc/kvm/Makefile b/arch/powerpc/kvm/Makefile index 56484d652377..e575cfd015fe 100644 --- a/arch/powerpc/kvm/Makefile +++ b/arch/powerpc/kvm/Makefile | |||
@@ -40,6 +40,7 @@ kvm-objs-$(CONFIG_KVM_E500) := $(kvm-e500-objs) | |||
40 | 40 | ||
41 | kvm-book3s_64-objs := \ | 41 | kvm-book3s_64-objs := \ |
42 | $(common-objs-y) \ | 42 | $(common-objs-y) \ |
43 | fpu.o \ | ||
43 | book3s.o \ | 44 | book3s.o \ |
44 | book3s_64_emulate.o \ | 45 | book3s_64_emulate.o \ |
45 | book3s_64_interrupts.o \ | 46 | book3s_64_interrupts.o \ |
diff --git a/arch/powerpc/kvm/fpu.S b/arch/powerpc/kvm/fpu.S new file mode 100644 index 000000000000..2b340a3eee90 --- /dev/null +++ b/arch/powerpc/kvm/fpu.S | |||
@@ -0,0 +1,273 @@ | |||
1 | /* | ||
2 | * FPU helper code to use FPU operations from inside the kernel | ||
3 | * | ||
4 | * Copyright (C) 2010 Alexander Graf (agraf@suse.de) | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include <asm/reg.h> | ||
14 | #include <asm/page.h> | ||
15 | #include <asm/mmu.h> | ||
16 | #include <asm/pgtable.h> | ||
17 | #include <asm/cputable.h> | ||
18 | #include <asm/cache.h> | ||
19 | #include <asm/thread_info.h> | ||
20 | #include <asm/ppc_asm.h> | ||
21 | #include <asm/asm-offsets.h> | ||
22 | |||
23 | /* Instructions operating on single parameters */ | ||
24 | |||
25 | /* | ||
26 | * Single operation with one input operand | ||
27 | * | ||
28 | * R3 = (double*)&fpscr | ||
29 | * R4 = (short*)&result | ||
30 | * R5 = (short*)¶m1 | ||
31 | */ | ||
32 | #define FPS_ONE_IN(name) \ | ||
33 | _GLOBAL(fps_ ## name); \ | ||
34 | lfd 0,0(r3); /* load up fpscr value */ \ | ||
35 | MTFSF_L(0); \ | ||
36 | lfs 0,0(r5); \ | ||
37 | \ | ||
38 | name 0,0; \ | ||
39 | \ | ||
40 | stfs 0,0(r4); \ | ||
41 | mffs 0; \ | ||
42 | stfd 0,0(r3); /* save new fpscr value */ \ | ||
43 | blr | ||
44 | |||
45 | /* | ||
46 | * Single operation with two input operands | ||
47 | * | ||
48 | * R3 = (double*)&fpscr | ||
49 | * R4 = (short*)&result | ||
50 | * R5 = (short*)¶m1 | ||
51 | * R6 = (short*)¶m2 | ||
52 | */ | ||
53 | #define FPS_TWO_IN(name) \ | ||
54 | _GLOBAL(fps_ ## name); \ | ||
55 | lfd 0,0(r3); /* load up fpscr value */ \ | ||
56 | MTFSF_L(0); \ | ||
57 | lfs 0,0(r5); \ | ||
58 | lfs 1,0(r6); \ | ||
59 | \ | ||
60 | name 0,0,1; \ | ||
61 | \ | ||
62 | stfs 0,0(r4); \ | ||
63 | mffs 0; \ | ||
64 | stfd 0,0(r3); /* save new fpscr value */ \ | ||
65 | blr | ||
66 | |||
67 | /* | ||
68 | * Single operation with three input operands | ||
69 | * | ||
70 | * R3 = (double*)&fpscr | ||
71 | * R4 = (short*)&result | ||
72 | * R5 = (short*)¶m1 | ||
73 | * R6 = (short*)¶m2 | ||
74 | * R7 = (short*)¶m3 | ||
75 | */ | ||
76 | #define FPS_THREE_IN(name) \ | ||
77 | _GLOBAL(fps_ ## name); \ | ||
78 | lfd 0,0(r3); /* load up fpscr value */ \ | ||
79 | MTFSF_L(0); \ | ||
80 | lfs 0,0(r5); \ | ||
81 | lfs 1,0(r6); \ | ||
82 | lfs 2,0(r7); \ | ||
83 | \ | ||
84 | name 0,0,1,2; \ | ||
85 | \ | ||
86 | stfs 0,0(r4); \ | ||
87 | mffs 0; \ | ||
88 | stfd 0,0(r3); /* save new fpscr value */ \ | ||
89 | blr | ||
90 | |||
91 | FPS_ONE_IN(fres) | ||
92 | FPS_ONE_IN(frsqrte) | ||
93 | FPS_ONE_IN(fsqrts) | ||
94 | FPS_TWO_IN(fadds) | ||
95 | FPS_TWO_IN(fdivs) | ||
96 | FPS_TWO_IN(fmuls) | ||
97 | FPS_TWO_IN(fsubs) | ||
98 | FPS_THREE_IN(fmadds) | ||
99 | FPS_THREE_IN(fmsubs) | ||
100 | FPS_THREE_IN(fnmadds) | ||
101 | FPS_THREE_IN(fnmsubs) | ||
102 | FPS_THREE_IN(fsel) | ||
103 | |||
104 | |||
105 | /* Instructions operating on double parameters */ | ||
106 | |||
107 | /* | ||
108 | * Beginning of double instruction processing | ||
109 | * | ||
110 | * R3 = (double*)&fpscr | ||
111 | * R4 = (u32*)&cr | ||
112 | * R5 = (double*)&result | ||
113 | * R6 = (double*)¶m1 | ||
114 | * R7 = (double*)¶m2 [load_two] | ||
115 | * R8 = (double*)¶m3 [load_three] | ||
116 | * LR = instruction call function | ||
117 | */ | ||
118 | fpd_load_three: | ||
119 | lfd 2,0(r8) /* load param3 */ | ||
120 | fpd_load_two: | ||
121 | lfd 1,0(r7) /* load param2 */ | ||
122 | fpd_load_one: | ||
123 | lfd 0,0(r6) /* load param1 */ | ||
124 | fpd_load_none: | ||
125 | lfd 3,0(r3) /* load up fpscr value */ | ||
126 | MTFSF_L(3) | ||
127 | lwz r6, 0(r4) /* load cr */ | ||
128 | mtcr r6 | ||
129 | blr | ||
130 | |||
131 | /* | ||
132 | * End of double instruction processing | ||
133 | * | ||
134 | * R3 = (double*)&fpscr | ||
135 | * R4 = (u32*)&cr | ||
136 | * R5 = (double*)&result | ||
137 | * LR = caller of instruction call function | ||
138 | */ | ||
139 | fpd_return: | ||
140 | mfcr r6 | ||
141 | stfd 0,0(r5) /* save result */ | ||
142 | mffs 0 | ||
143 | stfd 0,0(r3) /* save new fpscr value */ | ||
144 | stw r6,0(r4) /* save new cr value */ | ||
145 | blr | ||
146 | |||
147 | /* | ||
148 | * Double operation with no input operand | ||
149 | * | ||
150 | * R3 = (double*)&fpscr | ||
151 | * R4 = (u32*)&cr | ||
152 | * R5 = (double*)&result | ||
153 | */ | ||
154 | #define FPD_NONE_IN(name) \ | ||
155 | _GLOBAL(fpd_ ## name); \ | ||
156 | mflr r12; \ | ||
157 | bl fpd_load_none; \ | ||
158 | mtlr r12; \ | ||
159 | \ | ||
160 | name. 0; /* call instruction */ \ | ||
161 | b fpd_return | ||
162 | |||
163 | /* | ||
164 | * Double operation with one input operand | ||
165 | * | ||
166 | * R3 = (double*)&fpscr | ||
167 | * R4 = (u32*)&cr | ||
168 | * R5 = (double*)&result | ||
169 | * R6 = (double*)¶m1 | ||
170 | */ | ||
171 | #define FPD_ONE_IN(name) \ | ||
172 | _GLOBAL(fpd_ ## name); \ | ||
173 | mflr r12; \ | ||
174 | bl fpd_load_one; \ | ||
175 | mtlr r12; \ | ||
176 | \ | ||
177 | name. 0,0; /* call instruction */ \ | ||
178 | b fpd_return | ||
179 | |||
180 | /* | ||
181 | * Double operation with two input operands | ||
182 | * | ||
183 | * R3 = (double*)&fpscr | ||
184 | * R4 = (u32*)&cr | ||
185 | * R5 = (double*)&result | ||
186 | * R6 = (double*)¶m1 | ||
187 | * R7 = (double*)¶m2 | ||
188 | * R8 = (double*)¶m3 | ||
189 | */ | ||
190 | #define FPD_TWO_IN(name) \ | ||
191 | _GLOBAL(fpd_ ## name); \ | ||
192 | mflr r12; \ | ||
193 | bl fpd_load_two; \ | ||
194 | mtlr r12; \ | ||
195 | \ | ||
196 | name. 0,0,1; /* call instruction */ \ | ||
197 | b fpd_return | ||
198 | |||
199 | /* | ||
200 | * CR Double operation with two input operands | ||
201 | * | ||
202 | * R3 = (double*)&fpscr | ||
203 | * R4 = (u32*)&cr | ||
204 | * R5 = (double*)¶m1 | ||
205 | * R6 = (double*)¶m2 | ||
206 | * R7 = (double*)¶m3 | ||
207 | */ | ||
208 | #define FPD_TWO_IN_CR(name) \ | ||
209 | _GLOBAL(fpd_ ## name); \ | ||
210 | lfd 1,0(r6); /* load param2 */ \ | ||
211 | lfd 0,0(r5); /* load param1 */ \ | ||
212 | lfd 3,0(r3); /* load up fpscr value */ \ | ||
213 | MTFSF_L(3); \ | ||
214 | lwz r6, 0(r4); /* load cr */ \ | ||
215 | mtcr r6; \ | ||
216 | \ | ||
217 | name 0,0,1; /* call instruction */ \ | ||
218 | mfcr r6; \ | ||
219 | mffs 0; \ | ||
220 | stfd 0,0(r3); /* save new fpscr value */ \ | ||
221 | stw r6,0(r4); /* save new cr value */ \ | ||
222 | blr | ||
223 | |||
224 | /* | ||
225 | * Double operation with three input operands | ||
226 | * | ||
227 | * R3 = (double*)&fpscr | ||
228 | * R4 = (u32*)&cr | ||
229 | * R5 = (double*)&result | ||
230 | * R6 = (double*)¶m1 | ||
231 | * R7 = (double*)¶m2 | ||
232 | * R8 = (double*)¶m3 | ||
233 | */ | ||
234 | #define FPD_THREE_IN(name) \ | ||
235 | _GLOBAL(fpd_ ## name); \ | ||
236 | mflr r12; \ | ||
237 | bl fpd_load_three; \ | ||
238 | mtlr r12; \ | ||
239 | \ | ||
240 | name. 0,0,1,2; /* call instruction */ \ | ||
241 | b fpd_return | ||
242 | |||
243 | FPD_ONE_IN(fsqrts) | ||
244 | FPD_ONE_IN(frsqrtes) | ||
245 | FPD_ONE_IN(fres) | ||
246 | FPD_ONE_IN(frsp) | ||
247 | FPD_ONE_IN(fctiw) | ||
248 | FPD_ONE_IN(fctiwz) | ||
249 | FPD_ONE_IN(fsqrt) | ||
250 | FPD_ONE_IN(fre) | ||
251 | FPD_ONE_IN(frsqrte) | ||
252 | FPD_ONE_IN(fneg) | ||
253 | FPD_ONE_IN(fabs) | ||
254 | FPD_TWO_IN(fadds) | ||
255 | FPD_TWO_IN(fsubs) | ||
256 | FPD_TWO_IN(fdivs) | ||
257 | FPD_TWO_IN(fmuls) | ||
258 | FPD_TWO_IN_CR(fcmpu) | ||
259 | FPD_TWO_IN(fcpsgn) | ||
260 | FPD_TWO_IN(fdiv) | ||
261 | FPD_TWO_IN(fadd) | ||
262 | FPD_TWO_IN(fmul) | ||
263 | FPD_TWO_IN_CR(fcmpo) | ||
264 | FPD_TWO_IN(fsub) | ||
265 | FPD_THREE_IN(fmsubs) | ||
266 | FPD_THREE_IN(fmadds) | ||
267 | FPD_THREE_IN(fnmsubs) | ||
268 | FPD_THREE_IN(fnmadds) | ||
269 | FPD_THREE_IN(fsel) | ||
270 | FPD_THREE_IN(fmsub) | ||
271 | FPD_THREE_IN(fmadd) | ||
272 | FPD_THREE_IN(fnmsub) | ||
273 | FPD_THREE_IN(fnmadd) | ||