setos

拙OS
Log | Files | Refs | LICENSE

commit d27c2fc659c4cc374cebce88f5bf490a4b281f13
parent 8480760936e723c1b4425b92d51ffe503f9f5d15
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Thu, 28 Mar 2024 16:41:44 +0900

add Phdr

Diffstat:
Mloader.c | 7++++---
Mutils.c | 4++--
Mutils.h | 15+++++++++++----
3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/loader.c b/loader.c @@ -65,9 +65,10 @@ EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab) return stat; } UINT64 kernel_size = fileInfo->FileSize; - ElfHdr kernel_hdr; - read_elf_hdr(kernel, &kernel_hdr); - stat = kernel->SetPosition(kernel, kernel_hdr.entry); + ElfHdr kernel_ehdr; + Phdr kernel_phdr; + read_elf_hdr(kernel, &kernel_ehdr, &kernel_phdr); + stat = kernel->SetPosition(kernel, kernel_ehdr.entry); if (stat != EFI_SUCCESS) { efi_printf("set position of \"kernel.elf\": %d\n", stat); return stat; diff --git a/utils.c b/utils.c @@ -125,7 +125,7 @@ efi_printf(char *fmt, ...) } EFI_STATUS -read_elf_hdr(EFI_FILE_PROTOCOL *elf, ElfHdr *hdr) +read_elf_hdr(EFI_FILE_PROTOCOL *elf, ElfHdr *ehdr, Phdr *phdr) { EFI_STATUS stat; UINTN buf_size = 1024; @@ -146,6 +146,6 @@ read_elf_hdr(EFI_FILE_PROTOCOL *elf, ElfHdr *hdr) return EFI_INVALID_PARAMETER; } efi_printf("it is an elf file\n"); - hdr->entry = 0x1000; + ehdr->entry = 0x1000; return EFI_SUCCESS; } \ No newline at end of file diff --git a/utils.h b/utils.h @@ -20,10 +20,17 @@ int efi_printf(char *fmt, ...); // ELF header. typedef struct { - UINTN entry; - UINTN ehsize; // ELF header's size. + UINTN entry; + UINTN ehsize; // ELF header's size. + UINTN phoff; + UINT16 phentsize; + UINT16 phnum; } ElfHdr; +typedef struct { + +} Phdr; + // Read_elf_hdr reads elf header and populates hdr struct. // It modifies elf's offset. -EFI_STATUS read_elf_hdr(EFI_FILE_PROTOCOL *elf, ElfHdr *hdr); -\ No newline at end of file +EFI_STATUS read_elf_hdr(EFI_FILE_PROTOCOL *elf, ElfHdr *ehdr, Phdr *phdr); +\ No newline at end of file