Fix i686.

This commit is contained in:
4lDO2
2024-03-23 16:54:47 +01:00
parent 1b3e024f7d
commit 7261dccb72
6 changed files with 19 additions and 55 deletions
+2 -1
View File
@@ -9,7 +9,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 {
@@ -29,6 +29,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 page attribute table
#[cold]
+8 -48
View File
@@ -10,7 +10,7 @@ use rmm::{
};
use spin::Mutex;
use crate::cpu_set::LogicalCpuId;
use crate::{cpu_set::LogicalCpuId, memory::TheFrameAllocator};
use super::CurrentRmmArch as RmmA;
@@ -49,7 +49,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,
@@ -61,7 +61,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() {
@@ -184,46 +186,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(
@@ -239,8 +202,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);
@@ -291,7 +252,7 @@ impl KernelMapper {
unsafe {
Self::lock_for_manual_mapper(
current_processor,
PageMapper::current(TableKind::Kernel, FRAME_ALLOCATOR),
PageMapper::current(TableKind::Kernel, TheFrameAllocator),
)
}
}
@@ -537,7 +498,7 @@ pub unsafe fn init(
}
AREA_COUNT.get().write(area_i as u16);
let allocator = inner::<A>(
inner(
areas,
kernel_base,
kernel_size_aligned,
@@ -550,5 +511,4 @@ pub unsafe fn init(
initfs_base,
initfs_size_aligned,
);
*INNER_ALLOCATOR.lock() = Some(allocator);
}
-3
View File
@@ -202,9 +202,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();
// Initialize data structures used to track pages.
memory::init_mm();
// Stop graphical debug
#[cfg(feature = "graphical_debug")]
graphical_debug::fini();
+2 -2
View File
@@ -4,8 +4,8 @@ use core::{
sync::atomic::{self, AtomicUsize, Ordering},
};
use rmm::{
Arch, BuddyAllocator, BumpAllocator, FrameAllocator, FrameCount, FrameUsage, MemoryArea,
PageFlags, PageMapper, PhysicalAddress, TableKind, VirtualAddress, KILOBYTE, MEGABYTE,
Arch, BumpAllocator, FrameAllocator, FrameCount, FrameUsage, MemoryArea, PageFlags, PageMapper,
PhysicalAddress, TableKind, VirtualAddress, KILOBYTE, MEGABYTE,
};
use spin::Mutex;
+1 -1
View File
@@ -2130,7 +2130,7 @@ pub fn setup_new_utable() -> Result<Table> {
use crate::paging::KernelMapper;
let utable = unsafe {
PageMapper::create(TableKind::User, crate::rmm::FRAME_ALLOCATOR)
PageMapper::create(TableKind::User, crate::memory::TheFrameAllocator)
.ok_or(Error::new(ENOMEM))?
};
+6
View File
@@ -495,6 +495,12 @@ fn init_sections(mut allocator: BumpAllocator<RmmA>) {
while let Some(mut memory_map_area) = iter.next() {
// TODO: NonZeroUsize
// TODO: x86_32 fails without this check
if memory_map_area.size == 0 {
continue;
}
assert_ne!(
memory_map_area.size, 0,
"RMM should enforce areas are not zeroed"