setos

拙OS
Log | Files | Refs | LICENSE

commit 276d034a1c7bca2f6c56fae51461d14b2b70010e
parent 927519f884f6e2dfc0caa41e1c98b6644f37ae01
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri, 29 Mar 2024 14:08:46 +0900

allocate pages

Diffstat:
Mloader.c | 7+------
Muefi.h | 18+++++++++++++++++-
Mutils.c | 8++++++++
3 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/loader.c b/loader.c @@ -83,7 +83,6 @@ EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab) efi_printf("load \"kernel.elf\": %d\n", stat); return stat; } - stat = kernel->Close(kernel); if (stat != EFI_SUCCESS) { efi_printf("close file: %d\n", stat); @@ -94,19 +93,15 @@ EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab) stat = SystemTable->BootServices->GetMemoryMap(&mmsize, mmap, &mkey, &dsize, &dver); if (stat != EFI_SUCCESS) { efi_printf("get memory map: %d\n", stat); - for (;;) {} return stat; } stat = SystemTable->BootServices->ExitBootServices(ImageHandle, mkey); if (stat != EFI_SUCCESS) { efi_printf("exit boot services: %d\n", stat); - for (;;) {} return stat; } - - EFI_PHYSICAL_ADDRESS kernel_base = 0x100000; typedef void (* Kernel) (void); - ((Kernel) kernel_base)(); + ((Kernel) kernel_ehdr.entry)(); return EFI_SUCCESS; } diff --git a/uefi.h b/uefi.h @@ -238,6 +238,21 @@ struct _EFI_SIMPLE_FILE_SYSTEM_PROTOCOL { EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME OpenVolume; }; +typedef enum { + AllocateAnyPages, + AllocateMaxAddress, + AllocateAddress, + MaxAllocateType +} EFI_ALLOCATE_TYPE; + +typedef +EFI_STATUS (EFIAPI *EFI_ALLOCATE_PAGES)( + IN EFI_ALLOCATE_TYPE Type, + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN Pages, + IN OUT EFI_PHYSICAL_ADDRESS *Memory + ); + typedef EFI_STATUS (EFIAPI *EFI_GET_MEMORY_MAP)( IN OUT UINTN *MemoryMapSize, @@ -281,7 +296,8 @@ typedef struct { // task priority services void *task_priority_services[2]; // memory services - void *memory_services0[2]; + EFI_ALLOCATE_PAGES AllocatePages; + void *memory_services0[1]; EFI_GET_MEMORY_MAP GetMemoryMap; void *memory_services1[2]; // event timer services diff --git a/utils.c b/utils.c @@ -183,6 +183,14 @@ load_elf(EFI_FILE_PROTOCOL *elf, ElfHdr *ehdr, Phdr phdr[]) if (phdr[i].type != PT_LOAD) { continue; } + stat = SystemTable->BootServices->AllocatePages( + AllocateAddress, EfiLoaderData, + (phdr[i].memsz + 0xfff) / 0x1000, &phdr[i].vaddr + ); + if (stat != EFI_SUCCESS) { + efi_printf("allocate pages: %d\n", stat); + return stat; + } stat = elf->SetPosition(elf, phdr[i].offset); if (stat != EFI_SUCCESS) { efi_printf("set position: %d\n", stat);