From 7f350e7ee1c2c38e5ac0b6c22c17388f6c78f0b5 Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Wed, 10 Sep 2025 13:28:28 -0400 Subject: refactor paging code. regression on loading init program --- arch/x86_64/elf.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 arch/x86_64/elf.c (limited to 'arch/x86_64/elf.c') diff --git a/arch/x86_64/elf.c b/arch/x86_64/elf.c new file mode 100644 index 0000000..696b7a7 --- /dev/null +++ b/arch/x86_64/elf.c @@ -0,0 +1,27 @@ +#include "elf.h" +#include + +int +elf64_ehdr_valid(Elf64_Ehdr *ehdr) +{ + if(ehdr->e_ident[EI_MAG0] != ELFMAG0 || + ehdr->e_ident[EI_MAG1] != ELFMAG1 || + ehdr->e_ident[EI_MAG2] != ELFMAG2 || + ehdr->e_ident[EI_MAG3] != ELFMAG3) + return 0; + if(ehdr->e_ident[EI_CLASS] != ELFCLASS64) return 0; + if(ehdr->e_ident[EI_DATA] != ELFDATA2LSB) return 0; + if(ehdr->e_type != ET_EXEC) return 0; + if(ehdr->e_machine != EM_X86_64) return 0; + + return 1; +} + +void* +elf64_loadexec(Elf64_Ehdr *ehdr) +{ + if(!elf64_ehdr_valid(ehdr)) return NULL; + + void *entry = (void*)ehdr->e_entry; + return entry; +} -- cgit v1.2.1