diff --git a/src/arch/x86_64/long_mode_init.asm b/src/arch/x86_64/long_mode_init.asm index 4640c0b1..6e4c281e 100644 --- a/src/arch/x86_64/long_mode_init.asm +++ b/src/arch/x86_64/long_mode_init.asm @@ -18,6 +18,7 @@ extern main section .text bits 64 long_mode_start: + call setup_SSE ; call rust main call main @@ -26,6 +27,28 @@ long_mode_start: mov qword [0xb8000], rax hlt +; Check for SSE and enable it. If it's not supported throw error "a". +setup_SSE: + ; check for SSE + mov rax, 0x1 + cpuid + test edx, 1<<25 + jz .no_SSE + + ; enable SSE + mov rax, cr0 + and ax, 0xFFFB ; clear coprocessor emulation CR0.EM + or ax, 0x2 ; set coprocessor monitoring CR0.MP + mov cr0, rax + mov rax, cr4 + or ax, 3 << 9 ; set CR4.OSFXSR and CR4.OSXMMEXCPT at the same time + mov cr4, rax + + ret +.no_SSE: + mov al, "a" + jmp error + ; Prints `ERROR: ` and the given error code to screen and hangs. ; parameter: error code (in ascii) in al error: @@ -35,3 +58,4 @@ error: mov [0xb8008], rbx mov byte [0xb800e], al hlt + jmp error