Skip to content

Commit

Permalink
riscv-rt: Align _vector_table to 256 instead of 4
Browse files Browse the repository at this point in the history
The RISC-V Privileged Specification (version 1.11) for mtvec CSR says:
> The value in the BASE field must always be aligned on a 4-byte boundary, and the MODE setting may
> impose additional alignment constraints on the value in the BASE field.
> [...]
> An implementation may have different alignment constraints for different modes. In particular,
> MODE=Vectored may have stricter alignment constraints than MODE=Direct.

The Ibex Reference Guide for mtvec CSR says[^1]:
> The trap-vector base address, always aligned to 256 bytes

I'm not sure how we can parametrize mtvec alignment without cargo features, so this PR simply uses
the stricter alignment. If a cargo feature is preferred, I can add `mtvec-align-256`. Note that
multiple `mtvec-align-N` features are additive because the stricter one wins.

[^1]: https://ibex-core.readthedocs.io/en/latest/03_reference/cs_registers.html#machine-trap-vector-base-address-mtvec
  • Loading branch information
ia0 committed Jan 20, 2025
1 parent b391a48 commit d243b3c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion riscv-rt/src/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ core::arch::global_asm!(
.type _vector_table, @function
.option push
.balign 0x4 // TODO check if this is the correct alignment
.balign 0x100 // RISC-V requires 4, but implementations may be stricter
.option norelax
.option norvc
Expand Down

0 comments on commit d243b3c

Please sign in to comment.