diff options
author | 2016-06-26 22:14:12 -0700 | |
---|---|---|
committer | 2016-06-29 22:48:09 -0700 | |
commit | ecd59a3b130724ea9db16ea8b1b538e108f0dc1b (patch) | |
tree | 1ef55865bbc7e6549053db4ff48c2d3367f83db2 | |
parent | b96c0ee41bdd2e48e56ec6c08e5fe1a79b58f0d0 (diff) | |
download | rust-x86-ecd59a3b130724ea9db16ea8b1b538e108f0dc1b.tar.gz rust-x86-ecd59a3b130724ea9db16ea8b1b538e108f0dc1b.tar.zst rust-x86-ecd59a3b130724ea9db16ea8b1b538e108f0dc1b.zip |
Combine Interface: I/O; libpcu: repeated I/O
-rw-r--r-- | src/bits64/io.rs | 37 | ||||
-rw-r--r-- | src/bits64/mod.rs | 1 | ||||
-rw-r--r-- | src/shared/io.rs | 80 | ||||
-rw-r--r-- | src/shared/mod.rs | 68 |
4 files changed, 81 insertions, 105 deletions
diff --git a/src/bits64/io.rs b/src/bits64/io.rs deleted file mode 100644 index bb7cfb0..0000000 --- a/src/bits64/io.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! I/O port functionality. - -/// Write 8 bits to port -pub unsafe fn outb(port: u16, val: u8) { - asm!("outb %al, %dx" :: "{dx}"(port), "{al}"(val)); -} - -/// Read 8 bits from port -pub unsafe fn inb(port: u16) -> u8 { - let ret: u8; - asm!("inb %dx, %al" : "={ax}"(ret) : "{dx}"(port) :: "volatile"); - return ret; -} - -/// Write 16 bits to port -pub unsafe fn outw(port: u16, val: u16) { - asm!("outw %ax, %dx" :: "{dx}"(port), "{al}"(val)); -} - -/// Read 16 bits from port -pub unsafe fn inw(port: u16) -> u16 { - let ret: u16; - asm!("inw %dx, %ax" : "={ax}"(ret) : "{dx}"(port) :: "volatile"); - return ret; -} - -/// Write 32 bits to port -pub unsafe fn outl(port: u16, val: u32) { - asm!("outl %eax, %dx" :: "{dx}"(port), "{al}"(val)); -} - -/// Read 32 bits from port -pub unsafe fn inl(port: u16) -> u32 { - let ret: u32; - asm!("inl %dx, %eax" : "={ax}"(ret) : "{dx}"(port) :: "volatile"); - return ret; -} diff --git a/src/bits64/mod.rs b/src/bits64/mod.rs index 3ab65e8..2588287 100644 --- a/src/bits64/mod.rs +++ b/src/bits64/mod.rs @@ -30,7 +30,6 @@ macro_rules! check_bit_fn { ) } -pub mod io; pub mod msr; pub mod time; pub mod irq; diff --git a/src/shared/io.rs b/src/shared/io.rs new file mode 100644 index 0000000..16f641c --- /dev/null +++ b/src/shared/io.rs @@ -0,0 +1,80 @@ +//! I/O port functionality. + +/// Write 8 bits to port +pub unsafe fn outb(port: u16, val: u8) { + asm!("outb %al, %dx" :: "{dx}"(port), "{al}"(val)); +} + +/// Read 8 bits from port +pub unsafe fn inb(port: u16) -> u8 { + let ret: u8; + asm!("inb %dx, %al" : "={ax}"(ret) : "{dx}"(port) :: "volatile"); + ret +} + +/// Write 16 bits to port +pub unsafe fn outw(port: u16, val: u16) { + asm!("outw %ax, %dx" :: "{dx}"(port), "{al}"(val)); +} + +/// Read 16 bits from port +pub unsafe fn inw(port: u16) -> u16 { + let ret: u16; + asm!("inw %dx, %ax" : "={ax}"(ret) : "{dx}"(port) :: "volatile"); + ret +} + +/// Write 32 bits to port +pub unsafe fn outl(port: u16, val: u32) { + asm!("outl %eax, %dx" :: "{dx}"(port), "{al}"(val)); +} + +/// Read 32 bits from port +pub unsafe fn inl(port: u16) -> u32 { + let ret: u32; + asm!("inl %dx, %eax" : "={ax}"(ret) : "{dx}"(port) :: "volatile"); + ret +} + + +// Write 8-bit array to port +pub unsafe fn outsb(port: u16, buf: &[u8]) { + asm!("rep outsb (%esi), %dx" + :: "{ecx}"(buf.len()), "{dx}"(port), "{esi}"(buf.as_ptr()) + : "ecx", "edi"); +} + +// Read 8-bit array from port +pub unsafe fn insb(port: u16, buf: &mut [u8]) { + asm!("rep insb %dx, (%edi)" + :: "{ecx}"(buf.len()), "{dx}"(port), "{edi}"(buf.as_ptr()) + : "ecx", "edi" : "volatile"); +} + +// Write 16-bit array to port +pub unsafe fn outsw(port: u16, buf: &[u16]) { + asm!("rep outsw (%esi), %dx" + :: "{ecx}"(buf.len()), "{dx}"(port), "{esi}"(buf.as_ptr()) + : "ecx", "edi"); +} + +// Read 16-bit array from port +pub unsafe fn insw(port: u16, buf: &mut [u16]) { + asm!("rep insw %dx, (%edi)" + :: "{ecx}"(buf.len()), "{dx}"(port), "{edi}"(buf.as_ptr()) + : "ecx", "edi" : "volatile"); +} + +// Write 32-bit array to port +pub unsafe fn outsl(port: u16, buf: &[u32]) { + asm!("rep outsl (%esi), %dx" + :: "{ecx}"(buf.len()), "{dx}"(port), "{esi}"(buf.as_ptr()) + : "ecx", "edi"); +} + +// Read 32-bit array from port +pub unsafe fn insl(port: u16, buf: &mut [u32]) { + asm!("rep insl %dx, (%edi)" + :: "{ecx}"(buf.len()), "{dx}"(port), "{edi}"(buf.as_ptr()) + : "ecx", "edi" : "volatile"); +} diff --git a/src/shared/mod.rs b/src/shared/mod.rs index e9c8084..ad1d23c 100644 --- a/src/shared/mod.rs +++ b/src/shared/mod.rs @@ -1,6 +1,7 @@ #![allow(non_upper_case_globals)] pub mod control_regs; +pub mod io; bitflags! { pub flags Flags: usize { @@ -253,70 +254,3 @@ pub unsafe fn disable_interrupts() { pub unsafe fn halt() { asm!("hlt" :::: "volatile", "intel"); } - -#[inline(always)] -pub unsafe fn out8(port: u16, value: u8) { - asm!("out $0, $1" :: "{dx}"(port), "{al}"(value) :: "volatile", "intel"); -} - -#[inline(always)] -pub unsafe fn out16(port: u16, value: u16) { - asm!("out $0, $1" :: "{dx}"(port), "{ax}"(value) :: "volatile", "intel"); -} - -#[inline(always)] -pub unsafe fn out32(port: u16, value: u32) { - asm!("out $0, $1" :: "{dx}"(port), "{eax}"(value) :: "volatile", "intel"); -} - -#[inline(always)] -pub unsafe fn outs8(port: u16, buf: &[u8]) { - asm!("rep outsb dx, [esi]" :: "{ecx}"(buf.len()), "{dx}"(port), "{esi}"(buf.as_ptr()) : "ecx", "edi" : "intel"); -} - -#[inline(always)] -pub unsafe fn outs16(port: u16, buf: &[u16]) { - asm!("rep outsw dx, [esi]" :: "{ecx}"(buf.len()), "{dx}"(port), "{esi}"(buf.as_ptr()) : "ecx", "edi" : "intel"); -} - -#[inline(always)] -pub unsafe fn outs32(port: u16, buf: &[u32]) { - asm!("rep outsd dx, [esi]" :: "{ecx}"(buf.len()), "{dx}"(port), "{esi}"(buf.as_ptr()) : "ecx", "edi" : "intel"); -} - - -#[inline(always)] -pub unsafe fn in8(port: u16) -> u8 { - let r: u8; - asm!("in $0, $1" : "={al}"(r) : "{dx}"(port) :: "intel"); - r -} - -#[inline(always)] -pub unsafe fn in16(port: u16) -> u16 { - let r: u16; - asm!("in $0, $1" : "={ax}"(r) : "{dx}"(port) :: "intel"); - r -} - -#[inline(always)] -pub unsafe fn in32(port: u16) -> u32 { - let r: u32; - asm!("in $0, $1" : "={eax}"(r) : "{dx}"(port) :: "intel"); - r -} - -#[inline(always)] -pub unsafe fn ins8(port: u16, buf: &mut [u8]) { - asm!("rep insb [edi], dx" :: "{ecx}"(buf.len()), "{dx}"(port), "{edi}"(buf.as_ptr()) : "ecx", "edi" : "intel"); -} - -#[inline(always)] -pub unsafe fn ins16(port: u16, buf: &mut [u16]) { - asm!("rep insw [edi], dx" :: "{ecx}"(buf.len()), "{dx}"(port), "{edi}"(buf.as_ptr()) : "ecx", "edi" : "intel"); -} - -#[inline(always)] -pub unsafe fn ins32(port: u16, buf: &mut [u32]) { - asm!("rep insd [edi], dx" :: "{ecx}"(buf.len()), "{dx}"(port), "{edi}"(buf.as_ptr()) : "ecx", "edi" : "intel"); -} |