riscv-rt: add pre_init_trap handler to detect errors during the boot process
#188
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.
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 theesp-riscv-rtcrate.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_traproutine in the.text.abortsection. At the beginning of_abs_start, interrupts are disabled and thextvecregister is configured to handle exceptions or interrupts atpre_init_trap. Once the boot process is done,_setup_interruptsredirects interrupts to_start_trap.I thought about leaving
pre_init_trapuser-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 inriscv-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