mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 13:35:12 +00:00
Prekernel: Export some multiboot parameters in our own BootInfo struct
This allows us to specify virtual addresses for things the kernel should access via virtual addresses later on. By doing this we can make the kernel independent from specific physical addresses.
This commit is contained in:
parent
ff292fbe5a
commit
b10a86d463
Notes:
sideshowbarker
2024-07-18 08:03:32 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/b10a86d463d Pull-request: https://github.com/SerenityOS/serenity/pull/8962
8 changed files with 67 additions and 25 deletions
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <Kernel/Arch/x86/PageDirectory.h>
|
||||
#include <Kernel/Multiboot.h>
|
||||
#include <Kernel/PhysicalAddress.h>
|
||||
#include <Kernel/VirtualAddress.h>
|
||||
|
||||
|
@ -24,3 +25,14 @@ extern "C" PhysicalAddress boot_pd0;
|
|||
extern "C" PhysicalAddress boot_pd_kernel;
|
||||
extern "C" Kernel::PageTableEntry* boot_pd_kernel_pt1023;
|
||||
extern "C" const char* kernel_cmdline;
|
||||
extern "C" u32 multiboot_flags;
|
||||
extern "C" multiboot_memory_map_t* multiboot_memory_map;
|
||||
extern "C" size_t multiboot_memory_map_count;
|
||||
extern "C" multiboot_module_entry_t* multiboot_modules;
|
||||
extern "C" size_t multiboot_modules_count;
|
||||
extern "C" PhysicalAddress multiboot_framebuffer_addr;
|
||||
extern "C" u32 multiboot_framebuffer_pitch;
|
||||
extern "C" u32 multiboot_framebuffer_width;
|
||||
extern "C" u32 multiboot_framebuffer_height;
|
||||
extern "C" u8 multiboot_framebuffer_bpp;
|
||||
extern "C" u8 multiboot_framebuffer_type;
|
||||
|
|
|
@ -109,13 +109,13 @@ UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_devi
|
|||
// support, so we want to utilize the provided framebuffer of these
|
||||
// devices, if possible.
|
||||
if (!m_vga_adapter && PCI::is_io_space_enabled(address)) {
|
||||
if (multiboot_info_ptr->framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_RGB) {
|
||||
if (multiboot_framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_RGB) {
|
||||
dmesgln("Graphics: Using a preset resolution from the bootloader");
|
||||
adapter = VGACompatibleAdapter::initialize_with_preset_resolution(address,
|
||||
PhysicalAddress((u32)(multiboot_info_ptr->framebuffer_addr)),
|
||||
multiboot_info_ptr->framebuffer_width,
|
||||
multiboot_info_ptr->framebuffer_height,
|
||||
multiboot_info_ptr->framebuffer_pitch);
|
||||
multiboot_framebuffer_addr,
|
||||
multiboot_framebuffer_width,
|
||||
multiboot_framebuffer_height,
|
||||
multiboot_framebuffer_pitch);
|
||||
}
|
||||
} else {
|
||||
dmesgln("Graphics: Using a VGA compatible generic adapter");
|
||||
|
|
|
@ -121,5 +121,3 @@ struct multiboot_info {
|
|||
};
|
||||
};
|
||||
typedef struct multiboot_info multiboot_info_t;
|
||||
|
||||
extern "C" multiboot_info_t* multiboot_info_ptr;
|
||||
|
|
|
@ -22,7 +22,6 @@ struct [[gnu::packed]] BootInfo {
|
|||
u32 end_of_prekernel_image;
|
||||
u64 physical_to_virtual_offset;
|
||||
u64 kernel_base;
|
||||
u64 multiboot_info_ptr;
|
||||
# if ARCH(X86_64)
|
||||
u32 gdt64ptr;
|
||||
u16 code64_sel;
|
||||
|
@ -33,6 +32,17 @@ struct [[gnu::packed]] BootInfo {
|
|||
u32 boot_pd_kernel;
|
||||
u64 boot_pd_kernel_pt1023;
|
||||
u64 kernel_cmdline;
|
||||
u32 multiboot_flags;
|
||||
u64 multiboot_memory_map;
|
||||
u32 multiboot_memory_map_count;
|
||||
u64 multiboot_modules;
|
||||
u32 multiboot_modules_count;
|
||||
u64 multiboot_framebuffer_addr;
|
||||
u32 multiboot_framebuffer_pitch;
|
||||
u32 multiboot_framebuffer_width;
|
||||
u32 multiboot_framebuffer_height;
|
||||
u8 multiboot_framebuffer_bpp;
|
||||
u8 multiboot_framebuffer_type;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -143,7 +143,7 @@ extern "C" [[noreturn]] void init()
|
|||
multiboot_info_ptr->mods_count--;
|
||||
multiboot_info_ptr->mods_addr += sizeof(multiboot_module_entry_t);
|
||||
|
||||
auto adjust_by_load_base = [kernel_load_base](auto* ptr) {
|
||||
auto adjust_by_load_base = [kernel_load_base](auto ptr) {
|
||||
return (decltype(ptr))((FlatPtr)ptr + kernel_load_base);
|
||||
};
|
||||
|
||||
|
@ -152,7 +152,6 @@ extern "C" [[noreturn]] void init()
|
|||
info.end_of_prekernel_image = (PhysicalPtr)end_of_prekernel_image;
|
||||
info.physical_to_virtual_offset = kernel_load_base;
|
||||
info.kernel_base = kernel_load_base;
|
||||
info.multiboot_info_ptr = (FlatPtr)adjust_by_load_base(multiboot_info_ptr);
|
||||
#if ARCH(X86_64)
|
||||
info.gdt64ptr = (PhysicalPtr)gdt64ptr;
|
||||
info.code64_sel = code64_sel;
|
||||
|
@ -163,6 +162,17 @@ extern "C" [[noreturn]] void init()
|
|||
info.boot_pd_kernel = (PhysicalPtr)boot_pd_kernel;
|
||||
info.boot_pd_kernel_pt1023 = (FlatPtr)adjust_by_load_base(boot_pd_kernel_pt1023);
|
||||
info.kernel_cmdline = (FlatPtr)adjust_by_load_base(kernel_cmdline);
|
||||
info.multiboot_flags = multiboot_info_ptr->flags;
|
||||
info.multiboot_memory_map = adjust_by_load_base((FlatPtr)multiboot_info_ptr->mmap_addr);
|
||||
info.multiboot_memory_map_count = multiboot_info_ptr->mmap_length / sizeof(multiboot_memory_map_t);
|
||||
info.multiboot_modules = adjust_by_load_base((FlatPtr)multiboot_info_ptr->mods_addr);
|
||||
info.multiboot_modules_count = multiboot_info_ptr->mods_count;
|
||||
info.multiboot_framebuffer_addr = multiboot_info_ptr->framebuffer_addr;
|
||||
info.multiboot_framebuffer_pitch = multiboot_info_ptr->framebuffer_pitch;
|
||||
info.multiboot_framebuffer_width = multiboot_info_ptr->framebuffer_width;
|
||||
info.multiboot_framebuffer_height = multiboot_info_ptr->framebuffer_height;
|
||||
info.multiboot_framebuffer_bpp = multiboot_info_ptr->framebuffer_bpp;
|
||||
info.multiboot_framebuffer_type = multiboot_info_ptr->framebuffer_type;
|
||||
|
||||
asm(
|
||||
#if ARCH(I386)
|
||||
|
|
|
@ -199,7 +199,7 @@ UNMAP_AFTER_INIT void MemoryManager::parse_memory_map()
|
|||
m_used_memory_ranges.append(UsedMemoryRange { UsedMemoryRangeType::Prekernel, start_of_prekernel_image, end_of_prekernel_image });
|
||||
m_used_memory_ranges.append(UsedMemoryRange { UsedMemoryRangeType::Kernel, PhysicalAddress(virtual_to_low_physical((FlatPtr)start_of_kernel_image)), PhysicalAddress(page_round_up(virtual_to_low_physical((FlatPtr)end_of_kernel_image))) });
|
||||
|
||||
if (multiboot_info_ptr->flags & 0x4) {
|
||||
if (multiboot_flags & 0x4) {
|
||||
auto* bootmods_start = multiboot_copy_boot_modules_array;
|
||||
auto* bootmods_end = bootmods_start + multiboot_copy_boot_modules_count;
|
||||
|
||||
|
@ -208,8 +208,8 @@ UNMAP_AFTER_INIT void MemoryManager::parse_memory_map()
|
|||
}
|
||||
}
|
||||
|
||||
auto* mmap_begin = reinterpret_cast<multiboot_memory_map_t*>(low_physical_to_virtual(multiboot_info_ptr->mmap_addr));
|
||||
auto* mmap_end = reinterpret_cast<multiboot_memory_map_t*>(low_physical_to_virtual(multiboot_info_ptr->mmap_addr) + multiboot_info_ptr->mmap_length);
|
||||
auto* mmap_begin = multiboot_memory_map;
|
||||
auto* mmap_end = multiboot_memory_map + multiboot_memory_map_count;
|
||||
|
||||
struct ContiguousPhysicalRange {
|
||||
PhysicalAddress lower;
|
||||
|
|
|
@ -41,11 +41,6 @@ constexpr FlatPtr page_round_down(FlatPtr x)
|
|||
return ((FlatPtr)(x)) & ~(PAGE_SIZE - 1);
|
||||
}
|
||||
|
||||
inline FlatPtr low_physical_to_virtual(FlatPtr physical)
|
||||
{
|
||||
return physical + physical_to_virtual_offset;
|
||||
}
|
||||
|
||||
inline FlatPtr virtual_to_low_physical(FlatPtr virtual_)
|
||||
{
|
||||
return virtual_ - physical_to_virtual_offset;
|
||||
|
|
|
@ -120,13 +120,23 @@ READONLY_AFTER_INIT PhysicalAddress boot_pd0;
|
|||
READONLY_AFTER_INIT PhysicalAddress boot_pd_kernel;
|
||||
READONLY_AFTER_INIT PageTableEntry* boot_pd_kernel_pt1023;
|
||||
READONLY_AFTER_INIT const char* kernel_cmdline;
|
||||
READONLY_AFTER_INIT u32 multiboot_flags;
|
||||
READONLY_AFTER_INIT multiboot_memory_map_t* multiboot_memory_map;
|
||||
READONLY_AFTER_INIT size_t multiboot_memory_map_count;
|
||||
READONLY_AFTER_INIT multiboot_module_entry_t* multiboot_modules;
|
||||
READONLY_AFTER_INIT size_t multiboot_modules_count;
|
||||
READONLY_AFTER_INIT PhysicalAddress multiboot_framebuffer_addr;
|
||||
READONLY_AFTER_INIT u32 multiboot_framebuffer_pitch;
|
||||
READONLY_AFTER_INIT u32 multiboot_framebuffer_width;
|
||||
READONLY_AFTER_INIT u32 multiboot_framebuffer_height;
|
||||
READONLY_AFTER_INIT u8 multiboot_framebuffer_bpp;
|
||||
READONLY_AFTER_INIT u8 multiboot_framebuffer_type;
|
||||
}
|
||||
|
||||
extern "C" [[noreturn]] UNMAP_AFTER_INIT void init(BootInfo const& boot_info)
|
||||
{
|
||||
g_in_early_boot = true;
|
||||
|
||||
multiboot_info_ptr = (multiboot_info_t*)boot_info.multiboot_info_ptr;
|
||||
start_of_prekernel_image = PhysicalAddress { boot_info.start_of_prekernel_image };
|
||||
end_of_prekernel_image = PhysicalAddress { boot_info.end_of_prekernel_image };
|
||||
physical_to_virtual_offset = boot_info.physical_to_virtual_offset;
|
||||
|
@ -141,14 +151,25 @@ extern "C" [[noreturn]] UNMAP_AFTER_INIT void init(BootInfo const& boot_info)
|
|||
boot_pd_kernel = PhysicalAddress { boot_info.boot_pd_kernel };
|
||||
boot_pd_kernel_pt1023 = (PageTableEntry*)boot_info.boot_pd_kernel_pt1023;
|
||||
kernel_cmdline = (char const*)boot_info.kernel_cmdline;
|
||||
multiboot_flags = boot_info.multiboot_flags;
|
||||
multiboot_memory_map = (multiboot_memory_map_t*)boot_info.multiboot_memory_map;
|
||||
multiboot_memory_map_count = boot_info.multiboot_memory_map_count;
|
||||
multiboot_modules = (multiboot_module_entry_t*)boot_info.multiboot_modules;
|
||||
multiboot_modules_count = boot_info.multiboot_modules_count;
|
||||
multiboot_framebuffer_addr = PhysicalAddress { boot_info.multiboot_framebuffer_addr };
|
||||
multiboot_framebuffer_pitch = boot_info.multiboot_framebuffer_pitch;
|
||||
multiboot_framebuffer_width = boot_info.multiboot_framebuffer_width;
|
||||
multiboot_framebuffer_height = boot_info.multiboot_framebuffer_height;
|
||||
multiboot_framebuffer_bpp = boot_info.multiboot_framebuffer_bpp;
|
||||
multiboot_framebuffer_type = boot_info.multiboot_framebuffer_type;
|
||||
|
||||
setup_serial_debug();
|
||||
|
||||
// We need to copy the command line before kmalloc is initialized,
|
||||
// as it may overwrite parts of multiboot!
|
||||
CommandLine::early_initialize(kernel_cmdline);
|
||||
memcpy(multiboot_copy_boot_modules_array, (u8*)low_physical_to_virtual(multiboot_info_ptr->mods_addr), multiboot_info_ptr->mods_count * sizeof(multiboot_module_entry_t));
|
||||
multiboot_copy_boot_modules_count = multiboot_info_ptr->mods_count;
|
||||
memcpy(multiboot_copy_boot_modules_array, multiboot_modules, multiboot_modules_count * sizeof(multiboot_module_entry_t));
|
||||
multiboot_copy_boot_modules_count = multiboot_modules_count;
|
||||
s_bsp_processor.early_initialize(0);
|
||||
|
||||
// Invoke the constructors needed for the kernel heap
|
||||
|
@ -352,10 +373,6 @@ UNMAP_AFTER_INIT void setup_serial_debug()
|
|||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
multiboot_info_t* multiboot_info_ptr;
|
||||
}
|
||||
|
||||
// Define some Itanium C++ ABI methods to stop the linker from complaining.
|
||||
// If we actually call these something has gone horribly wrong
|
||||
void* __dso_handle __attribute__((visibility("hidden")));
|
||||
|
|
Loading…
Add table
Reference in a new issue