|
|
|
@ -19,9 +19,11 @@ size_t plic_ndevs; |
|
|
|
static void mstatus_init() |
|
|
|
{ |
|
|
|
// Enable FPU
|
|
|
|
if (supports_extension('D') || supports_extension('F')) |
|
|
|
write_csr(mstatus, MSTATUS_FS); |
|
|
|
|
|
|
|
// Enable user/supervisor use of perf counters
|
|
|
|
if (supports_extension('S')) |
|
|
|
write_csr(scounteren, -1); |
|
|
|
write_csr(mcounteren, -1); |
|
|
|
|
|
|
|
@ -29,12 +31,16 @@ static void mstatus_init() |
|
|
|
write_csr(mie, MIP_MSIP); |
|
|
|
|
|
|
|
// Disable paging
|
|
|
|
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); |
|
|
|
|