1/* libunwind - a platform-independent unwind library 2 Copyright (C) 2007 Google, Inc 3 Contributed by Arun Sharma <arun.sharma@google.com> 4 Copyright (C) 2010 Konstantin Belousov <kib@freebsd.org> 5 6This file is part of libunwind. 7 8Permission is hereby granted, free of charge, to any person obtaining 9a copy of this software and associated documentation files (the 10"Software"), to deal in the Software without restriction, including 11without limitation the rights to use, copy, modify, merge, publish, 12distribute, sublicense, and/or sell copies of the Software, and to 13permit persons to whom the Software is furnished to do so, subject to 14the following conditions: 15 16The above copyright notice and this permission notice shall be 17included in all copies or substantial portions of the Software. 18 19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 26 27#include "ucontext_i.h" 28 29/* int _Ux86_64_setcontext (const ucontext_t *ucp) 30 31 Restores the machine context provided. 32 Unlike the libc implementation, doesn't clobber %rax 33 34*/ 35 .global _Ux86_64_setcontext 36 .type _Ux86_64_setcontext, @function 37 38_Ux86_64_setcontext: 39 40#if defined __linux__ || defined __sun 41 /* restore fp state */ 42#ifdef UC_MCONTEXT_FPREGS_PTR 43 mov UC_MCONTEXT_FPREGS_PTR(%rdi),%r8 44#else // UC_MCONTEXT_FPREGS_PTR 45 leaq UC_MCONTEXT_FPREGS_MEM(%rdi),%r8 46#endif // UC_MCONTEXT_FPREGS_PTR 47 fldenv (%r8) 48 ldmxcsr FPREGS_OFFSET_MXCSR(%r8) 49#elif defined __FreeBSD__ 50 /* restore fp state */ 51 cmpq $UC_MCONTEXT_FPOWNED_FPU,UC_MCONTEXT_OWNEDFP(%rdi) 52 jne 1f 53 cmpq $UC_MCONTEXT_FPFMT_XMM,UC_MCONTEXT_FPFORMAT(%rdi) 54 jne 1f 55 fxrstor UC_MCONTEXT_FPSTATE(%rdi) 561: 57#else 58#error Port me 59#endif 60 61 /* restore the rest of the state */ 62 mov UC_MCONTEXT_GREGS_R8(%rdi),%r8 63 mov UC_MCONTEXT_GREGS_R9(%rdi),%r9 64 mov UC_MCONTEXT_GREGS_RBX(%rdi),%rbx 65 mov UC_MCONTEXT_GREGS_RBP(%rdi),%rbp 66 mov UC_MCONTEXT_GREGS_R12(%rdi),%r12 67 mov UC_MCONTEXT_GREGS_R13(%rdi),%r13 68 mov UC_MCONTEXT_GREGS_R14(%rdi),%r14 69 mov UC_MCONTEXT_GREGS_R15(%rdi),%r15 70 mov UC_MCONTEXT_GREGS_RSI(%rdi),%rsi 71 mov UC_MCONTEXT_GREGS_RDX(%rdi),%rdx 72 mov UC_MCONTEXT_GREGS_RAX(%rdi),%rax 73 mov UC_MCONTEXT_GREGS_RCX(%rdi),%rcx 74 mov UC_MCONTEXT_GREGS_RSP(%rdi),%rsp 75 76 /* push the return address on the stack */ 77 mov UC_MCONTEXT_GREGS_RIP(%rdi),%rcx 78 push %rcx 79 80 mov UC_MCONTEXT_GREGS_RCX(%rdi),%rcx 81 mov UC_MCONTEXT_GREGS_RDI(%rdi),%rdi 82 retq 83 84 .size _Ux86_64_setcontext, . - _Ux86_64_setcontext 85 86 /* We do not need executable stack. */ 87 .section .note.GNU-stack,"",@progbits 88