From 4e5595a089c815febd7a0d42ab62940bf13f73ac Mon Sep 17 00:00:00 2001 From: Kimplul Date: Wed, 29 Dec 2021 18:47:16 +0200 Subject: Preparations for refactoring --- common/elf.c | 5 ++++- common/proc.c | 16 ++++++++++++++++ common/tcb.c | 4 +--- 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 common/proc.c (limited to 'common') diff --git a/common/elf.c b/common/elf.c index c73d56c..fafef00 100644 --- a/common/elf.c +++ b/common/elf.c @@ -15,7 +15,7 @@ static void __map_exec(struct tcb *t, vm_t bin, uint8_t ei_c, vm_t phstart, size size_t vsz = program_header_prop(ei_c, runner, p_memsz); vm_t start = 0; - if(!(start = alloc_fixed_region(&t->sp_r, va, vsz, 0))) + if(!(start = alloc_fixed_region(&t->sp_r, va, vsz, &vsz))) return; /* out of memory or something */ uint8_t vflags = VM_V | VM_U; @@ -36,6 +36,9 @@ static void __map_exec(struct tcb *t, vm_t bin, uint8_t ei_c, vm_t phstart, size memcpy((void *)va, (void *)vo, vfz); /* skip while testing + * TODO: also fix, this fixes only the first region. Create new + * function? + * pm_t paddr = 0; stat_vmem(t->b_r, va, &paddr, 0, 0); mod_vmem(t->b_r, va, paddr, vflags); diff --git a/common/proc.c b/common/proc.c new file mode 100644 index 0000000..5fdf413 --- /dev/null +++ b/common/proc.c @@ -0,0 +1,16 @@ +#include + +/* TODO: add error checking */ +vm_t setup_call_stack(struct tcb *t, vm_t start, size_t bytes) +{ + pm_t offset = 0; + size_t pages = __pages(bytes); + uint8_t flags = VM_V | VM_R | VM_W | VM_U; + for(size_t i = 0; i < pages; ++i) + { + offset = alloc_page(BASE_PAGE, offset); + map_vmem(t->b_r, offset, start + BASE_PAGE_SIZE * i, flags, BASE_PAGE); + } + + return start; +} diff --git a/common/tcb.c b/common/tcb.c index 8a1e95e..1547d49 100644 --- a/common/tcb.c +++ b/common/tcb.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -64,8 +65,5 @@ struct tcb *get_tcb(id_t pid) struct tcb *cur_tcb() { - /* TODO: probably keep an array of processor ID's somewhere where each - * ID has a corresponding 'currently executing thread ID' field, and - * reutrn that. */ return __tcb_cache[cpu_id()]; } -- cgit v1.3