diff options
| author | Tianhao Wang <wth@riseup.net> | 2024-02-01 22:01:25 +0100 |
|---|---|---|
| committer | Tianhao Wang <shrik3@mailbox.org> | 2024-06-11 15:13:38 +0200 |
| commit | f857bd1d4f12316bd3434192d41c2489407c11a4 (patch) | |
| tree | 7ccedde31f7c403f6afbda7cd547e7af20145ef6 /src/machine/device_io.rs | |
| parent | 0ebc5ab0ee0fc80c801487f534687c8bd236abc1 (diff) | |
add IOPort struct
So that device IO can be be synchronized.
Diffstat (limited to 'src/machine/device_io.rs')
| -rw-r--r-- | src/machine/device_io.rs | 20 |
1 files changed, 20 insertions, 0 deletions
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); + } +} |
