Does QEMU support SSE out-of-the-box?
Posted: Sat Aug 24, 2024 7:53 am
I was rewriting my ISR handler to dump the SIMD/SSE registers. I read on the x86 registers page that
However, this does not print out "XCR0 can be accessed" there. I try and enable SSE via:
Interestingly, when run with no flags, QEMU actually just halts, implying SSE is not supported (by default). I look at the qemu -cpu command, and I see:
So I run qemu via (since -cpu host wasn't allowed without KVM/HVF)
And it still hangs! What's the deal? How do I test SSE in QEMU?
So, I check if bit 18 of cr4 is enabled:XCR0 can only be accessed if bit 18 of CR4 is set to 1. XGETBV and XSETBV instructions are used to access XCR0.
Code: Select all
uint32_t cr0 = 0;
asm ("movl %%cr4, %0;" : "=r" (cr4) ::);
if((cr4 & (1 << 18)) == 1){
printf("XCR0 can be accessed.\n");
}
- Checking if SSE is enable from CPUID
- Enabling it (from what the OSDev wiki says)
Code: Select all
check_sse:
mov $0x1, %eax
cpuid
test $1<<25, %edx
jz .NoSSE
ret
.NoSSE:
cli
2: hlt
jmp 2b
enable_sse:
# Check if SSE is supported
call check_sse
mov %cr0, %eax
and $0xfffb, %ax
or $0x2, %ax
mov %eax, %cr0
mov %cr4, %eax
or $0x600, %eax
mov %eax, %cr4
ret
_start:
mov $stack_top, %esp
call enable_sse
...
Code: Select all
x86 base base CPU model type with no features enabled
x86 host processor with all supported host features
x86 max Enables all features supported by the accelerator in the current host
Code: Select all
qemu-system-i386 -enable-kvm -cpu max -cdrom myos.iso