]> git.saurik.com Git - apple/libplatform.git/blame - src/ucontext/x86_64/getcontext.s
libplatform-254.40.4.tar.gz
[apple/libplatform.git] / src / ucontext / x86_64 / getcontext.s
CommitLineData
ada7c492
A
1/*
2 * Copyright (c) 2007,2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
442fbc9d 5 *
ada7c492
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
442fbc9d 12 *
ada7c492
A
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
442fbc9d 20 *
ada7c492
A
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#if defined(__x86_64__)
25
26#include <architecture/i386/asm_help.h>
27
28#define MCONTEXT_SS_RAX 16
29#define MCONTEXT_SS_RBX 24
30#define MCONTEXT_SS_RCX 32
31#define MCONTEXT_SS_RDX 40
32#define MCONTEXT_SS_RDI 48
33#define MCONTEXT_SS_RSI 56
34#define MCONTEXT_SS_RBP 64
35#define MCONTEXT_SS_RSP 72
36#define MCONTEXT_SS_R8 80
37#define MCONTEXT_SS_RIP 144
38#define MCONTEXT_SS_RFLAGS 152
39
40TEXT
41LABEL(_getcontext)
42 /* struct ucontext_t * $rdi */
43 push %rbp
44 movq %rsp, %rbp
45 movq %rsp, %rsi
46 CALL_EXTERN(_getmcontext) /* getmcontext(uctx, sp) */
47 pop %rbp
48
49#if DEBUG
50 movq $0, MCONTEXT_SS_RAX(%rax)
51 movq $0, MCONTEXT_SS_RDX(%rax)
52 movq $0, MCONTEXT_SS_RCX(%rax)
53 movq $0, MCONTEXT_SS_RDI(%rax)
54 movq $0, MCONTEXT_SS_RSI(%rax)
55 movq $0, MCONTEXT_SS_R8(%rax)
56 movq $0, MCONTEXT_SS_R8+8(%rax)
57 movq $0, MCONTEXT_SS_R8+16(%rax)
58 movq $0, MCONTEXT_SS_R8+24(%rax)
59 movq $0, MCONTEXT_SS_RFLAGS(%rax)
60#endif
61
62 movq %rbp, MCONTEXT_SS_RBP(%rax)
63 movq %rbx, MCONTEXT_SS_RBX(%rax)
64 movq %r12, MCONTEXT_SS_R8+32(%rax)
65 movq %r13, MCONTEXT_SS_R8+40(%rax)
66 movq %r14, MCONTEXT_SS_R8+48(%rax)
67 movq %r15, MCONTEXT_SS_R8+56(%rax)
68 movq (%rsp), %rcx /* return address */
69 movq %rcx, MCONTEXT_SS_RIP(%rax)
70 leaq 8(%rsp), %rcx
71 movq %rcx, MCONTEXT_SS_RSP(%rax)
72 xorl %eax, %eax
73 ret
74
75#endif /* __x86_64__ */