Initial memory management work

This commit is contained in:
River 2025-05-18 19:13:54 -04:00
parent c587f8863b
commit de130e924a
Signed by: shibedrill
GPG Key ID: 5FE0CB25945EFAA2
12 changed files with 87 additions and 56 deletions

View File

@ -1,2 +0,0 @@
// Copyright (c) 2025 shibedrill
// SPDX-License-Identifier: GPL-3.0-or-later

View File

@ -2,4 +2,3 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
pub mod asm; pub mod asm;
pub mod display;

View File

@ -1,2 +0,0 @@
// Copyright (c) 2025 shibedrill
// SPDX-License-Identifier: GPL-3.0-or-later

View File

@ -2,4 +2,3 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
pub mod asm; pub mod asm;
pub mod display;

View File

@ -1,2 +0,0 @@
// Copyright (c) 2025 shibedrill
// SPDX-License-Identifier: GPL-3.0-or-later

View File

@ -2,4 +2,3 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
pub mod asm; pub mod asm;
pub mod display;

View File

@ -1,7 +0,0 @@
// Copyright (c) 2025 shibedrill
// SPDX-License-Identifier: GPL-3.0-or-later
#![allow(dead_code)]
#![allow(unused_variables)]

View File

@ -3,5 +3,4 @@
pub mod acpi; pub mod acpi;
pub mod asm; pub mod asm;
pub mod display;
pub mod serial; pub mod serial;

View File

@ -32,3 +32,6 @@ pub static ADDRESS_REQUEST: ExecutableAddressRequest =
#[used] #[used]
#[unsafe(link_section = ".requests")] #[unsafe(link_section = ".requests")]
pub static FRAMEBUFFER_REQUEST: FramebufferRequest = limine::request::FramebufferRequest::new(); pub static FRAMEBUFFER_REQUEST: FramebufferRequest = limine::request::FramebufferRequest::new();
#[used]
#[unsafe(link_section = ".requests")]
pub static MEMMAP_REQUEST: MemoryMapRequest = limine::request::MemoryMapRequest::new();

View File

@ -46,7 +46,7 @@ impl Logger {
} else if level <= self.level { } else if level <= self.level {
for sub in &self.subscriber { for sub in &self.subscriber {
let mut message = String::new(); let mut message = String::new();
writeln!(&mut message, "{level:?}:\t {msg}").unwrap(); writeln!(&mut message, "{level:?}:\t{msg}").unwrap();
sub.lock().write(&message); sub.lock().write(&message);
} }
} }

View File

