- heap allocator now makes sure virtual memory pages are mapped before using them. this means we no longer have to use page faults to allocate frames, it is done automatically.

- fixed the apic code that caused a page fault. it now writes the correct values at the correct physical address
- improved startup logging including displaying how much RAM is installed.
This commit is contained in:
2025-03-05 20:49:21 +00:00
parent 8704b5d249
commit ef70bcf51e
9 changed files with 176 additions and 79 deletions
+39 -24
View File
@@ -23,6 +23,11 @@ use limine::BaseRevision;
use x86_64::VirtAddr;
use arch::x86_64::memory::allocation::page_alloc::FoundryOSFrameAllocator;
use crate::arch::x86_64::cpu::apic::enable_apic;
use crate::arch::x86_64::drivers::ascii::screensize_chars;
use crate::arch::x86_64::drivers::framebuffer::display::screensize_px;
use crate::arch::x86_64::memory::allocation::heap_alloc::FoundryAllocator;
use crate::arch::x86_64::memory::FRAME_ALLOCATOR;
use crate::arch::x86_64::memory::units::MemoryUnits;
pub mod arch;
pub mod resources;
@@ -32,8 +37,9 @@ pub mod util;
pub mod prelude {
pub use crate::std::io::{_print, _print_log, _serial_write};
pub use crate::std::debug::_debug;
pub use crate::{
print, print_log, printerr, println, println_log, printlnerr, serial_print, serial_println,
print, print_log, printerr, println, println_log, printlnerr, serial_print, serial_println, debug
};
}
@@ -71,50 +77,59 @@ pub fn boot() -> Result<(), &'static str> {
let memory_map = mapping::get_memory_map();
print_log!(" Initialising Serial... ");
if arch::x86_64::drivers::serial::init().is_err() {
println_log!("[Not Detected]")
let res = arch::x86_64::drivers::serial::init();
serial_print!(" Initialising Serial... ");
if res.is_err() {
debugln!("[Not Detected]")
} else {
println_log!("[Success]");
debugln!("[Success]");
}
print_log!(" Setting Up Global Descriptor Table... ");
debugln!(" Display...");
let dimensions = screensize_chars();
let dimensions2 = screensize_px();
debugln!(" => (px) : {}x{} ", dimensions2.0, dimensions2.1);
debugln!(" => (chars) : {}x{} ", dimensions.0, dimensions.1);
debugln!(" [Success]");
debug!(" Setting Up Global Descriptor Table... ");
gdt::init();
println_log!("[Success]");
debugln!("[Success]");
print_log!(" Setting Up Interrupt Descriptor Table... ");
debug!(" Setting Up Interrupt Descriptor Table... ");
interrupts::init_idt();
println_log!("[Success]");
debugln!("[Success]");
print_log!(" Initialising Memory Subsystem... ");
debugln!(" Initialising Memory Subsystem... ");
let physical_memory_offset = VirtAddr::new(*mapping::PHYSICAL_MEMORY_OFFSET);
init_page_table(physical_memory_offset);
println_log!("[Success]");
print_log!(" Setting Up Page Table... ");
FoundryOSFrameAllocator::init(memory_map);
println_log!("[Success]");
let available_bytes = FRAME_ALLOCATOR.get().unwrap().lock().available_memory();
debugln!(" => Available Memory: {}", MemoryUnits::from_bytes(available_bytes as usize));
print_log!(" Initialising Heap... ");
debugln!("[Success]");
debugln!(" Initialising Heap... ");
if unsafe { init_heap() }.is_err() {
return Err("Failed to initialise heap: error");
}
println_log!("[Success]");
debugln!(" [Success]");
// print_log!(" Enabling PICs... ");
// debug!(" Enabling PICs... ");
// interrupts::enable_pic();
// println_log!("[Success]");
// debugln!("[Success]");
// print_log!(" Disabling PICs... ");
// interrupts::disable_pic();
// println_log!("[Success]");
debug!(" Disabling PICs... ");
interrupts::disable_pic();
debugln!("[Success]");
print_log!(" Initialising APIC... ");
debug!(" Initialising APIC... ");
enable_apic();
println_log!("[Success]");
debugln!("[Success]");
print_log!(" Enabling Interrupts... ");
debug!(" Enabling Interrupts... ");
x86_64::instructions::interrupts::enable();
println_log!("[Success]");
debugln!("[Success]");
Ok(())
}