allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / arch / arm26 / nwfpe / fpa11_cpdt.c
blobe12db7c51a768c1901e3bb86b05801bbab5735c4
1 /*
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.
23 #include "fpa11.h"
24 #include "softfloat.h"
25 #include "fpopcode.h"
26 #include "fpmodule.h"
27 #include "fpmodule.inl"
29 #include <asm/uaccess.h>
31 static inline
32 void loadSingle(const unsigned int Fn,const unsigned int *pMem)
34 FPA11 *fpa11 = GET_FPA11();
35 fpa11->fType[Fn] = typeSingle;
36 get_user(fpa11->fpreg[Fn].fSingle, pMem);
39 static inline
40 void loadDouble(const unsigned int Fn,const unsigned int *pMem)
42 FPA11 *fpa11 = GET_FPA11();
43 unsigned int *p;
44 p = (unsigned int*)&fpa11->fpreg[Fn].fDouble;
45 fpa11->fType[Fn] = typeDouble;
46 get_user(p[0], &pMem[1]);
47 get_user(p[1], &pMem[0]); /* sign & exponent */
50 static inline
51 void loadExtended(const unsigned int Fn,const unsigned int *pMem)
53 FPA11 *fpa11 = GET_FPA11();
54 unsigned int *p;
55 p = (unsigned int*)&fpa11->fpreg[Fn].fExtended;
56 fpa11->fType[Fn] = typeExtended;
57 get_user(p[0], &pMem[0]); /* sign & exponent */
58 get_user(p[1], &pMem[2]); /* ls bits */
59 get_user(p[2], &pMem[1]); /* ms bits */
62 static inline
63 void loadMultiple(const unsigned int Fn,const unsigned int *pMem)
65 FPA11 *fpa11 = GET_FPA11();
66 register unsigned int *p;
67 unsigned long x;
69 p = (unsigned int*)&(fpa11->fpreg[Fn]);
70 get_user(x, &pMem[0]);
71 fpa11->fType[Fn] = (x >> 14) & 0x00000003;
73 switch (fpa11->fType[Fn])
75 case typeSingle:
76 case typeDouble:
78 get_user(p[0], &pMem[2]); /* Single */
79 get_user(p[1], &pMem[1]); /* double msw */
80 p[2] = 0; /* empty */
82 break;
84 case typeExtended:
86 get_user(p[1], &pMem[2]);
87 get_user(p[2], &pMem[1]); /* msw */
88 p[0] = (x & 0x80003fff);
90 break;
94 static inline
95 void storeSingle(const unsigned int Fn,unsigned int *pMem)
97 FPA11 *fpa11 = GET_FPA11();
98 union
100 float32 f;
101 unsigned int i[1];
102 } val;
104 switch (fpa11->fType[Fn])
106 case typeDouble:
107 val.f = float64_to_float32(fpa11->fpreg[Fn].fDouble);
108 break;
110 case typeExtended:
111 val.f = floatx80_to_float32(fpa11->fpreg[Fn].fExtended);
112 break;
114 default: val.f = fpa11->fpreg[Fn].fSingle;
117 put_user(val.i[0], pMem);
120 static inline
121 void storeDouble(const unsigned int Fn,unsigned int *pMem)
123 FPA11 *fpa11 = GET_FPA11();
124 union
126 float64 f;
127 unsigned int i[2];
128 } val;
130 switch (fpa11->fType[Fn])
132 case typeSingle:
133 val.f = float32_to_float64(fpa11->fpreg[Fn].fSingle);
134 break;
136 case typeExtended:
137 val.f = floatx80_to_float64(fpa11->fpreg[Fn].fExtended);
138 break;
140 default: val.f = fpa11->fpreg[Fn].fDouble;
143 put_user(val.i[1], &pMem[0]); /* msw */
144 put_user(val.i[0], &pMem[1]); /* lsw */
147 static inline
148 void storeExtended(const unsigned int Fn,unsigned int *pMem)
150 FPA11 *fpa11 = GET_FPA11();
151 union
153 floatx80 f;
154 unsigned int i[3];
155 } val;
157 switch (fpa11->fType[Fn])
159 case typeSingle:
160 val.f = float32_to_floatx80(fpa11->fpreg[Fn].fSingle);
161 break;
163 case typeDouble:
164 val.f = float64_to_floatx80(fpa11->fpreg[Fn].fDouble);
165 break;
167 default: val.f = fpa11->fpreg[Fn].fExtended;
170 put_user(val.i[0], &pMem[0]); /* sign & exp */
171 put_user(val.i[1], &pMem[2]);
172 put_user(val.i[2], &pMem[1]); /* msw */
175 static inline
176 void storeMultiple(const unsigned int Fn,unsigned int *pMem)
178 FPA11 *fpa11 = GET_FPA11();
179 register unsigned int nType, *p;
181 p = (unsigned int*)&(fpa11->fpreg[Fn]);
182 nType = fpa11->fType[Fn];
184 switch (nType)
186 case typeSingle:
187 case typeDouble:
189 put_user(p[0], &pMem[2]); /* single */
190 put_user(p[1], &pMem[1]); /* double msw */
191 put_user(nType << 14, &pMem[0]);
193 break;
195 case typeExtended:
197 put_user(p[2], &pMem[1]); /* msw */
198 put_user(p[1], &pMem[2]);
199 put_user((p[0] & 0x80003fff) | (nType << 14), &pMem[0]);
201 break;
205 unsigned int PerformLDF(const unsigned int opcode)
207 unsigned int *pBase, *pAddress, *pFinal, nRc = 1,
208 write_back = WRITE_BACK(opcode);
210 //printk("PerformLDF(0x%08x), Fd = 0x%08x\n",opcode,getFd(opcode));
212 pBase = (unsigned int*)readRegister(getRn(opcode));
213 if (REG_PC == getRn(opcode))
215 pBase += 2;
216 write_back = 0;
219 pFinal = pBase;
220 if (BIT_UP_SET(opcode))
221 pFinal += getOffset(opcode);
222 else
223 pFinal -= getOffset(opcode);
225 if (PREINDEXED(opcode)) pAddress = pFinal; else pAddress = pBase;
227 switch (opcode & MASK_TRANSFER_LENGTH)
229 case TRANSFER_SINGLE : loadSingle(getFd(opcode),pAddress); break;
230 case TRANSFER_DOUBLE : loadDouble(getFd(opcode),pAddress); break;
231 case TRANSFER_EXTENDED: loadExtended(getFd(opcode),pAddress); break;
232 default: nRc = 0;
235 if (write_back) writeRegister(getRn(opcode),(unsigned int)pFinal);
236 return nRc;
239 unsigned int PerformSTF(const unsigned int opcode)
241 unsigned int *pBase, *pAddress, *pFinal, nRc = 1,
242 write_back = WRITE_BACK(opcode);
244 //printk("PerformSTF(0x%08x), Fd = 0x%08x\n",opcode,getFd(opcode));
245 SetRoundingMode(ROUND_TO_NEAREST);
247 pBase = (unsigned int*)readRegister(getRn(opcode));
248 if (REG_PC == getRn(opcode))
250 pBase += 2;
251 write_back = 0;
254 pFinal = pBase;
255 if (BIT_UP_SET(opcode))
256 pFinal += getOffset(opcode);
257 else
258 pFinal -= getOffset(opcode);
260 if (PREINDEXED(opcode)) pAddress = pFinal; else pAddress = pBase;
262 switch (opcode & MASK_TRANSFER_LENGTH)
264 case TRANSFER_SINGLE : storeSingle(getFd(opcode),pAddress); break;
265 case TRANSFER_DOUBLE : storeDouble(getFd(opcode),pAddress); break;
266 case TRANSFER_EXTENDED: storeExtended(getFd(opcode),pAddress); break;
267 default: nRc = 0;
270 if (write_back) writeRegister(getRn(opcode),(unsigned int)pFinal);
271 return nRc;
274 unsigned int PerformLFM(const unsigned int opcode)
276 unsigned int i, Fd, *pBase, *pAddress, *pFinal,
277 write_back = WRITE_BACK(opcode);
279 pBase = (unsigned int*)readRegister(getRn(opcode));
280 if (REG_PC == getRn(opcode))
282 pBase += 2;
283 write_back = 0;
286 pFinal = pBase;
287 if (BIT_UP_SET(opcode))
288 pFinal += getOffset(opcode);
289 else
290 pFinal -= getOffset(opcode);
292 if (PREINDEXED(opcode)) pAddress = pFinal; else pAddress = pBase;
294 Fd = getFd(opcode);
295 for (i=getRegisterCount(opcode);i>0;i--)
297 loadMultiple(Fd,pAddress);
298 pAddress += 3; Fd++;
299 if (Fd == 8) Fd = 0;
302 if (write_back) writeRegister(getRn(opcode),(unsigned int)pFinal);
303 return 1;
306 unsigned int PerformSFM(const unsigned int opcode)
308 unsigned int i, Fd, *pBase, *pAddress, *pFinal,
309 write_back = WRITE_BACK(opcode);
311 pBase = (unsigned int*)readRegister(getRn(opcode));
312 if (REG_PC == getRn(opcode))
314 pBase += 2;
315 write_back = 0;
318 pFinal = pBase;
319 if (BIT_UP_SET(opcode))
320 pFinal += getOffset(opcode);
321 else
322 pFinal -= getOffset(opcode);
324 if (PREINDEXED(opcode)) pAddress = pFinal; else pAddress = pBase;
326 Fd = getFd(opcode);
327 for (i=getRegisterCount(opcode);i>0;i--)
329 storeMultiple(Fd,pAddress);
330 pAddress += 3; Fd++;
331 if (Fd == 8) Fd = 0;
334 if (write_back) writeRegister(getRn(opcode),(unsigned int)pFinal);
335 return 1;
338 #if 1
339 unsigned int EmulateCPDT(const unsigned int opcode)
341 unsigned int nRc = 0;
343 //printk("EmulateCPDT(0x%08x)\n",opcode);
345 if (LDF_OP(opcode))
347 nRc = PerformLDF(opcode);
349 else if (LFM_OP(opcode))
351 nRc = PerformLFM(opcode);
353 else if (STF_OP(opcode))
355 nRc = PerformSTF(opcode);
357 else if (SFM_OP(opcode))
359 nRc = PerformSFM(opcode);
361 else
363 nRc = 0;
366 return nRc;
368 #endif