#include "task.h" #include "alloc.h" #include "kpanic.h" #include "memory.h" static void set_eip(void (*fn)(void), struct task *task) { // TODO or not TODO } static struct task *create_task(uint8_t owner_id) { static uint32_t pid = 1; struct task *new_task = vmalloc(sizeof(struct task)); if (!new_task) return NULL; new_task->owner_id = owner_id; new_task->pid = pid++; new_task->heap = alloc_pages(4096, (void **)&new_task->cr3); if (!new_task->heap) { vfree(new_task); return NULL; } return new_task; } void exec_fn(void (*fn)(void)) { struct task *new_task = create_task(OWNER_KERNEL); if (!new_task) kpanic("failed to create new task"); new_task->status = RUN; new_task->next = current_task; new_task->prev = current_task->prev; current_task->prev = new_task; current_task = new_task; set_eip(fn, new_task); } /* * Create task * Allocate new pd => kmalloc(4096) * Add pd address to the struct task * */