summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Johnson <scottj@sifive.com>2016-12-07 18:01:26 -0800
committerScott Johnson <scottj@sifive.com>2016-12-07 18:01:26 -0800
commite0f235fc5344ccf79fa0e5bdd64591aef3814799 (patch)
tree8dc928d83205920905f397e2fe34fae65a74246c
parent697fadd2946dafaf84bc70413ba26116e872bc5f (diff)
Initialize FPU properly
* Only attempts if FPU actually implemented in design * Also initializes rounding modes, which are undefined at reset
-rw-r--r--bsp/env/freedom-e300-hifive1/init.c5
1 files changed, 4 insertions, 1 deletions
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));
}