diff options
author | Marvin Borner | 2021-01-07 22:06:24 +0100 |
---|---|---|
committer | Marvin Borner | 2021-01-07 22:06:24 +0100 |
commit | 52920b03e996cf60b2665772837bfa0f1661a430 (patch) | |
tree | c1fa3e96cbcc657c7235237abbc860c8bc2c4350 /kernel/features/load.c | |
parent | 80af2772db61a1ae52caf1194dd955d6263441f2 (diff) |
New read parameters
Diffstat (limited to 'kernel/features/load.c')
-rw-r--r-- | kernel/features/load.c | 43 |
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); -} |