Introduction to Paging

This commit is contained in:
2022-01-12 16:54:57 +08:00
parent 6f67926a75
commit c3e1897c23
2 changed files with 22 additions and 1 deletions

View File

@@ -1,9 +1,10 @@
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode};
use crate::{println, print};
use lazy_static::lazy_static;
use crate::gdt;
use pic8259::ChainedPics;
use spin;
use crate::hlt_loop;
lazy_static! {
static ref IDT: InterruptDescriptorTable = {
@@ -17,6 +18,7 @@ lazy_static! {
.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
};
}
@@ -89,3 +91,12 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
.notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8());
}
}
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();
}