2 NetWinder Floating Point Emulator
3 (c) Rebel.com, 1998-1999
4 (c) Philip Blundell, 1998
6 Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "softfloat.h"
25 //#include "fpmodule.h"
26 //#include "fpmodule.inl"
28 //#include <asm/uaccess.h>
31 void loadSingle(const unsigned int Fn
, target_ulong addr
)
33 FPA11
*fpa11
= GET_FPA11();
34 fpa11
->fType
[Fn
] = typeSingle
;
35 /* FIXME - handle failure of get_user() */
36 get_user_u32(fpa11
->fpreg
[Fn
].fSingle
, addr
);
40 void loadDouble(const unsigned int Fn
, target_ulong addr
)
42 FPA11
*fpa11
= GET_FPA11();
44 p
= (unsigned int*)&fpa11
->fpreg
[Fn
].fDouble
;
45 fpa11
->fType
[Fn
] = typeDouble
;
46 #ifdef HOST_WORDS_BIGENDIAN
47 /* FIXME - handle failure of get_user() */
48 get_user_u32(p
[0], addr
); /* sign & exponent */
49 get_user_u32(p
[1], addr
+ 4);
51 /* FIXME - handle failure of get_user() */
52 get_user_u32(p
[0], addr
+ 4);
53 get_user_u32(p
[1], addr
); /* sign & exponent */
58 void loadExtended(const unsigned int Fn
, target_ulong addr
)
60 FPA11
*fpa11
= GET_FPA11();
62 p
= (unsigned int*)&fpa11
->fpreg
[Fn
].fExtended
;
63 fpa11
->fType
[Fn
] = typeExtended
;
64 /* FIXME - handle failure of get_user() */
65 get_user_u32(p
[0], addr
); /* sign & exponent */
66 get_user_u32(p
[1], addr
+ 8); /* ls bits */
67 get_user_u32(p
[2], addr
+ 4); /* ms bits */
71 void loadMultiple(const unsigned int Fn
, target_ulong addr
)
73 FPA11
*fpa11
= GET_FPA11();
74 register unsigned int *p
;
77 p
= (unsigned int*)&(fpa11
->fpreg
[Fn
]);
78 /* FIXME - handle failure of get_user() */
79 get_user_u32(x
, addr
);
80 fpa11
->fType
[Fn
] = (x
>> 14) & 0x00000003;
82 switch (fpa11
->fType
[Fn
])
87 /* FIXME - handle failure of get_user() */
88 get_user_u32(p
[0], addr
+ 8); /* Single */
89 get_user_u32(p
[1], addr
+ 4); /* double msw */
96 /* FIXME - handle failure of get_user() */
97 get_user_u32(p
[1], addr
+ 8);
98 get_user_u32(p
[2], addr
+ 4); /* msw */
99 p
[0] = (x
& 0x80003fff);
106 void storeSingle(const unsigned int Fn
, target_ulong addr
)
108 FPA11
*fpa11
= GET_FPA11();
110 register unsigned int *p
= (unsigned int*)&val
;
112 switch (fpa11
->fType
[Fn
])
115 val
= float64_to_float32(fpa11
->fpreg
[Fn
].fDouble
, &fpa11
->fp_status
);
119 val
= floatx80_to_float32(fpa11
->fpreg
[Fn
].fExtended
, &fpa11
->fp_status
);
122 default: val
= fpa11
->fpreg
[Fn
].fSingle
;
125 /* FIXME - handle put_user() failures */
126 put_user_u32(p
[0], addr
);
130 void storeDouble(const unsigned int Fn
, target_ulong addr
)
132 FPA11
*fpa11
= GET_FPA11();
134 register unsigned int *p
= (unsigned int*)&val
;
136 switch (fpa11
->fType
[Fn
])
139 val
= float32_to_float64(fpa11
->fpreg
[Fn
].fSingle
, &fpa11
->fp_status
);
143 val
= floatx80_to_float64(fpa11
->fpreg
[Fn
].fExtended
, &fpa11
->fp_status
);
146 default: val
= fpa11
->fpreg
[Fn
].fDouble
;
148 /* FIXME - handle put_user() failures */
149 #ifdef HOST_WORDS_BIGENDIAN
150 put_user_u32(p
[0], addr
); /* msw */
151 put_user_u32(p
[1], addr
+ 4); /* lsw */
153 put_user_u32(p
[1], addr
); /* msw */
154 put_user_u32(p
[0], addr
+ 4); /* lsw */
159 void storeExtended(const unsigned int Fn
, target_ulong addr
)
161 FPA11
*fpa11
= GET_FPA11();
163 register unsigned int *p
= (unsigned int*)&val
;
165 switch (fpa11
->fType
[Fn
])
168 val
= float32_to_floatx80(fpa11
->fpreg
[Fn
].fSingle
, &fpa11
->fp_status
);
172 val
= float64_to_floatx80(fpa11
->fpreg
[Fn
].fDouble
, &fpa11
->fp_status
);
175 default: val
= fpa11
->fpreg
[Fn
].fExtended
;
178 /* FIXME - handle put_user() failures */
179 put_user_u32(p
[0], addr
); /* sign & exp */
180 put_user_u32(p
[1], addr
+ 8);
181 put_user_u32(p
[2], addr
+ 4); /* msw */
185 void storeMultiple(const unsigned int Fn
, target_ulong addr
)
187 FPA11
*fpa11
= GET_FPA11();
188 register unsigned int nType
, *p
;
190 p
= (unsigned int*)&(fpa11
->fpreg
[Fn
]);
191 nType
= fpa11
->fType
[Fn
];
198 put_user_u32(p
[0], addr
+ 8); /* single */
199 put_user_u32(p
[1], addr
+ 4); /* double msw */
200 put_user_u32(nType
<< 14, addr
);
206 put_user_u32(p
[2], addr
+ 4); /* msw */
207 put_user_u32(p
[1], addr
+ 8);
208 put_user_u32((p
[0] & 0x80003fff) | (nType
<< 14), addr
);
214 static unsigned int PerformLDF(const unsigned int opcode
)
216 target_ulong pBase
, pAddress
, pFinal
;
217 unsigned int nRc
= 1,
218 write_back
= WRITE_BACK(opcode
);
220 //printk("PerformLDF(0x%08x), Fd = 0x%08x\n",opcode,getFd(opcode));
222 pBase
= readRegister(getRn(opcode
));
223 if (REG_PC
== getRn(opcode
))
230 if (BIT_UP_SET(opcode
))
231 pFinal
+= getOffset(opcode
) * 4;
233 pFinal
-= getOffset(opcode
) * 4;
235 if (PREINDEXED(opcode
)) pAddress
= pFinal
; else pAddress
= pBase
;
237 switch (opcode
& MASK_TRANSFER_LENGTH
)
239 case TRANSFER_SINGLE
: loadSingle(getFd(opcode
),pAddress
); break;
240 case TRANSFER_DOUBLE
: loadDouble(getFd(opcode
),pAddress
); break;
241 case TRANSFER_EXTENDED
: loadExtended(getFd(opcode
),pAddress
); break;
245 if (write_back
) writeRegister(getRn(opcode
),(unsigned int)pFinal
);
249 static unsigned int PerformSTF(const unsigned int opcode
)
251 target_ulong pBase
, pAddress
, pFinal
;
252 unsigned int nRc
= 1,
253 write_back
= WRITE_BACK(opcode
);
255 //printk("PerformSTF(0x%08x), Fd = 0x%08x\n",opcode,getFd(opcode));
256 SetRoundingMode(ROUND_TO_NEAREST
);
258 pBase
= readRegister(getRn(opcode
));
259 if (REG_PC
== getRn(opcode
))
266 if (BIT_UP_SET(opcode
))
267 pFinal
+= getOffset(opcode
) * 4;
269 pFinal
-= getOffset(opcode
) * 4;
271 if (PREINDEXED(opcode
)) pAddress
= pFinal
; else pAddress
= pBase
;
273 switch (opcode
& MASK_TRANSFER_LENGTH
)
275 case TRANSFER_SINGLE
: storeSingle(getFd(opcode
),pAddress
); break;
276 case TRANSFER_DOUBLE
: storeDouble(getFd(opcode
),pAddress
); break;
277 case TRANSFER_EXTENDED
: storeExtended(getFd(opcode
),pAddress
); break;
281 if (write_back
) writeRegister(getRn(opcode
),(unsigned int)pFinal
);
285 static unsigned int PerformLFM(const unsigned int opcode
)
288 write_back
= WRITE_BACK(opcode
);
289 target_ulong pBase
, pAddress
, pFinal
;
291 pBase
= readRegister(getRn(opcode
));
292 if (REG_PC
== getRn(opcode
))
299 if (BIT_UP_SET(opcode
))
300 pFinal
+= getOffset(opcode
) * 4;
302 pFinal
-= getOffset(opcode
) * 4;
304 if (PREINDEXED(opcode
)) pAddress
= pFinal
; else pAddress
= pBase
;
307 for (i
=getRegisterCount(opcode
);i
>0;i
--)
309 loadMultiple(Fd
,pAddress
);
310 pAddress
+= 12; Fd
++;
314 if (write_back
) writeRegister(getRn(opcode
),(unsigned int)pFinal
);
318 static unsigned int PerformSFM(const unsigned int opcode
)
321 write_back
= WRITE_BACK(opcode
);
322 target_ulong pBase
, pAddress
, pFinal
;
324 pBase
= readRegister(getRn(opcode
));
325 if (REG_PC
== getRn(opcode
))
332 if (BIT_UP_SET(opcode
))
333 pFinal
+= getOffset(opcode
) * 4;
335 pFinal
-= getOffset(opcode
) * 4;
337 if (PREINDEXED(opcode
)) pAddress
= pFinal
; else pAddress
= pBase
;
340 for (i
=getRegisterCount(opcode
);i
>0;i
--)
342 storeMultiple(Fd
,pAddress
);
343 pAddress
+= 12; Fd
++;
347 if (write_back
) writeRegister(getRn(opcode
),(unsigned int)pFinal
);
352 unsigned int EmulateCPDT(const unsigned int opcode
)
354 unsigned int nRc
= 0;
356 //printk("EmulateCPDT(0x%08x)\n",opcode);
360 nRc
= PerformLDF(opcode
);
362 else if (LFM_OP(opcode
))
364 nRc
= PerformLFM(opcode
);
366 else if (STF_OP(opcode
))
368 nRc
= PerformSTF(opcode
);
370 else if (SFM_OP(opcode
))
372 nRc
= PerformSFM(opcode
);