Fixed wrong comment
This commit is contained in:
parent
eef96dfc87
commit
ed4aef8978
@ -6,6 +6,7 @@ use crate::boot::params::EXECUTABLE_FILE_RESPONSE;
|
|||||||
use crate::constants::NEWLINE;
|
use crate::constants::NEWLINE;
|
||||||
use crate::{LOGGER, LogLevel, format, log_info, log_trace};
|
use crate::{LOGGER, LogLevel, format, log_info, log_trace};
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
|
use free_list::{AllocError, FreeList, PAGE_SIZE, PageRange};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use limine::response::MemoryMapResponse;
|
use limine::response::MemoryMapResponse;
|
||||||
use limine::{
|
use limine::{
|
||||||
@ -15,14 +16,15 @@ use limine::{
|
|||||||
};
|
};
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
use talc::*;
|
use talc::*;
|
||||||
use free_list::{AllocError, FreeList, PageRange, PAGE_SIZE};
|
|
||||||
|
|
||||||
pub extern crate alloc;
|
pub extern crate alloc;
|
||||||
|
|
||||||
static FREELIST: Mutex<FreeList<32>> = Mutex::new(FreeList::<32>::new());
|
static FREELIST: Mutex<FreeList<32>> = Mutex::new(FreeList::<32>::new());
|
||||||
|
|
||||||
lazy_static! {
|
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> {
|
pub fn deallocate_usable() -> Result<(), AllocError> {
|
||||||
@ -30,7 +32,9 @@ pub fn deallocate_usable() -> Result<(), AllocError> {
|
|||||||
let mut any_error: Option<AllocError> = None;
|
let mut any_error: Option<AllocError> = None;
|
||||||
let mut bytes_deallocated: u64 = 0;
|
let mut bytes_deallocated: u64 = 0;
|
||||||
for entry in MEMMAP_RESPONSE.entries() {
|
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) {
|
if let Err(error) = deallocate(**entry) {
|
||||||
any_error = Some(error);
|
any_error = Some(error);
|
||||||
}
|
}
|
||||||
@ -45,12 +49,10 @@ pub fn deallocate_usable() -> Result<(), AllocError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn deallocate(entry: limine::memory_map::Entry) -> 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!");
|
let range = PageRange::from_start_len(entry.base as usize, entry.length as usize)
|
||||||
unsafe {
|
.expect("Could not convert map entry to range!");
|
||||||
FREELIST.lock().deallocate(range)
|
unsafe { FREELIST.lock().deallocate(range) }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn log_memory() {
|
pub fn log_memory() {
|
||||||
@ -113,8 +115,11 @@ pub fn log_memory() {
|
|||||||
log_trace!("Deallocating available memory...");
|
log_trace!("Deallocating available memory...");
|
||||||
let _ = deallocate_usable();
|
let _ = deallocate_usable();
|
||||||
let free_bytes = { FREELIST.lock().free_space() };
|
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 {
|
} else {
|
||||||
panic!("Memory map contains no entries");
|
panic!("Memory map contains no entries");
|
||||||
}
|
}
|
||||||
@ -168,7 +173,7 @@ lazy_static! {
|
|||||||
.expect("Did not get HHDM response from bootloader");
|
.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];
|
static mut ARENA: [u8; 1000000] = [0; 1000000];
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
|
Loading…
Reference in New Issue
Block a user