aboutsummaryrefslogtreecommitdiff
path: root/src/msr.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/msr.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/msr.rs')
-rw-r--r--src/msr.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/msr.rs b/src/msr.rs
index 643e54b..445e6cc 100644
--- a/src/msr.rs
+++ b/src/msr.rs
@@ -1,8 +1,10 @@
+//! MSR value list and function to read and write them.
+
/// Write 64 bits to msr register.
pub unsafe fn wrmsr(msr: u32, value: u64) {
let low = value as u32;
let high = (value >> 32) as u32;
- asm!("wrmsr" :: "{ecx}" (msr), "{eax}" (low), "{edx}" (high) );
+ asm!("wrmsr" :: "{ecx}" (msr), "{eax}" (low), "{edx}" (high) : "memory" : "volatile" );
}
/// Read 64 bits msr register.
@@ -10,7 +12,7 @@ pub unsafe fn wrmsr(msr: u32, value: u64) {
pub unsafe fn rdmsr(msr: u32) -> u64 {
let mut low: u32;
let mut high: u32;
- asm!("rdmsr" : "={eax}" (low), "={edx}" (high) : "{ecx}" (msr));
+ asm!("rdmsr" : "={eax}" (low), "={edx}" (high) : "{ecx}" (msr) : "memory" : "volatile");
((high as u64) << 32) | (low as u64)
}