aboutsummaryrefslogtreecommitdiff
path: root/src/io.rs
diff options
context:
space:
mode:
authorGravatar Gerd Zellweger <mail@gerdzellweger.com> 2015-11-29 12:17:36 +0100
committerGravatar Gerd Zellweger <mail@gerdzellweger.com> 2015-11-29 12:17:36 +0100
commit8ea2eb2dc442e9d0e89e08d40283b1aaba1cc87a (patch)
treeeaa63e77f9386864c26fb87a9f50f4628611abc8 /src/io.rs
parentbec7731473a0fae1d837a8a0fdfc902504ea9fcd (diff)
downloadrust-x86-8ea2eb2dc442e9d0e89e08d40283b1aaba1cc87a.tar.gz
rust-x86-8ea2eb2dc442e9d0e89e08d40283b1aaba1cc87a.tar.zst
rust-x86-8ea2eb2dc442e9d0e89e08d40283b1aaba1cc87a.zip
Fixing volatile and memory attributes for assembly.
For volatile: You can prevent an asm instruction from being deleted by writing the keyword volatile after the asm. [...] The volatile keyword indicates that the instruction has important side-effects. GCC will not delete a volatile asm if it is reachable. and An asm instruction without any output operands will be treated identically to a volatile asm instruction. And for memory: This will cause GCC to not keep memory values cached in registers across the assembler instruction and not optimize stores or loads to that memory. See also: https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Extended-Asm.html http://stackoverflow.com/questions/14449141/the-difference-between-asm-asm-volatile-and-clobbering-memory
Diffstat (limited to 'src/io.rs')
-rw-r--r--src/io.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/io.rs b/src/io.rs
index 0f0e96a..eded102 100644
--- a/src/io.rs
+++ b/src/io.rs
@@ -1,35 +1,37 @@
+//! 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));
+ 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));
+ 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));
+ 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));
+ 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));
+ 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));
+ asm!("inl %dx, %eax" : "={ax}"(ret) : "{dx}"(port) :: "volatile");
return ret;
}