aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kernel/features/load.c20
-rw-r--r--kernel/inc/load.h2
2 files changed, 16 insertions, 6 deletions
diff --git a/kernel/features/load.c b/kernel/features/load.c
index fd9883a..4468778 100644
--- a/kernel/features/load.c
+++ b/kernel/features/load.c
@@ -33,14 +33,22 @@ void elf_load(char *path, struct proc *proc)
char *data = read_file(path);
struct elf_header *h = (struct elf_header *)data;
- assert(elf_verify(h));
-
- printf("%d", h->type);
- switch (h->type) {
- case ET_EXEC:
+ if (!elf_verify(h))
return;
- case ET_REL:
+
+ if (h->type != ET_REL)
return;
+
+ struct elf_program_header *phdrs = (struct elf_program_header *)((u32 *)h + h->phoff);
+
+ printf("%d", h->phnum);
+ for (int i = 0; i < h->phnum; i++) {
+ struct elf_program_header *phdr = &phdrs[i];
+ printf("%d\n", phdr->type);
+ if (phdr->type != PT_LOAD)
+ continue;
+ memcpy((void *)phdr->vaddr, h + phdr->offset, phdr->filesz);
+ memset((void *)(phdr->vaddr + phdr->filesz), phdr->memsz - phdr->filesz, 0);
}
loop();
diff --git a/kernel/inc/load.h b/kernel/inc/load.h
index 597d3b5..863f04f 100644
--- a/kernel/inc/load.h
+++ b/kernel/inc/load.h
@@ -15,6 +15,8 @@
#define ET_REL 1 // Relocatable file
#define ET_EXEC 2 // Executable file
+#define PT_LOAD 1
+
struct elf_header {
u8 ident[16];
u16 type;