0

I have been working on making an x86_64 long mode operating system and I came across a bug that confuses me. My goal is to be able to initialize and use floating point variables in the kernel which is written in c++. I expected it to work much the same as initializing a char, int, or long. All of which work. However it instead causes the cpu to reboot. I have tried adding floating point variables to a previous program that uses GRUB to boot into the kernel (in protected mode), and they worked there. I have tried to research this issue, but have found nothing but dead ends talking about division by zero exceptions. The entire code for the boot loader and the very beginnings of the kernel can be found on Github. The issue occurs when when I add a line that initializes a floating point number anywhere in the code that is executed. Ex. changing

extern "C" void kmain(){
    clrscr(7);
    set(10, 10, 0);
    for(;;);
} 

to

extern "C" void kmain(){
    float test = 8;
    clrscr(7);
    set(10, 10, 0);
    for(;;);
}
  • 1
    Have you enabled SSE instructions before running this code? In 16 and 32 bit mode, the compiler uses x87 instructions which do not need to be enabled manually. – fuz Nov 27 '20 at 22:45
  • 1
    https://wiki.osdev.org/SSE – Michael Petch Nov 27 '20 at 23:05
  • 1
    You do know that if your kernel uses floating point, you're going to have to fix your kernel entry and exit code to save and restore all the floating point / xmm registers on every system call? This is fairly expensive and is the reason most kernels simply choose to avoid the use of floating point altogether, except for special situations where the save/restore overhead is really worth the cost. – Nate Eldredge Nov 28 '20 at 02:52

0 Answers0