diff options
Diffstat (limited to 'kernel/features')
-rw-r--r-- | kernel/features/load.c | 34 | ||||
-rw-r--r-- | kernel/features/proc.c | 2 | ||||
-rw-r--r-- | kernel/features/syscall.c | 1 |
3 files changed, 35 insertions, 2 deletions
diff --git a/kernel/features/load.c b/kernel/features/load.c index 14a3086..fd9883a 100644 --- a/kernel/features/load.c +++ b/kernel/features/load.c @@ -1,7 +1,10 @@ // MIT License, Copyright (c) 2020 Marvin Borner +#include <assert.h> +#include <cpu.h> #include <def.h> #include <fs.h> +#include <load.h> #include <mem.h> #include <proc.h> #include <str.h> @@ -17,3 +20,34 @@ void bin_load(char *path, struct proc *proc) proc->regs.eip = (u32)data; strcpy(proc->name, path + 1); } + +int elf_verify(struct elf_header *h) +{ + return h->ident[0] == ELF_MAG && (strncmp((char *)&h->ident[1], "ELF", 3) == 0) && + h->ident[4] == ELF_32 && h->ident[5] == ELF_LITTLE && h->ident[6] == ELF_CURRENT && + h->machine == ELF_386 && (h->type == ET_REL || h->type == ET_EXEC); +} + +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: + return; + case ET_REL: + return; + } + + loop(); + u32 stack = (u32)malloc(0x1000) + 0x1000; + proc->regs.ebp = (u32)stack; + proc->regs.esp = (u32)stack; + proc->regs.useresp = (u32)stack; + proc->regs.eip = (u32)h->entry; + strcpy(proc->name, path + 1); +} diff --git a/kernel/features/proc.c b/kernel/features/proc.c index 64a4ac1..7e6c95a 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -94,7 +94,7 @@ void proc_init() irq_install_handler(0, scheduler); root = proc_make(); - bin_load("/init", root); + elf_load("/init", root); proc_print(); _eip = root->regs.eip; diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c index eaa09b3..519532c 100644 --- a/kernel/features/syscall.c +++ b/kernel/features/syscall.c @@ -9,7 +9,6 @@ #include <str.h> #include <sys.h> -int i = 0; void syscall_handler(struct regs *r) { enum sys num = r->eax; |