-
Notifications
You must be signed in to change notification settings - Fork 8.1k
arch: riscv: streamline fatal handling code #92104
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
Merged
dkalowsk
merged 2 commits into
zephyrproject-rtos:main
from
ycsin:pr/riscv-fatal-streamline-2
Oct 24, 2025
+228
−116
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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
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,20 @@ | ||
| # Copyright (c) 2024 Meta Platforms | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| choice | ||
| prompt "Fatal type" | ||
| default TEST_RISCV_FATAL_PANIC | ||
|
|
||
| config TEST_RISCV_FATAL_PANIC | ||
| bool "Panic induced fault" | ||
| help | ||
| Tests the error handling via `z_riscv_fatal_error()` | ||
|
|
||
| config TEST_RISCV_FATAL_ILLEGAL_INSTRUCTION | ||
| bool "Illegal instruction induced fault" | ||
| help | ||
| Tests the error handling via `_Fault()` | ||
|
|
||
| endchoice | ||
|
|
||
| source "Kconfig.zephyr" |
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,83 @@ | ||
| /* | ||
| * Copyright (c) 2025 Meta Platforms. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <zephyr/toolchain.h> | ||
| #include <zephyr/linker/sections.h> | ||
|
|
||
| /** | ||
| * Load up a bunch of known values into registers | ||
| * and expect them to show up in the core dump. | ||
| * Value is register ABI name kinda spelled out, | ||
| * followed by zeros to pad to 32 bits, | ||
| * followed by FF00, followed by hex number of the register, | ||
| * follwed by the "hex-coded-decimal" number of the register. | ||
| */ | ||
|
|
||
| GTEXT(main) | ||
| SECTION_FUNC(TEXT, main) | ||
|
|
||
| li ra, 0xDADA0000FF000101 | ||
|
|
||
| /* SP is skipped because it can messes stuff up */ | ||
|
|
||
| #ifndef CONFIG_RISCV_GP | ||
| li gp, 0xDADA0000FF000101 | ||
| #endif | ||
|
|
||
| #ifndef CONFIG_THREAD_LOCAL_STORAGE | ||
| li tp, 0xE2E20000FF000404 | ||
| #endif /* CONFIG_THREAD_LOCAL_STORAGE */ | ||
|
|
||
| #ifndef CONFIG_TEST_RISCV_FATAL_PANIC | ||
| /* We will load `0` (RV_ECALL_RUNTIME_EXCEPT) to `t0` */ | ||
| li t0, 0xD0FF0000FF000505 | ||
| #endif /* CONFIG_TEST_RISCV_FATAL_PANIC */ | ||
| li t1, 0xD1FF0000FF000606 | ||
| li t2, 0xD2FF0000FF000707 | ||
|
|
||
| #ifndef CONFIG_FRAME_POINTER | ||
| li s0, 0xC0FF0000FF000808 | ||
| #endif /* CONFIG_FRAME_POINTER */ | ||
|
|
||
| li s1, 0xC1FF0000FF000909 | ||
|
|
||
| li a0, 0xA0FF0000FF000A10 | ||
| li a1, 0xA1FF0000FF000B11 | ||
| li a2, 0xA2FF0000FF000C12 | ||
| li a3, 0xA3FF0000FF000D13 | ||
| li a4, 0xA4FF0000FF000E14 | ||
| li a5, 0xA5FF0000FF000F15 | ||
|
|
||
| #ifndef CONFIG_RISCV_ISA_RV32E | ||
| li a6, 0xA6FF0000FF001016 | ||
| li a7, 0xA7FF0000FF001117 | ||
|
|
||
| li s2, 0xC2FF0000FF001218 | ||
| li s3, 0xC3FF0000FF001319 | ||
| li s4, 0xC4FF0000FF001420 | ||
| li s5, 0xC5FF0000FF001521 | ||
| li s6, 0xC6FF0000FF001622 | ||
| li s7, 0xC7FF0000FF001723 | ||
| li s8, 0xC8FF0000FF001824 | ||
| li s9, 0xC9FF0000FF001925 | ||
| li s10, 0xC10FF000FF001A26 | ||
| li s11, 0xC11FF000FF001B27 | ||
|
|
||
| li t3, 0xD3FF0000FF001C28 | ||
| li t4, 0xD4FF0000FF001D29 | ||
| li t5, 0xD5FF0000FF001E30 | ||
| li t6, 0xD6FF0000FF001F31 | ||
| #endif /* CONFIG_RISCV_ISA_RV32E */ | ||
|
|
||
| #ifdef CONFIG_TEST_RISCV_FATAL_PANIC | ||
| li a0, 4 /* K_ERR_KERNEL_PANIC */ | ||
| li t0, 0 /* RV_ECALL_RUNTIME_EXCEPT */ | ||
| ecall | ||
|
|
||
| #else /* CONFIG_TEST_RISCV_FATAL_ILLEGAL_INSTRUCTION */ | ||
| .insn 2, 0 | ||
| .insn 2, 0 | ||
| #endif /* CONFIG_TEST_RISCV_FATAL_PANIC */ | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main function has been rewritten in assembly, see #81688 (comment)