wip: scheduler needs to change eip or smth in order to call the fn

This commit is contained in:
2025-01-17 12:56:05 +01:00
parent b9691b1948
commit fa3ef311ad
9 changed files with 95 additions and 14 deletions

View File

@ -1,10 +1,14 @@
#include "kprintf.h"
#include "task.h"
struct task *current_task;
void scheduler(void)
{
struct task *it = current_task->next;
kprintf("camille mon bebou\n");
if (!current_task)
return;
struct task *it = current_task;
while (it->status != RUN)
it = it->next;
switch_to_task(it);

View File

@ -16,11 +16,11 @@ switch_to_task:
// and + 1 to get the argument (next task)
mov esi, [esp+(4+1)*4]
mov [current_task], esi
mov esp, [current_task]
mov eax, [current_task+4]
mov ebx, [current_task+8]
mov [TSS + 4], eax
mov esp, [current_task] // esp
mov eax, [current_task+4] // esp0
mov ebx, [current_task+8] // cr3
mov [TSS+4], eax // tss.esp0
mov ecx, cr3
// if cr3 hasn't change, do nothing
@ -34,4 +34,4 @@ switch_to_task:
pop ebp
pop ebx
ret
ret // this will also change eip to the next task's instructions

45
src/multitasking/task.c Normal file
View File

@ -0,0 +1,45 @@
#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
*
*/