This commit is contained in:
janis 2026-07-17 16:23:22 +02:00
parent 5c872bfca0
commit 316ef9bfc0
Signed by: janis
SSH key fingerprint: SHA256:bB1qbbqmDXZNT0KKD5c2Dfjg53JGhj7B3CFcLIzSqq8

View file

@ -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)
);
}
}
}