feat: docs & ARCH 2.2, 2.3, 2.4
This commit is contained in:
@@ -1,3 +1,19 @@
|
||||
use core::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
static HHDM_OFFSET: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
/// Store the Higher-Half Direct Map offset obtained from the bootloader.
|
||||
/// Must be called once during early boot, before any address translation.
|
||||
pub fn init_hhdm(offset: u64) {
|
||||
HHDM_OFFSET.store(offset, Ordering::Release);
|
||||
}
|
||||
|
||||
/// Return the HHDM offset (kernel virtual base for physical memory).
|
||||
#[inline]
|
||||
pub fn get_hhdm() -> u64 {
|
||||
HHDM_OFFSET.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[repr(transparent)]
|
||||
pub struct PhysAddr(pub u64);
|
||||
@@ -8,8 +24,8 @@ pub struct VirtAddr(pub u64);
|
||||
|
||||
impl PhysAddr {
|
||||
/// Convert physical address to virtual via HHDM offset
|
||||
pub fn to_virt(self, hhdm_offset: u64) -> VirtAddr {
|
||||
VirtAddr(self.0 + hhdm_offset)
|
||||
pub fn to_virt(self) -> VirtAddr {
|
||||
VirtAddr(self.0 + get_hhdm())
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
@@ -24,9 +40,10 @@ impl PhysAddr {
|
||||
|
||||
impl VirtAddr {
|
||||
#[allow(dead_code)]
|
||||
pub fn to_phys(self, hhdm_offset: u64) -> Option<PhysAddr> {
|
||||
if self.0 < hhdm_offset { return None; }
|
||||
Some(PhysAddr(self.0 - hhdm_offset))
|
||||
pub fn to_phys(self) -> Option<PhysAddr> {
|
||||
let hhdm = get_hhdm();
|
||||
if self.0 < hhdm { return None; }
|
||||
Some(PhysAddr(self.0 - hhdm))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
||||
Reference in New Issue
Block a user