]> git.dujemihanovic.xyz Git - nameless-os.git/blob - kernel/kernel.c
Get memory map from BIOS E820
[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 <stdint.h>
6 #include <mm/paging.h>
7
8 extern void double_fault(struct abort_frame *frame);
9 extern void keyb_handler(struct interrupt_frame *frame);
10 extern void pf_handler(struct fault_frame *frame);
11 static struct idt_descriptor idt[256] __attribute__((aligned(0x10)));
12 static struct idtr idtr __attribute__((aligned(0x10)));
13
14 struct e820_map {
15 uint64_t base;
16 uint64_t length;
17 uint32_t type;
18 uint32_t attrib;
19 };
20
21 void print_e820(struct e820_map *mmap, int mmap_size)
22 {
23 kprint(" Base | Length | Type | Attrib |\n", 0);
24 kprint("------------------------------------------------------------\n", 0);
25 for (int i=0; i<mmap_size; i++) {
26 kprintq(mmap[i].base);
27 kprintc('|', 0);
28 kprintq(mmap[i].length);
29 kprintc('|', 0);
30 kprintd(mmap[i].type);
31 kprintc('|', 0);
32 kprintd(mmap[i].attrib);
33 kprintc('|', 0);
34 kprintc('\n', 0);
35 }
36 }
37
38 void kmain(struct e820_map *mmap, int mmap_size)
39 {
40 screen_clear();
41 kprint("Welcome to Nameless OS!\nRunning revision: ", 0);
42 kprint(GIT_COMMIT, 0);
43 kprint("\n", 0);
44 kprint("BIOS memory map:\n", 0);
45 print_e820(mmap, mmap_size);
46 kprint("Preparing IDT...\n", 0);
47 idt_set_descriptor(idt, 8, 0x8, (uint32_t) double_fault, IDT_INTERRUPT_GATE, 0x0);
48 idt_set_descriptor(idt, 14, 0x8, (uint32_t) pf_handler, IDT_INTERRUPT_GATE, 0x0);
49 idt_set_descriptor(idt, 33, 0x8, (uint32_t) keyb_handler, IDT_INTERRUPT_GATE, 0x0);
50 kprint("IDT prepared, loading...\n", 0);
51 populate_idtr(&idtr, idt);
52 load_idt(idtr);
53 kprint("IDT loaded, enabling interrupts...\n", 0);
54 pic_init(0x20, 0x28);
55 pic_mask_all();
56 pic_unmask(1);
57 asm volatile ("sti");
58 kprint("All done\n", 0);
59 while(1);
60 }