mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Update blog to d57657ac29
This commit is contained in:
@@ -99,19 +99,37 @@ We compare the value in `eax` with the magic value and jump to the label `no_mul
|
|||||||
|
|
||||||
```nasm
|
```nasm
|
||||||
check_cpuid:
|
check_cpuid:
|
||||||
pushfd ; Store the FLAGS-register.
|
; Check if CPUID is supported by attempting to flip the ID bit (bit 21) in
|
||||||
pop eax ; Restore the A-register.
|
; the FLAGS register. If we can flip it, CPUID is available.
|
||||||
mov ecx, eax ; Set the C-register to the A-register.
|
|
||||||
xor eax, 1 << 21 ; Flip the ID-bit, which is bit 21.
|
; Copy FLAGS in to EAX via stack
|
||||||
push eax ; Store the A-register.
|
pushfd
|
||||||
popfd ; Restore the FLAGS-register.
|
pop eax
|
||||||
pushfd ; Store the FLAGS-register.
|
|
||||||
pop eax ; Restore the A-register.
|
; Copy to ECX as well for comparing later on
|
||||||
push ecx ; Store the C-register.
|
mov ecx, eax
|
||||||
popfd ; Restore the FLAGS-register.
|
|
||||||
xor eax, ecx ; Do a XOR-operation on the A-register and the C-register.
|
; Flip the ID bit
|
||||||
jz .no_cpuid ; The zero flag is set, no CPUID.
|
xor eax, 1 << 21
|
||||||
ret ; CPUID is available for use.
|
|
||||||
|
; 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:
|
.no_cpuid:
|
||||||
mov al, "1"
|
mov al, "1"
|
||||||
jmp error
|
jmp error
|
||||||
|
|||||||
Reference in New Issue
Block a user