assemblyx86simdsseavx

Is there anything more I need to do before using SSE instructions?


I attempted to use an SSE instruction after I enabled the CR4 register bit 18(OSXSAVE) and xsetbv, but it is not working. The CPU has triggered the INT 0x6 interrupt(#UD).

Is it because I didn't do anything else before I use SSE? I don't understand SIMD assembly instructions in system initializing at all.

[bits 32]
    mov eax,00040000h   ;cr4 bit18 osxsave
    mov cr4,eax
    xor edx,edx
    mov ecx,0           ;enable xcr0 sse avx bit
    mov eax,0x7
    xsetbv
    movss xmm0,xmm1     ;example instruction, it's trapped #UD.

Solution

  • If you consult Table 2-22. Type 5 Class Exception Conditions in the IntelĀ® 64 and IA-32 Architectures Software Developer's Manual Volume 2, you will see that #UD is generated "If CR4.OSFXSR[bit 9] = 0". Thus you need to set that bit as well. Use mov eax,00040200h.