diff options
author | dzwdz | 2021-07-20 21:38:09 +0200 |
---|---|---|
committer | dzwdz | 2021-07-20 21:38:09 +0200 |
commit | 9ad0eafcf7e2f3e0532666c5353b0f5294401b06 (patch) | |
tree | 2e17da4c1953b6f24fb9a9a6c533a62d3f6c4d4c /src/kernel/proc.c | |
parent | 061363a38eff486c809d397e69ae4fe290db95d2 (diff) |
per-process virtual memory
VGA is only mapped into the virtual memory because there are no other
ways of interacting with the OS.
Diffstat (limited to 'src/kernel/proc.c')
-rw-r--r-- | src/kernel/proc.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/kernel/proc.c b/src/kernel/proc.c index 4a931a5..6b80254 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -1,19 +1,30 @@ #include <kernel/arch/generic.h> #include <kernel/mem.h> #include <kernel/proc.h> +#include <stdint.h> struct process *process_current; -struct process *process_new(void *eip) { - struct process *proc; - proc = page_alloc(1); // TODO kmalloc - proc->stack_top = proc->esp = page_alloc(1) + 1 * PAGE_SIZE; - proc->eip = eip; +struct process *process_new() { + struct process *proc = page_alloc(1); // TODO kmalloc + proc->pages = pagedir_new(); + // map the stack to the last page in memory + pagedir_map(proc->pages, (void*)~PAGE_MASK, page_alloc(1), true, true); + proc->stack_top = proc->esp = (void*) ~0; + + // map the kernel + // yup, .text is writeable too. the plan is to not map the kernel + // into user memory at all, but i'll implement that later. TODO + for (size_t p = 0x100000; p < &_bss_end; p += PAGE_SIZE) + pagedir_map(proc->pages, (void*)p, (void*)p, false, true); + + // the kernel still has to load the executable code and set EIP return proc; } void process_switch(struct process *proc) { process_current = proc; + pagedir_switch(proc->pages); sysexit(proc->eip, proc->esp); } |