]> git.dujemihanovic.xyz Git - nameless-os.git/blob - kernel/arch/x86/irq/sample_handler.c
5b0e2d470217a767c0b02ddc295d4586e7e6fb84
[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 #include <panic.h>
7
8 typedef uint32_t uword_t;
9
10 struct interrupt_frame {
11 uword_t ip;
12 uword_t cs;
13 uword_t flags;
14 };
15
16 struct fault_frame {
17 struct pf_errcode error_code;
18 uintptr_t eip;
19 uint16_t cs;
20 uint32_t eflags;
21 };
22
23 struct abort_frame;
24
25 __attribute__((interrupt))
26 void keyb_handler(struct interrupt_frame *frame)
27 {
28 pic_send_eoi(1);
29 kprint("Got a keyboard interrupt!\n", 0);
30 inb(0x60);
31 int a = *(int *) (0xa0000000);
32 }
33
34 __attribute__((interrupt))
35 void pf_handler(struct fault_frame *frame)
36 {
37 int address;
38 struct pf_errcode errcode = frame->error_code;
39 asm ("mov %%cr2, %0": "=a" (address));
40 kprint("A page fault occurred!\n", VGA_COLOR_BRIGHT_RED);
41 kprint("Faulting address: ", 0);
42 kprintd(address);
43 kprint("\n", 0);
44 if (!errcode.p) {
45 kprint("Address points to non-mapped page\n", 0);
46 }
47 if (errcode.wr) {
48 kprint("Fault occurred while writing to memory\n", 0);
49 } else {
50 kprint("Fault occurred while reading from memory\n", 0);
51 }
52 if (errcode.id) {
53 kprint("Fault occurred while fetching instruction\n", 0);
54 }
55 PANIC("page fault");
56 }
57
58 __attribute__((interrupt))
59 void double_fault(struct abort_frame *frame)
60 {
61 PANIC("double fault");
62 }
63