2 NetWinder Floating Point Emulator
3 (c) Rebel.COM, 1998,1999
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 //#include "fpmodule.h"
27 //#include "fpmodule.inl"
29 //#include <asm/system.h>
33 /* forward declarations */
34 unsigned int EmulateCPDO(const unsigned int);
35 unsigned int EmulateCPDT(const unsigned int);
36 unsigned int EmulateCPRT(const unsigned int);
39 CPUARMState* user_registers;
41 /* Reset the FPA11 chip. Called to initialize and reset the emulator. */
45 FPA11 *fpa11 = GET_FPA11();
47 /* initialize the register type array */
50 fpa11->fType[i] = typeNone;
53 /* FPSR: set system id to FP_EMULATOR, set AC, clear all other bits */
54 fpa11->fpsr = FP_EMULATOR | BIT_AC;
56 /* FPCR: set SB, AB and DA bits, clear all others */
58 fpa11->fpcr = MASK_RESET;
62 void SetRoundingMode(const unsigned int opcode)
65 FPA11 *fpa11 = GET_FPA11();
68 fpa11->fpcr &= ~MASK_ROUNDING_MODE;
70 switch (opcode & MASK_ROUNDING_MODE)
73 case ROUND_TO_NEAREST:
74 rounding_mode = float_round_nearest_even;
76 fpa11->fpcr |= ROUND_TO_NEAREST;
80 case ROUND_TO_PLUS_INFINITY:
81 rounding_mode = float_round_up;
83 fpa11->fpcr |= ROUND_TO_PLUS_INFINITY;
87 case ROUND_TO_MINUS_INFINITY:
88 rounding_mode = float_round_down;
90 fpa11->fpcr |= ROUND_TO_MINUS_INFINITY;
95 rounding_mode = float_round_to_zero;
97 fpa11->fpcr |= ROUND_TO_ZERO;
101 set_float_rounding_mode(rounding_mode, &fpa11->fp_status);
104 void SetRoundingPrecision(const unsigned int opcode)
106 int rounding_precision;
107 FPA11 *fpa11 = GET_FPA11();
109 fpa11->fpcr &= ~MASK_ROUNDING_PRECISION;
111 switch (opcode & MASK_ROUNDING_PRECISION)
114 rounding_precision = 32;
116 fpa11->fpcr |= ROUND_SINGLE;
121 rounding_precision = 64;
123 fpa11->fpcr |= ROUND_DOUBLE;
128 rounding_precision = 80;
130 fpa11->fpcr |= ROUND_EXTENDED;
134 default: rounding_precision = 80;
136 set_floatx80_rounding_precision(rounding_precision, &fpa11->fp_status);
139 /* Emulate the instruction in the opcode. */
140 /* ??? This is not thread safe. */
141 unsigned int EmulateAll(unsigned int opcode, FPA11* qfpa, CPUARMState* qregs)
143 unsigned int nRc = 0;
144 // unsigned long flags;
146 // save_flags(flags); sti();
149 user_registers=qregs;
152 fprintf(stderr,"emulating FP insn 0x%08x, PC=0x%08x\n",
153 opcode, qregs[REG_PC]);
157 if (fpa11->initflag == 0) /* good place for __builtin_expect */
160 SetRoundingMode(ROUND_TO_NEAREST);
161 SetRoundingPrecision(ROUND_EXTENDED);
165 if (TEST_OPCODE(opcode,MASK_CPRT))
167 //fprintf(stderr,"emulating CPRT\n");
168 /* Emulate conversion opcodes. */
169 /* Emulate register transfer opcodes. */
170 /* Emulate comparison opcodes. */
171 nRc = EmulateCPRT(opcode);
173 else if (TEST_OPCODE(opcode,MASK_CPDO))
175 //fprintf(stderr,"emulating CPDO\n");
176 /* Emulate monadic arithmetic opcodes. */
177 /* Emulate dyadic arithmetic opcodes. */
178 nRc = EmulateCPDO(opcode);
180 else if (TEST_OPCODE(opcode,MASK_CPDT))
182 //fprintf(stderr,"emulating CPDT\n");
183 /* Emulate load/store opcodes. */
184 /* Emulate load/store multiple opcodes. */
185 nRc = EmulateCPDT(opcode);
189 /* Invalid instruction detected. Return FALSE. */
193 // restore_flags(flags);
195 //printf("returning %d\n",nRc);
200 unsigned int EmulateAll1(unsigned int opcode)
202 switch ((opcode >> 24) & 0xf)
206 if ((opcode >> 20) & 0x1)
208 switch ((opcode >> 8) & 0xf)
210 case 0x1: return PerformLDF(opcode); break;
211 case 0x2: return PerformLFM(opcode); break;
217 switch ((opcode >> 8) & 0xf)
219 case 0x1: return PerformSTF(opcode); break;
220 case 0x2: return PerformSFM(opcode); break;
228 return EmulateCPDO(opcode);
230 return EmulateCPRT(opcode);