From 6c81a67a65d2f481b5be1886de1da03e3ced6e0b Mon Sep 17 00:00:00 2001 From: travis-update-bot Date: Sat, 2 Jan 2016 15:12:00 +0000 Subject: [PATCH] Update blog to d57657ac2973fcdb9c3dda0bb00eaecda419fa72 --- _posts/2015-08-25-entering-longmode.md | 44 ++++++++++++++++++-------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/_posts/2015-08-25-entering-longmode.md b/_posts/2015-08-25-entering-longmode.md index 8680af6d..ba0e9342 100644 --- a/_posts/2015-08-25-entering-longmode.md +++ b/_posts/2015-08-25-entering-longmode.md @@ -99,19 +99,37 @@ We compare the value in `eax` with the magic value and jump to the label `no_mul ```nasm check_cpuid: - pushfd ; Store the FLAGS-register. - pop eax ; Restore the A-register. - mov ecx, eax ; Set the C-register to the A-register. - xor eax, 1 << 21 ; Flip the ID-bit, which is bit 21. - push eax ; Store the A-register. - popfd ; Restore the FLAGS-register. - pushfd ; Store the FLAGS-register. - pop eax ; Restore the A-register. - push ecx ; Store the C-register. - popfd ; Restore the FLAGS-register. - xor eax, ecx ; Do a XOR-operation on the A-register and the C-register. - jz .no_cpuid ; The zero flag is set, no CPUID. - ret ; CPUID is available for use. + ; Check if CPUID is supported by attempting to flip the ID bit (bit 21) in + ; the FLAGS register. If we can flip it, CPUID is available. + + ; Copy FLAGS in to EAX via stack + pushfd + pop eax + + ; Copy to ECX as well for comparing later on + mov ecx, eax + + ; Flip the ID bit + xor eax, 1 << 21 + + ; Copy EAX to FLAGS via the stack + push eax + popfd + + ; Copy FLAGS back to EAX (with the flipped bit if CPUID is supported) + pushfd + pop eax + + ; Restore FLAGS from the old version stored in ECX (i.e. flipping the ID bit + ; back if it was ever flipped). + push ecx + popfd + + ; Compare EAX and ECX. If they are equal then that means the bit wasn't + ; flipped, and CPUID isn't supported. + xor eax, ecx + jz .no_cpuid + ret .no_cpuid: mov al, "1" jmp error