1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
NetWinder Floating Point Emulator
( c ) Rebel . COM , 1998 , 1999
Direct questions , comments to Scott Bambrough < scottb @ netwinder . org >
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc ., 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "fpa11.h"
# include "fpopcode.h"
// # include "fpmodule.h"
// # include "fpmodule.inl"
// # include < asm / system . h >
# include < stdio . h >
/* forward declarations */
unsigned int EmulateCPDO ( const unsigned int );
unsigned int EmulateCPDT ( const unsigned int );
unsigned int EmulateCPRT ( const unsigned int );
FPA11 * qemufpa = 0 ;
39
CPUARMState * user_registers ;
40
41
42
43
44
45
/* Reset the FPA11 chip. Called to initialize and reset the emulator. */
void resetFPA11 ( void )
{
int i ;
FPA11 * fpa11 = GET_FPA11 ();
ths
authored
17 years ago
46
47
48
49
50
51
/* initialize the register type array */
for ( i = 0 ; i <= 7 ; i ++ )
{
fpa11 -> fType [ i ] = typeNone ;
}
ths
authored
17 years ago
52
53
54
/* FPSR: set system id to FP_EMULATOR, set AC, clear all other bits */
fpa11 -> fpsr = FP_EMULATOR | BIT_AC ;
ths
authored
17 years ago
55
56
57
58
59
60
61
62
63
/* FPCR: set SB, AB and DA bits, clear all others */
# if MAINTAIN_FPCR
fpa11 -> fpcr = MASK_RESET ;
# endif
}
void SetRoundingMode ( const unsigned int opcode )
{
64
int rounding_mode ;
65
FPA11 * fpa11 = GET_FPA11 ();
66
67
# if MAINTAIN_FPCR
68
fpa11 -> fpcr &= ~ MASK_ROUNDING_MODE ;
ths
authored
17 years ago
69
# endif
70
71
72
73
switch ( opcode & MASK_ROUNDING_MODE )
{
default :
case ROUND_TO_NEAREST :
74
rounding_mode = float_round_nearest_even ;
ths
authored
17 years ago
75
# if MAINTAIN_FPCR
76
fpa11 -> fpcr |= ROUND_TO_NEAREST ;
ths
authored
17 years ago
77
# endif
78
break ;
ths
authored
17 years ago
79
80
case ROUND_TO_PLUS_INFINITY :
81
rounding_mode = float_round_up ;
ths
authored
17 years ago
82
# if MAINTAIN_FPCR
83
fpa11 -> fpcr |= ROUND_TO_PLUS_INFINITY ;
ths
authored
17 years ago
84
# endif
85
break ;
ths
authored
17 years ago
86
87
case ROUND_TO_MINUS_INFINITY :
88
rounding_mode = float_round_down ;
ths
authored
17 years ago
89
# if MAINTAIN_FPCR
90
fpa11 -> fpcr |= ROUND_TO_MINUS_INFINITY ;
ths
authored
17 years ago
91
# endif
92
break ;
ths
authored
17 years ago
93
94
case ROUND_TO_ZERO :
95
rounding_mode = float_round_to_zero ;
ths
authored
17 years ago
96
# if MAINTAIN_FPCR
97
fpa11 -> fpcr |= ROUND_TO_ZERO ;
ths
authored
17 years ago
98
# endif
99
100
break ;
}
101
set_float_rounding_mode ( rounding_mode , & fpa11 -> fp_status );
102
103
104
105
}
void SetRoundingPrecision ( const unsigned int opcode )
{
106
int rounding_precision ;
107
FPA11 * fpa11 = GET_FPA11 ();
108
# if MAINTAIN_FPCR
109
fpa11 -> fpcr &= ~ MASK_ROUNDING_PRECISION ;
ths
authored
17 years ago
110
# endif
111
112
113
switch ( opcode & MASK_ROUNDING_PRECISION )
{
case ROUND_SINGLE :
114
rounding_precision = 32 ;
ths
authored
17 years ago
115
# if MAINTAIN_FPCR
116
fpa11 -> fpcr |= ROUND_SINGLE ;
ths
authored
17 years ago
117
# endif
118
break ;
ths
authored
17 years ago
119
120
case ROUND_DOUBLE :
121
rounding_precision = 64 ;
ths
authored
17 years ago
122
# if MAINTAIN_FPCR
123
fpa11 -> fpcr |= ROUND_DOUBLE ;
ths
authored
17 years ago
124
# endif
125
break ;
ths
authored
17 years ago
126
127
case ROUND_EXTENDED :
128
rounding_precision = 80 ;
ths
authored
17 years ago
129
# if MAINTAIN_FPCR
130
fpa11 -> fpcr |= ROUND_EXTENDED ;
ths
authored
17 years ago
131
# endif
132
break ;
ths
authored
17 years ago
133
134
default : rounding_precision = 80 ;
135
}
136
set_floatx80_rounding_precision ( rounding_precision , & fpa11 -> fp_status );
137
138
139
}
/* Emulate the instruction in the opcode. */
140
141
/* ??? This is not thread safe. */
unsigned int EmulateAll ( unsigned int opcode , FPA11 * qfpa , CPUARMState * qregs )
142
143
144
{
unsigned int nRc = 0 ;
// unsigned long flags ;
ths
authored
17 years ago
145
FPA11 * fpa11 ;
146
147
148
149
// save_flags ( flags ); sti ();
qemufpa = qfpa ;
user_registers = qregs ;
ths
authored
17 years ago
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# if 0
fprintf ( stderr , "emulating FP insn 0x%08x, PC=0x%08x \n " ,
opcode , qregs [ REG_PC ]);
# endif
fpa11 = GET_FPA11 ();
if ( fpa11 -> initflag == 0 ) /* good place for __builtin_expect */
{
resetFPA11 ();
SetRoundingMode ( ROUND_TO_NEAREST );
SetRoundingPrecision ( ROUND_EXTENDED );
fpa11 -> initflag = 1 ;
}
165
166
set_float_exception_flags ( 0 , & fpa11 -> fp_status );
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
if ( TEST_OPCODE ( opcode , MASK_CPRT ))
{
// fprintf ( stderr , "emulating CPRT \n " );
/* Emulate conversion opcodes. */
/* Emulate register transfer opcodes. */
/* Emulate comparison opcodes. */
nRc = EmulateCPRT ( opcode );
}
else if ( TEST_OPCODE ( opcode , MASK_CPDO ))
{
// fprintf ( stderr , "emulating CPDO \n " );
/* Emulate monadic arithmetic opcodes. */
/* Emulate dyadic arithmetic opcodes. */
nRc = EmulateCPDO ( opcode );
}
else if ( TEST_OPCODE ( opcode , MASK_CPDT ))
{
// fprintf ( stderr , "emulating CPDT \n " );
/* Emulate load/store opcodes. */
/* Emulate load/store multiple opcodes. */
nRc = EmulateCPDT ( opcode );
}
else
{
/* Invalid instruction detected. Return FALSE. */
nRc = 0 ;
}
// restore_flags ( flags );
196
197
198
199
200
if ( nRc == 1 && get_float_exception_flags ( & fpa11 -> fp_status ))
{
// printf ( "fef 0x%x \n " , float_exception_flags );
nRc =- get_float_exception_flags ( & fpa11 -> fp_status );
}
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// printf ( "returning %d \n " , nRc );
return ( nRc );
}
# if 0
unsigned int EmulateAll1 ( unsigned int opcode )
{
switch (( opcode >> 24 ) & 0xf )
{
case 0xc :
case 0xd :
if (( opcode >> 20 ) & 0x1 )
{
switch (( opcode >> 8 ) & 0xf )
{
case 0x1 : return PerformLDF ( opcode ); break ;
case 0x2 : return PerformLFM ( opcode ); break ;
default : return 0 ;
}
}
else
{
switch (( opcode >> 8 ) & 0xf )
{
case 0x1 : return PerformSTF ( opcode ); break ;
case 0x2 : return PerformSFM ( opcode ); break ;
default : return 0 ;
}
}
break ;
ths
authored
17 years ago
232
ths
authored
17 years ago
233
case 0xe :
234
235
236
237
238
if ( opcode & 0x10 )
return EmulateCPDO ( opcode );
else
return EmulateCPRT ( opcode );
break ;
ths
authored
17 years ago
239
240
241
242
243
244
default : return 0 ;
}
}
# endif