]> git.dujemihanovic.xyz Git - nameless-os.git/blobdiff - kernel/arch/x86/irq/sample_handler.c
(VERY BROKEN) Enable paging
[nameless-os.git] / kernel / arch / x86 / irq / sample_handler.c
index f4f4a4bfefad5aacf742f3c6ce2046c86eb1b85e..66a3223583249ef18041a7f6d7d5fb38245a9b08 100644 (file)
@@ -2,6 +2,7 @@
 #include <irq/i8259a.h>
 #include <io.h>
 #include <stdint.h>
+#include <mm/paging.h>
 
 typedef uint32_t uword_t;
 
@@ -11,6 +12,13 @@ struct interrupt_frame {
        uword_t flags;
 };
 
+struct fault_frame {
+       uint32_t error_code;
+       uintptr_t eip;
+       uint16_t cs;
+       uint32_t eflags;
+};
+
 struct abort_frame;
 
 __attribute__((interrupt))
@@ -21,6 +29,28 @@ void keyb_handler(struct interrupt_frame *frame)
        inb(0x60);
 }
 
+__attribute__((interrupt))
+void pf_handler(struct fault_frame *frame)
+{
+       struct pf_errcode *errcode = &(frame->error_code);
+       kprint("A page fault occurred!\n", VGA_COLOR_DARK_RED);
+       if (errcode->p) {
+               kprint("Attempted to access non-present page\n", 0);
+       }
+       if (errcode->wr) {
+               kprint("Kernel attempted to write to page\n", 0);
+       } else kprint("Kernel attempted to read from page\n", 0);
+       if (errcode->id) {
+               kprint("Fault occurred while fetching instruction\n", 0);
+       }
+       int cr2;
+       asm ("mov %%cr2, %0": "=a" (cr2));
+       kprint("CR2: ", 0);
+       kprintd(cr2);
+halt:
+       asm ("cli; hlt");
+       goto halt;
+}
 
 __attribute__((interrupt))
 void double_fault(struct abort_frame *frame)