Skip to content

Commit

Permalink
feat(kernel: pmm): panic on page fault
Browse files Browse the repository at this point in the history
  • Loading branch information
d4ilyrun committed Feb 25, 2024
1 parent 04a8963 commit 93f5a21
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 0 additions & 4 deletions kernel/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ void kernel_main(struct multiboot_info *mbt, unsigned int magic)

ASM("int $0");

// Intetionnaly provoke a PageFault exception
*(volatile u8 *)0xFFFF1234;

u32 page = pmm_allocate(PMM_MAP_KERNEL);
log_variable(page);
mmu_map(0xFFFF1000, page);
Expand All @@ -64,7 +61,6 @@ void kernel_main(struct multiboot_info *mbt, unsigned int magic)
*(volatile u8 *)0x12341235 = 0x69; // No page fault, Same page
log_variable(*(volatile u8 *)0xFFFF1235);
mmu_unmap(0xFFFF1000);
*(volatile u8 *)0xFFFF1234; // Page fault

while (1) {
timer_wait_ms(1000);
Expand Down
7 changes: 6 additions & 1 deletion kernel/src/memory/pmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,18 @@ static DEFINE_INTERRUPT_HANDLER(page_fault)
log_dbg("[PF] source", "%s access on a %s page %s",
error.write ? "write" : "read",
error.present ? "protected" : "non-present",
error.user ? "whie in user-mode" : "");
error.user ? "while in user-mode" : "");

// The CR2 register holds the virtual address which caused the Page Fault
u32 faulty_address = read_cr2();

log_dbg("[PF] error", LOG_FMT_32, frame.error);
log_dbg("[PF] address", LOG_FMT_32, faulty_address);

panic("PAGE FAULT at " LOG_FMT_32 ": %s access on a %s page %s",
faulty_address, error.write ? "write" : "read",
error.present ? "protected" : "non-present",
error.user ? "while in user-mode" : "");
}

bool pmm_init(struct multiboot_info *mbt)
Expand Down

0 comments on commit 93f5a21

Please sign in to comment.