Print PhysAddr

This commit is contained in:
2026-03-31 00:14:07 +03:00
parent c7c2905b40
commit 8cc70a6a1a
3 changed files with 25 additions and 3 deletions

View File

@@ -1,8 +1,8 @@
use crate::{gdt, print, println};
use crate::{gdt, hlt_loop, print, println};
use lazy_static::lazy_static;
use pic8259::ChainedPics;
use spin;
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode};
#[derive(Debug, Clone, Copy)]
#[repr(u8)]
@@ -22,6 +22,7 @@ lazy_static! {
}
idt[InterruptIndex::Timer.as_usize()].set_handler_fn(timer_interrupt_handler);
idt[InterruptIndex::Keyboard.as_usize()].set_handler_fn(keyboard_interrupt_handler);
idt.page_fault.set_handler_fn(page_fault_handler);
idt
};
@@ -91,6 +92,19 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
}
}
extern "x86-interrupt" fn page_fault_handler(
stack_frame: InterruptStackFrame,
error_code: PageFaultErrorCode,
) {
use x86_64::registers::control::Cr2;
println!("EXCEPTION: PAGE FAULT");
println!("Accessed Address: {:?}", Cr2::read());
println!("Error Code: {:?}", error_code);
println!("{:?}", stack_frame);
hlt_loop();
}
#[test_case]
fn test_breakpoint_exception() {
// invoke a breakpoint exception

View File

@@ -13,6 +13,14 @@ pub extern "C" fn _start() -> ! {
amix::init();
use x86_64::registers::control::Cr3;
let (level_4_page_table, _) = Cr3::read();
println!(
"Level 4 page table at: {:?}",
level_4_page_table.start_address()
);
#[cfg(test)]
test_main();

View File

@@ -129,7 +129,7 @@ impl fmt::Write for Writer {
lazy_static! {
pub static ref WRITER: Mutex<Writer> = Mutex::new(Writer {
column_position: 0,
color_code: ColorCode::new(Color::White, Color::Black),
color_code: ColorCode::new(Color::LightGray, Color::Black),
buffer: unsafe { &mut *(0xb8000 as *mut Buffer) },
});
}