Skip to content

Commit

Permalink
remove inline assembly + don't set reserved bits (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Freax13 authored Apr 15, 2020
1 parent 07a8c22 commit 84a7a45
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/sse.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
/// Enables Streaming SIMD Extensions (SSE) support for loaded kernels.
pub fn enable_sse() {
use bit_field::BitField;
use x86_64::registers::control::Cr0;
let mut flags = Cr0::read_raw();
flags.set_bit(2, false);
flags.set_bit(1, true);
flags.set_bit(9, true);
flags.set_bit(10, true);
use x86_64::registers::control::{Cr0, Cr0Flags, Cr4, Cr4Flags};
let mut flags = Cr0::read();
flags.remove(Cr0Flags::EMULATE_COPROCESSOR);
flags.insert(Cr0Flags::MONITOR_COPROCESSOR);
unsafe {
Cr0::write_raw(flags);
Cr0::write(flags);
}
// For now, we must use inline ASM here
let mut cr4: u64;

let mut flags = Cr4::read();
flags.insert(Cr4Flags::OSFXSR);
flags.insert(Cr4Flags::OSXMMEXCPT_ENABLE);
unsafe {
asm!("mov %cr4, $0" : "=r" (cr4));
}
cr4.set_bit(9, true);
cr4.set_bit(10, true);
unsafe {
asm!("mov $0, %cr4" :: "r" (cr4) : "memory");
Cr4::write(flags);
}
}

0 comments on commit 84a7a45

Please sign in to comment.