I created a new thread using PsCreateSystemThread to avoid the complications of performing floating-point operations in the main kernel context.
Managed the floating-point environment manually, saving and restoring state using MASM instructions, like this:
stmxcsr dword ptr [rsp - 54h]
ldmxcsr dword ptr gs:[180h]
movaps [rsp - 10h], xmm0
movaps [rsp + 0h], xmm1
movaps [rsp + 10h], xmm2
The thread executes floating-point operations.
The Problem:
Despite the setup, the results are inconsistent or erroneous. It seems like the floating-point state isn’t being managed properly, or there’s interference with other parts of the kernel.
Is there a specific way to correctly set up the floating-point environment in a kernel thread?
Are there pitfalls I need to watch out for when using PsCreateSystemThread for this purpose?
Should I be using MMX/SSE or other registers differently to ensure correctness?