Linux 2.6.13-rc4
[linux-2.6/next.git] / arch / arm / nwfpe / fpa11.c
blobbf61696865ec2c6531007d6eaa6aedd6c6bf8850
1 /*
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.
23 #include "fpa11.h"
24 #include "fpopcode.h"
26 #include "fpmodule.h"
27 #include "fpmodule.inl"
29 #include <linux/config.h>
30 #include <linux/compiler.h>
31 #include <linux/string.h>
32 #include <asm/system.h>
34 /* forward declarations */
35 unsigned int EmulateCPDO(const unsigned int);
36 unsigned int EmulateCPDT(const unsigned int);
37 unsigned int EmulateCPRT(const unsigned int);
39 /* Reset the FPA11 chip. Called to initialize and reset the emulator. */
40 static void resetFPA11(void)
42 int i;
43 FPA11 *fpa11 = GET_FPA11();
45 /* initialize the register type array */
46 for (i = 0; i <= 7; i++) {
47 fpa11->fType[i] = typeNone;
50 /* FPSR: set system id to FP_EMULATOR, set AC, clear all other bits */
51 fpa11->fpsr = FP_EMULATOR | BIT_AC;
54 void SetRoundingMode(const unsigned int opcode)
56 switch (opcode & MASK_ROUNDING_MODE) {
57 default:
58 case ROUND_TO_NEAREST:
59 float_rounding_mode = float_round_nearest_even;
60 break;
62 case ROUND_TO_PLUS_INFINITY:
63 float_rounding_mode = float_round_up;
64 break;
66 case ROUND_TO_MINUS_INFINITY:
67 float_rounding_mode = float_round_down;
68 break;
70 case ROUND_TO_ZERO:
71 float_rounding_mode = float_round_to_zero;
72 break;
76 void SetRoundingPrecision(const unsigned int opcode)
78 #ifdef CONFIG_FPE_NWFPE_XP
79 switch (opcode & MASK_ROUNDING_PRECISION) {
80 case ROUND_SINGLE:
81 floatx80_rounding_precision = 32;
82 break;
84 case ROUND_DOUBLE:
85 floatx80_rounding_precision = 64;
86 break;
88 case ROUND_EXTENDED:
89 floatx80_rounding_precision = 80;
90 break;
92 default:
93 floatx80_rounding_precision = 80;
95 #endif
98 void nwfpe_init_fpa(union fp_state *fp)
100 FPA11 *fpa11 = (FPA11 *)fp;
101 #ifdef NWFPE_DEBUG
102 printk("NWFPE: setting up state.\n");
103 #endif
104 memset(fpa11, 0, sizeof(FPA11));
105 resetFPA11();
106 SetRoundingMode(ROUND_TO_NEAREST);
107 SetRoundingPrecision(ROUND_EXTENDED);
108 fpa11->initflag = 1;
111 /* Emulate the instruction in the opcode. */
112 unsigned int EmulateAll(unsigned int opcode)
114 unsigned int code;
116 #ifdef NWFPE_DEBUG
117 printk("NWFPE: emulating opcode %08x\n", opcode);
118 #endif
119 code = opcode & 0x00000f00;
120 if (code == 0x00000100 || code == 0x00000200) {
121 /* For coprocessor 1 or 2 (FPA11) */
122 code = opcode & 0x0e000000;
123 if (code == 0x0e000000) {
124 if (opcode & 0x00000010) {
125 /* Emulate conversion opcodes. */
126 /* Emulate register transfer opcodes. */
127 /* Emulate comparison opcodes. */
128 return EmulateCPRT(opcode);
129 } else {
130 /* Emulate monadic arithmetic opcodes. */
131 /* Emulate dyadic arithmetic opcodes. */
132 return EmulateCPDO(opcode);
134 } else if (code == 0x0c000000) {
135 /* Emulate load/store opcodes. */
136 /* Emulate load/store multiple opcodes. */
137 return EmulateCPDT(opcode);
141 /* Invalid instruction detected. Return FALSE. */
142 return 0;