Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable AVX is supported by CPU #73

Merged
merged 3 commits into from
Sep 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/init/cpu.asm
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ init_cpu:
; Enable Math Co-processor
finit

; Enable AVX
mov eax, 1 ; CPUID Feature information 1
cpuid ; Sets info in eax and ecx
bt ecx, 28 ; AVX is supported if bit 28 is set in ecx
jnc avx_not_supported ; Skip activating AVX if not supported

avx_supported:

mov rax, cr4
bts rax, 18 ; Enable OSXSAVE (Bit 18)
mov cr4, rax

mov rcx, 0 ; Set load XCR Nr. 0
xgetbv ; Load XCR0 register
bts rax, 0 ; Set X87 enable (Bit 0)
bts rax, 1 ; Set SSE enable (Bit 1)
bts rax, 2 ; Set AVX enable (Bit 2)
xsetbv ; Save XCR0 register
avx_not_supported:

; Enable and Configure Local APIC
mov rsi, [os_LocalAPICAddress]
test rsi, rsi
Expand Down