2
0

304-mips_disable_fpu.patch 3.5 KB

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