Import 2.3.18pre1
[davej-history.git] / arch / arm / nwfpe / fpmodule.c
blobde28e39f5bd7d99c4e0151c60176d81d0d1d8525
1 /*
2 NetWinder Floating Point Emulator
3 (c) Rebel.com, 1998-1999
4 (c) Philip Blundell, 1998-1999
6 Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
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.
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.
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.
23 #include "config.h"
25 #ifdef MODULE
26 #include <linux/module.h>
27 #include <linux/version.h>
28 #else
29 #define MOD_INC_USE_COUNT
30 #define MOD_DEC_USE_COUNT
31 #endif
33 /* XXX */
34 #include <linux/types.h>
35 #include <linux/kernel.h>
36 #include <linux/signal.h>
37 #include <linux/sched.h>
38 #include <linux/mm.h>
39 #include <linux/init.h>
40 #include <linux/spinlock.h>
42 #include <asm/system.h>
43 #include <asm/uaccess.h>
44 #include <asm/io.h>
45 #include <asm/atomic.h>
46 #include <asm/pgtable.h>
47 /* XXX */
49 #include "softfloat.h"
50 #include "fpopcode.h"
51 #include "fpmodule.h"
52 #include "fpa11.h"
53 #include "fpa11.inl"
55 /* external data */
56 extern FPA11 *fpa11;
58 /* kernel symbols required for signal handling */
59 typedef struct task_struct* PTASK;
61 #ifdef MODULE
62 int fp_printk(const char *,...);
63 void fp_send_sig(unsigned long sig, PTASK p, int priv);
64 #if LINUX_VERSION_CODE > 0x20115
65 MODULE_AUTHOR("Scott Bambrough <scottb@netwinder.org>");
66 MODULE_DESCRIPTION("NWFPE floating point emulator");
67 #endif
69 #else
70 #define fp_printk printk
71 #define fp_send_sig send_sig
72 #define kern_fp_enter fp_enter
73 #endif
75 /* kernel function prototypes required */
76 void C_SYMBOL_NAME(fp_setup)(void);
78 /* external declarations for saved kernel symbols */
79 extern unsigned int C_SYMBOL_NAME(kern_fp_enter);
81 /* forward declarations */
82 extern void nwfpe_enter(void);
84 /* Original value of fp_enter from kernel before patched by fpe_init. */
85 static unsigned int orig_fp_enter;
87 /* Address of user registers on the kernel stack. */
88 unsigned int *userRegisters;
90 void __init C_SYMBOL_NAME(fpe_version)(void)
92 static const char szTitle[] = "<4>NetWinder Floating Point Emulator ";
93 static const char szVersion[] = "V0.94.1 ";
94 static const char szCopyright[] = "(c) 1998-1999 Rebel.com\n";
95 C_SYMBOL_NAME(fp_printk)(szTitle);
96 C_SYMBOL_NAME(fp_printk)(szVersion);
97 C_SYMBOL_NAME(fp_printk)(szCopyright);
100 int __init fpe_init(void)
102 /* Display title, version and copyright information. */
103 C_SYMBOL_NAME(fpe_version)();
105 /* Save pointer to the old FP handler and then patch ourselves in */
106 orig_fp_enter = C_SYMBOL_NAME(kern_fp_enter);
107 C_SYMBOL_NAME(kern_fp_enter) = (unsigned int)C_SYMBOL_NAME(nwfpe_enter);
109 return 0;
112 #ifdef MODULE
113 int init_module(void)
115 return(fpe_init());
118 void cleanup_module(void)
120 /* Restore the values we saved earlier. */
121 C_SYMBOL_NAME(kern_fp_enter) = orig_fp_enter;
123 #endif
125 #define _ARM_pc 60
126 #define _ARM_cpsr 64
129 ScottB: November 4, 1998
131 Moved this function out of softfloat-specialize into fpmodule.c.
132 This effectively isolates all the changes required for integrating with the
133 Linux kernel into fpmodule.c. Porting to NetBSD should only require modifying
134 fpmodule.c to integrate with the NetBSD kernel (I hope!).
136 [1/1/99: Not quite true any more unfortunately. There is Linux-specific
137 code to access data in user space in some other source files at the
138 moment. --philb]
140 float_exception_flags is a global variable in SoftFloat.
142 This function is called by the SoftFloat routines to raise a floating
143 point exception. We check the trap enable byte in the FPSR, and raise
144 a SIGFPE exception if necessary. If not the relevant bits in the
145 cumulative exceptions flag byte are set and we return.
148 void float_raise(signed char flags)
150 #if 0
151 printk(KERN_DEBUG "NWFPE: exception %08x at %08x from %08x\n", flags,
152 __builtin_return_address(0), userRegisters[15]);
153 #endif
155 float_exception_flags |= flags;
156 if (readFPSR() & (flags << 16))
158 /* raise exception */
159 C_SYMBOL_NAME(fp_send_sig)(SIGFPE,C_SYMBOL_NAME(current),1);
161 else
163 /* set the cumulative exceptions flags */
164 writeFPSR(flags);