Kernel/Bootloader: banan-os can now be booted with my bootloader :D
This commit is contained in:
parent
5f4d81a502
commit
065eec430e
|
@ -108,7 +108,16 @@ protected_mode:
|
|||
movw %bx, %fs
|
||||
movw %bx, %gs
|
||||
movw %bx, %ss
|
||||
jmp *%eax
|
||||
|
||||
movl %eax, %ecx
|
||||
|
||||
movl $0xD3C60CFF, %eax
|
||||
movl $banan_boot_info, %ebx
|
||||
xorl %edx, %edx
|
||||
xorl %esi, %esi
|
||||
xorl %edi, %edi
|
||||
|
||||
jmp *%ecx
|
||||
|
||||
|
||||
.code16
|
||||
|
@ -154,3 +163,9 @@ gdt:
|
|||
gdtr:
|
||||
.short . - gdt - 1
|
||||
.quad gdt
|
||||
|
||||
banan_boot_info:
|
||||
boot_command_line:
|
||||
.long command_line
|
||||
boot_memory_map:
|
||||
.long memory_map
|
||||
|
|
|
@ -68,6 +68,8 @@ command_line_enter_msg:
|
|||
|
||||
.section .bss
|
||||
|
||||
.global command_line
|
||||
command_line:
|
||||
# 100 character command line
|
||||
command_line_buffer:
|
||||
.skip 100
|
||||
|
|
|
@ -122,6 +122,8 @@ memory_map_error_msg:
|
|||
|
||||
.section .bss
|
||||
|
||||
.global memory_map
|
||||
memory_map:
|
||||
memory_map_entry_count:
|
||||
.skip 4
|
||||
# 100 entries should be enough...
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define BANAN_BOOTLOADER_MAGIC 0xD3C60CFF
|
||||
|
||||
struct BananBootloaderMemoryMapEntry
|
||||
{
|
||||
uint64_t address;
|
||||
uint64_t length;
|
||||
uint32_t type;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct BananBootloaderMemoryMapInfo
|
||||
{
|
||||
uint32_t entry_count;
|
||||
BananBootloaderMemoryMapEntry entries[];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct BananBootloaderInfo
|
||||
{
|
||||
uint32_t command_line_addr;
|
||||
uint32_t memory_map_addr;
|
||||
} __attribute__((packed));
|
|
@ -1,5 +1,5 @@
|
|||
#include <kernel/BootInfo.h>
|
||||
|
||||
#include <kernel/BananBootloader.h>
|
||||
#include <kernel/multiboot2.h>
|
||||
|
||||
namespace Kernel
|
||||
|
@ -64,10 +64,36 @@ namespace Kernel
|
|||
return {};
|
||||
}
|
||||
|
||||
void parse_boot_info_banan_bootloader(uint32_t info)
|
||||
{
|
||||
const auto& banan_bootloader_info = *reinterpret_cast<const BananBootloaderInfo*>(info);
|
||||
|
||||
const char* command_line = reinterpret_cast<const char*>(banan_bootloader_info.command_line_addr);
|
||||
MUST(g_boot_info.command_line.append(command_line));
|
||||
|
||||
const auto& memory_map = *reinterpret_cast<BananBootloaderMemoryMapInfo*>(banan_bootloader_info.memory_map_addr);
|
||||
MUST(g_boot_info.memory_map_entries.resize(memory_map.entry_count));
|
||||
for (size_t i = 0; i < memory_map.entry_count; i++)
|
||||
{
|
||||
const auto& mmap_entry = memory_map.entries[i];
|
||||
g_boot_info.memory_map_entries[i].address = mmap_entry.address;
|
||||
g_boot_info.memory_map_entries[i].length = mmap_entry.length;
|
||||
g_boot_info.memory_map_entries[i].type = mmap_entry.type;
|
||||
}
|
||||
}
|
||||
|
||||
BAN::StringView get_early_boot_command_line_banan_bootloader(uint32_t info)
|
||||
{
|
||||
const auto& banan_bootloader_info = *reinterpret_cast<const BananBootloaderInfo*>(info);
|
||||
return reinterpret_cast<const char*>(banan_bootloader_info.command_line_addr);
|
||||
}
|
||||
|
||||
bool validate_boot_magic(uint32_t magic)
|
||||
{
|
||||
if (magic == MULTIBOOT2_MAGIC)
|
||||
return true;
|
||||
if (magic == BANAN_BOOTLOADER_MAGIC)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -77,6 +103,8 @@ namespace Kernel
|
|||
{
|
||||
case MULTIBOOT2_MAGIC:
|
||||
return parse_boot_info_multiboot2(info);
|
||||
case BANAN_BOOTLOADER_MAGIC:
|
||||
return parse_boot_info_banan_bootloader(info);
|
||||
}
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
@ -87,6 +115,8 @@ namespace Kernel
|
|||
{
|
||||
case MULTIBOOT2_MAGIC:
|
||||
return get_early_boot_command_line_multiboot2(info);
|
||||
case BANAN_BOOTLOADER_MAGIC:
|
||||
return get_early_boot_command_line_banan_bootloader(info);
|
||||
}
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue