Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 4e4101cf authored by Palmer Dabbelt's avatar Palmer Dabbelt
Browse files

riscv: Add support to no-FPU systems



This patchset adds an option, CONFIG_FPU, to enable/disable floating-
point support within the kernel.  The kernel's new behavior will be as
follows:

* with CONFIG_FPU=y
  All FPU codes are reserved.  If no FPU is found during booting, a
  global flag will be set, and those functions will be bypassed with
  condition check to that flag.

* with CONFIG_FPU=n
  No floating-point instructions in kernel and all related settings
  are excluded.

Signed-off-by: default avatarPalmer Dabbelt <palmer@sifive.com>
parents aef53f97 9411ec60
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -210,6 +210,15 @@ config RISCV_BASE_PMU

endmenu

config FPU
	bool "FPU support"
	default y
	help
	  Say N here if you want to disable all floating-point related procedure
	  in the kernel.

	  If you don't know what to do here, say Y.

endmenu

menu "Kernel features"
+8 −11
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ ifeq ($(CONFIG_ARCH_RV64I),y)
	KBUILD_CFLAGS += -mabi=lp64
	KBUILD_AFLAGS += -mabi=lp64

	KBUILD_MARCH = rv64im
	KBUILD_LDFLAGS += -melf64lriscv
else
	BITS := 32
@@ -34,22 +33,20 @@ else

	KBUILD_CFLAGS += -mabi=ilp32
	KBUILD_AFLAGS += -mabi=ilp32
	KBUILD_MARCH = rv32im
	KBUILD_LDFLAGS += -melf32lriscv
endif

KBUILD_CFLAGS += -Wall

ifeq ($(CONFIG_RISCV_ISA_A),y)
	KBUILD_ARCH_A = a
endif
ifeq ($(CONFIG_RISCV_ISA_C),y)
	KBUILD_ARCH_C = c
endif

KBUILD_AFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_ARCH_A)fd$(KBUILD_ARCH_C)
# ISA string setting
riscv-march-$(CONFIG_ARCH_RV32I)	:= rv32im
riscv-march-$(CONFIG_ARCH_RV64I)	:= rv64im
riscv-march-$(CONFIG_RISCV_ISA_A)	:= $(riscv-march-y)a
riscv-march-$(CONFIG_FPU)		:= $(riscv-march-y)fd
riscv-march-$(CONFIG_RISCV_ISA_C)	:= $(riscv-march-y)c
KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
KBUILD_AFLAGS += -march=$(riscv-march-y)

KBUILD_CFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_ARCH_A)$(KBUILD_ARCH_C)
KBUILD_CFLAGS += -mno-save-restore
KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)

+11 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <asm/ptrace.h>
#include <asm/csr.h>

#ifdef CONFIG_FPU
extern void __fstate_save(struct task_struct *save_to);
extern void __fstate_restore(struct task_struct *restore_from);

@@ -55,6 +56,14 @@ static inline void __switch_to_aux(struct task_struct *prev,
	fstate_restore(next, task_pt_regs(next));
}

extern bool has_fpu;
#else
#define has_fpu false
#define fstate_save(task, regs) do { } while (0)
#define fstate_restore(task, regs) do { } while (0)
#define __switch_to_aux(__prev, __next) do { } while (0)
#endif

extern struct task_struct *__switch_to(struct task_struct *,
				       struct task_struct *);

@@ -62,6 +71,7 @@ extern struct task_struct *__switch_to(struct task_struct *,
do {							\
	struct task_struct *__prev = (prev);		\
	struct task_struct *__next = (next);		\
	if (has_fpu)					\
		__switch_to_aux(__prev, __next);	\
	((last) = __switch_to(__prev, __next));		\
} while (0)
+1 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ obj-y += vdso/

CFLAGS_setup.o := -mcmodel=medany

obj-$(CONFIG_FPU)		+= fpu.o
obj-$(CONFIG_SMP)		+= smpboot.o
obj-$(CONFIG_SMP)		+= smp.o
obj-$(CONFIG_MODULES)		+= module.o
+8 −0
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@
#include <asm/hwcap.h>

unsigned long elf_hwcap __read_mostly;
#ifdef CONFIG_FPU
bool has_fpu __read_mostly;
#endif

void riscv_fill_hwcap(void)
{
@@ -65,4 +68,9 @@ void riscv_fill_hwcap(void)
	}

	pr_info("elf_hwcap is 0x%lx", elf_hwcap);

#ifdef CONFIG_FPU
	if (elf_hwcap & (COMPAT_HWCAP_ISA_F | COMPAT_HWCAP_ISA_D))
		has_fpu = true;
#endif
}
Loading