Check if long mode is available

This commit is contained in:
Thomas Lovén 2017-11-03 21:06:09 +01:00
parent a9328d6b67
commit dd565454e3
2 changed files with 55 additions and 1 deletions

View File

@ -7,4 +7,9 @@ SECTIONS
*(.multiboot) *(.multiboot)
*(.text) *(.text)
} }
.data :
{
*(.data)
}
} }

View File

@ -1,9 +1,58 @@
.intel_syntax noprefix .intel_syntax noprefix
.section .data
check_cpuid_stack_top:
.long 0
.long 0
.long 0
check_cpuid_stack:
nop
.section .text .section .text
.global _start
.code32 .code32
error:
// Print "ERR!" in upper left corner
mov [0xb8000], dword ptr 0x4f524f45
mov [0xb8004], dword ptr 0x4f214f52
jmp $
check_cpuid:
mov check_cpuid_stack, esp
pushfd
pushfd
xor dword ptr[esp], 1<<21
popfd
pushfd
pop eax
xor eax, [esp]
popfd
and eax, 1<<21
jz error
ret
check_longmode:
// cpuid 0x8000 0000
mov eax, 0x80000000
cpuid
cmp eax, 0x80000001
jb error
// cpuid 0x8000 0001
mov eax, 0x80000001
cpuid
// Test for long mode flag
test edx, 1<<29
jz error
ret
.global _start
_start: _start:
cli cli
call check_cpuid
call check_longmode
jmp $ jmp $