port
This commit is contained in:
parent
5c872bfca0
commit
316ef9bfc0
|
|
@ -12,3 +12,38 @@ pub fn halt_loop() -> ! {
|
||||||
hlt();
|
hlt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct PortU16(pub u16);
|
||||||
|
|
||||||
|
impl PortU16 {
|
||||||
|
pub fn offset(&self, offset: u16) -> Self {
|
||||||
|
Self(self.0 + offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub unsafe fn read(&self) -> u16 {
|
||||||
|
let value: u16;
|
||||||
|
unsafe {
|
||||||
|
core::arch::asm!(
|
||||||
|
"in ax, dx",
|
||||||
|
in("dx") self.0,
|
||||||
|
out("ax") value,
|
||||||
|
options(nomem, nostack, preserves_flags)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
value
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub unsafe fn write(&self, value: u16) {
|
||||||
|
unsafe {
|
||||||
|
core::arch::asm!(
|
||||||
|
"out dx, ax",
|
||||||
|
in("dx") self.0,
|
||||||
|
in("ax") value,
|
||||||
|
options(nomem, nostack, preserves_flags)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue