aboutsummaryrefslogtreecommitdiff
path: root/machine
diff options
context:
space:
mode:
authorPalmer Dabbelt <palmer@dabbelt.com>2017-11-02 18:22:37 -0700
committerPalmer Dabbelt <palmer@dabbelt.com>2017-11-02 18:22:37 -0700
commit27498013ad7684a5f22a99790ac29badea205a3f (patch)
tree21fd7e514596ecd126d089b5ecff255bb809d433 /machine
parent21209988c72ee891727d5b9d548a224ae6958986 (diff)
downloadriscv-pk-27498013ad7684a5f22a99790ac29badea205a3f.zip
riscv-pk-27498013ad7684a5f22a99790ac29badea205a3f.tar.gz
riscv-pk-27498013ad7684a5f22a99790ac29badea205a3f.tar.bz2
Check if we have extensions before using them
Diffstat (limited to 'machine')
-rw-r--r--machine/minit.c17
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);