diff options
Diffstat (limited to 'kernel/features/load.c')
-rw-r--r-- | kernel/features/load.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/kernel/features/load.c b/kernel/features/load.c index f7fc1a5..743c009 100644 --- a/kernel/features/load.c +++ b/kernel/features/load.c @@ -1,28 +1,30 @@ // 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> +void proc_load(struct proc *proc, void *data) +{ + u32 stack = (u32)malloc(0x2000) + 0x1000; + + proc->regs.ebp = (u32)stack; + proc->regs.useresp = (u32)stack; + proc->regs.eip = (u32)data; +} + int bin_load(char *path, struct proc *proc) { // TODO: Remove hardcoded filesize struct stat s = { 0 }; vfs_stat(path, &s); char *data = malloc(s.size); - vfs_read(path, data, 0, s.size); - - u32 stack = (u32)malloc(0x2000) + 0x1000; + if (!vfs_read(path, data, 0, s.size)) + return 0; - proc->regs.ebp = (u32)stack; - proc->regs.useresp = (u32)stack; - proc->regs.eip = (u32)data; strcpy(proc->name, path); + proc_load(proc, data); - return data ? 0 : 1; + return 1; } |