Implement Error type for traps module
Recommended by the clippy lint https://rust-lang.github.io/rust-clippy/master/index.html#result_unit_err Using snafu because it already has a no_std feature unlike thiserror.
This commit is contained in:
parent
fef66a0191
commit
ab696eca8e
|
@ -27,12 +27,36 @@ dependencies = [
|
|||
"register",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "doc-comment"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "qemu-exit"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b73ae13954572c7ca0ec48ba9fe6a59c0392066eba62f8cb384ffd5addf538c5"
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r0"
|
||||
version = "1.0.0"
|
||||
|
@ -54,12 +78,50 @@ version = "1.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe"
|
||||
|
||||
[[package]]
|
||||
name = "snafu"
|
||||
version = "0.6.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c4e6046e4691afe918fd1b603fd6e515bcda5388a1092a9edbada307d159f09"
|
||||
dependencies = [
|
||||
"doc-comment",
|
||||
"snafu-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "snafu-derive"
|
||||
version = "0.6.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7073448732a89f2f3e6581989106067f403d378faeafb4a50812eb814170d3e5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.48"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tock-registers"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70323afdb8082186c0986da0e10f6e4ed103d681c921c00597e98d9806dac20f"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
|
||||
[[package]]
|
||||
name = "usize_conversions"
|
||||
version = "0.2.0"
|
||||
|
@ -84,6 +146,7 @@ dependencies = [
|
|||
"r0",
|
||||
"register",
|
||||
"rlibc",
|
||||
"snafu",
|
||||
"usize_conversions",
|
||||
"ux",
|
||||
]
|
||||
|
|
|
@ -31,3 +31,4 @@ bit_field = "0.10.0"
|
|||
register = "0.5.1"
|
||||
bitflags = "1.2.1"
|
||||
cfg-if = "1.0"
|
||||
snafu = { version = "0.6", default-features = false }
|
||||
|
|
|
@ -55,19 +55,28 @@ use {
|
|||
barrier,
|
||||
regs::{RegisterReadOnly, RegisterReadWrite, ESR_EL1, FAR_EL1, VBAR_EL1},
|
||||
},
|
||||
snafu::Snafu,
|
||||
};
|
||||
|
||||
global_asm!(include_str!("vectors.S"));
|
||||
|
||||
/// Errors possibly returned from the traps module.
|
||||
#[derive(Debug, Snafu)]
|
||||
pub enum Error {
|
||||
/// IVT address is unaligned.
|
||||
#[snafu(display("Unaligned base address for interrupt vector table"))]
|
||||
Unaligned,
|
||||
}
|
||||
|
||||
/// Configure base address of interrupt vectors table.
|
||||
/// Checks that address is properly 2KiB aligned.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// Totally unsafe in the land of the hardware.
|
||||
pub unsafe fn set_vbar_el1_checked(vec_base_addr: u64) -> Result<(), ()> {
|
||||
pub unsafe fn set_vbar_el1_checked(vec_base_addr: u64) -> Result<(), Error> {
|
||||
if vec_base_addr.trailing_zeros() < 11 {
|
||||
return Err(());
|
||||
return Err(Error::Unaligned);
|
||||
}
|
||||
|
||||
VBAR_EL1.set(vec_base_addr);
|
||||
|
|
Loading…
Reference in New Issue