Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Initialize FPU when available
Browse files Browse the repository at this point in the history
  • Loading branch information
Disasm committed Mar 29, 2019
1 parent c44748a commit 3a76c3b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ extern crate r0;

pub use macros::{entry, pre_init};

use riscv::register::{mstatus, mtvec};
use riscv::register::{mstatus, mtvec, misa, fcsr};

#[export_name = "error: riscv-rt appears more than once in the dependency graph"]
#[doc(hidden)]
Expand Down Expand Up @@ -251,7 +251,15 @@ pub unsafe extern "C" fn start_rust() -> ! {
r0::zero_bss(&mut _sbss, &mut _ebss);
r0::init_data(&mut _sdata, &mut _edata, &_sidata);

// TODO: Enable FPU when available
// Initialize FPU when available
if let Some(isa) = misa::read() {
if isa.has_extension('F') || isa.has_extension('D') {
fcsr::clear_flags();
fcsr::set_rounding_mode(fcsr::RoundingMode::RoundToNearestEven);
mstatus::set_fs(mstatus::FS::Dirty);
// TODO: fill registers with zeros
}
}

// Set mtvec to _start_trap
mtvec::write(&_start_trap as *const _ as usize, mtvec::TrapMode::Direct);
Expand Down

0 comments on commit 3a76c3b

Please sign in to comment.