wip: fork and wait are almost working (missing child's stack)

This commit is contained in:
0x35c 2025-01-28 15:44:09 +01:00
parent e60969b37a
commit 1ca8c68cf5
5 changed files with 23 additions and 12 deletions

View File

@ -38,11 +38,8 @@ void clock_init(struct registers *regs)
static void clock_handler(struct registers *regs) static void clock_handler(struct registers *regs)
{ {
(void)regs; (void)regs;
if (scheduler_counter % 100 == 0) { if (scheduler_counter % 100 == 0)
cli();
scheduler(); scheduler();
toris();
}
scheduler_counter++; scheduler_counter++;
sleep_counter--; sleep_counter--;
} }

View File

@ -43,10 +43,10 @@ static void owo(void)
static void awa(void) static void awa(void)
{ {
/* if (fork() < 0) */ if (fork() < 0)
/* kprintf("camille il a une grosse bite (18cm)\n"); */ kprintf("camille il a une grosse bite (18cm)\n");
kprintf("awaille\n"); kprintf("awaille\n");
/* wait(); */ wait();
} }
void kernel_main(multiboot_info_t *mbd, u32 magic) void kernel_main(multiboot_info_t *mbd, u32 magic)

View File

@ -1,5 +1,6 @@
#include "alloc.h" #include "alloc.h"
#include "debug.h" #include "debug.h"
#include "interrupts.h"
#include "kprintf.h" #include "kprintf.h"
#include "task.h" #include "task.h"
#include "time.h" #include "time.h"
@ -10,6 +11,7 @@ struct task *current_task;
void scheduler(void) void scheduler(void)
{ {
cli();
if (!current_task) // || current_task->next == current_task) if (!current_task) // || current_task->next == current_task)
return; return;
struct task *it = current_task->next; struct task *it = current_task->next;
@ -22,4 +24,5 @@ void scheduler(void)
it = it->next; it = it->next;
} }
switch_to_task(it); switch_to_task(it);
toris();
} }

View File

@ -20,6 +20,7 @@ struct task *create_task(u8 uid)
new_task->next = current_task->next; new_task->next = current_task->next;
new_task->prev = current_task; new_task->prev = current_task;
current_task->next = new_task; current_task->next = new_task;
new_task->status = RUN;
new_task->uid = uid; new_task->uid = uid;
new_task->esp0 = alloc_pages(STACK_SIZE, NULL); new_task->esp0 = alloc_pages(STACK_SIZE, NULL);
if (!new_task->esp0) { if (!new_task->esp0) {
@ -58,7 +59,6 @@ void exec_fn(void (*fn)(void))
struct task *new_task = create_task(OWNER_KERNEL); struct task *new_task = create_task(OWNER_KERNEL);
if (!new_task) if (!new_task)
kpanic("failed to create new task"); kpanic("failed to create new task");
new_task->status = RUN;
new_task->eip = (u32 *)fn; new_task->eip = (u32 *)fn;
} }
@ -69,9 +69,9 @@ void remove_task(struct task *task)
if (task->child) if (task->child)
remove_task(task->child); remove_task(task->child);
if (task->heap) if (task->heap)
vfree(task->heap); free_pages(task->heap, 4096);
if (task->esp0) if (task->esp0)
vfree(task->esp0); free_pages(task->esp0, STACK_SIZE);
task->heap = NULL; task->heap = NULL;
task->esp0 = NULL; task->esp0 = NULL;
if (task->status != ZOMBIE) { if (task->status != ZOMBIE) {
@ -86,8 +86,11 @@ void exit_task(void)
cli(); cli();
if (current_task->daddy && current_task->daddy->status != WAIT) if (current_task->daddy && current_task->daddy->status != WAIT)
current_task->status = ZOMBIE; current_task->status = ZOMBIE;
else else {
if (current_task->daddy->status == WAIT)
current_task->daddy->status = RUN;
current_task->status = STOPPED; current_task->status = STOPPED;
}
toris(); toris();
asm volatile("jmp scheduler"); asm volatile("jmp scheduler");
} }

View File

@ -3,7 +3,15 @@
u16 wait(void) u16 wait(void)
{ {
if (current_task->child == NULL)
return -1;
cli(); cli();
if (current_task->child->status == ZOMBIE)
current_task->child->status = STOPPED;
else
current_task->status = WAIT;
u16 child_pid = current_task->child->pid;
toris(); toris();
return 0; scheduler();
return child_pid;
} }