first commit
This commit is contained in:
55
src/bootload/longm.asm
Normal file
55
src/bootload/longm.asm
Normal file
@@ -0,0 +1,55 @@
|
||||
; DEPRECATED!
|
||||
|
||||
CPUID_EXTENSIONS equ 0x80000000
|
||||
CPUID_EXT_FEATURES equ 0x80000001
|
||||
EFLAGS_ID equ 1 << 21
|
||||
CPUID_EDX_EXT_FEAT_LM equ 1 << 29
|
||||
|
||||
enterlong:
|
||||
call .queryLongMode
|
||||
|
||||
|
||||
.NoLongMode
|
||||
cli
|
||||
hlt
|
||||
jmp .NoLongMode
|
||||
|
||||
.checkCPUID:
|
||||
pushfd
|
||||
pop eax
|
||||
|
||||
; The original value should be saved for comparison and restoration later
|
||||
mov ecx, eax
|
||||
xor eax, EFLAGS_ID
|
||||
|
||||
; storing the eflags and then retrieving it again will show whether or not
|
||||
; the bit could successfully be flipped
|
||||
push eax ; save to eflags
|
||||
popfd
|
||||
pushfd ; restore from eflags
|
||||
pop eax
|
||||
|
||||
; Restore EFLAGS to its original value
|
||||
push ecx
|
||||
popfd
|
||||
|
||||
; if the bit in eax was successfully flipped (eax != ecx), CPUID is supported.
|
||||
xor eax, ecx
|
||||
jnz .NoLongMode
|
||||
ret
|
||||
|
||||
.queryLongMode:
|
||||
call .checkCPUID
|
||||
|
||||
mov eax, CPUID_EXTENSIONS
|
||||
cpuid
|
||||
cmp eax, CPUID_FEATURES
|
||||
jb .NoLongMode
|
||||
|
||||
mov eax, CPUID_EXT_FEATURES
|
||||
cpuid
|
||||
test edx, CPUID_EDX_EXT_FEAT_LM
|
||||
jz .NoLongMode
|
||||
|
||||
ret
|
||||
|
||||
Reference in New Issue
Block a user