xyris
xyris copied to clipboard
Use FXSAVE Instruction when Switching Tasks
Our kernel uses SSE which means that the xmm
registers and probably other registers as well could be used my multiple kernel tasks. Currently we don't save those registers during context switches which means that our kernel is a time bomb and at any moment the compiler could generate SSE instructions and detonate it. We really should fix that.
The OSDev Wiki provides a nice snippet we could integrate into our tasks struct that would allow us to save and restore the registers on a task-by-task basis.
char fxsave_region[512] __attribute__((aligned(16)));
asm volatile(" fxsave; "::"m"(fxsave_region));
https://wiki.osdev.org/SSE#FXSAVE_and_FXRSTOR
GCC provides functions that can do this for us, so we should look into using those instead of inline assembly.