Skip to content

Commit a0fac61

Browse files
committed
riscv-rt: Align _vector_table to 256 instead of 4
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
1 parent b391a48 commit a0fac61

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

riscv-rt/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Changed
1111

12-
- Ensure the `.heap` section is 4-byte aligned
12+
- Ensure the vector table is 256-byte aligned.
13+
- Ensure the `.heap` section is 4-byte aligned.
1314
- Limit rustc cfg flags to `riscvi`, `riscvm`, `riscvf`, and `riscvd`.
1415
- Temporary use of `RISCV_RT_LLVM_ARCH_PATCH` environment variable to include the
1516
temporary patch required for avoid LLVM spurious errors.

riscv-rt/src/interrupts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ core::arch::global_asm!(
8181
.type _vector_table, @function
8282
8383
.option push
84-
.balign 0x4 // TODO check if this is the correct alignment
84+
.balign 0x100 // RISC-V requires 4, but implementations may be stricter
8585
.option norelax
8686
.option norvc
8787

0 commit comments

Comments
 (0)