Files
asterinas/ostd/src/arch/riscv/mod.rs
2025-06-11 16:54:59 +08:00

71 lines
1.8 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// SPDX-License-Identifier: MPL-2.0
//! Platform-specific code for the RISC-V platform.
pub mod boot;
pub(crate) mod cpu;
pub mod device;
pub mod iommu;
pub(crate) mod irq;
pub(crate) mod mm;
pub(crate) mod pci;
pub mod qemu;
pub mod serial;
pub mod task;
pub mod timer;
pub mod trap;
#[cfg(feature = "cvm_guest")]
pub(crate) fn init_cvm_guest() {
// Unimplemented, no-op
}
pub(crate) unsafe fn late_init_on_bsp() {
// SAFETY: This function is called in the boot context of the BSP.
unsafe { trap::init() };
// SAFETY: We're on the BSP and we're ready to boot all APs.
unsafe { crate::boot::smp::boot_all_aps() };
// SAFETY: This function is called once and at most once at a proper timing
// in the boot context of the BSP, with no timer-related operations having
// been performed.
unsafe { timer::init() };
let _ = pci::init();
}
pub(crate) unsafe fn init_on_ap() {
unimplemented!()
}
pub(crate) fn interrupts_ack(irq_number: usize) {
unimplemented!()
}
/// Return the frequency of TSC. The unit is Hz.
pub fn tsc_freq() -> u64 {
timer::get_timebase_freq()
}
/// Reads the current value of the processors time-stamp counter (TSC).
pub fn read_tsc() -> u64 {
riscv::register::time::read64()
}
/// Reads a hardware generated 64-bit random value.
///
/// Returns None if no random value was generated.
pub fn read_random() -> Option<u64> {
// FIXME: Implement a hardware random number generator on RISC-V platforms.
None
}
pub(crate) fn enable_cpu_features() {
cpu::extension::init();
unsafe {
// We adopt a lazy approach to enable the floating-point unit; it's not
// enabled before the first FPU trap.
riscv::register::sstatus::set_fs(riscv::register::sstatus::FS::Off);
}
}