]> git.dujemihanovic.xyz Git - nameless-os.git/blobdiff - kernel/arch/x86/irq/sample_handler.c
Add panic facility
[nameless-os.git] / kernel / arch / x86 / irq / sample_handler.c
index d9bd8f9c953a3e48a46b6695957e28d6650aed0d..5b0e2d470217a767c0b02ddc295d4586e7e6fb84 100644 (file)
@@ -2,6 +2,8 @@
 #include <irq/i8259a.h>
 #include <io.h>
 #include <stdint.h>
+#include <mm/paging.h>
+#include <panic.h>
 
 typedef uint32_t uword_t;
 
@@ -11,6 +13,13 @@ struct interrupt_frame {
        uword_t flags;
 };
 
+struct fault_frame {
+       struct pf_errcode error_code;
+       uintptr_t eip;
+       uint16_t cs;
+       uint32_t eflags;
+};
+
 struct abort_frame;
 
 __attribute__((interrupt))
@@ -19,15 +28,36 @@ void keyb_handler(struct interrupt_frame *frame)
        pic_send_eoi(1);
        kprint("Got a keyboard interrupt!\n", 0);
        inb(0x60);
+       int a = *(int *) (0xa0000000);
 }
 
+__attribute__((interrupt))
+void pf_handler(struct fault_frame *frame)
+{
+       int address;
+       struct pf_errcode errcode = frame->error_code;
+       asm ("mov %%cr2, %0": "=a" (address));
+       kprint("A page fault occurred!\n", VGA_COLOR_BRIGHT_RED);
+       kprint("Faulting address: ", 0);
+       kprintd(address);
+       kprint("\n", 0);
+       if (!errcode.p) {
+               kprint("Address points to non-mapped page\n", 0);
+       }
+       if (errcode.wr) {
+               kprint("Fault occurred while writing to memory\n", 0);
+       } else {
+               kprint("Fault occurred while reading from memory\n", 0);
+       }
+       if (errcode.id) {
+               kprint("Fault occurred while fetching instruction\n", 0);
+       }
+       PANIC("page fault");
+}
 
 __attribute__((interrupt))
 void double_fault(struct abort_frame *frame)
 {
-       *(volatile char *) (0xb8000) = ":";
-       *(volatile char *) (0xb8002) = "(";
-       asm volatile ("cli; hlt");
-       while(1);
+       PANIC("double fault");
 }