diff options
author | Nathan Ringo <nathan@remexre.com> | 2024-09-14 18:01:38 -0500 |
---|---|---|
committer | Nathan Ringo <nathan@remexre.com> | 2024-09-14 18:01:38 -0500 |
commit | 0392b41e7081c11caa9d04aa738bdac97062e9dd (patch) | |
tree | 3f6db51ec0583f4bfe24347d6aa423b050f80839 | |
parent | 5a7617e4d524a74a4fb21f956fead71e789c454c (diff) |
Fix parens, adds VMA init doc comment.
-rw-r--r-- | crates/kernel/src/alloc.rs | 10 | ||||
-rw-r--r-- | crates/kernel/src/lib.rs | 7 |
2 files changed, 13 insertions, 4 deletions
diff --git a/crates/kernel/src/alloc.rs b/crates/kernel/src/alloc.rs index f634c73..93d8b15 100644 --- a/crates/kernel/src/alloc.rs +++ b/crates/kernel/src/alloc.rs @@ -2,7 +2,7 @@ use crate::paging::{ BuddyAllocator, MapError, MappingFlags, PageTable, ASID, LOMEM_TOP, MAX_PAGE_SIZE_BITS, - PAGE_SIZES, + PAGE_SIZE, PAGE_SIZES, }; use allocator_api2::alloc::AllocError; use contracts::requires; @@ -15,7 +15,7 @@ static BUDDY_ALLOCATOR: FairMutex<Option<BuddyAllocator>> = FairMutex::new(None) /// The global kernel page table. static KERNEL_PAGE_TABLE: FairMutex<Option<&'static mut PageTable>> = FairMutex::new(None); -/// Initializes the allocator and enables paging. +/// Initializes the kernel page table and enables paging. /// /// # Safety /// @@ -63,8 +63,14 @@ pub unsafe fn init_kernel_page_table(buddy_allocator: BuddyAllocator) { *KERNEL_PAGE_TABLE.lock() = Some(page_table); } +/// Initializes the virtual memory allocator and the regular allocator. +/// +/// # Safety +/// +/// - `himem_top` must be accurate. #[requires(BUDDY_ALLOCATOR.lock().is_some())] #[requires(KERNEL_PAGE_TABLE.lock().is_some())] +#[requires(himem_top & (PAGE_SIZE - 1) == 0)] pub unsafe fn init_kernel_virtual_memory_allocator(himem_top: usize) { todo!() } diff --git a/crates/kernel/src/lib.rs b/crates/kernel/src/lib.rs index 8c964af..0ca535a 100644 --- a/crates/kernel/src/lib.rs +++ b/crates/kernel/src/lib.rs @@ -2,7 +2,10 @@ #![no_std] use crate::{ - alloc::{alloc_page, init_kernel_page_table, kernel_log_page_table, kernel_map}, + alloc::{ + alloc_page, init_kernel_page_table, init_kernel_virtual_memory_allocator, + kernel_log_page_table, kernel_map, + }, constants::STACK_SIZE, paging::{MappingFlags, PAGE_SIZE, PAGE_SIZE_BITS}, }; @@ -191,7 +194,7 @@ pub unsafe extern "C" fn hart0_early_boot(early_boot_addrs: &mut EarlyBootAddrs) let new_stack_start = new_stack_end - STACK_SIZE; vaddr_bump = new_stack_start; for i in 0..((STACK_SIZE >> PAGE_SIZE_BITS) - 1) { - let vaddr = new_kernel_start + i << PAGE_SIZE_BITS; + let vaddr = new_kernel_start + (i << PAGE_SIZE_BITS); let paddr = alloc_page(PAGE_SIZE).expect("failed to allocate memory for a hart0 stack page"); kernel_map( |