Ok. I didn't make 2.4.0 in 2000. Tough. I tried, but we had some
[davej-history.git] / arch / arm / nwfpe / fpmodule.c
blob24fa2775f0a004075889139f34ca937d81691df4
2 /*
3 NetWinder Floating Point Emulator
4 (c) Rebel.com, 1998-1999
5 (c) Philip Blundell, 1998-1999
7 Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
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.
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.
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.
24 #include <linux/module.h>
25 #include <linux/version.h>
26 #include <linux/config.h>
28 /* XXX */
29 #include <linux/types.h>
30 #include <linux/kernel.h>
31 #include <linux/signal.h>
32 #include <linux/sched.h>
33 #include <linux/init.h>
34 /* XXX */
36 #include "softfloat.h"
37 #include "fpopcode.h"
38 #include "fpmodule.h"
39 #include "fpa11.h"
40 #include "fpa11.inl"
42 /* external data */
43 extern FPA11 *fpa11;
45 /* kernel symbols required for signal handling */
46 typedef struct task_struct* PTASK;
48 #ifdef MODULE
49 void fp_send_sig(unsigned long sig, PTASK p, int priv);
50 #if LINUX_VERSION_CODE > 0x20115
51 MODULE_AUTHOR("Scott Bambrough <scottb@rebel.com>");
52 MODULE_DESCRIPTION("NWFPE floating point emulator");
53 #endif
55 #else
56 #define fp_send_sig send_sig
57 #define kern_fp_enter fp_enter
58 #endif
60 /* kernel function prototypes required */
61 void fp_setup(void);
63 /* external declarations for saved kernel symbols */
64 extern void (*kern_fp_enter)(void);
66 /* Original value of fp_enter from kernel before patched by fpe_init. */
67 static void (*orig_fp_enter)(void);
69 /* forward declarations */
70 extern void nwfpe_enter(void);
72 /* Address of user registers on the kernel stack. */
73 unsigned int *userRegisters;
75 int __init fpe_init(void)
77 if (sizeof(FPA11) > sizeof(union fp_state))
78 printk(KERN_ERR "nwfpe: bad structure size\n");
79 else {
80 /* Display title, version and copyright information. */
81 printk(KERN_WARNING "NetWinder Floating Point Emulator V0.95 "
82 "(c) 1998-1999 Rebel.com\n");
84 /* Save pointer to the old FP handler and then patch ourselves in */
85 orig_fp_enter = kern_fp_enter;
86 kern_fp_enter = nwfpe_enter;
89 return 0;
92 void __exit fpe_exit(void)
94 /* Restore the values we saved earlier. */
95 kern_fp_enter = orig_fp_enter;
99 ScottB: November 4, 1998
101 Moved this function out of softfloat-specialize into fpmodule.c.
102 This effectively isolates all the changes required for integrating with the
103 Linux kernel into fpmodule.c. Porting to NetBSD should only require modifying
104 fpmodule.c to integrate with the NetBSD kernel (I hope!).
106 [1/1/99: Not quite true any more unfortunately. There is Linux-specific
107 code to access data in user space in some other source files at the
108 moment (grep for get_user / put_user calls). --philb]
110 float_exception_flags is a global variable in SoftFloat.
112 This function is called by the SoftFloat routines to raise a floating
113 point exception. We check the trap enable byte in the FPSR, and raise
114 a SIGFPE exception if necessary. If not the relevant bits in the
115 cumulative exceptions flag byte are set and we return.
118 void float_raise(signed char flags)
120 register unsigned int fpsr, cumulativeTraps;
122 #ifdef CONFIG_DEBUG_USER
123 printk(KERN_DEBUG "NWFPE: %s[%d] takes exception %08x at %p from %08x\n",
124 current->comm, current->pid, flags,
125 __builtin_return_address(0), userRegisters[15]);
126 #endif
128 /* Keep SoftFloat exception flags up to date. */
129 float_exception_flags |= flags;
131 /* Read fpsr and initialize the cumulativeTraps. */
132 fpsr = readFPSR();
133 cumulativeTraps = 0;
135 /* For each type of exception, the cumulative trap exception bit is only
136 set if the corresponding trap enable bit is not set. */
137 if ((!(fpsr & BIT_IXE)) && (flags & BIT_IXC))
138 cumulativeTraps |= BIT_IXC;
139 if ((!(fpsr & BIT_UFE)) && (flags & BIT_UFC))
140 cumulativeTraps |= BIT_UFC;
141 if ((!(fpsr & BIT_OFE)) && (flags & BIT_OFC))
142 cumulativeTraps |= BIT_OFC;
143 if ((!(fpsr & BIT_DZE)) && (flags & BIT_DZC))
144 cumulativeTraps |= BIT_DZC;
145 if ((!(fpsr & BIT_IOE)) && (flags & BIT_IOC))
146 cumulativeTraps |= BIT_IOC;
148 /* Set the cumulative exceptions flags. */
149 if (cumulativeTraps)
150 writeFPSR(fpsr | cumulativeTraps);
152 /* Raise an exception if necessary. */
153 if (fpsr & (flags << 16))
154 fp_send_sig(SIGFPE, current, 1);
157 module_init(fpe_init);
158 module_exit(fpe_exit);