diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-04-29 17:38:41 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-04-29 17:38:41 +0300 |
| commit | 9273c16434316a8ab60dc78ee65a03e68031203a (patch) | |
| tree | 41754de4b7c459fc07e20189948c94a0e2cab966 /common/tcb.c | |
| parent | 105f3d0dab75f669d1fc404c06b73289b343591c (diff) | |
| download | kmi-9273c16434316a8ab60dc78ee65a03e68031203a.tar.gz kmi-9273c16434316a8ab60dc78ee65a03e68031203a.zip | |
continue building base for irq handling
Diffstat (limited to 'common/tcb.c')
| -rw-r--r-- | common/tcb.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/common/tcb.c b/common/tcb.c index 5d6b8a2..326d9ac 100644 --- a/common/tcb.c +++ b/common/tcb.c @@ -19,8 +19,6 @@ static struct tcb *cpu_tcb[MAX_CPUS] = { 0 }; void init_tcbs() { - /* assumption: init_tcb called after memory subsystem is initialized */ - init_nodes(&root, sizeof(struct tcb)); /* MM_O1 is 2MiB on riscv64, so 262144 different possible thread ids. * Should be enough, if we're really strapped for memory I might try * something smaller but this is fine for now. */ @@ -55,8 +53,17 @@ struct tcb *new_thread() if (unlikely(!tcbs)) return 0; - struct tcb *t = (struct tcb *)get_node(&root); - t->tid = __alloc_tid(t); + vm_t bottom = alloc_page(MM_O0, 0); + /* move tcb to top of kernel stack, keeping alignment in check + * (hopefully) */ + /* TODO: check alignment */ + struct tcb *t = (struct tcb *)align_down(bottom + __o_size(MM_O0) - sizeof(struct tcb), sizeof(long)); + memset(t, 0, sizeof(struct tcb)); + + id_t tid = __alloc_tid(t); + tcbs[tid] = t; + t->tid = tid; + return t; } @@ -67,8 +74,10 @@ void destroy_thread(struct tcb *t) /* remove thread id from list */ tcbs[t->tid] = 0; - /* free node associated with tcb */ - free_node(&root, t); + + /* free associated kernel stack */ + vm_t bottom = align_down((vm_t)t, __o_size(MM_O0)); + free_page(MM_O0, (pm_t)bottom); } struct tcb *cur_tcb() |
