From 458ac9bbbae573151bfccb1621b6c0af30c2068f Mon Sep 17 00:00:00 2001 From: Liav A Date: Sat, 3 Jul 2021 19:17:22 +0300 Subject: [PATCH] Kernel/x86_64: Halt if we happen to boot on non-x86_64 machine --- Kernel/Arch/x86/x86_64/Boot/boot.S | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Kernel/Arch/x86/x86_64/Boot/boot.S b/Kernel/Arch/x86/x86_64/Boot/boot.S index 03808dfe95..e4130f3786 100644 --- a/Kernel/Arch/x86/x86_64/Boot/boot.S +++ b/Kernel/Arch/x86/x86_64/Boot/boot.S @@ -101,6 +101,23 @@ start: cli cld + /* test for long mode presence, save the most important registers from corruption */ + pushl %eax + pushl %edx + pushl %ebx + + movl $0x80000001, %eax + cpuid + testl $(1 << 29), %edx /* Test if the LM-bit, which is bit 29, is set in the edx register. */ + jnz continue /* If LM-bit is not enabled, there is no long mode. */ + hlt + +continue: + /* restore the pushed registers */ + popl %ebx + popl %edx + popl %eax + /* We don't know where the bootloader might have put the command line. * It might be at an inconvenient location that we're not about to map, * so let's just copy it to a convenient location while we have the whole