Enhance command execution with improved concurrency and documentation updates. Refined the CommandTaskContext structure for better task management and clarified usage instructions for 'memtest' and 'tasktest' commands in README.md.

This commit is contained in:
2026-02-27 20:14:24 +00:00
parent 7ecf26cbd9
commit 9b1a70e3a5
4 changed files with 199 additions and 61 deletions

27
task.c
View File

@@ -1,7 +1,7 @@
/*
* task.c Cooperative multitasking: PCB pool, scheduler, yield/exit.
*
* Task 0 is the kernel/shell thread (uses the boot stack).
* Task 0 is the always-present kernel core thread (uses the boot stack).
* Additional tasks are created with task_create(), which allocates a
* stack from the PMM and sets up a fake context-switch frame so that
* context_switch() can "return" into a trampoline that calls the real
@@ -57,7 +57,7 @@ static void wstrcpy16(CHAR16 *dst, const CHAR16 *src, UINTN max)
/*
* Initialise the scheduler: clear all PCB slots and register the
* currently running kernel thread as task 0.
* currently running kernel core thread as task 0.
*/
void task_init(BootInfo *Boot)
{
@@ -79,7 +79,7 @@ void task_init(BootInfo *Boot)
}
/*
* Task 0 = the currently running kernel thread (the shell).
* Task 0 = the currently running kernel core thread.
* It already has a stack (the kernel's boot stack), so we don't
* allocate one. Its saved_rsp will be filled in during the
* first context_switch call in task_yield().
@@ -87,7 +87,7 @@ void task_init(BootInfo *Boot)
tasks[0].pid = next_pid++;
tasks[0].state = TASK_STATE_RUNNING;
tasks[0].switches = 1;
wstrcpy16(tasks[0].name, L"kernel", TASK_NAME_LEN);
wstrcpy16(tasks[0].name, L"core", TASK_NAME_LEN);
current_task = &tasks[0];
task_ready = TRUE;
@@ -329,6 +329,25 @@ UINTN task_count(void)
return count;
}
/* ----------------------------------------------------------------
* Wait for another task to finish
* ---------------------------------------------------------------- */
void task_wait(Task *t)
{
if (!task_ready || t == NULL) {
return;
}
/*
* Busy-wait cooperatively until the target task's PCB slot has
* been recycled back to FREE by task_exit().
*/
while (t->state != TASK_STATE_FREE) {
task_yield();
}
}
/* ----------------------------------------------------------------
* Print task list (implements the `ps` command)
* ---------------------------------------------------------------- */