Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ycsin
Copy link
Member

@ycsin ycsin commented Jun 24, 2025

Note

This is the recreation of #81688

  • Simplified the fatal handling code
  • Always print the content of callee-saved-registers
  • Updated the testcase to test more configurations

@ycsin ycsin force-pushed the pr/riscv-fatal-streamline-2 branch 3 times, most recently from b2b6003 to af0176d Compare June 24, 2025 14:46
ycsin added 3 commits June 25, 2025 14:53
`CONFIG_EXTRA_EXCEPTION_INFO` that was added in zephyrproject-rtos#78065 doesn't
seem necessary, as we were already storing and printing the
callee-saved-registers before that. All `CONFIG_EXTRA_EXCEPTION_INFO`
does in RISCV is to add an additional `_callee_saved_t *csf` in the
`struct arch_esf`, which overhead is negligible to what's being enabled
by `CONFIG_EXCEPTION_DEBUG`.

Let's remove `CONFIG_EXTRA_EXCEPTION_INFO`, and have that extra
`_callee_saved_t *csf` in the `struct arch_esf` as long as
`CONFIG_EXCEPTION_DEBUG` is enabled.

Then, since `*csf` is always available in the `struct arch_esf` when
`CONFIG_EXCEPTION_DEBUG=y`, we can simply rely on that pointer in
`z_riscv_fatal_error()` instead of an additional argument in
`z_riscv_fatal_error_csf()`, rendering it redundant and thus can be
removed.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Refactor the csf saving code into a macro and calls it before jumping
to `z_riscv_fault()`, so that callee-saved-registers are printed on
generic CPU exception as well.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
- Updated the testcase to test `z_riscv_fault()` error handling path.
- The main file is now fully assembly so that we can use precompiler
  guards more easily to test with/without frame pointer enabled.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
@ycsin ycsin force-pushed the pr/riscv-fatal-streamline-2 branch from af0176d to 28a2b4a Compare June 25, 2025 06:54
Copy link

@ycsin ycsin marked this pull request as ready for review June 25, 2025 08:48
@github-actions github-actions bot added Release Notes To be mentioned in the release notes area: Architectures area: RISCV RISCV Architecture (32-bit & 64-bit) platform: nRF Nordic nRFx labels Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Architectures area: RISCV RISCV Architecture (32-bit & 64-bit) platform: nRF Nordic nRFx Release Notes To be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants