]> git.dujemihanovic.xyz Git - nameless-os.git/blobdiff - kernel/kernel.c
Add Intel 8254 driver and print elapsed seconds
[nameless-os.git] / kernel / kernel.c
index e04b875e2959b5963e7c6f4ba394abba1f5f0be5..35100f1d24a54e6e95b3b23b48a09d7115b08526 100644 (file)
@@ -1,5 +1,38 @@
-void _start(void)
+#include <tty.h>
+#include <io.h>
+#include <irq/idt.h>
+#include <irq/i8259a.h>
+#include <time/i8254.h>
+#include <stdint.h>
+
+extern void double_fault(struct abort_frame *frame);
+extern void keyb_handler(struct interrupt_frame *frame);
+extern void timer_tick(struct interrupt_frame *frame);
+struct idt_descriptor idt[256] __attribute__((aligned(0x10)));
+struct idtr idtr __attribute__((aligned(0x10)));
+
+void kmain(void)
 {
-       char *video_memory = (char *) 0xB8000; /* VGA VRAM starts at 0xB8000 */
-       *video_memory = 'A'; /* put an A at the beginning of the VRAM */
+       ticks = 0;
+       screen_clear();
+       kprint("Welcome to Nameless OS!\nRunning revision: ", 0);
+       kprint(GIT_COMMIT, 0);
+       kprint("\n", 0);
+       kprint("Preparing IDT...\n", 0);
+       idt_set_descriptor(idt, 0x8, 0x8, (uint32_t) double_fault, IDT_TRAP_GATE, 0x0);
+       idt_set_descriptor(idt, 0x20, 0x8, (uint32_t) timer_tick, IDT_INTERRUPT_GATE, 0x0);
+       idt_set_descriptor(idt, 0x21, 0x8, (uint32_t) keyb_handler, IDT_INTERRUPT_GATE, 0x0);
+       kprint("IDT prepared, loading...\n", 0);
+       populate_idtr(&idtr, idt);
+       load_idt(idtr);
+       kprint("IDT loaded, enabling interrupts...\n", 0);
+       pic_init(0x20, 0x28);
+       pic_mask_all();
+       pic_unmask(1);
+       asm volatile ("sti");
+       kprint("Setting up timer...\n", 0);
+       i8254_configure_channel(0, SQUARE_WAVE_GENERATOR, 0);
+       i8254_irq_enable();
+       kprint("All done\n", 0);
+       while(1);
 }