From ebe6fe5d44d58fcb1b9d0ac52fa98a0a3ff309a7 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Fri, 7 Jan 2022 17:33:55 +0200 Subject: Steps towards better status/debugging control --- common/proc.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'common/proc.c') diff --git a/common/proc.c b/common/proc.c index c272727..13d3750 100644 --- a/common/proc.c +++ b/common/proc.c @@ -1,8 +1,8 @@ -#include #include +#include +#include #include #include -#include #include /* TODO: add error checking */ @@ -10,11 +10,11 @@ static vm_t setup_call_stack(struct tcb *t, size_t bytes) { pm_t offset = 0; size_t pages = __pages(bytes); - uint8_t flags = VM_V | VM_R | VM_W | VM_U; + vmflags_t flags = VM_V | VM_R | VM_W | VM_U; for(size_t i = 1; i <= pages; ++i) { offset = alloc_page(BASE_PAGE, offset); - map_vmem(t->b_r, offset, PROC_STACK_TOP - BASE_PAGE_SIZE * i, flags, BASE_PAGE); + map_vpage(t->b_r, offset, PROC_STACK_TOP - BASE_PAGE_SIZE * i, flags, BASE_PAGE); } return PROC_STACK_TOP - BASE_PAGE_SIZE * pages; @@ -25,9 +25,13 @@ static vm_t setup_proc_stack(struct tcb *t, size_t bytes) return alloc_uvmem(t, bytes, VM_V | VM_R | VM_W | VM_U); } -void init_proc(void *fdt, struct vm_branch *b) +stat_t init_proc(void *fdt, struct vm_branch *b) { + /* todo: cleanup or something */ struct tcb *t = (struct tcb *)alloc_page(BASE_PAGE, 0); + if(!t) + return ERR_OOMEM; + memset(t, 0, sizeof(struct tcb)); t->b_r = b; t->pid = 0; @@ -39,13 +43,20 @@ void init_proc(void *fdt, struct vm_branch *b) /* the binary gets to choose first what memory regions it requires */ t->entry = load_elf(t, get_init_base(fdt)); + if(!t->entry) + return ERR_ADDR; t->proc_stack = setup_proc_stack(t, __proc_stack_size); + if(!t->proc_stack) + return ERR_ADDR; + t->call_stack = setup_call_stack(t, __call_stack_size); + if(!t->call_stack) + return ERR_ADDR; flush_tlb(); /* TODO: move fdt into process space */ - jump_to_userspace(t, 1, 0); + return jump_to_userspace(t, 1, 0); } -- cgit v1.3