diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/redox_syscall/src/io/mmio.rs | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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) }; + } +} |