Skip to content

Commit

Permalink
Merge pull request #245 from rmsyn/riscv/mstatus-csr-macro
Browse files Browse the repository at this point in the history
riscv: define mstatus using CSR macro
  • Loading branch information
romancardenas authored Dec 17, 2024
2 parents 3cd758b + 906b027 commit b3a42fd
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 370 deletions.
1 change: 1 addition & 0 deletions riscv/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Use CSR helper macros to define `mimpid` register
- Use CSR helper macros to define `misa` register
- Use CSR helper macros to define `mip` register
- Use CSR helper macros to define `mstatus` register

## [v0.12.1] - 2024-10-20

Expand Down
1 change: 1 addition & 0 deletions riscv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#![no_std]
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::eq_op)]

pub use paste::paste;

Expand Down
19 changes: 17 additions & 2 deletions riscv/src/register/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,14 +669,20 @@ macro_rules! csr_field_enum {
($(#[$field_ty_doc:meta])*
$field_ty:ident {
default: $default_variant:ident,
$($variant:ident = $value:expr$(,)?)+
$(
$(#[$field_doc:meta])*
$variant:ident = $value:expr$(,)?
)+
}$(,)?
) => {
$(#[$field_ty_doc])*
#[repr(usize)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum $field_ty {
$($variant = $value),+
$(
$(#[$field_doc])*
$variant = $value
),+
}

impl $field_ty {
Expand Down Expand Up @@ -1098,4 +1104,13 @@ macro_rules! test_csr_field {
assert_eq!($reg.[<try_set_ $field>]($index, false), Err($err));
}
}};

// test an enum bit field
($reg:ident, $field:ident: $var:expr) => {{
$crate::paste! {
$reg.[<set_ $field>]($var);
assert_eq!($reg.$field(), $var);
assert_eq!($reg.[<try_ $field>](), Ok($var));
}
}};
}
Loading

0 comments on commit b3a42fd

Please sign in to comment.