Kernel: Don't ignore modules passed with multiboot2
This commit is contained in:
parent
c67198032f
commit
17f1ac10e3
|
@ -36,6 +36,12 @@ multiboot2_start:
|
||||||
.long 12
|
.long 12
|
||||||
.long V2P(_start)
|
.long V2P(_start)
|
||||||
|
|
||||||
|
# page align modules
|
||||||
|
.align 8
|
||||||
|
.short 6
|
||||||
|
.short 0
|
||||||
|
.long 8
|
||||||
|
|
||||||
.align 8
|
.align 8
|
||||||
.short 0
|
.short 0
|
||||||
.short 0
|
.short 0
|
||||||
|
|
|
@ -36,6 +36,12 @@ multiboot2_start:
|
||||||
.long 12
|
.long 12
|
||||||
.long V2P(_start)
|
.long V2P(_start)
|
||||||
|
|
||||||
|
# page align modules
|
||||||
|
.align 8
|
||||||
|
.short 6
|
||||||
|
.short 0
|
||||||
|
.long 8
|
||||||
|
|
||||||
.align 8
|
.align 8
|
||||||
.short 0
|
.short 0
|
||||||
.short 0
|
.short 0
|
||||||
|
|
|
@ -41,6 +41,12 @@ namespace Kernel
|
||||||
Type type;
|
Type type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct BootModule
|
||||||
|
{
|
||||||
|
paddr_t start;
|
||||||
|
size_t size;
|
||||||
|
};
|
||||||
|
|
||||||
struct BootInfo
|
struct BootInfo
|
||||||
{
|
{
|
||||||
BAN::String command_line;
|
BAN::String command_line;
|
||||||
|
@ -48,6 +54,7 @@ namespace Kernel
|
||||||
RSDP rsdp {};
|
RSDP rsdp {};
|
||||||
paddr_t kernel_paddr {};
|
paddr_t kernel_paddr {};
|
||||||
|
|
||||||
|
BAN::Vector<BootModule> modules;
|
||||||
BAN::Vector<MemoryMapEntry> memory_map_entries;
|
BAN::Vector<MemoryMapEntry> memory_map_entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#define MULTIBOOT2_TAG_END 0
|
#define MULTIBOOT2_TAG_END 0
|
||||||
#define MULTIBOOT2_TAG_CMDLINE 1
|
#define MULTIBOOT2_TAG_CMDLINE 1
|
||||||
|
#define MULTIBOOT2_TAG_MODULES 3
|
||||||
#define MULTIBOOT2_TAG_MMAP 6
|
#define MULTIBOOT2_TAG_MMAP 6
|
||||||
#define MULTIBOOT2_TAG_FRAMEBUFFER 8
|
#define MULTIBOOT2_TAG_FRAMEBUFFER 8
|
||||||
#define MULTIBOOT2_TAG_OLD_RSDP 14
|
#define MULTIBOOT2_TAG_OLD_RSDP 14
|
||||||
|
@ -33,6 +34,13 @@ struct multiboot2_cmdline_tag_t : public multiboot2_tag_t
|
||||||
char cmdline[];
|
char cmdline[];
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
struct multiboot2_modules_tag_t : public multiboot2_tag_t
|
||||||
|
{
|
||||||
|
uint32_t mod_start;
|
||||||
|
uint32_t mod_end;
|
||||||
|
uint8_t string[];
|
||||||
|
} __attribute__((packed));
|
||||||
|
|
||||||
struct multiboot2_mmap_entry_t
|
struct multiboot2_mmap_entry_t
|
||||||
{
|
{
|
||||||
uint64_t base_addr;
|
uint64_t base_addr;
|
||||||
|
|
|
@ -26,59 +26,73 @@ namespace Kernel
|
||||||
|
|
||||||
for (const auto* tag = multiboot2_info.tags; tag->type != MULTIBOOT2_TAG_END; tag = tag->next())
|
for (const auto* tag = multiboot2_info.tags; tag->type != MULTIBOOT2_TAG_END; tag = tag->next())
|
||||||
{
|
{
|
||||||
if (tag->type == MULTIBOOT2_TAG_CMDLINE)
|
switch (tag->type)
|
||||||
{
|
{
|
||||||
const auto& command_line_tag = *static_cast<const multiboot2_cmdline_tag_t*>(tag);
|
case MULTIBOOT2_TAG_CMDLINE:
|
||||||
MUST(g_boot_info.command_line.append(command_line_tag.cmdline));
|
|
||||||
}
|
|
||||||
else if (tag->type == MULTIBOOT2_TAG_FRAMEBUFFER)
|
|
||||||
{
|
|
||||||
const auto& framebuffer_tag = *static_cast<const multiboot2_framebuffer_tag_t*>(tag);
|
|
||||||
g_boot_info.framebuffer.address = framebuffer_tag.framebuffer_addr;
|
|
||||||
g_boot_info.framebuffer.pitch = framebuffer_tag.framebuffer_pitch;
|
|
||||||
g_boot_info.framebuffer.width = framebuffer_tag.framebuffer_width;
|
|
||||||
g_boot_info.framebuffer.height = framebuffer_tag.framebuffer_height;
|
|
||||||
g_boot_info.framebuffer.bpp = framebuffer_tag.framebuffer_bpp;
|
|
||||||
if (framebuffer_tag.framebuffer_type == MULTIBOOT2_FRAMEBUFFER_TYPE_RGB)
|
|
||||||
g_boot_info.framebuffer.type = FramebufferInfo::Type::RGB;
|
|
||||||
else if (framebuffer_tag.framebuffer_type == MULTIBOOT2_FRAMEBUFFER_TYPE_TEXT)
|
|
||||||
g_boot_info.framebuffer.type = FramebufferInfo::Type::Text;
|
|
||||||
else
|
|
||||||
g_boot_info.framebuffer.type = FramebufferInfo::Type::Unknown;
|
|
||||||
}
|
|
||||||
else if (tag->type == MULTIBOOT2_TAG_MMAP)
|
|
||||||
{
|
|
||||||
const auto& mmap_tag = *static_cast<const multiboot2_mmap_tag_t*>(tag);
|
|
||||||
|
|
||||||
const size_t entry_count = (mmap_tag.size - sizeof(multiboot2_mmap_tag_t)) / mmap_tag.entry_size;
|
|
||||||
|
|
||||||
MUST(g_boot_info.memory_map_entries.resize(entry_count));
|
|
||||||
|
|
||||||
for (size_t i = 0; i < entry_count; i++)
|
|
||||||
{
|
{
|
||||||
const auto& mmap_entry = *reinterpret_cast<const multiboot2_mmap_entry_t*>(reinterpret_cast<uintptr_t>(tag) + sizeof(multiboot2_mmap_tag_t) + i * mmap_tag.entry_size);
|
const auto& command_line_tag = *static_cast<const multiboot2_cmdline_tag_t*>(tag);
|
||||||
dprintln("entry {16H} {16H} {8H}",
|
MUST(g_boot_info.command_line.append(command_line_tag.cmdline));
|
||||||
(uint64_t)mmap_entry.base_addr,
|
break;
|
||||||
(uint64_t)mmap_entry.length,
|
|
||||||
(uint64_t)mmap_entry.type
|
|
||||||
);
|
|
||||||
g_boot_info.memory_map_entries[i].address = mmap_entry.base_addr;
|
|
||||||
g_boot_info.memory_map_entries[i].length = mmap_entry.length;
|
|
||||||
g_boot_info.memory_map_entries[i].type = bios_number_to_memory_type(mmap_entry.type);
|
|
||||||
}
|
}
|
||||||
}
|
case MULTIBOOT2_TAG_MODULES:
|
||||||
else if (tag->type == MULTIBOOT2_TAG_OLD_RSDP)
|
|
||||||
{
|
|
||||||
if (g_boot_info.rsdp.length == 0)
|
|
||||||
{
|
{
|
||||||
memcpy(&g_boot_info.rsdp, static_cast<const multiboot2_rsdp_tag_t*>(tag)->data, 20);
|
const auto& modules_tag = *static_cast<const multiboot2_modules_tag_t*>(tag);
|
||||||
g_boot_info.rsdp.length = 20;
|
MUST(g_boot_info.modules.emplace_back(modules_tag.mod_start, modules_tag.mod_end - modules_tag.mod_start));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MULTIBOOT2_TAG_FRAMEBUFFER:
|
||||||
|
{
|
||||||
|
const auto& framebuffer_tag = *static_cast<const multiboot2_framebuffer_tag_t*>(tag);
|
||||||
|
g_boot_info.framebuffer.address = framebuffer_tag.framebuffer_addr;
|
||||||
|
g_boot_info.framebuffer.pitch = framebuffer_tag.framebuffer_pitch;
|
||||||
|
g_boot_info.framebuffer.width = framebuffer_tag.framebuffer_width;
|
||||||
|
g_boot_info.framebuffer.height = framebuffer_tag.framebuffer_height;
|
||||||
|
g_boot_info.framebuffer.bpp = framebuffer_tag.framebuffer_bpp;
|
||||||
|
if (framebuffer_tag.framebuffer_type == MULTIBOOT2_FRAMEBUFFER_TYPE_RGB)
|
||||||
|
g_boot_info.framebuffer.type = FramebufferInfo::Type::RGB;
|
||||||
|
else if (framebuffer_tag.framebuffer_type == MULTIBOOT2_FRAMEBUFFER_TYPE_TEXT)
|
||||||
|
g_boot_info.framebuffer.type = FramebufferInfo::Type::Text;
|
||||||
|
else
|
||||||
|
g_boot_info.framebuffer.type = FramebufferInfo::Type::Unknown;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MULTIBOOT2_TAG_MMAP:
|
||||||
|
{
|
||||||
|
const auto& mmap_tag = *static_cast<const multiboot2_mmap_tag_t*>(tag);
|
||||||
|
|
||||||
|
const size_t entry_count = (mmap_tag.size - sizeof(multiboot2_mmap_tag_t)) / mmap_tag.entry_size;
|
||||||
|
|
||||||
|
MUST(g_boot_info.memory_map_entries.resize(entry_count));
|
||||||
|
|
||||||
|
for (size_t i = 0; i < entry_count; i++)
|
||||||
|
{
|
||||||
|
const auto& mmap_entry = *reinterpret_cast<const multiboot2_mmap_entry_t*>(reinterpret_cast<uintptr_t>(tag) + sizeof(multiboot2_mmap_tag_t) + i * mmap_tag.entry_size);
|
||||||
|
dprintln("entry {16H} {16H} {8H}",
|
||||||
|
(uint64_t)mmap_entry.base_addr,
|
||||||
|
(uint64_t)mmap_entry.length,
|
||||||
|
(uint64_t)mmap_entry.type
|
||||||
|
);
|
||||||
|
g_boot_info.memory_map_entries[i].address = mmap_entry.base_addr;
|
||||||
|
g_boot_info.memory_map_entries[i].length = mmap_entry.length;
|
||||||
|
g_boot_info.memory_map_entries[i].type = bios_number_to_memory_type(mmap_entry.type);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MULTIBOOT2_TAG_OLD_RSDP:
|
||||||
|
{
|
||||||
|
if (g_boot_info.rsdp.length == 0)
|
||||||
|
{
|
||||||
|
memcpy(&g_boot_info.rsdp, static_cast<const multiboot2_rsdp_tag_t*>(tag)->data, 20);
|
||||||
|
g_boot_info.rsdp.length = 20;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MULTIBOOT2_TAG_NEW_RSDP:
|
||||||
|
{
|
||||||
|
const auto& rsdp = *reinterpret_cast<const RSDP*>(static_cast<const multiboot2_rsdp_tag_t*>(tag)->data);
|
||||||
|
memcpy(&g_boot_info.rsdp, &rsdp, BAN::Math::min<uint32_t>(rsdp.length, sizeof(g_boot_info.rsdp)));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (tag->type == MULTIBOOT2_TAG_NEW_RSDP)
|
|
||||||
{
|
|
||||||
const auto& rsdp = *reinterpret_cast<const RSDP*>(static_cast<const multiboot2_rsdp_tag_t*>(tag)->data);
|
|
||||||
memcpy(&g_boot_info.rsdp, &rsdp, BAN::Math::min<uint32_t>(rsdp.length, sizeof(g_boot_info.rsdp)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,13 @@ namespace Kernel
|
||||||
if (entry.type != MemoryMapEntry::Type::Available)
|
if (entry.type != MemoryMapEntry::Type::Available)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// FIXME: only reserve kernel area and modules, not everything from 0 -> kernel end
|
||||||
paddr_t start = entry.address;
|
paddr_t start = entry.address;
|
||||||
if (start < (vaddr_t)g_kernel_end - KERNEL_OFFSET + g_boot_info.kernel_paddr)
|
if (start < (vaddr_t)g_kernel_end - KERNEL_OFFSET + g_boot_info.kernel_paddr)
|
||||||
start = (vaddr_t)g_kernel_end - KERNEL_OFFSET + g_boot_info.kernel_paddr;
|
start = (vaddr_t)g_kernel_end - KERNEL_OFFSET + g_boot_info.kernel_paddr;
|
||||||
|
for (const auto& module : g_boot_info.modules)
|
||||||
|
if (start < module.start + module.size)
|
||||||
|
start = module.start + module.size;
|
||||||
if (auto rem = start % PAGE_SIZE)
|
if (auto rem = start % PAGE_SIZE)
|
||||||
start += PAGE_SIZE - rem;
|
start += PAGE_SIZE - rem;
|
||||||
|
|
||||||
|
|
|
@ -258,6 +258,9 @@ static void init2(void*)
|
||||||
VirtualFileSystem::initialize(cmdline.root);
|
VirtualFileSystem::initialize(cmdline.root);
|
||||||
dprintln("VFS initialized");
|
dprintln("VFS initialized");
|
||||||
|
|
||||||
|
// FIXME: release memory used by modules. If modules are used
|
||||||
|
// they are already loaded in here
|
||||||
|
|
||||||
TTY::initialize_devices();
|
TTY::initialize_devices();
|
||||||
|
|
||||||
auto console_path = MUST(BAN::String::formatted("/dev/{}", cmdline.console));
|
auto console_path = MUST(BAN::String::formatted("/dev/{}", cmdline.console));
|
||||||
|
|
Loading…
Reference in New Issue