13 #include <linux/sched.h>
14 #include <linux/signal.h>
17 #include <asm/processor.h>
19 #include <asm/traps.h>
26 #define FPSCR_RCHG 0x00000000
27 extern unsigned long long float64_div(
unsigned long long a,
28 unsigned long long b);
29 extern unsigned long int float32_div(
unsigned long int a,
unsigned long int b);
30 extern unsigned long long float64_mul(
unsigned long long a,
31 unsigned long long b);
32 extern unsigned long int float32_mul(
unsigned long int a,
unsigned long int b);
33 extern unsigned long long float64_add(
unsigned long long a,
34 unsigned long long b);
35 extern unsigned long int float32_add(
unsigned long int a,
unsigned long int b);
36 extern unsigned long long float64_sub(
unsigned long long a,
37 unsigned long long b);
38 extern unsigned long int float32_sub(
unsigned long int a,
unsigned long int b);
40 static unsigned int fpu_exception_flags;
50 asm volatile (
"sts.l fpul, @-%0\n\t"
51 "sts.l fpscr, @-%0\n\t"
54 "fmov.s fr15, @-%0\n\t"
55 "fmov.s fr14, @-%0\n\t"
56 "fmov.s fr13, @-%0\n\t"
57 "fmov.s fr12, @-%0\n\t"
58 "fmov.s fr11, @-%0\n\t"
59 "fmov.s fr10, @-%0\n\t"
60 "fmov.s fr9, @-%0\n\t"
61 "fmov.s fr8, @-%0\n\t"
62 "fmov.s fr7, @-%0\n\t"
63 "fmov.s fr6, @-%0\n\t"
64 "fmov.s fr5, @-%0\n\t"
65 "fmov.s fr4, @-%0\n\t"
66 "fmov.s fr3, @-%0\n\t"
67 "fmov.s fr2, @-%0\n\t"
68 "fmov.s fr1, @-%0\n\t"
69 "fmov.s fr0, @-%0\n\t"
71 "fmov.s fr15, @-%0\n\t"
72 "fmov.s fr14, @-%0\n\t"
73 "fmov.s fr13, @-%0\n\t"
74 "fmov.s fr12, @-%0\n\t"
75 "fmov.s fr11, @-%0\n\t"
76 "fmov.s fr10, @-%0\n\t"
77 "fmov.s fr9, @-%0\n\t"
78 "fmov.s fr8, @-%0\n\t"
79 "fmov.s fr7, @-%0\n\t"
80 "fmov.s fr6, @-%0\n\t"
81 "fmov.s fr5, @-%0\n\t"
82 "fmov.s fr4, @-%0\n\t"
83 "fmov.s fr3, @-%0\n\t"
84 "fmov.s fr2, @-%0\n\t"
85 "fmov.s fr1, @-%0\n\t"
86 "fmov.s fr0, @-%0\n\t"
87 "lds %3, fpscr\n\t":
"=r" (
dummy)
88 :
"0"((
char *)(&tsk->
thread.xstate->hardfpu.status)),
100 asm volatile (
"lds %2, fpscr\n\t"
101 "fmov.s @%0+, fr0\n\t"
102 "fmov.s @%0+, fr1\n\t"
103 "fmov.s @%0+, fr2\n\t"
104 "fmov.s @%0+, fr3\n\t"
105 "fmov.s @%0+, fr4\n\t"
106 "fmov.s @%0+, fr5\n\t"
107 "fmov.s @%0+, fr6\n\t"
108 "fmov.s @%0+, fr7\n\t"
109 "fmov.s @%0+, fr8\n\t"
110 "fmov.s @%0+, fr9\n\t"
111 "fmov.s @%0+, fr10\n\t"
112 "fmov.s @%0+, fr11\n\t"
113 "fmov.s @%0+, fr12\n\t"
114 "fmov.s @%0+, fr13\n\t"
115 "fmov.s @%0+, fr14\n\t"
116 "fmov.s @%0+, fr15\n\t"
118 "fmov.s @%0+, fr0\n\t"
119 "fmov.s @%0+, fr1\n\t"
120 "fmov.s @%0+, fr2\n\t"
121 "fmov.s @%0+, fr3\n\t"
122 "fmov.s @%0+, fr4\n\t"
123 "fmov.s @%0+, fr5\n\t"
124 "fmov.s @%0+, fr6\n\t"
125 "fmov.s @%0+, fr7\n\t"
126 "fmov.s @%0+, fr8\n\t"
127 "fmov.s @%0+, fr9\n\t"
128 "fmov.s @%0+, fr10\n\t"
129 "fmov.s @%0+, fr11\n\t"
130 "fmov.s @%0+, fr12\n\t"
131 "fmov.s @%0+, fr13\n\t"
132 "fmov.s @%0+, fr14\n\t"
133 "fmov.s @%0+, fr15\n\t"
135 "lds.l @%0+, fpscr\n\t"
136 "lds.l @%0+, fpul\n\t"
152 unsigned long du,
dl;
153 unsigned long x = fpu->fpul;
154 int exp = 1023 - 126;
156 if (x != 0 && (x & 0x7f800000) == 0) {
157 du = (x & 0x80000000);
158 while ((x & 0x00800000) == 0) {
163 du |= (exp << 20) | (x >> 3);
180 unsigned short insn = *(
unsigned short *)regs->
pc;
181 unsigned short finsn;
182 unsigned long nextpc;
190 if (nib[0] == 0
xb || (nib[0] == 0x4 && nib[2] == 0x0 && nib[3] == 0
xb))
191 regs->
pr = regs->
pc + 4;
193 if (nib[0] == 0xa || nib[0] == 0
xb) {
195 nextpc = regs->
pc + 4 + ((
short)((insn & 0xfff) << 4) >> 3);
196 finsn = *(
unsigned short *)(regs->
pc + 2);
197 }
else if (nib[0] == 0x8 && nib[1] == 0xd) {
200 nextpc = regs->
pc + 4 + ((
char)(insn & 0xff) << 1);
202 nextpc = regs->
pc + 4;
203 finsn = *(
unsigned short *)(regs->
pc + 2);
204 }
else if (nib[0] == 0x8 && nib[1] == 0xf) {
207 nextpc = regs->
pc + 4;
209 nextpc = regs->
pc + 4 + ((
char)(insn & 0xff) << 1);
210 finsn = *(
unsigned short *)(regs->
pc + 2);
211 }
else if (nib[0] == 0x4 && nib[3] == 0
xb &&
212 (nib[2] == 0x0 || nib[2] == 0x2)) {
214 nextpc = regs->
regs[nib[1]];
215 finsn = *(
unsigned short *)(regs->
pc + 2);
216 }
else if (nib[0] == 0x0 && nib[3] == 0x3 &&
217 (nib[2] == 0x0 || nib[2] == 0x2)) {
219 nextpc = regs->
pc + 4 + regs->
regs[nib[1]];
220 finsn = *(
unsigned short *)(regs->
pc + 2);
221 }
else if (insn == 0x000b) {
224 finsn = *(
unsigned short *)(regs->
pc + 2);
230 if ((finsn & 0xf1ff) == 0xf0ad) {
236 denormal_to_double(&tsk->
thread.xstate->hardfpu,
243 }
else if ((finsn & 0xf00f) == 0xf002) {
250 n = (finsn >> 8) & 0xf;
251 m = (finsn >> 4) & 0xf;
252 hx = tsk->
thread.xstate->hardfpu.fp_regs[
n];
253 hy = tsk->
thread.xstate->hardfpu.fp_regs[
m];
254 fpscr = tsk->
thread.xstate->hardfpu.fpscr;
258 && (prec && ((hx & 0x7fffffff) < 0x00100000
259 || (hy & 0x7fffffff) < 0x00100000))) {
263 llx = ((
long long)hx << 32)
264 | tsk->
thread.xstate->hardfpu.fp_regs[n + 1];
265 lly = ((
long long)hy << 32)
266 | tsk->
thread.xstate->hardfpu.fp_regs[m + 1];
268 tsk->
thread.xstate->hardfpu.fp_regs[
n] = llx >> 32;
269 tsk->
thread.xstate->hardfpu.fp_regs[n + 1] = llx & 0xffffffff;
270 }
else if ((fpscr & FPSCR_CAUSE_ERROR)
271 && (!prec && ((hx & 0x7fffffff) < 0x00800000
272 || (hy & 0x7fffffff) < 0x00800000))) {
275 tsk->
thread.xstate->hardfpu.fp_regs[
n] = hx;
281 }
else if ((finsn & 0xf00e) == 0xf000) {
288 n = (finsn >> 8) & 0xf;
289 m = (finsn >> 4) & 0xf;
290 hx = tsk->
thread.xstate->hardfpu.fp_regs[
n];
291 hy = tsk->
thread.xstate->hardfpu.fp_regs[
m];
292 fpscr = tsk->
thread.xstate->hardfpu.fpscr;
295 if ((fpscr & FPSCR_CAUSE_ERROR)
296 && (prec && ((hx & 0x7fffffff) < 0x00100000
297 || (hy & 0x7fffffff) < 0x00100000))) {
301 llx = ((
long long)hx << 32)
302 | tsk->
thread.xstate->hardfpu.fp_regs[n + 1];
303 lly = ((
long long)hy << 32)
304 | tsk->
thread.xstate->hardfpu.fp_regs[m + 1];
305 if ((finsn & 0xf00f) == 0xf000)
309 tsk->
thread.xstate->hardfpu.fp_regs[
n] = llx >> 32;
310 tsk->
thread.xstate->hardfpu.fp_regs[n + 1] = llx & 0xffffffff;
311 }
else if ((fpscr & FPSCR_CAUSE_ERROR)
312 && (!prec && ((hx & 0x7fffffff) < 0x00800000
313 || (hy & 0x7fffffff) < 0x00800000))) {
315 if ((finsn & 0xf00f) == 0xf000)
319 tsk->
thread.xstate->hardfpu.fp_regs[
n] = hx;
325 }
else if ((finsn & 0xf003) == 0xf003) {
332 n = (finsn >> 8) & 0xf;
333 m = (finsn >> 4) & 0xf;
334 hx = tsk->
thread.xstate->hardfpu.fp_regs[
n];
335 hy = tsk->
thread.xstate->hardfpu.fp_regs[
m];
336 fpscr = tsk->
thread.xstate->hardfpu.fpscr;
339 if ((fpscr & FPSCR_CAUSE_ERROR)
340 && (prec && ((hx & 0x7fffffff) < 0x00100000
341 || (hy & 0x7fffffff) < 0x00100000))) {
345 llx = ((
long long)hx << 32)
346 | tsk->
thread.xstate->hardfpu.fp_regs[n + 1];
347 lly = ((
long long)hy << 32)
348 | tsk->
thread.xstate->hardfpu.fp_regs[m + 1];
352 tsk->
thread.xstate->hardfpu.fp_regs[
n] = llx >> 32;
353 tsk->
thread.xstate->hardfpu.fp_regs[n + 1] = llx & 0xffffffff;
354 }
else if ((fpscr & FPSCR_CAUSE_ERROR)
355 && (!prec && ((hx & 0x7fffffff) < 0x00800000
356 || (hy & 0x7fffffff) < 0x00800000))) {
359 tsk->
thread.xstate->hardfpu.fp_regs[
n] = hx;
365 }
else if ((finsn & 0xf0bd) == 0xf0bd) {
371 m = (finsn >> 8) & 0x7;
372 hx = tsk->
thread.xstate->hardfpu.fp_regs[
m];
374 if ((tsk->
thread.xstate->hardfpu.fpscr & FPSCR_CAUSE_ERROR)
375 && ((hx & 0x7fffffff) < 0x00100000)) {
379 llx = ((
long long)tsk->
thread.xstate->hardfpu.fp_regs[m] << 32)
380 | tsk->
thread.xstate->hardfpu.fp_regs[m + 1];
395 fpu_exception_flags |=
flags;
410 __unlazy_fpu(tsk, regs);
411 fpu_exception_flags = 0;
412 if (ieee_fpe_handler(regs)) {
413 tsk->
thread.xstate->hardfpu.fpscr &=
414 ~(FPSCR_CAUSE_MASK | FPSCR_FLAG_MASK);
415 tsk->
thread.xstate->hardfpu.fpscr |= fpu_exception_flags;
418 tsk->
thread.xstate->hardfpu.fpscr |= (fpu_exception_flags >> 10);
423 (fpu_exception_flags >> 2)) == 0) {