]> git.dujemihanovic.xyz Git - nameless-os.git/blob - kernel/kernel.c
Add PS/2 driver
[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/i8259a.h>
6 #include <input/ps2.h>
7
8 extern void double_fault(struct abort_frame *frame);
9 extern void keyb_handler(struct interrupt_frame *frame);
10 struct idt_descriptor idt[256] __attribute__((aligned(0x10)));
11 struct idtr idtr __attribute__((aligned(0x10)));
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 ps2_success = ps2_initialize();
21 switch (ps2_success) {
22 case -1:
23 kprint("No PS/2 devices found or working, we will have no input\n", 0);
24 break;
25 case 0:
26 kprint("Found one working PS/2 device\n", 0);
27 break;
28 case 1:
29 kprint("Found two working PS/2 devices\n", 0);
30 }
31 kprint("Preparing IDT...\n", 0);
32 idt_set_descriptor(idt, 0x8, 0x8, (uint32_t) double_fault, IDT_TRAP_GATE, 0x0);
33 idt_set_descriptor(idt, 0x21, 0x8, (uint32_t) keyb_handler, IDT_INTERRUPT_GATE, 0x0);
34 kprint("IDT prepared, loading...\n", 0);
35 populate_idtr(&idtr, idt);
36 load_idt(idtr);
37 kprint("IDT loaded, enabling interrupts...\n", 0);
38 pic_init(0x20, 0x28);
39 pic_mask_all();
40 pic_unmask(1);
41 asm volatile ("sti");
42 kprint("All done\n", 0);
43 while(1);
44 }