mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
76 lines
1.7 KiB
C
76 lines
1.7 KiB
C
#include <bootloader.h>
|
|
#include <multiboot.h>
|
|
#include <kernel.h>
|
|
#include <string.h>
|
|
|
|
struct boot_memmap memmap[BOOT_MAX_MMAP_ENTRIES];
|
|
struct boot_info bootloader;
|
|
|
|
// TODO:
|
|
int boot_init(int type, ...) {
|
|
return 1;
|
|
}
|
|
|
|
int boot_initMB1(void* ptr, uint32_t magic) {
|
|
multiboot_info_t* mbi = ptr;
|
|
|
|
if (magic != MULTIBOOT_BOOTLOADER_MAGIC) return 1;
|
|
|
|
// mem_* fields are valid
|
|
if (mbi->flags & MULTIBOOT_INFO_MEMORY) {
|
|
bootloader.memLower = mbi->mem_lower;
|
|
bootloader.memUpper = mbi->mem_upper;
|
|
}
|
|
|
|
// boot_device is valid
|
|
if (mbi->flags & MULTIBOOT_INFO_BOOTDEV) {
|
|
bootloader.bootDrive = (mbi->boot_device & 0xff000000) >> 24;
|
|
bootloader.bootPart1 = (mbi->boot_device & 0x00ff0000) >> 16;
|
|
bootloader.bootPart2 = (mbi->boot_device & 0x0000ff00) >> 8;
|
|
bootloader.bootPart3 = (mbi->boot_device & 0x000000ff);
|
|
}
|
|
|
|
// cmdline is valid
|
|
if (mbi->flags & MULTIBOOT_INFO_CMDLINE) {
|
|
bootloader.cmdline = (char*)mbi->cmdline;
|
|
}
|
|
|
|
// TODO: mods
|
|
// TODO: a.out symbol table
|
|
// TODO: ELF symbol table
|
|
|
|
// mmap_* fields are valid
|
|
if (mbi->flags & MULTIBOOT_INFO_MEM_MAP) {
|
|
bootloader.memmap = &memmap[0];
|
|
|
|
size_t i = 0;
|
|
multiboot_memory_map_t* entry = (multiboot_memory_map_t*)mbi->mmap_addr;
|
|
uint32_t mapLim = mbi->mmap_addr + mbi->mmap_length;
|
|
|
|
while ((uint32_t)entry < mapLim) {
|
|
bootloader.memmap[i].base = entry->addr;
|
|
bootloader.memmap[i].size = entry->len;
|
|
bootloader.memmap[i].type = (uint8_t)entry->type;
|
|
|
|
entry++;
|
|
i++;
|
|
}
|
|
bootloader.memmapLen = i;
|
|
}
|
|
|
|
// TODO: drives_*
|
|
// TODO: config_table
|
|
|
|
// boot_loader_name is valid
|
|
if (mbi->flags & MULTIBOOT_INFO_BOOT_LOADER_NAME) {
|
|
bootloader.bootname = (char*)mbi->boot_loader_name;
|
|
}
|
|
|
|
// TODO: APM table
|
|
// TODO: VBE table
|
|
// TODO: Framebuffer
|
|
|
|
return 0;
|
|
}
|
|
|