From 697fadd2946dafaf84bc70413ba26116e872bc5f Mon Sep 17 00:00:00 2001 From: Scott Johnson Date: Tue, 6 Dec 2016 11:00:55 -0800 Subject: Enable FPU in MSTATUS CSR during init This way, chips with FPU can run FPU instructions without taking exceptions. I've confirmed that dhrystone still runs successfully even on chips with no FPU. --- bsp/env/freedom-e300-hifive1/init.c | 1 + 1 file changed, 1 insertion(+) (limited to 'bsp/env/freedom-e300-hifive1') diff --git a/bsp/env/freedom-e300-hifive1/init.c b/bsp/env/freedom-e300-hifive1/init.c index d085f6c..be76f90 100644 --- a/bsp/env/freedom-e300-hifive1/init.c +++ b/bsp/env/freedom-e300-hifive1/init.c @@ -182,6 +182,7 @@ void _init() printf("core freq at %d Hz\n", get_cpu_freq()); write_csr(mtvec, &handle_trap); + write_csr(mstatus, MSTATUS_FS); // enable FPU _exit(main(0, NULL)); } -- cgit v1.2.3 From e0f235fc5344ccf79fa0e5bdd64591aef3814799 Mon Sep 17 00:00:00 2001 From: Scott Johnson Date: Wed, 7 Dec 2016 18:01:26 -0800 Subject: Initialize FPU properly * Only attempts if FPU actually implemented in design * Also initializes rounding modes, which are undefined at reset --- bsp/env/freedom-e300-hifive1/init.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'bsp/env/freedom-e300-hifive1') diff --git a/bsp/env/freedom-e300-hifive1/init.c b/bsp/env/freedom-e300-hifive1/init.c index be76f90..343f071 100644 --- a/bsp/env/freedom-e300-hifive1/init.c +++ b/bsp/env/freedom-e300-hifive1/init.c @@ -182,7 +182,10 @@ void _init() printf("core freq at %d Hz\n", get_cpu_freq()); write_csr(mtvec, &handle_trap); - write_csr(mstatus, MSTATUS_FS); // enable FPU + if (read_csr(misa) & (1 << ('F' - 'A'))) { // if F extension is present + write_csr(mstatus, MSTATUS_FS); // allow FPU instructions without trapping + write_csr(fcsr, 0); // initialize rounding mode, undefined at reset + } _exit(main(0, NULL)); } -- cgit v1.2.3