Do not require const-fn and asm features
This commit is contained in:
parent
3652547073
commit
41378757c0
|
@ -13,4 +13,5 @@ bare-metal = "0.2.0"
|
||||||
bit_field = "0.9.0"
|
bit_field = "0.9.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
const-fn = ["bare-metal/const-fn"]
|
||||||
inline-asm = []
|
inline-asm = []
|
|
@ -4,7 +4,7 @@ main() {
|
||||||
cargo check --target $TARGET
|
cargo check --target $TARGET
|
||||||
|
|
||||||
if [ $TRAVIS_RUST_VERSION = nightly ]; then
|
if [ $TRAVIS_RUST_VERSION = nightly ]; then
|
||||||
cargo check --target $TARGET --features inline-asm
|
cargo check --target $TARGET --features 'const-fn inline-asm'
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
23
src/asm.rs
23
src/asm.rs
|
@ -5,8 +5,12 @@ macro_rules! instruction {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn $fnname() {
|
pub unsafe fn $fnname() {
|
||||||
match () {
|
match () {
|
||||||
#[cfg(riscv)]
|
#[cfg(all(riscv, feature = "inline-asm"))]
|
||||||
() => asm!($asm :::: "volatile"),
|
() => asm!($asm :::: "volatile"),
|
||||||
|
|
||||||
|
#[cfg(all(riscv, not(feature = "inline-asm")))]
|
||||||
|
() => unimplemented!(),
|
||||||
|
|
||||||
#[cfg(not(riscv))]
|
#[cfg(not(riscv))]
|
||||||
() => unimplemented!(),
|
() => unimplemented!(),
|
||||||
}
|
}
|
||||||
|
@ -22,11 +26,16 @@ instruction!(sfence_vma_all, "sfence.vma");
|
||||||
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(riscv)]
|
#[allow(unused_variables)]
|
||||||
pub unsafe fn sfence_vma(asid: usize, addr: usize) {
|
pub unsafe fn sfence_vma(asid: usize, addr: usize) {
|
||||||
asm!("sfence.vma $0, $1" :: "r"(asid), "r"(addr) :: "volatile");
|
match () {
|
||||||
}
|
#[cfg(all(riscv, feature = "inline-asm"))]
|
||||||
|
() => asm!("sfence.vma $0, $1" :: "r"(asid), "r"(addr) :: "volatile"),
|
||||||
|
|
||||||
#[inline]
|
#[cfg(all(riscv, not(feature = "inline-asm")))]
|
||||||
#[cfg(not(riscv))]
|
() => unimplemented!(),
|
||||||
pub fn sfence_vma(_asid: usize, _addr: usize) {}
|
|
||||||
|
#[cfg(not(riscv))]
|
||||||
|
() => unimplemented!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![feature(asm)]
|
#![cfg_attr(feature = "inline-asm", feature(asm))]
|
||||||
#![feature(const_fn)]
|
|
||||||
|
|
||||||
extern crate bare_metal;
|
extern crate bare_metal;
|
||||||
extern crate bit_field;
|
extern crate bit_field;
|
||||||
|
|
|
@ -2,17 +2,21 @@ macro_rules! read_csr {
|
||||||
($csr_number:expr) => {
|
($csr_number:expr) => {
|
||||||
/// Reads the CSR
|
/// Reads the CSR
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(riscv)]
|
|
||||||
unsafe fn _read() -> usize {
|
unsafe fn _read() -> usize {
|
||||||
let r: usize;
|
match () {
|
||||||
asm!("csrrs $0, $1, x0" : "=r"(r) : "i"($csr_number) :: "volatile");
|
#[cfg(all(riscv, feature = "inline-asm"))]
|
||||||
r
|
() => {
|
||||||
}
|
let r: usize;
|
||||||
|
asm!("csrrs $0, $1, x0" : "=r"(r) : "i"($csr_number) :: "volatile");
|
||||||
|
r
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[cfg(all(riscv, not(feature = "inline-asm")))]
|
||||||
#[cfg(not(riscv))]
|
() => unimplemented!(),
|
||||||
unsafe fn _read() -> usize {
|
|
||||||
unimplemented!()
|
#[cfg(not(riscv))]
|
||||||
|
() => unimplemented!(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -21,17 +25,21 @@ macro_rules! read_csr_rv32 {
|
||||||
($csr_number:expr) => {
|
($csr_number:expr) => {
|
||||||
/// Reads the CSR
|
/// Reads the CSR
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(riscv32)]
|
|
||||||
unsafe fn _read() -> usize {
|
unsafe fn _read() -> usize {
|
||||||
let r: usize;
|
match () {
|
||||||
asm!("csrrs $0, $1, x0" : "=r"(r) : "i"($csr_number) :: "volatile");
|
#[cfg(all(riscv32, feature = "inline-asm"))]
|
||||||
r
|
() => {
|
||||||
}
|
let r: usize;
|
||||||
|
asm!("csrrs $0, $1, x0" : "=r"(r) : "i"($csr_number) :: "volatile");
|
||||||
|
r
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[cfg(all(riscv32, not(feature = "inline-asm")))]
|
||||||
#[cfg(not(riscv32))]
|
() => unimplemented!(),
|
||||||
unsafe fn _read() -> usize {
|
|
||||||
unimplemented!()
|
#[cfg(not(riscv32))]
|
||||||
|
() => unimplemented!(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -76,15 +84,18 @@ macro_rules! write_csr {
|
||||||
($csr_number:expr) => {
|
($csr_number:expr) => {
|
||||||
/// Writes the CSR
|
/// Writes the CSR
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(riscv)]
|
#[allow(unused_variables)]
|
||||||
unsafe fn _write(bits: usize) {
|
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(all(riscv, not(feature = "inline-asm")))]
|
||||||
#[cfg(not(riscv))]
|
() => unimplemented!(),
|
||||||
unsafe fn _write(_bits: usize) {
|
|
||||||
unimplemented!()
|
#[cfg(not(riscv))]
|
||||||
|
() => unimplemented!(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -105,15 +116,18 @@ macro_rules! set {
|
||||||
($csr_number:expr) => {
|
($csr_number:expr) => {
|
||||||
/// Set the CSR
|
/// Set the CSR
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(riscv)]
|
#[allow(unused_variables)]
|
||||||
unsafe fn _set(bits: usize) {
|
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(all(riscv, not(feature = "inline-asm")))]
|
||||||
#[cfg(not(riscv))]
|
() => unimplemented!(),
|
||||||
unsafe fn _set(_bits: usize) {
|
|
||||||
unimplemented!()
|
#[cfg(not(riscv))]
|
||||||
|
() => unimplemented!(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -122,15 +136,18 @@ macro_rules! clear {
|
||||||
($csr_number:expr) => {
|
($csr_number:expr) => {
|
||||||
/// Clear the CSR
|
/// Clear the CSR
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(riscv)]
|
#[allow(unused_variables)]
|
||||||
unsafe fn _clear(bits: usize) {
|
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(all(riscv, not(feature = "inline-asm")))]
|
||||||
#[cfg(not(riscv))]
|
() => unimplemented!(),
|
||||||
unsafe fn _clear(_bits: usize) {
|
|
||||||
unimplemented!()
|
#[cfg(not(riscv))]
|
||||||
|
() => unimplemented!(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue