Handle 64-bit load addresses for ELF64 images in the bootloader.

The ELF loader now uses a new platform function, platform_allocate_elf_region,
which returns 2 addresses: the real load address and an address where the
region is mapped in the loader's address space. All of the ELF loading code
has been changed to access the load region through the mapped address rather
than the addresses contained in the ELF image. The ELF64 version of
platform_allocate_elf_region on x86 uses the existing MMU code, which maps
everything at 0x80000000, but returns the correct 64-bit address. The long
mode switch code will just set up the 64-bit address space with everything
remapped at the correct address.
This commit is contained in:
Alex Smith
2012-06-24 22:57:48 +01:00
parent f6a3444449
commit 8846189866
13 changed files with 243 additions and 40 deletions
+18 -4
View File
@@ -1,7 +1,7 @@
/*
* Copyright 2003-2004, Axel Dörfler, [email protected]. All rights reserved.
* Copyright 2012, Alex Smith, [email protected].
* Distributed under the terms of the OpenBeOS License.
* Distributed under the terms of the MIT License.
*/
#ifndef KERNEL_BOOT_ELF_H
#define KERNEL_BOOT_ELF_H
@@ -44,9 +44,10 @@ struct preloaded_image {
} _PACKED;
struct preloaded_elf32_image : public preloaded_image {
Elf32_Ehdr elf_header;
Elf32_Ehdr elf_header;
elf32_region text_region;
elf32_region data_region;
uint32 mapped_delta;
FixedWidthPointer<Elf32_Sym> syms;
FixedWidthPointer<Elf32_Rel> rel;
@@ -61,9 +62,10 @@ struct preloaded_elf32_image : public preloaded_image {
} _PACKED;
struct preloaded_elf64_image : public preloaded_image {
Elf64_Ehdr elf_header;
Elf64_Ehdr elf_header;
elf64_region text_region;
elf64_region data_region;
uint64 mapped_delta;
FixedWidthPointer<Elf64_Sym> syms;
FixedWidthPointer<Elf64_Rel> rel;
@@ -77,11 +79,23 @@ struct preloaded_elf64_image : public preloaded_image {
FixedWidthPointer<Elf64_Sym> debug_symbols;
} _PACKED;
#ifdef _BOOT_MODE
extern status_t boot_elf_resolve_symbol(preloaded_elf32_image* image,
struct Elf32_Sym* symbol, Elf32_Addr* symbolAddress);
extern status_t boot_elf_resolve_symbol(preloaded_elf64_image* image,
struct Elf64_Sym* symbol, Elf64_Addr* symbolAddress);
// Helper method to set a relocation at the mapped address in the loader's
// address space.
template<typename ImageType, typename AddrType>
inline void
boot_elf_set_relocation(ImageType* image, AddrType resolveAddress,
AddrType finalAddress)
{
AddrType* dest = (AddrType*)(addr_t)(resolveAddress + image->mapped_delta);
*dest = finalAddress;
}
#endif
#endif /* KERNEL_BOOT_ELF_H */
+7
View File
@@ -72,6 +72,13 @@ extern size_t platform_get_user_input_text(Menu *menu, MenuItem *item,
char *buffer, size_t bufferSize);
extern char* platform_debug_get_log_buffer(size_t* _size);
/* ELF functions */
extern status_t platform_allocate_elf_region(uint32 *_address, uint32 size,
uint8 protection, void **_mappedAddress);
extern status_t platform_allocate_elf_region(uint64 *_address, uint64 size,
uint8 protection, void **_mappedAddress);
#endif
#endif /* KERNEL_BOOT_PLATFORM_H */