Add long mode checks
diff --git a/qloader2.bin b/qloader2.bin
index 5269c3fe..a1ea8530 100644
Binary files a/qloader2.bin and b/qloader2.bin differ
diff --git a/src/bootsect/bootsect.asm b/src/bootsect/bootsect.asm
index 641bff89..9cde36a2 100644
--- a/src/bootsect/bootsect.asm
+++ b/src/bootsect/bootsect.asm
@@ -51,7 +51,7 @@ halt:
; Data
-LoadingMsg db 0x0D, 0x0A, '<qLoader 2>', 0x0D, 0x0A, 0x0A, 0x00
+LoadingMsg db 0x0D, 0x0A, '<qloader2>', 0x0D, 0x0A, 0x0A, 0x00
Stage2Msg db 'stage1: Loading stage2...', 0x00
ErrReadDiskMsg db 0x0D, 0x0A, 'Error reading disk, system halted.', 0x00
ErrEnableA20Msg db 0x0D, 0x0A, 'Error enabling a20, system halted.', 0x00
diff --git a/src/lib/blib.c b/src/lib/blib.c
index 6774787b..3d0c7678 100644
--- a/src/lib/blib.c
+++ b/src/lib/blib.c
@@ -8,6 +8,21 @@
#include <lib/real.h>
#include <lib/cio.h>
+int cpuid(uint32_t leaf, uint32_t subleaf,
+ uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) {
+ uint32_t cpuid_max;
+ asm volatile ("cpuid"
+ : "=a" (cpuid_max)
+ : "a" (leaf & 0x80000000)
+ : "rbx", "rcx", "rdx");
+ if (leaf > cpuid_max)
+ return 1;
+ asm volatile ("cpuid"
+ : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
+ : "a" (leaf), "c" (subleaf));
+ return 0;
+}
+
__attribute__((noreturn)) void panic(const char *str) {
print("PANIC: %s", str);
for (;;) {
diff --git a/src/lib/blib.h b/src/lib/blib.h
index 9cc1a4de..781366aa 100644
--- a/src/lib/blib.h
+++ b/src/lib/blib.h
@@ -4,6 +4,9 @@
#include <stddef.h>
#include <stdint.h>
+int cpuid(uint32_t leaf, uint32_t subleaf,
+ uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
+
__attribute__((noreturn)) void panic(const char *str);
void pit_sleep(uint64_t pit_ticks);
diff --git a/src/protos/stivale.c b/src/protos/stivale.c
index 13a6800d..2fa9bcf6 100644
--- a/src/protos/stivale.c
+++ b/src/protos/stivale.c
@@ -52,13 +52,21 @@ void stivale_load(struct file_handle *fd, char *cmdline) {
switch (bits) {
case 64:
+ // Check if 64 bit CPU
+ {
+ uint32_t eax, ebx, ecx, edx;
+ cpuid(0x80000001, 0, &eax, &ebx, &ecx, &edx);
+ if (!(edx & (1 << 29))) {
+ panic("stivale: This CPU does not support 64-bit mode.");
+ }
+ }
ret = elf64_load_section(fd, &stivale_hdr, ".stivalehdr", sizeof(struct stivale_header));
break;
case 32:
ret = elf32_load_section(fd, &stivale_hdr, ".stivalehdr", sizeof(struct stivale_header));
break;
default:
- panic("Not 32 nor 64 bit x86 ELF file.");
+ panic("stivale: Not 32 nor 64 bit x86 ELF file.");
}
print("stivale: %u-bit ELF file detected\n", bits);
