bits 32 section .text F_ID equ 0x200000 global read_cpuid_ read_cpuid_: ; determine if cpuid is available pushf pop eax mov edx, eax ; keep a copy of the original eflags in edx xor eax, F_ID push eax popf pushf pop eax cmp edx, eax jnz .havecpuid ; failed to flip ID bit, CPUID not supported mov eax, -1 ret .havecpuid: push ebp mov ebp, esp push ebx push edi sub esp, 8 mov edi, [ebp + 8] xor eax, eax mov [esp], eax ; current index cpuid mov [edi], eax ; clamp to the size of our cpuid_info structure cmp eax, 1 jbe .skipclamp mov eax, 1 mov [esp + 4], eax ; maximum index .skipclamp: mov [edi + 4], ebx mov [edi + 8], edx mov [edi + 12], ecx add edi, 16 cpuid_loop: mov eax, [esp] inc eax cmp eax, [esp + 4] ja cpuid_done mov [esp], eax cpuid mov [edi], eax mov [edi + 4], ebx mov [edi + 8], edx mov [edi + 12], ecx add edi, 16 jmp cpuid_loop cpuid_done: add esp, 8 pop edi pop ebx pop ebp xor eax, eax ret