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

Commit 3a76c3b

Browse files
committed
Initialize FPU when available
1 parent c44748a commit 3a76c3b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ extern crate r0;
208208

209209
pub use macros::{entry, pre_init};
210210

211-
use riscv::register::{mstatus, mtvec};
211+
use riscv::register::{mstatus, mtvec, misa, fcsr};
212212

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

254-
// TODO: Enable FPU when available
254+
// Initialize FPU when available
255+
if let Some(isa) = misa::read() {
256+
if isa.has_extension('F') || isa.has_extension('D') {
257+
fcsr::clear_flags();
258+
fcsr::set_rounding_mode(fcsr::RoundingMode::RoundToNearestEven);
259+
mstatus::set_fs(mstatus::FS::Dirty);
260+
// TODO: fill registers with zeros
261+
}
262+
}
255263

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

0 commit comments

Comments
 (0)