diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/arm/nwfpe/fpmodule.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'arch/arm/nwfpe/fpmodule.c')
-rw-r--r-- | arch/arm/nwfpe/fpmodule.c | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/arch/arm/nwfpe/fpmodule.c b/arch/arm/nwfpe/fpmodule.c new file mode 100644 index 000000000000..a806fea5c3ed --- /dev/null +++ b/arch/arm/nwfpe/fpmodule.c | |||
@@ -0,0 +1,173 @@ | |||
1 | |||
2 | /* | ||
3 | NetWinder Floating Point Emulator | ||
4 | (c) Rebel.com, 1998-1999 | ||
5 | (c) Philip Blundell, 1998-1999 | ||
6 | |||
7 | Direct questions, comments to Scott Bambrough <scottb@netwinder.org> | ||
8 | |||
9 | This program is free software; you can redistribute it and/or modify | ||
10 | it under the terms of the GNU General Public License as published by | ||
11 | the Free Software Foundation; either version 2 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | This program is distributed in the hope that it will be useful, | ||
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | GNU General Public License for more details. | ||
18 | |||
19 | You should have received a copy of the GNU General Public License | ||
20 | along with this program; if not, write to the Free Software | ||
21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | */ | ||
23 | |||
24 | #include "fpa11.h" | ||
25 | |||
26 | #include <linux/module.h> | ||
27 | #include <linux/version.h> | ||
28 | #include <linux/config.h> | ||
29 | |||
30 | /* XXX */ | ||
31 | #include <linux/errno.h> | ||
32 | #include <linux/types.h> | ||
33 | #include <linux/kernel.h> | ||
34 | #include <linux/signal.h> | ||
35 | #include <linux/sched.h> | ||
36 | #include <linux/init.h> | ||
37 | /* XXX */ | ||
38 | |||
39 | #include "softfloat.h" | ||
40 | #include "fpopcode.h" | ||
41 | #include "fpmodule.h" | ||
42 | #include "fpa11.inl" | ||
43 | |||
44 | /* kernel symbols required for signal handling */ | ||
45 | #ifdef CONFIG_FPE_NWFPE_XP | ||
46 | #define NWFPE_BITS "extended" | ||
47 | #else | ||
48 | #define NWFPE_BITS "double" | ||
49 | #endif | ||
50 | |||
51 | #ifdef MODULE | ||
52 | void fp_send_sig(unsigned long sig, struct task_struct *p, int priv); | ||
53 | #else | ||
54 | #define fp_send_sig send_sig | ||
55 | #define kern_fp_enter fp_enter | ||
56 | |||
57 | extern char fpe_type[]; | ||
58 | #endif | ||
59 | |||
60 | /* kernel function prototypes required */ | ||
61 | void fp_setup(void); | ||
62 | |||
63 | /* external declarations for saved kernel symbols */ | ||
64 | extern void (*kern_fp_enter)(void); | ||
65 | extern void (*fp_init)(union fp_state *); | ||
66 | |||
67 | /* Original value of fp_enter from kernel before patched by fpe_init. */ | ||
68 | static void (*orig_fp_enter)(void); | ||
69 | static void (*orig_fp_init)(union fp_state *); | ||
70 | |||
71 | /* forward declarations */ | ||
72 | extern void nwfpe_enter(void); | ||
73 | |||
74 | static int __init fpe_init(void) | ||
75 | { | ||
76 | if (sizeof(FPA11) > sizeof(union fp_state)) { | ||
77 | printk(KERN_ERR "nwfpe: bad structure size\n"); | ||
78 | return -EINVAL; | ||
79 | } | ||
80 | |||
81 | if (sizeof(FPREG) != 12) { | ||
82 | printk(KERN_ERR "nwfpe: bad register size\n"); | ||
83 | return -EINVAL; | ||
84 | } | ||
85 | if (fpe_type[0] && strcmp(fpe_type, "nwfpe")) | ||
86 | return 0; | ||
87 | |||
88 | /* Display title, version and copyright information. */ | ||
89 | printk(KERN_WARNING "NetWinder Floating Point Emulator V0.97 (" | ||
90 | NWFPE_BITS " precision)\n"); | ||
91 | |||
92 | /* Save pointer to the old FP handler and then patch ourselves in */ | ||
93 | orig_fp_enter = kern_fp_enter; | ||
94 | orig_fp_init = fp_init; | ||
95 | kern_fp_enter = nwfpe_enter; | ||
96 | fp_init = nwfpe_init_fpa; | ||
97 | |||
98 | return 0; | ||
99 | } | ||
100 | |||
101 | static void __exit fpe_exit(void) | ||
102 | { | ||
103 | /* Restore the values we saved earlier. */ | ||
104 | kern_fp_enter = orig_fp_enter; | ||
105 | fp_init = orig_fp_init; | ||
106 | } | ||
107 | |||
108 | /* | ||
109 | ScottB: November 4, 1998 | ||
110 | |||
111 | Moved this function out of softfloat-specialize into fpmodule.c. | ||
112 | This effectively isolates all the changes required for integrating with the | ||
113 | Linux kernel into fpmodule.c. Porting to NetBSD should only require modifying | ||
114 | fpmodule.c to integrate with the NetBSD kernel (I hope!). | ||
115 | |||
116 | [1/1/99: Not quite true any more unfortunately. There is Linux-specific | ||
117 | code to access data in user space in some other source files at the | ||
118 | moment (grep for get_user / put_user calls). --philb] | ||
119 | |||
120 | float_exception_flags is a global variable in SoftFloat. | ||
121 | |||
122 | This function is called by the SoftFloat routines to raise a floating | ||
123 | point exception. We check the trap enable byte in the FPSR, and raise | ||
124 | a SIGFPE exception if necessary. If not the relevant bits in the | ||
125 | cumulative exceptions flag byte are set and we return. | ||
126 | */ | ||
127 | |||
128 | void float_raise(signed char flags) | ||
129 | { | ||
130 | register unsigned int fpsr, cumulativeTraps; | ||
131 | |||
132 | #ifdef CONFIG_DEBUG_USER | ||
133 | printk(KERN_DEBUG | ||
134 | "NWFPE: %s[%d] takes exception %08x at %p from %08lx\n", | ||
135 | current->comm, current->pid, flags, | ||
136 | __builtin_return_address(0), GET_USERREG()[15]); | ||
137 | #endif | ||
138 | |||
139 | /* Keep SoftFloat exception flags up to date. */ | ||
140 | float_exception_flags |= flags; | ||
141 | |||
142 | /* Read fpsr and initialize the cumulativeTraps. */ | ||
143 | fpsr = readFPSR(); | ||
144 | cumulativeTraps = 0; | ||
145 | |||
146 | /* For each type of exception, the cumulative trap exception bit is only | ||
147 | set if the corresponding trap enable bit is not set. */ | ||
148 | if ((!(fpsr & BIT_IXE)) && (flags & BIT_IXC)) | ||
149 | cumulativeTraps |= BIT_IXC; | ||
150 | if ((!(fpsr & BIT_UFE)) && (flags & BIT_UFC)) | ||
151 | cumulativeTraps |= BIT_UFC; | ||
152 | if ((!(fpsr & BIT_OFE)) && (flags & BIT_OFC)) | ||
153 | cumulativeTraps |= BIT_OFC; | ||
154 | if ((!(fpsr & BIT_DZE)) && (flags & BIT_DZC)) | ||
155 | cumulativeTraps |= BIT_DZC; | ||
156 | if ((!(fpsr & BIT_IOE)) && (flags & BIT_IOC)) | ||
157 | cumulativeTraps |= BIT_IOC; | ||
158 | |||
159 | /* Set the cumulative exceptions flags. */ | ||
160 | if (cumulativeTraps) | ||
161 | writeFPSR(fpsr | cumulativeTraps); | ||
162 | |||
163 | /* Raise an exception if necessary. */ | ||
164 | if (fpsr & (flags << 16)) | ||
165 | fp_send_sig(SIGFPE, current, 1); | ||
166 | } | ||
167 | |||
168 | module_init(fpe_init); | ||
169 | module_exit(fpe_exit); | ||
170 | |||
171 | MODULE_AUTHOR("Scott Bambrough <scottb@rebel.com>"); | ||
172 | MODULE_DESCRIPTION("NWFPE floating point emulator (" NWFPE_BITS " precision)"); | ||
173 | MODULE_LICENSE("GPL"); | ||