33fd6a91eb48759fba16399f6cce5cb96aa6d733
[openwrt/openwrt.git] / target / linux / generic / patches-3.10 / 304-mips_disable_fpu.patch
1 MIPS: allow disabling the kernel FPU emulator
2
3 This patch allows turning off the in-kernel Algorithmics
4 FPU emulator support, which allows one to save a couple of
5 precious blocks on an embedded system.
6
7 Signed-off-by: Florian Fainelli <florian@openwrt.org>
8 --
9 --- a/arch/mips/Kconfig
10 +++ b/arch/mips/Kconfig
11 @@ -976,6 +976,17 @@ config I8259
12 config MIPS_BONITO64
13 bool
14
15 +config MIPS_FPU_EMU
16 + bool "Enable FPU emulation"
17 + default y
18 + help
19 + This option allows building a kernel with or without the Algorithmics
20 + FPU emulator enabled. Turning off this option results in a kernel which
21 + does not catch floating operations exceptions. Make sure that your toolchain
22 + is configured to enable software floating point emulation in that case.
23 +
24 + If unsure say Y here.
25 +
26 config MIPS_MSC
27 bool
28
29 --- a/arch/mips/math-emu/Makefile
30 +++ b/arch/mips/math-emu/Makefile
31 @@ -2,10 +2,11 @@
32 # Makefile for the Linux/MIPS kernel FPU emulation.
33 #
34
35 -obj-y := cp1emu.o ieee754m.o ieee754d.o ieee754dp.o ieee754sp.o ieee754.o \
36 +obj-y := kernel_linkage.o dsemul.o cp1emu.o
37 +obj-$(CONFIG_MIPS_FPU_EMU) += ieee754m.o ieee754d.o ieee754dp.o ieee754sp.o ieee754.o \
38 ieee754xcpt.o dp_frexp.o dp_modf.o dp_div.o dp_mul.o dp_sub.o \
39 dp_add.o dp_fsp.o dp_cmp.o dp_logb.o dp_scalb.o dp_simple.o \
40 dp_tint.o dp_fint.o dp_tlong.o dp_flong.o sp_frexp.o sp_modf.o \
41 sp_div.o sp_mul.o sp_sub.o sp_add.o sp_fdp.o sp_cmp.o sp_logb.o \
42 sp_scalb.o sp_simple.o sp_tint.o sp_fint.o sp_tlong.o sp_flong.o \
43 - dp_sqrt.o sp_sqrt.o kernel_linkage.o dsemul.o
44 + dp_sqrt.o sp_sqrt.o
45 --- a/arch/mips/math-emu/cp1emu.c
46 +++ b/arch/mips/math-emu/cp1emu.c
47 @@ -59,7 +59,11 @@
48 #define __mips 4
49
50 /* Function which emulates a floating point instruction. */
51 +#ifdef CONFIG_DEBUG_FS
52 +DEFINE_PER_CPU(struct mips_fpu_emulator_stats, fpuemustats);
53 +#endif
54
55 +#ifdef CONFIG_MIPS_FPU_EMU
56 static int fpu_emu(struct pt_regs *, struct mips_fpu_struct *,
57 mips_instruction);
58
59 @@ -70,10 +74,6 @@ static int fpux_emu(struct pt_regs *,
60
61 /* Further private data for which no space exists in mips_fpu_struct */
62
63 -#ifdef CONFIG_DEBUG_FS
64 -DEFINE_PER_CPU(struct mips_fpu_emulator_stats, fpuemustats);
65 -#endif
66 -
67 /* Control registers */
68
69 #define FPCREG_RID 0 /* $0 = revision id */
70 @@ -82,11 +82,15 @@ DEFINE_PER_CPU(struct mips_fpu_emulator_
71 /* Determine rounding mode from the RM bits of the FCSR */
72 #define modeindex(v) ((v) & FPU_CSR_RM)
73
74 +#endif /* CONFIG_MIPS_FPU_EMU */
75 +
76 /* microMIPS bitfields */
77 #define MM_POOL32A_MINOR_MASK 0x3f
78 #define MM_POOL32A_MINOR_SHIFT 0x6
79 #define MM_MIPS32_COND_FC 0x30
80
81 +#ifdef CONFIG_MIPS_FPU_EMU
82 +
83 /* Convert Mips rounding mode (0..3) to IEEE library modes. */
84 static const unsigned char ieee_rm[4] = {
85 [FPU_CSR_RN] = IEEE754_RN,
86 @@ -116,9 +120,13 @@ static const unsigned int fpucondbit[8]
87 };
88 #endif
89
90 +#endif /* CONFIG_MIPS_FPU_EMU */
91 +
92 /* (microMIPS) Convert 16-bit register encoding to 32-bit register encoding. */
93 static const unsigned int reg16to32map[8] = {16, 17, 2, 3, 4, 5, 6, 7};
94
95 +#ifdef CONFIG_MIPS_FPU_EMU
96 +
97 /* (microMIPS) Convert certain microMIPS instructions to MIPS32 format. */
98 static const int sd_format[] = {16, 17, 0, 0, 0, 0, 0, 0};
99 static const int sdps_format[] = {16, 17, 22, 0, 0, 0, 0, 0};
100 @@ -463,6 +471,8 @@ static int microMIPS32_to_MIPS32(union m
101 return 0;
102 }
103
104 +#endif /* CONFIG_MIPS_FPU_EMU */
105 +
106 int mm_isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn,
107 unsigned long *contpc)
108 {
109 @@ -667,6 +677,8 @@ int mm_isBranchInstr(struct pt_regs *reg
110 return 0;
111 }
112
113 +#ifdef CONFIG_MIPS_FPU_EMU
114 +
115 /*
116 * Redundant with logic already in kernel/branch.c,
117 * embedded in compute_return_epc. At some point,
118 @@ -2102,7 +2114,6 @@ int fpu_emulator_cop1Handler(struct pt_r
119
120 return sig;
121 }
122 -
123 #ifdef CONFIG_DEBUG_FS
124
125 static int fpuemu_stat_get(void *data, u64 *val)
126 @@ -2151,4 +2162,11 @@ static int __init debugfs_fpuemu(void)
127 return 0;
128 }
129 __initcall(debugfs_fpuemu);
130 -#endif
131 +#endif /* CONFIG_DEBUGFS */
132 +#else
133 +int fpu_emulator_cop1Handler(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
134 + int has_fpu, void *__user *fault_addr)
135 +{
136 + return 0;
137 +}
138 +#endif /* CONFIG_MIPS_FPU_EMU */
139 --- a/arch/mips/math-emu/dsemul.c
140 +++ b/arch/mips/math-emu/dsemul.c
141 @@ -119,6 +119,7 @@ int mips_dsemul(struct pt_regs *regs, mi
142 return SIGILL; /* force out of emulation loop */
143 }
144
145 +#ifdef CONFIG_MIPS_FPU_EMU
146 int do_dsemulret(struct pt_regs *xcp)
147 {
148 struct emuframe __user *fr;
149 @@ -182,3 +183,9 @@ int do_dsemulret(struct pt_regs *xcp)
150
151 return 1;
152 }
153 +#else
154 +int do_dsemulret(struct pt_regs *xcp)
155 +{
156 + return 0;
157 +}
158 +#endif /* CONFIG_MIPS_FPU_EMU */
159 --- a/arch/mips/math-emu/kernel_linkage.c
160 +++ b/arch/mips/math-emu/kernel_linkage.c
161 @@ -29,6 +29,7 @@
162
163 #define SIGNALLING_NAN 0x7ff800007ff80000LL
164
165 +#ifdef CONFIG_MIPS_FPU_EMU
166 void fpu_emulator_init_fpu(void)
167 {
168 static int first = 1;
169 @@ -112,4 +113,36 @@ int fpu_emulator_restore_context32(struc
170
171 return err;
172 }
173 -#endif
174 +#endif /* CONFIG_64BIT */
175 +#else
176 +
177 +void fpu_emulator_init_fpu(void)
178 +{
179 + printk(KERN_INFO "FPU emulator disabled, make sure your toolchain"
180 + "was compiled with software floating point support (soft-float)\n");
181 + return;
182 +}
183 +
184 +int fpu_emulator_save_context(struct sigcontext __user *sc)
185 +{
186 + return 0;
187 +}
188 +
189 +int fpu_emulator_restore_context(struct sigcontext __user *sc)
190 +{
191 + return 0;
192 +}
193 +
194 +int fpu_emulator_save_context32(struct sigcontext32 __user *sc)
195 +{
196 + return 0;
197 +}
198 +
199 +int fpu_emulator_restore_context32(struct sigcontext32 __user *sc)
200 +{
201 + return 0;
202 +}
203 +
204 +#ifdef CONFIG_64BIT
205 +#endif /* CONFIG_64BIT */
206 +#endif /* CONFIG_MIPS_FPU_EMU */