2009-12-23 03:58:17 +01:00
|
|
|
/* libunwind - a platform-independent unwind library
|
2010-04-10 00:42:26 +02:00
|
|
|
Copyright (C) 2010 Konstantin Belousov <kib@freebsd.org>
|
2009-12-23 03:58:17 +01:00
|
|
|
|
|
|
|
This file is part of libunwind.
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
a copy of this software and associated documentation files (the
|
|
|
|
"Software"), to deal in the Software without restriction, including
|
|
|
|
without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be
|
|
|
|
included in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
|
|
|
|
#include "offsets.h"
|
|
|
|
|
|
|
|
.global _Ux86_getcontext
|
|
|
|
.type _Ux86_getcontext, @function
|
|
|
|
_Ux86_getcontext:
|
2010-04-29 01:32:30 +02:00
|
|
|
.cfi_startproc
|
2010-04-13 12:55:23 +02:00
|
|
|
pushl %eax
|
|
|
|
mov 8(%esp),%eax /* ucontext_t* */
|
|
|
|
popl FREEBSD_UC_MCONTEXT_EAX_OFF(%eax)
|
2010-03-10 22:51:59 +01:00
|
|
|
movl %ebx, FREEBSD_UC_MCONTEXT_EBX_OFF(%eax)
|
|
|
|
movl %ecx, FREEBSD_UC_MCONTEXT_ECX_OFF(%eax)
|
|
|
|
movl %edx, FREEBSD_UC_MCONTEXT_EDX_OFF(%eax)
|
|
|
|
movl %edi, FREEBSD_UC_MCONTEXT_EDI_OFF(%eax)
|
|
|
|
movl %esi, FREEBSD_UC_MCONTEXT_ESI_OFF(%eax)
|
|
|
|
movl %ebp, FREEBSD_UC_MCONTEXT_EBP_OFF(%eax)
|
2010-03-09 17:01:08 +01:00
|
|
|
|
|
|
|
movl (%esp), %ecx
|
2010-03-13 19:28:12 +01:00
|
|
|
movl %ecx, FREEBSD_UC_MCONTEXT_EIP_OFF(%eax)
|
2010-03-09 17:01:08 +01:00
|
|
|
|
|
|
|
leal 4(%esp), %ecx /* Exclude the return address. */
|
2010-03-13 19:28:12 +01:00
|
|
|
movl %ecx, FREEBSD_UC_MCONTEXT_ESP_OFF(%eax)
|
2010-03-09 17:01:08 +01:00
|
|
|
|
|
|
|
xorl %ecx, %ecx
|
|
|
|
movw %fs, %cx
|
2010-03-13 19:28:12 +01:00
|
|
|
movl %ecx, FREEBSD_UC_MCONTEXT_FS_OFF(%eax)
|
2010-03-09 17:01:08 +01:00
|
|
|
movw %gs, %cx
|
2010-03-13 19:28:12 +01:00
|
|
|
movl %ecx, FREEBSD_UC_MCONTEXT_GS_OFF(%eax)
|
2010-03-09 17:01:08 +01:00
|
|
|
movw %ds, %cx
|
2010-03-13 19:28:12 +01:00
|
|
|
movl %ecx, FREEBSD_UC_MCONTEXT_DS_OFF(%eax)
|
2010-03-09 17:01:08 +01:00
|
|
|
movw %es, %cx
|
2010-03-13 19:28:12 +01:00
|
|
|
movl %ecx, FREEBSD_UC_MCONTEXT_ES_OFF(%eax)
|
2010-03-09 17:01:08 +01:00
|
|
|
movw %ss, %cx
|
2010-03-13 19:28:12 +01:00
|
|
|
movl %ecx, FREEBSD_UC_MCONTEXT_SS_OFF(%eax)
|
2010-03-09 17:01:08 +01:00
|
|
|
movw %cs, %cx
|
2010-03-13 19:28:12 +01:00
|
|
|
movl %ecx, FREEBSD_UC_MCONTEXT_CS_OFF(%eax)
|
2010-03-09 17:01:08 +01:00
|
|
|
|
|
|
|
pushfl
|
2010-03-13 19:28:12 +01:00
|
|
|
popl FREEBSD_UC_MCONTEXT_EFLAGS_OFF(%eax)
|
|
|
|
|
|
|
|
movl $0, FREEBSD_UC_MCONTEXT_TRAPNO_OFF(%eax)
|
2010-04-16 23:18:33 +02:00
|
|
|
|
2010-03-13 19:28:12 +01:00
|
|
|
movl $FREEBSD_UC_MCONTEXT_FPOWNED_FPU,\
|
|
|
|
FREEBSD_UC_MCONTEXT_OWNEDFP_OFF(%eax)
|
|
|
|
movl $FREEBSD_UC_MCONTEXT_FPFMT_XMM,\
|
|
|
|
FREEBSD_UC_MCONTEXT_FPFORMAT_OFF(%eax)
|
2010-04-09 23:47:08 +02:00
|
|
|
|
2010-04-16 23:18:33 +02:00
|
|
|
/*
|
|
|
|
* Require CPU with fxsave implemented, and enabled by OS.
|
|
|
|
*
|
|
|
|
* If passed ucontext is not aligned to 16-byte boundary,
|
|
|
|
* save fpu context into temporary aligned location on stack
|
|
|
|
* and then copy.
|
|
|
|
*/
|
|
|
|
leal FREEBSD_UC_MCONTEXT_FPSTATE_OFF(%eax), %edx
|
|
|
|
testl $0xf, %edx
|
|
|
|
je 1f
|
|
|
|
movl %edx, %edi
|
|
|
|
movl %esp, %edx
|
|
|
|
subl $512, %esp
|
|
|
|
andl $~0xf, %esp
|
|
|
|
fxsave (%esp)
|
|
|
|
movl %esp, %esi
|
|
|
|
movl $512/4,%ecx
|
|
|
|
rep; movsl
|
|
|
|
movl %edx, %esp
|
|
|
|
movl FREEBSD_UC_MCONTEXT_ESI_OFF(%eax), %esi
|
|
|
|
movl FREEBSD_UC_MCONTEXT_EDI_OFF(%eax), %edi
|
|
|
|
jmp 2f
|
|
|
|
1: fxsave (%edx)
|
|
|
|
2:
|
2010-04-09 23:47:08 +02:00
|
|
|
|
2010-03-13 19:28:12 +01:00
|
|
|
movl $FREEBSD_UC_MCONTEXT_MC_LEN_VAL,\
|
|
|
|
FREEBSD_UC_MCONTEXT_MC_LEN_OFF(%eax)
|
2009-12-23 03:58:17 +01:00
|
|
|
|
2010-04-13 13:11:39 +02:00
|
|
|
xorl %eax, %eax
|
2009-12-23 03:58:17 +01:00
|
|
|
ret
|
2010-04-29 01:32:30 +02:00
|
|
|
.cfi_endproc
|
2010-03-09 17:01:08 +01:00
|
|
|
.size _Ux86_getcontext, . - _Ux86_getcontext
|
2009-12-23 03:58:17 +01:00
|
|
|
|
2010-03-09 17:01:08 +01:00
|
|
|
/* We do not need executable stack. */
|
|
|
|
.section .note.GNU-stack,"",@progbits
|