Skip to content

Commit

Permalink
riscv: fix target architecture condition compilation
Browse files Browse the repository at this point in the history
Uses a conditional compilation selector set by modern compiler versions
for code gated behind a target architecture.
  • Loading branch information
rmsyn committed May 3, 2024
1 parent a9d3e33 commit 7d70619
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions riscv/src/register/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ macro_rules! read_csr {
#[inline]
unsafe fn _read() -> usize {
match () {
#[cfg(riscv)]
#[cfg(target_arch = "riscv64")]
() => {
let r: usize;
core::arch::asm!(concat!("csrrs {0}, ", stringify!($csr_number), ", x0"), out(reg) r);
r
}

#[cfg(not(riscv))]
#[cfg(not(target_arch = "riscv64"))]
() => unimplemented!(),
}
}
Expand All @@ -36,14 +36,14 @@ macro_rules! read_csr_rv32 {
#[inline]
unsafe fn _read() -> usize {
match () {
#[cfg(riscv32)]
#[cfg(target_arch = "riscv32")]
() => {
let r: usize;
core::arch::asm!(concat!("csrrs {0}, ", stringify!($csr_number), ", x0"), out(reg) r);
r
}

#[cfg(not(riscv32))]
#[cfg(not(target_arch = "riscv32"))]
() => unimplemented!(),
}
}
Expand Down Expand Up @@ -127,10 +127,10 @@ macro_rules! write_csr {
#[allow(unused_variables)]
unsafe fn _write(bits: usize) {
match () {
#[cfg(riscv)]
#[cfg(target_arch = "riscv64")]
() => core::arch::asm!(concat!("csrrw x0, ", stringify!($csr_number), ", {0}"), in(reg) bits),

#[cfg(not(riscv))]
#[cfg(not(target_arch = "riscv64"))]
() => unimplemented!(),
}
}
Expand All @@ -150,10 +150,10 @@ macro_rules! write_csr_rv32 {
#[allow(unused_variables)]
unsafe fn _write(bits: usize) {
match () {
#[cfg(riscv32)]
#[cfg(target_arch = "riscv32")]
() => core::arch::asm!(concat!("csrrw x0, ", stringify!($csr_number), ", {0}"), in(reg) bits),

#[cfg(not(riscv32))]
#[cfg(not(target_arch = "riscv32"))]
() => unimplemented!(),
}
}
Expand Down Expand Up @@ -199,10 +199,10 @@ macro_rules! set {
#[allow(unused_variables)]
unsafe fn _set(bits: usize) {
match () {
#[cfg(riscv)]
#[cfg(target_arch = "riscv64")]
() => core::arch::asm!(concat!("csrrs x0, ", stringify!($csr_number), ", {0}"), in(reg) bits),

#[cfg(not(riscv))]
#[cfg(not(target_arch = "riscv64"))]
() => unimplemented!(),
}
}
Expand All @@ -220,10 +220,10 @@ macro_rules! set_rv32 {
#[allow(unused_variables)]
unsafe fn _set(bits: usize) {
match () {
#[cfg(riscv32)]
#[cfg(target_arch = "riscv32")]
() => core::arch::asm!(concat!("csrrs x0, ", stringify!($csr_number), ", {0}"), in(reg) bits),

#[cfg(not(riscv32))]
#[cfg(not(target_arch = "riscv32"))]
() => unimplemented!(),
}
}
Expand All @@ -241,10 +241,10 @@ macro_rules! clear {
#[allow(unused_variables)]
unsafe fn _clear(bits: usize) {
match () {
#[cfg(riscv)]
#[cfg(target_arch = "riscv64")]
() => core::arch::asm!(concat!("csrrc x0, ", stringify!($csr_number), ", {0}"), in(reg) bits),

#[cfg(not(riscv))]
#[cfg(not(target_arch = "riscv64"))]
() => unimplemented!(),
}
}
Expand All @@ -262,10 +262,10 @@ macro_rules! clear_rv32 {
#[allow(unused_variables)]
unsafe fn _clear(bits: usize) {
match () {
#[cfg(riscv32)]
#[cfg(target_arch = "riscv32")]
() => core::arch::asm!(concat!("csrrc x0, ", stringify!($csr_number), ", {0}"), in(reg) bits),

#[cfg(not(riscv32))]
#[cfg(not(target_arch = "riscv32"))]
() => unimplemented!(),
}
}
Expand Down Expand Up @@ -316,7 +316,7 @@ macro_rules! read_composite_csr {
#[inline]
pub fn read64() -> u64 {
match () {
#[cfg(riscv32)]
#[cfg(target_arch = "riscv32")]
() => loop {
let hi = $hi;
let lo = $lo;
Expand All @@ -325,7 +325,7 @@ macro_rules! read_composite_csr {
}
},

#[cfg(not(riscv32))]
#[cfg(not(target_arch = "riscv32"))]
() => $lo as u64,
}
}
Expand All @@ -337,10 +337,10 @@ macro_rules! set_pmp {
/// Set the pmp configuration corresponding to the index
#[inline]
pub unsafe fn set_pmp(index: usize, range: Range, permission: Permission, locked: bool) {
#[cfg(riscv32)]
#[cfg(target_arch = "riscv32")]
assert!(index < 4);

#[cfg(riscv64)]
#[cfg(target_arch = "riscv64")]
assert!(index < 8);

let mut value = _read();
Expand All @@ -357,10 +357,10 @@ macro_rules! clear_pmp {
/// Clear the pmp configuration corresponding to the index
#[inline]
pub unsafe fn clear_pmp(index: usize) {
#[cfg(riscv32)]
#[cfg(target_arch = "riscv32")]
assert!(index < 4);

#[cfg(riscv64)]
#[cfg(target_arch = "riscv64")]
assert!(index < 8);

let mut value = _read();
Expand Down

0 comments on commit 7d70619

Please sign in to comment.