diff options
author | Palmer Dabbelt <palmer@dabbelt.com> | 2017-11-02 18:22:37 -0700 |
---|---|---|
committer | Palmer Dabbelt <palmer@dabbelt.com> | 2017-11-02 18:22:37 -0700 |
commit | 27498013ad7684a5f22a99790ac29badea205a3f (patch) | |
tree | 21fd7e514596ecd126d089b5ecff255bb809d433 /machine | |
parent | 21209988c72ee891727d5b9d548a224ae6958986 (diff) | |
download | pk-27498013ad7684a5f22a99790ac29badea205a3f.zip pk-27498013ad7684a5f22a99790ac29badea205a3f.tar.gz pk-27498013ad7684a5f22a99790ac29badea205a3f.tar.bz2 |
Check if we have extensions before using them
Diffstat (limited to 'machine')
-rw-r--r-- | machine/minit.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/machine/minit.c b/machine/minit.c index a324d06..5f98501 100644 --- a/machine/minit.c +++ b/machine/minit.c @@ -19,22 +19,28 @@ size_t plic_ndevs; static void mstatus_init() { // Enable FPU - write_csr(mstatus, MSTATUS_FS); + if (supports_extension('D') || supports_extension('F')) + write_csr(mstatus, MSTATUS_FS); // Enable user/supervisor use of perf counters - write_csr(scounteren, -1); + if (supports_extension('S')) + write_csr(scounteren, -1); write_csr(mcounteren, -1); // Enable software interrupts write_csr(mie, MIP_MSIP); // Disable paging - write_csr(sptbr, 0); + if (supports_extension('S')) + write_csr(sptbr, 0); } // send S-mode interrupts and most exceptions straight to S-mode static void delegate_traps() { + if (!supports_extension('S')) + return; + uintptr_t interrupts = MIP_SSIP | MIP_STIP | MIP_SEIP; uintptr_t exceptions = (1U << CAUSE_MISALIGNED_FETCH) | @@ -53,11 +59,12 @@ static void delegate_traps() static void fp_init() { + if (!supports_extension('D') && !supports_extension('F')) + return; + assert(read_csr(mstatus) & MSTATUS_FS); #ifdef __riscv_flen - if (!supports_extension('D')) - die("FPU not found; recompile pk with -msoft-float"); for (int i = 0; i < 32; i++) init_fp_reg(i); write_csr(fcsr, 0); |