2 NetWinder Floating Point Emulator
3 (c) Rebel.COM, 1998,1999
5 Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
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>
34 CPUARMState
* user_registers
;
36 /* Reset the FPA11 chip. Called to initialize and reset the emulator. */
40 FPA11
*fpa11
= GET_FPA11();
42 /* initialize the register type array */
45 fpa11
->fType
[i
] = typeNone
;
48 /* FPSR: set system id to FP_EMULATOR, set AC, clear all other bits */
49 fpa11
->fpsr
= FP_EMULATOR
| BIT_AC
;
51 /* FPCR: set SB, AB and DA bits, clear all others */
53 fpa11
->fpcr
= MASK_RESET
;
57 void SetRoundingMode(const unsigned int opcode
)
60 FPA11
*fpa11
= GET_FPA11();
63 fpa11
->fpcr
&= ~MASK_ROUNDING_MODE
;
65 switch (opcode
& MASK_ROUNDING_MODE
)
68 case ROUND_TO_NEAREST
:
69 rounding_mode
= float_round_nearest_even
;
71 fpa11
->fpcr
|= ROUND_TO_NEAREST
;
75 case ROUND_TO_PLUS_INFINITY
:
76 rounding_mode
= float_round_up
;
78 fpa11
->fpcr
|= ROUND_TO_PLUS_INFINITY
;
82 case ROUND_TO_MINUS_INFINITY
:
83 rounding_mode
= float_round_down
;
85 fpa11
->fpcr
|= ROUND_TO_MINUS_INFINITY
;
90 rounding_mode
= float_round_to_zero
;
92 fpa11
->fpcr
|= ROUND_TO_ZERO
;
96 set_float_rounding_mode(rounding_mode
, &fpa11
->fp_status
);
99 void SetRoundingPrecision(const unsigned int opcode
)
101 int rounding_precision
;
102 FPA11
*fpa11
= GET_FPA11();
104 fpa11
->fpcr
&= ~MASK_ROUNDING_PRECISION
;
106 switch (opcode
& MASK_ROUNDING_PRECISION
)
109 rounding_precision
= 32;
111 fpa11
->fpcr
|= ROUND_SINGLE
;
116 rounding_precision
= 64;
118 fpa11
->fpcr
|= ROUND_DOUBLE
;
123 rounding_precision
= 80;
125 fpa11
->fpcr
|= ROUND_EXTENDED
;
129 default: rounding_precision
= 80;
131 set_floatx80_rounding_precision(rounding_precision
, &fpa11
->fp_status
);
134 /* Emulate the instruction in the opcode. */
135 /* ??? This is not thread safe. */
136 unsigned int EmulateAll(unsigned int opcode
, FPA11
* qfpa
, CPUARMState
* qregs
)
138 unsigned int nRc
= 0;
139 // unsigned long flags;
141 // save_flags(flags); sti();
144 user_registers
=qregs
;
147 fprintf(stderr
,"emulating FP insn 0x%08x, PC=0x%08x\n",
148 opcode
, qregs
[REG_PC
]);
152 if (fpa11
->initflag
== 0) /* good place for __builtin_expect */
155 SetRoundingMode(ROUND_TO_NEAREST
);
156 SetRoundingPrecision(ROUND_EXTENDED
);
160 set_float_exception_flags(0, &fpa11
->fp_status
);
162 if (TEST_OPCODE(opcode
,MASK_CPRT
))
164 //fprintf(stderr,"emulating CPRT\n");
165 /* Emulate conversion opcodes. */
166 /* Emulate register transfer opcodes. */
167 /* Emulate comparison opcodes. */
168 nRc
= EmulateCPRT(opcode
);
170 else if (TEST_OPCODE(opcode
,MASK_CPDO
))
172 //fprintf(stderr,"emulating CPDO\n");
173 /* Emulate monadic arithmetic opcodes. */
174 /* Emulate dyadic arithmetic opcodes. */
175 nRc
= EmulateCPDO(opcode
);
177 else if (TEST_OPCODE(opcode
,MASK_CPDT
))
179 //fprintf(stderr,"emulating CPDT\n");
180 /* Emulate load/store opcodes. */
181 /* Emulate load/store multiple opcodes. */
182 nRc
= EmulateCPDT(opcode
);
186 /* Invalid instruction detected. Return FALSE. */
190 // restore_flags(flags);
191 if(nRc
== 1 && get_float_exception_flags(&fpa11
->fp_status
))
193 //printf("fef 0x%x\n",float_exception_flags);
194 nRc
=-get_float_exception_flags(&fpa11
->fp_status
);
197 //printf("returning %d\n",nRc);
202 unsigned int EmulateAll1(unsigned int opcode
)
204 switch ((opcode
>> 24) & 0xf)
208 if ((opcode
>> 20) & 0x1)
210 switch ((opcode
>> 8) & 0xf)
212 case 0x1: return PerformLDF(opcode
); break;
213 case 0x2: return PerformLFM(opcode
); break;
219 switch ((opcode
>> 8) & 0xf)
221 case 0x1: return PerformSTF(opcode
); break;
222 case 0x2: return PerformSFM(opcode
); break;
230 return EmulateCPDO(opcode
);
232 return EmulateCPRT(opcode
);