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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "softfloat.h"
26 //#include "fpmodule.h"
27 //#include "fpmodule.inl"
29 //#include <asm/uaccess.h>
32 void loadSingle(const unsigned int Fn
, target_ulong addr
)
34 FPA11
*fpa11
= GET_FPA11();
35 fpa11
->fType
[Fn
] = typeSingle
;
36 /* FIXME - handle failure of get_user() */
37 get_user_u32(fpa11
->fpreg
[Fn
].fSingle
, addr
);
41 void loadDouble(const unsigned int Fn
, target_ulong addr
)
43 FPA11
*fpa11
= GET_FPA11();
45 p
= (unsigned int*)&fpa11
->fpreg
[Fn
].fDouble
;
46 fpa11
->fType
[Fn
] = typeDouble
;
47 #ifdef HOST_WORDS_BIGENDIAN
48 /* FIXME - handle failure of get_user() */
49 get_user_u32(p
[0], addr
); /* sign & exponent */
50 get_user_u32(p
[1], addr
+ 4);
52 /* FIXME - handle failure of get_user() */
53 get_user_u32(p
[0], addr
+ 4);
54 get_user_u32(p
[1], addr
); /* sign & exponent */
59 void loadExtended(const unsigned int Fn
, target_ulong addr
)
61 FPA11
*fpa11
= GET_FPA11();
63 p
= (unsigned int*)&fpa11
->fpreg
[Fn
].fExtended
;
64 fpa11
->fType
[Fn
] = typeExtended
;
65 /* FIXME - handle failure of get_user() */
66 get_user_u32(p
[0], addr
); /* sign & exponent */
67 get_user_u32(p
[1], addr
+ 8); /* ls bits */
68 get_user_u32(p
[2], addr
+ 4); /* ms bits */
72 void loadMultiple(const unsigned int Fn
, target_ulong addr
)
74 FPA11
*fpa11
= GET_FPA11();
75 register unsigned int *p
;
78 p
= (unsigned int*)&(fpa11
->fpreg
[Fn
]);
79 /* FIXME - handle failure of get_user() */
80 get_user_u32(x
, addr
);
81 fpa11
->fType
[Fn
] = (x
>> 14) & 0x00000003;
83 switch (fpa11
->fType
[Fn
])
88 /* FIXME - handle failure of get_user() */
89 get_user_u32(p
[0], addr
+ 8); /* Single */
90 get_user_u32(p
[1], addr
+ 4); /* double msw */
97 /* FIXME - handle failure of get_user() */
98 get_user_u32(p
[1], addr
+ 8);
99 get_user_u32(p
[2], addr
+ 4); /* msw */
100 p
[0] = (x
& 0x80003fff);
107 void storeSingle(const unsigned int Fn
, target_ulong addr
)
109 FPA11
*fpa11
= GET_FPA11();
111 register unsigned int *p
= (unsigned int*)&val
;
113 switch (fpa11
->fType
[Fn
])
116 val
= float64_to_float32(fpa11
->fpreg
[Fn
].fDouble
, &fpa11
->fp_status
);
120 val
= floatx80_to_float32(fpa11
->fpreg
[Fn
].fExtended
, &fpa11
->fp_status
);
123 default: val
= fpa11
->fpreg
[Fn
].fSingle
;
126 /* FIXME - handle put_user() failures */
127 put_user_u32(p
[0], addr
);
131 void storeDouble(const unsigned int Fn
, target_ulong addr
)
133 FPA11
*fpa11
= GET_FPA11();
135 register unsigned int *p
= (unsigned int*)&val
;
137 switch (fpa11
->fType
[Fn
])
140 val
= float32_to_float64(fpa11
->fpreg
[Fn
].fSingle
, &fpa11
->fp_status
);
144 val
= floatx80_to_float64(fpa11
->fpreg
[Fn
].fExtended
, &fpa11
->fp_status
);
147 default: val
= fpa11
->fpreg
[Fn
].fDouble
;
149 /* FIXME - handle put_user() failures */
150 #ifdef HOST_WORDS_BIGENDIAN
151 put_user_u32(p
[0], addr
); /* msw */
152 put_user_u32(p
[1], addr
+ 4); /* lsw */
154 put_user_u32(p
[1], addr
); /* msw */
155 put_user_u32(p
[0], addr
+ 4); /* lsw */
160 void storeExtended(const unsigned int Fn
, target_ulong addr
)
162 FPA11
*fpa11
= GET_FPA11();
164 register unsigned int *p
= (unsigned int*)&val
;
166 switch (fpa11
->fType
[Fn
])
169 val
= float32_to_floatx80(fpa11
->fpreg
[Fn
].fSingle
, &fpa11
->fp_status
);
173 val
= float64_to_floatx80(fpa11
->fpreg
[Fn
].fDouble
, &fpa11
->fp_status
);
176 default: val
= fpa11
->fpreg
[Fn
].fExtended
;
179 /* FIXME - handle put_user() failures */
180 put_user_u32(p
[0], addr
); /* sign & exp */
181 put_user_u32(p
[1], addr
+ 8);
182 put_user_u32(p
[2], addr
+ 4); /* msw */
186 void storeMultiple(const unsigned int Fn
, target_ulong addr
)
188 FPA11
*fpa11
= GET_FPA11();
189 register unsigned int nType
, *p
;
191 p
= (unsigned int*)&(fpa11
->fpreg
[Fn
]);
192 nType
= fpa11
->fType
[Fn
];
199 put_user_u32(p
[0], addr
+ 8); /* single */
200 put_user_u32(p
[1], addr
+ 4); /* double msw */
201 put_user_u32(nType
<< 14, addr
);
207 put_user_u32(p
[2], addr
+ 4); /* msw */
208 put_user_u32(p
[1], addr
+ 8);
209 put_user_u32((p
[0] & 0x80003fff) | (nType
<< 14), addr
);
215 static unsigned int PerformLDF(const unsigned int opcode
)
217 target_ulong pBase
, pAddress
, pFinal
;
218 unsigned int nRc
= 1,
219 write_back
= WRITE_BACK(opcode
);
221 //printk("PerformLDF(0x%08x), Fd = 0x%08x\n",opcode,getFd(opcode));
223 pBase
= readRegister(getRn(opcode
));
224 if (REG_PC
== getRn(opcode
))
231 if (BIT_UP_SET(opcode
))
232 pFinal
+= getOffset(opcode
) * 4;
234 pFinal
-= getOffset(opcode
) * 4;
236 if (PREINDEXED(opcode
)) pAddress
= pFinal
; else pAddress
= pBase
;
238 switch (opcode
& MASK_TRANSFER_LENGTH
)
240 case TRANSFER_SINGLE
: loadSingle(getFd(opcode
),pAddress
); break;
241 case TRANSFER_DOUBLE
: loadDouble(getFd(opcode
),pAddress
); break;
242 case TRANSFER_EXTENDED
: loadExtended(getFd(opcode
),pAddress
); break;
246 if (write_back
) writeRegister(getRn(opcode
),(unsigned int)pFinal
);
250 static unsigned int PerformSTF(const unsigned int opcode
)
252 target_ulong pBase
, pAddress
, pFinal
;
253 unsigned int nRc
= 1,
254 write_back
= WRITE_BACK(opcode
);
256 //printk("PerformSTF(0x%08x), Fd = 0x%08x\n",opcode,getFd(opcode));
257 SetRoundingMode(ROUND_TO_NEAREST
);
259 pBase
= readRegister(getRn(opcode
));
260 if (REG_PC
== getRn(opcode
))
267 if (BIT_UP_SET(opcode
))
268 pFinal
+= getOffset(opcode
) * 4;
270 pFinal
-= getOffset(opcode
) * 4;
272 if (PREINDEXED(opcode
)) pAddress
= pFinal
; else pAddress
= pBase
;
274 switch (opcode
& MASK_TRANSFER_LENGTH
)
276 case TRANSFER_SINGLE
: storeSingle(getFd(opcode
),pAddress
); break;
277 case TRANSFER_DOUBLE
: storeDouble(getFd(opcode
),pAddress
); break;
278 case TRANSFER_EXTENDED
: storeExtended(getFd(opcode
),pAddress
); break;
282 if (write_back
) writeRegister(getRn(opcode
),(unsigned int)pFinal
);
286 static unsigned int PerformLFM(const unsigned int opcode
)
289 write_back
= WRITE_BACK(opcode
);
290 target_ulong pBase
, pAddress
, pFinal
;
292 pBase
= readRegister(getRn(opcode
));
293 if (REG_PC
== getRn(opcode
))
300 if (BIT_UP_SET(opcode
))
301 pFinal
+= getOffset(opcode
) * 4;
303 pFinal
-= getOffset(opcode
) * 4;
305 if (PREINDEXED(opcode
)) pAddress
= pFinal
; else pAddress
= pBase
;
308 for (i
=getRegisterCount(opcode
);i
>0;i
--)
310 loadMultiple(Fd
,pAddress
);
311 pAddress
+= 12; Fd
++;
315 if (write_back
) writeRegister(getRn(opcode
),(unsigned int)pFinal
);
319 static unsigned int PerformSFM(const unsigned int opcode
)
322 write_back
= WRITE_BACK(opcode
);
323 target_ulong pBase
, pAddress
, pFinal
;
325 pBase
= readRegister(getRn(opcode
));
326 if (REG_PC
== getRn(opcode
))
333 if (BIT_UP_SET(opcode
))
334 pFinal
+= getOffset(opcode
) * 4;
336 pFinal
-= getOffset(opcode
) * 4;
338 if (PREINDEXED(opcode
)) pAddress
= pFinal
; else pAddress
= pBase
;
341 for (i
=getRegisterCount(opcode
);i
>0;i
--)
343 storeMultiple(Fd
,pAddress
);
344 pAddress
+= 12; Fd
++;
348 if (write_back
) writeRegister(getRn(opcode
),(unsigned int)pFinal
);
353 unsigned int EmulateCPDT(const unsigned int opcode
)
355 unsigned int nRc
= 0;
357 //printk("EmulateCPDT(0x%08x)\n",opcode);
361 nRc
= PerformLDF(opcode
);
363 else if (LFM_OP(opcode
))
365 nRc
= PerformLFM(opcode
);
367 else if (STF_OP(opcode
))
369 nRc
= PerformSTF(opcode
);
371 else if (SFM_OP(opcode
))
373 nRc
= PerformSFM(opcode
);