diff --git a/src/kernel/memory.rs b/src/kernel/memory.rs index 3ee5fce..40c5fb3 100644 --- a/src/kernel/memory.rs +++ b/src/kernel/memory.rs @@ -6,6 +6,7 @@ use crate::boot::params::EXECUTABLE_FILE_RESPONSE; use crate::constants::NEWLINE; use crate::{LOGGER, LogLevel, format, log_info, log_trace}; use alloc::string::String; +use free_list::{AllocError, FreeList, PAGE_SIZE, PageRange}; use lazy_static::lazy_static; use limine::response::MemoryMapResponse; use limine::{ @@ -15,14 +16,15 @@ use limine::{ }; use spin::Mutex; use talc::*; -use free_list::{AllocError, FreeList, PageRange, PAGE_SIZE}; pub extern crate alloc; static FREELIST: Mutex> = Mutex::new(FreeList::<32>::new()); lazy_static! { - pub static ref MEMMAP_RESPONSE: &'static MemoryMapResponse = MEMMAP_REQUEST.get_response().expect("Bootloader did not supply memory map"); + pub static ref MEMMAP_RESPONSE: &'static MemoryMapResponse = MEMMAP_REQUEST + .get_response() + .expect("Bootloader did not supply memory map"); } pub fn deallocate_usable() -> Result<(), AllocError> { @@ -30,7 +32,9 @@ pub fn deallocate_usable() -> Result<(), AllocError> { let mut any_error: Option = None; let mut bytes_deallocated: u64 = 0; for entry in MEMMAP_RESPONSE.entries() { - if (entry.entry_type == EntryType::USABLE) | (entry.entry_type == EntryType::BOOTLOADER_RECLAIMABLE) { + if (entry.entry_type == EntryType::USABLE) + | (entry.entry_type == EntryType::BOOTLOADER_RECLAIMABLE) + { if let Err(error) = deallocate(**entry) { any_error = Some(error); } @@ -45,12 +49,10 @@ pub fn deallocate_usable() -> Result<(), AllocError> { } } - pub fn deallocate(entry: limine::memory_map::Entry) -> Result<(), AllocError> { - let range = PageRange::from_start_len(entry.base as usize, entry.length as usize).expect("Could not convert map entry to range!"); - unsafe { - FREELIST.lock().deallocate(range) - } + let range = PageRange::from_start_len(entry.base as usize, entry.length as usize) + .expect("Could not convert map entry to range!"); + unsafe { FREELIST.lock().deallocate(range) } } pub fn log_memory() { @@ -113,8 +115,11 @@ pub fn log_memory() { log_trace!("Deallocating available memory..."); let _ = deallocate_usable(); let free_bytes = { FREELIST.lock().free_space() }; - log_info!("Freelist: 0x{:x} bytes ({} pages)", free_bytes, free_bytes / PAGE_SIZE); - + log_info!( + "Freelist: 0x{:x} bytes ({} pages)", + free_bytes, + free_bytes / PAGE_SIZE + ); } else { panic!("Memory map contains no entries"); } @@ -168,7 +173,7 @@ lazy_static! { .expect("Did not get HHDM response from bootloader"); } -// TODO: 10kb kernel heap. Need to figure out how to make this less stupid... +// TODO: 1mb kernel heap. Need to figure out how to make this less stupid... static mut ARENA: [u8; 1000000] = [0; 1000000]; #[global_allocator]