bootloader: Refactor semantics of platform_allocate_region() functions.

This cleans up a lot of subtle or hidden inconsistencies:

 * Drop the "exactAddress" parameter. It was added in hrev15708 (2005),
   but all callers in all bootloaders passed "false" to it until 2022,
   when one codepath in the ARM32 EFI loader started using it.

 * Adjust EFI's platform_allocate_lomem to platform_allocate_region_below,
   and add a platform_assign_kernel_address_for_region(). This allows the
   aforementioned ARM EFI codepath to continue to do what it wants,
   which is to get an identity-mapped trampoline page, without having
   functions with confusingly different semantics ("allocate_lomem"
   assigned the virtual addresses as identity-mapped unconditionally,
   but it didn't insert these into the virtual allocated ranges.)

   This also paves the way for other EFI loaders to use this method
   to allocate memory below whatever default the boot services
   would give us.

 * Drop fixed virtual address allocation for all arches on EFI, with the
   exception of fixed addresses inside KERNEL_LOAD_BASE, same as on
   other boot platforms. Anything which wants fixed virtual addresses
   outside that region can use the new "assign kernel address" method.

 * Validate kernel base and size against kMaxKernelSize, instead of
   assuming it fits. This matches behavior of other boot platforms.
   Ideally we would have some more generic routine for mapping the
   kernel, but this suffices for now.

Tested with x86_64 and ARM; both still boot (well, ARM boots as
far as it did before this commit, anyway.)

Change-Id: Ieb4fba752994101191a2335cb5395eb2b726fcbb
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9024
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Augustin Cavalier
2025-02-21 04:08:51 +00:00
committed by waddlesplash
parent e364871049
commit 0463b9511c
27 changed files with 109 additions and 90 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ extern void platform_free_heap_region(void *_base, size_t size);
/* MMU/memory functions */
extern status_t platform_allocate_region(void **_virtualAddress, size_t size,
uint8 protection, bool exactAddress);
uint8 protection);
extern status_t platform_free_region(void *address, size_t size);
extern status_t platform_bootloader_address_to_kernel_address(void *address, addr_t *_result);
extern status_t platform_kernel_address_to_bootloader_address(addr_t address, void **_result);