From f857bd1d4f12316bd3434192d41c2489407c11a4 Mon Sep 17 00:00:00 2001 From: Tianhao Wang Date: Thu, 1 Feb 2024 22:01:25 +0100 Subject: add IOPort struct So that device IO can be be synchronized. --- src/machine/device_io.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/machine/device_io.rs') diff --git a/src/machine/device_io.rs b/src/machine/device_io.rs index 4573653..2a0c907 100644 --- a/src/machine/device_io.rs +++ b/src/machine/device_io.rs @@ -1,2 +1,22 @@ #[cfg(target_arch = "x86_64")] pub use crate::arch::x86_64::io_port::*; + +// either use the io functions directly, or via a IOPort instance. +pub struct IOPort(u16); +impl IOPort { + pub fn new(port: u16) -> Self { + Self(port) + } + pub fn inw(&self) -> u16 { + inw(self.0) + } + pub fn inb(&self) -> u8 { + inb(self.0) + } + pub fn outw(&self, val: u16) { + outw(self.0, val); + } + pub fn outb(&self, val: u8) { + outb(self.0, val); + } +} -- cgit v1.2.3-70-g09d2