diff --git a/src/acpi/madt/arch/x86.rs b/src/acpi/madt/arch/x86.rs index dfc6a2228f..3503124f1f 100644 --- a/src/acpi/madt/arch/x86.rs +++ b/src/acpi/madt/arch/x86.rs @@ -69,11 +69,11 @@ pub(super) fn init(madt: Madt) { let cpu_id = LogicalCpuId::next(); // Allocate a stack - let stack_start = allocate_p2frame(4) - .expect("no more frames in acpi stack_start") - .base() - .data() - + crate::PHYS_OFFSET; + let stack_start = RmmA::phys_to_virt( + allocate_p2frame(4) + .expect("no more frames in acpi stack_start") + .base(), + ).data(); let stack_end = stack_start + (PAGE_SIZE << 4); let pcr_ptr = crate::arch::gdt::allocate_and_init_pcr(cpu_id, stack_end); diff --git a/src/acpi/mod.rs b/src/acpi/mod.rs index 2684ff5e0a..aa0b2ebf58 100644 --- a/src/acpi/mod.rs +++ b/src/acpi/mod.rs @@ -39,19 +39,17 @@ unsafe fn map_linearly(addr: PhysicalAddress, len: usize, mapper: &mut crate::me } } -pub fn get_sdt(sdt_address: usize, mapper: &mut KernelMapper) -> &'static Sdt { - let physaddr = PhysicalAddress::new(sdt_address); - +pub fn get_sdt(sdt_address: PhysicalAddress, mapper: &mut KernelMapper) -> &'static Sdt { let sdt; unsafe { const SDT_SIZE: usize = core::mem::size_of::(); - map_linearly(physaddr, SDT_SIZE, mapper); + map_linearly(sdt_address, SDT_SIZE, mapper); - sdt = &*(RmmA::phys_to_virt(physaddr).data() as *const Sdt); + sdt = &*(RmmA::phys_to_virt(sdt_address).data() as *const Sdt); map_linearly( - physaddr.add(SDT_SIZE), + sdt_address.add(SDT_SIZE), sdt.length as usize - SDT_SIZE, mapper, ); @@ -74,7 +72,7 @@ pub enum RxsdtEnum { Xsdt(Xsdt), } impl Rxsdt for RxsdtEnum { - fn iter(&self) -> Box> { + fn iter(&self) -> Box> { match self { Self::Rsdt(rsdt) => ::iter(rsdt), Self::Xsdt(xsdt) => ::iter(xsdt), @@ -96,7 +94,7 @@ pub unsafe fn init(already_supplied_rsdp: Option<*const u8>) { let rsdp_opt = Rsdp::get_rsdp(already_supplied_rsdp); if let Some(rsdp) = rsdp_opt { - debug!("SDT address: {:#x}", rsdp.sdt_address()); + debug!("SDT address: {:#x}", rsdp.sdt_address().data()); let rxsdt = get_sdt(rsdp.sdt_address(), &mut KernelMapper::lock_rw()); let rxsdt = if let Some(rsdt) = Rsdt::new(rxsdt) { @@ -138,7 +136,7 @@ pub unsafe fn init(already_supplied_rsdp: Option<*const u8>) { } for sdt_address in rxsdt.iter() { - let sdt = &*((sdt_address + crate::PHYS_OFFSET) as *const Sdt); + let sdt = &*(RmmA::phys_to_virt(sdt_address).data() as *const Sdt); let signature = get_sdt_signature(sdt); if let Some(ref mut ptrs) = *(SDT_POINTERS.write()) { diff --git a/src/acpi/rsdp.rs b/src/acpi/rsdp.rs index a68e94d5e2..28be137ebb 100644 --- a/src/acpi/rsdp.rs +++ b/src/acpi/rsdp.rs @@ -1,3 +1,5 @@ +use rmm::PhysicalAddress; + /// RSDP #[derive(Copy, Clone, Debug)] #[repr(C, packed)] @@ -24,11 +26,11 @@ impl Rsdp { } /// Get the RSDT or XSDT address - pub fn sdt_address(&self) -> usize { - if self.revision >= 2 { + pub fn sdt_address(&self) -> PhysicalAddress { + PhysicalAddress::new(if self.revision >= 2 { self.xsdt_address as usize } else { self.rsdt_address as usize - } + }) } } diff --git a/src/acpi/rsdt.rs b/src/acpi/rsdt.rs index ce996d8969..226d4b8d16 100644 --- a/src/acpi/rsdt.rs +++ b/src/acpi/rsdt.rs @@ -1,5 +1,6 @@ use alloc::boxed::Box; use core::{convert::TryFrom, mem}; +use rmm::PhysicalAddress; use super::{rxsdt::Rxsdt, sdt::Sdt}; @@ -23,7 +24,7 @@ impl Rsdt { } impl Rxsdt for Rsdt { - fn iter(&self) -> Box> { + fn iter(&self) -> Box> { Box::new(RsdtIter { sdt: self.0, i: 0 }) } } @@ -34,7 +35,7 @@ pub struct RsdtIter { } impl Iterator for RsdtIter { - type Item = usize; + type Item = PhysicalAddress; fn next(&mut self) -> Option { if self.i < self.sdt.data_len() / mem::size_of::() { let item = unsafe { @@ -43,7 +44,7 @@ impl Iterator for RsdtIter { .read_unaligned() }; self.i += 1; - Some(item as usize) + Some(PhysicalAddress::new(item as usize)) } else { None } diff --git a/src/acpi/rxsdt.rs b/src/acpi/rxsdt.rs index f1803884ba..a4bc6c967f 100644 --- a/src/acpi/rxsdt.rs +++ b/src/acpi/rxsdt.rs @@ -1,5 +1,6 @@ use alloc::boxed::Box; +use rmm::PhysicalAddress; pub trait Rxsdt { - fn iter(&self) -> Box>; + fn iter(&self) -> Box>; } diff --git a/src/acpi/xsdt.rs b/src/acpi/xsdt.rs index 5593250d02..55e41646ab 100644 --- a/src/acpi/xsdt.rs +++ b/src/acpi/xsdt.rs @@ -1,5 +1,6 @@ use alloc::boxed::Box; use core::{convert::TryFrom, mem}; +use rmm::PhysicalAddress; use super::{rxsdt::Rxsdt, sdt::Sdt}; @@ -23,7 +24,7 @@ impl Xsdt { } impl Rxsdt for Xsdt { - fn iter(&self) -> Box> { + fn iter(&self) -> Box> { Box::new(XsdtIter { sdt: self.0, i: 0 }) } } @@ -34,14 +35,14 @@ pub struct XsdtIter { } impl Iterator for XsdtIter { - type Item = usize; + type Item = PhysicalAddress; fn next(&mut self) -> Option { if self.i < self.sdt.data_len() / mem::size_of::() { let item = unsafe { core::ptr::read_unaligned((self.sdt.data_address() as *const u64).add(self.i)) }; self.i += 1; - Some(item as usize) + Some(PhysicalAddress::new(item as usize)) } else { None } diff --git a/src/startup/mod.rs b/src/startup/mod.rs index 12bc000a0c..6b68f8105b 100644 --- a/src/startup/mod.rs +++ b/src/startup/mod.rs @@ -1,5 +1,7 @@ use core::slice; +use crate::memory::{PhysicalAddress, RmmA, RmmArch}; + pub mod memory; #[repr(C, packed(8))] @@ -75,7 +77,8 @@ impl KernelArgs { pub(crate) fn env(&self) -> &'static [u8] { unsafe { slice::from_raw_parts( - (crate::PHYS_OFFSET + self.env_base as usize) as *const u8, + RmmA::phys_to_virt(PhysicalAddress::new(self.env_base as usize)).data() + as *const u8, self.env_size as usize, ) } @@ -86,7 +89,8 @@ impl KernelArgs { if self.hwdesc_base != 0 { let data = unsafe { slice::from_raw_parts( - (crate::PHYS_OFFSET + self.hwdesc_base as usize) as *const u8, + RmmA::phys_to_virt(PhysicalAddress::new(self.hwdesc_base as usize)).data() + as *const u8, self.hwdesc_size as usize, ) }; @@ -105,7 +109,8 @@ impl KernelArgs { if self.hwdesc_base != 0 { let data = unsafe { slice::from_raw_parts( - (crate::PHYS_OFFSET + self.hwdesc_base as usize) as *const u8, + RmmA::phys_to_virt(PhysicalAddress::new(self.hwdesc_base as usize)).data() + as *const u8, self.hwdesc_size as usize, ) };