]> git.dujemihanovic.xyz Git - nameless-os.git/blob - kernel/arch/x86/irq/sample_handler.c
(VERY BROKEN) Enable paging
[nameless-os.git] / kernel / arch / x86 / irq / sample_handler.c
1 #include <tty.h>
2 #include <irq/i8259a.h>
3 #include <io.h>
4 #include <stdint.h>
5 #include <mm/paging.h>
6
7 typedef uint32_t uword_t;
8
9 struct interrupt_frame {
10 uword_t ip;
11 uword_t cs;
12 uword_t flags;
13 };
14
15 struct fault_frame {
16 uint32_t error_code;
17 uintptr_t eip;
18 uint16_t cs;
19 uint32_t eflags;
20 };
21
22 struct abort_frame;
23
24 __attribute__((interrupt))
25 void keyb_handler(struct interrupt_frame *frame)
26 {
27 pic_send_eoi(1);
28 kprint("Got a keyboard interrupt!\n", 0);
29 inb(0x60);
30 }
31
32 __attribute__((interrupt))
33 void pf_handler(struct fault_frame *frame)
34 {
35 struct pf_errcode *errcode = &(frame->error_code);
36 kprint("A page fault occurred!\n", VGA_COLOR_DARK_RED);
37 if (errcode->p) {
38 kprint("Attempted to access non-present page\n", 0);
39 }
40 if (errcode->wr) {
41 kprint("Kernel attempted to write to page\n", 0);
42 } else kprint("Kernel attempted to read from page\n", 0);
43 if (errcode->id) {
44 kprint("Fault occurred while fetching instruction\n", 0);
45 }
46 int cr2;
47 asm ("mov %%cr2, %0": "=a" (cr2));
48 kprint("CR2: ", 0);
49 kprintd(cr2);
50 halt:
51 asm ("cli; hlt");
52 goto halt;
53 }
54
55 __attribute__((interrupt))
56 void double_fault(struct abort_frame *frame)
57 {
58 *(volatile uint32_t *) (0xb8000) = 0xcf28cf3a;
59 halt:
60 asm volatile ("cli; hlt");
61 goto halt;
62 }
63