Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/compiler.h> |
| 30 | #include <linux/string.h> |
| 31 | #include <asm/system.h> |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | /* Reset the FPA11 chip. Called to initialize and reset the emulator. */ |
| 34 | static void resetFPA11(void) |
| 35 | { |
| 36 | int i; |
| 37 | FPA11 *fpa11 = GET_FPA11(); |
| 38 | |
| 39 | /* initialize the register type array */ |
| 40 | for (i = 0; i <= 7; i++) { |
| 41 | fpa11->fType[i] = typeNone; |
| 42 | } |
| 43 | |
| 44 | /* FPSR: set system id to FP_EMULATOR, set AC, clear all other bits */ |
| 45 | fpa11->fpsr = FP_EMULATOR | BIT_AC; |
| 46 | } |
| 47 | |
Richard Purdie | f148af2 | 2005-08-03 19:49:17 +0100 | [diff] [blame] | 48 | int8 SetRoundingMode(const unsigned int opcode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
| 50 | switch (opcode & MASK_ROUNDING_MODE) { |
| 51 | default: |
| 52 | case ROUND_TO_NEAREST: |
Richard Purdie | f148af2 | 2005-08-03 19:49:17 +0100 | [diff] [blame] | 53 | return float_round_nearest_even; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | case ROUND_TO_PLUS_INFINITY: |
Richard Purdie | f148af2 | 2005-08-03 19:49:17 +0100 | [diff] [blame] | 56 | return float_round_up; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | case ROUND_TO_MINUS_INFINITY: |
Richard Purdie | f148af2 | 2005-08-03 19:49:17 +0100 | [diff] [blame] | 59 | return float_round_down; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
| 61 | case ROUND_TO_ZERO: |
Richard Purdie | f148af2 | 2005-08-03 19:49:17 +0100 | [diff] [blame] | 62 | return float_round_to_zero; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
Richard Purdie | f148af2 | 2005-08-03 19:49:17 +0100 | [diff] [blame] | 66 | int8 SetRoundingPrecision(const unsigned int opcode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
| 68 | #ifdef CONFIG_FPE_NWFPE_XP |
| 69 | switch (opcode & MASK_ROUNDING_PRECISION) { |
| 70 | case ROUND_SINGLE: |
Richard Purdie | f148af2 | 2005-08-03 19:49:17 +0100 | [diff] [blame] | 71 | return 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | case ROUND_DOUBLE: |
Richard Purdie | f148af2 | 2005-08-03 19:49:17 +0100 | [diff] [blame] | 74 | return 64; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | case ROUND_EXTENDED: |
Richard Purdie | f148af2 | 2005-08-03 19:49:17 +0100 | [diff] [blame] | 77 | return 80; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | default: |
Richard Purdie | f148af2 | 2005-08-03 19:49:17 +0100 | [diff] [blame] | 80 | return 80; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
| 82 | #endif |
Richard Purdie | f148af2 | 2005-08-03 19:49:17 +0100 | [diff] [blame] | 83 | return 80; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void nwfpe_init_fpa(union fp_state *fp) |
| 87 | { |
| 88 | FPA11 *fpa11 = (FPA11 *)fp; |
| 89 | #ifdef NWFPE_DEBUG |
| 90 | printk("NWFPE: setting up state.\n"); |
| 91 | #endif |
| 92 | memset(fpa11, 0, sizeof(FPA11)); |
| 93 | resetFPA11(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | fpa11->initflag = 1; |
| 95 | } |
| 96 | |
| 97 | /* Emulate the instruction in the opcode. */ |
| 98 | unsigned int EmulateAll(unsigned int opcode) |
| 99 | { |
| 100 | unsigned int code; |
| 101 | |
| 102 | #ifdef NWFPE_DEBUG |
| 103 | printk("NWFPE: emulating opcode %08x\n", opcode); |
| 104 | #endif |
| 105 | code = opcode & 0x00000f00; |
| 106 | if (code == 0x00000100 || code == 0x00000200) { |
| 107 | /* For coprocessor 1 or 2 (FPA11) */ |
| 108 | code = opcode & 0x0e000000; |
| 109 | if (code == 0x0e000000) { |
| 110 | if (opcode & 0x00000010) { |
| 111 | /* Emulate conversion opcodes. */ |
| 112 | /* Emulate register transfer opcodes. */ |
| 113 | /* Emulate comparison opcodes. */ |
| 114 | return EmulateCPRT(opcode); |
| 115 | } else { |
| 116 | /* Emulate monadic arithmetic opcodes. */ |
| 117 | /* Emulate dyadic arithmetic opcodes. */ |
| 118 | return EmulateCPDO(opcode); |
| 119 | } |
| 120 | } else if (code == 0x0c000000) { |
| 121 | /* Emulate load/store opcodes. */ |
| 122 | /* Emulate load/store multiple opcodes. */ |
| 123 | return EmulateCPDT(opcode); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /* Invalid instruction detected. Return FALSE. */ |
| 128 | return 0; |
| 129 | } |