[BOOT] Parse multiboot information

This commit is contained in:
2016-11-20 11:26:01 +01:00
parent d149d4d20a
commit 0120df249e
5 changed files with 179 additions and 11 deletions

View File

@@ -1,6 +1,13 @@
.intel_syntax noprefix
#include <mem.h>
.section .data
// Some room to store the bootloader return values
MultiBootMagic:
.quad 0x0
MultiBootData:
.quad 0x0
// Some info from here: http://os.phil-opp.com/multiboot-kernel.html
.section .text
.global _start
@@ -8,6 +15,9 @@
_start:
cli
// Save eax and ebx in memory
mov V2P(MultiBootMagic), eax
mov V2P(MultiBootData), ebx
// Check if long mode is available
// Otherwise, there's no point in continuing
@@ -74,6 +84,12 @@ long_mode_start:
mov rax, 0x0
mov [V2P(BootP4)], rax
// Get the saved bootloader data and pass to kmain
movabs rax, MultiBootMagic
mov rdi, rax
movabs rax, MultiBootData
mov rsi, rax
// Call c kernel code
.extern kmain
call kmain

View File

@@ -1,21 +1,14 @@
#include <debug.h>
#include <multiboot.h>
#include <mem.h>
int kmain(void)
int kmain(uint64_t multiboot_magic, void *multiboot_data)
{
debug_init();
debug_ok("MITTOS64 kernel booted\n");
debug_build_time();
debug_git_info();
// Test the printf functions
debug("binary:%b octal:%o dec:%d\n", 0xAA55, 0123, 456);
debug("hex:%x string:%s char:%c\n", 0xabcd, "Hello", 'T');
debug("pointer:%x\n", kmain);
debug_info("An information string\n");
debug_ok("%s prints ok\n", "This string");
debug_warning("A warning message\n");
debug_error("%d is less than %x\n", 12, 17);
multiboot_init(multiboot_magic, P2V(multiboot_data));
debug_info("BOOT COMPLETE\n");
for(;;)asm("hlt");

94
kernel/boot/multiboot.c Normal file
View File

@@ -0,0 +1,94 @@
#include <stdint.h>
#include <multiboot.h>
#include <mem.h>
#include <debug.h>
struct mboot_data_st mboot_data;
void parse_multiboot1()
{
mboot1_info *data = mboot_data.data;
if(data->flags & (1<<2))
{
debug_ok("MBOOT1 - commandline\n");
mboot_data.commandline = P2V(data->cmdline);
}
if(data->flags & (1<<9))
{
debug_ok("MBOOT1 - bootloader\n");
mboot_data.bootloader = P2V(data->bootloader_name);
}
}
char *mboot_tags_type[] = {
"", // 0
"Boot command line", // 1
"Boot loader name", // 2
"Module", // 3
"Basic memory information", // 4
"BIOS Boot device", // 5
"Memory map", // 6
"VBE info", // 7
"Framebuffer info", // 8
"ELF-Symbols", //9
"APM table", // 10
"EFI 32-bit system table pointer", // 11
"EFI 64-bit system table pointer", // 12
"SMBIOS tables", // 13
"ACPI old RSDP", // 14
"ACPI new RSDP", // 15
"Networking information", // 16
"EFI memory map", // 17
"EFI boot services not terminated",
};
void parse_multiboot2()
{
mboot2_tags_head *data = mboot_data.data;
mboot2_tag_basic *tag = (void *)(data + 1);
while(tag->type != 0)
{
switch(tag->type)
{
case MBOOT2_CMDLINE:
mboot_data.commandline = tag->data;
debug_ok("MBOOT2 - handle ");
break;
case MBOOT2_BOOTLOADER:
mboot_data.bootloader = tag->data;
debug_ok("MBOOT2 - handle ");
break;
default:
debug_warning("MBOOT2 - ignore ");
break;
}
if(tag->type <= 18)
debug("%s (%d bytes)\n", mboot_tags_type[tag->type], tag->size);
else
debug("Unknown tag: %d (%d bytes)\n", tag->type, tag->size);
tag = next_tag(tag);
}
}
void multiboot_init(uint64_t magic, void *data)
{
mboot_data.data = data;
debug_info("MBOOT - Magic:%x\n", magic);
if(magic == MBOOT1_MAGIC2)
{
debug_info("MBOOT - Multiboot version 1\n");
mboot_data.version = 1;
parse_multiboot1();
} else if (magic == MBOOT2_MAGIC2) {
debug_info("MBOOT - Multiboot version 2\n");
mboot_data.version = 2;
parse_multiboot2();
} else {
debug_error("PANIC - NOT A MULTIBOOT COMPLIANT BOOTLOADER\n");
for(;;);
}
if(mboot_data.commandline)
debug_info("MBOOT - Command line: %s\n", mboot_data.commandline);
if(mboot_data.bootloader)
debug_info("MBOOT - Bootloader: %s\n", mboot_data.bootloader);
}