]> git.dujemihanovic.xyz Git - nameless-os.git/blob - kernel/kernel.c
Rework interrupt handling
[nameless-os.git] / kernel / kernel.c
1 #include <stdint.h>
2 #include <tty.h>
3 #include <io.h>
4 #include <irq/idt.h>
5 #include <irq/interrupt.h>
6 #include <irq/i8259a.h>
7 #include <input/ps2.h>
8
9 struct idt_descriptor idt[256] __attribute__((aligned(0x10)));
10 struct idtr idtr __attribute__((aligned(0x10)));
11 extern void (*_int_handler_table[48])(void);
12
13 void kmain(void)
14 {
15 int ps2_success;
16 screen_clear();
17 kprint("Welcome to Nameless OS!\nRunning revision: ", 0);
18 kprint(GIT_COMMIT, 0);
19 kprint("\n", 0);
20 kprint("Preparing IDT...\n", 0);
21 for (int i=0; i<48; i++) {
22 idt_set_descriptor(idt, i, 0x8, _int_handler_table[i], IDT_INTERRUPT_GATE, 0);
23 }
24 kprint("IDT prepared, loading...\n", 0);
25 populate_idtr(&idtr, idt);
26 load_idt(idtr);
27 kprint("Setting up interrupts...\n", 0);
28 pic_init(0x20, 0x28);
29 pic_mask_all();
30 ps2_success = ps2_initialize();
31 switch (ps2_success) {
32 case -1:
33 kprint("No PS/2 devices found or working, we will have no input\n", 0);
34 break;
35 case 0:
36 kprint("Found one working PS/2 device\n", 0);
37 break;
38 case 1:
39 kprint("Found two working PS/2 devices\n", 0);
40 }
41 asm volatile ("sti");
42 kprint("All done\n", 0);
43 while(1);
44 }