]> git.dujemihanovic.xyz Git - nameless-os.git/blob - kernel/kernel.c
Add Intel 8254 driver and print elapsed seconds
[nameless-os.git] / kernel / kernel.c
1 #include <tty.h>
2 #include <io.h>
3 #include <irq/idt.h>
4 #include <irq/i8259a.h>
5 #include <time/i8254.h>
6 #include <stdint.h>
7
8 extern void double_fault(struct abort_frame *frame);
9 extern void keyb_handler(struct interrupt_frame *frame);
10 extern void timer_tick(struct interrupt_frame *frame);
11 struct idt_descriptor idt[256] __attribute__((aligned(0x10)));
12 struct idtr idtr __attribute__((aligned(0x10)));
13
14 void kmain(void)
15 {
16 ticks = 0;
17 screen_clear();
18 kprint("Welcome to Nameless OS!\nRunning revision: ", 0);
19 kprint(GIT_COMMIT, 0);
20 kprint("\n", 0);
21 kprint("Preparing IDT...\n", 0);
22 idt_set_descriptor(idt, 0x8, 0x8, (uint32_t) double_fault, IDT_TRAP_GATE, 0x0);
23 idt_set_descriptor(idt, 0x20, 0x8, (uint32_t) timer_tick, IDT_INTERRUPT_GATE, 0x0);
24 idt_set_descriptor(idt, 0x21, 0x8, (uint32_t) keyb_handler, IDT_INTERRUPT_GATE, 0x0);
25 kprint("IDT prepared, loading...\n", 0);
26 populate_idtr(&idtr, idt);
27 load_idt(idtr);
28 kprint("IDT loaded, enabling interrupts...\n", 0);
29 pic_init(0x20, 0x28);
30 pic_mask_all();
31 pic_unmask(1);
32 asm volatile ("sti");
33 kprint("Setting up timer...\n", 0);
34 i8254_configure_channel(0, SQUARE_WAVE_GENERATOR, 0);
35 i8254_irq_enable();
36 kprint("All done\n", 0);
37 while(1);
38 }