2 * Copyright (C) 1999 Eddie C. Dost (ecd@atecom.com)
5 #include <linux/types.h>
6 #include <linux/sched.h>
8 #include <asm/uaccess.h>
11 #include <asm/sfp-machine.h>
12 #include <math-emu/double.h>
14 #define FLOATFUNC(x) extern int x(void *, void *, void *, void *)
16 /* The instructions list which may be not implemented by a hardware FPU */
24 #ifdef CONFIG_MATH_EMULATION_HW_UNIMPLEMENTED
26 #define FLOATFUNC(x) static inline int x(void *op1, void *op2, void *op3, \
78 #define OP31 0x1f /* 31 */
79 #define LFS 0x30 /* 48 */
80 #define LFSU 0x31 /* 49 */
81 #define LFD 0x32 /* 50 */
82 #define LFDU 0x33 /* 51 */
83 #define STFS 0x34 /* 52 */
84 #define STFSU 0x35 /* 53 */
85 #define STFD 0x36 /* 54 */
86 #define STFDU 0x37 /* 55 */
87 #define OP59 0x3b /* 59 */
88 #define OP63 0x3f /* 63 */
92 #define LFSX 0x217 /* 535 */
93 #define LFSUX 0x237 /* 567 */
94 #define LFDX 0x257 /* 599 */
95 #define LFDUX 0x277 /* 631 */
96 #define STFSX 0x297 /* 663 */
97 #define STFSUX 0x2b7 /* 695 */
98 #define STFDX 0x2d7 /* 727 */
99 #define STFDUX 0x2f7 /* 759 */
100 #define STFIWX 0x3d7 /* 983 */
104 #define FDIVS 0x012 /* 18 */
105 #define FSUBS 0x014 /* 20 */
106 #define FADDS 0x015 /* 21 */
107 #define FSQRTS 0x016 /* 22 */
108 #define FRES 0x018 /* 24 */
109 #define FMULS 0x019 /* 25 */
110 #define FRSQRTES 0x01a /* 26 */
111 #define FMSUBS 0x01c /* 28 */
112 #define FMADDS 0x01d /* 29 */
113 #define FNMSUBS 0x01e /* 30 */
114 #define FNMADDS 0x01f /* 31 */
118 #define FDIV 0x012 /* 18 */
119 #define FSUB 0x014 /* 20 */
120 #define FADD 0x015 /* 21 */
121 #define FSQRT 0x016 /* 22 */
122 #define FSEL 0x017 /* 23 */
123 #define FRE 0x018 /* 24 */
124 #define FMUL 0x019 /* 25 */
125 #define FRSQRTE 0x01a /* 26 */
126 #define FMSUB 0x01c /* 28 */
127 #define FMADD 0x01d /* 29 */
128 #define FNMSUB 0x01e /* 30 */
129 #define FNMADD 0x01f /* 31 */
132 #define FCMPU 0x000 /* 0 */
133 #define FRSP 0x00c /* 12 */
134 #define FCTIW 0x00e /* 14 */
135 #define FCTIWZ 0x00f /* 15 */
136 #define FCMPO 0x020 /* 32 */
137 #define MTFSB1 0x026 /* 38 */
138 #define FNEG 0x028 /* 40 */
139 #define MCRFS 0x040 /* 64 */
140 #define MTFSB0 0x046 /* 70 */
141 #define FMR 0x048 /* 72 */
142 #define MTFSFI 0x086 /* 134 */
143 #define FNABS 0x088 /* 136 */
144 #define FABS 0x108 /* 264 */
145 #define MFFS 0x247 /* 583 */
146 #define MTFSF 0x2c7 /* 711 */
166 record_exception(struct pt_regs
*regs
, int eflag
)
174 if (eflag
& EFLAG_OVERFLOW
)
176 if (eflag
& EFLAG_UNDERFLOW
)
178 if (eflag
& EFLAG_DIVZERO
)
180 if (eflag
& EFLAG_INEXACT
)
182 if (eflag
& EFLAG_INVALID
)
184 if (eflag
& EFLAG_VXSNAN
)
185 fpscr
|= FPSCR_VXSNAN
;
186 if (eflag
& EFLAG_VXISI
)
187 fpscr
|= FPSCR_VXISI
;
188 if (eflag
& EFLAG_VXIDI
)
189 fpscr
|= FPSCR_VXIDI
;
190 if (eflag
& EFLAG_VXZDZ
)
191 fpscr
|= FPSCR_VXZDZ
;
192 if (eflag
& EFLAG_VXIMZ
)
193 fpscr
|= FPSCR_VXIMZ
;
194 if (eflag
& EFLAG_VXVC
)
196 if (eflag
& EFLAG_VXSOFT
)
197 fpscr
|= FPSCR_VXSOFT
;
198 if (eflag
& EFLAG_VXSQRT
)
199 fpscr
|= FPSCR_VXSQRT
;
200 if (eflag
& EFLAG_VXCVI
)
201 fpscr
|= FPSCR_VXCVI
;
204 // fpscr &= ~(FPSCR_VX);
205 if (fpscr
& (FPSCR_VXSNAN
| FPSCR_VXISI
| FPSCR_VXIDI
|
206 FPSCR_VXZDZ
| FPSCR_VXIMZ
| FPSCR_VXVC
|
207 FPSCR_VXSOFT
| FPSCR_VXSQRT
| FPSCR_VXCVI
))
210 fpscr
&= ~(FPSCR_FEX
);
211 if (((fpscr
& FPSCR_VX
) && (fpscr
& FPSCR_VE
)) ||
212 ((fpscr
& FPSCR_OX
) && (fpscr
& FPSCR_OE
)) ||
213 ((fpscr
& FPSCR_UX
) && (fpscr
& FPSCR_UE
)) ||
214 ((fpscr
& FPSCR_ZX
) && (fpscr
& FPSCR_ZE
)) ||
215 ((fpscr
& FPSCR_XX
) && (fpscr
& FPSCR_XE
)))
220 return (fpscr
& FPSCR_FEX
) ? 1 : 0;
224 do_mathemu(struct pt_regs
*regs
)
226 void *op0
= 0, *op1
= 0, *op2
= 0, *op3
= 0;
227 unsigned long pc
= regs
->nip
;
231 int (*func
)(void *, void *, void *, void *);
235 if (get_user(insn
, (u32
*)pc
))
238 switch (insn
>> 26) {
239 case LFS
: func
= lfs
; type
= D
; break;
240 case LFSU
: func
= lfs
; type
= DU
; break;
241 case LFD
: func
= lfd
; type
= D
; break;
242 case LFDU
: func
= lfd
; type
= DU
; break;
243 case STFS
: func
= stfs
; type
= D
; break;
244 case STFSU
: func
= stfs
; type
= DU
; break;
245 case STFD
: func
= stfd
; type
= D
; break;
246 case STFDU
: func
= stfd
; type
= DU
; break;
249 switch ((insn
>> 1) & 0x3ff) {
250 case LFSX
: func
= lfs
; type
= XE
; break;
251 case LFSUX
: func
= lfs
; type
= XEU
; break;
252 case LFDX
: func
= lfd
; type
= XE
; break;
253 case LFDUX
: func
= lfd
; type
= XEU
; break;
254 case STFSX
: func
= stfs
; type
= XE
; break;
255 case STFSUX
: func
= stfs
; type
= XEU
; break;
256 case STFDX
: func
= stfd
; type
= XE
; break;
257 case STFDUX
: func
= stfd
; type
= XEU
; break;
258 case STFIWX
: func
= stfiwx
; type
= XE
; break;
265 switch ((insn
>> 1) & 0x1f) {
266 case FDIVS
: func
= fdivs
; type
= AB
; break;
267 case FSUBS
: func
= fsubs
; type
= AB
; break;
268 case FADDS
: func
= fadds
; type
= AB
; break;
269 case FSQRTS
: func
= fsqrts
; type
= XB
; break;
270 case FRES
: func
= fres
; type
= XB
; break;
271 case FMULS
: func
= fmuls
; type
= AC
; break;
272 case FRSQRTES
: func
= frsqrtes
;type
= XB
; break;
273 case FMSUBS
: func
= fmsubs
; type
= ABC
; break;
274 case FMADDS
: func
= fmadds
; type
= ABC
; break;
275 case FNMSUBS
: func
= fnmsubs
; type
= ABC
; break;
276 case FNMADDS
: func
= fnmadds
; type
= ABC
; break;
284 switch ((insn
>> 1) & 0x1f) {
285 case FDIV
: func
= fdiv
; type
= AB
; break;
286 case FSUB
: func
= fsub
; type
= AB
; break;
287 case FADD
: func
= fadd
; type
= AB
; break;
288 case FSQRT
: func
= fsqrt
; type
= XB
; break;
289 case FRE
: func
= fre
; type
= XB
; break;
290 case FSEL
: func
= fsel
; type
= ABC
; break;
291 case FMUL
: func
= fmul
; type
= AC
; break;
292 case FRSQRTE
: func
= frsqrte
; type
= XB
; break;
293 case FMSUB
: func
= fmsub
; type
= ABC
; break;
294 case FMADD
: func
= fmadd
; type
= ABC
; break;
295 case FNMSUB
: func
= fnmsub
; type
= ABC
; break;
296 case FNMADD
: func
= fnmadd
; type
= ABC
; break;
303 switch ((insn
>> 1) & 0x3ff) {
304 case FCMPU
: func
= fcmpu
; type
= XCR
; break;
305 case FRSP
: func
= frsp
; type
= XB
; break;
306 case FCTIW
: func
= fctiw
; type
= XB
; break;
307 case FCTIWZ
: func
= fctiwz
; type
= XB
; break;
308 case FCMPO
: func
= fcmpo
; type
= XCR
; break;
309 case MTFSB1
: func
= mtfsb1
; type
= XCRB
; break;
310 case FNEG
: func
= fneg
; type
= XB
; break;
311 case MCRFS
: func
= mcrfs
; type
= XCRL
; break;
312 case MTFSB0
: func
= mtfsb0
; type
= XCRB
; break;
313 case FMR
: func
= fmr
; type
= XB
; break;
314 case MTFSFI
: func
= mtfsfi
; type
= XCRI
; break;
315 case FNABS
: func
= fnabs
; type
= XB
; break;
316 case FABS
: func
= fabs
; type
= XB
; break;
317 case MFFS
: func
= mffs
; type
= X
; break;
318 case MTFSF
: func
= mtfsf
; type
= XFLB
; break;
330 op0
= (void *)¤t
->thread
.TS_FPR((insn
>> 21) & 0x1f);
331 op1
= (void *)¤t
->thread
.TS_FPR((insn
>> 16) & 0x1f);
332 op2
= (void *)¤t
->thread
.TS_FPR((insn
>> 11) & 0x1f);
336 op0
= (void *)¤t
->thread
.TS_FPR((insn
>> 21) & 0x1f);
337 op1
= (void *)¤t
->thread
.TS_FPR((insn
>> 16) & 0x1f);
338 op2
= (void *)¤t
->thread
.TS_FPR((insn
>> 6) & 0x1f);
342 op0
= (void *)¤t
->thread
.TS_FPR((insn
>> 21) & 0x1f);
343 op1
= (void *)¤t
->thread
.TS_FPR((insn
>> 16) & 0x1f);
344 op2
= (void *)¤t
->thread
.TS_FPR((insn
>> 11) & 0x1f);
345 op3
= (void *)¤t
->thread
.TS_FPR((insn
>> 6) & 0x1f);
349 idx
= (insn
>> 16) & 0x1f;
350 sdisp
= (insn
& 0xffff);
351 op0
= (void *)¤t
->thread
.TS_FPR((insn
>> 21) & 0x1f);
352 op1
= (void *)((idx
? regs
->gpr
[idx
] : 0) + sdisp
);
356 idx
= (insn
>> 16) & 0x1f;
360 sdisp
= (insn
& 0xffff);
361 op0
= (void *)¤t
->thread
.TS_FPR((insn
>> 21) & 0x1f);
362 op1
= (void *)(regs
->gpr
[idx
] + sdisp
);
366 op0
= (void *)¤t
->thread
.TS_FPR((insn
>> 21) & 0x1f);
370 op0
= (void *)¤t
->thread
.TS_FPR((insn
>> 21) & 0x1f);
371 op1
= (void *)¤t
->thread
.TS_FPR((insn
>> 16) & 0x1f);
375 op0
= (void *)¤t
->thread
.TS_FPR((insn
>> 21) & 0x1f);
376 op1
= (void *)¤t
->thread
.TS_FPR((insn
>> 11) & 0x1f);
380 idx
= (insn
>> 16) & 0x1f;
381 op0
= (void *)¤t
->thread
.TS_FPR((insn
>> 21) & 0x1f);
383 if (((insn
>> 1) & 0x3ff) == STFIWX
)
384 op1
= (void *)(regs
->gpr
[(insn
>> 11) & 0x1f]);
388 op1
= (void *)(regs
->gpr
[idx
] + regs
->gpr
[(insn
>> 11) & 0x1f]);
394 idx
= (insn
>> 16) & 0x1f;
395 op0
= (void *)¤t
->thread
.TS_FPR((insn
>> 21) & 0x1f);
396 op1
= (void *)((idx
? regs
->gpr
[idx
] : 0)
397 + regs
->gpr
[(insn
>> 11) & 0x1f]);
401 op0
= (void *)®s
->ccr
;
402 op1
= (void *)((insn
>> 23) & 0x7);
403 op2
= (void *)¤t
->thread
.TS_FPR((insn
>> 16) & 0x1f);
404 op3
= (void *)¤t
->thread
.TS_FPR((insn
>> 11) & 0x1f);
408 op0
= (void *)®s
->ccr
;
409 op1
= (void *)((insn
>> 23) & 0x7);
410 op2
= (void *)((insn
>> 18) & 0x7);
414 op0
= (void *)((insn
>> 21) & 0x1f);
418 op0
= (void *)((insn
>> 23) & 0x7);
419 op1
= (void *)((insn
>> 12) & 0xf);
423 op0
= (void *)((insn
>> 17) & 0xff);
424 op1
= (void *)¤t
->thread
.TS_FPR((insn
>> 11) & 0x1f);
432 * If we support a HW FPU, we need to ensure the FP state
433 * is flushed into the thread_struct before attempting
436 #ifdef CONFIG_PPC_FPU
437 flush_fp_to_thread(current
);
440 eflag
= func(op0
, op1
, op2
, op3
);
443 regs
->ccr
&= ~(0x0f000000);
444 regs
->ccr
|= (__FPU_FPSCR
>> 4) & 0x0f000000;
447 trap
= record_exception(regs
, eflag
);
454 regs
->gpr
[idx
] = (unsigned long)op1
;
This page took 0.045734 seconds and 5 git commands to generate.