Skip to content

Conversation

@romancardenas
Copy link
Contributor

I'm working on enabling the vectored interrupt mode in riscv-rt. To do so, I'm following SiFive's RISC-V interrupt Cookbook and the esp-riscv-rt crate.

Section 2.1.3 of the SiFive Cookbook provides information about requiring a pre-init trap handler to detect errors before the boot process. This issue is also outlined in #156.

This PR adds a simple pre_init_trap routine in the .text.abort section. At the beginning of _abs_start, interrupts are disabled and the xtvec register is configured to handle exceptions or interrupts at pre_init_trap. Once the boot process is done, _setup_interrupts redirects interrupts to _start_trap.

I thought about leaving pre_init_trap user-defined with a dummy default implementation. However, it is quite dangerous to leave users to add their code before the boot process is done. Thus, in my opinion, it is better to leave it like this, being the new trap just kind of a flag to allow us to detect bugs in riscv-rt.

BEWARE: I'm far from an assembly expert, so a double-check is welcome 😁. Also, the folks from esp-rs (ping @jessebraham @MabezDev) could provide very valuable feedback on this.

Closes #156

@romancardenas romancardenas requested a review from a team as a code owner February 23, 2024 10:55
Copy link
Contributor

@almindor almindor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

I would wait for more folks to chime in though. The question of opening this to user edits is an interesting one.

@romancardenas
Copy link
Contributor Author

I could slightly modify the PR and define _pre_init_trap as a weak symbol so users could overwrite it. In any case, this should be properly documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

riscv-rt: Pre initialization trap handling

2 participants