1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-30 02:27:38 +01:00

Handle fpu state

This commit is contained in:
Konstantin Belousov 2010-03-06 23:22:46 +02:00
parent 62218e10eb
commit 200147d0f2
3 changed files with 25 additions and 5 deletions

View file

@ -55,12 +55,20 @@ _Ux86_64_getcontext:
movq %rax, UC_MCONTEXT_GREGS_RAX(%rdi) movq %rax, UC_MCONTEXT_GREGS_RAX(%rdi)
movq %rcx, UC_MCONTEXT_GREGS_RCX(%rdi) movq %rcx, UC_MCONTEXT_GREGS_RCX(%rdi)
#if defined __linux__
/* Save fp state (not needed, except for setcontext not /* Save fp state (not needed, except for setcontext not
restoring garbage). */ restoring garbage). */
leaq UC_MCONTEXT_FPREGS_MEM(%rdi),%r8 leaq UC_MCONTEXT_FPREGS_MEM(%rdi),%r8
movq %r8, UC_MCONTEXT_FPREGS_PTR(%rdi) movq %r8, UC_MCONTEXT_FPREGS_PTR(%rdi)
fnstenv (%r8) fnstenv (%r8)
stmxcsr FPREGS_OFFSET_MXCSR(%r8) stmxcsr FPREGS_OFFSET_MXCSR(%r8)
#elif defined __FreeBSD__
fxsave UC_MCONTEXT_FPSTATE(%rdi)
movq $UC_MCONTEXT_FPOWNED_FPU,UC_MCONTEXT_OWNEDFP(%rdi)
movq $UC_MCONTEXT_FPFMT_XMM,UC_MCONTEXT_FPFORMAT(%rdi)
#else
#error Port me
#endif
leaq 8(%rsp), %rax /* exclude this call. */ leaq 8(%rsp), %rax /* exclude this call. */
movq %rax, UC_MCONTEXT_GREGS_RSP(%rdi) movq %rax, UC_MCONTEXT_GREGS_RSP(%rdi)
@ -71,7 +79,5 @@ _Ux86_64_getcontext:
xorq %rax, %rax xorq %rax, %rax
retq retq
#ifdef __linux__
/* We do not need executable stack. */ /* We do not need executable stack. */
.section .note.GNU-stack,"",@progbits .section .note.GNU-stack,"",@progbits
#endif

View file

@ -37,9 +37,20 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
_Ux86_64_setcontext: _Ux86_64_setcontext:
/* restore fp state */ /* restore fp state */
#if defined __linux__
mov UC_MCONTEXT_FPREGS_PTR(%rdi),%r8 mov UC_MCONTEXT_FPREGS_PTR(%rdi),%r8
fldenv (%r8) fldenv (%r8)
ldmxcsr FPREGS_OFFSET_MXCSR(%r8) ldmxcsr FPREGS_OFFSET_MXCSR(%r8)
#elif defined __FreeBSD__
cmpq $UC_MCONTEXT_FPOWNED_FPU,UC_MCONTEXT_OWNEDFP(%rdi)
jne 1f
cmpq $UC_MCONTEXT_FPFMT_XMM,UC_MCONTEXT_FPFORMAT(%rdi)
jne 1f
fxrstor UC_MCONTEXT_FPSTATE(%rdi)
1:
#else
#error Port me
#endif
/* restore the rest of the state */ /* restore the rest of the state */
mov UC_MCONTEXT_GREGS_R8(%rdi),%r8 mov UC_MCONTEXT_GREGS_R8(%rdi),%r8

View file

@ -61,7 +61,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#define UC_MCONTEXT_GREGS_RCX 0x30 #define UC_MCONTEXT_GREGS_RCX 0x30
#define UC_MCONTEXT_GREGS_RSP 0xa0 #define UC_MCONTEXT_GREGS_RSP 0xa0
#define UC_MCONTEXT_GREGS_RIP 0xb0 #define UC_MCONTEXT_GREGS_RIP 0xb0
#define UC_MCONTEXT_FPREGS_PTR 0x1a8 /* XXXKIB */ #define UC_MCONTEXT_FPSTATE 0xf0
#define UC_MCONTEXT_FPREGS_MEM 0xe0 /* XXXKIB */ #define UC_MCONTEXT_OWNEDFP 0xe8
#define FPREGS_OFFSET_MXCSR 0x18 /* XXXKIB */ #define UC_MCONTEXT_FPFORMAT 0xe0
#define UC_MCONTEXT_FPOWNED_FPU 0x20001
#define UC_MCONTEXT_FPFMT_XMM 0x10002
#endif #endif