diff options
Diffstat (limited to 'third_party/rust/redox_syscall/src/io/mmio.rs')
-rw-r--r-- | third_party/rust/redox_syscall/src/io/mmio.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/third_party/rust/redox_syscall/src/io/mmio.rs b/third_party/rust/redox_syscall/src/io/mmio.rs new file mode 100644 index 0000000000..b8e7727d3c --- /dev/null +++ b/third_party/rust/redox_syscall/src/io/mmio.rs @@ -0,0 +1,31 @@ +use core::ptr::{read_volatile, write_volatile}; +use core::mem::uninitialized; +use core::ops::{BitAnd, BitOr, Not}; + +use super::io::Io; + +#[repr(packed)] +pub struct Mmio<T> { + value: T, +} + +impl<T> Mmio<T> { + /// Create a new Mmio without initializing + pub fn new() -> Self { + Mmio { + value: unsafe { uninitialized() } + } + } +} + +impl<T> Io for Mmio<T> where T: Copy + PartialEq + BitAnd<Output = T> + BitOr<Output = T> + Not<Output = T> { + type Value = T; + + fn read(&self) -> T { + unsafe { read_volatile(&self.value) } + } + + fn write(&mut self, value: T) { + unsafe { write_volatile(&mut self.value, value) }; + } +} |