fix: simple multitasking work !!!!

add a stack at every task, and execute task while multitasking switching
This commit is contained in:
2025-01-24 12:33:29 +01:00
parent dc84d5856b
commit 95fec015f2
5 changed files with 40 additions and 24 deletions

View File

@ -19,9 +19,16 @@ static struct task *create_task(uint8_t owner_id)
new_task->prev = current_task;
current_task->next = new_task;
new_task->owner_id = owner_id;
new_task->esp0 = alloc_pages(STACK_SIZE, NULL);
if (!new_task->esp0) {
vfree(new_task);
return NULL;
}
new_task->esp = new_task->esp0 + STACK_SIZE;
new_task->pid = pid++;
new_task->heap = alloc_pages(4096, (void **)&new_task->cr3);
if (!new_task->heap) {
free_pages(new_task->esp0, STACK_SIZE);
vfree(new_task);
return NULL;
}
@ -33,9 +40,11 @@ int create_kernel_task(void)
struct task *new_task = vmalloc(sizeof(struct task));
if (!new_task)
return -1;
new_task->status = RUN;
new_task->owner_id = 0;
new_task->pid = 0;
new_task->heap = page_directory;
new_task->cr3 = page_directory - KERNEL_START;
new_task->prev = new_task;
new_task->next = new_task;
current_task = new_task;