summaryrefslogtreecommitdiffstats
path: root/arch/x86_64/elf.c
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2025-09-10 13:28:28 -0400
committerJon Santmyer <jon@jonsantmyer.com>2025-09-10 13:28:28 -0400
commit7f350e7ee1c2c38e5ac0b6c22c17388f6c78f0b5 (patch)
treeaef9904e2495ce840319f2815cd859c47294c88a /arch/x86_64/elf.c
parent032a7bc4d79efea100a00cf3464bea3249a07ff6 (diff)
downloadjove-kernel-7f350e7ee1c2c38e5ac0b6c22c17388f6c78f0b5.tar.gz
jove-kernel-7f350e7ee1c2c38e5ac0b6c22c17388f6c78f0b5.tar.bz2
jove-kernel-7f350e7ee1c2c38e5ac0b6c22c17388f6c78f0b5.zip
refactor paging code. regression on loading init program
Diffstat (limited to 'arch/x86_64/elf.c')
-rw-r--r--arch/x86_64/elf.c27
1 files changed, 27 insertions, 0 deletions
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 <stddef.h>
+
+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;
+}