xyris icon indicating copy to clipboard operation
xyris copied to clipboard

Use FXSAVE Instruction when Switching Tasks

Open Kfeavel opened this issue 3 years ago • 3 comments

Kfeavel avatar Jul 02 '21 01:07 Kfeavel

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.

micahswitzer avatar Jul 02 '21 11:07 micahswitzer

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

Kfeavel avatar Jul 02 '21 21:07 Kfeavel

GCC provides functions that can do this for us, so we should look into using those instead of inline assembly.

Kfeavel avatar Sep 12 '21 20:09 Kfeavel