Skip to content

Commit

Permalink
Allow to disable FPU support
Browse files Browse the repository at this point in the history
FPU codes have been separated from common part in previous patches.
This patch add the CONFIG_FPU option and some stubs, so that a no-FPU
configuration is allowed.

Signed-off-by: Alan Kao <alankao@andestech.com>
Cc: Greentime Hu <greentime@andestech.com>
Cc: Vincent Chen <vincentc@andestech.com>
Cc: Zong Li <zong@andestech.com>
Cc: Nick Hu <nickhu@andestech.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
  • Loading branch information
Alan Kao authored and Palmer Dabbelt committed Oct 23, 2018
1 parent e8be530 commit 9671f70
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
9 changes: 9 additions & 0 deletions arch/riscv/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,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 type"
Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ KBUILD_CFLAGS += -Wall
riscv-march-$(CONFIG_ARCH_RV32I) := rv32im
riscv-march-$(CONFIG_ARCH_RV64I) := rv64im
riscv-march-$(CONFIG_RISCV_ISA_A) := $(riscv-march-y)a
riscv-march-y := $(riscv-march-y)fd
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)
Expand Down
10 changes: 10 additions & 0 deletions arch/riscv/include/asm/switch_to.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

#define DEFAULT_SSTATUS (SR_SPIE | SR_FS_INITIAL)

#else
#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)
#define DEFAULT_SSTATUS (SR_SPIE | SR_FS_OFF)
#endif

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

Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ extra-y += vmlinux.lds
obj-y += cpu.o
obj-y += cpufeature.o
obj-y += entry.o
obj-y += fpu.o
obj-y += irq.o
obj-y += process.o
obj-y += ptrace.o
Expand All @@ -32,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
Expand Down
4 changes: 3 additions & 1 deletion arch/riscv/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,22 @@ void show_regs(struct pt_regs *regs)
void start_thread(struct pt_regs *regs, unsigned long pc,
unsigned long sp)
{
regs->sstatus = SR_SPIE /* User mode, irqs on */ | SR_FS_INITIAL;
regs->sstatus = DEFAULT_SSTATUS;
regs->sepc = pc;
regs->sp = sp;
set_fs(USER_DS);
}

void flush_thread(void)
{
#ifdef CONFIG_FPU
/*
* Reset FPU context
* frm: round to nearest, ties to even (IEEE default)
* fflags: accrued exceptions cleared
*/
memset(&current->thread.fstate, 0, sizeof(current->thread.fstate));
#endif
}

int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
Expand Down
5 changes: 5 additions & 0 deletions arch/riscv/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct rt_sigframe {
struct ucontext uc;
};

#ifdef CONFIG_FPU
static long restore_fp_state(struct pt_regs *regs,
union __riscv_fp_state *sc_fpregs)
{
Expand Down Expand Up @@ -85,6 +86,10 @@ static long save_fp_state(struct pt_regs *regs,

return err;
}
#else
#define save_fp_state(task, regs) (0)
#define restore_fp_state(task, regs) (0)
#endif

static long restore_sigcontext(struct pt_regs *regs,
struct sigcontext __user *sc)
Expand Down

0 comments on commit 9671f70

Please sign in to comment.