Browse Source

Check if we have extensions before using them

pull/67/head
Palmer Dabbelt 9 years ago
parent
commit
27498013ad
  1. 17
      machine/minit.c

17
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);

Loading…
Cancel
Save