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.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/kernel/features/load.c b/kernel/features/load.c
index 4b3f8ea..31e22dc 100644
--- a/kernel/features/load.c
+++ b/kernel/features/load.c
@@ -6,15 +6,21 @@
#include <mm.h>
#include <str.h>
+// TODO: Fix pdi < 256!
+#define PROC_DATA_ADDR 0xc000000
+
#define PROC_STACK_SIZE 0x4000
+#define PROC_STACK_ADDR (PROC_DATA_ADDR - 256)
void proc_load(struct proc *proc, u32 entry)
{
- u32 stack;
- memory_alloc(proc->page_dir, PROC_STACK_SIZE, MEMORY_CLEAR, &stack);
+ /* memory_dir_switch(proc->page_dir); */
+ u32 paddr = physical_alloc(PROC_STACK_SIZE);
+ virtual_map(proc->page_dir, PROC_STACK_ADDR, paddr, PROC_STACK_SIZE,
+ MEMORY_USER | MEMORY_CLEAR);
- proc->regs.ebp = stack;
- proc->regs.useresp = stack;
+ proc->regs.ebp = PROC_STACK_ADDR;
+ proc->regs.useresp = PROC_STACK_ADDR;
proc->regs.eip = entry;
proc->entry = entry;
}
@@ -23,13 +29,22 @@ int bin_load(const char *path, struct proc *proc)
{
struct stat s = { 0 };
vfs_stat(path, &s);
- u32 data;
- memory_alloc(proc->page_dir, PAGE_ALIGN_UP(s.size), MEMORY_CLEAR, &data);
- if (!vfs_read(path, (void *)data, 0, s.size))
+ struct proc *current = proc_current();
+ struct page_dir *prev = current ? current->page_dir : memory_kernel_dir();
+
+ u32 size = PAGE_ALIGN_UP(s.size);
+ memory_dir_switch(proc->page_dir);
+ u32 paddr = physical_alloc(size);
+ virtual_map(proc->page_dir, PROC_DATA_ADDR, paddr, size, MEMORY_USER | MEMORY_CLEAR);
+
+ if (!vfs_read(path, (void *)PROC_DATA_ADDR, 0, s.size)) {
+ memory_dir_switch(prev);
return 1;
+ }
strcpy(proc->name, path);
- proc_load(proc, data);
+ proc_load(proc, PROC_DATA_ADDR);
+ memory_dir_switch(prev);
return 0;
}