-
Notifications
You must be signed in to change notification settings - Fork 31
Add configurable privilege mode for application entry #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,26 @@ | ||
| #include <hal.h> | ||
| #include <lib/libc.h> | ||
| #include <sys/logger.h> | ||
| #include <sys/syscall.h> | ||
| #include <sys/task.h> | ||
|
|
||
| #include "private/error.h" | ||
|
|
||
| #ifndef CONFIG_PRIVILEGED | ||
| /* Wrapper to run app_main() in U-mode. | ||
| * | ||
| * In U-mode, the return value cannot control preemptive mode (kcb is | ||
| * inaccessible), so it's ignored. The infinite loop keeps the task alive | ||
| * after app_main() returns. | ||
| */ | ||
| static void app_main_wrapper(void) | ||
| { | ||
| app_main(); | ||
| for (;;) | ||
| sys_tyield(); | ||
| } | ||
| #endif | ||
|
|
||
| /* C-level entry point for the kernel. | ||
| * | ||
| * This function is called from the boot code ('_entry'). It is responsible for | ||
|
|
@@ -42,8 +58,15 @@ int32_t main(void) | |
| printf("Logger initialized\n"); | ||
| } | ||
|
|
||
| /* Call the application's main entry point to create initial tasks. */ | ||
| #ifdef CONFIG_PRIVILEGED | ||
| /* M-mode: app_main() controls preemptive mode via return value */ | ||
| kcb->preemptive = (bool) app_main(); | ||
| #else | ||
| /* U-mode: preemptive mode fixed, app_main() runs as user task */ | ||
| kcb->preemptive = true; | ||
| mo_task_spawn(app_main_wrapper, DEFAULT_STACK_SIZE, TASK_MODE_U); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Spawning the wrapper in U-mode makes Prompt for AI agents
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In U-mode, This differs from M-mode semantics by design:
The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedback! I've saved this as a new learning to improve future reviews. |
||
| #endif | ||
|
|
||
| printf("Scheduler mode: %s\n", | ||
| kcb->preemptive ? "Preemptive" : "Cooperative"); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.