Check for CMOV support on boot

This commit is contained in:
Lucia Ceionia 2023-02-08 11:38:35 -06:00
parent 6a4c1908bb
commit 7799813a30
2 changed files with 14 additions and 1 deletions

View File

@ -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 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 %.o: %.nasm
nasm -f elf32 -o $@ $< nasm -f elf32 -o $@ $<

View File

@ -23,6 +23,11 @@ char check_sse() {
asm("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(1)); asm("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(1));
return (edx & (1 << 25)) != 0; 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() { void enable_sse() {
asm volatile( asm volatile(
@ -308,6 +313,14 @@ void start() {
// DL *should* be preserved // DL *should* be preserved
uint8_t dl; uint8_t dl;
asm volatile("nop":"=d"(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 += printByte(dl, vga_text);
vga_text++; vga_text++;