|
@@ -2,17 +2,21 @@ macro_rules! read_csr {
|
|
|
($csr_number:expr) => {
|
|
|
/// Reads the CSR
|
|
|
#[inline]
|
|
|
- #[cfg(riscv)]
|
|
|
unsafe fn _read() -> usize {
|
|
|
- let r: usize;
|
|
|
- asm!("csrrs $0, $1, x0" : "=r"(r) : "i"($csr_number) :: "volatile");
|
|
|
- r
|
|
|
- }
|
|
|
+ match () {
|
|
|
+ #[cfg(all(riscv, feature = "inline-asm"))]
|
|
|
+ () => {
|
|
|
+ let r: usize;
|
|
|
+ asm!("csrrs $0, $1, x0" : "=r"(r) : "i"($csr_number) :: "volatile");
|
|
|
+ r
|
|
|
+ }
|
|
|
|
|
|
- #[inline]
|
|
|
- #[cfg(not(riscv))]
|
|
|
- unsafe fn _read() -> usize {
|
|
|
- unimplemented!()
|
|
|
+ #[cfg(all(riscv, not(feature = "inline-asm")))]
|
|
|
+ () => unimplemented!(),
|
|
|
+
|
|
|
+ #[cfg(not(riscv))]
|
|
|
+ () => unimplemented!(),
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
}
|
|
@@ -21,17 +25,21 @@ macro_rules! read_csr_rv32 {
|
|
|
($csr_number:expr) => {
|
|
|
/// Reads the CSR
|
|
|
#[inline]
|
|
|
- #[cfg(riscv32)]
|
|
|
unsafe fn _read() -> usize {
|
|
|
- let r: usize;
|
|
|
- asm!("csrrs $0, $1, x0" : "=r"(r) : "i"($csr_number) :: "volatile");
|
|
|
- r
|
|
|
- }
|
|
|
+ match () {
|
|
|
+ #[cfg(all(riscv32, feature = "inline-asm"))]
|
|
|
+ () => {
|
|
|
+ let r: usize;
|
|
|
+ asm!("csrrs $0, $1, x0" : "=r"(r) : "i"($csr_number) :: "volatile");
|
|
|
+ r
|
|
|
+ }
|
|
|
|
|
|
- #[inline]
|
|
|
- #[cfg(not(riscv32))]
|
|
|
- unsafe fn _read() -> usize {
|
|
|
- unimplemented!()
|
|
|
+ #[cfg(all(riscv32, not(feature = "inline-asm")))]
|
|
|
+ () => unimplemented!(),
|
|
|
+
|
|
|
+ #[cfg(not(riscv32))]
|
|
|
+ () => unimplemented!(),
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
}
|
|
@@ -76,15 +84,18 @@ macro_rules! write_csr {
|
|
|
($csr_number:expr) => {
|
|
|
/// Writes the CSR
|
|
|
#[inline]
|
|
|
- #[cfg(riscv)]
|
|
|
+ #[allow(unused_variables)]
|
|
|
unsafe fn _write(bits: usize) {
|
|
|
- asm!("csrrw x0, $1, $0" :: "r"(bits), "i"($csr_number) :: "volatile");
|
|
|
- }
|
|
|
+ match () {
|
|
|
+ #[cfg(all(riscv, feature = "inline-asm"))]
|
|
|
+ () => asm!("csrrw x0, $1, $0" :: "r"(bits), "i"($csr_number) :: "volatile"),
|
|
|
|
|
|
- #[inline]
|
|
|
- #[cfg(not(riscv))]
|
|
|
- unsafe fn _write(_bits: usize) {
|
|
|
- unimplemented!()
|
|
|
+ #[cfg(all(riscv, not(feature = "inline-asm")))]
|
|
|
+ () => unimplemented!(),
|
|
|
+
|
|
|
+ #[cfg(not(riscv))]
|
|
|
+ () => unimplemented!(),
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
}
|
|
@@ -105,15 +116,18 @@ macro_rules! set {
|
|
|
($csr_number:expr) => {
|
|
|
/// Set the CSR
|
|
|
#[inline]
|
|
|
- #[cfg(riscv)]
|
|
|
+ #[allow(unused_variables)]
|
|
|
unsafe fn _set(bits: usize) {
|
|
|
- asm!("csrrs x0, $1, $0" :: "r"(bits), "i"($csr_number) :: "volatile");
|
|
|
- }
|
|
|
+ match () {
|
|
|
+ #[cfg(all(riscv, feature = "inline-asm"))]
|
|
|
+ () => asm!("csrrs x0, $1, $0" :: "r"(bits), "i"($csr_number) :: "volatile"),
|
|
|
|
|
|
- #[inline]
|
|
|
- #[cfg(not(riscv))]
|
|
|
- unsafe fn _set(_bits: usize) {
|
|
|
- unimplemented!()
|
|
|
+ #[cfg(all(riscv, not(feature = "inline-asm")))]
|
|
|
+ () => unimplemented!(),
|
|
|
+
|
|
|
+ #[cfg(not(riscv))]
|
|
|
+ () => unimplemented!(),
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
}
|
|
@@ -122,15 +136,18 @@ macro_rules! clear {
|
|
|
($csr_number:expr) => {
|
|
|
/// Clear the CSR
|
|
|
#[inline]
|
|
|
- #[cfg(riscv)]
|
|
|
+ #[allow(unused_variables)]
|
|
|
unsafe fn _clear(bits: usize) {
|
|
|
- asm!("csrrc x0, $1, $0" :: "r"(bits), "i"($csr_number) :: "volatile");
|
|
|
- }
|
|
|
+ match () {
|
|
|
+ #[cfg(all(riscv, feature = "inline-asm"))]
|
|
|
+ () => asm!("csrrc x0, $1, $0" :: "r"(bits), "i"($csr_number) :: "volatile"),
|
|
|
|
|
|
- #[inline]
|
|
|
- #[cfg(not(riscv))]
|
|
|
- unsafe fn _clear(_bits: usize) {
|
|
|
- unimplemented!()
|
|
|
+ #[cfg(all(riscv, not(feature = "inline-asm")))]
|
|
|
+ () => unimplemented!(),
|
|
|
+
|
|
|
+ #[cfg(not(riscv))]
|
|
|
+ () => unimplemented!(),
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
}
|