xref: /linux/arch/powerpc/kvm/fpu.S (revision 2874c5fd284268364ece81a7bd936f3c8168e567)
1*2874c5fdSThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-or-later */
2963cf3dcSAlexander Graf/*
3963cf3dcSAlexander Graf *  FPU helper code to use FPU operations from inside the kernel
4963cf3dcSAlexander Graf *
5963cf3dcSAlexander Graf *    Copyright (C) 2010 Alexander Graf (agraf@suse.de)
6963cf3dcSAlexander Graf */
7963cf3dcSAlexander Graf
8963cf3dcSAlexander Graf#include <asm/reg.h>
9963cf3dcSAlexander Graf#include <asm/page.h>
10963cf3dcSAlexander Graf#include <asm/mmu.h>
11963cf3dcSAlexander Graf#include <asm/pgtable.h>
12963cf3dcSAlexander Graf#include <asm/cputable.h>
13963cf3dcSAlexander Graf#include <asm/cache.h>
14963cf3dcSAlexander Graf#include <asm/thread_info.h>
15963cf3dcSAlexander Graf#include <asm/ppc_asm.h>
16963cf3dcSAlexander Graf#include <asm/asm-offsets.h>
17963cf3dcSAlexander Graf
18963cf3dcSAlexander Graf/* Instructions operating on single parameters */
19963cf3dcSAlexander Graf
20963cf3dcSAlexander Graf/*
21963cf3dcSAlexander Graf * Single operation with one input operand
22963cf3dcSAlexander Graf *
23963cf3dcSAlexander Graf * R3 = (double*)&fpscr
24963cf3dcSAlexander Graf * R4 = (short*)&result
25963cf3dcSAlexander Graf * R5 = (short*)&param1
26963cf3dcSAlexander Graf */
27963cf3dcSAlexander Graf#define FPS_ONE_IN(name) 					\
28963cf3dcSAlexander Graf_GLOBAL(fps_ ## name);							\
29963cf3dcSAlexander Graf	lfd	0,0(r3);		/* load up fpscr value */	\
30963cf3dcSAlexander Graf	MTFSF_L(0);							\
31963cf3dcSAlexander Graf	lfs	0,0(r5);						\
32963cf3dcSAlexander Graf									\
33963cf3dcSAlexander Graf	name	0,0;							\
34963cf3dcSAlexander Graf									\
35963cf3dcSAlexander Graf	stfs	0,0(r4);						\
36963cf3dcSAlexander Graf	mffs	0;							\
37963cf3dcSAlexander Graf	stfd	0,0(r3);	/* save new fpscr value */	\
38963cf3dcSAlexander Graf	blr
39963cf3dcSAlexander Graf
40963cf3dcSAlexander Graf/*
41963cf3dcSAlexander Graf * Single operation with two input operands
42963cf3dcSAlexander Graf *
43963cf3dcSAlexander Graf * R3 = (double*)&fpscr
44963cf3dcSAlexander Graf * R4 = (short*)&result
45963cf3dcSAlexander Graf * R5 = (short*)&param1
46963cf3dcSAlexander Graf * R6 = (short*)&param2
47963cf3dcSAlexander Graf */
48963cf3dcSAlexander Graf#define FPS_TWO_IN(name) 					\
49963cf3dcSAlexander Graf_GLOBAL(fps_ ## name);							\
50963cf3dcSAlexander Graf	lfd	0,0(r3);		/* load up fpscr value */	\
51963cf3dcSAlexander Graf	MTFSF_L(0);							\
52963cf3dcSAlexander Graf	lfs	0,0(r5);						\
53963cf3dcSAlexander Graf	lfs	1,0(r6);						\
54963cf3dcSAlexander Graf									\
55963cf3dcSAlexander Graf	name	0,0,1;							\
56963cf3dcSAlexander Graf									\
57963cf3dcSAlexander Graf	stfs	0,0(r4);						\
58963cf3dcSAlexander Graf	mffs	0;							\
59963cf3dcSAlexander Graf	stfd	0,0(r3);		/* save new fpscr value */	\
60963cf3dcSAlexander Graf	blr
61963cf3dcSAlexander Graf
62963cf3dcSAlexander Graf/*
63963cf3dcSAlexander Graf * Single operation with three input operands
64963cf3dcSAlexander Graf *
65963cf3dcSAlexander Graf * R3 = (double*)&fpscr
66963cf3dcSAlexander Graf * R4 = (short*)&result
67963cf3dcSAlexander Graf * R5 = (short*)&param1
68963cf3dcSAlexander Graf * R6 = (short*)&param2
69963cf3dcSAlexander Graf * R7 = (short*)&param3
70963cf3dcSAlexander Graf */
71963cf3dcSAlexander Graf#define FPS_THREE_IN(name) 					\
72963cf3dcSAlexander Graf_GLOBAL(fps_ ## name);							\
73963cf3dcSAlexander Graf	lfd	0,0(r3);		/* load up fpscr value */	\
74963cf3dcSAlexander Graf	MTFSF_L(0);							\
75963cf3dcSAlexander Graf	lfs	0,0(r5);						\
76963cf3dcSAlexander Graf	lfs	1,0(r6);						\
77963cf3dcSAlexander Graf	lfs	2,0(r7);						\
78963cf3dcSAlexander Graf									\
79963cf3dcSAlexander Graf	name	0,0,1,2;						\
80963cf3dcSAlexander Graf									\
81963cf3dcSAlexander Graf	stfs	0,0(r4);						\
82963cf3dcSAlexander Graf	mffs	0;							\
83963cf3dcSAlexander Graf	stfd	0,0(r3);		/* save new fpscr value */	\
84963cf3dcSAlexander Graf	blr
85963cf3dcSAlexander Graf
86963cf3dcSAlexander GrafFPS_ONE_IN(fres)
87963cf3dcSAlexander GrafFPS_ONE_IN(frsqrte)
88963cf3dcSAlexander GrafFPS_ONE_IN(fsqrts)
89963cf3dcSAlexander GrafFPS_TWO_IN(fadds)
90963cf3dcSAlexander GrafFPS_TWO_IN(fdivs)
91963cf3dcSAlexander GrafFPS_TWO_IN(fmuls)
92963cf3dcSAlexander GrafFPS_TWO_IN(fsubs)
93963cf3dcSAlexander GrafFPS_THREE_IN(fmadds)
94963cf3dcSAlexander GrafFPS_THREE_IN(fmsubs)
95963cf3dcSAlexander GrafFPS_THREE_IN(fnmadds)
96963cf3dcSAlexander GrafFPS_THREE_IN(fnmsubs)
97963cf3dcSAlexander GrafFPS_THREE_IN(fsel)
98963cf3dcSAlexander Graf
99963cf3dcSAlexander Graf
100963cf3dcSAlexander Graf/* Instructions operating on double parameters */
101963cf3dcSAlexander Graf
102963cf3dcSAlexander Graf/*
103963cf3dcSAlexander Graf * Beginning of double instruction processing
104963cf3dcSAlexander Graf *
105963cf3dcSAlexander Graf * R3 = (double*)&fpscr
106963cf3dcSAlexander Graf * R4 = (u32*)&cr
107963cf3dcSAlexander Graf * R5 = (double*)&result
108963cf3dcSAlexander Graf * R6 = (double*)&param1
109963cf3dcSAlexander Graf * R7 = (double*)&param2 [load_two]
110963cf3dcSAlexander Graf * R8 = (double*)&param3 [load_three]
111963cf3dcSAlexander Graf * LR = instruction call function
112963cf3dcSAlexander Graf */
113963cf3dcSAlexander Graffpd_load_three:
114963cf3dcSAlexander Graf	lfd	2,0(r8)			/* load param3 */
115963cf3dcSAlexander Graffpd_load_two:
116963cf3dcSAlexander Graf	lfd	1,0(r7)			/* load param2 */
117963cf3dcSAlexander Graffpd_load_one:
118963cf3dcSAlexander Graf	lfd	0,0(r6)			/* load param1 */
119963cf3dcSAlexander Graffpd_load_none:
120963cf3dcSAlexander Graf	lfd	3,0(r3)			/* load up fpscr value */
121963cf3dcSAlexander Graf	MTFSF_L(3)
122963cf3dcSAlexander Graf	lwz	r6, 0(r4)		/* load cr */
123963cf3dcSAlexander Graf	mtcr	r6
124963cf3dcSAlexander Graf	blr
125963cf3dcSAlexander Graf
126963cf3dcSAlexander Graf/*
127963cf3dcSAlexander Graf * End of double instruction processing
128963cf3dcSAlexander Graf *
129963cf3dcSAlexander Graf * R3 = (double*)&fpscr
130963cf3dcSAlexander Graf * R4 = (u32*)&cr
131963cf3dcSAlexander Graf * R5 = (double*)&result
132963cf3dcSAlexander Graf * LR = caller of instruction call function
133963cf3dcSAlexander Graf */
134963cf3dcSAlexander Graffpd_return:
135963cf3dcSAlexander Graf	mfcr	r6
136963cf3dcSAlexander Graf	stfd	0,0(r5)			/* save result */
137963cf3dcSAlexander Graf	mffs	0
138963cf3dcSAlexander Graf	stfd	0,0(r3)			/* save new fpscr value */
139963cf3dcSAlexander Graf	stw	r6,0(r4)		/* save new cr value */
140963cf3dcSAlexander Graf	blr
141963cf3dcSAlexander Graf
142963cf3dcSAlexander Graf/*
143963cf3dcSAlexander Graf * Double operation with no input operand
144963cf3dcSAlexander Graf *
145963cf3dcSAlexander Graf * R3 = (double*)&fpscr
146963cf3dcSAlexander Graf * R4 = (u32*)&cr
147963cf3dcSAlexander Graf * R5 = (double*)&result
148963cf3dcSAlexander Graf */
149963cf3dcSAlexander Graf#define FPD_NONE_IN(name) 						\
150963cf3dcSAlexander Graf_GLOBAL(fpd_ ## name);							\
151963cf3dcSAlexander Graf	mflr	r12;							\
152963cf3dcSAlexander Graf	bl	fpd_load_none;						\
153963cf3dcSAlexander Graf	mtlr	r12;							\
154963cf3dcSAlexander Graf									\
155963cf3dcSAlexander Graf	name.	0;			/* call instruction */		\
156963cf3dcSAlexander Graf	b	fpd_return
157963cf3dcSAlexander Graf
158963cf3dcSAlexander Graf/*
159963cf3dcSAlexander Graf * Double operation with one input operand
160963cf3dcSAlexander Graf *
161963cf3dcSAlexander Graf * R3 = (double*)&fpscr
162963cf3dcSAlexander Graf * R4 = (u32*)&cr
163963cf3dcSAlexander Graf * R5 = (double*)&result
164963cf3dcSAlexander Graf * R6 = (double*)&param1
165963cf3dcSAlexander Graf */
166963cf3dcSAlexander Graf#define FPD_ONE_IN(name) 						\
167963cf3dcSAlexander Graf_GLOBAL(fpd_ ## name);							\
168963cf3dcSAlexander Graf	mflr	r12;							\
169963cf3dcSAlexander Graf	bl	fpd_load_one;						\
170963cf3dcSAlexander Graf	mtlr	r12;							\
171963cf3dcSAlexander Graf									\
172963cf3dcSAlexander Graf	name.	0,0;			/* call instruction */		\
173963cf3dcSAlexander Graf	b	fpd_return
174963cf3dcSAlexander Graf
175963cf3dcSAlexander Graf/*
176963cf3dcSAlexander Graf * Double operation with two input operands
177963cf3dcSAlexander Graf *
178963cf3dcSAlexander Graf * R3 = (double*)&fpscr
179963cf3dcSAlexander Graf * R4 = (u32*)&cr
180963cf3dcSAlexander Graf * R5 = (double*)&result
181963cf3dcSAlexander Graf * R6 = (double*)&param1
182963cf3dcSAlexander Graf * R7 = (double*)&param2
183963cf3dcSAlexander Graf * R8 = (double*)&param3
184963cf3dcSAlexander Graf */
185963cf3dcSAlexander Graf#define FPD_TWO_IN(name) 						\
186963cf3dcSAlexander Graf_GLOBAL(fpd_ ## name);							\
187963cf3dcSAlexander Graf	mflr	r12;							\
188963cf3dcSAlexander Graf	bl	fpd_load_two;						\
189963cf3dcSAlexander Graf	mtlr	r12;							\
190963cf3dcSAlexander Graf									\
191963cf3dcSAlexander Graf	name.	0,0,1;			/* call instruction */		\
192963cf3dcSAlexander Graf	b	fpd_return
193963cf3dcSAlexander Graf
194963cf3dcSAlexander Graf/*
195963cf3dcSAlexander Graf * CR Double operation with two input operands
196963cf3dcSAlexander Graf *
197963cf3dcSAlexander Graf * R3 = (double*)&fpscr
198963cf3dcSAlexander Graf * R4 = (u32*)&cr
199963cf3dcSAlexander Graf * R5 = (double*)&param1
200963cf3dcSAlexander Graf * R6 = (double*)&param2
201963cf3dcSAlexander Graf * R7 = (double*)&param3
202963cf3dcSAlexander Graf */
203963cf3dcSAlexander Graf#define FPD_TWO_IN_CR(name)						\
204963cf3dcSAlexander Graf_GLOBAL(fpd_ ## name);							\
205963cf3dcSAlexander Graf	lfd	1,0(r6);		/* load param2 */		\
206963cf3dcSAlexander Graf	lfd	0,0(r5);		/* load param1 */		\
207963cf3dcSAlexander Graf	lfd	3,0(r3);		/* load up fpscr value */	\
208963cf3dcSAlexander Graf	MTFSF_L(3);							\
209963cf3dcSAlexander Graf	lwz	r6, 0(r4);		/* load cr */			\
210963cf3dcSAlexander Graf	mtcr	r6;							\
211963cf3dcSAlexander Graf									\
212963cf3dcSAlexander Graf	name	0,0,1;			/* call instruction */		\
213963cf3dcSAlexander Graf	mfcr	r6;							\
214963cf3dcSAlexander Graf	mffs	0;							\
215963cf3dcSAlexander Graf	stfd	0,0(r3);		/* save new fpscr value */	\
216963cf3dcSAlexander Graf	stw	r6,0(r4);		/* save new cr value */		\
217963cf3dcSAlexander Graf	blr
218963cf3dcSAlexander Graf
219963cf3dcSAlexander Graf/*
220963cf3dcSAlexander Graf * Double operation with three input operands
221963cf3dcSAlexander Graf *
222963cf3dcSAlexander Graf * R3 = (double*)&fpscr
223963cf3dcSAlexander Graf * R4 = (u32*)&cr
224963cf3dcSAlexander Graf * R5 = (double*)&result
225963cf3dcSAlexander Graf * R6 = (double*)&param1
226963cf3dcSAlexander Graf * R7 = (double*)&param2
227963cf3dcSAlexander Graf * R8 = (double*)&param3
228963cf3dcSAlexander Graf */
229963cf3dcSAlexander Graf#define FPD_THREE_IN(name) 						\
230963cf3dcSAlexander Graf_GLOBAL(fpd_ ## name);							\
231963cf3dcSAlexander Graf	mflr	r12;							\
232963cf3dcSAlexander Graf	bl	fpd_load_three;						\
233963cf3dcSAlexander Graf	mtlr	r12;							\
234963cf3dcSAlexander Graf									\
235963cf3dcSAlexander Graf	name.	0,0,1,2;		/* call instruction */		\
236963cf3dcSAlexander Graf	b	fpd_return
237963cf3dcSAlexander Graf
238963cf3dcSAlexander GrafFPD_ONE_IN(fsqrts)
239963cf3dcSAlexander GrafFPD_ONE_IN(frsqrtes)
240963cf3dcSAlexander GrafFPD_ONE_IN(fres)
241963cf3dcSAlexander GrafFPD_ONE_IN(frsp)
242963cf3dcSAlexander GrafFPD_ONE_IN(fctiw)
243963cf3dcSAlexander GrafFPD_ONE_IN(fctiwz)
244963cf3dcSAlexander GrafFPD_ONE_IN(fsqrt)
245963cf3dcSAlexander GrafFPD_ONE_IN(fre)
246963cf3dcSAlexander GrafFPD_ONE_IN(frsqrte)
247963cf3dcSAlexander GrafFPD_ONE_IN(fneg)
248963cf3dcSAlexander GrafFPD_ONE_IN(fabs)
249963cf3dcSAlexander GrafFPD_TWO_IN(fadds)
250963cf3dcSAlexander GrafFPD_TWO_IN(fsubs)
251963cf3dcSAlexander GrafFPD_TWO_IN(fdivs)
252963cf3dcSAlexander GrafFPD_TWO_IN(fmuls)
253963cf3dcSAlexander GrafFPD_TWO_IN_CR(fcmpu)
254963cf3dcSAlexander GrafFPD_TWO_IN(fcpsgn)
255963cf3dcSAlexander GrafFPD_TWO_IN(fdiv)
256963cf3dcSAlexander GrafFPD_TWO_IN(fadd)
257963cf3dcSAlexander GrafFPD_TWO_IN(fmul)
258963cf3dcSAlexander GrafFPD_TWO_IN_CR(fcmpo)
259963cf3dcSAlexander GrafFPD_TWO_IN(fsub)
260963cf3dcSAlexander GrafFPD_THREE_IN(fmsubs)
261963cf3dcSAlexander GrafFPD_THREE_IN(fmadds)
262963cf3dcSAlexander GrafFPD_THREE_IN(fnmsubs)
263963cf3dcSAlexander GrafFPD_THREE_IN(fnmadds)
264963cf3dcSAlexander GrafFPD_THREE_IN(fsel)
265963cf3dcSAlexander GrafFPD_THREE_IN(fmsub)
266963cf3dcSAlexander GrafFPD_THREE_IN(fmadd)
267963cf3dcSAlexander GrafFPD_THREE_IN(fnmsub)
268963cf3dcSAlexander GrafFPD_THREE_IN(fnmadd)
26949f6be8eSAndreas Schwab
27049f6be8eSAndreas Schwab_GLOBAL(kvm_cvt_fd)
27149f6be8eSAndreas Schwab	lfs	0,0(r3)
27249f6be8eSAndreas Schwab	stfd	0,0(r4)
27349f6be8eSAndreas Schwab	blr
27449f6be8eSAndreas Schwab
27549f6be8eSAndreas Schwab_GLOBAL(kvm_cvt_df)
27649f6be8eSAndreas Schwab	lfd	0,0(r3)
27749f6be8eSAndreas Schwab	stfs	0,0(r4)
27849f6be8eSAndreas Schwab	blr
279