Skip to content

Commit 130eb1a

Browse files
committed
x86: Detect and enable XSAVE and AVX properly and separately
1 parent 24289e4 commit 130eb1a

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/arch/x86/start.asm

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern kernel_start
2020
global _start
2121
global __xsave_enabled
2222
global __avx_enabled
23+
global __ecx_was
2324

2425
%define MB_MAGIC 0x1BADB002
2526
%define MB_FLAGS 0x3 ;; ALIGN + MEMINFO
@@ -77,8 +78,10 @@ rock_bottom:
7778

7879
;; enable SSE before we enter C/C++ land
7980
call enable_sse
81+
;; try to enable XSAVE before checking AVX
82+
call enable_xsave
8083
;; enable AVX if xsave and avx supported on CPU
81-
;call enable_avx
84+
call enable_avx
8285

8386
;; Place multiboot parameters on stack
8487
push ebx
@@ -99,11 +102,24 @@ enable_sse:
99102
ret
100103

101104
enable_xsave:
105+
push eax
106+
push ebx
107+
; check for XSAVE support
108+
mov eax, 1
109+
xor ecx, ecx
110+
cpuid
111+
; bit 26 ecx
112+
and ecx, 0x04000000
113+
cmp ecx, 0x04000000
114+
jne xsave_not_supported
102115
; enable XSAVE
103116
mov eax, cr4
104117
or eax, 0x40000
105118
mov cr4, eax
106119
mov WORD [__xsave_enabled], 0x1
120+
xsave_not_supported:
121+
pop ebx
122+
pop eax
107123
ret
108124

109125
enable_avx:
@@ -117,8 +133,6 @@ enable_avx:
117133
and ecx, 0x18000000
118134
cmp ecx, 0x18000000
119135
jne avx_not_supported
120-
;; enable XSAVE
121-
call enable_xsave
122136
;; enable AVX support
123137
xor ecx, ecx
124138
xgetbv

0 commit comments

Comments
 (0)