#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "multiboot.h" void verify_memmap(multiboot_info_t* mbd, uint32_t magic) { if (magic != MULTIBOOT_BOOTLOADER_MAGIC) panic("Invalid magic number!"); if (!(mbd->flags >> 6 & 0x1)) panic("Invalid memory map given by GRUB bootloader!"); if (!(mbd->flags & (1 << 0))) panic("Memory info not passed to kernel!"); puts("Printing available memory map..."); uint32_t i; for (i = 0; i < mbd->mmap_length; i += sizeof(multiboot_memory_map_t)) { multiboot_memory_map_t* mmmt = (multiboot_memory_map_t*) (mbd->mmap_addr + i); printf("Start Addr: %4 | Length: %4 | Size: %2 | Type: %d\n", mmmt->addr, mmmt->len, mmmt->size, mmmt->type); // mmmt-> len is in bytes (according to multiboot specification0 // mmmt->len / 1024 == kib // block size == blocks if (mmmt->type == MULTIBOOT_MEMORY_AVAILABLE && (mmmt->addr == 0x100000)) { // This is the main mem address we want // TODO: this is probably flaky, so i want to find a better and more reliable way to do this set_grub_mem_map(mmmt->addr, mmmt->len); } } printf("%2 %2\n", mbd->mem_lower, mbd->mem_upper); } void _main(multiboot_info_t* mbd, uint32_t magic) { #ifdef __TESTING__ // important components should be declared first, but if we're testing we want to log all of that terminal_initialize(); serial_initialize(); #endif printf("%2, %2\n", mbd->mem_lower, mbd->mem_upper); verify_memmap(mbd, magic); gdt_init(); idt_init(); #ifndef __TESTING__ terminal_initialize(); serial_initialize(); #endif //setup_paging(); init_kb(); init_pit(0x36, PIT_CHANNEL_0, 0); printf("Entering loop...\n"); while (1) { continue; } printf("Exiting loop...\n"); }