Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / arm / nwfpe / fpmodule.c
bloba806fea5c3ed6ccb6a9dfd84b5fa9c517edc16f3
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 "fpa11.h"
26 #include <linux/module.h>
27 #include <linux/version.h>
28 #include <linux/config.h>
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 */
39 #include "softfloat.h"
40 #include "fpopcode.h"
41 #include "fpmodule.h"
42 #include "fpa11.inl"
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
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
57 extern char fpe_type[];
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);
65 extern void (*fp_init)(union fp_state *);
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 *);
71 /* forward declarations */
72 extern void nwfpe_enter(void);
74 static int __init fpe_init(void)
76 if (sizeof(FPA11) > sizeof(union fp_state)) {
77 printk(KERN_ERR "nwfpe: bad structure size\n");
78 return -EINVAL;
81 if (sizeof(FPREG) != 12) {
82 printk(KERN_ERR "nwfpe: bad register size\n");
83 return -EINVAL;
85 if (fpe_type[0] && strcmp(fpe_type, "nwfpe"))
86 return 0;
88 /* Display title, version and copyright information. */
89 printk(KERN_WARNING "NetWinder Floating Point Emulator V0.97 ("
90 NWFPE_BITS " precision)\n");
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;
98 return 0;
101 static void __exit fpe_exit(void)
103 /* Restore the values we saved earlier. */
104 kern_fp_enter = orig_fp_enter;
105 fp_init = orig_fp_init;
109 ScottB: November 4, 1998
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!).
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]
120 float_exception_flags is a global variable in SoftFloat.
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.
128 void float_raise(signed char flags)
130 register unsigned int fpsr, cumulativeTraps;
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
139 /* Keep SoftFloat exception flags up to date. */
140 float_exception_flags |= flags;
142 /* Read fpsr and initialize the cumulativeTraps. */
143 fpsr = readFPSR();
144 cumulativeTraps = 0;
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;
159 /* Set the cumulative exceptions flags. */
160 if (cumulativeTraps)
161 writeFPSR(fpsr | cumulativeTraps);
163 /* Raise an exception if necessary. */
164 if (fpsr & (flags << 16))
165 fp_send_sig(SIGFPE, current, 1);
168 module_init(fpe_init);
169 module_exit(fpe_exit);
171 MODULE_AUTHOR("Scott Bambrough <scottb@rebel.com>");
172 MODULE_DESCRIPTION("NWFPE floating point emulator (" NWFPE_BITS " precision)");
173 MODULE_LICENSE("GPL");