From 4b8518b4e791c68154ec52badcc921b62afafb49 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 28 Apr 2020 18:32:36 +0200 Subject: Maaaany fixes... Sorry for the increasingly worse-getting commit messages :D --- src/kernel/memory/paging.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/kernel/memory/paging.c') diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c index 4192ba3..0789c2a 100644 --- a/src/kernel/memory/paging.c +++ b/src/kernel/memory/paging.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include struct page_directory *paging_current_directory = NULL; struct page_directory *paging_root_directory = NULL; @@ -100,6 +102,21 @@ void paging_map_user(struct page_directory *dir, uint32_t phys, uint32_t virt) } } +void page_fault(struct regs *regs) +{ + cli(); + if (current_proc != NULL) { + memcpy(¤t_proc->registers, regs, sizeof(struct regs)); + process_suspend(current_proc->pid); + warn("Segfault, halting process %d", current_proc->pid); + scheduler(regs); + } else { + warn("Page fault before multitasking started!"); + // fault_handler(regs); + halt_loop(); + } +} + void paging_install() { kheap_init(); @@ -107,8 +124,11 @@ void paging_install() paging_current_directory = paging_make_directory(); paging_root_directory = paging_current_directory; + isr_install_handler(14, page_fault); for (uint32_t i = 0; i < 0xF0000000; i += PAGE_S) paging_map(paging_root_directory, i, i); + paging_switch_directory(paging_root_directory); + info("Installed paging"); } void paging_convert_page(struct page_directory *kdir) -- cgit v1.2.3