Skip to content

Commit 9671f70

Browse files
NonerKaopalmer-dabbelt
authored andcommitted
Allow to disable FPU support
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>
1 parent e8be530 commit 9671f70

File tree

6 files changed

+29
-3
lines changed

6 files changed

+29
-3
lines changed

arch/riscv/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,15 @@ config RISCV_BASE_PMU
208208

209209
endmenu
210210

211+
config FPU
212+
bool "FPU support"
213+
default y
214+
help
215+
Say N here if you want to disable all floating-point related procedure
216+
in the kernel.
217+
218+
If you don't know what to do here, say Y.
219+
211220
endmenu
212221

213222
menu "Kernel type"

arch/riscv/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ KBUILD_CFLAGS += -Wall
4444
riscv-march-$(CONFIG_ARCH_RV32I) := rv32im
4545
riscv-march-$(CONFIG_ARCH_RV64I) := rv64im
4646
riscv-march-$(CONFIG_RISCV_ISA_A) := $(riscv-march-y)a
47-
riscv-march-y := $(riscv-march-y)fd
47+
riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd
4848
riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c
4949
KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
5050
KBUILD_AFLAGS += -march=$(riscv-march-y)

arch/riscv/include/asm/switch_to.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <asm/ptrace.h>
1919
#include <asm/csr.h>
2020

21+
#ifdef CONFIG_FPU
2122
extern void __fstate_save(struct task_struct *save_to);
2223
extern void __fstate_restore(struct task_struct *restore_from);
2324

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

59+
#define DEFAULT_SSTATUS (SR_SPIE | SR_FS_INITIAL)
60+
61+
#else
62+
#define fstate_save(task, regs) do { } while (0)
63+
#define fstate_restore(task, regs) do { } while (0)
64+
#define __switch_to_aux(__prev, __next) do { } while (0)
65+
#define DEFAULT_SSTATUS (SR_SPIE | SR_FS_OFF)
66+
#endif
67+
5868
extern struct task_struct *__switch_to(struct task_struct *,
5969
struct task_struct *);
6070

arch/riscv/kernel/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ extra-y += vmlinux.lds
1313
obj-y += cpu.o
1414
obj-y += cpufeature.o
1515
obj-y += entry.o
16-
obj-y += fpu.o
1716
obj-y += irq.o
1817
obj-y += process.o
1918
obj-y += ptrace.o
@@ -32,6 +31,7 @@ obj-y += vdso/
3231

3332
CFLAGS_setup.o := -mcmodel=medany
3433

34+
obj-$(CONFIG_FPU) += fpu.o
3535
obj-$(CONFIG_SMP) += smpboot.o
3636
obj-$(CONFIG_SMP) += smp.o
3737
obj-$(CONFIG_MODULES) += module.o

arch/riscv/kernel/process.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,22 @@ void show_regs(struct pt_regs *regs)
7676
void start_thread(struct pt_regs *regs, unsigned long pc,
7777
unsigned long sp)
7878
{
79-
regs->sstatus = SR_SPIE /* User mode, irqs on */ | SR_FS_INITIAL;
79+
regs->sstatus = DEFAULT_SSTATUS;
8080
regs->sepc = pc;
8181
regs->sp = sp;
8282
set_fs(USER_DS);
8383
}
8484

8585
void flush_thread(void)
8686
{
87+
#ifdef CONFIG_FPU
8788
/*
8889
* Reset FPU context
8990
* frm: round to nearest, ties to even (IEEE default)
9091
* fflags: accrued exceptions cleared
9192
*/
9293
memset(&current->thread.fstate, 0, sizeof(current->thread.fstate));
94+
#endif
9395
}
9496

9597
int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)

arch/riscv/kernel/signal.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct rt_sigframe {
3737
struct ucontext uc;
3838
};
3939

40+
#ifdef CONFIG_FPU
4041
static long restore_fp_state(struct pt_regs *regs,
4142
union __riscv_fp_state *sc_fpregs)
4243
{
@@ -85,6 +86,10 @@ static long save_fp_state(struct pt_regs *regs,
8586

8687
return err;
8788
}
89+
#else
90+
#define save_fp_state(task, regs) (0)
91+
#define restore_fp_state(task, regs) (0)
92+
#endif
8893

8994
static long restore_sigcontext(struct pt_regs *regs,
9095
struct sigcontext __user *sc)

0 commit comments

Comments
 (0)