aboutsummaryrefslogtreecommitdiff
path: root/src/controlregs.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/controlregs.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/controlregs.rs')
-rw-r--r--src/controlregs.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/controlregs.rs b/src/controlregs.rs
index 89242c2..b6cd334 100644
--- a/src/controlregs.rs
+++ b/src/controlregs.rs
@@ -1,44 +1,45 @@
-/// Contains various flags to control operations.
+//! Functions to read and write control registers.
+
pub unsafe fn cr0() -> u64
{
let ret: u64;
- asm!("mov %cr0, $0" : "=r" (ret) : );
+ asm!("mov %cr0, $0" : "=r" (ret));
ret
}
/// Write cr0.
pub unsafe fn cr0_write(val: u64)
{
- asm!("mov $0, %cr0" :: "r" (val));
+ asm!("mov $0, %cr0" :: "r" (val) : "memory");
}
/// Contains page-fault linear address.
pub unsafe fn cr2() -> u64 {
let ret: u64;
- asm!("mov %cr2, $0" : "=r" (ret) :);
+ asm!("mov %cr2, $0" : "=r" (ret));
ret
}
/// Contains page-table root pointer.
pub unsafe fn cr3() -> u64 {
let ret: u64;
- asm!("mov %cr3, $0" : "=r" (ret) :);
+ asm!("mov %cr3, $0" : "=r" (ret));
ret
}
/// Switch page-table PML4 pointer.
pub unsafe fn cr3_write(val: u64) {
- asm!("mov $0, %cr3" :: "r" (val));
+ asm!("mov $0, %cr3" :: "r" (val) : "memory");
}
/// Contains various flags to control operations in protected mode.
pub unsafe fn cr4() -> u64 {
let ret: u64;
- asm!("mov %cr4, $0" : "=r" (ret) :);
+ asm!("mov %cr4, $0" : "=r" (ret));
ret
}
/// Write cr4.
pub unsafe fn cr4_write(val: u64) {
- asm!("mov $0, %cr4" :: "r" (val));
+ asm!("mov $0, %cr4" :: "r" (val) : "memory");
}