1 /*
2 NetWinder Floating Point Emulator
3 (c) Rebel.COM, 1998,1999
4 (c) Philip Blundell, 2001
5
6 Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
7
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.
12
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.
17
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.
21 */
22
23 #include "fpa11.h"
24 #include "fpopcode.h"
25
26 #include "fpmodule.h"
27 #include "fpmodule.inl"
28
29 #include <asm/system.h>
30
31 /* forward declarations */
32 unsigned int EmulateCPDO(const unsigned int);
33 unsigned int EmulateCPDT(const unsigned int);
34 unsigned int EmulateCPRT(const unsigned int);
35
36 /* Reset the FPA11 chip. Called to initialize and reset the emulator. */
resetFPA11(void)37 void resetFPA11(void)
38 {
39 int i;
40 FPA11 *fpa11 = GET_FPA11();
41
42 /* initialize the register type array */
43 for (i = 0; i <= 7; i++) {
44 fpa11->fType[i] = typeNone;
45 }
46
47 /* FPSR: set system id to FP_EMULATOR, set AC, clear all other bits */
48 fpa11->fpsr = FP_EMULATOR | BIT_AC;
49 }
50
SetRoundingMode(const unsigned int opcode)51 void SetRoundingMode(const unsigned int opcode)
52 {
53 switch (opcode & MASK_ROUNDING_MODE) {
54 default:
55 case ROUND_TO_NEAREST:
56 float_rounding_mode = float_round_nearest_even;
57 break;
58
59 case ROUND_TO_PLUS_INFINITY:
60 float_rounding_mode = float_round_up;
61 break;
62
63 case ROUND_TO_MINUS_INFINITY:
64 float_rounding_mode = float_round_down;
65 break;
66
67 case ROUND_TO_ZERO:
68 float_rounding_mode = float_round_to_zero;
69 break;
70 }
71 }
72
SetRoundingPrecision(const unsigned int opcode)73 void SetRoundingPrecision(const unsigned int opcode)
74 {
75 #ifdef CONFIG_FPE_NWFPE_XP
76 switch (opcode & MASK_ROUNDING_PRECISION) {
77 case ROUND_SINGLE:
78 floatx80_rounding_precision = 32;
79 break;
80
81 case ROUND_DOUBLE:
82 floatx80_rounding_precision = 64;
83 break;
84
85 case ROUND_EXTENDED:
86 floatx80_rounding_precision = 80;
87 break;
88
89 default:
90 floatx80_rounding_precision = 80;
91 }
92 #endif
93 }
94
nwfpe_init_fpa(void)95 void nwfpe_init_fpa(void)
96 {
97 FPA11 *fpa11 = GET_FPA11();
98 #ifdef NWFPE_DEBUG
99 printk("NWFPE: setting up state.\n");
100 #endif
101 resetFPA11();
102 SetRoundingMode(ROUND_TO_NEAREST);
103 SetRoundingPrecision(ROUND_EXTENDED);
104 fpa11->initflag = 1;
105 }
106
107 /* Emulate the instruction in the opcode. */
EmulateAll(const unsigned int opcode)108 unsigned int EmulateAll(const unsigned int opcode)
109 {
110 #ifdef NWFPE_DEBUG
111 printk("NWFPE: emulating opcode %08x\n", opcode);
112 #endif
113
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);
127 }
128
129 /* Invalid instruction detected. Return FALSE. */
130 return 0;
131 }
132