From 11f7c25713c2d313fc7b32b46176b79a2a374df6 Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Mon, 12 Jan 2026 23:03:13 +0100 Subject: [PATCH] Abstract base mapping address retrieval --- boot/xtldr/modules/xtos_o/amd64/memory.cc | 14 ++++++++++++++ boot/xtldr/modules/xtos_o/i686/memory.cc | 14 ++++++++++++++ boot/xtldr/modules/xtos_o/includes/xtos.hh | 1 + boot/xtldr/modules/xtos_o/xtos.cc | 8 ++++---- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/boot/xtldr/modules/xtos_o/amd64/memory.cc b/boot/xtldr/modules/xtos_o/amd64/memory.cc index 02335aa..c5afa07 100644 --- a/boot/xtldr/modules/xtos_o/amd64/memory.cc +++ b/boot/xtldr/modules/xtos_o/amd64/memory.cc @@ -156,6 +156,20 @@ Xtos::EnablePaging(IN PXTBL_PAGE_MAPPING PageMap) return STATUS_EFI_SUCCESS; } +/** + * Returns the base address of the memory mapping. + * + * @return This routine returns the base address of the memory mapping. + * + * @since XT 1.0 + */ +XTCDECL +ULONG_PTR +Xtos::GetBaseMappingAddress(VOID) +{ + return KSEG0_BASE; +} + /** * Maps the page table for hardware layer addess space. * diff --git a/boot/xtldr/modules/xtos_o/i686/memory.cc b/boot/xtldr/modules/xtos_o/i686/memory.cc index 44ee233..08cf608 100644 --- a/boot/xtldr/modules/xtos_o/i686/memory.cc +++ b/boot/xtldr/modules/xtos_o/i686/memory.cc @@ -44,6 +44,20 @@ Xtos::DeterminePagingLevel(IN CONST PWCHAR Parameters) return 2; } +/** + * Returns the base address of the memory mapping. + * + * @return This routine returns the base address of the memory mapping. + * + * @since XT 1.0 + */ +XTCDECL +ULONG_PTR +Xtos::GetBaseMappingAddress(VOID) +{ + return KSEG0_BASE; +} + /** * Builds the actual memory mapping page table and enables paging. This routine exits EFI boot services as well. * diff --git a/boot/xtldr/modules/xtos_o/includes/xtos.hh b/boot/xtldr/modules/xtos_o/includes/xtos.hh index e917d10..8d4b31e 100644 --- a/boot/xtldr/modules/xtos_o/includes/xtos.hh +++ b/boot/xtldr/modules/xtos_o/includes/xtos.hh @@ -35,6 +35,7 @@ class Xtos private: STATIC XTCDECL ULONG DeterminePagingLevel(IN CONST PWCHAR Parameters); STATIC XTCDECL EFI_STATUS EnablePaging(IN PXTBL_PAGE_MAPPING PageMap); + STATIC XTCDECL ULONG_PTR GetBaseMappingAddress(VOID); STATIC XTCDECL VOID GetDisplayInformation(OUT PSYSTEM_RESOURCE_FRAMEBUFFER FrameBufferResource, IN PEFI_PHYSICAL_ADDRESS FrameBufferBase, IN PULONG_PTR FrameBufferSize, diff --git a/boot/xtldr/modules/xtos_o/xtos.cc b/boot/xtldr/modules/xtos_o/xtos.cc index e720c07..2edc751 100644 --- a/boot/xtldr/modules/xtos_o/xtos.cc +++ b/boot/xtldr/modules/xtos_o/xtos.cc @@ -554,7 +554,7 @@ Xtos::LoadModule(IN PEFI_FILE_HANDLE SystemDir, } /* Relocate the PE/COFF image file */ - Status = PeCoffProtocol->RelocateImage(*ImageContext, KSEG0_BASE + (ULONGLONG)(*ImageContext)->PhysicalAddress); + Status = PeCoffProtocol->RelocateImage(*ImageContext, GetBaseMappingAddress() | (ULONGLONG)(*ImageContext)->PhysicalAddress); if(Status != STATUS_EFI_SUCCESS) { /* Unable to relocate the file */ @@ -640,7 +640,7 @@ Xtos::MapMemory(IN OUT PXTBL_PAGE_MAPPING PageMap, if(KernelMapping) { /* Map memory based on kernel base address */ - BaseAddress = KSEG0_BASE; + BaseAddress = GetBaseMappingAddress(); } else { @@ -666,7 +666,7 @@ XTCDECL PVOID Xtos::PhysicalAddressToVirtual(PVOID PhysicalAddress) { - return (PVOID)((ULONG_PTR)PhysicalAddress | KSEG0_BASE); + return (PVOID)((ULONG_PTR)PhysicalAddress | GetBaseMappingAddress()); } /** @@ -762,7 +762,7 @@ Xtos::RunBootSequence(IN PEFI_FILE_HANDLE BootDir, /* Initialize virtual memory mappings */ XtLdrProtocol->Memory.InitializePageMap(&PageMap, DeterminePagingLevel(Parameters->Parameters), Size4K); - Status = XtLdrProtocol->Memory.MapEfiMemory(&PageMap, KSEG0_BASE); + Status = XtLdrProtocol->Memory.MapEfiMemory(&PageMap, GetBaseMappingAddress()); if(Status != STATUS_EFI_SUCCESS) { return Status;