Kernel: Add better support for bootloaders loading the kernel
Before I assumed that bootloaders loaded the kernel at physical address 0, but this patch kinda allows loading to different addresses. This still doesn't fully work as kernel bootstrap paging relies on kernel being loaded at 0
This commit is contained in:
@@ -40,8 +40,8 @@ namespace Kernel
|
||||
continue;
|
||||
|
||||
paddr_t start = entry.address;
|
||||
if (start < V2P(g_kernel_end))
|
||||
start = V2P(g_kernel_end);
|
||||
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;
|
||||
if (auto rem = start % PAGE_SIZE)
|
||||
start += PAGE_SIZE - rem;
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#include <BAN/Errors.h>
|
||||
#include <kernel/kprint.h>
|
||||
#include <kernel/BootInfo.h>
|
||||
#include <kernel/Memory/kmalloc.h>
|
||||
|
||||
#include <kernel/Thread.h>
|
||||
|
||||
#define MB (1 << 20)
|
||||
|
||||
extern uint8_t g_kernel_end[];
|
||||
@@ -424,7 +423,7 @@ BAN::Optional<Kernel::paddr_t> kmalloc_paddr_of(Kernel::vaddr_t vaddr)
|
||||
using namespace Kernel;
|
||||
|
||||
if ((vaddr_t)s_kmalloc_storage <= vaddr && vaddr < (vaddr_t)s_kmalloc_storage + sizeof(s_kmalloc_storage))
|
||||
return V2P(vaddr);
|
||||
return vaddr - KERNEL_OFFSET + g_boot_info.kernel_paddr;
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user