Skip to content

Commit

Permalink
riscv: fix mtvec address field
Browse files Browse the repository at this point in the history
The `address` (BASE from the spec) needs to be 4-byte aligned, but the
spec does not specify that the field is read/written as the masked
address.

Shifts the value in `mtvec::write(addr, mode)`, and `Mtvec::address`
for a more intuitive API.
  • Loading branch information
rmsyn committed Aug 8, 2024
1 parent 5612138 commit bf655ea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions riscv/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Fixed `sip::set_ssoft` and `sip::clear_ssoft` using wrong address
- Fixed assignment in `mstatus` unit tests.
- Fixed address field for `mtvec`

## [v0.11.1] - 2024-02-15

Expand Down
4 changes: 2 additions & 2 deletions riscv/src/register/mtvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Mtvec {
/// Returns the trap-vector base-address
#[inline]
pub fn address(&self) -> usize {
self.bits - (self.bits & 0b11)
self.bits >> 2
}

/// Returns the trap-vector mode
Expand All @@ -45,6 +45,6 @@ write_csr!(0x305);
/// Writes the CSR
#[inline]
pub unsafe fn write(addr: usize, mode: TrapMode) {
let bits = addr + mode as usize;
let bits = (addr << 2) | mode as usize;
_write(bits);
}

0 comments on commit bf655ea

Please sign in to comment.