Clean up ill-advised or unusual header guards
[qemu/kevin.git] / linux-user / arm / nwfpe / fpa11_cpdt.c
blobc32b0c2faac0bbaf249af57218c4e47d8b72cf4d
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, see <http://www.gnu.org/licenses/>.
22 #include "qemu/osdep.h"
23 #include "fpa11.h"
24 #include "fpu/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, target_ulong addr)
34 FPA11 *fpa11 = GET_FPA11();
35 fpa11->fType[Fn] = typeSingle;
36 /* FIXME - handle failure of get_user() */
37 get_user_u32(float32_val(fpa11->fpreg[Fn].fSingle), addr);
40 static inline
41 void loadDouble(const unsigned int Fn, target_ulong addr)
43 FPA11 *fpa11 = GET_FPA11();
44 unsigned int *p;
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);
51 #else
52 /* FIXME - handle failure of get_user() */
53 get_user_u32(p[0], addr + 4);
54 get_user_u32(p[1], addr); /* sign & exponent */
55 #endif
58 static inline
59 void loadExtended(const unsigned int Fn, target_ulong addr)
61 FPA11 *fpa11 = GET_FPA11();
62 unsigned int *p;
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 */
71 static inline
72 void loadMultiple(const unsigned int Fn, target_ulong addr)
74 FPA11 *fpa11 = GET_FPA11();
75 register unsigned int *p;
76 unsigned long x;
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])
85 case typeSingle:
86 case typeDouble:
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 */
91 p[2] = 0; /* empty */
93 break;
95 case typeExtended:
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);
102 break;
106 static inline
107 void storeSingle(const unsigned int Fn, target_ulong addr)
109 FPA11 *fpa11 = GET_FPA11();
110 float32 val;
111 register unsigned int *p = (unsigned int*)&val;
113 switch (fpa11->fType[Fn])
115 case typeDouble:
116 val = float64_to_float32(fpa11->fpreg[Fn].fDouble, &fpa11->fp_status);
117 break;
119 case typeExtended:
120 val = floatx80_to_float32(fpa11->fpreg[Fn].fExtended, &fpa11->fp_status);
121 break;
123 default: val = fpa11->fpreg[Fn].fSingle;
126 /* FIXME - handle put_user() failures */
127 put_user_u32(p[0], addr);
130 static inline
131 void storeDouble(const unsigned int Fn, target_ulong addr)
133 FPA11 *fpa11 = GET_FPA11();
134 float64 val;
135 register unsigned int *p = (unsigned int*)&val;
137 switch (fpa11->fType[Fn])
139 case typeSingle:
140 val = float32_to_float64(fpa11->fpreg[Fn].fSingle, &fpa11->fp_status);
141 break;
143 case typeExtended:
144 val = floatx80_to_float64(fpa11->fpreg[Fn].fExtended, &fpa11->fp_status);
145 break;
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 */
153 #else
154 put_user_u32(p[1], addr); /* msw */
155 put_user_u32(p[0], addr + 4); /* lsw */
156 #endif
159 static inline
160 void storeExtended(const unsigned int Fn, target_ulong addr)
162 FPA11 *fpa11 = GET_FPA11();
163 floatx80 val;
164 register unsigned int *p = (unsigned int*)&val;
166 switch (fpa11->fType[Fn])
168 case typeSingle:
169 val = float32_to_floatx80(fpa11->fpreg[Fn].fSingle, &fpa11->fp_status);
170 break;
172 case typeDouble:
173 val = float64_to_floatx80(fpa11->fpreg[Fn].fDouble, &fpa11->fp_status);
174 break;
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 */
185 static inline
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];
194 switch (nType)
196 case typeSingle:
197 case typeDouble:
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);
203 break;
205 case typeExtended:
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);
211 break;
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 (ARM_REG_PC == getRn(opcode))
226 pBase += 8;
227 write_back = 0;
230 pFinal = pBase;
231 if (BIT_UP_SET(opcode))
232 pFinal += getOffset(opcode) * 4;
233 else
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;
243 default: nRc = 0;
246 if (write_back) writeRegister(getRn(opcode),(unsigned int)pFinal);
247 return nRc;
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 (ARM_REG_PC == getRn(opcode))
262 pBase += 8;
263 write_back = 0;
266 pFinal = pBase;
267 if (BIT_UP_SET(opcode))
268 pFinal += getOffset(opcode) * 4;
269 else
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;
279 default: nRc = 0;
282 if (write_back) writeRegister(getRn(opcode),(unsigned int)pFinal);
283 return nRc;
286 static unsigned int PerformLFM(const unsigned int opcode)
288 unsigned int i, Fd,
289 write_back = WRITE_BACK(opcode);
290 target_ulong pBase, pAddress, pFinal;
292 pBase = readRegister(getRn(opcode));
293 if (ARM_REG_PC == getRn(opcode))
295 pBase += 8;
296 write_back = 0;
299 pFinal = pBase;
300 if (BIT_UP_SET(opcode))
301 pFinal += getOffset(opcode) * 4;
302 else
303 pFinal -= getOffset(opcode) * 4;
305 if (PREINDEXED(opcode)) pAddress = pFinal; else pAddress = pBase;
307 Fd = getFd(opcode);
308 for (i=getRegisterCount(opcode);i>0;i--)
310 loadMultiple(Fd,pAddress);
311 pAddress += 12; Fd++;
312 if (Fd == 8) Fd = 0;
315 if (write_back) writeRegister(getRn(opcode),(unsigned int)pFinal);
316 return 1;
319 static unsigned int PerformSFM(const unsigned int opcode)
321 unsigned int i, Fd,
322 write_back = WRITE_BACK(opcode);
323 target_ulong pBase, pAddress, pFinal;
325 pBase = readRegister(getRn(opcode));
326 if (ARM_REG_PC == getRn(opcode))
328 pBase += 8;
329 write_back = 0;
332 pFinal = pBase;
333 if (BIT_UP_SET(opcode))
334 pFinal += getOffset(opcode) * 4;
335 else
336 pFinal -= getOffset(opcode) * 4;
338 if (PREINDEXED(opcode)) pAddress = pFinal; else pAddress = pBase;
340 Fd = getFd(opcode);
341 for (i=getRegisterCount(opcode);i>0;i--)
343 storeMultiple(Fd,pAddress);
344 pAddress += 12; Fd++;
345 if (Fd == 8) Fd = 0;
348 if (write_back) writeRegister(getRn(opcode),(unsigned int)pFinal);
349 return 1;
352 #if 1
353 unsigned int EmulateCPDT(const unsigned int opcode)
355 unsigned int nRc = 0;
357 //printk("EmulateCPDT(0x%08x)\n",opcode);
359 if (LDF_OP(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);
375 else
377 nRc = 0;
380 return nRc;
382 #endif