Skip to content

Commit 335f3a7

Browse files
committed
Make Xip fields read-only
1 parent b1881e4 commit 335f3a7

File tree

3 files changed

+15
-32
lines changed

3 files changed

+15
-32
lines changed

riscv/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1616
- New methods and functions for dealing with pending interrupts in `mip` and `sip` registers
1717
using the `riscv_pac::CoreInterruptNumber` trait.
1818
- New `riscv::interrupt::is_interrupt_pending` function.
19+
- New `riscv::register::xip::clear_pending` atomic function for `mip` and `sip` registers.
20+
This function is marked as `unsafe`, as its availability depends both on the target chip
21+
and the target interrupt source.
1922

2023
### Changed
2124

@@ -27,6 +30,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2730
### Removed
2831

2932
- Removed custom build script, as `cfg(riscv)` is no longer necessary.
33+
- All the fields of `Mip` and `Sip` CSR proxies are now read-only. This change is motivated
34+
to avoid clearing unwanted interrupts triggered between CSR reads and CSR writes.
3035

3136
## [v0.14.0] - 2025-06-10
3237

riscv/src/register/mip.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
//! mip register
22
3-
use crate::bits::{bf_extract, bf_insert};
3+
use crate::bits::bf_extract;
44
use riscv_pac::CoreInterruptNumber;
55

6-
read_write_csr! {
6+
read_only_csr! {
77
/// `mip` register
88
Mip: 0x344,
99
mask: usize::MAX,
1010
}
1111

12-
read_write_csr_field! {
12+
read_only_csr_field! {
1313
Mip,
1414
/// Supervisor Software Interrupt Pending
1515
ssoft: 1,
@@ -21,7 +21,7 @@ read_only_csr_field! {
2121
msoft: 3,
2222
}
2323

24-
read_write_csr_field! {
24+
read_only_csr_field! {
2525
Mip,
2626
/// Supervisor Timer Interrupt Pending
2727
stimer: 5,
@@ -33,7 +33,7 @@ read_only_csr_field! {
3333
mtimer: 7,
3434
}
3535

36-
read_write_csr_field! {
36+
read_only_csr_field! {
3737
Mip,
3838
/// Supervisor External Interrupt Pending
3939
sext: 9,
@@ -51,18 +51,6 @@ impl Mip {
5151
pub fn is_pending<I: CoreInterruptNumber>(&self, interrupt: I) -> bool {
5252
bf_extract(self.bits, interrupt.number(), 1) != 0
5353
}
54-
55-
/// Clear the pending state of a specific core interrupt source.
56-
///
57-
/// # Safety
58-
///
59-
/// Not all interrupt sources allow clearing of pending interrupts via the `mip` register.
60-
/// Instead, it may be necessary to perform an alternative action to clear the interrupt.
61-
/// Check the specification of your target chip for details.
62-
#[inline]
63-
pub unsafe fn clear_pending<I: CoreInterruptNumber>(&mut self, interrupt: I) {
64-
self.bits = bf_insert(self.bits, interrupt.number(), 1, 0);
65-
}
6654
}
6755

6856
set!(0x344);
@@ -85,6 +73,7 @@ set_clear_csr!(
8573
/// Not all interrupt sources allow clearing of pending interrupts via the `mip` register.
8674
/// Instead, it may be necessary to perform an alternative action to clear the interrupt.
8775
/// Check the specification of your target chip for details.
76+
#[inline]
8877
pub unsafe fn clear_pending<I: CoreInterruptNumber>(interrupt: I) {
8978
_clear(1 << interrupt.number());
9079
}

riscv/src/register/sip.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
//! sip register
22
3-
use crate::bits::{bf_extract, bf_insert};
3+
use crate::bits::bf_extract;
44
use riscv_pac::CoreInterruptNumber;
55

6-
read_write_csr! {
6+
read_only_csr! {
77
/// sip register
88
Sip: 0x144,
99
mask: usize::MAX,
1010
}
1111

12-
read_write_csr_field! {
12+
read_only_csr_field! {
1313
Sip,
1414
/// Supervisor Software Interrupt Pending
1515
ssoft: 1,
@@ -33,18 +33,6 @@ impl Sip {
3333
pub fn is_pending<I: CoreInterruptNumber>(&self, interrupt: I) -> bool {
3434
bf_extract(self.bits, interrupt.number(), 1) != 0
3535
}
36-
37-
/// Clear the pending state of a specific core interrupt source.
38-
///
39-
/// # Safety
40-
///
41-
/// Not all interrupt sources allow clearing of pending interrupts via the `sip` register.
42-
/// Instead, it may be necessary to perform an alternative action to clear the interrupt.
43-
/// Check the specification of your target chip for details.
44-
#[inline]
45-
pub unsafe fn clear_pending<I: CoreInterruptNumber>(&mut self, interrupt: I) {
46-
self.bits = bf_insert(self.bits, interrupt.number(), 1, 0);
47-
}
4836
}
4937

5038
set!(0x144);
@@ -61,6 +49,7 @@ set_clear_csr!(
6149
/// Not all interrupt sources allow clearing of pending interrupts via the `sip` register.
6250
/// Instead, it may be necessary to perform an alternative action to clear the interrupt.
6351
/// Check the specification of your specific core for details.
52+
#[inline]
6453
pub unsafe fn clear_pending<I: CoreInterruptNumber>(interrupt: I) {
6554
_clear(1 << interrupt.number());
6655
}

0 commit comments

Comments
 (0)