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 "sfp-machine.h"
14 #define FLOATFUNC(x) extern int x(void *, void *, void *, void *)
68 #define OP31 0x1f /* 31 */
69 #define LFS 0x30 /* 48 */
70 #define LFSU 0x31 /* 49 */
71 #define LFD 0x32 /* 50 */
72 #define LFDU 0x33 /* 51 */
73 #define STFS 0x34 /* 52 */
74 #define STFSU 0x35 /* 53 */
75 #define STFD 0x36 /* 54 */
76 #define STFDU 0x37 /* 55 */
77 #define OP59 0x3b /* 59 */
78 #define OP63 0x3f /* 63 */
82 #define LFSX 0x217 /* 535 */
83 #define LFSUX 0x237 /* 567 */
84 #define LFDX 0x257 /* 599 */
85 #define LFDUX 0x277 /* 631 */
86 #define STFSX 0x297 /* 663 */
87 #define STFSUX 0x2b7 /* 695 */
88 #define STFDX 0x2d7 /* 727 */
89 #define STFDUX 0x2f7 /* 759 */
90 #define STFIWX 0x3d7 /* 983 */
94 #define FDIVS 0x012 /* 18 */
95 #define FSUBS 0x014 /* 20 */
96 #define FADDS 0x015 /* 21 */
97 #define FSQRTS 0x016 /* 22 */
98 #define FRES 0x018 /* 24 */
99 #define FMULS 0x019 /* 25 */
100 #define FMSUBS 0x01c /* 28 */
101 #define FMADDS 0x01d /* 29 */
102 #define FNMSUBS 0x01e /* 30 */
103 #define FNMADDS 0x01f /* 31 */
107 #define FDIV 0x012 /* 18 */
108 #define FSUB 0x014 /* 20 */
109 #define FADD 0x015 /* 21 */
110 #define FSQRT 0x016 /* 22 */
111 #define FSEL 0x017 /* 23 */
112 #define FMUL 0x019 /* 25 */
113 #define FRSQRTE 0x01a /* 26 */
114 #define FMSUB 0x01c /* 28 */
115 #define FMADD 0x01d /* 29 */
116 #define FNMSUB 0x01e /* 30 */
117 #define FNMADD 0x01f /* 31 */
120 #define FCMPU 0x000 /* 0 */
121 #define FRSP 0x00c /* 12 */
122 #define FCTIW 0x00e /* 14 */
123 #define FCTIWZ 0x00f /* 15 */
124 #define FCMPO 0x020 /* 32 */
125 #define MTFSB1 0x026 /* 38 */
126 #define FNEG 0x028 /* 40 */
127 #define MCRFS 0x040 /* 64 */
128 #define MTFSB0 0x046 /* 70 */
129 #define FMR 0x048 /* 72 */
130 #define MTFSFI 0x086 /* 134 */
131 #define FNABS 0x088 /* 136 */
132 #define FABS 0x108 /* 264 */
133 #define MFFS 0x247 /* 583 */
134 #define MTFSF 0x2c7 /* 711 */
153 #ifdef CONFIG_MATH_EMULATION
155 record_exception(struct pt_regs
*regs
, int eflag
)
163 if (eflag
& EFLAG_OVERFLOW
)
165 if (eflag
& EFLAG_UNDERFLOW
)
167 if (eflag
& EFLAG_DIVZERO
)
169 if (eflag
& EFLAG_INEXACT
)
171 if (eflag
& EFLAG_VXSNAN
)
172 fpscr
|= FPSCR_VXSNAN
;
173 if (eflag
& EFLAG_VXISI
)
174 fpscr
|= FPSCR_VXISI
;
175 if (eflag
& EFLAG_VXIDI
)
176 fpscr
|= FPSCR_VXIDI
;
177 if (eflag
& EFLAG_VXZDZ
)
178 fpscr
|= FPSCR_VXZDZ
;
179 if (eflag
& EFLAG_VXIMZ
)
180 fpscr
|= FPSCR_VXIMZ
;
181 if (eflag
& EFLAG_VXVC
)
183 if (eflag
& EFLAG_VXSOFT
)
184 fpscr
|= FPSCR_VXSOFT
;
185 if (eflag
& EFLAG_VXSQRT
)
186 fpscr
|= FPSCR_VXSQRT
;
187 if (eflag
& EFLAG_VXCVI
)
188 fpscr
|= FPSCR_VXCVI
;
191 fpscr
&= ~(FPSCR_VX
);
192 if (fpscr
& (FPSCR_VXSNAN
| FPSCR_VXISI
| FPSCR_VXIDI
|
193 FPSCR_VXZDZ
| FPSCR_VXIMZ
| FPSCR_VXVC
|
194 FPSCR_VXSOFT
| FPSCR_VXSQRT
| FPSCR_VXCVI
))
197 fpscr
&= ~(FPSCR_FEX
);
198 if (((fpscr
& FPSCR_VX
) && (fpscr
& FPSCR_VE
)) ||
199 ((fpscr
& FPSCR_OX
) && (fpscr
& FPSCR_OE
)) ||
200 ((fpscr
& FPSCR_UX
) && (fpscr
& FPSCR_UE
)) ||
201 ((fpscr
& FPSCR_ZX
) && (fpscr
& FPSCR_ZE
)) ||
202 ((fpscr
& FPSCR_XX
) && (fpscr
& FPSCR_XE
)))
207 return (fpscr
& FPSCR_FEX
) ? 1 : 0;
209 #endif /* CONFIG_MATH_EMULATION */
212 do_mathemu(struct pt_regs
*regs
)
214 void *op0
= 0, *op1
= 0, *op2
= 0, *op3
= 0;
215 unsigned long pc
= regs
->nip
;
219 #ifdef CONFIG_MATH_EMULATION
220 int (*func
)(void *, void *, void *, void *);
225 if (get_user(insn
, (u32
*)pc
))
228 #ifndef CONFIG_MATH_EMULATION
229 switch (insn
>> 26) {
231 idx
= (insn
>> 16) & 0x1f;
232 sdisp
= (insn
& 0xffff);
233 op0
= (void *)¤t
->thread
.fpr
[(insn
>> 21) & 0x1f];
234 op1
= (void *)((idx
? regs
->gpr
[idx
] : 0) + sdisp
);
235 lfd(op0
, op1
, op2
, op3
);
238 idx
= (insn
>> 16) & 0x1f;
239 sdisp
= (insn
& 0xffff);
240 op0
= (void *)¤t
->thread
.fpr
[(insn
>> 21) & 0x1f];
241 op1
= (void *)((idx
? regs
->gpr
[idx
] : 0) + sdisp
);
242 lfd(op0
, op1
, op2
, op3
);
243 regs
->gpr
[idx
] = (unsigned long)op1
;
246 idx
= (insn
>> 16) & 0x1f;
247 sdisp
= (insn
& 0xffff);
248 op0
= (void *)¤t
->thread
.fpr
[(insn
>> 21) & 0x1f];
249 op1
= (void *)((idx
? regs
->gpr
[idx
] : 0) + sdisp
);
250 stfd(op0
, op1
, op2
, op3
);
253 idx
= (insn
>> 16) & 0x1f;
254 sdisp
= (insn
& 0xffff);
255 op0
= (void *)¤t
->thread
.fpr
[(insn
>> 21) & 0x1f];
256 op1
= (void *)((idx
? regs
->gpr
[idx
] : 0) + sdisp
);
257 stfd(op0
, op1
, op2
, op3
);
258 regs
->gpr
[idx
] = (unsigned long)op1
;
261 op0
= (void *)¤t
->thread
.fpr
[(insn
>> 21) & 0x1f];
262 op1
= (void *)¤t
->thread
.fpr
[(insn
>> 11) & 0x1f];
263 fmr(op0
, op1
, op2
, op3
);
268 #else /* CONFIG_MATH_EMULATION */
269 switch (insn
>> 26) {
270 case LFS
: func
= lfs
; type
= D
; break;
271 case LFSU
: func
= lfs
; type
= DU
; break;
272 case LFD
: func
= lfd
; type
= D
; break;
273 case LFDU
: func
= lfd
; type
= DU
; break;
274 case STFS
: func
= stfs
; type
= D
; break;
275 case STFSU
: func
= stfs
; type
= DU
; break;
276 case STFD
: func
= stfd
; type
= D
; break;
277 case STFDU
: func
= stfd
; type
= DU
; break;
280 switch ((insn
>> 1) & 0x3ff) {
281 case LFSX
: func
= lfs
; type
= XE
; break;
282 case LFSUX
: func
= lfs
; type
= XEU
; break;
283 case LFDX
: func
= lfd
; type
= XE
; break;
284 case LFDUX
: func
= lfd
; type
= XEU
; break;
285 case STFSX
: func
= stfs
; type
= XE
; break;
286 case STFSUX
: func
= stfs
; type
= XEU
; break;
287 case STFDX
: func
= stfd
; type
= XE
; break;
288 case STFDUX
: func
= stfd
; type
= XEU
; break;
289 case STFIWX
: func
= stfiwx
; type
= XE
; break;
296 switch ((insn
>> 1) & 0x1f) {
297 case FDIVS
: func
= fdivs
; type
= AB
; break;
298 case FSUBS
: func
= fsubs
; type
= AB
; break;
299 case FADDS
: func
= fadds
; type
= AB
; break;
300 case FSQRTS
: func
= fsqrts
; type
= AB
; break;
301 case FRES
: func
= fres
; type
= AB
; break;
302 case FMULS
: func
= fmuls
; type
= AC
; break;
303 case FMSUBS
: func
= fmsubs
; type
= ABC
; break;
304 case FMADDS
: func
= fmadds
; type
= ABC
; break;
305 case FNMSUBS
: func
= fnmsubs
; type
= ABC
; break;
306 case FNMADDS
: func
= fnmadds
; type
= ABC
; break;
314 switch ((insn
>> 1) & 0x1f) {
315 case FDIV
: func
= fdiv
; type
= AB
; break;
316 case FSUB
: func
= fsub
; type
= AB
; break;
317 case FADD
: func
= fadd
; type
= AB
; break;
318 case FSQRT
: func
= fsqrt
; type
= AB
; break;
319 case FSEL
: func
= fsel
; type
= ABC
; break;
320 case FMUL
: func
= fmul
; type
= AC
; break;
321 case FRSQRTE
: func
= frsqrte
; type
= AB
; break;
322 case FMSUB
: func
= fmsub
; type
= ABC
; break;
323 case FMADD
: func
= fmadd
; type
= ABC
; break;
324 case FNMSUB
: func
= fnmsub
; type
= ABC
; break;
325 case FNMADD
: func
= fnmadd
; type
= ABC
; break;
332 switch ((insn
>> 1) & 0x3ff) {
333 case FCMPU
: func
= fcmpu
; type
= XCR
; break;
334 case FRSP
: func
= frsp
; type
= XB
; break;
335 case FCTIW
: func
= fctiw
; type
= XB
; break;
336 case FCTIWZ
: func
= fctiwz
; type
= XB
; break;
337 case FCMPO
: func
= fcmpo
; type
= XCR
; break;
338 case MTFSB1
: func
= mtfsb1
; type
= XCRB
; break;
339 case FNEG
: func
= fneg
; type
= XB
; break;
340 case MCRFS
: func
= mcrfs
; type
= XCRL
; break;
341 case MTFSB0
: func
= mtfsb0
; type
= XCRB
; break;
342 case FMR
: func
= fmr
; type
= XB
; break;
343 case MTFSFI
: func
= mtfsfi
; type
= XCRI
; break;
344 case FNABS
: func
= fnabs
; type
= XB
; break;
345 case FABS
: func
= fabs
; type
= XB
; break;
346 case MFFS
: func
= mffs
; type
= X
; break;
347 case MTFSF
: func
= mtfsf
; type
= XFLB
; break;
359 op0
= (void *)¤t
->thread
.fpr
[(insn
>> 21) & 0x1f];
360 op1
= (void *)¤t
->thread
.fpr
[(insn
>> 16) & 0x1f];
361 op2
= (void *)¤t
->thread
.fpr
[(insn
>> 11) & 0x1f];
365 op0
= (void *)¤t
->thread
.fpr
[(insn
>> 21) & 0x1f];
366 op1
= (void *)¤t
->thread
.fpr
[(insn
>> 16) & 0x1f];
367 op2
= (void *)¤t
->thread
.fpr
[(insn
>> 6) & 0x1f];
371 op0
= (void *)¤t
->thread
.fpr
[(insn
>> 21) & 0x1f];
372 op1
= (void *)¤t
->thread
.fpr
[(insn
>> 16) & 0x1f];
373 op2
= (void *)¤t
->thread
.fpr
[(insn
>> 11) & 0x1f];
374 op3
= (void *)¤t
->thread
.fpr
[(insn
>> 6) & 0x1f];
378 idx
= (insn
>> 16) & 0x1f;
379 sdisp
= (insn
& 0xffff);
380 op0
= (void *)¤t
->thread
.fpr
[(insn
>> 21) & 0x1f];
381 op1
= (void *)((idx
? regs
->gpr
[idx
] : 0) + sdisp
);
385 idx
= (insn
>> 16) & 0x1f;
389 sdisp
= (insn
& 0xffff);
390 op0
= (void *)¤t
->thread
.fpr
[(insn
>> 21) & 0x1f];
391 op1
= (void *)(regs
->gpr
[idx
] + sdisp
);
395 op0
= (void *)¤t
->thread
.fpr
[(insn
>> 21) & 0x1f];
399 op0
= (void *)¤t
->thread
.fpr
[(insn
>> 21) & 0x1f];
400 op1
= (void *)¤t
->thread
.fpr
[(insn
>> 16) & 0x1f];
404 op0
= (void *)¤t
->thread
.fpr
[(insn
>> 21) & 0x1f];
405 op1
= (void *)¤t
->thread
.fpr
[(insn
>> 11) & 0x1f];
409 idx
= (insn
>> 16) & 0x1f;
410 op0
= (void *)¤t
->thread
.fpr
[(insn
>> 21) & 0x1f];
412 if (((insn
>> 1) & 0x3ff) == STFIWX
)
413 op1
= (void *)(regs
->gpr
[(insn
>> 11) & 0x1f]);
417 op1
= (void *)(regs
->gpr
[idx
] + regs
->gpr
[(insn
>> 11) & 0x1f]);
423 idx
= (insn
>> 16) & 0x1f;
424 op0
= (void *)¤t
->thread
.fpr
[(insn
>> 21) & 0x1f];
425 op1
= (void *)((idx
? regs
->gpr
[idx
] : 0)
426 + regs
->gpr
[(insn
>> 11) & 0x1f]);
430 op0
= (void *)®s
->ccr
;
431 op1
= (void *)((insn
>> 23) & 0x7);
432 op2
= (void *)¤t
->thread
.fpr
[(insn
>> 16) & 0x1f];
433 op3
= (void *)¤t
->thread
.fpr
[(insn
>> 11) & 0x1f];
437 op0
= (void *)®s
->ccr
;
438 op1
= (void *)((insn
>> 23) & 0x7);
439 op2
= (void *)((insn
>> 18) & 0x7);
443 op0
= (void *)((insn
>> 21) & 0x1f);
447 op0
= (void *)((insn
>> 23) & 0x7);
448 op1
= (void *)((insn
>> 12) & 0xf);
452 op0
= (void *)((insn
>> 17) & 0xff);
453 op1
= (void *)¤t
->thread
.fpr
[(insn
>> 11) & 0x1f];
460 eflag
= func(op0
, op1
, op2
, op3
);
463 regs
->ccr
&= ~(0x0f000000);
464 regs
->ccr
|= (__FPU_FPSCR
>> 4) & 0x0f000000;
467 trap
= record_exception(regs
, eflag
);
474 regs
->gpr
[idx
] = (unsigned long)op1
;
480 #endif /* CONFIG_MATH_EMULATION */