aboutsummaryrefslogtreecommitdiff
path: root/kernel/features/load.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/features/load.c')
-rw-r--r--kernel/features/load.c43
1 files changed, 3 insertions, 40 deletions
diff --git a/kernel/features/load.c b/kernel/features/load.c
index b3d5828..e5b6903 100644
--- a/kernel/features/load.c
+++ b/kernel/features/load.c
@@ -11,7 +11,9 @@
int bin_load(char *path, struct proc *proc)
{
- char *data = vfs_read(path);
+ // TODO: Remove hardcoded filesize
+ char *data = malloc(0xffff);
+ vfs_read(path, data, 0, 0xffff);
u32 stack = (u32)malloc(0x2000) + 0x1000;
@@ -22,42 +24,3 @@ int bin_load(char *path, struct proc *proc)
return data ? 0 : 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);
-}
-
-// TODO: Fix elf loading
-void elf_load(char *path, struct proc *proc)
-{
- char *data = vfs_read(path);
- struct elf_header *h = (struct elf_header *)data;
-
- if (!elf_verify(h)) {
- printf("File is not elf");
- return;
- }
-
- if (h->type != ET_REL)
- return;
-
- struct elf_program_header *phdrs = (struct elf_program_header *)((u32 *)h + h->phoff);
-
- for (int i = 0; i < h->phnum; i++) {
- struct elf_program_header *phdr = &phdrs[i];
- if (phdr->type != PT_LOAD)
- continue;
- memcpy((void *)phdr->vaddr, h + phdr->offset, phdr->filesz);
- memset((void *)(phdr->vaddr + phdr->filesz), 0, phdr->memsz - phdr->filesz);
- }
-
- 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);
-}