Skip to content

Commit

Permalink
SailBugfix: Modify mepc / sepc based on availability of C extension
Browse files Browse the repository at this point in the history
This change in RISC-V modifies how the mepc / sepc is updated based on whether Compressed Instructions (C-extension) are supported.
  • Loading branch information
francois141 authored and CharlyCst committed Jan 31, 2025
1 parent 824456f commit 7f6abd2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/virt/csr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,11 @@ impl HwRegisterContextSetter<Csr> for VirtContext {
if value > Plat::get_max_valid_address() {
return;
}
self.csr.mepc = value & !0b1 // First bit is always zero
if self.get(Csr::Misa) & misa::C != 0 {
self.csr.mepc = value & !0b1
} else {
self.csr.mepc = value & !0b11
}
}
Csr::Mcause => self.csr.mcause = value,
Csr::Mtval => self.csr.mtval = value,
Expand Down Expand Up @@ -570,7 +574,11 @@ impl HwRegisterContextSetter<Csr> for VirtContext {
if value > Plat::get_max_valid_address() {
return;
}
self.csr.sepc = value & !0b1 // First bit is always zero
if self.get(Csr::Misa) & misa::C != 0 {
self.csr.sepc = value & !0b1
} else {
self.csr.sepc = value & !0b11
}
}
Csr::Scause => self.csr.scause = value,
Csr::Stval => self.csr.stval = value,
Expand Down

0 comments on commit 7f6abd2

Please sign in to comment.