skyesp wrote:
Hi all.
I'm just getting into OSdev with my first attempt, starting out following a youtube tutorial series for the assembly needed to start up. So far I can print text to VGA mode 3. I wanted to get a working system for printing numbers in place in order to be able to debug my IDT implementation but I encountered a perplexing issue: Whenever I attempt to cast from a float to an int in C++, QEMU appears to reset into BIOS.
I am assuming that the reset is due to an unhandled interrupt thanks to said IDT not working yet but I have no idea if that is right or why that would occur.
My toolchain is based off of
https://hub.docker.com/r/randomdude/gcc ... x86_64-elf, which seems to have issues with c++ code in general. Does anyone know how to fix this or which other platform independent c++ compiler to use?
Thanks!
The golden rule in OSDev -- or any low-level code like this (unless you really, really, really need it) is: avoid floating-point at all costs.
This is because floating-point is, by its nature, very complicated. If you absolutely need it (and you will once you get to running actual apps, but since your just starting out you shouldn't need that for a long, long time), you need to enable the
floating-point unit and
SSE. Then, on every interrupt, you need to save and restore both the FPU and SSE registers and state information. Only then will floating-point work.
Edit: I note to save both FPU and SSE state and to enable both because with floating point (from what I know) its not easy to predict exactly what instruction will correspond to a given FP operation in C/C++, and so you really can only either limit your compiler to emit certain instruction sets or enable both and work with both at once.