[cfe-dev] Preserve SSE state in interrupt handler

Anatol Pomozov via cfe-dev cfe-dev at lists.llvm.org
Wed Sep 13 13:16:04 PDT 2017


Hello folks

Clang has support for "interrupt" attribute at x86 platform. It is one
of the features needed for os development. And it works great in the
most cases.

There is one thing that I would like to clarify. What if the interrupt
handler uses SSE instructions? It is expected that a handler preserves
exact execution state. And the CPU state includes SSE/FPU as well.

I compiled a handler with SSE using clang 4.0. I see that %xmm
registers are saved to stack one-by-one:

  movaps %xmm0, %(rsp)
  movaps %xmm1, %10(rsp)
  movaps %xmm2, %20(rsp)
.....

But this code does not preserve SSE register state like MXCSR. Without
it the handler might change the SSE state and it will affect task that
was executing during the interrupt handling.

I think the interrupt attribute at x86 should be enhanced:
 * In addition to SSE data register, SSE state registers should be
preserved as well
 * The same rule applied to FPU state if handler uses FPU
 * Instead of iterating all registers would it make sense to use more
convenient FXSAVE instruction ("preserve FPU/SSE state")?

What do you think?



More information about the cfe-dev mailing list