[feat] Simple Multitask

This commit is contained in:
2026-05-31 12:11:57 +08:00
Unverified
parent 45693c96b5
commit b8212e2127
5 changed files with 307 additions and 3 deletions
+39
View File
@@ -0,0 +1,39 @@
#pragma once
#include <efi.h>
#include <memory/pmm.h>
#include <common.h>
#define TASK_STACK_SIZE (PAGE_SIZE * 4) // 16 KB kernel stack per task
#define TASK_MAX 32
#define TASK_NAME_LEN 32
typedef enum {
TASK_STATE_READY,
TASK_STATE_RUNNING,
TASK_STATE_TERMINATED,
} task_state_t;
typedef struct task {
UINT64 rsp; // saved stack pointer (for context switch)
UINT32 id;
task_state_t state;
char name[TASK_NAME_LEN];
void* stack_base; // base address of kernel stack
struct task* next; // circular linked list
} task_t;
// Create a new task. Returns task pointer or NULL on failure.
task_t* task_create(const char* name, void (*entry)(void));
// Yield CPU to next ready task (cooperative)
void yield(void);
// Start the scheduler — does not return. Picks first READY task and runs it.
void scheduler_run(void);
// Called by a task when it finishes — marks as TERMINATED and yields
void task_exit(void);
// Get current running task
task_t* scheduler_current(void);