blob: 7690f731ee8706227acdf3b1f56de14f2b906839 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 <linux/config.h>
30#include <linux/compiler.h>
31#include <linux/string.h>
32#include <asm/system.h>
33
34/* forward declarations */
35unsigned int EmulateCPDO(const unsigned int);
36unsigned int EmulateCPDT(const unsigned int);
37unsigned int EmulateCPRT(const unsigned int);
38
39/* Reset the FPA11 chip. Called to initialize and reset the emulator. */
40static void resetFPA11(void)
41{
42 int i;
43 FPA11 *fpa11 = GET_FPA11();
44
45 /* initialize the register type array */
46 for (i = 0; i <= 7; i++) {
47 fpa11->fType[i] = typeNone;
48 }
49
50 /* FPSR: set system id to FP_EMULATOR, set AC, clear all other bits */
51 fpa11->fpsr = FP_EMULATOR | BIT_AC;
52}
53
Richard Purdief148af22005-08-03 19:49:17 +010054int8 SetRoundingMode(const unsigned int opcode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
56 switch (opcode & MASK_ROUNDING_MODE) {
57 default:
58 case ROUND_TO_NEAREST:
Richard Purdief148af22005-08-03 19:49:17 +010059 return float_round_nearest_even;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 case ROUND_TO_PLUS_INFINITY:
Richard Purdief148af22005-08-03 19:49:17 +010062 return float_round_up;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64 case ROUND_TO_MINUS_INFINITY:
Richard Purdief148af22005-08-03 19:49:17 +010065 return float_round_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67 case ROUND_TO_ZERO:
Richard Purdief148af22005-08-03 19:49:17 +010068 return float_round_to_zero;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 }
70}
71
Richard Purdief148af22005-08-03 19:49:17 +010072int8 SetRoundingPrecision(const unsigned int opcode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
74#ifdef CONFIG_FPE_NWFPE_XP
75 switch (opcode & MASK_ROUNDING_PRECISION) {
76 case ROUND_SINGLE:
Richard Purdief148af22005-08-03 19:49:17 +010077 return 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79 case ROUND_DOUBLE:
Richard Purdief148af22005-08-03 19:49:17 +010080 return 64;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82 case ROUND_EXTENDED:
Richard Purdief148af22005-08-03 19:49:17 +010083 return 80;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85 default:
Richard Purdief148af22005-08-03 19:49:17 +010086 return 80;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
88#endif
Richard Purdief148af22005-08-03 19:49:17 +010089 return 80;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
92void nwfpe_init_fpa(union fp_state *fp)
93{
94 FPA11 *fpa11 = (FPA11 *)fp;
95#ifdef NWFPE_DEBUG
96 printk("NWFPE: setting up state.\n");
97#endif
98 memset(fpa11, 0, sizeof(FPA11));
99 resetFPA11();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 fpa11->initflag = 1;
101}
102
103/* Emulate the instruction in the opcode. */
104unsigned int EmulateAll(unsigned int opcode)
105{
106 unsigned int code;
107
108#ifdef NWFPE_DEBUG
109 printk("NWFPE: emulating opcode %08x\n", opcode);
110#endif
111 code = opcode & 0x00000f00;
112 if (code == 0x00000100 || code == 0x00000200) {
113 /* For coprocessor 1 or 2 (FPA11) */
114 code = opcode & 0x0e000000;
115 if (code == 0x0e000000) {
116 if (opcode & 0x00000010) {
117 /* Emulate conversion opcodes. */
118 /* Emulate register transfer opcodes. */
119 /* Emulate comparison opcodes. */
120 return EmulateCPRT(opcode);
121 } else {
122 /* Emulate monadic arithmetic opcodes. */
123 /* Emulate dyadic arithmetic opcodes. */
124 return EmulateCPDO(opcode);
125 }
126 } else if (code == 0x0c000000) {
127 /* Emulate load/store opcodes. */
128 /* Emulate load/store multiple opcodes. */
129 return EmulateCPDT(opcode);
130 }
131 }
132
133 /* Invalid instruction detected. Return FALSE. */
134 return 0;
135}