summaryrefslogtreecommitdiffstats
path: root/vendor/redox_syscall/src/io
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/redox_syscall/src/io')
-rw-r--r--vendor/redox_syscall/src/io/mmio.rs129
1 files changed, 126 insertions, 3 deletions
diff --git a/vendor/redox_syscall/src/io/mmio.rs b/vendor/redox_syscall/src/io/mmio.rs
index 3966ab454..ef8f60391 100644
--- a/vendor/redox_syscall/src/io/mmio.rs
+++ b/vendor/redox_syscall/src/io/mmio.rs
@@ -1,5 +1,6 @@
-use core::ptr::{read_volatile, write_volatile, addr_of, addr_of_mut};
use core::mem::MaybeUninit;
+use core::ptr;
+#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
use core::ops::{BitAnd, BitOr, Not};
use super::io::Io;
@@ -32,14 +33,136 @@ impl<T> Mmio<T> {
}
}
+// Generic implementation (WARNING: requires aligned pointers!)
+#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
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(addr_of!(self.value).cast::<T>()) }
+ unsafe { ptr::read_volatile(ptr::addr_of!(self.value).cast::<T>()) }
}
fn write(&mut self, value: T) {
- unsafe { write_volatile(addr_of_mut!(self.value).cast::<T>(), value) };
+ unsafe { ptr::write_volatile(ptr::addr_of_mut!(self.value).cast::<T>(), value) };
+ }
+}
+
+// x86 u8 implementation
+#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
+impl Io for Mmio<u8> {
+ type Value = u8;
+
+ fn read(&self) -> Self::Value {
+ unsafe {
+ let value: Self::Value;
+ let ptr: *const Self::Value = ptr::addr_of!(self.value).cast::<Self::Value>();
+ core::arch::asm!(
+ "mov {}, [{}]",
+ out(reg_byte) value,
+ in(reg) ptr
+ );
+ value
+ }
+ }
+
+ fn write(&mut self, value: Self::Value) {
+ unsafe {
+ let ptr: *mut Self::Value = ptr::addr_of_mut!(self.value).cast::<Self::Value>();
+ core::arch::asm!(
+ "mov [{}], {}",
+ in(reg) ptr,
+ in(reg_byte) value,
+ );
+ }
+ }
+}
+
+// x86 u16 implementation
+#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
+impl Io for Mmio<u16> {
+ type Value = u16;
+
+ fn read(&self) -> Self::Value {
+ unsafe {
+ let value: Self::Value;
+ let ptr: *const Self::Value = ptr::addr_of!(self.value).cast::<Self::Value>();
+ core::arch::asm!(
+ "mov {:x}, [{}]",
+ out(reg) value,
+ in(reg) ptr
+ );
+ value
+ }
+ }
+
+ fn write(&mut self, value: Self::Value) {
+ unsafe {
+ let ptr: *mut Self::Value = ptr::addr_of_mut!(self.value).cast::<Self::Value>();
+ core::arch::asm!(
+ "mov [{}], {:x}",
+ in(reg) ptr,
+ in(reg) value,
+ );
+ }
+ }
+}
+
+// x86 u32 implementation
+#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
+impl Io for Mmio<u32> {
+ type Value = u32;
+
+ fn read(&self) -> Self::Value {
+ unsafe {
+ let value: Self::Value;
+ let ptr: *const Self::Value = ptr::addr_of!(self.value).cast::<Self::Value>();
+ core::arch::asm!(
+ "mov {:e}, [{}]",
+ out(reg) value,
+ in(reg) ptr
+ );
+ value
+ }
+ }
+
+ fn write(&mut self, value: Self::Value) {
+ unsafe {
+ let ptr: *mut Self::Value = ptr::addr_of_mut!(self.value).cast::<Self::Value>();
+ core::arch::asm!(
+ "mov [{}], {:e}",
+ in(reg) ptr,
+ in(reg) value,
+ );
+ }
+ }
+}
+
+// x86 u64 implementation (x86_64 only)
+#[cfg(target_arch = "x86_64")]
+impl Io for Mmio<u64> {
+ type Value = u64;
+
+ fn read(&self) -> Self::Value {
+ unsafe {
+ let value: Self::Value;
+ let ptr: *const Self::Value = ptr::addr_of!(self.value).cast::<Self::Value>();
+ core::arch::asm!(
+ "mov {:r}, [{}]",
+ out(reg) value,
+ in(reg) ptr
+ );
+ value
+ }
+ }
+
+ fn write(&mut self, value: Self::Value) {
+ unsafe {
+ let ptr: *mut Self::Value = ptr::addr_of_mut!(self.value).cast::<Self::Value>();
+ core::arch::asm!(
+ "mov [{}], {:r}",
+ in(reg) ptr,
+ in(reg) value,
+ );
+ }
}
}