-
Notifications
You must be signed in to change notification settings - Fork 28
Add basic U-mode support with ecall-based syscalls #53
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
Open
HeatCrab
wants to merge
9
commits into
sysprog21:main
Choose a base branch
from
HeatCrab:u-mode/basic-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+598
−96
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e5d9095
Add syscall dispatcher abstraction layer
HeatCrab 5be9481
Add ecall-based syscall entry point
HeatCrab 40fc9f9
Handle user mode ecall for syscall dispatch
HeatCrab cf21bdb
Add user mode task spawning interface
HeatCrab 473a3d3
Fix preemptive mode task initialization
HeatCrab 7cfa23b
Add U-mode safe output syscall
HeatCrab 3830d80
Add U-mode validation test
HeatCrab f032cc0
Add U-mode test to functional test suite
HeatCrab 814b636
Update HAL documentation for dual-mode support
HeatCrab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| #include <linmo.h> | ||
|
|
||
| /* U-mode Validation Task | ||
| * | ||
| * Integrates two tests into a single task flow to ensure sequential execution: | ||
| * 1. Phase 1: Mechanism Check - Verify syscalls work. | ||
| * 2. Phase 2: Security Check - Verify privileged instructions trigger a trap. | ||
| */ | ||
| void umode_validation_task(void) | ||
| { | ||
| /* --- Phase 1: Mechanism Check (Syscalls) --- */ | ||
| umode_printf("[umode] Phase 1: Testing Syscall Mechanism\n"); | ||
|
|
||
| /* Test 1: sys_tid() - Simplest read-only syscall. */ | ||
| int my_tid = sys_tid(); | ||
| if (my_tid > 0) { | ||
| umode_printf("[umode] PASS: sys_tid() returned %d\n", my_tid); | ||
| } else { | ||
| umode_printf("[umode] FAIL: sys_tid() failed (ret=%d)\n", my_tid); | ||
| } | ||
|
|
||
| /* Test 2: sys_uptime() - Verify value transmission is correct. */ | ||
| int uptime = sys_uptime(); | ||
| if (uptime >= 0) { | ||
| umode_printf("[umode] PASS: sys_uptime() returned %d\n", uptime); | ||
| } else { | ||
| umode_printf("[umode] FAIL: sys_uptime() failed (ret=%d)\n", uptime); | ||
| } | ||
|
|
||
| /* Note: Skipping sys_tadd for now, as kernel user pointer checks might | ||
| * block function pointers in the .text segment, avoiding distraction. | ||
| */ | ||
|
|
||
| /* --- Phase 2: Security Check (Privileged Access) --- */ | ||
| umode_printf("[umode] ========================================\n"); | ||
| umode_printf("[umode] Phase 2: Testing Security Isolation\n"); | ||
| umode_printf( | ||
| "[umode] Action: Attempting to read 'mstatus' CSR from U-mode.\n"); | ||
| umode_printf("[umode] Expect: Kernel Panic with 'Illegal instruction'.\n"); | ||
| umode_printf("[umode] ========================================\n"); | ||
|
|
||
| /* CRITICAL: Delay before suicide to ensure logs are flushed from | ||
| * buffer to UART. | ||
| */ | ||
| sys_tdelay(10); | ||
|
|
||
| /* Privileged Instruction Trigger */ | ||
| uint32_t mstatus; | ||
| asm volatile("csrr %0, mstatus" : "=r"(mstatus)); | ||
|
|
||
| /* If execution reaches here, U-mode isolation failed (still has | ||
| * privileges). | ||
| */ | ||
| umode_printf( | ||
| "[umode] FAIL: Privileged instruction executed! (mstatus=0x%lx)\n", | ||
| (long) mstatus); | ||
|
|
||
| /* Spin loop to prevent further execution. */ | ||
| while (1) | ||
| sys_tyield(); | ||
| } | ||
|
|
||
| int32_t app_main(void) | ||
| { | ||
| umode_printf("[Kernel] Spawning U-mode validation task...\n"); | ||
|
|
||
| /* app_main is called from kernel context during bootstrap. | ||
| * Use mo_task_spawn_user to create the validation task in user mode. | ||
| * This ensures privilege isolation is properly tested. | ||
| */ | ||
| mo_task_spawn_user(umode_validation_task, DEFAULT_STACK_SIZE); | ||
|
|
||
| /* Return 1 to enable preemptive scheduler */ | ||
| return 1; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.