2004-02-17 00:43:58 +03:00
|
|
|
/*
|
|
|
|
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
|
2010-03-07 18:48:43 +03:00
|
|
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2004-02-17 00:43:58 +03:00
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:02 +03:00
|
|
|
#include "qemu/osdep.h"
|
2004-02-17 00:43:58 +03:00
|
|
|
#include "fpa11.h"
|
|
|
|
|
|
|
|
#include "fpopcode.h"
|
|
|
|
|
|
|
|
//#include "fpmodule.h"
|
|
|
|
//#include "fpmodule.inl"
|
|
|
|
|
|
|
|
//#include <asm/system.h>
|
|
|
|
|
|
|
|
|
2009-09-21 22:11:34 +04:00
|
|
|
FPA11* qemufpa = NULL;
|
2006-03-12 00:03:16 +03:00
|
|
|
CPUARMState* user_registers;
|
2004-02-17 00:43:58 +03:00
|
|
|
|
|
|
|
/* Reset the FPA11 chip. Called to initialize and reset the emulator. */
|
|
|
|
void resetFPA11(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FPA11 *fpa11 = GET_FPA11();
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-02-17 00:43:58 +03:00
|
|
|
/* initialize the register type array */
|
|
|
|
for (i=0;i<=7;i++)
|
|
|
|
{
|
|
|
|
fpa11->fType[i] = typeNone;
|
|
|
|
}
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-02-17 00:43:58 +03:00
|
|
|
/* FPSR: set system id to FP_EMULATOR, set AC, clear all other bits */
|
|
|
|
fpa11->fpsr = FP_EMULATOR | BIT_AC;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-02-17 00:43:58 +03:00
|
|
|
/* FPCR: set SB, AB and DA bits, clear all others */
|
2008-09-06 21:47:39 +04:00
|
|
|
#ifdef MAINTAIN_FPCR
|
2004-02-17 00:43:58 +03:00
|
|
|
fpa11->fpcr = MASK_RESET;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetRoundingMode(const unsigned int opcode)
|
|
|
|
{
|
2005-03-13 19:55:58 +03:00
|
|
|
int rounding_mode;
|
2004-02-17 00:43:58 +03:00
|
|
|
FPA11 *fpa11 = GET_FPA11();
|
2005-03-13 19:55:58 +03:00
|
|
|
|
2008-09-06 21:47:39 +04:00
|
|
|
#ifdef MAINTAIN_FPCR
|
2004-02-17 00:43:58 +03:00
|
|
|
fpa11->fpcr &= ~MASK_ROUNDING_MODE;
|
2007-09-17 12:09:54 +04:00
|
|
|
#endif
|
2004-02-17 00:43:58 +03:00
|
|
|
switch (opcode & MASK_ROUNDING_MODE)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case ROUND_TO_NEAREST:
|
2005-03-13 19:55:58 +03:00
|
|
|
rounding_mode = float_round_nearest_even;
|
2008-09-06 21:47:39 +04:00
|
|
|
#ifdef MAINTAIN_FPCR
|
2004-02-17 00:43:58 +03:00
|
|
|
fpa11->fpcr |= ROUND_TO_NEAREST;
|
2007-09-17 12:09:54 +04:00
|
|
|
#endif
|
2004-02-17 00:43:58 +03:00
|
|
|
break;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-02-17 00:43:58 +03:00
|
|
|
case ROUND_TO_PLUS_INFINITY:
|
2005-03-13 19:55:58 +03:00
|
|
|
rounding_mode = float_round_up;
|
2008-09-06 21:47:39 +04:00
|
|
|
#ifdef MAINTAIN_FPCR
|
2004-02-17 00:43:58 +03:00
|
|
|
fpa11->fpcr |= ROUND_TO_PLUS_INFINITY;
|
2007-09-17 12:09:54 +04:00
|
|
|
#endif
|
2004-02-17 00:43:58 +03:00
|
|
|
break;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-02-17 00:43:58 +03:00
|
|
|
case ROUND_TO_MINUS_INFINITY:
|
2005-03-13 19:55:58 +03:00
|
|
|
rounding_mode = float_round_down;
|
2008-09-06 21:47:39 +04:00
|
|
|
#ifdef MAINTAIN_FPCR
|
2004-02-17 00:43:58 +03:00
|
|
|
fpa11->fpcr |= ROUND_TO_MINUS_INFINITY;
|
2007-09-17 12:09:54 +04:00
|
|
|
#endif
|
2004-02-17 00:43:58 +03:00
|
|
|
break;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-02-17 00:43:58 +03:00
|
|
|
case ROUND_TO_ZERO:
|
2005-03-13 19:55:58 +03:00
|
|
|
rounding_mode = float_round_to_zero;
|
2008-09-06 21:47:39 +04:00
|
|
|
#ifdef MAINTAIN_FPCR
|
2004-02-17 00:43:58 +03:00
|
|
|
fpa11->fpcr |= ROUND_TO_ZERO;
|
2007-09-17 12:09:54 +04:00
|
|
|
#endif
|
2004-02-17 00:43:58 +03:00
|
|
|
break;
|
|
|
|
}
|
2005-03-13 19:55:58 +03:00
|
|
|
set_float_rounding_mode(rounding_mode, &fpa11->fp_status);
|
2004-02-17 00:43:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetRoundingPrecision(const unsigned int opcode)
|
|
|
|
{
|
2005-03-13 19:55:58 +03:00
|
|
|
int rounding_precision;
|
2004-02-17 00:43:58 +03:00
|
|
|
FPA11 *fpa11 = GET_FPA11();
|
2008-09-06 21:47:39 +04:00
|
|
|
#ifdef MAINTAIN_FPCR
|
2004-02-17 00:43:58 +03:00
|
|
|
fpa11->fpcr &= ~MASK_ROUNDING_PRECISION;
|
2007-09-17 12:09:54 +04:00
|
|
|
#endif
|
2004-02-17 00:43:58 +03:00
|
|
|
switch (opcode & MASK_ROUNDING_PRECISION)
|
|
|
|
{
|
|
|
|
case ROUND_SINGLE:
|
2005-03-13 19:55:58 +03:00
|
|
|
rounding_precision = 32;
|
2008-09-06 21:47:39 +04:00
|
|
|
#ifdef MAINTAIN_FPCR
|
2004-02-17 00:43:58 +03:00
|
|
|
fpa11->fpcr |= ROUND_SINGLE;
|
2007-09-17 12:09:54 +04:00
|
|
|
#endif
|
2004-02-17 00:43:58 +03:00
|
|
|
break;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-02-17 00:43:58 +03:00
|
|
|
case ROUND_DOUBLE:
|
2005-03-13 19:55:58 +03:00
|
|
|
rounding_precision = 64;
|
2008-09-06 21:47:39 +04:00
|
|
|
#ifdef MAINTAIN_FPCR
|
2004-02-17 00:43:58 +03:00
|
|
|
fpa11->fpcr |= ROUND_DOUBLE;
|
2007-09-17 12:09:54 +04:00
|
|
|
#endif
|
2004-02-17 00:43:58 +03:00
|
|
|
break;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-02-17 00:43:58 +03:00
|
|
|
case ROUND_EXTENDED:
|
2005-03-13 19:55:58 +03:00
|
|
|
rounding_precision = 80;
|
2008-09-06 21:47:39 +04:00
|
|
|
#ifdef MAINTAIN_FPCR
|
2004-02-17 00:43:58 +03:00
|
|
|
fpa11->fpcr |= ROUND_EXTENDED;
|
2007-09-17 12:09:54 +04:00
|
|
|
#endif
|
2004-02-17 00:43:58 +03:00
|
|
|
break;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2005-03-13 19:55:58 +03:00
|
|
|
default: rounding_precision = 80;
|
2004-02-17 00:43:58 +03:00
|
|
|
}
|
2005-03-13 19:55:58 +03:00
|
|
|
set_floatx80_rounding_precision(rounding_precision, &fpa11->fp_status);
|
2004-02-17 00:43:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Emulate the instruction in the opcode. */
|
2006-03-12 00:03:16 +03:00
|
|
|
/* ??? This is not thread safe. */
|
|
|
|
unsigned int EmulateAll(unsigned int opcode, FPA11* qfpa, CPUARMState* qregs)
|
2004-02-17 00:43:58 +03:00
|
|
|
{
|
|
|
|
unsigned int nRc = 0;
|
|
|
|
// unsigned long flags;
|
2007-09-17 01:08:06 +04:00
|
|
|
FPA11 *fpa11;
|
2018-01-11 16:25:39 +03:00
|
|
|
unsigned int cp;
|
2004-02-17 00:43:58 +03:00
|
|
|
// save_flags(flags); sti();
|
|
|
|
|
2018-01-11 16:25:39 +03:00
|
|
|
/* Check that this is really an FPA11 instruction: the coprocessor
|
|
|
|
* field in bits [11:8] must be 1 or 2.
|
|
|
|
*/
|
|
|
|
cp = (opcode >> 8) & 0xf;
|
|
|
|
if (cp != 1 && cp != 2) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-02-17 00:43:58 +03:00
|
|
|
qemufpa=qfpa;
|
|
|
|
user_registers=qregs;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-02-17 00:43:58 +03:00
|
|
|
#if 0
|
|
|
|
fprintf(stderr,"emulating FP insn 0x%08x, PC=0x%08x\n",
|
2011-04-20 14:19:15 +04:00
|
|
|
opcode, qregs[ARM_REG_PC]);
|
2004-02-17 00:43:58 +03:00
|
|
|
#endif
|
|
|
|
fpa11 = GET_FPA11();
|
|
|
|
|
|
|
|
if (fpa11->initflag == 0) /* good place for __builtin_expect */
|
|
|
|
{
|
|
|
|
resetFPA11();
|
|
|
|
SetRoundingMode(ROUND_TO_NEAREST);
|
|
|
|
SetRoundingPrecision(ROUND_EXTENDED);
|
|
|
|
fpa11->initflag = 1;
|
|
|
|
}
|
|
|
|
|
2008-04-08 00:30:53 +04:00
|
|
|
set_float_exception_flags(0, &fpa11->fp_status);
|
|
|
|
|
2004-02-17 00:43:58 +03:00
|
|
|
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);
|
2008-04-08 00:30:53 +04:00
|
|
|
if(nRc == 1 && get_float_exception_flags(&fpa11->fp_status))
|
|
|
|
{
|
|
|
|
//printf("fef 0x%x\n",float_exception_flags);
|
2009-10-02 21:59:12 +04:00
|
|
|
nRc = -get_float_exception_flags(&fpa11->fp_status);
|
2008-04-08 00:30:53 +04:00
|
|
|
}
|
2004-02-17 00:43:58 +03:00
|
|
|
|
|
|
|
//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;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
case 0xe:
|
2004-02-17 00:43:58 +03:00
|
|
|
if (opcode & 0x10)
|
|
|
|
return EmulateCPDO(opcode);
|
|
|
|
else
|
|
|
|
return EmulateCPRT(opcode);
|
|
|
|
break;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-02-17 00:43:58 +03:00
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|