]> git.dujemihanovic.xyz Git - nameless-os.git/blob - kernel/arch/x86/irq/sample_handler.c
Enable paging in bootloader
[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 struct pf_errcode 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 int a = *(int *) (0xa0000000);
31 }
32
33 __attribute__((interrupt))
34 void pf_handler(struct fault_frame *frame)
35 {
36 int address;
37 struct pf_errcode errcode = frame->error_code;
38 asm ("mov %%cr2, %0": "=a" (address));
39 kprint("A page fault occurred!\n", VGA_COLOR_DARK_RED);
40 kprint("Faulting address: ", 0);
41 kprintd(address);
42 kprint("\n", 0);
43 if (!errcode.p) {
44 kprint("Address points to non-mapped page\n", 0);
45 }
46 if (errcode.wr) {
47 kprint("Fault occurred while writing to memory\n", 0);
48 } else {
49 kprint("Fault occurred while reading from memory\n", 0);
50 }
51 if (errcode.id) {
52 kprint("Fault occurred while fetching instruction\n", 0);
53 }
54 asm("cli");
55 halt:
56 asm("hlt");
57 goto halt;
58 }
59
60 __attribute__((interrupt))
61 void double_fault(struct abort_frame *frame)
62 {
63 *(volatile uint32_t *) (0xb8000) = 0xcf28cf3a;
64 halt:
65 asm volatile ("cli; hlt");
66 goto halt;
67 }
68