Initial memory management work
This commit is contained in:
parent
c587f8863b
commit
de130e924a
@ -1,2 +0,0 @@
|
||||
// Copyright (c) 2025 shibedrill
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
@ -2,4 +2,3 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
pub mod asm;
|
||||
pub mod display;
|
||||
|
@ -1,2 +0,0 @@
|
||||
// Copyright (c) 2025 shibedrill
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
@ -2,4 +2,3 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
pub mod asm;
|
||||
pub mod display;
|
||||
|
@ -1,2 +0,0 @@
|
||||
// Copyright (c) 2025 shibedrill
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
@ -2,4 +2,3 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
pub mod asm;
|
||||
pub mod display;
|
||||
|
@ -1,7 +0,0 @@
|
||||
// Copyright (c) 2025 shibedrill
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
|
@ -3,5 +3,4 @@
|
||||
|
||||
pub mod acpi;
|
||||
pub mod asm;
|
||||
pub mod display;
|
||||
pub mod serial;
|
||||
|
@ -32,3 +32,6 @@ pub static ADDRESS_REQUEST: ExecutableAddressRequest =
|
||||
#[used]
|
||||
#[unsafe(link_section = ".requests")]
|
||||
pub static FRAMEBUFFER_REQUEST: FramebufferRequest = limine::request::FramebufferRequest::new();
|
||||
#[used]
|
||||
#[unsafe(link_section = ".requests")]
|
||||
pub static MEMMAP_REQUEST: MemoryMapRequest = limine::request::MemoryMapRequest::new();
|
||||
|
@ -46,7 +46,7 @@ impl Logger {
|
||||
} else if level <= self.level {
|
||||
for sub in &self.subscriber {
|
||||
let mut message = String::new();
|
||||
writeln!(&mut message, "{level:?}:\t {msg}").unwrap();
|
||||
writeln!(&mut message, "{level:?}:\t{msg}").unwrap();
|
||||
sub.lock().write(&message);
|
||||
}
|
||||
}
|
||||
|
@ -18,13 +18,17 @@ mod syscall_runner;
|
||||
use arch::current::*;
|
||||
use arch::x86_64::serial::Serialport;
|
||||
use limine::file::File;
|
||||
use spin::mutex::Mutex;
|
||||
use limine::memory_map::EntryType;
|
||||
#[allow(unused_imports)]
|
||||
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::log::*;
|
||||
use crate::memory::alloc::{boxed, format, string::*, vec, collections::BTreeMap};
|
||||
use crate::memory::alloc::{boxed, collections::BTreeMap, format, string::*, vec};
|
||||
use crate::params::*;
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
@ -49,11 +53,12 @@ unsafe extern "C" fn main() -> ! {
|
||||
);
|
||||
|
||||
// Set up logging level from params
|
||||
if let Some(level) = params.get("-loglevel") {
|
||||
if let Ok(parsed_level) = LogLevel::try_from(level.as_str()) {
|
||||
// Nothing we can do here if this fails since no log subscribers are initialized yet
|
||||
if let Some(level) = params.get("-loglevel")
|
||||
&& let Ok(parsed_level) = LogLevel::try_from(level.as_str())
|
||||
{
|
||||
LOGGER.lock().level = parsed_level;
|
||||
}
|
||||
}
|
||||
// Add subscribers to logger
|
||||
if let Some(device) = params.get("-logdev") {
|
||||
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() {
|
||||
log(
|
||||
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() {
|
||||
let fb = framebuffer_response.framebuffers().next().unwrap();
|
||||
log(
|
||||
LogLevel::Info,
|
||||
"Boot: Framebuffer response received. Display enabled."
|
||||
);
|
||||
log(LogLevel::Info, "Boot: Framebuffer response received");
|
||||
log(
|
||||
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();
|
||||
match _smp_response {
|
||||
None => log(
|
||||
LogLevel::Error,
|
||||
"MP: bootloader response not received. Multiprocessing is disabled.",
|
||||
),
|
||||
None => log(LogLevel::Error, "MP: Multiprocessing response not received"),
|
||||
Some(resp) => {
|
||||
log(LogLevel::Info, "MP: Multiprocessing response received");
|
||||
log(
|
||||
LogLevel::Info,
|
||||
"MP: bootloader response received. Multiprocessing enabled.",
|
||||
);
|
||||
log(
|
||||
LogLevel::Info,
|
||||
&format!("MP: {} CPUs found.", resp.cpus().len()),
|
||||
&format!("MP: {} CPUs found", resp.cpus().len()),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -140,7 +143,7 @@ unsafe extern "C" fn main() -> ! {
|
||||
log(
|
||||
LogLevel::Info,
|
||||
&format!(
|
||||
"Boot: Kernel modules count: {}",
|
||||
"Boot: {} kernel modules found",
|
||||
module_response.modules().len()
|
||||
),
|
||||
);
|
||||
@ -156,7 +159,7 @@ unsafe extern "C" fn main() -> ! {
|
||||
if let Some(irfs_path) = params.get("-initramfs") {
|
||||
log(
|
||||
LogLevel::Info,
|
||||
&format!("Boot: initramfs path requested: {}", irfs_path)
|
||||
&format!("Boot: initramfs path requested: {irfs_path}"),
|
||||
);
|
||||
let initramfs_option: Option<&File> = {
|
||||
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 {
|
||||
result = Some(file);
|
||||
}
|
||||
};
|
||||
}
|
||||
result
|
||||
};
|
||||
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(
|
||||
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");
|
||||
}
|
||||
}
|
||||
log(
|
||||
LogLevel::Trace,
|
||||
"Heartbeat"
|
||||
)
|
||||
log(LogLevel::Trace, "Heartbeat")
|
||||
}
|
||||
}
|
||||
|
@ -10,21 +10,21 @@ pub static KERNEL_VERSION_MAJOR: u8 = match u8::from_str_radix(env!("CARGO_PKG_V
|
||||
{
|
||||
Ok(ver) => ver,
|
||||
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)
|
||||
{
|
||||
Ok(ver) => ver,
|
||||
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)
|
||||
{
|
||||
Ok(ver) => ver,
|
||||
Err(_) => {
|
||||
panic!("Invalid version number ")
|
||||
panic!("Invalid patch version number ")
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user