]> git.dujemihanovic.xyz Git - nameless-os.git/blobdiff - kernel/kernel.c
Rework interrupt handling
[nameless-os.git] / kernel / kernel.c
index c0ecb80f1ef0053e3686b2eaf53054bac433f658..2af33720caf647ea2bf8e13a7df572795eb0cd07 100644 (file)
@@ -1,14 +1,44 @@
+#include <stdint.h>
 #include <tty.h>
+#include <io.h>
+#include <irq/idt.h>
+#include <irq/interrupt.h>
+#include <irq/i8259a.h>
+#include <input/ps2.h>
 
-void _start(void)
+struct idt_descriptor idt[256] __attribute__((aligned(0x10)));
+struct idtr idtr __attribute__((aligned(0x10)));
+extern void (*_int_handler_table[48])(void);
+
+void kmain(void)
 {
+       int ps2_success;
        screen_clear();
-       kprint("Hello there!\n\n\
-                       Hopefully your machine manages to print this text.\n\
-                       If it did, that's great news because I managed to write a partial VGA driver.\n\n\
-                       Right now, the short-term roadmap is as follows:\n\n\
-                           * Enable interrupts using the PIC.\n\
-                               * Write a driver for the Intel 8042 PS/2 controller so the OS can receive keystrokes.\n\
-                               * A working i8042 driver will also aid in enabling A20 Gate, which should be done ASAP so the OS can address odd (as in odd/even number) megabytes.\n\n\
-                       Feel free to mess around with the code, although I doubt it will be very interesting at the moment.\n");
+       kprint("Welcome to Nameless OS!\nRunning revision: ", 0);
+       kprint(GIT_COMMIT, 0);
+       kprint("\n", 0);
+       kprint("Preparing IDT...\n", 0);
+       for (int i=0; i<48; i++) {
+               idt_set_descriptor(idt, i, 0x8, _int_handler_table[i], IDT_INTERRUPT_GATE, 0);
+       }
+       kprint("IDT prepared, loading...\n", 0);
+       populate_idtr(&idtr, idt);
+       load_idt(idtr);
+       kprint("Setting up interrupts...\n", 0);
+       pic_init(0x20, 0x28);
+       pic_mask_all();
+       ps2_success = ps2_initialize();
+       switch (ps2_success) {
+               case -1:
+                       kprint("No PS/2 devices found or working, we will have no input\n", 0);
+                       break;
+               case 0:
+                       kprint("Found one working PS/2 device\n", 0);
+                       break;
+               case 1:
+                       kprint("Found two working PS/2 devices\n", 0);
+       }
+       asm volatile ("sti");
+       kprint("All done\n", 0);
+       while(1);
 }