@ -18,13 +18,17 @@ mod syscall_runner;
use arch::current::*; use arch::current::*;
use arch::x86_64::serial::Serialport; use arch::x86_64::serial::Serialport;
use limine::file::File; use limine::file::File;
use spin::mutex::Mutex; use limine::memory_map::EntryType;
#[allow(unused_imports)] #[allow(unused_imports)]
use lzma_rs::lzma_decompress; use lzma_rs::lzma_decompress;
use spin::mutex::Mutex;
use syscall_runner::KERNEL_VERSION_MAJOR;
use syscall_runner::KERNEL_VERSION_MINOR;
use syscall_runner::KERNEL_VERSION_PATCH;
use crate::boot::*; use crate::boot::*;
use crate::log::*; use crate::log::*;
use crate::memory::alloc::{boxed, format, string::*, vec, collections::BTreeMap}; use crate::memory::alloc::{boxed, collections::BTreeMap, format, string::*, vec};
use crate::params::*; use crate::params::*;
#[unsafe(no_mangle)] #[unsafe(no_mangle)]
@ -49,11 +53,12 @@ unsafe extern "C" fn main() -> ! {
); );
// Set up logging level from params // Set up logging level from params
if let Some(level) = params.get("-loglevel") { // Nothing we can do here if this fails since no log subscribers are initialized yet
if let Ok(parsed_level) = LogLevel::try_from(level.as_str()) { if let Some(level) = params.get("-loglevel")
&& let Ok(parsed_level) = LogLevel::try_from(level.as_str())
{
LOGGER.lock().level = parsed_level; LOGGER.lock().level = parsed_level;
} }
}
// Add subscribers to logger // Add subscribers to logger
if let Some(device) = params.get("-logdev") { if let Some(device) = params.get("-logdev") {
let log_device_list: vec::Vec<&str> = device.split(',').collect(); let log_device_list: vec::Vec<&str> = device.split(',').collect();
@ -86,6 +91,15 @@ unsafe extern "C" fn main() -> ! {
); );
} }
log(
LogLevel::Info,
&format!(
"Boot: Booting gila version {KERNEL_VERSION_MAJOR}.{KERNEL_VERSION_MINOR}.{KERNEL_VERSION_PATCH}"
),
);
log(LogLevel::Info, "Boot: Trans Rights!");
if let Some(address_response) = ADDRESS_REQUEST.get_response() { if let Some(address_response) = ADDRESS_REQUEST.get_response() {
log( log(
LogLevel::Trace, LogLevel::Trace,
@ -96,39 +110,28 @@ unsafe extern "C" fn main() -> ! {
) )
} }
log(
LogLevel::Info,
"Boot: Log devices configured. Booting `gila`.",
);
log(LogLevel::Info, "Boot: Trans Rights!");
if let Some(framebuffer_response) = FRAMEBUFFER_REQUEST.get_response() { if let Some(framebuffer_response) = FRAMEBUFFER_REQUEST.get_response() {
let fb = framebuffer_response.framebuffers().next().unwrap(); let fb = framebuffer_response.framebuffers().next().unwrap();
log( log(LogLevel::Info, "Boot: Framebuffer response received");
LogLevel::Info,
"Boot: Framebuffer response received. Display enabled."
);
log( log(
LogLevel::Trace, LogLevel::Trace,
&format!("Boot: Framebuffer dimensions: {}x{}, {}", fb.width(), fb.height(), fb.bpp()) &format!(
"Boot: Framebuffer dimensions: {}x{}, {}",
fb.width(),
fb.height(),
fb.bpp()
),
); );
} }
let _smp_response = MP_REQUEST.get_response(); let _smp_response = MP_REQUEST.get_response();
match _smp_response { match _smp_response {
None => log( None => log(LogLevel::Error, "MP: Multiprocessing response not received"),
LogLevel::Error,
"MP: bootloader response not received. Multiprocessing is disabled.",
),
Some(resp) => { Some(resp) => {
log(LogLevel::Info, "MP: Multiprocessing response received");
log( log(
LogLevel::Info, LogLevel::Info,
"MP: bootloader response received. Multiprocessing enabled.", &format!("MP: {} CPUs found", resp.cpus().len()),
);
log(
LogLevel::Info,
&format!("MP: {} CPUs found.", resp.cpus().len()),
); );
} }
} }
@ -140,7 +143,7 @@ unsafe extern "C" fn main() -> ! {
log( log(
LogLevel::Info, LogLevel::Info,
&format!( &format!(
"Boot: Kernel modules count: {}", "Boot: {} kernel modules found",
module_response.modules().len() module_response.modules().len()
), ),
); );
@ -156,7 +159,7 @@ unsafe extern "C" fn main() -> ! {
if let Some(irfs_path) = params.get("-initramfs") { if let Some(irfs_path) = params.get("-initramfs") {
log( log(
LogLevel::Info, LogLevel::Info,
&format!("Boot: initramfs path requested: {}", irfs_path) &format!("Boot: initramfs path requested: {irfs_path}"),
); );
let initramfs_option: Option<&File> = { let initramfs_option: Option<&File> = {
let mut result: Option<&File> = None; let mut result: Option<&File> = None;
@ -164,15 +167,60 @@ unsafe extern "C" fn main() -> ! {
if &file.path().to_string_lossy().to_string() == irfs_path { if &file.path().to_string_lossy().to_string() == irfs_path {
result = Some(file); result = Some(file);
} }
}; }
result result
}; };
if let Some(_initramfs_file) = initramfs_option { if let Some(_initramfs_file) = initramfs_option {
log(LogLevel::Info, "Boot: Found initramfs at supplied path")
}
}
}
if let Some(mmap_response) = MEMMAP_REQUEST.get_response() {
log(LogLevel::Info, "Boot: Memory map received");
if !mmap_response.entries().is_empty() {
log(LogLevel::Info, "Boot: Memory map entries list:");
let mut usable: u64 = 0;
let mut reclaimable: u64 = 0;
for entry in mmap_response.entries() {
log( log(
LogLevel::Info, LogLevel::Info,
"Boot: Found initramfs at supplied path" &format!(
"\t0x{:x} @ 0x{:x}: {}",
entry.length,
entry.base,
match entry.entry_type {
EntryType::ACPI_NVS => "ACPI (reserved)",
EntryType::ACPI_RECLAIMABLE => {
reclaimable += entry.length;
"ACPI (reclaimable)"
}
EntryType::BAD_MEMORY => "damaged/unusable",
EntryType::BOOTLOADER_RECLAIMABLE => {
reclaimable += entry.length;
"bootloader (reclaimable)"
}
#[allow(unreachable_patterns, deprecated)]
EntryType::EXECUTABLE_AND_MODULES | EntryType::KERNEL_AND_MODULES =>
"executable & modules",
EntryType::FRAMEBUFFER => "framebuffer",
EntryType::RESERVED => "reserved",
EntryType::USABLE => {
usable += entry.length;
"usable"
}
_ => "unidentified",
}
),
) )
} }
log(
LogLevel::Info,
&format!(
"Boot: Memory report: {usable} bytes usable, {reclaimable} bytes reclaimable, {} bytes ultimately available",
usable + reclaimable
),
)
} }
} }
@ -182,9 +230,6 @@ unsafe extern "C" fn main() -> ! {
core::arch::asm!("nop"); core::arch::asm!("nop");
} }
} }
log( log(LogLevel::Trace, "Heartbeat")
LogLevel::Trace,
"Heartbeat"
)
} }
} }

View File

@ -10,21 +10,21 @@ pub static KERNEL_VERSION_MAJOR: u8 = match u8::from_str_radix(env!("CARGO_PKG_V
{ {
Ok(ver) => ver, Ok(ver) => ver,
Err(_) => { Err(_) => {
panic!("Invalid version number ") panic!("Invalid major version number ")
} }
}; };
pub static KERNEL_VERSION_MINOR: u8 = match u8::from_str_radix(env!("CARGO_PKG_VERSION_MINOR"), 10) pub static KERNEL_VERSION_MINOR: u8 = match u8::from_str_radix(env!("CARGO_PKG_VERSION_MINOR"), 10)
{ {
Ok(ver) => ver, Ok(ver) => ver,
Err(_) => { Err(_) => {
panic!("Invalid version number ") panic!("Invalid minor version number ")
} }
}; };
pub static KERNEL_VERSION_PATCH: u8 = match u8::from_str_radix(env!("CARGO_PKG_VERSION_PATCH"), 10) pub static KERNEL_VERSION_PATCH: u8 = match u8::from_str_radix(env!("CARGO_PKG_VERSION_PATCH"), 10)
{ {
Ok(ver) => ver, Ok(ver) => ver,
Err(_) => { Err(_) => {
panic!("Invalid version number ") panic!("Invalid patch version number ")
} }
}; };