kernel: remove linux 3.18 support
[openwrt/openwrt.git] / target / linux / generic / pending-4.4 / 304-mips_disable_fpu.patch
1 From: Manuel Lauss <manuel.lauss@gmail.com>
2 Subject: [RFC PATCH v4 2/2] MIPS: make FPU emulator optional
3 Date: Mon, 7 Apr 2014 12:57:04 +0200
4 Message-Id: <1396868224-252888-2-git-send-email-manuel.lauss@gmail.com>
5
6 This small patch makes the MIPS FPU emulator optional. The kernel
7 kills float-users on systems without a hardware FPU by sending a SIGILL.
8
9 Disabling the emulator shrinks vmlinux by about 54kBytes (32bit,
10 optimizing for size).
11
12 Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
13 ---
14 v4: rediffed because of patch 1/2, should now work with micromips as well
15 v3: updated patch description with size savings.
16 v2: incorporated changes suggested by Jonas Gorski
17 force the fpu emulator on for micromips: relocating the parts
18 of the mmips code in the emulator to other areas would be a
19 much larger change; I went the cheap route instead with this.
20
21 arch/mips/Kbuild | 2 +-
22 arch/mips/Kconfig | 14 ++++++++++++++
23 arch/mips/include/asm/fpu.h | 5 +++--
24 arch/mips/include/asm/fpu_emulator.h | 15 +++++++++++++++
25 4 files changed, 33 insertions(+), 3 deletions(-)
26
27 --- a/arch/mips/Kconfig
28 +++ b/arch/mips/Kconfig
29 @@ -2725,6 +2725,20 @@ config MIPS_O32_FP64_SUPPORT
30
31 If unsure, say N.
32
33 +config MIPS_FPU_EMULATOR
34 + bool "MIPS FPU Emulator"
35 + default y
36 + help
37 + This option lets you disable the built-in MIPS FPU (Coprocessor 1)
38 + emulator, which handles floating-point instructions on processors
39 + without a hardware FPU. It is generally a good idea to keep the
40 + emulator built-in, unless you are perfectly sure you have a
41 + complete soft-float environment. With the emulator disabled, all
42 + users of float operations will be killed with an illegal instr-
43 + uction exception.
44 +
45 + Say Y, please.
46 +
47 config USE_OF
48 bool
49 select OF
50 --- a/arch/mips/Makefile
51 +++ b/arch/mips/Makefile
52 @@ -285,7 +285,7 @@ OBJCOPYFLAGS += --remove-section=.regin
53 head-y := arch/mips/kernel/head.o
54
55 libs-y += arch/mips/lib/
56 -libs-y += arch/mips/math-emu/
57 +libs-$(CONFIG_MIPS_FPU_EMULATOR) += arch/mips/math-emu/
58
59 # See arch/mips/Kbuild for content of core part of the kernel
60 core-y += arch/mips/
61 --- a/arch/mips/include/asm/fpu.h
62 +++ b/arch/mips/include/asm/fpu.h
63 @@ -223,8 +223,10 @@ static inline int init_fpu(void)
64 /* Restore FRE */
65 write_c0_config5(config5);
66 enable_fpu_hazard();
67 - } else
68 + } else if (IS_ENABLED(CONFIG_MIPS_FPU_EMULATOR))
69 fpu_emulator_init_fpu();
70 + else
71 + ret = SIGILL;
72
73 return ret;
74 }
75 --- a/arch/mips/include/asm/fpu_emulator.h
76 +++ b/arch/mips/include/asm/fpu_emulator.h
77 @@ -30,6 +30,7 @@
78 #include <asm/local.h>
79 #include <asm/processor.h>
80
81 +#ifdef CONFIG_MIPS_FPU_EMULATOR
82 #ifdef CONFIG_DEBUG_FS
83
84 struct mips_fpu_emulator_stats {
85 @@ -66,6 +67,21 @@ extern int do_dsemulret(struct pt_regs *
86 extern int fpu_emulator_cop1Handler(struct pt_regs *xcp,
87 struct mips_fpu_struct *ctx, int has_fpu,
88 void *__user *fault_addr);
89 +#else /* no CONFIG_MIPS_FPU_EMULATOR */
90 +static inline int do_dsemulret(struct pt_regs *xcp)
91 +{
92 + return 0; /* 0 means error, should never get here anyway */
93 +}
94 +
95 +static inline int fpu_emulator_cop1Handler(struct pt_regs *xcp,
96 + struct mips_fpu_struct *ctx, int has_fpu,
97 + void *__user *fault_addr)
98 +{
99 + *fault_addr = NULL;
100 + return SIGILL; /* we don't speak MIPS FPU */
101 +}
102 +#endif /* CONFIG_MIPS_FPU_EMULATOR */
103 +
104 int process_fpemu_return(int sig, void __user *fault_addr,
105 unsigned long fcr31);
106 int mm_isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn,