diff --git a/src/asm/ram64.s b/src/asm/ram64.s index 0dc81b46..0e94f98a 100644 --- a/src/asm/ram64.s +++ b/src/asm/ram64.s @@ -8,17 +8,6 @@ ram64_start: movb $'L', %al outb %al, %dx - # Enable SSE2 for XMM registers (needed for EFI calling) - # Clear CR0.EM and Set CR0.MP - movq %cr0, %rax - andb $0b11111011, %al # Clear bit 2 - orb $0b00000010, %al # Set bit 1 - movq %rax, %cr0 - # Set CR4.OSFXSR and CR4.OSXMMEXCPT - movq %cr4, %rax - orb $0b00000110, %ah # Set bits 9 and 10 - movq %rax, %cr4 - # Setup the stack (at the end of our RAM region) movq $ram_max, %rsp diff --git a/src/main.rs b/src/main.rs index 78f7a86c..b4a2e185 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,10 @@ use core::panic::PanicInfo; -use x86_64::instructions::hlt; +use x86_64::{ + instructions::hlt, + registers::control::{Cr0, Cr0Flags, Cr4, Cr4Flags}, +}; #[macro_use] mod serial; @@ -83,6 +86,18 @@ fn setup_pagetables() { log!("Page tables setup"); } +// Enable SSE2 for XMM registers (needed for EFI calling) +fn enable_sse() { + let mut cr0 = Cr0::read(); + cr0.remove(Cr0Flags::EMULATE_COPROCESSOR); + cr0.insert(Cr0Flags::MONITOR_COPROCESSOR); + unsafe { Cr0::write(cr0) }; + let mut cr4 = Cr4::read(); + cr4.insert(Cr4Flags::OSFXSR); + cr4.insert(Cr4Flags::OSXMMEXCPT_ENABLE); + unsafe { Cr4::write(cr4) }; +} + const VIRTIO_PCI_VENDOR_ID: u16 = 0x1af4; const VIRTIO_PCI_BLOCK_DEVICE_ID: u16 = 0x1042; @@ -166,6 +181,7 @@ fn boot_from_device(device: &mut block::VirtioBlockDevice) -> bool { #[cfg_attr(not(test), no_mangle)] pub extern "C" fn rust64_start() -> ! { log!("\nStarting.."); + enable_sse(); setup_pagetables(); pci::print_bus();