2 NetWinder Floating Point Emulator
3 (c) Rebel.COM, 1998,1999
4 (c) Philip Blundell, 2001
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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include "fpmodule.inl"
29 #include <asm/system.h>
31 /* forward declarations */
32 unsigned int EmulateCPDO(const unsigned int);
33 unsigned int EmulateCPDT(const unsigned int);
34 unsigned int EmulateCPRT(const unsigned int);
36 /* Reset the FPA11 chip. Called to initialize and reset the emulator. */
40 FPA11 *fpa11 = GET_FPA11();
42 /* initialize the register type array */
43 for (i = 0; i <= 7; i++) {
44 fpa11->fType[i] = typeNone;
47 /* FPSR: set system id to FP_EMULATOR, set AC, clear all other bits */
48 fpa11->fpsr = FP_EMULATOR | BIT_AC;
51 void SetRoundingMode(const unsigned int opcode)
53 switch (opcode & MASK_ROUNDING_MODE) {
55 case ROUND_TO_NEAREST:
56 float_rounding_mode = float_round_nearest_even;
59 case ROUND_TO_PLUS_INFINITY:
60 float_rounding_mode = float_round_up;
63 case ROUND_TO_MINUS_INFINITY:
64 float_rounding_mode = float_round_down;
68 float_rounding_mode = float_round_to_zero;
73 void SetRoundingPrecision(const unsigned int opcode)
75 #ifdef CONFIG_FPE_NWFPE_XP
76 switch (opcode & MASK_ROUNDING_PRECISION) {
78 floatx80_rounding_precision = 32;
82 floatx80_rounding_precision = 64;
86 floatx80_rounding_precision = 80;
90 floatx80_rounding_precision = 80;
95 void nwfpe_init_fpa(void)
97 FPA11 *fpa11 = GET_FPA11();
99 printk("NWFPE: setting up state.\n");
102 SetRoundingMode(ROUND_TO_NEAREST);
103 SetRoundingPrecision(ROUND_EXTENDED);
107 /* Emulate the instruction in the opcode. */
108 unsigned int EmulateAll(const unsigned int opcode)
111 printk("NWFPE: emulating opcode %08x\n", opcode);
114 if (TEST_OPCODE(opcode, MASK_CPRT)) {
115 /* Emulate conversion opcodes. */
116 /* Emulate register transfer opcodes. */
117 /* Emulate comparison opcodes. */
118 return EmulateCPRT(opcode);
119 } else if (TEST_OPCODE(opcode, MASK_CPDO)) {
120 /* Emulate monadic arithmetic opcodes. */
121 /* Emulate dyadic arithmetic opcodes. */
122 return EmulateCPDO(opcode);
123 } else if (TEST_OPCODE(opcode, MASK_CPDT)) {
124 /* Emulate load/store opcodes. */
125 /* Emulate load/store multiple opcodes. */
126 return EmulateCPDT(opcode);
129 /* Invalid instruction detected. Return FALSE. */