Fix aarch64.

This commit is contained in:
4lDO2
2024-03-23 19:16:53 +01:00
parent 7261dccb72
commit e6dc0e96f0
4 changed files with 11 additions and 52 deletions
+2 -1
View File
@@ -10,7 +10,7 @@ use self::mapper::PageFlushAll;
pub use super::CurrentRmmArch as RmmA;
pub use rmm::{Arch as RmmArch, Flusher, PageFlags, PhysicalAddress, TableKind, VirtualAddress};
pub type PageMapper = rmm::PageMapper<RmmA, crate::arch::rmm::LockedAllocator>;
pub type PageMapper = rmm::PageMapper<RmmA, crate::memory::TheFrameAllocator>;
pub use crate::rmm::KernelMapper;
pub mod entry;
@@ -21,6 +21,7 @@ pub const ENTRY_COUNT: usize = RmmA::PAGE_ENTRIES;
/// Size of pages
pub const PAGE_SIZE: usize = RmmA::PAGE_SIZE;
pub const PAGE_MASK: usize = RmmA::PAGE_OFFSET_MASK;
/// Setup Memory Access Indirection Register
#[cold]
+8 -48
View File
@@ -32,7 +32,7 @@ pub struct BootloaderMemoryEntry {
pub kind: BootloaderMemoryKind,
}
unsafe fn page_flags<A: Arch>(virt: VirtualAddress) -> PageFlags<A> {
unsafe fn page_flags<A: Arch>(virt: VirtualAddress) -> PageFlags<RmmA> {
use crate::kernel_executable_offsets::*;
let virt_addr = virt.data();
@@ -48,7 +48,7 @@ unsafe fn page_flags<A: Arch>(virt: VirtualAddress) -> PageFlags<A> {
}
}
unsafe fn inner<A: Arch>(
unsafe fn inner(
areas: &'static [MemoryArea],
kernel_base: usize,
kernel_size_aligned: usize,
@@ -60,7 +60,9 @@ unsafe fn inner<A: Arch>(
acpi_size_aligned: usize,
initfs_base: usize,
initfs_size_aligned: usize,
) -> BuddyAllocator<A> {
) {
type A = RmmA;
// First, calculate how much memory we have
let mut size = 0;
for area in areas.iter() {
@@ -203,46 +205,7 @@ unsafe fn inner<A: Arch>(
(offset + (KILOBYTE - 1)) / KILOBYTE
);
BuddyAllocator::<A>::new(bump_allocator).expect("failed to create BuddyAllocator")
}
// There can only be one allocator (at the moment), so making this a ZST is great!
#[derive(Clone, Copy)]
pub struct LockedAllocator;
static INNER_ALLOCATOR: Mutex<Option<BuddyAllocator<RmmA>>> = Mutex::new(None);
impl FrameAllocator for LockedAllocator {
unsafe fn allocate(&mut self, count: FrameCount) -> Option<PhysicalAddress> {
if let Some(ref mut allocator) = *INNER_ALLOCATOR.lock() {
allocator.allocate(count)
} else {
None
}
}
unsafe fn free(&mut self, address: PhysicalAddress, count: FrameCount) {
if let Some(ref mut allocator) = *INNER_ALLOCATOR.lock() {
allocator.free(address, count)
}
}
unsafe fn usage(&self) -> FrameUsage {
if let Some(ref allocator) = *INNER_ALLOCATOR.lock() {
allocator.usage()
} else {
FrameUsage::new(FrameCount::new(0), FrameCount::new(0))
}
}
}
impl core::fmt::Debug for LockedAllocator {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match INNER_ALLOCATOR.try_lock().as_deref() {
Some(Some(alloc)) => write!(f, "[locked allocator: {:?}]", unsafe { alloc.usage() }),
Some(None) => write!(f, "[uninitialized lock allocator]"),
None => write!(f, "[failed to lock]"),
}
}
crate::memory::init_mm(bump_allocator);
}
static AREAS: SyncUnsafeCell<[MemoryArea; 512]> = SyncUnsafeCell::new(
@@ -261,8 +224,6 @@ pub fn areas() -> &'static [MemoryArea] {
unsafe { &(&*AREAS.get())[..AREA_COUNT.get().read().into()] }
}
pub static FRAME_ALLOCATOR: LockedAllocator = LockedAllocator;
const NO_PROCESSOR: usize = !0;
static LOCK_OWNER: AtomicUsize = AtomicUsize::new(NO_PROCESSOR);
static LOCK_COUNT: AtomicUsize = AtomicUsize::new(0);
@@ -313,7 +274,7 @@ impl KernelMapper {
unsafe {
Self::lock_for_manual_mapper(
current_processor,
PageMapper::current(TableKind::Kernel, FRAME_ALLOCATOR),
PageMapper::current(TableKind::Kernel, crate::memory::TheFrameAllocator),
)
}
}
@@ -514,7 +475,7 @@ pub unsafe fn init(
}
AREA_COUNT.get().write(area_i as u16);
let allocator = inner::<A>(
inner(
areas,
kernel_base,
kernel_size_aligned,
@@ -527,5 +488,4 @@ pub unsafe fn init(
initfs_base,
initfs_size_aligned,
);
*INNER_ALLOCATOR.lock() = Some(allocator);
}
-2
View File
@@ -186,8 +186,6 @@ pub unsafe extern "C" fn kstart(args_ptr: *const KernelArgs) -> ! {
// Initialize all of the non-core devices not otherwise needed to complete initialization
device::init_noncore();
crate::memory::init_mm();
// Stop graphical debug
//#[cfg(feature = "graphical_debug")]
//graphical_debug::fini();
+1 -1
View File
@@ -2117,7 +2117,7 @@ impl Drop for Table {
#[cfg(target_arch = "aarch64")]
pub fn setup_new_utable() -> Result<Table> {
let utable = unsafe {
PageMapper::create(TableKind::User, crate::rmm::FRAME_ALLOCATOR)
PageMapper::create(TableKind::User, crate::memory::TheFrameAllocator)
.ok_or(Error::new(ENOMEM))?
};