Kernel: Make the kernel independent from specific physical addresses

Previously the kernel relied on a fixed offset between virtual and
physical addresses based on the kernel's load address. This allows us
to specify an independent offset.
This commit is contained in:
Gunnar Beutner 2021-07-22 13:05:04 +02:00 committed by Andreas Kling
parent c4887882cc
commit 3c616ae00f
Notes: sideshowbarker 2024-07-18 08:03:44 +09:00
5 changed files with 7 additions and 2 deletions

View File

@ -12,6 +12,7 @@
extern "C" PhysicalAddress start_of_prekernel_image;
extern "C" PhysicalAddress end_of_prekernel_image;
extern "C" size_t physical_to_virtual_offset;
extern "C" FlatPtr kernel_base;
#if ARCH(X86_64)
extern "C" u32 gdt64ptr;

View File

@ -20,6 +20,7 @@ namespace Kernel {
struct [[gnu::packed]] BootInfo {
u32 start_of_prekernel_image;
u32 end_of_prekernel_image;
u64 physical_to_virtual_offset;
u64 kernel_base;
u64 multiboot_info_ptr;
# if ARCH(X86_64)

View File

@ -150,6 +150,7 @@ extern "C" [[noreturn]] void init()
BootInfo info;
info.start_of_prekernel_image = (PhysicalPtr)start_of_prekernel_image;
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)

View File

@ -43,12 +43,12 @@ constexpr FlatPtr page_round_down(FlatPtr x)
inline FlatPtr low_physical_to_virtual(FlatPtr physical)
{
return physical + kernel_base;
return physical + physical_to_virtual_offset;
}
inline FlatPtr virtual_to_low_physical(FlatPtr virtual_)
{
return virtual_ - kernel_base;
return virtual_ - physical_to_virtual_offset;
}
enum class UsedMemoryRangeType {

View File

@ -111,6 +111,7 @@ extern "C" {
READONLY_AFTER_INIT PhysicalAddress start_of_prekernel_image;
READONLY_AFTER_INIT PhysicalAddress end_of_prekernel_image;
READONLY_AFTER_INIT FlatPtr kernel_base;
READONLY_AFTER_INIT size_t physical_to_virtual_offset;
#if ARCH(X86_64)
READONLY_AFTER_INIT PhysicalAddress boot_pml4t;
#endif
@ -128,6 +129,7 @@ extern "C" [[noreturn]] UNMAP_AFTER_INIT void init(BootInfo const& boot_info)
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;
kernel_base = boot_info.kernel_base;
#if ARCH(X86_64)
gdt64ptr = boot_info.gdt64ptr;