57 lines
1.9 KiB
C
57 lines
1.9 KiB
C
#ifndef TASK_H
|
|
#define TASK_H
|
|
|
|
#include <efi.h>
|
|
#include "boot_info.h"
|
|
|
|
/* Maximum number of concurrent tasks */
|
|
#define TASK_MAX 32
|
|
|
|
/* Stack size per task: 32 KB (8 pages) */
|
|
#define TASK_STACK_PAGES 8
|
|
#define TASK_STACK_SIZE (TASK_STACK_PAGES * 4096)
|
|
|
|
/* Maximum task name length */
|
|
#define TASK_NAME_LEN 32
|
|
|
|
/* Task states */
|
|
typedef enum {
|
|
TASK_STATE_FREE = 0, /* PCB slot is unused */
|
|
TASK_STATE_READY, /* Runnable, waiting for CPU */
|
|
TASK_STATE_RUNNING, /* Currently executing on CPU */
|
|
TASK_STATE_TERMINATED /* Finished execution */
|
|
} TaskState;
|
|
|
|
/* Task entry function signature */
|
|
typedef void (*TaskEntryFn)(void *arg);
|
|
|
|
/* ================================================================
|
|
* Process Control Block (PCB)
|
|
* ================================================================ */
|
|
typedef struct Task {
|
|
UINT32 pid; /* Process ID */
|
|
TaskState state; /* Current state */
|
|
CHAR16 name[TASK_NAME_LEN]; /* Human-readable name */
|
|
UINT64 saved_rsp; /* Saved stack pointer (context switch) */
|
|
UINT64 stack_base; /* Base address of allocated stack */
|
|
UINTN stack_pages; /* Stack size in pages */
|
|
TaskEntryFn entry; /* Entry function pointer */
|
|
void *arg; /* Argument passed to entry */
|
|
UINTN switches; /* Number of times scheduled */
|
|
} Task;
|
|
|
|
/* -------- Task API -------- */
|
|
|
|
void task_init(BootInfo *Boot);
|
|
Task *task_create(const CHAR16 *name, TaskEntryFn entry, void *arg);
|
|
void task_yield(void);
|
|
void task_exit(void);
|
|
Task *task_current(void);
|
|
UINTN task_count(void);
|
|
void task_print_list(BootInfo *Boot);
|
|
|
|
/* Assembly context switch (defined in context_switch.S) */
|
|
extern void context_switch(UINT64 *old_rsp, UINT64 new_rsp);
|
|
|
|
#endif
|