]> git.dujemihanovic.xyz Git - nameless-os.git/blobdiff - kernel/kernel.c
Add ability to print numbers in decimal
[nameless-os.git] / kernel / kernel.c
index 7b6d3543c39066879672e1b44acfc357b8a9f2d9..16b2b404e9f009fbe4e0ed912612152c6b3aa3aa 100644 (file)
@@ -1,39 +1,67 @@
 #include <tty.h>
 #include <io.h>
+#include <irq/idt.h>
+#include <irq/i8259a.h>
 #include <stdint.h>
+#include <mm/paging.h>
 
-const char *string = "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\
-* Complete the text-mode part of the VGA driver.\n\
-* Enable interrupts using the PIC.\n\
-* Write a driver for the Intel 8042 PS/2 controller so the OS can receive keystrokes.\n\
-* Once all that is done, it would be desirable to start the switch to userspace so the OS can actually be remotely usable.\n\n\
-Feel free to mess around with the code, although I doubt it will be very interesting at the moment.\n";
+struct abort_frame;
+struct interrupt_frame;
+struct fault_frame;
+extern void double_fault(struct abort_frame *frame);
+extern void keyb_handler(struct interrupt_frame *frame);
+extern void pf_handler(struct fault_frame *frame);
+static struct idt_descriptor idt[256] __attribute__((aligned(0x10)));
+static struct idtr idtr __attribute__((aligned(0x10)));
 
-void _start(void)
+struct e820_map {
+       uint64_t base;
+       uint64_t length;
+       uint32_t type;
+       uint32_t attrib;
+};
+
+void print_e820(struct e820_map *mmap, int mmap_size)
+{
+       kprint("       Base       |      Length      |   Type   |  Attrib  |\n", 0);
+       kprint("------------------------------------------------------------\n", 0);
+       for (int i=0; i<mmap_size; i++) {
+               kprintq(mmap[i].base);
+               kprintc('|', 0);
+               kprintq(mmap[i].length);
+               kprintc('|', 0);
+               kprintd(mmap[i].type);
+               kprintc('|', 0);
+               kprintd(mmap[i].attrib);
+               kprintc('|', 0);
+               kprintc('\n', 0);
+       }
+}
+
+void kmain(struct e820_map *mmap, int mmap_size)
 {
        screen_clear();
-       /*kprint(string, 0x07);*/
-       kprint("Color 0x01\n", VGA_COLOR_BLUE);
-       kprint("Color 0x02\n", VGA_COLOR_GREEN);
-       kprint("Color 0x03\n", VGA_COLOR_TEAL);
-       kprint("Color 0x04\n", VGA_COLOR_DARK_RED);
-       kprint("Color 0x05\n", VGA_COLOR_MAGENTA);
-       kprint("Color 0x06\n", VGA_COLOR_BROWN);
-       kprint("Color 0x07\n", VGA_COLOR_LIGHT_GRAY);
-       kprint("Color 0x08\n", VGA_COLOR_DARK_GRAY);
-       kprint("Color 0x09\n", VGA_COLOR_PURPLE);
-       kprint("Color 0x0A\n", VGA_COLOR_LIME);
-       kprint("Color 0x0B\n", VGA_COLOR_CYAN);
-       kprint("Color 0x0C\n", VGA_COLOR_BRIGHT_RED);
-       kprint("Color 0x0D\n", VGA_COLOR_PINK);
-       kprint("Color 0x0E\n", VGA_COLOR_YELLOW);
-       kprint("Color 0x0F\n", VGA_COLOR_WHITE);
-       kprintb(0xAE);
-       kprint("\n", 0);
-       kprintw(0xDEAD);
+       kprint("Welcome to Nameless OS!\nRunning revision: ", 0);
+       kprint(GIT_COMMIT, 0);
        kprint("\n", 0);
-       kprintd(0x89ABCDEF);
+       kprint("BIOS memory map:\n", 0);
+       print_e820(mmap, mmap_size);
+       kprint("Preparing IDT...\n", 0);
+       idt_set_descriptor(idt, 8, 0x8, (uint32_t) double_fault, IDT_INTERRUPT_GATE, 0x0);
+       idt_set_descriptor(idt, 14, 0x8, (uint32_t) pf_handler, IDT_INTERRUPT_GATE, 0x0);
+       idt_set_descriptor(idt, 33, 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("All done\n", 0);
+       kprintdec(12345);
+       kprintc('\n');
+       kprintdec(6789);
+       kprintc('\n');
+       while(1);
 }