From 7799813a305e34d287896f3fb9e25883c61c3be0 Mon Sep 17 00:00:00 2001 From: Lucia Ceionia Date: Wed, 8 Feb 2023 11:38:35 -0600 Subject: [PATCH] Check for CMOV support on boot --- Makefile | 2 +- kernel.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f94ab84..63efd2a 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ objects = entry.o kernel.o task.o handler.o interrupt.o v86.o print.o tss.o dosfs/dosfs.o gdt.o usermode.o paging.o fault.o tests.o kbd.o helper.o progs.o -CFLAGS = -target "i486-elf" -m32 -mgeneral-regs-only -ffreestanding -march=pentium-m -fno-stack-protector -Wno-int-conversion -nostdlib -c +CFLAGS = -target "i686-elf" -m32 -mgeneral-regs-only -ffreestanding -march=i686 -fno-stack-protector -Wno-int-conversion -nostdlib -c %.o: %.nasm nasm -f elf32 -o $@ $< diff --git a/kernel.c b/kernel.c index ead2cf1..a4f0767 100644 --- a/kernel.c +++ b/kernel.c @@ -23,6 +23,11 @@ char check_sse() { asm("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(1)); return (edx & (1 << 25)) != 0; } +char check_cmov() { + uint32_t eax, ebx, ecx, edx; + asm("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(1)); + return (edx & (1 << 15)) != 0; +} void enable_sse() { asm volatile( @@ -308,6 +313,14 @@ void start() { // DL *should* be preserved uint8_t dl; asm volatile("nop":"=d"(dl)); + + if (!check_cmov()) { + char cmov_err[] = "NO CMOV"; + for (int i = 0; i < sizeof(cmov_err); i++) + *(char *)&vga_text[i] = cmov_err[i]; + for (;;) asm volatile("hlt"); + } + vga_text += printByte(dl, vga_text); vga_text++;