diff options
author | Jon Santmyer <jon@jonsantmyer.com> | 2025-09-11 14:37:04 -0400 |
---|---|---|
committer | Jon Santmyer <jon@jonsantmyer.com> | 2025-09-11 14:37:04 -0400 |
commit | 42a2bdaecaee627247689b3f4ff2828fe3c8dc97 (patch) | |
tree | 17e59594b1979912401eecb05891234e028e8869 /arch/x86_64/tasking/tcb.c | |
parent | 7f350e7ee1c2c38e5ac0b6c22c17388f6c78f0b5 (diff) | |
download | jove-kernel-42a2bdaecaee627247689b3f4ff2828fe3c8dc97.tar.gz jove-kernel-42a2bdaecaee627247689b3f4ff2828fe3c8dc97.tar.bz2 jove-kernel-42a2bdaecaee627247689b3f4ff2828fe3c8dc97.zip |
load init from ELF executable
Diffstat (limited to 'arch/x86_64/tasking/tcb.c')
-rw-r--r-- | arch/x86_64/tasking/tcb.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/arch/x86_64/tasking/tcb.c b/arch/x86_64/tasking/tcb.c new file mode 100644 index 0000000..9877455 --- /dev/null +++ b/arch/x86_64/tasking/tcb.c @@ -0,0 +1,35 @@ +#include "arch/x86_64/tcb.h" +#include "arch/x86_64/processor.h" +#include "arch/x86_64/page.h" +#include "device/processor.h" +#include "object.h" +#include "init.h" +#include "string.h" + +#define INIT_TCB_BYTES (0x1000 + KERNEL_STACK_MINSIZE) +uint8_t _init_tcb_bytes[INIT_TCB_BYTES]; +tcb_t *_init_tcb = (tcb_t*)&_init_tcb_bytes; + +void +tcb_init(void *task_main) +{ + memset(_init_tcb, 0, INIT_TCB_BYTES); + _init_tcb->size = INIT_TCB_BYTES; + size_t kstack_bytes = (size_t)(INIT_TCB_BYTES - sizeof(tcb_t)); + + _init_tcb->ksp = (uintptr_t)_init_tcb->kstack + kstack_bytes - sizeof(intmax_t); + _init_tcb->pml4 = ko_entry_data(&_initDirectory.entries[INIT_OBJECT_PAGEMAP]); + + _initDirectory.entries[INIT_OBJECT_TCB] = (objdir_entry_t) { + .type = KO_TCB, + .data = vptr_tophys_koff((uintptr_t)_init_tcb) + }; + + ((processor_t*)processor_current())->tcb = _init_tcb; + + __asm__ volatile("\ + movq %0, %%rsp; \ + movq $0, %%rbp; \ + jmpq %1":: + "r"(_init_tcb->ksp), "r"(task_main)); +} |