fix: gate AVX enable on XSAVE support and set CR4.OSXSAVE first
continuous-integration/drone/push Build is failing
continuous-integration/drone/push Build is failing
XGETBV/XSETBV require CR4 bit 18 (OSXSAVE) to be set before execution, otherwise the CPU raises #UD (invalid opcode). Hyper-V enforces this strictly; VirtualBox was silently tolerating it. - Check both AVX and XSAVE CPUID flags before attempting AVX enable - Set CR4.OSXSAVE (bit 18) before issuing XGETBV/XSETBV - If XSAVE is not exposed by the hypervisor, AVX enable is skipped gracefully instead of faulting
This commit is contained in:
+8
-1
@@ -293,7 +293,14 @@ end;
|
||||
|
||||
procedure enableAVX();
|
||||
begin
|
||||
if CPUID.Capabilities1^.AVX then begin
|
||||
if CPUID.Capabilities1^.AVX and CPUID.Capabilities1^.XSAVE then begin
|
||||
{ Enable OSXSAVE in CR4 (bit 18) - required before XGETBV/XSETBV }
|
||||
asm
|
||||
MOV EAX, CR4
|
||||
OR EAX, (1 shl 18)
|
||||
MOV CR4, EAX
|
||||
end;
|
||||
{ Set XCR0 bits: x87 (0) + SSE (1) + AVX (2) }
|
||||
asm
|
||||
PUSH EAX
|
||||
PUSH ECX
|
||||
|
||||
Reference in New Issue
Block a user