diff options
Diffstat (limited to 'loader/loader_efi.c')
| -rw-r--r-- | loader/loader_efi.c | 96 |
1 files changed, 51 insertions, 45 deletions
diff --git a/loader/loader_efi.c b/loader/loader_efi.c index 5e238f6..de9ed39 100644 --- a/loader/loader_efi.c +++ b/loader/loader_efi.c @@ -22,7 +22,6 @@ struct system_image Elf64_Phdr *phdrs; }; -static struct system_buffer get_system_buffer(size_t size); static struct system_image *open_system_image(CHAR16 *path); static bool load_system_image(struct system_image *image); static struct efi_memory_map_data *get_memory_map_data(void); @@ -35,6 +34,8 @@ void loader_main(void) struct system_image *kernel_image = open_system_image(kernel_path); + Print(L"loading %s\r\n", kernel_path); + if (load_system_image(kernel_image)) { Print(L"loaded kernel image at base %16.0x size %d bytes\r\n", @@ -68,26 +69,6 @@ void loader_main(void) kernel_entry(&data); } -static struct system_buffer get_system_buffer(UINTN size) -{ - EFI_STATUS status; - struct system_buffer buffer; - - status = e_bs->AllocatePages(AllocateAnyPages, - SystemMemoryType, - EFI_SIZE_TO_PAGES(size), - &buffer.base); - - if (EFI_ERROR(status)) - { - Print(L"error allocating system buffer: %r\r\n", status); - buffer.base = 0; - buffer.size = 0; - } - - return buffer; -} - static bool validate_image(Elf64_Ehdr *ehdr) { if (ehdr->e_ident[EI_MAG0] != ELFMAG0 || @@ -108,29 +89,6 @@ static bool validate_image(Elf64_Ehdr *ehdr) return true; } -static UINTN get_image_size(struct system_image *image) -{ - UINTN size = 0; - Elf64_Phdr *phdrs = image->phdrs; - - for (int i = 0; i < image->ehdr.e_phnum; i++) - { - if (phdrs[i].p_type != PT_LOAD) - { - continue; - } - - if (phdrs[i].p_paddr + phdrs[i].p_memsz > size) - { - size = phdrs[i].p_paddr + phdrs[i].p_memsz; - if (phdrs[i].p_align > 1) - size = (size + phdrs[i].p_align - 1) & ~(phdrs[i].p_align - 1); - } - } - - return size; -} - static struct system_image *open_system_image(CHAR16 *path) { EFI_STATUS status; @@ -203,6 +161,55 @@ failure: return NULL; } +static struct system_buffer get_system_buffer(UINTN size) +{ + EFI_STATUS status; + struct system_buffer buffer; + + buffer.size = size; + + status = e_bs->AllocatePages(AllocateAnyPages, + SystemMemoryType, + EFI_SIZE_TO_PAGES(buffer.size), + &buffer.base); + + if (EFI_ERROR(status)) + { + Print(L"error allocating system buffer: %r\r\n", status); + buffer.base = 0; + buffer.size = 0; + } + + Print(L"allocated system buffer at %16.0x of %d bytes\r\n", + buffer.base, + buffer.size); + + return buffer; +} + +static UINTN get_image_size(struct system_image *image) +{ + UINTN size = 0; + Elf64_Phdr *phdrs = image->phdrs; + + for (int i = 0; i < image->ehdr.e_phnum; i++) + { + if (phdrs[i].p_type != PT_LOAD) + { + continue; + } + + if (phdrs[i].p_paddr + phdrs[i].p_memsz > size) + { + size = phdrs[i].p_paddr + phdrs[i].p_memsz; + if (phdrs[i].p_align > 1) + size = (size + phdrs[i].p_align - 1) & ~(phdrs[i].p_align - 1); + } + } + + return size; +} + static bool load_system_image(struct system_image *image) { image->buffer = get_system_buffer(get_image_size(image)); @@ -250,7 +257,6 @@ static bool load_system_image(struct system_image *image) return true; } - static struct efi_memory_map_data *get_memory_map_data(void) { EFI_STATUS status; |
