diff options
Diffstat (limited to 'kernel/features/load.c')
-rw-r--r-- | kernel/features/load.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/kernel/features/load.c b/kernel/features/load.c index 7d0c3c0..079cbbe 100644 --- a/kernel/features/load.c +++ b/kernel/features/load.c @@ -13,6 +13,10 @@ s32 bin_load(const char *path, struct proc *proc) { + UNUSED(path); + UNUSED(proc); + panic("Deprecated!\n"); +#if 0 if (!path || !memory_valid(path) || !proc) return -EFAULT; @@ -48,6 +52,7 @@ s32 bin_load(const char *path, struct proc *proc) memory_switch_dir(prev); return 0; +#endif } s32 elf_load(const char *path, struct proc *proc) @@ -56,14 +61,10 @@ s32 elf_load(const char *path, struct proc *proc) return -EFAULT; struct stat s = { 0 }; - memory_bypass_enable(); s32 stat = vfs_stat(path, &s); - memory_bypass_disable(); if (stat != 0) return stat; - strcpy(proc->name, path); - struct elf_header header = { 0 }; s32 read = vfs_read(path, &header, 0, sizeof(header)); if (read < 0) @@ -71,6 +72,8 @@ s32 elf_load(const char *path, struct proc *proc) if (read != sizeof(header)) return -ENOEXEC; + strcpy(proc->name, path); + // Valid? u8 *magic = header.ident; u8 valid_magic = magic[ELF_IDENT_MAG0] == ELF_MAG0 && magic[ELF_IDENT_MAG1] == ELF_MAG1 && @@ -81,9 +84,6 @@ s32 elf_load(const char *path, struct proc *proc) header.version != 1 || header.machine != ELF_MACHINE_386) return -ENOEXEC; - // I need to implement ext2 offset reading first - panic("TUDU, Marvin!\n"); - for (u32 i = 0; i < header.phnum; i++) { struct elf_program program = { 0 }; if (vfs_read(path, &program, header.phoff + header.phentsize * i, @@ -100,12 +100,13 @@ s32 elf_load(const char *path, struct proc *proc) memory_backup_dir(&prev); memory_switch_dir(proc->page_dir); - struct memory_range range = memory_range_around(program.vaddr, program.memsz); - struct memory_range prange = physical_alloc(range.size); - virtual_map(proc->page_dir, prange, range.base, MEMORY_CLEAR | MEMORY_USER); + struct memory_range vrange = memory_range_around(program.vaddr, program.memsz); + struct memory_range prange = physical_alloc(vrange.size); + virtual_map(proc->page_dir, prange, vrange.base, MEMORY_CLEAR | MEMORY_USER); - if ((u32)vfs_read(proc->name, (void *)program.vaddr, program.offset, - program.filesz) != program.filesz) { + if ((u32)vfs_read(path, (void *)program.vaddr, program.offset, program.filesz) != + program.filesz) { + print("OH NOSE!\n"); memory_switch_dir(prev); return -ENOEXEC; } @@ -118,8 +119,8 @@ s32 elf_load(const char *path, struct proc *proc) memory_switch_dir(proc->page_dir); u32 stack = (u32)memory_alloc(proc->page_dir, PROC_STACK_SIZE, MEMORY_USER | MEMORY_CLEAR); - proc->regs.ebp = stack; - proc->regs.useresp = stack; + proc->regs.ebp = stack + PROC_STACK_SIZE - 1; + proc->regs.useresp = stack + PROC_STACK_SIZE - 1; proc->regs.eip = header.entry; proc->entry = header.entry; |